Merge branch 'zret' of https://github.com/HarbourMasters/mm into zret

This commit is contained in:
RevoSucks
2023-10-31 06:31:09 -04:00
4 changed files with 490 additions and 22 deletions
+337 -19
View File
@@ -5,6 +5,9 @@
*/
#include "z_en_dt.h"
#include "objects/object_dt/object_dt.h"
#include "overlays/actors/ovl_En_Muto/z_en_muto.h"
#include "overlays/actors/ovl_En_Baisen/z_en_baisen.h"
#define FLAGS (ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_FRIENDLY)
@@ -15,6 +18,33 @@ void EnDt_Destroy(Actor* thisx, PlayState* play);
void EnDt_Update(Actor* thisx, PlayState* play);
void EnDt_Draw(Actor* thisx, PlayState* play);
void func_80BE9C74(EnDt* this);
void func_80BE9CE8(EnDt* this, s32 arg1);
void func_80BE9D9C(EnDt* this);
void func_80BE9DF8(EnDt* this);
void func_80BE9E94(EnDt* this, PlayState* play);
void func_80BE9EF8(EnDt* this, PlayState* play);
void func_80BEA088(EnDt* this, PlayState* play);
void func_80BEA254(EnDt* this, PlayState* play);
void func_80BEA394(EnDt* this, PlayState* play);
void func_80BEA8F0(EnDt* this, PlayState* play);
void func_80BEAB44(EnDt* this, PlayState* play);
void func_80BEABF8(EnDt* this, PlayState* play);
void func_80BEAC84(EnDt* this, PlayState* play);
void func_80BEAD2C(EnDt* this, PlayState* play);
void func_80BEADB8(EnDt* this);
void func_80BEADD4(EnDt* this, PlayState* play);
s32 EnDt_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* thisx);
extern ColliderCylinderInit D_80BEB29C;
extern u16 D_80BEB1D0[];
extern s16 D_80BEB268[];
extern s16 D_80BEB26A[];
extern s32 D_80BEB2C8[];
extern u8 D_80BEB2E0[];
extern s32 D_80BEB348[];
extern s32 D_80BEB35C[];
#if 0
ActorInit En_Dt_InitVars = {
/**/ ACTOR_EN_DT,
@@ -37,50 +67,338 @@ static ColliderCylinderInit D_80BEB29C = {
#endif
extern ColliderCylinderInit D_80BEB29C;
void EnDt_Init(Actor* thisx, PlayState* play) {
EnDt* this = THIS;
s32 csId;
s32 i;
extern UNK_TYPE D_0600112C;
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);
this->actor.targetMode = 6;
this->unk_274 = 0;
this->unk_278 = 0;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/EnDt_Init.s")
Collider_InitAndSetCylinder(play, &this->collider, &this->actor, &D_80BEB29C);
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/EnDt_Destroy.s")
if ((gSaveContext.save.day == 3) && (gSaveContext.save.isNight != 0)) {
func_80BEAC84(this, play);
} else {
//! FAKE:
EnDt* var_s1;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9C74.s")
csId = this->actor.csId;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9CE8.s")
i = 0;
// clang-format off
while (csId != CS_ID_NONE) { this->csIdList[i] = csId; csId = CutsceneManager_GetAdditionalCsId(csId); i++; };
// clang-format on
}
this->actionFunc = func_80BE9E94;
}
void EnDt_Destroy(Actor* thisx, PlayState* play) {
EnDt* this = THIS;
Collider_DestroyCylinder(play, &this->collider);
}
void func_80BE9C74(EnDt* this) {
s32 var_v1 = ABS_ALT((s16)(this->actor.yawTowardsPlayer - this->actor.world.rot.y));
this->unk_28A.y = 0;
if (var_v1 < 0x4E20) {
this->unk_28A.y = this->actor.yawTowardsPlayer - this->actor.world.rot.y;
if (this->unk_28A.y > 0x2710) {
this->unk_28A.y = 0x2710;
} else if (this->unk_28A.y < -0x2710) {
this->unk_28A.y = -0x2710;
}
}
}
void func_80BE9CE8(EnDt* this, s32 arg1) {
f32 var_fv1 = -4.0f;
this->unk_246 = arg1;
if ((this->unk_246 == 2) || (this->unk_246 == 5)) {
var_fv1 = 0.0f;
}
this->unk_250 = Animation_GetLastFrame(D_80BEB2C8[this->unk_246]);
Animation_Change(&this->skelanime, D_80BEB2C8[this->unk_246], 1.0f, 0.0f, this->unk_250, D_80BEB2E0[this->unk_246],
var_fv1);
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9D9C.s")
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9DF8.s")
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9E94.s")
void func_80BE9E94(EnDt* this, PlayState* play) {
Actor* actor = play->actorCtx.actorLists[ACTORCAT_NPC].first;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BE9EF8.s")
while (actor != NULL) {
if (actor->id == ACTOR_EN_MUTO) {
this->unk_274 = (EnMuto*)actor;
} else if (actor->id == ACTOR_EN_BAISEN) {
this->unk_278 = (EnBaisen*)actor;
}
actor = actor->next;
}
func_80BE9EF8(this, play);
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEA088.s")
void func_80BE9EF8(EnDt* this, PlayState* play) {
this->unk_256 = 0;
if (!(gSaveContext.save.saveInfo.weekEventReg[60] & 0x10)) {
if (gSaveContext.save.saveInfo.weekEventReg[63] & 0x80) {
this->unk_256 = 21;
this->unk_280 = 5;
func_80BE9D9C(this);
this->actor.textId = D_80BEB1D0[this->unk_256];
Message_StartTextbox(play, this->actor.textId, &this->actor);
func_800B7298(play, &this->actor, 7);
this->unk_254 = 1;
this->actionFunc = func_80BEA394;
} else {
goto block_5;
}
} else {
if (gSaveContext.save.saveInfo.weekEventReg[63] & 0x80) {
this->unk_256 = 23;
this->unk_280 = 5;
this->unk_290 = 1;
func_80BE9D9C(this);
Message_BombersNotebookQueueEvent(play, 7);
}
block_5:
if (this->unk_280 == 0) {
if (gSaveContext.save.saveInfo.weekEventReg[60] & 8) {
this->unk_256 = 9;
this->unk_280 = 2;
}
func_80BE9D9C(this);
if (!(gSaveContext.save.saveInfo.weekEventReg[60] & 8)) {
this->unk_280 = 1;
}
}
this->actor.textId = D_80BEB1D0[this->unk_256];
if (!(gSaveContext.save.saveInfo.weekEventReg[63] & 0x80)) {
func_80BE9DF8(this);
}
this->unk_254 = 1;
this->actionFunc = func_80BEA088;
}
}
void func_80BEA088(EnDt* this, PlayState* play) {
EnMuto* mutoh = NULL;
EnBaisen* viscen = NULL;
if (Actor_ProcessTalkRequest(&this->actor, &play->state)) {
func_80BEA254(this, play);
return;
}
if (!(gSaveContext.save.saveInfo.weekEventReg[63] & 0x80)) {
if (this->unk_274 != NULL) {
if (this->unk_278 != NULL) {
mutoh = this->unk_274;
viscen = this->unk_278;
}
}
this->unk_240 = 0;
this->unk_256 = 0;
if (Player_GetMask(play) == PLAYER_MASK_COUPLE) {
this->unk_256 = 0xB;
this->unk_240 = 1;
if ((this->unk_274 != NULL) && (this->unk_278 != NULL)) {
mutoh->textIdIndex = 4;
viscen->textIdIndex = 6;
}
} else if (gSaveContext.save.saveInfo.weekEventReg[60] & 8) {
this->unk_256 = 9;
}
}
this->actor.textId = D_80BEB1D0[this->unk_256];
if (!(gSaveContext.save.saveInfo.weekEventReg[0x3F] & 0x80) && (this->unk_274 != NULL) && (this->unk_278 != NULL) &&
((mutoh->cutsceneState == 1) || (viscen->unk2AC == 1))) {
func_80BEA254(this, play);
}
if ((gSaveContext.save.saveInfo.weekEventReg[0x3F] & 0x80) && (Player_GetMask(play) == 2)) {
this->actor.textId = 0x2368;
}
Actor_OfferTalk(&this->actor, play, 150.0f);
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEA254.s")
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEA394.s")
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEA8F0.s")
void func_80BEA8F0(EnDt* this, PlayState* play) {
f32 curFrame = this->skelanime.curFrame;
s16 subCamId;
s32 i;
s32 j;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEAAF8.s")
if (this->unk_244 != 0) {
if (this->unk_244 == 1) {
if ((this->unk_256 == 8) || (this->unk_280 == 4)) {
func_80BE9D9C(this);
}
this->unk_280++;
if (this->unk_280 >= 6) {
this->unk_280 = 5;
}
}
} else if (curFrame >= this->unk_250) {
j = D_80BEB26A[this->unk_26E];
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEAB44.s")
func_80BE9D9C(this);
Message_CloseTextbox(play);
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEABF8.s")
this->actor.textId = D_80BEB1D0[this->unk_256];
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEAC84.s")
Message_StartTextbox(play, this->actor.textId, &this->actor);
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEAD2C.s")
if (this->unk_256 == 8) {
Message_BombersNotebookQueueEvent(play, 7);
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEADB8.s")
for (i = 0; i < 24; i++) {
if ((play->msgCtx.currentTextId == D_80BEB268[i]) || (this->actor.textId == D_80BEB268[i])) {
this->unk_26E = i;
}
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEADD4.s")
i = D_80BEB26A[this->unk_26E];
if ((this->unk_270 == 2) && (i != j)) {
this->unk_270 = 1;
CutsceneManager_Stop(this->csIdList[j]);
CutsceneManager_Queue(this->csIdList[i]);
}
func_80BE9DF8(this);
Actor_ChangeFocus(&this->actor, play, this->targetActor);
subCamId = CutsceneManager_GetCurrentSubCamId(this->csIdList[i]);
Camera_SetTargetActor(Play_GetCamera(play, subCamId), this->targetActor);
this->actionFunc = func_80BEA394;
}
}
void func_80BEAAF8(EnDt* this, PlayState* play) {
Actor_OfferGetItem(this, play, GI_HEART_PIECE, 300.0f, 300.0f);
this->unk_254 = 3;
this->actionFunc = func_80BEAB44;
}
void func_80BEAB44(EnDt* this, PlayState* play) {
if (Actor_HasParent(&this->actor, play) != 0) {
this->unk_256 = 22;
this->actor.parent = NULL;
this->actor.textId = D_80BEB1D0[this->unk_256];
Actor_OfferTalkExchange(&this->actor, play, 400.0f, 400.0f, PLAYER_IA_MINUS1);
gSaveContext.save.saveInfo.weekEventReg[60] |= 0x10;
this->actionFunc = func_80BEABF8;
} else {
Actor_OfferGetItem(&this->actor, play, GI_HEART_PIECE, 300.0f, 300.0f);
}
}
void func_80BEABF8(EnDt* this, PlayState* play) {
SkelAnime_Update(&this->skelanime);
if (Actor_ProcessTalkRequest(&this->actor, &play->state) != 0) {
Message_BombersNotebookQueueEvent(play, 0x26);
Message_BombersNotebookQueueEvent(play, 7);
this->actionFunc = func_80BEA394;
} else {
Actor_OfferTalkExchange(&this->actor, play, 400.0f, 400.0f, PLAYER_IA_MINUS1);
}
}
void func_80BEAC84(EnDt* this, PlayState* play) {
func_80BE9CE8(this, 3);
this->unk_248 = 1;
this->unk_256 = 24;
Message_BombersNotebookQueueEvent(play, 7);
if (gSaveContext.save.saveInfo.weekEventReg[60] & 0x40) {
this->unk_256 = 26;
}
this->actor.textId = D_80BEB1D0[this->unk_256];
this->unk_24C = 3;
this->unk_248 = 1;
this->unk_254 = 4;
this->actionFunc = func_80BEAD2C;
}
void func_80BEAD2C(EnDt* this, PlayState* play) {
func_80BE9C74(this);
if (Actor_ProcessTalkRequest(&this->actor, play) != 0) {
func_80BEADB8(this);
return;
}
if ((gSaveContext.save.saveInfo.weekEventReg[63] & 0x80) && (Player_GetMask(play) == 2)) {
this->actor.textId = 0x2368;
}
Actor_OfferTalk(&this->actor, play, 150.0f);
}
void func_80BEADB8(EnDt* this) {
this->unk_254 = 5;
this->actionFunc = func_80BEADD4;
}
void func_80BEADD4(EnDt* this, PlayState* play) {
func_80BE9C74(this);
if ((Message_GetState(&play->msgCtx) == 5) && (Message_ShouldAdvance(play) != 0)) {
Message_CloseTextbox(play);
if (!(gSaveContext.save.saveInfo.weekEventReg[60] & 0x40)) {
this->unk_256 = 25;
Message_ContinueTextbox(play, D_80BEB1D0[this->unk_256]);
gSaveContext.save.saveInfo.weekEventReg[60] |= 0x40;
} else {
func_80BEAC84(this, play);
}
}
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/EnDt_Update.s")
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/func_80BEB06C.s")
s32 EnDt_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* thisx) {
EnDt* this = THIS;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Dt/EnDt_Draw.s")
if (limbIndex == 12) {
rot->y += -1 * this->unk_284.y;
}
return false;
}
void EnDt_Draw(Actor* thisx, PlayState* play) {
EnDt* this = THIS;
s32 index = 0;
OPEN_DISPS(play->state.gfxCtx);
Gfx_SetupDL25_Opa(play->state.gfxCtx);
Gfx_SetupDL25_Xlu(play->state.gfxCtx);
gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_80BEB348[this->unk_24C]));
if (this->unk_24C < 3) {
index = this->unk_24C;
}
gSPSegment(POLY_OPA_DISP++, 0x09, Lib_SegmentedToVirtual(D_80BEB35C[index]));
CLOSE_DISPS(play->state.gfxCtx);
SkelAnime_DrawFlexOpa(play, this->skelanime.skeleton, this->skelanime.jointTable, this->skelanime.dListCount,
EnDt_OverrideLimbDraw, NULL, &this->actor);
}
+23 -2
View File
@@ -9,9 +9,30 @@ typedef void (*EnDtActionFunc)(struct EnDt*, PlayState*);
typedef struct EnDt {
/* 0x000 */ Actor actor;
/* 0x144 */ char unk_144[0xF8];
/* 0x144 */ SkelAnime skelanime;
/* 0x188 */ Vec3s unk_188[15];
/* 0x1E2 */ Vec3s unk_1E2[15];
/* 0x23C */ EnDtActionFunc actionFunc;
/* 0x240 */ char unk_240[0xA0];
/* 0x240 */ s32 unk_240;
/* 0x244 */ s16 unk_244;
/* 0x246 */ s16 unk_246;
/* 0x248 */ s16 unk_248;
/* 0x24A */ s16 unk_24A;
/* 0x24C */ s16 unk_24C;
/* 0x250 */ f32 unk_250;
/* 0x254 */ s16 unk_254;
/* 0x256 */ s16 unk_256;
/* 0x258 */ s16 csIdList[11];
/* 0x26E */ s16 unk_26E;
/* 0x270 */ s16 unk_270;
/* 0x274 */ struct EnMuto* unk_274;
/* 0x278 */ struct EnBaisen* unk_278;
/* 0x27C */ struct Actor* targetActor;
/* 0x280 */ s32 unk_280;
/* 0x284 */ Vec3s unk_284;
/* 0x28A */ Vec3s unk_28A;
/* 0x290 */ s32 unk_290;
/* 0x294 */ ColliderCylinder collider;
} EnDt; // size = 0x2E0
#endif // Z_EN_DT_H
+1 -1
View File
@@ -16199,7 +16199,7 @@
0x80BEADB8:("func_80BEADB8",),
0x80BEADD4:("func_80BEADD4",),
0x80BEAE94:("EnDt_Update",),
0x80BEB06C:("func_80BEB06C",),
0x80BEB06C:("EnDt_OverrideLimbDraw",),
0x80BEB0A8:("EnDt_Draw",),
0x80BEB520:("EnCha_Init",),
0x80BEB5B0:("EnCha_Destroy",),
+129
View File
@@ -0,0 +1,129 @@
#!/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()