wii

Support for Wii ISOs, archives, textures and fonts.

ISO, ARC, TPL and BREFT files are handled with the wit, wszst and wimgt tools from Wiimms ISO/SZS Tools, which need to be installed separately. BRFNT fonts are converted by calling the brfnt2tpl executable externally.

hacktools.wii.extractARC(infolder, outfolder)[source]

Extract all the .arc files in a folder with wszst.

Parameters:
  • infolder (str) – Path of the folder to scan.

  • outfolder (str) – Path of the folder to extract to.

Return type:

None

hacktools.wii.extractTPL(infolder, outfolder, splitName=True, flatten=False)[source]

Extract all the .tpl files in a folder to png with wimgt.

Parameters:
  • infolder (str) – Path of the folder to scan.

  • outfolder (str) – Path of the folder to extract to.

  • splitName (bool) – Whether to name the output subfolder after the first component of each file path, instead of mirroring the whole path.

  • flatten (bool) – Whether to extract the files inside a .arc folder directly in it, instead of mirroring its inner folder structure.

Return type:

None

hacktools.wii.repackTPL(infolder, workfolder, outfolder)[source]

Repack modified pngs into the .arc folders extracted by extractARC.

For each png in workfolder that matches a .tpl file in infolder, the containing .arc folder is copied to outfolder, then the png is encoded over the tpl with wimgt, keeping the original image and palette formats.

Parameters:
  • infolder (str) – Path of the folder extracted by extractARC().

  • workfolder (str) – Path of the folder with the modified pngs.

  • outfolder (str) – Path of the folder the .arc folders are copied to.

Return type:

None

hacktools.wii.repackARC(workfolder, outfolder)[source]

Repack all the .arc folders in a folder with wszst.

Parameters:
  • workfolder (str) – Path of the folder to scan.

  • outfolder (str) – Path of the folder the .arc files are created in.

Return type:

None

hacktools.wii.extractBREFT(infolder, tempfolder, outfolder)[source]

Extract all the .breft files in a folder to png.

The files are first extracted with wszst to the temp folder, then every texture found in them is decoded with wimgt.

Parameters:
  • infolder (str) – Path of the folder to scan.

  • tempfolder (str) – Path of the folder holding the extracted archives.

  • outfolder (str) – Path of the folder the textures are decoded to.

Return type:

None

hacktools.wii.extractBRTEX(infolder, tempfolder, outfolder)[source]

Extract all the .brtex files in a folder to png.

The files are extracted with wszst to the temp folder, alongside the paired .brplt files when they exist, then every texture is converted to a temporary TPL and decoded with wimgt.

Parameters:
  • infolder (str) – Path of the folder to scan.

  • tempfolder (str) – Path of the folder holding the extracted archives.

  • outfolder (str) – Path of the folder the textures are decoded to.

Return type:

None

hacktools.wii.repackBRTEX(infolder, tempfolder, workfolder, outfolder)[source]

Repack modified pngs into .brtex and .brplt files.

For each folder in workfolder that matches a .brtex file in infolder, the file is extracted with wszst to the temp folder, alongside the paired .brplt file when it exists. Every png is encoded to a temporary TPL with wimgt, keeping the original image and palette formats, and the data is copied back into the TEX0 and PLT0 textures. The files are then rebuilt with wszst into outfolder.

Parameters:
  • infolder (str) – Path of the folder to scan.

  • tempfolder (str) – Path of the folder holding the extracted archives.

  • workfolder (str) – Path of the folder with the modified pngs.

  • outfolder (str) – Path of the folder the files are created in.

Return type:

None

hacktools.wii.extractBRFNT(infile, outfile)[source]

Extract a BRFNT font to png, with brfnt2tpl and wimgt.

Parameters:
  • infile (str) – Path of the BRFNT file.

  • outfile (str) – Path of the output png file.

Return type:

None

hacktools.wii.repackBRFNT(outfile, workfile)[source]

Repack a png into a BRFNT font, with brfnt2tpl.

Parameters:
  • outfile (str) – Path of the BRFNT file to update.

  • workfile (str) – Path of the png file to pack.

Return type:

None

hacktools.wii.extractIso(isofile, extractfolder, workfolder='')[source]

Extract an ISO with wit.

Parameters:
  • isofile (str) – Path of the ISO file.

  • extractfolder (str) – Path of the folder to extract to.

  • workfolder (str) – Optional path of a work folder the extracted files are copied to.

Return type:

None

hacktools.wii.repackIso(isofile, isopatch, workfolder, patchfile='')[source]

Repack an ISO with wit.

Parameters:
  • isofile (str) – Path of the original ISO file, unused.

  • isopatch (str) – Path of the output ISO file.

  • workfolder (str) – Path of the folder to repack.

  • patchfile (str) – Unused.

Return type:

None

hacktools.wii.getTexDataSize(width, height, format)[source]

Calculate the data size of an image in the given GX format.

Parameters:
  • width (int) – Width of the image.

  • height (int) – Height of the image.

  • format (int) – Format of the image data.

Returns:

The size of the block-aligned image data.

Return type:

int

hacktools.wii.getTPLTransform(file)[source]

Read the image and palette formats of a TPL file.

Parameters:

file (str) – Path of the TPL file.

Returns:

The formats as a wimgt transform string, like TPL.C8.PRGB5A3.

Return type:

str

hacktools.wii.getTexTransform(texfile, palfile=None)[source]

Read the image and palette formats of a TEX0 texture.

Parameters:
  • texfile (str) – Path of the TEX0 file.

  • palfile (str | None) – Optional path of the paired PLT0 file.

Returns:

The formats as a wimgt transform string, like TPL.C8.PRGB5A3.

Return type:

str

hacktools.wii.texToTPL(texfile, tplfile, palfile=None)[source]

Convert a TEX0 texture and its optional PLT0 palette to a TPL file.

Parameters:
  • texfile (str) – Path of the TEX0 file.

  • tplfile (str) – Path of the output TPL file.

  • palfile (str | None) – Optional path of the paired PLT0 file.

Return type:

None

hacktools.wii.tplToTex(tplfile, texfile, palfile=None)[source]

Copy the image and palette data of a TPL back into TEX0/PLT0 files.

The palette is padded to the original color count when possible, so the PLT0 file layout is unchanged.

Parameters:
  • tplfile (str) – Path of the TPL file.

  • texfile (str) – Path of the TEX0 file to update.

  • palfile (str | None) – Optional path of the paired PLT0 file to update.

Return type:

None

class hacktools.wii.TPL[source]

Structure of a TPL texture file.

Format reference: http://wiki.tockdom.com/wiki/TPL_(File_Format)

imgnum

Number of images in the file.

tableoff

Offset of the image table.

images

List of images in the file.

class hacktools.wii.TPLImage[source]

Structure of a single image in a TPL file.

imgoff

Offset of the image header.

paloff

Offset of the palette header, 0 if the image has no palette.

palformat

Format of the palette colors, only 0x02 (RGB5A3) is supported.

paldataoff

Offset of the palette data.

palette

Palette colors, as a list of RGBA tuples.

width

Width of the image.

height

Height of the image.

format

Format of the image data, only 0x02 (IA8), 0x08 (C4) and 0x09 (C8) are supported.

dataoff

Offset of the image data.

tilewidth

Width of a single tile.

tileheight

Height of a single tile.

blockwidth

Width rounded up to a multiple of the tile width.

blockheight

Height rounded up to a multiple of the tile height.

hacktools.wii.readTPL(file)[source]

Read the image table and palettes of a TPL file.

Parameters:

file (str) – Path of the TPL file.

Returns:

The parsed TPL structure.

Return type:

TPL

hacktools.wii.writeTPL(file, tpl, infile)[source]

Write png images back into a TPL file.

The first image is read from infile, the following ones from .mmN.png files next to it, with N being the image number. If an image size changed, the new size is written in the header.

Parameters:
  • file (str) – Path of the TPL file to update.

  • tpl (TPL) – TPL structure returned by readTPL().

  • infile (str) – Path of the png file to pack.

Return type:

None

hacktools.wii.getFontGlyphs(file, encoding='shift_jis')[source]

Read the glyph information of a BRFNT font.

The glyph widths are read from the HDWC section, and matched with the character codes from the PAMC sections.

Parameters:
  • file (str) – Path of the font file.

  • encoding (str) – Encoding of the character codes.

Returns:

A dictionary of character -> FontGlyph.

Return type:

dict

hacktools.wii.extractFontData(file, outfile)[source]

Extract the glyph data of a font to a text file.

Each line has the char=start,width,length format, with “=” characters written as <3D>.

Parameters:
  • file (str) – Path of the font file.

  • outfile (str) – Path of the output text file.

Return type:

None

hacktools.wii.repackFontData(infile, outfile, datafile)[source]

Repack the glyph data of a font from a text file.

Parameters:
  • infile (str) – Path of the original font file.

  • outfile (str) – Path of the output font file.

  • datafile (str) – Path of the text file, in the format written by extractFontData().

Return type:

None