diff --git a/Config/FFBPlugin.ini b/Config/FFBPlugin.ini index 67f170f..33a8b77 100644 --- a/Config/FFBPlugin.ini +++ b/Config/FFBPlugin.ini @@ -252,18 +252,21 @@ GameId=64 FeedbackLength=500 EnableDamper=0 DamperStrength=100 +DoubleConstant=0 [Tokyo Cop] GameId=65 FeedbackLength=500 EnableDamper=0 DamperStrength=100 +DoubleConstant=0 [Ring Riders] GameId=66 FeedbackLength=500 EnableDamper=0 DamperStrength=100 +DoubleConstant=0 [Winter X Games SnoCross] GameId=44 diff --git a/Game Files/GaelcoTuningRace.cpp b/Game Files/GaelcoTuningRace.cpp index 5ef1b5f..abe23a7 100644 --- a/Game Files/GaelcoTuningRace.cpp +++ b/Game Files/GaelcoTuningRace.cpp @@ -13,14 +13,17 @@ along with FFB Arcade Plugin.If not, see < https://www.gnu.org/licenses/>. #include #include "GaelcoTuningRace.h" + static EffectTriggers* myTriggers; static EffectConstants* myConstants; static Helpers* myHelpers; + extern int EnableDamper; extern int DamperStrength; static bool init; -static int __stdcall SetMotor(DWORD* a1) +static int(__stdcall* SetMotorOri)(DWORD* a1); +static int __stdcall SetMotorHook(DWORD* a1) { long double v1 = *(float*)&a1; @@ -46,43 +49,17 @@ static int __stdcall SetMotor(DWORD* a1) myTriggers->Rumble(0, percentForce, percentLength); myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); } - return 0; + return SetMotorOri(a1); } -static bool Hook(void* toHook, void* ourFunct, int len) { - if (len < 5) { - return false; - } - - DWORD curProtection; - VirtualProtect(toHook, len, PAGE_EXECUTE_READWRITE, &curProtection); - - memset(toHook, 0x90, len); - - DWORD relativeAddress = ((DWORD)ourFunct - (DWORD)toHook) - 5; - - *(BYTE*)toHook = 0xE9; - *(DWORD*)((DWORD)toHook + 1) = relativeAddress; - - DWORD temp; - VirtualProtect(toHook, len, curProtection, &temp); - - return true; -} - -static DWORD jmpBackAddy; - void GaelcoTuningRace::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers* triggers) { + if (!init) { - int hookLength = 6; - DWORD hookAddress = 0x8188ABC; - if (hookAddress) - { - jmpBackAddy = hookAddress + hookLength; - Hook((void*)hookAddress, SetMotor, hookLength); - init = true; - } + init = true; + MH_Initialize(); + MH_CreateHook((void*)0x8188ABC, SetMotorHook, (void**)&SetMotorOri); + MH_EnableHook(MH_ALL_HOOKS); } if (EnableDamper) diff --git a/Game Files/RingRiders.cpp b/Game Files/RingRiders.cpp index 7b96485..2878354 100644 --- a/Game Files/RingRiders.cpp +++ b/Game Files/RingRiders.cpp @@ -20,7 +20,8 @@ extern int EnableDamper; extern int DamperStrength; static bool init; -static int __stdcall SetMotor(DWORD* a1, float a2) +static int(__stdcall* SetMotorOri)(DWORD* a1, float a2); +static int __stdcall SetMotorHook(DWORD* a1, float a2) { if (a2 > 0) { @@ -44,46 +45,20 @@ static int __stdcall SetMotor(DWORD* a1, float a2) myTriggers->Rumble(0, percentForce, percentLength); myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); } - return 0; + return SetMotorOri(a1, a2); } -static bool Hook(void* toHook, void* ourFunct, int len) { - if (len < 5) { - return false; - } - - DWORD curProtection; - VirtualProtect(toHook, len, PAGE_EXECUTE_READWRITE, &curProtection); - - memset(toHook, 0x90, len); - - DWORD relativeAddress = ((DWORD)ourFunct - (DWORD)toHook) - 5; - - *(BYTE*)toHook = 0xE9; - *(DWORD*)((DWORD)toHook + 1) = relativeAddress; - - DWORD temp; - VirtualProtect(toHook, len, curProtection, &temp); - - return true; -} - -static DWORD jmpBackAddy; - void RingRiders::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers* triggers) { + if (!init) { - int hookLength = 6; - DWORD hookAddress = 0x8107568; - if (hookAddress) - { - jmpBackAddy = hookAddress + hookLength; - Hook((void*)hookAddress, SetMotor, hookLength); - init = true; - } + init = true; + MH_Initialize(); + MH_CreateHook((void*)0x8107568, SetMotorHook, (void**)&SetMotorOri); + MH_EnableHook(MH_ALL_HOOKS); } - if (EnableDamper == 1) + if (EnableDamper) triggers->Damper(DamperStrength / 100.0); myTriggers = triggers; diff --git a/Game Files/TokyoCop.cpp b/Game Files/TokyoCop.cpp index 4ce0630..d667bf3 100644 --- a/Game Files/TokyoCop.cpp +++ b/Game Files/TokyoCop.cpp @@ -16,11 +16,13 @@ along with FFB Arcade Plugin.If not, see < https://www.gnu.org/licenses/>. static EffectTriggers* myTriggers; static EffectConstants* myConstants; static Helpers* myHelpers; + extern int EnableDamper; extern int DamperStrength; static bool init; -static int __stdcall SetMotor(DWORD* a1, float a2) +static int(__stdcall* SetMotorOri)(DWORD* a1, float a2); +static int __stdcall SetMotorHook(DWORD* a1, float a2) { if (a2 > 0) { @@ -44,46 +46,20 @@ static int __stdcall SetMotor(DWORD* a1, float a2) myTriggers->Rumble(0, percentForce, percentLength); myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); } - return 0; + return SetMotorOri(a1, a2); } -static bool Hook(void* toHook, void* ourFunct, int len) { - if (len < 5) { - return false; - } - - DWORD curProtection; - VirtualProtect(toHook, len, PAGE_EXECUTE_READWRITE, &curProtection); - - memset(toHook, 0x90, len); - - DWORD relativeAddress = ((DWORD)ourFunct - (DWORD)toHook) - 5; - - *(BYTE*)toHook = 0xE9; - *(DWORD*)((DWORD)toHook + 1) = relativeAddress; - - DWORD temp; - VirtualProtect(toHook, len, curProtection, &temp); - - return true; -} - -static DWORD jmpBackAddy; - void TokyoCop::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers* triggers) { + if (!init) { - int hookLength = 6; - DWORD hookAddress = 0x80E6FA4; - if (hookAddress) - { - jmpBackAddy = hookAddress + hookLength; - Hook((void*)hookAddress, SetMotor, hookLength); - init = true; - } + init = true; + MH_Initialize(); + MH_CreateHook((void*)0x80E6FA4, SetMotorHook, (void**)&SetMotorOri); + MH_EnableHook(MH_ALL_HOOKS); } - if (EnableDamper == 1) + if (EnableDamper) triggers->Damper(DamperStrength / 100.0); myTriggers = triggers;