Virtualize game state functions in the core/logic bridge.
This commit is contained in:
parent
bdfdab1d3a
commit
5c5d43137d
@ -52,7 +52,7 @@ using namespace SourceHook;
|
|||||||
* Add 1 to the RHS of this expression to bump the intercom file
|
* Add 1 to the RHS of this expression to bump the intercom file
|
||||||
* This is to prevent mismatching core/logic binaries
|
* This is to prevent mismatching core/logic binaries
|
||||||
*/
|
*/
|
||||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 43)
|
#define SM_LOGIC_MAGIC (0x0F47C0DE - 44)
|
||||||
|
|
||||||
#if defined SM_LOGIC
|
#if defined SM_LOGIC
|
||||||
class IVEngineServer
|
class IVEngineServer
|
||||||
@ -308,11 +308,16 @@ public:
|
|||||||
virtual const char *GetSourceEngineName() = 0;
|
virtual const char *GetSourceEngineName() = 0;
|
||||||
virtual bool SymbolsAreHidden() = 0;
|
virtual bool SymbolsAreHidden() = 0;
|
||||||
|
|
||||||
void (*LogToGame)(const char *message);
|
// Game state and helper functions.
|
||||||
void (*ConPrint)(const char *message);
|
virtual bool IsMapLoading() = 0;
|
||||||
|
virtual bool IsMapRunning() = 0;
|
||||||
|
virtual int MaxClients() = 0;
|
||||||
|
virtual bool DescribePlayer(int index, const char **namep, const char **authp, int *useridp) = 0;
|
||||||
|
virtual void LogToGame(const char *message) = 0;
|
||||||
|
virtual void ConPrint(const char *message) = 0;
|
||||||
|
virtual void ConsolePrintVa(const char *fmt, va_list ap) = 0;
|
||||||
|
|
||||||
const char * (*GetCoreConfigValue)(const char*);
|
const char * (*GetCoreConfigValue)(const char*);
|
||||||
bool (*IsMapLoading)();
|
|
||||||
bool (*IsMapRunning)();
|
|
||||||
int (*LoadMMSPlugin)(const char *file, bool *ok, char *error, size_t maxlength);
|
int (*LoadMMSPlugin)(const char *file, bool *ok, char *error, size_t maxlength);
|
||||||
void (*UnloadMMSPlugin)(int id);
|
void (*UnloadMMSPlugin)(int id);
|
||||||
void (*DoGlobalPluginLoads)();
|
void (*DoGlobalPluginLoads)();
|
||||||
@ -323,10 +328,7 @@ public:
|
|||||||
int (*GetImmunityMode)();
|
int (*GetImmunityMode)();
|
||||||
void (*UpdateAdminCmdFlags)(const char *cmd, OverrideType type, FlagBits bits, bool remove);
|
void (*UpdateAdminCmdFlags)(const char *cmd, OverrideType type, FlagBits bits, bool remove);
|
||||||
bool (*LookForCommandAdminFlags)(const char *cmd, FlagBits *pFlags);
|
bool (*LookForCommandAdminFlags)(const char *cmd, FlagBits *pFlags);
|
||||||
bool (*DescribePlayer)(int index, const char **namep, const char **authp, int *useridp);
|
|
||||||
int (*MaxClients)();
|
|
||||||
int (*GetGlobalTarget)();
|
int (*GetGlobalTarget)();
|
||||||
void (*ConsolePrintVa)(const char *fmt, va_list ap);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sm_logic_t
|
struct sm_logic_t
|
||||||
|
@ -300,31 +300,11 @@ static ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity
|
|||||||
static ConVar sm_immunity_mode("sm_immunity_mode", "1", FCVAR_SPONLY, "Mode for deciding immunity protection");
|
static ConVar sm_immunity_mode("sm_immunity_mode", "1", FCVAR_SPONLY, "Mode for deciding immunity protection");
|
||||||
static ConVar sm_datetime_format("sm_datetime_format", "%m/%d/%Y - %H:%M:%S", 0, "Default formatting time rules");
|
static ConVar sm_datetime_format("sm_datetime_format", "%m/%d/%Y - %H:%M:%S", 0, "Default formatting time rules");
|
||||||
|
|
||||||
static void log_to_game(const char *message)
|
|
||||||
{
|
|
||||||
Engine_LogPrintWrapper(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void conprint(const char *message)
|
|
||||||
{
|
|
||||||
META_CONPRINT(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* get_core_config_value(const char* key)
|
static const char* get_core_config_value(const char* key)
|
||||||
{
|
{
|
||||||
return g_CoreConfig.GetCoreConfigValue(key);
|
return g_CoreConfig.GetCoreConfigValue(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_map_loading()
|
|
||||||
{
|
|
||||||
return g_SourceMod.IsMapLoading();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool is_map_running()
|
|
||||||
{
|
|
||||||
return g_SourceMod.IsMapRunning();
|
|
||||||
}
|
|
||||||
|
|
||||||
static DatabaseInfo keyvalues_to_dbinfo(KeyValues *kv)
|
static DatabaseInfo keyvalues_to_dbinfo(KeyValues *kv)
|
||||||
{
|
{
|
||||||
DatabaseInfo info;
|
DatabaseInfo info;
|
||||||
@ -399,28 +379,6 @@ void do_global_plugin_loads()
|
|||||||
g_SourceMod.DoGlobalPluginLoads();
|
g_SourceMod.DoGlobalPluginLoads();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool describe_player(int index, const char **namep, const char **authp, int *useridp)
|
|
||||||
{
|
|
||||||
CPlayer *player = g_Players.GetPlayerByIndex(index);
|
|
||||||
if (!player || !player->IsConnected())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (namep)
|
|
||||||
*namep = player->GetName();
|
|
||||||
if (authp) {
|
|
||||||
const char *auth = player->GetAuthString();
|
|
||||||
*authp = (auth && *auth) ? auth : "STEAM_ID_PENDING";
|
|
||||||
}
|
|
||||||
if (useridp)
|
|
||||||
*useridp = GetPlayerUserId(player->GetEdict());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_max_clients()
|
|
||||||
{
|
|
||||||
return g_Players.MaxClients();
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_global_target()
|
static int get_global_target()
|
||||||
{
|
{
|
||||||
return g_SourceMod.GetGlobalTarget();
|
return g_SourceMod.GetGlobalTarget();
|
||||||
@ -515,11 +473,7 @@ public:
|
|||||||
this->menus = &g_Menus;
|
this->menus = &g_Menus;
|
||||||
this->spe1 = &g_pSourcePawn;
|
this->spe1 = &g_pSourcePawn;
|
||||||
this->spe2 = &g_pSourcePawn2;
|
this->spe2 = &g_pSourcePawn2;
|
||||||
this->LogToGame = log_to_game;
|
|
||||||
this->ConPrint = conprint;
|
|
||||||
this->GetCoreConfigValue = get_core_config_value;
|
this->GetCoreConfigValue = get_core_config_value;
|
||||||
this->IsMapLoading = is_map_loading;
|
|
||||||
this->IsMapRunning = is_map_running;
|
|
||||||
this->LoadMMSPlugin = load_mms_plugin;
|
this->LoadMMSPlugin = load_mms_plugin;
|
||||||
this->UnloadMMSPlugin = unload_mms_plugin;
|
this->UnloadMMSPlugin = unload_mms_plugin;
|
||||||
this->DoGlobalPluginLoads = do_global_plugin_loads;
|
this->DoGlobalPluginLoads = do_global_plugin_loads;
|
||||||
@ -530,10 +484,7 @@ public:
|
|||||||
this->GetImmunityMode = get_immunity_mode;
|
this->GetImmunityMode = get_immunity_mode;
|
||||||
this->UpdateAdminCmdFlags = update_admin_cmd_flags;
|
this->UpdateAdminCmdFlags = update_admin_cmd_flags;
|
||||||
this->LookForCommandAdminFlags = look_for_cmd_admin_flags;
|
this->LookForCommandAdminFlags = look_for_cmd_admin_flags;
|
||||||
this->DescribePlayer = describe_player;
|
|
||||||
this->MaxClients = get_max_clients;
|
|
||||||
this->GetGlobalTarget = get_global_target;
|
this->GetGlobalTarget = get_global_target;
|
||||||
this->ConsolePrintVa = UTIL_ConsolePrintVa;
|
|
||||||
this->gamesuffix = GAMEFIX;
|
this->gamesuffix = GAMEFIX;
|
||||||
this->serverGlobals = &::serverGlobals;
|
this->serverGlobals = &::serverGlobals;
|
||||||
this->serverFactory = nullptr;
|
this->serverFactory = nullptr;
|
||||||
@ -549,6 +500,13 @@ public:
|
|||||||
const char *GetGameDescription() override;
|
const char *GetGameDescription() override;
|
||||||
const char *GetSourceEngineName() override;
|
const char *GetSourceEngineName() override;
|
||||||
bool SymbolsAreHidden() override;
|
bool SymbolsAreHidden() override;
|
||||||
|
bool IsMapLoading() override;
|
||||||
|
bool IsMapRunning() override;
|
||||||
|
int MaxClients() override;
|
||||||
|
bool DescribePlayer(int index, const char **namep, const char **authp, int *useridp) override;
|
||||||
|
void LogToGame(const char *message) override;
|
||||||
|
void ConPrint(const char *message) override;
|
||||||
|
void ConsolePrintVa(const char *fmt, va_list ap) override;
|
||||||
} sCoreProviderImpl;
|
} sCoreProviderImpl;
|
||||||
|
|
||||||
ConVar *CoreProviderImpl::FindConVar(const char *name)
|
ConVar *CoreProviderImpl::FindConVar(const char *name)
|
||||||
@ -659,6 +617,53 @@ bool CoreProviderImpl::SymbolsAreHidden()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CoreProviderImpl::LogToGame(const char *message)
|
||||||
|
{
|
||||||
|
Engine_LogPrintWrapper(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreProviderImpl::ConPrint(const char *message)
|
||||||
|
{
|
||||||
|
META_CONPRINT(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreProviderImpl::ConsolePrintVa(const char *message, va_list ap)
|
||||||
|
{
|
||||||
|
UTIL_ConsolePrintVa(message, ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CoreProviderImpl::IsMapLoading()
|
||||||
|
{
|
||||||
|
return g_SourceMod.IsMapLoading();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CoreProviderImpl::IsMapRunning()
|
||||||
|
{
|
||||||
|
return g_SourceMod.IsMapRunning();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CoreProviderImpl::MaxClients()
|
||||||
|
{
|
||||||
|
return g_Players.MaxClients();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CoreProviderImpl::DescribePlayer(int index, const char **namep, const char **authp, int *useridp)
|
||||||
|
{
|
||||||
|
CPlayer *player = g_Players.GetPlayerByIndex(index);
|
||||||
|
if (!player || !player->IsConnected())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (namep)
|
||||||
|
*namep = player->GetName();
|
||||||
|
if (authp) {
|
||||||
|
const char *auth = player->GetAuthString();
|
||||||
|
*authp = (auth && *auth) ? auth : "STEAM_ID_PENDING";
|
||||||
|
}
|
||||||
|
if (useridp)
|
||||||
|
*useridp = GetPlayerUserId(player->GetEdict());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void InitLogicBridge()
|
void InitLogicBridge()
|
||||||
{
|
{
|
||||||
serverGlobals.universalTime = g_pUniversalTime;
|
serverGlobals.universalTime = g_pUniversalTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user