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
11 changes: 8 additions & 3 deletions src/LiveSplit.AutoSplittingRuntime/ASR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public Runtime(
Action pauseGameTime,
Action resumeGameTime,
SetCustomVariableDelegate setCustomVariable,
LogDelegate log
LogDelegate log,
GetSplitsPathDelegate getSplitsPath
) : base(IntPtr.Zero)
{
IntPtr settingsMapPtr = settingsMap?.ptr ?? IntPtr.Zero;
Expand All @@ -75,7 +76,8 @@ LogDelegate log
pauseGameTime,
resumeGameTime,
setCustomVariable,
log
log,
getSplitsPath
);
if (ptr == IntPtr.Zero)
{
Expand Down Expand Up @@ -715,6 +717,8 @@ internal Widgets(IntPtr ptr) : base(ptr) { }
public delegate void SetGameTimeDelegate(long gameTime);
public delegate void SetCustomVariableDelegate(IntPtr namePtr, UIntPtr nameLen, IntPtr valuePtr, UIntPtr valueLen);
public delegate void LogDelegate(IntPtr messagePtr, UIntPtr messageLen);
[return: MarshalAs(UnmanagedType.LPUTF8Str)]
public delegate string GetSplitsPathDelegate();

public static class ASRNative
{
Expand All @@ -734,7 +738,8 @@ public static extern IntPtr Runtime_new(
Action pause_game_time,
Action resume_game_time,
SetCustomVariableDelegate set_custom_variable,
LogDelegate log
LogDelegate log,
GetSplitsPathDelegate getSplitsPath
);
[DllImport("asr_capi", CallingConvention = CallingConvention.Cdecl)]
public static extern void Runtime_drop(IntPtr self);
Expand Down
5 changes: 4 additions & 1 deletion src/LiveSplit.AutoSplittingRuntime/ComponentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public string ScriptPath
};

private readonly StateDelegate getState;
private readonly GetSplitsPathDelegate getSplitsPath;
private readonly IndexDelegate getIndex;
private readonly SegmentSplittedDelegate segmentSplitted;
private readonly Action start;
Expand Down Expand Up @@ -71,6 +72,7 @@ public ComponentSettings(TimerModel model)
_ => 0,
};
};
getSplitsPath = () => model.CurrentState.Run?.FilePath ?? "";
getIndex = () => model.CurrentState.CurrentSplitIndex;
segmentSplitted = (idx) =>
{
Expand Down Expand Up @@ -138,7 +140,8 @@ public void ReloadRuntime(SettingsMap settingsMap)
pauseGameTime,
resumeGameTime,
setCustomVariable,
log
log,
getSplitsPath
);
}
}
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.
14 changes: 14 additions & 0 deletions src/asr-capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct CTimer {
resume_game_time: unsafe extern "C" fn(),
set_custom_variable: unsafe extern "C" fn(*const u8, usize, *const u8, usize),
log: unsafe extern "C" fn(*const u8, usize),
get_splits_path: unsafe extern "C" fn() -> *const u8,
}

#[cfg(target_pointer_width = "64")]
Expand Down Expand Up @@ -141,6 +142,19 @@ impl Timer for CTimer {
fn log_runtime(&mut self, message: fmt::Arguments<'_>, _: LogLevel) {
log(self.log, message);
}

fn splits_path(&self) -> Option<std::path::PathBuf> {
let ptr = unsafe { (self.get_splits_path)() };
if ptr.is_null() {
return None;
}
let s = unsafe { str(ptr) };
if s.is_empty() {
None
} else {
Some(std::path::PathBuf::from(s))
}
}
}

#[cfg(target_pointer_width = "64")]
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 @@ -37,6 +37,7 @@ pub unsafe extern "C" fn Runtime_new(
_resume_game_time: unsafe extern "C" fn(),
_set_custom_variable: unsafe extern "C" fn(*const u8, usize, *const u8, usize),
_log: unsafe extern "C" fn(*const u8, usize),
_get_splits_path: unsafe extern "C" fn() -> *const u8,
) -> Option<Box<Runtime>> {
#[cfg(target_pointer_width = "64")]
{
Expand Down Expand Up @@ -77,6 +78,7 @@ pub unsafe extern "C" fn Runtime_new(
resume_game_time: _resume_game_time,
set_custom_variable: _set_custom_variable,
log: _log,
get_splits_path: _get_splits_path,
},
_settings_map.map(|settings_map| *settings_map),
None,
Expand Down