Skip to content

Commit 48b5f88

Browse files
committed
Fix compilation for l4d2 & csgo
1 parent a6c3aea commit 48b5f88

4 files changed

Lines changed: 38 additions & 46 deletions

File tree

core/UserMessages.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ google::protobuf::Message *UserMessages::StartProtobufMessage(int msg_id, const
268268
return NULL;
269269
}
270270

271-
protobuf::Message *msg = OnStartMessage_Pre(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, messageName);
271+
protobuf::Message *msg = OnStartMessage_Pre(engine, static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, messageName).ret;
272272
switch (m_FakeMetaRes)
273273
{
274274
case KHook::Action::Ignore:
@@ -284,7 +284,7 @@ google::protobuf::Message *UserMessages::StartProtobufMessage(int msg_id, const
284284
break;
285285
}
286286

287-
OnStartMessage_Post(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, messageName);
287+
OnStartMessage_Post(engine, static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, messageName);
288288
}
289289

290290
return buffer;
@@ -301,11 +301,11 @@ bool UserMessages::EndMessage()
301301
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
302302
if (m_CurFlags & USERMSG_BLOCKHOOKS)
303303
{
304-
ENGINE_CALL(SendUserMessage)(static_cast<IRecipientFilter &>(m_CellRecFilter), m_CurId, *m_FakeEngineBuffer);
304+
KHook::CallOriginal(&IVEngineServer::SendUserMessage, engine, static_cast<IRecipientFilter &>(m_CellRecFilter), m_CurId, *m_FakeEngineBuffer);
305305
delete m_FakeEngineBuffer;
306306
m_FakeEngineBuffer = NULL;
307307
} else {
308-
OnMessageEnd_Pre();
308+
OnMessageEnd_Pre(engine);
309309

310310
switch (m_FakeMetaRes)
311311
{
@@ -318,7 +318,7 @@ bool UserMessages::EndMessage()
318318
//case KHook::Action::Supersede:
319319
}
320320

321-
OnMessageEnd_Post();
321+
OnMessageEnd_Post(engine);
322322
}
323323
#else
324324
if (m_CurFlags & USERMSG_BLOCKHOOKS)
@@ -498,7 +498,7 @@ void UserMessages::_DecRefCounter()
498498
}
499499

500500
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
501-
KHook::Return<void> UserMessages::OnSendUserMessage_Pre(IVEngineServer*, IRecipientFilter &filter, int msg_type, const protobuf::Message &msg)
501+
KHook::Return<void> UserMessages::OnSendUserMessage_Pre(IVEngineServer* enginesrv, IRecipientFilter &filter, int msg_type, const protobuf::Message &msg)
502502
{
503503
#if SOURCE_ENGINE == SE_CSGO
504504
const char *pszName = g_Cstrike15UsermessageHelpers.GetName(msg_type);
@@ -508,7 +508,7 @@ KHook::Return<void> UserMessages::OnSendUserMessage_Pre(IVEngineServer*, IRecipi
508508
const char *pszName = g_VietnamUsermessageHelpers.GetName(msg_type);
509509
#endif
510510

511-
OnStartMessage_Pre(&filter, msg_type, pszName);
511+
OnStartMessage_Pre(enginesrv, &filter, msg_type, pszName);
512512

513513
if (m_FakeMetaRes == KHook::Action::Supersede)
514514
{
@@ -522,30 +522,30 @@ KHook::Return<void> UserMessages::OnSendUserMessage_Pre(IVEngineServer*, IRecipi
522522
m_FakeEngineBuffer = &const_cast<protobuf::Message &>(msg);
523523
}
524524

525-
OnStartMessage_Post(&filter, msg_type, pszName);
525+
OnStartMessage_Post(enginesrv, &filter, msg_type, pszName);
526526

527-
OnMessageEnd_Pre();
527+
OnMessageEnd_Pre(enginesrv);
528528
if (m_FakeMetaRes == KHook::Action::Supersede)
529529
return { KHook::Action::Supersede };
530530

531531
return { KHook::Action::Ignore };
532532
}
533533

534-
KHook::Return<void> UserMessages::OnSendUserMessage_Post(IVEngineServer*, IRecipientFilter &filter, int msg_type, const protobuf::Message &msg)
534+
KHook::Return<void> UserMessages::OnSendUserMessage_Post(IVEngineServer* enginesrv, IRecipientFilter &filter, int msg_type, const protobuf::Message &msg)
535535
{
536-
OnMessageEnd_Post();
536+
OnMessageEnd_Post(enginesrv);
537537
return { KHook::Action::Ignore };
538538
}
539539
#endif
540540

541541
#ifdef USE_PROTOBUF_USERMESSAGES
542542
#define UM_RETURN_META_VALUE(res, val) \
543543
m_FakeMetaRes = res; \
544-
return val;
544+
return { res, val };
545545

546546
#define UM_RETURN_META(res) \
547547
m_FakeMetaRes = res; \
548-
return;
548+
return { res };
549549
#else
550550
#define UM_RETURN_META_VALUE(res, val) \
551551
return { res, val };

core/logic/smn_core.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
#include <bridge/include/CoreProvider.h>
5959
#include <bridge/include/IScriptManager.h>
6060
#include <bridge/include/IExtensionBridge.h>
61-
#include "PseudoAddrManager.h"
6261

6362
using namespace SourceMod;
6463
using namespace SourcePawn;

extensions/sdktools/extension.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,29 @@ extern sp_nativeinfo_t g_ClientNatives[];
9797
static void InitSDKToolsAPI();
9898

9999
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
100-
CDetour *g_WriteBaselinesDetour = NULL;
101-
102-
DETOUR_DECL_MEMBER3(CNetworkStringTableContainer__WriteBaselines, void, char const *, mapName, void *, buffer, int, currentTick)
103-
{
100+
class CNetworkStringTableContainer;
101+
KHook::Return<void> CNetworkStringTableContainer__WriteBaselines(CNetworkStringTableContainer* container, char const * mapName, void * buffer, int currentTick) {
104102
// Replace nAtTick with INT_MAX to work around CS:GO engine bug.
105103
// Due to a timing issue in the engine, stringtable entries added in OnConfigsExecuted can be considered
106104
// to have been added in the future for the first client that connects, which causes them to be ignored
107105
// when iterating for networking, which triggers a Host_Error encoding the CreateStringTable netmsg.
108-
return DETOUR_MEMBER_CALL(CNetworkStringTableContainer__WriteBaselines)(mapName, buffer, INT_MAX);
106+
void (CNetworkStringTableContainer::*dummy_func)(const char*, void*, int) = nullptr;
107+
return KHook::Recall<decltype(dummy_func)>(dummy_func, { KHook::Action::Ignore }, container, mapName, buffer, INT_MAX);
109108
}
109+
KHook::Member<CNetworkStringTableContainer, void, const char*, void*, int> g_WriteBaselinesDetour(CNetworkStringTableContainer__WriteBaselines, nullptr);
110110
#endif
111111

112112
SDKTools::SDKTools() :
113+
#if defined CLIENTVOICE_HOOK_SUPPORT
114+
m_HookClientVoice(&IServerGameClients::ClientVoice, this, nullptr, &SDKTools::OnClientVoice),
115+
#endif
113116
m_HookSetClientListening(&IVoiceServer::SetClientListening, this, &SDKTools::OnSetClientListening, nullptr),
114117
m_HookClientCommand(&IServerGameClients::ClientCommand, this, nullptr, &SDKTools::OnClientCommand),
115-
m_HookLevelInit(&IServerGameDLL::LevelInit, this, nullptr, &SDKTools::LevelInit),
116-
m_HookLevelShutdown(&IServerGameDLL::LevelShutdown, this, nullptr, &SDKTools::LevelShutdown)
117118
#if SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_CSGO
118-
,m_HookOnSendClientCommand(&IVEngineServer::ClientCommand, this, &SDKTools::OnSendClientCommand, nullptr)
119-
#endif
120-
#if defined CLIENTVOICE_HOOK_SUPPORT
121-
,m_HookClientVoice(&IServerGameClients::ClientVoice, this, nullptr, &SDKTools::OnClientVoice)
119+
m_HookOnSendClientCommand(KHook::GetVtableIndex(&IVEngineServer::ClientCommand), this, &SDKTools::OnSendClientCommand, nullptr),
122120
#endif
121+
m_HookLevelInit(&IServerGameDLL::LevelInit, this, nullptr, &SDKTools::LevelInit),
122+
m_HookLevelShutdown(&IServerGameDLL::LevelShutdown, this, nullptr, &SDKTools::LevelShutdown)
123123
{}
124124

125125
bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late)
@@ -210,12 +210,12 @@ bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late)
210210
#endif
211211

212212
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
213-
g_WriteBaselinesDetour = DETOUR_CREATE_MEMBER(CNetworkStringTableContainer__WriteBaselines, "WriteBaselines");
214-
if (g_WriteBaselinesDetour) {
215-
g_WriteBaselinesDetour->EnableDetour();
216-
} else {
217-
g_pSM->LogError(myself, "Failed to find WriteBaselines signature -- stringtable error workaround disabled.");
213+
void* addr = nullptr;
214+
if (!g_pGameConf->GetMemSig("WriteBaselines", &addr) || addr == nullptr) {
215+
ke::SafeSprintf(error, maxlength, "Failed to find WriteBaselines signature -- stringtable error workaround disabled.");
216+
return false;
218217
}
218+
g_WriteBaselinesDetour.Configure(addr);
219219
#endif
220220

221221
return true;
@@ -247,10 +247,7 @@ void SDKTools::SDK_OnUnload()
247247
ShutdownHelpers();
248248

249249
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
250-
if (g_WriteBaselinesDetour) {
251-
g_WriteBaselinesDetour->DisableDetour();
252-
g_WriteBaselinesDetour = NULL;
253-
}
250+
g_WriteBaselinesDetour.Configure((void*)nullptr);
254251
#endif
255252

256253
if (g_pAcceptInput)

extensions/sdktools/vsound.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,16 +1343,14 @@ static cell_t EmitSoundEntry(IPluginContext *pContext, const cell_t *params)
13431343
if (g_InSoundHook)
13441344
{
13451345
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
1346-
SH_CALL(enginesoundPatch,
1347-
static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
1346+
KHook::CallOriginal<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
13481347
soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int, void *)>
1349-
(&IEngineSound::EmitSound))(crf, player[0], channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level, seed,
1348+
(&IEngineSound::EmitSound, engsound, crf, player[0], channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level, seed,
13501349
flags, pitch, pOrigin, pDir, pOrigVec, updatePos, soundtime, speakerentity, nullptr);
13511350
#else
1352-
SH_CALL(enginesoundPatch,
1353-
static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
1351+
KHook::CallOriginal<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
13541352
soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
1355-
(&IEngineSound::EmitSound))(crf, player[0], channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level, seed,
1353+
&IEngineSound::EmitSound, engsound, crf, player[0], channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level, seed,
13561354
flags, pitch, pOrigin, pDir, pOrigVec, updatePos, soundtime, speakerentity);
13571355
#endif
13581356
}
@@ -1367,16 +1365,14 @@ SH_CALL(enginesoundPatch,
13671365
if (g_InSoundHook)
13681366
{
13691367
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
1370-
SH_CALL(enginesoundPatch,
1371-
static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
1368+
KHook::CallOriginal<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
13721369
soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int, void *)>
1373-
(&IEngineSound::EmitSound))(crf, entity, channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level,
1370+
(&IEngineSound::EmitSound, engsound, crf, entity, channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level,
13741371
seed, flags, pitch, pOrigin, pDir, pOrigVec, updatePos, soundtime, speakerentity, nullptr);
13751372
#else
1376-
SH_CALL(enginesoundPatch,
1377-
static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
1373+
KHook::CallOriginal<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
13781374
soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
1379-
(&IEngineSound::EmitSound))(crf, entity, channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level,
1375+
(&IEngineSound::EmitSound, engsound, crf, entity, channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level,
13801376
seed, flags, pitch, pOrigin, pDir, pOrigVec, updatePos, soundtime, speakerentity);
13811377
#endif
13821378
}

0 commit comments

Comments
 (0)