Skip to content

Commit

Permalink
MHWilds: Fix UI code (VR, on_*_gui_draw_element, hide UI)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 2, 2024
1 parent 1f522aa commit 21c3c02
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/mods/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ std::optional<std::string> Hooks::hook_update_camera_controller2() {
}

std::optional<std::string> Hooks::hook_gui_draw() {
// TODO: FIX THIS!!!
#if TDB_VER < 74
spdlog::info("[Hooks] Attempting to hook GUI functions...");

auto game = g_framework->get_module().as<HMODULE>();
Expand All @@ -296,6 +294,7 @@ std::optional<std::string> Hooks::hook_gui_draw() {
++*(_DWORD *)(gui_manager + 232);
*(_QWORD *)&v35 = draw_task_function; <-- "gui_draw_call" is found within this function.
*/
size_t offset = 12;
spdlog::info("[Hooks] Scanning for first GUI draw call...");
auto gui_draw_call = utility::scan(game, "49 8B 0C CE 48 83 79 10 00 74 ? E8 ? ? ? ?");

Expand All @@ -305,21 +304,28 @@ std::optional<std::string> Hooks::hook_gui_draw() {
gui_draw_call = utility::scan(game, "49 8B 0C CE 48 83 79 20 00 74 ? E8 ? ? ? ?");

if (!gui_draw_call) {
return "Unable to find gui_draw_call pattern.";
// MHWILDS
gui_draw_call = utility::scan(game, "48 8B 0C C3 48 83 79 ? 00 74 ? 48 89 ? E8 ? ? ? ?");
offset = 15;

if (!gui_draw_call) {
//return "Unable to find gui_draw_call pattern.";
spdlog::error("[Hooks] Unable to find gui_draw_call pattern.");
return std::nullopt; // Don't bother erroring out the entire mod just because of this
}
}
}

spdlog::info("[Hooks] Found gui_draw_call at {:x}", *gui_draw_call);

auto gui_draw = utility::calculate_absolute(*gui_draw_call + 12);
auto gui_draw = utility::calculate_absolute(*gui_draw_call + offset);
spdlog::info("[Hooks] gui_draw: {:x}", gui_draw);

m_gui_draw_hook = std::make_unique<FunctionHook>(gui_draw, &gui_draw_hook);

if (!m_gui_draw_hook->create()) {
return "Failed to hook GUI::draw";
}
#endif

return std::nullopt;
}
Expand Down

0 comments on commit 21c3c02

Please sign in to comment.