Skip to content

Instantly share code, notes, and snippets.

@Dragorn421
Created August 24, 2020 15:27
Show Gist options
  • Save Dragorn421/13c39d4b58055a76530f058cf608fecd to your computer and use it in GitHub Desktop.
Save Dragorn421/13c39d4b58055a76530f058cf608fecd to your computer and use it in GitHub Desktop.
Lame mips_to_c wrapper for mips_to_c-ing a whole file
#!/usr/bin/env python3
import sys
import argparse
from pathlib import Path
import subprocess
import re
# input arguments
parser = argparse.ArgumentParser(description='Lame mips_to_c wrapper.')
parser.add_argument('c_file', help='C file')
#parser.add_argument('--sum', default=max, help='')
args = parser.parse_args()
c_file_path = Path(args.c_file).resolve()
# find directories
dir = c_file_path.parent
decomp_dir = None
mips_to_c_dir = None
while not (decomp_dir and mips_to_c_dir):
if dir.parent == dir:
if not decomp_dir:
print('The C file is not in a subdirectory of the root decomp directory')
if not mips_to_c_dir:
print('Cannot find mips_to_c directory with mips_to_c.py inside in the parent directories')
sys.exit(1)
if not decomp_dir and (dir / '.git').is_dir() and (dir / 'zelda_ocarina_mq_dbg.z64').is_file():
decomp_dir = dir
print('Found .git and zelda_ocarina_mq_dbg.z64 in', decomp_dir)
print('Assuming it is the root decomp directory')
if not mips_to_c_dir and (dir / 'mips_to_c').is_dir() and (dir / 'mips_to_c' / 'mips_to_c.py').is_file():
mips_to_c_dir = dir / 'mips_to_c'
print('Found directory named mips_to_c with mips_to_c.py inside', mips_to_c_dir)
print('Assuming it is the mips_to_c directory')
dir = dir.parent
del dir
# preprocess c file
args = (
'gcc -E -o /dev/stdout -D _LANGUAGE_C'.split(' ')
+ ['-I', str(decomp_dir / 'include'), str(c_file_path)]
)
print('args =', args)
p = subprocess.Popen(args, stdout=subprocess.PIPE, universal_newlines=True)
stdout, stderr = p.communicate()
if p.returncode:
print('gcc exited with', p.returncode)
print('stdout =', stdout)
print('stderr =', stderr)
sys.exit(1)
out = stdout
out = re.sub(r'#[^\n]*\n', r'', out)
out = re.sub(r'__builtin_va_list(?: [a-zA-Z0-9_]*)?', r'...', out)
preprocessed_c_file_path = c_file_path.parent / f'{c_file_path.stem}.i'
with preprocessed_c_file_path.open('w') as f:
f.write(out)
# decompile
with c_file_path.open() as f_in:
with (c_file_path.parent / f'{c_file_path.stem}_dec.c').open('w') as f_out:
for line in f_in:
m = re.match(r'^#pragma GLOBAL_ASM\("(.*)"\)\n$', line)
if m:
asm_file_path = decomp_dir / m.group(1)
print(asm_file_path)
p = subprocess.Popen(
[ 'python3', str(mips_to_c_dir / 'mips_to_c.py'),
'--context', str(preprocessed_c_file_path),
str(asm_file_path)
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
)
stdout, stderr = p.communicate()
if p.returncode and 'Run with --no-andor to disable detection' in stdout:
f_out.write('/*\n')
f_out.write(f'mips_to_c exited with {p.returncode}\n')
if stdout:
f_out.write('stdout:\n')
f_out.write(stdout)
f_out.write('\n')
else:
f_out.write('no stdout\n')
if stderr:
f_out.write('stderr:\n')
f_out.write(stderr)
f_out.write('\n')
else:
f_out.write('no stderr\n')
f_out.write('*/\n')
f_out.write('// trying again with --no-andor\n')
p = subprocess.Popen(
[ 'python3', str(mips_to_c_dir / 'mips_to_c.py'),
'--context', str(preprocessed_c_file_path),
'--no-andor',
str(asm_file_path)
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
)
stdout, stderr = p.communicate()
if p.returncode:
print('mips_to_c exited with', p.returncode, '(skipping)')
f_out.write(line)
f_out.write('/*\n')
f_out.write(f'mips_to_c exited with {p.returncode}\n')
if stdout:
f_out.write('stdout:\n')
f_out.write(stdout)
f_out.write('\n')
else:
f_out.write('no stdout\n')
if stderr:
f_out.write('stderr:\n')
f_out.write(stderr)
f_out.write('\n')
else:
f_out.write('no stderr\n')
f_out.write('*/\n')
else:
f_out.write('#if 0\n')
f_out.write(line)
f_out.write('#else\n')
f_out.write(stdout)
f_out.write('\n')
f_out.write('#endif\n')
else:
f_out.write(line)
/*
the following is the contents of the z_en_box_dec.c file generated alongside the original z_en_box.c by running
oot$ ./path/to/helper.py src/overlays/actors/ovl_En_Box/z_en_box.c
from the root directory in the oot decomp repository
*/
#include "z_en_box.h"
#define FLAGS 0x00000000
#define THIS ((EnBox*)thisx)
void EnBox_Init(Actor* thisx, GlobalContext* globalCtx);
void EnBox_Destroy(Actor* thisx, GlobalContext* globalCtx);
void EnBox_Update(Actor* thisx, GlobalContext* globalCtx);
void EnBox_Draw(Actor* thisx, GlobalContext* globalCtx);
/*
const ActorInit En_Box_InitVars = {
Chest,
ACTORTYPE_CHEST,
FLAGS,
OBJECT_BOX,
sizeof(EnBox),
(ActorFunc)EnBox_Init,
(ActorFunc)EnBox_Destroy,
(ActorFunc)EnBox_Update,
(ActorFunc)EnBox_Draw,
};
*/
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C8DC0.s")
#else
void func_809C8DC0(void *arg0, ?32 arg1) {
arg0->unk1B4 = arg1;
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C8DC8.s")
#else
void func_809C8DC8(Actor *arg0, CollisionContext *arg1) {
CollisionPoly *sp30;
? sp2C;
f32 sp24;
? sp20;
Actor *temp_a3;
f32 temp_f0;
sp20.unk0 = (s32) arg0->posRot.pos.x;
temp_a3 = arg0;
sp20.unk4 = (s32) arg0->posRot.pos.y;
sp20.unk8 = (s32) arg0->posRot.pos.z;
arg0 = temp_a3;
sp24 = sp24 + 1.0f;
temp_f0 = func_8003C9A4(arg1 + 0x7C0, &sp30, (void *) &sp2C, temp_a3, &sp20);
if (temp_f0 != -32000.0f) {
arg0->posRot.pos.y = temp_f0;
}
}
#endif
/*
mips_to_c exited with 1
stdout:
Failed to decompile function EnBox_Init:
Complex control flow; node assumed to be part of &&/|| wasn't. Run with --no-andor to disable detection of &&/|| and try again.
no stderr
*/
// trying again with --no-andor
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/EnBox_Init.s")
#else
void EnBox_Init(Actor *thisx, GlobalContext *globalCtx) {
GenericAnimationHeader *sp4C;
s32 sp48;
f32 sp44;
f32 sp40;
SkelAnime *sp34;
DynaCollisionContext *sp30;
DynaCollisionContext *temp_a1;
GenericAnimationHeader *temp_a0;
SkelAnime *temp_a1_2;
s16 temp_v0_6;
u32 temp_v0;
u8 temp_t0;
u8 temp_v0_2;
u8 temp_v0_3;
u8 temp_v0_4;
u8 temp_v0_5;
u8 temp_v0_7;
temp_a0 = *(&D_809CA800 + (gSaveContext.linkAge * 4));
sp48 = 0;
sp44 = 0.0f;
sp4C = temp_a0;
sp40 = (f32) SkelAnime_GetFrameCount(temp_a0);
Actor_ProcessInitChain(thisx, &D_809CA810);
DynaPolyInfo_SetActorMove((DynaPolyActor *) thisx, 0);
DynaPolyInfo_Alloc((void *)0x6005FC8, (void *) &sp48);
temp_a1 = &globalCtx->colCtx.dyna;
sp30 = temp_a1;
temp_v0 = DynaPolyInfo_RegisterActor(globalCtx, temp_a1, thisx, sp48);
thisx->unk14C = temp_v0;
func_8003ECA8(globalCtx, temp_a1, temp_v0);
thisx->unk1F6 = (u8)0U;
thisx->unk1F9 = (u8) (((s32) thisx->params >> 0xC) & 0xF);
thisx->unk1FA = (u8)0;
thisx->unk1FB = (u8)0;
thisx->gravity = -5.5f;
thisx->unk1F8 = (u8) thisx->posRot.rot.z;
thisx->minVelocityY = -50.0f;
if (Flags_GetTreasure(globalCtx, (s32) (thisx->params & 0x1F)) != 0) {
thisx->unk1F7 = (u8)0xFF;
thisx->unk1FA = (u8)0x64;
func_809C8DC0(thisx, &func_809C9D70);
thisx->unk1F6 = (u8) (thisx->unk1F6 | 0x10);
sp44 = sp40;
} else {
temp_v0_2 = thisx->unk1F9;
if (temp_v0_2 != 3) {
if (temp_v0_2 == 8) {
block_4:
if (Flags_GetSwitch(globalCtx, (s32) thisx->unk1F8) == 0) {
func_8003EBF8(globalCtx, sp30, (s32) thisx->unk14C);
if (Math_Rand_ZeroOne() < 0.5f) {
thisx->unk1F6 = (u8) (thisx->unk1F6 | 4);
}
thisx->unk1A8 = -0xC;
func_809C8DC0(thisx, &func_809C9630);
thisx->unk1F7 = (u8)0;
thisx->unk1F6 = (u8) (thisx->unk1F6 | 1);
thisx->flags = (u32) (thisx->flags | 0x10);
} else {
block_8:
temp_v0_3 = thisx->unk1F9;
if (temp_v0_3 != 1) {
if (temp_v0_3 == 7) {
block_10:
if (Flags_GetClear(globalCtx, (s32) thisx->room) == 0) {
func_809C8DC0(thisx, &func_809C990C);
func_8003EBF8(globalCtx, sp30, (s32) thisx->unk14C);
thisx->unk1F6 = (u8) (thisx->unk1F6 | 1);
thisx->posRot.pos.y = (f32) (thisx->initPosRot.pos.y - 50.0f);
thisx->unk1F7 = (u8)0;
thisx->flags = (u32) (thisx->flags | 0x10);
} else {
block_12:
temp_v0_4 = thisx->unk1F9;
if (temp_v0_4 != 9) {
if (temp_v0_4 == 0xA) {
block_14:
func_809C8DC0(thisx, &func_809C9700);
thisx->flags = (u32) (thisx->flags | 0x2000000);
func_8003EBF8(globalCtx, sp30, (s32) thisx->unk14C);
thisx->unk1F6 = (u8) (thisx->unk1F6 | 1);
thisx->posRot.pos.y = (f32) (thisx->initPosRot.pos.y - 50.0f);
thisx->unk1F7 = (u8)0;
thisx->flags = (u32) (thisx->flags | 0x10);
} else {
if (temp_v0_4 == 0xB) {
if (Flags_GetSwitch(globalCtx, (s32) thisx->unk1F8) == 0) {
func_809C8DC0(thisx, &func_809C988C);
func_8003EBF8(globalCtx, sp30, (s32) thisx->unk14C);
thisx->unk1F6 = (u8) (thisx->unk1F6 | 1);
thisx->posRot.pos.y = (f32) (thisx->initPosRot.pos.y - 50.0f);
thisx->unk1F7 = (u8)0;
thisx->flags = (u32) (thisx->flags | 0x10);
} else {
block_18:
temp_v0_5 = thisx->unk1F9;
if (temp_v0_5 != 4) {
if (temp_v0_5 == 6) {
block_20:
thisx->flags = (u32) (thisx->flags | 0x80);
}
} else {
goto block_20;
}
func_809C8DC0(thisx, &func_809C9B28);
temp_t0 = thisx->unk1F6 | 1;
thisx->unk1F6 = temp_t0;
thisx->unk1F6 = (u8) (temp_t0 | 0x10);
}
} else {
goto block_18;
}
}
} else {
goto block_14;
}
}
} else {
goto block_12;
}
} else {
goto block_10;
}
}
} else {
goto block_8;
}
} else {
goto block_4;
}
}
thisx->shape.rot.z = (u16)0;
temp_v0_6 = thisx->shape.rot.z;
thisx->posRot.rot.y = (s16) (thisx->posRot.rot.y + 0x8000);
thisx->posRot.rot.z = temp_v0_6;
thisx->initPosRot.rot.z = temp_v0_6;
temp_a1_2 = thisx + 0x164;
sp34 = temp_a1_2;
SkelAnime_Init(globalCtx, temp_a1_2, (void *)0x60047D8, (AnimationHeader *) sp4C, thisx + 0x1B8, thisx + 0x1D6, 5);
SkelAnime_ChangeAnim(sp34, (AnimationHeader *) sp4C, 1.5f, (bitwise f32) (bitwise s32) sp44, sp40, 2, 0.0f);
temp_v0_7 = thisx->unk1F9;
if (temp_v0_7 == 5) {
block_26:
Actor_SetScale(thisx, 0.005f);
Actor_SetHeight(thisx, 20.0f);
return;
}
if (temp_v0_7 == 6) {
goto block_26;
}
if (temp_v0_7 == 7) {
goto block_26;
}
if (temp_v0_7 == 8) {
goto block_26;
}
Actor_SetScale(thisx, 0.01f);
Actor_SetHeight(thisx, 40.0f);
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/EnBox_Destroy.s")
#else
void EnBox_Destroy(Actor *thisx, GlobalContext *globalCtx) {
DynaPolyInfo_Free(globalCtx, &globalCtx->colCtx.dyna, thisx->unk14C);
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C92F4.s")
#else
void *func_809C92F4(void *arg0, void *arg1, void *arg2, void *arg3) {
f32 sp24;
s16 sp22;
s32 temp_v0;
sp24 = Math_Rand_ZeroOne() * 25.0f;
temp_v0 = (s32) (Math_Rand_ZeroOne() * 65536.0f);
sp22 = (s16) temp_v0;
arg1->unk0 = (s32) arg0->unk24;
arg1->unk4 = (s32) arg0->unk28;
arg1->unk8 = (s32) arg0->unk2C;
arg1->unk0 = (f32) ((bitwise f32) arg1->unk0 + (Math_Sins((s16) ((s32) (temp_v0 << 0x10) >> 0x10)) * sp24));
arg1->unk8 = (f32) ((bitwise f32) arg1->unk8 + (Math_Coss(sp22) * sp24));
arg2->unk4 = 1.0f;
arg2->unk0 = Math_Sins(sp22);
arg2->unk8 = Math_Coss(sp22);
arg3->unk0 = 0.0f;
arg3->unk4 = 0.0f;
arg3->unk8 = 0.0f;
return arg3;
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C93F8.s")
#else
void func_809C93F8(s32 arg0, GlobalContext *arg1) {
? sp60;
? sp54;
? sp48;
s32 temp_s0;
s32 phi_s0;
phi_s0 = 0;
loop_1:
func_809C92F4(arg0, &sp60, &sp54, &sp48);
func_8002873C(arg1, (Vec3f *) &sp60, (Vec3f *) &sp54, (Vec3f *) &sp48, 0x64, 0x1E, 0xF);
temp_s0 = phi_s0 + 1;
phi_s0 = temp_s0;
if (temp_s0 != 0x14) {
goto loop_1;
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C94AC.s")
#else
f32 func_809C94AC(void *arg0, GlobalContext *arg1) {
f32 temp_f0;
s32 temp_v0;
u8 temp_t2;
u8 temp_t8;
temp_t8 = arg0->unk1F6 & -2;
arg0->unk1F7 = (u8)0xFF;
arg0->unk1F6 = temp_t8;
if ((arg0->unk88 & 1) != 0) {
temp_t2 = temp_t8 | 2;
temp_v0 = temp_t2 & 0xFF;
arg0->unk1F6 = temp_t2;
if ((temp_v0 & 4) != 0) {
arg0->unk1F6 = (u8) (temp_v0 & 0xFFFB);
} else {
arg0->unk1F6 = (u8) (temp_v0 | 4);
}
if (arg0->unk1F9 == 3) {
arg0->unk60 = (f32) (-arg0->unk60 * 0.55f);
} else {
arg0->unk60 = (f32) (-arg0->unk60 * 0.65f);
}
if (arg0->unk60 < 5.5f) {
arg0->unkB8 = (u16)0;
arg0->unk28 = (f32) arg0->unk80;
func_809C8DC0(arg0, &func_809C9B28);
func_800803F0(arg1, arg0->unk1AE);
}
Audio_PlaySoundGeneral((u16)0x2856U, arg0 + 0xE4, 4U, &D_801333E0, &D_801333E0, &D_801333E8);
func_809C93F8(arg0, arg1);
}
temp_f0 = arg0->unk28 - arg0->unk80;
if ((arg0->unk1F6 & 4) != 0) {
arg0->unkB8 = (s16) (s32) (temp_f0 * 50.0f);
return temp_f0;
}
arg0->unkB8 = (s16) (s32) (-temp_f0 * 50.0f);
return temp_f0;
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C9630.s")
#else
void func_809C9630(Actor *arg0, GlobalContext *arg1) {
s16 temp_v0;
s32 temp_v0_2;
temp_v0 = arg0->params & 0x1F;
if ((s32) temp_v0 >= 0x14) {
if ((s32) temp_v0 < 0x20) {
func_8002F5F0(arg0, arg1);
}
}
temp_v0_2 = arg0->unk1A8;
if (temp_v0_2 >= 0) {
func_809C8DC0(arg0, &func_809C94AC);
arg0->unk1AC = func_800800F8(arg1, (u16)0x1194, (u16)0x270F, arg0, 0);
func_8003EC50(arg1, &arg1->colCtx.dyna, arg0->unk14C);
return;
}
if (temp_v0_2 >= -0xB) {
arg0->unk1A8 = (s32) (temp_v0_2 + 1);
return;
}
if (Flags_GetSwitch(arg1, (s32) arg0->unk1F8) != 0) {
arg0->unk1A8 = (s32) (arg0->unk1A8 + 1);
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C9700.s")
#else
void func_809C9700(Actor *arg0, GlobalContext *arg1) {
void *sp20;
GlobalContext *temp_a2;
s16 temp_v0;
s32 temp_v0_3;
u16 temp_v1_2;
u8 temp_v0_2;
void *temp_v1;
u8 phi_v0;
temp_v0 = arg0->params & 0x1F;
if ((s32) temp_v0 >= 0x14) {
if ((s32) temp_v0 < 0x20) {
sp20 = arg1->unk1C44;
arg1 = arg1;
func_8002F5F0(arg0, arg1);
}
}
sp20 = arg1->unk1C44;
arg1 = arg1;
temp_v1 = arg1->unk1C44;
temp_a2 = arg1;
if (22500.0f < Math3D_Vec3fDistSq((Vec3f *) &arg0->posRot, arg1->unk1C44 + 0x24)) {
block_18:
arg0->unk1FB = (u8)0U;
} else {
temp_v0_2 = arg0->unk1FB;
phi_v0 = temp_v0_2;
if (temp_v0_2 == 0) {
temp_v0_3 = temp_v1->unk680;
if ((temp_v0_3 << 7) >= 0) {
temp_v1->unk680 = (s32) (temp_v0_3 | 0x800000);
return;
}
arg0->unk1FB = (u8)1U;
phi_v0 = (u8)1U & 0xFF;
}
if (phi_v0 == 1) {
func_8010BD58(temp_a2, (u16)1U);
arg0->unk1FB = (u8)2U;
return;
}
if (phi_v0 == 2) {
if (temp_a2->msgCtx.unk_E3EE == 4) {
temp_v1_2 = temp_a2->msgCtx.unk_E3EC;
if ((temp_v1_2 != 8) || (arg0->unk1F9 != 9)) {
if (temp_v1_2 == 9) {
if (arg0->unk1F9 == 0xA) {
block_17:
arg0->flags = (u32) (arg0->flags & 0xFDFFFFFF);
arg1 = temp_a2;
func_809C8DC0(arg0, &func_809C99C4, temp_a2);
func_80080480(arg1, arg0);
arg0->unk1A8 = 0;
}
}
} else {
goto block_17;
}
goto block_18;
}
}
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C988C.s")
#else
void func_809C988C(Actor *arg0, GlobalContext *arg1) {
s16 temp_v0;
temp_v0 = arg0->params & 0x1F;
if ((s32) temp_v0 >= 0x14) {
if ((s32) temp_v0 < 0x20) {
func_8002F5F0(arg0, arg1);
}
}
if (Flags_GetSwitch(arg1, (s32) arg0->unk1F8) != 0) {
func_80080480(arg1, arg0);
func_809C8DC0(arg0, &func_809C99C4);
arg0->unk1A8 = -0x1E;
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C990C.s")
#else
void func_809C990C(Actor *arg0, GlobalContext *arg1) {
s16 temp_v0;
temp_v0 = arg0->params & 0x1F;
if ((s32) temp_v0 >= 0x14) {
if ((s32) temp_v0 < 0x20) {
func_8002F5F0(arg0, arg1);
}
}
if (Flags_GetTempClear(arg1, (s32) arg0->room) != 0) {
if (func_8008E988(arg1) == 0) {
Flags_SetClear(arg1, (s32) arg0->room);
func_809C8DC0(arg0, &func_809C99C4);
func_80080480(arg1, arg0);
if (func_80080728(arg1, arg0->type) != 0) {
arg0->unk1A8 = 0;
return;
}
arg0->unk1A8 = -0x1E;
}
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C99C4.s")
#else
void func_809C99C4(void *arg0, GlobalContext *arg1) {
if ((func_8005B198() == arg0->unk2) || (arg0->unk1A8 != 0)) {
func_809C8DC0(arg0, &func_809C9A7C);
arg0->unk1A8 = 0;
Actor_Spawn(arg1 + 0x1C24, arg1, (u16)0x8C, (bitwise f32) arg0->unk8, arg0->unkC, arg0->unk10, 0, 0, 0, 0x11);
Audio_PlaySoundGeneral((u16)0x287BU, arg0 + 0xE4, 4U, &D_801333E0, &D_801333E0, &D_801333E8);
} else {
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C9A7C.s")
#else
s32 func_809C9A7C(void *arg0, GlobalContext *arg1) {
s32 temp_a2;
s32 temp_v0;
temp_a2 = arg0->unk14C;
arg0 = arg0;
func_8003EC50(arg1, arg1 + 0x810, temp_a2);
temp_v0 = arg0->unk1A8;
if (temp_v0 < 0) {
arg0->unk1A8 = (s32) (temp_v0 + 1);
return temp_v0;
}
if (temp_v0 < 0x28) {
arg0->unk1A8 = (s32) (temp_v0 + 1);
arg0->unk28 = (f32) (arg0->unk28 + 1.25f);
return temp_v0;
}
if (temp_v0 < 0x3C) {
arg0->unk1F7 = (u8) (arg0->unk1F7 + 0xC);
arg0->unk1A8 = (s32) (temp_v0 + 1);
arg0->unk28 = (f32) arg0->unkC;
return temp_v0;
}
return func_809C8DC0(arg0, &func_809C9B28, arg0);
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C9B28.s")
#else
void func_809C9B28(Actor *arg0, GlobalContext *arg1) {
GenericAnimationHeader *sp60;
f32 sp4C;
GenericAnimationHeader *temp_a0;
s16 temp_v0;
u8 temp_v0_2;
s32 phi_v0;
temp_v0 = arg0->unk1F4;
arg0->unk1F7 = (u8)0xFF;
arg0->unk1F6 = (u8) (arg0->unk1F6 | 1);
if (temp_v0 != 0) {
if ((s32) temp_v0 < 0) {
phi_v0 = 2;
} else {
phi_v0 = 0;
}
temp_a0 = *(&D_809CA800 + ((phi_v0 * 4) + (gSaveContext.linkAge * 4)));
sp60 = temp_a0;
SkelAnime_ChangeAnim(arg0 + 0x164, (AnimationHeader *) sp60, 1.5f, 0.0f, (f32) SkelAnime_GetFrameCount(temp_a0), 2, 0.0f);
func_809C8DC0(arg0, &func_809C9D70);
if ((s32) arg0->unk1F4 > 0) {
temp_v0_2 = arg0->unk1F9;
if (temp_v0_2 != 5) {
if (temp_v0_2 != 6) {
if (temp_v0_2 != 7) {
if (temp_v0_2 != 8) {
Actor_SpawnAttached(arg1 + 0x1C24, arg0, arg1, (u16)0xAA, arg0->posRot.pos.x, arg0->posRot.pos.y, arg0->posRot.pos.z, (?32) arg0->shape.rot.x, (?32) arg0->shape.rot.y, (?32) arg0->shape.rot.z, -1);
func_800F5C64(0x92B);
}
}
}
}
}
osSyncPrintf((const char *) "Actor_Environment_Tbox_On() %d\n", arg0->params & 0x1F);
Flags_SetTreasure(arg1, (s32) (arg0->params & 0x1F));
return;
}
func_8002DBD0(arg0, (Vec3f *) &sp4C, arg1->unk1C44 + 0x24);
if (-50.0f < sp54) {
if (sp54 < 0.0f) {
if (fabsf(sp50) < 10.0f) {
if (fabsf(sp4C) < 20.0f) {
if (func_8002DFC8(arg0, (u16)0x3000, arg1) != 0) {
func_8002F554(arg0, arg1, 0 - (((s32) arg0->params >> 5) & 0x7F));
}
}
}
}
}
if (Flags_GetTreasure(arg1, (s32) (arg0->params & 0x1F)) != 0) {
func_809C8DC0(arg0, &func_809C9D70);
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C9D70.s")
#else
s16 func_809C9D70(void *arg0, ? arg1) {
u16 sp2E;
SkelAnime *sp28;
SkelAnime *temp_a0;
f32 temp_f0;
s16 temp_v0;
s16 temp_v0_2;
f32 phi_f2;
s16 phi_return;
arg0->unk4 = (s32) (arg0->unk4 & -0x81);
temp_a0 = arg0 + 0x164;
sp28 = temp_a0;
if (SkelAnime_FrameUpdateMatrix(temp_a0) != 0) {
temp_v0 = arg0->unk1F4;
if ((s32) temp_v0 <= 0) {
if ((s32) temp_v0 < -0x77) {
return (s16) Math_ApproxF(arg0 + 0x1B0, 0.0f, 0.05f);
}
arg0->unk1F4 = (s16) (temp_v0 - 1);
return temp_v0;
}
if ((s32) temp_v0 >= 0x78) {
return (s16) Math_ApproxF(arg0 + 0x1B0, 0.0f, 0.05f);
}
arg0->unk1F4 = (s16) (temp_v0 + 1);
return temp_v0;
}
sp2E = (u16)0U;
if (func_800A56C8(sp28, 30.0f) != 0) {
sp2E = (u16)0x281FU;
} else {
if (func_800A56C8(sp28, 90.0f) != 0) {
sp2E = (u16)0x2820U;
}
}
if (sp2E != 0) {
Audio_PlaySoundGeneral(sp2E, arg0 + 0xE4, 4U, &D_801333E0, &D_801333E0, &D_801333E8);
}
temp_v0_2 = arg0->unk184->unk16;
phi_return = temp_v0_2;
if ((s32) temp_v0_2 > 0) {
arg0->unk1B0 = (f32) ((f32) (0x7D00 - temp_v0_2) * 0.00006f);
temp_f0 = arg0->unk1B0;
if (temp_f0 < 0.0f) {
phi_f2 = 0.0f;
block_18:
arg0->unk1B0 = phi_f2;
phi_return = (bitwise s16) temp_f0;
} else {
phi_f2 = 1.0f;
phi_return = (bitwise s16) temp_f0;
if (1.0f < temp_f0) {
goto block_18;
}
}
}
return phi_return;
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809C9EF8.s")
#else
void func_809C9EF8(Actor *arg0, s32 arg1) {
f32 sp54;
f32 sp4C;
f32 sp48;
f32 sp44;
f32 sp40;
? sp34;
f32 sp30;
f32 sp28;
f32 temp_f0;
f32 temp_f0_2;
f32 temp_f0_3;
f32 temp_f0_4;
f32 temp_f0_5;
f32 temp_f12;
f32 temp_f12_2;
f32 temp_f12_3;
f32 temp_f12_4;
f32 temp_f2;
f32 temp_f2_2;
f32 temp_f2_3;
u8 temp_v0;
f32 phi_f12;
sp40.unk0 = (s32) D_809CA814.unk0;
sp40.unk4 = (s32) D_809CA814.unk4;
sp40.unk8 = (s32) D_809CA814.unk8;
sp34.unk0 = (s32) D_809CA820.unk0;
sp34.unk4 = (s32) D_809CA820.unk4;
sp34.unk8 = (s32) D_809CA820.unk8;
arg0->unk1FA = (u8) (arg0->unk1FA + 1);
func_8002F974(arg0, (u16)0x31F1U);
if (Math_Rand_ZeroOne() < 0.3f) {
temp_f0 = Math_Rand_ZeroOne();
sp4C.unk0 = (bitwise s32) arg0->posRot.pos.x;
sp4C.unk4 = (bitwise s32) arg0->posRot.pos.y;
temp_f2 = (temp_f0 + temp_f0) - 1.0f;
sp4C.unk8 = (bitwise s32) arg0->posRot.pos.z;
temp_v0 = arg0->unk1F9;
if ((((temp_v0 == 5) || (temp_v0 == 6)) || (temp_v0 == 7)) || (temp_v0 == 8)) {
sp30 = temp_f2;
temp_f12_3 = temp_f2 * 10.0f;
sp4C = sp4C + (temp_f12_3 * Math_Sins((s16) ((s32) ((arg0->posRot.rot.y + 0x4000) << 0x10) >> 0x10)));
sp28 = temp_f12_3;
sp54 = sp54 + (temp_f12_3 * Math_Coss((s16) ((s32) ((arg0->posRot.rot.y + 0x4000) << 0x10) >> 0x10)));
temp_f0_4 = Math_Rand_ZeroOne(temp_f12_3);
temp_f2_3 = (temp_f0_4 + temp_f0_4) - 1.0f;
sp30 = temp_f2_3;
temp_f0_5 = Math_Sins(arg0->posRot.rot.y);
temp_f12_4 = temp_f2_3 * 0.8f;
sp44 = 1.8f;
sp40 = temp_f0_5 * temp_f12_4;
sp28 = temp_f12_4;
sp48 = Math_Coss(arg0->posRot.rot.y) * temp_f12_4;
phi_f12 = temp_f12_4;
} else {
sp30 = temp_f2;
temp_f12 = temp_f2 * 20.0f;
sp4C = sp4C + (temp_f12 * Math_Sins((s16) ((s32) ((arg0->posRot.rot.y + 0x4000) << 0x10) >> 0x10)));
sp28 = temp_f12;
sp54 = sp54 + (temp_f12 * Math_Coss((s16) ((s32) ((arg0->posRot.rot.y + 0x4000) << 0x10) >> 0x10)));
temp_f0_2 = Math_Rand_ZeroOne(temp_f12);
temp_f2_2 = (temp_f0_2 + temp_f0_2) - 1.0f;
sp30 = temp_f2_2;
temp_f0_3 = Math_Sins(arg0->posRot.rot.y);
temp_f12_2 = temp_f2_2 * 1.6f;
sp44 = 1.8f;
sp40 = temp_f0_3 * temp_f12_2;
sp28 = temp_f12_2;
sp48 = Math_Coss(arg0->posRot.rot.y) * temp_f12_2;
phi_f12 = temp_f12_2;
}
func_8002AA44(phi_f12, arg1, &sp4C, &sp40, &sp34, 0x96);
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/EnBox_Update.s")
#else
void EnBox_Update(Actor *thisx, GlobalContext *globalCtx) {
u8 temp_v0;
u8 temp_v0_2;
temp_v0 = thisx->unk1F6;
if ((temp_v0 & 0x10) != 0) {
thisx->unk1F6 = (u8) (temp_v0 & 0xFFEF);
func_809C8DC8(globalCtx);
}
thisx->unk1B4(thisx, globalCtx);
if ((thisx->unk1F6 & 1) == 0) {
Actor_MoveForward(thisx);
func_8002E4B4(globalCtx, thisx, 0.0f, 0.0f, 0.0f, 0x1C);
}
temp_v0_2 = thisx->unk1F9;
if ((((temp_v0_2 == 5) || (temp_v0_2 == 6)) || (temp_v0_2 == 7)) || (temp_v0_2 == 8)) {
Actor_SetHeight(thisx, 20.0f);
} else {
Actor_SetHeight(thisx, 40.0f);
}
if ((((s32) thisx->params >> 5) & 0x7F) == 0x7C) {
if (&func_809C9D70 == thisx->unk1B4) {
if (45.0f < thisx->unk17C) {
if ((s32) thisx->unk1FA < 0x64) {
func_809C9EF8(thisx, globalCtx);
}
}
}
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809CA2D8.s")
#else
void func_809CA2D8(void *arg0, s32 arg1, ? arg2, ? arg3, void *arg4, void *arg5) {
void *sp24;
void *sp18;
void *temp_v0;
void *temp_v0_2;
void *temp_v0_3;
void *temp_v0_4;
void *temp_v0_5;
void *temp_v0_6;
if (arg1 == 1) {
temp_v0 = *arg5;
*arg5 = (void *) (temp_v0 + 8);
*temp_v0 = 0xDA380003;
sp24 = temp_v0;
sp24->unk4 = Matrix_NewMtx(*arg0, (char *) "../z_en_box.c", 0x5D4);
if (arg4->unk1F9 == 2) {
temp_v0_3 = *arg5;
*arg5 = (void *) (temp_v0_3 + 8);
temp_v0_3->unk4 = 0x6000AE8;
temp_v0_3->unk0 = 0xDE000000;
return;
}
temp_v0_2 = *arg5;
*arg5 = (void *) (temp_v0_2 + 8);
temp_v0_2->unk4 = 0x60006F0;
temp_v0_2->unk0 = 0xDE000000;
return;
}
if (arg1 == 3) {
temp_v0_4 = *arg5;
*arg5 = (void *) (temp_v0_4 + 8);
*temp_v0_4 = 0xDA380003;
sp18 = temp_v0_4;
sp18->unk4 = Matrix_NewMtx(*arg0, (char *) "../z_en_box.c", 0x5DE);
if (arg4->unk1F9 != 2) {
temp_v0_5 = *arg5;
*arg5 = (void *) (temp_v0_5 + 8);
temp_v0_5->unk4 = 0x60010C0;
temp_v0_5->unk0 = 0xDE000000;
return;
}
temp_v0_6 = *arg5;
*arg5 = (void *) (temp_v0_6 + 8);
temp_v0_6->unk4 = 0x6001678;
temp_v0_6->unk0 = 0xDE000000;
}
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809CA448.s")
#else
void *func_809CA448(GraphicsContext *arg0) {
void *sp18;
void *temp_v0;
void *phi_v1;
temp_v0 = Graph_Alloc(arg0, 8U);
phi_v1 = temp_v0;
if (temp_v0 == 0) {
sp18 = temp_v0;
__assert((const char *) "gfxp != NULL", (const char *) "../z_en_box.c", 0x5F8);
phi_v1 = sp18;
}
phi_v1->unk0 = 0xDF000000;
phi_v1->unk4 = 0;
return phi_v1;
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809CA4A0.s")
#else
void *func_809CA4A0(GraphicsContext *arg0) {
void *sp18;
void *temp_v0;
void *temp_v0_2;
void *phi_v1;
temp_v0 = Graph_Alloc(arg0, 0x10U);
phi_v1 = temp_v0;
if (temp_v0 == 0) {
sp18 = temp_v0;
__assert((const char *) "gfxp != NULL", (const char *) "../z_en_box.c", 0x60A);
phi_v1 = sp18;
}
temp_v0_2 = phi_v1;
temp_v0_2->unk0 = 0xE200001C;
temp_v0_2->unk4 = 0xC81049F8;
phi_v1->unk8 = 0xDF000000;
phi_v1->unkC = 0;
return phi_v1;
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/func_809CA518.s")
#else
void *func_809CA518(GraphicsContext *arg0) {
void *sp18;
void *temp_v0;
void *temp_v0_2;
void *phi_v1;
temp_v0 = Graph_Alloc(arg0, 0x10U);
phi_v1 = temp_v0;
if (temp_v0 == 0) {
sp18 = temp_v0;
__assert((const char *) "gfxp != NULL", (const char *) "../z_en_box.c", 0x61C);
phi_v1 = sp18;
}
temp_v0_2 = phi_v1;
temp_v0_2->unk0 = 0xE200001C;
temp_v0_2->unk4 = 0xC8112078;
phi_v1->unk8 = 0xDF000000;
phi_v1->unkC = 0;
return phi_v1;
}
#endif
/*
mips_to_c exited with 1
stdout:
Failed to decompile function EnBox_Draw:
Complex control flow; node assumed to be part of &&/|| wasn't. Run with --no-andor to disable detection of &&/|| and try again.
no stderr
*/
// trying again with --no-andor
#if 0
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Box/EnBox_Draw.s")
#else
void EnBox_Draw(Actor *thisx, GlobalContext *globalCtx) {
Gfx *sp58;
Gfx *sp4C;
Gfx *sp40;
Gfx *sp3C;
Gfx *temp_v0_10;
Gfx *temp_v0_3;
Gfx *temp_v0_4;
Gfx *temp_v0_6;
Gfx *temp_v0_7;
Gfx *temp_v0_8;
Gfx *temp_v0_9;
GraphicsContext *temp_a1;
GraphicsContext *temp_s0;
u8 temp_v0;
u8 temp_v0_2;
u8 temp_v0_5;
u8 temp_v1;
s32 phi_v0;
Gfx *phi_v1;
temp_a1 = globalCtx->state.gfxCtx;
temp_s0 = temp_a1;
Graph_OpenDisps(&sp58, temp_a1, (const char *) "../z_en_box.c", 0x62D);
temp_v1 = thisx->unk1F7;
if (temp_v1 == 0xFF) {
temp_v0 = thisx->unk1F9;
if (temp_v0 != 4) {
if (temp_v0 == 6) {
block_3:
if ((thisx->flags & 0x80) != 0x80) {
temp_v0_2 = thisx->unk1F9;
if (temp_v0_2 != 4) {
if (temp_v0_2 == 6) {
block_6:
temp_v0_8 = temp_s0->polyOpa.p;
temp_s0->polyOpa.p = (Gfx *) (temp_v0_8 + 8);
temp_v0_8->words.w0 = 0xE7000000U;
temp_v0_8->words.w1 = 0U;
temp_v0_9 = temp_s0->polyOpa.p;
temp_s0->polyOpa.p = (Gfx *) (temp_v0_9 + 8);
temp_v0_9->words.w0 = 0xFB000000U;
temp_v0_9->words.w1 = 0xFFU;
temp_v0_10 = temp_s0->polyOpa.p;
temp_s0->polyOpa.p = (Gfx *) (temp_v0_10 + 8);
temp_v0_10->words.w0 = 0xDB060020U;
sp4C = temp_v0_10;
sp4C->words.w1 = func_809CA448(globalCtx->state.gfxCtx);
func_80093D18(globalCtx->state.gfxCtx);
temp_s0->polyOpa.p = SkelAnime_Draw2(globalCtx, thisx->unk168, thisx->unk184, NULL, &func_809CA2D8, thisx, temp_s0->polyOpa.p);
} else {
block_7:
if (temp_v1 != 0) {
temp_v0_3 = temp_s0->polyXlu.p;
temp_s0->polyXlu.p = (Gfx *) (temp_v0_3 + 8);
temp_v0_3->words.w1 = 0U;
temp_v0_3->words.w0 = 0xE7000000U;
func_80093D84(globalCtx->state.gfxCtx);
temp_v0_4 = temp_s0->polyXlu.p;
temp_s0->polyXlu.p = (Gfx *) (temp_v0_4 + 8);
temp_v0_4->words.w0 = 0xFB000000U;
temp_v0_4->words.w1 = (u32) thisx->unk1F7;
temp_v0_5 = thisx->unk1F9;
if (temp_v0_5 != 4) {
if (temp_v0_5 == 6) {
block_10:
temp_v0_7 = temp_s0->polyXlu.p;
temp_s0->polyXlu.p = (Gfx *) (temp_v0_7 + 8);
temp_v0_7->words.w0 = 0xDB060020U;
sp40 = temp_v0_7;
phi_v0 = func_809CA518(globalCtx->state.gfxCtx);
phi_v1 = sp40;
} else {
temp_v0_6 = temp_s0->polyXlu.p;
temp_s0->polyXlu.p = (Gfx *) (temp_v0_6 + 8);
temp_v0_6->words.w0 = 0xDB060020U;
sp3C = temp_v0_6;
phi_v0 = func_809CA4A0(globalCtx->state.gfxCtx);
phi_v1 = sp3C;
}
} else {
goto block_10;
}
phi_v1->words.w1 = phi_v0;
temp_s0->polyXlu.p = SkelAnime_Draw2(globalCtx, thisx->unk168, thisx->unk184, NULL, &func_809CA2D8, thisx, temp_s0->polyXlu.p);
}
}
} else {
goto block_6;
}
} else {
goto block_7;
}
} else {
goto block_6;
}
} else {
goto block_3;
}
} else {
goto block_3;
}
Graph_CloseDisps(&sp58, globalCtx->state.gfxCtx, (const char *) "../z_en_box.c", 0x667);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment