mirror of
https://github.com/rehlds/metamod-r.git
synced 2025-01-27 22:17:54 +03:00
Update stub plugin
This commit is contained in:
parent
3af38129f4
commit
0c99300d8d
@ -7,7 +7,7 @@ const RehldsFuncs_t* g_RehldsFuncs;
|
|||||||
IRehldsHookchains* g_RehldsHookchains;
|
IRehldsHookchains* g_RehldsHookchains;
|
||||||
IRehldsServerStatic* g_RehldsSvs;
|
IRehldsServerStatic* g_RehldsSvs;
|
||||||
|
|
||||||
bool rehlds_api_try_init(CSysModule* engineModule, char* failureReason)
|
bool rehlds_api_init(CSysModule* engineModule)
|
||||||
{
|
{
|
||||||
if (!engineModule) {
|
if (!engineModule) {
|
||||||
gpMetaUtilFuncs->pfnLogConsole(PLID, "Failed to locate engine module\n");
|
gpMetaUtilFuncs->pfnLogConsole(PLID, "Failed to locate engine module\n");
|
||||||
@ -16,14 +16,13 @@ bool rehlds_api_try_init(CSysModule* engineModule, char* failureReason)
|
|||||||
|
|
||||||
CreateInterfaceFn ifaceFactory = Sys_GetFactory(engineModule);
|
CreateInterfaceFn ifaceFactory = Sys_GetFactory(engineModule);
|
||||||
if (!ifaceFactory) {
|
if (!ifaceFactory) {
|
||||||
sprintf(failureReason, "Failed to locate interface factory in engine module\n");
|
gpMetaUtilFuncs->pfnLogConsole(PLID, "Failed to locate interface factory in engine module\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int retCode = 0;
|
int retCode = 0;
|
||||||
g_RehldsApi = (IRehldsApi*)ifaceFactory(VREHLDS_HLDS_API_VERSION, &retCode);
|
g_RehldsApi = (IRehldsApi*)ifaceFactory(VREHLDS_HLDS_API_VERSION, &retCode);
|
||||||
if (!g_RehldsApi) {
|
if (!g_RehldsApi) {
|
||||||
sprintf(failureReason, "Failed to locate retrieve rehlds api interface from engine module, return code is %d\n", retCode);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,12 +30,12 @@ bool rehlds_api_try_init(CSysModule* engineModule, char* failureReason)
|
|||||||
int minorVersion = g_RehldsApi->GetMinorVersion();
|
int minorVersion = g_RehldsApi->GetMinorVersion();
|
||||||
|
|
||||||
if (majorVersion != REHLDS_API_VERSION_MAJOR) {
|
if (majorVersion != REHLDS_API_VERSION_MAJOR) {
|
||||||
sprintf(failureReason, "REHLDS Api major version mismatch; expected %d, real %d\n", REHLDS_API_VERSION_MAJOR, majorVersion);
|
gpMetaUtilFuncs->pfnLogConsole(PLID, "REHLDS Api major version mismatch; expected %d, real %d\n", REHLDS_API_VERSION_MAJOR, majorVersion);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minorVersion < REHLDS_API_VERSION_MINOR) {
|
if (minorVersion < REHLDS_API_VERSION_MINOR) {
|
||||||
sprintf(failureReason, "REHLDS Api minor version mismatch; expected at least %d, real %d\n", REHLDS_API_VERSION_MINOR, minorVersion);
|
gpMetaUtilFuncs->pfnLogConsole(PLID, "REHLDS Api minor version mismatch; expected at least %d, real %d\n", REHLDS_API_VERSION_MINOR, minorVersion);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,25 +46,31 @@ bool rehlds_api_try_init(CSysModule* engineModule, char* failureReason)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool meta_init_rehlds_api() {
|
bool meta_init_rehlds_api()
|
||||||
char failReason[2048];
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Find the most appropriate module handle from a list of DLL candidates
|
||||||
|
// Notes:
|
||||||
|
// - "swds.dll" is the library Dedicated Server
|
||||||
|
//
|
||||||
|
// Let's also attempt to locate the ReHLDS API in the client's library
|
||||||
|
// - "sw.dll" is the client library for Software render, with a built-in listenserver
|
||||||
|
// - "hw.dll" is the client library for Hardware render, with a built-in listenserver
|
||||||
|
const char *dllNames[] = { "swds.dll", "hw.dll", "sw.dll" }; // List of DLL candidates to lookup for the ReHLDS API
|
||||||
|
CSysModule *engineModule = NULL; // The module handle of the selected DLL
|
||||||
|
for (const char *dllName : dllNames)
|
||||||
|
{
|
||||||
|
if (engineModule = Sys_GetModuleHandle(dllName))
|
||||||
|
break; // gotcha
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
CSysModule* engineModule = Sys_LoadModule("swds.dll");
|
|
||||||
if (!rehlds_api_try_init(engineModule, failReason)) {
|
|
||||||
engineModule = Sys_LoadModule("filesystem_stdio.dll");
|
|
||||||
if (!rehlds_api_try_init(engineModule, failReason)) {
|
|
||||||
gpMetaUtilFuncs->pfnLogConsole(PLID, "%s", failReason);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
CSysModule* engineModule = Sys_LoadModule("engine_i486.so");
|
CSysModule *engineModule = Sys_GetModuleHandle("engine_i486.so");
|
||||||
if (!rehlds_api_try_init(engineModule, failReason)) {
|
#endif
|
||||||
gpMetaUtilFuncs->pfnLogConsole(PLID, "%s", failReason);
|
|
||||||
|
if (!rehlds_api_init(engineModule)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,14 @@ void *Sys_GetProcAddress(void *pModuleHandle, const char *pName)
|
|||||||
return GetProcAddress((HMODULE)pModuleHandle, pName);
|
return GetProcAddress((HMODULE)pModuleHandle, pName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Purpose: Returns a module handle by its name.
|
||||||
|
// Input : pModuleName - module name
|
||||||
|
// Output : the module handle or NULL in case of an error
|
||||||
|
CSysModule *Sys_GetModuleHandle(const char *pModuleName)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<CSysModule *>(GetModuleHandle(pModuleName));
|
||||||
|
}
|
||||||
|
|
||||||
// Purpose: Loads a DLL/component from disk and returns a handle to it
|
// Purpose: Loads a DLL/component from disk and returns a handle to it
|
||||||
// Input : *pModuleName - filename of the component
|
// Input : *pModuleName - filename of the component
|
||||||
// Output : opaque handle to the module (hides system dependency)
|
// Output : opaque handle to the module (hides system dependency)
|
||||||
|
@ -114,6 +114,8 @@ extern CreateInterfaceFn Sys_GetFactory(const char *pModuleName);
|
|||||||
// load/unload components
|
// load/unload components
|
||||||
class CSysModule;
|
class CSysModule;
|
||||||
|
|
||||||
|
extern CSysModule *Sys_GetModuleHandle(const char *pModuleName);
|
||||||
|
|
||||||
// Load & Unload should be called in exactly one place for each module
|
// Load & Unload should be called in exactly one place for each module
|
||||||
// The factory for that module should be passed on to dependent components for
|
// The factory for that module should be passed on to dependent components for
|
||||||
// proper versioning.
|
// proper versioning.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user