mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Added state check kek
This commit is contained in:
parent
d9fe7effe5
commit
309e4acf21
1
.gitignore
vendored
1
.gitignore
vendored
@ -348,3 +348,4 @@ MigrationBackup/
|
|||||||
|
|
||||||
# Ionide (cross platform F# VS Code tools) working folder
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
.ionide/
|
.ionide/
|
||||||
|
.vscode/settings.json
|
||||||
|
@ -27,3 +27,62 @@ inline std::string OriginUID = "1010417302770";
|
|||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
void RunConsoleCommand(std::string command);
|
void RunConsoleCommand(std::string command);
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ServerBrowser
|
||||||
|
|
||||||
|
class CCompanion
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum class ESection {
|
||||||
|
ServerBrowser,
|
||||||
|
HostServer,
|
||||||
|
Settings
|
||||||
|
} CurrentSection;
|
||||||
|
|
||||||
|
enum class EHostStatus {
|
||||||
|
WaitingForStateChange,
|
||||||
|
Hosting,
|
||||||
|
NotHosting,
|
||||||
|
ConnectedToSomeoneElse
|
||||||
|
};
|
||||||
|
|
||||||
|
CCompanion();
|
||||||
|
////////////////////
|
||||||
|
// Server Browser //
|
||||||
|
////////////////////
|
||||||
|
ImVector<ServerListing*> ServerList;
|
||||||
|
ServerListing* SelectedServer;
|
||||||
|
|
||||||
|
ImGuiTextFilter ServerBrowserFilter;
|
||||||
|
|
||||||
|
char ServerConnStringBuffer[256] = { 0 };
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// Settings //
|
||||||
|
////////////////////
|
||||||
|
char MatchmakingServerStringBuffer[256] = { 0 };
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// Host Server //
|
||||||
|
////////////////////
|
||||||
|
std::vector<std::string> MapsList;
|
||||||
|
std::string* SelectedMap = nullptr;
|
||||||
|
char ServerNameBuffer[64] = { 0 };
|
||||||
|
bool StartAsDedi;
|
||||||
|
EHostStatus HostingStatus = EHostStatus::WaitingForStateChange;
|
||||||
|
|
||||||
|
void RefreshServerList();
|
||||||
|
|
||||||
|
void SendHostingPostRequest();
|
||||||
|
void SetSection(ESection section);
|
||||||
|
void CompMenu();
|
||||||
|
void ServerBrowserSection();
|
||||||
|
void SettingsSection();
|
||||||
|
void HostServerSection();
|
||||||
|
void Draw(const char* title, bool* p_open);
|
||||||
|
void UpdateHostingStatus();
|
||||||
|
|
||||||
|
std::string GetGameStateLastMap();
|
||||||
|
};
|
@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
#include "overlay.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
@ -7,7 +9,6 @@
|
|||||||
#include <detours.h>
|
#include <detours.h>
|
||||||
#include "hooks.h"
|
#include "hooks.h"
|
||||||
#include "id3dx.h"
|
#include "id3dx.h"
|
||||||
#include "overlay.h"
|
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "patterns.h"
|
#include "patterns.h"
|
||||||
|
|
||||||
@ -18,6 +19,9 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <shlobj.h>
|
||||||
|
#include <objbase.h>
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
* _overlay.cpp
|
* _overlay.cpp
|
||||||
*-----------------------------------------------------------------------------*/
|
*-----------------------------------------------------------------------------*/
|
||||||
@ -456,39 +460,8 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CCompanion {
|
|
||||||
public:
|
|
||||||
////////////////////
|
|
||||||
// Server Browser //
|
|
||||||
////////////////////
|
|
||||||
ImVector<ServerListing*> ServerList;
|
|
||||||
ServerListing* SelectedServer;
|
|
||||||
|
|
||||||
ImGuiTextFilter ServerBrowserFilter;
|
CCompanion::CCompanion()
|
||||||
|
|
||||||
char ServerConnStringBuffer[256] = { 0 };
|
|
||||||
|
|
||||||
////////////////////
|
|
||||||
// Settings //
|
|
||||||
////////////////////
|
|
||||||
char MatchmakingServerStringBuffer[256] = { 0 };
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////
|
|
||||||
// Host Server //
|
|
||||||
////////////////////
|
|
||||||
std::vector<std::string> MapsList;
|
|
||||||
std::string* SelectedMap = nullptr;
|
|
||||||
char ServerNameBuffer[64] = { 0 };
|
|
||||||
bool StartAsDedi;
|
|
||||||
|
|
||||||
enum class ESection : UINT8 {
|
|
||||||
ServerBrowser,
|
|
||||||
HostServer,
|
|
||||||
Settings
|
|
||||||
} CurrentSection;
|
|
||||||
|
|
||||||
CCompanion()
|
|
||||||
{
|
{
|
||||||
memset(MatchmakingServerStringBuffer, 0, sizeof(MatchmakingServerStringBuffer));
|
memset(MatchmakingServerStringBuffer, 0, sizeof(MatchmakingServerStringBuffer));
|
||||||
memset(ServerNameBuffer, 0, sizeof(ServerNameBuffer));
|
memset(ServerNameBuffer, 0, sizeof(ServerNameBuffer));
|
||||||
@ -512,9 +485,87 @@ public:
|
|||||||
|
|
||||||
//RefreshServerList();
|
//RefreshServerList();
|
||||||
|
|
||||||
|
static std::thread HostingServerRequestThread([this]()
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
UpdateHostingStatus();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
HostingServerRequestThread.detach();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefreshServerList()
|
void CCompanion::UpdateHostingStatus()
|
||||||
|
{
|
||||||
|
std::string lastMap = GetGameStateLastMap();
|
||||||
|
|
||||||
|
switch(HostingStatus)
|
||||||
|
{
|
||||||
|
case EHostStatus::NotHosting:
|
||||||
|
{
|
||||||
|
if(lastMap != "no_map" && lastMap != "")
|
||||||
|
HostingStatus = EHostStatus::ConnectedToSomeoneElse;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case EHostStatus::WaitingForStateChange:
|
||||||
|
{
|
||||||
|
if(lastMap != "no_map" && lastMap != "")
|
||||||
|
HostingStatus = EHostStatus::Hosting;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case EHostStatus::Hosting:
|
||||||
|
{
|
||||||
|
SendHostingPostRequest();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case EHostStatus::ConnectedToSomeoneElse:
|
||||||
|
{
|
||||||
|
if(lastMap == "no_map" || lastMap == "")
|
||||||
|
{
|
||||||
|
HostingStatus = EHostStatus::NotHosting;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << HostingStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CCompanion::GetGameStateLastMap()
|
||||||
|
{
|
||||||
|
|
||||||
|
// I know you're gonna comment abt this function; but I dont think it's necessary to include a fully-fledged VDF parser for now
|
||||||
|
|
||||||
|
wchar_t* savedGamesPath = new wchar_t[256];
|
||||||
|
|
||||||
|
SHGetKnownFolderPath(FOLDERID_SavedGames, KF_FLAG_CREATE, nullptr, &savedGamesPath);
|
||||||
|
|
||||||
|
if (savedGamesPath == nullptr) return "";
|
||||||
|
|
||||||
|
std::wstringstream filePath;
|
||||||
|
|
||||||
|
filePath << savedGamesPath;
|
||||||
|
filePath << "\\Respawn\\Apex\\local\\previousgamestate.txt";
|
||||||
|
|
||||||
|
CoTaskMemFree(static_cast<void*>(savedGamesPath));
|
||||||
|
|
||||||
|
std::ifstream f(filePath.str());
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
|
std::getline(f, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the substring of the line that contains only the map name
|
||||||
|
return line.substr(35, line.size() - 35 - 1);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCompanion::RefreshServerList()
|
||||||
{
|
{
|
||||||
ServerList.clear();
|
ServerList.clear();
|
||||||
|
|
||||||
@ -548,7 +599,7 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendHostingPostRequest()
|
void CCompanion::SendHostingPostRequest()
|
||||||
{
|
{
|
||||||
httplib::Client client(MatchmakingServerStringBuffer);
|
httplib::Client client(MatchmakingServerStringBuffer);
|
||||||
client.set_connection_timeout(10);
|
client.set_connection_timeout(10);
|
||||||
@ -570,13 +621,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetSection(ESection section)
|
void CCompanion::SetSection(ESection section)
|
||||||
{
|
{
|
||||||
CurrentSection = section;
|
CurrentSection = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CompMenu()
|
void CCompanion::CompMenu()
|
||||||
{
|
{
|
||||||
ImGui::BeginTabBar("CompMenu");
|
ImGui::BeginTabBar("CompMenu");
|
||||||
if (ImGui::TabItemButton("Server Browser"))
|
if (ImGui::TabItemButton("Server Browser"))
|
||||||
@ -594,7 +645,7 @@ public:
|
|||||||
ImGui::EndTabBar();
|
ImGui::EndTabBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerBrowserSection()
|
void CCompanion::ServerBrowserSection()
|
||||||
{
|
{
|
||||||
|
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
@ -676,7 +727,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostServerSection()
|
void CCompanion::HostServerSection()
|
||||||
{
|
{
|
||||||
ImGui::InputTextWithHint("Server Name##ServerHost_ServerName", "Required Field", ServerNameBuffer, IM_ARRAYSIZE(ServerNameBuffer));
|
ImGui::InputTextWithHint("Server Name##ServerHost_ServerName", "Required Field", ServerNameBuffer, IM_ARRAYSIZE(ServerNameBuffer));
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
@ -699,8 +750,14 @@ public:
|
|||||||
|
|
||||||
if (ImGui::Button("Start The Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
|
if (ImGui::Button("Start The Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (strcmp(ServerNameBuffer, "") != 0)
|
if (strcmp(ServerNameBuffer, "") != 0)
|
||||||
{
|
{
|
||||||
|
UpdateHostingStatus();
|
||||||
|
if(HostingStatus == EHostStatus::NotHosting)
|
||||||
|
HostingStatus = EHostStatus::WaitingForStateChange;
|
||||||
|
UpdateHostingStatus();
|
||||||
|
|
||||||
std::stringstream cmd;
|
std::stringstream cmd;
|
||||||
cmd << "map " << SelectedMap->c_str();
|
cmd << "map " << SelectedMap->c_str();
|
||||||
RunConsoleCommand(cmd.str());
|
RunConsoleCommand(cmd.str());
|
||||||
@ -708,7 +765,7 @@ public:
|
|||||||
{
|
{
|
||||||
ToggleDevCommands();
|
ToggleDevCommands();
|
||||||
}
|
}
|
||||||
SendHostingPostRequest();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcmp(ServerNameBuffer, "") == 0) ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), "ERROR: Please specify a name for the server!");
|
if (strcmp(ServerNameBuffer, "") == 0) ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), "ERROR: Please specify a name for the server!");
|
||||||
@ -728,13 +785,13 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsSection()
|
void CCompanion::SettingsSection()
|
||||||
{
|
{
|
||||||
ImGui::InputText("Matchmaking Server String", MatchmakingServerStringBuffer, IM_ARRAYSIZE(MatchmakingServerStringBuffer), 0);
|
ImGui::InputText("Matchmaking Server String", MatchmakingServerStringBuffer, IM_ARRAYSIZE(MatchmakingServerStringBuffer), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Draw(const char* title, bool* p_open)
|
void CCompanion::Draw(const char* title, bool* p_open)
|
||||||
{
|
{
|
||||||
ImGui::SetNextWindowSize(ImVec2(800, 890), ImGuiCond_FirstUseEver);
|
ImGui::SetNextWindowSize(ImVec2(800, 890), ImGuiCond_FirstUseEver);
|
||||||
ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver);
|
ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver);
|
||||||
@ -772,8 +829,6 @@ public:
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
// INTERNALS
|
// INTERNALS
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user