1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2024-11-29 11:24:19 +01:00

Hook Connect on ISource2Server instead of ISource2ServerConfig.

This commit is contained in:
Nicholas Hastings 2015-08-31 14:59:29 -04:00
parent 4461b5e1b8
commit c07bab9763

View File

@ -36,7 +36,6 @@
#include "gamedll.h"
class IServerGameDLL;
class ISource2ServerConfig;
#define MAX_GAMEDLL_PATHS 10
@ -48,7 +47,6 @@ static void *gamedll_libs[MAX_GAMEDLL_PATHS];
static unsigned int gamedll_path_count = 0;
static void *gamedll_lib = NULL;
static IServerGameDLL *gamedll_iface = NULL;
static ISource2ServerConfig *config_iface = NULL;
static QueryValveInterface gamedll_qvi = NULL;
static int gamedll_version = 0;
static int isgd_shutdown_index = -1;
@ -233,7 +231,7 @@ mm_PatchConnect(bool patch);
static void *isgd_orig_init = NULL;
static void *isgd_orig_shutdown = NULL;
static void *is2sc_orig_connect = NULL;
static void *is2s_orig_connect = NULL;
class VEmptyClass
{
@ -256,7 +254,7 @@ enum InitReturnVal_t
INIT_LAST_VAL,
};
class ISource2ServerConfig
class ISource2Server
{
public:
virtual bool Connect(QueryValveInterface factory)
@ -275,7 +273,7 @@ public:
#if defined _WIN32
void *addr;
} u;
u.addr = is2sc_orig_connect;
u.addr = is2s_orig_connect;
#else
struct
{
@ -283,22 +281,16 @@ public:
intptr_t adjustor;
} s;
} u;
u.s.addr = is2sc_orig_connect;
u.s.addr = is2s_orig_connect;
u.s.adjustor = 0;
#endif
result = (((VEmptyClass *) config_iface)->*u.mfpnew)(factory);
result = (((VEmptyClass *) gamedll_iface)->*u.mfpnew)(factory);
}
mm_PatchConnect(false);
return result;
}
};
class ISource2Server
{
public:
virtual bool Connect(QueryValveInterface factory) { return true; }
virtual void Disconnect() {}
virtual void *QueryInterface(const char *pInterfaceName) { return nullptr; }
@ -566,7 +558,6 @@ public:
static IServerGameDLL isgd_thunk;
static ISource2Server is2s_thunk;
static ISource2ServerConfig is2sc_thunk;
static void
mm_PatchDllInit(bool patch)
@ -657,14 +648,14 @@ mm_PatchConnect(bool patch)
void **vtable_dest;
SourceHook::MemFuncInfo mfp;
SourceHook::GetFuncInfo(&ISource2ServerConfig::Connect, mfp);
SourceHook::GetFuncInfo(&ISource2Server::Connect, mfp);
assert(mfp.isVirtual);
assert(mfp.thisptroffs == 0);
assert(mfp.vtbloffs == 0);
vtable_src = (void **) *(void **) &is2sc_thunk;
vtable_dest = (void **) *(void **) config_iface;
vtable_src = (void **) *(void **) &is2s_thunk;
vtable_dest = (void **) *(void **) gamedll_iface;
SourceHook::SetMemAccess(&vtable_dest[mfp.vtblindex],
sizeof(void*),
@ -672,15 +663,15 @@ mm_PatchConnect(bool patch)
if (patch)
{
assert(is2sc_orig_connect == NULL);
is2sc_orig_connect = vtable_dest[mfp.vtblindex];
assert(is2s_orig_connect == NULL);
is2s_orig_connect = vtable_dest[mfp.vtblindex];
vtable_dest[mfp.vtblindex] = vtable_src[mfp.vtblindex];
}
else
{
assert(is2sc_orig_connect != NULL);
vtable_dest[mfp.vtblindex] = is2sc_orig_connect;
is2sc_orig_connect = NULL;
assert(is2s_orig_connect != NULL);
vtable_dest[mfp.vtblindex] = is2s_orig_connect;
is2s_orig_connect = NULL;
}
}
@ -727,11 +718,8 @@ mm_GameDllRequest(const char *name, int *ret)
{
mm_FreeCachedLibraries();
gamedll_lib = lib;
config_iface = (ISource2ServerConfig *) ptr;
gamedll_qvi = qvi;
mm_PatchConnect(true);
if (ret != NULL)
*ret = 0;
return ptr;
@ -741,6 +729,7 @@ mm_GameDllRequest(const char *name, int *ret)
{
gamedll_iface = (IServerGameDLL *)gamedll_qvi(name, ret);
gamedll_version = atoi(&name[13]);
mm_PatchConnect(true);
mm_PatchDllInit(true);
if (ret != NULL)