Files
pmd-sky/include/main_02056D70.h
cecilarmitais 6371544da2 Decomp GetUnitNpcIds and GetAdventureNpcIds
Decompile both from asm/main_02056960.s. Each walks the four entries of
TEAM_MEMBER_TABLE_PTR->active_roster and, for every entry with bit 1 of its flags
byte set, takes member_index and keeps it if IsMonsterIdInNormalRange accepts it
and a filter rejects it: GetUnitNpcIds excludes the three main characters via
sub_02055410, sub_02055474 and sub_020554D8, and GetAdventureNpcIds excludes via
sub_020564B0. Matching indices are appended to the caller's buffer and the count
is returned.

Both tolerate a null buffer. The target reserves eight bytes of stack and
redirects the pointer there when the argument is null, which is why the frame
reserves space nothing else uses. That is reproduced with a local s16 scratch[4].

They merge into a new src/main_02056D70.c; extracting them splits
asm/main_02056960.s, the trailing functions move verbatim into
asm/main_02056EB8.s, and main.lsf gains the two objects.

The buffer parameter is s16*, which is what both call sites pass and what the
stores write. Their prototypes move out of main_02064FFC.h, where they were
declared as void* while their callers were decompiled, into the new header. That
tightening also required sub_02065050's two scratch buffers to change from
u8[8] to s16[4] -- the same eight bytes, and already how sub_0206549C declares
its own. sub_02065050 was rebuilt to confirm it stays byte-identical.

The flag test reads the first byte of struct team_member directly, as
(*(u8 *)m & 2). common.h models that byte as a bitfield of f_is_valid:1 followed
by flags_unk1:7, and no access through those members reproduces the target's
single tst: reading flags_unk1 emits a shift pair to extract the field first, and
splitting bit 1 into its own one-bit member is worse still. The raw byte read is
the only form that matches, so it is used here rather than changing a struct
shared with the rest of the tree.

No new names are introduced. struct team_member, struct team_member_table, their
fields and TEAM_MEMBER_TABLE_PTR already exist, and both function names were
already labelled.

No comments are added to any pmd-sky file.

Authored by Claude (Opus 4.8) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-16 13:45:14 -07:00

10 lines
153 B
C

#ifndef PMDSKY_MAIN_02056D70_H
#define PMDSKY_MAIN_02056D70_H
#include "util.h"
int GetAdventureNpcIds(s16* buf);
int GetUnitNpcIds(s16* buf);
#endif