diff --git a/SekiroSpeedrunUtil/MemoryThread.cs b/SekiroSpeedrunUtil/MemoryThread.cs index a3a51b2..8b9ed50 100644 --- a/SekiroSpeedrunUtil/MemoryThread.cs +++ b/SekiroSpeedrunUtil/MemoryThread.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Threading; using SekiroSpeedrunUtil.structs; @@ -35,7 +36,6 @@ private void ThreadProc() { _manualResetEvent.WaitOne(); Thread.Sleep((int)_threadPriority); try { - var remoteProc = RemoteProc.Instance(); if(remoteProc == null) continue; diff --git a/SekiroSpeedrunUtil/ui/FormMain.cs b/SekiroSpeedrunUtil/ui/FormMain.cs index c4042ec..88862a7 100644 --- a/SekiroSpeedrunUtil/ui/FormMain.cs +++ b/SekiroSpeedrunUtil/ui/FormMain.cs @@ -92,7 +92,7 @@ private void SetStatus(string status, Color color) { }); } - private void UpdateCtrl(ISynchronizeInvoke obj, MethodInvoker action) { + private static void UpdateCtrl(ISynchronizeInvoke obj, MethodInvoker action) { obj.InvokeIfRequired(action); } diff --git a/SekiroSpeedrunUtil/ui/Main.cs b/SekiroSpeedrunUtil/ui/Main.cs index 8ac5872..59721a6 100644 --- a/SekiroSpeedrunUtil/ui/Main.cs +++ b/SekiroSpeedrunUtil/ui/Main.cs @@ -32,6 +32,14 @@ private void InitLogic() { private void Init() { Diag.WriteLine("Initializing"); SetStatus("Initializing", Color.OrangeRed); + + var remoteProc = RemoteProc.Instance(); + if (remoteProc == null) { + MetroMessageBox.Show(this, "Sekiro should be running but was not found..", "Error", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + InitHotkeys(); foreach (var flag in Defs.Flags.FastReverse()) { @@ -87,13 +95,6 @@ private void Init() { }); LastIdol.Start(); - var remoteProc = RemoteProc.Instance(); - if (remoteProc == null) { - MetroMessageBox.Show(this, "Sekiro should be running but was not found..", "Error", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - var lastIdol = remoteProc.Read(Defs.PointerByName("LastCommutedIdol").GetAddress(remoteProc)); var idol = Defs.IdolById(lastIdol); if (idol == null) { diff --git a/SekiroSpeedrunUtil/ui/MainSaveMan.cs b/SekiroSpeedrunUtil/ui/MainSaveMan.cs index 4f84edc..586fbc0 100644 --- a/SekiroSpeedrunUtil/ui/MainSaveMan.cs +++ b/SekiroSpeedrunUtil/ui/MainSaveMan.cs @@ -96,7 +96,7 @@ private void SaveGame(string name) { private void QuickLoad() { if (_smQuickLoadLastItem == string.Empty || _smQuickLoadLastProfile == string.Empty) return; try { - var fPath = $"{ProfileDir(_smQuickLoadLastProfile)}/{_smQuickLoadLastItem.Replace(" ", "_")}"; + var fPath = $"{ProfileDir(true)}/{_smQuickLoadLastItem.Replace(" ", "_")}"; File.Copy(fPath, $"{_sekiroDir}/S0000.sl2", true); Toast("Quickload Success!", Color.MediumAquamarine, Color.Black); } catch (Exception ex) { @@ -112,7 +112,7 @@ private void QuickLoad() { private void QuickLoadQuick() { if (_smQuickLoadLastQuick == string.Empty || _smQuickLoadLastProfile == string.Empty) return; try { - var fPath = $"{ProfileDir(_smQuickLoadLastProfile)}/{_smQuickLoadLastQuick.Replace(" ", "_")}"; + var fPath = $"{ProfileDir(true)}/{_smQuickLoadLastQuick.Replace(" ", "_")}"; File.Copy(fPath, $"{_sekiroDir}/S0000.sl2", true); Toast("Quickload Success!", Color.MediumAquamarine, Color.Black); } catch (Exception ex) { @@ -190,6 +190,7 @@ private void SmOpenSavesDir_Click(object sender, EventArgs e) { private void SmProfiles_SelectedIndexChanged(object sender, EventArgs e) { try { _profileDir = ProfileDir(); + _smQuickLoadLastProfile = smProfiles.SelectedItem.ToString(); SmListSaves(); } catch (Exception ex) { MetroMessageBox.Show(this, @@ -213,9 +214,9 @@ private string SaveDir() { return $"{appdataPath}/{_saveDir}/saves"; } - private string ProfileDir(string name = null) { - if(name != null) _smQuickLoadLastProfile = smProfiles.SelectedItem.ToString(); - var dir = name == null ? $"{SaveDir()}/{smProfiles.SelectedItem}" : $"{SaveDir()}/{name}"; + private string ProfileDir(bool quick = false) { + var name = quick ? _smQuickLoadLastProfile : smProfiles.SelectedItem; + var dir = $"{SaveDir()}/{name}"; if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); return dir; } @@ -272,13 +273,11 @@ private void SmPseudoReadonlyHandler(object sender, GlobalEventArgs e) { if (b == 0) { if (_smSelfWrite) return; _smSelfWrite = true; - //QuickLoad(); - if (_smQuickLoadLastItem == string.Empty || _smQuickLoadLastProfile == string.Empty) return; try { - var fPath = $"{ProfileDir(_smQuickLoadLastProfile)}/{_smQuickLoadLastItem.Replace(" ", "_")}"; + var fPath = $"{ProfileDir(true)}/{_smQuickLoadLastItem.Replace(" ", "_")}"; File.Copy(fPath, $"{_sekiroDir}/S0000.sl2", true); - Toast("Quickload Success!", Color.MediumAquamarine, Color.Black); + Diag.WriteLine("Pseudo read-only success"); } catch (Exception ex) { MetroMessageBox.Show(this, ex.Message,