Macro for native console window

This commit is contained in:
Federico Cecchetto 2022-02-26 21:42:44 +01:00
parent dfc98bb475
commit c20b0c50ab
2 changed files with 19 additions and 14 deletions

View File

@ -30,7 +30,9 @@ namespace console
if (process == GetCurrentProcessId() || IsDebuggerPresent()) if (process == GetCurrentProcessId() || IsDebuggerPresent())
{ {
#ifndef NATIVE_CONSOLE
ShowWindow(con_window, SW_HIDE); ShowWindow(con_window, SW_HIDE);
#endif
} }
} }
@ -66,12 +68,14 @@ namespace console
{ {
hide_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)_pipe(this->handles_, 1024, _O_TEXT);
(void)_dup2(this->handles_[1], 1); (void)_dup2(this->handles_[1], 1);
(void)_dup2(this->handles_[1], 2); (void)_dup2(this->handles_[1], 2);
#endif
//setvbuf(stdout, nullptr, _IONBF, 0);
//setvbuf(stderr, nullptr, _IONBF, 0);
} }
void post_start() override void post_start() override
@ -79,9 +83,9 @@ namespace console
this->terminate_runner_ = false; this->terminate_runner_ = false;
this->console_runner_ = utils::thread::create_named_thread("Console IO", [this] this->console_runner_ = utils::thread::create_named_thread("Console IO", [this]
{ {
this->runner(); this->runner();
}); });
} }
void pre_destroy() override void pre_destroy() override
@ -105,9 +109,9 @@ namespace console
_close(this->handles_[1]); _close(this->handles_[1]);
messages.access([&](message_queue& msgs) messages.access([&](message_queue& msgs)
{ {
msgs = {}; msgs = {};
}); });
} }
void post_unpack() override void post_unpack() override
@ -133,7 +137,9 @@ namespace console
{ {
if (game::environment::is_dedi() || !utils::flags::has_flag("noconsole")) if (game::environment::is_dedi() || !utils::flags::has_flag("noconsole"))
{ {
#ifndef NATIVE_CONSOLE
game::Sys_ShowConsole(); game::Sys_ShowConsole();
#endif
} }
if (!game::environment::is_dedi()) if (!game::environment::is_dedi())
@ -181,10 +187,10 @@ namespace console
{ {
messages.access([&](message_queue& msgs) messages.access([&](message_queue& msgs)
{ {
message_queue_copy = std::move(msgs); message_queue_copy = std::move(msgs);
msgs = {}; msgs = {};
}); });
} }
while (!message_queue_copy.empty()) while (!message_queue_copy.empty())

View File

@ -166,7 +166,6 @@ namespace game
* Variables * Variables
**************************************************************/ **************************************************************/
WEAK symbol<CmdArgs> sv_cmd_args{0, 0x14946BA20}; WEAK symbol<CmdArgs> sv_cmd_args{0, 0x14946BA20};
WEAK symbol<const char*> command_whitelist{0x141079A60, 0x14120C360}; WEAK symbol<const char*> command_whitelist{0x141079A60, 0x14120C360};