Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Jan 11, 2024
1 parent a88aacc commit b711c02
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 15 deletions.
2 changes: 2 additions & 0 deletions data/plugins/GTAIV.EFLC.FusionFix.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ FrameLimitType = 2 // 1: realtime (thread-lock) | 2
FpsLimit = 0 // used when FPS Limit menu toggle is set to ON
CutsceneFpsLimit = 0
ScriptCutsceneFovLimit = 30
LoadingFpsLimit = 30 // used to avoid game freeze on loading (e.g. Off Route mission)
UnlockFramerateDuringLoadscreens = 0

[MISC]
DefaultCameraAngleInTLAD = 0
Expand Down
7 changes: 0 additions & 7 deletions source/fixes.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,6 @@ public:
injector::MakeNOP(pattern.get_first(0), 16, true);
}

// Off Route infinite loading
{
auto pattern = hook::pattern("68 ? ? ? ? FF B6 ? ? ? ? E8 ? ? ? ? 83 C4 08 84 C0 74 E2");
if (!pattern.empty())
injector::WriteMemory(pattern.get_first(1), 0xFFFFFFFF, true);
}

// Fix for light coronas being rendered through objects in water reflections.
{
static auto bCoronaShader = false;
Expand Down
29 changes: 28 additions & 1 deletion source/framelimit.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ float fFpsLimit;
float fCutsceneFpsLimit;
float fScriptCutsceneFpsLimit;
float fScriptCutsceneFovLimit;
float fLoadingFpsLimit;

class FrameLimiter
{
Expand Down Expand Up @@ -127,13 +128,15 @@ bool __cdecl sub_411F50(uint32_t* a1, uint32_t* a2)
FrameLimiter FpsLimiter;
FrameLimiter CutsceneFpsLimiter;
FrameLimiter ScriptCutsceneFpsLimiter;
FrameLimiter LoadingFpsLimiter;
bool(*CCutscenes__hasCutsceneFinished)();
bool(*CCamera__isWidescreenBordersActive)();
bool bUnlockFramerateDuringLoadscreens = true;
void __cdecl sub_855640()
{
static auto preset = FusionFixSettings.GetRef("PREF_FPS_LIMIT_PRESET");

if (bLoadscreenShown && !*bLoadscreenShown && !bLoadingShown)
if ((bLoadscreenShown && !*bLoadscreenShown && !bLoadingShown) || !bUnlockFramerateDuringLoadscreens)
{
if (preset && *preset >= FusionFixSettings.FpsCaps.eCustom) {
if (fFpsLimit > 0.0f || (*preset > FusionFixSettings.FpsCaps.eCustom && *preset < int32_t(FusionFixSettings.FpsCaps.data.size())))
Expand All @@ -151,6 +154,16 @@ void __cdecl sub_855640()
}
}

bool __cdecl sub_403CD0(HANDLE hHandle, DWORD dwMilliseconds)
{
if (CMenuManager__m_MenuActive)
{
if (!*CMenuManager__m_MenuActive)
LoadingFpsLimiter.Sync();
}
return hHandle && WaitForSingleObject(hHandle, dwMilliseconds) == WAIT_OBJECT_0;
}

class Framelimit
{
public:
Expand All @@ -166,6 +179,8 @@ public:
fCutsceneFpsLimit = static_cast<float>(iniReader.ReadInteger("FRAMELIMIT", "CutsceneFpsLimit", 0));
fScriptCutsceneFpsLimit = static_cast<float>(iniReader.ReadInteger("FRAMELIMIT", "ScriptCutsceneFpsLimit", 0));
fScriptCutsceneFovLimit = static_cast<float>(iniReader.ReadInteger("FRAMELIMIT", "ScriptCutsceneFovLimit", 0));
fLoadingFpsLimit = static_cast<float>(iniReader.ReadInteger("FRAMELIMIT", "LoadingFpsLimit", 30));
bUnlockFramerateDuringLoadscreens = iniReader.ReadInteger("FRAMELIMIT", "UnlockFramerateDuringLoadscreens", 0) != 0;

//if (fFpsLimit || fCutsceneFpsLimit || fScriptCutsceneFpsLimit)
{
Expand All @@ -180,6 +195,7 @@ public:
FpsLimiter.Init(mode, fFpsLimit);
CutsceneFpsLimiter.Init(mode, fCutsceneFpsLimit);
ScriptCutsceneFpsLimiter.Init(mode, fScriptCutsceneFpsLimit);
LoadingFpsLimiter.Init(mode, std::clamp(fLoadingFpsLimit, 30.0f, FLT_MAX));

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 Expand Up @@ -224,6 +240,17 @@ public:
}
}; injector::MakeInline<SetFOVHook>(pattern.get_first(0), pattern.get_first(6));
}

// Off Route infinite loading
{
auto pattern = hook::pattern("E8 ? ? ? ? 83 C4 08 84 C0 74 E2");
if (!pattern.empty())
injector::MakeCALL(pattern.get_first(), sub_403CD0, true);

pattern = hook::pattern("E8 ? ? ? ? 83 C4 0C 84 C0 75 25");
if (!pattern.empty())
injector::MakeCALL(pattern.get_first(), sub_403CD0, true);
}
};

FusionFix::onShutdownEvent() += []()
Expand Down
37 changes: 37 additions & 0 deletions source/frameratevigilante.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,43 @@ public:
}
}; injector::MakeInline<FramerateVigilanteHook1>(pattern.get_first(0), pattern.get_first(6));
}

pattern = hook::pattern("F3 0F 10 05 ? ? ? ? F3 0F 58 C1 F3 0F 11 05 ? ? ? ? EB 36");
static auto f1032790 = *pattern.get_first<float*>(4);
if (!pattern.empty())
{
struct LoadingTextSpeed
{
void operator()(SafetyHookContext& regs)
{
regs.xmm0.f32[0] = (*f1032790) / 10.0f;
}
}; injector::MakeInline2<LoadingTextSpeed>(pattern.get_first(0), pattern.get_first(8));
}

pattern = hook::pattern("F3 0F 59 05 ? ? ? ? F3 0F 59 05 ? ? ? ? F3 0F 59 05 ? ? ? ? F3 0F 58 05 ? ? ? ? F3 0F 11 05");
if (!pattern.empty())
{
struct LoadingTextSpeed2
{
void operator()(SafetyHookContext& regs)
{
regs.xmm0.f32[0] *= (1000.0f) / 10.0f;
}
}; injector::MakeInline2<LoadingTextSpeed2>(pattern.get_first(0), pattern.get_first(8));
}

pattern = hook::pattern("F3 0F 58 0D ? ? ? ? 0F 5B C0 F3 0F 11 0D");
if (!pattern.empty())
{
struct LoadingTextSparks
{
void operator()(SafetyHookContext& regs)
{
regs.xmm1.f32[0] += (0.085f) / 10.0f;
}
}; injector::MakeInline2<LoadingTextSparks>(pattern.get_first(0), pattern.get_first(8));
}
};
}
} FramerateVigilante;
20 changes: 14 additions & 6 deletions source/loadingdelays.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import common;
import framelimit;
import comvars;

bool bRestoreSleep = false;
void WINAPI FusionSleep(DWORD dwMilliseconds)
{
auto bMenuActive = CMenuManager__m_MenuActive && *CMenuManager__m_MenuActive;
auto bLoadscreenActive = (bLoadscreenShown && *bLoadscreenShown) || bLoadingShown;

if (!bMenuActive && bLoadscreenActive)
return Sleep(0);
if (!bRestoreSleep)
{
auto bMenuActive = CMenuManager__m_MenuActive && *CMenuManager__m_MenuActive;
auto bLoadscreenActive = (bLoadscreenShown && *bLoadscreenShown) || bLoadingShown;

if (!bMenuActive && bLoadscreenActive)
return Sleep(0);
}
return Sleep(dwMilliseconds);
}

Expand All @@ -33,11 +36,16 @@ public:
injector::MakeJMP(pattern.get_first(), hook::get_pattern("6A FF 6A 01 6A 00 6A 01 6A 01 6A 00 6A 01 6A 01 6A 00 6A 00 6A 00 6A 00 6A 00 6A 00 B9 ? ? ? ? C6 46 04 00"));
};

FusionFix::onAfterUALRestoredIATEvent() += []()
FusionFix::onInitEvent() += []()
{
IATHook::Replace(GetModuleHandleA(NULL), "kernel32.DLL",
std::forward_as_tuple("Sleep", FusionSleep)
);
};

FusionFix::onGameInitEvent() += []()
{
bRestoreSleep = true;
};
}
} LoadingDelays;
3 changes: 2 additions & 1 deletion source/shaders.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public:
// Setup variables for shaders
static auto dw11A2948 = *find_pattern("C7 05 ? ? ? ? ? ? ? ? 0F 85 ? ? ? ? 6A 00", "D8 05 ? ? ? ? D9 1D ? ? ? ? 83 05").get_first<float*>(2);
static auto dw103E49C = *hook::get_pattern<void**>("A3 ? ? ? ? C7 80", 1);
auto bLoadscreenActive = (bLoadscreenShown && *bLoadscreenShown) || bLoadingShown;

if (*dw103E49C)
if (*dw103E49C && !bLoadscreenActive)
{
static Cam cam = 0;
Natives::GetRootCam(&cam);
Expand Down

0 comments on commit b711c02

Please sign in to comment.