Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4387,6 +4387,9 @@ void CSettings::SaveData()
if (CGUIListItem* pQualitySelected = m_pComboFxQuality->GetSelectedItem())
{
gameSettings->SetFXQuality((int)pQualitySelected->GetData());

// Update grass draw distance to reflect new FX quality setting
g_pCore->GetMultiplayer()->RefreshGrassDrawDistance();
}

// Aspect ratio
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6998,6 +6998,7 @@ void CClientGame::ResetWorldProperties(const ResetWorldPropsInfo& resetPropsInfo
g_pMultiplayer->ResetSunSize();
g_pMultiplayer->RestoreWindVelocity();
g_pMultiplayer->ResetColorFilter();
g_pMultiplayer->ResetGrassDrawDistance();

g_pGame->GetWeather()->ResetAmountOfRain();
}
Expand Down
13 changes: 13 additions & 0 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,19 @@ void CPacketHandler::Packet_MapInfo(NetBitStreamInterface& bitStream)
bitStream.ReadBit(bOcclusionsEnabled);

g_pGame->GetWorld()->SetOcclusionsEnabled(bOcclusionsEnabled);

// Grass draw distance
bool overrideGrassDrawDistance = false;
float grassCloseDistance, grassFarDistance;
if (!bitStream.ReadBit(overrideGrassDrawDistance))
return;
if (overrideGrassDrawDistance)
{
if (!bitStream.Read(grassCloseDistance) || !bitStream.Read(grassFarDistance))
return;

g_pMultiplayer->SetGrassDrawDistance(grassCloseDistance, grassFarDistance);
}
}

void CPacketHandler::Packet_PartialPacketInfo(NetBitStreamInterface& bitStream)
Expand Down
24 changes: 23 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ void CLuaWorldDefs::LoadFunctions()
{"isTimeFrozen", ArgumentParser<IsTimeFrozen>},
{"isVolumetricShadowsEnabled", ArgumentParser<IsVolumetricShadowsEnabled>},
{"isDynamicPedShadowsEnabled", ArgumentParser<IsDynamicPedShadowsEnabled>},
{"testSphereAgainstWorld", ArgumentParser<TestSphereAgainstWorld>}};
{"testSphereAgainstWorld", ArgumentParser<TestSphereAgainstWorld>},

// Grass draw distance functions
{"getGrassDrawDistance", ArgumentParser<GetGrassDrawDistance>},
{"setGrassDrawDistance", ArgumentParser<SetGrassDrawDistance>},
{"resetGrassDrawDistance", ArgumentParser<ResetGrassDrawDistance>}};

// Add functions
for (const auto& [name, func] : functions)
Expand Down Expand Up @@ -1818,6 +1823,23 @@ int CLuaWorldDefs::ResetFogDistance(lua_State* luaVM)
return 1;
}

CLuaMultiReturn<float, float> CLuaWorldDefs::GetGrassDrawDistance()
{
float closeDistance, farDistance;
g_pMultiplayer->GetGrassDrawDistance(closeDistance, farDistance);
return {closeDistance, farDistance};
}

void CLuaWorldDefs::SetGrassDrawDistance(float closeDistance, float farDistance)
{
g_pMultiplayer->SetGrassDrawDistance(closeDistance, farDistance);
}

void CLuaWorldDefs::ResetGrassDrawDistance()
{
g_pMultiplayer->ResetGrassDrawDistance();
}

int CLuaWorldDefs::GetSunColor(lua_State* luaVM)
{
unsigned char ucCoreRed, ucCoreGreen, ucCoreBlue, ucCoronaRed, ucCoronaGreen, ucCoronaBlue;
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class CLuaWorldDefs : public CLuaDefs
LUA_DECLARE(GetFogDistance);
LUA_DECLARE(SetFogDistance);
LUA_DECLARE(ResetFogDistance);
static CLuaMultiReturn<float, float> GetGrassDrawDistance();
static void SetGrassDrawDistance(float closeDistance, float farDistance);
static void ResetGrassDrawDistance();
LUA_DECLARE(GetSunColor);
LUA_DECLARE(SetSunColor);
LUA_DECLARE(ResetSunColor);
Expand Down
18 changes: 18 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ void CWorldRPCs::LoadFunctions()
AddHandler(SET_WORLD_SPECIAL_PROPERTY, SetWorldSpecialPropertyEnabled, "SetWorldSpecialPropertyEnabled");

AddHandler(RESET_WORLD_PROPERTIES, ResetWorldProperties, "ResetWorldProperties");

AddHandler(SET_GRASS_DRAW_DISTANCE, SetGrassDrawDistance, "SetGrassDrawDistance");
AddHandler(RESET_GRASS_DRAW_DISTANCE, ResetGrassDrawDistance, "ResetGrassDrawDistance");
}

void CWorldRPCs::SetTime(NetBitStreamInterface& bitStream)
Expand Down Expand Up @@ -354,6 +357,16 @@ void CWorldRPCs::SetFogDistance(NetBitStreamInterface& bitStream)
}
}

void CWorldRPCs::SetGrassDrawDistance(NetBitStreamInterface& bitStream)
{
float closeDistance, farDistance;

if (bitStream.Read(closeDistance) && bitStream.Read(farDistance))
{
g_pMultiplayer->SetGrassDrawDistance(closeDistance, farDistance);
}
}

void CWorldRPCs::SetAircraftMaxHeight(NetBitStreamInterface& bitStream)
{
float fMaxHeight;
Expand Down Expand Up @@ -414,6 +427,11 @@ void CWorldRPCs::ResetFogDistance(NetBitStreamInterface& bitStream)
g_pMultiplayer->RestoreFogDistance();
}

void CWorldRPCs::ResetGrassDrawDistance(NetBitStreamInterface& bitStream)
{
g_pMultiplayer->ResetGrassDrawDistance();
}

void CWorldRPCs::SetWeaponProperty(NetBitStreamInterface& bitStream)
{
unsigned char ucWeapon = 0;
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CWorldRPCs.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ class CWorldRPCs : public CRPCFunctions
DECLARE_RPC(SetSyncIntervals);
DECLARE_RPC(SetWorldSpecialPropertyEnabled);
DECLARE_RPC(ResetWorldProperties);
DECLARE_RPC(SetGrassDrawDistance);
DECLARE_RPC(ResetGrassDrawDistance);
};
51 changes: 51 additions & 0 deletions Client/multiplayer_sa/CMultiplayerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <game/CPedDamageResponse.h>
#include <game/CEventList.h>
#include <game/CEventDamage.h>
#include <game/CSettings.h>

class CEventDamageSAInterface;

Expand Down Expand Up @@ -594,6 +595,8 @@ CMultiplayerSA::CMultiplayerSA()
m_fMaddDoggPoolLevel = 1082.73f;
m_dwLastStaticAnimGroupID = eAnimGroup::ANIM_GROUP_DEFAULT;
m_dwLastStaticAnimID = eAnimID::ANIM_ID_WALK;
m_grassCloseDistance = DEFAULT_GRASS_CLOSE_DISTANCE;
m_grassFarDistance = DEFAULT_GRASS_FAR_DISTANCE;
}

CMultiplayerSA::~CMultiplayerSA()
Expand Down Expand Up @@ -2064,6 +2067,54 @@ void CMultiplayerSA::RestoreFogDistance()
}
}

void CMultiplayerSA::SetGrassDrawDistance(float closeDistance, float farDistance)
{
// Store unscaled values
m_grassCloseDistance = closeDistance;
m_grassFarDistance = farDistance;

// Apply FX quality scaling
CGameSettings* pSettings = pGameInterface ? pGameInterface->GetSettings() : nullptr;
const unsigned int fxQuality = pSettings ? pSettings->GetFXQuality() : 2;

if (fxQuality)
farDistance /= 2.0f;

MemPutFast<float>(VAR_CGrassCloseDist, closeDistance);
MemPutFast<float>(VAR_CGrassFarDist, farDistance);
}

void CMultiplayerSA::GetGrassDrawDistance(float& closeDistance, float& farDistance) const
{
closeDistance = *(float*)VAR_CGrassCloseDist;
farDistance = *(float*)VAR_CGrassFarDist;
}

void CMultiplayerSA::ResetGrassDrawDistance()
{
// Store unscaled default values
m_grassCloseDistance = DEFAULT_GRASS_CLOSE_DISTANCE;
m_grassFarDistance = DEFAULT_GRASS_FAR_DISTANCE;

// Apply FX quality scaling
CGameSettings* pSettings = pGameInterface ? pGameInterface->GetSettings() : nullptr;
const unsigned int fxQuality = pSettings ? pSettings->GetFXQuality() : 2;

float farDistance = DEFAULT_GRASS_FAR_DISTANCE;

if (fxQuality)
farDistance /= 2.0f;

MemPutFast<float>(VAR_CGrassCloseDist, DEFAULT_GRASS_CLOSE_DISTANCE);
MemPutFast<float>(VAR_CGrassFarDist, farDistance);
}

void CMultiplayerSA::RefreshGrassDrawDistance()
{
// Re-apply stored grass distances with current FX quality
SetGrassDrawDistance(m_grassCloseDistance, m_grassFarDistance);
}

void CMultiplayerSA::GetSunColor(unsigned char& ucCoreRed, unsigned char& ucCoreGreen, unsigned char& ucCoreBlue, unsigned char& ucCoronaRed,
unsigned char& ucCoronaGreen, unsigned char& ucCoronaBlue)
{
Expand Down
11 changes: 11 additions & 0 deletions Client/multiplayer_sa/CMultiplayerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
class CRemoteDataSA;
#define DEFAULT_NEAR_CLIP_DISTANCE ( 0.3f )
#define DEFAULT_SHADOWS_OFFSET ( 0.013f ) // GTA default = 0.06f
#define DEFAULT_GRASS_CLOSE_DISTANCE ( 3.0f )
#define DEFAULT_GRASS_FAR_DISTANCE ( 60.0f )

#define VAR_CGrassCloseDist 0xC02DBC
#define VAR_CGrassFarDist 0x8D132C

enum eRadioStationID
{
Expand Down Expand Up @@ -192,6 +197,10 @@ void InitHooks();
float GetFogDistance();
void SetFogDistance(float fDistance);
void RestoreFogDistance();
void SetGrassDrawDistance(float closeDistance, float farDistance) override;
void GetGrassDrawDistance(float& closeDistance, float& farDistance) const override;
void ResetGrassDrawDistance() override;
void RefreshGrassDrawDistance() override;
void GetSunColor(unsigned char& ucCoreRed, unsigned char& ucCoreGreen, unsigned char& ucCoreBlue, unsigned char& ucCoronaRed, unsigned char& ucCoronaGreen,
unsigned char& ucCoronaBlue);
void SetSunColor(unsigned char ucCoreRed, unsigned char ucCoreGreen, unsigned char ucCoreBlue, unsigned char ucCoronaRed, unsigned char ucCoronaGreen,
Expand Down Expand Up @@ -391,6 +400,8 @@ void InitHooks();
eAnimID m_dwLastStaticAnimID;
DWORD m_dwLastAnimArrayAddress;
float m_fShadowsOffset;
float m_grassCloseDistance;
float m_grassFarDistance;

bool m_isRapidVehicleStopFixEnabled{false};

Expand Down
4 changes: 4 additions & 0 deletions Client/sdk/multiplayer/CMultiplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ class CMultiplayer
virtual void SetFogDistance(float fDistance) = 0;
virtual float GetFogDistance() = 0;
virtual void RestoreFogDistance() = 0;
virtual void SetGrassDrawDistance(float closeDistance, float farDistance) = 0;
virtual void GetGrassDrawDistance(float& closeDistance, float& farDistance) const = 0;
virtual void ResetGrassDrawDistance() = 0;
virtual void RefreshGrassDrawDistance() = 0;
virtual void GetSunColor(unsigned char& ucCoreRed, unsigned char& ucCoreGreen, unsigned char& ucCoreBlue, unsigned char& ucCoronaRed,
unsigned char& ucCoronaGreen, unsigned char& ucCoronaBlue) = 0;
virtual void SetSunColor(unsigned char ucCoreRed, unsigned char ucCoreGreen, unsigned char ucCoreBlue, unsigned char ucCoronaRed,
Expand Down
3 changes: 3 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ CGame::CGame() : m_FloodProtect(4, 30000, 30000) // Max of 4 connecti
m_bOverrideWindVelocity = false;
m_bOverrideFarClip = false;
m_bOverrideFogDistance = false;
m_overrideGrassDrawDistance = false;
m_grassCloseDistance = 3.0f;
m_grassFarDistance = 60.0f;
m_bOverrideMoonSize = false;

m_pASE = NULL;
Expand Down
18 changes: 18 additions & 0 deletions Server/mods/deathmatch/logic/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ class CGame
float GetFogDistance() { return m_fFogDistance; }
void SetFogDistance(float& fFogDistance) { m_fFogDistance = fFogDistance; }

bool HasGrassDrawDistance() const noexcept { return m_overrideGrassDrawDistance; }
void SetHasGrassDrawDistance(bool overrideGrassDrawDistance) noexcept { m_overrideGrassDrawDistance = overrideGrassDrawDistance; }

void GetGrassDrawDistance(float& closeDistance, float& farDistance) const noexcept
{
closeDistance = m_grassCloseDistance;
farDistance = m_grassFarDistance;
}
void SetGrassDrawDistance(float closeDistance, float farDistance) noexcept
{
m_grassCloseDistance = closeDistance;
m_grassFarDistance = farDistance;
}

float GetAircraftMaxHeight() { return m_fAircraftMaxHeight; }
void SetAircraftMaxHeight(float fMaxHeight) { m_fAircraftMaxHeight = fMaxHeight; }

Expand Down Expand Up @@ -640,6 +654,10 @@ class CGame
bool m_bOverrideFogDistance;
float m_fFogDistance;

bool m_overrideGrassDrawDistance;
float m_grassCloseDistance;
float m_grassFarDistance;

SGarageStates m_bGarageStates;

// FPS statistics
Expand Down
8 changes: 7 additions & 1 deletion Server/mods/deathmatch/logic/CMapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ void CMapManager::OnPlayerJoin(CPlayer& Player)
bool bOverrideFogDistance = g_pGame->HasFogDistance();
float fFogDistance = g_pGame->GetFogDistance();

// Grass draw distance
bool overrideGrassDrawDistance = g_pGame->HasGrassDrawDistance();
float grassCloseDistance, grassFarDistance;
g_pGame->GetGrassDrawDistance(grassCloseDistance, grassFarDistance);

marker.Set("FirstBit");

// Send the packet to the given player
Expand All @@ -528,7 +533,8 @@ void CMapManager::OnPlayerJoin(CPlayer& Player)
fJetpackMaxHeight, bOverrideWaterColor, ucWaterRed, ucWaterGreen, ucWaterBlue, ucWaterAlpha, bInteriorSoundsEnabled,
bOverrideRainLevel, fRainLevel, bOverrideSunSize, fSunSize, bOverrideSunColor, ucCoreR, ucCoreG, ucCoreB, ucCoronaR, ucCoronaG,
ucCoronaB, bOverrideWindVelocity, fWindVelX, fWindVelY, fWindVelZ, bOverrideFarClipDistance, fFarClip, bOverrideFogDistance,
fFogDistance, fAircraftMaxHeight, fAircraftMaxVelocity, bOverrideMoonSize, iMoonSize));
fFogDistance, fAircraftMaxHeight, fAircraftMaxVelocity, bOverrideMoonSize, iMoonSize, overrideGrassDrawDistance, grassCloseDistance,
grassFarDistance));

marker.Set("SendMapInfoPacket");

Expand Down
30 changes: 30 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10710,6 +10710,17 @@ bool CStaticFunctionDefinitions::GetFogDistance(float& fFogDist)
return false;
}

bool CStaticFunctionDefinitions::GetGrassDrawDistance(float& closeDistance, float& farDistance)
{
if (g_pGame->HasGrassDrawDistance())
{
g_pGame->GetGrassDrawDistance(closeDistance, farDistance);
return true;
}

return false;
}

bool CStaticFunctionDefinitions::GetAircraftMaxHeight(float& fMaxHeight)
{
fMaxHeight = g_pGame->GetAircraftMaxHeight();
Expand Down Expand Up @@ -10894,6 +10905,17 @@ bool CStaticFunctionDefinitions::SetFogDistance(float fFogDist)
return true;
}

void CStaticFunctionDefinitions::SetGrassDrawDistance(float closeDistance, float farDistance)
{
g_pGame->SetGrassDrawDistance(closeDistance, farDistance);
g_pGame->SetHasGrassDrawDistance(true);

CBitStream BitStream;
BitStream.pBitStream->Write(closeDistance);
BitStream.pBitStream->Write(farDistance);
m_pPlayerManager->BroadcastOnlyJoined(CLuaPacket(SET_GRASS_DRAW_DISTANCE, *BitStream.pBitStream));
}

bool CStaticFunctionDefinitions::SetAircraftMaxHeight(float fMaxHeight)
{
g_pGame->SetAircraftMaxHeight(fMaxHeight);
Expand Down Expand Up @@ -10986,6 +11008,14 @@ bool CStaticFunctionDefinitions::ResetFogDistance()
return true;
}

void CStaticFunctionDefinitions::ResetGrassDrawDistance()
{
g_pGame->SetHasGrassDrawDistance(false);

CBitStream BitStream;
m_pPlayerManager->BroadcastOnlyJoined(CLuaPacket(RESET_GRASS_DRAW_DISTANCE, *BitStream.pBitStream));
}

bool CStaticFunctionDefinitions::RemoveWorldModel(unsigned short usModel, float fRadius, const CVector& vecPosition, char cInterior)
{
g_pGame->GetBuildingRemovalManager()->CreateBuildingRemoval(usModel, fRadius, vecPosition, cInterior);
Expand Down
3 changes: 3 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ class CStaticFunctionDefinitions
static bool GetWindVelocity(float& fVelX, float& fVelY, float& fVelZ);
static bool GetFarClipDistance(float& fFarClip);
static bool GetFogDistance(float& fFogDist);
static bool GetGrassDrawDistance(float& closeDistance, float& farDistance);
static bool GetAircraftMaxHeight(float& fMaxHeight);
static bool GetOcclusionsEnabled(bool& bEnabled);
static bool GetMoonSize(int& iSize);
Expand Down Expand Up @@ -644,6 +645,7 @@ class CStaticFunctionDefinitions
static bool SetWindVelocity(float fVelX, float fVelY, float fVelZ);
static bool SetFarClipDistance(float fFarClip);
static bool SetFogDistance(float fFogDist);
static void SetGrassDrawDistance(float closeDistance, float farDistance);
static bool SetAircraftMaxHeight(float fMaxHeight);
static bool SetAircraftMaxVelocity(float fVelocity);
static bool SetOcclusionsEnabled(bool bEnabled);
Expand All @@ -653,6 +655,7 @@ class CStaticFunctionDefinitions
static bool ResetWindVelocity();
static bool ResetFarClipDistance();
static bool ResetFogDistance();
static void ResetGrassDrawDistance();
static bool RemoveWorldModel(unsigned short usModel, float fRadius, const CVector& vecPosition, char cInterior);
static bool RestoreWorldModel(unsigned short usModel, float fRadius, const CVector& vecPosition, char cInterior);
static bool RestoreAllWorldModels();
Expand Down
Loading