11/* ****************************************************************************
22 *
3- * PROJECT: Multi Theft Auto
3+ * PROJECT: Multi Theft Auto v1.0
44 * LICENSE: See LICENSE in the top level directory
55 * FILE: game_sa/CHudSA.cpp
66 * PURPOSE: HUD display
1919
2020extern CGameSA* pGame;
2121
22- static float radarAltimeterFix = 0 . 0014625f ; // Changes altimeter width (and maybe x pos)
23- static constexpr float aspectRatioMultiplicatorUntouched = 0 . 0015625f ; // (1 / 640)
22+ char szVehicleName[ 50 ] = { ' \0 ' };
23+ char szZoneName[ 50 ] = { ' \0 ' };
2424
2525static ComponentProperties componentProperties;
2626
@@ -56,19 +56,24 @@ CHudSA::CHudSA()
5656{
5757 InitComponentList ();
5858
59- m_pfAspectRatioMultiplicatorX = reinterpret_cast < float *>(VAR_AspectRatioMultX);
60- m_pfAspectRatioMultiplicatorY = reinterpret_cast < float *>(VAR_AspectRatioMult) ;
59+ // Set the default values
60+ m_fSniperCrosshairScale = 210 . 0f ;
6161
62- MemPut<float >(0x866C84 , 640 .0f / ((4 .0f / 3 .0f ) * 448 .0f )); // 0x866C84: Weapon sprite x position
63- MemPut<float >(m_pfAspectRatioMultiplicatorX, 0 .0015625f ); // (1 / 640)
64- MemPut<float >(m_pfAspectRatioMultiplicatorY, 0 .002232143f ); // (1 / 448)
65-
66- MemPut<const float *>(0x58B141 , &aspectRatioMultiplicatorUntouched); // Vehicle name x pos
67- MemPut<const float *>(0x58AE4C , &aspectRatioMultiplicatorUntouched); // Area name x pos
68- MemPut<float *>(0x58A6E0 , &radarAltimeterFix); // Fix radar altimeter
62+ m_pfCameraCrosshairScale = (float *)VAR_CameraCrosshairScale;
63+ MemPut<float >(m_pfCameraCrosshairScale, 192 .0f );
64+ m_pfAspectRatioMultiplicator = (float *)VAR_AspectRatioMult;
65+ MemPut<float >(m_pfAspectRatioMultiplicator, 0 .002232143f );
6966
7067 UpdateStreetchCalculations ();
7168
69+ // Patch xrefs to 0x863B34, because this variable seems to be shared (2 other functions without any context access to it; probably a compiler optimization)
70+ MemPut<DWORD>(0x58E7D4 + 2 , (DWORD)&m_fSniperCrosshairScale);
71+ MemPut<DWORD>(0x58E7EA + 2 , (DWORD)&m_fSniperCrosshairScale);
72+ MemPut<DWORD>(0x53E3ED + 2 , (DWORD)&m_fSniperCrosshairScale);
73+ MemPut<DWORD>(0x53E41A + 2 , (DWORD)&m_fSniperCrosshairScale);
74+ MemPut<DWORD>(0x53E488 + 2 , (DWORD)&m_fSniperCrosshairScale);
75+ MemPut<DWORD>(0x53E4BF + 2 , (DWORD)&m_fSniperCrosshairScale);
76+
7277 // Initalize default data
7378 componentProperties.hpBar = MapGet (defaultComponentProperties, HUD_HEALTH);
7479 componentProperties.breathBar = MapGet (defaultComponentProperties, HUD_BREATH);
@@ -193,8 +198,8 @@ bool CHudSA::IsComponentVisible(eHudComponent component)
193198
194199void CHudSA::UpdateStreetchCalculations ()
195200{
196- calcStreetchX = rsGlobal->maximumWidth * (*m_pfAspectRatioMultiplicatorX );
197- calcStreetchY = rsGlobal->maximumHeight * (*m_pfAspectRatioMultiplicatorY );
201+ calcStreetchX = rsGlobal->maximumWidth * (*reinterpret_cast < float *>(VAR_AspectRatioMultX) );
202+ calcStreetchY = rsGlobal->maximumHeight * (*m_pfAspectRatioMultiplicator );
198203
199204 SComponentPlacement& hpPlacement = componentProperties.hpBar .placement ;
200205 hpPlacement.height = calcStreetchY * 9 .0f ;
@@ -260,13 +265,14 @@ void CHudSA::AdjustComponents(float fAspectRatio)
260265 // Fix for #7400 (HUD elements do not scale correctly for widescreen)
261266 // 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 /
262267 // 16/9
263- const float ratio = (640 .0f / (fAspectRatio * 448 .0f ));
268+ MemPut<float >(m_pfAspectRatioMultiplicator, 0 .002232143f / (4 .0f / 3 .0f ) * fAspectRatio );
269+
270+ // Set the sniper crosshair scale (fix for #7659)
271+ m_fSniperCrosshairScale = 210 .0f * (4 .0f / 3 .0f ) / fAspectRatio ;
272+
273+ // Set the camera crosshair scale (same display flaw as in #7659)
274+ MemPut<float >(m_pfCameraCrosshairScale, 192 .0f * (4 .0f / 3 .0f ) / fAspectRatio );
264275
265- radarAltimeterFix = ratio * 0 .00147f ;
266- MemPut<float >(m_pfAspectRatioMultiplicatorX, ratio * 0 .0015625f );
267- MemPut<float >(m_pfAspectRatioMultiplicatorY, ratio * 0 .002232143f );
268- MemPut<float >(0x866C84 , ratio * 0 .17343046f ); // 0x866C84: Weapon sprite x position
269-
270276 UpdateStreetchCalculations ();
271277}
272278
@@ -276,10 +282,9 @@ void CHudSA::AdjustComponents(float fAspectRatio)
276282void CHudSA::ResetComponentAdjustment ()
277283{
278284 // Restore default values (4:3 aspect ratio)
279- radarAltimeterFix = 0 .0014625f ;
280- MemPut<float >(m_pfAspectRatioMultiplicatorX, 0 .0015625f ); // (1 / 640)
281- MemPut<float >(m_pfAspectRatioMultiplicatorY, 0 .002232143f ); // (1 / 448)
282- MemPut<float >(0x866C84 , 0 .17343046f ); // 0x866C84: Weapon sprite x position
285+ MemPut<float >(m_pfAspectRatioMultiplicator, 0 .002232143f );
286+ MemPut<float >(m_pfCameraCrosshairScale, 192 .0f );
287+ m_fSniperCrosshairScale = 210 .0f ;
283288
284289 UpdateStreetchCalculations ();
285290}
0 commit comments