Repository navigation
fakes: replace 45 fakes with natural C that still matches - #2
Conversation
The function's parameter is a Vec by value, not a const Vec*. Every caller already behaved as a by-value call: mot_slit.c copied mario->position into a local and passed its address, and marioRollChgChk called it through a by-value function-pointer cast (a listed fake). With the real prototype all three callers pass mario->position directly and the cast is gone. In the function, the by-value parameter gives the loads their own alias class instead of the worst-case pointer one, so the copy into the ray start schedules as in the target. The body uses compound literals for the ray start and direction, and h is set after marioGetPtr(). Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
extdrv and punidrv keep the smart-allocated texture handle in a void* field (image) and pass its address to animPoseDisp_MakeExtTexture, which stores the smartAlloc result through it and reads the texel address back through a smartEntry* cast. With the field typed void** the callers' &tex->image was a void*** that the smartEntry** header prototype rejected, so both callers called through a local function-pointer cast (two listed fakes). With the field a void* and the parameter a void**, both callers make the plain call; smartTexObj still takes the field (void* converts to its void** parameter). Both fakes and their rows are gone. extMakeTexture is DOL code in every version; it has no version conditionals. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
envGlareFilter's four coordinates are s16 parameters: the function rounds and clamps them in place and stores them into the s16-wide glare rectangle. The s32 parameters needed s16 copies in the body, and the two callers (test_glare in eki_03 and hom_00), compiled against the s16 prototype, called through a local function-pointer cast (two listed fakes). With the s16 prototype the body works on the parameters directly and both callers make the plain call. Both fakes and their rows are gone. envGlareFilter is DOL code in every version with no version conditionals; test_glare keeps its JP/demo envGlareFilterZ split. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
BattlePartyAnimeLoad returns whether the partner's animations have loaded: both _anime_load_wait scripts (battle_event_default.c and jin's unit_faker_mario.c) test the result to block until it is TRUE. With the void prototype the four callers called through a BOOL(s32) cast (four listed fakes). The function now returns animEffectAsync's result (the same code: the call already leaves it in r3) and every caller makes the plain call. The four fakes and their rows are gone. BattlePartyAnimeLoad and both callers' files have no version conditionals here. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
Both ss_check helpers take the script argument the way the other user functions do, `EvtWord* args = event->args; s32 dest = *args++;`. Reading event->args through the local puts the ssf load ahead of the args read as in the target, so the dead `!ssf` condition that did this (a listed fake in each file) is gone with its rows. (`args[0]` without the post-increment does not match: 86.91%.) Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The retail recipe lookups put each result in an ItemType local before handing it to evtSetValue (`id = itemNameToID(...); evtSetValue(event, args[n], id);`), the Mystery result of cook_chk in its own `cook` local, and cook_chk2 tests the recipe pair through a CookRecipe pointer. That orders the args[n] loads after the inlined itemNameToID as in the target, so the retail (volatile u32) casts are gone. The demos' cooking.xml versions (VERSION <= VERSION_DEMO_JP) keep their casts: they cannot be checked here. Their comments no longer point at the retail function, and the FAKES.md row now lists only the two demos. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
entryToPath keeps the archive's string-table pointer in a FstStringStart local next to the existing FstStart one, the pair of names dvdfs.c's file-system code uses (there as globals) and the stringOff/parentDir macros were written for, as the US decomp has it. With the local, the recursive entryToPath inlines to the target depth (136 instructions) without the `#pragma inline_depth(3)` that ran from it to the end of the file (a listed fake). arc.c has no version conditionals and no line-numbered asserts. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
mario_kemuri is written as the US decomp has it: one early return for a raised system level, tube mode or the pipe motion, then a return after each floor kind's effect (and after resetting the grass counter when Mario is not walking or dashing). This gives the target's branch layout, so the `s = s;` self-assignment in the empty pipe branch (a listed fake) and the unused `out:` label are gone. Same behaviour. The file's `#pragma dont_inline on` region stays; its FAKES.md row now lists only that. mario_kemuri has no version conditionals. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
…guard
_get_msg reads the output variable as `EvtWord* args = event->args; s32 index = *args++;`
after the work pointer, as the US decomp has it and as other single-argument
USER_FUNCs here do (npcdrv.c reads its index the same way). That gives the target's
code without the `if (!event->args && !event->args) {}` dead guard in case 1, which
carried no FAKE comment or FAKES.md row. Removing only the guard does not match
(99.99%), and neither does the args form without the post-increment.
_get_msg has no version conditionals.
Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The retail branch called marioGetMoveRate through a `(f32 (*)(void))` cast, on the reading that the original passed no direction and the function picked up whatever was left in f1. Storing the angle with a chained assignment (`*angle = ang = revise360(...)`) leaves ang in f1, so `marioGetMoveRate(ang)` needs no register move and gives the target code in L_getStick and its inlined copy in yoshi_use. The calls pass the angle, as the demo branch already did, so this is not a game bug: its KNOWN_GAME_BUGS.md row goes with the FAKES.md row. Only the VERSION > VERSION_DEMO_JP branch changed; the demo branch is as it was. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
evt_mario.c's callers compute a direction and pass it as a third f32 through a file-local wider prototype, while the definition took two arguments and called party_set_behind_dir through a `(void (*)(PartyEntry*))` cast so the direction came from whatever was in f1. The direction arrives in f1 and is still there at the party_set_behind_dir call, so a real `f32 dir` parameter passed straight on gives the same code on both sides. The header has the three-argument prototype, evt_mario.c includes party/party_move.h instead of redeclaring it, and the KNOWN_GAME_BUGS.md row goes: the direction is passed. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The call went through an unprototyped `void (*)()` cast with (s32) coordinates, because `GXPeekARGB((s32)sx, (s32)sy, ...)` narrows the ints to the u16 parameters with two clrlwi. Passing the float screen coordinates straight to the u16 parameters converts them without the narrowing, and the buffer goes as `(u32*)argb`, so the plain SDK call gives the target code. The function has VERSION >= VERSION_JP / <= VERSION_DEMO_JP blocks around other statements; they are unchanged. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The function kept a second pointer to idx (and one to z) so the two arrays took the target base registers. Written with the display callback's own `void* param` signature (the effect pointer assigned from it, so dispEntry needs no cast), the locals declared in the order the target's register allocation follows, and plain z[]/idx[] indexing in the sort and draw loops, it gives the target code. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
effSleepDisp needed opt_propagation off, a sleepPos helper that kept a `1.0f * y` product, and the sine argument as a comma expression with a compound assignment. Written plainly it gives the target code: the display callback's own `void* param` signature (so dispEntry needs no cast), `0.5f * sinf(6.2831855f * (...) / 64)` for the two wave offsets and the quad corners as `w / 2` and `w / 8 * j` products. sinf is a file-local inline over the double sin(), as mapdrv.c has; through it the sine argument is evaluated before the 0.5f factor, which keeps the .sdata2 constants in the target order (1/64 before 0.5). The texture id keeps its EFF_TEX version offset. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
mapEntry reads the active group's MapWork through mapGetWork(), as the rest of the file does. The inlined call gives wp r31 by itself, so the comma expression that forced it is gone. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
After switching to group 1, bmapLoad reads the battle MapWork through mapGetWork(), the same way it reads the field one at the top. That gives wp the target register without the comma expression. The statement is shared by every version (bmapLoad has demo-only archive code around it). Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
caseEntry declares i as s32 and starts the free-slot search with `i = 0, entry = wp->entries` in the for statement. That gives i and entry the target's registers, so the no-op 64-bit mask on the return value goes. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
evtEntry's priority parameter is an s32, not a u8. The definition stores it to the u8 EventEntry.priority either way (same code), and every other caller in src/ and rels/ passes a literal 0 or 10, which needs no truncation under either type. caseMain passes its CaseEntry's priority straight through, which only the s32 parameter gives, so it no longer calls evtEntry through a cast to an s32-priority prototype. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
lightGetNearObj's position parameter is a Vec*, not a Vec by value: mapSetLight and mapSetMaterialLight pass the Vec's address with no stack copy. Its body is rewritten for the pointer: indexed tmp[n] writes, the filter loop with `continue`s and j as the found count. That matches with the pointer parameter, so mapdrv.c's file-local macro that called it through a Vec* cast is gone. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The three scale2 extents call fabs() from <math.h> (in this unit's prefix header). Its inline argument temporary gives the |max - min| loads the target float registers, so the `(0, x)` comma expressions around __fabs go. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
pouchSetHP, pouchSetFP and pouchSetAP take an s32 and pouchGetMaxHP, pouchGetMaxFP and pouchGetMaxAP return one. The definitions store to and read the s16 pouch fields the same way under either type. The callers show it: win_item.c (winItemMain), win_main.c (itemUseFunc) and battle_break_slot.c (BattleBreakSlot_Main) called the setters through s32 casts, and evt_kinopio's power_chk called all six getters through one. With the s32 prototypes those calls are plain. The other callers (evt_pouch, statuswindow, battle_item_data, battle_seq_end, tou_07 and the literal calls in seq_e3 and seq_title) build the same. PAL's itemUseDisp branch keeps its casts of pouchGetMaxHP/FP: they now have the header's own type, but that branch isn't in the US build, so the plain call there is left until a PAL build can confirm it. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The US winMarioDisp computes each draw position in place instead of parking every float live range in its own named variable. iconX serves the three icon columns, the label and ruby widths and the special-move y live in blocks, and white/black have copies (white2, black2) for the star icons, the counter frames and the special-move list. That builds the target's float registers by itself, so the one-element q1/q2 copies of row0/row1 and the two dead int guards that kept them live go. The JP winMarioDisp (with its own dead store, still listed) is not touched. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
lightEntry's parameters are (name, type, position, rotation, color, spotAngle, attenAngle, attenType, flags): the two floats come before the two ints. The registers are the same either way, but that is the argument order _mapLoad passes. _mapLoad, its only caller, now calls it directly with the light's colour by value instead of through a cast to that order with the colour copied into a local and passed by address. The other fake in _mapLoad (the written-out chunk search) is unchanged. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
Both functions now guard the whole body with one test of the name (not empty, not "(^x^)party") and search the NPC table for the speaker in place, with a work pointer and the table size in locals, instead of two early returns and a call to npcNameToPtr. That builds the target code under the file's normal optimizer settings, so the opt_propagation/opt_lifetimes off pragmas that started at npcSetTalkPose now cover only npcCheckHitMarioSide, which still needs them. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The three facing tests of fbatEncountCheck subtract camGetPtr(CAMERA_3D)->viewYaw directly instead of storing it to yaw in every switch arm first. That keeps dir (Mario's facing) in its own register through the loop, so the dead int-guarded re-definition of dir inside the loop goes. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
BtlUnit_GetStatus, BtlUnit_SetStatus, BtlUnit_CheckStatus and BtlUnit_CheckRecoveryStatus take the StatusEffectType as s8, not as the enum. Every caller already behaved that way: battle_damage.c, battle_status_icon.c and battle_disp.c called them through s8 function-pointer casts (listed fakes), and the definitions switched on (s8)type. With the s8 prototypes those callers make plain calls, the definitions test type directly, and the casts and their FAKES.md rows are gone (BattleSetStatusDamage, _bsi_default_turn, _bsi_guruguru, _bsi_allergy, _bsi_biribiri, _bsi_regeneration, _GetStatusPoseType). btlseqEnd's status-clearing loop counts with an s8 i, which its (s8)i casts were standing in for. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The function returns a u8, not a BOOL. battle_audience_kinopio.c called it through a u8() function-pointer cast (a listed fake) and battle_audience.c through u8 casts at every call; with the u8 prototype all of them make plain calls. In the definition the last test is written like the ones before it (status 12 returns FALSE, then TRUE), which is what the u8 return compiles to. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
…ectly The button icons are u16 locals that BattleACGetButtonIcon's u16 result goes into, and the icons are drawn with plain iconDispGx calls on compound-literal positions. This replaces the s32 function-pointer cast of BattleACGetButtonIcon (a listed fake) and the ICONGX cast of iconDispGx, and the `(u16)c` tests the s32 locals needed. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
… directly The A icons are u16 locals for BattleACGetButtonIcon's u16 result, the icons are drawn with plain iconDispGx calls on compound-literal positions, and the star icon starts unlit and is lit in the zone. This replaces the s32 function-pointer cast of BattleACGetButtonIcon (a listed fake), the ICON cast of iconDispGx and the Vec temporaries built field by field. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
… directly The A icons are u16 locals for BattleACGetButtonIcon's u16 result, and the plain iconDispGx call picks the pressed one with a conditional while the cursor is within 15 of the target. This replaces the s32 function-pointer casts of iconDispGx and BattleACGetButtonIcon (listed fakes). The pulse test reads inRangeCnt % 30 in the condition and the call. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The gauge's fill ratio is the third parameter and the width the fourth, not the other way round. The registers are the same either way (r3-r5 and f1), but MWCC evaluates the arguments in the listed order: ac_repeatedly.c called the function through an unprototyped cast (a listed fake) to get the ratio evaluated before the width. With the real order it makes a plain call; every other caller is reordered and builds the same. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
…unctions directly The button icons are u16 locals for BattleACGetButtonIcon's u16 result, the icons are drawn with plain iconDispGx calls on compound-literal positions, and BattleAcDrawGauge is called through its header prototype, which now lists the ratio before the width. This replaces the function-pointer casts of BattleAcDrawGauge and BattleACGetButtonIcon (listed fakes), the RL_IconDisp cast of iconDispGx and the (s8) cast on the s8 state field. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
BtlUnit_snd_se's last parameter is the pitch it passes on to BtlUnit_snd_se_pos, an s16 like that function's, not an s32 pan. With the s16 parameter it makes a plain call instead of going through an s32 function-pointer cast (a listed fake), and the Stampede slide sound no longer needs its (s16) cast. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
iconDispGxCol's flags are a u16, not an s16. sac_genki.c's disp_3D called it through a (Mtx, u16, s32, GXColor) cast (a listed fake); with the u16 prototype and the icon in a u16 local, as iconDispGxCol takes it, it makes a plain call. No other caller changes. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
Written as nested tests, with the pose's loop count read once into a u32 local and the 70% volume applied with vol *= 0.7, the function matches with normal optimisation, so the `#pragma opt_propagation off` push/pop around it (a listed fake) is gone. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
The single-item entry is filled through the same running index as the Double Dip and Triple Dip entries (num = 0, then num++), and unit and cmd are set in their declarations. Written that way the function matches with normal optimisation, so the `#pragma opt_propagation off` around it (a listed fake) is gone. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
With the member's flags read once into a local, the item check written as a switch that returns for anything but -1, early returns for the first two fidgets and the conditions joined with &&, the function matches with normal optimisation: the `#pragma opt_propagation off` and `opt_lifetimes off` around it (a listed fake) are gone. One trick stays and is now marked: the (f32) cast of 10.0f * a, already an f32, which the target needs (it was in the old code unmarked). The FAKES.md row now describes it. Checked: G8ME01 builds 30 files OK. Not checked: the other six versions (no game files here).
LLCOOLT
left a comment
There was a problem hiding this comment.
Hey, thanks for this! Happy to see someone tackling some of the fakes. I built all versions and confirmed it is byte-identical.
| typedef void (*PouchSetAPS32Fn)(s32); | ||
| // FAKE: win_item.c calls pouchGetMaxHP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. | ||
| // FAKE: PAL's itemUseDisp still calls pouchGetMaxHP and pouchGetMaxFP through these s32 prototypes. They are now the | ||
| // header's own types, so the plain call should build the same, but it has not been checked against a PAL build. |
There was a problem hiding this comment.
PAL now builds byte-identical with this PR. After merging I’ll try replacing the two PouchGetMax*RetS32Fn casts at lines 1004 and 1025 with plain pouchGetMaxHP() / pouchGetMaxFP() calls, remove these typedefs and the FAKE comment, and drop the matching FAKES.md row if all seven versions still match
| | JP, US, PAL, DEMO_US_2, DEMO_EU | src/event/evt_sub.c | coin_fmt (data: the orphan "%f%f%f" in .rodata) | the releases and the September demos (`#if VERSION >= VERSION_JP`): `#pragma force_active on` around an unreferenced `static const char[]` keeps the string of a stripped coin-position helper at the start of .rodata | without the pragma the linker strips the string and the JP build fails (DOL and every REL); the original helper is unknown | | ||
| | all | src/driver/shadowdrv.c | _filter | `f32 t = 20.0f;` dead store under `#pragma opt_dead_assignments off`: its literal takes the target .sdata2 slot; also `#pragma opt_dead_assignments off`: keeps the dead stores that the target has | without it .sdata2 is reordered (DOL hash differs) | | ||
| | all | rels/gor/src/gor_01.c | cook_chk, cook_chk2 | `(volatile u32)args[n]` as the script-variable argument of evtSetValue, so args[n] is loaded after the inlined itemNameToID result as in the target (the JP demo's cooking.xml versions of both functions use the same cast, also for the naniga_okorukana_cook result in cook_chk2) | plain `args[n]`, the result in a local first (two instructions swap), a `(u32)` cast of the result, `event->args[n]` | | ||
| | DEMO_US_1, DEMO_JP | rels/gor/src/gor_01.c | cook_chk, cook_chk2 (the demos' cooking.xml versions) | `(volatile u32)args[n]` as the script-variable argument of evtSetValue, so args[n] is loaded after the inlined itemNameToID result as in the target (in cook_chk2 also for the naniga_okorukana_cook result) | plain `args[n]`, the result in a local first (two instructions swap), a `(u32)` cast of the result, `event->args[n]`; the retail versions match plainly with the result in an `ItemType id` local (`id = itemNameToID(...); evtSetValue(event, args[n], id);`), a form not checked in the demos (no demo files here) | |
There was a problem hiding this comment.
After merging I’ll try the retail form (ItemType id = itemNameToID(...); evtSetValue(event, args[n], id);) in the demos’ cook_chk and cook_chk2 (gor_01.c lines 7379–7381, 7405, 7437). If both demos still match, I’ll remove the volatile casts and this row; if not, I’ll update the row with what was tried.
…casts Follow-ups from PR #2, which could only check G8ME01: - win_item.c: PAL's itemUseDisp calls pouchGetMaxHP and pouchGetMaxFP directly. The header prototypes already return s32, so the PouchGetMax*RetS32Fn typedefs were no-ops. - gor_01.c: the demos' cooking.xml cook_chk and cook_chk2 use the retail form (the result in an ItemType id local, then evtSetValue with plain args[n]) instead of (volatile u32) casts. Only the JP demo builds the gor REL. Both FAKES.md rows are gone. All seven versions build byte-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replaces fakes with natural C that still matches: 37 commits, one per function or topic. FAKES.md goes from 472 to 427 rows and the code from 659 to 602
FAKEcomments.These forms come from a separate US (G8ME01) decompilation I've been working on with Claude Code under a "no tricks" rule, which matched many of the same functions without fakes. Each one was ported into this tree's names, types and style, and kept only if the build stayed byte-identical.
What changed
Real prototypes instead of calls through casts. Where every caller agreed on a prototype the header didn't have, the header now has it and the casts are gone:
marioCreviceWallChktakes its Vec by value;BtlUnit_GetStatus/SetStatus/CheckStatus/CheckRecoveryStatustake the status id ass8;pouchSetHP/FP/APtakes32and the max getters returns32;evtEntrytakes ans32priority;BattleAcDrawGaugetakes the ratio before the width;envGlareFiltertakess16,BattlePartyAnimeLoadreturnsBOOL,BattleAudience_GetEscapeChangeOKreturnsu8,iconDispGxColtakesu16flags,BtlUnit_snd_setakes ans16pitch;lightGetNearObjtakes its position by pointer, andlightEntrytakes the spot angles before attenType and flags;animPoseDisp_MakeExtTexture's image out-parameter is avoid**.Every caller in
src/andrels/is updated.Two "original bugs" that weren't.
partyMoveBehindMario3andL_getStick/yoshi_usedo pass the direction; the casts hid it. Their KNOWN_GAME_BUGS.md rows are removed.Plain C instead of dead guards, comma expressions, self-assignments, one-element arrays or
opt_*/inline pragmas: mario_kemuri, winMarioDisp (US), npcSetTalkPose/npcSetStayPose, fbatEncountCheck, the ac_power_gauge/ac_power_gauge_lv2/ac_monosiri_target/ac_repeatedly_lv actionCommandDisp functions, BtlUnit_ControlPoseSoundMain, _btlcmd_MakeMultiItemTable, BattleAudienceCtrlProcessKinopioWait, mapEntry/bmapLoad, caseEntry, mobjHitEntry, entryToPath, ss_check (mri_16, tik_00), cook_chk/cook_chk2 (retail), effSleepDisp, effMahojinDisp, effSplashGetCol._get_msghad an unmarked dead guard (if (!event->args && !event->args) {}); it reads its argument through an args pointer now. BattleAudienceCtrlProcessKinopioWait still needs one cast that wasn't marked, so it's now markedFAKEwith a row.How it was checked
30 files OK(all 30 hashes),tools/format_check.pyreports nothing to reformat, andtools/check_versions.pypasses.