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

79 lines
1.4 KiB
C++
Raw Normal View History

2022-02-03 14:05:24 -05:00
#include <std_include.hpp>
#include "console.hpp"
#include "loader/component_loader.hpp"
2022-02-03 14:05:24 -05:00
#include "game/game.hpp"
#include "command.hpp"
namespace game_console
{
void print(int type, const std::string& data);
}
namespace console
{
namespace
{
DWORD WINAPI console(LPVOID)
2022-02-28 20:39:22 -05:00
{
FreeConsole();
AllocConsole();
AttachConsole(GetCurrentProcessId());
2022-02-28 20:39:22 -05:00
(void)freopen("CONIN$", "r", stdin);
(void)freopen("CONOUT$", "w", stdout);
2022-02-03 14:05:24 -05:00
std::string cmd;
2022-02-03 14:05:24 -05:00
while (true)
2022-02-03 14:05:24 -05:00
{
std::getline(std::cin, cmd);
2022-02-28 20:39:22 -05:00
}
return 0;
2022-02-03 14:05:24 -05:00
}
}
std::string format(va_list* ap, const char* message)
2022-02-03 14:05:24 -05:00
{
static thread_local char buffer[0x1000];
2022-02-03 14:05:24 -05:00
const auto count = _vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer), message, *ap);
2022-02-03 14:05:24 -05:00
if (count < 0) return {};
return { buffer, static_cast<size_t>(count) };
2022-02-03 14:05:24 -05:00
}
void dispatch_message(const int type, const std::string& message)
2022-02-03 14:05:24 -05:00
{
printf("%s\n", message.data());
//game_console::print(type, message);
//messages.access([&message](message_queue& msgs)
// {
// msgs.emplace(message);
// });
2022-02-03 14:05:24 -05:00
}
void print(const int type, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
const auto result = format(&ap, fmt);
va_end(ap);
dispatch_message(type, result);
}
class component final : public component_interface
{
public:
void post_start() override
{
CreateThread(0, 0, console, 0, 0, 0);
}
};
2022-02-03 14:05:24 -05:00
}
REGISTER_COMPONENT(console::component)