mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Implement CommandLine utilities
This commit is contained in:
parent
64c07af6e0
commit
0146f22e0a
@ -6,6 +6,7 @@
|
||||
|
||||
#include "core/stdafx.h"
|
||||
#include "core/init.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier0/ConCommand.h"
|
||||
#include "tier0/completion.h"
|
||||
#include "tier0/cvar.h"
|
||||
@ -119,7 +120,6 @@ void Systems_Init()
|
||||
#ifdef DEDICATED
|
||||
Dedicated_Init();
|
||||
#endif // DEDICATED
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -339,6 +339,7 @@
|
||||
<ClInclude Include="thirdparty\spdlog\include\tweakme.h" />
|
||||
<ClInclude Include="thirdparty\spdlog\include\version.h" />
|
||||
<ClInclude Include="tier0\basetypes.h" />
|
||||
<ClInclude Include="tier0\commandline.h" />
|
||||
<ClInclude Include="tier0\ConCommand.h" />
|
||||
<ClInclude Include="tier0\completion.h" />
|
||||
<ClInclude Include="tier0\cvar.h" />
|
||||
@ -485,6 +486,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tier0\commandline.cpp" />
|
||||
<ClCompile Include="tier0\ConCommand.cpp" />
|
||||
<ClCompile Include="tier0\completion.cpp" />
|
||||
<ClCompile Include="tier0\cvar.cpp" />
|
||||
|
@ -660,6 +660,9 @@
|
||||
<ClInclude Include="mathlib\bits.h">
|
||||
<Filter>sdk\mathlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tier0\commandline.h">
|
||||
<Filter>sdk\tier0</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="client\IVEngineClient.cpp">
|
||||
@ -863,6 +866,9 @@
|
||||
<ClCompile Include="mathlib\bits.cpp">
|
||||
<Filter>sdk\mathlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tier0\commandline.cpp">
|
||||
<Filter>sdk\tier0</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="r5dev.def" />
|
||||
|
@ -191,6 +191,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tier0\commandline.cpp" />
|
||||
<ClCompile Include="tier0\ConCommand.cpp" />
|
||||
<ClCompile Include="tier0\completion.cpp" />
|
||||
<ClCompile Include="tier0\cvar.cpp" />
|
||||
@ -401,6 +402,7 @@
|
||||
<ClInclude Include="thirdparty\spdlog\include\tweakme.h" />
|
||||
<ClInclude Include="thirdparty\spdlog\include\version.h" />
|
||||
<ClInclude Include="tier0\basetypes.h" />
|
||||
<ClInclude Include="tier0\commandline.h" />
|
||||
<ClInclude Include="tier0\ConCommand.h" />
|
||||
<ClInclude Include="tier0\completion.h" />
|
||||
<ClInclude Include="tier0\cvar.h" />
|
||||
|
@ -399,6 +399,9 @@
|
||||
<ClCompile Include="mathlib\bits.cpp">
|
||||
<Filter>sdk\mathlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tier0\commandline.cpp">
|
||||
<Filter>sdk\tier0</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="client\cdll_engine_int.h">
|
||||
@ -1034,6 +1037,9 @@
|
||||
<ClInclude Include="mathlib\bits.h">
|
||||
<Filter>sdk\mathlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tier0\commandline.h">
|
||||
<Filter>sdk\tier0</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="r5dev.def" />
|
||||
|
132
r5dev/tier0/commandline.cpp
Normal file
132
r5dev/tier0/commandline.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
//=============================================================================//
|
||||
//
|
||||
// Purpose: Command line utilities
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "core/stdafx.h"
|
||||
#include "tier0/cvar.h"
|
||||
#include "tier0/commandline.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create a command line from the passed in string
|
||||
// Note that if you pass in a @filename, then the routine will read settings
|
||||
// from a file instead of the command line
|
||||
//-----------------------------------------------------------------------------
|
||||
void CCommandLine::CreateCmdLine(const char* pszCommandline)
|
||||
{
|
||||
using OriginalFn = void(__thiscall*)(CCommandLine*, const char*);
|
||||
(*reinterpret_cast<OriginalFn**>(this))[0](this, pszCommandline);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// purpose: creates a command line from the arguments passed in
|
||||
//-----------------------------------------------------------------------------
|
||||
void CCommandLine::CreateCmdLine(int argc, char** argv)
|
||||
{
|
||||
using OriginalFn = void(__thiscall*)(CCommandLine*, int, char**);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[1](this, argc, argv);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// purpose: allocates a pool for the command line [seems unused]
|
||||
//-----------------------------------------------------------------------------
|
||||
void CCommandLine::CreatePool(void* pMem)
|
||||
{
|
||||
using OriginalFn = void(__thiscall*)(CCommandLine*, void*);
|
||||
(*reinterpret_cast<OriginalFn**>(this))[2](this, pMem);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return current command line
|
||||
// Output : const char
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CCommandLine::GetCmdLine(void)
|
||||
{
|
||||
using OriginalFn = const char* (__thiscall*)(CCommandLine*);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[3](this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Search for the parameter in the current commandline
|
||||
// Input : *psz -
|
||||
// **ppszValue -
|
||||
// Output : char
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CCommandLine::CheckParm(const char* psz, const char** ppszValue)
|
||||
{
|
||||
using OriginalFn = const char* (__thiscall*)(CCommandLine*, const char*, const char**);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[4](this, psz, ppszValue);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Remove specified string ( and any args attached to it ) from command line
|
||||
// Input : *pszParm -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CCommandLine::RemoveParm(void)
|
||||
{
|
||||
using OriginalFn = void(__thiscall*)(CCommandLine*);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[5](this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Append parameter and argument values to command line
|
||||
// Input : *pszParm -
|
||||
// *pszValues -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CCommandLine::AppendParm(const char* pszParm, const char* pszValues)
|
||||
{
|
||||
using OriginalFn = void(__thiscall*)(CCommandLine*, const char*, const char*);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[6](this, pszParm, pszParm);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// purpose: returns the argument after the one specified, or the default if not found
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CCommandLine::ParmValue(const char* psz, const char* pDefaultVal)
|
||||
{
|
||||
using OriginalFn = const char* (__thiscall*)(CCommandLine*, const char*, const char*);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[7](this, psz, pDefaultVal);
|
||||
}
|
||||
|
||||
int CCommandLine::ParmValue(const char* psz, int nDefaultVal)
|
||||
{
|
||||
using OriginalFn = int(__thiscall*)(CCommandLine*, const char*, int);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[8](this, psz, nDefaultVal);
|
||||
}
|
||||
|
||||
float CCommandLine::ParmValue(const char* psz, float flDefaultVal)
|
||||
{
|
||||
using OriginalFn = float(__thiscall*)(CCommandLine*, const char*, float);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[9](this, psz, flDefaultVal);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// purpose: returns individual command line arguments
|
||||
//-----------------------------------------------------------------------------
|
||||
int CCommandLine::ParmCount(void)
|
||||
{
|
||||
using OriginalFn = int(__thiscall*)(CCommandLine*);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[10](this);
|
||||
}
|
||||
|
||||
int CCommandLine::FindParm(const char* psz)
|
||||
{
|
||||
using OriginalFn = int(__thiscall*)(CCommandLine*, const char*);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[11](this, psz);
|
||||
}
|
||||
|
||||
const char* CCommandLine::GetParm(int nIndex)
|
||||
{
|
||||
using OriginalFn = const char* (__thiscall*)(CCommandLine*, int);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[12](this, nIndex);
|
||||
}
|
||||
|
||||
void CCommandLine::SetParm(int nIndex, char const* pParm)
|
||||
{
|
||||
using OriginalFn = void(__thiscall*)(CCommandLine*, int, const char*);
|
||||
return (*reinterpret_cast<OriginalFn**>(this))[13](this, nIndex, pParm);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
CCommandLine* g_pCmdLine = reinterpret_cast<CCommandLine*>(p_CCVar_GetCommandLineValue.FindPatternSelf("48 8D 0D", ADDRESS::Direction::DOWN, 250).ResolveRelativeAddressSelf(0x3, 0x7).GetPtr());
|
34
r5dev/tier0/commandline.h
Normal file
34
r5dev/tier0/commandline.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
class CCommandLine // VTABLE @0x141369C78 in R5pc_r5launch_N1094_CL456479_2019_10_30_05_20_PM
|
||||
{
|
||||
public:
|
||||
void CreateCmdLine(const char* pszCommandline);
|
||||
void CreateCmdLine(int argc, char** argv);
|
||||
void CreatePool(void* pMem);
|
||||
const char* GetCmdLine(void);
|
||||
const char* CheckParm(const char* psz, const char** ppszValue);
|
||||
void RemoveParm(void);
|
||||
void AppendParm(const char* pszParm, const char* pszValues);
|
||||
const char* ParmValue(const char* psz, const char* pDefaultVal);
|
||||
int ParmValue(const char* psz, int nDefaultVal);
|
||||
float ParmValue(const char* psz, float flDefaultVal);
|
||||
int ParmCount(void);
|
||||
int FindParm(const char* psz);
|
||||
const char* GetParm(int nIndex);
|
||||
void SetParm(int nIndex, char const* pParm);
|
||||
};
|
||||
extern CCommandLine* g_pCmdLine;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class HCommandLine : public IDetour
|
||||
{
|
||||
virtual void debugp()
|
||||
{
|
||||
std::cout << "| VAR: g_pCmdLine : 0x" << std::hex << std::uppercase << g_pCmdLine << std::setw(0) << " |" << std::endl;
|
||||
std::cout << "+----------------------------------------------------------------+" << std::endl;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
REGISTER(HCommandLine);
|
@ -6,12 +6,14 @@ namespace
|
||||
{
|
||||
/* ==== CCVAR =========================================================================================================================================================== */
|
||||
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
|
||||
ADDRESS p_CCvar_Disconnect = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x57\x41\x56\x48\x83\xEC\x38\x4C\x8B\x35", "xxxxxxxxxxx");
|
||||
void* (*CCvar_Disconnect)() = (void* (*)())p_CCvar_Disconnect.GetPtr(); /*40 57 41 56 48 83 EC 38 4C 8B 35 ? ? ? ?*/
|
||||
ADDRESS p_CCVar_Disconnect = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x57\x41\x56\x48\x83\xEC\x38\x4C\x8B\x35", "xxxxxxxxxxx");
|
||||
void* (*CCVar_Disconnect)() = (void* (*)())p_CCVar_Disconnect.GetPtr(); /*40 57 41 56 48 83 EC 38 4C 8B 35 ? ? ? ?*/
|
||||
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
|
||||
ADDRESS p_CCvar_Disconnect = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x83\xEC\x28\x48\x8B\x0D\x00\x00\x00\x00\x48\x85\xC9\x74\x26\x80\x3D\x00\x00\x00\x00\x00\x74\x1D\x48\x8B\x01\x8B\x15\x00\x00\x00\x00\xFF\x50\x58\xC7\x05\x00\x00\x00\x00\x00\x00\x00\x00\xC6\x05\x00\x00\x00\x00\x00\x48\xC7\x05\x00\x00\x00", "xxxxxxx????xxxxxxx?????xxxxxxx????xxxxx????????xx");
|
||||
void* (*CCvar_Disconnect)() = (void* (*)())p_CCvar_Disconnect.GetPtr(); /*48 83 EC 28 48 8B 0D ? ? ? ? 48 85 C9 74 26 80 3D ? ? ? ? ? 74 1D 48 8B 01 8B 15 ? ? ? ? FF 50 58 C7 05 ? ? ? ? ? ? ? ? C6 05 ? ? ? ? ? 48 C7 05 ? ? ? ? ? ? ? ?*/
|
||||
ADDRESS p_CCVar_Disconnect = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x83\xEC\x28\x48\x8B\x0D\x00\x00\x00\x00\x48\x85\xC9\x74\x26\x80\x3D\x00\x00\x00\x00\x00\x74\x1D\x48\x8B\x01\x8B\x15\x00\x00\x00\x00\xFF\x50\x58\xC7\x05\x00\x00\x00\x00\x00\x00\x00\x00\xC6\x05\x00\x00\x00\x00\x00\x48\xC7\x05\x00\x00\x00", "xxxxxxx????xxxxxxx?????xxxxxxx????xxxxx????????xx");
|
||||
void* (*CCVar_Disconnect)() = (void* (*)())p_CCVar_Disconnect.GetPtr(); /*48 83 EC 28 48 8B 0D ? ? ? ? 48 85 C9 74 26 80 3D ? ? ? ? ? 74 1D 48 8B 01 8B 15 ? ? ? ? FF 50 58 C7 05 ? ? ? ? ? ? ? ? C6 05 ? ? ? ? ? 48 C7 05 ? ? ? ? ? ? ? ?*/
|
||||
#endif
|
||||
ADDRESS p_CCVar_GetCommandLineValue = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x55\x48\x83\xEC\x20\x48\x8D\x6C\x24\x00\x48\x89\x5D\x10\x49\xC7\xC0\x00\x00\x00\x00", "xxxxxxxxxx?xxxxxxx????");
|
||||
const char* (*CCVar_GetCommandLineValue)(void* thisptr, const char* pVariableName) = (const char* (*)(void*, const char*))p_CCVar_GetCommandLineValue.GetPtr(); /*40 55 48 83 EC 20 48 8D 6C 24 ? 48 89 5D 10 49 C7 C0 ? ? ? ?*/
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -88,8 +90,9 @@ class HCvar : public IDetour
|
||||
{
|
||||
virtual void debugp()
|
||||
{
|
||||
std::cout << "| FUN: CCvar::Disconnect : 0x" << std::hex << std::uppercase << p_CCvar_Disconnect.GetPtr() << std::setw(npad) << " |" << std::endl;
|
||||
std::cout << "| VAR: g_pCvar : 0x" << std::hex << std::uppercase << g_pCvar << std::setw(0) << " |" << std::endl;
|
||||
std::cout << "| FUN: CCVar::Disconnect : 0x" << std::hex << std::uppercase << p_CCVar_Disconnect.GetPtr() << std::setw(npad) << " |" << std::endl;
|
||||
std::cout << "| FUN: CCVar::GetCommandLineValue : 0x" << std::hex << std::uppercase << p_CCVar_GetCommandLineValue.GetPtr() << std::setw(npad) << " |" << std::endl;
|
||||
std::cout << "| VAR: g_pCvar : 0x" << std::hex << std::uppercase << g_pCvar << std::setw(0) << " |" << std::endl;
|
||||
std::cout << "+----------------------------------------------------------------+" << std::endl;
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user