From cb57226b1a07c37152b148d4db39bf7968ee86ca Mon Sep 17 00:00:00 2001 From: Yanis <35189056+Yanis002@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:36:53 +0100 Subject: [PATCH] Fix crashes related to actor cutscenes (#166) --- .github/workflows/format.yml | 4 ++-- format.py | 5 ++++- include/z64play.h | 1 + src/code/cutscene_manager.c | 4 +++- src/code/z_camera.c | 8 ++++++++ src/code/z_play.c | 16 ++++++++++------ 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 0072ae52f..7a83937ca 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -6,7 +6,7 @@ jobs: check-main: if: ${{ github.event_name == 'push' }} name: Check all files - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 with: @@ -25,7 +25,7 @@ jobs: check-pr: if: ${{ github.event_name == 'pull_request' }} name: Check modified files - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 with: diff --git a/format.py b/format.py index 035047558..b6b7f0a7e 100755 --- a/format.py +++ b/format.py @@ -94,6 +94,9 @@ def run_clang_apply_replacements(tmp_dir: str): exec_str = f"{CLANG_APPLY_REPLACEMENTS} {APPLY_OPTS} {tmp_dir}" subprocess.run(exec_str, shell=True) +def get_version(): + exec_str = f"{CLANG_FORMAT} --version" + return subprocess.run(exec_str, shell=True, capture_output=True).stdout.decode("utf-8").removesuffix("\n") def cleanup_whitespace(file: str): """ @@ -151,7 +154,7 @@ def format_files(src_files: List[str], extra_files: List[str], nb_jobs: int): with multiprocessing.get_context("fork").Pool(nb_jobs) as pool: pool.map(cleanup_whitespace, src_files + extra_files) - print("Done formatting files.") + print(f"Done formatting files with version '{get_version()}'.") def list_files_to_format(): diff --git a/include/z64play.h b/include/z64play.h index c8d7defe7..631994b9d 100644 --- a/include/z64play.h +++ b/include/z64play.h @@ -115,6 +115,7 @@ typedef struct PlayState { #endif #if ENABLE_CUTSCENE_IMPROVEMENTS ActorCsCamInfo* actorCsCamList; + u8 actorCsUsed; #endif } PlayState; // size = 0x12518 diff --git a/src/code/cutscene_manager.c b/src/code/cutscene_manager.c index 6b4061226..3f33fba7c 100644 --- a/src/code/cutscene_manager.c +++ b/src/code/cutscene_manager.c @@ -125,7 +125,9 @@ CutsceneEntry* CutsceneManager_GetCutsceneEntryImpl(s16 csId) { void CutsceneManager_Init(PlayState* play, CutsceneEntry* cutsceneList, s16 numEntries) { s32 i; - if (cutsceneList != NULL) { + play->actorCsUsed = cutsceneList != NULL; + + if (play->actorCsUsed) { sSceneCutsceneList = cutsceneList; sSceneCutsceneCount = numEntries; } diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 5c146b8c2..3275db70a 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -8625,6 +8625,14 @@ s32 Camera_RequestBgCam(Camera* camera, s32 requestedBgCamIndex) { s16 requestedCamSetting; s16 settingChangeSuccessful; +#if ENABLE_CUTSCENE_IMPROVEMENTS + //! TODO: better fix? though this is probably good enough as whatever function calls this one will be + // used for bg cameras, it's likely safe to assume this will never be related to actor cutscenes. + if (!(requestedBgCamIndex & CAM_DATA_IS_BG)) { + requestedBgCamIndex |= CAM_DATA_IS_BG; + } +#endif + if ((requestedBgCamIndex == -1) || (requestedBgCamIndex == camera->bgCamIndex)) { camera->behaviorFlags |= CAM_BEHAVIOR_BG_PROCESSED; return -1; diff --git a/src/code/z_play.c b/src/code/z_play.c index ebeda310b..05bcb6c6f 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -496,20 +496,24 @@ void Play_Init(GameState* thisx) { Camera_InitDataUsingPlayer(&this->mainCamera, player); Camera_RequestMode(&this->mainCamera, CAM_MODE_NORMAL); + playerStartBgCamIndex = PLAYER_GET_START_BG_CAM_INDEX(&player->actor); + #if ENABLE_CUTSCENE_IMPROVEMENTS - if ((player->actor.params & 0xFF) != 0xFF) { - Camera_ChangeActorCsCamIndex(&this->mainCamera, player->actor.params & 0xFF); + if (playerStartBgCamIndex != PLAYER_START_BG_CAM_DEFAULT) { + if (this->actorCsUsed) { + Camera_ChangeActorCsCamIndex(&this->mainCamera, playerStartBgCamIndex); + } else { + Camera_RequestBgCam(&this->mainCamera, playerStartBgCamIndex); + } } CutsceneManager_StoreCamera(&this->mainCamera); -#endif - - playerStartBgCamIndex = PLAYER_GET_START_BG_CAM_INDEX(&player->actor); - +#else if (playerStartBgCamIndex != PLAYER_START_BG_CAM_DEFAULT) { PRINTF("player has start camera ID (" VT_FGCOL(BLUE) "%d" VT_RST ")\n", playerStartBgCamIndex); Camera_RequestBgCam(&this->mainCamera, playerStartBgCamIndex); } +#endif if (R_SCENE_CAM_TYPE == SCENE_CAM_TYPE_FIXED_TOGGLE_VIEWPOINT) { this->viewpoint = VIEWPOINT_PIVOT;