t7x/src/client/component/console.cpp

73 lines
1.3 KiB
C++
Raw Normal View History

2022-05-21 06:04:08 -04:00
#include <std_include.hpp>
#include "console.hpp"
#include "loader/component_loader.hpp"
#include <utils/thread.hpp>
#include <utils/hook.hpp>
namespace console
{
2022-05-23 11:57:45 -04:00
namespace
{
void create_game_console()
{
2022-05-27 13:08:39 -04:00
reinterpret_cast<void(*)()>(0x142333F80_g)();
2022-05-23 11:57:45 -04:00
}
}
2022-05-21 06:04:08 -04:00
class component final : public component_interface
{
public:
void post_unpack() override
{
this->terminate_runner_ = false;
this->console_runner_ = utils::thread::create_named_thread("Console IO", [this]
{
2022-05-27 13:08:39 -04:00
{
utils::hook::detour d;
d.create(0x142333B40_g, utils::hook::assemble([](utils::hook::assembler& a)
{
a.mov(r8, "BOIII Console");
a.mov(r9d, 0x80CA0000);
a.sub(eax, edx);
a.jmp(0x142333B4F_g);
}));
2022-05-27 13:08:39 -04:00
create_game_console();
}
2022-05-23 11:57:45 -04:00
MSG msg{};
while (!this->terminate_runner_)
{
2022-05-29 12:51:24 -04:00
if (PeekMessageW(&msg, nullptr, NULL, NULL, PM_REMOVE))
2022-05-23 11:57:45 -04:00
{
TranslateMessage(&msg);
2022-05-29 12:51:24 -04:00
DispatchMessageW(&msg);
2022-05-23 11:57:45 -04:00
}
else
{
std::this_thread::sleep_for(1ms);
}
}
2022-05-21 06:04:08 -04:00
});
}
void pre_destroy() override
{
this->terminate_runner_ = true;
if (this->console_runner_.joinable())
{
this->console_runner_.join();
}
}
private:
std::atomic_bool terminate_runner_{false};
std::thread console_runner_;
};
}
REGISTER_COMPONENT(console::component)