Create class instances earlier.

This commit is contained in:
IcePixelx 2021-11-05 00:57:52 +01:00
parent e92453db37
commit 15078652e1
8 changed files with 75 additions and 107 deletions

View File

@ -1,12 +1,7 @@
#pragma once #pragma once
#include "serverlisting.h"
#include "gui_utility.h" #include "gui_utility.h"
#include "r5net.h" #include "r5net.h"
///////////////////////////////////////////////////////////////////////////////
// Initialization
void DrawBrowser();
class CCompanion class CCompanion
{ {
private: private:
@ -38,9 +33,9 @@ public:
//////////////////// ////////////////////
// Server Browser // // Server Browser //
//////////////////// ////////////////////
private:
R5Net::Client* r5net; R5Net::Client* r5net = nullptr;
public:
R5Net::Client* GetR5Net() { return r5net; } R5Net::Client* GetR5Net() { return r5net; }
std::vector<ServerListing> ServerList; std::vector<ServerListing> ServerList;

View File

@ -1,11 +1,6 @@
#pragma once #pragma once
#include "serverlisting.h"
#include "gui_utility.h" #include "gui_utility.h"
///////////////////////////////////////////////////////////////////////////////
// Initialization
void DrawConsole();
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Globals // Globals
extern ImVector<char*> Items; extern ImVector<char*> Items;

View File

@ -605,7 +605,7 @@ void CCompanion::Draw(const char* title)
void CCompanion::ProcessCommand(const char* command_line) void CCompanion::ProcessCommand(const char* command_line)
{ {
spdlog::debug("[+CCompanion+] Processing command: {} creating tread now.\n", command_line); spdlog::debug("[+CCompanion+] Processing command: {} creating thread now.\n", command_line);
std::thread t(&CCompanion::ExecCommand, this, command_line); std::thread t(&CCompanion::ExecCommand, this, command_line);
spdlog::debug("[+CCompanion+] Thread created.\n"); spdlog::debug("[+CCompanion+] Thread created.\n");
t.detach(); t.detach();
@ -676,20 +676,4 @@ void CCompanion::RegenerateEncryptionKey()
void CCompanion::ChangeEncryptionKeyTo(const std::string str) void CCompanion::ChangeEncryptionKeyTo(const std::string str)
{ {
addr_NetChan_SetEncKey(addr_NetChan_EncKeyPtr.GetPtr(), str.c_str()); addr_NetChan_SetEncKey(addr_NetChan_EncKeyPtr.GetPtr(), str.c_str());
} }
//#############################################################################
// ENTRYPOINT
//#############################################################################
void DrawBrowser()
{
static CCompanion browser;
static bool AssignPtr = []() {
g_ServerBrowser = &browser;
spdlog::debug("[+CCompanion+] Created CCompanion Class instance.\n");
return true;
} ();
browser.Draw("Companion");
}

View File

@ -400,19 +400,4 @@ int CGameConsole::TextEditCallback(ImGuiInputTextCallbackData* data)
} }
} }
return 0; return 0;
} }
//#############################################################################
// ENTRYPOINT
//#############################################################################
void DrawConsole()
{
static CGameConsole console;
static bool AssignPtr = []() {
g_GameConsole = &console;
spdlog::debug("[+CGameConsole+] Created CGameConsole Class instance.\n");
return true;
} ();
console.Draw("Console");
}

View File

@ -5,6 +5,50 @@
#include "console.h" #include "console.h"
#include "patterns.h" #include "patterns.h"
//#############################################################################
// WORKER THREAD
//#############################################################################
DWORD __stdcall ProcessConsoleWorker(LPVOID)
{
while (true) // Loop forever
{
std::string sCommand = std::string();
///////////////////////////////////////////////////////////////////////
// Get the user input on the debug console
std::getline(std::cin, sCommand);
///////////////////////////////////////////////////////////////////////
// Engine toggles
if (sCommand == "toggle net") { Hooks::ToggleNetTrace(); continue; }
if (sCommand == "toggle dev") { Hooks::ToggleDevCommands(); continue; }
if (sCommand == "toggle fal") { g_bReturnAllFalse = !g_bReturnAllFalse; continue; }
///////////////////////////////////////////////////////////////////////
// Debug toggles
if (sCommand == "pattern test") { PrintHAddress(); PrintOAddress(); continue; }
if (sCommand == "directx test") { PrintDXAddress(); continue; }
if (sCommand == "console test") { g_bDebugConsole = !g_bDebugConsole; continue; }
///////////////////////////////////////////////////////////////////////
// Exec toggles
if (sCommand == "1") { Hooks::ToggleDevCommands(); addr_CommandExecute(NULL, "exec autoexec_dev"); }
if (sCommand == "2") { g_bDebugLoading = !g_bDebugLoading; continue; }
///////////////////////////////////////////////////////////////////////
// Execute the command in the r5 SQVM
addr_CommandExecute(NULL, sCommand.c_str());
sCommand.clear();
///////////////////////////////////////////////////////////////////////
// Sleep and loop
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
return 0;
}
//############################################################################# //#############################################################################
// INITIALIZATION // INITIALIZATION
//############################################################################# //#############################################################################
@ -37,72 +81,30 @@ void SetupConsole()
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Open input/output streams // Open input/output streams
FILE* fDummy; FILE* fDummy;
freopen_s(&fDummy, "CONIN$", "r", stdin); freopen_s(&fDummy, "CONIN$", "r", stdin);
freopen_s(&fDummy, "CONOUT$", "w", stdout); freopen_s(&fDummy, "CONOUT$", "w", stdout);
freopen_s(&fDummy, "CONOUT$", "w", stderr); freopen_s(&fDummy, "CONOUT$", "w", stderr);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Create a worker thread to process console commands // Create a worker thread to process console commands
DWORD threadId0; DWORD threadID = NULL;
DWORD __stdcall ProcessConsoleWorker(LPVOID); HANDLE hThread = CreateThread(NULL, 0, ProcessConsoleWorker, NULL, 0, &threadID);
HANDLE hThread0 = CreateThread(NULL, 0, ProcessConsoleWorker, NULL, 0, &threadId0);
if (hThread0)
{
printf("THREAD ID: %ld\n\n", threadId0);
CloseHandle(hThread0);
}
// Initialize global spdlog. // Initialize global spdlog.
auto console = spdlog::stdout_logger_mt("console"); auto console = spdlog::stdout_logger_mt("console");
console->set_pattern("[%I:%M:%S:%e] [%L] %v"); // Set pattern. console->set_pattern("[%I:%M:%S:%e] [%L] %v"); // Set pattern.
spdlog::set_default_logger(console); // Set as default. spdlog::set_default_logger(console); // Set as default.
spdlog::flush_every(std::chrono::seconds(5)); // Flush buffers every 5 seconds for every logger. spdlog::flush_every(std::chrono::seconds(5)); // Flush buffers every 5 seconds for every logger.
#ifdef _DEBUG #ifdef _DEBUG
console->set_level(spdlog::level::debug); console->set_level(spdlog::level::debug);
#endif #endif
spdlog::debug("Console and spdlog are setup now!\n"); spdlog::debug("Console and spdlog are setup now!\n");
}
//############################################################################# if (hThread)
// WORKER THREAD
//#############################################################################
DWORD __stdcall ProcessConsoleWorker(LPVOID)
{
while (true) // Loop forever
{ {
std::string sCommand; spdlog::info("THREAD ID: {}\n\n", threadID);
CloseHandle(hThread);
///////////////////////////////////////////////////////////////////////
// Get the user input on the debug console
printf(">");
std::getline(std::cin, sCommand);
///////////////////////////////////////////////////////////////////////
// Engine toggles
if (sCommand == "toggle net") { Hooks::ToggleNetTrace(); continue; }
if (sCommand == "toggle dev") { Hooks::ToggleDevCommands(); continue; }
if (sCommand == "toggle fal") { g_bReturnAllFalse = !g_bReturnAllFalse; continue; }
///////////////////////////////////////////////////////////////////////
// Debug toggles
if (sCommand == "pattern test") { PrintHAddress(); PrintOAddress(); continue; }
if (sCommand == "directx test") { PrintDXAddress(); continue; }
if (sCommand == "console test") { g_bDebugConsole = !g_bDebugConsole; continue; }
///////////////////////////////////////////////////////////////////////
// Exec toggles
if (sCommand == "1") { Hooks::ToggleDevCommands(); addr_CommandExecute(NULL, "exec autoexec_dev"); }
if (sCommand == "2") { g_bDebugLoading = !g_bDebugLoading; continue; }
///////////////////////////////////////////////////////////////////////
// Execute the command in the r5 SQVM
addr_CommandExecute(NULL, sCommand.c_str());
sCommand.clear();
///////////////////////////////////////////////////////////////////////
// Sleep and loop
Sleep(50);
} }
return 0;
} }

View File

@ -41,13 +41,6 @@ void* Hooks::ConnectClient(void* thisptr, void* packet)
if (!GameGlobals::BanSystem) if (!GameGlobals::BanSystem)
return originalConnectClient(thisptr, packet); return originalConnectClient(thisptr, packet);
static int skipConnects = 0;
if (skipConnects != 2) // Skip first two connect attempts.
{
skipConnects++;
return originalConnectClient(thisptr, packet);
}
std::string finalIPAddress = "null"; std::string finalIPAddress = "null";
MemoryAddress ipAddressField = MemoryAddress(((std::uintptr_t)packet + 0x10)); MemoryAddress ipAddressField = MemoryAddress(((std::uintptr_t)packet + 0x10));
if (ipAddressField && ipAddressField.GetValue<int>() != 0x0) if (ipAddressField && ipAddressField.GetValue<int>() != 0x0)

View File

@ -219,6 +219,21 @@ void DrawMenu()
ImGui_ImplWin32_NewFrame(); ImGui_ImplWin32_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
// Init class instances.
static CGameConsole console;
static bool AssignConsolePtr = []() {
g_GameConsole = &console;
spdlog::debug("[+CGameConsole+] Created CGameConsole Class instance.\n");
return true;
} ();
static CCompanion companion;
static bool AssignCompanionPtr = []() {
g_ServerBrowser = &companion;
spdlog::debug("[+CCompanion+] Created CCompanion Class instance.\n");
return true;
} ();
// Handle game input if one of the menus is open. // Handle game input if one of the menus is open.
if (g_bShowConsole || g_bShowBrowser) if (g_bShowConsole || g_bShowBrowser)
{ {
@ -231,12 +246,12 @@ void DrawMenu()
if (g_bShowConsole) if (g_bShowConsole)
{ {
DrawConsole(); console.Draw("Console");
} }
if (g_bShowBrowser) if (g_bShowBrowser)
{ {
DrawBrowser(); companion.Draw("Companion");
} }
// Handle end of frame and prepare rendering. // Handle end of frame and prepare rendering.

View File

@ -1,3 +1,2 @@
#include "netpch.h" #include "netpch.h"
#include "r5\serverlisting.h" #include "r5\serverlisting.h"