Font Tool v0.1 and font formats description

Anything related to Tony Hawk's Pro Skater 4 modding goes here.
reapher
Posts: 5
Joined: Sun Oct 11, 2015 10:34 pm
Contact:

Font Tool v0.1 and font formats description

Postby reapher » Sun Jul 09, 2017 10:11 pm

Hi, I haven't been doing too much in regards to THPS but as a curiosity I recently made a tool which can open fonts from THPS4, THUG, and THUG2, do some basic editing, and save fonts to those formats. I don't know if there is already a tool but I made this from my own research. Some of the features currently don't work like saving characters to TGA file and importing TGA files to characters, but you can currently load and view characters from a THUG2 font and save it for THPS4/THUG(same format) and vice-versa. You can also change the corresponding Ascii/keycodes to characters and the baseline which they sit on with the tool. Some features don't work yet like adding new characters and importing TGA files for characters. There are also some situations in which the tool may crash when opening, saving, and reopening fonts from different THPS versions in one session or trying to open a THUG2 font when THUG or THPS4 is the selected version or vice-versa. Right now it's an alpha tool.

The program is written in C# and requires .NET or mono runtimes to work. I found it's much easier to make complex GUIs using C# rather than C/C++ and this tool is heavily GUI based. You should also run it as Administrator or else it might not be able to open files from your Program Files directory.

Here's a demonstration of changing the trick text font in THPS4

Default THPS4 font:
thps4_default.jpg
thps4_default.jpg (136.73 KiB) Viewed 254 times


THUG2 trick font in THPS4:
thug2_font_in_thps4.jpg
thug2_font_in_thps4.jpg (133.99 KiB) Viewed 254 times


Changing the timer font in THPS4

Default THPS4 font:
thps4_default.jpg
thps4_default.jpg (116.54 KiB) Viewed 253 times


THUG timer font in THPS4:
thug_font_in_thps4.jpg
thug_font_in_thps4.jpg (109.85 KiB) Viewed 253 times


Tool:
FntViewer.zip
(7.66 KiB) Downloaded 11 times


Here's the source code files and project file. I used SharpDevelop IDE:
FntViewer_sources.zip
(116.72 KiB) Downloaded 9 times


Some pics of the tool:
thps4.jpg
thps4.jpg (42.31 KiB) Viewed 254 times
thug.jpg
thug.jpg (42.76 KiB) Viewed 254 times
thug2.jpg
thug2.jpg (45.54 KiB) Viewed 254 times


The way to convert fonts from one game to another is to, for example, select THPS4 in the drop down box, load a THPS4 font file, then select THUG in the drop down box and save the font to the THUG font directory
Last edited by reapher on Sun Jul 09, 2017 11:47 pm, edited 2 times in total.
reapher
Posts: 5
Joined: Sun Oct 11, 2015 10:34 pm
Contact:

Re: Font Tool v0.1 and font formats description

Postby reapher » Sun Jul 09, 2017 10:28 pm

The font files for THPS4 and THUG1 are the same format. The files for THUG2 are slightly different.

[Font Header Section]

There is a section at the beginning of the file I will call the font header.

-All of them start with 4 bytes that equals the total size of the file.
-In THUG2 there are 4 more bytes after the file length which are usually 0x00000001. This is not present in THPS4. I don't know what this value means.
-Next is 4 bytes that tell the number of characters in the file.
-Next is 4 bytes which tells the default height of the font characters.
-Next is 4 bytes which tells the maximum number of pixels any character is over the font baseline.

The THPS4/THUG font header has 16 bytes and THUG2 has 20 bytes total.

[Basic Character Descriptions]

In the next section are described the baselines and ASCII codes for each character. For each character there are:

-2 bytes which tell the baseline of the character
-2 bytes which tell the ASCII code of each character
-In THUG2 there are 2 more bytes for each character that are usually 0x0000. Maybe it supports 4 byte ASCII codes.

[Texture Section]

The next section contains a bitmap and color lookup table. The color lookup table always contains 256 32bit colors (1024 bytes) and the bitmap contains 1 byte values telling which color from the lookup table is used for each pixel. The bitmap is a single image containing all the characters separated by 1 pixel black lines. There is some info preceding the bitmap, that is the texture header and it contains:

-4 bytes telling the size of the remaining data in the file, including these 4 bytes
-2 bytes telling the width of the bitmap
-2 bytes telling the height of the bitmap
-2 bytes telling the depth of the bitmap(ex. 8 means 8 bits, or one byte per pixel)
-6 bytes of garbage data that is not used

The texture header is followed by the bitmap data. It's length is the texture width * texture height * texture depth (depth 8 means 1 byte)

The bitmap is then followed by 1024 bytes describing the color lookup table. Each color is in RGBA format and is 4 bytes. If a pixel of the bitmap has byte 0x1F it means that it is represented by color 31(1F in decimal) of the color lookup table.

[Extra Character Data]

The next section has data describing the locations of each character in the bitmap. These are in the same order as the Basic Character Data before the Texture section. Each character has extra data for:

-2 bytes telling the X position in the bitmap
-2 bytes telling the Y position in the bitmap
-2 bytes telling the character width in the bitmap
-2 bytes telling the character height in the bitmap
reapher
Posts: 5
Joined: Sun Oct 11, 2015 10:34 pm
Contact:

Re: Font Tool v0.1 and font formats description

Postby reapher » Mon Jul 10, 2017 1:48 pm

I also made another tool before this in C that converts THUG/THPS4 fonts to a directory of TGA files for each character and a text file that lists the characters. It's a lot more complicated to import images into the font because the positions of each character in the bitmap has to be recalculated and I haven't written code for that yet. I'll get TGA exporting into the first font tool soon since that's pretty simple but it may be a while before I make it so that the individual images can be changed. Anyway here's this other program, it's a console application so just drag and drop fnt files from THPS4/THUG onto it and it will output the individual characters as TGA images.

fnt2tga.zip
(5.22 KiB) Downloaded 8 times


Source code/project file (I use Codeblocks editor, and sorry the code isn't very clear, optimized or commented)
fnt2tga_src.zip
(38.4 KiB) Downloaded 8 times
reapher
Posts: 5
Joined: Sun Oct 11, 2015 10:34 pm
Contact:

Re: Font Tool v0.1 and font formats description

Postby reapher » Sun Jul 16, 2017 2:29 pm

Cool

Just found out this also works for THPS3 fonts when the tool is in THPS4 mode

Return to “THPS4 modding”

Who is online

Users browsing this forum: No registered users and 1 guest