1 page
^^
vv
List results:
Search options:
Use \ before commas in usernames
Edit history:
uNsane: 2009-04-14 03:55:16 am
¯\_(ツ)_/¯
I made a Python script that converts any IPS patch between headerless and headered. To use it, simply extract the archive (I recommend to your Python directory, and I also recommend moving your IPS to the Python directory. Doing this will prevent you from having to type out full directories for each file.) and then follow the instructions in ips_hdr_readme.txt.

The script *should* work on any platform with Python. Written in Python 2.5. Et cetera; this stuff is all in the readme.


Edit: It is very important that everybody who downloaded before now (April 14) re-download; any patch with RLE will be destroyed by the old version. This is officially version 1.0, but I forgot to put that into the actual script/readme. Anyways, download here.
Thread title: 
OMG FLAN!!!!!!!
So we need to get this "python" program do we? Can you provide a link if possible please?
Edit history:
Crys: 2009-03-26 10:44:16 am
Green-Kirby, ROAR!
-Post removed-
Super Secret Area - Dead Ahead!
I'm not sure if that link's correct - and PLEASE don't try substituting it with the word python... Shocked

The closest I could find is .ORG.
O..M..G..    Shocked

please, do not attempt to correct the spelling in that link -  no matter what you do !
¯\_(ツ)_/¯
Oh, yeah, Python is at http://www.python.org/ under downloads. I don't know why I didn't provide a link there; maybe because I made the post while very tired.
This should be very useful, especially if I wanted to patch the games like Super Mario World or A Link to the Past roms that requires header.

Thanks!
¯\_(ツ)_/¯
I found out something very nasty about the IPS format recently. I've been trying to update the script to account for RLE mode, which currently will cause the script to silently destroy the patch, but I can't seem to get it to work. If you know Python, please help out; I have all the necessary information in the below spoilers.

If you open up any valid IPS patch in a hex editor, the first 5 bytes will always be 50 41 54 43 48, or PATCH. After this begins a loop, with a big-endian 24-bit pointer to the location in the destination file (not the loaded ROM) to write to, a big-endian 16-bit size value, which is, of course, the number of bytes to write, then a series of bytes to write. At the end of the file will be 45 4F 46 - EOF. The problem within this is that a size value of 00 00 will initiate RLE mode, where the next value after said RLE indicator is another big-endian 16-bit number of writes and the single byte after this is the value to be written.

My script, as it currently functions, loads each pointer, modifies it, and stores it back in, then reads the size value and jumps ahead by that amount. The problem therein is that if the size is 00 00, indicating RLE, my script will read the 00 00 and jump ahead by that amount to what it thinks is the next pointer. Normally, this wouldn't be anything of a problem; I just add in a simple if to see if the size is 00 00 and jump ahead by 3 if it is. However, when I tried to add this in, I inexplicably began to get a strange exception:
Code (Python):
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ips_hdr.py", line 19, in <module>
    p1,p2=struct.unpack(">BH",f.read(3))
  File "[...]\Python\Lib\struct.py", line 87, in unpack
    return o.unpack(s)
struct.error: unpack requires a string argument of length 3.
There's no reason for this, since I'm clearly it what it needs, and it doesn't trip this until after it encounters the RLE section. I have no explanation for any of this, which is why I need help.


Code (Python):
import struct
f=open("INPUTYOURINPUT.INPUTYOURINPUT","r+b") # Change the first argument to your patch name.
switchv=1 # change to -1 for converting headered patches to headerless.
headlen=512 # change this value to the number of bytes in the header, if not 512.
DEBUG=False # change this to True if you're having problems.

# If you're having problems about struct.unpack requiring a string of length 3,
# it's likely that the patch is using RLE. For whatever reason, my script
# refuses to do what I tell it to when it encounters the RLE flag.


if f.read(5)=='PATCH':
	if switchv==1: print 'Converting headerless patch to headered.\nIf this is wrong, change switchv in ips_hdr.py and run twice.'
	elif switchv==-1: print 'Converting headered patch to headerless.\nIf this is wrong, change switchv in ips_hdr.py and run twice.'
	else:
		print 'switchv is an unexpected value; script will continue, but the patch may be damaged.'
	while f.read(3)!='EOF':
		f.seek(-3,1)
		p1,p2=struct.unpack(">BH",f.read(3))
		if DEBUG: print (p1+p2,f.tell())
		p2=(p1<<16)|p2
		p2+=headlen*switchv
		p1=(p2&(0xff<<16))>>16
		f.seek(-3,1)
		f.write(struct.pack(">B",p1)+struct.pack(">H",p2))
		d=struct.unpack(">H",f.read(2))
		if d!=0: f.seek(d[0],1)
		else: f.seek(3,1)
	print 'Done! Thanks for using my utility.'
else: print 'Error - The target is not a valid patch file.\nPlease change ips_hdr.py according to your needs.\nIf this continues to be a problem, please check your patch.'
¯\_(ツ)_/¯
New version is out, and this time it won't destroy your RLE patches! I'm going to have to ask all 12 people who downloaded the old version to re-download, though.