From fa383cda68e91ff618d2f6e2c67a17b9d25a1a11 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Tue, 5 Aug 2025 21:38:23 +1000 Subject: [PATCH] chore: apply alliedmodders hl2sdk again (#974) --- .gitmodules | 2 +- libraries/hl2sdk-cs2 | 2 +- src/core/managers/entity_manager.cpp | 2 +- src/core/managers/entity_manager.h | 23 ++------ src/core/recipientfilters.h | 54 ++++++------------- src/scripting/natives/natives_commands.cpp | 5 +- src/scripting/natives/natives_engine.cpp | 2 +- src/scripting/natives/natives_entities.cpp | 2 +- .../natives/natives_usermessages.cpp | 29 ++++------ 9 files changed, 38 insertions(+), 83 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4a7e6bb6..31cde692 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "libraries/hl2sdk-cs2"] path = libraries/hl2sdk-cs2 - url = https://github.com/roflmuffin/hl2sdk + url = https://github.com/alliedmodders/hl2sdk branch = cs2 [submodule "libraries/metamod-source"] path = libraries/metamod-source diff --git a/libraries/hl2sdk-cs2 b/libraries/hl2sdk-cs2 index f6ca58ae..7108a5d4 160000 --- a/libraries/hl2sdk-cs2 +++ b/libraries/hl2sdk-cs2 @@ -1 +1 @@ -Subproject commit f6ca58ae0ff3c6d0e83055252519e06e95ca14df +Subproject commit 7108a5d4a696afd77d40fb0a6e241677fd403bda diff --git a/src/core/managers/entity_manager.cpp b/src/core/managers/entity_manager.cpp index 0f8bed1c..c3acca49 100644 --- a/src/core/managers/entity_manager.cpp +++ b/src/core/managers/entity_manager.cpp @@ -313,7 +313,7 @@ void DetourFireOutputInternal(CEntityIOOutput* const pThis, } } -SndOpEventGuid_t EntityEmitSoundFilter(CBitRecipientFilter& filter, uint32 ent, const char* pszSound, float flVolume, float flPitch) +SndOpEventGuid_t EntityEmitSoundFilter(CRecipientFilter& filter, uint32 ent, const char* pszSound, float flVolume, float flPitch) { if (!CBaseEntity_EmitSoundFilter) { diff --git a/src/core/managers/entity_manager.h b/src/core/managers/entity_manager.h index 6664bf7c..0254e106 100644 --- a/src/core/managers/entity_manager.h +++ b/src/core/managers/entity_manager.h @@ -24,6 +24,7 @@ #include "scripting/script_engine.h" #include "entitysystem.h" #include "scripting/callback_manager.h" +#include "core/recipientfilters.h" #include @@ -235,26 +236,8 @@ struct SndOpEventGuid_t uint64 pad; // size might be incorrect }; -class CBitRecipientFilter -{ - public: - CBitRecipientFilter() : m_Recipients(0), m_bInitMessage(false), m_nBufType(BUF_RELIABLE) {} - CBitRecipientFilter(uint64 recipients) : m_Recipients(recipients), m_bInitMessage(false), m_nBufType(BUF_RELIABLE) {} - virtual ~CBitRecipientFilter() {} - virtual bool IsInitMessage() { return m_bInitMessage; } - virtual NetChannelBufType_t GetType() { return m_nBufType; } - virtual uint64* GetRecipients() { return &m_Recipients; } - - void AddRecipientsFromMask(uint64 mask) { m_Recipients = mask; } - - private: - uint64 m_Recipients; - NetChannelBufType_t m_nBufType; - bool m_bInitMessage; -}; - -inline SndOpEventGuid_t(FASTCALL* CBaseEntity_EmitSoundFilter)(CBitRecipientFilter& filter, CEntityIndex ent, const EmitSound_t& params); +inline SndOpEventGuid_t(FASTCALL* CBaseEntity_EmitSoundFilter)(CRecipientFilter& filter, CEntityIndex ent, const EmitSound_t& params); SndOpEventGuid_t -EntityEmitSoundFilter(CBitRecipientFilter& filter, uint32 ent, const char* pszSound, float flVolume = 1.0f, float flPitch = 1.0f); +EntityEmitSoundFilter(CRecipientFilter& filter, uint32 ent, const char* pszSound, float flVolume = 1.0f, float flPitch = 1.0f); } // namespace counterstrikesharp diff --git a/src/core/recipientfilters.h b/src/core/recipientfilters.h index b751ed01..4ee5d473 100644 --- a/src/core/recipientfilters.h +++ b/src/core/recipientfilters.h @@ -14,56 +14,26 @@ * along with CounterStrikeSharp. If not, see . * */ +#pragma once #include "irecipientfilter.h" -class CSingleRecipientFilter : public IRecipientFilter -{ - public: - CSingleRecipientFilter(CPlayerSlot iRecipient, NetChannelBufType_t nBufType = BUF_RELIABLE, bool bInitMessage = false) - : m_iRecipient(iRecipient), m_nBufType(nBufType), m_bInitMessage(bInitMessage) - { - } - - ~CSingleRecipientFilter() override {} - - NetChannelBufType_t GetNetworkBufType(void) const override { return m_nBufType; } - bool IsInitMessage(void) const override { return m_bInitMessage; } - int GetRecipientCount(void) const override { return 1; } - CPlayerSlot GetRecipientIndex(int slot) const override { return m_iRecipient; } - - private: - CPlayerSlot m_iRecipient; - NetChannelBufType_t m_nBufType; - bool m_bInitMessage; -}; - class CRecipientFilter : public IRecipientFilter { public: - CRecipientFilter() + CRecipientFilter(NetChannelBufType_t nBufType = BUF_RELIABLE, bool bInitMessage = false) + : m_nBufType(nBufType), m_bInitMessage(bInitMessage) { - m_nBufType = BUF_RELIABLE; - m_bInitMessage = false; } ~CRecipientFilter() override {} NetChannelBufType_t GetNetworkBufType(void) const override { return m_nBufType; } bool IsInitMessage(void) const override { return m_bInitMessage; } - int GetRecipientCount(void) const override { return m_Recipients.Count(); } - - CPlayerSlot GetRecipientIndex(int slot) const override - { - if (slot < 0 || slot >= GetRecipientCount()) return CPlayerSlot(-1); - - return m_Recipients[slot]; - } + const CPlayerBitVec& GetRecipients(void) const override { return m_Recipients; } void AddRecipient(CPlayerSlot slot) { - if (m_Recipients.Find(slot) != m_Recipients.InvalidIndex()) return; - - m_Recipients.AddToTail(slot); + if (slot.Get() >= 0 && slot.Get() < ABSOLUTE_PLAYER_LIMIT) m_Recipients.Set(slot.Get()); } void AddRecipientsFromMask(uint64 mask) @@ -77,8 +47,18 @@ class CRecipientFilter : public IRecipientFilter } } - private: + protected: NetChannelBufType_t m_nBufType; bool m_bInitMessage; - CUtlVectorFixed m_Recipients; + CPlayerBitVec m_Recipients; +}; + +class CSingleRecipientFilter : public CRecipientFilter +{ + public: + CSingleRecipientFilter(CPlayerSlot nRecipientSlot, NetChannelBufType_t nBufType = BUF_RELIABLE, bool bInitMessage = false) + : CRecipientFilter(nBufType, bInitMessage) + { + if (nRecipientSlot.Get() >= 0 && nRecipientSlot.Get() < ABSOLUTE_PLAYER_LIMIT) m_Recipients.Set(nRecipientSlot.Get()); + } }; diff --git a/src/scripting/natives/natives_commands.cpp b/src/scripting/natives/natives_commands.cpp index c1d763d6..761d82be 100644 --- a/src/scripting/natives/natives_commands.cpp +++ b/src/scripting/natives/natives_commands.cpp @@ -217,9 +217,8 @@ void ReplicateConVar(ScriptContext& script_context) cvarMsg->set_name(name); cvarMsg->set_value(value); - uint64 recipientMask = 0; - recipientMask |= (uint64)1 << slot; - globals::gameEventSystem->PostEventAbstract(-1, false, 1, &recipientMask, pNetMsg, msg, 0, NetChannelBufType_t::BUF_RELIABLE); + CSingleRecipientFilter filter(slot); + globals::gameEventSystem->PostEventAbstract(-1, false, &filter, pNetMsg, msg, 0); delete msg; } diff --git a/src/scripting/natives/natives_engine.cpp b/src/scripting/natives/natives_engine.cpp index f1974b53..bc1cc518 100644 --- a/src/scripting/natives/natives_engine.cpp +++ b/src/scripting/natives/natives_engine.cpp @@ -64,7 +64,7 @@ float GetCurrentTime(ScriptContext& script_context) { return globals::getGlobalV int GetTickCount(ScriptContext& script_context) { return globals::getGlobalVars()->tickcount; } -float GetGameFrameTime(ScriptContext& script_context) { return 0; } +float GetGameFrameTime(ScriptContext& script_context) { return globals::getGlobalVars()->frametime; } double GetEngineTime(ScriptContext& script_context) { return Plat_FloatTime(); } diff --git a/src/scripting/natives/natives_entities.cpp b/src/scripting/natives/natives_entities.cpp index a5b501d8..b4116c24 100644 --- a/src/scripting/natives/natives_entities.cpp +++ b/src/scripting/natives/natives_entities.cpp @@ -266,7 +266,7 @@ SoundEventGuid_t EmitSoundFilter(ScriptContext& script_context) auto volume = script_context.GetArgument(3); auto pitch = script_context.GetArgument(4); - CBitRecipientFilter filter{}; + CRecipientFilter filter{}; filter.AddRecipientsFromMask(filtermask); SndOpEventGuid_t ret = EntityEmitSoundFilter(filter, ent, sound, volume, pitch); diff --git a/src/scripting/natives/natives_usermessages.cpp b/src/scripting/natives/natives_usermessages.cpp index e2db090f..51867158 100644 --- a/src/scripting/natives/natives_usermessages.cpp +++ b/src/scripting/natives/natives_usermessages.cpp @@ -734,27 +734,20 @@ static void UserMessageSend(ScriptContext& scriptContext) { auto message = scriptContext.GetArgument(0); + CRecipientFilter filter{}; + + filter.AddRecipientsFromMask(message->GetRecipientMask() ? *message->GetRecipientMask() : 0); + // This is for calling send in a UM hook, if calling normal send using the UM instance from the UM hook, it will cause an inifinite // loop, then crashing the server - static void (IGameEventSystem::*PostEventAbstract)(CSplitScreenSlot, bool, int, const uint64*, INetworkMessageInternal*, - const CNetMessage*, unsigned long, NetChannelBufType_t) = - &IGameEventSystem::PostEventAbstract; + static void (IGameEventSystem::*PostEventAbstract)(CSplitScreenSlot, bool, IRecipientFilter*, INetworkMessageInternal*, + const CNetMessage*, unsigned long) = &IGameEventSystem::PostEventAbstract; - // @hack Swap this back to CRecipientFilter when that is properly reversed so we don't have to do this crappy loop hack - std::vector recipients; - uint64 recipientMask = message->GetRecipientMask() ? *message->GetRecipientMask() : 0; - for (int i = 0; i < 64; i++) - { - if (recipientMask & ((uint64)1 << i)) - { - if (message->IsManuallyAllocated()) - globals::gameEventSystem->PostEventAbstract(i, false, 1, &recipientMask, message->GetSerializableMessage(), - message->GetProtobufMessage(), 0, NetChannelBufType_t::BUF_RELIABLE); - else - SH_CALL(globals::gameEventSystem, PostEventAbstract)(i, false, 1, &recipientMask, message->GetSerializableMessage(), - message->GetProtobufMessage(), 0, NetChannelBufType_t::BUF_RELIABLE); - } - } + if (message->IsManuallyAllocated()) + globals::gameEventSystem->PostEventAbstract(0, false, &filter, message->GetSerializableMessage(), message->GetProtobufMessage(), 0); + else + SH_CALL(globals::gameEventSystem, PostEventAbstract)(0, false, &filter, message->GetSerializableMessage(), + message->GetProtobufMessage(), 0); } static void UserMessageDelete(ScriptContext& scriptContext)