Skip to content

Commit

Permalink
Merge pull request #4 from LuminarLight/tool-mode
Browse files Browse the repository at this point in the history
Tool mode
  • Loading branch information
LuminarLight authored Feb 3, 2024
2 parents 7c71bdb + be61841 commit 261c292
Show file tree
Hide file tree
Showing 30 changed files with 622 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ oprofile_data/
/bin/bios
/bin/cache
/bin/cheats
/bin/patches
#/bin/patches
/bin/covers
/bin/dumps
/bin/gamesettings
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ If you have any changes that you think would improve the emulator but would get
- Included 'Sanity' in the application's name at most places.
- Reworked the auto-updater. It no longer relies on the PCSX2 website, instead it now relies only on GitHub. This gives us full independence.
- Integrated memory-increasing changes from the [128MB Build](https://github.com/xTVaser/pcsx2-rr/tree/128mb-build) of PCSX2, which means that we have 128MB EE memory now. This shouldn't impact games that don't use it.
- If a 'DRIVERS\FIREWIRE.IRX' or a 'DISKINFO.BIN' file exists on the disc, then it will be treated as the main ELF for booting and CRC purposes. If neither are found, the old behaviour will be used (looking up 'SYSTEM.CNF' and getting ELF path from there). This had to be done because in Jak pre-release builds, the "official" ELF is just a loader for these files, and this loader is usually fully identical between different pre-release builds of the same Jak game, which means they also have same CRC, making patches and everything impossible. But the FIREWIRE.IRX and DISKINFO.BIN files are (almost always) unique, allowing us to uniquely identify these builds.
- If a 'DRIVERS\FIREWIRE.IRX' or a 'DISKINFO.BIN' file exists on the disc, then it will be treated as the main ELF for booting and CRC purposes. If neither are found, the old behaviour will be used (looking up 'SYSTEM.CNF' and getting ELF path from there). This had to be done because in Jak pre-release builds, the "official" ELF is just a loader for these files, and this loader is usually fully identical between different pre-release builds of the same Jak game, which means they also have same CRC, making patches and everything impossible. But the FIREWIRE.IRX and DISKINFO.BIN files are (almost always) unique, allowing us to uniquely identify these builds. A nice side-effect of booting these files directly is that we completely avoid the WIBU protection.
- Assign serial code 'X' to ISOs where we treat FIREWIRE.IRX or DISKINFO.BIN as the main ELF. Because per-game settings for some reason don't work if the serial is empty.
- GitHub releases for the project are no longer automatic. I think manual is better for a project like this.
- Each release can now have a message that will appear for users in the auto updater window. The commit list will still be there as well.
- Added a 'Enable TOOL Mode' toggle. Basically patch segregation. When a Jak game is booted in Debug Mode, the memory changes significantly. This means that patches made for the game running in normal mode corrupt the game when running in debug mode. When TOOL Mode is enabled, the emulator will auto-load patches with 'TOOL' label. It will also attempt to load patches with 'Widescreen 16:9 TOOL' and 'No-Interlacing TOOL' labels instead of their TOOL-less counterparts, but only if all other conditions are met (for example the setting that force-loads widescreen patches).
- When you look at the patches of a game, normally it doesn't indicate whether a patch would get auto-loaded due to global settings or not. Now there is an indicator for this - if a patch will get loaded due to global settings, it will be highlighted in green in the list. This is especially useful if you want to have a clear picture when you are using the patch segregation features.
- Imported and reworked the Jak Debug Mode patches from the [128MB Build](https://github.com/xTVaser/pcsx2-rr/tree/128mb-build) (the author field was filled where it was determinable, otherwise it was left empty - please contact me if there are any mistakes in this), and also added some new ones. These will automatically load when TOOL Mode is enabled.

### Plans/TODO:
- Invent a way to quickly toggle between "TOOL Mode" and normal mode, and maybe also separate the patches somehow. When a Jak game is booted in Debug Mode, the memory changes significantly. So patches made for the game running in normal mode would likely corrupt the game when running in debug mode.
- Add the Jak debug mode pnach files. Need to rework them a bit for the new pnach format.
- Properly get the serial even if we use FIREWIRE.IRX or DISKINFO.BIN as main ELF for an ISO.
- Prevent non-labelled patches. This is PCSX2-Sanity, we can expect our users to adapt their pnach files. In most cases they just have to add one line to the top of the file.
- Make the release notes of the repository customizable, instead of always using the last commit description.


And here is the parent's README:
Expand Down
2 changes: 2 additions & 0 deletions bin/patches/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*3A84D099*
*C20596DB*
32 changes: 32 additions & 0 deletions bin/patches/SCED-51700_F41C1B29_Jak2junedemoPAL_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[TOOL]
gametitle=Jak II: Renegade [Demo] - (PAL)(SCED-51700)
author=Luminar
description=Makes the game boot in Debug Mode. You will spawn in the void. Use the Debug Menu to escape.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits
comment=Credits to Luminar Light for making this pnach.
comment=You will spawn in the void. Use the Debug Menu to escape.

// NOP Disabling MasterDebug
patch=0,EE,00100400,word,00000000
// NOP Disabling DebugSegment
patch=0,EE,00100408,word,00000000
// NOP SendFromBufferD call in InitListener - This is called only when MasterDebug is on
patch=0,EE,00108930,word,00000000

// 0x4ff0000 for global heap initialization - Set in InitMachine
patch=0,EE,001031dc,word,3c0604ff

// This is about changing the stack pointer
// Shoves a MIPS instruction into near the very top of the entry point
// Ghidra blows up here, but binary ninja can handle it
// Orginally at this position there is `2D E8 40 00` - `daddu $sp, $v0, $zero`
// This changes it to - `lui sp, 0x0800` Which loads the value 0x0800 to the stackpointer register, modifying it.
patch=0,EE,0010017c,word,3c1d0800

// Change DebugBootMessage from `demo` to `play`.
patch=0,EE,00127610,word,79616c70

// The level that the game wants to load on startup with 'play' DebugBootMessage is missing. Getting around this problem with DebugBootLevel is not a correct solution, since it modifies how the game looks for DGO files - making most levels unreachable.
// It is possible to tell the game to load a different DGO instead of the missing one. The patches below will make the game load 'DEMO.DGO' instead of 'PRI.DGO'.
// This is the only level that it wants on startup - the game will work fine now, but you will spawn in the void. Just use the Debug Menu to escape.
patch=1,EE,0087AB78,word,6f6d6564
11 changes: 11 additions & 0 deletions bin/patches/SCES-50361_9C712FF0_JakTPLpal_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[TOOL]
gametitle=Jak and Daxter: The Precursor Legacy - (PAL-M6) - (SCES-50361)
author=Luminar
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits
comment=Credits to Luminar Light for making the patch for this game build.

// NOP Disabling DebugSegment
patch=0,EE,00100290,word,00000000
// NOP Disabling MasterDebug
patch=0,EE,0010029c,word,00000000
23 changes: 23 additions & 0 deletions bin/patches/SCES-51608_2479F4A9_Jak2pal_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[TOOL]
gametitle=Jak II: Renegade - (PAL-M7)(SCES-51608)
author=Luminar
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits
comment=Credits to Luminar Light for making the patch for this game build.

// NOP Disabling MasterDebug
patch=0,EE,001003f8,word,00000000
// NOP Disabling DebugSegment
patch=0,EE,00100400,word,00000000
// NOP SendFromBufferD call in InitListener - This is called only when MasterDebug is on
patch=0,EE,00108d88,word,00000000

// 0x4ff0000 for global heap initialization - Set in InitMachine
patch=0,EE,00103364,word,3c0604ff

// This is about changing the stack pointer
// Shoves a MIPS instruction into near the very top of the entry point
// Ghidra blows up here, but binary ninja can handle it
// Orginally at this position there is `2D E8 40 00` - `daddu $sp, $v0, $zero`
// This changes it to - `lui sp, 0x0800` Which loads the value 0x0800 to the stackpointer register, modifying it.
patch=0,EE,0010017c,word,3c1d0800
23 changes: 23 additions & 0 deletions bin/patches/SCES-52460_12804727_Jak3pal_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[TOOL]
gametitle=Jak 3 - (PAL-M7)(SCES-52460)
author=Luminar
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits in Jak 1/2. ELF edits for Jak 3 figured out by xTVaser.
comment=Credits to Luminar Light for making the patch for this game build.

// NOP Disabling MasterDebug
patch=0,EE,00100404,word,00000000
// NOP Disabling DebugSegment
patch=0,EE,00100408,word,00000000
// NOP SendFromBufferD call in InitListener - This is called only when MasterDebug is on
patch=0,EE,00109998,word,00000000

// 0x4ff0000 for global heap initialization - Set in InitMachine
patch=0,EE,0010372c,word,3c0604ff

// This is about changing the stack pointer
// Shoves a MIPS instruction into near the very top of the entry point
// Ghidra blows up here, but binary ninja can handle it
// Orginally at this position there is `2D E8 40 00` - `daddu $sp, $v0, $zero`
// This changes it to - `lui sp, 0x0800` Which loads the value 0x0800 to the stackpointer register, modifying it.
patch=0,EE,0010017c,word,3c1d0800
68 changes: 68 additions & 0 deletions bin/patches/SCES_53286_DF659E77_JakXpal_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[TOOL]
gametitle=Jak X (PAL)(SCES-53286)
author=Luminar
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to Luminar for making the patch for this build.
comment=Special thanks to water111 and Vaser for their relevant research done for earlier Jak games. It helped make this possible.

//---// The following patches are on the "ELF side". //---//
// The ELF of Jak X is encrypted/packed/compressed (not sure which). It unpacks itself while booting. So analyzing it is a bit more difficult, but doable if you use a memory dump.
// If you want to patch the "early part" of memory, you should add condition (E-type extended) patches to ensure you only write after the unpacking is done.

// nop the disabling of MasterDebug, this will make MasterDebug stay 1
// Edit: We don't actually need this, and I couldn't find a way to make the game work with MasterDebug on. So this patch is commented out for now, but kept here for reference.
//patch=1,EE,00266884,word,00000000

// nop the disabling of DebugSegment, this will make DebugSegment stay 1
patch=1,EE,0026688c,word,00000000
// nop the disabling of DebugSymbols, this will make DebugSymbols stay 1
patch=1,EE,00266898,word,00000000

// The following patch was copied from Jak 3's patches (found the same thing in Jak X), but since it only matters with MasterDebug, we can comment it out.
// NOP SendFromBufferD call in InitListener - This is called only when MasterDebug is on
//patch=1,EE,00270470,word,00000000

// Extra console logs. Very useful.
// The E-type patch is needed because writing the patch too early causes weird problems, preventing us from booting the game.
patch=1,EE,E00027D2,extended,00282EC1
patch=1,EE,001EDA00,extended,00000001

// nop the weird function call in InitMachine that returns something but we don't use it because I rewrote the init heap function calls.
patch=1,EE,0026a054,word,00000000

// Change malloc param to 0x10, because it is like that in Jak 3 and it works.
patch=1,EE,0026a064,word,24040010

// Rewrite init heap function call for global heap.
patch=1,EE,0026a0d4,word,8e04bb40
patch=1,EE,0026a0d8,word,3c0604d2
patch=1,EE,0026a0dc,word,34c609a0
patch=1,EE,0026a0e0,word,00402825
patch=1,EE,0026a0e4,word,0c096e30
patch=1,EE,0026a0e8,word,00000000

// Rewrite init heap function call for debug heap.
patch=1,EE,0026a10c,word,3c0f0026
patch=1,EE,0026a110,word,3c0602f0
patch=1,EE,0026a114,word,8de4bb44
patch=1,EE,0026a118,word,00000000
patch=1,EE,0026a11c,word,0c096e30
patch=1,EE,0026a120,word,3c050500

// This was copied straight from the Jak 3 patches (I found the same place in Jak X).
// This is about changing the stack pointer
// Shoves a MIPS instruction into near the very top of the entry point
// Ghidra blows up here, but binary ninja can handle it
// Orginally at this position there is `2D E8 40 00` - `daddu $sp, $v0, $zero`
// This changes it to - `lui sp, 0x0800` Which loads the value 0x0800 to the stackpointer register, modifying it.
patch=1,EE,002665d4,word,3c1d0800

//---// The following patches are on the "GOAL side". //---//

// Make 'read-sound-info-tweaks' unable to get stuck in a while loop, by ruining the loop itself.
// This is needed to be able to boot the game in "debug mode". Without this patch, the game will get stuck forever, after printing "reading sound info ..." twice.
patch=1,EE,067a69b4,word,00000000

// Make 'set-blackout-frames' always act as if the parameter was 0. The other branch will never be called.
// This gets rid of the (sometimes infinite) blackout you get when using Game... Continue... to warp to a continue-point.
patch=1,EE,00ad3834,word,00000000
11 changes: 11 additions & 0 deletions bin/patches/SCPS-15021_EDE4FE64_JakTPLntscj_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[TOOL]
gametitle=Jak x Daxter: Kyuusekai no Isan - (NTSC-J) - (SCPS-15021)
author=Luminar
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits
comment=Credits to Luminar Light for making the patch for this game build.

// NOP Disabling DebugSegment
patch=0,EE,0010028c,word,00000000
// NOP Disabling MasterDebug
patch=0,EE,00100298,word,00000000
28 changes: 28 additions & 0 deletions bin/patches/SCPS-15057_B4976DAF_Jak2ntscj_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[TOOL]
gametitle=Jak II - (NTSC-J)(SCPS-15057)
//author=
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits

// NOP Disabling MasterDebug
patch=0,EE,001003f8,word,00000000
// NOP Disabling DebugSegment
patch=0,EE,00100400,word,00000000
// NOP SendFromBufferD call in InitListener - This is called only when MasterDebug is on
patch=0,EE,00108cd0,word,00000000

// 0x4ff0000 for global heap initialization - Set in InitMachine
patch=0,EE,001032bc,word,3c0604ff

// This is about changing the stack pointer
// Shoves a MIPS instruction into near the very top of the entry point
// Ghidra blows up here, but binary ninja can handle it
// Orginally at this position there is `2D E8 40 00` - `daddu $sp, $v0, $zero`
// This changes it to - `lui sp, 0x0800` Which loads the value 0x0800 to the stackpointer register, modifying it.
patch=0,EE,0010017c,word,3c1d0800

// Example - Changing the Starting Level, Disabled by Default
// Load halfpipe level by default - "halfpipe" BigEndian - 68 61 6c 66 | 70 69 70 65
// LittleEndian:
//patch=0,EE,00127f10,word,666C6168
//patch=0,EE,00127f14,word,65706970
10 changes: 10 additions & 0 deletions bin/patches/SCUS-97124_1B3976AB_JakTPLntscv1_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[TOOL]
gametitle=Jak and Daxter - The Precursor Legacy - (U) - (SCUS-97124)
//author=
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits

// NOP Disabling DebugSegment
patch=0,EE,00100290,word,00000000
// NOP Disabling MasterDebug
patch=0,EE,0010029c,word,00000000
10 changes: 10 additions & 0 deletions bin/patches/SCUS-97124_472E7699_JakTPLntscv2_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[TOOL]
gametitle=Jak and Daxter - The Precursor Legacy - (U) - (SCUS-97124)
//author=
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits

// NOP Disabling DebugSegment
patch=0,EE,00100290,word,00000000
// NOP Disabling MasterDebug
patch=0,EE,0010029c,word,00000000
28 changes: 28 additions & 0 deletions bin/patches/SCUS-97265_9184AAF1_Jak2ntsc_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[TOOL]
gametitle=Jak II - (U)(SCUS-97265)
//author=
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits

// NOP Disabling MasterDebug
patch=0,EE,001003f8,word,00000000
// NOP Disabling DebugSegment
patch=0,EE,00100400,word,00000000
// NOP SendFromBufferD call in InitListener - This is called only when MasterDebug is on
patch=0,EE,00108cd0,word,00000000

// 0x4ff0000 for global heap initialization - Set in InitMachine
patch=0,EE,001032bc,word,3c0604ff

// This is about changing the stack pointer
// Shoves a MIPS instruction into near the very top of the entry point
// Ghidra blows up here, but binary ninja can handle it
// Orginally at this position there is `2D E8 40 00` - `daddu $sp, $v0, $zero`
// This changes it to - `lui sp, 0x0800` Which loads the value 0x0800 to the stackpointer register, modifying it.
patch=0,EE,0010017c,word,3c1d0800

// Example - Changing the Starting Level, Disabled by Default
// Load halfpipe level by default - "halfpipe" BigEndian - 68 61 6c 66 | 70 69 70 65
// LittleEndian:
//patch=0,EE,00127f10,word,666C6168
//patch=0,EE,00127f14,word,65706970
33 changes: 33 additions & 0 deletions bin/patches/SCUS-97273_A2034C69_Jak2marchdemoNTSC_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[TOOL]
gametitle=Jak II [Demo] - (U)(SCUS-97273)
author=Luminar
description=Makes the game boot in Debug Mode. You will spawn in the void. Use the Debug Menu to escape.
comment=Enables Developer/Debug Mode - Credit to water111 and Vaser for discovering / documenting the required ELF edits for the Jak 2 Demo.
comment=Thanks to Luminar Light for figuring out how to get around the missing level problem.
comment=You will spawn in the void. Use the Debug Menu to escape.

// NOP Disabling MasterDebug
patch=0,EE,001002ec,word,00000000
// NOP Disabling DebugSegment
patch=0,EE,001002f4,word,00000000
// NOP SendFromBufferD call in InitListener - This is called only when MasterDebug is on
patch=0,EE,00108660,word,00000000

// 0x4ff0000 for global heap initialization - Set in InitMachine
patch=0,EE,00102fac,word,3c0604ff

// This is about changing the stack pointer
// Shoves a MIPS instruction into near the very top of the entry point
// Ghidra blows up here, but binary ninja can handle it
// Orginally at this position there is `2D E8 40 00` - `daddu $sp, $v0, $zero`
// This changes it to - `lui sp, 0x0800` Which loads the value 0x0800 to the stackpointer register, modifying it.
patch=0,EE,00100068,word,3c1d0800

// This changes the DebugBootMessage from `demo` to `play`.
patch=0,EE,00126e10,word,79616c70

// The levels that the game wants to load on startup with 'play' DebugBootMessage are missing. Getting around this problem with DebugBootLevel is not a correct solution, since it modifies how the game looks for DGO files - making most levels unreachable.
// It is possible to tell the game to load a different DGO instead of the missing ones. The patches below will make the game load 'DEMO.DGO' instead of 'FEA.DGO' and 'PRI.DGO'.
// These are the only two levels that it wants on startup - the game will work fine now, but you will spawn in the void. Just use the Debug Menu to escape.
patch=1,EE,0077BB18,word,6f6d6564
patch=1,EE,0077C1B8,word,6f6d6564
22 changes: 22 additions & 0 deletions bin/patches/SCUS-97330_644CFD03_Jak3ntsc_DebugMode.pnach
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[TOOL]
gametitle=Jak 3 - (U)(SCUS-97330)
//author=
description=Makes the game boot in Debug Mode.
comment=Enables Developer/Debug Mode - Credit to water111 for discovering / documenting the required ELF edits in Jak 1/2. ELF edits for Jak 3 figured out by xTVaser.

// NOP Disabling MasterDebug
patch=0,EE,00100404,word,00000000
// NOP Disabling DebugSegment
patch=0,EE,00100408,word,00000000
// NOP SendFromBufferD call in InitListener - This is called only when MasterDebug is on
patch=0,EE,001098f0,word,00000000

// 0x4ff0000 for global heap initialization - Set in InitMachine
patch=0,EE,00103694,word,3c0604ff

// This is about changing the stack pointer
// Shoves a MIPS instruction into near the very top of the entry point
// Ghidra blows up here, but binary ninja can handle it
// Orginally at this position there is `2D E8 40 00` - `daddu $sp, $v0, $zero`
// This changes it to - `lui sp, 0x0800` Which loads the value 0x0800 to the stackpointer register, modifying it.
patch=0,EE,0010017c,word,3c1d0800
Loading

0 comments on commit 261c292

Please sign in to comment.