From 34d5a880e0970008da81e9625de739ed28871c35 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Tue, 1 Mar 2022 02:39:22 +0100 Subject: [PATCH] Dedi progress --- src/client/component/console.cpp | 61 ++++++++++++++++++++++-------- src/client/component/dedicated.cpp | 17 +++++---- src/client/game/symbols.hpp | 2 +- 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index dd9b7e1e..381f16f1 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -21,6 +21,12 @@ namespace console using message_queue = std::queue; utils::concurrency::container messages; + bool native_console() + { + static const auto flag = utils::flags::has_flag("nativeconsole"); + return flag; + } + void hide_console() { auto* const con_window = GetConsoleWindow(); @@ -28,11 +34,9 @@ namespace console DWORD process; GetWindowThreadProcessId(con_window, &process); - if (process == GetCurrentProcessId() || IsDebuggerPresent()) + if (!native_console() && (process == GetCurrentProcessId() || IsDebuggerPresent())) { -#ifndef NATIVE_CONSOLE ShowWindow(con_window, SW_HIDE); -#endif } } @@ -48,6 +52,12 @@ namespace console void dispatch_message(const int type, const std::string& message) { + if (native_console()) + { + printf("%s\n", message.data()); + return; + } + game_console::print(type, message); messages.access([&message](message_queue& msgs) { @@ -68,14 +78,17 @@ namespace console { hide_console(); -#ifdef NATIVE_CONSOLE - setvbuf(stdout, nullptr, _IONBF, 0); - setvbuf(stderr, nullptr, _IONBF, 0); -#else - (void)_pipe(this->handles_, 1024, _O_TEXT); - (void)_dup2(this->handles_[1], 1); - (void)_dup2(this->handles_[1], 2); -#endif + if (native_console()) + { + setvbuf(stdout, nullptr, _IONBF, 0); + setvbuf(stderr, nullptr, _IONBF, 0); + } + else + { + (void)_pipe(this->handles_, 1024, _O_TEXT); + (void)_dup2(this->handles_[1], 1); + (void)_dup2(this->handles_[1], 2); + } } void post_start() override @@ -84,7 +97,14 @@ namespace console this->console_runner_ = utils::thread::create_named_thread("Console IO", [this] { - this->runner(); + if (native_console()) + { + this->native_input(); + } + else + { + this->runner(); + } }); } @@ -135,11 +155,9 @@ namespace console { this->console_thread_ = utils::thread::create_named_thread("Console", [this]() { - if (game::environment::is_dedi() || !utils::flags::has_flag("noconsole")) + if (!native_console() && (game::environment::is_dedi() || !utils::flags::has_flag("noconsole"))) { -#ifndef NATIVE_CONSOLE game::Sys_ShowConsole(); -#endif } if (!game::environment::is_dedi()) @@ -229,6 +247,19 @@ namespace console std::this_thread::yield(); } + + void native_input() + { + std::string cmd; + + while (true) + { + std::getline(std::cin, cmd); + command::execute(cmd); + } + + std::this_thread::yield(); + } }; HWND get_window() diff --git a/src/client/component/dedicated.cpp b/src/client/component/dedicated.cpp index c5fda9d2..6e63f082 100644 --- a/src/client/component/dedicated.cpp +++ b/src/client/component/dedicated.cpp @@ -226,13 +226,12 @@ namespace dedicated utils::hook::set(0x140620D10, 0xC3); // render thread utils::hook::set(0x14025B850, 0xC3); // called from Com_Frame, seems to do renderer stuff utils::hook::set(0x1402507B0, 0xC3); // CL_CheckForResend, which tries to connect to the local server constantly - utils::hook::set(0x1405D5176, 0); // r_loadForRenderer default to 0 + utils::hook::set(0x1405D5178, 0x00); // r_loadForRenderer default to 0 utils::hook::set(0x14050C2D0, 0xC3); // recommended settings check - TODO: Check hook utils::hook::set(0x140514C00, 0xC3); // some mixer-related function called on shutdown utils::hook::set(0x140409830, 0xC3); // dont load ui gametype stuff - // (COULD NOT FIND IN H1) - // utils::hook::nop(0x14043ABB8, 6); // unknown check in SV_ExecuteClientMessage // ?? + utils::hook::nop(0x140481B06, 6); // unknown check in SV_ExecuteClientMessage utils::hook::nop(0x140480FAC, 4); // allow first slot to be occupied utils::hook::nop(0x14025619B, 2); // properly shut down dedicated servers utils::hook::nop(0x14025615E, 2); // ^ @@ -273,22 +272,24 @@ namespace dedicated utils::hook::set(0x1405E0C00, 0xC3); // ^ utils::hook::set(0x1405DFE50, 0xC3); // ^ - utils::hook::set(0x1404B67E0, 0xC3); // sound crashes (H1 - questionable, function looks way different) + // utils::hook::set(0x1404B67E0, 0xC3); // sound crashes (H1 - questionable, function looks way different) utils::hook::set(0x14048B660, 0xC3); // disable host migration utils::hook::set(0x14042B2E0, 0xC3); // render synchronization lock utils::hook::set(0x14042B210, 0xC3); // render synchronization unlock - utils::hook::set(0x140176D2D, 0xEB); - // LUI: Unable to start the LUI system due to errors in main.lua + utils::hook::set(0x140176D2D, 0xEB); // LUI: Unable to start the LUI system due to errors in main.lua utils::hook::nop(0x140506ECE, 5); // Disable sound pak file loading utils::hook::nop(0x140506ED6, 2); // ^ utils::hook::set(0x1402C5910, 0xC3); // Disable image pak file loading // Reduce min required memory - utils::hook::set(0x14050C715, 0x80000000); + utils::hook::set(0x14050C717, 0x80000000); + + utils::hook::set(0x1402BF7F0, 0xC3); // some loop + utils::hook::set(0x14007E150, 0xC3); // related to shader caching / techsets / fastfiles // initialize the game after onlinedataflags is 32 (workaround) scheduler::schedule([=]() @@ -315,7 +316,7 @@ namespace dedicated console::info("==================================\n"); // remove disconnect command - game::Cmd_RemoveCommand(reinterpret_cast(751)); + game::Cmd_RemoveCommand("disconnect"); execute_startup_command_queue(); execute_console_command_queue(); diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index b31329f6..cb0feba9 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -14,7 +14,7 @@ namespace game WEAK symbol Conbuf_AppendText{0x1403E3300, 0x140513FF0}; WEAK symbol Cmd_ExecuteSingleCommand{0x140343980, 0x140403F60}; WEAK symbol Cmd_AddCommandInternal{0x1403433E0, 0x140403950}; - WEAK symbol Cmd_RemoveCommand{0x140343FF0, 0x1403AFEF0}; + WEAK symbol Cmd_RemoveCommand{0x140343FF0, 0x1404045D0}; WEAK symbol Cmd_TokenizeString{0x140344110, 0x1404046F0}; WEAK symbol Cmd_EndTokenizeString{0x140343630, 0x140403C20};