Merge pull request #29 from mjkzy/stuff

scheduler stuff
This commit is contained in:
Maurice Heumann 2022-09-18 08:22:27 +02:00 committed by GitHub
commit aebfd94858
5 changed files with 30 additions and 20 deletions

View File

@ -1,22 +1,21 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "version.hpp"
#include "scheduler.hpp"
#include <utils/hook.hpp>
#include <version.hpp>
namespace branding
{
namespace
{
utils::hook::detour r_end_frame_hook;
void draw_branding()
{
constexpr auto x = 4;
constexpr auto y = 0;
constexpr auto scale = 0.5f;
//float color[4] = {0.666f, 0.666f, 0.666f, 0.666f};
float color[4] = {236 / 255.0f, 113 / 255.0f, 10 / 255.0f, 1.0f};
auto* font = reinterpret_cast<uint32_t*(*)()>(0x141CAC8E0_g)();
@ -26,12 +25,6 @@ namespace branding
y + static_cast<float>(font[2]) * scale,
scale, scale, 0.0f, color, game::ITEM_TEXTSTYLE_SHADOWEDMORE);
}
void r_end_frame_stub()
{
draw_branding();
r_end_frame_hook.invoke<void>();
}
}
class component final : public component_interface
@ -39,7 +32,7 @@ namespace branding
public:
void post_unpack() override
{
r_end_frame_hook.create(0x142273560_g, r_end_frame_stub);
scheduler::loop(draw_branding, scheduler::renderer);
}
};
}

View File

@ -68,14 +68,15 @@ namespace exception
void display_error_dialog()
{
const std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p.\n"
"A minidump has been written.\n\n",
exception_data.code, exception_data.address);
const std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p (0x%p).\n"
"A minidump has been written.\n",
exception_data.code, exception_data.address,
reverse_g(reinterpret_cast<uint64_t>(exception_data.address)));
utils::thread::suspend_other_threads();
show_mouse_cursor();
MessageBoxA(nullptr, error_str.data(), "S1x ERROR", MB_ICONERROR);
MessageBoxA(nullptr, error_str.data(), "BOIII ERROR", MB_ICONERROR);
TerminateProcess(GetCurrentProcess(), exception_data.code);
}
@ -86,11 +87,12 @@ namespace exception
recovery_data.last_recovery = std::chrono::high_resolution_clock::now();
++recovery_data.recovery_counts;
game::Com_Error(game::ERR_DROP, "Fatal error (0x%08X) at 0x%p.\nA minidump has been written.\n\n"
game::Com_Error(game::ERR_DROP, "Fatal error (0x%08X) at 0x%p (0x%p).\nA minidump has been written.\n\n"
"BOIII has tried to recover your game, but it might not run stable anymore.\n\n"
"Make sure to update your graphics card drivers and install operating system updates!\n"
"Closing or restarting Steam might also help.",
exception_data.code, exception_data.address);
exception_data.code, exception_data.address,
reverse_g(reinterpret_cast<uint64_t>(exception_data.address)));
}
else
{
@ -137,6 +139,7 @@ namespace exception
line("Timestamp: "s + get_timestamp());
line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode));
line(utils::string::va("Address: 0x%llX", exceptioninfo->ExceptionRecord->ExceptionAddress));
line(utils::string::va("Base: 0x%llX", get_base()));
#pragma warning(push)
#pragma warning(disable: 4996)

View File

@ -85,6 +85,7 @@ namespace scheduler
volatile bool kill = false;
std::thread thread;
task_pipeline pipelines[pipeline::count];
utils::hook::detour r_end_frame_hook;
utils::hook::detour g_run_frame_hook;
utils::hook::detour main_frame_hook;
@ -162,6 +163,13 @@ namespace scheduler
});
}
void post_unpack() override
{
r_end_frame_hook.create(0x142273560_g, r_end_frame_stub); // some func called before R_EndFrame, maybe SND_EndFrame?
g_run_frame_hook.create(0x14065C360_g, server_frame_stub); // GlassSv_Update
main_frame_hook.create(0x1420F9860_g, main_frame_stub); // Com_Frame_Try_Block_Function
}
void pre_destroy() override
{
kill = true;

View File

@ -136,17 +136,22 @@ std::vector<std::unique_ptr<component_interface>>& component_loader::get_compone
return *components;
}
size_t operator"" _g(const size_t val)
size_t get_base()
{
static auto base = size_t(utils::nt::library{}.get_ptr());
assert(base && "Failed to resolve base");
return base;
}
size_t operator"" _g(const size_t val)
{
static auto base = get_base();
return base + (val - 0x140000000);
}
size_t reverse_g(const size_t val)
{
static auto base = size_t(utils::nt::library{}.get_ptr());
assert(base && "Failed to resolve base");
static auto base = get_base();
return (val - base) + 0x140000000;
}

View File

@ -57,6 +57,7 @@ namespace \
static component_loader::installer<name> __component; \
}
size_t get_base();
size_t operator"" _g(size_t val);
size_t reverse_g(size_t val);
size_t reverse_g(const void* val);