Skip to content

Commit bbf511d

Browse files
authored
Add new event onPlayerChangesWorldSpecialProperty (#3873)
* Add stream * Add packet & implementation * Make suggested changes
1 parent 514a3b3 commit bbf511d

File tree

10 files changed

+120
-16
lines changed

10 files changed

+120
-16
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,55 +5982,68 @@ bool CClientGame::IsGlitchEnabled(unsigned char ucGlitch)
59825982
return ucGlitch < NUM_GLITCHES && m_Glitches[ucGlitch];
59835983
}
59845984

5985-
bool CClientGame::SetWorldSpecialProperty(WorldSpecialProperty property, bool isEnabled)
5985+
bool CClientGame::SetWorldSpecialProperty(WorldSpecialProperty property, bool isEnabled) noexcept
59865986
{
59875987
switch (property)
59885988
{
59895989
case WorldSpecialProperty::HOVERCARS:
59905990
case WorldSpecialProperty::AIRCARS:
59915991
case WorldSpecialProperty::EXTRABUNNY:
59925992
case WorldSpecialProperty::EXTRAJUMP:
5993-
return g_pGame->SetCheatEnabled(EnumToString(property), isEnabled);
5993+
g_pGame->SetCheatEnabled(EnumToString(property), isEnabled);
5994+
break;
59945995
case WorldSpecialProperty::RANDOMFOLIAGE:
59955996
g_pGame->SetRandomFoliageEnabled(isEnabled);
5996-
return true;
5997+
break;
59975998
case WorldSpecialProperty::SNIPERMOON:
59985999
g_pGame->SetMoonEasterEggEnabled(isEnabled);
5999-
return true;
6000+
break;
60006001
case WorldSpecialProperty::EXTRAAIRRESISTANCE:
60016002
g_pGame->SetExtraAirResistanceEnabled(isEnabled);
6002-
return true;
6003+
break;
60036004
case WorldSpecialProperty::UNDERWORLDWARP:
60046005
g_pGame->SetUnderWorldWarpEnabled(isEnabled);
6005-
return true;
6006+
break;
60066007
case WorldSpecialProperty::VEHICLESUNGLARE:
60076008
g_pGame->SetVehicleSunGlareEnabled(isEnabled);
6008-
return true;
6009+
break;
60096010
case WorldSpecialProperty::CORONAZTEST:
60106011
g_pGame->SetCoronaZTestEnabled(isEnabled);
6011-
return true;
6012+
break;
60126013
case WorldSpecialProperty::WATERCREATURES:
60136014
g_pGame->SetWaterCreaturesEnabled(isEnabled);
6014-
return true;
6015+
break;
60156016
case WorldSpecialProperty::BURNFLIPPEDCARS:
60166017
g_pGame->SetBurnFlippedCarsEnabled(isEnabled);
6017-
return true;
6018+
break;
60186019
case WorldSpecialProperty::FIREBALLDESTRUCT:
60196020
g_pGame->SetFireballDestructEnabled(isEnabled);
6020-
return true;
6021+
break;
60216022
case WorldSpecialProperty::EXTENDEDWATERCANNONS:
60226023
g_pGame->SetExtendedWaterCannonsEnabled(isEnabled);
6024+
break;
60236025
case WorldSpecialProperty::ROADSIGNSTEXT:
60246026
g_pGame->SetRoadSignsTextEnabled(isEnabled);
6025-
return true;
6027+
break;
60266028
case WorldSpecialProperty::TUNNELWEATHERBLEND:
60276029
g_pGame->SetTunnelWeatherBlendEnabled(isEnabled);
6028-
return true;
6030+
break;
60296031
case WorldSpecialProperty::IGNOREFIRESTATE:
60306032
g_pGame->SetIgnoreFireStateEnabled(isEnabled);
6031-
return true;
6033+
break;
6034+
default:
6035+
return false;
60326036
}
6033-
return false;
6037+
6038+
if (g_pNet->CanServerBitStream(eBitStreamVersion::WorldSpecialPropertyEvent)) {
6039+
NetBitStreamInterface* stream = g_pNet->AllocateNetBitStream();
6040+
stream->WriteString(EnumToString(property));
6041+
stream->WriteBit(isEnabled);
6042+
g_pNet->SendPacket(PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY, stream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
6043+
g_pNet->DeallocateNetBitStream(stream);
6044+
}
6045+
6046+
return true;
60346047
}
60356048

60366049
bool CClientGame::IsWorldSpecialProperty(WorldSpecialProperty property)

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class CClientGame
410410
bool SetGlitchEnabled(unsigned char cGlitch, bool bEnabled);
411411
bool IsGlitchEnabled(unsigned char cGlitch);
412412

413-
bool SetWorldSpecialProperty(WorldSpecialProperty property, bool isEnabled);
413+
bool SetWorldSpecialProperty(WorldSpecialProperty property, bool isEnabled) noexcept;
414414
bool IsWorldSpecialProperty(WorldSpecialProperty property);
415415

416416
bool SetCloudsEnabled(bool bEnabled);

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "packets/CPlayerNetworkStatusPacket.h"
5959
#include "packets/CPlayerListPacket.h"
6060
#include "packets/CPlayerClothesPacket.h"
61+
#include "packets/CPlayerWorldSpecialPropertyPacket.h"
6162
#include "packets/CServerInfoSyncPacket.h"
6263
#include "packets/CLuaPacket.h"
6364
#include "../utils/COpenPortsTester.h"
@@ -1293,6 +1294,12 @@ bool CGame::ProcessPacket(CPacket& Packet)
12931294
return true;
12941295
}
12951296

1297+
case PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY:
1298+
{
1299+
Packet_PlayerWorldSpecialProperty(static_cast<CPlayerWorldSpecialPropertyPacket&>(Packet));
1300+
return true;
1301+
}
1302+
12961303
default:
12971304
break;
12981305
}
@@ -1609,6 +1616,7 @@ void CGame::AddBuiltInEvents()
16091616
m_Events.AddEvent("onPlayerTeamChange", "oldTeam, newTeam", nullptr, false);
16101617
m_Events.AddEvent("onPlayerTriggerInvalidEvent", "eventName, isAdded, isRemote", nullptr, false);
16111618
m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false);
1619+
m_Events.AddEvent("onPlayerChangesWorldSpecialProperty", "property, enabled", nullptr, false);
16121620

16131621
// Ped events
16141622
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
@@ -4256,6 +4264,23 @@ void CGame::Packet_PlayerResourceStart(CPlayerResourceStartPacket& Packet)
42564264
}
42574265
}
42584266

4267+
void CGame::Packet_PlayerWorldSpecialProperty(CPlayerWorldSpecialPropertyPacket& packet) noexcept
4268+
{
4269+
CPlayer* player = packet.GetSourcePlayer();
4270+
4271+
if (!player)
4272+
return;
4273+
4274+
const std::string& property = packet.GetProperty();
4275+
const bool enabled = packet.IsEnabled();
4276+
4277+
CLuaArguments arguments;
4278+
arguments.PushString(property);
4279+
arguments.PushBoolean(enabled);
4280+
4281+
player->CallEvent("onPlayerChangesWorldSpecialProperty", arguments, nullptr);
4282+
}
4283+
42594284
void CGame::Packet_PlayerModInfo(CPlayerModInfoPacket& Packet)
42604285
{
42614286
CPlayer* pPlayer = Packet.GetSourcePlayer();

Server/mods/deathmatch/logic/CGame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ class CGame
519519
void Packet_PlayerNoSocket(class CPlayerNoSocketPacket& Packet);
520520
void Packet_PlayerNetworkStatus(class CPlayerNetworkStatusPacket& Packet);
521521
void Packet_PlayerResourceStart(class CPlayerResourceStartPacket& Packet);
522+
void Packet_PlayerWorldSpecialProperty(class CPlayerWorldSpecialPropertyPacket& packet) noexcept;
522523

523524
static void PlayerCompleteConnect(CPlayer* pPlayer);
524525

Server/mods/deathmatch/logic/CPacketTranslator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "packets/CPlayerNoSocketPacket.h"
4949
#include "packets/CPlayerNetworkStatusPacket.h"
5050
#include "packets/CPlayerResourceStartPacket.h"
51+
#include "packets/CPlayerWorldSpecialPropertyPacket.h"
5152

5253
CPacketTranslator::CPacketTranslator(CPlayerManager* pPlayerManager)
5354
{
@@ -212,6 +213,10 @@ CPacket* CPacketTranslator::Translate(const NetServerPlayerID& Socket, ePacketID
212213
pTemp = new CPlayerResourceStartPacket;
213214
break;
214215

216+
case PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY:
217+
pTemp = new CPlayerWorldSpecialPropertyPacket;
218+
break;
219+
215220
default:
216221
break;
217222
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.cpp
6+
*
7+
* Multi Theft Auto is available from https://www.multitheftauto.com/
8+
*
9+
*****************************************************************************/
10+
11+
#include "StdInc.h"
12+
#include "CPlayerWorldSpecialPropertyPacket.h"
13+
14+
bool CPlayerWorldSpecialPropertyPacket::Read(NetBitStreamInterface& stream) noexcept
15+
{
16+
stream.ReadString(m_property);
17+
stream.ReadBit(m_enabled);
18+
19+
return true;
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.h
6+
*
7+
* Multi Theft Auto is available from https://www.multitheftauto.com/
8+
*
9+
*****************************************************************************/
10+
11+
#pragma once
12+
13+
#include <string>
14+
#include <cstdint>
15+
#include "CPacket.h"
16+
17+
class CPlayerWorldSpecialPropertyPacket final : public CPacket
18+
{
19+
public:
20+
CPlayerWorldSpecialPropertyPacket() noexcept {}
21+
22+
ePacketID GetPacketID() const noexcept { return PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY; }
23+
unsigned long GetFlags() const noexcept { return PACKET_HIGH_PRIORITY | PACKET_RELIABLE | PACKET_SEQUENCED; }
24+
virtual ePacketOrdering GetPacketOrdering() const noexcept { return PACKET_ORDERING_DEFAULT; }
25+
26+
bool Read(NetBitStreamInterface& stream) noexcept;
27+
28+
std::string GetProperty() const noexcept { return m_property; }
29+
bool IsEnabled() const noexcept { return m_enabled; }
30+
31+
private:
32+
std::string m_property;
33+
bool m_enabled;
34+
};

Shared/mods/deathmatch/logic/Enums.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,5 @@ ADD_ENUM1(PACKET_ID_CHAT_CLEAR)
214214
ADD_ENUM1(PACKET_ID_SERVER_INFO_SYNC)
215215
ADD_ENUM1(PACKET_ID_DISCORD_JOIN)
216216
ADD_ENUM1(PACKET_ID_PLAYER_RESOURCE_START)
217+
ADD_ENUM1(PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY)
217218
IMPLEMENT_ENUM_END("ePacketID")

Shared/sdk/net/Packets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,5 @@ enum ePacketID
151151
PACKET_ID_SERVER_INFO_SYNC,
152152
PACKET_ID_DISCORD_JOIN,
153153
PACKET_ID_PLAYER_RESOURCE_START,
154+
PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY
154155
};

Shared/sdk/net/bitstream.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,10 @@ enum class eBitStreamVersion : unsigned short
584584
// 2024-11-22
585585
FixSyncerDistance,
586586

587+
// Add onPlayerChangesWorldSpecialProperty
588+
// 2024-11-26
589+
WorldSpecialPropertyEvent,
590+
587591
// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
588592
// Make sure you only add things above this comment.
589593
Next,

0 commit comments

Comments
 (0)