Skip to content

Commit

Permalink
Framerate: increase reflection update rate based on FramerateLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
emoose committed Sep 21, 2024
1 parent 276a5cb commit 30267f3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/hooks_framerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ class ReplaceGameUpdateLoop : public Hook

do
{
if (Settings::FramerateFastLoad == 3)
Game::FileLoad_Ctrl();

QueryPerformanceCounter(&counter);
timeCurrent = double(counter.QuadPart) / FramelimiterFrequency;
timeElapsed = timeCurrent - FramelimiterPrevCounter;

if (Settings::FramerateFastLoad == 3)
Game::FileLoad_Ctrl();

if (Settings::FramerateLimitMode == 0) // "efficient" mode
{
if (FramelimiterTargetFrametime + FramelimiterDeviation <= timeElapsed)
Expand Down Expand Up @@ -304,6 +304,19 @@ class ReplaceGameUpdateLoop : public Hook
EventDisplay_midhook2 = safetyhook::create_mid(Module::exe_ptr(EventDisplay_HookAddr2), EventDisplay_dest);
DispPlCar_midhook = safetyhook::create_mid(Module::exe_ptr(DispPlCar_HookAddr), EventDisplay_dest);
}

// Increase reflection update rate, default is 3 (30fps)
// Set it to framerate limit div 10 (add 9 to make it round up to nearest 10)
int numUpdates = (Settings::FramerateLimit + 9) / 10;
if (numUpdates > 3)
{
constexpr int Envmap_RenderToCubeMap_PatchAddr = 0x1447E;
Memory::VP::Nop(Module::exe_ptr(Envmap_RenderToCubeMap_PatchAddr), 2);

constexpr int Envmap_RenderToCubeMap_PatchAddr2 = 0x14480 + 1;
Memory::VP::Patch(Module::exe_ptr(Envmap_RenderToCubeMap_PatchAddr2), numUpdates);
}

return !!dest_hook;
}

Expand All @@ -313,7 +326,6 @@ ReplaceGameUpdateLoop ReplaceGameUpdateLoop::instance;

class FullscreenRefreshRate : public Hook
{
const static int PatchAddr = 0xE9B9;

public:
std::string_view description() override
Expand All @@ -328,8 +340,8 @@ class FullscreenRefreshRate : public Hook

bool apply() override
{
auto* patch_addr = Module::exe_ptr<uint8_t>(PatchAddr);
Memory::VP::Patch(patch_addr, Settings::FramerateLimit);
constexpr int PatchAddr = 0xE9B9;
Memory::VP::Patch(Module::exe_ptr<uint8_t>(PatchAddr), Settings::FramerateLimit);

return true;
}
Expand Down

0 comments on commit 30267f3

Please sign in to comment.