Dedi progress

This commit is contained in:
Federico Cecchetto 2022-03-01 02:39:22 +01:00
parent fb2efeb089
commit 34d5a880e0
3 changed files with 56 additions and 24 deletions

View File

@ -21,6 +21,12 @@ namespace console
using message_queue = std::queue<std::string>;
utils::concurrency::container<message_queue> 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()

View File

@ -226,13 +226,12 @@ namespace dedicated
utils::hook::set<uint8_t>(0x140620D10, 0xC3); // render thread
utils::hook::set<uint8_t>(0x14025B850, 0xC3); // called from Com_Frame, seems to do renderer stuff
utils::hook::set<uint8_t>(0x1402507B0, 0xC3); // CL_CheckForResend, which tries to connect to the local server constantly
utils::hook::set<uint8_t>(0x1405D5176, 0); // r_loadForRenderer default to 0
utils::hook::set<uint8_t>(0x1405D5178, 0x00); // r_loadForRenderer default to 0
utils::hook::set<uint8_t>(0x14050C2D0, 0xC3); // recommended settings check - TODO: Check hook
utils::hook::set<uint8_t>(0x140514C00, 0xC3); // some mixer-related function called on shutdown
utils::hook::set<uint8_t>(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<uint8_t>(0x1405E0C00, 0xC3); // ^
utils::hook::set<uint8_t>(0x1405DFE50, 0xC3); // ^
utils::hook::set<uint8_t>(0x1404B67E0, 0xC3); // sound crashes (H1 - questionable, function looks way different)
// utils::hook::set<uint8_t>(0x1404B67E0, 0xC3); // sound crashes (H1 - questionable, function looks way different)
utils::hook::set<uint8_t>(0x14048B660, 0xC3); // disable host migration
utils::hook::set<uint8_t>(0x14042B2E0, 0xC3); // render synchronization lock
utils::hook::set<uint8_t>(0x14042B210, 0xC3); // render synchronization unlock
utils::hook::set<uint8_t>(0x140176D2D, 0xEB);
// LUI: Unable to start the LUI system due to errors in main.lua
utils::hook::set<uint8_t>(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<uint8_t>(0x1402C5910, 0xC3); // Disable image pak file loading
// Reduce min required memory
utils::hook::set<uint64_t>(0x14050C715, 0x80000000);
utils::hook::set<uint64_t>(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<const char*>(751));
game::Cmd_RemoveCommand("disconnect");
execute_startup_command_queue();
execute_console_command_queue();

View File

@ -14,7 +14,7 @@ namespace game
WEAK symbol<void(const char* message)> Conbuf_AppendText{0x1403E3300, 0x140513FF0};
WEAK symbol<void(int localClientNum, int controllerIndex, const char* text)> Cmd_ExecuteSingleCommand{0x140343980, 0x140403F60};
WEAK symbol<void(const char* cmdName, void(), cmd_function_s* allocedCmd)> Cmd_AddCommandInternal{0x1403433E0, 0x140403950};
WEAK symbol<void(const char*)> Cmd_RemoveCommand{0x140343FF0, 0x1403AFEF0};
WEAK symbol<void(const char*)> Cmd_RemoveCommand{0x140343FF0, 0x1404045D0};
WEAK symbol<void(const char* text_in)> Cmd_TokenizeString{0x140344110, 0x1404046F0};
WEAK symbol<void()> Cmd_EndTokenizeString{0x140343630, 0x140403C20};