From 983172006bd937db2d330dbf69b71ac2144a7015 Mon Sep 17 00:00:00 2001 From: IcePixelx <41352111+PixieCore@users.noreply.github.com> Date: Sun, 8 Aug 2021 22:13:54 +0200 Subject: [PATCH 1/2] code clean up --- r5dev/include/enums.h | 14 ++ r5dev/src/CCompanion.cpp | 110 +++++++------ r5dev/src/CGameConsole.cpp | 314 +++++++++++++++++++------------------ 3 files changed, 228 insertions(+), 210 deletions(-) diff --git a/r5dev/include/enums.h b/r5dev/include/enums.h index 435722f2..9467d4a0 100644 --- a/r5dev/include/enums.h +++ b/r5dev/include/enums.h @@ -342,4 +342,18 @@ enum HostStates_t HS_GAME_SHUTDOWN = 0x5, HS_SHUTDOWN = 0x6, HS_RESTART = 0x7, +}; + +enum SIGNONSTATE +{ + SIGNONSTATE_NONE = 0, // no state yet; about to connect + SIGNONSTATE_CHALLENGE = 1, // client challenging server; all OOB packets + SIGNONSTATE_CONNECTED = 2, // client is connected to server; netchans ready + SIGNONSTATE_NEW = 3, // just got serverinfo and string tables + SIGNONSTATE_PRESPAWN = 4, // received signon buffers + SIGNONSTATE_GETTING_DATA = 5, // getting persistence data I assume? + SIGNONSTATE_SPAWN = 6, // ready to receive entity packets + SIGNONSTATE_FIRST_SNAP = 7, // ??? + SIGNONSTATE_FULL = 8, // we are fully connected; first non-delta packet received + SIGNONSTATE_CHANGELEVEL = 9, // server is changing level; please wait }; \ No newline at end of file diff --git a/r5dev/src/CCompanion.cpp b/r5dev/src/CCompanion.cpp index 21116d49..c9a6f732 100644 --- a/r5dev/src/CCompanion.cpp +++ b/r5dev/src/CCompanion.cpp @@ -127,10 +127,11 @@ void CCompanion::SendHostingPostRequest() #endif httplib::Result result = client.Post("/servers/add", body_str.c_str(), body_str.length(), "application/json"); -#ifdef OVERLAY_DEBUG if (result) { +#ifdef OVERLAY_DEBUG std::cout << " [+CCompanion+] Request Result: " << result->body << "\n"; +#endif nlohmann::json res = nlohmann::json::parse(result->body); if (!res["success"] && !res["err"].is_null()) { @@ -155,9 +156,7 @@ void CCompanion::SendHostingPostRequest() HostRequestMessage = ""; HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); } - } -#endif } const nlohmann::json CCompanion::SendGetServerByTokenRequest(const std::string &token, const std::string &password) @@ -181,7 +180,6 @@ const nlohmann::json CCompanion::SendGetServerByTokenRequest(const std::string & return nlohmann::json::object(); } - void CCompanion::CompMenu() { ImGui::BeginTabBar("CompMenu"); @@ -214,50 +212,52 @@ void CCompanion::ServerBrowserSection() const float FooterHeight = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); ImGui::BeginChild("ServerListChild", { 0, -FooterHeight }, true, ImGuiWindowFlags_AlwaysVerticalScrollbar); - ImGui::BeginTable("##ServerBrowser_ServerList", 4, ImGuiTableFlags_Resizable); { - ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 35); - ImGui::TableSetupColumn("Map", ImGuiTableColumnFlags_WidthStretch, 25); - ImGui::TableSetupColumn("Port", ImGuiTableColumnFlags_WidthStretch, 10); - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch, 8); - ImGui::TableHeadersRow(); - - for (ServerListing* server : ServerList) + ImGui::BeginTable("##ServerBrowser_ServerList", 4, ImGuiTableFlags_Resizable); { - const char* name = server->name.c_str(); - const char* map = server->map.c_str(); - const char* port = server->port.c_str(); + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 35); + ImGui::TableSetupColumn("Map", ImGuiTableColumnFlags_WidthStretch, 25); + ImGui::TableSetupColumn("Port", ImGuiTableColumnFlags_WidthStretch, 10); + ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch, 8); + ImGui::TableHeadersRow(); - if (ServerBrowserFilter.PassFilter(name) - || ServerBrowserFilter.PassFilter(map) - || ServerBrowserFilter.PassFilter(port)) + for (ServerListing* server : ServerList) { - ImGui::TableNextColumn(); - ImGui::Text(name); + const char* name = server->name.c_str(); + const char* map = server->map.c_str(); + const char* port = server->port.c_str(); - ImGui::TableNextColumn(); - ImGui::Text(map); - - ImGui::TableNextColumn(); - ImGui::Text(port); - - ImGui::TableNextColumn(); - std::string selectButtonText = "Connect##"; - selectButtonText += (server->name + server->ip + server->map); - - if (ImGui::Button(selectButtonText.c_str())) + if (ServerBrowserFilter.PassFilter(name) + || ServerBrowserFilter.PassFilter(map) + || ServerBrowserFilter.PassFilter(port)) { - SelectedServer = server; - server->Select(); + ImGui::TableNextColumn(); + ImGui::Text(name); + + ImGui::TableNextColumn(); + ImGui::Text(map); + + ImGui::TableNextColumn(); + ImGui::Text(port); + + ImGui::TableNextColumn(); + std::string selectButtonText = "Connect##"; + selectButtonText += (server->name + server->ip + server->map); + + if (ImGui::Button(selectButtonText.c_str())) + { + SelectedServer = server; + server->Select(); + } } } - } + ImGui::EndTable(); } - ImGui::EndTable(); ImGui::EndChild(); ImGui::Separator(); + ImGui::InputTextWithHint("##ServerBrowser_ServerConnString", "Enter IP address or \"localhost\"", ServerConnStringBuffer, IM_ARRAYSIZE(ServerConnStringBuffer)); ImGui::SameLine(); @@ -508,29 +508,25 @@ void CCompanion::Draw(const char* title) ImGui::SetNextWindowSize(ImVec2(840, 600), ImGuiCond_FirstUseEver); ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver); - if (!ImGui::Begin(title, NULL, ImGuiWindowFlags_NoScrollbar)) + ImGui::Begin(title, NULL, ImGuiWindowFlags_NoScrollbar); { - ImGui::End(); - return; - } - /////////////////////////////////////////////////////////////////////// - CompMenu(); + CompMenu(); - switch (CurrentSection) - { - case ESection::ServerBrowser: - ServerBrowserSection(); - break; - case ESection::HostServer: - HostServerSection(); - break; - case ESection::Settings: - SettingsSection(); - break; - default: - break; + switch (CurrentSection) + { + case ESection::ServerBrowser: + ServerBrowserSection(); + break; + case ESection::HostServer: + HostServerSection(); + break; + case ESection::Settings: + SettingsSection(); + break; + default: + break; + } } - ImGui::End(); } @@ -555,14 +551,14 @@ void CCompanion::ConnectToServer(const std::string& ip, const std::string& port) { std::stringstream cmd; cmd << "connect " << ip << ":" << port; - g_ServerBrowser->ProcessCommand(cmd.str().c_str()); + ProcessCommand(cmd.str().c_str()); } void CCompanion::ConnectToServer(const std::string& connString) { std::stringstream cmd; cmd << "connect " << connString; - g_ServerBrowser->ProcessCommand(cmd.str().c_str()); + ProcessCommand(cmd.str().c_str()); } //############################################################################# diff --git a/r5dev/src/CGameConsole.cpp b/r5dev/src/CGameConsole.cpp index 722e6126..4d6956b4 100644 --- a/r5dev/src/CGameConsole.cpp +++ b/r5dev/src/CGameConsole.cpp @@ -29,7 +29,6 @@ CGameConsole::CGameConsole() Commands.push_back("CLEAR"); Commands.push_back("CLASSIFY"); - AddLog("[DEBUG] THREAD ID: %ld\n", g_dThreadId); } @@ -59,177 +58,186 @@ void CGameConsole::Draw(const char* title) ImGui::SetNextWindowSize(ImVec2(1000, 600), ImGuiCond_FirstUseEver); ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver); - if (!ImGui::Begin(title, NULL)) // Passing a bool only causes problems if you Begin a new window. I would not suggest to use it. + ImGui::Begin(title, NULL); // ImGui::Begin should never fail, if it does we got another problem. { - ImGui::End(); return; - } - // 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(); + // Reserve enough left-over height and width for 1 separator + 1 input text + const float FooterHeightToReserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); + const float FooterWidthtoReserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetWindowWidth(); - /////////////////////////////////////////////////////////////////////// - ImGui::Separator(); - if (ImGui::BeginPopup("Options")) - { - ImGui::Checkbox("Auto-scroll", &AutoScroll); - if (ImGui::SmallButton("Clear")) + /////////////////////////////////////////////////////////////////////// + ImGui::Separator(); + if (ImGui::BeginPopup("Options")) { - ClearLog(); + ImGui::Checkbox("Auto-scroll", &AutoScroll); + if (ImGui::SmallButton("Clear")) + { + ClearLog(); + } + copy_to_clipboard = ImGui::SmallButton("Copy"); + ImGui::EndPopup(); } - copy_to_clipboard = ImGui::SmallButton("Copy"); - ImGui::EndPopup(); - } - if (ImGui::Button("Options")) - { - ImGui::OpenPopup("Options"); - } - ImGui::SameLine(); - if (ImGui::BeginPopup("Tools")) - { - Hooks::bToggledDevFlags ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255)); - if (ImGui::SmallButton("Developer Mode")) + if (ImGui::Button("Options")) { - Hooks::ToggleDevCommands(); - AddLog("+--------------------------------------------------------+\n"); - AddLog("|>>>>>>>>>>>>>>| DEVONLY COMMANDS TOGGLED |<<<<<<<<<<<<<<|\n"); - AddLog("+--------------------------------------------------------+\n"); - ProcessCommand("exec autoexec"); + ImGui::OpenPopup("Options"); } - ImGui::PopStyleColor(); // Pop color override. - Hooks::bToggledNetTrace ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255)); - if (ImGui::SmallButton("Netchannel Trace")) + ImGui::SameLine(); + if (ImGui::BeginPopup("Tools")) { - Hooks::ToggleNetTrace(); - AddLog("+--------------------------------------------------------+\n"); - AddLog("|>>>>>>>>>>>>>>| NETCHANNEL TRACE TOGGLED |<<<<<<<<<<<<<<|\n"); - AddLog("+--------------------------------------------------------+\n"); - ProcessCommand("exec netchan"); + Hooks::bToggledDevFlags ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255)); + if (ImGui::SmallButton("Developer Mode")) + { + Hooks::ToggleDevCommands(); + AddLog("+--------------------------------------------------------+\n"); + AddLog("|>>>>>>>>>>>>>>| DEVONLY COMMANDS TOGGLED |<<<<<<<<<<<<<<|\n"); + AddLog("+--------------------------------------------------------+\n"); + ProcessCommand("exec autoexec"); + } + ImGui::PopStyleColor(); // Pop color override. + Hooks::bToggledNetTrace ? ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 255, 0, 255)) : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 0, 0, 255)); + if (ImGui::SmallButton("Netchannel Trace")) + { + Hooks::ToggleNetTrace(); + AddLog("+--------------------------------------------------------+\n"); + AddLog("|>>>>>>>>>>>>>>| NETCHANNEL TRACE TOGGLED |<<<<<<<<<<<<<<|\n"); + AddLog("+--------------------------------------------------------+\n"); + ProcessCommand("exec netchan"); + } + ImGui::PopStyleColor(); // Pop color override. + ImGui::EndPopup(); } - ImGui::PopStyleColor(); // Pop color override. - ImGui::EndPopup(); - } - if (ImGui::Button("Tools")) - { - ImGui::OpenPopup("Tools"); - } - ImGui::SameLine(); - Filter.Draw("Filter [\"-incl,-excl\"] [\"error\"]", footer_width_to_reserve - 500); - ImGui::Separator(); - - /////////////////////////////////////////////////////////////////////// - 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) - { - ImGui::LogToClipboard(); - } - for (int i = 0; i < Items.Size; i++) - { - const char* item = Items[i]; - if (!Filter.PassFilter(item)) + if (ImGui::Button("Tools")) { - continue; + ImGui::OpenPopup("Tools"); } - /////////////////////////////////////////////////////////////////// - ImVec4 color; - bool has_color = false; + ImGui::SameLine(); + Filter.Draw("Filter [\"-incl,-excl\"] [\"error\"]", FooterWidthtoReserve - 500); + ImGui::Separator(); - /////////////////////////////////////////////////////////////////// - // 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; } + /////////////////////////////////////////////////////////////////////// + ImGui::BeginChild("ScrollingRegion", ImVec2(0, -FooterHeightToReserve), true, ImGuiWindowFlags_AlwaysVerticalScrollbar); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 4.f, 6.f }); + if (copy_to_clipboard) + { + ImGui::LogToClipboard(); + } + for (int i = 0; i < Items.Size; i++) + { + const char* item = Items[i]; + if (!Filter.PassFilter(item)) + { + continue; + } + /////////////////////////////////////////////////////////////////// + ImVec4 color; + bool has_color = false; - /////////////////////////////////////////////////////////////////// - // Virtual machines - 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; } + /////////////////////////////////////////////////////////////////// + // 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; } - /////////////////////////////////////////////////////////////////// - // Callbacks - //if (strstr(item, "CodeCallback_")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } + /////////////////////////////////////////////////////////////////// + // Virtual machines + 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; } - /////////////////////////////////////////////////////////////////// - // 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; } + /////////////////////////////////////////////////////////////////// + // Callbacks + //if (strstr(item, "CodeCallback_")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } - /////////////////////////////////////////////////////////////////// - // 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; } + /////////////////////////////////////////////////////////////////// + // 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; } - /////////////////////////////////////////////////////////////////// - // Filters - //if (strstr(item, ") -> ")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; } + /////////////////////////////////////////////////////////////////// + // 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; } - if (has_color) { ImGui::PushStyleColor(ImGuiCol_Text, color); } - ImGui::TextWrapped(item); - if (has_color) { ImGui::PopStyleColor(); } + /////////////////////////////////////////////////////////////////// + // 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(); } + } + if (copy_to_clipboard) { ImGui::LogFinish(); } + + if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) { ImGui::SetScrollHereY(1.0f); } + ScrollToBottom = false; + + /////////////////////////////////////////////////////////////////////// + ImGui::PopStyleVar(); + ImGui::EndChild(); + ImGui::Separator(); + + /////////////////////////////////////////////////////////////////////// + // Console + bool ShouldReclaimFocus = false; + ImGui::PushItemWidth(FooterWidthtoReserve - 80); + if (ImGui::IsWindowAppearing()) { ImGui::SetKeyboardFocusHere(); } + ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; + + std::function CommandExec = [&](char* InputBuf) + { + char* s = InputBuf; + const char* replace = ""; + if (strstr(InputBuf, "`")) + { + strcpy_s(s, sizeof(replace), replace); + } + + Strtrim(s); + + if (s[0]) + { + ProcessCommand(s); + } + + strcpy_s(s, sizeof(replace), replace); + ShouldReclaimFocus = true; + }; + + if (ImGui::InputText("##input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this)) + { + CommandExec(InputBuf); + } + + ImGui::SameLine(); + + if (ImGui::Button("Submit")) + { + CommandExec(InputBuf); + } + + // Auto-focus on window apparition + ImGui::SetItemDefaultFocus(); + + // Auto focus previous widget + if (ShouldReclaimFocus) + { + ImGui::SetKeyboardFocusHere(-1); + } } - if (copy_to_clipboard) { ImGui::LogFinish(); } - - if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) { ImGui::SetScrollHereY(1.0f); } - ScrollToBottom = 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; - - if (ImGui::InputText("##input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this)) - { - char* s = InputBuf; - const char* replace = ""; - if (strstr(InputBuf, "`")) { strcpy_s(s, sizeof(replace), replace); } - Strtrim(s); - if (s[0]) { ProcessCommand(s); } - strcpy_s(s, sizeof(replace), replace); - reclaim_focus = true; - } - - ImGui::SameLine(); - if (ImGui::Button("Submit")) - { - char* s = InputBuf; - const char* replace = ""; - if (s[0]) { ProcessCommand(s); } - strcpy_s(s, sizeof(replace), replace); - reclaim_focus = true; - } - - // Auto-focus on window apparition - ImGui::SetItemDefaultFocus(); - - // Auto focus previous widget - if (reclaim_focus) - { - ImGui::SetKeyboardFocusHere(-1); - } - ImGui::End(); } From 443d3fcc1581ba79dd4e6c41134725a75563ffb8 Mon Sep 17 00:00:00 2001 From: IcePixelx <41352111+PixieCore@users.noreply.github.com> Date: Sun, 8 Aug 2021 22:32:30 +0200 Subject: [PATCH 2/2] added filesystemwarning hook, commented and not doing anything yet --- r5dev/include/enums.h | 13 +++++++++++++ r5dev/include/hooks.h | 7 +++++++ r5dev/include/patterns.h | 5 +++++ r5dev/r5dev.vcxproj | 1 + r5dev/r5dev.vcxproj.filters | 6 ++++++ r5dev/src/hooks/cbasefilesystem.cpp | 12 ++++++++++++ r5dev/src/hooks/hooks.cpp | 12 ++++++++++++ 7 files changed, 56 insertions(+) create mode 100644 r5dev/src/hooks/cbasefilesystem.cpp diff --git a/r5dev/include/enums.h b/r5dev/include/enums.h index 9467d4a0..e51e8569 100644 --- a/r5dev/include/enums.h +++ b/r5dev/include/enums.h @@ -356,4 +356,17 @@ enum SIGNONSTATE SIGNONSTATE_FIRST_SNAP = 7, // ??? SIGNONSTATE_FULL = 8, // we are fully connected; first non-delta packet received SIGNONSTATE_CHANGELEVEL = 9, // server is changing level; please wait +}; + +enum FileWarningLevel_t +{ + FILESYSTEM_WARNING = -1, + FILESYSTEM_WARNING_QUIET = 0, + FILESYSTEM_WARNING_REPORTUNCLOSED, + FILESYSTEM_WARNING_REPORTUSAGE, + FILESYSTEM_WARNING_REPORTALLACCESSES, + FILESYSTEM_WARNING_REPORTALLACCESSES_READ, + FILESYSTEM_WARNING_REPORTALLACCESSES_READWRITE, + FILESYSTEM_WARNING_REPORTALLACCESSES_ASYNC + }; \ No newline at end of file diff --git a/r5dev/include/hooks.h b/r5dev/include/hooks.h index 1de9564a..f59366a7 100644 --- a/r5dev/include/hooks.h +++ b/r5dev/include/hooks.h @@ -78,6 +78,13 @@ namespace Hooks extern ShowCursorFn originalShowCursor; #pragma endregion +#pragma region CBaseFileSystem + void FileSystemWarning(void* thisptr, FileWarningLevel_t level, const char* fmt, ...); + + using FileSystemWarningFn = void(*)(void*, FileWarningLevel_t, const char*, ...); + extern FileSystemWarningFn originalFileSystemWarning; +#pragma endregion + #pragma region Other int MSG_EngineError(char* fmt, va_list args); diff --git a/r5dev/include/patterns.h b/r5dev/include/patterns.h index 67402636..ea2eb7d3 100644 --- a/r5dev/include/patterns.h +++ b/r5dev/include/patterns.h @@ -51,6 +51,10 @@ namespace FUNC_AT_ADDRESS(addr_CVEngineServer_IsPersistenceDataAvailable, bool(*)(__int64, int), r5_patterns.PatternSearch("3B 15 ?? ?? ?? ?? 7D 33").GetPtr()); #pragma endregion +#pragma region CBaseFileSystem + FUNC_AT_ADDRESS(addr_CBaseFileSystem_FileSystemWarning, void(*)(void*, FileWarningLevel_t, const char*, ...), r5_patterns.PatternSearch("E8 ? ? ? ? 33 C0 80 3B 2A").FollowNearCallSelf().GetPtr()); +#pragma endregion + #pragma region Utility /*0x140295600*/ FUNC_AT_ADDRESS(addr_MSG_EngineError, int(*)(char*, va_list), r5_patterns.PatternSearch("48 89 5C 24 08 48 89 74 24 10 57 48 81 EC 30 08 00 00 48 8B DA").GetPtr()); @@ -72,6 +76,7 @@ namespace PRINT_ADDRESS("NET_SendDatagram ", addr_NET_SendDatagram); PRINT_ADDRESS("CHLClient::FrameStageNotify", addr_CHLClient_FrameStageNotify); PRINT_ADDRESS("CVEngineServer::IsPersistenceDataAvailable", addr_CVEngineServer_IsPersistenceDataAvailable); + PRINT_ADDRESS("CBaseFileSystem::FileSystemWarning", addr_CBaseFileSystem_FileSystemWarning); PRINT_ADDRESS("MSG_EngineError", addr_MSG_EngineError); std::cout << "+--------------------------------------------------------+" << std::endl; // TODO implement error handling when sigscan fails or result is 0 diff --git a/r5dev/r5dev.vcxproj b/r5dev/r5dev.vcxproj index 7a0958d8..ae70997b 100644 --- a/r5dev/r5dev.vcxproj +++ b/r5dev/r5dev.vcxproj @@ -369,6 +369,7 @@ Use pch.h + diff --git a/r5dev/r5dev.vcxproj.filters b/r5dev/r5dev.vcxproj.filters index 395730dd..6d13b7f3 100644 --- a/r5dev/r5dev.vcxproj.filters +++ b/r5dev/r5dev.vcxproj.filters @@ -100,6 +100,9 @@ {1979149f-6402-4985-b900-25a91f1168ac} + + {90ee1072-2d57-4d4e-aa1e-f19a81e6b27f} + @@ -186,6 +189,9 @@ gui + + hooks\src\cbasefilesystem + diff --git a/r5dev/src/hooks/cbasefilesystem.cpp b/r5dev/src/hooks/cbasefilesystem.cpp new file mode 100644 index 00000000..51edd63d --- /dev/null +++ b/r5dev/src/hooks/cbasefilesystem.cpp @@ -0,0 +1,12 @@ +#include "pch.h" +#include "hooks.h" +namespace Hooks +{ + FileSystemWarningFn originalFileSystemWarning = nullptr; +} + +void Hooks::FileSystemWarning(void* thisptr, FileWarningLevel_t level, const char* fmt, ...) +{ +// How you call original functions, you dont need it here. +// originalFileSystemWarning(thisptr, level, fmt, ...); +} \ No newline at end of file diff --git a/r5dev/src/hooks/hooks.cpp b/r5dev/src/hooks/hooks.cpp index 212cf262..3793c8a8 100644 --- a/r5dev/src/hooks/hooks.cpp +++ b/r5dev/src/hooks/hooks.cpp @@ -37,6 +37,10 @@ void Hooks::InstallHooks() MH_CreateHook(addr_ConVar_IsFlagSet, &Hooks::ConVar_IsFlagSet, NULL); MH_CreateHook(addr_ConCommand_IsFlagSet, &Hooks::ConCommand_IsFlagSet, NULL); + /////////////////////////////////////////////////////////////////////////////// + // Hooks CBaseFileSystem functions. + //MH_CreateHook(addr_CBaseFileSystem_FileSystemWarning, &Hooks::FileSystemWarning, reinterpret_cast(&originalFileSystemWarning); + /////////////////////////////////////////////////////////////////////////////// // Hook Utility functions MH_CreateHook(addr_MSG_EngineError, &Hooks::MSG_EngineError, reinterpret_cast(&originalMSG_EngineError)); @@ -85,6 +89,10 @@ void Hooks::InstallHooks() MH_EnableHook(addr_ConVar_IsFlagSet); MH_EnableHook(addr_ConCommand_IsFlagSet); + /////////////////////////////////////////////////////////////////////////////// + // Enable CBaseFileSystem hooks + //MH_EnableHook(addr_CBaseFileSystem_FileSystemWarning); + /////////////////////////////////////////////////////////////////////////////// // Enabled Utility hooks MH_EnableHook(addr_MSG_EngineError); @@ -135,6 +143,10 @@ void Hooks::RemoveHooks() // Unhook Utility functions MH_RemoveHook(addr_MSG_EngineError); + /////////////////////////////////////////////////////////////////////////////// + // Unhook CBaseFileSystem functions. + //MH_RemoveHook(addr_CBaseFileSystem_FileSystemWarning); + /////////////////////////////////////////////////////////////////////////////// // Reset Minhook MH_Uninitialize();