Use CBuf_AddText() and Cbuf_Execute() instead

Small improvement
This commit is contained in:
Kawe Mazidjatari 2022-03-25 13:17:57 +01:00
parent 699b1c33a6
commit 96bf41655a
7 changed files with 57 additions and 35 deletions

View File

@ -32,18 +32,25 @@ void __fastcall HFrameStageNotify(CHLClient* rcx, ClientFrameStage_t frameStage)
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2) // !TEMP UNTIL CHOSTSTATE IS BUILD AGNOSTIC! // #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2) // !TEMP UNTIL CHOSTSTATE IS BUILD AGNOSTIC! //
if (!g_pCmdLine->CheckParm("-devsdk")) if (!g_pCmdLine->CheckParm("-devsdk"))
{ {
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_server.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server.cfg\"", cmd_source_t::kCommandSrcCode);
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_client.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server.cfg\"", cmd_source_t::kCommandSrcCode);
IVEngineClient_CommandExecute(NULL, "exec \"autoexec.cfg\""); #ifndef DEDICATED
IVEngineClient_CommandExecute(NULL, "exec \"rcon_client.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_client.cfg\"", cmd_source_t::kCommandSrcCode);
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_client.cfg\"", cmd_source_t::kCommandSrcCode);
#endif // !DEDICATED
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec.cfg\"", cmd_source_t::kCommandSrcCode);
} }
else // Development configs. else // Development configs.
{ {
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_server_dev.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server_dev.cfg\"", cmd_source_t::kCommandSrcCode);
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_client_dev.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server_dev.cfg\"", cmd_source_t::kCommandSrcCode);
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_dev.cfg\""); #ifndef DEDICATED
IVEngineClient_CommandExecute(NULL, "exec \"rcon_client_dev.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_client_dev.cfg\"", cmd_source_t::kCommandSrcCode);
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_client_dev.cfg\"", cmd_source_t::kCommandSrcCode);
#endif // !DEDICATED
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_dev.cfg\"", cmd_source_t::kCommandSrcCode);
} }
Cbuf_Execute();
*(bool*)m_bRestrictServerCommands = true; // Restrict commands. *(bool*)m_bRestrictServerCommands = true; // Restrict commands.
ConCommandBase* disconnect = (ConCommandBase*)g_pCVar->FindCommand("disconnect"); ConCommandBase* disconnect = (ConCommandBase*)g_pCVar->FindCommand("disconnect");

View File

@ -34,7 +34,6 @@
#endif // !GAMECLIENTONLY #endif // !GAMECLIENTONLY
bool g_bLevelResourceInitialized = false; bool g_bLevelResourceInitialized = false;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: state machine's main processing loop // Purpose: state machine's main processing loop
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -73,7 +72,7 @@ FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
{ {
case HostStates_t::HS_NEW_GAME: case HostStates_t::HS_NEW_GAME:
{ {
DevMsg(eDLL_T::ENGINE, "Loading level: '%s'\n", g_pHostState->m_levelName); DevMsg(eDLL_T::ENGINE, "%s - Loading level: '%s'\n", "CHostState::FrameUpdate", g_pHostState->m_levelName);
g_pHostState->State_NewGame(); g_pHostState->State_NewGame();
break; break;
} }
@ -95,7 +94,7 @@ FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
} }
case HostStates_t::HS_GAME_SHUTDOWN: case HostStates_t::HS_GAME_SHUTDOWN:
{ {
DevMsg(eDLL_T::ENGINE, "Shutdown host game\n"); DevMsg(eDLL_T::ENGINE, "%s - Shutdown host game\n", "CHostState::FrameUpdate");
g_bLevelResourceInitialized = false; g_bLevelResourceInitialized = false;
Host_Game_ShutdownFn(g_pHostState); Host_Game_ShutdownFn(g_pHostState);
@ -103,7 +102,7 @@ FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
} }
case HostStates_t::HS_RESTART: case HostStates_t::HS_RESTART:
{ {
DevMsg(eDLL_T::ENGINE, "Restarting state machine\n"); DevMsg(eDLL_T::ENGINE, "%s - Restarting state machine\n", "CHostState::FrameUpdate");
g_bLevelResourceInitialized = false; g_bLevelResourceInitialized = false;
#ifndef DEDICATED #ifndef DEDICATED
CL_EndMovieFn(); CL_EndMovieFn();
@ -114,7 +113,7 @@ FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
} }
case HostStates_t::HS_SHUTDOWN: case HostStates_t::HS_SHUTDOWN:
{ {
DevMsg(eDLL_T::ENGINE, "Shutdown state machine\n"); DevMsg(eDLL_T::ENGINE, "%s - Shutdown state machine\n", "CHostState::FrameUpdate");
g_bLevelResourceInitialized = false; g_bLevelResourceInitialized = false;
#ifndef DEDICATED #ifndef DEDICATED
CL_EndMovieFn(); CL_EndMovieFn();
@ -196,24 +195,25 @@ FORCEINLINE void CHostState::LoadConfig(void) const
{ {
if (!g_pCmdLine->CheckParm("-devsdk")) if (!g_pCmdLine->CheckParm("-devsdk"))
{ {
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_server.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server.cfg\"", cmd_source_t::kCommandSrcCode);
IVEngineClient_CommandExecute(NULL, "exec \"rcon_server.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server.cfg\"", cmd_source_t::kCommandSrcCode);
#ifndef DEDICATED #ifndef DEDICATED
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_client.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_client.cfg\"", cmd_source_t::kCommandSrcCode);
IVEngineClient_CommandExecute(NULL, "exec \"rcon_client.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_client.cfg\"", cmd_source_t::kCommandSrcCode);
#endif // !DEDICATED #endif // !DEDICATED
IVEngineClient_CommandExecute(NULL, "exec \"autoexec.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec.cfg\"", cmd_source_t::kCommandSrcCode);
} }
else // Development configs. else // Development configs.
{ {
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_server_dev.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server_dev.cfg\"", cmd_source_t::kCommandSrcCode);
IVEngineClient_CommandExecute(NULL, "exec \"rcon_server_dev.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server_dev.cfg\"", cmd_source_t::kCommandSrcCode);
#ifndef DEDICATED #ifndef DEDICATED
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_client_dev.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_client_dev.cfg\"", cmd_source_t::kCommandSrcCode);
IVEngineClient_CommandExecute(NULL, "exec \"rcon_client_dev.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_client_dev.cfg\"", cmd_source_t::kCommandSrcCode);
#endif // !DEDICATED #endif // !DEDICATED
IVEngineClient_CommandExecute(NULL, "exec \"autoexec_dev.cfg\""); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_dev.cfg\"", cmd_source_t::kCommandSrcCode);
} }
Cbuf_Execute();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -265,7 +265,7 @@ FORCEINLINE void CHostState::State_NewGame(void)
if (!CModelLoader_Map_IsValidFn(g_CModelLoader, m_levelName) // Check if map is valid and if we can start a new game. if (!CModelLoader_Map_IsValidFn(g_CModelLoader, m_levelName) // Check if map is valid and if we can start a new game.
|| !Host_NewGameFn(m_levelName, nullptr, m_bBackgroundLevel, m_bSplitScreenConnect, nullptr) || !g_ServerGameClients) || !Host_NewGameFn(m_levelName, nullptr, m_bBackgroundLevel, m_bSplitScreenConnect, nullptr) || !g_ServerGameClients)
{ {
Error(eDLL_T::ENGINE, "Error: Map not valid\n"); Error(eDLL_T::ENGINE, "%s - Error: Map not valid\n", "CHostState::State_NewGame");
#ifndef DEDICATED #ifndef DEDICATED
SCR_EndLoadingPlaque(); SCR_EndLoadingPlaque();
#endif // !DEDICATED #endif // !DEDICATED
@ -286,7 +286,7 @@ FORCEINLINE void CHostState::State_NewGame(void)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
FORCEINLINE void CHostState::State_ChangeLevelSP(void) FORCEINLINE void CHostState::State_ChangeLevelSP(void)
{ {
DevMsg(eDLL_T::ENGINE, "Changing singleplayer level to: '%s'\n", m_levelName); DevMsg(eDLL_T::ENGINE, "%s - Changing singleplayer level to: '%s'\n", "CHostState::State_ChangeLevelSP", m_levelName);
m_flShortFrameTime = 1.5; // Set frame time. m_flShortFrameTime = 1.5; // Set frame time.
g_bLevelResourceInitialized = false; g_bLevelResourceInitialized = false;
@ -296,7 +296,7 @@ FORCEINLINE void CHostState::State_ChangeLevelSP(void)
} }
else else
{ {
Error(eDLL_T::ENGINE, "Error: Unable to find map: '%s'\n", m_levelName); Error(eDLL_T::ENGINE, "%s - Error: Unable to find map: '%s'\n", "CHostState::State_ChangeLevelSP", m_levelName);
} }
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run. m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.
@ -313,7 +313,7 @@ FORCEINLINE void CHostState::State_ChangeLevelSP(void)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
FORCEINLINE void CHostState::State_ChangeLevelMP(void) FORCEINLINE void CHostState::State_ChangeLevelMP(void)
{ {
DevMsg(eDLL_T::ENGINE, "Changing multiplayer level to: '%s'\n", m_levelName); DevMsg(eDLL_T::ENGINE, "%s - Changing multiplayer level to: '%s'\n", "CHostState::State_ChangeLevelMP", m_levelName);
m_flShortFrameTime = 0.5; // Set frame time. m_flShortFrameTime = 0.5; // Set frame time.
g_bLevelResourceInitialized = false; g_bLevelResourceInitialized = false;
@ -330,7 +330,7 @@ FORCEINLINE void CHostState::State_ChangeLevelMP(void)
} }
else else
{ {
Error(eDLL_T::ENGINE, "Error: Unable to find map: '%s'\n", m_levelName); Error(eDLL_T::ENGINE, "%s - Error: Unable to find map: '%s'\n", "CHostState::State_ChangeLevelMP", m_levelName);
} }
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run. m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.

View File

@ -15,7 +15,6 @@
#include "protoc/sv_rcon.pb.h" #include "protoc/sv_rcon.pb.h"
#include "protoc/cl_rcon.pb.h" #include "protoc/cl_rcon.pb.h"
#include "mathlib/sha256.h" #include "mathlib/sha256.h"
#include "client/IVEngineClient.h"
#include "common/igameserverdata.h" #include "common/igameserverdata.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -390,7 +389,9 @@ void CRConServer::Execute(const cl_rcon::request& cl_request) const
else // Execute command with "<val>". else // Execute command with "<val>".
{ {
std::string svExec = cl_request.requestbuf() + " \"" + cl_request.requestval() + "\""; std::string svExec = cl_request.requestbuf() + " \"" + cl_request.requestval() + "\"";
IVEngineClient_CommandExecute(NULL, svExec.c_str());
Cbuf_AddText(Cbuf_GetCurrentPlayer(), svExec.c_str(), cmd_source_t::kCommandSrcCode);
Cbuf_Execute();
} }
} }

View File

@ -663,7 +663,7 @@ int CConsole::TextEditCallbackStub(ImGuiInputTextCallbackData* iData)
void CConsole::AddLog(const char* fmt, ...) IM_FMTARGS(2) void CConsole::AddLog(const char* fmt, ...) IM_FMTARGS(2)
{ {
char buf[1024]; char buf[1024];
va_list args; va_list args{};
va_start(args, fmt); va_start(args, fmt);
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0; buf[IM_ARRAYSIZE(buf) - 1] = 0;

View File

@ -295,6 +295,16 @@ char* ConCommandBase::CopyString(const char* szFrom) const
return szTo; return szTo;
} }
//-----------------------------------------------------------------------------
// Purpose: Returns current player calling this function
// Output : ECommandTarget_t -
//-----------------------------------------------------------------------------
ECommandTarget_t Cbuf_GetCurrentPlayer(void)
{
// Always returns 'CBUF_FIRST_PLAYER' in Respawn's code.
return ECommandTarget_t::CBUF_FIRST_PLAYER;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void ConCommand_Attach() void ConCommand_Attach()
{ {

View File

@ -131,8 +131,8 @@ public:
namespace namespace
{ {
/* ==== COMMAND_BUFFER ================================================================================================================================================== */ /* ==== COMMAND_BUFFER ================================================================================================================================================== */
ADDRESS p_Cbuf_AddText = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x44\x89\x4C\x24\x00\x48\x89\x4C\x24\x00\x55\x56\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x81\xEC\x00\x00\x00\x00\x48\x8D\x6C\x24\x00\x48\x89\x9D\x00\x00\x00\x00\x4C\x8B", "xxxx?xxxx?xxxxxxxxxxxxxx????xxxx?xxx????xx"); ADDRESS p_Cbuf_AddText = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x20\x48\x63\xD9\x41\x8B\xF8\x48\x8D\x0D\x00\x00\x00\x00\x48\x8B\xF2\xFF\x15\x00\x00\x00\x00\x48\x8D\x05\x00\x00\x00\x00\x41\xB9\x00\x00\x00\x00", "xxxx?xxxx?xxxxxxxxxxxxxx????xxxxx????xxx????xx????");
bool (*Cbuf_AddText)(ECommandTarget_t eTarget, const char* pText, cmd_source_t cmdSource, int nTickDelay) = (bool (*)(ECommandTarget_t, const char*, cmd_source_t, int))p_Cbuf_AddText.GetPtr(); /*44 89 4C 24 ? 48 89 4C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 48 8D 6C 24 ? 48 89 9D ? ? ? ? 4C 8B*/ void (*Cbuf_AddText)(ECommandTarget_t eTarget, const char* pText, cmd_source_t cmdSource) = (void (*)(ECommandTarget_t, const char*, cmd_source_t))p_Cbuf_AddText.GetPtr(); /*48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC 20 48 63 D9 41 8B F8 48 8D 0D ? ? ? ? 48 8B F2 FF 15 ? ? ? ? 48 8D 05 ? ? ? ? 41 B9 ? ? ? ?*/
ADDRESS p_Cbuf_Execute = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x20\xFF\x15\x00\x00\x00\x00", "xxxx?xxxx?xxxx?xxxxxxx????"); ADDRESS p_Cbuf_Execute = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x20\xFF\x15\x00\x00\x00\x00", "xxxx?xxxx?xxxx?xxxxxxx????");
void (*Cbuf_Execute)(void) = (void (*)(void))p_Cbuf_Execute.GetPtr(); /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 20 FF 15 ? ? ? ?*/ void (*Cbuf_Execute)(void) = (void (*)(void))p_Cbuf_Execute.GetPtr(); /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 20 FF 15 ? ? ? ?*/
@ -157,6 +157,8 @@ namespace
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
ECommandTarget_t Cbuf_GetCurrentPlayer(void);
void ConCommand_Attach(); void ConCommand_Attach();
void ConCommand_Detach(); void ConCommand_Detach();

View File

@ -7,11 +7,11 @@
#include "core/stdafx.h" #include "core/stdafx.h"
#include "core/init.h" #include "core/init.h"
#include "core/logdef.h" #include "core/logdef.h"
#include "tier0/cmd.h"
#ifndef DEDICATED #ifndef DEDICATED
#include "windows/id3dx.h" #include "windows/id3dx.h"
#endif // !DEDICATED #endif // !DEDICATED
#include "windows/console.h" #include "windows/console.h"
#include "client/IVEngineClient.h"
#include "common/opcodes.h" #include "common/opcodes.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -145,7 +145,9 @@ DWORD __stdcall ProcessConsoleWorker(LPVOID)
if (sCommand == "opcodes test") { RuntimePtc_Toggle(); continue; } if (sCommand == "opcodes test") { RuntimePtc_Toggle(); continue; }
// Execute the command in the r5 SQVM // Execute the command in the r5 SQVM
IVEngineClient_CommandExecute(NULL, sCommand.c_str()); Cbuf_AddText(Cbuf_GetCurrentPlayer(), sCommand.c_str(), cmd_source_t::kCommandSrcCode);
Cbuf_Execute();
sCommand.clear(); sCommand.clear();
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////