Skip to content

Commit

Permalink
additional cutscene frame limiter
Browse files Browse the repository at this point in the history
- fixes #303
  • Loading branch information
ThirteenAG committed Jan 25, 2024
1 parent 8114261 commit e054ba5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/comvars.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export uint32_t* rage__scrEngine__ms_dwNativeTableSize;
export uint32_t** rage__scrEngine__ms_pNatives;
export uintptr_t** rage__scrProgram__ms_pGlobals;
export uint32_t* rage__scrProgram__ms_pGlobalsSize;
export uint32_t* CCutscenes__m_dwCutsceneState;
export void* (__stdcall* getNativeAddress)(uint32_t);
export float* fTimeStep;
export HWND gWnd;
Expand Down Expand Up @@ -102,6 +103,9 @@ public:

pattern = hook::pattern("BE ? ? ? ? 8D 44 24 0C 50 8D 46 10 50");
pCGameConfigReader__ms_imgFiles = *pattern.get_first<decltype(pCGameConfigReader__ms_imgFiles)>(1);

pattern = hook::pattern("A1 ? ? ? ? 83 F8 08 74 05");
CCutscenes__m_dwCutsceneState = *pattern.get_first<uint32_t*>(1);
};
}
} Common;
11 changes: 11 additions & 0 deletions source/framelimit.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ FrameLimiter FpsLimiter;
FrameLimiter CutsceneFpsLimiter;
FrameLimiter ScriptCutsceneFpsLimiter;
FrameLimiter LoadingFpsLimiter;
FrameLimiter LoadingFpsLimiter2;
bool(*CCutscenes__hasCutsceneFinished)();
bool(*CCamera__isWidescreenBordersActive)();
bool bUnlockFramerateDuringLoadscreens = true;
Expand All @@ -147,10 +148,19 @@ void __cdecl sub_855640()
if (CCamera__isWidescreenBordersActive())
{
if (CCutscenes__hasCutsceneFinished())
{
if (fCutsceneFpsLimit)
CutsceneFpsLimiter.Sync();
else if (fScriptCutsceneFpsLimit)
ScriptCutsceneFpsLimiter.Sync();

// To avoid more softlocks with high fps
if (!fCutsceneFpsLimit && CCutscenes__m_dwCutsceneState)
{
if (*CCutscenes__m_dwCutsceneState == 9 || *CCutscenes__m_dwCutsceneState == 10)
LoadingFpsLimiter2.Sync();
}
}
}
}

Expand Down Expand Up @@ -193,6 +203,7 @@ public:
CutsceneFpsLimiter.Init(mode, fCutsceneFpsLimit);
ScriptCutsceneFpsLimiter.Init(mode, fScriptCutsceneFpsLimit);
LoadingFpsLimiter.Init(mode, std::clamp(fLoadingFpsLimit, 30.0f, FLT_MAX));
LoadingFpsLimiter2.Init(mode, 240.0f);

auto pattern = find_pattern("E8 ? ? ? ? 84 C0 75 89", "E8 ? ? ? ? 84 C0 75 15 38 05");
CCutscenes__hasCutsceneFinished = (bool(*)()) injector::GetBranchDestination(pattern.get_first(0)).get();
Expand Down

0 comments on commit e054ba5

Please sign in to comment.