Initial import of core-legacy as a gameinfo provider.
Initial import of core-legacy as a gameinfo provider.
1.1 --- a/core-legacy/CSmmAPI.cpp Sun Nov 23 21:21:49 2008 -0600
1.2 +++ b/core-legacy/CSmmAPI.cpp Sun Nov 23 21:22:04 2008 -0600
1.3 @@ -460,11 +460,12 @@
1.4 }
1.5 }
1.6
1.7 - const char *usepath = g_SmmPath.c_str();
1.8 - if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_file, g_SmmPath.c_str()))
1.9 - {
1.10 + char our_path[PATH_SIZE];
1.11 + GetFileOfAddress((void*)LoadAsGameDLL, our_path, sizeof(our_path));
1.12 +
1.13 + const char *usepath = our_path;
1.14 + if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_file, our_path))
1.15 usepath = rel_path;
1.16 - }
1.17
1.18 char command[PATH_SIZE * 2];
1.19 g_VspListener.SetLoadable(true);
1.20 @@ -475,7 +476,7 @@
1.21 void CSmmAPI::EnableVSPListener()
1.22 {
1.23 /* If GameInit already passed and we're not already enabled or loaded, go ahead and LoadAsVSP load */
1.24 - if (bGameInit && !m_VSP && !g_VspListener.IsLoaded() && !g_bIsBridgedAsVsp)
1.25 + if (g_bGameInit && !m_VSP && !g_VspListener.IsLoaded() && !g_bIsBridgedAsVsp)
1.26 {
1.27 LoadAsVSP();
1.28 }
2.1 --- a/core-legacy/Makefile Sun Nov 23 21:21:49 2008 -0600
2.2 +++ b/core-legacy/Makefile Sun Nov 23 21:22:04 2008 -0600
2.3 @@ -15,14 +15,15 @@
2.4 HL2PUB = $(HL2SDK)/public
2.5 HL2LIB = $(HL2SDK)/linux_sdk
2.6
2.7 -OBJECTS = oslink.cpp \
2.8 - util.cpp \
2.9 - concommands.cpp \
2.10 - CSmmAPI.cpp \
2.11 - sourcemm.cpp \
2.12 - CPlugin.cpp \
2.13 - vsp_listener.cpp \
2.14 - vsp_bridge.cpp \
2.15 +OBJECTS = oslink.cpp \
2.16 + util.cpp \
2.17 + concommands.cpp \
2.18 + CSmmAPI.cpp \
2.19 + sourcemm.cpp \
2.20 + CPlugin.cpp \
2.21 + vsp_listener.cpp \
2.22 + vsp_bridge.cpp \
2.23 + gamedll_bridge.cpp \
2.24 sourcehook/sourcehook.cpp
2.25
2.26 LINK = $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so -static-libgcc
3.1 --- a/core-legacy/concommands.cpp Sun Nov 23 21:21:49 2008 -0600
3.2 +++ b/core-legacy/concommands.cpp Sun Nov 23 21:22:04 2008 -0600
3.3 @@ -157,10 +157,13 @@
3.4
3.5 return;
3.6 } else if (strcmp(command, "game") == 0) {
3.7 + char bin_path[PATH_SIZE];
3.8 + GetFileOfAddress((void*)g_GameDll.factory, bin_path, sizeof(bin_path));
3.9 +
3.10 CONMSG("GameDLL Information\n");
3.11 CONMSG(" Description: %s\n", g_GameDll.pGameDLL->GetGameDescription());
3.12 CONMSG(" Mod Path: %s\n", g_ModPath.c_str());
3.13 - CONMSG(" DLL Path: %s\n", g_BinPath.c_str());
3.14 + CONMSG(" DLL Path: %s\n", bin_path);
3.15 CONMSG(" Interface: ServerGameDLL%03d\n", g_GameDllVersion);
3.16
3.17 // Display user messages
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/core-legacy/gamedll_bridge.cpp Sun Nov 23 21:22:04 2008 -0600
4.3 @@ -0,0 +1,91 @@
4.4 +#include <assert.h>
4.5 +#include "sourcemm.h"
4.6 +#include "CPlugin.h"
4.7 +#include <loader_bridge.h>
4.8 +
4.9 +using namespace SourceMM;
4.10 +
4.11 +#define IFACE_MACRO(orig,nam) \
4.12 + CPluginManager::CPlugin *pl; \
4.13 + SourceHook::List<CPluginEventHandler>::iterator event; \
4.14 + IMetamodListener *api; \
4.15 + int mret = 0; \
4.16 + void *val = NULL; \
4.17 + for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
4.18 + pl = (*iter); \
4.19 + for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
4.20 + api = (*event).event; \
4.21 + mret = IFACE_FAILED; \
4.22 + if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
4.23 + if (ret) *ret = mret; \
4.24 + return val; \
4.25 + } \
4.26 + } \
4.27 + } \
4.28 + return (orig)(iface, ret);
4.29 +
4.30 +
4.31 +class GameDllBridge : public IGameDllBridge
4.32 +{
4.33 +public:
4.34 + virtual bool DLLInit_Pre(const gamedll_bridge_info *info, char *buffer, size_t maxlength)
4.35 + {
4.36 + assert(!g_GameDll.loaded && !g_bIsBridgedAsVsp);
4.37 + LoadAsGameDLL(info);
4.38 + return true;
4.39 + }
4.40 + virtual void DLLInit_Post()
4.41 + {
4.42 + g_PluginMngr.SetAllLoaded();
4.43 + }
4.44 + virtual void *QueryInterface(const char *iface, int *ret)
4.45 + {
4.46 + /* We use this interface for responding to the meta client command */
4.47 + if (strncmp(iface, "ServerGameClients", 17) == 0)
4.48 + {
4.49 + void *ptr = (g_GameDll.factory)(iface, ret);
4.50 + g_GameDll.pGameClients = static_cast<IServerGameClients *>(ptr);
4.51 + return ptr;
4.52 + }
4.53 +
4.54 + /* If we got here, there's definitely a GameDLL */
4.55 + IFACE_MACRO(g_GameDll.factory, GameDLL);
4.56 + }
4.57 + virtual void Unload()
4.58 + {
4.59 + }
4.60 +};
4.61 +
4.62 +GameDllBridge mm14_gamedll_bridge;
4.63 +
4.64 +SMM_API IGameDllBridge *
4.65 +GetGameDllBridge()
4.66 +{
4.67 + return &mm14_gamedll_bridge;
4.68 +}
4.69 +
4.70 +/* Wrapper function. This is called when the GameDLL thinks it's using
4.71 + * the engine's real engineFactory.
4.72 + */
4.73 +void *EngineFactory(const char *iface, int *ret)
4.74 +{
4.75 + IFACE_MACRO(g_Engine.engineFactory, Engine);
4.76 +}
4.77 +
4.78 +/* Wrapper function. This is called when the GameDLL thinks it's using
4.79 + * the engine's real physicsFactory.
4.80 + */
4.81 +void *PhysicsFactory(const char *iface, int *ret)
4.82 +{
4.83 + IFACE_MACRO(g_Engine.physicsFactory, Physics);
4.84 +}
4.85 +
4.86 +/* Wrapper function. This is called when the GameDLL thinks it's using
4.87 + * the engine's real fileSystemFactory.
4.88 + */
4.89 +void *FileSystemFactory(const char *iface, int *ret)
4.90 +{
4.91 + IFACE_MACRO(g_Engine.fileSystemFactory, FileSystem);
4.92 +}
4.93 +
4.94 +
5.1 --- a/core-legacy/sourcemm.cpp Sun Nov 23 21:21:49 2008 -0600
5.2 +++ b/core-legacy/sourcemm.cpp Sun Nov 23 21:22:04 2008 -0600
5.3 @@ -32,66 +32,45 @@
5.4 #undef CommandLine
5.5 DLL_IMPORT ICommandLine *CommandLine();
5.6
5.7 -SH_DECL_HOOK4(IServerGameDLL, DLLInit, SH_NOATTRIB, false, bool, CreateInterfaceFn, CreateInterfaceFn, CreateInterfaceFn, CGlobalVars *);
5.8 SH_DECL_HOOK0_void(IServerGameDLL, DLLShutdown, SH_NOATTRIB, false);
5.9 SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
5.10 SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
5.11 SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
5.12 SH_DECL_HOOK0(IServerGameDLL, GameInit, SH_NOATTRIB, false, bool);
5.13
5.14 -bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
5.15 -bool DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
5.16 void DLLShutdown_handler();
5.17 void LevelShutdown_handler();
5.18 -bool LevelInit_handler(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
5.19 +bool LevelInit_handler(char const *pMapName,
5.20 + char const *pMapEntities,
5.21 + char const *pOldLevel,
5.22 + char const *pLandmarkName,
5.23 + bool loadGame,
5.24 + bool background);
5.25 bool GameInit_handler();
5.26 void LookForVDFs(const char *dir);
5.27 -bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
5.28 +bool KVLoadFromFile(KeyValues *kv,
5.29 + IBaseFileSystem *filesystem,
5.30 + const char *resourceName,
5.31 + const char *pathID = NULL);
5.32
5.33 -GameDllInfo g_GameDll = {false, NULL, NULL, NULL, NULL};
5.34 +GameDllInfo g_GameDll = {false, NULL, NULL, NULL};
5.35 EngineInfo g_Engine;
5.36 SourceHook::CSourceHookImpl g_SourceHook;
5.37 SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
5.38 SourceHook::String g_ModPath;
5.39 -SourceHook::String g_BinPath;
5.40 -SourceHook::String g_SmmPath;
5.41 PluginId g_PLID = Pl_Console; /* Technically, SourceMM is the "Console" plugin... :p */
5.42 -bool bInFirstLevel = true;
5.43 -bool gParsedGameInfo = false;
5.44 -bool bGameInit = false;
5.45 -SourceHook::List<GameDllInfo *> gamedll_list;
5.46 +static bool bInFirstLevel = true;
5.47 +bool g_bGameInit = false;
5.48 SourceHook::CallClass<IServerGameDLL> *g_GameDllPatch;
5.49 SourceHook::CallClass<ICvar> *g_CvarPatch;
5.50 int g_GameDllVersion = 0;
5.51 -const char VSPIFACE_001[] = "ISERVERPLUGINCALLBACKS001";
5.52 -const char VSPIFACE_002[] = "ISERVERPLUGINCALLBACKS002";
5.53 -const char GAMEINFO_PATH[] = "|gameinfo_path|";
5.54 +static const char VSPIFACE_001[] = "ISERVERPLUGINCALLBACKS001";
5.55 +static const char VSPIFACE_002[] = "ISERVERPLUGINCALLBACKS002";
5.56 +static const char GAMEINFO_PATH[] = "|gameinfo_path|";
5.57 IFileSystem *baseFs = NULL;
5.58 bool g_bLevelChanged = false;
5.59 IServerPluginCallbacks *g_pRealVspCallbacks = &g_VspListener;
5.60
5.61 -void ClearGamedllList();
5.62 -
5.63 -/* Helper Macro */
5.64 -#define IFACE_MACRO(orig,nam) \
5.65 - CPluginManager::CPlugin *pl; \
5.66 - SourceHook::List<CPluginEventHandler>::iterator event; \
5.67 - IMetamodListener *api; \
5.68 - int mret = 0; \
5.69 - void *val = NULL; \
5.70 - for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
5.71 - pl = (*iter); \
5.72 - for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
5.73 - api = (*event).event; \
5.74 - mret = IFACE_FAILED; \
5.75 - if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
5.76 - if (ret) *ret = mret; \
5.77 - return val; \
5.78 - } \
5.79 - } \
5.80 - } \
5.81 - return (orig)(iface, ret);
5.82 -
5.83 #define ITER_EVENT(evn, args) \
5.84 CPluginManager::CPlugin *pl; \
5.85 SourceHook::List<CPluginEventHandler>::iterator event; \
5.86 @@ -111,18 +90,17 @@
5.87 /* Initialize everything here */
5.88 void InitMainStates()
5.89 {
5.90 - char full_path[PATH_SIZE] = {0};
5.91 - GetFileOfAddress((void *)g_GameDll.factory, full_path, sizeof(full_path));
5.92 - g_BinPath.assign(full_path);
5.93 -
5.94 /* Like Metamod, reload plugins at the end of the map.
5.95 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
5.96 * if the server is shut down (silly, but rare case).
5.97 */
5.98 bInFirstLevel = true;
5.99
5.100 - SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLInit, g_GameDll.pGameDLL, DLLInit, false);
5.101 - SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLInit, g_GameDll.pGameDLL, DLLInit_Post, true);
5.102 + char smm_path[PATH_SIZE];
5.103 + const char *game_dir = CommandLine()->ParmValue("-game", "hl2");
5.104 + abspath(smm_path, game_dir);
5.105 + g_ModPath.assign(smm_path);
5.106 +
5.107 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, g_GameDll.pGameDLL, DLLShutdown_handler, false);
5.108 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelShutdown, g_GameDll.pGameDLL, LevelShutdown_handler, true);
5.109 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelInit, g_GameDll.pGameDLL, LevelInit_handler, true);
5.110 @@ -225,16 +203,20 @@
5.111 return true;
5.112 }
5.113
5.114 -bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
5.115 +void LoadAsGameDLL(const gamedll_bridge_info *info)
5.116 {
5.117 - g_Engine.engineFactory = engineFactory;
5.118 - g_Engine.fileSystemFactory = filesystemFactory;
5.119 - g_Engine.physicsFactory = physicsFactory;
5.120 - g_Engine.pGlobals = pGlobals;
5.121 + g_Engine.engineFactory = (CreateInterfaceFn)info->engineFactory;
5.122 + g_Engine.fileSystemFactory = (CreateInterfaceFn)info->fsFactory;
5.123 + g_Engine.physicsFactory = (CreateInterfaceFn)info->physicsFactory;
5.124 + g_Engine.pGlobals = (CGlobalVars*)info->pGlobals;
5.125 + g_GameDll.loaded = true;
5.126 + g_GameDll.factory = (CreateInterfaceFn)info->gsFactory;
5.127 + g_GameDll.pGameDLL = (IServerGameDLL*)info->isgd;
5.128 + g_GameDllVersion = info->dllVersion;
5.129
5.130 - StartupMetamod(engineFactory, false);
5.131 + InitMainStates();
5.132
5.133 - RETURN_META_VALUE(MRES_IGNORED, true);
5.134 + StartupMetamod(g_Engine.engineFactory, false);
5.135 }
5.136
5.137 bool AlternatelyLoadMetamod(CreateInterfaceFn ifaceFactory, CreateInterfaceFn serverFactory)
5.138 @@ -254,7 +236,6 @@
5.139
5.140 /* Now find the server */
5.141 g_GameDll.factory = serverFactory;
5.142 - g_GameDll.lib = NULL;
5.143
5.144 char gamedll_iface[] = "ServerGameDLL000";
5.145 for (unsigned int i = 3; i <= 50; i++)
5.146 @@ -285,15 +266,6 @@
5.147 }
5.148 }
5.149
5.150 - char smm_path[PATH_SIZE];
5.151 - const char *game_dir;
5.152 - GetFileOfAddress((void *)AlternatelyLoadMetamod, smm_path, sizeof(smm_path));
5.153 - g_SmmPath.assign(smm_path);
5.154 -
5.155 - game_dir = CommandLine()->ParmValue("-game", "hl2");
5.156 - abspath(smm_path, game_dir);
5.157 - g_ModPath.assign(smm_path);
5.158 -
5.159 InitMainStates();
5.160
5.161 if (!StartupMetamod(ifaceFactory, true))
5.162 @@ -308,7 +280,7 @@
5.163
5.164 bool GameInit_handler()
5.165 {
5.166 - if (bGameInit)
5.167 + if (g_bGameInit)
5.168 RETURN_META_VALUE(MRES_IGNORED, true);
5.169
5.170 if (g_SmmAPI.VSPEnabled() && !g_bIsBridgedAsVsp)
5.171 @@ -317,286 +289,11 @@
5.172 if (g_bIsBridgedAsVsp)
5.173 DoInitialPluginLoads();
5.174
5.175 - bGameInit = true;
5.176 + g_bGameInit = true;
5.177
5.178 RETURN_META_VALUE(MRES_IGNORED, true);
5.179 }
5.180
5.181 -bool DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
5.182 -{
5.183 - g_PluginMngr.SetAllLoaded();
5.184 - RETURN_META_VALUE(MRES_IGNORED, true);
5.185 -}
5.186 -
5.187 -/* This is where the magic happens */
5.188 -SMM_API void *CreateInterface(const char *iface, int *ret)
5.189 -{
5.190 - /* Prevent loading of self as a SourceMM plugin or Valve server plugin :x */
5.191 - if (strcmp(iface, PLAPI_NAME) == 0)
5.192 - {
5.193 - Warning("Do not try loading Metamod:Source as a Metamod:Source plugin");
5.194 -
5.195 - if (ret)
5.196 - {
5.197 - *ret = IFACE_FAILED;
5.198 - }
5.199 -
5.200 - return NULL;
5.201 - }
5.202 -
5.203 - /* We check these separately because we can't reply
5.204 - * unless our interface version really matches.
5.205 - */
5.206 - if (!g_bIsBridgedAsVsp &&
5.207 - (strcmp(iface, VSPIFACE_002) == 0 ||
5.208 - strcmp(iface, VSPIFACE_001) == 0))
5.209 - {
5.210 - if (ret)
5.211 - {
5.212 - *ret = IFACE_OK;
5.213 - }
5.214 - return &g_VspListener;
5.215 - }
5.216 -
5.217 - /* If we're a VSP, bypass this by default */
5.218 - if (g_bIsBridgedAsVsp)
5.219 - {
5.220 - IFACE_MACRO(g_GameDll.factory, GameDLL);
5.221 - }
5.222 -
5.223 - if (!gParsedGameInfo)
5.224 - {
5.225 - gParsedGameInfo = true;
5.226 - const char *gameDir = NULL;
5.227 - char gamePath[PATH_SIZE];
5.228 - char smmPath[PATH_SIZE];
5.229 -
5.230 - /* Get path to SourceMM DLL */
5.231 - if (!GetFileOfAddress((void *)CreateInterface, smmPath, sizeof(smmPath)))
5.232 - {
5.233 - Error("GetFileOfAddress() failed! Metamod cannot load.\n");
5.234 - return NULL;
5.235 - }
5.236 -
5.237 - g_SmmPath.assign(smmPath);
5.238 -
5.239 - /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
5.240 - gameDir = CommandLine()->ParmValue("-game", "hl2");
5.241 -
5.242 - /* Get absolute path */
5.243 - abspath(gamePath, gameDir);
5.244 - g_ModPath.assign(gamePath);
5.245 -
5.246 - char tempPath[PATH_SIZE];
5.247 -
5.248 - /* Path to gameinfo.txt */
5.249 - g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s", g_ModPath.c_str(), "gameinfo.txt");
5.250 -
5.251 - FILE *fp = fopen(tempPath, "rt");
5.252 -
5.253 - if (!fp)
5.254 - {
5.255 - Error("Unable to open gameinfo.txt! Metamod cannot load.\n");
5.256 - return NULL;
5.257 - }
5.258 -
5.259 - char buffer[255];
5.260 - char key[128], val[128];
5.261 - size_t len = 0;
5.262 - bool search = false;
5.263 - bool gamebin = false;
5.264 - char *ptr;
5.265 - const char *lptr;
5.266 - char curPath[PATH_SIZE];
5.267 -
5.268 - getcwd(curPath, PATH_SIZE);
5.269 -
5.270 - while (!feof(fp))
5.271 - {
5.272 - buffer[0] = '\0';
5.273 - fgets(buffer, sizeof(buffer), fp);
5.274 - len = strlen(buffer);
5.275 - if (buffer[len-1] == '\n')
5.276 - buffer[--len] = '\0';
5.277 - UTIL_TrimComments(buffer);
5.278 - UTIL_TrimLeft(buffer);
5.279 - UTIL_TrimRight(buffer);
5.280 - if (stricmp(buffer, "SearchPaths") == 0)
5.281 - search = true;
5.282 - if (!search)
5.283 - continue;
5.284 - UTIL_KeySplit(buffer, key, sizeof(key) - 1, val, sizeof(val) - 1);
5.285 - if (stricmp(key, "Game") == 0 || stricmp(key, "GameBin") == 0)
5.286 - {
5.287 - if (stricmp(key, "Game") == 0)
5.288 - gamebin = false;
5.289 - else
5.290 - gamebin = true;
5.291 -
5.292 - if (strncmp(val, GAMEINFO_PATH, sizeof(GAMEINFO_PATH) - 1) == 0)
5.293 - {
5.294 - ptr = &(val[sizeof(GAMEINFO_PATH) - 1]);
5.295 - if (ptr[0] == '.')
5.296 - ptr++;
5.297 - lptr = g_ModPath.c_str();
5.298 - } else {
5.299 - ptr = val;
5.300 - lptr = curPath;
5.301 - }
5.302 -
5.303 - size_t ptr_len = strlen(ptr);
5.304 - if (ptr[ptr_len] == '/' || ptr[ptr_len] == '\\')
5.305 - ptr[--ptr_len] = '\0';
5.306 -
5.307 - /* No need to append "bin" if key is GameBin */
5.308 - if (gamebin)
5.309 - {
5.310 - g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s", lptr, ptr, SERVER_DLL);
5.311 - } else if (!ptr[0]) {
5.312 - g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s", lptr, "bin", SERVER_DLL);
5.313 - } else {
5.314 - g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
5.315 - }
5.316 -
5.317 - /* If not path to SourceMM... */
5.318 - if (!UTIL_PathCmp(smmPath, tempPath))
5.319 - {
5.320 - FILE *fp = fopen(tempPath, "rb");
5.321 - if (!fp)
5.322 - continue;
5.323 - //:TODO: Optimize this a bit!
5.324 - SourceHook::List<GameDllInfo *>::iterator iter;
5.325 - GameDllInfo *pCheck;
5.326 - bool found = false;
5.327 - for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
5.328 - {
5.329 - pCheck = (*iter);
5.330 - if (GetFileOfAddress((void *)pCheck->factory, buffer, sizeof(buffer)))
5.331 - {
5.332 - if (UTIL_PathCmp(tempPath, buffer))
5.333 - {
5.334 - found = true;
5.335 - break;
5.336 - }
5.337 - }
5.338 - }
5.339 - if (found)
5.340 - continue;
5.341 - fclose(fp);
5.342 - HINSTANCE gamedll = dlmount(tempPath);
5.343 - if (gamedll == NULL)
5.344 - continue;
5.345 - CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(gamedll, "CreateInterface");
5.346 - if (fn == NULL)
5.347 - {
5.348 - dlclose(gamedll);
5.349 - continue;
5.350 - }
5.351 - GameDllInfo *pInfo = new GameDllInfo;
5.352 - pInfo->factory = fn;
5.353 - pInfo->lib = gamedll;
5.354 - pInfo->loaded = true;
5.355 - pInfo->pGameDLL = NULL;
5.356 - gamedll_list.push_back(pInfo);
5.357 - break;
5.358 - }
5.359 - }
5.360 - }
5.361 - fclose(fp);
5.362 - }
5.363 -
5.364 - if (!g_GameDll.loaded)
5.365 - {
5.366 - const char *str = "ServerGameDLL";
5.367 - size_t len = strlen(str);
5.368 -
5.369 - if (strncmp(iface, str, len) == 0)
5.370 - {
5.371 - /* This is the interface we want! Right now we support versions 3 through 8 */
5.372 - g_GameDllVersion = atoi(&(iface[len]));
5.373 - int sizeTooBig = 0; //rename this to sizeWrong in the future!
5.374 - if (g_GameDllVersion < MIN_GAMEDLL_VERSION || g_GameDllVersion > MAX_GAMEDLL_VERSION)
5.375 - {
5.376 - /* Maybe this will get used in the future */
5.377 - sizeTooBig = g_GameDllVersion;
5.378 - if (ret)
5.379 - {
5.380 - *ret = IFACE_FAILED;
5.381 - }
5.382 - }
5.383 - SourceHook::List<GameDllInfo *>::iterator iter;
5.384 - GameDllInfo *pInfo = NULL;
5.385 - void *ptr;
5.386 - for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
5.387 - {
5.388 - pInfo = (*iter);
5.389 - ptr = (pInfo->factory)(iface, ret);
5.390 - if (ptr)
5.391 - {
5.392 - /* This is our GameDLL. Unload the others. */
5.393 - gamedll_list.erase(iter);
5.394 - ClearGamedllList();
5.395 - pInfo->pGameDLL = static_cast<IServerGameDLL *>(ptr);
5.396 - g_GameDll = *pInfo;
5.397 - delete pInfo;
5.398 - break;
5.399 - }
5.400 - }
5.401 - if (g_GameDll.loaded)
5.402 - {
5.403 - if (sizeTooBig)
5.404 - {
5.405 - Error("This mod version requires a SourceMM update (ServerGameDLL%03d)!\n", sizeTooBig);
5.406 - if (ret)
5.407 - {
5.408 - *ret = IFACE_FAILED;
5.409 - }
5.410 - return NULL;
5.411 - } else {
5.412 - InitMainStates();
5.413 - }
5.414 - } else {
5.415 - sizeTooBig = 0;
5.416 - if (ret)
5.417 - *ret = IFACE_FAILED;
5.418 - return NULL;
5.419 - }
5.420 - } else {
5.421 - /* wtf do we do... */
5.422 - /* :TODO: .. something a bit more intelligent? */
5.423 - Error("Engine requested unknown interface before GameDLL was known!\n");
5.424 - return NULL;
5.425 - }
5.426 - }
5.427 -
5.428 - /* We use this interface for responding to the meta client command */
5.429 - if (strncmp(iface, "ServerGameClients", 17) == 0)
5.430 - {
5.431 - void *ptr = (g_GameDll.factory)(iface, ret);
5.432 - g_GameDll.pGameClients = static_cast<IServerGameClients *>(ptr);
5.433 -
5.434 - return ptr;
5.435 - }
5.436 -
5.437 - /* If we got here, there's definitely a GameDLL */
5.438 - IFACE_MACRO(g_GameDll.factory, GameDLL);
5.439 -}
5.440 -
5.441 -void ClearGamedllList()
5.442 -{
5.443 - SourceHook::List<GameDllInfo *>::iterator iter;
5.444 -
5.445 - GameDllInfo *pInfo;
5.446 - for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
5.447 - {
5.448 - pInfo = (*iter);
5.449 - dlclose(pInfo->lib);
5.450 - delete pInfo;
5.451 - }
5.452 -
5.453 - gamedll_list.clear();
5.454 -}
5.455 -
5.456 void UnloadMetamod(bool shutting_down)
5.457 {
5.458 /* Unload plugins */
5.459 @@ -617,12 +314,6 @@
5.460 g_CvarPatch = NULL;
5.461
5.462 g_SourceHook.CompleteShutdown();
5.463 -
5.464 - if (g_GameDll.lib && g_GameDll.loaded)
5.465 - {
5.466 - dlclose(g_GameDll.lib);
5.467 - }
5.468 - memset(&g_GameDll, 0, sizeof(GameDllInfo));
5.469 }
5.470
5.471 void DLLShutdown_handler()
5.472 @@ -945,31 +636,6 @@
5.473 return total;
5.474 }
5.475
5.476 -
5.477 -/* Wrapper function. This is called when the GameDLL thinks it's using
5.478 - * the engine's real engineFactory.
5.479 - */
5.480 -void *EngineFactory(const char *iface, int *ret)
5.481 -{
5.482 - IFACE_MACRO(g_Engine.engineFactory, Engine);
5.483 -}
5.484 -
5.485 -/* Wrapper function. This is called when the GameDLL thinks it's using
5.486 - * the engine's real physicsFactory.
5.487 - */
5.488 -void *PhysicsFactory(const char *iface, int *ret)
5.489 -{
5.490 - IFACE_MACRO(g_Engine.physicsFactory, Physics);
5.491 -}
5.492 -
5.493 -/* Wrapper function. This is called when the GameDLL thinks it's using
5.494 - * the engine's real fileSystemFactory.
5.495 - */
5.496 -void *FileSystemFactory(const char *iface, int *ret)
5.497 -{
5.498 - IFACE_MACRO(g_Engine.fileSystemFactory, FileSystem);
5.499 -}
5.500 -
5.501 void LogMessage(const char *msg, ...)
5.502 {
5.503 va_list ap;
6.1 --- a/core-legacy/sourcemm.h Sun Nov 23 21:21:49 2008 -0600
6.2 +++ b/core-legacy/sourcemm.h Sun Nov 23 21:22:04 2008 -0600
6.3 @@ -26,6 +26,7 @@
6.4 #include "oslink.h"
6.5 #include "util.h"
6.6 #include "version.h"
6.7 +#include "loader_bridge.h"
6.8
6.9 /**
6.10 * Versioning
6.11 @@ -65,7 +66,6 @@
6.12 struct GameDllInfo
6.13 {
6.14 bool loaded;
6.15 - HINSTANCE lib;
6.16 CreateInterfaceFn factory;
6.17 IServerGameDLL *pGameDLL;
6.18 IServerGameClients *pGameClients;
6.19 @@ -105,12 +105,6 @@
6.20 /** @brief Mod path (important!)*/
6.21 extern SourceHook::String g_ModPath;
6.22
6.23 -/** @brief Path to server binary */
6.24 -extern SourceHook::String g_BinPath;
6.25 -
6.26 -/** @brief Path to SourceMM binary */
6.27 -extern SourceHook::String g_SmmPath;
6.28 -
6.29 /** @brief Global variable for SourceHook macros */
6.30 extern SourceHook::ISourceHook *g_SHPtr;
6.31
6.32 @@ -120,7 +114,7 @@
6.33 /** @brief ServerGameDLL version that is currently loaded */
6.34 extern int g_GameDllVersion;
6.35
6.36 -extern bool bGameInit;
6.37 +extern bool g_bGameInit;
6.38 extern bool g_bLevelChanged;
6.39
6.40 void UnloadMetamod(bool shutting_down);
6.41 @@ -128,7 +122,10 @@
6.42 /** @brief Global CallClass for IServerGameDLL */
6.43 extern SourceHook::CallClass<IServerGameDLL> *g_GameDllPatch;
6.44
6.45 +void LoadAsGameDLL(const gamedll_bridge_info *info);
6.46 +
6.47 /** @brief Global CallClass for ICvar */
6.48 extern SourceHook::CallClass<ICvar> *g_CvarPatch;
6.49
6.50 #endif //_INCLUDE_SOURCEMM_H
6.51 +
7.1 --- a/core-legacy/util.cpp Sun Nov 23 21:21:49 2008 -0600
7.2 +++ b/core-legacy/util.cpp Sun Nov 23 21:22:04 2008 -0600
7.3 @@ -82,91 +82,6 @@
7.4 }
7.5 }
7.6
7.7 -/* :TODO: this should skip string literals */
7.8 -void UTIL_TrimComments(char *buffer)
7.9 -{
7.10 - int num_sc = 0;
7.11 - size_t len = strlen(buffer);
7.12 - if (buffer)
7.13 - {
7.14 - for (int i = len - 1; i >= 0; i--)
7.15 - {
7.16 - if (buffer[i] == '/')
7.17 - {
7.18 - if (++num_sc >= 2 && i==0)
7.19 - {
7.20 - buffer[i] = '\0';
7.21 - return;
7.22 - }
7.23 - } else {
7.24 - if (num_sc >= 2)
7.25 - {
7.26 - buffer[i] = '\0';
7.27 - return;
7.28 - }
7.29 - num_sc = 0;
7.30 - }
7.31 - /* size_t won't go below 0, manually break out */
7.32 - if (i == 0)
7.33 - {
7.34 - break;
7.35 - }
7.36 - }
7.37 - }
7.38 -}
7.39 -
7.40 -void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2)
7.41 -{
7.42 - size_t start;
7.43 - size_t len = strlen(str);
7.44 -
7.45 - for (start = 0; start < len; start++)
7.46 - {
7.47 - if (!isspace(str[start]))
7.48 - {
7.49 - break;
7.50 - }
7.51 - }
7.52 -
7.53 - size_t end;
7.54 - for (end = start; end < len; end++)
7.55 - {
7.56 - if (isspace(str[end]))
7.57 - {
7.58 - break;
7.59 - }
7.60 - }
7.61 -
7.62 - size_t i, c = 0;
7.63 - for (i = start; i < end; i++, c++)
7.64 - {
7.65 - if (c >= len1)
7.66 - {
7.67 - break;
7.68 - }
7.69 - buf1[c] = str[i];
7.70 - }
7.71 - buf1[c] = '\0';
7.72 -
7.73 - for (start = end; start < len; start++)
7.74 - {
7.75 - if (!isspace(str[start]))
7.76 - {
7.77 - break;
7.78 - }
7.79 - }
7.80 -
7.81 - for (c = 0; start < len; start++, c++)
7.82 - {
7.83 - if (c >= len2)
7.84 - {
7.85 - break;
7.86 - }
7.87 - buf2[c] = str[start];
7.88 - }
7.89 - buf2[c] = '\0';
7.90 -}
7.91 -
7.92 bool UTIL_PathCmp(const char *path1, const char *path2)
7.93 {
7.94 size_t pos1 = 0, pos2 = 0;
8.1 --- a/core-legacy/util.h Sun Nov 23 21:21:49 2008 -0600
8.2 +++ b/core-legacy/util.h Sun Nov 23 21:22:04 2008 -0600
8.3 @@ -27,11 +27,6 @@
8.4 const char *UTIL_GetExtension(const char *file);
8.5
8.6 /**
8.7 - * @brief Removes C-style comments from string.
8.8 - */
8.9 -void UTIL_TrimComments(char *buffer);
8.10 -
8.11 -/**
8.12 * @brief Removes whitespace characters from left side of string.
8.13 */
8.14 void UTIL_TrimLeft(char *buffer);
8.15 @@ -42,11 +37,6 @@
8.16 void UTIL_TrimRight(char *buffer);
8.17
8.18 /**
8.19 - * @brief Breaks a string at the first space until it reaches a non-space.
8.20 - */
8.21 -void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2);
8.22 -
8.23 -/**
8.24 * @brief Compares two file paths.
8.25 */
8.26 bool UTIL_PathCmp(const char *path1, const char *path2);