2008-11-26 07:19:30 +01:00
|
|
|
/**
|
2009-11-23 06:54:55 +01:00
|
|
|
* vim: set ts=4 sw=4 tw=99 noet :
|
2008-11-26 07:19:30 +01:00
|
|
|
* ======================================================
|
|
|
|
* Metamod:Source
|
2009-11-23 06:54:55 +01:00
|
|
|
* Copyright (C) 2004-2009 AlliedModders LLC and authors.
|
2008-11-26 07:19:30 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-11-24 10:50:12 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include "sourcemm.h"
|
|
|
|
#include "concommands.h"
|
2009-10-29 07:37:52 +01:00
|
|
|
#include "util.h"
|
2008-11-24 10:50:12 +01:00
|
|
|
#include <loader_bridge.h>
|
2013-11-24 04:10:27 +01:00
|
|
|
#include <sh_string.h>
|
|
|
|
#include <versionlib.h>
|
2008-11-24 10:50:12 +01:00
|
|
|
|
|
|
|
SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
|
|
|
|
|
|
|
ConCommand *g_plugin_unload = NULL;
|
|
|
|
bool g_bIsTryingToUnload;
|
|
|
|
bool g_bIsBridgedAsVsp;
|
2013-11-24 04:10:27 +01:00
|
|
|
SourceHook::String vsp_desc("Metamod:Source");
|
2008-11-24 10:50:12 +01:00
|
|
|
|
|
|
|
void InterceptPluginUnloads()
|
|
|
|
{
|
|
|
|
g_bIsTryingToUnload = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterceptPluginUnloads_Post()
|
|
|
|
{
|
|
|
|
g_bIsTryingToUnload = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
class VspBridge : public IVspBridge
|
|
|
|
{
|
|
|
|
virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
|
|
|
|
{
|
2009-11-23 06:54:55 +01:00
|
|
|
assert(!g_bIsBridgedAsVsp);
|
|
|
|
|
|
|
|
if (!g_GameDll.loaded)
|
|
|
|
{
|
2013-11-24 04:10:27 +01:00
|
|
|
vsp_desc.append(" ");
|
|
|
|
vsp_desc.append(METAMOD_VERSION);
|
|
|
|
|
2009-11-23 06:54:55 +01:00
|
|
|
CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory;
|
|
|
|
CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory;
|
2008-11-24 10:50:12 +01:00
|
|
|
|
2009-11-23 06:54:55 +01:00
|
|
|
if (!AlternatelyLoadMetamod(engineFactory, gsFactory))
|
|
|
|
return false;
|
2008-11-24 10:50:12 +01:00
|
|
|
|
2009-11-23 06:54:55 +01:00
|
|
|
extern ConVar metamod_version;
|
|
|
|
char buffer[255];
|
|
|
|
|
|
|
|
UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString());
|
|
|
|
metamod_version.SetValue(buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-24 04:10:27 +01:00
|
|
|
vsp_desc.append(" Interface ");
|
|
|
|
vsp_desc.append(METAMOD_VERSION);
|
2009-11-23 06:54:55 +01:00
|
|
|
}
|
2008-11-24 10:50:12 +01:00
|
|
|
|
|
|
|
ConCommandBase *pBase = g_Engine.icvar->GetCommands();
|
|
|
|
while (pBase != NULL)
|
|
|
|
{
|
|
|
|
if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0)
|
|
|
|
{
|
|
|
|
g_plugin_unload = (ConCommand *)pBase;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pBase = const_cast<ConCommandBase *>(pBase->GetNext());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_plugin_unload != NULL)
|
|
|
|
{
|
|
|
|
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
|
|
|
|
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_bIsBridgedAsVsp = true;
|
|
|
|
g_pRealVspCallbacks = info->vsp_callbacks;
|
2009-10-29 08:52:39 +01:00
|
|
|
g_vsp_version = info->vsp_version;
|
2008-11-24 10:50:12 +01:00
|
|
|
|
|
|
|
g_PluginMngr.SetVSPAsLoaded();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Unload()
|
|
|
|
{
|
2008-11-18 14:20:38 +01:00
|
|
|
if (g_bIsTryingToUnload)
|
|
|
|
{
|
|
|
|
Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (g_plugin_unload != NULL)
|
|
|
|
{
|
|
|
|
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
|
|
|
|
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
|
|
|
|
g_plugin_unload = NULL;
|
2008-11-24 10:50:12 +01:00
|
|
|
}
|
2009-11-23 06:54:55 +01:00
|
|
|
if (!g_GameDll.loaded)
|
|
|
|
{
|
|
|
|
g_SMConVarAccessor.UnloadMetamodCommands();
|
|
|
|
UnloadMetamod(false);
|
|
|
|
}
|
2008-11-24 10:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual const char *GetDescription()
|
|
|
|
{
|
2013-11-24 04:10:27 +01:00
|
|
|
return vsp_desc.c_str();
|
2008-11-24 10:50:12 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
VspBridge mm14_vsp_bridge;
|
|
|
|
|
|
|
|
SMM_API IVspBridge *
|
|
|
|
GetVspBridge()
|
|
|
|
{
|
|
|
|
return &mm14_vsp_bridge;
|
|
|
|
}
|