ds@599: #include ds@599: #include "sourcemm.h" ds@599: #include "concommands.h" ds@599: #include ds@599: ds@599: SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); ds@599: ds@599: ConCommand *g_plugin_unload = NULL; ds@599: bool g_bIsTryingToUnload; ds@599: bool g_bIsBridgedAsVsp; ds@599: ds@599: void InterceptPluginUnloads() ds@599: { ds@599: g_bIsTryingToUnload = true; ds@599: } ds@599: ds@599: void InterceptPluginUnloads_Post() ds@599: { ds@599: g_bIsTryingToUnload = false; ds@599: } ds@599: ds@599: class VspBridge : public IVspBridge ds@599: { ds@599: virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) ds@599: { ds@599: assert(!g_GameDll.loaded && !g_bIsBridgedAsVsp); ds@599: ds@599: CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory; ds@599: CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory; ds@599: ds@599: if (!AlternatelyLoadMetamod(engineFactory, gsFactory)) ds@599: return false; ds@599: ds@599: ConCommandBase *pBase = g_Engine.icvar->GetCommands(); ds@599: while (pBase != NULL) ds@599: { ds@599: if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0) ds@599: { ds@599: g_plugin_unload = (ConCommand *)pBase; ds@599: break; ds@599: } ds@599: pBase = const_cast(pBase->GetNext()); ds@599: } ds@599: ds@599: if (g_plugin_unload != NULL) ds@599: { ds@599: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); ds@599: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); ds@599: } ds@599: ds@599: extern ConVar metamod_version; ds@599: char buffer[255]; ds@599: ds@599: UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString()); ds@599: metamod_version.SetValue(buffer); ds@599: ds@599: g_bIsBridgedAsVsp = true; ds@599: g_pRealVspCallbacks = info->vsp_callbacks; ds@599: ds@599: g_PluginMngr.SetVSPAsLoaded(); ds@599: ds@599: return true; ds@599: } ds@599: ds@599: virtual void Unload() ds@599: { 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@599: } ds@599: g_SMConVarAccessor.UnloadMetamodCommands(); ds@599: UnloadMetamod(false); ds@599: } ds@599: ds@599: virtual const char *GetDescription() ds@599: { ds@599: return "Metamod:Source " MMS_FULL_VERSION; ds@599: } ds@599: }; ds@599: ds@599: VspBridge mm14_vsp_bridge; ds@599: ds@599: SMM_API IVspBridge * ds@599: GetVspBridge() ds@599: { ds@599: return &mm14_vsp_bridge; ds@599: }