#bindings #scripthookv #gta #natives

scripthookv-rs

Rust bindings for ScriptHookV

9 releases

0.3.0 Mar 26, 2022
0.2.1 Dec 31, 2021
0.1.6 Dec 24, 2021

#960 in Game dev

30 downloads per month

MIT license

56KB
1.5K SLoC

scripthookv-rs

Scripthookv-rs provides Rust bindings for ScriptHookV and GTA 5 natives.

DISCLAIMER: This crate is still in early development and API is subject to change.

Crates

libscripthookv-sys

This crate contains the raw bindings for ScriptHookV without any wrapping.

Installation

Add the following to your cargo.toml dependencies:

libscripthookv-sys = "0.1.0"

scripthookv-rs

This crate contains a wrapped api for ScriptHookV

Installation

Add the following to your cargo.toml dependencies:

scripthookv-rs = "0.3.0"
once_cell = "1.9.0"
winapi = { version = "0.3.9", features = [ "consoleapi", "winuser", "wincon" ] }
async-trait = "0.1.52"

scripthookv-rs-gta

This crate contains a wrapped api for GTA 5 natives. It should be installed together with the scripthookv-rs crate.

Installation

This crate has not been published yet.

Usage

Entrypoint

For your entrypoint you can use the shv_entrypoint macro. This macro generates a DllMain for you.

extern "C" fn script_main() {
  loop {
    // On tick logic

    script_yield();
  }
}

#[shv_entrypoint]
fn entrypoint(module: ModuleHandle) -> ScriptHookV {
  ScriptHookVBuilder::new(module)
    .script(script_main)
    .build()
}

Natives

Natives can be invoked directly with the native_call macro like this:

call_native!(Vehicle, 0xAF35D0D2583051B0, adder_hash, coords, heading, false, false, false);
//           ^^^^^^^  ^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//       Return type         Native hash                                        Parameters

Alternatively you can use my nativedb to generate wrapping similar to a natives.h file.

Road map

  • Wrap all ScriptHookV functions*.
  • Dedicated readmes for all crates.
  • More elegant wrapping for ScriptHookV.
  • Provide elegant API for most natives.
  • Provide a UI crate similar to LemonUI.
  • Automated tests.

* excluding deprecated functions.

Contributing

Pull requests are always welcome. For major changes, please open an issue first to discuss what you would like to change.

Acknowledgements

License

MIT

Dependencies

~5–17MB
~190K SLoC