From 2f239760adb657f6e3d6a4040634bc5a97a5fd6b Mon Sep 17 00:00:00 2001 From: IcePixelx <41352111+PixieCore@users.noreply.github.com> Date: Mon, 19 Jul 2021 14:31:12 +0200 Subject: [PATCH] Assign g_GameConsole ptr only 1 time, Fixed variable initialization, fixed overlay.cpp crash with free call. --- r5dev/include/overlay.h | 7 ++++--- r5dev/src/overlay.cpp | 42 +++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/r5dev/include/overlay.h b/r5dev/include/overlay.h index 189b8eb9..09dc3dac 100644 --- a/r5dev/include/overlay.h +++ b/r5dev/include/overlay.h @@ -182,10 +182,11 @@ public: //////////////////// std::vector MapsList; std::string* SelectedMap = nullptr; - std::string HostRequestMessage; - ImVec4 HostRequestMessageColor; + std::string HostRequestMessage = ""; + ImVec4 HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); char ServerNameBuffer[64] = { 0 }; - bool StartAsDedi; + bool StartAsDedi = false; + bool BroadCastServer = false; void SetSection(ESection section) { diff --git a/r5dev/src/overlay.cpp b/r5dev/src/overlay.cpp index 321363e0..8b339908 100644 --- a/r5dev/src/overlay.cpp +++ b/r5dev/src/overlay.cpp @@ -246,7 +246,7 @@ void CGameConsole::ProcessCommand(const char* command_line) { if (Stricmp(History[i], command_line) == 0) { - free(History[i]); + delete History[i]; History.erase(History.begin() + i); break; } @@ -384,6 +384,9 @@ void CCompanion::UpdateHostingStatus() } case EHostStatus::Hosting: { + if (!BroadCastServer) // Do we wanna broadcast server to the browser? + break; + SendHostingPostRequest(GameGlobals::HostState->m_levelName); break; } @@ -559,6 +562,8 @@ void CCompanion::ServerBrowserSection() void CCompanion::HostServerSection() { + static std::string ServerNameErr = ""; + ImGui::InputTextWithHint("Server Name##ServerHost_ServerName", "Required Field", ServerNameBuffer, IM_ARRAYSIZE(ServerNameBuffer)); ImGui::Spacing(); if (ImGui::BeginCombo("Map##ServerHost_MapListBox", SelectedMap->c_str())) @@ -576,22 +581,36 @@ void CCompanion::HostServerSection() ImGui::Checkbox("Start as dedicated server (HACK)##ServerHost_DediCheckbox", &StartAsDedi); + ImGui::SameLine(); + + ImGui::Checkbox("Broadcast Server to Server Browser", &BroadCastServer); + ImGui::Separator(); if (ImGui::Button("Start The Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32))) { - UpdateHostingStatus(); - - std::stringstream cmd; - cmd << "map " << SelectedMap->c_str(); - g_GameConsole->ProcessCommand(cmd.str().c_str()); - - if (StartAsDedi) + if (strlen(ServerNameBuffer) != 0) { - ToggleDevCommands(); + ServerNameErr = std::string(); + UpdateHostingStatus(); + + std::stringstream cmd; + cmd << "map " << SelectedMap->c_str(); + g_GameConsole->ProcessCommand(cmd.str().c_str()); + + if (StartAsDedi) + { + ToggleDevCommands(); + } + } + else + { + HostRequestMessage = "No Server Name assigned."; + HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); } } + ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), ServerNameErr.c_str()); ImGui::TextColored(HostRequestMessageColor, HostRequestMessage.c_str()); if (StartAsDedi) @@ -696,7 +715,10 @@ void Strtrim(char* s) void DrawConsole() { static CGameConsole console; - g_GameConsole = &console; + static bool AssignPtr = []() { + g_GameConsole = &console; + return true; + } (); console.Draw("Console"); }