Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect behavior of onPlayerChangesWorldSpecialProperty event #3994

Merged
merged 3 commits into from
Jan 30, 2025
Merged
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
43 changes: 18 additions & 25 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5998,74 +5998,66 @@ bool CClientGame::IsGlitchEnabled(unsigned char ucGlitch)
return ucGlitch < NUM_GLITCHES && m_Glitches[ucGlitch];
}

bool CClientGame::SetWorldSpecialProperty(WorldSpecialProperty property, bool isEnabled) noexcept
bool CClientGame::SetWorldSpecialProperty(const WorldSpecialProperty property, const bool enabled) noexcept
{
switch (property)
{
case WorldSpecialProperty::HOVERCARS:
case WorldSpecialProperty::AIRCARS:
case WorldSpecialProperty::EXTRABUNNY:
case WorldSpecialProperty::EXTRAJUMP:
g_pGame->SetCheatEnabled(EnumToString(property), isEnabled);
g_pGame->SetCheatEnabled(EnumToString(property), enabled);
break;
case WorldSpecialProperty::RANDOMFOLIAGE:
g_pGame->SetRandomFoliageEnabled(isEnabled);
g_pGame->SetRandomFoliageEnabled(enabled);
break;
case WorldSpecialProperty::SNIPERMOON:
g_pGame->SetMoonEasterEggEnabled(isEnabled);
g_pGame->SetMoonEasterEggEnabled(enabled);
break;
case WorldSpecialProperty::EXTRAAIRRESISTANCE:
g_pGame->SetExtraAirResistanceEnabled(isEnabled);
g_pGame->SetExtraAirResistanceEnabled(enabled);
break;
case WorldSpecialProperty::UNDERWORLDWARP:
g_pGame->SetUnderWorldWarpEnabled(isEnabled);
g_pGame->SetUnderWorldWarpEnabled(enabled);
break;
case WorldSpecialProperty::VEHICLESUNGLARE:
g_pGame->SetVehicleSunGlareEnabled(isEnabled);
g_pGame->SetVehicleSunGlareEnabled(enabled);
break;
case WorldSpecialProperty::CORONAZTEST:
g_pGame->SetCoronaZTestEnabled(isEnabled);
g_pGame->SetCoronaZTestEnabled(enabled);
break;
case WorldSpecialProperty::WATERCREATURES:
g_pGame->SetWaterCreaturesEnabled(isEnabled);
g_pGame->SetWaterCreaturesEnabled(enabled);
break;
case WorldSpecialProperty::BURNFLIPPEDCARS:
g_pGame->SetBurnFlippedCarsEnabled(isEnabled);
g_pGame->SetBurnFlippedCarsEnabled(enabled);
break;
case WorldSpecialProperty::FIREBALLDESTRUCT:
g_pGame->SetFireballDestructEnabled(isEnabled);
g_pGame->SetFireballDestructEnabled(enabled);
break;
case WorldSpecialProperty::EXTENDEDWATERCANNONS:
g_pGame->SetExtendedWaterCannonsEnabled(isEnabled);
g_pGame->SetExtendedWaterCannonsEnabled(enabled);
break;
case WorldSpecialProperty::ROADSIGNSTEXT:
g_pGame->SetRoadSignsTextEnabled(isEnabled);
g_pGame->SetRoadSignsTextEnabled(enabled);
break;
case WorldSpecialProperty::TUNNELWEATHERBLEND:
g_pGame->SetTunnelWeatherBlendEnabled(isEnabled);
g_pGame->SetTunnelWeatherBlendEnabled(enabled);
break;
case WorldSpecialProperty::IGNOREFIRESTATE:
g_pGame->SetIgnoreFireStateEnabled(isEnabled);
g_pGame->SetIgnoreFireStateEnabled(enabled);
break;
case WorldSpecialProperty::FLYINGCOMPONENTS:
m_pVehicleManager->SetSpawnFlyingComponentEnabled(isEnabled);
m_pVehicleManager->SetSpawnFlyingComponentEnabled(enabled);
break;
default:
return false;
}

if (g_pNet->CanServerBitStream(eBitStreamVersion::WorldSpecialPropertyEvent)) {
NetBitStreamInterface* stream = g_pNet->AllocateNetBitStream();
stream->WriteString(EnumToString(property));
stream->WriteBit(isEnabled);
g_pNet->SendPacket(PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY, stream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
g_pNet->DeallocateNetBitStream(stream);
}

return true;
}

bool CClientGame::IsWorldSpecialProperty(WorldSpecialProperty property)
bool CClientGame::IsWorldSpecialProperty(const WorldSpecialProperty property)
{
switch (property)
{
Expand Down Expand Up @@ -6103,6 +6095,7 @@ bool CClientGame::IsWorldSpecialProperty(WorldSpecialProperty property)
case WorldSpecialProperty::FLYINGCOMPONENTS:
return m_pVehicleManager->IsSpawnFlyingComponentEnabled();
}

return false;
}

Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ class CClientGame
bool SetGlitchEnabled(unsigned char cGlitch, bool bEnabled);
bool IsGlitchEnabled(unsigned char cGlitch);

bool SetWorldSpecialProperty(WorldSpecialProperty property, bool isEnabled) noexcept;
bool IsWorldSpecialProperty(WorldSpecialProperty property);
bool SetWorldSpecialProperty(const WorldSpecialProperty property, const bool enabled) noexcept;
bool IsWorldSpecialProperty(const WorldSpecialProperty property);

bool SetCloudsEnabled(bool bEnabled);
bool GetCloudsEnabled();
Expand Down
20 changes: 17 additions & 3 deletions Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,14 +1266,28 @@ int CLuaWorldDefs::SetOcclusionsEnabled(lua_State* luaVM)
return 1;
}

bool CLuaWorldDefs::IsWorldSpecialPropertyEnabled(WorldSpecialProperty property)
bool CLuaWorldDefs::IsWorldSpecialPropertyEnabled(const WorldSpecialProperty property) noexcept
{
return m_pClientGame->IsWorldSpecialProperty(property);
}

bool CLuaWorldDefs::SetWorldSpecialPropertyEnabled(WorldSpecialProperty property, bool isEnabled)
bool CLuaWorldDefs::SetWorldSpecialPropertyEnabled(const WorldSpecialProperty property, const bool enabled) noexcept
{
return m_pClientGame->SetWorldSpecialProperty(property, isEnabled);
if (!m_pClientGame->SetWorldSpecialProperty(property, enabled))
return false;

if (!g_pNet->CanServerBitStream(eBitStreamVersion::WorldSpecialPropertyEvent))
return true;

if (auto stream = g_pNet->AllocateNetBitStream())
{
stream->WriteString(EnumToString(property));
stream->WriteBit(enabled);
g_pNet->SendPacket(PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY, stream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
g_pNet->DeallocateNetBitStream(stream);
}

return true;
}

int CLuaWorldDefs::SetCloudsEnabled(lua_State* luaVM)
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CLuaWorldDefs : public CLuaDefs
LUA_DECLARE(GetGaragePosition);
LUA_DECLARE(GetGarageSize);
LUA_DECLARE(GetGarageBoundingBox);
static bool IsWorldSpecialPropertyEnabled(WorldSpecialProperty property);
static bool IsWorldSpecialPropertyEnabled(const WorldSpecialProperty property) noexcept;
LUA_DECLARE(GetBlurLevel);
LUA_DECLARE(GetTrafficLightState);
LUA_DECLARE(AreTrafficLightsLocked);
Expand All @@ -57,7 +57,7 @@ class CLuaWorldDefs : public CLuaDefs
LUA_DECLARE(SetMinuteDuration);
LUA_DECLARE(SetWaveHeight);
LUA_DECLARE(SetGarageOpen);
static bool SetWorldSpecialPropertyEnabled(WorldSpecialProperty property, bool isEnabled);
static bool SetWorldSpecialPropertyEnabled(const WorldSpecialProperty property, const bool enabled) noexcept;
LUA_DECLARE(SetBlurLevel);
LUA_DECLARE(ResetBlurLevel);
LUA_DECLARE(SetJetpackMaxHeight);
Expand Down
Loading