Skip to content

Commit

Permalink
Move Source-engine provider to templated SourceHook
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooshua committed Apr 24, 2024
1 parent aa88f23 commit 11df174
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions core/provider/source/provider_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ static SourceProvider g_SourceProvider;

IMetamodSourceProvider* provider = &g_SourceProvider;

SH_DECL_HOOK0(IServerGameDLL, GameInit, SH_NOATTRIB, 0, bool);
SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, const char*, const char*, const char*, const char*, bool, bool);
SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, 0);
auto OnGameInit = SourceHook::Hook<&g_SHPtr, IServerGameDLL, &IServerGameDLL::GameInit, bool>::Make();
auto OnLevelInit = SourceHook::Hook<&g_SHPtr, IServerGameDLL, &IServerGameDLL::LevelInit, bool, const char*, const char*, const char*, const char*, bool, bool>::Make();
auto OnLevelShutdown = SourceHook::Hook<&g_SHPtr, IServerGameDLL, &IServerGameDLL::LevelShutdown, void>::Make();

#if SOURCE_ENGINE >= SE_ORANGEBOX
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t*, const CCommand&);
auto OnClientCommand = SourceHook::Hook<&g_SHPtr, IServerGameClients, &IServerGameClients::ClientCommand, void, edict_t*, const CCommand&>::Make();
#else
SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t*);
auto OnClientCommand = SourceHook::Hook<&g_SHPtr, IServerGameClients, &IServerGameClients::ClientCommand, void, edict_t*>::Make();
#endif

void SourceProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory,
Expand All @@ -69,34 +69,30 @@ void SourceProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory,
}
}
#else
engine = (IVEngineServer*)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL));
engine = (IVEngineServer *) ((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL));
#endif
if (!engine)
{
if (!engine) {
DisplayError("Could not find IVEngineServer! Metamod cannot load.");
return;
}

#if SOURCE_ENGINE >= SE_ORANGEBOX
icvar = (ICvar*)((engineFactory)(CVAR_INTERFACE_VERSION, NULL));
icvar = (ICvar *) ((engineFactory)(CVAR_INTERFACE_VERSION, NULL));
#else
icvar = (ICvar*)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION, NULL));
#endif
if (!icvar)
{
if (!icvar) {
DisplayError("Could not find ICvar! Metamod cannot load.");
return;
}

if ((gameclients = (IServerGameClients*)(serverFactory("ServerGameClients003", NULL)))
== NULL)
{
gameclients = (IServerGameClients*)(serverFactory("ServerGameClients004", NULL));
if ((gameclients = (IServerGameClients *) (serverFactory("ServerGameClients003", NULL)))
== NULL) {
gameclients = (IServerGameClients *) (serverFactory("ServerGameClients004", NULL));
}

baseFs = (IFileSystem*)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL));
if (baseFs == NULL)
{
baseFs = (IFileSystem *) ((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL));
if (baseFs == NULL) {
mm_LogMessage("Unable to find \"%s\": .vdf files will not be parsed", FILESYSTEM_INTERFACE_VERSION);
}

Expand All @@ -122,21 +118,20 @@ void SourceProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory,
}
#endif

if (gameclients)
{
SH_ADD_HOOK(IServerGameClients, ClientCommand, gameclients, SH_MEMBER(this, &SourceProvider::Hook_ClientCommand), false);
if (gameclients) {
OnClientCommand->Add(g_PLID, gameclients, false, SH_MEMBER(this, &SourceProvider::Hook_ClientCommand));
}

SH_ADD_HOOK(IServerGameDLL, GameInit, server, SH_MEMBER(this, &SourceProvider::Hook_GameInit), false);
SH_ADD_HOOK(IServerGameDLL, LevelInit, server, SH_MEMBER(this, &SourceProvider::Hook_LevelInit), true);
SH_ADD_HOOK(IServerGameDLL, LevelShutdown, server, SH_MEMBER(this, &SourceProvider::Hook_LevelShutdown), true);
OnGameInit->Add(g_PLID, server, false, SH_MEMBER(this, &SourceProvider::Hook_GameInit));
OnLevelInit->Add(g_PLID, server, true, SH_MEMBER(this, &SourceProvider::Hook_LevelInit));
OnLevelShutdown->Add(g_PLID, server, true, SH_MEMBER(this, &SourceProvider::Hook_LevelShutdown));
}

void SourceProvider::Notify_DLLShutdown_Pre()
{
SH_REMOVE_HOOK(IServerGameDLL, GameInit, server, SH_MEMBER(this, &SourceProvider::Hook_GameInit), false);
SH_REMOVE_HOOK(IServerGameDLL, LevelInit, server, SH_MEMBER(this, &SourceProvider::Hook_LevelInit), true);
SH_REMOVE_HOOK(IServerGameDLL, LevelShutdown, server, SH_MEMBER(this, &SourceProvider::Hook_LevelShutdown), true);
OnGameInit->Remove(g_PLID, server, false, SH_MEMBER(this, &SourceProvider::Hook_GameInit));
OnLevelInit->Remove(g_PLID, server, true, SH_MEMBER(this, &SourceProvider::Hook_LevelInit));
OnLevelShutdown->Remove(g_PLID, server, true, SH_MEMBER(this, &SourceProvider::Hook_LevelShutdown));

m_ConVarAccessor.RemoveMetamodCommands();

Expand Down

0 comments on commit 11df174

Please sign in to comment.