Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/LiveSplit.AutoSplittingRuntime/ASR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public Runtime(
SetGameTimeDelegate setGameTime,
Action pauseGameTime,
Action resumeGameTime,
SetTimingMethodDelegate setTimingMethod,
SetCustomVariableDelegate setCustomVariable,
LogDelegate log
) : base(IntPtr.Zero)
Expand All @@ -74,6 +75,7 @@ LogDelegate log
setGameTime,
pauseGameTime,
resumeGameTime,
setTimingMethod,
setCustomVariable,
log
);
Expand Down Expand Up @@ -713,6 +715,7 @@ internal Widgets(IntPtr ptr) : base(ptr) { }
public delegate int IndexDelegate();
public delegate int SegmentSplittedDelegate(int idx);
public delegate void SetGameTimeDelegate(long gameTime);
public delegate void SetTimingMethodDelegate(uint method);
public delegate void SetCustomVariableDelegate(IntPtr namePtr, UIntPtr nameLen, IntPtr valuePtr, UIntPtr valueLen);
public delegate void LogDelegate(IntPtr messagePtr, UIntPtr messageLen);

Expand All @@ -733,6 +736,7 @@ public static extern IntPtr Runtime_new(
SetGameTimeDelegate set_game_time,
Action pause_game_time,
Action resume_game_time,
SetTimingMethodDelegate set_timing_method,
SetCustomVariableDelegate set_custom_variable,
LogDelegate log
);
Expand Down
11 changes: 11 additions & 0 deletions src/LiveSplit.AutoSplittingRuntime/ComponentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public string ScriptPath
private readonly SetGameTimeDelegate setGameTime;
private readonly Action pauseGameTime;
private readonly Action resumeGameTime;
private readonly SetTimingMethodDelegate setTimingMethod;
private readonly SetCustomVariableDelegate setCustomVariable;

public ComponentSettings(TimerModel model)
Expand Down Expand Up @@ -89,6 +90,15 @@ public ComponentSettings(TimerModel model)
setGameTime = (ticks) => model.CurrentState.SetGameTime(new TimeSpan(ticks));
pauseGameTime = () => model.CurrentState.IsGameTimePaused = true;
resumeGameTime = () => model.CurrentState.IsGameTimePaused = false;
setTimingMethod = (method) =>
{
model.CurrentState.CurrentTimingMethod = method switch
{
0 => TimingMethod.RealTime,
1 => TimingMethod.GameTime,
_ => model.CurrentState.CurrentTimingMethod,
};
};
setCustomVariable = (namePtr, nameLen, valuePtr, valueLen) =>
{
string name = ASRString.FromPtrLen(namePtr, nameLen);
Expand Down Expand Up @@ -137,6 +147,7 @@ public void ReloadRuntime(SettingsMap settingsMap)
setGameTime,
pauseGameTime,
resumeGameTime,
setTimingMethod,
setCustomVariable,
log
);
Expand Down
Binary file modified src/LiveSplit.AutoSplittingRuntime/x64/asr_capi.dll
Binary file not shown.
Binary file modified src/LiveSplit.AutoSplittingRuntime/x86/asr_capi.dll
Binary file not shown.
11 changes: 10 additions & 1 deletion src/asr-capi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(target_pointer_width = "64")]
use {
livesplit_auto_splitting::{time, wasi_path, LogLevel, Timer, TimerState},
livesplit_auto_splitting::{time, wasi_path, LogLevel, Timer, TimerState, TimingMethod},
std::{cell::RefCell, ffi::CStr, fmt, path::Path},
};

Expand Down Expand Up @@ -58,6 +58,7 @@ pub struct CTimer {
set_game_time: unsafe extern "C" fn(i64),
pause_game_time: unsafe extern "C" fn(),
resume_game_time: unsafe extern "C" fn(),
set_timing_method: unsafe extern "C" fn(u32),
set_custom_variable: unsafe extern "C" fn(*const u8, usize, *const u8, usize),
log: unsafe extern "C" fn(*const u8, usize),
}
Expand Down Expand Up @@ -128,6 +129,14 @@ impl Timer for CTimer {
unsafe { (self.resume_game_time)() }
}

fn set_timing_method(&mut self, method: TimingMethod) {
let v = match method {
TimingMethod::RealTime => 0u32,
TimingMethod::GameTime => 1u32,
};
unsafe { (self.set_timing_method)(v) }
}

fn set_variable(&mut self, name: &str, value: &str) {
unsafe {
(self.set_custom_variable)(name.as_ptr(), name.len(), value.as_ptr(), value.len())
Expand Down
2 changes: 2 additions & 0 deletions src/asr-capi/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub unsafe extern "C" fn Runtime_new(
_set_game_time: unsafe extern "C" fn(i64),
_pause_game_time: unsafe extern "C" fn(),
_resume_game_time: unsafe extern "C" fn(),
_set_timing_method: unsafe extern "C" fn(u32),
_set_custom_variable: unsafe extern "C" fn(*const u8, usize, *const u8, usize),
_log: unsafe extern "C" fn(*const u8, usize),
) -> Option<Box<Runtime>> {
Expand Down Expand Up @@ -75,6 +76,7 @@ pub unsafe extern "C" fn Runtime_new(
set_game_time: _set_game_time,
pause_game_time: _pause_game_time,
resume_game_time: _resume_game_time,
set_timing_method: _set_timing_method,
set_custom_variable: _set_custom_variable,
log: _log,
},
Expand Down