Skip to content

Commit

Permalink
Fix calling Send using UM instance from UM hook (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarukon authored Sep 22, 2024
1 parent 4b1a2c4 commit 9c8f25f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/UserMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class UserMessage
const CNetMessagePB<google::protobuf::Message>* GetProtobufMessage();
INetworkMessageInternal* GetSerializableMessage() { return msgSerializable; }
uint64* GetRecipientMask() { return recipientMask; }
bool IsManuallyAllocated() { return manuallyAllocated; }

private:
CNetMessagePB<google::protobuf::Message>* msg = nullptr;
Expand Down
8 changes: 7 additions & 1 deletion src/scripting/natives/natives_usermessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,13 @@ static void UserMessageSend(ScriptContext& scriptContext)
CRecipientFilter filter{};
filter.AddRecipientsFromMask(message->GetRecipientMask() ? *message->GetRecipientMask() : 0);

globals::gameEventSystem->PostEventAbstract(0, false, &filter, message->GetSerializableMessage(), message->GetProtobufMessage(), 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, IRecipientFilter*, INetworkMessageInternal*, const CNetMessage*, unsigned long) = &IGameEventSystem::PostEventAbstract;

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)
Expand Down

0 comments on commit 9c8f25f

Please sign in to comment.