Skip to content
NullSablexPublic
forked from zottce/samp-rs

About

Write SA-MP and open.mp plugins in safe Rust instead of C++. The #[native] macro turns Rust methods into Pawn-callable functions; one source compiles to a single binary that runs natively on both servers. FFI is panic-safe and ABI-correct for Linux (Itanium) and Windows (MSVC).

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

6 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

CI release rust-samp rust-samp-sdk rust-samp-codegen downloads docs.rs MSRV stars License: MIT OpenSSF Scorecard dependency status

rust-samp

Rust toolkit for writing SA-MP server plugins and native Open Multiplayer components. A single compiled binary works as a SA-MP plugin and as a first-class Open Multiplayer component, with no extra configuration.

As a component it can also talk to the Open Multiplayer server directly — player and vehicle events delivered by the server itself, entities created and read, players found by id — instead of going through Pawn. See Talking to the Server Directly.

Fork of samp-rs by ZOTTCE. Modernized for Rust edition 2024 and extended with a pure-Rust implementation of the Open Multiplayer component ABI (Itanium and MSVC), without bindgen or any C/C++ dependency.

Not affiliated. This is an independent, community-maintained project. It is not affiliated with, endorsed by, sponsored by, or otherwise connected to SA-MP, the open.mp (Open Multiplayer) project, or the upstream samp-rs repository this fork derives from. It has no relationship with any of them. "SA-MP" and "open.mp" belong to their respective owners and are referenced here solely to describe what this toolkit is compatible with.

Quickstart

rustup target add i686-unknown-linux-gnu

Cargo.toml — from crates.io:

[lib]
crate-type = ["cdylib"]

[dependencies]
samp = { package = "rust-samp", version = "3" }
log  = "0.4"

Or via git (any version, including v3.0.0 and earlier, which are not on crates.io):

[dependencies]
samp = { git = "https://github.com/NullSablex/rust-samp.git", tag = "vX.Y.Z" }

The package is published as rust-samp to avoid colliding with the upstream samp-rs fork on the registry. The package = "rust-samp" alias keeps source-level use samp::prelude::*; imports unchanged.

src/lib.rs:

use samp::prelude::*;
use samp::{native, initialize_plugin, SampPlugin};

#[derive(SampPlugin, Default)]
struct Hello;

impl Hello {
    #[native(name = "Hello_Greet")]
    fn greet(_amx: &Amx, name: &AmxString, out: UnsizedBuffer, size: usize) -> AmxResult<bool> {
        out.write_str(size, &format!("Hello, {}!", &**name))?;
        Ok(true)
    }
}

initialize_plugin!(type: Hello, natives: [Hello::greet]);
cargo build --release --target i686-unknown-linux-gnu

Drop the resulting .so into the server's plugins/. Full walkthrough in docs/first-plugin.md.

Workspace

Crate Purpose
samp Main crate — depend on this one.
samp-sdk Low-level bindings: AMX VM + Open Multiplayer component ABI.
samp-codegen Procedural macros (#[native], initialize_plugin!, SampPlugin).

Each crate is versioned on its own: a repository release (v3.x.y, the GitHub tag) bundles whatever crate versions it lists in the CHANGELOG, so the crate numbers on crates.io need not match the release number.

Edition 2024, workspace resolver = "3". Target: i686 — both servers are 32-bit.

Platform matrix

Target SA-MP Native Open Multiplayer Build command
i686-unknown-linux-gnu ✅ ✅ (Itanium ABI) cargo build
i686-pc-windows-msvc ✅ ✅ (MSVC ABI) cargo xwin build --xwin-arch x86 (from Linux)
i686-pc-windows-gnu ✅ ❌ cargo build --features samp-only

Feature flags

  • (default) — SA-MP exports + Open Multiplayer ComponentEntryPoint.
  • samp-only — opt out of the Open Multiplayer code path; plugin still loads on Open Multiplayer in legacy mode. Declare it on the plugin as samp-only = ["samp/samp-only"] and build with --features samp-only, so the plugin's own #[cfg(feature = "samp-only")] agrees with the SDK.
  • encoding — string conversion for the code pages servers run (Windows-1250 through 1257, ISO-8859-2, UTF-8 and the rest of the WHATWG set) via encoding_rs.
  • debug — samp::debug: the AMX_DBG debug-info parser plus the opcode helpers (numbering, instruction sizes, the computed-goto OpcodeMap) and call-stack walking, for building debuggers and tooling on the VM (see VM Debugging).
  • compression — gzip-compress rotated log archives (LoggerConfig::compress_archives); pulls in flate2.

Examples

Path Highlights
examples/hello Minimal plugin (#[derive(SampPlugin)], &AmxString, write_str).
examples/counter Stateful plugin: on_tick, Ref<i32>, background work, native open.mp events and entities.
examples/advanced Memcache plugin: custom AmxCell, encoding feature, layered fern.
examples/sink-demo External log sink: end-to-end Sentry integration via the Sink trait.
examples/omp-showcase Test harness: runs every generated open.mp wrapper on a live server — entities, an NPC as player, set/get round trips.

Documentation

Full user docs under docs/ (MkDocs Material). Starting points:

License

MIT — see LICENSE.

About

Write SA-MP and open.mp plugins in safe Rust instead of C++. The #[native] macro turns Rust methods into Pawn-callable functions; one source compiles to a single binary that runs natively on both servers. FFI is panic-safe and ABI-correct for Linux (Itanium) and Windows (MSVC).

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

6 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages