From 8004ee4db373f8697f0ec1c07f20aca94792cd63 Mon Sep 17 00:00:00 2001
From: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date: Sat, 31 Jul 2021 16:51:06 +0200
Subject: [PATCH] Added more Server Host Utils.
---
r5dev/include/enums.h | 12 ++++++++++++
r5dev/include/gameclasses.h | 2 +-
r5dev/include/overlay.h | 1 -
r5dev/r5dev.vcxproj.filters | 6 ++++++
r5dev/src/overlay.cpp | 26 +++++++++++++++++---------
5 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/r5dev/include/enums.h b/r5dev/include/enums.h
index 9d0d470b..435722f2 100644
--- a/r5dev/include/enums.h
+++ b/r5dev/include/enums.h
@@ -331,3 +331,15 @@ enum ClientFrameStage_t
FRAME_NET_FULL_FRAME_UPDATE_ON_REMOVE
};
+
+enum HostStates_t
+{
+ HS_NEW_GAME = 0x0,
+ HS_LOAD_GAME = 0x1,
+ HS_CHANGE_LEVEL_SP = 0x2,
+ HS_CHANGE_LEVEL_MP = 0x3,
+ HS_RUN = 0x4,
+ HS_GAME_SHUTDOWN = 0x5,
+ HS_SHUTDOWN = 0x6,
+ HS_RESTART = 0x7,
+};
\ No newline at end of file
diff --git a/r5dev/include/gameclasses.h b/r5dev/include/gameclasses.h
index e0cb8599..486509d4 100644
--- a/r5dev/include/gameclasses.h
+++ b/r5dev/include/gameclasses.h
@@ -236,7 +236,7 @@ class CHostState
{
public:
__int32 m_iCurrentState; //0x0000
- __int32 n_iNextState; //0x0004
+ __int32 m_iNextState; //0x0004
Vector3 m_vecLocation; //0x0008
QAngle m_angLocation; //0x0014
char m_levelName[64]; //0x0020
diff --git a/r5dev/include/overlay.h b/r5dev/include/overlay.h
index 1dafde50..023e159f 100644
--- a/r5dev/include/overlay.h
+++ b/r5dev/include/overlay.h
@@ -267,7 +267,6 @@ public:
}
void RefreshServerList();
- void UpdateMyServerInfo();
void SendHostingPostRequest();
const nlohmann::json SendGetServerByTokenRequest(const std::string &token, const std::string &password);
void CompMenu();
diff --git a/r5dev/r5dev.vcxproj.filters b/r5dev/r5dev.vcxproj.filters
index 34b18dc7..f2611110 100644
--- a/r5dev/r5dev.vcxproj.filters
+++ b/r5dev/r5dev.vcxproj.filters
@@ -177,6 +177,9 @@
r5-sdk\src
+
+ shared\libraries\imgui
+
@@ -539,6 +542,9 @@
core\include
+
+ shared\libraries\imgui\include
+
diff --git a/r5dev/src/overlay.cpp b/r5dev/src/overlay.cpp
index 633e98c1..621e8932 100644
--- a/r5dev/src/overlay.cpp
+++ b/r5dev/src/overlay.cpp
@@ -353,11 +353,6 @@ CCompanion::CCompanion()
HostingServerRequestThread.detach();
}
-void CCompanion::UpdateMyServerInfo()
-{
- MyServer.map = GameGlobals::HostState->m_levelName;
-
-}
void CCompanion::UpdateHostingStatus()
{
if (!GameGlobals::HostState || !GameGlobals::Cvar) // Is HostState and Cvar valid?
@@ -378,7 +373,6 @@ void CCompanion::UpdateHostingStatus()
if (!BroadCastServer) // Do we wanna broadcast server to the browser?
break;
- UpdateMyServerInfo();
SendHostingPostRequest();
break;
}
@@ -429,7 +423,7 @@ void CCompanion::SendHostingPostRequest()
// send a post request to "/servers/add" with a json body
nlohmann::json body = nlohmann::json::object();
body["name"] = MyServer.name;
- body["map"] = MyServer.map;
+ body["map"] = std::string(GameGlobals::HostState->m_levelName);
static ConVar* hostport = GameGlobals::Cvar->FindVar("hostport"); // static since it won't move memory locations.
body["port"] = hostport->m_pzsCurrentValue; //body["port"] = MyServer.port;
body["password"] = MyServer.password;
@@ -771,6 +765,12 @@ void CCompanion::HostServerSection()
}
}
+ if (ImGui::Button("Force Start##ServerHost_ForceStart", ImVec2(ImGui::GetWindowSize().x, 32)))
+ {
+ strncpy_s(GameGlobals::HostState->m_levelName, MyServer.map.c_str(), 64); // Copy new map into hoststate levelname. 64 is size of m_levelname.
+ GameGlobals::HostState->m_iNextState = HostStates_t::HS_NEW_GAME; // Force CHostState::FrameUpdate to start a server.
+ }
+
ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), ServerNameErr.c_str());
ImGui::TextColored(HostRequestMessageColor, HostRequestMessage.c_str());
if (!HostToken.empty())
@@ -778,16 +778,24 @@ void CCompanion::HostServerSection()
ImGui::InputText("##ServerHost_HostToken", &HostToken, ImGuiInputTextFlags_ReadOnly);
}
- if (StartAsDedi)
+ if (GameGlobals::HostState->m_bActiveGame)
{
if (ImGui::Button("Reload Scripts##ServerHost_ReloadServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
ProcessCommand("reparse_weapons");
ProcessCommand("reload");
}
+
if (ImGui::Button("Stop The Server##ServerHost_StopServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
- ProcessCommand("disconnect");
+ ProcessCommand("LeaveMatch"); // Use script callback instead.
+ GameGlobals::HostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN; // Force CHostState::FrameUpdate to shutdown the server for dedicated.
+ }
+
+ if (ImGui::Button("Change Level##ServerHost_ChangeLevel", ImVec2(ImGui::GetWindowSize().x, 32)))
+ {
+ strncpy_s(GameGlobals::HostState->m_levelName, MyServer.map.c_str(), 64); // Copy new map into hoststate levelname. 64 is size of m_levelname.
+ GameGlobals::HostState->m_iNextState = HostStates_t::HS_CHANGE_LEVEL_MP; // Force CHostState::FrameUpdate to change the level.
}
}
}