Skip to content

Commit

Permalink
Lake light fix (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
mercury501 authored Sep 23, 2024
1 parent d31c014 commit 0e6baf6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Patches/Patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ void PatchHoldDamage();
void PatchHoldToStomp();
void PatchInputTweaks();
void PatchInventoryBGMBug();
void PatchLakeMoonSize();
void PatchLockScreenPosition();
void PatchLowHealthIndicator();
void PatchMainMenu();
Expand Down Expand Up @@ -749,6 +750,7 @@ void CheckFlashlightAvailable();
float GetConditionalFlashlightBrightnessRed();
float GetConditionalFlashlightBrightnessGreen();
float GetConditionalFlashlightBrightnessBlue();
void CheckLakeMoonSize();

// Define the template function declaration
template<typename T>
Expand Down
36 changes: 36 additions & 0 deletions Patches/Resolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,42 @@ void UpdateResolutionVector()
UsingScaledResolutions = (ScaleWindowedResolution != 0);
}

float LakeLightResolutionMultiplier = 1.;

BYTE* LoadLakeCustomValueReturn = nullptr;

__declspec(naked) void __stdcall LoadLakeCustomValue()
{
__asm
{
fld dword ptr[LakeLightResolutionMultiplier]
fld dword ptr[LakeLightResolutionMultiplier]

jmp LoadLakeCustomValueReturn
}
}

void PatchLakeMoonSize()
{
constexpr BYTE LakeCustomValueSearchBytes[]{ 0x83, 0xC4, 0x18, 0xD8, 0x74 };
BYTE* LakeCustomValueAddr = (BYTE*)SearchAndGetAddresses(0x004DBE17, 0x004DC0C7, 0x004DB987, LakeCustomValueSearchBytes, sizeof(LakeCustomValueSearchBytes), 0x84, __FUNCTION__);

if (!LakeCustomValueAddr)
{
Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!";
return;
}

LoadLakeCustomValueReturn = LakeCustomValueAddr + 0x0C;

WriteJMPtoMemory(LakeCustomValueAddr, LoadLakeCustomValue, 0x06);
}

void CheckLakeMoonSize()
{
LakeLightResolutionMultiplier = (float)BufferHeight / 240.;
}

template void GetNonScaledResolution<LONG>(LONG&, LONG&);
template void GetNonScaledResolution<int>(int&, int&);
template void GetNonScaledResolution<UINT>(UINT&, UINT&);
Expand Down
3 changes: 3 additions & 0 deletions Wrappers/d3d8/IDirect3DDevice8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,9 @@ HRESULT m_IDirect3DDevice8::Present(CONST RECT* pSourceRect, CONST RECT* pDestRe
// Check flashlight availability
CheckFlashlightAvailable();

// Fix moon size on the lake
CheckLakeMoonSize();

if (EnableEnhancedMouse || EnhanceMouseCursor)
{
OverlayRef.RenderMouseCursor();
Expand Down
3 changes: 3 additions & 0 deletions dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ void DelayedStart()
SetResolutionPatch();
}

// Fix lake moon size
PatchLakeMoonSize();

// Fixes issues in the Advanced Options screen
if (FixAdvancedOptions)
{
Expand Down

0 comments on commit 0e6baf6

Please sign in to comment.