Skip to content

Commit 1fac287

Browse files
Add new world special property (vehicle sun glare effect) (#2495)
Co-authored-by: Uladzislau Nikalayevich <[email protected]>
1 parent df4d35d commit 1fac287

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

Client/game_sa/CGameSA.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ CGameSA::CGameSA()
222222
CFxSystemSA::StaticSetHooks();
223223
CFileLoaderSA::StaticSetHooks();
224224
D3DResourceSystemSA::StaticSetHooks();
225+
CVehicleSA::StaticSetHooks();
225226
}
226227

227228
CGameSA::~CGameSA()
@@ -603,6 +604,9 @@ bool CGameSA::IsCheatEnabled(const char* szCheatName)
603604
if (!strcmp(szCheatName, PROP_UNDERWORLD_WARP))
604605
return IsUnderWorldWarpEnabled();
605606

607+
if (!strcmp(szCheatName, PROP_VEHICLE_SUNGLARE))
608+
return IsVehicleSunGlareEnabled();
609+
606610
std::map<std::string, SCheatSA*>::iterator it = m_Cheats.find(szCheatName);
607611
if (it == m_Cheats.end())
608612
return false;
@@ -635,6 +639,12 @@ bool CGameSA::SetCheatEnabled(const char* szCheatName, bool bEnable)
635639
return true;
636640
}
637641

642+
if (!strcmp(szCheatName, PROP_VEHICLE_SUNGLARE))
643+
{
644+
SetVehicleSunGlareEnabled(bEnable);
645+
return true;
646+
}
647+
638648
std::map<std::string, SCheatSA*>::iterator it = m_Cheats.find(szCheatName);
639649
if (it == m_Cheats.end())
640650
return false;
@@ -724,6 +734,17 @@ void CGameSA::SetJetpackWeaponEnabled(eWeaponType weaponType, bool bEnabled)
724734
}
725735
}
726736

737+
void CGameSA::SetVehicleSunGlareEnabled(bool bEnabled)
738+
{
739+
// State turning will be handled in hooks handler
740+
CVehicleSA::SetVehiclesSunGlareEnable(bEnabled);
741+
}
742+
743+
bool CGameSA::IsVehicleSunGlareEnabled()
744+
{
745+
return CVehicleSA::GetVehiclesSunGlareEnable();
746+
}
747+
727748
bool CGameSA::PerformChecks()
728749
{
729750
std::map<std::string, SCheatSA*>::iterator it;

Client/game_sa/CGameSA.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ extern unsigned int OBJECTDYNAMICINFO_MAX; // default: 160
8585
#define PROP_SNIPER_MOON "snipermoon"
8686
#define PROP_EXTRA_AIR_RESISTANCE "extraairresistance"
8787
#define PROP_UNDERWORLD_WARP "underworldwarp"
88+
#define PROP_VEHICLE_SUNGLARE "vehiclesunglare"
89+
8890

8991
struct SCheatSA
9092
{
@@ -391,6 +393,9 @@ class CGameSA : public CGame
391393
void SetJetpackWeaponEnabled(eWeaponType weaponType, bool bEnabled);
392394
bool GetJetpackWeaponEnabled(eWeaponType weaponType);
393395

396+
void SetVehicleSunGlareEnabled(bool bEnabled);
397+
bool IsVehicleSunGlareEnabled();
398+
394399
unsigned long GetMinuteDuration();
395400
void SetMinuteDuration(unsigned long ulTime);
396401

Client/game_sa/CVehicleSA.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ bool g_bVehiclePointerInvalid = false;
1616

1717
#include "gamesa_renderware.h"
1818

19+
static BOOL m_bVehicleSunGlare = false;
20+
_declspec(naked) void DoVehicleSunGlare(void* this_)
21+
{
22+
_asm {
23+
mov eax, FUNC_CVehicle_DoSunGlare
24+
jmp eax
25+
}
26+
}
27+
28+
void _declspec(naked) HOOK_Vehicle_PreRender(void)
29+
{
30+
_asm {
31+
mov ecx, m_bVehicleSunGlare
32+
cmp ecx, 0
33+
jle noglare
34+
mov ecx, esi
35+
call DoVehicleSunGlare
36+
noglare:
37+
mov [esp+0D4h], edi
38+
push 6ABD04h
39+
retn
40+
}
41+
}
42+
1943
namespace
2044
{
2145
bool ClumpDumpCB(RpAtomic* pAtomic, void* data)
@@ -2318,6 +2342,22 @@ void CVehicleSA::OnChangingPosition(const CVector& vecNewPosition)
23182342
}
23192343
}
23202344

2345+
void CVehicleSA::StaticSetHooks()
2346+
{
2347+
// Setup vehicle sun glare hook
2348+
HookInstall(FUNC_CAutomobile_OnVehiclePreRender, (DWORD)HOOK_Vehicle_PreRender, 5);
2349+
}
2350+
2351+
void CVehicleSA::SetVehiclesSunGlareEnable(bool bEnabled)
2352+
{
2353+
m_bVehicleSunGlare = bEnabled;
2354+
}
2355+
2356+
bool CVehicleSA::GetVehiclesSunGlareEnable()
2357+
{
2358+
return m_bVehicleSunGlare;
2359+
}
2360+
23212361
namespace
23222362
{
23232363
VOID _MatrixConvertFromEulerAngles(CMatrix_Padded* matrixPadded, float fX, float fY, float fZ)

Client/game_sa/CVehicleSA.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ class CVehicleSA;
164164
#define VAR_CVehicle_Variation1 0x8A6458
165165
#define VAR_CVehicle_Variation2 0x8A6459
166166

167+
// for vehicle sun glare
168+
#define FUNC_CAutomobile_OnVehiclePreRender 0x6ABCFD
169+
#define FUNC_CVehicle_DoSunGlare 0x6DD6F0
170+
167171
struct SRailNodeSA
168172
{
169173
short sX; // x coordinate times 8
@@ -769,6 +773,10 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
769773
CVector* GetDummyPositions() { return m_dummyPositions.data(); }
770774
const CVector* GetDummyPositions() const override { return m_dummyPositions.data(); }
771775

776+
static void StaticSetHooks();
777+
static void SetVehiclesSunGlareEnable(bool bEnabled);
778+
static bool GetVehiclesSunGlareEnable();
779+
772780
private:
773781
static void SetAutomobileDummyPosition(CAutomobileSAInterface* automobile, eVehicleDummies dummy, const CVector& position);
774782

0 commit comments

Comments
 (0)