Skip to content

Commit

Permalink
THPS4: Fix for field of view not being aspect corrected (#1469)
Browse files Browse the repository at this point in the history
  • Loading branch information
mallgrab authored Nov 22, 2023
1 parent fbe14e6 commit b470b0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
ResX = 0
ResY = 0
FixHUD = 1
FOVFactor = 1.0
RandomSongOrderFix = 1
10 changes: 7 additions & 3 deletions source/TonyHawksProSkater4.WidescreenFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Screen
float fAspectRatio;
float fAspectRatioDiff;
float fFieldOfView;
float fFOVFactor;
float fHUDScaleX;
float fHudOffset;
float fHudOffsetReal;
Expand All @@ -23,6 +24,7 @@ void Init()
Screen.Height = iniReader.ReadInteger("MAIN", "ResY", 0);
bool bFixHUD = iniReader.ReadInteger("MAIN", "FixHUD", 1) != 0;
bool bRandomSongOrderFix = iniReader.ReadInteger("MAIN", "RandomSongOrderFix", 1) != 0;
Screen.fFOVFactor = iniReader.ReadFloat("MAIN", "FOVFactor", 0.0f);

if (!Screen.Width || !Screen.Height)
std::tie(Screen.Width, Screen.Height) = GetDesktopRes();
Expand All @@ -35,6 +37,8 @@ void Init()
Screen.fHUDScaleX = 1.0f / Screen.fWidth * (Screen.fHeight / 480.0f);
Screen.fHudOffset = ((480.0f * Screen.fAspectRatio) - 640.0f) / 2.0f;
Screen.fHudOffsetReal = (Screen.fWidth - Screen.fHeight * (4.0f / 3.0f)) / 2.0f;
if (Screen.fFOVFactor <= 0.0f)
Screen.fFOVFactor = 1.0f;

//Resolution
auto pattern = hook::pattern("8B 4C B4 20 89 15");
Expand Down Expand Up @@ -69,9 +73,9 @@ void Init()
{
void operator()(injector::reg_pack& regs)
{
float fov = 0.0f;
_asm {fst dword ptr[fov]}
*(float*)(regs.esi + 0xA4) = AdjustFOV(fov, Screen.fAspectRatio);
float fov = *(float*)(regs.esi + 0xA4);
float adjustedFov = AdjustFOV(fov, Screen.fAspectRatio);
*(float*)(regs.esi + 0xA0) = adjustedFov * Screen.fFOVFactor;
}
}; injector::MakeInline<FovHook>(pattern.get_first(0), pattern.get_first(6));

Expand Down

0 comments on commit b470b0b

Please sign in to comment.