Updated Console

Added command line tag for external console
This commit is contained in:
bodnjenie14 2024-05-27 17:04:52 +01:00 committed by GitHub
parent d003511810
commit 324fcc2425
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,3 @@
//TODO: Fix console branding
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include <utilities/string.hpp>
@ -14,9 +12,8 @@ namespace console
{
namespace
{
const char* branding_str = "Project-Bo4 >";
size_t branding_lenght = std::strlen(branding_str);
const char* branding_str = "shield> ";
size_t branding_length = std::strlen(branding_str);
utilities::hook::detour printf_hook;
std::recursive_mutex print_mutex;
@ -64,7 +61,7 @@ namespace console
return {};
}
return {buffer, static_cast<size_t>(count)};
return { buffer, static_cast<size_t>(count) };
}
void update()
@ -73,11 +70,8 @@ namespace console
show_cursor(false);
set_cursor_pos(0);
invoke_printf("%s", con.buffer);
//invoke_printf("%s %s", branding_str, con.buffer);
set_cursor_pos(con.cursor);
//set_cursor_pos(branding_lenght + con.cursor);
invoke_printf("%s%s", branding_str, con.buffer);
set_cursor_pos(branding_length + con.cursor);
show_cursor(true);
}
@ -88,18 +82,17 @@ namespace console
show_cursor(false);
set_cursor_pos(0);
for (auto i = 0; i < std::strlen(con.buffer); i++)
for (auto i = 0; i < branding_length + std::strlen(con.buffer); i++)
{
invoke_printf(" ");
}
set_cursor_pos(con.cursor);
set_cursor_pos(0);
show_cursor(true);
}
int dispatch_message(const int type, const std::string& message)
{
std::lock_guard _0(print_mutex);
clear_output();
@ -132,7 +125,7 @@ namespace console
CONSOLE_SCREEN_BUFFER_INFO info{};
GetConsoleScreenBufferInfo(OUTPUT_HANDLE, &info);
const auto columns = static_cast<size_t>(info.srWindow.Right - info.srWindow.Left - 1);
return std::max(size_t(0), std::min(columns, sizeof(con.buffer)));
return std::max(size_t(0), std::min(columns, sizeof(con.buffer) - branding_length));
}
void handle_resize()
@ -200,9 +193,7 @@ namespace console
if (con.cursor > 0)
{
con.cursor--;
set_cursor_pos(con.cursor);
//set_cursor_pos(branding_lenght + con.cursor);
set_cursor_pos(branding_length + con.cursor);
}
break;
@ -212,8 +203,7 @@ namespace console
if (con.cursor < std::strlen(con.buffer))
{
con.cursor++;
set_cursor_pos(con.cursor);
//set_cursor_pos(branding_lenght + con.cursor);
set_cursor_pos(branding_length + con.cursor);
}
break;
@ -246,9 +236,7 @@ namespace console
con.cursor = 0;
clear_output();
invoke_printf("]%s\r\n", con.buffer);
invoke_printf("%s%s\r\n", branding_str, con.buffer);
strncpy_s(con.buffer, "", sizeof(con.buffer));
break;
}
@ -260,9 +248,7 @@ namespace console
}
clear_output();
std::memmove(con.buffer + con.cursor - 1, con.buffer + con.cursor, strlen(con.buffer) + 1 - con.cursor);
con.buffer - 1;
con.cursor--;
update();
@ -288,8 +274,7 @@ namespace console
break;
}
std::memmove(con.buffer + con.cursor + 1,
con.buffer + con.cursor, std::strlen(con.buffer) + 1 - con.cursor);
std::memmove(con.buffer + con.cursor + 1, con.buffer + con.cursor, std::strlen(con.buffer) + 1 - con.cursor);
con.buffer[con.cursor] = c;
con.cursor++;
@ -347,7 +332,7 @@ namespace console
con.thread = utilities::thread::create_named_thread("Console", []()
{
const auto handle = GetStdHandle(STD_INPUT_HANDLE);
HANDLE handles[2] = {handle, con.kill_event};
HANDLE handles[2] = { handle, con.kill_event };
MSG msg{};
INPUT_RECORD record{};
@ -385,8 +370,7 @@ namespace console
break;
}
}
}
});
} });
}
void pre_destroy() override