Threaded console
This commit is contained in:
parent
07934e9216
commit
d45554eeaa
@ -19,6 +19,8 @@ namespace Components
|
||||
|
||||
bool Console::HasConsole = false;
|
||||
|
||||
std::thread Console::ConsoleThread;
|
||||
|
||||
char** Console::GetAutoCompleteFileList(const char *path, const char *extension, Game::FsListBehavior_e behavior, int *numfiles, int allocTrackType)
|
||||
{
|
||||
if (path == reinterpret_cast<char*>(0xBAADF00D) || path == reinterpret_cast<char*>(0xCDCDCDCD) || IsBadReadPtr(path, 1)) return nullptr;
|
||||
@ -368,6 +370,31 @@ namespace Components
|
||||
Console::RefreshOutput();
|
||||
}
|
||||
|
||||
void Console::ConsoleRunner()
|
||||
{
|
||||
Game::Sys_ShowConsole();
|
||||
|
||||
MSG message;
|
||||
while (IsWindow(*reinterpret_cast<HWND*>(0x64A3288)) != FALSE && GetMessageA(&message, 0, 0, 0))
|
||||
{
|
||||
TranslateMessage(&message);
|
||||
DispatchMessageA(&message);
|
||||
}
|
||||
|
||||
// if (Game::Com_Milliseconds() - Console::LastRefresh > 50)
|
||||
// {
|
||||
// // Force process termination
|
||||
// // if the main thread is not responding
|
||||
// OutputDebugStringA("Process termination forced, as the main thread is not responding!");
|
||||
// ExitProcess(static_cast<uint32_t>(-1));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Send quit command to safely terminate the application
|
||||
Command::Execute("wait 200;quit\n", false);
|
||||
// }
|
||||
}
|
||||
|
||||
Console::Console()
|
||||
{
|
||||
// Console '%s: %s> ' string
|
||||
@ -401,6 +428,14 @@ namespace Components
|
||||
{
|
||||
FreeConsole();
|
||||
Utils::Hook::Nop(0x60BB58, 11);
|
||||
Utils::Hook::Nop(0x60BB68, 5);
|
||||
|
||||
QuickPatch::OnFrame([] ()
|
||||
{
|
||||
Console::LastRefresh = Game::Com_Milliseconds();
|
||||
});
|
||||
|
||||
Console::ConsoleThread = std::thread(Console::ConsoleRunner);
|
||||
}
|
||||
else if (Dedicated::IsDedicated()/* || ZoneBuilder::IsEnabled()*/)
|
||||
{
|
||||
@ -417,4 +452,12 @@ namespace Components
|
||||
FreeConsole();
|
||||
}
|
||||
}
|
||||
|
||||
Console::~Console()
|
||||
{
|
||||
if (Console::ConsoleThread.joinable())
|
||||
{
|
||||
Console::ConsoleThread.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ namespace Components
|
||||
{
|
||||
public:
|
||||
Console();
|
||||
~Console();
|
||||
const char* GetName() { return "Console"; };
|
||||
|
||||
private:
|
||||
@ -32,6 +33,8 @@ namespace Components
|
||||
|
||||
static bool HasConsole;
|
||||
|
||||
static std::thread ConsoleThread;
|
||||
|
||||
static void ShowPrompt();
|
||||
static void RefreshStatus();
|
||||
static void RefreshOutput();
|
||||
@ -42,5 +45,7 @@ namespace Components
|
||||
static void Error(const char* format, ...);
|
||||
static void Create();
|
||||
static void Destroy();
|
||||
|
||||
static void ConsoleRunner();
|
||||
};
|
||||
}
|
||||
|
@ -493,6 +493,10 @@ namespace Components
|
||||
// Don't create default assets
|
||||
Utils::Hook::Set<BYTE>(0x407BAA, 0xEB);
|
||||
|
||||
// Don't display errors when assets are missing (we might manually build those)
|
||||
Utils::Hook::Nop(0x5BB3F2, 5);
|
||||
Utils::Hook::Nop(0x5BB422, 5);
|
||||
Utils::Hook::Nop(0x5BB43A, 5);
|
||||
// Increase asset pools
|
||||
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_MAP_ENTS, 10);
|
||||
|
||||
|
@ -136,6 +136,7 @@ namespace Game
|
||||
|
||||
Sys_IsMainThread_t Sys_IsMainThread = (Sys_IsMainThread_t)0x4C37D0;
|
||||
Sys_SendPacket_t Sys_SendPacket = (Sys_SendPacket_t)0x60FDC0;
|
||||
Sys_ShowConsole_t Sys_ShowConsole = (Sys_ShowConsole_t)0x4305E0;
|
||||
|
||||
UI_AddMenuList_t UI_AddMenuList = (UI_AddMenuList_t)0x4533C0;
|
||||
UI_LoadMenus_t UI_LoadMenus = (UI_LoadMenus_t)0x641460;
|
||||
|
@ -317,6 +317,9 @@ namespace Game
|
||||
typedef bool(__cdecl * Sys_SendPacket_t)(netsrc_t sock, size_t len, const char *format, netadr_t adr);
|
||||
extern Sys_SendPacket_t Sys_SendPacket;
|
||||
|
||||
typedef void(__cdecl * Sys_ShowConsole_t)();
|
||||
extern Sys_ShowConsole_t Sys_ShowConsole;
|
||||
|
||||
typedef void(__cdecl * UI_AddMenuList_t)(UiContext *dc, MenuList *menuList, int close);
|
||||
extern UI_AddMenuList_t UI_AddMenuList;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user