diff options
Diffstat (limited to 'NorthstarDedicatedTest/convar.h')
-rw-r--r-- | NorthstarDedicatedTest/convar.h | 114 |
1 files changed, 70 insertions, 44 deletions
diff --git a/NorthstarDedicatedTest/convar.h b/NorthstarDedicatedTest/convar.h index 30ab702b..a00c7f0e 100644 --- a/NorthstarDedicatedTest/convar.h +++ b/NorthstarDedicatedTest/convar.h @@ -1,6 +1,9 @@ #pragma once #include "sourceinterface.h" -#include <set> +#include "color.h" +#include "cvar.h" +#include "concommand.h" + // taken directly from iconvar.h // The default, no flags at all @@ -17,14 +20,13 @@ // ConVar only #define FCVAR_PROTECTED \ (1 << 5) // It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as - // value + // value. #define FCVAR_SPONLY (1 << 6) // This cvar cannot be changed by clients connected to a multiplayer server. #define FCVAR_ARCHIVE (1 << 7) // set to cause it to be saved to vars.rc #define FCVAR_NOTIFY (1 << 8) // notifies players when changed #define FCVAR_USERINFO (1 << 9) // changes the client's info string #define FCVAR_PRINTABLEONLY (1 << 10) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ). - #define FCVAR_GAMEDLL_FOR_REMOTE_CLIENTS \ (1 << 10) // When on concommands this allows remote clients to execute this cmd on the server. // We are changing the default behavior of concommands to disallow execution by remote clients without @@ -34,8 +36,7 @@ #define FCVAR_NEVER_AS_STRING (1 << 12) // never try to print that cvar // It's a ConVar that's shared between the client and the server. -// At signon, the values of all such ConVars are sent from the server to the client (skipped for local -// client, of course ) +// At signon, the values of all such ConVars are sent from the server to the client (skipped for local client, of course ) // If a change is requested it must come from the console (i.e., no remote client changes) // If a value is changed while a server is active, it's replicated to all connected clients #define FCVAR_REPLICATED (1 << 13) // server setting enforced on clients, TODO rename to FCAR_SERVER at some time @@ -66,52 +67,77 @@ // #define FCVAR_AVAILABLE (1<<27) // #define FCVAR_AVAILABLE (1<<31) +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class ConCommandBase; class ConCommand; +class ConVar; -// still need to map out functions and that for this, would be nice to be able to get actual values out of these in native -// also i sure do hope this size is right because there's a fairly decent chance it isn't +//----------------------------------------------------------------------------- +// Purpose: A console variable +//----------------------------------------------------------------------------- class ConVar { public: - // if there are ever crashes caused by modifying custom cvars, check this - unsigned char unknown[0x40]; - char* m_pszString; - size_t m_StringLength; - float m_fValue; - int32_t m_nValue; - unsigned char unknown2[0x28]; - - public: - virtual void EngineDestructor(void) {} - virtual bool IsCommand(void) const { return false; } - virtual bool IsFlagSet(int flag) { return false; } - virtual void AddFlags(int flags) {} - virtual void RemoveFlags(int flags) {} - virtual int GetFlags() const { return 0; } - virtual const char* GetName(void) const { return nullptr; } - virtual const char* GetHelpText(void) const { return nullptr; } - virtual bool IsRegistered(void) const { return false; } -}; - -class ICvar -{ - public: - struct VTable + ConVar(void){}; + ConVar(const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString); + ConVar( + const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString, bool bMin, float fMin, bool bMax, + float fMax, void* pCallback); + ~ConVar(void); + + const char* GetBaseName(void) const; + const char* GetHelpText(void) const; + + void AddFlags(int nFlags); + void RemoveFlags(int nFlags); + + bool GetBool(void) const; + float GetFloat(void) const; + int GetInt(void) const; + Color GetColor(void) const; + const char* GetString(void) const; + + bool GetMin(float& flMinValue) const; + bool GetMax(float& flMaxValue) const; + float GetMinValue(void) const; + float GetMaxValue(void) const; + + bool HasMin(void) const; + bool HasMax(void) const; + + void SetValue(int nValue); + void SetValue(float flValue); + void SetValue(const char* pszValue); + void SetValue(Color clValue); + + void ChangeStringValue(const char* pszTempValue, float flOldValue); + bool SetColorFromString(const char* pszValue); + bool ClampValue(float& value); + + bool IsRegistered(void) const; + bool IsCommand(void) const; + static bool IsFlagSet(ConVar* pConVar, int nFlags); + + struct CVValue_t { - // void* unknown[10]; - // void(*UnregisterConCommand) (ICvar* cvar, ConCommand* pCommandBase); - // void* unknown2[28]; - // ConVar*(*FindVar)(const char* var_name); // offset for this is currently very wrong - char* unknown[112]; - ConCommand* (*FindCommandBase)(ICvar* self, const char* varName); // this offset is also wrong for some reason + const char* m_pszString; + int64_t m_iStringLength; + float m_fValue; + int m_nValue; }; - VTable* m_vtable; -}; + ConCommandBase m_ConCommandBase{}; // 0x0000 + ConVar* m_pParent{}; // 0x0040 + CVValue_t m_Value{}; // 0x0048 + bool m_bHasMin{}; // 0x005C + float m_fMinVal{}; // 0x0060 + bool m_bHasMax{}; // 0x0064 + float m_fMaxVal{}; // 0x0068 + void* m_pMalloc{}; // 0x0070 + char m_pPad80[10]{}; // 0x0080 +}; // Size: 0x0080 -ConVar* RegisterConVar(const char* name, const char* defaultValue, int flags, const char* helpString); -ConVar* FindConVar(const char* name); void InitialiseConVars(HMODULE baseAddress); - -extern std::unordered_map<std::string, ConVar*> g_CustomConvars; -extern SourceInterface<ICvar>* g_pCvar;
\ No newline at end of file +extern std::unordered_map<std::string, ConVar*> g_CustomConvars;
\ No newline at end of file |