A minimal, cross-platform proof-of-concept for creating Source Engine server plugins using Rust.
Important
This is a proof-of-concept and has only been tested to load successfully in Portal 2 on Windows and Linux. It serves as a starting point and demonstrates the correct ABI setup for both platforms.
- Add the target toolchain:
rustup target add i686-pc-windows-msvc
- Build the project:
cargo build --target i686-pc-windows-msvc --release
- The output will be
target/i686-pc-windows-msvc/release/source_plugin_rs.dll.
- Install multilib build tools (e.g.,
sudo apt-get install gcc-multilib). - Add the target toolchain:
rustup target add i686-unknown-linux-gnu
- Build the project:
cargo build --target i686-unknown-linux-gnu --release
- The output will be
target/i686-unknown-linux-gnu/release/libsource_plugin_rs.so.
The plugin implements IServerPluginCallbacks003:
| Function | When Called | Use Case |
|---|---|---|
load() |
Plugin loaded | Initialize resources |
server_activate() |
Map loaded | Hook game state |
game_frame() |
Every tick | Game logic |
unload() |
Plugin unloaded | Cleanup |
See Valve's SDK docs for details.
Edit the functions in src/lib.rs:
define_vtable_fn!(fn server_activate(_edict_list: *const c_void, _edict_count: i32, _client_max: i32) {
eprintln!("[RUST_PLUGIN] Map loaded! Let's do something cool...");
// Your code here
});Contributions welcome! Please open an issue or PR.
Credits: Thanks to 0xNULLderef for technical guidance.
MIT License - see LICENSE file.