Added better cross-engine support for finding Valve commandline (bug 5216, r=asherkin).

This commit is contained in:
Nicholas Hastings 2012-02-25 15:09:56 -05:00
parent 545868da38
commit 4669c320f6
4 changed files with 97 additions and 3 deletions

View File

@ -38,8 +38,20 @@
#include <IGameConfigs.h> #include <IGameConfigs.h>
#include <compat_wrappers.h> #include <compat_wrappers.h>
#include <Logger.h> #include <Logger.h>
#include "LibrarySys.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#if defined _WIN32
#define TIER0_NAME "tier0.dll"
#define VSTDLIB_NAME "vstdlib.dll"
#elif defined __APPLE__
#define TIER0_NAME "libtier0.dylib"
#define VSTDLIB_NAME "libvstdlib.dylib"
#elif defined __linux__
#define TIER0_NAME LIB_PREFIX "tier0" LIB_SUFFIX
#define VSTDLIB_NAME LIB_PREFIX "vstdlib" LIB_SUFFIX
#endif
CHalfLife2 g_HL2; CHalfLife2 g_HL2;
ConVar *sv_lan = NULL; ConVar *sv_lan = NULL;
@ -131,6 +143,12 @@ void CHalfLife2::OnSourceModAllInitialized()
} }
void CHalfLife2::OnSourceModAllInitialized_Post() void CHalfLife2::OnSourceModAllInitialized_Post()
{
InitLogicalEntData();
InitCommandLine();
}
void CHalfLife2::InitLogicalEntData()
{ {
char *addr = NULL; char *addr = NULL;
@ -196,6 +214,64 @@ void CHalfLife2::OnSourceModAllInitialized_Post()
} }
} }
void CHalfLife2::InitCommandLine()
{
char path[PLATFORM_MAX_PATH];
char error[256];
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "../bin/" TIER0_NAME);
if (!g_LibSys.IsPathFile(path))
{
g_Logger.LogError("Could not find path for: " TIER0_NAME);
return;
}
ILibrary *lib = g_LibSys.OpenLibrary(path, error, sizeof(error));
m_pGetCommandLine = (GetCommandLine)lib->GetSymbolAddress("CommandLine_Tier0");
/* '_Tier0' dropped on Alien Swarm version */
if (m_pGetCommandLine == NULL)
{
m_pGetCommandLine = (GetCommandLine)lib->GetSymbolAddress("CommandLine");
}
if (m_pGetCommandLine == NULL)
{
/* We probably have a Ship engine. */
lib->CloseLibrary();
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "../bin/" VSTDLIB_NAME);
if (!g_LibSys.IsPathFile(path))
{
g_Logger.LogError("Could not find path for: " VSTDLIB_NAME);
return;
}
if ((lib = g_LibSys.OpenLibrary(path, error, sizeof(error))) == NULL)
{
g_Logger.LogError("Could not load %s: %s", path, error);
return;
}
m_pGetCommandLine = (GetCommandLine)lib->GetSymbolAddress("CommandLine");
if (m_pGetCommandLine == NULL)
{
g_Logger.LogError("Could not locate any command line functionality");
}
lib->CloseLibrary();
}
}
ICommandLine *CHalfLife2::GetValveCommandLine()
{
if (!m_pGetCommandLine)
return NULL;
return m_pGetCommandLine();
}
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11 #if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
bool CHalfLife2::IsOriginalEngine() bool CHalfLife2::IsOriginalEngine()
{ {

View File

@ -44,6 +44,11 @@
#include <server_class.h> #include <server_class.h>
#include <datamap.h> #include <datamap.h>
#include <ihandleentity.h> #include <ihandleentity.h>
#include <tier0\icommandline.h>
#undef GetCommandLine
typedef ICommandLine *(*GetCommandLine)();
class CCommand; class CCommand;
@ -136,6 +141,7 @@ public: //IGameHelpers
cell_t EntityToBCompatRef(CBaseEntity *pEntity); cell_t EntityToBCompatRef(CBaseEntity *pEntity);
void *GetGlobalEntityList(); void *GetGlobalEntityList();
int GetSendPropOffset(SendProp *prop); int GetSendPropOffset(SendProp *prop);
ICommandLine *GetValveCommandLine();
public: public:
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd); void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
void ProcessFakeCliCmdQueue(); void ProcessFakeCliCmdQueue();
@ -151,6 +157,9 @@ public:
#endif #endif
private: private:
DataTableInfo *_FindServerClass(const char *classname); DataTableInfo *_FindServerClass(const char *classname);
private:
void InitLogicalEntData();
void InitCommandLine();
private: private:
Trie *m_pClasses; Trie *m_pClasses;
List<DataTableInfo *> m_Tables; List<DataTableInfo *> m_Tables;
@ -163,6 +172,7 @@ private:
CStack<DelayedFakeCliCmd *> m_FreeCmds; CStack<DelayedFakeCliCmd *> m_FreeCmds;
CStack<CachedCommandInfo> m_CommandStack; CStack<CachedCommandInfo> m_CommandStack;
Queue<DelayedKickInfo> m_DelayedKicks; Queue<DelayedKickInfo> m_DelayedKicks;
GetCommandLine m_pGetCommandLine;
}; };
extern CHalfLife2 g_HL2; extern CHalfLife2 g_HL2;

View File

@ -44,7 +44,6 @@
#include "HalfLife2.h" #include "HalfLife2.h"
#include <inetchannel.h> #include <inetchannel.h>
#include <iclient.h> #include <iclient.h>
#include <tier0/icommandline.h>
#include <IGameConfigs.h> #include <IGameConfigs.h>
#include "ExtensionSys.h" #include "ExtensionSys.h"
#include <sourcemod_version.h> #include <sourcemod_version.h>
@ -244,7 +243,8 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl
// clientMax will not necessarily be correct here (such as on late SourceTV enable) // clientMax will not necessarily be correct here (such as on late SourceTV enable)
m_maxClients = gpGlobals->maxClients; m_maxClients = gpGlobals->maxClients;
m_bIsSourceTVActive = (tv_enable && tv_enable->GetBool() && CommandLine()->FindParm("-nohltv") == 0); ICommandLine *commandLine = g_HL2.GetValveCommandLine();
m_bIsSourceTVActive = (tv_enable && tv_enable->GetBool() && (!commandLine || commandLine->FindParm("-nohltv") == 0));
m_bIsReplayActive = false; m_bIsReplayActive = false;
#if SOURCE_ENGINE == SE_ORANGEBOXVALVE #if SOURCE_ENGINE == SE_ORANGEBOXVALVE
m_bIsReplayActive = (replay_enable && replay_enable->GetBool()); m_bIsReplayActive = (replay_enable && replay_enable->GetBool());

View File

@ -40,12 +40,13 @@
*/ */
#define SMINTERFACE_GAMEHELPERS_NAME "IGameHelpers" #define SMINTERFACE_GAMEHELPERS_NAME "IGameHelpers"
#define SMINTERFACE_GAMEHELPERS_VERSION 7 #define SMINTERFACE_GAMEHELPERS_VERSION 8
class CBaseEntity; class CBaseEntity;
class CBaseHandle; class CBaseHandle;
class SendProp; class SendProp;
class ServerClass; class ServerClass;
class ICommandLine;
struct edict_t; struct edict_t;
struct datamap_t; struct datamap_t;
struct typedescription_t; struct typedescription_t;
@ -284,6 +285,13 @@ namespace SourceMod
* @return True on success, false on failure. * @return True on success, false on failure.
*/ */
virtual bool HintTextMsg(int client, const char *msg) =0; virtual bool HintTextMsg(int client, const char *msg) =0;
/**
* @brief Retrieves the Valve command line pointer.
*
* @return ICommandLine ptr or NULL if not found.
*/
virtual ICommandLine *GetValveCommandLine() =0;
}; };
} }