Skip to main content

samp_sdk/raw/
types.rs

1//! Direct translation of the `amx.h` header structs into Rust.
2//!
3//! All are `#[repr(C, packed)]` — the AMX assumes a layout identical to the
4//! original Pawn interpreter. Do not add, remove, or reorder fields without
5//! reviewing the corresponding C header, or the VM will start reading/writing
6//! at the wrong offsets.
7
8use super::functions::{AmxCallback, AmxDebug, AmxNative};
9use std::os::raw::{c_char, c_int, c_long, c_uchar, c_void};
10
11/// AMX VM instance. Each AMX loaded by the server (gamemode + filterscripts)
12/// is a pointer to this struct.
13#[repr(C, packed)]
14pub struct AMX {
15    pub base: *mut c_uchar,
16    pub data: *mut c_uchar,
17    pub callback: AmxCallback,
18    pub debug: AmxDebug,
19    pub cip: i32,
20    pub frm: i32,
21    pub hea: i32,
22    pub hlw: i32,
23    pub stk: i32,
24    pub stp: i32,
25    pub flags: c_int,
26    pub usertags: [c_long; 4usize],
27    pub userdata: [*mut c_void; 4usize],
28    pub error: c_int,
29    pub paramcount: c_int,
30    pub pri: i32,
31    pub alt: i32,
32    pub reset_stk: i32,
33    pub reset_hea: i32,
34    pub sysreq_d: i32,
35}
36
37/// Entry of the natives table registered via `amx_Register` — a name+pointer pair.
38#[repr(C, packed)]
39#[derive(Copy, Clone)]
40pub struct AMX_NATIVE_INFO {
41    pub name: *const c_char,
42    pub func: AmxNative,
43}
44
45/// Public/native function stub inside the `.amx`. Layout with inline name (20 bytes).
46#[repr(C, packed)]
47pub struct AMX_FUNCSTUB {
48    pub address: u32,
49    pub name: [c_char; 20usize],
50}
51
52/// Function stub in `.amx` compiled with `defsize=8` — the name is resolved by
53/// an offset in the nametable (not inline).
54///
55/// Name inherited from the original C header (`AMX_FUNCSTUBNT` — the leading
56/// "ANX" is a historic typo kept for binary compatibility).
57#[repr(C, packed)]
58pub struct ANX_FUNCSTUBNT {
59    pub address: u32,
60    pub nameofs: u32,
61}
62
63/// Header of the `.amx` file loaded in memory. Offsets in this struct point
64/// to sections inside the file itself.
65#[repr(C, packed)]
66pub struct AMX_HEADER {
67    pub size: i32,
68    pub magic: u16,
69    pub file_version: c_char,
70    pub amx_version: c_char,
71    pub flags: i16,
72    pub defsize: i16,
73    pub cod: i32,
74    pub dat: i32,
75    pub hea: i32,
76    pub stp: i32,
77    pub cip: i32,
78    pub publics: i32,
79    pub natives: i32,
80    pub libraries: i32,
81    pub pubvars: i32,
82    pub tags: i32,
83    pub nametable: i32,
84}