From 11232925ccad70c3a342af7b1709a40558233359 Mon Sep 17 00:00:00 2001 From: "H.M. Burger" <92937601+Onenutmcgee@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:02:53 -0500 Subject: [PATCH] Adding tt_002 (Faerie) overlay (#1801) I also deduped the common shared servant functions except ProcessSfxState. That one has a jumptable and I didn't want to mess with multiple files/.rodata while just adding a new overlay. --- Makefile | 14 ++++- Makefile.psx.mk | 2 +- README.md | 1 + config/check.us.sha | 1 + config/splat.us.tt_002.yaml | 45 +++++++++++++++ config/symbols.us.tt_002.txt | 20 +++++++ src/servant/tt_002/3678.c | 109 +++++++++++++++++++++++++++++++++++ tools/dups/src/main.rs | 7 +++ tools/progress.py | 1 + 9 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 config/splat.us.tt_002.yaml create mode 100644 config/symbols.us.tt_002.txt create mode 100644 src/servant/tt_002/3678.c diff --git a/Makefile b/Makefile index c8a19b6de..eb8cdb160 100644 --- a/Makefile +++ b/Makefile @@ -142,7 +142,7 @@ extract: extract_$(VERSION) build: ##@ build game files build: build_$(VERSION) -build_us: main dra weapon ric cen dre mad no0 no3 np3 nz0 sel st0 wrp rwrp mar rbo3 tt_000 tt_001 +build_us: main dra weapon ric cen dre mad no0 no3 np3 nz0 sel st0 wrp rwrp mar rbo3 tt_000 tt_001 tt_002 build_hd: dra cen wrp tt_000 clean: ##@ clean extracted files, assets, and build artifacts git clean -fdx assets/ @@ -224,6 +224,7 @@ format-symbols: ./tools/symbols.py remove-orphans config/splat.us.tt_000.yaml ./tools/symbols.py remove-orphans config/splat.hd.tt_000.yaml ./tools/symbols.py remove-orphans config/splat.us.tt_001.yaml + ./tools/symbols.py remove-orphans config/splat.us.tt_002.yaml ./tools/symbols.py remove-orphans config/splat.us.stmad.yaml format-license: find src/ | grep -E '\.c$$|\.h$$' | grep -vE 'PsyCross|mednafen|psxsdk|3rd|saturn/lib' | python3 ./tools/lint-license.py - AGPL-3.0-or-later @@ -371,6 +372,13 @@ $(BUILD_DIR)/TT_001.BIN: $(BUILD_DIR)/tt_001_raw.bin cp $< $@ dd status=none if=/dev/zero bs=1 count=$$((40960 - $$(stat -c %s $<))) >> $@ +tt_002: $(BUILD_DIR)/TT_002.BIN +$(BUILD_DIR)/tt_002_raw.bin: $(BUILD_DIR)/tt_002.elf + $(OBJCOPY) -O binary $< $@ +$(BUILD_DIR)/TT_002.BIN: $(BUILD_DIR)/tt_002_raw.bin + cp $< $@ + dd status=none if=/dev/zero bs=1 count=$$((40960 - $$(stat -c %s $<))) >> $@ + mad_fix: stmad_dirs $$(call list_o_files,st/mad) $$(call list_o_files,st) $(LD) $(LD_FLAGS) -o $(BUILD_DIR)/stmad_fix.elf \ -Map $(BUILD_DIR)/stmad_fix.map \ @@ -481,6 +489,7 @@ force_symbols: ##@ Extract a full list of symbols from a successful build $(PYTHON) ./tools/symbols.py elf build/us/borbo3.elf > config/symbols.us.borbo3.txt $(PYTHON) ./tools/symbols.py elf build/us/tt_000.elf > config/symbols.us.tt_000.txt $(PYTHON) ./tools/symbols.py elf build/us/tt_001.elf > config/symbols.us.tt_001.txt + $(PYTHON) ./tools/symbols.py elf build/us/tt_002.elf > config/symbols.us.tt_002.txt context: ##@ create a context for decomp.me. Set the SOURCE variable prior to calling this target $(M2CTX) $(SOURCE) @@ -521,6 +530,7 @@ disk_prepare: build $(SOTNDISK) cp $(BUILD_DIR)/F_RBO3.BIN $(DISK_DIR)/BOSS/RBO3/F_RBO3.BIN cp $(BUILD_DIR)/TT_000.BIN $(DISK_DIR)/SERVANT/TT_000.BIN cp $(BUILD_DIR)/TT_001.BIN $(DISK_DIR)/SERVANT/TT_001.BIN + cp $(BUILD_DIR)/TT_002.BIN $(DISK_DIR)/SERVANT/TT_002.BIN disk: disk_prepare $(SOTNDISK) make build/sotn.$(VERSION).cue $(DISK_DIR) $(CONFIG_DIR)/disk.us.lba disk_debug: disk_prepare @@ -632,7 +642,7 @@ include tools/tools.mk .PHONY: all, clean, patch, check, build, expected .PHONY: format, ff, format-src, format-tools, format-symbols -.PHONY: main, dra, ric, cen, dre, mad, no3, np3, nz0, st0, wrp, rwrp, bomar, borbo3, tt_000, tt_001 +.PHONY: main, dra, ric, cen, dre, mad, no3, np3, nz0, st0, wrp, rwrp, bomar, borbo3, tt_000, tt_001, tt_002 .PHONY: %_dirs .PHONY: extract, extract_% .PHONY: update-dependencies python-dendencies diff --git a/Makefile.psx.mk b/Makefile.psx.mk index d90f764e5..07b42f7fa 100644 --- a/Makefile.psx.mk +++ b/Makefile.psx.mk @@ -9,7 +9,7 @@ PSX_RSTAGES := rwrp PSX_BOSTAGES := mar PSX_RBOSTAGES := rbo3 PSX_ALLSTAGES := $(addprefix st,$(PSX_KSTAGES)) $(addprefix st,$(PSX_RSTAGES)) $(addprefix bo,$(PSX_BOSTAGES)) $(addprefix bo,$(PSX_RBOSTAGES)) -PSX_SERVANTS := tt_000 tt_001 +PSX_SERVANTS := tt_000 tt_001 tt_002 PSX_US_TARGETS := main $(PSX_OVLS) $(PSX_ALLSTAGES) $(PSX_SERVANTS) PSX_HD_TARGETS := dra ric tt_000 stcen stwrp diff --git a/README.md b/README.md index f33532953..318f42916 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ This repo does not include any assets or assembly code necessary for compiling t | BOSS/RBO3/RBO3.BIN | ![code coverage RBO3.BIN](https://img.shields.io/endpoint?label=RBO3%20code&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fsotn%2Fus%2Fcode%2F%3Fmode%3Dshield%26measure%3Dborbo3) | ![decompiled functions](https://img.shields.io/endpoint?label=RBO3%20funcs&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fsotn%2Fus%2Ffunctions%2F%3Fmode%3Dshield%26measure%3Dborbo3) | Medusa boss | SERVANT/TT_000.BIN | ![code coverage TT_000.BIN](https://img.shields.io/endpoint?label=TT_000%20code&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fsotn%2Fus%2Fcode%2F%3Fmode%3Dshield%26measure%3Dtt_000) | ![decompiled functions](https://img.shields.io/endpoint?label=TT_000%20funcs&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fsotn%2Fus%2Ffunctions%2F%3Fmode%3Dshield%26measure%3Dtt_000) | Bat Familiar | SERVANT/TT_001.BIN | ![code coverage TT_001.BIN](https://img.shields.io/endpoint?label=TT_001%20code&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fsotn%2Fus%2Fcode%2F%3Fmode%3Dshield%26measure%3Dtt_001) | ![decompiled functions](https://img.shields.io/endpoint?label=TT_001%20funcs&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fsotn%2Fus%2Ffunctions%2F%3Fmode%3Dshield%26measure%3Dtt_001) | Ghost Familiar +| SERVANT/TT_002.BIN | ![code coverage TT_002.BIN](https://img.shields.io/endpoint?label=TT_002%20code&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fsotn%2Fus%2Fcode%2F%3Fmode%3Dshield%26measure%3Dtt_002) | ![decompiled functions](https://img.shields.io/endpoint?label=TT_002%20funcs&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fsotn%2Fus%2Ffunctions%2F%3Fmode%3Dshield%26measure%3Dtt_002) | Faerie Familiar Code coverage means how many bytes of code have been successfully converted from assembly into C code, while decomp function is how many functions have been successfully decompiled. diff --git a/config/check.us.sha b/config/check.us.sha index 102df017b..34e2e2261 100644 --- a/config/check.us.sha +++ b/config/check.us.sha @@ -28,3 +28,4 @@ ee1aaa34f3464b1d1cd72052cec7a4b9089d1887 build/us/F_RWRP.BIN c721a1d2bc6bdd9901801e792d23b5996d940b97 build/us/F_RBO3.BIN 82dd4ae1c4e3dc0fd483a49e5e4ab4fc5e25ada7 build/us/TT_000.BIN 326c9d2f9b9e2af678f5d63b30b31fba99ae75d4 build/us/TT_001.BIN +4589bb04fe475439c6d6e9b7273a8971ad859b4d build/us/TT_002.BIN diff --git a/config/splat.us.tt_002.yaml b/config/splat.us.tt_002.yaml new file mode 100644 index 000000000..a8afe550f --- /dev/null +++ b/config/splat.us.tt_002.yaml @@ -0,0 +1,45 @@ +options: + platform: psx + basename: tt_002 + base_path: .. + build_path: build/us + target_path: disks/us/SERVANT/TT_002.BIN + asm_path: asm/us/servant/tt_002 + asset_path: assets/servant/tt_002 + src_path: src/servant/tt_002 + ld_script_path: build/us/tt_002.ld + compiler: GCC + symbol_addrs_path: + - config/symbols.us.txt + - config/symbols.us.tt_002.txt + undefined_funcs_auto_path: config/undefined_funcs_auto.us.tt_002.txt + undefined_syms_auto_path: config/undefined_syms_auto.us.tt_002.txt + find_file_boundaries: true + use_legacy_include_asm: false + migrate_rodata_to_functions: true + asm_jtbl_label_macro: jlabel + symbol_name_format: us_$VRAM + section_order: + - .data + - .rodata + - .text + - .bss + - .sbss + ld_bss_is_noload: false + disasm_unknown: true + include_macro_inc: false + disassemble_all: true +sha1: 4589bb04fe475439c6d6e9b7273a8971ad859b4d +segments: + - name: tt_002 + type: code + start: 0 + vram: 0x80170000 + align: 4 + subalign: 4 + subsegments: + - [0x0, data] + - [0x3678, .rodata, 3678] + - [0x39D0, c, 3678] + - [0x92D0, sbss] + - [0xA000] diff --git a/config/symbols.us.tt_002.txt b/config/symbols.us.tt_002.txt new file mode 100644 index 000000000..f7de91a66 --- /dev/null +++ b/config/symbols.us.tt_002.txt @@ -0,0 +1,20 @@ +g_Events = 0x80172D2C; +g_PlaySfxStep = 0x8017365C; +g_EntityRanges = 0x80173660; +g_EventQueue = 0x80173668; +g_CurrentServant = 0x8017366C; +g_CurrentRoomX = 0x80173670; +g_CurrentRoomY = 0x80173674; +CreateEventEntity_Dupe = 0x80173B14; +ServantUpdateAnim = 0x8017865C; +DestroyEntity = 0x80178804; +AccumulateTowardZero = 0x80178870; +SearchForEntityInRange = 0x801788A8; +CalculateAngleToEntity = 0x80178928; +GetTargetPositionWithDistanceBuffer = 0x8017896C; +CalculateDistance = 0x801789E0; +ProcessEvent = 0x80178C08; +CreateEventEntity = 0x80178FDC; +IsMovementAllowed = 0x80179098; +CheckAllEntitiesValid = 0x801791B0; +ServantUnk0 = 0x8017925C; diff --git a/src/servant/tt_002/3678.c b/src/servant/tt_002/3678.c new file mode 100644 index 000000000..4a8fb7edc --- /dev/null +++ b/src/servant/tt_002/3678.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +#include "common.h" +#include + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_801739D0); + +// This is a duplicate CreateEventEntity which is lower in the file, but we need +// both to match the binary for PSX +void CreateEventEntity_Dupe(Entity* entityParent, s32 entityId, s32 params) { + Entity* entity; + s32 i; + + for (i = 0; i < 3; i++) { + entity = &g_Entities[5 + i]; + if (!entity->entityId) { + break; + } + } + + if (!entity->entityId) { + DestroyEntity(entity); + entity->entityId = entityId; + entity->zPriority = entityParent->zPriority; + entity->facingLeft = entityParent->facingLeft; + entity->flags = FLAG_KEEP_ALIVE_OFFCAMERA; + entity->posX.val = entityParent->posX.val; + entity->posY.val = entityParent->posY.val; + // Not necessarily making batFamBlueTrail here, but + // that's an Ext that works. Just needs parent at 0x8C. + entity->ext.batFamBlueTrail.parent = entityParent; + entity->params = params; + } +} + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80173BD0); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80173D60); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_801746E8); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80174998); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80174F0C); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_801753E4); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80175730); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80175A78); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80175DBC); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80176178); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80176504); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80176B6C); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80176C98); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80177380); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80177958); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80177AC4); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80177F64); + +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80177F84); + +#ifndef VERSION_PSP +#include "../servant_update_anim.h" +#endif + +#include "../../destroy_entity.h" + +#ifndef VERSION_PSP +#include "../accumulate_toward_zero.h" +#include "../search_for_entity_in_range.h" +#endif + +#include "../calculate_angle_to_entity.h" + +#include "../get_target_position_with_distance_buffer.h" + +#ifndef VERSION_PSP +#include "../calculate_distance.h" + +// There is some .rodata jumptable stuff going on with ProcessSfxState +// where the table is in the middle of the .rodata function +INCLUDE_ASM("servant/tt_002/nonmatchings/3678", func_us_80178A30); +// #include "../play_sfx.h" +#endif + +#include "../process_event.h" + +#include "../create_event_entity.h" + +#include "../is_movement_allowed.h" + +#ifndef VERSION_PSP +#include "../check_all_entities_valid.h" +#endif + +#include "../servant_unk0.h" + +INCLUDE_RODATA("servant/tt_002/nonmatchings/3678", func_us_80173994); + +INCLUDE_RODATA("servant/tt_002/nonmatchings/3678", func_us_801739C8); diff --git a/tools/dups/src/main.rs b/tools/dups/src/main.rs index 677a2178a..796b7955e 100644 --- a/tools/dups/src/main.rs +++ b/tools/dups/src/main.rs @@ -259,6 +259,13 @@ fn do_dups_report(output_file: Option, threshold: f64) { include_asm: get_all_include_asm("../../src/servant/tt_001"), path_matcher: "/tt_001/".to_string(), }, + SrcAsmPair { + asm_dir: String::from("../../asm/us/servant/tt_002/matchings/"), + src_dir: String::from("../../src/servant/tt_002"), + overlay_name: String::from("TT_002"), + include_asm: get_all_include_asm("../../src/servant/tt_002"), + path_matcher: "/tt_002/".to_string(), + }, SrcAsmPair { asm_dir: String::from("../../asm/us/st/cen/matchings/"), src_dir: String::from("../../src/st/cen/"), diff --git a/tools/progress.py b/tools/progress.py index d8606581f..048b82f41 100755 --- a/tools/progress.py +++ b/tools/progress.py @@ -371,6 +371,7 @@ if __name__ == "__main__": progress["borbo3"] = DecompProgressStats("borbo3", "boss/rbo3") progress["tt_000"] = DecompProgressStats("tt_000", "servant/tt_000") progress["tt_001"] = DecompProgressStats("tt_001", "servant/tt_001") + progress["tt_002"] = DecompProgressStats("tt_002", "servant/tt_002") hydrate_previous_metrics(progress, args.version) progress = remove_not_existing_overlays(progress)