Skip to content

Commit

Permalink
Fixed a bug with the game crashing on an original version of the game.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zero1UP committed Dec 27, 2019
1 parent 7c13f3e commit 2485dca
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 58 deletions.
14 changes: 12 additions & 2 deletions FragmentPatcher.cds
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// Fragment ELF Detection and Code Loader

address $8007a228
Expand All @@ -17,8 +18,9 @@ setreg t5,$8007537C
// Load the currently loaded elf text
lw t6 zero(t5)

// if t6 isn't currently anything terminate
beq t6 zero, :__EOF
// if t5 doesn't get set initially, it won't show the main elf till you come back from a
// menu
beq t6 zero, :__MainElfCodeLoader
nop

//If the main elf is loaded jump to the code loader
Expand Down Expand Up @@ -62,17 +64,21 @@ __OnlineElfCodeLoader:
ori t1,t1, $a400

__OnlineElfCodeLoaderAddress:

// Gets the address line to our code from the Code stack
lw t6,$000(t1)

// Gets the data line to our code from the Code stack
lw t7,0004(t1)

// Jump back to EOF if t6 is zero (t6 would contain the next adddress)
beq t6,zero :__EOF
nop

// Store the data line to the actual address
sw t7, zero(t6)
beq zero,zero :__OnlineElfCodeLoaderAddress

// We do not want to nop here for the delay slot
// Add 8 to t5 so it will grab the next address data pair
addiu t1,t1,$0008
Expand All @@ -83,17 +89,21 @@ __OfflineElfCodeLoader:
ori t1,t1, $a700

__OfflineElfCodeLoaderAddress:

// Gets the address line to our code from the Code stack
lw t6,$000(t1)

// Gets the data line to our code from the Code stack
lw t7,0004(t1)

// Jump back to EOF if t6 is zero (t6 would contain the next adddress)
beq t6,zero :__EOF
nop

// Store the data line to the actual address
sw t7, zero(t6)
beq zero,zero :__OfflineElfCodeLoaderAddress

// We do not want to nop here for the delay slot
// Add 8 to t5 so it will grab the next address data pair
addiu t1,t1,$0008
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ EE_BIN = fragmentPatcher.elf
EE_OBJS = fragmentPatcher.o menu.o systemHook.s
EE_LDFLAGS = -L$(PS2SDK)/sbv/lib
EE_LIBS = -lpad -ldebug -lcdvd -lc

all: $(EE_BIN)

clean:
Expand Down
73 changes: 24 additions & 49 deletions fragmentPatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "r5900_regs.h"
#include <iopheap.h>
#include <sbv_patches.h>
#include "math.h"
#include "menu.h"


Expand Down Expand Up @@ -117,9 +116,6 @@ static void loadModules(void)
}
}

/////////////////////////////////////////////////////////////////////
//waitPadReady
/////////////////////////////////////////////////////////////////////
static int waitPadReady(int port, int slot)
{
int state;
Expand All @@ -142,9 +138,6 @@ static int waitPadReady(int port, int slot)
return 0;
}

/////////////////////////////////////////////////////////////////////
//initalizePad
/////////////////////////////////////////////////////////////////////
static int initializePad(int port, int slot)
{

Expand Down Expand Up @@ -206,9 +199,7 @@ static int initializePad(int port, int slot)
return 1;
}

/////////////////////////////////////////////////////////////////////
//buttonStatts
/////////////////////////////////////////////////////////////////////

static void buttonStatts(int port, int slot)
{
int ret;
Expand All @@ -222,9 +213,7 @@ static void buttonStatts(int port, int slot)
}
}

/////////////////////////////////////////////////////////////////////
//checkPadConnected
/////////////////////////////////////////////////////////////////////

void checkPadConnected(void)
{
int ret, i;
Expand All @@ -242,9 +231,7 @@ void checkPadConnected(void)
}
}

/////////////////////////////////////////////////////////////////////
//pad_wat_button
/////////////////////////////////////////////////////////////////////

void pad_wait_button(u32 button)
{
while(1)
Expand All @@ -254,18 +241,6 @@ void pad_wait_button(u32 button)
}
}

void waitCdReady()
{
// Block until the dvdrom is ready to take commands
cdDiskReady(0);

// Spin up the cd/dvd
cdStandby();
}

/////////////////////////////////////////////////////////////////////
//getSyscallVTblAddr
/////////////////////////////////////////////////////////////////////
u32 getSyscallVTblAddr(void)
{
const s32 syscall_num[2] = { 0xFE, 0xFF };
Expand All @@ -291,9 +266,7 @@ u32 getSyscallVTblAddr(void)
return addr;
}

/////////////////////////////////////////////////////////////////////
//getVTblAddr
/////////////////////////////////////////////////////////////////////

int getVTblAddr(void)
{
//GET SYSCALL VECTOR ADDRESS
Expand Down Expand Up @@ -480,7 +453,7 @@ int getVTblAddr(void)
*(u32*)0x8007A248 = 0x3C0D8007;
*(u32*)0x8007A24C = 0x35AD537C;
*(u32*)0x8007A250 = 0x8DAE0000;
*(u32*)0x8007A254 = 0x11C00023;
*(u32*)0x8007A254 = 0x11C00009;
*(u32*)0x8007A258 = 0x00000000;
*(u32*)0x8007A25C = 0x114E0007;
*(u32*)0x8007A260 = 0x00000000;
Expand Down Expand Up @@ -546,6 +519,7 @@ int getVTblAddr(void)




*(u32*)0x800002FC = 0x0C01E800;


Expand All @@ -554,30 +528,31 @@ int getVTblAddr(void)

startGame();
}
//if (new_pad & PAD_SELECT)
//{
// ee_kmode_enter();

// ee_kmode_exit();


// startGame();
//}
}
return 0;
}

void startGame()
{
cdStop();

scr_printf(" Loading... ");

//wait for CD to spin up
waitCdReady();
// Shutdown
padPortClose(0, 0);
int cdWait = 6;

// 6 = Ready
// 0 = Error
// 2 = Ready
while (cdWait == 6)
{
cdWait = sceCdNCmdDiskReady();
}

if(cdWait == 2)
{
// Shutdown
padPortClose(0, 0);

SifExitRpc();
LoadExecPS2("cdrom0:\\SLPS_255.27;1", 0, NULL);
}

SifExitRpc();
LoadExecPS2("cdrom0:\\SLPS_255.27;1", 0, NULL); // needed for loading SCUS after patch
}
7 changes: 3 additions & 4 deletions menu.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "menu.h"
void menu_DisplayMain(void)
{
char *currentVersion = "Patch Version: 1.0.4 beta 2 \n";
char *currentVersion = "Patch Version: 1.0.5\n";

scr_printf(".hack//Fragment Patcher by 1UP\n");
scr_printf(currentVersion);
Expand All @@ -10,7 +10,6 @@ void menu_DisplayMain(void)
scr_printf("Press SQUARE for more information. \n");
scr_printf("Press CIRCLE to view about. \n");
scr_printf("Press CROSS to return to main screen. \n");
//scr_printf("Press SELECT to load the patch with O and X swapped. \n");
scr_printf("Press START to load the patch and start the game.");
}

Expand All @@ -30,8 +29,8 @@ void menu_PatchInformation(void)
scr_printf("Disable item loss on crash. (ONLINE ONLY) \n");
scr_printf("You will not have to have this setting set. \n");
scr_printf("------------------------------------------- \n");
scr_printf("BETA INFORMATION!! \n");
scr_printf("Changed where the patcher checks for which file is loaded. \n");
scr_printf("1.0.5 Changes \n");
scr_printf("Fixed a bug with the game crashing on an original version of the game. \n");
scr_printf("Press CROSS to return to main screen.");

}
1 change: 0 additions & 1 deletion menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ void menu_DisplayMain(void);
void menu_DisplayAbout(void);
void menu_PatchInformation(void);
#endif

3 changes: 2 additions & 1 deletion systemHook.s
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ _orig_jal:
lq $ra, 0($sp)
jr $ra
addiu $sp, $sp, 240
.end readPad
.end readPad

0 comments on commit 2485dca

Please sign in to comment.