diff --git a/src/LiveSplit.AutoSplittingRuntime/ASR.cs b/src/LiveSplit.AutoSplittingRuntime/ASR.cs index 1ae81b2..a57ccab 100644 --- a/src/LiveSplit.AutoSplittingRuntime/ASR.cs +++ b/src/LiveSplit.AutoSplittingRuntime/ASR.cs @@ -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; @@ -75,7 +76,8 @@ LogDelegate log pauseGameTime, resumeGameTime, setCustomVariable, - log + log, + getSplitsPath ); if (ptr == IntPtr.Zero) { @@ -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 { @@ -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); diff --git a/src/LiveSplit.AutoSplittingRuntime/ComponentSettings.cs b/src/LiveSplit.AutoSplittingRuntime/ComponentSettings.cs index 75cc216..f36c776 100644 --- a/src/LiveSplit.AutoSplittingRuntime/ComponentSettings.cs +++ b/src/LiveSplit.AutoSplittingRuntime/ComponentSettings.cs @@ -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; @@ -71,6 +72,7 @@ public ComponentSettings(TimerModel model) _ => 0, }; }; + getSplitsPath = () => model.CurrentState.Run?.FilePath ?? ""; getIndex = () => model.CurrentState.CurrentSplitIndex; segmentSplitted = (idx) => { @@ -138,7 +140,8 @@ public void ReloadRuntime(SettingsMap settingsMap) pauseGameTime, resumeGameTime, setCustomVariable, - log + log, + getSplitsPath ); } } diff --git a/src/LiveSplit.AutoSplittingRuntime/x64/asr_capi.dll b/src/LiveSplit.AutoSplittingRuntime/x64/asr_capi.dll index e63052c..652ef3c 100644 Binary files a/src/LiveSplit.AutoSplittingRuntime/x64/asr_capi.dll and b/src/LiveSplit.AutoSplittingRuntime/x64/asr_capi.dll differ diff --git a/src/LiveSplit.AutoSplittingRuntime/x86/asr_capi.dll b/src/LiveSplit.AutoSplittingRuntime/x86/asr_capi.dll index 548b449..eeacac2 100644 Binary files a/src/LiveSplit.AutoSplittingRuntime/x86/asr_capi.dll and b/src/LiveSplit.AutoSplittingRuntime/x86/asr_capi.dll differ diff --git a/src/asr-capi/src/lib.rs b/src/asr-capi/src/lib.rs index 5d619d1..881ad79 100644 --- a/src/asr-capi/src/lib.rs +++ b/src/asr-capi/src/lib.rs @@ -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")] @@ -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 { + 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")] diff --git a/src/asr-capi/src/runtime.rs b/src/asr-capi/src/runtime.rs index 560d105..13e370c 100644 --- a/src/asr-capi/src/runtime.rs +++ b/src/asr-capi/src/runtime.rs @@ -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> { #[cfg(target_pointer_width = "64")] { @@ -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,