Skip to content

Commit 9c8f25f

Browse files
authored
Fix calling Send using UM instance from UM hook (#578)
1 parent 4b1a2c4 commit 9c8f25f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/core/UserMessage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class UserMessage
132132
const CNetMessagePB<google::protobuf::Message>* GetProtobufMessage();
133133
INetworkMessageInternal* GetSerializableMessage() { return msgSerializable; }
134134
uint64* GetRecipientMask() { return recipientMask; }
135+
bool IsManuallyAllocated() { return manuallyAllocated; }
135136

136137
private:
137138
CNetMessagePB<google::protobuf::Message>* msg = nullptr;

src/scripting/natives/natives_usermessages.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,13 @@ static void UserMessageSend(ScriptContext& scriptContext)
620620
CRecipientFilter filter{};
621621
filter.AddRecipientsFromMask(message->GetRecipientMask() ? *message->GetRecipientMask() : 0);
622622

623-
globals::gameEventSystem->PostEventAbstract(0, false, &filter, message->GetSerializableMessage(), message->GetProtobufMessage(), 0);
623+
// 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
624+
static void (IGameEventSystem::*PostEventAbstract)(CSplitScreenSlot, bool, IRecipientFilter*, INetworkMessageInternal*, const CNetMessage*, unsigned long) = &IGameEventSystem::PostEventAbstract;
625+
626+
if (message->IsManuallyAllocated())
627+
globals::gameEventSystem->PostEventAbstract(0, false, &filter, message->GetSerializableMessage(), message->GetProtobufMessage(), 0);
628+
else
629+
SH_CALL(globals::gameEventSystem, PostEventAbstract)(0, false, &filter, message->GetSerializableMessage(), message->GetProtobufMessage(), 0);
624630
}
625631

626632
static void UserMessageDelete(ScriptContext& scriptContext)

0 commit comments

Comments
 (0)