News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: How am I supposed to hack PSX games?  (Read 8180 times)

Raccoon Sam

  • Jr. Member
  • **
  • Posts: 58
  • Left is Right and Right is Wrong
    • View Profile
    • Twitter
How am I supposed to hack PSX games?
« on: June 06, 2014, 03:36:02 am »
Probably safe to mention right now that I'm a mac user. I can still run most Windows apps through a compatibility layer, but if there's a native way, I'd rather go with that.

So, I've previously dealt only with NES/SNES/Game Boy/Wonderswan games when it comes to hacking, and with a hex editor and a brute-force approach, I've always managed. It's just one file I'm editing, and the changes I make can be instantly seen by running them on an emulator.
With PSX though, I can get the ISO, mount it, and have read access to all the files. I can view the individual files, but because it's a CD ROM image, writing is forbidden.
My intuition tells me that I should copy all the files to my hard drive and edit them, but then I won't be able to run them on an emulator anymore(?). The ones I've used have only "Open Image file" or "Boot from CD" options.
So far the only even remotely reasonable way I can think of is editing the ISO file itself (like a SNES ROM), but although the changes I make are instant, I lose the luxury of a file directory thus having to keep track of offsets and pointers.

Is there some trick that gives me write access to mounted Images or an emulator that allows booting from a folder?  :-[

weissvulf

  • Sr. Member
  • ****
  • Posts: 324
  • Good news! An anomaly solved the enigma.
    • View Profile
Re: How am I supposed to hack PSX games?
« Reply #1 on: June 06, 2014, 05:18:21 am »
It really depends on what you are editing and when the game loads it of the CD.
 
What I do is make edits in an emulator save state, then when they are perfected, transfer the edits into the ISO's files.

PS1 games tend to load the EXE and "universal" resources into RAM at boot and leave them there. Changes to the ISO won't show up in an emulator if that data is already loaded in RAM (without a full reset). But some resources are loaded from the CD mid-game as needed.

If what you are editing is in a file that is loaded mid-game, you can play the ISO directly in the emulator (NOT by mounting it in a virtual drive), then make a save state right before the file is loaded from CD to RAM. Then if you edit the ISO directly, the changes should pass to the emulator as the file is loaded without doing a full reset.

If you want to edit a save state, remember that many emulators compress their saves by default.  You should be able to decompress the save and they will still load in the emulator. I think epsxe uses .gz compression, pSX doesn't use compression.

Another useful tidbit you might not know if you're used to cartridge games:
CD images (.bin etc) contain sector data as well as the actual file data. If you edit the ISO directly, you will see sector tags injected into the data at regular intervals (every 0x800 bytes). CDMage is the best tool I know that can extract and inject a files into a CD image.  It strips away the extra "sector" data as the file is extracted and puts it back right when the file is reinserted. 
« Last Edit: June 06, 2014, 05:38:04 am by weissvulf »

Gemini

  • Hero Member
  • *****
  • Posts: 2016
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: How am I supposed to hack PSX games?
« Reply #2 on: June 06, 2014, 06:53:40 am »
Is there some trick that gives me write access to mounted Images or an emulator that allows booting from a folder?  :-[
The short answer would be "no". Long story: you can't really because most PSX games simply don't rely much of standard CD-Rom info (aka TOC) and usually reroute access by using separate custom tables in order to optimize access, and work around a bug in Sony's cd libraries incapable of reading a directory whose data grows bigger than a sector (the following sectors are simply ignored, returning "not found" errors on string lookup).

You have really two options: rebuild an ISO from scratch and update via batch the file allocation tables, or replace entries with something like CDMage while keeping a similar data size.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

Bob Liu

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: How am I supposed to hack PSX games?
« Reply #3 on: June 06, 2014, 07:11:24 am »
I edit from the iso themselves but very few people do this, I find it much easier as it cuts out some of the busy work. Most people want to be safe and don't do that but it's your choice, I only have to start a new game to get the edits to appear so that's handy enough for me. What game are you looking into hacking anyway.

esperknight

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: How am I supposed to hack PSX games?
« Reply #4 on: June 06, 2014, 09:39:43 am »
What Gemini said is true but at the same time you can update the TOC correctly and easily using CUE's PSX-MODE2 program.  I've used it for a number of PSX games and it works very awesomely well.

Very few games I have encountered have not used the TOC for look ups (albeit they may have used there own code to access said TOC, I don't pay attention).  So far out of the number I've messed with I've only encountered a small amount that don't use the TOC (well, maybe partially) and the one's I can recall off the top of my head is ...Iru! and Shin Megami Tensei Devil Children.

If you're curious to see how I do it by hand here's the code for ...Iru! : iru_file_insert.cpp.  Due to the ton of files needing to be inserted I searched before hand all the positions I needed to update and just use a list that I pass in.

weissvulf

  • Sr. Member
  • ****
  • Posts: 324
  • Good news! An anomaly solved the enigma.
    • View Profile
Re: How am I supposed to hack PSX games?
« Reply #5 on: June 06, 2014, 12:54:42 pm »
Is there some trick that gives me write access to mounted Images or an emulator that allows booting from a folder?
Someone correct me if I'm wrong, but the way to get "write access to a mounted image" is to not mount the image in a virtual drive, but load the image directly into the emulator. Every virtual drives I know locks write access when you mount an image. But emulators (pSX v1.13 for example) don't lock write access to the ISO while it's being played, so you can have the ISO open in a hex editor and edit it while its being played.

It only gets complicated if you need to resize a file.
« Last Edit: June 06, 2014, 01:10:26 pm by weissvulf »

Tirlititi

  • Jr. Member
  • **
  • Posts: 38
    • View Profile
Re: How am I supposed to hack PSX games?
« Reply #6 on: June 06, 2014, 12:56:22 pm »
I also hack the ISO file directly, but I'll take a look at PSX-MODE2. It seems really interesting :)
Quote from: Unmon
This staff of mine has transformed itself into a dragon and has swallowed up the universe! Oh, where are the rivers and mountains and the great earth?

alfador

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How am I supposed to hack PSX games?
« Reply #7 on: June 18, 2014, 04:34:27 pm »
Some notes from my monkeying around with Chrono Cross under Linux:

pSX will read genuine .iso images, which don't include the sector header or EDC/ECC data that makes .bin images a pain to work with. Most other emulators won't, though. The extra data in a .bin sector consists of a header (~24 bytes) and trailing error detection and correction data, for a total sector length of 2354 bytes. An emulator isn't likely to care whether the CD error detection data is accurate or not, but an actual console probably will.

The code for correctly inflating .iso to .bin (or fixing error correction data on a hacked CD image) is numerical and tedious. If you need to write correct CD error detection data, swipe the implementation from cdrtools or some other open-source package.

At least some Squaresoft games of that era don't use the CD TOC. Cross has its own file table in sectors 24-36 of the CD, consisting of four-byte entries that combine sector pointers with some other information. Other games may be similar, or totally different. (What, you thought these studios talked to each other?)

Dunno about the Mac version, but the Linux version of pSX doesn't include a debugger. Run the Windows version if you can. (In general, finding non-WIndows debuggers is...difficult).

creeperton

  • Hero Member
  • *****
  • Posts: 604
    • View Profile
.
« Reply #8 on: June 26, 2014, 07:21:01 am »
.
« Last Edit: November 16, 2015, 01:40:59 am by creeperton »