From b9e9369637f488177d82d6dc9d6845831a04a2d8 Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Wed, 18 May 2022 14:35:39 +0300 Subject: [PATCH] Add console input --- src/client/component/binding.cpp | 2 +- src/client/component/command.cpp | 2 +- src/client/component/console.cpp | 20 ++++++++++++++++---- src/client/component/console.hpp | 9 +++++++++ src/client/component/dedicated.cpp | 8 ++++---- src/client/component/game_console.cpp | 2 +- src/client/game/symbols.hpp | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/client/component/binding.cpp b/src/client/component/binding.cpp index 15828dfe..ab101b1d 100644 --- a/src/client/component/binding.cpp +++ b/src/client/component/binding.cpp @@ -103,7 +103,7 @@ namespace binding if (static_cast(key) < custom_binds.size() && !custom_binds[key].empty()) { - game::Cbuf_AddText(local_client_num, utils::string::va("%s\n", custom_binds[key].data())); + game::Cbuf_AddText(local_client_num, 0, utils::string::va("%s\n", custom_binds[key].data())); } return; diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index ba460c92..4ed2b282 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -493,7 +493,7 @@ namespace command } else { - game::Cbuf_AddText(0, command.data()); + game::Cbuf_AddText(0, 0, command.data()); } } diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index cfe8afef..c813372a 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -14,6 +14,8 @@ namespace console { namespace { + static bool ingame = false; + DWORD WINAPI console(LPVOID) { ShowWindow(GetConsoleWindow(), SW_SHOW); @@ -24,6 +26,10 @@ namespace console while (true) { std::getline(std::cin, cmd); + if (ingame) + { + game::Cbuf_AddText(0, 0, cmd.data()); + } } return 0; @@ -45,10 +51,6 @@ namespace console printf("%s\n", message.data()); //game_console::print(type, message); - //messages.access([&message](message_queue& msgs) - // { - // msgs.emplace(message); - // }); } void print(const int type, const char* fmt, ...) @@ -68,6 +70,16 @@ namespace console { CreateThread(0, 0, console, 0, 0, 0); } + + void post_unpack() override + { + ingame = true; + } + + void pre_destroy() override + { + ingame = false; + } }; } diff --git a/src/client/component/console.hpp b/src/client/component/console.hpp index 302951a8..8dcf5fab 100644 --- a/src/client/component/console.hpp +++ b/src/client/component/console.hpp @@ -9,6 +9,7 @@ namespace console enum console_type { con_type_error = 1, + con_type_dev = 2, con_type_warning = 3, con_type_info = 7 }; @@ -21,6 +22,14 @@ namespace console print(con_type_error, fmt, std::forward(args)...); } + template + void debug(const char* fmt, Args&&... args) + { +#ifdef DEBUG + print(2, fmt, std::forward(args)...); +#endif + } + template void warn(const char* fmt, Args&&... args) { diff --git a/src/client/component/dedicated.cpp b/src/client/component/dedicated.cpp index e1439d82..2acfcce5 100644 --- a/src/client/component/dedicated.cpp +++ b/src/client/component/dedicated.cpp @@ -83,8 +83,8 @@ namespace dedicated { if (game::Live_SyncOnlineDataFlags(0) == 0) { - game::Cbuf_AddText(client, command); - game::Cbuf_AddText(client, "\n"); + game::Cbuf_AddText(client, 0, command); + game::Cbuf_AddText(client, 0, "\n"); } else { @@ -99,8 +99,8 @@ namespace dedicated for (const auto& command : queue) { - game::Cbuf_AddText(0, command.data()); - game::Cbuf_AddText(0, "\n"); + game::Cbuf_AddText(0, 0, command.data()); + game::Cbuf_AddText(0, 0, "\n"); } } diff --git a/src/client/component/game_console.cpp b/src/client/component/game_console.cpp index 2e8dfd9d..85fd4ff8 100644 --- a/src/client/component/game_console.cpp +++ b/src/client/component/game_console.cpp @@ -680,7 +680,7 @@ namespace game_console if (key == game::keyNum_t::K_ENTER) { - game::Cbuf_AddText(0, utils::string::va("%s \n", fixed_input.data())); + game::Cbuf_AddText(0, 0, utils::string::va("%s \n", fixed_input.data())); if (history_index != -1) { diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 75bd2671..d6650edc 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -15,7 +15,7 @@ namespace game WEAK symbol AllocThread{0x0, 0x509440}; WEAK symbol AllocVariable{0x0, 0x0}; - WEAK symbol Cbuf_AddText{0x0, 0x1CF480}; + WEAK symbol Cbuf_AddText{0x0, 0x1CF480}; WEAK symbol Cbuf_ExecuteBufferInternal{0x0, 0x155BC0}; WEAK symbol Conbuf_AppendText{0x0, 0x0};