2021-12-25 22:36:38 +01:00
# include "core/stdafx.h"
# include "tier0/cvar.h"
# include "tier0/completion.h"
# include "tier0/ConCommand.h"
# include "client/client.h"
# include "engine/sys_utils.h"
//-----------------------------------------------------------------------------
2022-01-09 16:14:17 +01:00
// purpose: construct/allocate
2021-12-25 22:36:38 +01:00
//-----------------------------------------------------------------------------
2022-01-09 16:14:17 +01:00
ConCommand : : ConCommand ( const char * pszName , const char * pszHelpString , int nFlags , void * pCallback , void * pCommandCompletionCallback )
2021-12-25 22:36:38 +01:00
{
2022-01-09 16:14:17 +01:00
ConCommand * pCommand = reinterpret_cast < ConCommand * > ( MemAlloc_Wrapper ( 0x68 ) ) ; // Allocate new memory with StdMemAlloc else we crash.
memset ( pCommand , 0 , 0x68 ) ; // Set all to null.
std : : uintptr_t pCommandBase = reinterpret_cast < std : : uintptr_t > ( pCommand ) ; // To ptr.
2021-12-25 22:36:38 +01:00
2022-01-09 16:14:17 +01:00
* ( void * * ) pCommandBase = g_pConCommandVtable . RCast < void * > ( ) ; // 0x00 to ConCommand vtable.
* ( const char * * ) ( pCommandBase + 0x18 ) = pszName ; // 0x18 to ConCommand Name.
* ( const char * * ) ( pCommandBase + 0x20 ) = pszHelpString ; // 0x20 to ConCommand help string.
* ( std : : int32_t * ) ( pCommandBase + 0x38 ) = nFlags ; // 0x38 to ConCommand Flags.
* ( void * * ) ( pCommandBase + 0x40 ) = p_ConCommand_NullSub . RCast < void * > ( ) ; // 0x40 Nullsub since every concommand has it.
* ( void * * ) ( pCommandBase + 0x50 ) = pCallback ; // 0x50 has function callback.
2021-12-25 22:36:38 +01:00
* ( std : : int32_t * ) ( pCommandBase + 0x60 ) = 2 ; // 0x60 Set to use callback and newcommand callback.
if ( pCommandCompletionCallback ) // callback after execution desired?
{
* ( void * * ) ( pCommandBase + 0x58 ) = pCommandCompletionCallback ; // 0x58 to our callback after execution.
}
else
{
* ( void * * ) ( pCommandBase + 0x58 ) = p_ConCommand_CallbackCompletion . RCast < void * > ( ) ; // 0x58 nullsub.
}
p_ConCommand_RegisterConCommand . RCast < void ( * ) ( void * ) > ( ) ( ( void * ) pCommandBase ) ; // Register command in ConVarAccessor.
2022-01-09 16:14:17 +01:00
* this = * pCommand ;
2021-12-25 22:36:38 +01:00
}
//-----------------------------------------------------------------------------
2022-01-09 16:14:17 +01:00
// Purpose: ConCommand registration
2021-12-25 22:36:38 +01:00
//-----------------------------------------------------------------------------
2022-01-09 16:14:17 +01:00
void ConCommand : : Init ( void )
2021-12-25 22:36:38 +01:00
{
//-------------------------------------------------------------------------
// SERVER DLL |
2022-01-09 16:14:17 +01:00
ConCommand * sv_kick = new ConCommand ( " sv_kick " , " Kick a client from the server by name. | Usage: kick <name>. " , 0 , _Kick_f_CompletionFunc , nullptr ) ;
ConCommand * sv_kickid = new ConCommand ( " sv_kickid " , " Kick a client from the server by UserID or OriginID | Usage: kickid <OriginID>/<UserID>. " , 0 , _KickID_f_CompletionFunc , nullptr ) ;
ConCommand * sv_ban = new ConCommand ( " sv_ban " , " Bans a client from the server by name. | Usage: ban <name>. " , 0 , _Ban_f_CompletionFunc , nullptr ) ;
ConCommand * sv_banid = new ConCommand ( " sv_banid " , " Bans a client from the server by OriginID, UserID or IPAddress | Usage: banid <OriginID>/<IPAddress>/<UserID>. " , 0 , _BanID_f_CompletionFunc , nullptr ) ;
ConCommand * sv_unban = new ConCommand ( " sv_unban " , " Unbans a client from the Server by IPAddress or OriginID | Usage: unban <OriginID>/<IPAddress>. " , 0 , _Unban_f_CompletionFunc , nullptr ) ;
ConCommand * sv_reloadbanlist = new ConCommand ( " sv_reloadbanlist " , " Reloads the ban list from the disk. " , 0 , _ReloadBanList_f_CompletionFunc , nullptr ) ;
2021-12-25 22:36:38 +01:00
# ifndef DEDICATED
//-------------------------------------------------------------------------
// CLIENT DLL |
2022-01-09 16:14:17 +01:00
ConCommand * cl_showconsole = new ConCommand ( " cl_showconsole " , " Opens the game console. " , 0 , _CGameConsole_f_CompletionFunc , nullptr ) ;
ConCommand * cl_showbrowser = new ConCommand ( " cl_showbrowser " , " Opens the server browser. " , 0 , _CCompanion_f_CompletionFunc , nullptr ) ;
2021-12-25 22:36:38 +01:00
# endif // !DEDICATED
//-------------------------------------------------------------------------
// FILESYSTEM API |
2022-01-09 16:14:17 +01:00
ConCommand * fs_decompress_pak = new ConCommand ( " fs_decompress_pak " , " Decompresses user specified 'vpk_dir' file. " , 0 , _VPK_Decompress_f_CompletionFunc , nullptr ) ;
2021-12-25 22:36:38 +01:00
//-------------------------------------------------------------------------
// RTECH API |
2022-01-09 16:14:17 +01:00
ConCommand * rtech_strtoguid = new ConCommand ( " rtech_strtoguid " , " Calculates the GUID from input data. " , 0 , _RTech_StringToGUID_f_CompletionFunc , nullptr ) ;
ConCommand * rtech_asyncload = new ConCommand ( " rtech_asyncload " , " Loads user specified 'RPak' file. " , 0 , _RTech_AsyncLoad_f_CompletionFunc , nullptr ) ;
ConCommand * rtech_decompress = new ConCommand ( " rtech_decompress " , " Decompresses user specified 'RPak' file. " , 0 , _RTech_Decompress_f_CompletionFunc , nullptr ) ;
2021-12-25 22:36:38 +01:00
//-------------------------------------------------------------------------
// NETCHANNEL |
2022-01-09 16:14:17 +01:00
ConCommand * net_toggletrace = new ConCommand ( " net_toggletrace " , " Logs the sending and receiving datagram to a file on the disk. " , 0 , _NET_TraceNetChan_f_CompletionFunc , nullptr ) ;
ConCommand * net_setkey = new ConCommand ( " net_setkey " , " Sets user specified base64 net key. " , 0 , _NET_SetKey_f_CompletionFunc , nullptr ) ;
ConCommand * net_generatekey = new ConCommand ( " net_generatekey " , " Generates and sets a random base64 net key. " , 0 , _NET_GenerateKey_f_CompletionFunc , nullptr ) ;
}
//-----------------------------------------------------------------------------
// Purpose: Add's flags to ConCommand.
// Input : nFlags -
//-----------------------------------------------------------------------------
void ConCommandBase : : AddFlags ( int nFlags )
{
m_nFlags | = nFlags ;
}
//-----------------------------------------------------------------------------
// Purpose: Removes flags from ConCommand.
// Input : nFlags -
//-----------------------------------------------------------------------------
void ConCommandBase : : RemoveFlags ( int nFlags )
{
m_nFlags & = ~ nFlags ;
}
//-----------------------------------------------------------------------------
// Purpose: Checks if ConCommand has requested flags.
// Input : nFlags -
// Output : True if ConCommand has nFlags.
//-----------------------------------------------------------------------------
bool ConCommandBase : : HasFlags ( int nFlags )
{
return m_nFlags & nFlags ;
}
//-----------------------------------------------------------------------------
// Purpose: test each ConCommand query before execution.
// Input : *pCommandBase - nFlags
// Output : false if execution is permitted, true if not.
//-----------------------------------------------------------------------------
bool ConCommandBase : : IsFlagSet ( ConCommandBase * pCommandBase , int nFlags )
{
2022-01-09 17:17:05 +01:00
if ( cm_debug_cmdquery - > GetBool ( ) )
2022-01-09 16:14:17 +01:00
{
printf ( " -------------------------------------------------- \n " ) ;
printf ( " Flaged: %08X \n " , pCommandBase - > m_nFlags ) ;
}
// Mask off FCVAR_CHEATS and FCVAR_DEVELOPMENTONLY.
2022-01-09 17:17:05 +01:00
if ( cm_return_false_cmdquery_cheats - > GetBool ( ) )
2022-01-09 16:14:17 +01:00
{
pCommandBase - > RemoveFlags ( FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT ) ;
}
else // Mask off FCVAR_DEVELOPMENTONLY.
{
pCommandBase - > RemoveFlags ( FCVAR_DEVELOPMENTONLY ) ;
}
2022-01-09 17:17:05 +01:00
if ( cm_debug_cmdquery - > GetBool ( ) )
2022-01-09 16:14:17 +01:00
{
printf ( " Masked: %08X \n " , pCommandBase - > m_nFlags ) ;
printf ( " Verify: %08X \n " , nFlags ) ;
printf ( " -------------------------------------------------- \n " ) ;
}
2022-01-10 02:03:31 +01:00
if ( nFlags & FCVAR_RELEASE & & ! cm_return_false_cmdquery_all - > GetBool ( ) )
2022-01-09 16:14:17 +01:00
{
// Default retail behaviour.
return ConCommandBase_IsFlagSet ( pCommandBase , nFlags ) ;
}
2022-01-09 17:17:05 +01:00
if ( cm_return_false_cmdquery_all - > GetBool ( ) )
2022-01-09 16:14:17 +01:00
{
// Returning false on all queries may cause problems.
return false ;
}
// Return false on every FCVAR_DEVELOPMENTONLY || FCVAR_CHEAT query.
return pCommandBase - > HasFlags ( nFlags ) ! = 0 ;
2021-12-25 22:36:38 +01:00
}
void ConCommand_Attach ( )
{
2022-01-09 16:14:17 +01:00
DetourAttach ( ( LPVOID * ) & ConCommandBase_IsFlagSet , & ConCommandBase : : IsFlagSet ) ;
2021-12-25 22:36:38 +01:00
}
void ConCommand_Detach ( )
{
2022-01-09 16:14:17 +01:00
DetourDetach ( ( LPVOID * ) & ConCommandBase_IsFlagSet , & ConCommandBase : : IsFlagSet ) ;
2021-12-25 22:36:38 +01:00
}
2022-01-09 16:14:17 +01:00
ConCommand * g_pConCommand = new ConCommand ( ) ;