diff --git a/core-legacy/CPlugin.cpp b/core-legacy/CPlugin.cpp index a65cf97..b766c55 100644 --- a/core-legacy/CPlugin.cpp +++ b/core-legacy/CPlugin.cpp @@ -1,5 +1,5 @@ /* ======== SourceMM ======== - * Copyright (C) 2004-2008 Metamod:Source Development Team + * Copyright (C) 2004-2009 Metamod:Source Development Team * No warranties of any kind * * License: zlib/libpng @@ -12,7 +12,6 @@ #include "CSmmAPI.h" #include "sourcemm.h" #include "concommands.h" -#include "vsp_listener.h" #include "util.h" /** @@ -427,8 +426,7 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source //if (pl->m_API->GetApiVersion() >= 4) pl->m_API->AllPluginsLoaded(); } - if (g_bIsBridgedAsVsp || - (g_VspListener.IsLoaded() && g_SmmAPI.VSPEnabled())) + if (g_bIsBridgedAsVsp) { SourceHook::List::iterator event; for (event = pl->m_Events.begin(); diff --git a/core-legacy/CSmmAPI.cpp b/core-legacy/CSmmAPI.cpp index 5e7388f..5e64b8a 100644 --- a/core-legacy/CSmmAPI.cpp +++ b/core-legacy/CSmmAPI.cpp @@ -1,5 +1,5 @@ /* ======== SourceMM ======== - * Copyright (C) 2004-2008 Metamod:Source Development Team + * Copyright (C) 2004-2009 Metamod:Source Development Team * No warranties of any kind * * License: zlib/libpng @@ -13,7 +13,6 @@ #include "sourcemm.h" #include "concommands.h" #include "CPlugin.h" -#include "vsp_listener.h" #include "util.h" /** @@ -466,15 +465,13 @@ void CSmmAPI::LoadAsVSP() } } - char our_path[PATH_SIZE]; - GetFileOfAddress((void*)LoadAsGameDLL, our_path, sizeof(our_path)); - - const char *usepath = our_path; - if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_file, our_path)) + const char *usepath = g_MetamodPath.c_str(); + if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_file, g_MetamodPath.c_str())) + { usepath = rel_path; + } char command[PATH_SIZE * 2]; - g_VspListener.SetLoadable(true); UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath); g_Engine.engine->ServerCommand(command); } @@ -482,7 +479,7 @@ void CSmmAPI::LoadAsVSP() void CSmmAPI::EnableVSPListener() { /* If GameInit already passed and we're not already enabled or loaded, go ahead and LoadAsVSP load */ - if (g_bGameInit && !m_VSP && !g_VspListener.IsLoaded() && !g_bIsBridgedAsVsp) + if (g_bGameInit && !m_VSP && !g_bIsBridgedAsVsp) { LoadAsVSP(); } diff --git a/core-legacy/Makefile b/core-legacy/Makefile index 39f73d8..c21da8d 100644 --- a/core-legacy/Makefile +++ b/core-legacy/Makefile @@ -21,7 +21,6 @@ OBJECTS = oslink.cpp \ CSmmAPI.cpp \ sourcemm.cpp \ CPlugin.cpp \ - vsp_listener.cpp \ vsp_bridge.cpp \ gamedll_bridge.cpp \ sourcehook/sourcehook.cpp diff --git a/core-legacy/concommands.cpp b/core-legacy/concommands.cpp index 4e7247b..4f18550 100644 --- a/core-legacy/concommands.cpp +++ b/core-legacy/concommands.cpp @@ -1,5 +1,5 @@ /* ======== SourceMM ======== - * Copyright (C) 2004-2008 Metamod:Source Development Team + * Copyright (C) 2004-2009 Metamod:Source Development Team * No warranties of any kind * * License: zlib/libpng @@ -15,7 +15,6 @@ #include "CPlugin.h" #include "sh_string.h" #include "sh_list.h" -#include "vsp_listener.h" #include "util.h" /** @@ -121,7 +120,7 @@ CON_COMMAND(meta, "Metamod:Source Menu") int args = e->Cmd_Argc(); - if (g_bIsBridgedAsVsp && !g_bLevelChanged) + if (!g_GameDll.loaded && !g_bLevelChanged) { CONMSG("WARNING: You must change the map to activate Metamod:Source.\n"); return; @@ -143,13 +142,13 @@ CON_COMMAND(meta, "Metamod:Source Menu") } else if (strcmp(command, "version") == 0) { CONMSG("Metamod:Source version %s\n", MMS_FULL_VERSION); CONMSG("Build ID: %s\n", MMS_BUILD_UNIQUEID); - if (g_bIsBridgedAsVsp) + if (g_GameDll.loaded) { - CONMSG("Loaded As: Valve Server Plugin\n"); + CONMSG("Loaded As: GameDLL (gameinfo.txt)\n"); } else { - CONMSG("Loaded As: GameDLL (gameinfo.txt)\n"); + CONMSG("Loaded As: Valve Server Plugin\n"); } CONMSG("Compiled on: %s\n", SOURCEMM_DATE); CONMSG("Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION); diff --git a/core-legacy/msvc9/mm_core-legacy.vcproj b/core-legacy/msvc9/mm_core-legacy.vcproj index a219809..06bb9ea 100644 --- a/core-legacy/msvc9/mm_core-legacy.vcproj +++ b/core-legacy/msvc9/mm_core-legacy.vcproj @@ -226,10 +226,6 @@ RelativePath="..\vsp_bridge.cpp" > - - - - @@ -57,6 +56,7 @@ EngineInfo g_Engine; SourceHook::CSourceHookImpl g_SourceHook; SourceHook::ISourceHook *g_SHPtr = &g_SourceHook; SourceHook::String g_ModPath; +SourceHook::String g_MetamodPath; PluginId g_PLID = Pl_Console; /* Technically, SourceMM is the "Console" plugin... :p */ static bool bInFirstLevel = true; bool g_bGameInit = false; @@ -66,7 +66,7 @@ static const char VSPIFACE_002[] = "ISERVERPLUGINCALLBACKS002"; static const char GAMEINFO_PATH[] = "|gameinfo_path|"; IFileSystem *baseFs = NULL; bool g_bLevelChanged = false; -IServerPluginCallbacks *g_pRealVspCallbacks = &g_VspListener; +IServerPluginCallbacks *g_pRealVspCallbacks = NULL; unsigned int g_vsp_version = 0; #define ITER_EVENT(evn, args) \ @@ -125,41 +125,6 @@ void DoInitialPluginLoads() LoadPlugins(filepath, vdfpath); } -SMM_API void * -CreateInterface(const char *iface, int *ret) -{ - void *ptr = NULL; - - if (!g_bIsBridgedAsVsp && strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0) - { - if (g_VspListener.IsLoaded()) - { - if (ret != NULL) - *ret = IFACE_FAILED; - return NULL; - } - - assert(&g_VspListener == g_pRealVspCallbacks); - - int vsp_version = atoi(&iface[22]); - if (vsp_version < 1 || vsp_version > 2) - { - if (ret != NULL) - *ret = IFACE_FAILED; - return NULL; - } - - g_vsp_version = vsp_version; - - return g_pRealVspCallbacks; - } - - if (ret) - *ret = (ptr != NULL) ? IFACE_OK : IFACE_FAILED; - - return ptr; -} - bool StartupMetamod(CreateInterfaceFn engineFactory, bool bWaitForGameInit) { g_Engine.engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL)); @@ -241,6 +206,7 @@ void LoadAsGameDLL(const gamedll_bridge_info *info) g_GameDll.factory = (CreateInterfaceFn)info->gsFactory; g_GameDll.pGameDLL = (IServerGameDLL*)info->isgd; g_GameDllVersion = info->dllVersion; + g_MetamodPath.assign(info->vsp_listener_path); InitMainStates(); diff --git a/core-legacy/sourcemm.h b/core-legacy/sourcemm.h index 5342fb8..fbf475e 100644 --- a/core-legacy/sourcemm.h +++ b/core-legacy/sourcemm.h @@ -1,5 +1,5 @@ /* ======== SourceMM ======== - * Copyright (C) 2004-2008 Metamod:Source Development Team + * Copyright (C) 2004-2009 Metamod:Source Development Team * No warranties of any kind * * License: zlib/libpng @@ -96,6 +96,9 @@ extern SourceHook::CSourceHookImpl g_SourceHook; /** @brief Mod path (important!)*/ extern SourceHook::String g_ModPath; +/** @brief Path to Metamod binary */ +extern SourceHook::String g_MetamodPath; + /** @brief Global variable for SourceHook macros */ extern SourceHook::ISourceHook *g_SHPtr; diff --git a/core-legacy/vsp_bridge.cpp b/core-legacy/vsp_bridge.cpp index 3899a90..4b61b98 100644 --- a/core-legacy/vsp_bridge.cpp +++ b/core-legacy/vsp_bridge.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #include @@ -36,6 +34,7 @@ SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); ConCommand *g_plugin_unload = NULL; bool g_bIsTryingToUnload; bool g_bIsBridgedAsVsp; +const char *vsp_desc = "Metamod:Source " MMS_FULL_VERSION; void InterceptPluginUnloads() { @@ -51,13 +50,26 @@ class VspBridge : public IVspBridge { virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) { - assert(!g_GameDll.loaded && !g_bIsBridgedAsVsp); + assert(!g_bIsBridgedAsVsp); - CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory; - CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory; + if (!g_GameDll.loaded) + { + CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory; + CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory; - if (!AlternatelyLoadMetamod(engineFactory, gsFactory)) - return false; + if (!AlternatelyLoadMetamod(engineFactory, gsFactory)) + return false; + + extern ConVar metamod_version; + char buffer[255]; + + UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString()); + metamod_version.SetValue(buffer); + } + else + { + vsp_desc = "Metamod:Source Interface " MMS_FULL_VERSION; + } ConCommandBase *pBase = g_Engine.icvar->GetCommands(); while (pBase != NULL) @@ -76,12 +88,6 @@ class VspBridge : public IVspBridge SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); } - extern ConVar metamod_version; - char buffer[255]; - - UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString()); - metamod_version.SetValue(buffer); - g_bIsBridgedAsVsp = true; g_pRealVspCallbacks = info->vsp_callbacks; g_vsp_version = info->vsp_version; @@ -104,13 +110,16 @@ class VspBridge : public IVspBridge SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); g_plugin_unload = NULL; } - g_SMConVarAccessor.UnloadMetamodCommands(); - UnloadMetamod(false); + if (!g_GameDll.loaded) + { + g_SMConVarAccessor.UnloadMetamodCommands(); + UnloadMetamod(false); + } } virtual const char *GetDescription() { - return "Metamod:Source " MMS_FULL_VERSION; + return vsp_desc; } }; diff --git a/core-legacy/vsp_listener.cpp b/core-legacy/vsp_listener.cpp deleted file mode 100644 index 79a5250..0000000 --- a/core-legacy/vsp_listener.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* ======== SourceMM ======== - * Copyright (C) 2004-2008 Metamod:Source Development Team - * No warranties of any kind - * - * License: zlib/libpng - * - * Author(s): David "BAILOPAN" Anderson - * ============================ - */ - -#include "vsp_listener.h" -#include "CPlugin.h" -#include "concommands.h" - -using namespace SourceMM; - -VSPListener g_VspListener; - -VSPListener::VSPListener() -{ - m_Loaded = false; - m_Loadable = false; -} - -void VSPListener::ClientActive(edict_t *pEntity) -{ -} - -PLUGIN_RESULT VSPListener::ClientCommand(edict_t *pEntity) -{ - return PLUGIN_CONTINUE; -} - -PLUGIN_RESULT VSPListener::ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) -{ - return PLUGIN_CONTINUE; -} - -void VSPListener::ClientDisconnect(edict_t *pEntity) -{ -} - -void VSPListener::ClientPutInServer(edict_t *pEntity, char const *playername) -{ -} - -void VSPListener::ClientSettingsChanged(edict_t *pEdict) -{ -} - -void VSPListener::SetCommandClient(int index) -{ -} - -void VSPListener::GameFrame(bool simulating) -{ -} - -const char *VSPListener::GetPluginDescription() -{ - return "Metamod:Source Interface " MMS_FULL_VERSION; -} - -bool VSPListener::IsLoaded() -{ - return m_Loaded; -} - -void VSPListener::LevelInit(char const *pMapName) -{ -} - -void VSPListener::LevelShutdown() -{ -} - -PLUGIN_RESULT VSPListener::NetworkIDValidated(const char *pszUserName, const char *pszNetworkID) -{ - return PLUGIN_CONTINUE; -} - -void VSPListener::Pause() -{ -} - -void VSPListener::UnPause() -{ -} - -void VSPListener::ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) -{ -} - -void VSPListener::Unload() -{ - m_Loadable = true; - m_Loaded = false; -} - -void VSPListener::SetLoadable(bool set) -{ - m_Loadable = set; -} - -bool VSPListener::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) -{ - if (m_Loaded || !m_Loadable) - return false; - - m_Loaded = true; - SetLoadable(false); - - g_PluginMngr.SetVSPAsLoaded(); - - return true; -} - diff --git a/core-legacy/vsp_listener.h b/core-legacy/vsp_listener.h deleted file mode 100644 index d1d7b19..0000000 --- a/core-legacy/vsp_listener.h +++ /dev/null @@ -1,50 +0,0 @@ -/* ======== SourceMM ======== - * Copyright (C) 2004-2008 Metamod:Source Development Team - * No warranties of any kind - * - * License: zlib/libpng - * - * Author(s): David "BAILOPAN" Anderson - * ============================ - */ - -#ifndef _INCLUDE_SOURCEMM_VSPLISTENER_H_ -#define _INCLUDE_SOURCEMM_VSPLISTENER_H_ - -#include "sourcemm.h" -#include "iserverplugin.h" - -class VSPListener : public IServerPluginCallbacks -{ -public: - VSPListener(); -public: - virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory); - virtual void Unload(); - virtual void Pause(); - virtual void UnPause(); - virtual const char *GetPluginDescription(); - virtual void LevelInit(char const *pMapName); - virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax); - virtual void GameFrame(bool simulating); - virtual void LevelShutdown(void); - virtual void ClientActive(edict_t *pEntity); - virtual void ClientDisconnect(edict_t *pEntity); - virtual void ClientPutInServer(edict_t *pEntity, char const *playername); - virtual void SetCommandClient(int index); - virtual void ClientSettingsChanged(edict_t *pEdict); - virtual PLUGIN_RESULT ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen); - virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity); - virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID); -public: - bool IsLoaded(); - void SetLoadable(bool loadable); -private: - bool m_Loaded; - bool m_Loadable; -}; - -extern VSPListener g_VspListener; - -#endif //_INCLUDE_SOURCEMM_VSPLISTENER_H_ - diff --git a/core/Makefile b/core/Makefile index fd24714..5fd4bf7 100644 --- a/core/Makefile +++ b/core/Makefile @@ -20,7 +20,6 @@ OBJECTS = metamod.cpp \ sourcehook/sourcehook_hookmangen.cpp \ provider/console.cpp \ provider/provider_ep2.cpp \ - provider/vsp_listener.cpp \ vsp_bridge.cpp \ gamedll_bridge.cpp @@ -43,6 +42,7 @@ ifeq "$(ENGINE)" "orangebox" INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/orangebox BINARY = metamod.2.ep2.so + LIB_SUFFIX = i486 override ENGSET = true endif ifeq "$(ENGINE)" "orangeboxvalve" @@ -53,6 +53,7 @@ ifeq "$(ENGINE)" "orangeboxvalve" INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/orangebox BINARY = metamod.2.ep2v.so + LIB_SUFFIX = i486 override ENGSET = true endif ifeq "$(ENGINE)" "left4dead" @@ -63,6 +64,7 @@ ifeq "$(ENGINE)" "left4dead" INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/l4d BINARY = metamod.2.l4d.so + LIB_SUFFIX = i486 override ENGSET = true endif ifeq "$(ENGINE)" "left4dead2" @@ -73,16 +75,13 @@ ifeq "$(ENGINE)" "left4dead2" INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/left4dead2_demo BINARY = metamod.2.l4d2.so + LIB_SUFFIX = linux override ENGSET = true endif CFLAGS += -DSE_DARKMESSIAH=2 -DSE_ORANGEBOX=3 -DSE_ORANGEBOXVALVE=4 -DSE_LEFT4DEAD=5 -DSE_LEFT4DEAD2=6 -ifeq "$(ENGINE)" "left4dead2" - LINK += $(HL2LIB)/tier1_i486.a vstdlib_linux.so tier0_linux.so -static-libgcc -else - LINK += $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so -static-libgcc -endif +LINK += $(HL2LIB)/tier1_i486.a vstdlib_$(LIB_SUFFIX).so tier0_$(LIB_SUFFIX).so -static-libgcc INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \ -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 -I. -Isourcehook -I../loader @@ -123,13 +122,8 @@ all: check mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)/provider mkdir -p $(BIN_DIR)/sourcehook - if [ "$(ENGINE)" = "left4dead2" ]; then \ - ln -sf $(HL2LIB)/vstdlib_linux.so vstdlib_linux.so; \ - ln -sf $(HL2LIB)/tier0_linux.so tier0_linux.so; \ - else \ - ln -sf $(HL2LIB)/vstdlib_i486.so vstdlib_i486.so; \ - ln -sf $(HL2LIB)/tier0_i486.so tier0_i486.so; \ - fi + ln -sf $(HL2LIB)/vstdlib_$(LIB_SUFFIX).so + ln -sf $(HL2LIB)/tier0_$(LIB_SUFFIX).so $(MAKE) -f Makefile metamod check: diff --git a/core/gamedll_bridge.cpp b/core/gamedll_bridge.cpp index 0e61d27..4a92d84 100644 --- a/core/gamedll_bridge.cpp +++ b/core/gamedll_bridge.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #include @@ -49,6 +47,7 @@ public: g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, info->dllVersion, true); + g_Metamod.SetVSPListener(info->vsp_listener_path); mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory, (CreateInterfaceFn)info->physicsFactory, (CreateInterfaceFn)info->fsFactory, diff --git a/core/metamod.cpp b/core/metamod.cpp index 51b9c19..29288b7 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #include @@ -182,17 +180,8 @@ mm_InitializeForLoad() bool mm_DetectGameInformation() { - char mm_path[PATH_SIZE]; char game_path[PATH_SIZE]; - /* Get path to SourceMM DLL */ - if (!GetFileOfAddress((void *)mm_InitializeForLoad, mm_path, sizeof(mm_path))) - { - return false; - } - - metamod_path.assign(mm_path); - /* Get value of -game from command line, defaulting to hl2 as engine seems to do */ const char *game_dir = provider->GetCommandLineValue("-game"); @@ -220,33 +209,6 @@ ServerFactory(const char *iface, int *ret) IFACE_MACRO(gamedll_info.factory, GameDLL); } -SMM_API void * -CreateInterface(const char *iface, int *ret) -{ - void *ptr = NULL; - - if (!mm_IsVspBridged() && strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0) - { - if (vsp_callbacks != NULL) - { - if (ret != NULL) - *ret = IFACE_FAILED; - return NULL; - } - - vsp_version = atoi(&iface[22]); - ptr = provider->GetVSPCallbacks(vsp_version); - - if (ptr == NULL) - vsp_version = 0; - } - - if (ret) - *ret = (ptr != NULL) ? IFACE_OK : IFACE_FAILED; - - return ptr; -} - static int LoadPluginsFromFile(const char *filepath, int &skipped) { @@ -868,7 +830,9 @@ void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...) void MetamodSource::EnableVSPListener() { if (is_game_init && !vsp_load_requested && !vsp_loaded) + { InitializeVSP(); + } vsp_load_requested = true; } @@ -1077,6 +1041,16 @@ void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int ve vsp_callbacks = callbacks; ITER_EVENT(OnVSPListening, (callbacks)); + + if (is_gamedll_loaded) + { + /* + * MM:S is loaded as a game DLL so we need to set these for mm_IsVspBridged() and + * mm_IsVspLoadComplete() + */ + g_bIsVspBridged = true; + were_plugins_loaded = true; + } } IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion) @@ -1118,6 +1092,11 @@ void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, is_gamedll_loaded = loaded; } +void MetamodSource::SetVSPListener(const char *path) +{ + metamod_path.assign(path); +} + static bool ProcessVDF(const char *path, bool &skipped) { diff --git a/core/metamod.h b/core/metamod.h index d5e6323..6fc9712 100644 --- a/core/metamod.h +++ b/core/metamod.h @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #ifndef _INCLUDE_SOURCEMM_H @@ -100,6 +98,7 @@ public: void UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand); void NotifyVSPListening(IServerPluginCallbacks *callbacks, int version); void SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded); + void SetVSPListener(const char *path); }; bool diff --git a/core/metamod_provider.h b/core/metamod_provider.h index c5f8504..c837cfb 100644 --- a/core/metamod_provider.h +++ b/core/metamod_provider.h @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #ifndef _INCLUDE_METAMOD_SOURCE_SUPPORT_H_ @@ -142,15 +140,6 @@ namespace SourceMM */ virtual void ClientConsolePrint(edict_t *client, const char *msg) =0; - /** - * @brief Returns a server plugin helper for the given interface - * string. - * - * @param iface Interface version - * @return IServerPluginCallbacks pointer. - */ - virtual IServerPluginCallbacks *GetVSPCallbacks(int version) =0; - /** * @brief Halts the server with a fatal error message. * diff --git a/core/msvc9/mm_core.vcproj b/core/msvc9/mm_core.vcproj index e707999..f43e071 100644 --- a/core/msvc9/mm_core.vcproj +++ b/core/msvc9/mm_core.vcproj @@ -983,10 +983,6 @@ RelativePath="..\provider\provider_ep2.h" > - - - - #include "metamod.h" @@ -74,7 +73,6 @@ void _ServerCommand(); /* Variables */ static bool usermsgs_extracted = false; static CVector usermsgs_list; -static VSPListener g_VspListener; static BaseProvider g_Ep1Provider; static List conbases_unreg; @@ -420,17 +418,6 @@ ConVar *BaseProvider::CreateConVar(const char *name, return pVar; } -IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(int version) -{ - if (version > 2) - { - return NULL; - } - - g_VspListener.SetLoadable(true); - return &g_VspListener; -} - bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len) { if (baseFs == NULL) diff --git a/core/provider/provider_ep2.h b/core/provider/provider_ep2.h index 1ad74df..255f67d 100644 --- a/core/provider/provider_ep2.h +++ b/core/provider/provider_ep2.h @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #ifndef _INCLUDE_METAMOD_SOURCE_BASE_PROVIDER_H_ @@ -56,7 +54,6 @@ public: virtual void ConsolePrint(const char *msg); virtual bool IsRemotePrintingAvailable(); virtual void ClientConsolePrint(edict_t *client, const char *msg); - virtual IServerPluginCallbacks *GetVSPCallbacks(int version); virtual void DisplayError(const char *fmt, ...); virtual void DisplayWarning(const char *fmt, ...); virtual int TryServerGameDLL(const char *iface); diff --git a/core/provider/vsp_listener.cpp b/core/provider/vsp_listener.cpp deleted file mode 100644 index eede351..0000000 --- a/core/provider/vsp_listener.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/** - * vim: set ts=4 : - * ====================================================== - * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. - * All rights reserved. - * ====================================================== - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from - * the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in a - * product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ - */ - -#include -#include "../metamod_oslink.h" -#include "metamod.h" -#include -#include -#include -#include "iplayerinfo.h" -#include "vsp_listener.h" -#include "version.h" -#include "provider_ep2.h" - -using namespace SourceMM; - -VSPListener::VSPListener() -{ - m_bLoaded = false; - m_bLoadable = false; -} - -void VSPListener::ClientActive(edict_t *pEntity) -{ -} - -#if SOURCE_ENGINE >= SE_ORANGEBOX -PLUGIN_RESULT VSPListener::ClientCommand(edict_t *pEntity, const CCommand &cmd) -#else -PLUGIN_RESULT VSPListener::ClientCommand(edict_t *pEntity) -#endif -{ - return PLUGIN_CONTINUE; -} - -PLUGIN_RESULT VSPListener::ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) -{ - return PLUGIN_CONTINUE; -} - -void VSPListener::ClientDisconnect(edict_t *pEntity) -{ -} - -void VSPListener::ClientPutInServer(edict_t *pEntity, char const *playername) -{ -} - -void VSPListener::ClientSettingsChanged(edict_t *pEdict) -{ -} - -void VSPListener::SetCommandClient(int index) -{ -} - -void VSPListener::GameFrame(bool simulating) -{ -} - -const char *VSPListener::GetPluginDescription() -{ - return "Metamod:Source Interface " MMS_FULL_VERSION; -} - -bool VSPListener::IsLoaded() -{ - return m_bLoaded; -} - -void VSPListener::LevelInit(char const *pMapName) -{ -} - -void VSPListener::LevelShutdown() -{ -} - -PLUGIN_RESULT VSPListener::NetworkIDValidated(const char *pszUserName, const char *pszNetworkID) -{ - return PLUGIN_CONTINUE; -} - -void VSPListener::Pause() -{ -} - -void VSPListener::UnPause() -{ -} - -void VSPListener::ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) -{ -} - -void VSPListener::Unload() -{ - m_bLoaded = false; - m_bLoadable = true; -} - -void VSPListener::SetLoadable(bool set) -{ - m_bLoadable = set; -} - -bool VSPListener::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) -{ - m_bLoaded = true; - SetLoadable(false); - - g_Metamod.NotifyVSPListening(this, -1); - - return true; -} - -#if SOURCE_ENGINE != SE_DARKMESSIAH -void VSPListener::OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, - edict_t *pPlayerEntity, - EQueryCvarValueStatus eStatus, - const char *pCvarName, - const char *pCvarValue) -{ -} -#endif - diff --git a/core/provider/vsp_listener.h b/core/provider/vsp_listener.h deleted file mode 100644 index 52a6ac6..0000000 --- a/core/provider/vsp_listener.h +++ /dev/null @@ -1,81 +0,0 @@ -/** - * vim: set ts=4 : - * ====================================================== - * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. - * All rights reserved. - * ====================================================== - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from - * the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in a - * product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_ -#define _INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_ - -#if defined _DEBUG -#define DEBUG2 -#undef _DEBUG -#endif -#include "iserverplugin.h" -#if defined DEBUG2 -#undef DEBUG2 -#define _DEBUG -#endif - - - -class VSPListener : public IServerPluginCallbacks -{ -public: - VSPListener(); -public: - virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory); - virtual void Unload(); - virtual void Pause(); - virtual void UnPause(); - virtual const char *GetPluginDescription(); - virtual void LevelInit(char const *pMapName); - virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax); - virtual void GameFrame(bool simulating); - virtual void LevelShutdown(void); - virtual void ClientActive(edict_t *pEntity); - virtual void ClientDisconnect(edict_t *pEntity); - virtual void ClientPutInServer(edict_t *pEntity, char const *playername); - virtual void SetCommandClient(int index); - virtual void ClientSettingsChanged(edict_t *pEdict); - virtual PLUGIN_RESULT ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen); -#if SOURCE_ENGINE >= SE_ORANGEBOX - virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity, const CCommand &cmd); -#else - virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity); -#endif - virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID); -#if SOURCE_ENGINE != SE_DARKMESSIAH - virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ); -#endif -public: - bool IsLoaded(); - void SetLoadable(bool loadable); -private: - bool m_bLoaded; - bool m_bLoadable; -}; - -#endif //_INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_ - diff --git a/core/vsp_bridge.cpp b/core/vsp_bridge.cpp index bc7eb42..783e481 100644 --- a/core/vsp_bridge.cpp +++ b/core/vsp_bridge.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #include "metamod.h" @@ -42,6 +40,7 @@ SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); ConCommand *g_plugin_unload = NULL; bool g_bIsTryingToUnload; +const char *vsp_desc = "Metamod:Source " MMS_FULL_VERSION; #if SOURCE_ENGINE >= SE_ORANGEBOX void InterceptPluginUnloads(const CCommand &args) @@ -66,59 +65,65 @@ class VspBridge : public IVspBridge public: virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) { - assert(!g_Metamod.IsLoadedAsGameDLL()); - - CGlobalVars *pGlobals; - IPlayerInfoManager *playerInfoManager; - - playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL); - if (playerInfoManager == NULL) + if (!g_Metamod.IsLoadedAsGameDLL()) { - UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game"); - return false; - } + CGlobalVars *pGlobals; + IPlayerInfoManager *playerInfoManager; - pGlobals = playerInfoManager->GetGlobalVars(); - - char gamedll_iface[] = "ServerGameDLL000"; - for (unsigned int i = 3; i <= 50; i++) - { - gamedll_iface[15] = '0' + i; - if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL) + playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL); + if (playerInfoManager == NULL) { - g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false); - break; + UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game"); + return false; } - } - if (server == NULL) + pGlobals = playerInfoManager->GetGlobalVars(); + + char gamedll_iface[] = "ServerGameDLL000"; + for (unsigned int i = 3; i <= 50; i++) + { + gamedll_iface[15] = '0' + i; + if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL) + { + g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false); + break; + } + } + + if (server == NULL) + { + UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible)."); + return false; + } + + char gameclients_iface[] = "ServerGameClients000"; + for (unsigned int i = 3; i <= 4; i++) + { + gameclients_iface[19] = '0' + i; + if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL) + break; + } + + if (!mm_DetectGameInformation()) + { + UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load."); + return false; + } + + mm_InitializeForLoad(); + mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory, + (CreateInterfaceFn)info->engineFactory, + (CreateInterfaceFn)info->engineFactory, + pGlobals); + g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version); + mm_StartupMetamod(true); + } + else { - UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible)."); - return false; + vsp_desc = "Metamod:Source Interface " MMS_FULL_VERSION; + g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version); } - char gameclients_iface[] = "ServerGameClients000"; - for (unsigned int i = 3; i <= 4; i++) - { - gameclients_iface[19] = '0' + i; - if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL) - break; - } - - if (!mm_DetectGameInformation()) - { - UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load."); - return false; - } - - mm_InitializeForLoad(); - mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory, - (CreateInterfaceFn)info->engineFactory, - (CreateInterfaceFn)info->engineFactory, - pGlobals); - g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version); - mm_StartupMetamod(true); - #if SOURCE_ENGINE >= SE_ORANGEBOX g_plugin_unload = icvar->FindCommand("plugin_unload"); #else @@ -156,12 +161,15 @@ public: SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); g_plugin_unload = NULL; } - mm_UnloadMetamod(); + if (!g_Metamod.IsLoadedAsGameDLL()) + { + mm_UnloadMetamod(); + } } virtual const char *GetDescription() { - return "Metamod:Source " MMS_FULL_VERSION; + return vsp_desc; } }; diff --git a/loader/Makefile b/loader/Makefile index ac2297a..97e69ff 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -22,10 +22,10 @@ CPP = gcc-4.1 ifeq "$(ENGINE)" "left4dead2" BINARY = server_linux.so - CFLAGS += -DBINARY_SUFFIX=\"_linux.so\" + CFLAGS += -DLIB_SUFFIX=\"_linux.so\" else BINARY = server_i486.so - CFLAGS += -DBINARY_SUFFIX=\"_i486.so\" + CFLAGS += -DLIB_SUFFIX=\"_i486.so\" endif LINK += -static-libgcc diff --git a/loader/gamedll.cpp b/loader/gamedll.cpp index 2ec7b94..35a2c2c 100644 --- a/loader/gamedll.cpp +++ b/loader/gamedll.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #include @@ -52,17 +50,17 @@ static IServerGameDLL *gamedll_iface = NULL; static QueryValveInterface gamedll_qvi = NULL; static int gamedll_version = 0; static int isgd_shutdown_index = -1; +static char mm_path[PLATFORM_MAX_PATH]; #if defined _WIN32 #define SERVER_NAME "server.dll" #elif defined __linux__ -#define SERVER_NAME "server" BINARY_SUFFIX +#define SERVER_NAME "server" LIB_SUFFIX #endif static bool mm_DetectGameInformation() { - char mm_path[PLATFORM_MAX_PATH]; char game_path[PLATFORM_MAX_PATH]; if (game_info_detected) @@ -77,7 +75,7 @@ mm_DetectGameInformation() if (!mm_GetFileOfAddress((void*)mm_DetectGameInformation, mm_path, sizeof(mm_path))) { - mm_LogFatal("Could not locate metamod loader library path"); + mm_LogFatal("Could not locate Metamod loader library path"); return false; } @@ -216,18 +214,18 @@ public: QueryValveInterface fileSystemFactory, void *pGlobals) { - MetamodBackend backend = mm_DetermineBackend(engineFactory, game_name); + mm_backend = mm_DetermineBackend(engineFactory, game_name); char error[255]; - if (backend == MMBackend_UNKNOWN) + if (mm_backend == MMBackend_UNKNOWN) { mm_LogFatal("Could not detect engine version"); } else { - if (!mm_LoadMetamodLibrary(backend, error, sizeof(error))) + if (!mm_LoadMetamodLibrary(mm_backend, error, sizeof(error))) { - mm_LogFatal("Detected engine %d but could not load: %s", backend, error); + mm_LogFatal("Detected engine %d but could not load: %s", mm_backend, error); } else { @@ -236,7 +234,7 @@ public: if (get_bridge == NULL) { mm_UnloadMetamodLibrary(); - mm_LogFatal("Detected engine %d but could not find GetGameDllBridge callback", backend); + mm_LogFatal("Detected engine %d but could not find GetGameDllBridge callback", mm_backend); } else { @@ -256,13 +254,14 @@ public: info.dllVersion = gamedll_version; info.isgd = gamedll_iface; info.gsFactory = gamedll_qvi; + info.vsp_listener_path = mm_path; strcpy(error, "Unknown error"); if (!gamedll_bridge->DLLInit_Pre(&info, error, sizeof(error))) { gamedll_bridge = NULL; mm_UnloadMetamodLibrary(); - mm_LogFatal("Unknown error loading Metamod for engine %d: %s", backend, error); + mm_LogFatal("Unknown error loading Metamod for engine %d: %s", mm_backend, error); } } diff --git a/loader/loader.cpp b/loader/loader.cpp index b8ba443..8dd2d96 100644 --- a/loader/loader.cpp +++ b/loader/loader.cpp @@ -41,6 +41,7 @@ typedef ICommandLine *(*GetCommandLine)(); static HMODULE mm_library = NULL; static char mm_fatal_logfile[PLATFORM_MAX_PATH] = "metamod-fatal.log"; +MetamodBackend mm_backend = MMBackend_UNKNOWN; extern void mm_LogFatal(const char *message, ...) @@ -81,7 +82,7 @@ static const char *backend_names[] = #define LIBRARY_EXT ".dll" #define LIBRARY_MINEXT ".dll" #elif defined __linux__ -#define LIBRARY_EXT BINARY_SUFFIX +#define LIBRARY_EXT LIB_SUFFIX #define LIBRARY_MINEXT ".so" #endif @@ -146,16 +147,22 @@ CreateInterface(const char *name, int *ret) return NULL; } - /* If we've got a gamedll bridge, forward the request. */ - if (gamedll_bridge != NULL) - return gamedll_bridge->QueryInterface(name, ret); - - /* Otherwise, we're probably trying to load Metamod. */ void *ptr; if (strncmp(name, "ISERVERPLUGINCALLBACKS", 22) == 0) + { + /* Either load as VSP or start VSP listener */ ptr = mm_GetVspCallbacks(atoi(&name[22])); - else + } + else if (gamedll_bridge == NULL) + { + /* Load as gamedll */ ptr = mm_GameDllRequest(name, ret); + } + else + { + /* If we've got a gamedll bridge, forward the request. */ + return gamedll_bridge->QueryInterface(name, ret); + } if (ret != NULL) *ret = (ptr != NULL) ? 0 : 1; @@ -173,8 +180,8 @@ mm_GetProcAddress(const char *name) #define TIER0_NAME "bin\\tier0.dll" #define VSTDLIB_NAME "bin\\vstdlib.dll" #elif defined __linux__ -#define TIER0_NAME "bin/tier0" BINARY_SUFFIX -#define VSTDLIB_NAME "bin/vstdlib" BINARY_SUFFIX +#define TIER0_NAME "bin/tier0" LIB_SUFFIX +#define VSTDLIB_NAME "bin/vstdlib" LIB_SUFFIX #endif const char * diff --git a/loader/loader.h b/loader/loader.h index 1f33d6d..16c5c67 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -86,5 +86,7 @@ mm_GetGameName(); extern MetamodBackend mm_DetermineBackend(QueryValveInterface qvi, const char *game_name); +extern MetamodBackend mm_backend; + #endif /* _INCLUDE_METAMOD_SOURCE_LOADER_H_ */ diff --git a/loader/loader_bridge.h b/loader/loader_bridge.h index fb4f539..07570ce 100644 --- a/loader/loader_bridge.h +++ b/loader/loader_bridge.h @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ====================================================== * Metamod:Source - * Copyright (C) 2004-2008 AlliedModders LLC and authors. + * Copyright (C) 2004-2009 AlliedModders LLC and authors. * All rights reserved. * ====================================================== * @@ -21,8 +21,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * - * Version: $Id$ */ #ifndef _INCLUDE_METAMOD_SOURCE_LOADER_BRIDGE_H_ @@ -56,6 +54,7 @@ struct gamedll_bridge_info void * pGlobals; unsigned int dllVersion; void * isgd; + const char * vsp_listener_path; }; class IGameDllBridge diff --git a/loader/serverplugin.cpp b/loader/serverplugin.cpp index f889c08..ac3e2f3 100644 --- a/loader/serverplugin.cpp +++ b/loader/serverplugin.cpp @@ -31,6 +31,7 @@ #include #include #include "serverplugin.h" +#include "gamedll.h" typedef enum { @@ -52,12 +53,6 @@ class CCommand; class IServerPluginCallbacks; struct edict_t; -#if defined WIN32 -#define LIBRARY_EXT ".dll" -#else -#define LIBRARY_EXT "_i486.so" -#endif - class IRandomThings { public: @@ -90,19 +85,23 @@ public: load_allowed = false; - if ((game_name = mm_GetGameName()) == NULL) + /* Backend should already filled in if loaded as gamedll */ + if (gamedll_bridge == NULL) { - return false; + if ((game_name = mm_GetGameName()) == NULL) + { + return false; + } + + mm_backend = mm_DetermineBackend(engineFactory, game_name); } - MetamodBackend backend = mm_DetermineBackend(engineFactory, game_name); - - if (backend == MMBackend_UNKNOWN) + if (mm_backend == MMBackend_UNKNOWN) { mm_LogFatal("Could not detect engine version"); return false; } - else if (backend >= MMBackend_Episode2) + else if (mm_backend >= MMBackend_Episode2) { /* We need to insert the right type of call into this vtable */ void **vtable_src; @@ -126,24 +125,30 @@ public: vtable_src = (void **)*(void **)&sample; vtable_dest = (void **)*(void **)this; SourceHook::SetMemAccess(&vtable_dest[mfp_dest.vtblindex], - sizeof(void*), + sizeof(void*), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC); vtable_dest[mfp_dest.vtblindex] = vtable_src[mfp_src.vtblindex]; } char error[255]; - if (!mm_LoadMetamodLibrary(backend, error, sizeof(error))) + if (gamedll_bridge == NULL) { - mm_LogFatal("Detected engine %d but could not load: %s", backend, error); - return false; + if (!mm_LoadMetamodLibrary(mm_backend, error, sizeof(error))) + { + mm_LogFatal("Detected engine %d but could not load: %s", mm_backend, error); + return false; + } } typedef IVspBridge *(*GetVspBridge)(); GetVspBridge get_bridge = (GetVspBridge)mm_GetProcAddress("GetVspBridge"); if (get_bridge == NULL) { - mm_UnloadMetamodLibrary(); - mm_LogFatal("Detected engine %d but could not find GetVspBridge callback", backend); + if (gamedll_bridge == NULL) + { + mm_UnloadMetamodLibrary(); + } + mm_LogFatal("Detected engine %d but could not find GetVspBridge callback", mm_backend); return false; } @@ -160,8 +165,11 @@ public: if (!vsp_bridge->Load(&info, error, sizeof(error))) { vsp_bridge = NULL; - mm_UnloadMetamodLibrary(); - mm_LogFatal("Unknown error loading Metamod for engine %d: %s", backend, error); + if (gamedll_bridge == NULL) + { + mm_UnloadMetamodLibrary(); + } + mm_LogFatal("Unknown error loading Metamod for engine %d: %s", mm_backend, error); return false; } @@ -172,7 +180,11 @@ public: if (vsp_bridge == NULL) return; vsp_bridge->Unload(); - mm_UnloadMetamodLibrary(); + + if (gamedll_bridge == NULL) + { + mm_UnloadMetamodLibrary(); + } } virtual void Pause() {