Mods in C
Цей контент ще не доступний вашою мовою.
A mod is a DLL that exports five functions over the C ABI, so any language that
can include a C header can write one: C, C++, Zig, Odin. The header is
enshwick.h,
written from the same Rust types the loader uses and checked against the ABI’s
layout on every change. Here you build the example mod
hello.c,
which writes one line to the log when it starts.
Write the mod
Section titled “Write the mod”- Copy
enshwick.hnext to your source file. - Fill a static
EnshwickManifest: itsheaderis the struct’s size andENSHWICK_ABI_VERSION; a mod needs at leastid,versionandside.ENSHWICK_STR_INIT("text")makes a string. - Define
enshwick_mod_abi,enshwick_mod_query,enshwick_mod_initandenshwick_mod_ready;enshwick_mod_shutdownis optional. The header declares them withENSHWICK_EXPORT, so the DLL exports them. - In
enshwick_mod_init, call the loader through theEnshwickHostApitable it passes, such ashost->log(me, EnshwickLevel_INFO, line).
Names follow one pattern: Rust’s Status::OK is EnshwickStatus_OK, the type
HookSpec is EnshwickHookSpec, and a constant such as MAX_ZONES is
ENSHWICK_MAX_ZONES. Every comment in the header is the Rust item’s
documentation.
Build it
Section titled “Build it”On Windows with LLVM, or on Linux and macOS with clang and lld:
clang --target=x86_64-pc-windows-msvc -std=c11 -O2 -shared -fuse-ld=lld \ hello.c -o hello_c.dllhello.c uses no C runtime, so it also builds with
-ffreestanding -nostdlib -Wl,/NOENTRY and needs no Windows SDK. A mod that
calls the C runtime links it as usual: with Visual Studio’s cl /LD, clang-cl
or cargo-xwin’s SDK off Windows.
Check it
Section titled “Check it”Run cargo enshwick manifest hello_c.dll on Windows. It loads the DLL, asks it
for its manifest and prints the id, version and side. Then copy the DLL into the
game’s mods/ folder. The log shows hello from C under you.hello-c when the
loader starts it.
Keep it current
Section titled “Keep it current”A struct that starts with an EnshwickHeader only grows at its end, and the
loader reads your struct only as far as your header says, so a mod built against
an older enshwick.h keeps loading. Take a newer header for the newer fields
and functions. The ABI reference has the rules.