Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Remove uses of Autohook fromserverchathooks.cpp #834

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions primedev/server/serverchathooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>

AUTOHOOK_INIT()

class CServerGameDLL;

class CRecipientFilter
Expand All @@ -19,9 +17,6 @@ class CRecipientFilter

CServerGameDLL* g_pServerGameDLL;

void(__fastcall* CServerGameDLL__OnReceivedSayTextMessage)(
CServerGameDLL* self, unsigned int senderPlayerId, const char* text, int channelId);

void(__fastcall* CRecipientFilter__Construct)(CRecipientFilter* self);
void(__fastcall* CRecipientFilter__Destruct)(CRecipientFilter* self);
void(__fastcall* CRecipientFilter__AddAllPlayers)(CRecipientFilter* self);
Expand All @@ -35,10 +30,11 @@ void(__fastcall* MessageWriteString)(const char* sz);
void(__fastcall* MessageWriteBool)(bool bValue);

bool bShouldCallSayTextHook = false;
// clang-format off
AUTOHOOK(_CServerGameDLL__OnReceivedSayTextMessage, server.dll + 0x1595C0,
void, __fastcall, (CServerGameDLL* self, unsigned int senderPlayerId, const char* text, bool isTeam))
// clang-format on

static void(__fastcall* o_pCServerGameDLL__OnReceivedSayTextMessage)(
CServerGameDLL* self, unsigned int senderPlayerId, const char* text, bool isTeam) = nullptr;
static void __fastcall h_CServerGameDLL__OnReceivedSayTextMessage(
CServerGameDLL* self, unsigned int senderPlayerId, const char* text, bool isTeam)
{
RemoveAsciiControlSequences(const_cast<char*>(text), true);

Expand All @@ -47,7 +43,7 @@ void, __fastcall, (CServerGameDLL* self, unsigned int senderPlayerId, const char
if (bShouldCallSayTextHook)
{
bShouldCallSayTextHook = false;
_CServerGameDLL__OnReceivedSayTextMessage(self, senderPlayerId, text, isTeam);
o_pCServerGameDLL__OnReceivedSayTextMessage(self, senderPlayerId, text, isTeam);
return;
}

Expand All @@ -59,13 +55,13 @@ void, __fastcall, (CServerGameDLL* self, unsigned int senderPlayerId, const char
"CServerGameDLL_ProcessMessageStartThread", static_cast<int>(senderPlayerId) - 1, text, isTeam);

if (result == SQRESULT_ERROR)
_CServerGameDLL__OnReceivedSayTextMessage(self, senderPlayerId, text, isTeam);
o_pCServerGameDLL__OnReceivedSayTextMessage(self, senderPlayerId, text, isTeam);
}

void ChatSendMessage(unsigned int playerIndex, const char* text, bool isTeam)
{
bShouldCallSayTextHook = true;
CServerGameDLL__OnReceivedSayTextMessage(
h_CServerGameDLL__OnReceivedSayTextMessage(
g_pServerGameDLL,
// Ensure the first bit isn't set, since this indicates a custom message
(playerIndex + 1) & CUSTOM_MESSAGE_INDEX_MASK,
Expand Down Expand Up @@ -156,10 +152,9 @@ ON_DLL_LOAD("engine.dll", EngineServerChatHooks, (CModule module))

ON_DLL_LOAD_RELIESON("server.dll", ServerChatHooks, ServerSquirrel, (CModule module))
{
AUTOHOOK_DISPATCH_MODULE(server.dll)
o_pCServerGameDLL__OnReceivedSayTextMessage = module.Offset(0x1595C0).RCast<decltype(o_pCServerGameDLL__OnReceivedSayTextMessage)>();
HookAttach(&(PVOID&)o_pCServerGameDLL__OnReceivedSayTextMessage, (PVOID)h_CServerGameDLL__OnReceivedSayTextMessage);

CServerGameDLL__OnReceivedSayTextMessage =
module.Offset(0x1595C0).RCast<void(__fastcall*)(CServerGameDLL*, unsigned int, const char*, int)>();
CRecipientFilter__Construct = module.Offset(0x1E9440).RCast<void(__fastcall*)(CRecipientFilter*)>();
CRecipientFilter__Destruct = module.Offset(0x1E9700).RCast<void(__fastcall*)(CRecipientFilter*)>();
CRecipientFilter__AddAllPlayers = module.Offset(0x1E9940).RCast<void(__fastcall*)(CRecipientFilter*)>();
Expand Down
Loading