From d4acd190fe932a54f86c30f7ff42c8e4a5cbe547 Mon Sep 17 00:00:00 2001 From: Zac Date: Mon, 2 Dec 2024 19:36:14 +0000 Subject: [PATCH] Match chetkido --- config/symbol_addrs.txt | 10 +++++++++- include/text.h | 4 ++-- src/P2/game.c | 2 +- src/P2/joy.c | 43 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/config/symbol_addrs.txt b/config/symbol_addrs.txt index 86ba6235..a9a36b8e 100644 --- a/config/symbol_addrs.txt +++ b/config/symbol_addrs.txt @@ -1,6 +1,9 @@ _start = 0x100008; // type:func _exit = 0x1000B8; // type:func +//////////////////////////////////////////////////////////////// +// UNKNOWN MISCELLANEOUS +//////////////////////////////////////////////////////////////// __builtin_delete = 0x18d778; // type:func memcmp = 0x1F59C4; // type:func @@ -8,6 +11,10 @@ PvAllocGlobalImpl__Fi = 0x18D4B0; // type:func _gpReg = 0x2832F0; +g_chzCiphertext = 0x2483b8; // size:0x9 +g_chzThePasswordIs = 0x24a848; // size:0x14 + + //////////////////////////////////////////////////////////////// // Unknown file // Related to save files @@ -815,6 +822,7 @@ g_cframe = 0x2622cc; // size:0x4 //////////////////////////////////////////////////////////////// // P2/game.c +// TODO mangle function names //////////////////////////////////////////////////////////////// StartupGame__Fv = 0x160070; // type:func @@ -825,7 +833,7 @@ call_search_level_by_id = 0x160180; // type:func FFindLevel = 0x1601A0; // type:func get_level_completion_by_id = 0x1601D8; // type:func tally_world_completion = 0x160208; // type:func -get_game_completion = 0x1602A0; // type:func +get_game_completion__Fv = 0x1602A0; // type:func UnlockIntroCutsceneFromWid = 0x160340; // type:func DefeatBossFromWid = 0x1603E8; // type:func UnlockEndgameCutscenesFromFgs = 0x1604B8; // type:func diff --git a/include/text.h b/include/text.h index 85125fdc..10f68450 100644 --- a/include/text.h +++ b/include/text.h @@ -132,7 +132,7 @@ extern "C" * * @param pchz The string to count. */ - uint strlen(char *pchz); + //uint strlen(char *pchz); // conflicts with built-in strlen /** * @brief Copy a string. @@ -140,7 +140,7 @@ extern "C" * @param pchzDst The destination string. * @param pchzSrc The source string. */ - char *strcpy(char *pchzDst, char *pchzSrc); + //char *strcpy(char *pchzDst, char *pchzSrc); // conflicts with built-in strcpy /** * @brief Search for a character in a string. diff --git a/src/P2/game.c b/src/P2/game.c index f3e3212b..e9337a16 100644 --- a/src/P2/game.c +++ b/src/P2/game.c @@ -26,7 +26,7 @@ INCLUDE_ASM(const s32, "P2/game", get_level_completion_by_id); INCLUDE_ASM(const s32, "P2/game", tally_world_completion); -INCLUDE_ASM(const s32, "P2/game", get_game_completion); +INCLUDE_ASM(const s32, "P2/game", get_game_completion__Fv); INCLUDE_ASM(const s32, "P2/game", UnlockIntroCutsceneFromWid); diff --git a/src/P2/joy.c b/src/P2/joy.c index d973e758..14c52c43 100644 --- a/src/P2/joy.c +++ b/src/P2/joy.c @@ -3,6 +3,14 @@ #include #include #include +#include +#include +#include + +//static char g_chzThePasswordIs[] = "The password is: %s"; +//static char g_chzCiphertext[] = "@KFWHJGL"; // decrypts to "chetkido" +extern char g_chzThePasswordIs[]; +extern char g_chzCiphertext[]; extern void* PvAllocGlobalImpl(int); // todo: remove when function is known @@ -237,6 +245,39 @@ INCLUDE_ASM(const s32, "P2/joy", AddFcht__Fi); INCLUDE_ASM(const s32, "P2/joy", func_0016F470); -INCLUDE_ASM(const s32, "P2/joy", Chetkido__Fv); +void Chetkido() { + // Check preconditions + int widCur; + FGS cmpFlags; + GS *gsCur; + + widCur = (g_pgsCur->gameworldCur << 8) | (g_pgsCur->worldlevelCur); + if (widCur != 0x400) // level is "A Perilous Ascent" + return; + + cmpFlags = get_game_completion(); + if ((cmpFlags & (FGS_HalfClues|FGS_AllClues)) != (FGS_HalfClues|FGS_AllClues)) // clues collected + return; + + gsCur = g_pgsCur; + if (gsCur->ccoin != 99 || gsCur->clife != 0) // 99 coins and 0 lives + return; + + // Decrypt chetkido using XOR cipher, key 0x23 + char buf[64]; + char achzPlaintext[16]; + char *pchCur = &achzPlaintext[0]; + + strcpy(achzPlaintext, g_chzCiphertext); + while (*pchCur != '\0') { + *pchCur++ ^= 0x23; + } + + // Show note blot with message + sprintf(buf, g_chzThePasswordIs, achzPlaintext); + ((NOTE*)&g_note.unk278)->pvtnote->pfnSetNoteAchzDraw((NOTE*)&g_note.unk278, buf); + SetBlotDtVisible((NOTE *)&g_note.unk278, 10.0f); + ((NOTE*)&g_note.unk278)->pvtnote->pfnShowBlot((NOTE*)&g_note.unk278); +} INCLUDE_ASM(const s32, "P2/joy", StartupCodes__Fv);