livesplit-auto-splitting
livesplit-auto-splitting is a library that provides a runtime for running
auto splitters that can control a speedrun timer. These auto splitters are
provided as WebAssembly modules.
Requirements for the Auto Splitters
The auto splitters must provide an update
function with the following
signature:
#[no_mangle]
pub extern "C" fn update() {}
This function is called periodically by the runtime at the configured tick
rate. The tick rate is 120 Hz by default, but can be changed by the auto
splitter.
In addition the WebAssembly module is expected to export a memory called
memory
.
API exposed to the Auto Splitters
The following functions are provided to the auto splitters in the module
env
:
#[repr(transparent)]
pub struct Address(pub u64);
#[repr(transparent)]
pub struct NonZeroAddress(pub NonZeroU64);
#[repr(transparent)]
pub struct ProcessId(NonZeroU64);
#[repr(transparent)]
pub struct TimerState(u32);
impl TimerState {
pub const NOT_RUNNING: Self = Self(0);
pub const RUNNING: Self = Self(1);
pub const PAUSED: Self = Self(2);
pub const ENDED: Self = Self(3);
}
extern "C" {
pub fn timer_get_state() -> TimerState;
pub fn timer_start();
pub fn timer_split();
pub fn timer_reset();
pub fn timer_set_variable(
key_ptr: *const u8,
key_len: usize,
value_ptr: *const u8,
value_len: usize,
);
pub fn timer_set_game_time(secs: i64, nanos: i32);
pub fn timer_pause_game_time();
pub fn timer_resume_game_time();
pub fn process_attach(name_ptr: *const u8, name_len: usize) -> Option<ProcessId>;
pub fn process_detach(process: ProcessId);
pub fn process_is_open(process: ProcessId) -> bool;
pub fn process_read(
process: ProcessId,
address: Address,
buf_ptr: *mut u8,
buf_len: usize,
) -> bool;
pub fn process_get_module_address(
process: ProcessId,
name_ptr: *const u8,
name_len: usize,
) -> Option<NonZeroAddress>;
pub fn process_get_module_size(
process: ProcessId,
name_ptr: *const u8,
name_len: usize,
) -> Option<NonZeroU64>;
pub fn runtime_set_tick_rate(ticks_per_second: f64);
pub fn runtime_print_message(text_ptr: *const u8, text_len: usize);
pub fn user_settings_add_bool(
key_ptr: *const u8,
key_len: usize,
description_ptr: *const u8,
description_len: usize,
default_value: bool,
) -> bool;
}
On top of the runtime's API, there's also unstable WASI
support via the
unstable
feature.