|
dvander@608
|
1 |
/** |
|
dvander@608
|
2 |
* vim: set ts=4 : |
|
dvander@608
|
3 |
* ====================================================== |
|
dvander@608
|
4 |
* Metamod:Source |
|
dvander@608
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC and authors. |
|
dvander@608
|
6 |
* All rights reserved. |
|
dvander@608
|
7 |
* ====================================================== |
|
dvander@608
|
8 |
* |
|
dvander@608
|
9 |
* This software is provided 'as-is', without any express or implied warranty. |
|
dvander@608
|
10 |
* In no event will the authors be held liable for any damages arising from |
|
dvander@608
|
11 |
* the use of this software. |
|
dvander@608
|
12 |
* |
|
dvander@608
|
13 |
* Permission is granted to anyone to use this software for any purpose, |
|
dvander@608
|
14 |
* including commercial applications, and to alter it and redistribute it |
|
dvander@608
|
15 |
* freely, subject to the following restrictions: |
|
dvander@608
|
16 |
* |
|
dvander@608
|
17 |
* 1. The origin of this software must not be misrepresented; you must not |
|
dvander@608
|
18 |
* claim that you wrote the original software. If you use this software in a |
|
dvander@608
|
19 |
* product, an acknowledgment in the product documentation would be |
|
dvander@608
|
20 |
* appreciated but is not required. |
|
dvander@608
|
21 |
* 2. Altered source versions must be plainly marked as such, and must not be |
|
dvander@608
|
22 |
* misrepresented as being the original software. |
|
dvander@608
|
23 |
* 3. This notice may not be removed or altered from any source distribution. |
|
dvander@608
|
24 |
* |
|
dvander@608
|
25 |
* Version: $Id$ |
|
dvander@608
|
26 |
*/ |
|
dvander@608
|
27 |
|
|
ds@599
|
28 |
#include <assert.h> |
|
ds@599
|
29 |
#include "sourcemm.h" |
|
ds@599
|
30 |
#include "concommands.h" |
|
dvander@663
|
31 |
#include "util.h" |
|
ds@599
|
32 |
#include <loader_bridge.h> |
|
ds@599
|
33 |
|
|
ds@599
|
34 |
SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); |
|
ds@599
|
35 |
|
|
ds@599
|
36 |
ConCommand *g_plugin_unload = NULL; |
|
ds@599
|
37 |
bool g_bIsTryingToUnload; |
|
ds@599
|
38 |
bool g_bIsBridgedAsVsp; |
|
ds@599
|
39 |
|
|
ds@599
|
40 |
void InterceptPluginUnloads() |
|
ds@599
|
41 |
{ |
|
ds@599
|
42 |
g_bIsTryingToUnload = true; |
|
ds@599
|
43 |
} |
|
ds@599
|
44 |
|
|
ds@599
|
45 |
void InterceptPluginUnloads_Post() |
|
ds@599
|
46 |
{ |
|
ds@599
|
47 |
g_bIsTryingToUnload = false; |
|
ds@599
|
48 |
} |
|
ds@599
|
49 |
|
|
ds@599
|
50 |
class VspBridge : public IVspBridge |
|
ds@599
|
51 |
{ |
|
ds@599
|
52 |
virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) |
|
ds@599
|
53 |
{ |
|
ds@599
|
54 |
assert(!g_GameDll.loaded && !g_bIsBridgedAsVsp); |
|
ds@599
|
55 |
|
|
ds@599
|
56 |
CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory; |
|
ds@599
|
57 |
CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory; |
|
ds@599
|
58 |
|
|
ds@599
|
59 |
if (!AlternatelyLoadMetamod(engineFactory, gsFactory)) |
|
ds@599
|
60 |
return false; |
|
ds@599
|
61 |
|
|
ds@599
|
62 |
ConCommandBase *pBase = g_Engine.icvar->GetCommands(); |
|
ds@599
|
63 |
while (pBase != NULL) |
|
ds@599
|
64 |
{ |
|
ds@599
|
65 |
if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0) |
|
ds@599
|
66 |
{ |
|
ds@599
|
67 |
g_plugin_unload = (ConCommand *)pBase; |
|
ds@599
|
68 |
break; |
|
ds@599
|
69 |
} |
|
ds@599
|
70 |
pBase = const_cast<ConCommandBase *>(pBase->GetNext()); |
|
ds@599
|
71 |
} |
|
ds@599
|
72 |
|
|
ds@599
|
73 |
if (g_plugin_unload != NULL) |
|
ds@599
|
74 |
{ |
|
ds@599
|
75 |
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); |
|
ds@599
|
76 |
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); |
|
ds@599
|
77 |
} |
|
ds@599
|
78 |
|
|
ds@599
|
79 |
extern ConVar metamod_version; |
|
ds@599
|
80 |
char buffer[255]; |
|
ds@599
|
81 |
|
|
ds@599
|
82 |
UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString()); |
|
ds@599
|
83 |
metamod_version.SetValue(buffer); |
|
ds@599
|
84 |
|
|
ds@599
|
85 |
g_bIsBridgedAsVsp = true; |
|
ds@599
|
86 |
g_pRealVspCallbacks = info->vsp_callbacks; |
|
ds@599
|
87 |
|
|
ds@599
|
88 |
g_PluginMngr.SetVSPAsLoaded(); |
|
ds@599
|
89 |
|
|
ds@599
|
90 |
return true; |
|
ds@599
|
91 |
} |
|
ds@599
|
92 |
|
|
ds@599
|
93 |
virtual void Unload() |
|
ds@599
|
94 |
{ |
|
ds@576
|
95 |
if (g_bIsTryingToUnload) |
|
ds@576
|
96 |
{ |
|
ds@576
|
97 |
Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n"); |
|
ds@576
|
98 |
return; |
|
ds@576
|
99 |
} |
|
ds@576
|
100 |
if (g_plugin_unload != NULL) |
|
ds@576
|
101 |
{ |
|
ds@576
|
102 |
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); |
|
ds@576
|
103 |
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); |
|
ds@576
|
104 |
g_plugin_unload = NULL; |
|
ds@599
|
105 |
} |
|
ds@599
|
106 |
g_SMConVarAccessor.UnloadMetamodCommands(); |
|
ds@599
|
107 |
UnloadMetamod(false); |
|
ds@599
|
108 |
} |
|
ds@599
|
109 |
|
|
ds@599
|
110 |
virtual const char *GetDescription() |
|
ds@599
|
111 |
{ |
|
ds@599
|
112 |
return "Metamod:Source " MMS_FULL_VERSION; |
|
ds@599
|
113 |
} |
|
ds@599
|
114 |
}; |
|
ds@599
|
115 |
|
|
ds@599
|
116 |
VspBridge mm14_vsp_bridge; |
|
ds@599
|
117 |
|
|
ds@599
|
118 |
SMM_API IVspBridge * |
|
ds@599
|
119 |
GetVspBridge() |
|
ds@599
|
120 |
{ |
|
ds@599
|
121 |
return &mm14_vsp_bridge; |
|
ds@599
|
122 |
} |