Replace internal ILibrary use with ke::SharedLib.

This commit is contained in:
David Anderson 2015-08-27 14:09:42 -04:00
parent 5ecd906905
commit ec01ca72a0
3 changed files with 25 additions and 28 deletions

View File

@ -38,7 +38,7 @@
#include <IGameConfigs.h>
#include <compat_wrappers.h>
#include <Logger.h>
#include "LibrarySys.h"
#include <amtl/os/am-shared-library.h>
#include "logic_bridge.h"
#include <tier0/mem.h>
@ -239,32 +239,30 @@ void CHalfLife2::InitCommandLine()
#if SOURCE_ENGINE != SE_DARKMESSIAH
if (!is_original_engine)
{
ke::AutoPtr<ILibrary> lib(g_LibSys.OpenLibrary(TIER0_NAME, error, sizeof(error)));
if (lib == NULL)
{
ke::Ref<ke::SharedLib> lib = ke::SharedLib::Open(TIER0_NAME, error, sizeof(error));
if (!lib) {
logger->LogError("Could not load %s: %s", TIER0_NAME, error);
return;
}
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine_Tier0");
m_pGetCommandLine = lib->get<decltype(m_pGetCommandLine)>("CommandLine_Tier0");
/* '_Tier0' dropped on Alien Swarm version */
if (m_pGetCommandLine == NULL)
{
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine");
m_pGetCommandLine = lib->get<decltype(m_pGetCommandLine)>("CommandLine");
}
}
else
#endif
{
ke::AutoPtr<ILibrary> lib(g_LibSys.OpenLibrary(VSTDLIB_NAME, error, sizeof(error)));
if (lib == NULL)
{
ke::Ref<ke::SharedLib> lib = ke::SharedLib::Open(VSTDLIB_NAME, error, sizeof(error));
if (!lib) {
logger->LogError("Could not load %s: %s", VSTDLIB_NAME, error);
return;
}
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine");
m_pGetCommandLine = lib->get<decltype(m_pGetCommandLine)>("CommandLine");
}
if (m_pGetCommandLine == NULL)

View File

@ -58,6 +58,7 @@
#else
#include "convar_sm.h"
#endif
#include <amtl/os/am-shared-library.h>
#if defined _WIN32
#define MATCHMAKINGDS_SUFFIX ""
@ -74,7 +75,7 @@
#define MATCHMAKINGDS_EXT "so"
#endif
static ILibrary *g_pLogic = NULL;
static ke::Ref<ke::SharedLib> g_Logic;
static LogicInitFunction logic_init_fn;
IThreader *g_pThreader;
@ -650,15 +651,14 @@ void InitLogicBridge()
core_bridge.serverFactory = (void *)g_SMAPI->GetServerFactory(false);
core_bridge.listeners = SMGlobalClass::head;
ILibrary *mmlib;
char path[PLATFORM_MAX_PATH];
g_LibSys.PathFormat(path, sizeof(path), "%s/bin/matchmaking_ds%s.%s", g_SMAPI->GetBaseDir(), MATCHMAKINGDS_SUFFIX, MATCHMAKINGDS_EXT);
if ((mmlib = g_LibSys.OpenLibrary(path, NULL, 0)))
if (ke::Ref<ke::SharedLib> mmlib = ke::SharedLib::Open(path, NULL, 0))
{
core_bridge.matchmakingDSFactory = mmlib->GetSymbolAddress("CreateInterface");
mmlib->CloseLibrary();
core_bridge.matchmakingDSFactory =
mmlib->get<decltype(core_bridge.matchmakingDSFactory)>("CreateInterface");
}
logic_init_fn(&core_bridge, &logicore);
@ -695,9 +695,8 @@ bool StartLogicBridge(char *error, size_t maxlength)
g_SourceMod.GetSourceModPath());
char myerror[255];
g_pLogic = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
if (!g_pLogic)
g_Logic = ke::SharedLib::Open(file, myerror, sizeof(myerror));
if (!g_Logic)
{
if (error && maxlength)
{
@ -706,10 +705,10 @@ bool StartLogicBridge(char *error, size_t maxlength)
return false;
}
LogicLoadFunction llf = (LogicLoadFunction)g_pLogic->GetSymbolAddress("logic_load");
LogicLoadFunction llf = g_Logic->get<decltype(llf)>("logic_load");
if (llf == NULL)
{
g_pLogic->CloseLibrary();
g_Logic = nullptr;
if (error && maxlength)
{
UTIL_Format(error, maxlength, "could not find logic_load function");
@ -717,7 +716,7 @@ bool StartLogicBridge(char *error, size_t maxlength)
return false;
}
GetITextParsers getitxt = (GetITextParsers)g_pLogic->GetSymbolAddress("get_textparsers");
GetITextParsers getitxt = g_Logic->get<decltype(getitxt)>("get_textparsers");
textparsers = getitxt();
logic_init_fn = llf(SM_LOGIC_MAGIC);
@ -727,6 +726,6 @@ bool StartLogicBridge(char *error, size_t maxlength)
void ShutdownLogicBridge()
{
g_pLogic->CloseLibrary();
g_Logic = nullptr;
}

View File

@ -42,6 +42,7 @@
#include <IGameConfigs.h>
#include "frame_hooks.h"
#include "logic_bridge.h"
#include <amtl/os/am-shared-library.h>
SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
@ -50,7 +51,7 @@ SH_DECL_HOOK1_void(IVEngineServer, ServerCommand, SH_NOATTRIB, false, const char
SourceModBase g_SourceMod;
ILibrary *g_pJIT = NULL;
ke::Ref<ke::SharedLib> g_JIT;
SourceHook::String g_BaseDir;
ISourcePawnEngine *g_pSourcePawn = NULL;
ISourcePawnEngine2 *g_pSourcePawn2 = NULL;
@ -79,8 +80,7 @@ void ShutdownJIT()
g_pSourcePawn = NULL;
}
g_pJIT->CloseLibrary();
g_pJIT = NULL;
g_JIT = nullptr;
}
SourceModBase::SourceModBase()
@ -183,8 +183,8 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
PLATFORM_LIB_EXT
);
g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
if (!g_pJIT)
g_JIT = ke::SharedLib::Open(file, myerror, sizeof(myerror));
if (!g_JIT)
{
if (error && maxlength)
{
@ -196,7 +196,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
}
GetSourcePawnFactoryFn factoryFn =
(GetSourcePawnFactoryFn)g_pJIT->GetSymbolAddress("GetSourcePawnFactory");
g_JIT->get<decltype(factoryFn)>("GetSourcePawnFactory");
if (!factoryFn) {
if (error && maxlength)