Skip to content

Commit

Permalink
wip(client) - passing shim build
Browse files Browse the repository at this point in the history
  • Loading branch information
rumblefrog committed Apr 9, 2021
1 parent f9683e8 commit ee36700
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
14 changes: 12 additions & 2 deletions client/shim/AMBuildScript
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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(',')
Expand Down Expand Up @@ -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 + '=' +
Expand Down
23 changes: 21 additions & 2 deletions client/shim/shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion client/shim/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#include <steam/steamclientpublic.h>
#include <bindings.h>
#include <CDetour/detours.h>
#include <sm_ext.h>

class Shim : public ISmmPlugin
class Shim : public ISmmPlugin, public IMetamodListener
{
public:
void BroadcastVoiceData_Callback(int bytes, const char *data);
Expand All @@ -27,6 +28,8 @@ class Shim : public ISmmPlugin
const char *GetDate();
const char *GetLicense();
const char *GetLogTag();
private:
void BindToSourcemod();
private:
CDetour *m_VoiceDetour;
};
Expand Down
4 changes: 2 additions & 2 deletions client/shim/sm_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions client/shim/sm_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _INCLUDE_SHIM_SOURCEMOD_EXTENSION_

#include "sm_sdk_config.h"
#include "shim.h"

using namespace SourceMod;

Expand Down

0 comments on commit ee36700

Please sign in to comment.