Fix crashes when quitting

This commit is contained in:
Federico Cecchetto 2021-12-28 04:25:14 +01:00
parent 5f17804280
commit 7b8e9c9bf1
5 changed files with 27 additions and 8 deletions

View File

@ -154,7 +154,7 @@ namespace command
{ {
utils::hook::jump(0x5A74F0_b, dvar_command_stub, true); utils::hook::jump(0x5A74F0_b, dvar_command_stub, true);
add("quit", game::Com_Quit_f); add("quit", game::Quit);
add("startmap", [](const params& params) add("startmap", [](const params& params)
{ {

View File

@ -15,6 +15,7 @@ namespace console
namespace namespace
{ {
std::thread console_thread; std::thread console_thread;
bool kill = false;
} }
class component final : public component_interface class component final : public component_interface
@ -27,14 +28,25 @@ namespace console
console_thread = utils::thread::create_named_thread("Console", []() console_thread = utils::thread::create_named_thread("Console", []()
{ {
std::string cmd; while (!kill)
while (true)
{ {
std::getline(std::cin, cmd); // to do: get input and shit without blocking the thread
game_console::add(cmd.data(), false); std::this_thread::sleep_for(1s);
} }
std::this_thread::yield();
}); });
} }
void pre_destroy() override
{
kill = true;
if (console_thread.joinable())
{
console_thread.join();
}
}
}; };
} }

View File

@ -268,7 +268,6 @@ namespace gui
void pre_destroy() override void pre_destroy() override
{ {
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown(); ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
} }

View File

@ -20,12 +20,17 @@ namespace patches
} }
} }
uint64_t off_11C52460;
void* sub_46148() void* sub_46148()
{ {
off_11C52460 = 0xAD0C58_b; static uint64_t off_11C52460 = 0xAD0C58_b;
return &off_11C52460; return &off_11C52460;
} }
DECLSPEC_NORETURN void quit_stub(const int code)
{
component_loader::pre_destroy();
exit(0);
}
} }
class component final : public component_interface class component final : public component_interface
@ -38,6 +43,8 @@ namespace patches
utils::hook::set(0x272F70_b, 0xC301B0); utils::hook::set(0x272F70_b, 0xC301B0);
utils::hook::jump(0x46148_b, sub_46148, true); utils::hook::jump(0x46148_b, sub_46148, true);
utils::hook::jump(0x64EF10_b, quit_stub, true);
// Unlock fps in main menu // Unlock fps in main menu
utils::hook::set<BYTE>(0x3D8E1B_b, 0xEB); utils::hook::set<BYTE>(0x3D8E1B_b, 0xEB);

View File

@ -26,6 +26,7 @@ namespace game
WEAK symbol<void(errorParm code, const char* message, ...)> Com_Error{0x5A2D80}; WEAK symbol<void(errorParm code, const char* message, ...)> Com_Error{0x5A2D80};
WEAK symbol<void()> Com_Quit_f{0x5A50D0}; WEAK symbol<void()> Com_Quit_f{0x5A50D0};
WEAK symbol<void()> Quit{0x5A52A0};
WEAK symbol<void(XAssetType type, void(__cdecl* func)(game::XAssetHeader, void*), const void* inData, bool includeOverride)> WEAK symbol<void(XAssetType type, void(__cdecl* func)(game::XAssetHeader, void*), const void* inData, bool includeOverride)>
DB_EnumXAssets_Internal{0x4129F0}; DB_EnumXAssets_Internal{0x4129F0};