From 668308697d538a76629a3d0d3ef067d97a49dd9f Mon Sep 17 00:00:00 2001 From: Dutchman101 <12105539+Dutchman101@users.noreply.github.com> Date: Thu, 21 Nov 2024 23:21:48 +0000 Subject: [PATCH 1/3] Updated module version of https://mirror-cdn.multitheftauto.com/bdata/fork-support/netc.dll Release new "forks full AC" netc module to fix "Network module not compatible!" with latest sources See https://wiki.multitheftauto.com/wiki/Forks_Full_AC From 514a3b36d09906f09bb32e900c39dc09b1c29d10 Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Fri, 22 Nov 2024 21:08:02 +0100 Subject: [PATCH 2/3] Fix the BitStream version mistake made in #3863 (#3866) --- Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp | 8 ++++++-- .../mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 9 +++++++-- Shared/sdk/net/bitstream.h | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp index fd305f6955..380767ccc7 100644 --- a/Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp @@ -619,8 +619,12 @@ void CWorldRPCs::SetSyncIntervals(NetBitStreamInterface& bitStream) bitStream.Read(g_TickRateSettings.iObjectSync); bitStream.Read(g_TickRateSettings.iKeySyncRotation); bitStream.Read(g_TickRateSettings.iKeySyncAnalogMove); - bitStream.Read(g_TickRateSettings.iPedSyncerDistance); - bitStream.Read(g_TickRateSettings.iUnoccupiedVehicleSyncerDistance); + + if (bitStream.Can(eBitStreamVersion::FixSyncerDistance)) + { + bitStream.Read(g_TickRateSettings.iPedSyncerDistance); + bitStream.Read(g_TickRateSettings.iUnoccupiedVehicleSyncerDistance); + } } void CWorldRPCs::SetMoonSize(NetBitStreamInterface& bitStream) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 930e814879..24c9ff6edc 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -10861,8 +10861,13 @@ bool CStaticFunctionDefinitions::SendSyncIntervals(CPlayer* pPlayer) BitStream.pBitStream->Write(g_TickRateSettings.iObjectSync); BitStream.pBitStream->Write(g_TickRateSettings.iKeySyncRotation); BitStream.pBitStream->Write(g_TickRateSettings.iKeySyncAnalogMove); - BitStream.pBitStream->Write(g_TickRateSettings.iPedSyncerDistance); - BitStream.pBitStream->Write(g_TickRateSettings.iUnoccupiedVehicleSyncerDistance); + + if (pPlayer->CanBitStream(eBitStreamVersion::FixSyncerDistance)) + { + BitStream.pBitStream->Write(g_TickRateSettings.iPedSyncerDistance); + BitStream.pBitStream->Write(g_TickRateSettings.iUnoccupiedVehicleSyncerDistance); + } + if (pPlayer) pPlayer->Send(CLuaPacket(SET_SYNC_INTERVALS, *BitStream.pBitStream)); else diff --git a/Shared/sdk/net/bitstream.h b/Shared/sdk/net/bitstream.h index 88bdfcfff2..d5471c7898 100644 --- a/Shared/sdk/net/bitstream.h +++ b/Shared/sdk/net/bitstream.h @@ -580,6 +580,10 @@ enum class eBitStreamVersion : unsigned short // 2024-11-07 WorldSpecialProperty_IgnoreFireState, + // Fix iPedSyncerDistance and iUnoccupiedVehicleSyncerDistance sync + // 2024-11-22 + FixSyncerDistance, + // 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, From bbf511d4c5a94fc42d4ead201446fcef8ae430ec Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Wed, 27 Nov 2024 20:10:52 +0100 Subject: [PATCH 3/3] Add new event onPlayerChangesWorldSpecialProperty (#3873) * Add stream * Add packet & implementation * Make suggested changes --- Client/mods/deathmatch/logic/CClientGame.cpp | 43 ++++++++++++------- Client/mods/deathmatch/logic/CClientGame.h | 2 +- Server/mods/deathmatch/logic/CGame.cpp | 25 +++++++++++ Server/mods/deathmatch/logic/CGame.h | 1 + .../deathmatch/logic/CPacketTranslator.cpp | 5 +++ .../CPlayerWorldSpecialPropertyPacket.cpp | 20 +++++++++ .../CPlayerWorldSpecialPropertyPacket.h | 34 +++++++++++++++ Shared/mods/deathmatch/logic/Enums.cpp | 1 + Shared/sdk/net/Packets.h | 1 + Shared/sdk/net/bitstream.h | 4 ++ 10 files changed, 120 insertions(+), 16 deletions(-) create mode 100644 Server/mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.cpp create mode 100644 Server/mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.h diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 52ca69f3f0..7169125a24 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -5982,7 +5982,7 @@ 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) { @@ -5990,47 +5990,60 @@ bool CClientGame::SetWorldSpecialProperty(WorldSpecialProperty property, bool is 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) diff --git a/Client/mods/deathmatch/logic/CClientGame.h b/Client/mods/deathmatch/logic/CClientGame.h index c76dc223aa..e887199fcd 100644 --- a/Client/mods/deathmatch/logic/CClientGame.h +++ b/Client/mods/deathmatch/logic/CClientGame.h @@ -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); diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index 98ea8250b2..b1a2ca18d6 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -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" @@ -1293,6 +1294,12 @@ bool CGame::ProcessPacket(CPacket& Packet) return true; } + case PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY: + { + Packet_PlayerWorldSpecialProperty(static_cast(Packet)); + return true; + } + default: break; } @@ -1609,6 +1616,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); @@ -4256,6 +4264,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(); diff --git a/Server/mods/deathmatch/logic/CGame.h b/Server/mods/deathmatch/logic/CGame.h index d865e858ec..e6bd4dfccf 100644 --- a/Server/mods/deathmatch/logic/CGame.h +++ b/Server/mods/deathmatch/logic/CGame.h @@ -519,6 +519,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); diff --git a/Server/mods/deathmatch/logic/CPacketTranslator.cpp b/Server/mods/deathmatch/logic/CPacketTranslator.cpp index 3b6d92c3db..3cf0fa0965 100644 --- a/Server/mods/deathmatch/logic/CPacketTranslator.cpp +++ b/Server/mods/deathmatch/logic/CPacketTranslator.cpp @@ -48,6 +48,7 @@ #include "packets/CPlayerNoSocketPacket.h" #include "packets/CPlayerNetworkStatusPacket.h" #include "packets/CPlayerResourceStartPacket.h" +#include "packets/CPlayerWorldSpecialPropertyPacket.h" CPacketTranslator::CPacketTranslator(CPlayerManager* pPlayerManager) { @@ -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; } diff --git a/Server/mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.cpp b/Server/mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.cpp new file mode 100644 index 0000000000..59c3ec4c7b --- /dev/null +++ b/Server/mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.cpp @@ -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; +} diff --git a/Server/mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.h b/Server/mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.h new file mode 100644 index 0000000000..cb6dd9e2f1 --- /dev/null +++ b/Server/mods/deathmatch/logic/packets/CPlayerWorldSpecialPropertyPacket.h @@ -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 +#include +#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; +}; diff --git a/Shared/mods/deathmatch/logic/Enums.cpp b/Shared/mods/deathmatch/logic/Enums.cpp index 20be17719d..64aa8db8f1 100644 --- a/Shared/mods/deathmatch/logic/Enums.cpp +++ b/Shared/mods/deathmatch/logic/Enums.cpp @@ -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") diff --git a/Shared/sdk/net/Packets.h b/Shared/sdk/net/Packets.h index 0941ca49dd..411af7cb88 100644 --- a/Shared/sdk/net/Packets.h +++ b/Shared/sdk/net/Packets.h @@ -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 }; diff --git a/Shared/sdk/net/bitstream.h b/Shared/sdk/net/bitstream.h index d5471c7898..f422739ad4 100644 --- a/Shared/sdk/net/bitstream.h +++ b/Shared/sdk/net/bitstream.h @@ -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,