@@ -26,13 +26,13 @@ class DumpCheckpoint : public IOptionalCheat {
2626 ScopedCallback<ActionEvent> mDumpCheckpointEventCallback ;
2727
2828 // injected services
29- std::weak_ptr<IMCCStateHook> mccStateHook ;
30- std::weak_ptr<IMessagesGUI> messagesGUI ;
31- std::weak_ptr <RuntimeExceptionHandler> runtimeExceptions;
32- std::weak_ptr<IGetMCCVersion> getMCCVer ;
33- std::weak_ptr<ISharedMemory> sharedMem ;
34- std::weak_ptr<IModalDialogRenderer> modalDialogs ;
35- std::weak_ptr<SettingsStateAndEvents> settings ;
29+ std::weak_ptr<IMCCStateHook> mccStateHookWeak ;
30+ std::weak_ptr<IMessagesGUI> messagesGUIWeak ;
31+ std::shared_ptr <RuntimeExceptionHandler> runtimeExceptions;
32+ std::weak_ptr<IGetMCCVersion> getMCCVerWeak ;
33+ std::weak_ptr<ISharedMemory> sharedMemWeak ;
34+ std::weak_ptr<IModalDialogRenderer> modalDialogsWeak ;
35+ std::weak_ptr<SettingsStateAndEvents> settingsWeak ;
3636
3737
3838 // data
@@ -46,14 +46,24 @@ class DumpCheckpoint : public IOptionalCheat {
4646
4747 // primary event callback
4848 void onDump () {
49- if (!mccStateHook. lock ()-> isGameCurrentlyPlaying ( mImplGame )) return ;
49+
5050
5151 try
5252 {
53+ lockOrThrow (mccStateHookWeak, mccStateHook);
54+ lockOrThrow (messagesGUIWeak, messagesGUI);
55+ lockOrThrow (getMCCVerWeak, getMCCVer);
56+ lockOrThrow (sharedMemWeak, sharedMem);
57+ lockOrThrow (modalDialogsWeak, modalDialogs);
58+ lockOrThrow (settingsWeak, settings);
59+
60+
61+ if (!mccStateHook->isGameCurrentlyPlaying (mImplGame )) return ;
62+ PLOG_DEBUG << " onDump called " << mImplGame .toString ();
5363 // Automatically force checkpoint beforehand if user wants that
54- if (settings. lock () ->dumpCheckpointForcesSave ->GetValue ())
64+ if (settings->dumpCheckpointForcesSave ->GetValue ())
5565 {
56- settings. lock () ->forceCheckpointEvent ->operator ()();
66+ settings->forceCheckpointEvent ->operator ()();
5767 Sleep (10 );
5868 }
5969
@@ -65,10 +75,10 @@ class DumpCheckpoint : public IOptionalCheat {
6575 t.wYear , t.wMonth , t.wDay , t.wHour , t.wMinute , t.wSecond );
6676
6777 // ask the user what they want to call it, if they want that. Otherwise we use the default checkpoint name
68- if (settings. lock () ->autonameCheckpoints ->GetValue () == false )
78+ if (settings->autonameCheckpoints ->GetValue () == false )
6979 {
7080 PLOG_DEBUG << " calling blocking func showSaveDumpNameDialog" ;
71- auto modalReturn = modalDialogs. lock () ->showSaveDumpNameDialog (" Name dumped checkpoint" , checkpointName); // this is a blocking call
81+ auto modalReturn = modalDialogs->showSaveDumpNameDialog (" Name dumped checkpoint" , checkpointName); // this is a blocking call
7282 PLOG_DEBUG << " showSaveDumpNameDialog returned! " ;
7383
7484 if (!std::get<bool >(modalReturn)) { PLOG_DEBUG << " User cancelled dump" ; return ; } // user cancelled dump
@@ -77,7 +87,7 @@ class DumpCheckpoint : public IOptionalCheat {
7787
7888
7989 int64_t checkpointLength = *mCheckpointLength .get ();
80- auto currentSaveFolder = sharedMem. lock () ->getDumpInfo (mImplGame );
90+ auto currentSaveFolder = sharedMem->getDumpInfo (mImplGame );
8191 PLOG_DEBUG << " Attempting checkpoint dump for game: " << mImplGame .toString ();;
8292
8393 auto dumpPath = currentSaveFolder.selectedFolderPath + " \\ " + checkpointName + " .bin" ;
@@ -108,7 +118,7 @@ class DumpCheckpoint : public IOptionalCheat {
108118 if (err) throw HCMRuntimeException (std::format (" error storing checkpointData from memory! code: {}" , err));
109119
110120 // add version information to last 10 bytes of file
111- std::string versionString = getMCCVer. lock () ->getMCCVersionAsString ().data ();
121+ std::string versionString = getMCCVer->getMCCVersionAsString ().data ();
112122 if (versionString.size () != 10 ) throw HCMRuntimeException (std::format (" Version string was the wrong size somehow?! Expected: 10, Actual: {}" , versionString.size ()));
113123 std::copy (std::begin (versionString), std::end (versionString), std::end (checkpointData) - 10 );
114124
@@ -128,14 +138,14 @@ class DumpCheckpoint : public IOptionalCheat {
128138 throw HCMRuntimeException (std::format (" Failed to write checkpoint file to location {}: error: {}" , dumpPath, e.what ()));
129139 }
130140
131- messagesGUI. lock () ->addMessage (std::format (" Dumped checkpoint: {}.bin to {}" , checkpointName, currentSaveFolder.selectedFolderName ));
141+ messagesGUI->addMessage (std::format (" Dumped checkpoint: {}.bin to {}" , checkpointName, currentSaveFolder.selectedFolderName ));
132142
133143 PLOG_INFO << std::format (" successfully dumped checkpoint from 0x{:X} to path: {}" , (uint64_t )checkpointLoc, dumpPath);
134144
135145 }
136146 catch (HCMRuntimeException ex)
137147 {
138- runtimeExceptions. lock () ->handleMessage (ex);
148+ runtimeExceptions->handleMessage (ex);
139149 }
140150 }
141151
@@ -144,13 +154,13 @@ class DumpCheckpoint : public IOptionalCheat {
144154 DumpCheckpoint (GameState game, IDIContainer& dicon)
145155 : mImplGame (game),
146156 mDumpCheckpointEventCallback (dicon.Resolve<SettingsStateAndEvents>().lock()->dumpCheckpointEvent, [this]() { onDump (); }),
147- getMCCVer (dicon.Resolve<IGetMCCVersion>()),
148- mccStateHook (dicon.Resolve<IMCCStateHook>()),
149- sharedMem (dicon.Resolve<ISharedMemory>()),
157+ getMCCVerWeak (dicon.Resolve<IGetMCCVersion>()),
158+ mccStateHookWeak (dicon.Resolve<IMCCStateHook>()),
159+ sharedMemWeak (dicon.Resolve<ISharedMemory>()),
150160 runtimeExceptions(dicon.Resolve<RuntimeExceptionHandler>()),
151- messagesGUI (dicon.Resolve<IMessagesGUI>()),
152- modalDialogs (dicon.Resolve<IModalDialogRenderer>()),
153- settings (dicon.Resolve<SettingsStateAndEvents>())
161+ messagesGUIWeak (dicon.Resolve<IMessagesGUI>()),
162+ modalDialogsWeak (dicon.Resolve<IModalDialogRenderer>()),
163+ settingsWeak (dicon.Resolve<SettingsStateAndEvents>())
154164 {
155165 auto ptr = dicon.Resolve <PointerManager>().lock ();
156166 mInjectRequirements = ptr->getData <std::shared_ptr<InjectRequirements>>(" injectRequirements" , game);
0 commit comments