Initial import of gameinfo loader.
6 #include <sh_memfuncinfo.h>
8 #include "serverplugin.h"
19 eQueryCvarValueStatus_ValueIntact=0,
20 eQueryCvarValueStatus_CvarNotFound=1,
21 eQueryCvarValueStatus_NotACvar=2,
22 eQueryCvarValueStatus_CvarProtected=3
23 } EQueryCvarValueStatus;
25 typedef int QueryCvarCookie_t;
27 class IServerPluginCallbacks;
31 #define LIBRARY_EXT ".dll"
33 #define LIBRARY_EXT "_i486.so"
39 virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity, const CCommand& args)
41 return PLUGIN_CONTINUE;
45 IVspBridge *vsp_bridge = NULL;
48 * The vtable must match the general layout for ISPC. We modify the vtable
49 * based on what we get back.
53 unsigned int vsp_version;
60 virtual bool Load(QueryValveInterface engineFactory, QueryValveInterface gsFactory)
67 MetamodBackend backend = mm_DetermineBackend(engineFactory);
69 if (backend == MMBackend_UNKNOWN)
71 mm_LogFatal("Could not detect engine version");
74 else if (backend >= MMBackend_Episode2)
76 /* We need to insert the right type of call into this vtable */
80 SourceHook::MemFuncInfo mfp_dest, mfp_src;
82 mfp_dest.isVirtual = false;
83 mfp_src.isVirtual = false;
85 SourceHook::GetFuncInfo(&ServerPlugin::ClientCommand, mfp_dest);
86 SourceHook::GetFuncInfo(&IRandomThings::ClientCommand, mfp_src);
88 assert(mfp_dest.isVirtual);
89 assert(mfp_dest.thisptroffs == 0);
90 assert(mfp_dest.vtbloffs == 0);
91 assert(mfp_src.isVirtual);
92 assert(mfp_src.thisptroffs == 0);
93 assert(mfp_src.vtbloffs == 0);
95 vtable_src = (void **)*(void **)&sample;
96 vtable_dest = (void **)*(void **)this;
97 SourceHook::SetMemAccess(&vtable_dest[mfp_dest.vtblindex],
99 SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
100 vtable_dest[mfp_dest.vtblindex] = vtable_src[mfp_src.vtblindex];
104 if (!mm_LoadMetamodLibrary(backend, error, sizeof(error)))
106 mm_LogFatal("Detected engine %d but could not load: %s", backend, error);
110 typedef IVspBridge *(*GetVspBridge)();
111 GetVspBridge get_bridge = (GetVspBridge)mm_GetProcAddress("GetVspBridge");
112 if (get_bridge == NULL)
114 mm_UnloadMetamodLibrary();
115 mm_LogFatal("Detected engine %d but could not find GetVspBridge callback", backend);
119 vsp_bridge = get_bridge();
121 vsp_bridge_info info;
123 info.engineFactory = engineFactory;
124 info.gsFactory = gsFactory;
125 info.vsp_callbacks = (IServerPluginCallbacks*)this;
126 info.vsp_version = vsp_version;
128 strcpy(error, "Unknown error");
129 if (!vsp_bridge->Load(&info, error, sizeof(error)))
132 mm_UnloadMetamodLibrary();
133 mm_LogFatal("Unknown error loading Metamod for engine %d: %s", backend, error);
139 virtual void Unload()
141 if (vsp_bridge == NULL)
143 vsp_bridge->Unload();
144 mm_UnloadMetamodLibrary();
149 virtual void UnPause()
152 virtual const char *GetPluginDescription()
154 if (vsp_bridge == NULL)
155 return "Metamod:Source Loader Shim";
156 return vsp_bridge->GetDescription();
158 virtual void LevelInit(char const *pMapName)
161 virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
164 virtual void GameFrame(bool simulating)
167 virtual void LevelShutdown()
170 virtual void ClientActive(edict_t *pEntity)
173 virtual void ClientDisconnect(edict_t *pEntity)
176 virtual void ClientPutInServer(edict_t *pEntity, char const *playername)
179 virtual void SetCommandClient(int index)
182 virtual void ClientSettingsChanged(edict_t *pEdict)
185 virtual PLUGIN_RESULT ClientConnect(bool *bAllowConnect,
188 const char *pszAddress,
192 return PLUGIN_CONTINUE;
194 virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity)
196 return PLUGIN_CONTINUE;
198 virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID)
200 return PLUGIN_CONTINUE;
202 virtual void OnQueryCvarValueFinished(QueryCvarCookie_t iCookie,
203 edict_t *pPlayerEntity,
204 EQueryCvarValueStatus eStatus,
205 const char *pCvarName,
206 const char *pCvarValue)
209 void PrepForLoad(unsigned int version)
211 vsp_version = version;
216 ServerPlugin mm_vsp_callbacks;
218 void *mm_GetVspCallbacks(unsigned int version)
220 if (vsp_bridge != NULL)
223 /* Only support versions 1 or 2 right now */
227 mm_vsp_callbacks.PrepForLoad(version);
229 return &mm_vsp_callbacks;