Skip to content

Commit ce202ae

Browse files
committed
Initial commit of grass set/get feature
1 parent c757a89 commit ce202ae

File tree

19 files changed

+201
-3
lines changed

19 files changed

+201
-3
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6985,6 +6985,7 @@ void CClientGame::ResetWorldProperties(const ResetWorldPropsInfo& resetPropsInfo
69856985
g_pMultiplayer->ResetSunSize();
69866986
g_pMultiplayer->RestoreWindVelocity();
69876987
g_pMultiplayer->ResetColorFilter();
6988+
g_pMultiplayer->ResetGrassDrawDistance();
69886989

69896990
g_pGame->GetWeather()->ResetAmountOfRain();
69906991
}

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,19 @@ void CPacketHandler::Packet_MapInfo(NetBitStreamInterface& bitStream)
25442544
g_pMultiplayer->SetFogDistance(fFogDistance);
25452545
}
25462546

2547+
// Grass draw distance
2548+
bool bOverrideGrassDrawDistance = false;
2549+
float fGrassCloseDistance, fGrassFarDistance;
2550+
if (!bitStream.ReadBit(bOverrideGrassDrawDistance))
2551+
return;
2552+
if (bOverrideGrassDrawDistance)
2553+
{
2554+
if (!bitStream.Read(fGrassCloseDistance) || !bitStream.Read(fGrassFarDistance))
2555+
return;
2556+
2557+
g_pMultiplayer->SetGrassDrawDistance(fGrassCloseDistance, fGrassFarDistance);
2558+
}
2559+
25472560
// Aircraft max height
25482561
float fAircraftMaxHeight = 800;
25492562
if (!bitStream.Read(fAircraftMaxHeight))

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ void CLuaWorldDefs::LoadFunctions()
149149
{"isTimeFrozen", ArgumentParser<IsTimeFrozen>},
150150
{"isVolumetricShadowsEnabled", ArgumentParser<IsVolumetricShadowsEnabled>},
151151
{"isDynamicPedShadowsEnabled", ArgumentParser<IsDynamicPedShadowsEnabled>},
152-
{"testSphereAgainstWorld", ArgumentParser<TestSphereAgainstWorld>}};
152+
{"testSphereAgainstWorld", ArgumentParser<TestSphereAgainstWorld>},
153+
154+
// Grass draw distance functions
155+
{"getGrassDrawDistance", ArgumentParser<GetGrassDrawDistance>},
156+
{"setGrassDrawDistance", ArgumentParser<SetGrassDrawDistance>},
157+
{"resetGrassDrawDistance", ArgumentParser<ResetGrassDrawDistance>}};
153158

154159
// Add functions
155160
for (const auto& [name, func] : functions)
@@ -1818,6 +1823,25 @@ int CLuaWorldDefs::ResetFogDistance(lua_State* luaVM)
18181823
return 1;
18191824
}
18201825

1826+
CLuaMultiReturn<float, float> CLuaWorldDefs::GetGrassDrawDistance()
1827+
{
1828+
float fCloseDistance, fFarDistance;
1829+
g_pMultiplayer->GetGrassDrawDistance(fCloseDistance, fFarDistance);
1830+
return {fCloseDistance, fFarDistance};
1831+
}
1832+
1833+
bool CLuaWorldDefs::SetGrassDrawDistance(float closeDistance, float farDistance)
1834+
{
1835+
g_pMultiplayer->SetGrassDrawDistance(closeDistance, farDistance);
1836+
return true;
1837+
}
1838+
1839+
bool CLuaWorldDefs::ResetGrassDrawDistance()
1840+
{
1841+
g_pMultiplayer->ResetGrassDrawDistance();
1842+
return true;
1843+
}
1844+
18211845
int CLuaWorldDefs::GetSunColor(lua_State* luaVM)
18221846
{
18231847
unsigned char ucCoreRed, ucCoreGreen, ucCoreBlue, ucCoronaRed, ucCoronaGreen, ucCoronaBlue;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class CLuaWorldDefs : public CLuaDefs
9090
LUA_DECLARE(GetFogDistance);
9191
LUA_DECLARE(SetFogDistance);
9292
LUA_DECLARE(ResetFogDistance);
93+
static CLuaMultiReturn<float, float> GetGrassDrawDistance();
94+
static bool SetGrassDrawDistance(float closeDistance, float farDistance);
95+
static bool ResetGrassDrawDistance();
9396
LUA_DECLARE(GetSunColor);
9497
LUA_DECLARE(SetSunColor);
9598
LUA_DECLARE(ResetSunColor);

Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ void CWorldRPCs::LoadFunctions()
7373
AddHandler(SET_WORLD_SPECIAL_PROPERTY, SetWorldSpecialPropertyEnabled, "SetWorldSpecialPropertyEnabled");
7474

7575
AddHandler(RESET_WORLD_PROPERTIES, ResetWorldProperties, "ResetWorldProperties");
76+
77+
AddHandler(SET_GRASS_DRAW_DISTANCE, SetGrassDrawDistance, "SetGrassDrawDistance");
78+
AddHandler(RESET_GRASS_DRAW_DISTANCE, ResetGrassDrawDistance, "ResetGrassDrawDistance");
7679
}
7780

7881
void CWorldRPCs::SetTime(NetBitStreamInterface& bitStream)
@@ -354,6 +357,16 @@ void CWorldRPCs::SetFogDistance(NetBitStreamInterface& bitStream)
354357
}
355358
}
356359

360+
void CWorldRPCs::SetGrassDrawDistance(NetBitStreamInterface& bitStream)
361+
{
362+
float fCloseDistance, fFarDistance;
363+
364+
if (bitStream.Read(fCloseDistance) && bitStream.Read(fFarDistance))
365+
{
366+
g_pMultiplayer->SetGrassDrawDistance(fCloseDistance, fFarDistance);
367+
}
368+
}
369+
357370
void CWorldRPCs::SetAircraftMaxHeight(NetBitStreamInterface& bitStream)
358371
{
359372
float fMaxHeight;
@@ -414,6 +427,11 @@ void CWorldRPCs::ResetFogDistance(NetBitStreamInterface& bitStream)
414427
g_pMultiplayer->RestoreFogDistance();
415428
}
416429

430+
void CWorldRPCs::ResetGrassDrawDistance(NetBitStreamInterface& bitStream)
431+
{
432+
g_pMultiplayer->ResetGrassDrawDistance();
433+
}
434+
417435
void CWorldRPCs::SetWeaponProperty(NetBitStreamInterface& bitStream)
418436
{
419437
unsigned char ucWeapon = 0;

Client/mods/deathmatch/logic/rpc/CWorldRPCs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ class CWorldRPCs : public CRPCFunctions
6666
DECLARE_RPC(SetSyncIntervals);
6767
DECLARE_RPC(SetWorldSpecialPropertyEnabled);
6868
DECLARE_RPC(ResetWorldProperties);
69+
DECLARE_RPC(SetGrassDrawDistance);
70+
DECLARE_RPC(ResetGrassDrawDistance);
6971
};

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,24 @@ void CMultiplayerSA::RestoreFogDistance()
20642064
}
20652065
}
20662066

2067+
void CMultiplayerSA::SetGrassDrawDistance(float fCloseDistance, float fFarDistance)
2068+
{
2069+
MemPutFast<float>(0xC02DBC, fCloseDistance);
2070+
MemPutFast<float>(0x8D132C, fFarDistance);
2071+
}
2072+
2073+
void CMultiplayerSA::GetGrassDrawDistance(float& fCloseDistance, float& fFarDistance) const
2074+
{
2075+
fCloseDistance = *(float*)0xC02DBC;
2076+
fFarDistance = *(float*)0x8D132C;
2077+
}
2078+
2079+
void CMultiplayerSA::ResetGrassDrawDistance()
2080+
{
2081+
MemPutFast<float>(0xC02DBC, 3.0f);
2082+
MemPutFast<float>(0x8D132C, 60.0f);
2083+
}
2084+
20672085
void CMultiplayerSA::GetSunColor(unsigned char& ucCoreRed, unsigned char& ucCoreGreen, unsigned char& ucCoreBlue, unsigned char& ucCoronaRed,
20682086
unsigned char& ucCoronaGreen, unsigned char& ucCoronaBlue)
20692087
{

Client/multiplayer_sa/CMultiplayerSA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ void InitHooks();
192192
float GetFogDistance();
193193
void SetFogDistance(float fDistance);
194194
void RestoreFogDistance();
195+
void SetGrassDrawDistance(float fCloseDistance, float fFarDistance);
196+
void GetGrassDrawDistance(float& fCloseDistance, float& fFarDistance) const;
197+
void ResetGrassDrawDistance();
195198
void GetSunColor(unsigned char& ucCoreRed, unsigned char& ucCoreGreen, unsigned char& ucCoreBlue, unsigned char& ucCoronaRed, unsigned char& ucCoronaGreen,
196199
unsigned char& ucCoronaBlue);
197200
void SetSunColor(unsigned char ucCoreRed, unsigned char ucCoreGreen, unsigned char ucCoreBlue, unsigned char ucCoronaRed, unsigned char ucCoronaGreen,

Client/sdk/multiplayer/CMultiplayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ class CMultiplayer
299299
virtual void SetFogDistance(float fDistance) = 0;
300300
virtual float GetFogDistance() = 0;
301301
virtual void RestoreFogDistance() = 0;
302+
virtual void SetGrassDrawDistance(float fCloseDistance, float fFarDistance) = 0;
303+
virtual void GetGrassDrawDistance(float& fCloseDistance, float& fFarDistance) const = 0;
304+
virtual void ResetGrassDrawDistance() = 0;
302305
virtual void GetSunColor(unsigned char& ucCoreRed, unsigned char& ucCoreGreen, unsigned char& ucCoreBlue, unsigned char& ucCoronaRed,
303306
unsigned char& ucCoronaGreen, unsigned char& ucCoronaBlue) = 0;
304307
virtual void SetSunColor(unsigned char ucCoreRed, unsigned char ucCoreGreen, unsigned char ucCoreBlue, unsigned char ucCoronaRed,

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ CGame::CGame() : m_FloodProtect(4, 30000, 30000) // Max of 4 connecti
219219
m_bOverrideWindVelocity = false;
220220
m_bOverrideFarClip = false;
221221
m_bOverrideFogDistance = false;
222+
m_bOverrideGrassDrawDistance = false;
223+
m_fGrassCloseDistance = 3.0f;
224+
m_fGrassFarDistance = 60.0f;
222225
m_bOverrideMoonSize = false;
223226

224227
m_pASE = NULL;

0 commit comments

Comments
 (0)