Page 1 of 2

H2 Font File Format

Posted: Sun Feb 24, 2013 11:13 pm
by troymac1ure
I know we had another topic going on this, but I'm posting this to have a place that can be updated to reflect the format as the remaining parts <hopefully> get uncovered.

The font files are divided into 4 main sections:
  • [1] Header section
    [2] UTF Table
    [3] Index Table
    [4] Character Data
HEADER SECTION - Little is known about this section other than the following:
Address range: 0x0000 -> 0x03ff

Code: Select all

 0x0000 ->
 0x01ff = Always filled with 0x00
 0x0200 = [int32] Font File Identifier?
         Always 0x010000F0
 0x020c = [int32] Number of Index Table entries
 0x0220 = Number of ?Unknown? entries in header table
 0x0224 ->
 0x0224 + NumberOf?Unknown? = Unknown codes
UTF TABLE - Is always 65536 (0x10000) bytes in size.
Address range: 0x000400 -> 0x0403ff

Code: Select all

Each entry (0x04 bytes in size)
 Byte 0x00 [int32] = Entry number in Index Table
         Does not have to be unique, Index entries may be shared
INDEX TABLE - Size is equal to [Number of entries in Index Table] * 16 (0x10)
Address range: 0x040400 -> 0x040400 + NumberOfEntries * 0x10

Code: Select all

Each entry (0x10 bytes in size)
   Byte 0x00:   [int16]   Character Display Width
   Byte 0x02:   [int16]   Number of bytes used
   Byte 0x04:   [int16]   Width of byte runs
   Byte 0x06:   [int16]   Height of the byte runs
   Byte 0x08:   [int16]   Unknown
         Appears to usually be -1,0,1,2,3 although I have seen 5 and -3 as well
         This may be some kind of draw shift, allowing for overlapping of previous characters
   Byte 0x0A:   (short)   Unknown
         Seems to remain the same value for all characters in a font
   Byte 0x0C:   (int32)   Offset to data
CHARACTER DATA - Entry lengths are determined by SIZE in the index table pointer
Address range: 0x040400 + NumberOfEntries * 0x10 -> EndOfFile

Code: Select all

There are three methods used. The first is a color change, the second is a pixel run-length and the third is a coded run length.
Data Byte:
 0x00 = COLOR CHANGE + 1 pixel run (This is the only multi-byte code)
         The two bytes immediately following the 0x00 code are a4r4g4b4 data values.
         *NOTE* After the color change a single pixel is drawn.
 0x01->
 0x7f = PIXEL RUN LENGTH
         If bit 6 (0x40) is not set, the pixels are skipped.
         If bit 6 (0x40) is set, the pixels are drawn.
         bits 0 -> 5 (0x3f) = number of pixels to skip or draw
 0x80 ->
 0xff = CODED RUN-LENGTH
        These are individual codes that provide a run-length as well as a brightness
        *NOTE* The may possibly contain alpha changes as well
This is the H2 Font Viewer source (includes debug binary as well) link (currently v0.91):
http://www.remnantmods.com/archive/misc ... Viewer.rar
*v0.91 RELEASE NOTES*
-> This update fixes a massive memory leak. When shut down, memory was not released.
-> Changed loading method and discovered there are actually many unused characters (multiple duplicates at times)
-> Fixed mouse popup displays to show correct information.

Re: H2 Font File Format

Posted: Tue Feb 26, 2013 7:19 am
by troymac1ure
Image

:huh:

Re: H2 Font File Format

Posted: Tue Feb 26, 2013 8:35 am
by JacksonCougar
:wonder:

Re: H2 Font File Format

Posted: Tue Feb 26, 2013 9:55 am
by XZodia
custom font?

Re: H2 Font File Format

Posted: Tue Feb 26, 2013 6:08 pm
by troymac1ure
Sure. Custom emblems. Whatever.
It's not tested in game, but I'm confident.
Also, it's got almost no optimization, so the emblem above is 2673 bytes large (largest H2 emblem I've seen is around 1600 so far), but I will try to test it in-game tonight.
It accepts on A8R8G8B8 bitmap (I used a PNG image for above).

Re: H2 Font File Format

Posted: Tue Feb 26, 2013 9:26 pm
by XZodia
Awesome, what about the characters? is that one of the h2 fonts, a font file or images you loaded in?

Re: H2 Font File Format

Posted: Tue Feb 26, 2013 11:26 pm
by troymac1ure
That's the handel_gothic-24 font (used to display LOADING xx% when no videos are found at startup), but the selected image is my family clan's crest. It was loaded in from a PNG file and accessed through UTF code 0x1F (this is when the labels were still incorrectly labelling things)

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 9:52 am
by troymac1ure
Just testing the start of my new font character importer program:
Image

I noticed that the clan icon, which I imported over the "%" character, has some artifacts (looks like I didn't run the length to the end) and also a few on the "i", "n" and "g" letters as well.
I made those letters in an editor quickly and saved them as a .PNG file. Imported each one over the old letter and presto!

Also, in the program you can write text to see how your font will display. It looks as though it displays pretty much perfectly to the H2 display, although this is my first test.

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 10:07 am
by XZodia
Awesome!

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 10:11 am
by JacksonCougar
This is really fucking sweet :p Considering making a Git repository for this?

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 4:35 pm
by Grimdoomer
JacksonCougar wrote:This is really fucking sweet :p Considering making a Git repository for this?
Fuck git we're not on linux. Use svn.

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 4:46 pm
by JacksonCougar
Grimdoomer wrote:
JacksonCougar wrote:This is really fucking sweet :p Considering making a Git repository for this?
Fuck git we're not on linux. Use svn.
I like git for windows more than tortoise-svn¹—which is the extent of my source-management experience.
¹Besides svn lost sunfish so fuck that guy ( and by association fuck me for forgetting to 'add' files to the svn... bleh )

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 4:58 pm
by XZodia
I agree that git failz.

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 5:10 pm
by troymac1ure
I'll u/l the code and someone else can do a git repository. I have only set one up and it was a hay-day. I don't use it enough to get to know it that well.
Anyways, the code is just class file and then a few procedures on a form to complete. Pretty straight forward.

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 6:32 pm
by OwnZ joO
XZodia wrote:I agree that git failz.
Git(or any distributed version control) is much better if you actually learn how to use it. That being said, Github for Windows makes it dead simple to use, so I would recommend that if you're having trouble.

Re: H2 Font File Format

Posted: Thu Feb 28, 2013 6:57 pm
by XZodia
I have tried that, its really bad...

Re: H2 Font File Format

Posted: Fri Mar 01, 2013 4:07 am
by Grimdoomer
XZodia wrote:I have tried that, its really bad...
This.

I would recommend google code as a svn repository.

Re: H2 Font File Format

Posted: Fri Mar 01, 2013 4:18 am
by Click16
Instead of arguing over these mediocre things, I'm gonna congratulate Troy. First custom/edited injected Halo 2 font I've seen. *applause*

Re: H2 Font File Format

Posted: Fri Mar 01, 2013 9:01 am
by troymac1ure
Thanks Click.
It needs tweaking, but the main base is there anyways. I only made the 7 letters that are seen on screen, the rest are still the regular handel-24 font letters, but a whole font could be customized.
Each letter took me a while to get saved in a .png format with transparency, but the injection takes a matter of a split second to inject after calculating the proper character code.

New options could include:
-Type character to overwrite (currently uses UTF code)
-GUI click to select character to overwrite
-Import whole font from single bitmap (each character in an even grid, auto-width adjusted if necessary or similar)

Anyways, if the main goal is for custom medals, this will inject those no problem (as soon as I fix the artifacts).

Re: H2 Font File Format

Posted: Sat Mar 02, 2013 5:16 am
by OwnZ joO
Grimdoomer wrote:
XZodia wrote:I have tried that, its really bad...
This.

I would recommend google code as a svn repository.
What is bad about it, git's a different paradigm for sure so it takes some unlearning of svn, but it's worth it once you get it. I work with SVN at work for the record, and I do realize that the GUIs for SVN are more mature, but command line is better than a GUI anyway and Git on Windows uses powershell which is more similar to a linux shell than windows command line.

Also, good work Troy.

Re: H2 Font File Format

Posted: Sun Mar 03, 2013 8:51 pm
by Grimdoomer
OwnZ joO wrote: command line is better than a GUI anyway
Depends on the application and context of how it would be used. As far as SVN/git is concerned, I don't really see either being the better solution. If you usually clone the entire source tree then there really is no use for a gui application. However, if you don't or you would like more control over exactly what files/folders you are cloning then a gui application would be ideal over a command line one.
OwnZ joO wrote:Git on Windows uses powershell which is more similar to a linux shell than windows command line.
Why on earth would you give windows users an application that uses a linux style command prompt? GitHub for windows looks like a nice application, except there doesn't appear to be any way to clone a repository from the gui application or from the "Clone in Windows" button without a GitHub account. I shouldn't have to make an account to clone a repository, especially if I will not be committing anything back to it.

But seeing as you can clone a branch on github by clicking the "Zip" button I don't really care if git or svn is chosen.

Re: H2 Font File Format

Posted: Mon Mar 04, 2013 3:52 am
by OwnZ joO
Grimdoomer wrote:
OwnZ joO wrote:Git on Windows uses powershell which is more similar to a linux shell than windows command line.
Why on earth would you give windows users an application that uses a linux style command prompt? GitHub for windows looks like a nice application, except there doesn't appear to be any way to clone a repository from the gui application or from the "Clone in Windows" button without a GitHub account.
Because it's linux-like, not linux, and the linux command line is INCREDIBLY powerful and convenient. It's also included in Windows 7 and up and easily installable on other versions of Windows.

Yeah it doesn't appear that you can clone in windows using the GUI app without having an account. You can issue a git clone https://github.com/account/repository.git commant from powershell to clone one without an account though.

Re: H2 Font File Format

Posted: Mon Mar 04, 2013 12:57 pm
by CaptainPoopface
This discussion does not belong in the H2 font format thread...

Re: H2 Font File Format

Posted: Mon Mar 04, 2013 9:04 pm
by Click16
CaptainPoopface wrote:This discussion does not belong in the H2 font format thread...
My thoughts exactly. I tried to change the subject a few posts back, but I was unsuccessful. On a side note: I was looking at the medals for Halo 3, and I noticed that they share the same style as Halo 2's. I am hoping to transfer a few over when I can.

Re: H2 Font File Format

Posted: Mon Mar 04, 2013 11:26 pm
by troymac1ure
I was making the importing program more user friendly last night. Before it was basically a "can I get this to work?" scenario...