diff --git a/mc2hook/mc2hook/handlers/BurnoutHandler.cpp b/mc2hook/mc2hook/handlers/BurnoutHandler.cpp new file mode 100644 index 0000000..fd086c0 --- /dev/null +++ b/mc2hook/mc2hook/handlers/BurnoutHandler.cpp @@ -0,0 +1,48 @@ +#include "BurnoutHandler.h" +#include + +static float burnoutIncreaseSpeed = 0.0f; +static float burnoutDecreaseSpeed = 0.0f; +static float burnoutDamageAmount = 0.0f; + +static float burnoutIncreaseSpeedCached = 0.0f; +static float burnoutDecreaseSpeedCached = 0.0f; +static float burnoutDamageAmountCached = 0.0f; + +static float physicsFixesBaselineFPS = 0.0f; + +static bool vehCarSimValuesCached = false; + +void BurnoutHandler::vehCarSimUpdate() +{ + hook::Thunk<0x4D3290>::Call(this); // call original + + if (vehCarSimValuesCached == false) + { + burnoutIncreaseSpeedCached = *getPtr(this, 0x190); + burnoutDecreaseSpeedCached = *getPtr(this, 0x194); + burnoutDamageAmountCached = *getPtr(this, 0x198); + vehCarSimValuesCached = true; + } + + burnoutIncreaseSpeed = burnoutIncreaseSpeedCached * datTimeManager::GetSeconds() * physicsFixesBaselineFPS; + burnoutDecreaseSpeed = burnoutDecreaseSpeedCached * datTimeManager::GetSeconds() * physicsFixesBaselineFPS; + burnoutDamageAmount = burnoutDamageAmountCached * datTimeManager::GetSeconds() * physicsFixesBaselineFPS; + + *getPtr(this, 0x190) = burnoutIncreaseSpeed; + *getPtr(this, 0x194) = burnoutDecreaseSpeed; + *getPtr(this, 0x198) = burnoutDamageAmount; +} + +void BurnoutHandler::Install() +{ + physicsFixesBaselineFPS = HookConfig::GetFloat("Physics", "PhysicsFixesBaselineFPS", 30.0f); + + // Cap physics at 30fps as a lowest possible value + if (physicsFixesBaselineFPS < 30.0f) + { + physicsFixesBaselineFPS = 30.0f; + } + + InstallVTableHook("vehCarSim Some Update", &vehCarSimUpdate, { 0x644A6C }); +} diff --git a/mc2hook/mc2hook/handlers/BurnoutHandler.h b/mc2hook/mc2hook/handlers/BurnoutHandler.h new file mode 100644 index 0000000..7180c6f --- /dev/null +++ b/mc2hook/mc2hook/handlers/BurnoutHandler.h @@ -0,0 +1,9 @@ +#pragma once +#include + +class BurnoutHandler +{ +public: + void vehCarSimUpdate(); + static void Install(); +}; diff --git a/mc2hook/mc2hook/handlers/handlers.h b/mc2hook/mc2hook/handlers/handlers.h index ea7a661..200584f 100644 --- a/mc2hook/mc2hook/handlers/handlers.h +++ b/mc2hook/mc2hook/handlers/handlers.h @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -35,6 +36,7 @@ static void InstallHandlersPostEngineInit() InstallHandler("Path Handler"); InstallHandler("Panel Handler (Keyboard input test really)"); InstallHandler("Transmission Handler"); + InstallHandler("Burnout Handler"); } // Installed at game launch diff --git a/mc2hook/mc2hook/mc2hook.vcxproj b/mc2hook/mc2hook/mc2hook.vcxproj index 056702b..25f2cfd 100644 --- a/mc2hook/mc2hook/mc2hook.vcxproj +++ b/mc2hook/mc2hook/mc2hook.vcxproj @@ -188,6 +188,7 @@ + @@ -241,6 +242,7 @@ + diff --git a/mc2hook/mc2hook/mc2hook.vcxproj.filters b/mc2hook/mc2hook/mc2hook.vcxproj.filters index 027b650..b802e41 100644 --- a/mc2hook/mc2hook/mc2hook.vcxproj.filters +++ b/mc2hook/mc2hook/mc2hook.vcxproj.filters @@ -219,6 +219,9 @@ Header Files + + Header Files + @@ -341,5 +344,8 @@ Source Files + + Source Files + \ No newline at end of file