attempt to use tournament mode region for gecko codelist

- When booting a GALE01 ISO, use the tournament mode region to store the Gecko
  codelist. If the user is booting a 20XX ISO or some non-GALE01 ISO, just use
  the default codelist location.

- Let the codehandler read a pointer to the codelist to-be-used, and expect
  the kernel to fill in the pointer when writing codehandler to memory
This commit is contained in:
meta
2018-11-09 16:50:19 -06:00
parent 989d49178b
commit 321b9ae4ea
4 changed files with 79 additions and 10 deletions

View File

@@ -771,8 +771,11 @@ _packetdivide:
_codehandler:
mflr r29
lis r15, codelist@h
ori r15, r15, codelist@l
# Expect the kernel to write the codelist pointer
lis r13, codelist_addr@h
ori r13, r13, codelist_addr@l
lwz r15, 0(r13)
ori r7, r31, cheatdata@l # set pointer for storing data (before the codelist)
@@ -1676,6 +1679,11 @@ regbuffer:
.align 3
# Expect the kernel write a pointer to the codelist that we should use
.global codelist_addr
codelist_addr:
.long 0
codelist:
.space 2*4
.end

View File

@@ -48,8 +48,11 @@ _start:
sth r21, 0x4010(r3) # disable MP3 memory protection
mflr r29
lis r15, codelist@h
ori r15, r15, codelist@l
# Expect the kernel to write the codelist pointer
lis r13, codelist_addr@h
ori r13, r13, codelist_addr@l
lwz r15, 0(r13)
ori r7, r31, cheatdata@l # set pointer for storing data (before the codelist)
@@ -977,6 +980,11 @@ regbuffer:
.align 3
# Expect the kernel write a pointer to the codelist that we should use
.global codelist_addr
codelist_addr:
.long 0
codelist:
.space 2*4
.end

View File

@@ -56,6 +56,8 @@ static FIL GameFile;
static u64 LastOffset64 = ~0ULL;
bool Datel = false;
char GAME_TITLENAME[0x100];
// CISO: On-disc structure.
// Temporarily loaded into cache memory.
#define CISO_MAGIC 0x4349534F /* "CISO" */
@@ -350,6 +352,10 @@ bool ISOInit()
/* Get BI2.bin region code */
ISOReadDirect(isoTmpBuf, sizeof(BI2region), 0x458 + ISOShift64);
memcpy(&BI2region, isoTmpBuf, sizeof(BI2region));
// Save ISO game string (we can distinguish between ISOs if necessary)
ISOReadDirect(&GAME_TITLENAME, 0x100, 0x20 + ISOShift64);
/* Reset Cache */
CacheInited = 0;

View File

@@ -44,6 +44,11 @@ u32 GAME_ID = 0;
u16 GAME_ID6 = 0;
u32 TITLE_ID = 0;
// First 0x100 bytes of the ISO title string
extern char GAME_TITLENAME[];
static const char TITLE_20XX[] = "Super Smash Bros Melee 20XX 4.07";
#define PATCH_OFFSET_START (0x3000 - (sizeof(u32) * 3))
#define PATCH_OFFSET_ENTRY PATCH_OFFSET_START - FakeEntryLoad_size
static u32 POffset = PATCH_OFFSET_ENTRY;
@@ -73,6 +78,9 @@ extern vu32 TRIGame;
#define SONICRIDERS_HOOK_NTSCJ 0x5551A8
#define SONICRIDERS_HOOK_PAL 0x5554E8
#define CODELIST_TOURNAMENT_BASE 0x001910E0
#define CODELIST_TOURNAMENT_END 0x0019AF4C
u32 PatchState = PATCH_STATE_NONE;
u32 PSOHack = PSO_STATE_NONE;
u32 ELFLoading = 0;
@@ -3185,6 +3193,11 @@ void DoPatches( char *Buffer, u32 Length, u32 DiscOffset )
}
if(cheatsWanted || debuggerWanted)
{
u32 cheats_start;
u32 cheats_area;
u32 codelist_addr;
//setup jump to codehandler stub
if(OSSleepThreadHook || PADHook)
{
@@ -3192,7 +3205,6 @@ void DoPatches( char *Buffer, u32 Length, u32 DiscOffset )
if(OSSleepThreadHook) PatchB( codehandler_stub_offset, OSSleepThreadHook );
if(PADHook) PatchB( codehandler_stub_offset, PADHook );
}
u32 cheats_start;
if(debuggerWanted)
{
//copy into dedicated space
@@ -3200,21 +3212,56 @@ void DoPatches( char *Buffer, u32 Length, u32 DiscOffset )
//copy game id for debugger
memcpy((void*)0x1800, (void*)0, 8);
//main code area start
cheats_start = 0x1000 + codehandler_size - 8;
cheats_start = 0x1000 + codehandler_size - 8;
codelist_addr = 0x1000 + codehandler_size - 12;
}
else
{
//copy into dedicated space
memcpy( (void*)0x1000, codehandleronly, codehandleronly_size );
//main code area start
cheats_start = 0x1000 + codehandleronly_size - 8;
cheats_start = 0x1000 + codehandleronly_size - 8;
codelist_addr = 0x1000 + codehandleronly_size - 12;
}
u32 cheats_area = (POffset < cheats_start) ? 0 : (POffset - cheats_start);
if(cheats_area > 0)
{
cheats_area = (POffset < cheats_start) ? 0 : (POffset - cheats_start);
/* Ishiiruka uses the tournament mode region [0x801910e0-0x8019af4c] for
* extra codehandler space when booting Melee. Note that the codehandler
* must be patched to deal with this. Additionally, in order for this to
* work, we need to always make sure that 0x8022d638 is patched to redirect
* the menu somewhere else. In case the user provides a GCT without this
* patch, apply it here to avoid crashes.
*
* 20XX builds use this region for storing custom data/code, so just revert
* to the standard codelist address if the user is booting some 20XX ISO, or
* if the user chooses to boot any other non-GALE01 ISO.
*/
if (TITLE_ID == 0x47414C) {
// If this is *not* a 20XX ISO, use tournament region and apply patch
if (strncmp(GAME_TITLENAME, TITLE_20XX, sizeof(TITLE_20XX)) != 0)
{
// Patch to redirect tournament mode menu to debug menu
write32(0x0022d6e8, 0x38000006);
dbgprintf("Patch:Redirect Melee tournament mode to debug menu\r\n");
cheats_start = CODELIST_TOURNAMENT_BASE;
cheats_area = CODELIST_TOURNAMENT_END - CODELIST_TOURNAMENT_BASE;
}
else
{
dbgprintf("Patch:Detected 20XX ISO, using default codehandler behaviour\r\n");
}
}
// The pointer to the codelist should always be at (<codehandler size> - 0xC)
if (cheats_area > 0) {
dbgprintf("Possible Code Size: %08x\r\n", cheats_area);
dbgprintf("Codelist at 0x%08x\r\n", (cheats_start | 0x80000000));
memset((void*)cheats_start, 0, cheats_area);
write32(codelist_addr, (cheats_start | 0x80000000));
}
//copy in gct file if requested
if( cheatsWanted && TRIGame != TRI_SB && useipl == 0 )
{