diff --git a/.gitignore b/.gitignore index e29bd0f..eef9ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,9 +9,7 @@ *.map newcodeinfo.h build/ -hooks/ bak/ -/source/Version.cmake # IDA *.id* diff --git a/v100/hooks.hks b/hooks/all.hks similarity index 100% rename from v100/hooks.hks rename to hooks/all.hks diff --git a/make_release.sh b/make_release.sh index 1279b13..8649e17 100755 --- a/make_release.sh +++ b/make_release.sh @@ -22,14 +22,8 @@ build () { print_status "building for $TARGET_VERSION" - # Copy the version-specific hooks - rm -r $RST_ROOT/hooks/ || true - mkdir $RST_ROOT/hooks - cp $RST_ROOT/$TARGET_VERSION/hooks.hks $RST_ROOT/hooks/ - # Copy the version-specific build files cp $RST_ROOT/$TARGET_VERSION/*.bin $RST_ROOT/ - cp $RST_ROOT/$TARGET_VERSION/Version.cmake $RST_ROOT/source/ # Touch main.cpp to get an up-to-date build time touch $RST_ROOT/source/rst/main.cpp @@ -55,7 +49,7 @@ build () { # Clean up rm -r $RST_ROOT/loader/*.bin $RST_ROOT/loader/*.sym || true rm -r $RST_ROOT/*.bin $RST_ROOT/*.sym || true - rm -r $RST_ROOT/bak $RST_ROOT/hooks || true + rm -r $RST_ROOT/bak || true } build v100 diff --git a/readme.md b/readme.md index 517e6b9..a644c79 100644 --- a/readme.md +++ b/readme.md @@ -45,16 +45,14 @@ I personally consider the project to be pretty much complete. The game is **play * `common/`: small utilities. * `game/`: implementation for the known parts of *Majora's Mask 3D*. Contains headers and some reimplementation of game functions. * `rst/`: *Project Restoration* code. -* `v100/`, `v101/` and `v110/`: Version-specific data. - * `hooks.hks`: configuration for patches and hooks (for Magikoopa). - * `Version.cmake`: defines for *Project Restoration* code. +* `hooks/`: configuration for patches and hooks (for Magikoopa). * `loader/`: Code loader (from [Magikoopa](https://github.com/RicBent/Magikoopa)). Sometimes you will find *Project Restoration* extensions and new code under `source/game`. Those extensions will always be clearly labelled as such. ### Build instructions -* Put the original code.bin and exheader.bin in v100, v101 and v110. +* Put the original code.bin and exheader.bin files in the v100, v101 and v110 folders respectively. You must dump those binaries from the ExeFS yourself; those are **not** provided in this repository for copyright reasons. * Run make_release.sh. You need git and Magikoopa in your PATH. **Currently, a [fork](https://github.com/leoetlino/Magikoopa) is required**. * Generated code patches (code.bps) and patched exheaders can be found in `release/`. diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 7f798d2..48d2e32 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -97,5 +97,3 @@ add_custom_target(newcode_product ALL COMMAND sh -c "${CMAKE_OBJDUMP} -t newcode.elf>newcode.sym" BYPRODUCTS newcode.bin newcode.sym ) - -include(Version.cmake) diff --git a/source/common/utils.h b/source/common/utils.h index 0ae549b..128d160 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -9,23 +9,14 @@ namespace rst::util { -#if defined(RST_VER) -constexpr u32 Version = RST_VER; -#else -constexpr u32 Version = 0; -#endif -static_assert(Version == 0 || Version == 1, "Unknown version"); - -template * = nullptr> -constexpr uintptr_t GetAddr(Ts... addresses) { - return std::get(std::forward_as_tuple(addresses...)); +constexpr uintptr_t GetAddr(uintptr_t addr) { + return addr; } /// Returns a version-specific address from a list of addresses and casts it to Type*. -template -constexpr auto GetPointer(Ts... addresses) { - static_assert(Version < sizeof...(Ts), "Missing address!"); - return reinterpret_cast(GetAddr(addresses...)); +template +inline auto GetPointer(uintptr_t addr) { + return reinterpret_cast(GetAddr(addr)); } template @@ -36,11 +27,10 @@ static void InitIfNeeded(T* instance, bool* init_flag, void (*init_fn)(T*)) { init_fn(instance); } -template -static T& GetInstance(std::tuple ptrs, std::tuple flags, std::tuple fns) { - T* instance = std::apply([](auto&&... a) { return GetPointer(a...); }, ptrs); - InitIfNeeded(instance, std::apply([](auto&&... a) { return GetPointer(a...); }, flags), - std::apply([](auto&&... a) { return GetPointer(a...); }, fns)); +template +static T& GetInstance(uintptr_t ptr, uintptr_t init_flag, uintptr_t init_fn) { + T* instance = GetPointer(ptr); + InitIfNeeded(instance, GetPointer(init_flag), GetPointer(init_fn)); return *instance; } diff --git a/source/game/common_data.cpp b/source/game/common_data.cpp index d819f59..c5253f3 100644 --- a/source/game/common_data.cpp +++ b/source/game/common_data.cpp @@ -6,7 +6,7 @@ namespace game { CommonData& GetCommonData() { // Right before the static context in .bss. - return *rst::util::GetPointer(0x7751D8, 0x7761D8); + return *rst::util::GetPointer(0x7751D8); } } // namespace game diff --git a/source/game/player.cpp b/source/game/player.cpp index 8a97218..f39d989 100644 --- a/source/game/player.cpp +++ b/source/game/player.cpp @@ -15,7 +15,7 @@ static void PlayerChangeStateToStill(Player* player, GlobalContext* gctx) { } // namespace FormParam& GetFormParam(FormParamIndex idx) { - return rst::util::GetPointer(0x7AE9E8, 0x7AF9E8)[u8(idx) % 8]; + return rst::util::GetPointer(0x7AE9E8)[u8(idx) % 8]; } Player::ArrowInfo Player::GetArrowInfo(GlobalContext* gctx) const { diff --git a/source/game/sound.cpp b/source/game/sound.cpp index 210a7a7..3e9ac92 100644 --- a/source/game/sound.cpp +++ b/source/game/sound.cpp @@ -10,8 +10,7 @@ namespace game::sound { class StreamMgr; static StreamMgr& GetStreamMgr() { - return rst::util::GetInstance(std::tuple{0x7CB49C}, std::tuple{0x6B0A3C}, - std::tuple{0x1E11F8}); + return rst::util::GetInstance(0x7CB49C, 0x6B0A3C, 0x1E11F8); } bool PlayEffect(EffectId id) { diff --git a/source/game/static_context.cpp b/source/game/static_context.cpp index 84d4f7d..f06d2e5 100644 --- a/source/game/static_context.cpp +++ b/source/game/static_context.cpp @@ -5,7 +5,7 @@ namespace game { StaticContext& GetStaticContext() { - return *rst::util::GetPointer(0x7892D0, 0x78A2D0); + return *rst::util::GetPointer(0x7892D0); } } // namespace game diff --git a/source/game/ui.cpp b/source/game/ui.cpp index 75b3648..163420e 100644 --- a/source/game/ui.cpp +++ b/source/game/ui.cpp @@ -173,8 +173,7 @@ Anim* LayoutClass::GetAnim(std::string_view name) const { } LayoutMgr& LayoutMgr::Instance() { - return rst::util::GetInstance(std::tuple{0x7CDC9C}, std::tuple{0x6B0AFC}, - std::tuple{0x16963C}); + return rst::util::GetInstance(0x7CDC9C, 0x6B0AFC, 0x16963C); } void LayoutMgr::FreeLayout(Layout* layout) { diff --git a/v100/Version.cmake b/v100/Version.cmake deleted file mode 100644 index ac32f3a..0000000 --- a/v100/Version.cmake +++ /dev/null @@ -1 +0,0 @@ -target_compile_definitions(newcode PRIVATE RST_VER=0) diff --git a/v110/Version.cmake b/v110/Version.cmake deleted file mode 100644 index 893c433..0000000 --- a/v110/Version.cmake +++ /dev/null @@ -1 +0,0 @@ -target_compile_definitions(newcode PRIVATE RST_VER=1) diff --git a/v110/hooks.hks b/v110/hooks.hks deleted file mode 100644 index 2714237..0000000 --- a/v110/hooks.hks +++ /dev/null @@ -1,87 +0,0 @@ -zora_swim_1a: - # Remove fast swim magic check - type: patch - data: E3A00001 - addr: 0x00220F50 - reverse: true -zora_swim_1b: - # Remove fast swim magic check - type: patch - data: E3A00001 - addr: 0x002210CC - reverse: true -zora_swim_1c: - # Remove fast swim magic check - type: patch - data: E3A00001 - addr: 0x001FFDA8 - reverse: true -zora_swim_2: - # Change fast swim start trigger (A+R -> A) - type: branch - link: true - func: rst_trampoline_rst_link_ShouldUseZoraFastSwim - addr: 0x220EEC -zora_swim_2: - type: patch - data: 00 F0 20 E3 01 00 50 E3 - addr: 0x220F1C -zora_swim_3a: - # Change fast swim continue trigger (A+R -> A) - type: branch - link: true - func: rst_trampoline_rst_link_ShouldUseZoraFastSwim - addr: 0x1FFD64 -zora_swim_3a: - type: patch - data: 00 F0 20 E3 00 F0 20 E3 01 00 50 E3 - addr: 0x1FFD68 -zora_swim_3b: - # Change fast swim continue trigger (A+R -> A) - type: branch - link: true - func: rst_trampoline_rst_link_ShouldUseZoraFastSwim - addr: 0x1FFA74 -zora_swim_3b: - type: patch - data: 00 F0 20 E3 00 F0 20 E3 01 00 50 E3 - addr: 0x1FFA78 -zora_swim_4: - type: patch - data: EA000009 - addr: 0x00220EF0 - reverse: true - -fix_transformation_mask_equip_checks_1: - # prevent forced transform when mask is not equipped - type: patch - data: E12FFF1E - addr: 0x001E76A0 - reverse: true -fix_transformation_mask_equip_checks_2a: - # remove other checks (fix first-person mode, Goron rolling and potentially more) - type: patch - data: EA00003B - addr: 0x001EDFA4 - reverse: true -fix_transformation_mask_equip_checks_2b: - type: patch - data: EA000052 - reverse: true - addr: 0x001F78BC - -decouple_trigger_btns: - type: patch - data: 12 00 00 EA # skips over the ZL/ZR checks - addr: 0x1167C8 - -ice_arrows: - type: patch - data: 00 F0 20 E3 # nop - addr: 0x318898 - -main_hook: - type: softbranch - opcode: post - func: rst_Calc - addr: 0x106798