[ProStreet] Make `WriteSettingsToFile` compatible with a lazy hook
@@ -620,22 +620,15 @@ void Init()
}; injector::MakeInline<DeadzoneHookY>(pattern.get_first(18 + 0), pattern.get_first(18 + 6));
}
- auto GetFolderPathpattern = hook::pattern("50 6A 00 6A 00 68 ? 80 00 00 6A 00");
- if (bWriteSettingsToFile && injector::GetBranchDestination(GetFolderPathpattern.get(0).get<uintptr_t>(14), true).as_int() == 0)
+ if (bWriteSettingsToFile)
{
- auto msgboxID = MessageBox(
- NULL,
- (LPCWSTR)L"WriteSettingsToFile option will not work with your exe version. Use different exe or disable that option.\nDo you want to disable it now?",
- (LPCWSTR)L"NFSProStreet.GenericFix",
- MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON1
- );
-
- if (msgboxID == IDYES)
+ struct LazyHook
{
- iniReader.WriteInteger("MISC", "WriteSettingsToFile", 0);
- bWriteSettingsToFile = false;
- }
- }
+ static void hook()
+ {
+ auto GetFolderPathpattern = hook::pattern("50 6A 00 6A 00 68 ? 80 00 00 6A 00");
+ while (!injector::GetBranchDestination(GetFolderPathpattern.get(0).get<uintptr_t>(14), true).as_int())
+ std::this_thread::sleep_for(std::chrono::seconds(1));
if (!szCustomUserFilesDirectoryInGameDir.empty())
{
@@ -659,8 +652,6 @@ void Init()
}
}
- if (bWriteSettingsToFile)
- {
auto[DesktopResW, DesktopResH] = GetDesktopRes();
char szSettingsSavePath[MAX_PATH];
uintptr_t GetFolderPathCallDest = injector::GetBranchDestination(GetFolderPathpattern.get(0).get<uintptr_t>(14), true).as_int();
@@ -707,6 +698,10 @@ void Init()
RegistryWrapper::AddDefault("g_Refresh", "60");
}
}
+ };
+
+ std::thread(LazyHook::hook).detach();
+ }
if (bDisableMotionBlur)
{
