2022-02-03 14:05:24 -05:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "console.hpp"
|
|
|
|
#include "loader/component_loader.hpp"
|
2022-05-17 14:03:29 -04:00
|
|
|
|
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
|
|
|
|
{
|
2022-05-17 14:03:29 -04:00
|
|
|
DWORD WINAPI console(LPVOID)
|
2022-02-28 20:39:22 -05:00
|
|
|
{
|
2022-05-18 04:26:48 -04:00
|
|
|
ShowWindow(GetConsoleWindow(), SW_SHOW);
|
|
|
|
SetConsoleTitle("H1-Mod");
|
2022-02-03 14:05:24 -05:00
|
|
|
|
2022-05-17 14:03:29 -04:00
|
|
|
std::string cmd;
|
2022-02-03 14:05:24 -05:00
|
|
|
|
2022-05-17 14:03:29 -04:00
|
|
|
while (true)
|
2022-02-03 14:05:24 -05:00
|
|
|
{
|
2022-05-17 14:03:29 -04:00
|
|
|
std::getline(std::cin, cmd);
|
2022-02-28 20:39:22 -05:00
|
|
|
}
|
|
|
|
|
2022-05-17 14:03:29 -04:00
|
|
|
return 0;
|
2022-02-03 14:05:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:03:29 -04:00
|
|
|
std::string format(va_list* ap, const char* message)
|
2022-02-03 14:05:24 -05:00
|
|
|
{
|
2022-05-17 14:03:29 -04:00
|
|
|
static thread_local char buffer[0x1000];
|
2022-02-03 14:05:24 -05:00
|
|
|
|
2022-05-17 14:03:29 -04:00
|
|
|
const auto count = _vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer), message, *ap);
|
2022-02-03 14:05:24 -05:00
|
|
|
|
2022-05-17 14:03:29 -04:00
|
|
|
if (count < 0) return {};
|
|
|
|
return { buffer, static_cast<size_t>(count) };
|
2022-02-03 14:05:24 -05:00
|
|
|
}
|
|
|
|
|
2022-05-17 14:03:29 -04:00
|
|
|
void dispatch_message(const int type, const std::string& message)
|
2022-02-03 14:05:24 -05:00
|
|
|
{
|
2022-05-17 14:03:29 -04: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);
|
|
|
|
}
|
2022-05-17 14:03:29 -04:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-05-17 14:03:29 -04:00
|
|
|
REGISTER_COMPONENT(console::component)
|