|
ds@576
|
1 |
#include "metamod.h" |
|
ds@576
|
2 |
#include "metamod_util.h" |
|
ds@576
|
3 |
#include <interface.h> |
|
ds@576
|
4 |
#include <eiface.h> |
|
ds@576
|
5 |
#include <iplayerinfo.h> |
|
ds@576
|
6 |
#include <assert.h> |
|
ds@576
|
7 |
#include <loader_bridge.h> |
|
ds@576
|
8 |
#include "provider/provider_ep2.h" |
|
ds@576
|
9 |
|
|
ds@576
|
10 |
SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); |
|
ds@576
|
11 |
|
|
ds@576
|
12 |
ConCommand *g_plugin_unload = NULL; |
|
ds@576
|
13 |
bool g_bIsTryingToUnload; |
|
ds@576
|
14 |
|
|
ds@576
|
15 |
void InterceptPluginUnloads(const CCommand &args) |
|
ds@576
|
16 |
{ |
|
ds@576
|
17 |
g_bIsTryingToUnload = true; |
|
ds@576
|
18 |
} |
|
ds@576
|
19 |
|
|
ds@576
|
20 |
void InterceptPluginUnloads_Post(const CCommand &args) |
|
ds@576
|
21 |
{ |
|
ds@576
|
22 |
g_bIsTryingToUnload = false; |
|
ds@576
|
23 |
} |
|
ds@576
|
24 |
|
|
ds@576
|
25 |
class VspBridge : public IVspBridge |
|
ds@576
|
26 |
{ |
|
ds@576
|
27 |
public: |
|
ds@576
|
28 |
virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) |
|
ds@576
|
29 |
{ |
|
ds@576
|
30 |
assert(!g_Metamod.IsLoadedAsGameDLL()); |
|
ds@576
|
31 |
|
|
ds@576
|
32 |
CGlobalVars *pGlobals; |
|
ds@576
|
33 |
IPlayerInfoManager *playerInfoManager; |
|
ds@576
|
34 |
|
|
ds@576
|
35 |
playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL); |
|
ds@576
|
36 |
if (playerInfoManager == NULL) |
|
ds@576
|
37 |
{ |
|
ds@576
|
38 |
UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game"); |
|
ds@576
|
39 |
return false; |
|
ds@576
|
40 |
} |
|
ds@576
|
41 |
|
|
ds@576
|
42 |
pGlobals = playerInfoManager->GetGlobalVars(); |
|
ds@576
|
43 |
|
|
ds@576
|
44 |
char gamedll_iface[] = "ServerGameDLL000"; |
|
ds@576
|
45 |
for (unsigned int i = 5; i <= 50; i++) |
|
ds@576
|
46 |
{ |
|
ds@576
|
47 |
gamedll_iface[15] = '0' + i; |
|
ds@576
|
48 |
if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL) |
|
ds@576
|
49 |
{ |
|
dvander@589
|
50 |
g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false); |
|
ds@576
|
51 |
break; |
|
ds@576
|
52 |
} |
|
ds@576
|
53 |
} |
|
ds@576
|
54 |
|
|
ds@576
|
55 |
if (server == NULL) |
|
ds@576
|
56 |
{ |
|
ds@576
|
57 |
UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible)."); |
|
ds@576
|
58 |
return false; |
|
ds@576
|
59 |
} |
|
ds@576
|
60 |
|
|
ds@576
|
61 |
char gameclients_iface[] = "ServerGameClients000"; |
|
ds@576
|
62 |
for (unsigned int i = 3; i <= 4; i++) |
|
ds@576
|
63 |
{ |
|
ds@576
|
64 |
gameclients_iface[19] = '0' + i; |
|
ds@576
|
65 |
if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL) |
|
ds@576
|
66 |
break; |
|
ds@576
|
67 |
} |
|
ds@576
|
68 |
|
|
ds@576
|
69 |
if (!mm_DetectGameInformation()) |
|
ds@576
|
70 |
{ |
|
ds@576
|
71 |
UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load."); |
|
ds@576
|
72 |
return false; |
|
ds@576
|
73 |
} |
|
ds@576
|
74 |
|
|
ds@576
|
75 |
mm_InitializeForLoad(); |
|
ds@576
|
76 |
mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory, |
|
ds@576
|
77 |
(CreateInterfaceFn)info->engineFactory, |
|
ds@576
|
78 |
(CreateInterfaceFn)info->engineFactory, |
|
ds@576
|
79 |
pGlobals); |
|
dvander@592
|
80 |
g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version); |
|
ds@576
|
81 |
mm_StartupMetamod(true); |
|
ds@576
|
82 |
|
|
ds@576
|
83 |
g_plugin_unload = icvar->FindCommand("plugin_unload"); |
|
ds@576
|
84 |
|
|
ds@576
|
85 |
if (g_plugin_unload != NULL) |
|
ds@576
|
86 |
{ |
|
ds@576
|
87 |
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); |
|
ds@576
|
88 |
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); |
|
ds@576
|
89 |
} |
|
ds@576
|
90 |
|
|
ds@576
|
91 |
return true; |
|
ds@576
|
92 |
} |
|
ds@576
|
93 |
|
|
ds@576
|
94 |
virtual void Unload() |
|
ds@576
|
95 |
{ |
|
ds@576
|
96 |
if (g_bIsTryingToUnload) |
|
ds@576
|
97 |
{ |
|
ds@576
|
98 |
Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n"); |
|
ds@576
|
99 |
return; |
|
ds@576
|
100 |
} |
|
ds@576
|
101 |
if (g_plugin_unload != NULL) |
|
ds@576
|
102 |
{ |
|
ds@576
|
103 |
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); |
|
ds@576
|
104 |
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); |
|
ds@576
|
105 |
g_plugin_unload = NULL; |
|
ds@576
|
106 |
} |
|
ds@576
|
107 |
mm_UnloadMetamod(); |
|
ds@576
|
108 |
} |
|
ds@576
|
109 |
|
|
ds@576
|
110 |
virtual const char *GetDescription() |
|
ds@576
|
111 |
{ |
|
ds@599
|
112 |
return "Metamod:Source " MMS_FULL_VERSION; |
|
ds@576
|
113 |
} |
|
ds@576
|
114 |
}; |
|
ds@576
|
115 |
|
|
ds@576
|
116 |
VspBridge mm16_vsp_bridge; |
|
ds@576
|
117 |
|
|
ds@576
|
118 |
SMM_API IVspBridge * |
|
ds@576
|
119 |
GetVspBridge() |
|
ds@576
|
120 |
{ |
|
ds@576
|
121 |
return &mm16_vsp_bridge; |
|
ds@576
|
122 |
} |
|
ds@576
|
123 |
|