#C API for (advanced?) modding

167 messages · Page 1 of 1 (latest)

sick vector
#

I think a C API that could directly control the game would definitely be nice. It could offer more control than the current text language. People could use it to make custom gamemodes, maybe create optimization mods, control the systems themselves, etc.

orchid elm
#

C# modding is planned

sick vector
#

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

orchid elm
#

Cosmoteer is made with C# so that’s the obvious choice

elfin shard
#

you must be joking

#

just use Lua at that point

sick vector
#

I don't want C specifically, most other languages have C interop so they will then be able to create mods

elfin shard
#

ah

#

so you are suggesting Lua modding possibly

sick vector
#

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

torpid tree
#

Python 💀

sick vector
elfin shard
torpid tree
#

Who pinged me bruh

#

Some funny guy

torpid tree
#

Ghost pinging

elfin shard
sick vector
#

Jokes on you I'm a rust fanboy

torpid tree
#

Rust

sick vector
#

I'm more of a "Rust is better than C++" and I'd immediately be swarmed

torpid tree
#

💤

sick vector
#

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

worldly latch
#

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

sick vector
#

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

worldly latch
#

That is entirely unnecessary.

#

Like i said, C# is an easy language. :p

sick vector
#

I'm not disagreeing with this, but expose your library using C's ABI then every language can use it

#

Not only C#

worldly latch
#

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.

sick vector
#

Nothing stops it 😛

#

This would not effect the game whatsoever

#

Your just AOT compiling some public library

worldly latch
#

It can only work with managed code, whatever modded C code is on the other side stays shitty and slow. :P

sick vector
#

Let's be real, the mod will probably run faster than the game

worldly latch
#

Oh, and you cannot use harmony with C ABI.

#

Since harmony works through the VM functions.

sick vector
#

Harmony?

#

I can write C# at a kids level, so I'm not aware of some stuff it has

worldly latch
#

Harmony is a modding lib that lets you rewrite any method as the game runs.

sick vector
#

That will be unaffected

worldly latch
#

Usually it's done as the game loads, but nothing stops you from using it later either

#

Any method.

sick vector
#

All your changing is moving the games internal classes -> external dll

worldly latch
#

That includes adding intermod stuff.

sick vector
#

Or do you mean the classes have methods that need editing at runtime?

worldly latch
#

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

sick vector
#

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

worldly latch
#

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.

sick vector
#

Not trying to fix anything, I'm not a fan of C# therefore I naturally appreciate support for other languages

worldly latch
#

You don't need to think to write C# code.

sick vector
#

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#

worldly latch
#

I would much rather let JIT do the work.

sick vector
#

JIT will still stay the same

worldly latch
#

Do the work on the mods, not just the base game.

sick vector
#

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

worldly latch
#

There are genuinely more problems with C and, what's the issue it solves?

#

Having to learn another scripting language?

#

Pfft.

sick vector
#

C's problems don't matter here, your just exposing using it's ABI

worldly latch
#

Yeah that creates issues

sick vector
#

Definitely doesn't

worldly latch
#

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.

sick vector
#

I don't see how this interferes in any way

worldly latch
#

Dude

#

Dude

#

Do you want to fix other mods in fucking assembler?

sick vector
#

Why would that be necessary?

worldly latch
#

How else do you expect it to happen?

#

Even visible source is not entirely common.

sick vector
#

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

worldly latch
#

That's not how game modding works

sick vector
#

There is no standard for it

worldly latch
#

Like, whatsoever

sick vector
#

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

worldly latch
#

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.

sick vector
#

I'm willing to bet that when C# mod support comes, the rest of the languages will follow

worldly latch
#

I've never seen anyone try to mod a game in a language that the game isn't written in.

sick vector
#

I don't know what .net emits for classes, but It's probably similar to C++ with Clang

worldly latch
#

Okay, i've seen some madlads write scala mods on minecraft, but it still compiles to managed code.

sick vector
worldly latch
#

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.

sick vector
#

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

worldly latch
#

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

sick vector
#

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#

worldly latch
#

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#.

sick vector
#

Let me ask this first, for C# support do you plan on compiling mods to DLLs?

worldly latch
#

CLI DLLs, not C ABI

sick vector
#

"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

worldly latch
#

I am currently trying to imagine the infrastructure you would need to build to extend C# classes in an outside language.

sick vector
#

For the love of god, I hope for my sake C# mods won't be extending classes

worldly latch
#

Passing objects built by the VM out and back in, that sort of thing.

sick vector
#

They probably will, let's be honest

worldly latch
#

My dude

#

You ever, you know, modded a game?

sick vector
#

Shit man that will make this rather not pog

sick vector
#

I found Harmony rather interesting, I've never seen a game do that before

#

It makes what I want somewhat more complicated

worldly latch
#

No, true scripting languages don't count. You can twist Lua into a pretzel.

sick vector
#

I mean C# FFI in general is a pain in the ass

worldly latch
#

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.

sick vector
#

I'll probably end up having to get a instance of the .net runtime to pull this off

sick vector
#

Unless your playing with pointer magic, it's somewhat difficult to do this wrong

worldly latch
#

My dude

sick vector
#

Looking at the DLLExport in C#, I'm starting to think it's actually C's ABI

worldly latch
#

C# has the best memory management system

#

Known as "you don't get to manage memory"

sick vector
#

I'm aware :)

worldly latch
#

Write perfectly safe code without the sheer amount of boilerplate Rust likes to have.

sick vector
#

Also I'm fairly certain C# does have manual management support

worldly latch
sick vector
#

I mean the same goes for rust

worldly latch
sick vector
#

I just ask for the gun and I get the bullet already loaded

sick vector
#

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

weak zenith
#

ah finally a use case for java

elfin shard
#

no

weak zenith
#

you will bring java modding if this happens

worldly latch
#

C# is just java with sugar, let's be real

sick vector
#

Unless someone writes a wrapper for it, but why would anybody do that

#

This time I actually agree, you should just stick to C#