Skip to content

Commit

Permalink
Match chetkido
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnlyZac authored Dec 2, 2024
1 parent 8488750 commit d4acd19
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
10 changes: 9 additions & 1 deletion config/symbol_addrs.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
_start = 0x100008; // type:func
_exit = 0x1000B8; // type:func

////////////////////////////////////////////////////////////////
// UNKNOWN MISCELLANEOUS
////////////////////////////////////////////////////////////////
__builtin_delete = 0x18d778; // type:func
memcmp = 0x1F59C4; // type:func

PvAllocGlobalImpl__Fi = 0x18D4B0; // type:func

_gpReg = 0x2832F0;

g_chzCiphertext = 0x2483b8; // size:0x9
g_chzThePasswordIs = 0x24a848; // size:0x14


////////////////////////////////////////////////////////////////
// Unknown file
// Related to save files
Expand Down Expand Up @@ -815,6 +822,7 @@ g_cframe = 0x2622cc; // size:0x4

////////////////////////////////////////////////////////////////
// P2/game.c
// TODO mangle function names
////////////////////////////////////////////////////////////////
StartupGame__Fv = 0x160070; // type:func

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ 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.
*
* @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.
Expand Down
2 changes: 1 addition & 1 deletion src/P2/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
43 changes: 42 additions & 1 deletion src/P2/joy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
#include <joy.h>
#include <clock.h>
#include <transition.h>
#include <game.h>
#include <text.h>
#include <screen.h>

//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

Expand Down Expand Up @@ -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);

0 comments on commit d4acd19

Please sign in to comment.