psx¶
Support for PSX BIN/CUE images, EXE string repacking and TIM images.
- hacktools.psx.extractBIN(infolder, outfolder, cuefile)[source]¶
Extract a BIN/CUE image with pydumpsxiso.
The image is extracted to infolder along with the rebuild xml file, then everything is copied to outfolder, adjusting the xml to point to the repack folder.
- hacktools.psx.repackBIN(infolder, binin, binout, cuefile, patchfile='')[source]¶
Repack a BIN/CUE image with pymkpsxiso.
- Parameters:
infolder (str) – Path of the folder holding the rebuild xml file, as extracted by
extractBIN().binin (str) – Path of the original bin file, used to create the patch.
binout (str) – Path of the output bin file.
cuefile (str) – Path of the output cue file.
patchfile (str) – Path of the xdelta patch to create, or empty to skip patch creation.
- Return type:
None
- hacktools.psx.extractEXE(binrange, readfunc=<function detectEncodedString>, encoding='shift_jis', exein='', exefile='data/exe_output.txt', writepos=False)[source]¶
Extract strings from ranges of the EXE to a text file.
- Parameters:
binrange – A (start, end) range, or a list of them.
readfunc – Function used to detect strings, called with (stream, encoding).
encoding (str) – Encoding passed to readfunc.
exein (str) – Path of the EXE file.
exefile (str) – Path of the output text file.
writepos (bool) – Whether to write the position of each string before it.
- Return type:
None
- hacktools.psx.repackEXE(binrange, freeranges=None, manualptrs=None, readfunc=<function detectEncodedString>, writefunc=<function writeEncodedString>, encoding='shift_jis', comments='#', exein='', exeout='', ptrfile='data/manualptrs.asm', exefile='data/exe_input.txt')[source]¶
Repack translated strings into the EXE.
Strings are repacked with common.repackBinaryStrings, using 0x8000f800 as the pointer start. Pointers that aren’t found automatically are looked up in manualptrs, and an asm file is written with a li opcode for each of them.
- Parameters:
binrange – A (start, end) range, or a list of them.
freeranges (list | None) – List of (start, end) ranges that can hold relocated strings.
manualptrs (dict | None) – Dictionary of pointer -> list of (location, register) tuples for the manual pointers.
readfunc – Function used to detect strings, called with (stream, encoding).
writefunc – Function used to write strings, called with (stream, string, maxlen, encoding).
encoding (str) – Encoding passed to readfunc and writefunc.
comments (str) – Comment marker used in the text file.
exein (str) – Path of the original EXE file.
exeout (str) – Path of the output EXE file.
ptrfile (str) – Path of the asm file written for the manual pointers.
exefile (str) – Path of the input text file.
- Returns:
False if the input text file is missing, True otherwise.
- Return type:
bool
- hacktools.psx.extractTIM(infolder, outfolder, extensions='.tim', readfunc=None)[source]¶
Extract all the TIM images in a folder to png.
- Parameters:
- Return type:
None
- class hacktools.psx.TIM[source]¶
Structure of a TIM image.
- bpp¶
Bits per pixel, 4, 8, 16 or 24.
- clutsize¶
Size of the CLUT section.
- clutposx¶
X position of the CLUT in the framebuffer.
- clutposy¶
Y position of the CLUT in the framebuffer.
- clutwidth¶
Number of colors in each CLUT.
- clutheight¶
Number of CLUTs.
- clutoff¶
Offset of the CLUT data.
- cluts¶
List of CLUTs, each a list of RGBA tuples.
- posx¶
X position of the image in the framebuffer.
- posy¶
Y position of the image in the framebuffer.
- width¶
Width of the image in pixels.
- height¶
Height of the image.
- size¶
Size of the image data section.
- dataoff¶
Offset of the image data.
- data¶
Image data, a list of palette indexes or RGBA tuples depending on the bpp.
- hacktools.psx.readCLUTData(f, clutwidth)[source]¶
Read a single CLUT of a TIM image.
- Parameters:
f (Stream) – Stream to read from.
clutwidth (int) – Number of colors to read.
- Returns:
The palette, as a list of RGBA tuples.
- Return type:
list
- hacktools.psx.readTIMData(f, tim, pixelnum)[source]¶
Read the pixel data of a TIM image.
Palette indexes are read for 4 and 8bpp images, RGBA colors otherwise. Reading stops with a warning if the stream ends early.
- hacktools.psx.getUniqueCLUT(tim, transp=False)[source]¶
Get the index of the first CLUT with no duplicated colors.
- Parameters:
tim (TIM) – Image to search the CLUTs of.
transp (bool) – Whether the alpha channel counts when comparing colors.
- Returns:
The index of the first CLUT with all different colors, or 0 if there’s none.
- Return type:
int
- hacktools.psx.drawTIM(outfile, tim, transp=False, forcepal=-1, allpalettes=False, nopal=False)[source]¶
Draw a TIM image to a png file.
For 4 and 8bpp images, the palette is drawn on the right side of the image, unless disabled with nopal.
- Parameters:
outfile (str) – Path of the png file to create, or “” to return the image without saving it.
tim (TIM) – Image to draw.
transp (bool) – Whether to keep the alpha channel of the colors.
forcepal (int) – Index of the CLUT to use, or -1 to pick the first one with no duplicated colors.
allpalettes (bool) – Whether to draw all the CLUTs instead of just the used one.
nopal (bool) – Whether to skip drawing the palette.
- Returns:
The image object if outfile is “”, nothing otherwise.
- hacktools.psx.writeTIM(f, tim, infile, transp=False, forcepal=-1, palsize=0)[source]¶
Write a png image back into a TIM, only supported for 4 and 8bpp.
- Parameters:
f (Stream) – Stream opened on the TIM file.
infile – Path of the png file, or a PIL pixel access object.
transp (bool) – Whether the alpha channel counts when matching colors.
forcepal (int) – Index of the CLUT to use, or -1 to pick the first one with no duplicated colors.
palsize (int) – Width of the palette drawn on the right side of the png, ignored when matching pixels.
- Return type:
None