From ca4ef708bf4d294fa17d446566ccf445b2e5bb24 Mon Sep 17 00:00:00 2001 From: BrentVL-1952840 <70229620+Brentdevent@users.noreply.github.com> Date: Mon, 24 Apr 2023 23:38:55 +0200 Subject: [PATCH] Make zone path for user content toggleable --- src/client/component/workshop.cpp | 65 +++++++++++++++++++++++++++++-- src/client/game/symbols.hpp | 1 + 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/client/component/workshop.cpp b/src/client/component/workshop.cpp index 29a00a6b..2d2b2acc 100644 --- a/src/client/component/workshop.cpp +++ b/src/client/component/workshop.cpp @@ -3,6 +3,7 @@ #include "workshop.hpp" #include "game/game.hpp" +#include "game/utils.hpp" #include #include @@ -12,6 +13,8 @@ namespace workshop { namespace { + const game::dvar_t* enable_zone_folder; + utils::hook::detour setup_server_map_hook; utils::hook::detour load_usermap_hook; @@ -141,6 +144,60 @@ namespace workshop return utils::hook::invoke(0x1420D6380_g, type, pub_id.data(), a3); } + + void override_path_mods_stub(utils::hook::assembler& a) + { + const auto new_path = a.newLabel(); + const auto default_path = a.newLabel(); + const auto original_func = a.newLabel(); + + a.pushad64(); + a.mov(rax, qword_ptr(reinterpret_cast(&enable_zone_folder))); + a.test(rax, rax); + a.jz(new_path); + + a.cmp(byte_ptr(rax, 0x28), 0); + a.je(new_path); + + a.bind(default_path); + a.popad64(); + a.mov(rcx, "%s/%s/%s/zone"); + a.jmp(original_func); + + a.bind(new_path); + a.popad64(); + a.mov(rcx, "%s/%s/%s"); + + a.bind(original_func); + a.jmp(game::select(0x1420D6AA0, 0x1404E2930)); + } + + void override_path_usercontent_stub(utils::hook::assembler& a) + { + const auto new_path = a.newLabel(); + const auto default_path = a.newLabel(); + const auto original_func = a.newLabel(); + + a.pushad64(); + a.mov(rax, qword_ptr(reinterpret_cast(&enable_zone_folder))); + a.test(rax, rax); + a.jz(new_path); + + a.cmp(byte_ptr(rax, 0x28), 0); + a.je(new_path); + + a.bind(default_path); + a.popad64(); + a.mov(rcx, "%s/%s/zone"); + a.jmp(original_func); + + a.bind(new_path); + a.popad64(); + a.mov(rcx, "%s/%s"); + + a.bind(original_func); + a.jmp(game::select(0x1420D6574, 0x1404E24A4)); + } } std::string get_mod_resized_name(const std::string& dir_name) @@ -259,10 +316,10 @@ namespace workshop public: void post_unpack() override { - // %s/%s/%s/zone -> %s/%s/%s - utils::hook::set(game::select(0x14303E8D8, 0x140E73BB8), 0); - // %s/%s/zone -> %s/%s - utils::hook::set(game::select(0x14303E7AD, 0x140E73AD5), 0); + enable_zone_folder = game::register_dvar_bool("enable_zone_folder", false, game::DVAR_ARCHIVE, "Load custom zones from the zone folder within the usermaps/mods folder"); + + utils::hook::jump(game::select(0x1420D6A99, 0x1404E2929), utils::hook::assemble(override_path_mods_stub)); + utils::hook::jump(game::select(0x1420D656D, 0x1404E249D), utils::hook::assemble(override_path_usercontent_stub)); load_usermap_hook.create(game::select(0x1420D5700, 0x1404E18B0), load_usermap_stub); utils::hook::call(game::select(0x1420D67F5, 0x1404E25F2), load_usermap_content_stub); diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index c938ac18..d6bb03aa 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -107,6 +107,7 @@ namespace game WEAK symbol isModLoaded{0x1420D5020}; WEAK symbol loadMod{0x1420D6930}; + WEAK symbol reloadUserContent{0x1420D66C0, 0x1404E25C0}; // Dvar WEAK symbol Dvar_IsSessionModeBaseDvar{0x1422C23A0, 0x140576890};