ds@576: #include "metamod.h" ds@576: #include "metamod_util.h" ds@576: #include ds@576: #include ds@576: #include ds@576: #include ds@576: #include ds@576: #include "provider/provider_ep2.h" ds@576: ds@576: SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); ds@576: ds@576: ConCommand *g_plugin_unload = NULL; ds@576: bool g_bIsTryingToUnload; ds@576: ds@576: void InterceptPluginUnloads(const CCommand &args) ds@576: { ds@576: g_bIsTryingToUnload = true; ds@576: } ds@576: ds@576: void InterceptPluginUnloads_Post(const CCommand &args) ds@576: { ds@576: g_bIsTryingToUnload = false; ds@576: } ds@576: ds@576: class VspBridge : public IVspBridge ds@576: { ds@576: public: ds@576: virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) ds@576: { ds@576: assert(!g_Metamod.IsLoadedAsGameDLL()); ds@576: ds@576: CGlobalVars *pGlobals; ds@576: IPlayerInfoManager *playerInfoManager; ds@576: ds@576: playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL); ds@576: if (playerInfoManager == NULL) ds@576: { ds@576: UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game"); ds@576: return false; ds@576: } ds@576: ds@576: pGlobals = playerInfoManager->GetGlobalVars(); ds@576: ds@576: char gamedll_iface[] = "ServerGameDLL000"; ds@576: for (unsigned int i = 5; i <= 50; i++) ds@576: { ds@576: gamedll_iface[15] = '0' + i; ds@576: if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL) ds@576: { ds@576: g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i); ds@576: break; ds@576: } ds@576: } ds@576: ds@576: if (server == NULL) ds@576: { ds@576: UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible)."); ds@576: return false; ds@576: } ds@576: ds@576: char gameclients_iface[] = "ServerGameClients000"; ds@576: for (unsigned int i = 3; i <= 4; i++) ds@576: { ds@576: gameclients_iface[19] = '0' + i; ds@576: if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL) ds@576: break; ds@576: } ds@576: ds@576: if (!mm_DetectGameInformation()) ds@576: { ds@576: UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load."); ds@576: return false; ds@576: } ds@576: ds@576: mm_InitializeForLoad(); ds@576: mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory, ds@576: (CreateInterfaceFn)info->engineFactory, ds@576: (CreateInterfaceFn)info->engineFactory, ds@576: pGlobals); ds@576: mm_StartupMetamod(true); ds@576: ds@576: g_plugin_unload = icvar->FindCommand("plugin_unload"); ds@576: ds@576: if (g_plugin_unload != NULL) ds@576: { ds@576: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); ds@576: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); ds@576: } ds@576: ds@576: return true; ds@576: } ds@576: ds@576: virtual void Unload() ds@576: { ds@576: if (g_bIsTryingToUnload) ds@576: { ds@576: Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n"); ds@576: return; ds@576: } ds@576: if (g_plugin_unload != NULL) ds@576: { ds@576: SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); ds@576: SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); ds@576: g_plugin_unload = NULL; ds@576: } ds@576: mm_UnloadMetamod(); ds@576: } ds@576: ds@576: virtual const char *GetDescription() ds@576: { ds@576: return "Metamod:Source " SVN_FULL_VERSION; ds@576: } ds@576: }; ds@576: ds@576: VspBridge mm16_vsp_bridge; ds@576: ds@576: SMM_API IVspBridge * ds@576: GetVspBridge() ds@576: { ds@576: return &mm16_vsp_bridge; ds@576: } ds@576: