From ee367004c65f857f849b37b827c8d8d2b0b723ba Mon Sep 17 00:00:00 2001 From: rumblefrog Date: Fri, 9 Apr 2021 00:25:21 -0400 Subject: [PATCH] wip(client) - passing shim build --- client/shim/AMBuildScript | 14 ++++++++++++-- client/shim/shim.cpp | 23 +++++++++++++++++++++-- client/shim/shim.h | 5 ++++- client/shim/sm_ext.cpp | 4 ++-- client/shim/sm_ext.h | 1 + 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/client/shim/AMBuildScript b/client/shim/AMBuildScript index 2600340..41de195 100644 --- a/client/shim/AMBuildScript +++ b/client/shim/AMBuildScript @@ -1,24 +1,30 @@ import os proj_name = 'source-chat-relay' + proj_srcs = [ 'shim.cpp', + 'sm_sdk_config.cpp', + 'sm_ext.cpp', 'libc_compat.cpp', 'asm/asm.c', 'CDetour/detours.cpp', 'util/MemoryUtils.cpp', ] + proj_c_flags = [ '-Wall', '-Wno-non-virtual-dtor', '-Wno-overloaded-virtual', '-Werror', ] + proj_c_flags_opt = [ '-O3', '-funroll-loops', '-pipe', ] + proj_c_flags_dbg = [ '-g', '-ggdb3', @@ -135,8 +141,8 @@ class MMSConfig(object): def detectSM(self): if builder.options.sm_path: self.sm_path = builder.options.sm_path - else - raise Exception('SM path not specified') + else: + raise Exception('SM path not specified') def detectSDKs(self): sdk_list = builder.options.sdks.split(',') @@ -308,6 +314,10 @@ class MMSConfig(object): os.path.join(context.currentSourcePath, 'CDetour'), os.path.join(context.currentSourcePath, 'util'), os.path.join(context.currentSourcePath, 'asm'), + os.path.join(builder.options.sm_path, 'sourcepawn', 'include'), + os.path.join(builder.options.sm_path, 'public', 'amtl'), + os.path.join(builder.options.sm_path, 'public', 'amtl', 'amtl'), + os.path.join(builder.options.sm_path, 'public'), ] defines = ['SE_' + PossibleSDKs[i].define + '=' + diff --git a/client/shim/shim.cpp b/client/shim/shim.cpp index 1108ac7..7411984 100644 --- a/client/shim/shim.cpp +++ b/client/shim/shim.cpp @@ -168,13 +168,21 @@ void Shim::ClientCommand(edict_t *pEntity, const CCommand &args) void *Shim::OnMetamodQuery(const char* iface, int *ret) { - // if (strcmp(iface, SOURCEMOD_NOTICE_EXTENSIONS) == 0) { + if (strcmp(iface, SOURCEMOD_NOTICE_EXTENSIONS) == 0) { + BindToSourcemod(); + } + + if (ret != NULL) { + *ret = IFACE_OK; + } - // } + return NULL; } bool Shim::Unload(char *error, size_t maxlen) { + SM_UnloadExtension(); + SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, gameclients, this, &Shim::ClientDisconnect, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, gameclients, this, &Shim::ClientPutInServer, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, gameclients, this, &Shim::ClientCommand, false); @@ -188,6 +196,17 @@ bool Shim::Unload(char *error, size_t maxlen) return true; } +void Shim::BindToSourcemod() +{ + char error[256]; + + if (!SM_LoadExtension(error, sizeof(error))) { + char message[512]; + snprintf(message, sizeof(message), "Could not load as a SourceMod extension: %s\n", error); + engine->LogPrint(message); + } +} + const char *Shim::GetLicense() { return extension_license(); diff --git a/client/shim/shim.h b/client/shim/shim.h index 79c8d75..5fc3bda 100644 --- a/client/shim/shim.h +++ b/client/shim/shim.h @@ -6,8 +6,9 @@ #include #include #include +#include -class Shim : public ISmmPlugin +class Shim : public ISmmPlugin, public IMetamodListener { public: void BroadcastVoiceData_Callback(int bytes, const char *data); @@ -27,6 +28,8 @@ class Shim : public ISmmPlugin const char *GetDate(); const char *GetLicense(); const char *GetLogTag(); + private: + void BindToSourcemod(); private: CDetour *m_VoiceDetour; }; diff --git a/client/shim/sm_ext.cpp b/client/shim/sm_ext.cpp index 280db30..c3a862b 100644 --- a/client/shim/sm_ext.cpp +++ b/client/shim/sm_ext.cpp @@ -31,7 +31,7 @@ void ShimExtension::OnExtensionUnload() } void ShimExtension::OnExtensionsAllLoaded() {} -void ShimExtension::OnExtensionPauseChange() {} +void ShimExtension::OnExtensionPauseChange(bool pause) {} bool ShimExtension::QueryRunning(char *error, size_t maxlength) { @@ -97,7 +97,7 @@ bool SM_LoadExtension(char *error, size_t maxlength) { #endif ); - if ((myself = smexts->LoadExternal(&g_RCBotSourceMod, path, "scr.ext", error, maxlength)) + if ((myself = smexts->LoadExternal(&g_SMExt, path, "scr.ext", error, maxlength)) == NULL) { SM_UnsetInterfaces(); return false; diff --git a/client/shim/sm_ext.h b/client/shim/sm_ext.h index a96d193..fe4aaff 100644 --- a/client/shim/sm_ext.h +++ b/client/shim/sm_ext.h @@ -2,6 +2,7 @@ #define _INCLUDE_SHIM_SOURCEMOD_EXTENSION_ #include "sm_sdk_config.h" +#include "shim.h" using namespace SourceMod;