Skip to content

Fix HUD size when playing on widescreen #3444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f1d7a6f
Fix HUD size when playing on widescreen
henrymarques Jun 8, 2024
eee2a8e
Remove junk code from hud header file
henrymarques Jun 8, 2024
41f7701
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue…
henrymarques Jun 8, 2024
7992392
Upload widescreen fix
henrymarques Jun 8, 2024
d618a60
Removed frontend fixes due it's not necessary
henrymarques Jul 11, 2024
b0cf8f5
Removed unnecessary null pointers and null checks
henrymarques Jul 11, 2024
6a4ee2f
Change type references
henrymarques Jul 11, 2024
88d0820
Remove unused variables, change altimeter size and const to constexpr
henrymarques Jul 13, 2024
aa2c42c
Change variable names and remove unused functions
henrymarques Jul 13, 2024
b299e1b
Remove AdjustFOV due it's not used
henrymarques Jul 13, 2024
099e827
Remove unused structs, align zones and vehicle names
henrymarques Jul 17, 2024
d68a3d6
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue…
henrymarques Jul 17, 2024
0fa951a
Remove unecessary patches
henrymarques Jul 18, 2024
41ef5a5
Align weapon ammo, add fov fix
henrymarques Jul 19, 2024
4254ce2
Add ability to choose hud match aspect ratio
henrymarques Jul 23, 2024
6911919
Remove testing junk
henrymarques Jul 23, 2024
a0b4dd1
Merge branch 'master' of github.com:multitheftauto/mtasa-blue into fe…
henrymarques Jan 4, 2025
07effc3
Fix merge conflicts
henrymarques Jan 7, 2025
3d0998a
Rework hud changes
henrymarques Jan 7, 2025
4e396f7
Merge branch 'master' of github.com:multitheftauto/mtasa-blue into fe…
henrymarques Jan 7, 2025
f1a16a6
Move hud changes to CHudSA.cpp
henrymarques Jan 9, 2025
d9554ae
Adjust altimeter size
henrymarques Jan 11, 2025
1d12abc
Add comments
henrymarques Jan 11, 2025
26b64e5
Make functions static
henrymarques Jan 12, 2025
91c5dc6
Merge branch 'master' of github.com:multitheftauto/mtasa-blue into bu…
henrymarques Feb 13, 2025
52e2731
Change cast on CHudSA
henrymarques Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 24 additions & 29 deletions Client/game_sa/CHudSA.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CHudSA.cpp
* PURPOSE: HUD display
Expand All @@ -19,8 +19,8 @@

extern CGameSA* pGame;

char szVehicleName[50] = {'\0'};
char szZoneName[50] = {'\0'};
static float radarAltimeterFix = 0.0014625f; // Changes altimeter width (and maybe x pos)
static constexpr float aspectRatioMultiplicatorUntouched = 0.0015625f; // (1 / 640)

static ComponentProperties componentProperties;

Expand Down Expand Up @@ -56,23 +56,18 @@ CHudSA::CHudSA()
{
InitComponentList();

// Set the default values
m_fSniperCrosshairScale = 210.0f;
m_pfAspectRatioMultiplicatorX = reinterpret_cast<float*>(VAR_AspectRatioMultX);
m_pfAspectRatioMultiplicatorY = reinterpret_cast<float*>(VAR_AspectRatioMult);

m_pfCameraCrosshairScale = (float*)VAR_CameraCrosshairScale;
MemPut<float>(m_pfCameraCrosshairScale, 192.0f);
m_pfAspectRatioMultiplicator = (float*)VAR_AspectRatioMult;
MemPut<float>(m_pfAspectRatioMultiplicator, 0.002232143f);
MemPut<float>(0x866C84, 640.0f / ((4.0f / 3.0f) * 448.0f)); // 0x866C84: Weapon sprite x position
MemPut<float>(m_pfAspectRatioMultiplicatorX, 0.0015625f); // (1 / 640)
MemPut<float>(m_pfAspectRatioMultiplicatorY, 0.002232143f); // (1 / 448)

UpdateStreetchCalculations();
MemPut<const float*>(0x58B141, &aspectRatioMultiplicatorUntouched); // Vehicle name x pos
MemPut<const float*>(0x58AE4C, &aspectRatioMultiplicatorUntouched); // Area name x pos
MemPut<float*>(0x58A6E0, &radarAltimeterFix); // Fix radar altimeter

// Patch xrefs to 0x863B34, because this variable seems to be shared (2 other functions without any context access to it; probably a compiler optimization)
MemPut<DWORD>(0x58E7D4 + 2, (DWORD)&m_fSniperCrosshairScale);
MemPut<DWORD>(0x58E7EA + 2, (DWORD)&m_fSniperCrosshairScale);
MemPut<DWORD>(0x53E3ED + 2, (DWORD)&m_fSniperCrosshairScale);
MemPut<DWORD>(0x53E41A + 2, (DWORD)&m_fSniperCrosshairScale);
MemPut<DWORD>(0x53E488 + 2, (DWORD)&m_fSniperCrosshairScale);
MemPut<DWORD>(0x53E4BF + 2, (DWORD)&m_fSniperCrosshairScale);
UpdateStreetchCalculations();

// Initalize default data
componentProperties.hpBar = MapGet(defaultComponentProperties, HUD_HEALTH);
Expand Down Expand Up @@ -198,8 +193,8 @@ bool CHudSA::IsComponentVisible(eHudComponent component)

void CHudSA::UpdateStreetchCalculations()
{
calcStreetchX = rsGlobal->maximumWidth * (*reinterpret_cast<float*>(VAR_AspectRatioMultX));
calcStreetchY = rsGlobal->maximumHeight * (*m_pfAspectRatioMultiplicator);
calcStreetchX = rsGlobal->maximumWidth * (*m_pfAspectRatioMultiplicatorX);
calcStreetchY = rsGlobal->maximumHeight * (*m_pfAspectRatioMultiplicatorY);

SComponentPlacement& hpPlacement = componentProperties.hpBar.placement;
hpPlacement.height = calcStreetchY * 9.0f;
Expand Down Expand Up @@ -265,14 +260,13 @@ void CHudSA::AdjustComponents(float fAspectRatio)
// Fix for #7400 (HUD elements do not scale correctly for widescreen)
// 0x859524: GTA multiplies all HUD and menu transformation variables by this floating point value. It is equal to 1/448, so just translate it to 16/10 /
// 16/9
MemPut<float>(m_pfAspectRatioMultiplicator, 0.002232143f / (4.0f / 3.0f) * fAspectRatio);

// Set the sniper crosshair scale (fix for #7659)
m_fSniperCrosshairScale = 210.0f * (4.0f / 3.0f) / fAspectRatio;

// Set the camera crosshair scale (same display flaw as in #7659)
MemPut<float>(m_pfCameraCrosshairScale, 192.0f * (4.0f / 3.0f) / fAspectRatio);
const float ratio = (640.0f / (fAspectRatio * 448.0f));

radarAltimeterFix = ratio * 0.00147f;
MemPut<float>(m_pfAspectRatioMultiplicatorX, ratio * 0.0015625f);
MemPut<float>(m_pfAspectRatioMultiplicatorY, ratio * 0.002232143f);
MemPut<float>(0x866C84, ratio * 0.17343046f); // 0x866C84: Weapon sprite x position

UpdateStreetchCalculations();
}

Expand All @@ -282,9 +276,10 @@ void CHudSA::AdjustComponents(float fAspectRatio)
void CHudSA::ResetComponentAdjustment()
{
// Restore default values (4:3 aspect ratio)
MemPut<float>(m_pfAspectRatioMultiplicator, 0.002232143f);
MemPut<float>(m_pfCameraCrosshairScale, 192.0f);
m_fSniperCrosshairScale = 210.0f;
radarAltimeterFix = 0.0014625f;
MemPut<float>(m_pfAspectRatioMultiplicatorX, 0.0015625f); // (1 / 640)
MemPut<float>(m_pfAspectRatioMultiplicatorY, 0.002232143f); // (1 / 448)
MemPut<float>(0x866C84, 0.17343046f); // 0x866C84: Weapon sprite x position

UpdateStreetchCalculations();
}
Expand Down
3 changes: 2 additions & 1 deletion Client/game_sa/CHudSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ class CHudSA : public CHud
private:
std::map<eHudComponent, SHudComponent> m_HudComponentMap;

float* m_pfAspectRatioMultiplicator;
float* m_pfAspectRatioMultiplicatorX;
float* m_pfAspectRatioMultiplicatorY;
float* m_pfCameraCrosshairScale;
float m_fSniperCrosshairScale;

Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CSettingsSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CSettingsSA::CSettingsSA()
HookInstall(HOOKPOS_StoreShadowForVehicle, (DWORD)HOOK_StoreShadowForVehicle, 9);
m_iDesktopWidth = 0;
m_iDesktopHeight = 0;
MemPut<BYTE>(0x6FF420, 0xC3); // Truncate CalculateAspectRatio
MemPut<BYTE>(0x6FF420, 0xC3);

MemPut(0x732926, &ms_fVehicleLODDistance);
MemPut(0x732940, &ms_fTrainPlaneLODDistance);
Expand Down
1 change: 1 addition & 0 deletions Client/multiplayer_sa/CMultiplayerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ void CMultiplayerSA::InitHooks()

InitHooks_Streaming();
InitHooks_FrameRateFixes();
InitHooks_WidescreenFix();
InitHooks_ProjectileCollisionFix();
InitHooks_ObjectStreamerOptimization();

Expand Down
1 change: 1 addition & 0 deletions Client/multiplayer_sa/CMultiplayerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CMultiplayerSA : public CMultiplayer
void InitHooks_FixLineOfSightArgs();
void InitHooks_Streaming();
void InitHooks_FrameRateFixes();
void InitHooks_WidescreenFix();
void InitHooks_ProjectileCollisionFix();
void InitHooks_ObjectStreamerOptimization();
void InitHooks_Postprocess();
Expand Down
88 changes: 88 additions & 0 deletions Client/multiplayer_sa/CMultiplayerSA_WidescreenFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: multiplayer_sa/CMultiplayerSA_WidescreenFix.cpp
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/

// NOTE: This code is based on ThirteenAG's fix, which is licensed under the MIT license.
#include "StdInc.h"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

static constexpr float CameraWidth = 0.01403292f;
static constexpr float SkyMultiFix = 10.0f;

static float* ScreenAspectRatio = reinterpret_cast<float*>(0xC3EFA4);
static float* ScreenFieldOfView = reinterpret_cast<float*>(0x8D5038);

static float AdjustFOV(float factor, float aspectRatio) noexcept
{
return std::round((2.0f * std::atan(((aspectRatio) / (4.0f / 3.0f)) *
std::tan(factor / 2.0f * ((float)M_PI / 180.0f)))) *
(180.0f / (float)M_PI) * 100.0f) / 100.0f;
}

static void SetFOV(float factor)
{
*ScreenFieldOfView = AdjustFOV(factor, *ScreenAspectRatio);
}

static constexpr std::uintptr_t RETURN_CCamera_Find3rdPersonCamTargetVector = 0x5149A6;
static void __declspec(naked) CalculateAimingPoint()
{
_asm
{
fstp st
mov edx, [ScreenAspectRatio]
fmul [edx]
mov edi, [esp + 1Ch + 14h]
mov edx, edi
jmp RETURN_CCamera_Find3rdPersonCamTargetVector
}
}

static void InstallAspectRatioFixes()
{
// Disables jump instructions in GetVideoModeList
MemSet((void*)0x745BD1, 0x90, 2);
MemSet((void*)0x745BD9, 0x90, 2);

// Proportional coronas, skips multiplication by ScreenY in CCoronas::Render
MemSet((void*)0x6FB2C9, 0x90, 4);

// Load ScreenY value from the stack
MemPut<BYTE>(0x6FB2BD, 0x6C); // CCoronas::Render
MemPut<BYTE>(0x6FB2DC, 0x78); // CCoronas::Render
MemPut<BYTE>(0x713BE5, 0x20); // CClouds::Render
MemPut<BYTE>(0x713B6D, 0x38); // CClouds::Render
MemPut<BYTE>(0x713CFB, 0x38); // CClouds::Render
MemPut<BYTE>(0x713EFC, 0x30); // CClouds::Render
MemPut<BYTE>(0x714004, 0x38); // CClouds::Render
}

static void InstallFieldOfViewFixes()
{
// Fix sky blurring white in ultrawide screens
MemPut<const float*>(0x714843, &SkyMultiFix);
MemPut<const float*>(0x714860, &SkyMultiFix);

HookInstall(0x6FF410, reinterpret_cast<DWORD>(SetFOV), 9);
HookInstall(0x51499E, reinterpret_cast<DWORD>(CalculateAimingPoint), 6);

// Skips division by CDraw::ms_fAspectRatio
MemSet((void*)0x50AD79, 0x90, 6);
MemPut<const float*>(0x50AD5B, &CameraWidth); // CCamera::Find3rdPersonQuickAimPitch
MemPut<const float*>(0x51498F, &CameraWidth); // CCamera::Find3rdPersonCamTargetVector
}

void CMultiplayerSA::InitHooks_WidescreenFix()
{
InstallAspectRatioFixes();
InstallFieldOfViewFixes();
}
2 changes: 1 addition & 1 deletion Client/sdk/game/CSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class CGameSettings

virtual float GetAspectRatioValue() = 0;
virtual eAspectRatio GetAspectRatio() = 0;
virtual void SetAspectRatio(eAspectRatio aspectRatio, bool bAdjustmentEnabled = true) = 0;
virtual void SetAspectRatio(eAspectRatio aspectRatio, bool isAdjustmentEnabled) = 0;

virtual bool IsGrassEnabled() = 0;
virtual void SetGrassEnabled(bool bEnable) = 0;
Expand Down