Added GameGlobals, Re-factored overlay.cpp.

This commit is contained in:
IcePixelx 2021-07-18 17:34:15 +02:00
parent 51f5a29541
commit 5191a24d37
13 changed files with 736 additions and 781 deletions

View File

@ -4,6 +4,7 @@
// Initialization
void SetupConsole();
void RemoveCMHooks();
void ToggleDevCommands();
/////////////////////////////////////////////////////////////////////////////
// Hooks

View File

@ -516,3 +516,15 @@ public:
(*reinterpret_cast<OriginalFn**>(this))[58](this, curStage); /* 48 83 EC 28 89 15 ? ? ? ? */
}
};
/////////////////////////////////////////////////////////////////////////////
// Initialize Game Globals
namespace GameGlobals
{
extern CHostState* HostState;
extern CInputSystem* InputSystem;
void InitGameGlobals();
extern bool IsInitialized;
}

View File

@ -8,7 +8,7 @@
void PrintDXAddress();
void InstallDXHooks();
void RemoveDXHooks();
void ShowGameConsole(bool* p_open);
void DrawMenu();
/////////////////////////////////////////////////////////////////////////////
// Internals
@ -20,13 +20,121 @@ void Strtrim(char* s);
/////////////////////////////////////////////////////////////////////////////
// Globals
inline ImVector<char*> Items;
inline std::string OriginUID = "1010417302770";
/////////////////////////////////////////////////////////////////////////////
class CGameConsole
{
private:
///////////////////////////////////////////////////////////////////////////
char InputBuf[256] = { 0 };
ImVector<const char*> Commands;
ImVector<char*> History;
int HistoryPos = -1;
ImGuiTextFilter Filter;
bool AutoScroll = true;
bool ScrollToBottom = false;
bool ThemeSet = false;
using json = nlohmann::json;
void RunConsoleCommand(std::string command);
public:
///////////////////////////////////////////////////////////////////////////
CGameConsole();
~CGameConsole();
void Draw(const char* title);
void ProcessCommand(const char* command_line);
void ExecCommand(const char* command_line);
int TextEditCallback(ImGuiInputTextCallbackData* data);
///////////////////////////////////////////////////////////////////////////
// History
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data)
{
CGameConsole* console = (CGameConsole*)data->UserData;
return console->TextEditCallback(data);
}
///////////////////////////////////////////////////////////////////////////
// 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);
}
};
extern CGameConsole* g_GameConsole;
/////////////////////////////////////////////////////////////////////////////
// ServerBrowser
@ -34,28 +142,31 @@ void RunConsoleCommand(std::string command);
class CCompanion
{
public:
CCompanion();
////////////////////
// Enums //
//////////////////
enum class ESection {
ServerBrowser,
HostServer,
Settings
} CurrentSection;
} CurrentSection = ESection::ServerBrowser;
enum class EHostStatus {
NotHosting,
WaitingForStateChange,
Hosting,
ConnectedToSomeoneElse
};
} HostingStatus = EHostStatus::NotHosting;
CCompanion();
////////////////////
// Server Browser //
////////////////////
///////////////////
ImVector<ServerListing*> ServerList;
ServerListing* SelectedServer;
ImGuiTextFilter ServerBrowserFilter;
char ServerConnStringBuffer[256] = { 0 };
////////////////////
@ -63,7 +174,6 @@ public:
////////////////////
char MatchmakingServerStringBuffer[256] = { 0 };
////////////////////
// Host Server //
////////////////////
@ -71,18 +181,18 @@ public:
std::string* SelectedMap = nullptr;
char ServerNameBuffer[64] = { 0 };
bool StartAsDedi;
EHostStatus HostingStatus = EHostStatus::NotHosting;
void SetSection(ESection section)
{
CurrentSection = section;
}
void RefreshServerList();
void SendHostingPostRequest();
void SetSection(ESection section);
void SendHostingPostRequest(char* mapName);
void CompMenu();
void ServerBrowserSection();
void SettingsSection();
void HostServerSection();
void Draw(const char* title, bool* p_open);
void Draw(const char* title);
void UpdateHostingStatus();
std::string GetGameStateLastMap();
};

View File

@ -21,33 +21,33 @@ namespace
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* ==== SQUIRREL ======================================================================================================================================================== */
DWORD64 p_SQVM_Print = /*0x141057FD0*/ reinterpret_cast<DWORD64>(PatternScan("r5apex.exe","48 8B C4 48 89 50 10 4C 89 40 18 4C 89 48 20 53 56 57 48 81 EC 30 08 00 00 48 8B DA 48 8D 70 18 48 8B F9 E8 ?? ?? ?? FF 48 89 74 24 28 48 8D 54 24 30 33"));
void* SQVM_Print = (void*)p_SQVM_Print;
void* org_SQVM_Print = (void*)p_SQVM_Print;
//DWORD64 p_SQVM_LoadScript = FindPattern("r5apex.exe", (const unsigned char*)"\x48\x89\x5C\x24\x10\x48\x89\x74\x24\x18\x48\x89\x7C\x24\x20\x48\x89\x4C\x24\x08\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8D\x6C", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); // For S0 and S1
DWORD64 p_SQVM_LoadScript = /*0x141055630*/ reinterpret_cast<DWORD64>(PatternScan("r5apex.exe", "48 8B C4 48 89 48 08 55 41 56 48 8D 68")); // For anything S2 and above (current S8)
bool (*SQVM_LoadScript)(void* sqvm, const char* script_path, const char* script_name, int flag) = (bool (*)(void*, const char*, const char*, int))p_SQVM_LoadScript; /*E8 ?? ?? ?? ?? 84 C0 74 1C 41 B9 ?? ?? ?? ??*/
bool (*org_SQVM_LoadScript)(void* sqvm, const char* script_path, const char* script_name, int flag) = (bool (*)(void*, const char*, const char*, int))p_SQVM_LoadScript; /*E8 ?? ?? ?? ?? 84 C0 74 1C 41 B9 ?? ?? ?? ??*/
DWORD64 p_SQVM_LoadRson = /*0x140C957E0*/ reinterpret_cast<DWORD64>(PatternScan("r5apex.exe", "4C 8B DC 49 89 5B 08 57 48 81 EC A0 00 00 00 33"));
int (*SQVM_LoadRson)(const char* rson_name) = (int (*)(const char*))p_SQVM_LoadRson;
int (*org_SQVM_LoadRson)(const char* rson_name) = (int (*)(const char*))p_SQVM_LoadRson;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* ==== NETCHAN ========================================================================================================================================================= */
DWORD64 p_NET_ReceiveDatagram = /*0x1402655F0*/ reinterpret_cast<DWORD64>(PatternScan("r5apex.exe", "48 89 74 24 18 48 89 7C 24 20 55 41 54 41 55 41 56 41 57 48 8D AC 24 50 EB"));
bool (*NET_ReceiveDatagram)(int, void*, bool) = (bool (*)(int, void*, bool))p_NET_ReceiveDatagram; /*E8 ?? ?? ?? ?? 84 C0 75 35 48 8B D3*/
bool (*org_NET_ReceiveDatagram)(int, void*, bool) = (bool (*)(int, void*, bool))p_NET_ReceiveDatagram; /*E8 ?? ?? ?? ?? 84 C0 75 35 48 8B D3*/
DWORD64 p_NET_SendDatagram = /*0x1402662D0*/ reinterpret_cast<DWORD64>(PatternScan("r5apex.exe", "48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 41 56 41 57 48 81 EC ? 05 ? ?"));
int (*NET_SendDatagram)(SOCKET s, const char* buf, int len, int flags) = (int (*)(SOCKET, const char*, int, int))p_NET_SendDatagram;
int (*org_NET_SendDatagram)(SOCKET s, const char* buf, int len, int flags) = (int (*)(SOCKET, const char*, int, int))p_NET_SendDatagram;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* ==== CHLCLIENT ======================================================================================================================================================= */
DWORD64 p_CHLClient_FrameStageNotify = /*0x1405C0740*/ reinterpret_cast<DWORD64>(PatternScan("r5apex.exe", "48 83 EC 28 89 15 ?? ?? ?? ??"));
void (*CHLClient_FrameStageNotify)(void* rcx, int curStage) = (void (*)(void*, int))p_CHLClient_FrameStageNotify;
void (*org_CHLClient_FrameStageNotify)(void* rcx, int curStage) = (void (*)(void*, int))p_CHLClient_FrameStageNotify;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* ==== UTILITY ========================================================================================================================================================= */
DWORD64 p_MSG_EngineError = /*0x140295600*/ reinterpret_cast<DWORD64>(PatternScan("r5apex.exe", "48 89 5C 24 08 48 89 74 24 10 57 48 81 EC 30 08 00 00 48 8B DA 48 8B F9 E8 ?? ?? ?? FF 33 F6 48"));
int (*MSG_EngineError)(char* fmt, va_list args) = (int (*)(char*, va_list))p_MSG_EngineError;
int (*org_MSG_EngineError)(char* fmt, va_list args) = (int (*)(char*, va_list))p_MSG_EngineError;
// Un-used atm.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -4,7 +4,6 @@
class ServerListing
{
public:
std::string name;
@ -14,6 +13,6 @@ public:
int expiry;
ServerListing(std::string name, std::string map, std::string ip, std::string version, int expiry);
bool Select();
void Select();
};

View File

@ -313,6 +313,7 @@
<ClCompile Include="..\external\imgui\src\imgui_widgets.cpp" />
<ClCompile Include="src\console.cpp" />
<ClCompile Include="src\dllmain.cpp" />
<ClCompile Include="src\gameclasses.cpp" />
<ClCompile Include="src\hooks.cpp" />
<ClCompile Include="src\id3dx.cpp" />
<ClCompile Include="src\input.cpp" />

View File

@ -102,6 +102,9 @@
<ClCompile Include="src\serverlisting.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\gameclasses.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\console.h">

16
r5dev/src/gameclasses.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "gameclasses.h"
namespace GameGlobals
{
bool IsInitialized = false;
CHostState* HostState = nullptr;
CInputSystem* InputSystem = nullptr;
void InitGameGlobals()
{
HostState = reinterpret_cast<CHostState*>(0x141736120); // Get CHostState from memory.
InputSystem = *reinterpret_cast<CInputSystem**>(0x14D40B380); // Get IInputSystem from memory.
IsInitialized = true;
}
}

View File

@ -16,7 +16,7 @@
bool HNET_ReceiveDatagram(int sock, void* inpacket, bool raw)
{
bool result = NET_ReceiveDatagram(sock, inpacket, raw);
bool result = org_NET_ReceiveDatagram(sock, inpacket, raw);
if (result)
{
int i = NULL;
@ -32,7 +32,7 @@ bool HNET_ReceiveDatagram(int sock, void* inpacket, bool raw)
unsigned int HNET_SendDatagram(SOCKET s, const char* buf, int len, int flags)
{
unsigned int result = NET_SendDatagram(s, buf, len, flags);
unsigned int result = org_NET_SendDatagram(s, buf, len, flags);
if (result)
{
///////////////////////////////////////////////////////////////////////////
@ -49,16 +49,12 @@ unsigned int HNET_SendDatagram(SOCKET s, const char* buf, int len, int flags)
void __fastcall HCHLClient__FrameStageNotify(CHLClient* rcx, ClientFrameStage_t curStage) /* __fastcall so we can make sure first argument will be RCX and second RDX. */
{
static CHostState* HostState = reinterpret_cast<CHostState*>(0x141736120);
switch (curStage)
{
case FRAME_START: // FrameStageNotify gets called every frame by CEngine::Frame with the stage being FRAME_START. We can use this to check/set global variables.
{
if (HostState->m_bWaitingForConnection) // Easy way to check if we are DEDI.
{
// printf("AWAITING CONNECTION\n");
}
if (!GameGlobals::IsInitialized)
GameGlobals::InitGameGlobals();
break;
}
@ -66,7 +62,7 @@ void __fastcall HCHLClient__FrameStageNotify(CHLClient* rcx, ClientFrameStage_t
break;
}
CHLClient_FrameStageNotify(rcx, curStage);
org_CHLClient_FrameStageNotify(rcx, curStage);
}
//#################################################################################
@ -103,14 +99,14 @@ __int64 HSQVM_LoadRson(const char* rson_name)
///////////////////////////////////////////////////////////////////////////////
// Returns the new path if the rson exists on the disk
if (FileExists(filepath) && SQVM_LoadRson(rson_name))
if (FileExists(filepath) && org_SQVM_LoadRson(rson_name))
{
printf("\n");
printf("##################################################\n");
printf("] '%s'\n", filepath);
printf("##################################################\n");
printf("\n");
return SQVM_LoadRson(filepath);
return org_SQVM_LoadRson(filepath);
}
else
{
@ -119,7 +115,7 @@ __int64 HSQVM_LoadRson(const char* rson_name)
printf("] '%s'\n", rson_name);
printf("##################################################\n");
printf("\n");
return SQVM_LoadRson(rson_name);
return org_SQVM_LoadRson(rson_name);
}
}
@ -143,7 +139,7 @@ bool HSQVM_LoadScript(void* sqvm, const char* script_path, const char* script_na
}
///////////////////////////////////////////////////////////////////////////////
// Returns true if the script exists on the disk
if (FileExists(filepath) && SQVM_LoadScript(sqvm, filepath, script_name, flag))
if (FileExists(filepath) && org_SQVM_LoadScript(sqvm, filepath, script_name, flag))
{
return true;
}
@ -151,7 +147,7 @@ bool HSQVM_LoadScript(void* sqvm, const char* script_path, const char* script_na
{
printf(" [!] FAILED. Try SP / VPK for '%s'\n", filepath);
}
return SQVM_LoadScript(sqvm, script_path, script_name, flag);
return org_SQVM_LoadScript(sqvm, script_path, script_name, flag);
}
//#################################################################################
@ -166,7 +162,7 @@ int HMSG_EngineError(char* fmt, va_list args)
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
Items.push_back(Strdup(buf));
return MSG_EngineError(fmt, args);
return org_MSG_EngineError(fmt, args);
}
//#################################################################################
@ -182,17 +178,17 @@ void InstallENHooks()
///////////////////////////////////////////////////////////////////////////////
// Hook Squirrel functions
DetourAttach((LPVOID*)&SQVM_Print, &HSQVM_Print);
DetourAttach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson);
DetourAttach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript);
DetourAttach((LPVOID*)&org_SQVM_Print, &HSQVM_Print);
DetourAttach((LPVOID*)&org_SQVM_LoadRson, &HSQVM_LoadRson);
DetourAttach((LPVOID*)&org_SQVM_LoadScript, &HSQVM_LoadScript);
///////////////////////////////////////////////////////////////////////////////
// Hook Game Functions
DetourAttach((LPVOID*)&CHLClient_FrameStageNotify, &HCHLClient__FrameStageNotify);
DetourAttach((LPVOID*)&org_CHLClient_FrameStageNotify, &HCHLClient__FrameStageNotify);
///////////////////////////////////////////////////////////////////////////////
// Hook Utility functions
DetourAttach((LPVOID*)&MSG_EngineError, &HMSG_EngineError);
DetourAttach((LPVOID*)&org_MSG_EngineError, &HMSG_EngineError);
///////////////////////////////////////////////////////////////////////////////
// Commit the transaction
@ -212,22 +208,22 @@ void RemoveENHooks()
///////////////////////////////////////////////////////////////////////////////
// Unhook Squirrel functions
DetourDetach((LPVOID*)&SQVM_Print, &HSQVM_Print);
DetourDetach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson);
DetourDetach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript);
DetourDetach((LPVOID*)&org_SQVM_Print, &HSQVM_Print);
DetourDetach((LPVOID*)&org_SQVM_LoadRson, &HSQVM_LoadRson);
DetourDetach((LPVOID*)&org_SQVM_LoadScript, &HSQVM_LoadScript);
///////////////////////////////////////////////////////////////////////////////
// Unhook Game Functions
DetourDetach((LPVOID*)&CHLClient_FrameStageNotify, &HCHLClient__FrameStageNotify);
DetourDetach((LPVOID*)&org_CHLClient_FrameStageNotify, &HCHLClient__FrameStageNotify);
///////////////////////////////////////////////////////////////////////////////
// Unhook Netchan functions
DetourDetach((LPVOID*)&NET_SendDatagram, &HNET_SendDatagram);
DetourDetach((LPVOID*)&NET_ReceiveDatagram, &HNET_ReceiveDatagram);
DetourDetach((LPVOID*)&org_NET_SendDatagram, &HNET_SendDatagram);
DetourDetach((LPVOID*)&org_NET_ReceiveDatagram, &HNET_ReceiveDatagram);
///////////////////////////////////////////////////////////////////////////////
// Unhook Utility functions
DetourDetach((LPVOID*)&MSG_EngineError, &HMSG_EngineError);
DetourDetach((LPVOID*)&org_MSG_EngineError, &HMSG_EngineError);
///////////////////////////////////////////////////////////////////////////////
// Commit the transaction
@ -247,8 +243,8 @@ void ToggleNetHooks()
if (!g_net)
{
DetourAttach((LPVOID*)&NET_SendDatagram, &HNET_SendDatagram);
DetourAttach((LPVOID*)&NET_ReceiveDatagram, &HNET_ReceiveDatagram);
DetourAttach((LPVOID*)&org_NET_SendDatagram, &HNET_SendDatagram);
DetourAttach((LPVOID*)&org_NET_ReceiveDatagram, &HNET_ReceiveDatagram);
printf("\n");
printf("+--------------------------------------------------------+\n");
printf("|>>>>>>>>>>>>>| NETCHANNEL TRACE ACTIVATED |<<<<<<<<<<<<<|\n");
@ -257,8 +253,8 @@ void ToggleNetHooks()
}
else
{
DetourDetach((LPVOID*)&NET_SendDatagram, &HNET_SendDatagram);
DetourDetach((LPVOID*)&NET_ReceiveDatagram, &HNET_ReceiveDatagram);
DetourDetach((LPVOID*)&org_NET_SendDatagram, &HNET_SendDatagram);
DetourDetach((LPVOID*)&org_NET_ReceiveDatagram, &HNET_ReceiveDatagram);
printf("\n");
printf("+--------------------------------------------------------+\n");
printf("|>>>>>>>>>>>>| NETCHANNEL TRACE DEACTIVATED |<<<<<<<<<<<<|\n");

View File

@ -256,23 +256,22 @@ void SetupImGui()
void DrawImGui()
{
bool bShowMenu = false;
if (!GameGlobals::IsInitialized || !GameGlobals::InputSystem) // Check if GameGlobals initialized and if InputSystem is valid.
return;
ImGui_ImplWin32_NewFrame();
ImGui_ImplDX11_NewFrame();
ImGui::NewFrame();
static CInputSystem* InputSystem = *reinterpret_cast<CInputSystem**>(0x14D40B380);
if (g_bShowMenu)
{
InputSystem->EnableInput(false); // Disable input.
ShowGameConsole(&bShowMenu);
GameGlobals::InputSystem->EnableInput(false); // Disable input.
DrawMenu();
}
else if (!g_bShowMenu)
else
{
InputSystem->EnableInput(true); // Enable input.
GameGlobals::InputSystem->EnableInput(true); // Enable input.
}
ImGui::EndFrame();

View File

@ -11,6 +11,7 @@
#include "id3dx.h"
#include "console.h"
#include "patterns.h"
#include "gameclasses.h"
#include "imgui.h"
#include "imgui_impl_dx11.h"
@ -22,26 +23,15 @@
#include <shlobj.h>
#include <objbase.h>
#define DebugOverlay
CGameConsole* g_GameConsole = nullptr;
/*-----------------------------------------------------------------------------
* _overlay.cpp
*-----------------------------------------------------------------------------*/
class CGameConsole
{
private:
///////////////////////////////////////////////////////////////////////////
char InputBuf[256] = { 0 };
ImVector<const char*> Commands;
ImVector<char*> History;
int HistoryPos = -1;
ImGuiTextFilter Filter;
bool AutoScroll = true;
bool ScrollToBottom = false;
bool ThemeSet = false;
public:
///////////////////////////////////////////////////////////////////////////
CGameConsole()
CGameConsole::CGameConsole()
{
ClearLog();
memset(InputBuf, 0, sizeof(InputBuf));
@ -59,126 +49,20 @@ public:
AddLog("[DEBUG] THREAD ID: %ld\n", g_dThreadId);
}
~CGameConsole()
CGameConsole::~CGameConsole()
{
ClearLog();
for (int i = 0; i < History.Size; i++) { free(History[i]); }
}
///////////////////////////////////////////////////////////////////////////
// Internals
static int Stricmp(const char* s1, const char* s2)
for (int i = 0; i < History.Size; i++)
{
int d;
while ((d = toupper(*s2) - toupper(*s1)) == 0 && *s1)
{
s1++; s2++;
free(History[i]);
}
return d;
}
static int Strnicmp(const char* s1, const char* s2, int n)
{
int d = 0; while (n > 0 && (d = toupper(*s2) - toupper(*s1)) == 0 && *s1)
{
s1++; s2++; n--;
}
return d;
}
static char* Strdup(const char* s)
{
IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = malloc(len); IM_ASSERT(buf); if (buf != NULL)
{
return (char*)memcpy(buf, (const void*)s, len);
}
return NULL;
}
static void Strtrim(char* s)
{
char* str_end = s + strlen(s); while (str_end > s && str_end[-1] == ' ') str_end--; *str_end = 0;
}
///////////////////////////////////////////////////////////////////////////
// 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);
}
///////////////////////////////////////////////////////////////////////////
// Draw
void Draw(const char* title, bool* p_open)
void CGameConsole::Draw(const char* title)
{
if (!ThemeSet)
{
@ -346,18 +230,15 @@ public:
ImGui::End();
}
///////////////////////////////////////////////////////////////////////////
// Exec
void ProcessCommand(const char* command_line)
void CGameConsole::ProcessCommand(const char* command_line)
{
std::thread t(&CGameConsole::ExecCommand, this, command_line);
t.detach();
// HACK: This is to avoid a race condition.
Sleep(1);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
AddLog("# %s\n", command_line);
HistoryPos = -1;
@ -379,32 +260,31 @@ public:
else if (Stricmp(command_line, "HELP") == 0)
{
AddLog("Commands:");
for (int i = 0; i < Commands.Size; i++) { AddLog("- %s", Commands[i]); }
for (int i = 0; i < Commands.Size; i++)
{
AddLog("- %s", Commands[i]);
}
}
else if (Stricmp(command_line, "HISTORY") == 0)
{
int first = History.Size - 10;
for (int i = first > 0 ? first : 0; i < History.Size; i++) { AddLog("%3d: %s\n", i, History[i]); }
for (int i = first > 0 ? first : 0; i < History.Size; i++)
{
AddLog("%3d: %s\n", i, History[i]);
}
}
ScrollToBottom = true;
}
void ExecCommand(const char* command_line)
void CGameConsole::ExecCommand(const char* command_line)
{
CommandExecute(NULL, command_line);
}
///////////////////////////////////////////////////////////////////////////
// History
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data)
{
CGameConsole* console = (CGameConsole*)data->UserData;
return console->TextEditCallback(data);
}
///////////////////////////////////////////////////////////////////////////
// Edit
int TextEditCallback(ImGuiInputTextCallbackData* data)
int CGameConsole::TextEditCallback(ImGuiInputTextCallbackData* data)
{
switch (data->EventFlag)
{
@ -452,19 +332,17 @@ public:
}
return 0;
}
};
///////////////////////////////////////////////////////////////////////////
// Companion
CCompanion::CCompanion()
{
memset(MatchmakingServerStringBuffer, 0, sizeof(MatchmakingServerStringBuffer));
memset(ServerNameBuffer, 0, sizeof(ServerNameBuffer));
memset(ServerConnStringBuffer, 0, sizeof(ServerConnStringBuffer));
strcpy_s(MatchmakingServerStringBuffer, "r5a-comp-sv.herokuapp.com");
std::string path = "stbsp";
for (const auto& entry : std::filesystem::directory_iterator(path))
{
@ -477,8 +355,6 @@ CCompanion::CCompanion()
SelectedMap = &MapsList[0];
//RefreshServerList();
static std::thread HostingServerRequestThread([this]()
{
while (true)
@ -487,78 +363,32 @@ CCompanion::CCompanion()
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
}
});
HostingServerRequestThread.detach();
HostingServerRequestThread.detach();
}
void CCompanion::UpdateHostingStatus()
{
std::string lastMap = GetGameStateLastMap();
if (!GameGlobals::HostState) // Is HostState valid?
return;
GameGlobals::HostState->m_bActiveGame ? HostingStatus = EHostStatus::Hosting : HostingStatus = EHostStatus::NotHosting; // Are we hosting a server?
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:
{
if (lastMap == "no_map" || lastMap == "")
HostingStatus = EHostStatus::NotHosting;
else SendHostingPostRequest();
SendHostingPostRequest(GameGlobals::HostState->m_levelName);
break;
}
case EHostStatus::ConnectedToSomeoneElse:
{
if(lastMap == "no_map" || lastMap == "")
{
HostingStatus = EHostStatus::NotHosting;
}
default:
break;
}
}
}
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()
{
@ -566,16 +396,20 @@ CCompanion::CCompanion()
static bool bThreadLocked = false;
if (!bThreadLocked) {
std::thread t([this]() {
std::cout << "Refreshing server list with string" << MatchmakingServerStringBuffer << std::endl;
if (!bThreadLocked)
{
std::thread t([this]()
{
#ifdef DebugOverlay
std::cout << " [+CCompanion+] Refreshing server list with string" << MatchmakingServerStringBuffer << "\n";
#endif
bThreadLocked = true;
httplib::Client client(MatchmakingServerStringBuffer);
client.set_connection_timeout(10);
auto res = client.Get("/servers");
if (res)
{
json root = json::parse(res->body);
nlohmann::json root = nlohmann::json::parse(res->body);
for (auto obj : root["servers"])
{
ServerList.push_back(
@ -588,40 +422,34 @@ CCompanion::CCompanion()
t.detach();
}
}
void CCompanion::SendHostingPostRequest()
void CCompanion::SendHostingPostRequest(char* mapName)
{
httplib::Client client(MatchmakingServerStringBuffer);
client.set_connection_timeout(10);
// send a post request to "/servers/add" with a json body
json body = json::object();
nlohmann::json body = nlohmann::json::object();
body["name"] = ServerNameBuffer;
body["map"] = *SelectedMap;
body["map"] = mapName;
body["version"] = "1.0";
std::string body_str = body.dump();
std::cout << body_str << "\n";
#ifdef DebugOverlay
std::cout << " [+CCompanion+] Sending request now, Body:" << body_str << "\n";
#endif
auto res = client.Post("/servers/add", body_str.c_str(), body_str.length(), "application/json");
if (res)
httplib::Result result = client.Post("/servers/add", body_str.c_str(), body_str.length(), "application/json");
#ifdef DebugOverlay
if (result)
{
std::cout << "Hosting Request Result: " << res->body << "\n";
std::cout << " [+CCompanion+] Request Result: " << result->body << "\n";
}
#endif
}
void CCompanion::SetSection(ESection section)
{
CurrentSection = section;
}
void CCompanion::CompMenu()
{
ImGui::BeginTabBar("CompMenu");
@ -642,7 +470,6 @@ CCompanion::CCompanion()
void CCompanion::ServerBrowserSection()
{
ImGui::BeginGroup();
ServerBrowserFilter.Draw();
ImGui::SameLine();
@ -654,9 +481,9 @@ CCompanion::CCompanion()
ImGui::Separator();
ImGui::BeginChild("ServerListChild", { 0, 780 }, false, ImGuiWindowFlags_HorizontalScrollbar);
{
ImGui::BeginTable("bumbumceau", 6);
{
ImGui::TableSetupColumn("Name", 0, 35);
ImGui::TableSetupColumn("IP Address", 0, 20);
ImGui::TableSetupColumn("Map", 0, 25);
@ -707,8 +534,9 @@ CCompanion::CCompanion()
}
}
}
ImGui::EndTable();
}
ImGui::EndChild();
ImGui::Separator();
@ -718,7 +546,7 @@ CCompanion::CCompanion()
{
std::stringstream cmd;
cmd << "connect " << ServerConnStringBuffer;
RunConsoleCommand(cmd.str().c_str());
g_GameConsole->ProcessCommand(cmd.str().c_str());
}
}
@ -745,39 +573,36 @@ CCompanion::CCompanion()
if (ImGui::Button("Start The Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
if (strcmp(ServerNameBuffer, "") != 0)
{
UpdateHostingStatus();
if(HostingStatus == EHostStatus::NotHosting)
HostingStatus = EHostStatus::WaitingForStateChange;
UpdateHostingStatus();
std::stringstream cmd;
cmd << "map " << SelectedMap->c_str();
RunConsoleCommand(cmd.str());
g_GameConsole->ProcessCommand(cmd.str().c_str());
if (StartAsDedi)
{
ToggleDevCommands();
}
}
}
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!");
if (StartAsDedi)
{
if (ImGui::Button("Reload Scripts##ServerHost_ReloadServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
RunConsoleCommand("reparse_weapons");
RunConsoleCommand("reload");
g_GameConsole->ProcessCommand("reparse_weapons");
g_GameConsole->ProcessCommand("reload");
}
if (ImGui::Button("Stop The Server##ServerHost_StopServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
RunConsoleCommand("disconnect");
g_GameConsole->ProcessCommand("disconnect");
}
}
}
void CCompanion::SettingsSection()
@ -785,15 +610,15 @@ CCompanion::CCompanion()
ImGui::InputText("Matchmaking Server String", MatchmakingServerStringBuffer, IM_ARRAYSIZE(MatchmakingServerStringBuffer), 0);
}
void CCompanion::Draw(const char* title, bool* p_open)
void CCompanion::Draw(const char* title)
{
ImGui::SetNextWindowSize(ImVec2(800, 890), ImGuiCond_FirstUseEver);
ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver);
if (!ImGui::Begin(title, NULL))
{
ImGui::End(); return;
ImGui::End();
return;
}
///////////////////////////////////////////////////////////////////////
CompMenu();
@ -803,16 +628,12 @@ CCompanion::CCompanion()
case ESection::ServerBrowser:
ServerBrowserSection();
break;
case ESection::HostServer:
HostServerSection();
break;
case ESection::Settings:
SettingsSection();
break;
default:
break;
}
@ -820,10 +641,8 @@ CCompanion::CCompanion()
ImGui::End();
}
//#############################################################################
// INTERNALS
//#############################################################################
///////////////////////////////////////////////////////////////////////////
// Internals
int Stricmp(const char* s1, const char* s2)
{
int d;
@ -833,6 +652,7 @@ int Stricmp(const char* s1, const char* s2)
}
return d;
}
int Strnicmp(const char* s1, const char* s2, int n)
{
int d = 0; while (n > 0 && (d = toupper(*s2) - toupper(*s1)) == 0 && *s1)
@ -841,6 +661,7 @@ int Strnicmp(const char* s1, const char* s2, int n)
}
return d;
}
char* Strdup(const char* s)
{
IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = malloc(len); IM_ASSERT(buf); if (buf != NULL)
@ -849,9 +670,13 @@ char* Strdup(const char* s)
}
return NULL;
}
void Strtrim(char* s)
{
char* str_end = s + strlen(s); while (str_end > s && str_end[-1] == ' ') str_end--; *str_end = 0;
char* str_end = s + strlen(s);
while (str_end > s && str_end[-1] == ' ')
str_end--; *str_end = 0;
}
@ -859,17 +684,11 @@ void Strtrim(char* s)
// ENTRYPOINT
//#############################################################################
void ShowGameConsole(bool* p_open)
void DrawMenu()
{
static CGameConsole console;
g_GameConsole = &console;
static CCompanion browser;
console.Draw("Console", p_open);
browser.Draw("Companion", p_open);
}
void RunConsoleCommand(std::string command)
{
static CGameConsole console;
console.ProcessCommand(command.c_str());
console.Draw("Console");
browser.Draw("Companion");
}

View File

@ -11,10 +11,9 @@ ServerListing::ServerListing(std::string name, std::string map, std::string ip,
this->expiry = expiry;
}
bool ServerListing::Select()
void ServerListing::Select()
{
std::stringstream cmd;
cmd << "connect " << this->ip;
RunConsoleCommand(cmd.str().c_str());
return true;
g_GameConsole->ProcessCommand(cmd.str().c_str());
}