#C API for (advanced?) modding
167 messages · Page 1 of 1 (latest)
C# modding is planned
As long as it exposes it via C's ABI then I'm not complaining 🙏
Definitely think C++/Rust/Carbon/Go/etc would be nice to use for modding
With the obvious inclusion of C# support as you say
Cosmoteer is made with C# so that’s the obvious choice
If you want C modding
you must be joking
just use Lua at that point
I don't want C specifically, most other languages have C interop so they will then be able to create mods
I could then use Lua or even Python if I wanted to, creating bindings for them directly is stupid, so rather expose using C's ABI
Python 💀
Personally I would probably end up using Rust, maybe even create a wrapper for python or lua myself then
No.
rust?
Ghost pinging
did you know?
if you are alone in a desert, just say "C++ is better than Rust" and someone will find you
Jokes on you I'm a rust fanboy
Rust
I'm more of a "Rust is better than C++" and I'd immediately be swarmed
💤
Doesn't bother me, both are good for their own reasons
Use whichever you want, if the game uses C's ABI then it ultimately becomes the choice of mod devs using whatever they want to
Doing this will probably lead to some wonderful homies who create wrappers for the rest of us to use
The game uses a VM language
A wrapper to a non-managed language would be backwards on so many levels.
Just learn C#, sheesh. It's an easy language. :P
C# gets compiled to an IL, so yes a VM language, at runtime .NET has the option to JIT it or not
Writing a simple DLL that both the game and mods use isn't difficult, even if using C#
Take Rust for a mod example:```rs
#[link(name = "bootstrapperdll", kind = "static")]
#[link(name = "Runtime", kind = "static")]
#[link(name = "libcosmoteer", kind = "static")]
extern "C" {
pub fn some_cosmoteer_function();
}
I can VERY easily boostrap the CLR GC and runtime libraries
This suggestion isn't a "I don't like C#", It's to make modding available to literally anybody, hell you could even write your mod in assembly if you really wanted to
I'm not disagreeing with this, but expose your library using C's ABI then every language can use it
Not only C#
That would generally mean you're not letting JIT do its thing.
And let's be real, i trust JIT more than i trust a modder.
Nothing stops it 😛
This would not effect the game whatsoever
Your just AOT compiling some public library
It can only work with managed code, whatever modded C code is on the other side stays shitty and slow. :P
Let's be real, the mod will probably run faster than the game
Oh, and you cannot use harmony with C ABI.
Since harmony works through the VM functions.
Harmony is a modding lib that lets you rewrite any method as the game runs.
That will be unaffected
Usually it's done as the game loads, but nothing stops you from using it later either
Any method.
All your changing is moving the games internal classes -> external dll
That includes adding intermod stuff.
Or do you mean the classes have methods that need editing at runtime?
Classes always need editing at runtime.
I've never seen a game whose modding isn't enhanced by reflection.
Or what, you think that most moddable games being written in a VM language is a fluke? :p
Not at all
C# isn't a bad choice whatsoever, I personally believe it's the better choice for games
Give me some time to research more into this, that'll justify if this idea is a waste or not
I would appreciate wide language support, but if it's not feasible then I guess that's the end of it
The thing is, you're trying to "fix" a problem that doesn't exist. The game doesn't need C ABI, since C# is basically a scripting language with good libraries and static typing.
At mod level.
Not trying to fix anything, I'm not a fan of C# therefore I naturally appreciate support for other languages
You don't need to think to write C# code.
Not sure how FFI would change this just yet, but if Harmony works with it nicely, then using C's ABI is no extra work.
The real work has to be put in on our sides, if we end up using languages other than C#
I would much rather let JIT do the work.
JIT will still stay the same
Do the work on the mods, not just the base game.
We're moving Harmony (to both sides) and move the data classes to a DLL
Any language supporting C's ABI will then be able to work with said data classes
In a non-threading environment
There are genuinely more problems with C and, what's the issue it solves?
Having to learn another scripting language?
Pfft.
C's problems don't matter here, your just exposing using it's ABI
Yeah that creates issues
Definitely doesn't
You're thinking from a software development viewpoint, modding viewpoint is different
Hacking into each other's mods to fix shit is a common fucking thing.
I don't see how this interferes in any way
Why would that be necessary?
My initial question was to let your language interpreter expose it's data classes via C's ABIs so we can "fake" the source
But at the same time, provide more control over the game
That's not how game modding works
There is no standard for it
Like, whatsoever
Whether you have a Lua engine or not
If you support C# modding, it's C's "format" of a DLL, which every other language supporting it's ABI can then be used at the same time
There actually are two standards, Lua and managed. Managed is basically raw OOP with minimal restrictions, and Lua is allergic to OOP so you use duck typing there.
Generally this means you need to extend a bunch of vanilla runner classes and then feed them back into the game via its data loader. Json, xml, whatever.
Note: code that, usually, runs every tick.
I'm willing to bet that when C# mod support comes, the rest of the languages will follow
I've never seen anyone try to mod a game in a language that the game isn't written in.
I don't know what .net emits for classes, but It's probably similar to C++ with Clang
Okay, i've seen some madlads write scala mods on minecraft, but it still compiles to managed code.
dies of laughter
If it exposes using C's ABI (Which it 99% of the time does), then all other languages can
Yeah, no, go read up on how managed languages work first
Cpp, and most languages, compile into raw assembler.
C# and Java both compile into an intermediate language that is like two levels separated from the system, to the point where you can easily restore source files in both languages.
I'm aware of that, I've written all my Unity plugins in Rust
I've had to work through FII with C# many, many times
Python has a IL, which is interpreted
Rust has a IL, which is compiled to native assembler
At the end of the day, It's not black magic to get LLVM working nicely with anything
At the end of the day, you are the first person i've seen want to mod a C# game in fucking Rust in a decade
C/C++/Rust all provide the ability to use higher level languages, be it lua, go, python, whatever else
You do can do this the same way you would support C#
It's completely unnecessary, especially when minimal mod support would take like less than a screen worth of code, if we're talking only C#.
Let me ask this first, for C# support do you plan on compiling mods to DLLs?
CLI DLLs, not C ABI
"Note that a C# DLL is also a CLI DLL and can be used in a C++/CLI .NET project in the exact same way as a C++/CLI DLL."
There's our answer, this isn't restricted to C#
So either C# has it's own ABI for that (I find this option more likely), or it still uses C's ABI. Both ways LLVM should most definitely be able to interact with this
I am currently trying to imagine the infrastructure you would need to build to extend C# classes in an outside language.
For the love of god, I hope for my sake C# mods won't be extending classes
Passing objects built by the VM out and back in, that sort of thing.
They probably will, let's be honest
dies of laughter
My dude
You ever, you know, modded a game?
Shit man that will make this rather not pog
Oh yeah, just not using C#
I found Harmony rather interesting, I've never seen a game do that before
It makes what I want somewhat more complicated
No, true scripting languages don't count. You can twist Lua into a pretzel.
I mean C# FFI in general is a pain in the ass
^Warned you
In the end, i don't see what's so bad about C#, apart from the inherent issues of the memory model that you can also evade if you want.
I'll probably end up having to get a instance of the .net runtime to pull this off
I promise you, both myself and Rusts compiler will make memory errors difficult
Unless your playing with pointer magic, it's somewhat difficult to do this wrong
My dude
Looking at the DLLExport in C#, I'm starting to think it's actually C's ABI
C# has the best memory management system
Known as "you don't get to manage memory"
I'm aware :)
Write perfectly safe code without the sheer amount of boilerplate Rust likes to have.
Also I'm fairly certain C# does have manual management support
What boilerplate 🤣
You can shoot yourself in the leg, you just need to ask VM for both the gun and the bullet separately first.
I mean the same goes for rust
least brainwashed rust user
I just ask for the gun and I get the bullet already loaded
I'm not brainwashed because I know Rust rather well
I've written both x86 and ARM kernels, pid 0 apps for linux etc
Whether or not we get "official" support for C, I'll probably end up trying this just to have some fun
Seems it won't be difficult, somebody's already done a crate to host .net
Anyways, I'm going to leave this post open, maybe one day the devs will bless me with C support
Perhaps the C# support doesn't extend classes (I don't know how possible this would be), but yeah, crazy request for later in development
ah finally a use case for java
no
you will bring java modding if this happens
C# is just java with sugar, let's be real