From aa9e32b59ab9726940f991ab5a53151e47132a96 Mon Sep 17 00:00:00 2001 From: Aaron M Date: Sun, 5 Jan 2020 22:21:12 +1300 Subject: [PATCH] Use ExitProcess over TerminateProcess --- Config/FFBPlugin.ini | 1 + DllMain.cpp | 42 ++++++++++++++---------------- Game Files/AliensExtermination.cpp | 2 +- Game Files/Daytona3.cpp | 2 +- Game Files/InitialD0.cpp | 6 +++++ Game Files/M2Emulator.cpp | 2 +- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Config/FFBPlugin.ini b/Config/FFBPlugin.ini index 6ea1917..41ae281 100644 --- a/Config/FFBPlugin.ini +++ b/Config/FFBPlugin.ini @@ -173,6 +173,7 @@ FeedbackLength=80 PowerMode=0 EnableForceSpringEffect=0 ForceSpringStrength=70 +EscapeKeyExitViaPlugin=0 [InitialD 4] GameId=16 diff --git a/DllMain.cpp b/DllMain.cpp index c8b4aaf..a472052 100644 --- a/DllMain.cpp +++ b/DllMain.cpp @@ -2934,6 +2934,24 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved) hlp.log((char*)processName.c_str()); keepRunning = false; + if (haptic > 0) + { + SDL_HapticStopAll(haptic); + SDL_HapticClose(haptic); // release the haptic device / clean-up. + } + + if (haptic2 > 0) + { + SDL_HapticStopAll(haptic2); + SDL_HapticClose(haptic2); + } + + if (haptic3 > 0) + { + SDL_HapticStopAll(haptic3); + SDL_HapticClose(haptic3); + } + if (gl_hOriginalDll) { FreeLibrary(gl_hOriginalDll); @@ -2964,7 +2982,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved) if (EnableRumble == 1) { SDL_JoystickRumble(GameController, 0, 0, 0); - } + } } if (GameController2) @@ -2974,28 +2992,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved) SDL_JoystickRumble(GameController2, 0, 0, 0); } } - - // this doesn't seem to really work...hmm...if i ALT+F4, then the program quits and haptic is still set. - // try setting GameId to HEAVY (-5 or -6..can't remember) and then force quit. Wheel will stay heavy :/. - if (haptic) - { - SDL_HapticStopEffect(haptic, effects.effect_constant_id); - SDL_HapticStopEffect(haptic, effects.effect_friction_id); - SDL_HapticStopEffect(haptic, effects.effect_leftright_id); - SDL_HapticStopEffect(haptic, effects.effect_sine_id); - SDL_HapticStopEffect(haptic, effects.effect_spring_id); - SDL_HapticStopEffect(haptic, effects.effect_vibration_id); - SDL_HapticStopAll(haptic); - SDL_HapticClose(haptic); // release the haptic device / clean-up. - } - - if (haptic2) - { - SDL_HapticStopEffect(haptic2, effects.effect_sine_id_device2); - SDL_HapticStopAll(haptic2); - SDL_HapticClose(haptic2); - } - break; } diff --git a/Game Files/AliensExtermination.cpp b/Game Files/AliensExtermination.cpp index 95ce3b7..e76968f 100644 --- a/Game Files/AliensExtermination.cpp +++ b/Game Files/AliensExtermination.cpp @@ -62,7 +62,7 @@ void AliensExtermination::FFBLoop(EffectConstants* constants, Helpers* helpers, { if (hWnd > NULL) { - TerminateProcess(GetCurrentProcess(), 0); + ExitProcess(0); } } if (!init) diff --git a/Game Files/Daytona3.cpp b/Game Files/Daytona3.cpp index b3a0038..61ddcf3 100644 --- a/Game Files/Daytona3.cpp +++ b/Game Files/Daytona3.cpp @@ -125,7 +125,7 @@ void Daytona3::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTrigg { //SendMessage(hWnd, WM_CLOSE, NULL, NULL); system("taskkill /f /im InpWrapper.exe"); - TerminateProcess(GetCurrentProcess(), 0); + ExitProcess(0); } } diff --git a/Game Files/InitialD0.cpp b/Game Files/InitialD0.cpp index 7ac0fa1..c2115e7 100644 --- a/Game Files/InitialD0.cpp +++ b/Game Files/InitialD0.cpp @@ -18,9 +18,15 @@ along with FFB Arcade Plugin.If not, see < https://www.gnu.org/licenses/>. static wchar_t* settingsFilename = TEXT(".\\FFBPlugin.ini"); static int EnableForceSpringEffect = GetPrivateProfileInt(TEXT("Settings"), TEXT("EnableForceSpringEffect"), 0, settingsFilename); static int ForceSpringStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("ForceSpringStrength"), 0, settingsFilename); +static int EscapeKeyExitViaPlugin = GetPrivateProfileInt(TEXT("Settings"), TEXT("EscapeKeyExitViaPlugin"), 0, settingsFilename); void InitialD0::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers* triggers) { + if (GetAsyncKeyState((VK_ESCAPE)) && (EscapeKeyExitViaPlugin == 1)) + { + ExitProcess(0); + } + UINT8 ff = helpers->ReadByte(0x168317F, true); UINT8 static oldff = 0; UINT8 newff = ff; diff --git a/Game Files/M2Emulator.cpp b/Game Files/M2Emulator.cpp index d471b9c..bf64b07 100644 --- a/Game Files/M2Emulator.cpp +++ b/Game Files/M2Emulator.cpp @@ -27,7 +27,7 @@ static bool init = false; static bool __stdcall ExitHook(UINT uExitCode) { - TerminateProcess(GetCurrentProcess(), 0); + ExitProcess(0); return 0; }