chore: apply alliedmodders hl2sdk again (#974)

This commit is contained in:
Michael Wilson
2025-08-05 21:38:23 +10:00
committed by GitHub
parent e1acada35e
commit fa383cda68
9 changed files with 38 additions and 83 deletions

2
.gitmodules vendored
View File

@@ -1,6 +1,6 @@
[submodule "libraries/hl2sdk-cs2"] [submodule "libraries/hl2sdk-cs2"]
path = libraries/hl2sdk-cs2 path = libraries/hl2sdk-cs2
url = https://github.com/roflmuffin/hl2sdk url = https://github.com/alliedmodders/hl2sdk
branch = cs2 branch = cs2
[submodule "libraries/metamod-source"] [submodule "libraries/metamod-source"]
path = libraries/metamod-source path = libraries/metamod-source

View File

@@ -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) if (!CBaseEntity_EmitSoundFilter)
{ {

View File

@@ -24,6 +24,7 @@
#include "scripting/script_engine.h" #include "scripting/script_engine.h"
#include "entitysystem.h" #include "entitysystem.h"
#include "scripting/callback_manager.h" #include "scripting/callback_manager.h"
#include "core/recipientfilters.h"
#include <variant.h> #include <variant.h>
@@ -235,26 +236,8 @@ struct SndOpEventGuid_t
uint64 pad; // size might be incorrect uint64 pad; // size might be incorrect
}; };
class CBitRecipientFilter inline SndOpEventGuid_t(FASTCALL* CBaseEntity_EmitSoundFilter)(CRecipientFilter& filter, CEntityIndex ent, const EmitSound_t& params);
{
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);
SndOpEventGuid_t 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 } // namespace counterstrikesharp

View File

@@ -14,56 +14,26 @@
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. * * along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/ */
#pragma once
#include "irecipientfilter.h" #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 class CRecipientFilter : public IRecipientFilter
{ {
public: 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 {} ~CRecipientFilter() override {}
NetChannelBufType_t GetNetworkBufType(void) const override { return m_nBufType; } NetChannelBufType_t GetNetworkBufType(void) const override { return m_nBufType; }
bool IsInitMessage(void) const override { return m_bInitMessage; } bool IsInitMessage(void) const override { return m_bInitMessage; }
int GetRecipientCount(void) const override { return m_Recipients.Count(); } const CPlayerBitVec& GetRecipients(void) const override { return m_Recipients; }
CPlayerSlot GetRecipientIndex(int slot) const override
{
if (slot < 0 || slot >= GetRecipientCount()) return CPlayerSlot(-1);
return m_Recipients[slot];
}
void AddRecipient(CPlayerSlot slot) void AddRecipient(CPlayerSlot slot)
{ {
if (m_Recipients.Find(slot) != m_Recipients.InvalidIndex()) return; if (slot.Get() >= 0 && slot.Get() < ABSOLUTE_PLAYER_LIMIT) m_Recipients.Set(slot.Get());
m_Recipients.AddToTail(slot);
} }
void AddRecipientsFromMask(uint64 mask) void AddRecipientsFromMask(uint64 mask)
@@ -77,8 +47,18 @@ class CRecipientFilter : public IRecipientFilter
} }
} }
private: protected:
NetChannelBufType_t m_nBufType; NetChannelBufType_t m_nBufType;
bool m_bInitMessage; bool m_bInitMessage;
CUtlVectorFixed<CPlayerSlot, 64> 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());
}
}; };

View File

@@ -217,9 +217,8 @@ void ReplicateConVar(ScriptContext& script_context)
cvarMsg->set_name(name); cvarMsg->set_name(name);
cvarMsg->set_value(value); cvarMsg->set_value(value);
uint64 recipientMask = 0; CSingleRecipientFilter filter(slot);
recipientMask |= (uint64)1 << slot; globals::gameEventSystem->PostEventAbstract(-1, false, &filter, pNetMsg, msg, 0);
globals::gameEventSystem->PostEventAbstract(-1, false, 1, &recipientMask, pNetMsg, msg, 0, NetChannelBufType_t::BUF_RELIABLE);
delete msg; delete msg;
} }

View File

@@ -64,7 +64,7 @@ float GetCurrentTime(ScriptContext& script_context) { return globals::getGlobalV
int GetTickCount(ScriptContext& script_context) { return globals::getGlobalVars()->tickcount; } 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(); } double GetEngineTime(ScriptContext& script_context) { return Plat_FloatTime(); }

View File

@@ -266,7 +266,7 @@ SoundEventGuid_t EmitSoundFilter(ScriptContext& script_context)
auto volume = script_context.GetArgument<float>(3); auto volume = script_context.GetArgument<float>(3);
auto pitch = script_context.GetArgument<float>(4); auto pitch = script_context.GetArgument<float>(4);
CBitRecipientFilter filter{}; CRecipientFilter filter{};
filter.AddRecipientsFromMask(filtermask); filter.AddRecipientsFromMask(filtermask);
SndOpEventGuid_t ret = EntityEmitSoundFilter(filter, ent, sound, volume, pitch); SndOpEventGuid_t ret = EntityEmitSoundFilter(filter, ent, sound, volume, pitch);

View File

@@ -734,27 +734,20 @@ static void UserMessageSend(ScriptContext& scriptContext)
{ {
auto message = scriptContext.GetArgument<UserMessage*>(0); auto message = scriptContext.GetArgument<UserMessage*>(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 // 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 // loop, then crashing the server
static void (IGameEventSystem::*PostEventAbstract)(CSplitScreenSlot, bool, int, const uint64*, INetworkMessageInternal*, static void (IGameEventSystem::*PostEventAbstract)(CSplitScreenSlot, bool, IRecipientFilter*, INetworkMessageInternal*,
const CNetMessage*, unsigned long, NetChannelBufType_t) = const CNetMessage*, unsigned long) = &IGameEventSystem::PostEventAbstract;
&IGameEventSystem::PostEventAbstract;
// @hack Swap this back to CRecipientFilter when that is properly reversed so we don't have to do this crappy loop hack if (message->IsManuallyAllocated())
std::vector<CPlayerSlot> recipients; globals::gameEventSystem->PostEventAbstract(0, false, &filter, message->GetSerializableMessage(), message->GetProtobufMessage(), 0);
uint64 recipientMask = message->GetRecipientMask() ? *message->GetRecipientMask() : 0; else
for (int i = 0; i < 64; i++) SH_CALL(globals::gameEventSystem, PostEventAbstract)(0, false, &filter, message->GetSerializableMessage(),
{ message->GetProtobufMessage(), 0);
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);
}
}
} }
static void UserMessageDelete(ScriptContext& scriptContext) static void UserMessageDelete(ScriptContext& scriptContext)