summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurel <285191559+0Aurel@users.noreply.github.com>2026-05-23 17:10:58 +0200
committerGitHub <noreply@github.com>2026-05-23 17:10:58 +0200
commit51640eb100522a3986779599f057d72c8cb9e42e (patch)
tree96dd74c92bc9d024088cf506597973448140ec2e
parent0bb7400136dd84c00abdaf96c5dbdb63c02f836f (diff)
Decompile Game_16 (#167)HEADmain
* Game_16 OK * Remove unnecessary FadeControl constructor definition * Define HW_RESET_PARAMETER_BUF macro to replace hardcoded address * Refactor Game constructor to use proper C++ initialization Address Yanis' review comments: - Make Game::func_0202cf44 static with Game* parameter to allow passing as callback pointer - Replace raw mUnk_00c array with Game_0c class containing constructor - Add Game_0c constructor with inline initialization calling func_ov016_0211fab8 - Add FadeControl_Derived1 class for mFadeControl member - Use C++ initializer list in Game constructor for mModeId, mPrevModeId, mMode, mUnk_00c, and mFadeControl * Fix Game constructor and FadeControl initialization - Use PAD macro in Game_0c instead of unk8 pad[] - Pass 'this' instead of 'pad' to func_ov016_0211fab8 - Add FadeControl constructor that calls _ZN11FadeControlC2Ev - FadeControl_Derived1 now uses empty constructor (base class ctor called automatically) - Update mUnk_00c.pad to mUnk_00c.pad_0x00 (PAD macro creates named member) - Add types.h include to nds/system.h * Remove explicit call to mangled constructor symbol - Removed _ZN11FadeControlC2Ev call from FadeControl constructor - FadeControl now has an empty constructor (called automatically by derived classes) - FadeControl_Derived1 uses empty constructor which calls base class ctor * Update symbols.txt for func_0202cf44 signature change Changed mangled name from _ZN4Game13func_0202cf44Ev to _ZN4Game13func_0202cf44EPS_ to reflect the function becoming static with a Game* parameter.
-rw-r--r--config/eur/arm9/symbols.txt2
-rw-r--r--config/usa/arm9/symbols.txt2
-rw-r--r--include/Game/Game.hpp25
-rw-r--r--libs/nds/include/nds/system.h19
-rw-r--r--src/16_Startup/Game/Game_16.cpp41
-rw-r--r--src/Main/Game/Game.cpp26
6 files changed, 95 insertions, 20 deletions
diff --git a/config/eur/arm9/symbols.txt b/config/eur/arm9/symbols.txt
index f765415a..f9dc3d5f 100644
--- a/config/eur/arm9/symbols.txt
+++ b/config/eur/arm9/symbols.txt
@@ -1384,7 +1384,7 @@ _ZN4Game13func_0202c97cEv kind:function(thumb,size=0x24) addr:0x0202c97c
_ZN4Game3RunEv kind:function(arm,size=0x528) addr:0x0202c9a0
_ZN4Game13func_0202cec8Eib kind:function(thumb,size=0x6c) addr:0x0202cec8
_ZN4Game13func_0202cf34Ev kind:function(thumb,size=0x10) addr:0x0202cf34
-_ZN4Game13func_0202cf44Ev kind:function(arm,size=0x170) addr:0x0202cf44
+_ZN4Game13func_0202cf44EPS_ kind:function(arm,size=0x170) addr:0x0202cf44
_ZN4GameD1Ev kind:function(arm,size=0x18) addr:0x0202d0b4
func_0202d0cc kind:function(thumb,size=0x3a) addr:0x0202d0cc
func_0202d108 kind:function(thumb,size=0x38) addr:0x0202d108
diff --git a/config/usa/arm9/symbols.txt b/config/usa/arm9/symbols.txt
index f46857bd..992e9c13 100644
--- a/config/usa/arm9/symbols.txt
+++ b/config/usa/arm9/symbols.txt
@@ -1384,7 +1384,7 @@ _ZN4Game13func_0202c97cEv kind:function(thumb,size=0x24) addr:0x0202c964
_ZN4Game3RunEv kind:function(arm,size=0x528) addr:0x0202c988
_ZN4Game13func_0202cec8Eib kind:function(thumb,size=0x6c) addr:0x0202ceb0
_ZN4Game13func_0202cf34Ev kind:function(thumb,size=0x10) addr:0x0202cf1c
-_ZN4Game13func_0202cf44Ev kind:function(arm,size=0x170) addr:0x0202cf2c
+_ZN4Game13func_0202cf44EPS_ kind:function(arm,size=0x170) addr:0x0202cf2c
_ZN4GameD1Ev kind:function(arm,size=0x18) addr:0x0202d09c
func_0202d0cc kind:function(thumb,size=0x3a) addr:0x0202d0b4
func_0202d108 kind:function(thumb,size=0x38) addr:0x0202d0f0
diff --git a/include/Game/Game.hpp b/include/Game/Game.hpp
index 607d13a3..60625526 100644
--- a/include/Game/Game.hpp
+++ b/include/Game/Game.hpp
@@ -7,6 +7,9 @@
#include "Render/FadeControl.hpp"
#include "System/OverlayManager.hpp"
+class Game;
+typedef void (*UnkCallback)(Game *);
+
typedef GameMode *(*GameModeCreateFunc)(GameModeId modeId);
struct GameModeData {
@@ -24,13 +27,29 @@ struct GameModeData {
};
extern const GameModeData gGameModes[];
+extern "C" void func_ov016_0211fab8(void *, void (*)(), void *, unk32);
+
+class Game_0c {
+public:
+ /* 00 */ PAD(0x00, 0xC0);
+
+ Game_0c(UnkCallback callback, void *param2, u32 param3) {
+ func_ov016_0211fab8(this, (void (*)()) callback, param2, param3);
+ }
+};
+
+class FadeControl_Derived1 : public FadeControl {
+public:
+ FadeControl_Derived1() {}
+};
+
class Game {
public:
/* 000 */ GameModeId mModeId;
/* 004 */ GameModeId mPrevModeId;
/* 008 */ GameMode *mMode;
- /* 00c */ unk8 mUnk_00c[0xc0];
- /* 0cc */ FadeControl mFadeControl;
+ /* 00c */ Game_0c mUnk_00c;
+ /* 0cc */ FadeControl_Derived1 mFadeControl;
/* 0f0 */ u16 mUnk_0f0;
/* 0f2 */ vu16 mUnk_0f2;
/* 0f4 */ s32 mUnk_0f4;
@@ -55,7 +74,7 @@ public:
void Run();
bool func_0202cec8(s32 param1, bool param2);
void func_0202cf34();
- void func_0202cf44();
+ static void func_0202cf44(Game *game);
void func_ov016_0211fd68();
};
diff --git a/libs/nds/include/nds/system.h b/libs/nds/include/nds/system.h
new file mode 100644
index 00000000..9649a657
--- /dev/null
+++ b/libs/nds/include/nds/system.h
@@ -0,0 +1,19 @@
+#ifndef _NDS_SYSTEM_H
+#define _NDS_SYSTEM_H
+
+#include "types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Reset Parameter Buffer (BIOS reset information)
+// Not documented on gbatek, located at 0x027ffc20
+// Contains reset state information - value 2 indicates specific reset condition
+#define HW_RESET_PARAMETER_BUF (*(s32 *) 0x027ffc20)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/16_Startup/Game/Game_16.cpp b/src/16_Startup/Game/Game_16.cpp
index 85e094b3..4a243706 100644
--- a/src/16_Startup/Game/Game_16.cpp
+++ b/src/16_Startup/Game/Game_16.cpp
@@ -1,4 +1,41 @@
#include "Game/Game.hpp"
-Game::Game() {}
-void Game::func_ov016_0211fd68() {}
+#include <nds/system.h>
+
+#include "GameStart/GameStart.hpp"
+#include "Render/FadeController.hpp"
+#include "System/OverlayManager.hpp"
+
+extern "C" void func_0200d938(void *);
+
+ARM Game::Game() :
+ mModeId(1),
+ mPrevModeId(1),
+ mMode(NULL),
+ mUnk_00c(Game::func_0202cf44, this, 0),
+ mFadeControl() {
+ mUnk_0f0 = 0;
+ mUnk_0f2 = 1;
+ mUnk_0f4 = 0;
+ mUnk_0f8 = 0;
+ mUnk_0fc = 0;
+ mUnk_0fe = 0;
+ mUnk_100 = false;
+ mUnk_101 = 0;
+ mUnk_102 = false;
+ mUnk_103 = 0;
+}
+
+ARM void Game::func_ov016_0211fd68() {
+ mFadeControl.Register();
+ mFadeControl.mUnk_20 = false;
+ gFadeController.func_0202d77c(&mFadeControl);
+ if (HW_RESET_PARAMETER_BUF == 2) {
+ gOverlayManager.LoadGameMode(1);
+ GameStart::func_ov008_02112e88();
+ gOverlayManager.UnloadGameMode();
+ mPrevModeId = 4;
+ mModeId = 3;
+ }
+ func_0200d938(mUnk_00c.pad_0x00);
+}
diff --git a/src/Main/Game/Game.cpp b/src/Main/Game/Game.cpp
index b02fa9f9..fa3019c2 100644
--- a/src/Main/Game/Game.cpp
+++ b/src/Main/Game/Game.cpp
@@ -467,38 +467,38 @@ THUMB void Game::func_0202cf34() {
}
extern "C" void func_02017cd0();
-ARM void Game::func_0202cf44() {
+ARM void Game::func_0202cf44(Game *game) {
while (true) {
- if (mUnk_100) {
- mUnk_0f4 += 1;
+ if (game->mUnk_100) {
+ game->mUnk_0f4 += 1;
while (REG_GFX_RAM_COUNT_2 != 0) {
}
func_02005778();
func_02017cd0();
- if (mUnk_0fc != mUnk_0fe) {
- this->func_0202c678();
+ if (game->mUnk_0fc != game->mUnk_0fe) {
+ game->func_0202c678();
}
if (data_027e080c.func_0202eef8()) {
data_027e08f8.mUnk_1 = true;
} else {
- data_027e0c54.func_02036240(&mUnk_0f0);
- data_027e0c38.func_02033d84(&mUnk_0f0);
- mMode->vfunc_0c(&mUnk_0f0);
- gMessageManager.func_02036c50(&mUnk_0f0);
+ data_027e0c54.func_02036240(&game->mUnk_0f0);
+ data_027e0c38.func_02033d84(&game->mUnk_0f0);
+ game->mMode->vfunc_0c(&game->mUnk_0f0);
+ gMessageManager.func_02036c50(&game->mUnk_0f0);
if ((s32) (data_027e080c.mUnk_04 == 3 || data_027e080c.mUnk_08 == 3) == 0) {
- gFadeController.SetScreenBrightness(mUnk_103);
+ gFadeController.SetScreenBrightness(game->mUnk_103);
}
- data_027e0cbc.func_0203d67c(&mUnk_0f0);
+ data_027e0cbc.func_0203d67c(&game->mUnk_0f0);
if (gOverlayManager.mLoadedOverlays[0] != OverlayId_None) {
data_027e0db0.func_ov000_0207b43c();
}
- if (mModeId == 2) {
+ if (game->mModeId == 2) {
data_027e077c.func_ov009_0211653c();
}
data_02068894.func_0203235c();
data_02075dac.func_0203f974();
}
- mUnk_100 = false;
+ game->mUnk_100 = false;
}
data_027e08e4.func_0202f2ac();
}