2008-03-30 09:00:22 +02:00
|
|
|
/**
|
2013-08-25 21:16:07 +02:00
|
|
|
* vim: set ts=4 sw=4 tw=99 noet :
|
2008-03-30 09:00:22 +02:00
|
|
|
* =============================================================================
|
|
|
|
* SourceMod
|
2010-07-28 00:32:32 +02:00
|
|
|
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
2008-03-30 09:00:22 +02:00
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "UserMessages.h"
|
|
|
|
#include "sm_stringutil.h"
|
2013-03-29 19:37:29 +01:00
|
|
|
#include "logic_bridge.h"
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2016-04-27 05:18:47 +02:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
2013-01-23 03:43:12 +01:00
|
|
|
#include <cstrike15_usermessage_helpers.h>
|
2020-03-11 23:36:25 +01:00
|
|
|
#elif SOURCE_ENGINE == SE_BLADE
|
|
|
|
#include <berimbau_usermessage_helpers.h>
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2015-09-06 06:44:18 +02:00
|
|
|
#include <amtl/am-string.h>
|
2013-01-23 03:43:12 +01:00
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
UserMessages g_UserMsgs;
|
|
|
|
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
const protobuf::Message *GetMessagePrototype(int msg_type);
|
|
|
|
#endif
|
|
|
|
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
2013-01-23 03:43:12 +01:00
|
|
|
SH_DECL_HOOK3_void(IVEngineServer, SendUserMessage, SH_NOATTRIB, 0, IRecipientFilter &, int, const protobuf::Message &);
|
|
|
|
#else
|
2010-07-28 00:32:32 +02:00
|
|
|
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
2008-11-14 16:18:30 +01:00
|
|
|
SH_DECL_HOOK3(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRecipientFilter *, int, const char *);
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
SH_DECL_HOOK2(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRecipientFilter *, int);
|
2008-11-14 16:18:30 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
SH_DECL_HOOK0_void(IVEngineServer, MessageEnd, SH_NOATTRIB, 0);
|
2020-03-11 23:36:25 +01:00
|
|
|
#endif // ==SE_CSGO || ==SE_BLADE
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
UserMessages::UserMessages()
|
|
|
|
#ifndef USE_PROTOBUF_USERMESSAGES
|
|
|
|
: m_InterceptBuffer(m_pBase, 2500)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
: m_InterceptBuffer(nullptr)
|
2013-01-23 03:43:12 +01:00
|
|
|
{
|
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
m_HookCount = 0;
|
|
|
|
m_InExec = false;
|
|
|
|
m_InHook = false;
|
|
|
|
m_CurFlags = 0;
|
|
|
|
m_CurId = INVALID_MESSAGE_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
UserMessages::~UserMessages()
|
|
|
|
{
|
|
|
|
CStack<ListenerInfo *>::iterator iter;
|
|
|
|
for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++)
|
|
|
|
{
|
|
|
|
delete (*iter);
|
|
|
|
}
|
|
|
|
m_FreeListeners.popall();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserMessages::OnSourceModStartup(bool late)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifndef USE_PROTOBUF_USERMESSAGES
|
2008-03-30 09:00:22 +02:00
|
|
|
/* -1 means SourceMM was unable to get the user message list */
|
|
|
|
m_FallbackSearch = (g_SMAPI->GetUserMessageCount() == -1);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserMessages::OnSourceModAllInitialized()
|
|
|
|
{
|
2013-03-29 19:37:29 +01:00
|
|
|
sharesys->AddInterface(NULL, this);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserMessages::OnSourceModAllShutdown()
|
|
|
|
{
|
|
|
|
if (m_HookCount)
|
|
|
|
{
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
2013-03-17 03:15:25 +01:00
|
|
|
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
2013-03-17 03:15:25 +01:00
|
|
|
SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
m_HookCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int UserMessages::GetMessageIndex(const char *msg)
|
|
|
|
{
|
2016-04-27 05:18:47 +02:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
2013-01-23 03:43:12 +01:00
|
|
|
// Can split this per engine and/or game later
|
|
|
|
return g_Cstrike15UsermessageHelpers.GetIndex(msg);
|
2020-03-11 23:36:25 +01:00
|
|
|
#elif SOURCE_ENGINE == SE_BLADE
|
|
|
|
return g_BerimbauUsermessageHelpers.GetIndex(msg);
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-08-25 21:16:07 +02:00
|
|
|
int msgid;
|
|
|
|
if (!m_Names.retrieve(msg, &msgid))
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (m_FallbackSearch)
|
|
|
|
{
|
|
|
|
char msgbuf[64];
|
|
|
|
int size;
|
|
|
|
msgid = 0;
|
|
|
|
|
|
|
|
while (gamedll->GetUserMessageInfo(msgid, msgbuf, sizeof(msgbuf), size))
|
|
|
|
{
|
|
|
|
if (strcmp(msgbuf, msg) == 0)
|
|
|
|
{
|
2013-08-25 21:16:07 +02:00
|
|
|
m_Names.insert(msg, msgid);
|
2008-03-30 09:00:22 +02:00
|
|
|
return msgid;
|
|
|
|
}
|
|
|
|
msgid++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msgid = g_SMAPI->FindUserMessage(msg);
|
|
|
|
|
|
|
|
if (msgid != INVALID_MESSAGE_ID)
|
2013-08-25 21:16:07 +02:00
|
|
|
m_Names.insert(msg, msgid);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return msgid;
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlength) const
|
|
|
|
{
|
2013-03-19 16:19:38 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
2016-04-27 05:18:47 +02:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
2013-01-23 03:43:12 +01:00
|
|
|
const char *pszName = g_Cstrike15UsermessageHelpers.GetName(msgid);
|
2020-03-11 23:36:25 +01:00
|
|
|
#elif SOURCE_ENGINE == SE_BLADE
|
|
|
|
const char *pszName = g_BerimbauUsermessageHelpers.GetName(msgid);
|
2013-03-19 16:19:38 +01:00
|
|
|
#endif
|
2013-01-23 03:43:12 +01:00
|
|
|
if (!pszName)
|
|
|
|
return false;
|
|
|
|
|
2015-09-06 06:44:18 +02:00
|
|
|
ke::SafeStrcpy(buffer, maxlength, pszName);
|
2013-01-23 03:43:12 +01:00
|
|
|
return true;
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
if (m_FallbackSearch)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
return gamedll->GetUserMessageInfo(msgid, buffer, maxlength, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *msg = g_SMAPI->GetUserMessage(msgid);
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
{
|
2015-09-06 06:44:18 +02:00
|
|
|
ke::SafeStrcpy(buffer, maxlength, msg);
|
2008-03-30 09:00:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
bf_write *UserMessages::StartBitBufMessage(int msg_id, const cell_t players[], unsigned int playersNum, int flags)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
return NULL;
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
bf_write *buffer;
|
|
|
|
|
|
|
|
if (m_InExec || m_InHook)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (msg_id < 0 || msg_id >= 255)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_CellRecFilter.Initialize(players, playersNum);
|
|
|
|
|
|
|
|
m_CurFlags = flags;
|
|
|
|
if (m_CurFlags & USERMSG_INITMSG)
|
|
|
|
{
|
|
|
|
m_CellRecFilter.SetToInit(true);
|
|
|
|
}
|
|
|
|
if (m_CurFlags & USERMSG_RELIABLE)
|
|
|
|
{
|
|
|
|
m_CellRecFilter.SetToReliable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_InExec = true;
|
|
|
|
|
|
|
|
if (m_CurFlags & USERMSG_BLOCKHOOKS)
|
|
|
|
{
|
2010-07-28 00:32:32 +02:00
|
|
|
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
2008-11-14 16:18:30 +01:00
|
|
|
buffer = ENGINE_CALL(UserMessageBegin)(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, g_SMAPI->GetUserMessage(msg_id));
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
buffer = ENGINE_CALL(UserMessageBegin)(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id);
|
2008-11-14 16:18:30 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
} else {
|
2010-07-28 00:32:32 +02:00
|
|
|
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
2008-11-14 16:18:30 +01:00
|
|
|
buffer = engine->UserMessageBegin(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, g_SMAPI->GetUserMessage(msg_id));
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
buffer = engine->UserMessageBegin(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id);
|
2008-11-14 16:18:30 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif // USE_PROTOBUF_USERMESSAGES
|
|
|
|
}
|
|
|
|
|
|
|
|
google::protobuf::Message *UserMessages::StartProtobufMessage(int msg_id, const cell_t players[], unsigned int playersNum, int flags)
|
|
|
|
{
|
|
|
|
#ifndef USE_PROTOBUF_USERMESSAGES
|
|
|
|
return NULL;
|
|
|
|
#else
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
PbHandle buffer;
|
2013-01-23 03:43:12 +01:00
|
|
|
|
|
|
|
if (m_InExec || m_InHook)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (msg_id < 0 || msg_id >= 255)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_CurId = msg_id;
|
|
|
|
m_CellRecFilter.Initialize(players, playersNum);
|
|
|
|
|
|
|
|
m_CurFlags = flags;
|
|
|
|
if (m_CurFlags & USERMSG_INITMSG)
|
|
|
|
{
|
|
|
|
m_CellRecFilter.SetToInit(true);
|
|
|
|
}
|
|
|
|
if (m_CurFlags & USERMSG_RELIABLE)
|
|
|
|
{
|
|
|
|
m_CellRecFilter.SetToReliable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_InExec = true;
|
|
|
|
|
|
|
|
if (m_CurFlags & USERMSG_BLOCKHOOKS)
|
|
|
|
{
|
|
|
|
// direct message creation, return buffer "from engine". keep track
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
m_FakeEngineBuffer =
|
|
|
|
PbHandle(GetMessagePrototype(msg_id)->New(), PbHandle::Owned, PbHandle::Local);
|
|
|
|
buffer = m_FakeEngineBuffer.AsUnowned();
|
2013-01-23 03:43:12 +01:00
|
|
|
} else {
|
2013-01-26 18:14:40 +01:00
|
|
|
char messageName[32];
|
|
|
|
if (!GetMessageName(msg_id, messageName, sizeof(messageName)))
|
|
|
|
{
|
|
|
|
m_InExec = false;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
// The message returned here should always local.
|
|
|
|
auto msg = OnStartMessage_Pre(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, messageName);
|
2013-01-23 03:43:12 +01:00
|
|
|
switch (m_FakeMetaRes)
|
|
|
|
{
|
|
|
|
case MRES_IGNORED:
|
|
|
|
case MRES_HANDLED:
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
m_FakeEngineBuffer =
|
|
|
|
PbHandle(GetMessagePrototype(msg_id)->New(), PbHandle::Owned, PbHandle::Local);
|
|
|
|
buffer = m_FakeEngineBuffer.AsUnowned();
|
2013-01-23 03:43:12 +01:00
|
|
|
break;
|
|
|
|
case MRES_OVERRIDE:
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
m_FakeEngineBuffer =
|
|
|
|
PbHandle(GetMessagePrototype(msg_id)->New(), PbHandle::Owned, PbHandle::Local);
|
2013-01-23 03:43:12 +01:00
|
|
|
// fallthrough
|
|
|
|
case MRES_SUPERCEDE:
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
buffer = std::move(msg);
|
2013-01-23 03:43:12 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-26 18:14:40 +01:00
|
|
|
OnStartMessage_Post(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, messageName);
|
2013-01-23 03:43:12 +01:00
|
|
|
}
|
|
|
|
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
assert(!buffer.is_owned());
|
|
|
|
return buffer.GetLocalMessage();
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif // USE_PROTOBUF_USERMESSAGES
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UserMessages::EndMessage()
|
|
|
|
{
|
|
|
|
if (!m_InExec)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
2020-06-23 19:12:23 +02:00
|
|
|
PbHandle localBuffer = std::move(m_FakeEngineBuffer);
|
2013-01-23 03:43:12 +01:00
|
|
|
if (m_CurFlags & USERMSG_BLOCKHOOKS)
|
|
|
|
{
|
2020-06-23 19:12:23 +02:00
|
|
|
PbHandle priv = localBuffer.ToPrivate(m_CurId);
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
ENGINE_CALL(SendUserMessage)(static_cast<IRecipientFilter &>(m_CellRecFilter), m_CurId,
|
|
|
|
*priv.GetPrivateMessage());
|
2013-01-23 03:43:12 +01:00
|
|
|
} else {
|
|
|
|
OnMessageEnd_Pre();
|
|
|
|
|
|
|
|
switch (m_FakeMetaRes)
|
|
|
|
{
|
|
|
|
case MRES_IGNORED:
|
|
|
|
case MRES_HANDLED:
|
|
|
|
case MRES_OVERRIDE:
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
{
|
2020-06-23 19:12:23 +02:00
|
|
|
PbHandle priv = localBuffer.ToPrivate(m_CurId);
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
engine->SendUserMessage(static_cast<IRecipientFilter &>(m_CellRecFilter), m_CurId,
|
|
|
|
*priv.GetPrivateMessage());
|
2013-01-23 03:43:12 +01:00
|
|
|
break;
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
}
|
2013-01-23 03:43:12 +01:00
|
|
|
//case MRES_SUPERCEDE:
|
|
|
|
}
|
|
|
|
|
|
|
|
OnMessageEnd_Post();
|
|
|
|
}
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
if (m_CurFlags & USERMSG_BLOCKHOOKS)
|
|
|
|
{
|
|
|
|
ENGINE_CALL(MessageEnd)();
|
|
|
|
} else {
|
|
|
|
engine->MessageEnd();
|
|
|
|
}
|
2020-03-11 23:36:25 +01:00
|
|
|
#endif // SE_CSGO || SE_BLADE
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
m_InExec = false;
|
|
|
|
m_CurFlags = 0;
|
|
|
|
m_CellRecFilter.Reset();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
UserMessageType UserMessages::GetUserMessageType() const
|
|
|
|
{
|
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
return UM_Protobuf;
|
|
|
|
#else
|
|
|
|
return UM_BitBuf;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-03-01 22:39:25 +01:00
|
|
|
bool UserMessages::HookUserMessage2(int msg_id,
|
|
|
|
IUserMessageListener *pListener,
|
|
|
|
bool intercept)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
return InternalHook(msg_id, (IProtobufUserMessageListener *)pListener, intercept, true);
|
|
|
|
#else
|
|
|
|
return InternalHook(msg_id, (IBitBufUserMessageListener *)pListener, intercept, true);
|
|
|
|
#endif
|
2009-03-01 22:39:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UserMessages::UnhookUserMessage2(int msg_id,
|
|
|
|
IUserMessageListener *pListener,
|
|
|
|
bool intercept)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
return InternalUnhook(msg_id, (IProtobufUserMessageListener *)pListener, intercept, true);
|
|
|
|
#else
|
|
|
|
return InternalUnhook(msg_id, (IBitBufUserMessageListener *)pListener, intercept, true);
|
|
|
|
#endif
|
2009-03-01 22:39:25 +01:00
|
|
|
}
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
bool UserMessages::HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept)
|
2009-03-01 22:39:25 +01:00
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
return InternalHook(msg_id, (IProtobufUserMessageListener *)pListener, intercept, false);
|
|
|
|
#else
|
|
|
|
return InternalHook(msg_id, (IBitBufUserMessageListener *)pListener, intercept, false);
|
|
|
|
#endif
|
2009-03-01 22:39:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UserMessages::UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
return InternalUnhook(msg_id, (IProtobufUserMessageListener *)pListener, intercept, false);
|
|
|
|
#else
|
|
|
|
return InternalUnhook(msg_id, (IBitBufUserMessageListener *)pListener, intercept, false);
|
|
|
|
#endif
|
2009-03-01 22:39:25 +01:00
|
|
|
}
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
bool UserMessages::InternalHook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew)
|
|
|
|
#else
|
|
|
|
bool UserMessages::InternalHook(int msg_id, IBitBufUserMessageListener *pListener, bool intercept, bool isNew)
|
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (msg_id < 0 || msg_id >= 255)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListenerInfo *pInfo;
|
|
|
|
if (m_FreeListeners.empty())
|
|
|
|
{
|
|
|
|
pInfo = new ListenerInfo;
|
|
|
|
} else {
|
|
|
|
pInfo = m_FreeListeners.front();
|
|
|
|
m_FreeListeners.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
pInfo->Callback = pListener;
|
|
|
|
pInfo->IsHooked = false;
|
|
|
|
pInfo->KillMe = false;
|
2009-03-01 22:39:25 +01:00
|
|
|
pInfo->IsNew = isNew;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
if (!m_HookCount++)
|
|
|
|
{
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
2013-03-17 03:15:25 +01:00
|
|
|
SH_ADD_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
|
|
|
SH_ADD_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
2013-03-17 03:15:25 +01:00
|
|
|
SH_ADD_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false);
|
|
|
|
SH_ADD_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true);
|
|
|
|
SH_ADD_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false);
|
|
|
|
SH_ADD_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (intercept)
|
|
|
|
{
|
|
|
|
m_msgIntercepts[msg_id].push_back(pInfo);
|
|
|
|
} else {
|
|
|
|
m_msgHooks[msg_id].push_back(pInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:19:38 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
const protobuf::Message *GetMessagePrototype(int msg_type)
|
2013-03-19 16:19:38 +01:00
|
|
|
{
|
2016-04-27 05:18:47 +02:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
2013-03-19 16:19:38 +01:00
|
|
|
return g_Cstrike15UsermessageHelpers.GetPrototype(msg_type);
|
2020-03-11 23:36:25 +01:00
|
|
|
#elif SOURCE_ENGINE == SE_BLADE
|
|
|
|
return g_BerimbauUsermessageHelpers.GetPrototype(msg_type);
|
2013-03-19 16:19:38 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
bool UserMessages::InternalUnhook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew)
|
|
|
|
#else
|
|
|
|
bool UserMessages::InternalUnhook(int msg_id, IBitBufUserMessageListener *pListener, bool intercept, bool isNew)
|
|
|
|
#endif
|
2009-03-01 22:39:25 +01:00
|
|
|
{
|
2008-03-30 09:00:22 +02:00
|
|
|
MsgList *pList;
|
|
|
|
MsgIter iter;
|
|
|
|
ListenerInfo *pInfo;
|
|
|
|
bool deleted = false;
|
|
|
|
|
|
|
|
if (msg_id < 0 || msg_id >= 255)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pList = (intercept) ? &m_msgIntercepts[msg_id] : &m_msgHooks[msg_id];
|
|
|
|
for (iter=pList->begin(); iter!=pList->end(); iter++)
|
|
|
|
{
|
|
|
|
pInfo = (*iter);
|
2009-03-01 22:39:25 +01:00
|
|
|
if (pInfo->Callback == pListener && pInfo->IsNew == isNew)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (pInfo->IsHooked)
|
|
|
|
{
|
|
|
|
pInfo->KillMe = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
pList->erase(iter);
|
|
|
|
deleted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deleted)
|
|
|
|
{
|
|
|
|
_DecRefCounter();
|
|
|
|
}
|
|
|
|
|
|
|
|
return deleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserMessages::_DecRefCounter()
|
|
|
|
{
|
|
|
|
if (--m_HookCount == 0)
|
|
|
|
{
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
2013-03-17 03:15:25 +01:00
|
|
|
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
2013-03-17 03:15:25 +01:00
|
|
|
SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
2013-01-23 03:43:12 +01:00
|
|
|
void UserMessages::OnSendUserMessage_Pre(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg)
|
|
|
|
{
|
2016-04-27 05:18:47 +02:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
2020-03-11 23:36:25 +01:00
|
|
|
const char *pszName = g_Cstrike15UsermessageHelpers.GetName(msg_type);
|
|
|
|
#elif SOURCE_ENGINE == SE_BLADE
|
|
|
|
const char *pszName = g_BerimbauUsermessageHelpers.GetName(msg_type);
|
2013-03-19 16:19:38 +01:00
|
|
|
#endif
|
2020-03-11 23:36:25 +01:00
|
|
|
|
|
|
|
OnStartMessage_Pre(&filter, msg_type, pszName);
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
|
|
|
{
|
2013-02-11 05:06:26 +01:00
|
|
|
int size = msg.ByteSize();
|
|
|
|
uint8 *data = (uint8 *)stackalloc(size);
|
|
|
|
msg.SerializePartialToArray(data, size);
|
2013-02-11 21:11:04 +01:00
|
|
|
m_InterceptBuffer->ParsePartialFromArray(data, size);
|
2013-01-23 03:43:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
m_FakeEngineBuffer =
|
|
|
|
PbHandle(&const_cast<protobuf::Message &>(msg), PbHandle::Unowned, PbHandle::Private);
|
2013-01-23 03:43:12 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 23:36:25 +01:00
|
|
|
OnStartMessage_Post(&filter, msg_type, pszName);
|
2013-02-11 21:11:04 +01:00
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
OnMessageEnd_Pre();
|
|
|
|
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
|
|
|
RETURN_META(MRES_SUPERCEDE);
|
|
|
|
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserMessages::OnSendUserMessage_Post(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg)
|
|
|
|
{
|
|
|
|
OnMessageEnd_Post();
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
|
|
#define UM_RETURN_META_VALUE(res, val) \
|
|
|
|
m_FakeMetaRes = res; \
|
|
|
|
return val;
|
|
|
|
|
|
|
|
#define UM_RETURN_META(res) \
|
|
|
|
m_FakeMetaRes = res; \
|
|
|
|
return;
|
|
|
|
#else
|
|
|
|
#define UM_RETURN_META_VALUE(res, val) \
|
|
|
|
RETURN_META_VALUE(res, val)
|
|
|
|
|
|
|
|
#define UM_RETURN_META(res) \
|
|
|
|
RETURN_META(res)
|
|
|
|
#endif
|
|
|
|
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
PbHandle UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name)
|
2013-01-23 03:43:12 +01:00
|
|
|
#elif SOURCE_ENGINE >= SE_LEFT4DEAD
|
2008-11-14 16:18:30 +01:00
|
|
|
bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name)
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_type)
|
2008-11-14 16:18:30 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
bool is_intercept_empty = m_msgIntercepts[msg_type].empty();
|
|
|
|
bool is_hook_empty = m_msgHooks[msg_type].empty();
|
|
|
|
|
|
|
|
if ((is_intercept_empty && is_hook_empty)
|
|
|
|
|| (m_InExec && (m_CurFlags & USERMSG_BLOCKHOOKS)))
|
|
|
|
{
|
|
|
|
m_InHook = false;
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
UM_RETURN_META_VALUE(MRES_IGNORED, nullptr);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m_CurId = msg_type;
|
|
|
|
m_CurRecFilter = filter;
|
|
|
|
m_InHook = true;
|
|
|
|
m_BlockEndPost = false;
|
|
|
|
|
|
|
|
if (!is_intercept_empty)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
m_InterceptBuffer =
|
|
|
|
PbHandle(GetMessagePrototype(msg_type)->New(), PbHandle::Owned, PbHandle::Local);
|
|
|
|
UM_RETURN_META_VALUE(MRES_SUPERCEDE, m_InterceptBuffer.AsUnowned());
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
m_InterceptBuffer.Reset();
|
2013-01-23 03:43:12 +01:00
|
|
|
UM_RETURN_META_VALUE(MRES_SUPERCEDE, &m_InterceptBuffer);
|
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
UM_RETURN_META_VALUE(MRES_IGNORED, nullptr);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
void* UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name)
|
2013-01-23 03:43:12 +01:00
|
|
|
#elif SOURCE_ENGINE >= SE_LEFT4DEAD
|
2008-11-14 16:18:30 +01:00
|
|
|
bf_write *UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name)
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
bf_write *UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_type)
|
2008-11-14 16:18:30 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (!m_InHook)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
UM_RETURN_META_VALUE(MRES_IGNORED, NULL);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
2013-02-11 21:11:04 +01:00
|
|
|
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
m_OrigBuffer = m_InterceptBuffer.AsUnowned();
|
2013-02-11 21:11:04 +01:00
|
|
|
else
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
m_OrigBuffer = m_FakeEngineBuffer.AsUnowned();
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
m_OrigBuffer = META_RESULT_ORIG_RET(bf_write *);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
UM_RETURN_META_VALUE(MRES_IGNORED, NULL);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserMessages::OnMessageEnd_Post()
|
|
|
|
{
|
2009-03-01 22:39:25 +01:00
|
|
|
if (!m_InHook)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
UM_RETURN_META(MRES_IGNORED);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MsgList *pList;
|
|
|
|
MsgIter iter;
|
|
|
|
ListenerInfo *pInfo;
|
|
|
|
|
2009-02-18 03:03:17 +01:00
|
|
|
m_InHook = false;
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
pList = &m_msgIntercepts[m_CurId];
|
|
|
|
for (iter=pList->begin(); iter!=pList->end(); )
|
|
|
|
{
|
|
|
|
pInfo = (*iter);
|
2009-03-01 22:39:25 +01:00
|
|
|
if (m_BlockEndPost && !pInfo->IsNew)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-03-30 09:00:22 +02:00
|
|
|
pInfo->IsHooked = true;
|
|
|
|
pInfo->Callback->OnUserMessageSent(m_CurId);
|
2009-03-01 22:39:25 +01:00
|
|
|
if (pInfo->IsNew)
|
|
|
|
{
|
|
|
|
pInfo->Callback->OnPostUserMessage(m_CurId, !m_BlockEndPost);
|
|
|
|
}
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
if (pInfo->KillMe)
|
|
|
|
{
|
|
|
|
iter = pList->erase(iter);
|
|
|
|
m_FreeListeners.push(pInfo);
|
|
|
|
_DecRefCounter();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pInfo->IsHooked = false;
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
pList = &m_msgHooks[m_CurId];
|
|
|
|
for (iter=pList->begin(); iter!=pList->end(); )
|
|
|
|
{
|
|
|
|
pInfo = (*iter);
|
2009-03-01 22:39:25 +01:00
|
|
|
if (m_BlockEndPost && !pInfo->IsNew)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-03-30 09:00:22 +02:00
|
|
|
pInfo->IsHooked = true;
|
|
|
|
pInfo->Callback->OnUserMessageSent(m_CurId);
|
2009-03-01 22:39:25 +01:00
|
|
|
if (pInfo->IsNew)
|
|
|
|
{
|
|
|
|
pInfo->Callback->OnPostUserMessage(m_CurId, !m_BlockEndPost);
|
|
|
|
}
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
if (pInfo->KillMe)
|
|
|
|
{
|
|
|
|
iter = pList->erase(iter);
|
|
|
|
m_FreeListeners.push(pInfo);
|
|
|
|
_DecRefCounter();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pInfo->IsHooked = false;
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserMessages::OnMessageEnd_Pre()
|
|
|
|
{
|
|
|
|
if (!m_InHook)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
UM_RETURN_META(MRES_IGNORED);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MsgList *pList;
|
|
|
|
MsgIter iter;
|
|
|
|
ListenerInfo *pInfo;
|
|
|
|
|
|
|
|
ResultType res;
|
|
|
|
bool intercepted = false;
|
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
pList = &m_msgIntercepts[m_CurId];
|
|
|
|
for (iter=pList->begin(); iter!=pList->end(); )
|
|
|
|
{
|
|
|
|
pInfo = (*iter);
|
|
|
|
pInfo->IsHooked = true;
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
PbHandle local = m_InterceptBuffer.ToLocal(m_CurId);
|
|
|
|
res = pInfo->Callback->InterceptUserMessage(m_CurId, local.GetLocalMessage(), m_CurRecFilter);
|
|
|
|
m_InterceptBuffer.CopyFrom(local);
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
res = pInfo->Callback->InterceptUserMessage(m_CurId, &m_InterceptBuffer, m_CurRecFilter);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
intercepted = true;
|
|
|
|
|
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case Pl_Stop:
|
|
|
|
{
|
|
|
|
if (pInfo->KillMe)
|
|
|
|
{
|
|
|
|
pList->erase(iter);
|
|
|
|
m_FreeListeners.push(pInfo);
|
|
|
|
_DecRefCounter();
|
|
|
|
goto supercede;
|
|
|
|
}
|
|
|
|
pInfo->IsHooked = false;
|
|
|
|
goto supercede;
|
|
|
|
}
|
|
|
|
case Pl_Handled:
|
|
|
|
{
|
|
|
|
handled = true;
|
|
|
|
if (pInfo->KillMe)
|
|
|
|
{
|
|
|
|
iter = pList->erase(iter);
|
|
|
|
m_FreeListeners.push(pInfo);
|
|
|
|
_DecRefCounter();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if (pInfo->KillMe)
|
|
|
|
{
|
|
|
|
iter = pList->erase(iter);
|
|
|
|
m_FreeListeners.push(pInfo);
|
|
|
|
_DecRefCounter();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pInfo->IsHooked = false;
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
2009-05-24 18:01:18 +02:00
|
|
|
if (!handled && intercepted)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
PbHandle priv = m_InterceptBuffer.ToPrivate(m_CurId);
|
|
|
|
ENGINE_CALL(SendUserMessage)(static_cast<IRecipientFilter &>(*m_CurRecFilter), m_CurId, *priv.GetPrivateMessage());
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
bf_write *engine_bfw;
|
2010-07-28 00:32:32 +02:00
|
|
|
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
2008-11-14 16:18:30 +01:00
|
|
|
engine_bfw = ENGINE_CALL(UserMessageBegin)(m_CurRecFilter, m_CurId, g_SMAPI->GetUserMessage(m_CurId));
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
engine_bfw = ENGINE_CALL(UserMessageBegin)(m_CurRecFilter, m_CurId);
|
2008-11-14 16:18:30 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
m_ReadBuffer.StartReading(m_InterceptBuffer.GetBasePointer(), m_InterceptBuffer.GetNumBytesWritten());
|
|
|
|
engine_bfw->WriteBitsFromBuffer(&m_ReadBuffer, m_InterceptBuffer.GetNumBitsWritten());
|
|
|
|
ENGINE_CALL(MessageEnd)();
|
2020-03-11 23:36:25 +01:00
|
|
|
#endif // SE_CSGO || SE_BLADE
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-03-11 23:36:25 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
|
Introduce a pbproxy library to solve macOS linker issues.
On SDKs which use protobufs, the engine has objects compiled against a specific
version of protobuf. Normally this is fine, we take care on Linux to use the
same C++ ABI. On macOS however, we use libc++ to enable C++11 functionality,
whereas the protobuf library has been compiled with libstc++. These ABIs are
not compatible.
To address the problem, we introduce PbHandle. PbHandle is a wrapper around
protobuf::Message with two added pieces of state: whether or not the handle
"owns" the message (and can free it in its destructor), and whether or not
the handle was created by the engine (private) or created by SourceMod
(local).
Whenever we transfer a protobuf::Message pointer to SourceMod, we must take
care to convert it to a Local version first. Whenever we transfer a protobuf
pointer to the engine, we must convert it to a Private handle.
For platforms with no ABI differences (almost all of them), the handle is a
no-op. The private and local localities are compatible and no translation
takes place.
On macOS, CS:GO does require translation. SourceMod loads a tiny shim
library that contains a copy of the protobuf sources compiled against the
game's ABI. It then provides serialization and deserialization methods.
SourceMod must not interact with the game's protobuf objects without first
going through this proxy library.
Note that PbHandle is not quite like unique_ptr. It can be converted into a
PbHandle that does not destroy the underlying object. This is mainly because
UserMessages.cpp has rather complex state, so it is useful to track locality
without destroying an object. An unowned PbHandle must not outlive the
owning PbHandle.
2020-05-23 07:57:42 +02:00
|
|
|
PbHandle tmp_msg(GetMessagePrototype(m_CurId)->New(), PbHandle::Owned, PbHandle::Local);
|
|
|
|
tmp_msg.CopyFrom(m_OrigBuffer);
|
|
|
|
auto pTempMsg = tmp_msg.GetLocalMessage();
|
2013-02-11 05:11:04 +01:00
|
|
|
#else
|
|
|
|
bf_write *pTempMsg = m_OrigBuffer;
|
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-02-11 05:06:26 +01:00
|
|
|
pList = &m_msgHooks[m_CurId];
|
|
|
|
for (iter=pList->begin(); iter!=pList->end(); )
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2013-02-11 05:06:26 +01:00
|
|
|
pInfo = (*iter);
|
|
|
|
pInfo->IsHooked = true;
|
|
|
|
pInfo->Callback->OnUserMessage(m_CurId, pTempMsg, m_CurRecFilter);
|
|
|
|
|
|
|
|
if (pInfo->KillMe)
|
|
|
|
{
|
|
|
|
iter = pList->erase(iter);
|
|
|
|
m_FreeListeners.push(pInfo);
|
|
|
|
_DecRefCounter();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pInfo->IsHooked = false;
|
|
|
|
iter++;
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
UM_RETURN_META((intercepted) ? MRES_SUPERCEDE : MRES_IGNORED);
|
2008-03-30 09:00:22 +02:00
|
|
|
supercede:
|
|
|
|
m_BlockEndPost = true;
|
2013-01-23 03:43:12 +01:00
|
|
|
UM_RETURN_META(MRES_SUPERCEDE);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|