From b82f54bb957ffdeda4105fe0b81e3923e107b291 Mon Sep 17 00:00:00 2001 From: cadmic Date: Thu, 15 Aug 2024 20:44:05 -0700 Subject: [PATCH] Decompile N64 anti-piracy checks in overlays (#2042) * Decompile N64 anti-piracy checks in overlays * Fix BSS splits (I think) * Use physical address and comment on meaning Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> --------- Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> --- include/cic6105.h | 8 ++++++++ include/variables.h | 1 + spec | 3 +++ src/boot/cic6105.c | 2 ++ src/overlays/actors/ovl_Bg_Zg/z_bg_zg.c | 10 ++++++++++ src/overlays/actors/ovl_En_Zl2/z_en_zl2.c | 20 ++++++++++++++------ src/overlays/actors/ovl_Fishing/z_fishing.c | 12 +++++++++++- tools/disasm/ntsc-1.2/files_boot.csv | 2 +- 8 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 include/cic6105.h diff --git a/include/cic6105.h b/include/cic6105.h new file mode 100644 index 0000000000..ab004d63a3 --- /dev/null +++ b/include/cic6105.h @@ -0,0 +1,8 @@ +#ifndef CIC6105_H +#define CIC6105_H + +#include "ultra64.h" + +extern u32 B_80008EE0; + +#endif diff --git a/include/variables.h b/include/variables.h index 930a4c2cad..3bb6a6794d 100644 --- a/include/variables.h +++ b/include/variables.h @@ -9,6 +9,7 @@ extern Mtx D_01000000; extern u32 osTvType; extern u32 osRomBase; extern u32 osResetType; +extern u32 osCicId; extern u32 osMemSize; extern u8 osAppNMIBuffer[0x40]; diff --git a/spec b/spec index c821e8b298..6c926d9566 100644 --- a/spec +++ b/spec @@ -20,6 +20,9 @@ beginseg include "$(BUILD_DIR)/src/boot/z_std_dma.o" include "$(BUILD_DIR)/src/boot/yaz0.o" include "$(BUILD_DIR)/src/boot/z_locale.o" +#if PLATFORM_N64 + include "$(BUILD_DIR)/src/boot/cic6105.o" +#endif #if OOT_DEBUG include "$(BUILD_DIR)/src/boot/assert.o" #endif diff --git a/src/boot/cic6105.c b/src/boot/cic6105.c index 8b13789179..6e5515b931 100644 --- a/src/boot/cic6105.c +++ b/src/boot/cic6105.c @@ -1 +1,3 @@ +#include "cic6105.h" +u32 B_80008EE0; diff --git a/src/overlays/actors/ovl_Bg_Zg/z_bg_zg.c b/src/overlays/actors/ovl_Bg_Zg/z_bg_zg.c index de6446e02f..e10ede8d2f 100644 --- a/src/overlays/actors/ovl_Bg_Zg/z_bg_zg.c +++ b/src/overlays/actors/ovl_Bg_Zg/z_bg_zg.c @@ -71,6 +71,16 @@ s32 func_808C0CC8(BgZg* this) { } void func_808C0CD4(BgZg* this, PlayState* play) { +#if PLATFORM_N64 + // Anti-piracy check, bars will not open if the check fails. + // The address 0x000002E8 is near the start of RDRAM, and is written when IPL3 copies itself to + // RDRAM after RDRAM has been initialized. Specifically, this is an instruction from some + // embedded RSP code at offset 0x7F8 into IPL3 (0xC86E2000 disassembles to `lqv $v14[0], ($3)`). + if (IO_READ(0x000002E8) != 0xC86E2000) { + return; + } +#endif + if (func_808C0C98(this, play) != 0) { this->action = 1; func_808C0C50(this); diff --git a/src/overlays/actors/ovl_En_Zl2/z_en_zl2.c b/src/overlays/actors/ovl_En_Zl2/z_en_zl2.c index c3867c17f7..f06b5fbd1a 100644 --- a/src/overlays/actors/ovl_En_Zl2/z_en_zl2.c +++ b/src/overlays/actors/ovl_En_Zl2/z_en_zl2.c @@ -447,17 +447,25 @@ void func_80B4F230(EnZl2* this, s16 arg1, s32 arg2) { s32 func_80B4F45C(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx, Gfx** gfx) { s32 pad; EnZl2* this = (EnZl2*)thisx; - Mtx* sp74; - MtxF sp34; - Vec3s sp2C; - s16 pad2; - s16* unk_1DC = this->unk_1DC; if (limbIndex == 14) { - sp74 = GRAPH_ALLOC(play->state.gfxCtx, sizeof(Mtx) * 7); + Mtx* sp74 = GRAPH_ALLOC(play->state.gfxCtx, sizeof(Mtx) * 7); + MtxF sp34; + Vec3s sp2C; + s16 pad2; + s16* unk_1DC = this->unk_1DC; + gSPSegment((*gfx)++, 0x0C, sp74); Matrix_Push(); + +#if PLATFORM_N64 + // Anti-piracy check, Zelda's hair is misshapen if the check fails + if (osCicId != 6105) { + Matrix_Scale(2.0f, 0.5f, 2.0f, MTXMODE_APPLY); + } +#endif + Matrix_Translate(pos->x, pos->y, pos->z, MTXMODE_APPLY); Matrix_RotateZYX(rot->x, rot->y, rot->z, MTXMODE_APPLY); Matrix_Push(); diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index b70769e2a6..42595eb432 100644 --- a/src/overlays/actors/ovl_Fishing/z_fishing.c +++ b/src/overlays/actors/ovl_Fishing/z_fishing.c @@ -10,8 +10,11 @@ #include "assets/objects/object_fish/object_fish.h" #include "ichain.h" #include "terminal.h" +#if PLATFORM_N64 +#include "cic6105.h" +#endif -#pragma increment_block_number "gc-eu:205 gc-eu-mq:205 gc-jp:207 gc-jp-ce:207 gc-jp-mq:207 gc-us:207 gc-us-mq:207" +#pragma increment_block_number "gc-eu:204 gc-eu-mq:204 gc-jp:206 gc-jp-ce:206 gc-jp-mq:206 gc-us:206 gc-us-mq:206" #define FLAGS ACTOR_FLAG_4 @@ -852,7 +855,14 @@ void Fishing_Init(Actor* thisx, PlayState* play2) { if (thisx->params < EN_FISH_PARAM) { FishingGroupFish* fish; +#if PLATFORM_N64 + // Anti-piracy check, if the check fails the line can't be reeled in if + // a fish is caught and the fish will always let go after 50 frames. + sReelLock = !(B_80008EE0 == 0xAD090010); +#else sReelLock = 0; +#endif + sFishingMain = this; Collider_InitJntSph(play, &sFishingMain->collider); Collider_SetJntSph(play, &sFishingMain->collider, thisx, &sJntSphInit, sFishingMain->colliderElements); diff --git a/tools/disasm/ntsc-1.2/files_boot.csv b/tools/disasm/ntsc-1.2/files_boot.csv index 248233ea98..a028cff131 100644 --- a/tools/disasm/ntsc-1.2/files_boot.csv +++ b/tools/disasm/ntsc-1.2/files_boot.csv @@ -126,7 +126,7 @@ offset,vram,.bss 72F0,80007750,src/boot/idle 7F00,80008360,src/boot/z_std_dma 8670,80008AD0,src/boot/yaz0 -8A80,80008EE0,src/boot/z_locale +8A80,80008EE0,src/boot/cic6105 8AA0,80008F00,src/libultra/io/driverominit 8B20,80008F80,src/libultra/io/piacs 8B40,80008FA0,src/libultra/os/initialize