2021-07-19 15:45:42 +02:00
|
|
|
#include "pch.h"
|
2021-07-12 08:47:54 -07:00
|
|
|
#include "id3dx.h"
|
2021-04-17 04:51:04 -07:00
|
|
|
#include "hooks.h"
|
2021-06-08 10:54:49 -07:00
|
|
|
#include "opcptc.h"
|
|
|
|
#include "console.h"
|
2021-04-16 14:12:39 +02:00
|
|
|
#include "patterns.h"
|
2021-04-13 04:45:22 -07:00
|
|
|
|
2021-11-05 00:57:52 +01:00
|
|
|
//#############################################################################
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2021-06-28 15:51:32 -07:00
|
|
|
//#############################################################################
|
|
|
|
// INITIALIZATION
|
|
|
|
//#############################################################################
|
2021-04-13 04:45:22 -07:00
|
|
|
|
|
|
|
void SetupConsole()
|
|
|
|
{
|
2021-06-28 15:51:32 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-04-13 04:45:22 -07:00
|
|
|
// Create the console window
|
2021-11-05 00:09:49 +01:00
|
|
|
if (!AllocConsole())
|
2021-04-13 04:45:22 -07:00
|
|
|
{
|
2021-04-16 14:15:29 +02:00
|
|
|
OutputDebugString("Failed to create console window!\n");
|
2021-04-13 04:45:22 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-28 15:51:32 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-04-13 04:45:22 -07:00
|
|
|
// Set the window title
|
2021-04-17 04:51:04 -07:00
|
|
|
FILE* sBuildTxt;
|
2021-04-25 14:36:55 -07:00
|
|
|
CHAR sBuildBuf[1024] = { 0 };
|
2021-06-08 10:54:49 -07:00
|
|
|
|
2021-06-19 07:18:39 -07:00
|
|
|
fopen_s(&sBuildTxt, "build.txt", "r");
|
2021-04-16 14:12:39 +02:00
|
|
|
if (sBuildTxt)
|
|
|
|
{
|
2021-04-16 11:06:20 -07:00
|
|
|
while (fgets(sBuildBuf, sizeof(sBuildBuf), sBuildTxt) != NULL)
|
2021-04-25 14:36:55 -07:00
|
|
|
{
|
2021-04-16 14:12:39 +02:00
|
|
|
fclose(sBuildTxt);
|
2021-04-25 14:36:55 -07:00
|
|
|
}
|
2021-04-16 14:12:39 +02:00
|
|
|
}
|
2021-04-16 11:06:20 -07:00
|
|
|
SetConsoleTitle(sBuildBuf);
|
2021-04-13 04:45:22 -07:00
|
|
|
|
2021-06-28 15:51:32 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-04-13 04:45:22 -07:00
|
|
|
// Open input/output streams
|
|
|
|
FILE* fDummy;
|
2021-11-05 00:57:52 +01:00
|
|
|
freopen_s(&fDummy, "CONIN$", "r", stdin);
|
2021-04-13 04:45:22 -07:00
|
|
|
freopen_s(&fDummy, "CONOUT$", "w", stdout);
|
|
|
|
freopen_s(&fDummy, "CONOUT$", "w", stderr);
|
|
|
|
|
2021-06-28 15:51:32 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-04-25 14:36:55 -07:00
|
|
|
// Create a worker thread to process console commands
|
2021-11-05 00:57:52 +01:00
|
|
|
DWORD threadID = NULL;
|
|
|
|
HANDLE hThread = CreateThread(NULL, 0, ProcessConsoleWorker, NULL, 0, &threadID);
|
2021-10-05 00:25:58 +02:00
|
|
|
|
|
|
|
// 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.
|
2021-11-05 00:57:52 +01:00
|
|
|
|
2021-10-05 00:25:58 +02:00
|
|
|
#ifdef _DEBUG
|
|
|
|
console->set_level(spdlog::level::debug);
|
|
|
|
#endif
|
2021-04-13 04:45:22 -07:00
|
|
|
|
2021-11-05 00:57:52 +01:00
|
|
|
spdlog::debug("Console and spdlog are setup now!\n");
|
2021-04-13 04:45:22 -07:00
|
|
|
|
2021-11-05 00:57:52 +01:00
|
|
|
if (hThread)
|
2021-04-17 04:51:04 -07:00
|
|
|
{
|
2021-11-05 00:57:52 +01:00
|
|
|
spdlog::info("THREAD ID: {}\n\n", threadID);
|
|
|
|
CloseHandle(hThread);
|
2021-04-17 04:51:04 -07:00
|
|
|
}
|
2021-07-27 23:08:20 +02:00
|
|
|
}
|