CConsole: heavy cleanup

* Move all default assignments to constructor.
* Rename cvar 'con_max_size_logvector' to 'con_max_lines'.
* Rename cvar 'con_max_size_history' to 'con_max_history'.
* Use array indexes instead of hardcoding context prefixes.
* Added netcon context prefix to help legend.
* Added public method to obtain history as string vector.
* Added public method to clear history.
* Internal CConsole::AddLog no longer locks the mutex.
* CConsole::LoadFlagIcons accesses resource vector by reference.
* Implemented "HELP", "HISTORY" and "CLEAR" as real console commands: "con_help", "con_history", "con_clearlines".
* Added a new command "con_clearhistory" (clears the dev console submission history).
This commit is contained in:
Kawe Mazidjatari 2022-10-19 16:10:36 +02:00
parent d113774a6d
commit 44f2f87460
8 changed files with 239 additions and 146 deletions

View File

@ -21,24 +21,57 @@ History:
#include "windows/id3dx.h"
#include "windows/console.h"
#include "windows/resource.h"
#include "squirrel/sqtype.h"
#include "gameui/IConsole.h"
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CConsole::CConsole(void)
CConsole::CConsole(void)
: m_pszConsoleLabel("Console")
, m_pszLoggingLabel("LoggingRegion")
, m_nHistoryPos(-1)
, m_nSuggestPos(-1)
, m_nScrollBack(0)
, m_nSelectBack(0)
, m_flScrollX(0.f)
, m_flScrollY(0.f)
, m_flFadeAlpha(0.f)
, m_bInitialized(false)
, m_bReclaimFocus(false)
, m_bCopyToClipBoard(false)
, m_bModifyInput(false)
, m_bCanAutoComplete(false)
, m_bSuggestActive(false)
, m_bSuggestMoved(false)
, m_bSuggestUpdate(false)
, m_bActivate(false)
, m_Style(ImGuiStyle_t::NONE)
{
m_nInputFlags =
ImGuiInputTextFlags_EnterReturnsTrue |
ImGuiInputTextFlags_CallbackCompletion |
ImGuiInputTextFlags_CallbackHistory |
ImGuiInputTextFlags_CallbackAlways |
ImGuiInputTextFlags_CallbackEdit |
ImGuiInputTextFlags_AutoCaretEnd;
m_nSuggestFlags =
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_AlwaysVerticalScrollbar |
ImGuiWindowFlags_AlwaysHorizontalScrollbar;
m_nLoggingFlags =
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_HorizontalScrollbar |
ImGuiWindowFlags_AlwaysVerticalScrollbar;
memset(m_szInputBuf, '\0', sizeof(m_szInputBuf));
m_nHistoryPos = -1;
m_bInitialized = false;
m_pszConsoleLabel = "Console";
m_pszLoggingLabel = "LoggingRegion";
m_vCommands.push_back("CLEAR");
m_vCommands.push_back("HELP");
m_vCommands.push_back("HISTORY");
memset(m_szWindowLabel, '\0', sizeof(m_szWindowLabel));
snprintf(m_szSummary, sizeof(m_szSummary), "%zu history items", m_vHistory.size());
}
@ -138,6 +171,9 @@ void CConsole::RunFrame(void)
//-----------------------------------------------------------------------------
void CConsole::RunTask()
{
// m_Logger and m_vHistory are modified.
std::lock_guard<std::mutex> l(m_Mutex);
ClampLogSize();
ClampHistorySize();
}
@ -211,7 +247,9 @@ void CConsole::DrawSurface(void)
///////////////////////////////////////////////////////////////////////
ImGui::BeginChild(m_pszLoggingLabel, ImVec2(0, -flFooterHeightReserve), true, m_nLoggingFlags);
m_Mutex.lock();
// Mutex is locked here, as we start using/modifying
// non-atomic members that are used from several threads.
std::lock_guard<std::mutex> l(m_Mutex);
m_Logger.Render();
if (m_bCopyToClipBoard)
@ -219,15 +257,14 @@ void CConsole::DrawSurface(void)
m_Logger.Copy(true);
m_bCopyToClipBoard = false;
}
m_Mutex.unlock();
m_flScrollX = ImGui::GetScrollX();
m_flScrollY = ImGui::GetScrollY();
///////////////////////////////////////////////////////////////////////
ImGui::EndChild();
ImGui::Separator();
///////////////////////////////////////////////////////////////////////
ImGui::PushItemWidth(flFooterWidthReserve - 80);
if (ImGui::InputText("##input", m_szInputBuf, IM_ARRAYSIZE(m_szInputBuf), m_nInputFlags, &TextEditCallbackStub, reinterpret_cast<void*>(this)))
{
@ -328,12 +365,12 @@ void CConsole::SuggestPanel(void)
for (size_t i = 0; i < m_vSuggest.size(); i++)
{
bool bIsIndexActive = m_nSuggestPos == i;
const bool bIsIndexActive = m_nSuggestPos == i;
ImGui::PushID(static_cast<int>(i));
if (con_suggestion_showflags->GetBool())
{
int k = ColorCodeFlags(m_vSuggest[i].m_nFlags);
const int k = ColorCodeFlags(m_vSuggest[i].m_nFlags);
ImGui::Image(m_vFlagIcons[k].m_idIcon, ImVec2(m_vFlagIcons[k].m_nWidth, m_vFlagIcons[k].m_nHeight));
ImGui::SameLine();
}
@ -343,10 +380,14 @@ void CConsole::SuggestPanel(void)
ImGui::Separator();
// Remove the default value from ConVar before assigning it to the input buffer.
string svConVar = m_vSuggest[i].m_svName.substr(0, m_vSuggest[i].m_svName.find(' ')) + ' ';
memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1);
const string svConVar = m_vSuggest[i].m_svName.substr(0, m_vSuggest[i].m_svName.find(' ')) + ' ';
memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1);
ResetAutoComplete();
// Mutex lock is obtained here are we modify m_vHistory
// which is used in the main and render thread.
std::lock_guard<std::mutex> l(m_Mutex);
BuildSummary(svConVar);
}
ImGui::PopID();
@ -447,22 +488,22 @@ void CConsole::FindFromPartial(void)
{
ClearAutoComplete();
for (size_t i = 0; i < m_vsvCommandBases.size(); i++)
for (const CSuggest& suggest : m_vsvCommandBases)
{
if (m_vSuggest.size() >= con_suggestion_limit->GetSizeT())
{
return;
}
if (m_vsvCommandBases[i].m_svName.find(m_szInputBuf) == string::npos)
if (suggest.m_svName.find(m_szInputBuf) == string::npos)
{
continue;
}
if (std::find(m_vSuggest.begin(), m_vSuggest.end(),
m_vsvCommandBases[i].m_svName) == m_vSuggest.end())
suggest.m_svName) == m_vSuggest.end())
{
string svValue; int nFlags = FCVAR_NONE;
const ConCommandBase* pCommandBase = g_pCVar->FindCommandBase(m_vsvCommandBases[i].m_svName.c_str());
const ConCommandBase* pCommandBase = g_pCVar->FindCommandBase(suggest.m_svName.c_str());
if (!pCommandBase || pCommandBase->IsFlagSet(FCVAR_HIDDEN))
{
@ -504,13 +545,14 @@ void CConsole::FindFromPartial(void)
}
else // Display compile-time flags instead.
{
nFlags = m_vsvCommandBases[i].m_nFlags;
nFlags = suggest.m_nFlags;
}
}
m_vSuggest.push_back(CSuggest(m_vsvCommandBases[i].m_svName + svValue, nFlags));
m_vSuggest.push_back(CSuggest(suggest.m_svName + svValue, nFlags));
}
else { break; }
}
std::sort(m_vSuggest.begin(), m_vSuggest.end());
}
@ -520,13 +562,11 @@ void CConsole::FindFromPartial(void)
//-----------------------------------------------------------------------------
void CConsole::ProcessCommand(const char* pszCommand)
{
DevMsg(eDLL_T::COMMON, "] %s\n", pszCommand);
AddLog(ImVec4(1.00f, 0.80f, 0.60f, 1.00f), "] %s\n", pszCommand);
Cbuf_AddText(Cbuf_GetCurrentPlayer(), pszCommand, cmd_source_t::kCommandSrcCode);
//g_TaskScheduler->Dispatch(Cbuf_Execute, 0); // Run in main thread.
m_nHistoryPos = -1;
for (size_t i = m_vHistory.size(); i-- > 0; )
for (size_t i = m_vHistory.size(); i-- > 0;)
{
if (m_vHistory[i].compare(pszCommand) == 0)
{
@ -536,41 +576,6 @@ void CConsole::ProcessCommand(const char* pszCommand)
}
m_vHistory.push_back(Strdup(pszCommand));
if (Stricmp(pszCommand, "CLEAR") == 0)
{
ClearLog();
}
else if (Stricmp(pszCommand, "HELP") == 0)
{
AddLog(ImVec4(0.81f, 0.81f, 0.81f, 1.00f), "Commands:\n");
for (size_t i = 0; i < m_vCommands.size(); i++)
{
AddLog(ImVec4(0.81f, 0.81f, 0.81f, 1.00f), "- %s\n", m_vCommands[i].c_str());
}
AddLog(ImVec4(0.81f, 0.81f, 0.81f, 1.00f), "Contexts:\n");
AddLog(ImVec4(0.59f, 0.58f, 0.73f, 1.00f), "- Script(S): = Server DLL (Script)\n");
AddLog(ImVec4(0.59f, 0.58f, 0.63f, 1.00f), "- Script(C): = Client DLL (Script)\n");
AddLog(ImVec4(0.59f, 0.48f, 0.53f, 1.00f), "- Script(U): = UI DLL (Script)\n");
AddLog(ImVec4(0.23f, 0.47f, 0.85f, 1.00f), "- Native(S): = Server DLL (Code)\n");
AddLog(ImVec4(0.46f, 0.46f, 0.46f, 1.00f), "- Native(C): = Client DLL (Code)\n");
AddLog(ImVec4(0.59f, 0.35f, 0.46f, 1.00f), "- Native(U): = UI DLL (Code)\n");
AddLog(ImVec4(0.70f, 0.70f, 0.70f, 1.00f), "- Native(E): = Engine DLL (Code)\n");
AddLog(ImVec4(0.32f, 0.64f, 0.72f, 1.00f), "- Native(F): = FileSystem (Code)\n");
AddLog(ImVec4(0.36f, 0.70f, 0.35f, 1.00f), "- Native(R): = PakLoadAPI (Code)\n");
AddLog(ImVec4(0.75f, 0.41f, 0.67f, 1.00f), "- Native(M): = MaterialSystem (Code)\n");
}
else if (Stricmp(pszCommand, "HISTORY") == 0)
{
ssize_t nFirst = static_cast<ssize_t>(m_vHistory.size()) - 10;
for (ssize_t i = nFirst > 0 ? nFirst : 0; i < static_cast<ssize_t>(m_vHistory.size()); i++)
{
AddLog(ImVec4(0.81f, 0.81f, 0.81f, 1.00f), "%3d: %s\n", i, m_vHistory[i].c_str());
}
}
m_Logger.m_bScrollToBottom = true;
}
@ -582,16 +587,16 @@ void CConsole::BuildSummary(string svConVar)
{
if (!svConVar.empty())
{
for (size_t i = 0; i < svConVar.size(); i++)
for (size_t i = 0, s = svConVar.size(); i < s; i++)
{
if (svConVar[i] == ' ' || svConVar[i] == ';')
const char c = svConVar[i];
if (c == ' ' || c == ';')
{
svConVar.erase(i, svConVar.length() - 1); // Remove space or semicolon before we call 'g_pCVar->FindVar(..)'.
}
}
ConVar* pConVar = g_pCVar->FindVar(svConVar.c_str());
if (pConVar)
if (const ConVar* pConVar = g_pCVar->FindVar(svConVar.c_str()))
{
// Display the current and default value of ConVar if found.
snprintf(m_szSummary, sizeof(m_szSummary), "(\"%s\", default \"%s\")", pConVar->GetString(), pConVar->GetDefault());
@ -616,7 +621,7 @@ void CConsole::BuildSummary(string svConVar)
void CConsole::BuildSuggestPanelRect(void)
{
float flSinglePadding = 0.f;
float flItemHeight = ImGui::GetTextLineHeightWithSpacing() + 1.0f;
const float flItemHeight = ImGui::GetTextLineHeightWithSpacing() + 1.0f;
if (m_vSuggest.size() > 1)
{
@ -627,7 +632,9 @@ void CConsole::BuildSuggestPanelRect(void)
m_ivSuggestWindowPos = ImGui::GetItemRectMin();
m_ivSuggestWindowPos.y += ImGui::GetItemRectSize().y;
float flWindowHeight = (flSinglePadding + std::clamp(static_cast<float>(m_vSuggest.size()) * (flItemHeight), 37.0f, 127.5f));
const float flWindowHeight = (flSinglePadding + std::clamp(
static_cast<float>(m_vSuggest.size()) * (flItemHeight), 37.0f, 127.5f));
m_ivSuggestWindowSize = ImVec2(600, flWindowHeight);
}
@ -636,10 +643,11 @@ void CConsole::BuildSuggestPanelRect(void)
//-----------------------------------------------------------------------------
void CConsole::ClampLogSize(void)
{
std::lock_guard<std::mutex> l(m_Mutex);
if (m_Logger.GetTotalLines() > con_max_size_logvector->GetInt())
const int nMaxLines = con_max_lines->GetInt();
if (m_Logger.GetTotalLines() > nMaxLines)
{
while (m_Logger.GetTotalLines() > con_max_size_logvector->GetInt())
while (m_Logger.GetTotalLines() > nMaxLines)
{
m_Logger.RemoveLine(0);
m_nScrollBack++;
@ -656,7 +664,7 @@ void CConsole::ClampLogSize(void)
//-----------------------------------------------------------------------------
void CConsole::ClampHistorySize(void)
{
while (m_vHistory.size() > con_max_size_history->GetSizeT())
while (m_vHistory.size() > con_max_history->GetSizeT())
{
m_vHistory.erase(m_vHistory.begin());
}
@ -668,22 +676,20 @@ void CConsole::ClampHistorySize(void)
//-----------------------------------------------------------------------------
bool CConsole::LoadFlagIcons(void)
{
int k = 0; // Get all image resources for displaying flags.
for (int i = IDB_PNG3; i <= IDB_PNG24; i++)
{
m_vFlagIcons.push_back(MODULERESOURCE());
m_vFlagIcons[k] = GetModuleResource(i);
bool ret = false;
bool ret = LoadTextureBuffer(reinterpret_cast<unsigned char*>(m_vFlagIcons[k].m_pData), static_cast<int>(m_vFlagIcons[k].m_nSize),
&m_vFlagIcons[k].m_idIcon, &m_vFlagIcons[k].m_nWidth, &m_vFlagIcons[k].m_nHeight);
if (!ret)
{
IM_ASSERT(ret);
return false;
}
k++;
// Get all image resources for displaying flags.
for (int i = IDB_PNG3, k = NULL; i <= IDB_PNG24; i++, k++)
{
m_vFlagIcons.push_back(MODULERESOURCE(GetModuleResource(i)));
MODULERESOURCE& rFlagIcon = m_vFlagIcons[k];
ret = LoadTextureBuffer(reinterpret_cast<unsigned char*>(rFlagIcon.m_pData),
static_cast<int>(rFlagIcon.m_nSize), &rFlagIcon.m_idIcon, &rFlagIcon.m_nWidth, &rFlagIcon.m_nHeight);
IM_ASSERT(ret);
}
return true;
return ret;
}
//-----------------------------------------------------------------------------
@ -899,7 +905,9 @@ void CConsole::AddLog(const ConLog_t& conLog)
//-----------------------------------------------------------------------------
// Purpose: adds logs to the vector (internal)
// Input : *fmt -
// Only call when mutex lock is obtained!
// Input : &color -
// *fmt -
// ... -
//-----------------------------------------------------------------------------
void CConsole::AddLog(const ImVec4& color, const char* fmt, ...) IM_FMTARGS(2)
@ -911,7 +919,6 @@ void CConsole::AddLog(const ImVec4& color, const char* fmt, ...) IM_FMTARGS(2)
buf[IM_ARRAYSIZE(buf) - 1] = 0;
va_end(args);
std::lock_guard<std::mutex> l(m_Mutex);
m_Logger.InsertText(ConLog_t(Strdup(buf), color));
}
@ -966,6 +973,26 @@ void CConsole::ClearLog(void)
m_Logger.RemoveLine(0, (m_Logger.GetTotalLines() - 1));
}
//-----------------------------------------------------------------------------
// Purpose: gets all console submissions
// Output : vector of strings
//-----------------------------------------------------------------------------
vector<string> CConsole::GetHistory(void)
{
std::lock_guard<std::mutex> l(m_Mutex);
return m_vHistory;
}
//-----------------------------------------------------------------------------
// Purpose: clears the entire submission history vector
//-----------------------------------------------------------------------------
void CConsole::ClearHistory(void)
{
std::lock_guard<std::mutex> l(m_Mutex);
m_vHistory.clear();
BuildSummary();
}
//-----------------------------------------------------------------------------
// Purpose: sets the console front-end style
//-----------------------------------------------------------------------------

View File

@ -48,71 +48,58 @@ private:
public:
void AddLog(const ConLog_t& conLog);
void RemoveLog(int nStart, int nEnd);
private:
void AddLog(const ImVec4& color, const char* fmt, ...) IM_FMTARGS(2);
void ClearLog(void);
vector<string> GetHistory(void);
void ClearHistory(void);
private: // Internal only.
void AddLog(const ImVec4& color, const char* fmt, ...) IM_FMTARGS(2);
///////////////////////////////////////////////////////////////////////////
virtual void SetStyleVar(void);
private:
///////////////////////////////////////////////////////////////////////////
const char* m_pszConsoleLabel = nullptr;
const char* m_pszLoggingLabel = nullptr;
char m_szInputBuf[512] = { '\0' };
char m_szSummary[512] = { '\0' };
char m_szWindowLabel[512] = { '\0' };
const char* m_pszConsoleLabel;
const char* m_pszLoggingLabel;
char m_szInputBuf[512];
char m_szSummary[512];
char m_szWindowLabel[512];
vector<string> m_vCommands;
vector<string> m_vHistory;
string m_svInputConVar;
ssize_t m_nHistoryPos = -1;
int m_nScrollBack = 0;
int m_nSelectBack = 0;
float m_flScrollX = 0.f;
float m_flScrollY = 0.f;
float m_flFadeAlpha = 0.f;
ssize_t m_nHistoryPos;
ssize_t m_nSuggestPos;
int m_nScrollBack;
int m_nSelectBack;
float m_flScrollX;
float m_flScrollY;
float m_flFadeAlpha;
bool m_bInitialized = false;
bool m_bReclaimFocus = false;
bool m_bCopyToClipBoard = false;
bool m_bModifyInput = false;
bool m_bInitialized;
bool m_bReclaimFocus;
bool m_bCopyToClipBoard;
bool m_bModifyInput;
bool m_bCanAutoComplete;
bool m_bSuggestActive;
bool m_bSuggestMoved;
bool m_bSuggestUpdate;
bool m_bCanAutoComplete = false;
bool m_bSuggestActive = false;
bool m_bSuggestMoved = false;
bool m_bSuggestUpdate = false;
ssize_t m_nSuggestPos = -1;
vector<CSuggest> m_vSuggest;
vector<MODULERESOURCE> m_vFlagIcons;
vector<string> m_vHistory;
ImGuiStyle_t m_Style = ImGuiStyle_t::NONE;
ImGuiStyle_t m_Style;
ImVec2 m_ivSuggestWindowPos;
ImVec2 m_ivSuggestWindowSize;
CTextLogger m_Logger;
mutable std::mutex m_Mutex;
ImGuiInputTextFlags m_nInputFlags =
ImGuiInputTextFlags_AutoCaretEnd |
ImGuiInputTextFlags_CallbackCompletion |
ImGuiInputTextFlags_CallbackHistory |
ImGuiInputTextFlags_CallbackAlways |
ImGuiInputTextFlags_CallbackEdit |
ImGuiInputTextFlags_EnterReturnsTrue;
ImGuiInputTextFlags m_nInputFlags;
ImGuiWindowFlags m_nSuggestFlags;
ImGuiWindowFlags m_nLoggingFlags;
ImGuiWindowFlags m_nSuggestFlags =
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_AlwaysVerticalScrollbar |
ImGuiWindowFlags_AlwaysHorizontalScrollbar;
ImGuiWindowFlags m_nLoggingFlags =
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_HorizontalScrollbar |
ImGuiWindowFlags_AlwaysVerticalScrollbar;
public:
bool m_bActivate = false;
vector<CSuggest> m_vsvCommandBases;

View File

@ -175,12 +175,12 @@ void ConVar::Init(void) const
con_notify_warning_clr = ConVar::Create("con_notify_warning_clr", "180 180 20 255", FCVAR_MATERIAL_SYSTEM_THREAD, "Warning RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr);
con_notify_error_clr = ConVar::Create("con_notify_error_clr" , "225 20 20 255" , FCVAR_MATERIAL_SYSTEM_THREAD, "Error RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr);
con_max_size_logvector = ConVar::Create("con_max_size_logvector" , "1024", FCVAR_DEVELOPMENTONLY, "Maximum number of logs in the console before cleanup starts.", true, 1.f, false, 0.f, nullptr, nullptr);
con_max_size_history = ConVar::Create("con_max_size_history" , "512" , FCVAR_DEVELOPMENTONLY, "Maximum number of command history items before cleanup starts.", true, 0.f, false, 0.f, nullptr, nullptr);
con_suggestion_limit = ConVar::Create("con_suggestion_limit" , "128" , FCVAR_DEVELOPMENTONLY, "Maximum number of suggestions the autocomplete window will show for the console.", true, 0.f, false, 0.f, nullptr, nullptr);
con_suggestion_showhelptext = ConVar::Create("con_suggestion_showhelptext" , "1" , FCVAR_DEVELOPMENTONLY, "Show CommandBase help text in autocomplete window.", false, 0.f, false, 0.f, nullptr, nullptr);
con_suggestion_showflags = ConVar::Create("con_suggestion_showflags" , "1" , FCVAR_DEVELOPMENTONLY, "Show CommandBase flags in autocomplete window.", false, 0.f, false, 0.f, nullptr, nullptr);
con_suggestion_flags_realtime = ConVar::Create("con_suggestion_flags_realtime" , "1" , FCVAR_DEVELOPMENTONLY, "Whether to show compile-time or run-time CommandBase flags.", false, 0.f, false, 0.f, nullptr, nullptr);
con_max_lines = ConVar::Create("con_max_lines" , "1024", FCVAR_DEVELOPMENTONLY, "Maximum number of lines in the console before cleanup starts.", true, 1.f, false, 0.f, nullptr, nullptr);
con_max_history = ConVar::Create("con_max_history" , "512" , FCVAR_DEVELOPMENTONLY, "Maximum number of command submission items before history cleanup starts.", true, 0.f, false, 0.f, nullptr, nullptr);
con_suggestion_limit = ConVar::Create("con_suggestion_limit" , "128" , FCVAR_DEVELOPMENTONLY, "Maximum number of suggestions the autocomplete window will show for the console.", true, 0.f, false, 0.f, nullptr, nullptr);
con_suggestion_showhelptext = ConVar::Create("con_suggestion_showhelptext" , "1" , FCVAR_DEVELOPMENTONLY, "Show CommandBase help text in autocomplete window.", false, 0.f, false, 0.f, nullptr, nullptr);
con_suggestion_showflags = ConVar::Create("con_suggestion_showflags" , "1" , FCVAR_DEVELOPMENTONLY, "Show CommandBase flags in autocomplete window.", false, 0.f, false, 0.f, nullptr, nullptr);
con_suggestion_flags_realtime = ConVar::Create("con_suggestion_flags_realtime", "1" , FCVAR_DEVELOPMENTONLY, "Whether to show compile-time or run-time CommandBase flags.", false, 0.f, false, 0.f, nullptr, nullptr);
#endif // !DEDICATED
//-------------------------------------------------------------------------
// FILESYSTEM |

View File

@ -329,6 +329,7 @@ void ConCommand::Init(void)
ConCommand::Create("sphere", "Draw a debug sphere.", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, Sphere_f, nullptr);
ConCommand::Create("capsule", "Draw a debug capsule.", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, Capsule_f, nullptr);
#endif //!DEDICATED
ConCommand::Create("con_help", "Shows the colors and description of each context.", FCVAR_RELEASE, CON_Help_f, nullptr);
#ifndef CLIENT_DLL
ConCommand::Create("reload_playlists", "Reloads the playlists file.", FCVAR_RELEASE, Host_ReloadPlaylists_f, nullptr);
#endif // !CLIENT_DLL
@ -347,11 +348,15 @@ void ConCommand::Init(void)
//-------------------------------------------------------------------------
// CLIENT DLL |
ConCommand::Create("script_client", "Run input code as CLIENT script on the VM.", FCVAR_CLIENTDLL | FCVAR_CHEAT, SQVM_ClientScript_f, nullptr);
ConCommand::Create("cl_showconsole", "Opens the game console.", FCVAR_CLIENTDLL | FCVAR_RELEASE, GameConsole_Invoke_f, nullptr);
ConCommand::Create("cl_showconsole", "Opens the developer console.", FCVAR_CLIENTDLL | FCVAR_RELEASE, GameConsole_Invoke_f, nullptr);
ConCommand::Create("cl_showbrowser", "Opens the server browser.", FCVAR_CLIENTDLL | FCVAR_RELEASE, ServerBrowser_Invoke_f, nullptr);
ConCommand::Create("rcon", "Forward RCON query to remote server. | Usage: rcon \"<query>\".", FCVAR_CLIENTDLL | FCVAR_RELEASE, RCON_CmdQuery_f, nullptr);
ConCommand::Create("rcon_disconnect", "Disconnect from RCON server.", FCVAR_CLIENTDLL | FCVAR_RELEASE, RCON_Disconnect_f, nullptr);
ConCommand::Create("con_removeline", "Removes a range of lines from the console.", FCVAR_CLIENTDLL | FCVAR_RELEASE, CON_RemoveLine_f, nullptr);
ConCommand::Create("con_history", "Shows the developer console submission history.", FCVAR_CLIENTDLL | FCVAR_RELEASE, CON_LogHistory_f, nullptr);
ConCommand::Create("con_removeline", "Removes a range of lines from the developer console.", FCVAR_CLIENTDLL | FCVAR_RELEASE, CON_RemoveLine_f, nullptr);
ConCommand::Create("con_clearlines", "Clears all lines from the developer console.", FCVAR_CLIENTDLL | FCVAR_RELEASE, CON_ClearLines_f, nullptr);
ConCommand::Create("con_clearhistory", "Clears all submissions from the developer console history.", FCVAR_CLIENTDLL | FCVAR_RELEASE, CON_ClearHistory_f, nullptr);
//-------------------------------------------------------------------------
// UI DLL |
ConCommand::Create("script_ui", "Run input code as UI script on the VM.", FCVAR_CLIENTDLL | FCVAR_CHEAT, SQVM_UIScript_f, nullptr);

View File

@ -144,8 +144,8 @@ ConVar* con_notify_common_clr = nullptr;
ConVar* con_notify_warning_clr = nullptr;
ConVar* con_notify_error_clr = nullptr;
ConVar* con_max_size_logvector = nullptr;
ConVar* con_max_size_history = nullptr;
ConVar* con_max_lines = nullptr;
ConVar* con_max_history = nullptr;
ConVar* con_suggestion_limit = nullptr;
ConVar* con_suggestion_showhelptext = nullptr;
ConVar* con_suggestion_showflags = nullptr;

View File

@ -140,8 +140,8 @@ extern ConVar* con_notify_common_clr;
extern ConVar* con_notify_warning_clr;
extern ConVar* con_notify_error_clr;
extern ConVar* con_max_size_logvector;
extern ConVar* con_max_size_history;
extern ConVar* con_max_lines;
extern ConVar* con_max_history;
extern ConVar* con_suggestion_limit;
extern ConVar* con_suggestion_showhelptext;
extern ConVar* con_suggestion_showflags;

View File

@ -627,7 +627,50 @@ void NET_UseRandomKeyChanged_f(IConVar* pConVar, const char* pOldString, float f
NET_SetKey(DEFAULT_NET_ENCRYPTION_KEY);
}
}
/*
=====================
CON_Help_f
Shows the colors and
description of each
context.
=====================
*/
void CON_Help_f(const CCommand& args)
{
DevMsg(eDLL_T::COMMON, "Contexts:\n");
SQVM_PrintFunc(reinterpret_cast<HSQUIRRELVM>(SQCONTEXT::SERVER), (SQChar*)(" = Server DLL (Script)\n"));
SQVM_PrintFunc(reinterpret_cast<HSQUIRRELVM>(SQCONTEXT::CLIENT), (SQChar*)(" = Client DLL (Script)\n"));
SQVM_PrintFunc(reinterpret_cast<HSQUIRRELVM>(SQCONTEXT::UI), (SQChar*)(" = UI DLL (Script)\n"));
DevMsg(eDLL_T::SERVER, " = Server DLL (Code)\n");
DevMsg(eDLL_T::CLIENT, " = Client DLL (Code)\n");
DevMsg(eDLL_T::UI, " = UI DLL (Code)\n");
DevMsg(eDLL_T::ENGINE, " = Engine DLL (Code)\n");
DevMsg(eDLL_T::FS, " = FileSystem (Code)\n");
DevMsg(eDLL_T::RTECH, " = PakLoad API (Code)\n");
DevMsg(eDLL_T::MS, " = MaterialSystem (Code)\n");
DevMsg(eDLL_T::NETCON, " = Net Console (Code)\n");
}
#ifndef DEDICATED
/*
=====================
CON_LogHistory_f
Shows the game console
submission history.
=====================
*/
void CON_LogHistory_f(const CCommand& args)
{
const vector<string> vHistory = g_pConsole->GetHistory();
for (size_t i = 0, nh = vHistory.size(); i < nh; i++)
{
DevMsg(eDLL_T::COMMON, "%3d: %s\n", i, vHistory[i].c_str());
}
}
/*
=====================
CON_RemoveLine_f
@ -650,6 +693,32 @@ void CON_RemoveLine_f(const CCommand& args)
g_pConsole->RemoveLog(start, end);
}
/*
=====================
CON_ClearLines_f
Clears all lines from
the developer console.
=====================
*/
void CON_ClearLines_f(const CCommand& args)
{
g_pConsole->ClearLog();
}
/*
=====================
CON_ClearHistory_f
Clears all submissions from the
developer console history.
=====================
*/
void CON_ClearHistory_f(const CCommand& args)
{
g_pConsole->ClearHistory();
}
/*
=====================
RCON_CmdQuery_f

View File

@ -37,8 +37,13 @@ void VPK_Mount_f(const CCommand& args);
void NET_SetKey_f(const CCommand& args);
void NET_GenerateKey_f(const CCommand& args);
void NET_UseRandomKeyChanged_f(IConVar* pConVar, const char* pOldString, float flOldValue);
void CON_Help_f(const CCommand& args);
#ifndef DEDICATED
void CON_LogHistory_f(const CCommand& args);
void CON_RemoveLine_f(const CCommand& args);
void CON_ClearLines_f(const CCommand& args);
void CON_ClearHistory_f(const CCommand& args);
void RCON_CmdQuery_f(const CCommand& args);
void RCON_Disconnect_f(const CCommand& args);
#endif // !DEDICATED