Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/melee/ft/chara/ftCrazyHand/ftCh_Init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ void ftCh_Damage2_Anim(HSD_GObj* gobj)
attrs = fp->ft_data->ext_attr;
fp->mv.ch.unk0.xC.x = fp->cur_pos.x - attrs->x28;
fp->mv.ch.unk0.xC.y = attrs->x24;
Fighter_ChangeMotionState(gobj, ftMh_MS_Damage, 0,
Fighter_ChangeMotionState(gobj, ftMh_MS_Damage2, 0,
fp->mv.ch.unk0.xC.z = ftCh_Init_804DA070,
ftCh_Init_804DA074, ftCh_Init_804DA070,
NULL);
Expand Down
94 changes: 75 additions & 19 deletions src/melee/gr/gricemt.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,20 @@ void grIceMt_801F7EE8(Ground_GObj* arg0)
}

/// #grIceMt_801F7F1C
void grIceMt_801F7F1C(Ground_GObj* arg0)
void grIceMt_801F7F1C(HSD_GObj* gobj)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ground_GObj is a typedef for HSD_GObj, but leaving it as a Ground_GObj gives more information to readers (and m2c, our decompiler).

{
int i = 0;
Ground* gp = GET_GROUND(arg0);
u8 _[8];
void* ptr;
s32 i;

i = 0;
ptr = gobj->user_data;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most GObj types have an associated getter macro, which we try to use everywhere. GET_GROUND

do {
if (42 != 0) {
grMaterial_801C8CDC(arg0);
if (*(void**)((u8*)ptr + 0xF8) != NULL) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ptr should be a Ground*, not a void*
Offset 0xF8 is inside the GroundVars union, which holds different data for every Ground. We should use icemt, icemt2, or maybe create an icemt3. One stage can have multiple Grounds, and I don't know which one this callback is expecting.
icemt looks like it has an HSD_GObj array at 0xF8 so it's probably that one.
gp->gv.icemt.xF8[0]

grMaterial_801C8CDC(*(void**)((u8*)ptr + 0xF8));
}
i++;
i += 1;
ptr = (void*)((u8*)ptr + 4);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a compiler optimization.

for (int i = 0; i < 2; i++) {
  foo(arr[i]);
}
// can compile to:
for (int i = 0; i < 2; i++) {
  foo(arr++);
}

} while (i < 2);
}

Expand Down Expand Up @@ -631,13 +636,19 @@ void grIceMt_801F815C(Ground_GObj* param1)
/// #grIceMt_801F81B4
void grIceMt_801F81B4(Ground_GObj* arg0)
{
int i = 0;
Ground* gp = GET_GROUND(arg0);
Ground* gp;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function looks like a copypaste of grIceMt_801F7F1C (which is fine, but same comments apply).
There's a chance one inlines the other, or both inline a third function - if the stack is wrong after cleanup that might be a thing to try.

int i;
PAD_STACK(8);

i = 0;
gp = arg0->user_data;

do {
if (42 != 0) {
grMaterial_801C8CDC(arg0);
if (*(HSD_GObj**)((u8*)gp + 0xF8) != NULL) {
grMaterial_801C8CDC(*(HSD_GObj**)((u8*)gp + 0xF8));
}
i++;
gp = (Ground*)((u8*)gp + 4);
} while (i < 2);
}

Expand Down Expand Up @@ -1007,28 +1018,73 @@ void grIceMt_801F91EC(HSD_GObj* param_1, s16* param_2, int param_3,
/// #grIceMt_801F929C
void grIceMt_801F929C(HSD_GObj* arg0, void* arg1)
{
mpLib_80057BC0(2);
mpJointListAdd(2);
grAnime_801C83D0(arg0, 2, 7);
s16 temp_r3;

if (*(s16*)((u8*)arg1 + 0x0) != 0) {
Copy link
Copy Markdown
Collaborator

@BR- BR- Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of pointer math here. Need to use M2C_FIELD(arg1, s16*, 0) or figure out the type of arg1.
The callsites are passing a pointer to inside of the GroundVars struct, making me think there should be an inner struct.
It might be easier to make a new temporary struct and unify it later:

struct grIceMt_801F929C_arg1 { /// @todo this should be an internal struct within grIceMt_GroundVars
    s16 x0;
    s16 x2;
    // ...
}* p = arg1;

I'd prefer: actual struct > m2c_field = temporary struct > pointer math.

*(s16*)((u8*)arg1 + 0x2) = (s16) (*(s16*)((u8*)arg1 + 0x2) + 1);
temp_r3 = *(s16*)((u8*)arg1 + 0x2);
if (temp_r3 == *(s16*)((u8*)arg1 + 0xA)) {
mpLib_80057BC0(*(s16*)((u8*)arg1 + 0x8));
} else if (temp_r3 == *(s16*)((u8*)arg1 + 0xC)) {
mpJointListAdd(*(s16*)((u8*)arg1 + 0x8));
}
if (grAnime_801C83D0(arg0, *(s16*)((u8*)arg1 + 0x4), 7) != 0) {
*(s16*)((u8*)arg1 + 0x0) = 0;
}
}
}

/// #fn_801F9338
void fn_801F9338(Ground* gp, int arg1, CollData* arg2, s32 arg3,
mpLib_GroundEnum arg4, float arg8)
{
// mpLib_80057BC0(2);
// mpJointListAdd(2);
// grAnime_801C83D0(arg0,2,7);
HSD_GObj* temp_r3;
s16* temp_r30;
s16 temp_r4;
u8 flag_byte;

temp_r30 = (s16*)((u8*)gp + 0x100);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More pointer math. 0x100 is a HSD_GObj* in icemt, which doesn't seem right for this usage. Perhaps this shares a struct with 801F929C above? icemt3 might be the way to go until we can figure out what's going on.
I think a struct is more likely than an array.

flag_byte = *(u8*)((u8*)arg2 + 0x34);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer struct access by name: arg2->x34_flags
Since it's a bitfield, the shifting and masking below is unnecessary too.
This variable probably shouldn't exist, just inline arg2->x34_flags.b1234 in the if statement.

if (((flag_byte >> 3) & 0xF) == 1 && *temp_r30 == 0) {
temp_r3 = Ground_801C2BA4(2);
*temp_r30 = 1;
temp_r30[1] = 0;
grAnime_801C7A04(temp_r3, temp_r30[2], 7, 1.0f);
grAnime_801C7B24(temp_r3, temp_r30[2], 7, 0.0f);
grAnime_801C78FC(temp_r3, temp_r30[2], 7);
temp_r4 = temp_r30[3];
if (temp_r4 != -1) {
grAnime_801C7A04(temp_r3, temp_r4, 7, 1.0f);
grAnime_801C7B24(temp_r3, temp_r30[3], 7, 0.0f);
grAnime_801C78FC(temp_r3, temp_r30[3], 7);
}
}
grIceMt_801FA7F0(gp, arg1, arg2, arg3, arg4, arg8);
}

/// #fn_801F9448
void fn_801F9448(Ground* gp, int arg1, CollData* arg2, s32 arg3,
mpLib_GroundEnum arg4, float arg8)
{
// mpLib_80057BC0(2);
// mpJointListAdd(2);
// grAnime_801C83D0(arg0,2,7);
HSD_GObj* gobj;
s16* icemt_ptr = &gp->gv.icemt.x10E;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be some inlines afoot here, this looks very similar to fn_801F9338, but don't sweat it.
Same comments apply.

s16 temp_r4;
u8 flag_byte = *(u8*)((u8*)arg2 + 0x34);

if (((flag_byte >> 3) & 0xF) == 1 && icemt_ptr[0] == 0) {
gobj = Ground_801C2BA4(2);
icemt_ptr[0] = 1;
icemt_ptr[1] = 0;
grAnime_801C7A04(gobj, icemt_ptr[2], 7, 1.0f);
grAnime_801C7B24(gobj, icemt_ptr[2], 7, 0.0f);
grAnime_801C78FC(gobj, icemt_ptr[2], 7);
temp_r4 = icemt_ptr[3];
if (temp_r4 != -1) {
grAnime_801C7A04(gobj, temp_r4, 7, 1.0f);
grAnime_801C7B24(gobj, icemt_ptr[3], 7, 0.0f);
grAnime_801C78FC(gobj, icemt_ptr[3], 7);
}
}
grIceMt_801FA7F0(gp, arg1, arg2, arg3, arg4, arg8);
}

Expand Down
20 changes: 12 additions & 8 deletions src/melee/gr/grpura.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,18 @@ void grPura_8021228C(Ground_GObj* arg0) {}
/// #grPura_80212290
void grPura_80212290(Ground_GObj* arg0)
{
Ground* gp = GET_GROUND(arg0);
HSD_JObj* jobj = arg0->hsd_obj;
HSD_ImageDesc* image = grPu_803E6E20;
HSD_MObjSetToonTextureImage(image);
lb_80011C18(jobj, 0x1000);
grPura_80213250(jobj);
HSD_MObjSetToonTextureImage(0);
grAnime_801C8138(arg0, gp->map_id, 0);
Ground* temp_r31;
HSD_JObj* temp_r30;
PAD_STACK(8);

temp_r31 = arg0->user_data;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET_GROUND (we are pretty sure they used it everywhere, and not having it can affect codegen in strange ways. this time it didn't but good to stay consistent)

temp_r30 = arg0->hsd_obj;
*(void (**)(HSD_GObj*, int))((u8*)arg0 + 0x1C) = fn_802130D0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arg0->render_cb

HSD_MObjSetToonTextureImage(&grPu_803E7620);
lb_80011C18(temp_r30, 0x1000U);
grPura_80213250(temp_r30);
HSD_MObjSetToonTextureImage(NULL);
grAnime_801C8138((HSD_GObj* ) arg0, temp_r31->map_id, 0);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no cast required between HSD_GObj and Ground_GObj, they're the same type

}

bool grPura_80212314(Ground_GObj* arg0)
Expand Down
9 changes: 8 additions & 1 deletion src/melee/it/items/itoldkuri.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ void it_802D73F0(Item_GObj* gobj)
it_802D747C(gobj);
}

void it_802D747C(Item_GObj* gobj) {}
void it_802D747C(Item_GObj* gobj)
{
u8 _[8];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PAD_STACK(8); preferred. Makes me think this might be an inline, because the same code (and padding) is present in itOldkuri_UnkMotion9_Anim.

it_8027CAD8(gobj);
it_8027C0A8(gobj, 0.0f, 5.0f);
it_802756E0(gobj);
it_802D848C(gobj, 0, 2);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 = ITEM_ANIM_UPDATE

}

bool itOldkuri_UnkMotion0_Anim(Item_GObj* gobj)
{
Expand Down
Loading