Decomp GetWindow; retype overlay_31's window callbacks as ids

Decompile from asm:

  GetWindow  0x020275F8

It indexes WINDOW_LIST with a stride of 0xE0, so its argument is a window id
rather than a pointer, and its result is the address of one entry.

overlay_31_02382820.c declared it as taking a struct Window * and passed one,
which cannot be what the target computes: multiplying a pointer by 0xE0 and
adding it to WINDOW_LIST is meaningless. The value it passes is an id, and the
same value goes to DrawTextInWindow and UpdateWindow, so those take ids too.
This retypes the three window callbacks and both of those prototypes
accordingly, along with the callback type CreateTextBox stores.

That retyping is byte-neutral -- a pointer and an id both travel in r0 -- but
overlay_31_02382820.o was already matching, so it is rebuilt here to confirm
rather than assumed.

struct Window keeps its existing return type and gains padding to its real 0xE0
size, which is what lets &WINDOW_LIST[id] stride correctly. Its first seven
bytes are unchanged, so the width field overlay_31 reads is where it was. The
struct moves from the overlay's header into include/window.h, which already
exists and is where a main-binary function returning one can reach it; the
overlay includes it rather than the main binary including an overlay header.

No comments are added to any pmd-sky file.

Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build with overlay_31_02382820.o rebuilt:
build/pmdsky.us/pmdsky.us.nds: OK.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
cecilarmitais
2026-08-17 02:09:00 -07:00
parent 2472ad54f7
commit aade0cdfc8
10 changed files with 3089 additions and 3045 deletions

View File

@@ -1,30 +1,30 @@
#pragma once
.public DecompressAtHalf
.public DelayWteFree
.public GetWindow
.public LoadAlert
.public LoadCursors
.public LoadFileFromRom
.public LoadWteFromRom
.public MemZero
.public Memcpy32
.public UnloadFile
.public WINDOW_LIST
.public _0209AC4C
.public _0209AC50
.public _0209AC54
.public _0209AC58
.public _0209AC64
.public _0209AC78
.public _0209ACA8
.public _0209ACAC
.public _0209ADC8
.public _0209ADDC
.public _0209ADF0
.public _0209AE08
.public _0209B32C_JP
.public _0209B408_JP
.public _020AFC70
.public _020AFD04
.public _020AFD4C
.public _020AFD58
.public _020AFD5C
.public _020AFD60
.public _020AFD94
.public _020AFD98
.public _020AFD9C
.public _022A7A5C
.public _022A7A6C
.public _022A7A74
.public _022A7A78
.public _022A7A8C
.public _022A7AA0
@@ -36,67 +36,18 @@
.public _022A7B1C
.public _022A7EDC
.public _022A88E4
.public _022A88F0
.public _022A88F8
.public _022A88FC
.public _022A8908
.public _022A8990
.public _022A8991
.public _022A8992
.public _022A8994
.public _022A92B4_JP
.public _022A92B8_JP
.public _022A9A5C
.public _022AA35C
.public CURSOR_16_ANIMATION_CONTROL
.public CURSOR_16_SPRITE_ID
.public CURSOR_ANIMATION_CONTROL
.public DecompressAtHalf
.public DelayWteFree
.public GetPageItemYOffset
.public InitAnimationControlWithSet__0201C0B0
.public InitRender3dElement64
.public LoadAlert
.public LoadFileFromRom
.public LoadWanTableEntry
.public LoadWteFromRom
.public MemAlloc
.public Memcpy32
.public MemFree
.public memset
.public MemZero
.public PREV_MENU_ITEMS
.public SetAnimationForAnimationControl
.public SetSpriteIdForAnimationControl
.public sub_0200302C
.public sub_020030FC
.public sub_0200A124
.public sub_0200A174
.public sub_0200A184
.public sub_0200A29C
.public sub_0200B2C4
.public sub_0200B330
.public sub_0200B340
.public sub_0200B3C0
.public sub_0200B3FC
.public sub_0201C108
.public sub_0201D9C8
.public sub_0201E12C
.public sub_0201F2A0
.public sub_02025C7C
.public sub_0202760C
.public sub_02027624
.public sub_0202796C_JP
.public sub_020282C8
.public sub_0202903C
.public sub_02029A50
.public sub_02029A68
.public sub_02029B0C
.public sub_02029EC4
.public sub_02029FE8
.public sub_0202A124
.public sub_0202A2C8
.public sub_0202A388
.public sub_02032918
.public sub_0203293C
.public sub_02033350
.public sub_02033390
.public sub_020333B4
.public UnloadFile
.public WAN_TABLE
.public WINDOW_LIST

View File

@@ -0,0 +1,72 @@
#pragma once
.public CURSOR_16_ANIMATION_CONTROL
.public CURSOR_16_SPRITE_ID
.public CURSOR_ANIMATION_CONTROL
.public GetPageItemYOffset
.public InitAnimationControlWithSet__0201C0B0
.public InitRender3dElement64
.public LoadWanTableEntry
.public MemAlloc
.public MemFree
.public Memcpy32
.public PREV_MENU_ITEMS
.public SetAnimationForAnimationControl
.public SetSpriteIdForAnimationControl
.public WAN_TABLE
.public WINDOW_LIST
.public _0209AC64
.public _0209AC78
.public _0209ACA8
.public _0209ACAC
.public _0209ADF0
.public _0209AE08
.public _020AFC70
.public _020AFD4C
.public _020AFD94
.public _020AFD98
.public _020AFD9C
.public _022A7A6C
.public _022A7A74
.public _022A7A78
.public _022A7A8C
.public _022A7AA0
.public _022A7AC8
.public _022A7AE4
.public _022A7B00
.public _022A7B1C
.public _022A7EDC
.public _022A88E4
.public _022A88F0
.public _022A88F8
.public _022A88FC
.public _022A8908
.public _022A8990
.public _022A8991
.public _022A8992
.public _022A8994
.public _022A9A5C
.public _022AA35C
.public memset
.public sub_0200302C
.public sub_020030FC
.public sub_0200A174
.public sub_0200A184
.public sub_0200B330
.public sub_0200B340
.public sub_0200B3C0
.public sub_0200B3FC
.public sub_0201C108
.public sub_0201D9C8
.public sub_0201F2A0
.public sub_02029A50
.public sub_02029A68
.public sub_02029B0C
.public sub_02029EC4
.public sub_02029FE8
.public sub_0202A2C8
.public sub_0202A388
.public sub_02032918
.public sub_0203293C
.public sub_02033350
.public sub_02033390
.public sub_020333B4

File diff suppressed because it is too large Load Diff

2949
asm/main_0202760C.s Normal file

File diff suppressed because it is too large Load Diff

7
include/main_020275F8.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef PMDSKY_MAIN_020275F8_H
#define PMDSKY_MAIN_020275F8_H
#include "window.h"
#endif

View File

@@ -1,15 +1,13 @@
#ifndef PMDSKY_OVERLAY_31_02382820_H
#define PMDSKY_OVERLAY_31_02382820_H
#include "window.h"
#include "main_020348E4.h"
#include "util.h"
#include "preprocessString.h"
#include "dungeon.h"
struct Window {
u8 PAD[6];
u8 width; // 0x6: Window width in multiples of 8 pixels
};
void EntryOverlay31(void);
@@ -33,8 +31,8 @@ void EntryOverlay31(void);
#define LINE_HEIGHT 12
#define X_OFFSET 115
// Draws the contents shown in the main dungeon menu status window showing the player's belly, money, play time, etc.
void DrawDungeonMenuStatusWindow(struct Window* window);
void DungeonMenuSwitch(struct Window* window);
void DrawDungeonMenuStatusWindow(s32 window_id);
void DungeonMenuSwitch(s32 window_id);
struct struct_2 {
u32 b; // 0x0
@@ -89,7 +87,7 @@ void StairsMenu(struct entity* arg_1, u32 arg_2);
// r0: Entity pointer (in practice, always the leader)
void CreateStairsMenuState(struct entity* entity);
// Callback function passed to CreateAdvancedTextBox for creating the subheading for the stairs menu.
void StairsSubheadingCallback(struct Window* window);
void StairsSubheadingCallback(s32 window_id);

View File

@@ -17,4 +17,17 @@ typedef struct {
u8 allow_default; // 0xF: If true, try using emote index 0 if the desired emote can't be found
} portrait_params;
#include "util.h"
struct Window {
u8 PAD[6];
u8 width;
u8 pad2[0xD9];
};
extern struct Window WINDOW_LIST[];
struct Window *GetWindow(s32 window_id);
#endif //PMDSKY_WINDOW_H

View File

@@ -140,6 +140,8 @@ Static main
Object asm/main_0202598C.o
Object src/main_020265C4.o
Object asm/main_0202676C.o
Object src/main_020275F8.o
Object asm/main_0202760C.o
Object src/main_02029A50.o
Object asm/main_02029A68.o
Object src/main_02029EC8.o

7
src/main_020275F8.c Normal file
View File

@@ -0,0 +1,7 @@
#include "main_020275F8.h"
#include "window.h"
struct Window* GetWindow(s32 window_id)
{
return &WINDOW_LIST[window_id];
}

View File

@@ -6,6 +6,7 @@
#include "number_util.h"
#include "weather.h"
#include "main_02001188.h"
#include "window.h"
extern struct dungeon *DUNGEON_PTR[];
@@ -33,15 +34,14 @@ extern void GetMonsterOrTrapName(u8*, void*, u32); // The third argument isn't a
// function (../asm/overlay_29_022E1A40.s#L1378)
extern u8* StringFromId(u32);
extern void PreprocessString(u8* dst, u32 dsize, const u8* src, u32 flags, struct PPStrValues* ptr);
extern void DrawTextInWindow(struct Window*, u32, u32, u8*);
extern void UpdateWindow(struct Window*);
extern void DrawTextInWindow(s32, u32, u32, u8*);
extern void UpdateWindow(s32);
extern u8* AllocateTemp1024ByteBufferFromPool(void);
extern struct Window* GetWindow(struct Window*);
extern s32 sub_020265A8(u8*); // Measures the text's width in pixels
extern u8 CreateParentMenuFromStringIds(u32*, u32, struct struct_2*, u32*);
extern u8 CreateTextBox(u32*, void (*fun)(struct Window*));
extern u8 CreateTextBox(u32*, void (*fun)(s32));
extern u32 IsParentMenuActive(s8);
extern u32 GetWindowIdSelectedItemOnPage(s8);
extern u32 GetPressedButtons(u32, u16*);
@@ -73,7 +73,7 @@ void EntryOverlay31(void) {
}
void DrawDungeonMenuStatusWindow(struct Window* window)
void DrawDungeonMenuStatusWindow(s32 window_id)
{
struct PPStrValues str_values;
u8 str_buff[DRAW_DUNGEON_MENU_STATUS_WINDOW_BUFF_SIZE];
@@ -93,22 +93,22 @@ void DrawDungeonMenuStatusWindow(struct Window* window)
str = StringFromId(DRAW_DUNGEON_MENU_STATUS_WINDOW_STR_ID_1);
PreprocessString(str_buff, DRAW_DUNGEON_MENU_STATUS_WINDOW_BUFF_SIZE, str, 0, &str_values);
DrawTextInWindow(window, X_OFFSET, 0, str_buff);
DrawTextInWindow(window_id, X_OFFSET, 0, str_buff);
str_values.gold_left_0 = GetMoneyCarried();
str = StringFromId(DRAW_DUNGEON_MENU_STATUS_WINDOW_STR_ID_2);
PreprocessString(str_buff, DRAW_DUNGEON_MENU_STATUS_WINDOW_BUFF_SIZE, str, 0, &str_values);
DrawTextInWindow(window, X_OFFSET, LINE_HEIGHT, str_buff);
DrawTextInWindow(window_id, X_OFFSET, LINE_HEIGHT, str_buff);
str_values.weather_0 = GetApparentWeather(NULL);
str = StringFromId(DRAW_DUNGEON_MENU_STATUS_WINDOW_STR_ID_3);
PreprocessString(str_buff, DRAW_DUNGEON_MENU_STATUS_WINDOW_BUFF_SIZE, str, 0, &str_values);
DrawTextInWindow(window, X_OFFSET, LINE_HEIGHT * 2, str_buff);
DrawTextInWindow(window_id, X_OFFSET, LINE_HEIGHT * 2, str_buff);
str_values.time_0 = sub_0204F9E0();
str = StringFromId(DRAW_DUNGEON_MENU_STATUS_WINDOW_STR_ID_4);
PreprocessString(str_buff, DRAW_DUNGEON_MENU_STATUS_WINDOW_BUFF_SIZE, str, DRAW_DUNGEON_MENU_STATUS_WINDOW_CONST_1, &str_values);
DrawTextInWindow(window, X_OFFSET, LINE_HEIGHT * 3, str_buff);
DrawTextInWindow(window_id, X_OFFSET, LINE_HEIGHT * 3, str_buff);
line_offset = 0;
for (i = 0; i < 4; i++) {
@@ -130,7 +130,7 @@ void DrawDungeonMenuStatusWindow(struct Window* window)
str = StringFromId(DRAW_DUNGEON_MENU_STATUS_WINDOW_STR_ID_5);
PreprocessString(str_buff, DRAW_DUNGEON_MENU_STATUS_WINDOW_BUFF_SIZE, str, 0, &str_values);
DrawTextInWindow(window, 4, line_offset, str_buff);
DrawTextInWindow(window_id, 4, line_offset, str_buff);
line_offset += 12;
if (line_offset >= 0x30) {
@@ -139,21 +139,21 @@ void DrawDungeonMenuStatusWindow(struct Window* window)
}
}
UpdateWindow(window);
UpdateWindow(window_id);
}
void DungeonMenuSwitch(struct Window* window)
void DungeonMenuSwitch(s32 window_id)
{
struct PPStrValues str_values;
str_values.dungeon_0 = DUNGEON_PTR[0]->id | 0x40000;
str_values.digits_0 = DUNGEON_PTR[0]->floor;
u8* str_buff = AllocateTemp1024ByteBufferFromPool();
PreprocessString(str_buff, 0x400, DUNGEON_MENU_SWITCH_STR1, 0, &str_values);
struct Window* window2 = GetWindow(window);
struct Window* window2 = GetWindow(window_id);
s32 text_width = sub_020265A8(str_buff);
s32 x_offset = (window2->width * 8 - text_width) / 2;
DrawTextInWindow(window, x_offset, 2, str_buff);
UpdateWindow(window);
DrawTextInWindow(window_id, x_offset, 2, str_buff);
UpdateWindow(window_id);
}
u32 DungeonMenuLoop(void)
@@ -295,11 +295,11 @@ void CreateStairsMenuState(struct entity* entity)
ov31_0238A2A0.st3->d = r4;
}
void StairsSubheadingCallback(struct Window* window)
void StairsSubheadingCallback(s32 window_id)
{
u8* str = StringFromId(ov31_02389E22[ov31_0238A2A0.st3->d * 2]);
ov31_0238A2A0.str = str;
DrawTextInWindow(window, 16, 18, str);
UpdateWindow(window);
DrawTextInWindow(window_id, 16, 18, str);
UpdateWindow(window_id);
}