From 8d2c34761e6ee33c3b328e0b86fc8e0b61c5d222 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Tue, 31 Oct 2023 14:24:41 -0300 Subject: [PATCH 1/6] fix warnings in z_en_dt.c --- src/overlays/actors/ovl_En_Dt/z_en_dt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/overlays/actors/ovl_En_Dt/z_en_dt.c b/src/overlays/actors/ovl_En_Dt/z_en_dt.c index 8169fb794..42b97ff28 100644 --- a/src/overlays/actors/ovl_En_Dt/z_en_dt.c +++ b/src/overlays/actors/ovl_En_Dt/z_en_dt.c @@ -74,8 +74,8 @@ void EnDt_Init(Actor* thisx, PlayState* play) { this->actor.colChkInfo.mass = 0xFF; ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 19.0f); - SkelAnime_InitFlex(play, &this->skelanime, &object_dt_Skel_00B0CC, &object_dt_Anim_00112C, &this->unk_188, - &this->unk_1E2, 0xF); + SkelAnime_InitFlex(play, &this->skelanime, &object_dt_Skel_00B0CC, &object_dt_Anim_00112C, this->unk_188, + this->unk_1E2, 0xF); this->actor.targetMode = 6; this->unk_274 = 0; this->unk_278 = 0; @@ -294,7 +294,7 @@ void func_80BEA8F0(EnDt* this, PlayState* play) { } void func_80BEAAF8(EnDt* this, PlayState* play) { - Actor_OfferGetItem(this, play, GI_HEART_PIECE, 300.0f, 300.0f); + Actor_OfferGetItem(&this->actor, play, GI_HEART_PIECE, 300.0f, 300.0f); this->unk_254 = 3; this->actionFunc = func_80BEAB44; } @@ -342,7 +342,7 @@ void func_80BEAC84(EnDt* this, PlayState* play) { void func_80BEAD2C(EnDt* this, PlayState* play) { func_80BE9C74(this); - if (Actor_ProcessTalkRequest(&this->actor, play) != 0) { + if (Actor_ProcessTalkRequest(&this->actor, &play->state) != 0) { func_80BEADB8(this); return; } From df968bdc458d1668c49e91590bf1928b27f73587 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Tue, 31 Oct 2023 14:37:14 -0300 Subject: [PATCH 2/6] func_80BE9D9C NON_MATCHING --- src/overlays/actors/ovl_En_Dt/z_en_dt.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/overlays/actors/ovl_En_Dt/z_en_dt.c b/src/overlays/actors/ovl_En_Dt/z_en_dt.c index 42b97ff28..de5cf5f61 100644 --- a/src/overlays/actors/ovl_En_Dt/z_en_dt.c +++ b/src/overlays/actors/ovl_En_Dt/z_en_dt.c @@ -42,6 +42,7 @@ extern s16 D_80BEB268[]; extern s16 D_80BEB26A[]; extern s32 D_80BEB2C8[]; extern u8 D_80BEB2E0[]; +extern s32 D_80BEB2E8[]; extern s32 D_80BEB348[]; extern s32 D_80BEB35C[]; @@ -132,7 +133,26 @@ void func_80BE9CE8(EnDt* this, s32 arg1) { var_fv1); } +// Regalloc +// https://decomp.me/scratch/wKYaQ +#ifdef NON_MATCHING +void func_80BE9D9C(EnDt* this) { + s32 temp_v0; + s32* temp_v1; + + temp_v0 = this->unk_280 * 4; + temp_v0++; + temp_v1 = &D_80BEB2E8[temp_v0]; + func_80BE9CE8(this, *temp_v1); + temp_v0 = 1; + this->unk_24C = temp_v1[temp_v0]; + temp_v1++; + temp_v1++; + this->unk_248 = *temp_v1; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9D9C.s") +#endif #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9DF8.s") From 0df782f68e890d064a94c441f4da6960a5bd5236 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Tue, 31 Oct 2023 14:44:17 -0300 Subject: [PATCH 3/6] restore m2ctx --- tools/m2ctx.py | 9 +++- tools/m2ctx2.py | 129 ------------------------------------------------ 2 files changed, 7 insertions(+), 131 deletions(-) delete mode 100755 tools/m2ctx2.py diff --git a/tools/m2ctx.py b/tools/m2ctx.py index 49e065f8e..875793152 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -75,8 +75,13 @@ def custom_replacements(output): def import_c_file(in_file) -> str: in_file = os.path.relpath(in_file, root_dir) - cpp_command = ["gcc", "-E", "-P", "-Iinclude", "-Iassets", "-Isrc", "-undef", "-D__sgi", "-D_LANGUAGE_C", - "-DNON_MATCHING", "-DM2CTX", "-D_Static_assert(x, y)=", "-D__attribute__(x)=", in_file] + cpp_command = ["gcc", "-E", "-P", "-undef", "-dM", *CPP_FLAGS, in_file] + cpp_command2 = ["gcc", "-E", "-P", "-undef", *CPP_FLAGS, in_file] + + with tempfile.NamedTemporaryFile(suffix=".c") as tmp: + stock_macros = subprocess.check_output(["gcc", "-E", "-P", "-undef", "-dM", tmp.name], cwd=root_dir, encoding="utf-8") + + out_text = "" try: out_text += subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") diff --git a/tools/m2ctx2.py b/tools/m2ctx2.py deleted file mode 100755 index 875793152..000000000 --- a/tools/m2ctx2.py +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os -import sys -import subprocess -import tempfile -from pathlib import Path - -script_dir = Path(os.path.dirname(os.path.realpath(__file__))) -root_dir = script_dir / ".." -src_dir = root_dir / "src" - -# Project-specific -CPP_FLAGS = [ - "-Iinclude", - "-Isrc", - "-Iassets", - "-Ibuild", - "-I.", - - "-D__sgi", - "-D_LANGUAGE_C", - "-DNON_MATCHING", - "-D_Static_assert(x, y)=", - "-D__attribute__(x)=" - "-D_MIPS_SZLONG=32", - "-ffreestanding", - "-DM2CTX", - - "-std=gnu89", -] - -# Read through the processes context and replace whatever -def custom_replacements(output): - actorList = [] - output = output.splitlines() - - i = 0 - while i < len(output): - line = output[i] - - ############### actorLists[2].first -> Player* ############### - if "typedef struct ActorListEntry " in line: - actorListText = "" - i += 1 - while not output[i].startswith("}"): - actorListText += output[i] - i += 1 - actorCats = [ - "actorSwitch", - "bg", - "player", - "explosive", - "npc", - "enemy", - "prop", - "itemAction", - "misc", - "boss", - "door", - "chest", - ] - for x in range(12): - actorList.append(actorListText.replace("first;", f"{actorCats[x]};") + "\n") - if x == 2: - actorList[x] = actorList[x].replace("Actor*", "struct Player*") - elif "ActorListEntry actorLists[ACTORCAT_MAX];" in line: - output[i] = "struct {\n" + "".join(actorList) + "};" - ######################################################## - - i += 1 - return "\n".join(output) - -def import_c_file(in_file) -> str: - in_file = os.path.relpath(in_file, root_dir) - - cpp_command = ["gcc", "-E", "-P", "-undef", "-dM", *CPP_FLAGS, in_file] - cpp_command2 = ["gcc", "-E", "-P", "-undef", *CPP_FLAGS, in_file] - - with tempfile.NamedTemporaryFile(suffix=".c") as tmp: - stock_macros = subprocess.check_output(["gcc", "-E", "-P", "-undef", "-dM", tmp.name], cwd=root_dir, encoding="utf-8") - - out_text = "" - - try: - out_text += subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") - out_text += subprocess.check_output(cpp_command2, cwd=root_dir, encoding="utf-8") - except subprocess.CalledProcessError: - print( - "Failed to preprocess input file, when running command:\n" - + " ".join(cpp_command), - file=sys.stderr, - ) - sys.exit(1) - - if not out_text: - print("Output is empty - aborting") - sys.exit(1) - - for line in stock_macros.strip().splitlines(): - out_text = out_text.replace(line + "\n", "") - return out_text - - -def main(): - parser = argparse.ArgumentParser(usage="./m2ctx.py path/to/file.c or ./m2ctx.py (from an actor or gamestate's asm dir)", - description="Creates a ctx.c file for m2c or decomp.me. " - "Output will be saved as ctx.c") - parser.add_argument('filepath', help="path of c file to be processed") - parser.add_argument("--custom", "-c", dest="custom", action="store_true", default=False, - help="Apply custom replacements to the output to help aid m2c output") - args = parser.parse_args() - - c_file_path = args.filepath - print("Using file: {}".format(c_file_path)) - - output = import_c_file(c_file_path) - - if args.custom: - output = custom_replacements(output) - - ctxPath = root_dir / "ctx.c" - with ctxPath.open("w", encoding="UTF-8") as f: - f.write(output) - - -if __name__ == "__main__": - main() From a421f53d014938a5b6508bb77ee4673a8df84276 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Tue, 31 Oct 2023 14:48:36 -0300 Subject: [PATCH 4/6] func_80BE9D9C matching --- src/overlays/actors/ovl_En_Dt/z_en_dt.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/overlays/actors/ovl_En_Dt/z_en_dt.c b/src/overlays/actors/ovl_En_Dt/z_en_dt.c index de5cf5f61..6882e9d3f 100644 --- a/src/overlays/actors/ovl_En_Dt/z_en_dt.c +++ b/src/overlays/actors/ovl_En_Dt/z_en_dt.c @@ -133,26 +133,16 @@ void func_80BE9CE8(EnDt* this, s32 arg1) { var_fv1); } -// Regalloc -// https://decomp.me/scratch/wKYaQ -#ifdef NON_MATCHING void func_80BE9D9C(EnDt* this) { - s32 temp_v0; - s32* temp_v1; + s32 temp_v0 = this->unk_280 * 4; - temp_v0 = this->unk_280 * 4; temp_v0++; - temp_v1 = &D_80BEB2E8[temp_v0]; - func_80BE9CE8(this, *temp_v1); - temp_v0 = 1; - this->unk_24C = temp_v1[temp_v0]; - temp_v1++; - temp_v1++; - this->unk_248 = *temp_v1; + func_80BE9CE8(this, D_80BEB2E8[temp_v0]); + temp_v0++; + this->unk_24C = D_80BEB2E8[temp_v0]; + temp_v0++; + this->unk_248 = D_80BEB2E8[temp_v0]; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9D9C.s") -#endif #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9DF8.s") From c8e6cfee91e0d04b8d5aafe45c76b25c9c362068 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Tue, 31 Oct 2023 14:55:53 -0300 Subject: [PATCH 5/6] EnDt_Update Matching --- src/overlays/actors/ovl_En_Dt/z_en_dt.c | 46 ++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/overlays/actors/ovl_En_Dt/z_en_dt.c b/src/overlays/actors/ovl_En_Dt/z_en_dt.c index 6882e9d3f..d531ed93a 100644 --- a/src/overlays/actors/ovl_En_Dt/z_en_dt.c +++ b/src/overlays/actors/ovl_En_Dt/z_en_dt.c @@ -382,7 +382,51 @@ void func_80BEADD4(EnDt* this, PlayState* play) { } } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/EnDt_Update.s") +void EnDt_Update(Actor* thisx, PlayState* play) { + EnDt* this = THIS; + s32 pad; + + SkelAnime_Update(&this->skelanime); + Actor_SetScale(&this->actor, 0.01f); + + if ((this->unk_254 != 4) && (this->unk_254 != 5) && (gSaveContext.save.day == 3) && + (gSaveContext.save.isNight != 0)) { + func_80BEAC84(this, play); + } + + if (!(gSaveContext.save.saveInfo.weekEventReg[63] & 0x80) && + ((gSaveContext.save.day != 3) || ((gSaveContext.save.day == 3) && (gSaveContext.save.isNight == 0)))) { + Audio_PlaySequenceAtPos(3, &gSfxDefaultPos, 49, 1000.0f); + Actor_PlaySfx(&this->actor, NA_SE_EV_CROWD - SFX_FLAG); + } + + if (this->unk_24A != 0) { + this->unk_24A--; + } + + if (this->unk_244 != 0) { + this->unk_244--; + } + + if (this->unk_290 != 0) { + func_80BE9C74(this); + } + + if ((this->unk_248 == 0) && (this->unk_24A == 0)) { + this->unk_24C++; + if (this->unk_24C >= 3) { + this->unk_24C = 0; + this->unk_24A = (s32)Rand_ZeroFloat(60.0f) + 20; + } + } + this->actionFunc(this, play); + this->actor.shape.rot.y = this->actor.world.rot.y; + Math_SmoothStepToS(&this->unk_284.y, this->unk_28A.y, 1, 3000, 0); + Actor_SetFocus(&this->actor, 60.0f); + Actor_MoveWithGravity(&this->actor); + Collider_UpdateCylinder(&this->actor, &this->collider); + CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider); +} s32 EnDt_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* thisx) { EnDt* this = THIS; From b151f6cf3a9930c801832065d6b49fa56cf22724 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Tue, 31 Oct 2023 16:51:43 -0300 Subject: [PATCH 6/6] func_80BEA254 matching --- src/overlays/actors/ovl_En_Dt/z_en_dt.c | 55 ++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/overlays/actors/ovl_En_Dt/z_en_dt.c b/src/overlays/actors/ovl_En_Dt/z_en_dt.c index d531ed93a..d37462d39 100644 --- a/src/overlays/actors/ovl_En_Dt/z_en_dt.c +++ b/src/overlays/actors/ovl_En_Dt/z_en_dt.c @@ -247,7 +247,60 @@ void func_80BEA088(EnDt* this, PlayState* play) { Actor_OfferTalk(&this->actor, play, 150.0f); } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEA254.s") +void func_80BEA254(EnDt* this, PlayState* play) { + EnMuto* sp1C; + EnBaisen* sp18; + s16* var_v0; + s32 i; + + if (!(gSaveContext.save.saveInfo.weekEventReg[0x3F] & 0x80)) { + if (this->unk_274 != NULL) { + if (this->unk_278 != NULL) { + sp1C = this->unk_274; + sp18 = this->unk_278; + } + } + if ((this->unk_274 != NULL) && (this->unk_278 != NULL)) { + sp1C->cutsceneState = 1; + sp18->unk2AC = 1; + if (Player_GetMask(play) == 0xA) { + sp1C->textIdIndex = 4; + sp18->textIdIndex = 6; + this->unk_280 = 5; + if (gSaveContext.save.saveInfo.weekEventReg[0x3C] & 8) { + this->unk_280 = 4; + } + func_80BE9D9C(this); + } + } + } + this->unk_270 = 0; + +#if 0 + for (i = 0; i < 24; i++) { + if ((play->msgCtx.currentTextId == D_80BEB268[i]) || (this->actor.textId == D_80BEB268[i])) { + this->unk_270 = 1; + this->unk_26E = i; + } + } +#else + // clang-format off + var_v0 = D_80BEB268; i = 0; loop_11: + // clang-format on + if ((play->msgCtx.currentTextId == (*var_v0)) || (this->actor.textId == (*var_v0))) { + this->unk_270 = 1; + this->unk_26E = i; + } else { + i += 2; + var_v0 += 2; + if (i < 24) { + goto loop_11; + } + } +#endif + this->unk_254 = 2; + this->actionFunc = func_80BEA394; +} #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEA394.s")