rust-samp-sdk 3.6.0

Low-level FFI bindings for the SA-MP AMX virtual machine and open.mp native component ABI. Used internally by `rust-samp`; depend on it directly only if you need raw access without the higher-level macros and lifecycle.
Documentation
//! `ICore` — generated by `cargo xtask gen-omp` from `core.hpp`.
//! Implemented by `Core` in the server's `omp-server`.
//!
//! Do not edit: change `xtask/omp-wrappers.toml` or the generator and
//! regenerate. Slots are clang's layout of the header for each ABI, checked
//! against the official binaries by `cargo xtask check-abi --generated`.

#![allow(unused_imports)]

use crate::omp::containers::{FlatSet, HybridString, Pair, Span};
use crate::omp::types::{
    Colour, GTAQuat, Hours, Microseconds, Milliseconds, Minutes, Seconds, StringView, TimePoint,
    UID, Vector2, Vector3, Vector4, WorldTimePoint,
};
use crate::omp::vtable::{call_vtable_small_struct, opaque, slots, virtual_fns};
use crate::omp::*;

slots! {
    /// `SemanticVersion ICore::getVersion()`
    SLOT_GET_VERSION: usize = 6, 5;
    /// `int ICore::getNetworkBitStreamVersion()`
    SLOT_GET_NETWORK_BIT_STREAM_VERSION: usize = 7, 6;
    /// `IPlayerPool & ICore::getPlayers()`
    SLOT_GET_PLAYERS: usize = 8, 7;
    /// `IEventDispatcher<CoreEventHandler> & ICore::getEventDispatcher()`
    SLOT_GET_EVENT_DISPATCHER: usize = 9, 8;
    /// `IConfig & ICore::getConfig()`
    SLOT_GET_CONFIG: usize = 10, 9;
    /// `const FlatPtrHashSet<INetwork> & ICore::getNetworks()`
    SLOT_GET_NETWORKS: usize = 11, 10;
    /// `unsigned int ICore::getTickCount()`
    SLOT_GET_TICK_COUNT: usize = 12, 11;
    /// `void ICore::setGravity(float)`
    SLOT_SET_GRAVITY: usize = 13, 12;
    /// `float ICore::getGravity()`
    SLOT_GET_GRAVITY: usize = 14, 13;
    /// `void ICore::setWeather(int)`
    SLOT_SET_WEATHER: usize = 15, 14;
    /// `void ICore::setWorldTime(Hours)`
    SLOT_SET_WORLD_TIME: usize = 16, 15;
    /// `void ICore::useStuntBonuses(bool)`
    SLOT_USE_STUNT_BONUSES: usize = 17, 16;
    /// `void ICore::setData(SettableCoreDataType, StringView)`
    SLOT_SET_DATA: usize = 18, 17;
    /// `void ICore::setThreadSleep(Microseconds)`
    SLOT_SET_THREAD_SLEEP: usize = 19, 18;
    /// `void ICore::useDynTicks(const bool)`
    SLOT_USE_DYN_TICKS: usize = 20, 19;
    /// `void ICore::resetAll()`
    SLOT_RESET_ALL: usize = 21, 20;
    /// `void ICore::reloadAll()`
    SLOT_RELOAD_ALL: usize = 22, 21;
    /// `StringView ICore::getWeaponName(PlayerWeapon)`
    SLOT_GET_WEAPON_NAME: usize = 23, 22;
    /// `void ICore::connectBot(StringView, StringView)`
    SLOT_CONNECT_BOT: usize = 24, 23;
    /// `void ICore::requestHTTP(HTTPResponseHandler *, HTTPRequestType, StringView, StringView)`
    SLOT_REQUEST_HTTP: usize = 25, 24;
    /// `unsigned int ICore::tickRate()`
    SLOT_TICK_RATE: usize = 26, 25;
    /// `bool ICore::sha256(StringView, StringView, StaticArray<char, 64 + 1> &)`
    SLOT_SHA256: usize = 27, 26;
    /// `StringView ICore::getVersionHash()`
    SLOT_GET_VERSION_HASH: usize = 28, 27;
    /// `void ICore::requestHTTP4(HTTPResponseHandler *, HTTPRequestType, StringView, StringView)`
    SLOT_REQUEST_HTTP4: usize = 29, 28;
}

virtual_fns! {
    /// `int ICore::getNetworkBitStreamVersion()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_network_bit_stream_version(
        core: ICore,
    ) -> i32 = [0, SLOT_GET_NETWORK_BIT_STREAM_VERSION] or 0;

    /// `IPlayerPool & ICore::getPlayers()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_players(
        core: ICore,
    ) -> *mut IPlayerPool = [0, SLOT_GET_PLAYERS] or std::ptr::null_mut();

    /// `IEventDispatcher<CoreEventHandler> & ICore::getEventDispatcher()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_event_dispatcher(
        core: ICore,
    ) -> *mut EventDispatcher<CoreHandler> = [0, SLOT_GET_EVENT_DISPATCHER] or std::ptr::null_mut();

    /// `IConfig & ICore::getConfig()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_config(core: ICore) -> *mut IConfig = [0, SLOT_GET_CONFIG] or std::ptr::null_mut();

    /// `const FlatPtrHashSet<INetwork> & ICore::getNetworks()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_networks(
        core: ICore,
    ) -> *const FlatSet<std::ffi::c_void> = [0, SLOT_GET_NETWORKS] or std::ptr::null();

    /// `unsigned int ICore::getTickCount()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_tick_count(core: ICore) -> u32 = [0, SLOT_GET_TICK_COUNT] or 0;

    /// `void ICore::setGravity(float)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_set_gravity(core: ICore, gravity: f32) = [0, SLOT_SET_GRAVITY];

    /// `float ICore::getGravity()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_gravity(core: ICore) -> f32 = [0, SLOT_GET_GRAVITY] or 0.0;

    /// `void ICore::setWeather(int)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_set_weather(core: ICore, weather: i32) = [0, SLOT_SET_WEATHER];

    /// `void ICore::setWorldTime(Hours)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_set_world_time(core: ICore, time: Hours) = [0, SLOT_SET_WORLD_TIME];

    /// `void ICore::useStuntBonuses(bool)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_use_stunt_bonuses(core: ICore, enable: bool) = [0, SLOT_USE_STUNT_BONUSES];

    /// `void ICore::setData(SettableCoreDataType, StringView)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_set_data(core: ICore, type_value: i32, data: StringView) = [0, SLOT_SET_DATA];

    /// `void ICore::setThreadSleep(Microseconds)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_set_thread_sleep(core: ICore, value: Microseconds) = [0, SLOT_SET_THREAD_SLEEP];

    /// `void ICore::useDynTicks(const bool)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_use_dyn_ticks(core: ICore, enable: bool) = [0, SLOT_USE_DYN_TICKS];

    /// `void ICore::resetAll()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_reset_all(core: ICore) = [0, SLOT_RESET_ALL];

    /// `void ICore::reloadAll()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_reload_all(core: ICore) = [0, SLOT_RELOAD_ALL];

    /// `void ICore::connectBot(StringView, StringView)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_connect_bot(
        core: ICore,
        name: StringView,
        script: StringView,
    ) = [0, SLOT_CONNECT_BOT];

    /// `void ICore::requestHTTP(HTTPResponseHandler *, HTTPRequestType, StringView, StringView)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_request_http(
        core: ICore,
        handler: *mut HTTPResponseHandler,
        type_value: i32,
        url: StringView,
        data: StringView,
    ) = [0, SLOT_REQUEST_HTTP];

    /// `unsigned int ICore::tickRate()`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_tick_rate(core: ICore) -> u32 = [0, SLOT_TICK_RATE] or 0;

    /// `bool ICore::sha256(StringView, StringView, StaticArray<char, 64 + 1> &)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    #[must_use]
    pub fn core_sha256(
        core: ICore,
        password: StringView,
        salt: StringView,
        output: &mut [i8; 65],
    ) -> bool = [0, SLOT_SHA256] or false;

    /// `void ICore::requestHTTP4(HTTPResponseHandler *, HTTPRequestType, StringView, StringView)`.
    ///
    /// # Safety
    /// `core` must be a live `ICore`.
    pub fn core_request_http4(
        core: ICore,
        handler: *mut HTTPResponseHandler,
        type_value: i32,
        url: StringView,
        data: StringView,
    ) = [0, SLOT_REQUEST_HTTP4];
}

/// `SemanticVersion ICore::getVersion()`.
///
/// # Safety
/// `core` must be a live `ICore`.
#[must_use]
pub unsafe fn core_version(core: *mut ICore) -> Option<SemanticVersion> {
    call_vtable_small_struct!(
        core.cast::<u8>(),
        0,
        SLOT_GET_VERSION,
        SemanticVersion,
        SemanticVersion::new(0, 0, 0)
    )
}

/// `StringView ICore::getWeaponName(PlayerWeapon)`.
///
/// # Safety
/// `core` must be a live `ICore`.
#[must_use]
pub unsafe fn core_weapon_name(core: *mut ICore, weapon: i32) -> Option<String> {
    let view = call_vtable_small_struct!(
        core.cast::<u8>(),
        0,
        SLOT_GET_WEAPON_NAME,
        StringView,
        StringView::EMPTY,
        (i32)(weapon)
    )?;
    unsafe { view.to_owned_string() }
}

/// `StringView ICore::getVersionHash()`.
///
/// # Safety
/// `core` must be a live `ICore`.
#[must_use]
pub unsafe fn core_version_hash(core: *mut ICore) -> Option<String> {
    let view = call_vtable_small_struct!(
        core.cast::<u8>(),
        0,
        SLOT_GET_VERSION_HASH,
        StringView,
        StringView::EMPTY
    )?;
    unsafe { view.to_owned_string() }
}