Skip to content

Commit

Permalink
Merge branch 'master' into clean-eVehicleTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Moris authored Nov 27, 2024
2 parents fcc2c93 + bbf511d commit 8641aba
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 16 deletions.
43 changes: 28 additions & 15 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5982,55 +5982,68 @@ bool CClientGame::IsGlitchEnabled(unsigned char ucGlitch)
return ucGlitch < NUM_GLITCHES && m_Glitches[ucGlitch];
}

bool CClientGame::SetWorldSpecialProperty(WorldSpecialProperty property, bool isEnabled)
bool CClientGame::SetWorldSpecialProperty(WorldSpecialProperty property, bool isEnabled) noexcept
{
switch (property)
{
case WorldSpecialProperty::HOVERCARS:
case WorldSpecialProperty::AIRCARS:
case WorldSpecialProperty::EXTRABUNNY:
case WorldSpecialProperty::EXTRAJUMP:
return g_pGame->SetCheatEnabled(EnumToString(property), isEnabled);
g_pGame->SetCheatEnabled(EnumToString(property), isEnabled);
break;
case WorldSpecialProperty::RANDOMFOLIAGE:
g_pGame->SetRandomFoliageEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::SNIPERMOON:
g_pGame->SetMoonEasterEggEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::EXTRAAIRRESISTANCE:
g_pGame->SetExtraAirResistanceEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::UNDERWORLDWARP:
g_pGame->SetUnderWorldWarpEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::VEHICLESUNGLARE:
g_pGame->SetVehicleSunGlareEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::CORONAZTEST:
g_pGame->SetCoronaZTestEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::WATERCREATURES:
g_pGame->SetWaterCreaturesEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::BURNFLIPPEDCARS:
g_pGame->SetBurnFlippedCarsEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::FIREBALLDESTRUCT:
g_pGame->SetFireballDestructEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::EXTENDEDWATERCANNONS:
g_pGame->SetExtendedWaterCannonsEnabled(isEnabled);
break;
case WorldSpecialProperty::ROADSIGNSTEXT:
g_pGame->SetRoadSignsTextEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::TUNNELWEATHERBLEND:
g_pGame->SetTunnelWeatherBlendEnabled(isEnabled);
return true;
break;
case WorldSpecialProperty::IGNOREFIRESTATE:
g_pGame->SetIgnoreFireStateEnabled(isEnabled);
return true;
break;
default:
return false;
}
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)
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class CClientGame
bool SetGlitchEnabled(unsigned char cGlitch, bool bEnabled);
bool IsGlitchEnabled(unsigned char cGlitch);

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

bool SetCloudsEnabled(bool bEnabled);
Expand Down
25 changes: 25 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "packets/CPlayerNetworkStatusPacket.h"
#include "packets/CPlayerListPacket.h"
#include "packets/CPlayerClothesPacket.h"
#include "packets/CPlayerWorldSpecialPropertyPacket.h"
#include "packets/CServerInfoSyncPacket.h"
#include "packets/CLuaPacket.h"
#include "../utils/COpenPortsTester.h"
Expand Down Expand Up @@ -1309,6 +1310,12 @@ bool CGame::ProcessPacket(CPacket& Packet)
return true;
}

case PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY:
{
Packet_PlayerWorldSpecialProperty(static_cast<CPlayerWorldSpecialPropertyPacket&>(Packet));
return true;
}

default:
break;
}
Expand Down Expand Up @@ -1625,6 +1632,7 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerTeamChange", "oldTeam, newTeam", nullptr, false);
m_Events.AddEvent("onPlayerTriggerInvalidEvent", "eventName, isAdded, isRemote", nullptr, false);
m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false);
m_Events.AddEvent("onPlayerChangesWorldSpecialProperty", "property, enabled", nullptr, false);

// Ped events
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
Expand Down Expand Up @@ -4272,6 +4280,23 @@ void CGame::Packet_PlayerResourceStart(CPlayerResourceStartPacket& Packet)
}
}

void CGame::Packet_PlayerWorldSpecialProperty(CPlayerWorldSpecialPropertyPacket& packet) noexcept
{
CPlayer* player = packet.GetSourcePlayer();

if (!player)
return;

const std::string& property = packet.GetProperty();
const bool enabled = packet.IsEnabled();

CLuaArguments arguments;
arguments.PushString(property);
arguments.PushBoolean(enabled);

player->CallEvent("onPlayerChangesWorldSpecialProperty", arguments, nullptr);
}

void CGame::Packet_PlayerModInfo(CPlayerModInfoPacket& Packet)
{
CPlayer* pPlayer = Packet.GetSourcePlayer();
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ class CGame
void Packet_PlayerNoSocket(class CPlayerNoSocketPacket& Packet);
void Packet_PlayerNetworkStatus(class CPlayerNetworkStatusPacket& Packet);
void Packet_PlayerResourceStart(class CPlayerResourceStartPacket& Packet);
void Packet_PlayerWorldSpecialProperty(class CPlayerWorldSpecialPropertyPacket& packet) noexcept;

static void PlayerCompleteConnect(CPlayer* pPlayer);

Expand Down
5 changes: 5 additions & 0 deletions Server/mods/deathmatch/logic/CPacketTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "packets/CPlayerNoSocketPacket.h"
#include "packets/CPlayerNetworkStatusPacket.h"
#include "packets/CPlayerResourceStartPacket.h"
#include "packets/CPlayerWorldSpecialPropertyPacket.h"

CPacketTranslator::CPacketTranslator(CPlayerManager* pPlayerManager)
{
Expand Down Expand Up @@ -212,6 +213,10 @@ CPacket* CPacketTranslator::Translate(const NetServerPlayerID& Socket, ePacketID
pTemp = new CPlayerResourceStartPacket;
break;

case PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY:
pTemp = new CPlayerWorldSpecialPropertyPacket;
break;

default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.cpp
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/

#include "StdInc.h"
#include "CPlayerWorldSpecialPropertyPacket.h"

bool CPlayerWorldSpecialPropertyPacket::Read(NetBitStreamInterface& stream) noexcept
{
stream.ReadString(m_property);
stream.ReadBit(m_enabled);

return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.h
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once

#include <string>
#include <cstdint>
#include "CPacket.h"

class CPlayerWorldSpecialPropertyPacket final : public CPacket
{
public:
CPlayerWorldSpecialPropertyPacket() noexcept {}

ePacketID GetPacketID() const noexcept { return PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY; }
unsigned long GetFlags() const noexcept { return PACKET_HIGH_PRIORITY | PACKET_RELIABLE | PACKET_SEQUENCED; }
virtual ePacketOrdering GetPacketOrdering() const noexcept { return PACKET_ORDERING_DEFAULT; }

bool Read(NetBitStreamInterface& stream) noexcept;

std::string GetProperty() const noexcept { return m_property; }
bool IsEnabled() const noexcept { return m_enabled; }

private:
std::string m_property;
bool m_enabled;
};
1 change: 1 addition & 0 deletions Shared/mods/deathmatch/logic/Enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,5 @@ ADD_ENUM1(PACKET_ID_CHAT_CLEAR)
ADD_ENUM1(PACKET_ID_SERVER_INFO_SYNC)
ADD_ENUM1(PACKET_ID_DISCORD_JOIN)
ADD_ENUM1(PACKET_ID_PLAYER_RESOURCE_START)
ADD_ENUM1(PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY)
IMPLEMENT_ENUM_END("ePacketID")
1 change: 1 addition & 0 deletions Shared/sdk/net/Packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ enum ePacketID
PACKET_ID_SERVER_INFO_SYNC,
PACKET_ID_DISCORD_JOIN,
PACKET_ID_PLAYER_RESOURCE_START,
PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY
};
4 changes: 4 additions & 0 deletions Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ enum class eBitStreamVersion : unsigned short
// 2024-11-22
FixSyncerDistance,

// Add onPlayerChangesWorldSpecialProperty
// 2024-11-26
WorldSpecialPropertyEvent,

// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
// Make sure you only add things above this comment.
Next,
Expand Down

0 comments on commit 8641aba

Please sign in to comment.