From b336c9c30d0d1cd3ad2bfeb14053d37484297995 Mon Sep 17 00:00:00 2001 From: Nick Hastings Date: Sun, 2 Apr 2023 09:30:08 -0400 Subject: [PATCH] Make ConVars opaque outside of providers --- core/metamod.cpp | 6 +++--- core/metamod_provider.h | 8 +++++--- core/provider/provider_base.h | 6 +++--- core/provider/source/provider_source.cpp | 16 ++++++++-------- core/provider/source/provider_source.h | 6 +++--- core/provider/source2/provider_source2.cpp | 6 +++--- core/provider/source2/provider_source2.h | 6 +++--- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/core/metamod.cpp b/core/metamod.cpp index 1acb0eb..22dfce1 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -77,9 +77,9 @@ static bool is_game_init = false; static bool vsp_load_requested = false; static bool vsp_loaded = false; static game_dll_t gamedll_info; -static ConVar *metamod_version = NULL; -static ConVar *mm_pluginsfile = NULL; -static ConVar *mm_basedir = NULL; +static MetamodSourceConVar *metamod_version = NULL; +static MetamodSourceConVar *mm_pluginsfile = NULL; +static MetamodSourceConVar *mm_basedir = NULL; static CreateInterfaceFn engine_factory = NULL; static CreateInterfaceFn physics_factory = NULL; static CreateInterfaceFn filesystem_factory = NULL; diff --git a/core/metamod_provider.h b/core/metamod_provider.h index 2c04dac..a726306 100644 --- a/core/metamod_provider.h +++ b/core/metamod_provider.h @@ -28,6 +28,8 @@ namespace SourceMM { + class MetamodSourceConVar; + enum { ConVarFlag_None = 0, @@ -219,7 +221,7 @@ namespace SourceMM * @param help Help text. * @return ConVar pointer. */ - virtual ConVar *CreateConVar(const char *name, + virtual MetamodSourceConVar *CreateConVar(const char *name, const char *defval, const char *help, int flags) =0; @@ -230,7 +232,7 @@ namespace SourceMM * @param convar ConVar pointer. * @return String value. */ - virtual const char *GetConVarString(ConVar *convar) =0; + virtual const char *GetConVarString(MetamodSourceConVar *convar) =0; /** * @brief Sets a ConVar string. @@ -238,7 +240,7 @@ namespace SourceMM * @param convar ConVar pointer. * @param str String pointer. */ - virtual void SetConVarString(ConVar *convar, const char *str) =0; + virtual void SetConVarString(MetamodSourceConVar *convar, const char *str) =0; /** * @brief Retrieves the absolute path to the game directory. diff --git a/core/provider/provider_base.h b/core/provider/provider_base.h index 0461068..2801bd3 100644 --- a/core/provider/provider_base.h +++ b/core/provider/provider_base.h @@ -61,13 +61,13 @@ public: // Must implement virtual void ConsolePrint(const char* msg) override = 0; virtual void ClientConsolePrint(edict_t* client, const char* msg) override = 0; virtual void ServerCommand(const char* cmd) override = 0; - virtual ConVar* CreateConVar(const char* name, + virtual MetamodSourceConVar *CreateConVar(const char* name, const char* defval, const char* help, int flags) override = 0; - virtual const char* GetConVarString(ConVar* convar) override = 0; - virtual void SetConVarString(ConVar* convar, const char* str) override = 0; virtual IConCommandBaseAccessor* GetConCommandBaseAccessor() override = 0; + virtual const char* GetConVarString(MetamodSourceConVar *convar) override = 0; + virtual void SetConVarString(MetamodSourceConVar *convar, const char* str) override = 0; virtual bool RegisterConCommandBase(ConCommandBase* pCommand) override = 0; virtual void UnregisterConCommandBase(ConCommandBase* pCommand) override = 0; virtual bool IsConCommandBaseACommand(ConCommandBase* pCommand) override = 0; diff --git a/core/provider/source/provider_source.cpp b/core/provider/source/provider_source.cpp index cef0a7c..c685ebb 100644 --- a/core/provider/source/provider_source.cpp +++ b/core/provider/source/provider_source.cpp @@ -339,19 +339,19 @@ void SourceProvider::ServerCommand(const char* cmd) engine->ServerCommand(cmd); } -const char* SourceProvider::GetConVarString(ConVar* convar) +const char* SourceProvider::GetConVarString(MetamodSourceConVar *convar) { - if (convar == NULL) + if (nullptr == convar) { - return NULL; + return nullptr; } - return convar->GetString(); + return reinterpret_cast(convar)->GetString(); } -void SourceProvider::SetConVarString(ConVar* convar, const char* str) +void SourceProvider::SetConVarString(MetamodSourceConVar *convar, const char* str) { - convar->SetValue(str); + reinterpret_cast(convar)->SetValue(str); } bool SourceProvider::IsConCommandBaseACommand(ConCommandBase* pCommand) @@ -374,7 +374,7 @@ void SourceProvider::UnregisterConCommandBase(ConCommandBase* pCommand) return m_ConVarAccessor.Unregister(pCommand); } -ConVar* SourceProvider::CreateConVar(const char* name, +MetamodSourceConVar* SourceProvider::CreateConVar(const char* name, const char* defval, const char* help, int flags) @@ -393,7 +393,7 @@ ConVar* SourceProvider::CreateConVar(const char* name, m_ConVarAccessor.RegisterConCommandBase(pVar); - return pVar; + return reinterpret_cast(pVar); } #if SOURCE_ENGINE >= SE_ORANGEBOX diff --git a/core/provider/source/provider_source.h b/core/provider/source/provider_source.h index 67951aa..6debaec 100644 --- a/core/provider/source/provider_source.h +++ b/core/provider/source/provider_source.h @@ -46,13 +46,13 @@ public: // BaseProvider virtual void ConsolePrint(const char* msg) override; virtual void ClientConsolePrint(edict_t* client, const char* msg) override; virtual void ServerCommand(const char* cmd) override; - virtual ConVar* CreateConVar(const char* name, + virtual MetamodSourceConVar *CreateConVar(const char* name, const char* defval, const char* help, int flags) override; - virtual const char* GetConVarString(ConVar* convar) override; - virtual void SetConVarString(ConVar* convar, const char* str) override; virtual IConCommandBaseAccessor* GetConCommandBaseAccessor() override; + virtual const char* GetConVarString(MetamodSourceConVar *convar) override; + virtual void SetConVarString(MetamodSourceConVar *convar, const char* str) override; virtual bool RegisterConCommandBase(ConCommandBase* pCommand) override; virtual void UnregisterConCommandBase(ConCommandBase* pCommand) override; virtual bool IsConCommandBaseACommand(ConCommandBase* pCommand) override; diff --git a/core/provider/source2/provider_source2.cpp b/core/provider/source2/provider_source2.cpp index 76c80ff..1eab4e7 100644 --- a/core/provider/source2/provider_source2.cpp +++ b/core/provider/source2/provider_source2.cpp @@ -242,7 +242,7 @@ void Source2Provider::ServerCommand(const char* cmd) engine->ServerCommand(cmd); } -const char* Source2Provider::GetConVarString(ConVar* convar) +const char* Source2Provider::GetConVarString(MetamodSourceConVar *convar) { #ifdef S2_CONVAR_UNFINISHED if (convar == NULL) @@ -256,7 +256,7 @@ const char* Source2Provider::GetConVarString(ConVar* convar) #endif } -void Source2Provider::SetConVarString(ConVar* convar, const char* str) +void Source2Provider::SetConVarString(MetamodSourceConVar *convar, const char* str) { #ifdef S2_CONVAR_UNFINISHED convar->SetValue(str); @@ -297,7 +297,7 @@ void Source2Provider::UnregisterConCommandBase(ConCommandBase* pCommand) #endif } -ConVar* Source2Provider::CreateConVar(const char* name, +MetamodSourceConVar* Source2Provider::CreateConVar(const char* name, const char* defval, const char* help, int flags) diff --git a/core/provider/source2/provider_source2.h b/core/provider/source2/provider_source2.h index da89353..ae0de44 100644 --- a/core/provider/source2/provider_source2.h +++ b/core/provider/source2/provider_source2.h @@ -53,13 +53,13 @@ public: virtual void ConsolePrint(const char* msg) override; virtual void ClientConsolePrint(edict_t* client, const char* msg) override; virtual void ServerCommand(const char* cmd) override; - virtual ConVar* CreateConVar(const char* name, + virtual MetamodSourceConVar *CreateConVar(const char* name, const char* defval, const char* help, int flags) override; - virtual const char* GetConVarString(ConVar* convar) override; - virtual void SetConVarString(ConVar* convar, const char* str) override; virtual IConCommandBaseAccessor* GetConCommandBaseAccessor() override; + virtual const char* GetConVarString(MetamodSourceConVar *convar) override; + virtual void SetConVarString(MetamodSourceConVar *convar, const char* str) override; virtual bool RegisterConCommandBase(ConCommandBase* pCommand) override; virtual void UnregisterConCommandBase(ConCommandBase* pCommand) override; virtual bool IsConCommandBaseACommand(ConCommandBase* pCommand) override;