Skip to content

Commit

Permalink
Couple of fixes (#1117)
Browse files Browse the repository at this point in the history
* Increased draw distance for leave ending
* Fixed flashlight inhibiting in room 312
* Reworked room 312 flashlight fix
  • Loading branch information
mercury501 authored Nov 24, 2024
1 parent 0405c0c commit 1e9dd06
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Patches/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3240,10 +3240,10 @@ BYTE* InventoryItemPointer()
{
if (InventoryItemAddr)
{
return WorldColorBAddr;
return InventoryItemAddr;
}

// Get WorldColorB address
// Get InventoryItem address
InventoryItemAddr =
GameVersion == SH2V_10 ? (BYTE*)0x01F7A7E2 :
GameVersion == SH2V_11 ? (BYTE*)0x01F7E3E2 :
Expand Down
17 changes: 0 additions & 17 deletions Patches/InputTweaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,6 @@ void InputTweaks::TweakGetDeviceState(LPDIRECTINPUTDEVICE8A ProxyInterface, DWOR
{
ControllerData->rgbButtons[KeyBinds.GetPauseButtonBind()] = KEY_CLEAR;
}

// If James is in room 312 and has the VHS in his inventory
if (GetRoomID() == R_HTL_RM_312 && GetInventoryItem() > 0x80)
{
ControllerData->rgbButtons[KeyBinds.GetToggleFlashlightButtonBind()] = KEY_CLEAR;
}

// Clear controller data
ControllerData = nullptr;
Expand Down Expand Up @@ -567,12 +561,6 @@ void InputTweaks::TweakGetDeviceState(LPDIRECTINPUTDEVICE8A ProxyInterface, DWOR
SetKey(KeyBinds.GetKeyBind(KEY_TURN_RIGHT));
}

// If James is in room 312 and has the VHS in his inventory
if (GetRoomID() == R_HTL_RM_312 && GetInventoryItem() > 0x80)
{
ClearKey(KeyBinds.GetKeyBind(KEY_FLASHLIGHT));
}

if (SetUpKey)
{
SetKey(KeyBinds.GetKeyBind(KEY_MOVE_FORWARDS));
Expand Down Expand Up @@ -1099,11 +1087,6 @@ BYTE KeyBindsHandler::GetPauseButtonBind()
return *(GetKeyBindsPointer() + 0xF0);
}

BYTE KeyBindsHandler::GetToggleFlashlightButtonBind()
{
return *(GetKeyBindsPointer() + 0x110);
}

int CountCollectedMemos()
{
auto* psVar2 = GetMemoCountIndexPointer();
Expand Down
1 change: 0 additions & 1 deletion Patches/InputTweaks.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class KeyBindsHandler
public:
BYTE GetKeyBind(int KeyIndex);
BYTE GetPauseButtonBind();
BYTE GetToggleFlashlightButtonBind();
};

// Hitboxes for pause and memo menu
Expand Down
39 changes: 39 additions & 0 deletions Patches/LeaveEndingDrawDistance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (C) 2024 mercury501
*
* This software is provided 'as-is', without any express or implied warranty. In no event will the
* authors be held liable for any damages arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
* original software. If you use this software in a product, an acknowledgment in the product
* documentation would be appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
* being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

#include "Common\Utils.h"
#include "Patches\Patches.h"
#include "Logging\Logging.h"

void PatchLeaveEndingCemeteryDrawDistance()
{
DWORD CemeteryDrawDistance = GameVersion == SH2V_10 ? 0x008E7878 :
GameVersion == SH2V_11 ? 0x008EB548 :
GameVersion == SH2V_DC ? 0x008EA548 :
NULL;

if (CemeteryDrawDistance == NULL)
{
Logging::Log() << __FUNCTION__ << " Couldn't parse game version.";
return;
}

float DrawDistanceValue = 40000.0f;

UpdateMemoryAddress((BYTE*)CemeteryDrawDistance, &DrawDistanceValue, sizeof(float));

Logging::Log() << __FUNCTION__ << " Patched L. ending draw distance!";
}
2 changes: 2 additions & 0 deletions Patches/Patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ void PatchHoldToStomp();
void PatchInputTweaks();
void PatchInventoryBGMBug();
void PatchLakeMoonSize();
void PatchLeaveEndingCemeteryDrawDistance();
void PatchLockScreenPosition();
void PatchLowHealthIndicator();
void PatchMainMenu();
Expand Down Expand Up @@ -751,6 +752,7 @@ float GetConditionalFlashlightBrightnessRed();
float GetConditionalFlashlightBrightnessGreen();
float GetConditionalFlashlightBrightnessBlue();
void CheckLakeMoonSize();
void CheckRoom312Flashlight();

// Define the template function declaration
template<typename T>
Expand Down
55 changes: 55 additions & 0 deletions Patches/Room312FlashlightFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (C) 2024 mercury501
*
* This software is provided 'as-is', without any express or implied warranty. In no event will the
* authors be held liable for any damages arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
* original software. If you use this software in a product, an acknowledgment in the product
* documentation would be appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
* being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

#include "Common\Utils.h"
#include "Patches\Patches.h"
#include "Logging\Logging.h"

BYTE* InhibitFlashlightAddr = nullptr;

bool InhibitedFlashlightFlag = false;

void CheckRoom312Flashlight()
{
if (!InhibitFlashlightAddr)
{
InhibitFlashlightAddr = GameVersion == SH2V_10 ? (BYTE*)0x0048EBC8 :
GameVersion == SH2V_11 ? (BYTE*)0x0048EE68 :
GameVersion == SH2V_DC ? (BYTE*)0x0048F078 :
nullptr;

if (!InhibitFlashlightAddr)
{
Logging::Log() << __FUNCTION__ << " Couldn't identify game version.";
return;
}

Logging::Log() << __FUNCTION__ << " Initialized room 312 flashlight fix!";
}

bool InhibitFlashlight = GetRoomID() == R_HTL_RM_312 && (GetInventoryItem() & 0x80);

if (InhibitFlashlight && !InhibitedFlashlightFlag)
{
UpdateMemoryAddress(InhibitFlashlightAddr, "\x90\xE9", 0x02);
InhibitedFlashlightFlag = true;
}
else if (!InhibitFlashlight && InhibitedFlashlightFlag)
{
UpdateMemoryAddress(InhibitFlashlightAddr, "\x0F\x84", 0x02);
InhibitedFlashlightFlag = false;
}
}
3 changes: 3 additions & 0 deletions Wrappers/d3d8/IDirect3DDevice8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,9 @@ HRESULT m_IDirect3DDevice8::Present(CONST RECT* pSourceRect, CONST RECT* pDestRe
// Fix moon size on the lake
CheckLakeMoonSize();

// Fix flashlight glitch in room 312
CheckRoom312Flashlight();

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 @@ -804,6 +804,9 @@ void DelayedStart()
{
PatchCustomAdvancedOptions();
}

// Increase cemetery draw distance for leave ending
PatchLeaveEndingCemeteryDrawDistance();

// Remove the "Now loading..." and "Press Return to continue." messages
if (DisableLoadingPressReturnMessages)
Expand Down
2 changes: 2 additions & 0 deletions sh2-enhce.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ copy /Y "$(ProjectDir)Resources\SH2EEsetup.exe" "$(TargetDir)" &gt;nul</Command>
<ClCompile Include="Patches\InputTweaks.cpp" />
<ClCompile Include="Patches\FMVPatches.cpp" />
<ClCompile Include="Patches\HoldDamage.cpp" />
<ClCompile Include="Patches\LeaveEndingDrawDistance.cpp" />
<ClCompile Include="Patches\LowHealthIndicator.cpp" />
<ClCompile Include="Patches\MapTranscription.cpp" />
<ClCompile Include="Patches\DelayedFadeIn.cpp" />
Expand Down Expand Up @@ -260,6 +261,7 @@ copy /Y "$(ProjectDir)Resources\SH2EEsetup.exe" "$(TargetDir)" &gt;nul</Command>
<ClCompile Include="Patches\EnhancedFlashlight.cpp" />
<ClCompile Include="Patches\PauseScreen.cpp" />
<ClCompile Include="Patches\ReplaceWindowTitle.cpp" />
<ClCompile Include="Patches\Room312FlashlightFix.cpp" />
<ClCompile Include="Patches\RotatingMannequinGlitch.cpp" />
<ClCompile Include="Patches\RowboatFix.cpp" />
<ClCompile Include="Patches\SaveBGImage.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions sh2-enhce.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@
<ClCompile Include="Patches\WaterEnhancement.cpp">
<Filter>Patches</Filter>
</ClCompile>
<ClCompile Include="Patches\LeaveEndingDrawDistance.cpp">
<Filter>Patches</Filter>
</ClCompile>
<ClCompile Include="Patches\Room312FlashlightFix.cpp">
<Filter>Patches</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Common\Settings.h">
Expand Down

0 comments on commit 1e9dd06

Please sign in to comment.