Skip to content

Commit b8b7ce5

Browse files
authored
Freeze Time functions (#3567)
1 parent 008eaa7 commit b8b7ce5

File tree

7 files changed

+58
-3
lines changed

7 files changed

+58
-3
lines changed

Client/game_sa/CClockSA.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ void CClockSA::Get(BYTE* bHour, BYTE* bMinute)
3030
*bMinute = *(BYTE*)VAR_TimeMinutes;
3131
*bHour = *(BYTE*)VAR_TimeHours;
3232
}
33+
34+
bool CClockSA::SetTimeFrozen(bool value) noexcept
35+
{
36+
if (value)
37+
MemSet((void*)0x53BFBD, 0x90, 5);
38+
else
39+
MemCpy((void*)0x53BFBD, "\xE8\x4E\x0F\xFF\xFF", 5);
40+
41+
m_bTimeCycleFrozen = value;
42+
return true;
43+
}
44+
45+
bool CClockSA::ResetTimeFrozen() noexcept
46+
{
47+
return SetTimeFrozen(false);
48+
}

Client/game_sa/CClockSA.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ class CClockSA : public CClock
2222
public:
2323
void Set(BYTE bHour, BYTE bMinute);
2424
void Get(BYTE* bHour, BYTE* bMinute);
25+
26+
bool SetTimeFrozen(bool value) noexcept;
27+
bool IsTimeFrozen() const noexcept { return m_bTimeCycleFrozen; };
28+
bool ResetTimeFrozen() noexcept;
29+
30+
private:
31+
bool m_bTimeCycleFrozen;
2532
};

Client/game_sa/CWeatherSA.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,4 @@ class CWeatherSA : public CWeather
6060
static unsigned char* VAR_CWeather__OldWeatherType;
6161
static unsigned char* VAR_CWeather__NewWeatherType;
6262
static float* VAR_CWeather__Rain;
63-
6463
};

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <game/CWeather.h>
3434
#include <game/Task.h>
3535
#include <game/CBuildingRemoval.h>
36+
#include "game/CClock.h"
3637
#include <windowsx.h>
3738
#include "CServerInfo.h"
3839

@@ -5408,6 +5409,7 @@ void CClientGame::ResetMapInfo()
54085409

54095410
// Hud
54105411
g_pGame->GetHud()->SetComponentVisible(HUD_ALL, true);
5412+
54115413
// Disable area names as they are on load until camera unfades
54125414
g_pGame->GetHud()->SetComponentVisible(HUD_AREA_NAME, false);
54135415
g_pGame->GetHud()->SetComponentVisible(HUD_VITAL_STATS, false);
@@ -5548,6 +5550,9 @@ void CClientGame::ResetMapInfo()
55485550
// Disable the change of any player stats
55495551
g_pMultiplayer->SetLocalStatsStatic(true);
55505552

5553+
// Reset Frozen Time
5554+
g_pGame->GetClock()->ResetTimeFrozen();
5555+
55515556
// Close all garages
55525557
CGarage* pGarage = NULL;
55535558
CGarages* pGarages = g_pCore->GetGame()->GetGarages();

Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <game/CWeather.h>
1313
#include <game/CColPoint.h>
1414
#include <game/CCoronas.h>
15+
#include <game/CClock.h>
1516
#include "lua/CLuaFunctionParser.h"
1617

1718
void CLuaWorldDefs::LoadFunctions()
@@ -103,6 +104,7 @@ void CLuaWorldDefs::LoadFunctions()
103104
{"removeWorldModel", RemoveWorldBuilding},
104105
{"restoreAllWorldModels", RestoreWorldBuildings},
105106
{"restoreWorldModel", RestoreWorldBuilding},
107+
{"setTimeFrozen", ArgumentParser<SetTimeFrozen>},
106108

107109
// World create funcs
108110
{"createSWATRope", CreateSWATRope},
@@ -125,13 +127,15 @@ void CLuaWorldDefs::LoadFunctions()
125127
{"resetMoonSize", ResetMoonSize},
126128
{"resetBlurLevel", ResetBlurLevel},
127129
{"resetWorldProperty", ArgumentParserWarn<false, ResetWorldProperty>},
130+
{"resetTimeFrozen", ArgumentParser<ResetTimeFrozen>},
128131

129132
// World check funcs
130133
{"areTrafficLightsLocked", AreTrafficLightsLocked},
131134
{"isPedTargetingMarkerEnabled", IsPedTargetingMarkerEnabled},
132135
{"isLineOfSightClear", IsLineOfSightClear},
133136
{"isWorldSpecialPropertyEnabled", ArgumentParserWarn<false, IsWorldSpecialPropertyEnabled>},
134-
{"isGarageOpen", IsGarageOpen}};
137+
{"isGarageOpen", IsGarageOpen},
138+
{"isTimeFrozen", ArgumentParser<IsTimeFrozen>}};
135139

136140
// Add functions
137141
for (const auto& [name, func] : functions)
@@ -2234,3 +2238,18 @@ bool CLuaWorldDefs::ResetWorldProperty(eWorldProperty property)
22342238
}
22352239
return false;
22362240
}
2241+
2242+
bool CLuaWorldDefs::SetTimeFrozen(bool value) noexcept
2243+
{
2244+
return g_pGame->GetClock()->SetTimeFrozen(value);
2245+
}
2246+
2247+
bool CLuaWorldDefs::IsTimeFrozen() noexcept
2248+
{
2249+
return g_pGame->GetClock()->IsTimeFrozen();
2250+
}
2251+
2252+
bool CLuaWorldDefs::ResetTimeFrozen() noexcept
2253+
{
2254+
return g_pGame->GetClock()->ResetTimeFrozen();
2255+
}

Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,9 @@ class CLuaWorldDefs : public CLuaDefs
130130
static std::variant<bool, float, CLuaMultiReturn<float, float, float>> GetWorldProperty(eWorldProperty property);
131131
static bool SetWorldProperty(eWorldProperty property, float arg1, std::optional<float> arg2, std::optional<float> arg3);
132132
static bool ResetWorldProperty(eWorldProperty property);
133-
};
133+
134+
static bool SetTimeFrozen(bool value) noexcept;
135+
static bool IsTimeFrozen() noexcept;
136+
static bool ResetTimeFrozen() noexcept;
137+
};
138+

Client/sdk/game/CClock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ class CClock
1616
public:
1717
virtual void Set(BYTE bHour, BYTE bMinute) = 0;
1818
virtual void Get(BYTE* bHour, BYTE* bMinute) = 0;
19+
20+
virtual bool SetTimeFrozen(bool value) noexcept = 0;
21+
virtual bool IsTimeFrozen() const noexcept = 0;
22+
virtual bool ResetTimeFrozen() noexcept = 0;
1923
};

0 commit comments

Comments
 (0)