From f27b60d4fef5d3d081a2fe231169219416c877c8 Mon Sep 17 00:00:00 2001 From: Yanis002 <35189056+Yanis002@users.noreply.github.com> Date: Sat, 8 Feb 2025 22:25:31 +0100 Subject: [PATCH 1/6] match most of OverlayManager.cpp --- config/eur/arm9/delinks.txt | 3 + include/System/OverlayManager.hpp | 1 + libs/nds/include/nds/Overlay.h | 8 +++ src/Main/System/OverlayManager.cpp | 90 ++++++++++++++++++++++++++++-- 4 files changed, 97 insertions(+), 5 deletions(-) diff --git a/config/eur/arm9/delinks.txt b/config/eur/arm9/delinks.txt index 97a31c17..7e3f8e58 100644 --- a/config/eur/arm9/delinks.txt +++ b/config/eur/arm9/delinks.txt @@ -10,6 +10,9 @@ src/Main/Actor/ActorType.cpp: .text start:0x0203e784 end:0x0203e8a0 .bss start:0x02069180 end:0x02069188 +src/Main/System/OverlayManager.cpp: + .text start:0x0202ff44 end:0x0203003c + libs/cpp/src/__register_global_object.cpp: complete .text start:0x0204f8d4 end:0x0204f8f4 diff --git a/include/System/OverlayManager.hpp b/include/System/OverlayManager.hpp index 636208fc..4c83bbe4 100644 --- a/include/System/OverlayManager.hpp +++ b/include/System/OverlayManager.hpp @@ -6,6 +6,7 @@ typedef u32 OverlayId; enum OverlayId_ { + OverlayId_None = -1, OverlayId_Core, OverlayId_01, OverlayId_02, diff --git a/libs/nds/include/nds/Overlay.h b/libs/nds/include/nds/Overlay.h index 7a8c6fa9..5339a9d7 100644 --- a/libs/nds/include/nds/Overlay.h +++ b/libs/nds/include/nds/Overlay.h @@ -1,6 +1,10 @@ #ifndef _NDS_OVERLAY_H #define _NDS_OVERLAY_H +#ifdef __cplusplus +extern "C" { +#endif + typedef struct Overlay { /* 00 */ unk32 mId; /* 04 */ void *mBaseAddress; @@ -27,4 +31,8 @@ bool Overlay_Destroy(Overlay *overlay); bool Overlay_Load(Overlay *overlay, unk32 param2); bool Overlay_Unload(Overlay *overlay, unk32 param2); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/Main/System/OverlayManager.cpp b/src/Main/System/OverlayManager.cpp index 9c50ebb6..8446eaa8 100644 --- a/src/Main/System/OverlayManager.cpp +++ b/src/Main/System/OverlayManager.cpp @@ -1,7 +1,87 @@ +#include "global.h" #include "System/OverlayManager.hpp" +#include "nds/Overlay.h" -void OverlayManager::Load(OverlayIndex index, OverlayId id) {} -void OverlayManager::LoadIfNotLoaded(OverlayIndex index, OverlayId id) {} -void OverlayManager::Unload(OverlayIndex index) {} -void OverlayManager::LoadOverlaySetup(s32 index) {} -void OverlayManager::UnloadOverlaySetup() {} +struct UnkStruct_020ee698 { + /* 00 */ unk8 mUnk_00[0x2C]; + /* 2c */ unk32 mUnk_2c; + /* 30 */ +}; +extern UnkStruct_020ee698 data_ov000_020ee698; + +struct OverlaySetup { + /* 00 */ unk8 mUnk_00; + /* 01 */ unk8 mUnk_01; + /* 02 */ unk8 mUnk_02; + /* 03 */ unk8 mUnk_03; + /* 04 */ OverlayId slot1Overlay; + /* 08 */ OverlayId slot2Overlay; + /* 0c */ OverlayId slot3Overlay; + /* 10 */ OverlayId slot12Overlay; + /* 14 */ void* mUnk_14; + /* 18 */ void* mUnk_18; + /* 1c */ +}; +extern OverlaySetup gOverlaySetups[]; + +extern u32 *data_027e0ce0[]; +extern "C" void func_ov007_02102850(u32**); +extern "C" void func_ov007_021028a0(u32**); + +THUMB void OverlayManager::Load(OverlayIndex index, OverlayId id) { + if (id != OverlayId_None) { + Overlay_Load(NULL, id); + } + + this->mLoadedOverlays[index] = id; +} + +// non-matching (regalloc) +THUMB void OverlayManager::LoadIfNotLoaded(OverlayIndex index, OverlayId id) { + if (this->mLoadedOverlays[index] != id) { + this->Unload(index); + this->Load(index, id); + } +} + +THUMB void OverlayManager::Unload(OverlayIndex index) { + if (this->mLoadedOverlays[index] != OverlayId_None) { + Overlay_Unload(NULL, this->mLoadedOverlays[index]); + this->mLoadedOverlays[index] = OverlayId_None; + } +} + +//! TODO: solve the .word issue with the overlay IDs +//! both functions should match otherwise +THUMB void OverlayManager::LoadOverlaySetup(s32 index) { + OverlayId overlayId; + OverlaySetup* pSetup; + + pSetup = &gOverlaySetups[index]; + + this->LoadIfNotLoaded(OverlayIndex_1, pSetup->slot1Overlay); + this->LoadIfNotLoaded(OverlayIndex_2, pSetup->slot2Overlay); + + if (index == 5) { + func_ov007_02102850(data_027e0ce0); + } else { + overlayId = pSetup->slot12Overlay; + + if (index == 6 && data_ov000_020ee698.mUnk_2c == 2) { + overlayId = OverlayId_61; + } + + this->Load(OverlayIndex_3, pSetup->slot3Overlay); + this->Load(OverlayIndex_12, overlayId); + } +} + +THUMB void OverlayManager::UnloadOverlaySetup() { + this->Unload(OverlayIndex_12); + this->Unload(OverlayIndex_3); + + if (this->mLoadedOverlays[2] == OverlayId_07) { + func_ov007_021028a0(data_027e0ce0); + this->Unload(OverlayIndex_2); + } +} From 25fef6bba19b0c3b016dc09c3aa9490d6ee2cddd Mon Sep 17 00:00:00 2001 From: Yanis002 <35189056+Yanis002@users.noreply.github.com> Date: Sat, 8 Feb 2025 22:31:43 +0100 Subject: [PATCH 2/6] format? --- src/Main/System/OverlayManager.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Main/System/OverlayManager.cpp b/src/Main/System/OverlayManager.cpp index 8446eaa8..8ba3f925 100644 --- a/src/Main/System/OverlayManager.cpp +++ b/src/Main/System/OverlayManager.cpp @@ -1,5 +1,5 @@ -#include "global.h" #include "System/OverlayManager.hpp" +#include "global.h" #include "nds/Overlay.h" struct UnkStruct_020ee698 { @@ -18,15 +18,15 @@ struct OverlaySetup { /* 08 */ OverlayId slot2Overlay; /* 0c */ OverlayId slot3Overlay; /* 10 */ OverlayId slot12Overlay; - /* 14 */ void* mUnk_14; - /* 18 */ void* mUnk_18; + /* 14 */ void *mUnk_14; + /* 18 */ void *mUnk_18; /* 1c */ }; extern OverlaySetup gOverlaySetups[]; extern u32 *data_027e0ce0[]; -extern "C" void func_ov007_02102850(u32**); -extern "C" void func_ov007_021028a0(u32**); +extern "C" void func_ov007_02102850(u32 **); +extern "C" void func_ov007_021028a0(u32 **); THUMB void OverlayManager::Load(OverlayIndex index, OverlayId id) { if (id != OverlayId_None) { @@ -55,7 +55,7 @@ THUMB void OverlayManager::Unload(OverlayIndex index) { //! both functions should match otherwise THUMB void OverlayManager::LoadOverlaySetup(s32 index) { OverlayId overlayId; - OverlaySetup* pSetup; + OverlaySetup *pSetup; pSetup = &gOverlaySetups[index]; @@ -66,11 +66,11 @@ THUMB void OverlayManager::LoadOverlaySetup(s32 index) { func_ov007_02102850(data_027e0ce0); } else { overlayId = pSetup->slot12Overlay; - + if (index == 6 && data_ov000_020ee698.mUnk_2c == 2) { overlayId = OverlayId_61; } - + this->Load(OverlayIndex_3, pSetup->slot3Overlay); this->Load(OverlayIndex_12, overlayId); } From 222f3f7daaa5787ff967a1db78876cdfc3f8aa10 Mon Sep 17 00:00:00 2001 From: Yanis002 <35189056+Yanis002@users.noreply.github.com> Date: Sat, 8 Feb 2025 23:07:14 +0100 Subject: [PATCH 3/6] match OverlayManager::LoadIfNotLoaded (thanks to Maide) --- src/Main/System/OverlayManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Main/System/OverlayManager.cpp b/src/Main/System/OverlayManager.cpp index 8ba3f925..8fff1fc6 100644 --- a/src/Main/System/OverlayManager.cpp +++ b/src/Main/System/OverlayManager.cpp @@ -36,9 +36,10 @@ THUMB void OverlayManager::Load(OverlayIndex index, OverlayId id) { this->mLoadedOverlays[index] = id; } -// non-matching (regalloc) THUMB void OverlayManager::LoadIfNotLoaded(OverlayIndex index, OverlayId id) { - if (this->mLoadedOverlays[index] != id) { + OverlayId loadedId = this->mLoadedOverlays[index]; + + if (loadedId != id) { this->Unload(index); this->Load(index, id); } From 910df5dd0ca1624fa8d481f776724e818035ffd7 Mon Sep 17 00:00:00 2001 From: Aetias Date: Sun, 16 Feb 2025 11:41:35 +0100 Subject: [PATCH 4/6] Delink OverlayManager for US version --- config/usa/arm9/delinks.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/usa/arm9/delinks.txt b/config/usa/arm9/delinks.txt index 5c30acbc..14d31538 100644 --- a/config/usa/arm9/delinks.txt +++ b/config/usa/arm9/delinks.txt @@ -10,6 +10,9 @@ src/Main/Actor/ActorType.cpp: .text start:0x0203e740 end:0x0203e85c .bss start:0x02069120 end:0x02069128 +src/Main/System/OverlayManager.cpp: + .text start:0x0202ff40 end:0x02030038 + libs/cpp/src/__register_global_object.cpp: complete .text start:0x0204f890 end:0x0204f8b0 From 9d82f34f530a0795089b704662f2b11a4361a045 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Thu, 20 Feb 2025 16:01:07 -0500 Subject: [PATCH 5/6] Fix shebangs and permissions --- tools/configure.py | 2 +- tools/m2ctx.py | 2 +- tools/ninja_syntax.py | 2 -- tools/setup.py | 2 ++ tools/sha1.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 tools/configure.py mode change 100644 => 100755 tools/setup.py mode change 100644 => 100755 tools/sha1.py diff --git a/tools/configure.py b/tools/configure.py old mode 100644 new mode 100755 index f3c34311..45d9824a --- a/tools/configure.py +++ b/tools/configure.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 import os from pathlib import Path diff --git a/tools/m2ctx.py b/tools/m2ctx.py index f2275e33..7c20c34a 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import pyperclip diff --git a/tools/ninja_syntax.py b/tools/ninja_syntax.py index 2aa8456e..e0716e8a 100644 --- a/tools/ninja_syntax.py +++ b/tools/ninja_syntax.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright 2011 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tools/setup.py b/tools/setup.py old mode 100644 new mode 100755 index f81ca25d..6e83c64a --- a/tools/setup.py +++ b/tools/setup.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import requests import zipfile import io diff --git a/tools/sha1.py b/tools/sha1.py old mode 100644 new mode 100755 index 8cd6edd8..fd1cbda8 --- a/tools/sha1.py +++ b/tools/sha1.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from pathlib import Path import argparse From 80be00c0562f89c20f1cd82d4210924e40e144a3 Mon Sep 17 00:00:00 2001 From: Ozero4 <114027116+Ozero4@users.noreply.github.com> Date: Sat, 22 Feb 2025 00:48:25 +0100 Subject: [PATCH 6/6] Fixed "issue tracker" link The link redirected to the AetiasHax's fork --- docs/decompiling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/decompiling.md b/docs/decompiling.md index 3ec8f682..e9f9c3b1 100644 --- a/docs/decompiling.md +++ b/docs/decompiling.md @@ -8,7 +8,7 @@ stuck or need assistance. - [The Ghidra project](#the-ghidra-project) ## Pick a source file -See the `decomp` tag in the [issue tracker](https://github.com/AetiasHax/ph/issues?q=is%3Aopen+is%3Aissue+label%3Adecomp) for +See the `decomp` tag in the [issue tracker](https://github.com/zeldaret/ph/issues?q=is%3Aopen+is%3Aissue+label%3Adecomp) for a list of delinked source files that are ready to be decompiled. This list grows as more source files are delinked from the rest of the base ROM.