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

View File

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

View File

@ -605,7 +605,7 @@ void CCompanion::Draw(const char* title)
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);
spdlog::debug("[+CCompanion+] Thread created.\n");
t.detach();
@ -677,19 +677,3 @@ void CCompanion::ChangeEncryptionKeyTo(const std::string 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

@ -401,18 +401,3 @@ int CGameConsole::TextEditCallback(ImGuiInputTextCallbackData* data)
}
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 "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
//#############################################################################
@ -43,66 +87,24 @@ void SetupConsole()
///////////////////////////////////////////////////////////////////////////
// Create a worker thread to process console commands
DWORD threadId0;
DWORD __stdcall ProcessConsoleWorker(LPVOID);
HANDLE hThread0 = CreateThread(NULL, 0, ProcessConsoleWorker, NULL, 0, &threadId0);
if (hThread0)
{
printf("THREAD ID: %ld\n\n", threadId0);
CloseHandle(hThread0);
}
DWORD threadID = NULL;
HANDLE hThread = CreateThread(NULL, 0, ProcessConsoleWorker, NULL, 0, &threadID);
// Initialize global spdlog.
auto console = spdlog::stdout_logger_mt("console");
console->set_pattern("[%I:%M:%S:%e] [%L] %v"); // Set pattern.
spdlog::set_default_logger(console); // Set as default.
spdlog::flush_every(std::chrono::seconds(5)); // Flush buffers every 5 seconds for every logger.
#ifdef _DEBUG
console->set_level(spdlog::level::debug);
#endif
spdlog::debug("Console and spdlog are setup now!\n");
}
//#############################################################################
// WORKER THREAD
//#############################################################################
DWORD __stdcall ProcessConsoleWorker(LPVOID)
{
while (true) // Loop forever
if (hThread)
{
std::string sCommand;
///////////////////////////////////////////////////////////////////////
// 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);
spdlog::info("THREAD ID: {}\n\n", threadID);
CloseHandle(hThread);
}
return 0;
}

View File

@ -41,13 +41,6 @@ void* Hooks::ConnectClient(void* thisptr, void* packet)
if (!GameGlobals::BanSystem)
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";
MemoryAddress ipAddressField = MemoryAddress(((std::uintptr_t)packet + 0x10));
if (ipAddressField && ipAddressField.GetValue<int>() != 0x0)

View File

@ -219,6 +219,21 @@ void DrawMenu()
ImGui_ImplWin32_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.
if (g_bShowConsole || g_bShowBrowser)
{
@ -231,12 +246,12 @@ void DrawMenu()
if (g_bShowConsole)
{
DrawConsole();
console.Draw("Console");
}
if (g_bShowBrowser)
{
DrawBrowser();
companion.Draw("Companion");
}
// Handle end of frame and prepare rendering.

View File

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