diff --git a/r5dev/common/opcodes.cpp b/r5dev/common/opcodes.cpp index 95a213c8..1f45e803 100644 --- a/r5dev/common/opcodes.cpp +++ b/r5dev/common/opcodes.cpp @@ -182,38 +182,48 @@ void RuntimePtc_Init() /* .TEXT */ void RuntimePtc_Toggle() /* .TEXT */ { - //static bool g_nop = true; +#ifdef GAMEDLL_S3 + static bool g_nop = true; - //if (g_nop) - //{ - // //------------------------------------------------------------------------- - // // CALL --> NOP | Allow some maps to be loaded by nopping out a call in LoadProp function - // dst007.Offset(0x5E8).Patch({ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); - // //------------------------------------------------------------------------- - // // CALL --> NOP | Disable the viewmodel rendered to avoid a crash from a certain entity in desertlands_mu1 - // dst008.Offset(0x67).Patch({ 0x90, 0x90, 0x90, 0x90, 0x90 }); + if (g_nop) + { + //------------------------------------------------------------------------- + // CALL --> NOP | Allow some maps to be loaded by nopping out a call in LoadProp function + dst007.Offset(0x5E8).Patch({ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); + //------------------------------------------------------------------------- + // CALL --> NOP | Disable the viewmodel rendered to avoid a crash from a certain entity in desertlands_mu1 + //dst008.Offset(0x67).Patch({ 0x90, 0x90, 0x90, 0x90, 0x90 }); - // printf("\n"); - // printf("+--------------------------------------------------------+\n"); - // printf("|>>>>>>>>>>>>>>| TEXT OPCODES OVERWRITTEN |<<<<<<<<<<<<<<|\n"); - // printf("+--------------------------------------------------------+\n"); - // printf("\n"); - //} - //else - //{ - // //------------------------------------------------------------------------- - // // NOP --> CALL | Recover function DST007 - // dst007.Offset(0x5E8).Patch({ 0x48, 0x8B, 0x03, 0xFF, 0x90, 0xB0, 0x02, 0x00, 0x00, 0x84, 0xC0 }); - // //------------------------------------------------------------------------- - // // NOP --> CALL | Recover function DST008 - // dst008.Offset(0x67).Patch({ 0xE8, 0x54, 0xD8, 0xFF, 0xFF }); + printf("\n"); + printf("+--------------------------------------------------------+\n"); + printf("|>>>>>>>>>>>>>>| TEXT OPCODES OVERWRITTEN |<<<<<<<<<<<<<<|\n"); + printf("+--------------------------------------------------------+\n"); + printf("\n"); + } + else + { + //------------------------------------------------------------------------- + // NOP --> CALL | Recover function DST007 + dst007.Offset(0x5E8).Patch({ 0x48, 0x8B, 0x03, 0xFF, 0x90, 0xB0, 0x02, 0x00, 0x00, 0x84, 0xC0 }); + //------------------------------------------------------------------------- + // NOP --> CALL | Recover function DST008 + //dst008.Offset(0x67).Patch({ 0xE8, 0x54, 0xD8, 0xFF, 0xFF }); - // printf("\n"); - // printf("+--------------------------------------------------------+\n"); - // printf("|>>>>>>>>>>>>>>>| TEXT OPCODES RECOVERED |<<<<<<<<<<<<<<<|\n"); - // printf("+--------------------------------------------------------+\n"); - // printf("\n"); - //} - //g_nop = !g_nop; + printf("\n"); + printf("+--------------------------------------------------------+\n"); + printf("|>>>>>>>>>>>>>>>| TEXT OPCODES RECOVERED |<<<<<<<<<<<<<<<|\n"); + printf("+--------------------------------------------------------+\n"); + printf("\n"); + } + g_nop = !g_nop; + + +/* +rtech_asyncload "common.rpak" +rtech_asyncload "common_mp.rpak" +rtech_asyncload "mp_rr_canyonlands_mu1.rpak" +rtech_asyncload "mp_rr_desertlands_64k_x_64k.rpak" +*/ +#endif // GAMEDLL_S3 } diff --git a/r5dev/common/opcodes.h b/r5dev/common/opcodes.h index f26bb949..a952e23a 100644 --- a/r5dev/common/opcodes.h +++ b/r5dev/common/opcodes.h @@ -16,11 +16,12 @@ void RuntimePtc_Toggle(); namespace { +#ifdef GAMEDLL_S3 /* -------------- OTHER ------------------------------------------------------------------------------------------------------------------------------------------------- */ - //ADDRESS dst007 = /*0x14028F3B0*/ FindPatternSIMD(g_szGameDll, (const unsigned char*)"\x48\x8B\xC4\x44\x89\x40\x18\x48\x89\x50\x10\x55\x53\x56\x57\x41", "xxxxxxxxxxxxxxxx"); - //ADDRESS dst008 = /*0x140E3E110*/ FindPatternSIMD(g_szGameDll, (const unsigned char*)"\x48\x83\xEC\x78\x48\x8B\x84\x24\x00\x00\x00\x00\x4D\x8B\xD8\x00", "xxxxxxxx????xxx?"); + ADDRESS dst007 = /*0x14028F3B0*/ FindPatternSIMD(g_szGameDll, (const unsigned char*)"\x48\x8B\xC4\x44\x89\x40\x18\x48\x89\x50\x10\x55\x53\x56\x57\x41", "xxxxxxxxxxxxxxxx"); + ADDRESS dst008 = /*0x140E3E110*/ FindPatternSIMD(g_szGameDll, (const unsigned char*)"\x48\x83\xEC\x78\x48\x8B\x84\x24\x00\x00\x00\x00\x4D\x8B\xD8\x00", "xxxxxxxx????xxx?"); /* -------------- ------- ----------------------------------------------------------------------------------------------------------------------------------------------- */ - +#endif // GAMEDLL_S3 namespace { //------------------------------------------------------------------------- diff --git a/r5dev/engine/host_state.cpp b/r5dev/engine/host_state.cpp index 03748851..468f3333 100644 --- a/r5dev/engine/host_state.cpp +++ b/r5dev/engine/host_state.cpp @@ -22,11 +22,11 @@ void KeepAliveToPylon() DevMsg(eDLL_T::CLIENT, "Sending PostServerHost request\n"); bool result = g_pR5net->PostServerHost(m_szHostRequestMessage, m_szHostToken, ServerListing{ - g_pCVar->FindVar("hostname")->m_pzsCurrentValue, + g_pCVar->FindVar("hostname")->GetString(), std::string(g_pHostState->m_levelName), "", - g_pCVar->FindVar("hostport")->m_pzsCurrentValue, - g_pCVar->FindVar("mp_gamemode")->m_pzsCurrentValue, + g_pCVar->FindVar("hostport")->GetString(), + g_pCVar->FindVar("mp_gamemode")->GetString(), false, // BUG BUG: Checksum is null on dedi diff --git a/r5dev/engine/sys_utils.cpp b/r5dev/engine/sys_utils.cpp index ca526574..57a59e93 100644 --- a/r5dev/engine/sys_utils.cpp +++ b/r5dev/engine/sys_utils.cpp @@ -76,7 +76,7 @@ void DevMsg(eDLL_T idx, const char* fmt, ...) const char* c = s.c_str(); g_pLogSystem.AddLog((LogType_t)eDLL_T::ENGINE, s); - Items.push_back(Strdup((const char*)c)); + g_pIConsole->m_ivConLog.push_back(Strdup((const char*)c)); #endif // !DEDICATED } diff --git a/r5dev/gameui/IBrowser.cpp b/r5dev/gameui/IBrowser.cpp index c226209c..ffd91627 100644 --- a/r5dev/gameui/IBrowser.cpp +++ b/r5dev/gameui/IBrowser.cpp @@ -1,3 +1,16 @@ +/****************************************************************************** +------------------------------------------------------------------------------- +File : IBrowser.cpp +Date : 09:06:2021 +Author : Sal +Purpose: Implements the in-game server browser front-end +------------------------------------------------------------------------------- +History: +- 09:06:2021 21:07 : Created by Sal +- 25:07:2021 14:26 : Implement private servers connect dialog and password field + +******************************************************************************/ + #include "core/stdafx.h" #include "core/init.h" #include "core/resource.h" @@ -17,19 +30,6 @@ #include "squirrel/sqinit.h" #include "gameui/IBrowser.h" -/****************************************************************************** -------------------------------------------------------------------------------- -File : IBrowser.cpp -Date : 09:06:2021 -Author : Sal -Purpose: Implements the in-game server browser frontend -------------------------------------------------------------------------------- -History: -- 09:06:2021 21:07 : Created by Sal -- 25:07:2021 14:26 : Implement private servers connect dialog and password field - -******************************************************************************/ - //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- @@ -56,7 +56,6 @@ IBrowser::IBrowser() } } - m_szMatchmakingHostName = r5net_matchmaking_hostname->m_pzsCurrentValue; static std::thread hostingServerRequestThread([this]() { while (true) @@ -90,118 +89,53 @@ IBrowser::~IBrowser() } //----------------------------------------------------------------------------- -// Purpose: updates the hoster's status +// Purpose: draws the main browser front-end //----------------------------------------------------------------------------- -void IBrowser::UpdateHostingStatus() +void IBrowser::Draw(const char* title, bool* bDraw) { - if (!g_pHostState || !g_pCVar) + if (!m_bInitialized) { + SetStyleVar(); + m_szMatchmakingHostName = r5net_matchmaking_hostname->GetString(); + + m_bInitialized = true; + } + + if (!ImGui::Begin(title, bDraw)) + { + ImGui::End(); return; } + ImGui::End(); - eHostingStatus = g_pHostState->m_bActiveGame ? EHostStatus::HOSTING : EHostStatus::NOT_HOSTING; // Are we hosting a server? - switch (eHostingStatus) + if (*bDraw == NULL) { - case EHostStatus::NOT_HOSTING: - { - m_szHostRequestMessage.clear(); - m_iv4HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - break; + m_bActivate = false; } - case EHostStatus::HOSTING: + + ImGui::SetNextWindowSize(ImVec2(840, 600), ImGuiCond_FirstUseEver); + ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver); + + ImGui::Begin(title, NULL, ImGuiWindowFlags_NoScrollbar); { - if (eServerVisibility == EServerVisibility::OFFLINE) - { - break; - } + CompMenu(); - if (*g_nRemoteFunctionCallsChecksum == NULL) // Check if script checksum is valid yet. + switch (eCurrentSection) { + case ESection::SERVER_BROWSER: + ServerBrowserSection(); break; - } - - switch (eServerVisibility) - { - - case EServerVisibility::HIDDEN: - m_Server.bHidden = true; + case ESection::HOST_SERVER: + HostServerSection(); break; - case EServerVisibility::PUBLIC: - m_Server.bHidden = false; + case ESection::SETTINGS: + SettingsSection(); break; default: break; } - - SendHostingPostRequest(); - break; - } - default: - break; - } -} - -//----------------------------------------------------------------------------- -// Purpose: refreshes the server browser list with available servers -//----------------------------------------------------------------------------- -void IBrowser::RefreshServerList() -{ - static bool bThreadLocked = false; - - m_vServerList.clear(); - m_szServerListMessage.clear(); - - if (!bThreadLocked) - { - std::thread t([this]() - { - DevMsg(eDLL_T::CLIENT, "Refreshing server list with string '%s'\n", r5net_matchmaking_hostname->m_pzsCurrentValue); - bThreadLocked = true; - m_vServerList = g_pR5net->GetServersList(m_szServerListMessage); - bThreadLocked = false; - }); - - t.detach(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: sends the hosting POST request to the comp server -//----------------------------------------------------------------------------- -void IBrowser::SendHostingPostRequest() -{ - m_szHostToken = std::string(); - DevMsg(eDLL_T::CLIENT, "Sending PostServerHost request\n"); - bool result = g_pR5net->PostServerHost(m_szHostRequestMessage, m_szHostToken, - ServerListing{ - m_Server.svServerName, - std::string(g_pHostState->m_levelName), - "", - g_pCVar->FindVar("hostport")->m_pzsCurrentValue, - g_pCVar->FindVar("mp_gamemode")->m_pzsCurrentValue, - m_Server.bHidden, - std::to_string(*g_nRemoteFunctionCallsChecksum), - - std::string(), - g_szNetKey.c_str() - } - ); - - if (result) - { - m_iv4HostRequestMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); - std::stringstream msg; - msg << "Broadcasting! "; - if (!m_szHostToken.empty()) - { - msg << "Share the following token for clients to connect: "; - } - m_szHostRequestMessage = msg.str().c_str(); - } - else - { - m_iv4HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); } + ImGui::End(); } //----------------------------------------------------------------------------- @@ -314,6 +248,60 @@ void IBrowser::ServerBrowserSection() ImGui::PopItemWidth(); } +//----------------------------------------------------------------------------- +// Purpose: refreshes the server browser list with available servers +//----------------------------------------------------------------------------- +void IBrowser::RefreshServerList() +{ + static bool bThreadLocked = false; + + m_vServerList.clear(); + m_szServerListMessage.clear(); + + if (!bThreadLocked) + { + std::thread t([this]() + { + DevMsg(eDLL_T::CLIENT, "Refreshing server list with matchmaking host '%s'\n", r5net_matchmaking_hostname->GetString()); + bThreadLocked = true; + m_vServerList = g_pR5net->GetServersList(m_szServerListMessage); + bThreadLocked = false; + }); + + t.detach(); + } +} + +//----------------------------------------------------------------------------- +// Purpose: connects to specified server +//----------------------------------------------------------------------------- +void IBrowser::ConnectToServer(const std::string ip, const std::string port, const std::string encKey) +{ + if (!encKey.empty()) + { + ChangeEncryptionKeyTo(encKey); + } + + std::stringstream cmd; + cmd << "connect " << ip << ":" << port; + ProcessCommand(cmd.str().c_str()); +} + +//----------------------------------------------------------------------------- +// Purpose: connects to specified server +//----------------------------------------------------------------------------- +void IBrowser::ConnectToServer(const std::string connString, const std::string encKey) +{ + if (!encKey.empty()) + { + ChangeEncryptionKeyTo(encKey); + } + + std::stringstream cmd; + cmd << "connect " << connString; + ProcessCommand(cmd.str().c_str()); +} + //----------------------------------------------------------------------------- // Purpose: draws the hidden private server modal //----------------------------------------------------------------------------- @@ -571,73 +559,94 @@ void IBrowser::HostServerSection() } //----------------------------------------------------------------------------- -// Purpose: draws the settings section +// Purpose: updates the hoster's status //----------------------------------------------------------------------------- -void IBrowser::SettingsSection() +void IBrowser::UpdateHostingStatus() { - ImGui::InputTextWithHint("Hostname##MatchmakingServerString", "Matchmaking Server String", &m_szMatchmakingHostName); - if (ImGui::Button("Update Hostname")) + if (!g_pHostState || !g_pCVar) { - r5net_matchmaking_hostname->m_pzsCurrentValue = m_szMatchmakingHostName.c_str(); - if (g_pR5net) - { - delete g_pR5net; - g_pR5net = new R5Net::Client(r5net_matchmaking_hostname->m_pzsCurrentValue); - } - } - ImGui::InputText("Netkey##SettingsSection_EncKey", (char*)g_szNetKey.c_str(), ImGuiInputTextFlags_ReadOnly); - if (ImGui::Button("Regenerate Encryption Key##SettingsSection_RegenEncKey")) - { - RegenerateEncryptionKey(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: draws the main browser frontend -//----------------------------------------------------------------------------- -void IBrowser::Draw(const char* title, bool* bDraw) -{ - if (!m_bThemeSet) - { - SetStyleVar(); - m_bThemeSet = true; - } - - if (!ImGui::Begin(title, bDraw)) - { - ImGui::End(); return; } - ImGui::End(); - if (*bDraw == NULL) + eHostingStatus = g_pHostState->m_bActiveGame ? EHostStatus::HOSTING : EHostStatus::NOT_HOSTING; // Are we hosting a server? + switch (eHostingStatus) { - g_bShowBrowser = false; + case EHostStatus::NOT_HOSTING: + { + m_szHostRequestMessage.clear(); + m_iv4HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + break; } - - ImGui::SetNextWindowSize(ImVec2(840, 600), ImGuiCond_FirstUseEver); - ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver); - - ImGui::Begin(title, NULL, ImGuiWindowFlags_NoScrollbar); + case EHostStatus::HOSTING: { - CompMenu(); - - switch (eCurrentSection) + if (eServerVisibility == EServerVisibility::OFFLINE) { - case ESection::SERVER_BROWSER: - ServerBrowserSection(); break; - case ESection::HOST_SERVER: - HostServerSection(); + } + + if (*g_nRemoteFunctionCallsChecksum == NULL) // Check if script checksum is valid yet. + { break; - case ESection::SETTINGS: - SettingsSection(); + } + + switch (eServerVisibility) + { + + case EServerVisibility::HIDDEN: + m_Server.bHidden = true; + break; + case EServerVisibility::PUBLIC: + m_Server.bHidden = false; break; default: break; } + + SendHostingPostRequest(); + break; + } + default: + break; + } +} + +//----------------------------------------------------------------------------- +// Purpose: sends the hosting POST request to the comp server +//----------------------------------------------------------------------------- +void IBrowser::SendHostingPostRequest() +{ + m_szHostToken = std::string(); + DevMsg(eDLL_T::CLIENT, "Sending PostServerHost request\n"); + bool result = g_pR5net->PostServerHost(m_szHostRequestMessage, m_szHostToken, + ServerListing{ + m_Server.svServerName, + std::string(g_pHostState->m_levelName), + "", + g_pCVar->FindVar("hostport")->GetString(), + g_pCVar->FindVar("mp_gamemode")->GetString(), + m_Server.bHidden, + std::to_string(*g_nRemoteFunctionCallsChecksum), + + std::string(), + g_szNetKey.c_str() + } + ); + + if (result) + { + m_iv4HostRequestMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); + std::stringstream msg; + msg << "Broadcasting! "; + if (!m_szHostToken.empty()) + { + msg << "Share the following token for clients to connect: "; + } + m_szHostRequestMessage = msg.str().c_str(); + } + else + { + m_iv4HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); } - ImGui::End(); } //----------------------------------------------------------------------------- @@ -653,33 +662,25 @@ void IBrowser::ProcessCommand(const char* command_line) } //----------------------------------------------------------------------------- -// Purpose: connects to specified server +// Purpose: draws the settings section //----------------------------------------------------------------------------- -void IBrowser::ConnectToServer(const std::string ip, const std::string port, const std::string encKey) +void IBrowser::SettingsSection() { - if (!encKey.empty()) + ImGui::InputTextWithHint("Hostname##MatchmakingServerString", "Matchmaking Server String", &m_szMatchmakingHostName); + if (ImGui::Button("Update Hostname")) { - ChangeEncryptionKeyTo(encKey); + r5net_matchmaking_hostname->SetValue(m_szMatchmakingHostName.c_str()); + if (g_pR5net) + { + delete g_pR5net; + g_pR5net = new R5Net::Client(r5net_matchmaking_hostname->GetString()); + } } - - std::stringstream cmd; - cmd << "connect " << ip << ":" << port; - ProcessCommand(cmd.str().c_str()); -} - -//----------------------------------------------------------------------------- -// Purpose: connects to specified server -//----------------------------------------------------------------------------- -void IBrowser::ConnectToServer(const std::string connString, const std::string encKey) -{ - if (!encKey.empty()) + ImGui::InputText("Netkey##SettingsSection_EncKey", (char*)g_szNetKey.c_str(), ImGuiInputTextFlags_ReadOnly); + if (ImGui::Button("Regenerate Encryption Key##SettingsSection_RegenEncKey")) { - ChangeEncryptionKeyTo(encKey); + RegenerateEncryptionKey(); } - - std::stringstream cmd; - cmd << "connect " << connString; - ProcessCommand(cmd.str().c_str()); } //----------------------------------------------------------------------------- @@ -698,18 +699,67 @@ void IBrowser::ChangeEncryptionKeyTo(const std::string str) HNET_SetKey(str); } -//############################################################################# -// ENTRYPOINT -//############################################################################# - -IBrowser* g_pServerBrowser = nullptr; -void DrawBrowser(bool* bDraw) +//----------------------------------------------------------------------------- +// Purpose: sets the browser front-end style +//----------------------------------------------------------------------------- +void IBrowser::SetStyleVar() { - static IBrowser browser; - static bool AssignPtr = []() - { - g_pServerBrowser = &browser; - return true; - } (); - browser.Draw("Server Browser", bDraw); + ImGuiStyle& style = ImGui::GetStyle(); + ImVec4* colors = style.Colors; + + colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); + colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f); + colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + colors[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f); + colors[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f); + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); + colors[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f); + colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); + colors[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + colors[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + colors[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + colors[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); + colors[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); + colors[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); + colors[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); + colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); + colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + colors[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + colors[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); + colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + colors[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + + style.WindowBorderSize = 0.0f; + style.FrameBorderSize = 1.0f; + style.ChildBorderSize = 1.0f; + style.PopupBorderSize = 1.0f; + style.TabBorderSize = 1.0f; + + style.WindowRounding = 2.5f; + style.FrameRounding = 0.0f; + style.ChildRounding = 0.0f; + style.PopupRounding = 0.0f; + style.TabRounding = 1.0f; + style.ScrollbarRounding = 1.0f; + + style.ItemSpacing = ImVec2(4, 4); + style.WindowPadding = ImVec2(5, 5); } + + +IBrowser* g_pIBrowser = new IBrowser(); diff --git a/r5dev/gameui/IBrowser.h b/r5dev/gameui/IBrowser.h index 6ff873e3..f5dcd5ed 100644 --- a/r5dev/gameui/IBrowser.h +++ b/r5dev/gameui/IBrowser.h @@ -3,16 +3,36 @@ #include "networksystem/serverlisting.h" #include "networksystem/r5net.h" -void DrawBrowser(bool* bDraw); - class IBrowser { private: - bool m_bThemeSet = false; + bool m_bInitialized = false; public: IBrowser(); ~IBrowser(); + void Draw(const char* title, bool* bDraw); + void CompMenu(); + + void ServerBrowserSection(); + void RefreshServerList(); + void ConnectToServer(const std::string ip, const std::string port, const std::string encKey); + void ConnectToServer(const std::string connString, const std::string encKey); + + void HiddenServersModal(); + void HostServerSection(); + + void UpdateHostingStatus(); + void SendHostingPostRequest(); + + void ProcessCommand(const char* command_line); + + void SettingsSection(); + void RegenerateEncryptionKey(); + void ChangeEncryptionKeyTo(const std::string str); + + void SetStyleVar(); + //////////////////// // Enums // //////////////////// @@ -40,6 +60,8 @@ public: // Server Browser // //////////////////// public: + bool m_bActivate = false; + std::vector m_vServerList; ImGuiTextFilter m_imServerBrowserFilter; char m_chServerConnStringBuffer[256] = { 0 }; @@ -80,94 +102,15 @@ public: /* Texture */ ID3D11ShaderResourceView* m_idLockedIcon = nullptr; + std::vector* m_vucLockedIconBlob; int m_nLockedIconWidth = 0; int m_nLockedIconHeight = 0; - std::vector* m_vucLockedIconBlob; void SetSection(ESection section) { eCurrentSection = section; } - - //////////////////// - // Style // - //////////////////// - void SetStyleVar() - { - ImGuiStyle& style = ImGui::GetStyle(); - ImVec4* colors = style.Colors; - - colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); - colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f); - colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f); - colors[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f); - colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); - colors[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); - colors[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); - colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - colors[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - - style.WindowBorderSize = 0.0f; - style.FrameBorderSize = 1.0f; - style.ChildBorderSize = 1.0f; - style.PopupBorderSize = 1.0f; - style.TabBorderSize = 1.0f; - - style.WindowRounding = 2.5f; - style.FrameRounding = 0.0f; - style.ChildRounding = 0.0f; - style.PopupRounding = 0.0f; - style.TabRounding = 1.0f; - style.ScrollbarRounding = 1.0f; - - style.ItemSpacing = ImVec2(4, 4); - style.WindowPadding = ImVec2(5, 5); - } - - void RefreshServerList(); - void SendHostingPostRequest(); - void CompMenu(); - void ServerBrowserSection(); - void SettingsSection(); - void HiddenServersModal(); - void HostServerSection(); - void Draw(const char* title, bool* bDraw); - void UpdateHostingStatus(); - void ProcessCommand(const char* command_line); - - void RegenerateEncryptionKey(); - void ChangeEncryptionKeyTo(const std::string str); - - void ConnectToServer(const std::string ip, const std::string port, const std::string encKey); - void ConnectToServer(const std::string connString, const std::string encKey); }; -extern IBrowser* g_pServerBrowser; +extern IBrowser* g_pIBrowser; #endif diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 8d39c37c..470bee85 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -1,17 +1,9 @@ -#include "core/stdafx.h" -#include "core/init.h" -#include "tier0/cvar.h" -#include "windows/id3dx.h" -#include "windows/console.h" -#include "gameui/IConsole.h" -#include "client/IVEngineClient.h" - /****************************************************************************** ------------------------------------------------------------------------------- File : IConsole.cpp Date : 18:07:2021 Author : Kawe Mazidjatari -Purpose: Implements the in-game console frontend +Purpose: Implements the in-game console front-end ------------------------------------------------------------------------------- History: - 15:06:2021 | 14:56 : Created by Kawe Mazidjatari @@ -20,6 +12,14 @@ History: ******************************************************************************/ +#include "core/stdafx.h" +#include "core/init.h" +#include "tier0/cvar.h" +#include "windows/id3dx.h" +#include "windows/console.h" +#include "gameui/IConsole.h" +#include "client/IVEngineClient.h" + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- @@ -31,7 +31,7 @@ CConsole::CConsole() m_nHistoryPos = -1; m_bAutoScroll = true; m_bScrollToBottom = false; - m_bThemeSet = false; + m_bInitialized = false; m_ivCommands.push_back("CLEAR"); m_ivCommands.push_back("HELP"); @@ -56,19 +56,22 @@ CConsole::~CConsole() //----------------------------------------------------------------------------- void CConsole::Draw(const char* title, bool* bDraw) { - bool copy_to_clipboard = false; - static auto iConsoleConfig = &g_pImGuiConfig->IConsole_Config; - static auto iBrowserConfig = &g_pImGuiConfig->IBrowser_Config; - - if (!m_bThemeSet) + if (!m_bInitialized) { SetStyleVar(); - m_bThemeSet = true; + m_bInitialized = true; } - if (iConsoleConfig->m_bAutoClear && Items.Size > iConsoleConfig->m_nAutoClearLimit) // Check if Auto-Clear is enabled and if its above our limit. + if (g_pImGuiConfig->IConsole_Config.m_bAutoClear) // Check if Auto-Clear is enabled. { - ClearLog(); - m_ivHistory.clear(); + // Loop and clear the beginning of the vector until we are below our limit. + while (m_ivConLog.Size > g_pImGuiConfig->IConsole_Config.m_nAutoClearLimit) + { + m_ivConLog.erase(m_ivConLog.begin()); + } + while (m_ivHistory.Size > 512) + { + m_ivHistory.erase(m_ivHistory.begin()); + } } //ImGui::ShowStyleEditor(); @@ -81,66 +84,26 @@ void CConsole::Draw(const char* title, bool* bDraw) ImGui::End(); return; } - if (*bDraw == NULL) + if (!*bDraw) { - g_bShowConsole = false; + m_bActivate = false; } // Reserve enough left-over height and width for 1 separator + 1 input text const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); - const float footer_width_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetWindowWidth(); + const float footer_width_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetWindowWidth(); /////////////////////////////////////////////////////////////////////// ImGui::Separator(); if (ImGui::BeginPopup("Options")) { - ImGui::Checkbox("Auto-Scroll", &m_bAutoScroll); - - if (ImGui::Checkbox("Auto-Clear", &iConsoleConfig->m_bAutoClear)) - { - g_pImGuiConfig->Save(); - } - - ImGui::SameLine(); - ImGui::PushItemWidth(100); - - if (ImGui::InputInt("Limit##AutoClearAfterCertainIndexCGameConsole", &iConsoleConfig->m_nAutoClearLimit)) - { - g_pImGuiConfig->Save(); - } - - ImGui::PopItemWidth(); - - if (ImGui::SmallButton("Clear")) - { - ClearLog(); - } - - ImGui::SameLine(); - copy_to_clipboard = ImGui::SmallButton("Copy"); - - ImGui::Text("Console Hotkey:"); - ImGui::SameLine(); - - if (ImGui::Hotkey("##OpenIConsoleBind0", &iConsoleConfig->m_nBind0, ImVec2(80, 80))) - { - g_pImGuiConfig->Save(); - } - - ImGui::Text("Browser Hotkey:"); - ImGui::SameLine(); - - if (ImGui::Hotkey("##OpenIBrowserBind0", &iBrowserConfig->m_nBind0, ImVec2(80, 80))) - { - g_pImGuiConfig->Save(); - } - - ImGui::EndPopup(); + Options(); } if (ImGui::Button("Options")) { ImGui::OpenPopup("Options"); } + ImGui::SameLine(); m_itFilter.Draw("Filter [\"-incl,-excl\"] [\"error\"]", footer_width_to_reserve - 500); ImGui::Separator(); @@ -148,95 +111,28 @@ void CConsole::Draw(const char* title, bool* bDraw) /////////////////////////////////////////////////////////////////////// ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), true, ImGuiWindowFlags_AlwaysVerticalScrollbar); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 4.f, 6.f }); - if (copy_to_clipboard) + + if (m_bCopyToClipBoard) { ImGui::LogToClipboard(); } + ColorLog(); + if (m_bCopyToClipBoard) { ImGui::LogToClipboard(); + ImGui::LogFinish(); + + m_bCopyToClipBoard = false; } - for (int i = 0; i < Items.Size; i++) + + if (m_bScrollToBottom || (m_bAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) { - const char* item = Items[i]; - if (!m_itFilter.PassFilter(item)) - { - continue; - } - /////////////////////////////////////////////////////////////////// - ImVec4 color; - bool has_color = false; - - /////////////////////////////////////////////////////////////////// - // General - if (strstr(item, "[INFO]")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; } - if (strstr(item, "[ERROR]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "[DEBUG]")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } - if (strstr(item, "[WARNING]")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strncmp(item, "# ", 2) == 0) { color = ImVec4(1.00f, 0.80f, 0.60f, 1.00f); has_color = true; } - - /////////////////////////////////////////////////////////////////// - // Script virtual machines per game dll - if (strstr(item, "Script(S):")) { color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); has_color = true; } - if (strstr(item, "Script(C):")) { color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); has_color = true; } - if (strstr(item, "Script(U):")) { color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); has_color = true; } - - /////////////////////////////////////////////////////////////////// - // Native per game dll - if (strstr(item, "Native(S):")) { color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); has_color = true; } - if (strstr(item, "Native(C):")) { color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); has_color = true; } - if (strstr(item, "Native(U):")) { color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); has_color = true; } - - /////////////////////////////////////////////////////////////////// - // Native per sys dll - if (strstr(item, "Native(E):")) { color = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); has_color = true; } - if (strstr(item, "Native(F):")) { color = ImVec4(0.32f, 0.64f, 0.72f, 1.00f); has_color = true; } - if (strstr(item, "Native(R):")) { color = ImVec4(0.36f, 0.70f, 0.35f, 1.00f); has_color = true; } - if (strstr(item, "Native(M):")) { color = ImVec4(0.75f, 0.41f, 0.67f, 1.00f); has_color = true; } - - /////////////////////////////////////////////////////////////////// - // Callbacks - //if (strstr(item, "CodeCallback_")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } - - /////////////////////////////////////////////////////////////////// - // Squirrel VM script errors - if (strstr(item, ".gnut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; } - if (strstr(item, ".nut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; } - if (strstr(item, "[CLIENT]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "[SERVER]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "[UI]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "SCRIPT ERROR")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "SCRIPT COMPILE")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, ".gnut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, ".nut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "): -> ")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - - /////////////////////////////////////////////////////////////////// - // Squirrel VM script debug - if (strstr(item, "CALLSTACK")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strstr(item, "LOCALS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strstr(item, "*FUNCTION")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strstr(item, "DIAGPRINTS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strstr(item, " File : ")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } - if (strstr(item, "<><>GRX<><>")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } - - /////////////////////////////////////////////////////////////////// - // Filters - //if (strstr(item, ") -> ")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; } - - if (has_color) { ImGui::PushStyleColor(ImGuiCol_Text, color); } - ImGui::TextWrapped(item); - if (has_color) { ImGui::PopStyleColor(); } + ImGui::SetScrollHereY(1.0f); + m_bScrollToBottom = false; } - if (copy_to_clipboard) { ImGui::LogFinish(); } - - if (m_bScrollToBottom || (m_bAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) { ImGui::SetScrollHereY(1.0f); } - m_bScrollToBottom = false; /////////////////////////////////////////////////////////////////////// ImGui::PopStyleVar(); ImGui::EndChild(); ImGui::Separator(); - /////////////////////////////////////////////////////////////////////// - // Console - bool reclaim_focus = false; ImGui::PushItemWidth(footer_width_to_reserve - 80); if (ImGui::IsWindowAppearing()) { ImGui::SetKeyboardFocusHere(); } ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; @@ -244,12 +140,15 @@ void CConsole::Draw(const char* title, bool* bDraw) if (ImGui::InputText("##input", m_szInputBuf, IM_ARRAYSIZE(m_szInputBuf), input_text_flags, &TextEditCallbackStub, (void*)this)) { char* s = m_szInputBuf; + + const char* replace = ""; + if (strstr(m_szInputBuf, "`")) { strcpy_s(s, sizeof(replace), replace); } Strtrim(s); if (s[0]) { ProcessCommand(s); } strcpy_s(s, sizeof(replace), replace); - reclaim_focus = true; + m_bReclaimFocus = true; } ImGui::SameLine(); @@ -259,21 +158,71 @@ void CConsole::Draw(const char* title, bool* bDraw) const char* replace = ""; if (s[0]) { ProcessCommand(s); } strcpy_s(s, sizeof(replace), replace); - reclaim_focus = true; + m_bReclaimFocus = true; } // Auto-focus on window apparition. ImGui::SetItemDefaultFocus(); // Auto focus previous widget. - if (reclaim_focus) + if (m_bReclaimFocus) { ImGui::SetKeyboardFocusHere(); + m_bReclaimFocus = false; } ImGui::End(); } +//----------------------------------------------------------------------------- +// Purpose: draws the options panel +//----------------------------------------------------------------------------- +void CConsole::Options() +{ + ImGui::Checkbox("Auto-Scroll", &m_bAutoScroll); + + if (ImGui::Checkbox("Auto-Clear", &g_pImGuiConfig->IConsole_Config.m_bAutoClear)) + { + g_pImGuiConfig->Save(); + } + + ImGui::SameLine(); + ImGui::PushItemWidth(100); + + if (ImGui::InputInt("Limit##AutoClearFirstIConsole", &g_pImGuiConfig->IConsole_Config.m_nAutoClearLimit)) + { + g_pImGuiConfig->Save(); + } + + ImGui::PopItemWidth(); + + if (ImGui::SmallButton("Clear")) + { + ClearLog(); + } + + ImGui::SameLine(); + m_bCopyToClipBoard = ImGui::SmallButton("Copy"); + + ImGui::Text("Console Hotkey:"); + ImGui::SameLine(); + + if (ImGui::Hotkey("##OpenIConsoleBind0", &g_pImGuiConfig->IConsole_Config.m_nBind0, ImVec2(80, 80))) + { + g_pImGuiConfig->Save(); + } + + ImGui::Text("Browser Hotkey:"); + ImGui::SameLine(); + + if (ImGui::Hotkey("##OpenIBrowserBind0", &g_pImGuiConfig->IBrowser_Config.m_nBind0, ImVec2(80, 80))) + { + g_pImGuiConfig->Save(); + } + + ImGui::EndPopup(); +} + //----------------------------------------------------------------------------- // Purpose: executes submitted commands in a separate thread //----------------------------------------------------------------------------- @@ -305,25 +254,25 @@ void CConsole::ProcessCommand(const char* command_line) } else if (Stricmp(command_line, "HELP") == 0) { - AddLog("Frontend commands:"); + AddLog("Commands:"); for (int i = 0; i < m_ivCommands.Size; i++) { AddLog("- %s", m_ivCommands[i]); } AddLog("Log types:"); - AddLog("Script(S): = Server (Script VM)"); - AddLog("Script(C): = Client (Script VM)"); - AddLog("Script(U): = UI (Script VM)"); + AddLog("Script(S): = Server DLL (Script VM)"); + AddLog("Script(C): = Client DLL (Script VM)"); + AddLog("Script(U): = UI DLL (Script VM)"); - AddLog("Native(S): = Server dll (Code)"); - AddLog("Native(C): = Client dll (code)"); - AddLog("Native(U): = UI dll (code)"); + AddLog("Native(S): = Server DLL (Code)"); + AddLog("Native(C): = Client DLL (Code)"); + AddLog("Native(U): = UI DLL (Code)"); - AddLog("Native(E): = Engine dll (code)"); - AddLog("Native(F): = FileSystem dll (code)"); - AddLog("Native(R): = RTech dll (code)"); - AddLog("Native(M): = MaterialSystem dll (code)"); + AddLog("Native(E): = Engine DLL (Code)"); + AddLog("Native(F): = FileSys DLL (Code)"); + AddLog("Native(R): = RTech DLL (Code)"); + AddLog("Native(M): = MatSys DLL (Code)"); } else if (Stricmp(command_line, "HISTORY") == 0) { @@ -389,20 +338,169 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* data) return 0; } -//############################################################################# -// ENTRYPOINT -//############################################################################# - -CConsole* g_GameConsole = nullptr; -void DrawConsole(bool* bDraw) +//----------------------------------------------------------------------------- +// Purpose: text edit callback stub +//----------------------------------------------------------------------------- +int CConsole::TextEditCallbackStub(ImGuiInputTextCallbackData* data) { - static CConsole console; - static bool AssignPtr = []() - { - g_GameConsole = &console; - return true; - } (); - console.Draw("Console", bDraw); + CConsole* console = (CConsole*)data->UserData; + return console->TextEditCallback(data); } -/////////////////////////////////////////////////////////////////////////// +//----------------------------------------------------------------------------- +// Purpose: adds logs to the vector +//----------------------------------------------------------------------------- +void CConsole::AddLog(const char* fmt, ...) IM_FMTARGS(2) +{ + char buf[1024]; + va_list args; + va_start(args, fmt); + vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); + buf[IM_ARRAYSIZE(buf) - 1] = 0; + va_end(args); + m_ivConLog.push_back(Strdup(buf)); +} + +//----------------------------------------------------------------------------- +// Purpose: clears the entire vector +//----------------------------------------------------------------------------- +void CConsole::ClearLog() +{ + for (int i = 0; i < m_ivConLog.Size; i++) { free(m_ivConLog[i]); } + m_ivConLog.clear(); +} + +//----------------------------------------------------------------------------- +// Purpose: colors important logs +//----------------------------------------------------------------------------- +void CConsole::ColorLog() +{ + for (int i = 0; i < m_ivConLog.Size; i++) + { + const char* item = m_ivConLog[i]; + if (!m_itFilter.PassFilter(item)) + { + continue; + } + /////////////////////////////////////////////////////////////////////// + ImVec4 color; + bool has_color = false; + + // General + if (strstr(item, "[INFO]")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; } + if (strstr(item, "[ERROR]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(item, "[DEBUG]")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } + if (strstr(item, "[WARNING]")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } + if (strncmp(item, "# ", 2) == 0) { color = ImVec4(1.00f, 0.80f, 0.60f, 1.00f); has_color = true; } + + // Script virtual machines per game dll + if (strstr(item, "Script(S):")) { color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); has_color = true; } + if (strstr(item, "Script(C):")) { color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); has_color = true; } + if (strstr(item, "Script(U):")) { color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); has_color = true; } + + // Native per game dll + if (strstr(item, "Native(S):")) { color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); has_color = true; } + if (strstr(item, "Native(C):")) { color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); has_color = true; } + if (strstr(item, "Native(U):")) { color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); has_color = true; } + + // Native per sys dll + if (strstr(item, "Native(E):")) { color = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); has_color = true; } + if (strstr(item, "Native(F):")) { color = ImVec4(0.32f, 0.64f, 0.72f, 1.00f); has_color = true; } + if (strstr(item, "Native(R):")) { color = ImVec4(0.36f, 0.70f, 0.35f, 1.00f); has_color = true; } + if (strstr(item, "Native(M):")) { color = ImVec4(0.75f, 0.41f, 0.67f, 1.00f); has_color = true; } + + // Callbacks + //if (strstr(item, "CodeCallback_")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } + + // Squirrel VM script errors + if (strstr(item, ".gnut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; } + if (strstr(item, ".nut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; } + if (strstr(item, "[CLIENT]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(item, "[SERVER]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(item, "[UI]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(item, "SCRIPT ERROR")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(item, "SCRIPT COMPILE")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(item, ".gnut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(item, ".nut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(item, "): -> ")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + + // Squirrel VM script debug + if (strstr(item, "CALLSTACK")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } + if (strstr(item, "LOCALS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } + if (strstr(item, "*FUNCTION")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } + if (strstr(item, "DIAGPRINTS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } + if (strstr(item, " File : ")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } + if (strstr(item, "<><>GRX<><>")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } + + // Filters + //if (strstr(item, ") -> ")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; } + + if (has_color) { ImGui::PushStyleColor(ImGuiCol_Text, color); } + ImGui::TextWrapped(item); + if (has_color) { ImGui::PopStyleColor(); } + } +} + +//----------------------------------------------------------------------------- +// Purpose: sets the console front-end style +//----------------------------------------------------------------------------- +void CConsole::SetStyleVar() +{ + ImGuiStyle& style = ImGui::GetStyle(); + ImVec4* colors = style.Colors; + + colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); + colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f); + colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + colors[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f); + colors[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f); + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); + colors[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f); + colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); + colors[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + colors[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + colors[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + colors[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); + colors[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); + colors[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); + colors[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); + colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); + colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + colors[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + colors[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); + colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + colors[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + + style.WindowBorderSize = 0.0f; + style.FrameBorderSize = 1.0f; + style.ChildBorderSize = 1.0f; + style.PopupBorderSize = 1.0f; + style.TabBorderSize = 1.0f; + + style.WindowRounding = 2.5f; + style.FrameRounding = 0.0f; + style.ChildRounding = 0.0f; + style.PopupRounding = 0.0f; + style.TabRounding = 1.0f; + style.ScrollbarRounding = 1.0f; + + style.ItemSpacing = ImVec2(4, 4); + style.WindowPadding = ImVec2(5, 5); +} + +CConsole* g_pIConsole = new CConsole(); diff --git a/r5dev/gameui/IConsole.h b/r5dev/gameui/IConsole.h index 3d9e9b96..b451698c 100644 --- a/r5dev/gameui/IConsole.h +++ b/r5dev/gameui/IConsole.h @@ -1,124 +1,44 @@ #pragma once #ifndef DEDICATED - -/////////////////////////////////////////////////////////////////////////////// -// Initialization -void DrawConsole(bool* bDraw); - -/////////////////////////////////////////////////////////////////////////////// -// Globals -inline ImVector Items; - class CConsole { private: /////////////////////////////////////////////////////////////////////////// - char m_szInputBuf[256] = { 0 }; + char m_szInputBuf[512] = { 0 }; ImVector m_ivCommands; ImVector m_ivHistory; - int m_nHistoryPos = -1; + int m_nHistoryPos = -1; ImGuiTextFilter m_itFilter; - bool m_bAutoScroll = true; - bool m_bScrollToBottom = false; - bool m_bThemeSet = false; + bool m_bAutoScroll = true; + bool m_bScrollToBottom = false; + bool m_bCopyToClipBoard = false; + bool m_bReclaimFocus = false; + bool m_bInitialized = false; public: - /////////////////////////////////////////////////////////////////////////// + bool m_bActivate = false; + ImVector m_ivConLog; + /////////////////////////////////////////////////////////////////////////// CConsole(); ~CConsole(); void Draw(const char* title, bool* bDraw); + void Options(); + void ProcessCommand(const char* command_line); int TextEditCallback(ImGuiInputTextCallbackData* data); + static int TextEditCallbackStub(ImGuiInputTextCallbackData* data); /////////////////////////////////////////////////////////////////////////// - // History - static int TextEditCallbackStub(ImGuiInputTextCallbackData* data) - { - CConsole* console = (CConsole*)data->UserData; - return console->TextEditCallback(data); - } + void AddLog(const char* fmt, ...) IM_FMTARGS(2); + void ClearLog(); + void ColorLog(); /////////////////////////////////////////////////////////////////////////// - // Utility - void ClearLog() - { - for (int i = 0; i < Items.Size; i++) { free(Items[i]); } - Items.clear(); - } - void AddLog(const char* fmt, ...) IM_FMTARGS(2) - { - char buf[1024]; - va_list args; - va_start(args, fmt); - vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); - buf[IM_ARRAYSIZE(buf) - 1] = 0; - va_end(args); - Items.push_back(Strdup(buf)); - } - - /////////////////////////////////////////////////////////////////////// - // Style - void SetStyleVar() - { - ImGuiStyle& style = ImGui::GetStyle(); - ImVec4* colors = style.Colors; - - colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); - colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f); - colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f); - colors[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f); - colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); - colors[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); - colors[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); - colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - colors[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - - style.WindowBorderSize = 0.0f; - style.FrameBorderSize = 1.0f; - style.ChildBorderSize = 1.0f; - style.PopupBorderSize = 1.0f; - style.TabBorderSize = 1.0f; - - style.WindowRounding = 2.5f; - style.FrameRounding = 0.0f; - style.ChildRounding = 0.0f; - style.PopupRounding = 0.0f; - style.TabRounding = 1.0f; - style.ScrollbarRounding = 1.0f; - - style.ItemSpacing = ImVec2(4, 4); - style.WindowPadding = ImVec2(5, 5); - } + void SetStyleVar(); }; -extern CConsole* g_GameConsole; +/////////////////////////////////////////////////////////////////////////////// +extern CConsole* g_pIConsole; #endif // !DEDICATED diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index 1e5f43c1..0ecd5d9d 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -71,7 +71,7 @@ void* HSQVM_PrintFunc(void* sqvm, char* fmt, ...) #ifndef DEDICATED std::string s = g_spd_sqvm_p_oss.str(); const char* c = s.c_str(); - Items.push_back(Strdup((const char*)c)); + g_pIConsole->m_ivConLog.push_back(Strdup((const char*)c)); #endif // !DEDICATED } #ifndef DEDICATED @@ -141,7 +141,7 @@ void* HSQVM_WarningFunc(void* sqvm, int a2, int a3, int* nStringSize, void** ppS #ifndef DEDICATED std::string s = g_spd_sqvm_w_oss.str(); const char* c = s.c_str(); - Items.push_back(Strdup(c)); + g_pIConsole->m_ivConLog.push_back(Strdup(c)); #endif // !DEDICATED } #ifndef DEDICATED @@ -149,7 +149,7 @@ void* HSQVM_WarningFunc(void* sqvm, int a2, int a3, int* nStringSize, void** ppS { g_pLogSystem.AddLog((LogType_t)vmIdx, s); const char* c = s.c_str(); - Items.push_back(Strdup(c)); + g_pIConsole->m_ivConLog.push_back(Strdup(c)); } #endif // !DEDICATED g_bSQVM_WarnFuncCalled = false; diff --git a/r5dev/tier0/ConCommand.cpp b/r5dev/tier0/ConCommand.cpp index c0cf8f94..df3fdd67 100644 --- a/r5dev/tier0/ConCommand.cpp +++ b/r5dev/tier0/ConCommand.cpp @@ -99,9 +99,9 @@ bool ConCommandBase::HasFlags(int nFlags) } //----------------------------------------------------------------------------- -// Purpose: test each ConCommand query before execution. +// Purpose: Test each ConCommand query before execution. // Input : *pCommandBase - nFlags -// Output : false if execution is permitted, true if not. +// Output : False if execution is permitted, true if not. //----------------------------------------------------------------------------- bool ConCommandBase::IsFlagSet(ConCommandBase* pCommandBase, int nFlags) { diff --git a/r5dev/tier0/IConVar.cpp b/r5dev/tier0/IConVar.cpp index 079aa2c4..02051c26 100644 --- a/r5dev/tier0/IConVar.cpp +++ b/r5dev/tier0/IConVar.cpp @@ -63,6 +63,11 @@ void ConVar::Init(void) cl_consoleoverlay_offset_x = new ConVar("cl_consoleoverlay_offset_x", "10", FCVAR_DEVELOPMENTONLY, "X offset for console overlay.", false, 1.f, false, 50.f, nullptr, nullptr); cl_consoleoverlay_offset_y = new ConVar("cl_consoleoverlay_offset_y", "10", FCVAR_DEVELOPMENTONLY, "Y offset for console overlay.", false, 1.f, false, 50.f, nullptr, nullptr); + cl_consoleoverlay_native_clr = new ConVar("cl_consoleoverlay_native_clr", "255 255 255 255", FCVAR_DEVELOPMENTONLY, "Native RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr); + cl_consoleoverlay_server_clr = new ConVar("cl_consoleoverlay_server_clr", "190 183 240 255", FCVAR_DEVELOPMENTONLY, "Server script VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr); + cl_consoleoverlay_client_clr = new ConVar("cl_consoleoverlay_client_clr", "117 116 139 255", FCVAR_DEVELOPMENTONLY, "Client script VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr); + cl_consoleoverlay_ui_clr = new ConVar("cl_consoleoverlay_ui_clr", "197 160 177 255", FCVAR_DEVELOPMENTONLY, "UI script VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr); + cl_showsimstats = new ConVar("cl_showsimstats", "0", FCVAR_DEVELOPMENTONLY, "Shows the tick counter for the server/client simulation and the render frame.", false, 0.f, false, 0.f, nullptr, nullptr); cl_simstats_offset_x = new ConVar("cl_simstats_offset_x", "1250", FCVAR_DEVELOPMENTONLY, "X offset for simulation debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr); cl_simstats_offset_y = new ConVar("cl_simstats_offset_y", "885", FCVAR_DEVELOPMENTONLY, "Y offset for simulation debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr); @@ -314,41 +319,41 @@ void ConVar::SetValue(float flValue) // Purpose: sets the ConVar string value. // Input : *szValue - //----------------------------------------------------------------------------- -void ConVar::SetValue(const char* szValue) +void ConVar::SetValue(const char* pszValue) { - if (strcmp(this->m_pParent->m_pzsCurrentValue, szValue) == 0) + if (strcmp(this->m_pParent->m_pzsCurrentValue, pszValue) == 0) { return; } - this->m_pParent->m_pzsCurrentValue = szValue; + this->m_pParent->m_pzsCurrentValue = pszValue; char szTempValue[32]{}; - const char* pszValue{}; + const char* pszNewValue{}; // Only valid for root convars. assert(m_pParent == this); float flOldValue = m_flValue; - pszValue = (char*)szValue; - if (!pszValue) + pszNewValue = (char*)pszValue; + if (!pszNewValue) { - pszValue = ""; + pszNewValue = ""; } - if (!SetColorFromString(szValue)) + if (!SetColorFromString(pszValue)) { // Not a color, do the standard thing - float flNewValue = (float)atof(szValue); + float flNewValue = (float)atof(pszValue); if (!IsFinite(flNewValue)) { - DevMsg(eDLL_T::ENGINE ,"Warning: ConVar '%s' = '%s' is infinite, clamping value.\n", GetBaseName(), szValue); + DevMsg(eDLL_T::ENGINE ,"Warning: ConVar '%s' = '%s' is infinite, clamping value.\n", GetBaseName(), pszValue); flNewValue = FLT_MAX; } if (ClampValue(flNewValue)) { snprintf(szTempValue, sizeof(szTempValue), "%f", flNewValue); - pszValue = szTempValue; + pszNewValue = szTempValue; } // Redetermine value @@ -358,7 +363,7 @@ void ConVar::SetValue(const char* szValue) if (!(m_ConCommandBase.m_nFlags & FCVAR_NEVER_AS_STRING)) { - ChangeStringValue(pszValue, flOldValue); + ChangeStringValue(pszNewValue, flOldValue); } } @@ -519,9 +524,9 @@ bool ConVar::ClampValue(float& flValue) } //----------------------------------------------------------------------------- -// Purpose: test each ConVar query before setting the cvar. +// Purpose: Test each ConVar query before setting the value. // Input : *pConVar - nFlags -// Output : false if change is permitted, true if not. +// Output : False if change is permitted, true if not. //----------------------------------------------------------------------------- bool ConVar::IsFlagSet(ConVar* pConVar, int nFlags) { diff --git a/r5dev/tier0/completion.cpp b/r5dev/tier0/completion.cpp index ac857890..0274700e 100644 --- a/r5dev/tier0/completion.cpp +++ b/r5dev/tier0/completion.cpp @@ -15,19 +15,22 @@ #include "rtech/rtech_game.h" #include "rtech/rtech_utils.h" #include "vpklib/packedstore.h" +#ifndef DEDICATED +#include "gameui/IBrowser.h" #include "gameui/IConsole.h" +#endif // !DEDICATED #include "public/include/bansystem.h" #include "mathlib/crc32.h" #ifndef DEDICATED void _CGameConsole_f_CompletionFunc(const CCommand& cmd) { - g_bShowConsole = !g_bShowConsole; + g_pIConsole->m_bActivate = !g_pIConsole->m_bActivate; } void _CCompanion_f_CompletionFunc(const CCommand& cmd) { - g_bShowBrowser = !g_bShowBrowser; + g_pIBrowser->m_bActivate = !g_pIBrowser->m_bActivate; } #endif // !DEDICATED diff --git a/r5dev/tier0/cvar.cpp b/r5dev/tier0/cvar.cpp index 77a67b84..374c6a2d 100644 --- a/r5dev/tier0/cvar.cpp +++ b/r5dev/tier0/cvar.cpp @@ -19,6 +19,10 @@ ConVar* cl_drawconsoleoverlay = new ConVar(); ConVar* cl_consoleoverlay_lines = new ConVar(); ConVar* cl_consoleoverlay_offset_x = new ConVar(); ConVar* cl_consoleoverlay_offset_y = new ConVar(); +ConVar* cl_consoleoverlay_native_clr = new ConVar(); +ConVar* cl_consoleoverlay_server_clr = new ConVar(); +ConVar* cl_consoleoverlay_client_clr = new ConVar(); +ConVar* cl_consoleoverlay_ui_clr = new ConVar(); ConVar* cl_showsimstats = new ConVar(); ConVar* cl_simstats_offset_x = new ConVar(); diff --git a/r5dev/tier0/cvar.h b/r5dev/tier0/cvar.h index 35f9588b..c0810fe6 100644 --- a/r5dev/tier0/cvar.h +++ b/r5dev/tier0/cvar.h @@ -32,6 +32,10 @@ extern ConVar* cl_drawconsoleoverlay; extern ConVar* cl_consoleoverlay_lines; extern ConVar* cl_consoleoverlay_offset_x; extern ConVar* cl_consoleoverlay_offset_y; +extern ConVar* cl_consoleoverlay_native_clr; +extern ConVar* cl_consoleoverlay_server_clr; +extern ConVar* cl_consoleoverlay_client_clr; +extern ConVar* cl_consoleoverlay_ui_clr; extern ConVar* cl_showsimstats; extern ConVar* cl_simstats_offset_x; diff --git a/r5dev/vgui/CEngineVGui.cpp b/r5dev/vgui/CEngineVGui.cpp index 8124f9aa..cfe7ac4b 100644 --- a/r5dev/vgui/CEngineVGui.cpp +++ b/r5dev/vgui/CEngineVGui.cpp @@ -70,18 +70,15 @@ void CLogSystem::AddLog(LogType_t type, std::string message) //----------------------------------------------------------------------------- void CLogSystem::DrawLog() { - if (m_vLogs.empty()) - { - return; - } + if (m_vLogs.empty()) { return; } for (int i = 0; i < m_vLogs.size(); ++i) { if (m_vLogs[i].Ticks >= 0) { if (i < cl_consoleoverlay_lines->GetInt()) { - float fadepct = fminf(static_cast(m_vLogs[i].Ticks) / 255.f, 4.0); // TODO [ AMOS ]: register a ConVar for this! - float ptc = static_cast(ceilf(fadepct * 100.f)); // TODO [ AMOS ]: register a ConVar for this! + float fadepct = fminf(static_cast(m_vLogs[i].Ticks) / 255.f, 4.f); // TODO [ AMOS ]: register a ConVar for this! + float ptc = static_cast(ceilf(fadepct * 100.f)); int alpha = static_cast(ptc); int y = (cl_consoleoverlay_offset_y->GetInt() + (fontHeight * i)); int x = cl_consoleoverlay_offset_x->GetInt(); @@ -109,7 +106,7 @@ void CLogSystem::DrawLog() //----------------------------------------------------------------------------- void CLogSystem::DrawSimStats() { - Color c = { 255, 255, 255, 255 }; + static Color c = { 255, 255, 255, 255 }; static const char* szLogbuf[4096]{}; snprintf((char*)szLogbuf, 4096, "Server Frame: (%d) Client Frame: (%d) Render Frame: (%d)\n", *sv_m_nTickCount, *cl_host_tickcount, *render_tickcount); @@ -122,7 +119,7 @@ void CLogSystem::DrawSimStats() //----------------------------------------------------------------------------- void CLogSystem::DrawGPUStats() { - Color c = { 255, 255, 255, 255 }; + static Color c = { 255, 255, 255, 255 }; static const char* szLogbuf[4096]{}; snprintf((char*)szLogbuf, 4096, "%8d/%8d/%8dkiB unusable/unfree/total GPU Streaming Texture memory\n", *unusable_streaming_tex_memory / 1024, *unfree_streaming_tex_memory / 1024, *unusable_streaming_tex_memory / 1024); @@ -137,19 +134,19 @@ Color CLogSystem::GetLogColorForType(LogType_t type) { switch (type) { - case LogType_t::NATIVE: - return { 255, 255, 255, 255 }; - case LogType_t::SCRIPT_SERVER: - return { 190, 183, 240, 255 }; - case LogType_t::SCRIPT_CLIENT: - return { 117, 116, 139, 255 }; - case LogType_t::SCRIPT_UI: - return { 197, 160, 177, 255 }; - default: - return { 255, 255, 255, 255 }; + case LogType_t::NATIVE: + return { cl_consoleoverlay_native_clr->GetColor() }; + case LogType_t::SCRIPT_SERVER: + return { cl_consoleoverlay_server_clr->GetColor() }; + case LogType_t::SCRIPT_CLIENT: + return { cl_consoleoverlay_client_clr->GetColor() }; + case LogType_t::SCRIPT_UI: + return { cl_consoleoverlay_ui_clr->GetColor() }; + default: + return { cl_consoleoverlay_native_clr->GetColor() }; } - return { 255, 255, 255, 255 }; + return { cl_consoleoverlay_native_clr->GetColor() }; } /////////////////////////////////////////////////////////////////////////////// diff --git a/r5dev/vpc/basefilesystem.cpp b/r5dev/vpc/basefilesystem.cpp index 3df3575e..1bff7e83 100644 --- a/r5dev/vpc/basefilesystem.cpp +++ b/r5dev/vpc/basefilesystem.cpp @@ -48,7 +48,7 @@ void HCBaseFileSystem_Warning(void* thisptr, FileWarningLevel_t level, const cha std::string s = fs_oss.str(); const char* c = s.c_str(); - Items.push_back(Strdup((const char*)c)); + g_pIConsole->m_ivConLog.push_back(Strdup((const char*)c)); #endif // !DEDICATED } diff --git a/r5dev/vpklib/packedstore.cpp b/r5dev/vpklib/packedstore.cpp index 8e070f68..0c965fd3 100644 --- a/r5dev/vpklib/packedstore.cpp +++ b/r5dev/vpklib/packedstore.cpp @@ -66,11 +66,11 @@ vpk_dir_h CPackedStore::GetPackDirFile(std::string svPackDirFile) { std::string svPackDirPrefix = DIR_LOCALE_PREFIX[i] + DIR_LOCALE_PREFIX[i]; StringReplace(svPackDirFile, DIR_LOCALE_PREFIX[i].c_str(), svPackDirPrefix.c_str()); - break; + goto escape; } } } - } + }escape:; } vpk_dir_h vpk_dir(svPackDirFile); @@ -195,11 +195,8 @@ void CPackedStore::UnpackAll(vpk_dir_h vpk_dir, std::string svPathOut) for ( vpk_entry_block block : vpk_dir.m_vvEntryBlocks) { - if (block.m_iArchiveIndex != i) - { - // Break if block archive index is not part of the extracting archive chunk index. - break; - } + // Escape if block archive index is not part of the extracting archive chunk index. + if (block.m_iArchiveIndex != i) { goto escape; } else { std::string svFilePath = CreateDirectories(svPathOut + "\\" + block.m_svBlockPath); @@ -271,9 +268,9 @@ void CPackedStore::UnpackAll(vpk_dir_h vpk_dir, std::string svPathOut) ValidateCRC32PostDecomp(svFilePath); //ValidateAdler32PostDecomp(svFilePath); - m_nEntryCount = 0; + m_nEntryCount = 0; } - }cont:; + }escape:; } packChunkStream.close(); } @@ -357,7 +354,7 @@ vpk_dir_h::vpk_dir_h(std::string svPath) for (int i = 0; i < this->m_iArchiveCount + 1; i++) { std::string svArchivePath = g_pPackedStore->GetPackChunkFile(svPath, i); - DevMsg(eDLL_T::FS, "] '%s\n", svArchivePath.c_str()); + DevMsg(eDLL_T::FS, "] '%s'\n", svArchivePath.c_str()); this->m_vsvArchives.push_back(svArchivePath); } } diff --git a/r5dev/windows/id3dx.cpp b/r5dev/windows/id3dx.cpp index 4bce7642..a774b3bc 100644 --- a/r5dev/windows/id3dx.cpp +++ b/r5dev/windows/id3dx.cpp @@ -29,8 +29,6 @@ typedef BOOL(WINAPI* IPostMessageA)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM l typedef BOOL(WINAPI* IPostMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); /////////////////////////////////////////////////////////////////////////////////// -extern BOOL g_bShowConsole = false; -extern BOOL g_bShowBrowser = false; static BOOL g_bInitMenu = false; static BOOL g_bInitialized = false; static BOOL g_bPresentHooked = false; @@ -68,16 +66,16 @@ LRESULT CALLBACK HwndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (wParam == g_pImGuiConfig->IConsole_Config.m_nBind0 || wParam == g_pImGuiConfig->IConsole_Config.m_nBind1) { - g_bShowConsole = !g_bShowConsole; + g_pIConsole->m_bActivate = !g_pIConsole->m_bActivate; } if (wParam == g_pImGuiConfig->IBrowser_Config.m_nBind0 || wParam == g_pImGuiConfig->IBrowser_Config.m_nBind1) { - g_bShowBrowser = !g_bShowBrowser; + g_pIBrowser->m_bActivate = !g_pIBrowser->m_bActivate; } } - if (g_bShowConsole || g_bShowBrowser) + if (g_pIConsole->m_bActivate || g_pIBrowser->m_bActivate) {////////////////////////////////////////////////////////////////////////////// ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam); g_bBlockInput = true; @@ -267,25 +265,22 @@ void SetupImGui() void DrawImGui() { - bool bShowConsole = g_bShowConsole; - bool bShowBrowser = g_bShowBrowser; - ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - if (g_bShowConsole) + if (g_pIConsole->m_bActivate) { g_pInputSystem->EnableInput(false); // Disable input to game when console is drawn. - DrawConsole(&bShowConsole); + g_pIConsole->Draw("Console", &g_pIConsole->m_bActivate); } - if (g_bShowBrowser) + if (g_pIBrowser->m_bActivate) { g_pInputSystem->EnableInput(false); // Disable input to game when browser is drawn. - DrawBrowser(&bShowBrowser); + g_pIBrowser->Draw("Server Browser", &g_pIBrowser->m_bActivate); } - if (!g_bShowConsole && !g_bShowBrowser) + if (!g_pIConsole->m_bActivate && !g_pIBrowser->m_bActivate) { g_pInputSystem->EnableInput(true); // Enable input to game when both are not drawn. } @@ -371,8 +366,8 @@ HRESULT GetDeviceAndCtxFromSwapchain(IDXGISwapChain* pSwapChain, ID3D11Device** HRESULT __stdcall GetResizeBuffers(IDXGISwapChain* pSwapChain, UINT nBufferCount, UINT nWidth, UINT nHeight, DXGI_FORMAT dxFormat, UINT nSwapChainFlags) { - g_bShowConsole = false; - g_bShowBrowser = false; + g_pIConsole->m_bActivate = false; + g_pIBrowser->m_bActivate = false; g_bInitialized = false; g_bPresentHooked = false; diff --git a/r5dev/windows/id3dx.h b/r5dev/windows/id3dx.h index 3a773db8..9d6737d9 100644 --- a/r5dev/windows/id3dx.h +++ b/r5dev/windows/id3dx.h @@ -28,8 +28,6 @@ typedef HRESULT(__stdcall* IDXGIResizeBuffers) (IDXGISwapChain* pSwapChain, UI ///////////////////////////////////////////////////////////////////////////// // Globals extern DWORD g_dThreadId; -extern BOOL g_bShowConsole; -extern BOOL g_bShowBrowser; ///////////////////////////////////////////////////////////////////////////// // Enums