Added CCVar Game Class and ConVar/ConCommandBase Class.

This commit is contained in:
IcePixelx 2021-07-24 03:16:10 +02:00
parent 53383fc5a9
commit c9c5818594
3 changed files with 67 additions and 10 deletions

View File

@ -517,12 +517,68 @@ public:
}
};
struct CVValue_t
class ConCommandBase
{
char* m_pszString;
__int64 m_StringLength;
float m_fValue;
int m_nValue;
public:
void* m_pConCommandBaseVTable; //0x0000
ConCommandBase* m_pNext; //0x0008
bool m_bRegistered; //0x0010
private:
char pad_0011[7]; //0x0011
public:
const char* m_pszName; //0x0018
const char* m_pszHelpString; //0x0020
private:
char pad_0028[16]; //0x0028
public:
__int32 m_nFlags; //0x0038
private:
char pad_003C[4]; //0x003C
}; //Size: 0x0038
class ConVar
{
public:
ConCommandBase m_ConCommandBase; // 0x0000
void* m_pConVarVTable; //0x0040
ConVar* m_pParent; //0x0048
const char* n_pszDefaultValue; //0x0050
const char* m_pzsCurrentValue; //0x0058
__int64 m_iStringLength; //0x0060
float m_flValue; //0x0068
__int64 m_iValue; //0x006C
bool m_bHasMin; //0x0070
private:
char pad_0071[3]; //0x0071
public:
float m_flMinValue; //0x0074
bool m_bHasMax; //0x0078
private:
char pad_0079[3]; //0x0079
public:
float m_flMaxValue; //0x007C
}; //Size: 0x0080
class CCVar
{
public:
ConCommandBase* FindCommandBase(const char* szCommandName) // @0x1405983A0 in R5pc_r5launch_N1094_CL456479_2019_10_30_05_20_PM
{
using OriginalFn = ConCommandBase*(__thiscall*)(CCVar*, const char*);
return (*reinterpret_cast<OriginalFn**>(this))[14](this, szCommandName);
}
ConVar* FindVar(const char* szVarName) // @0x1405983B0 in R5pc_r5launch_N1094_CL456479_2019_10_30_05_20_PM
{
using OriginalFn = ConVar*(__thiscall*)(CCVar*, const char*);
return (*reinterpret_cast<OriginalFn**>(this))[16](this, szVarName);
}
void* /*Implement ConCommand class.*/ FindCommand(const char* szCommandName) // @0x1405983F0 in R5pc_r5launch_N1094_CL456479_2019_10_30_05_20_PM
{
using OriginalFn = void*(__thiscall*)(CCVar*, const char*);
return (*reinterpret_cast<OriginalFn**>(this))[18](this, szCommandName);
}
};
/////////////////////////////////////////////////////////////////////////////
@ -532,6 +588,7 @@ namespace GameGlobals
{
extern CHostState* HostState;
extern CInputSystem* InputSystem;
extern CCVar* Cvar;
void InitGameGlobals();
extern bool IsInitialized;

View File

@ -6,11 +6,13 @@ namespace GameGlobals
bool IsInitialized = false;
CHostState* HostState = nullptr;
CInputSystem* InputSystem = nullptr;
CCVar* Cvar = nullptr;
void InitGameGlobals()
{
HostState = reinterpret_cast<CHostState*>(0x141736120); // Get CHostState from memory.
InputSystem = *reinterpret_cast<CInputSystem**>(0x14D40B380); // Get IInputSystem from memory.
Cvar = *reinterpret_cast<CCVar**>(0x14D40B348); // Get CCVar from memory.
IsInitialized = true;
}

View File

@ -355,7 +355,7 @@ CCompanion::CCompanion()
void CCompanion::UpdateHostingStatus()
{
if (!GameGlobals::HostState) // Is HostState valid?
if (!GameGlobals::HostState || !GameGlobals::Cvar) // Is HostState and Cvar valid?
return;
GameGlobals::HostState->m_bActiveGame ? HostingStatus = EHostStatus::Hosting : HostingStatus = EHostStatus::NotHosting; // Are we hosting a server?
@ -425,14 +425,12 @@ void CCompanion::SendHostingPostRequest(char* mapName)
body["name"] = ServerNameBuffer;
body["map"] = mapName;
CVValue_t* hostport_value = (CVValue_t*)(0x141734DD0 + 0x58);
static ConVar* hostport = GameGlobals::Cvar->FindVar("hostport"); // static since it won't move memory locations.
body["port"] = hostport_value->m_pszString;
body["port"] = hostport->m_pzsCurrentValue;
std::string body_str = body.dump();
#ifdef OVERLAY_DEBUG
std::cout << " [+CCompanion+] Sending request now, Body: " << body_str << "\n";
#endif