h2-mod/src/client/component/console.cpp

54 lines
902 B
C++
Raw Normal View History

2021-09-06 18:40:37 -04:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
2021-09-07 19:21:20 -04:00
#include "command.hpp"
2021-09-06 18:40:37 -04:00
#include "game_console.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
2021-09-07 19:21:20 -04:00
#include <utils/thread.hpp>
2021-09-06 18:40:37 -04:00
#include <utils/hook.hpp>
namespace console
{
namespace
{
2021-09-07 19:21:20 -04:00
std::thread console_thread;
2021-12-27 22:25:14 -05:00
bool kill = false;
2021-09-06 18:40:37 -04:00
}
class component final : public component_interface
{
public:
void post_unpack() override
{
2021-09-07 19:21:20 -04:00
ShowWindow(GetConsoleWindow(), SW_SHOW);
SetConsoleTitle("H2-Mod");
console_thread = utils::thread::create_named_thread("Console", []()
{
2021-12-27 22:25:14 -05:00
while (!kill)
2021-09-07 19:21:20 -04:00
{
2021-12-28 11:14:47 -05:00
// to do: get input without blocking the thread
std::this_thread::sleep_for(1ms);
2021-09-07 19:21:20 -04:00
}
2021-12-27 22:25:14 -05:00
std::this_thread::yield();
2021-09-07 19:21:20 -04:00
});
2021-09-06 18:40:37 -04:00
}
2021-12-27 22:25:14 -05:00
void pre_destroy() override
{
kill = true;
if (console_thread.joinable())
{
console_thread.join();
}
}
2021-09-06 18:40:37 -04:00
};
}
REGISTER_COMPONENT(console::component)