Author Topic: War2 fonts (.fnt)  (Read 17679 times)

Offline shesycompany

  • Death Knight
  • *********
  • Posts: 3587
  • retired, be in music section
    • View Profile
Re: War2 fonts (.fnt)
« Reply #15 on: February 28, 2019, 04:27:28 AM »
this is the russian keyboard correct?
http://russian.typeit.org/


ahh ok got the russian just looking
wow nice job!

well i cant get around the thing that flips half my char as of right now... again good job thats impressive
« Last Edit: February 28, 2019, 05:36:00 AM by easycompany »

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1650
    • View Profile
Re: War2 fonts (.fnt)
« Reply #16 on: February 28, 2019, 09:57:04 AM »
this is the russian keyboard correct?
http://russian.typeit.org/

Yes, russian characters are ok, but they are located on improper buttons. This looks like russian "qwerty". I think, not important.

ahh ok got the russian just looking
wow nice job!

Also, order of russian characters in blizzard russian font is very strange: not alphabetic (a-z), not small, then capital or w/e, looks like random mix of capital and small letters. I didn't understand any regularity in that order.

well i cant get around the thing that flips half my char as of right now... again good job thats impressive

Hm, my code i posted here and then my code from bitbucket i also shared here work fine with all chars. Looks like something wrong with your code then...
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline shesycompany

  • Death Knight
  • *********
  • Posts: 3587
  • retired, be in music section
    • View Profile
Re: War2 fonts (.fnt)
« Reply #17 on: February 28, 2019, 04:51:53 PM »
mmm yes it seems :D
but the chinese dudes could put text on the grp's

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: War2 fonts (.fnt)
« Reply #18 on: March 01, 2019, 06:48:12 AM »
@Lambchops, thanks, for such detailed format description, i've been too lazy to describe it anywhere, i just hope such format is obvious from my source code.


@iL Yw. :) Thanks for posting your source, it saves time when you can see what others have done.

there are only 4 colors used

1 = yellow ( palette entry 0xC8 )
2 = beige  ( 0xC7 )
4 = brown ( 0xC0 )
5 = black   ( 0x00 )

value 3 is not used in the font you posted - maybe in the others idk.

I also saw 6(instead of 5 for shadow) and even 0(1 or 2 bytes) in other fonts. Not sure if they are not bugs, i didn't load and check that font.


OK. Well the only .fnt file I have looked at so far is the font10x.fnt that @easycompany posted, if there are other possible combinations of byte values/colors that info must be stored somewhere else because it isn't in the .fnt file. Possibly there could be a corresponding "font palette" file stored seperately.

Font Header is as mentioned in iL's source except for the "DWORD Unk1" at the end.
This is actually the pointer to the pixel data for the first character, but as the first character in this font is 0x20 (decimal 32) which is a SPACE, there is no pixel data, so the pointer is set to 0.

You mean that is not a "DWORD Unk1" in font header, but it's an address of 1-st character (which is NULL because it's SPACE)? Same idea, at least everything works after i commented "DWORD Unk1" and used that way to act.


Yes.

If I get time I'll try to write a quick extractor/packer so you can edit them easily (no promises)

look at my code: extractor is already working (still not sure about character with X-offset), packer for that format is next step to finish that program.


OK, here it is.

This will extract all the characters out of a .fnt file into a bunch of individual .bmp files so you can edit them. Just drop a .fnt file onto War2FontTool.exe.

When you edit them (with MSPaint or whatever) make sure to copy the existing color values and not use any other colors. Any unknown colors will be removed.

You can add extra .bmps for missing chars (do this by copying an existing .bmp then rename and edit).

You can change the width/height of the bitmaps to resize the chars. The X/Y offsets are calculated automatically.

The green color will be transparent.

When you have finished editing the bitmaps, just drop any one of them onto War2FontTool.exe to compile them all into a .fnt file.
This will overwrite the original file without warning, so keep a backup.

The maximum size allowed for an individual character is 64x64 pixels.

The .fnt file will always be declared to include character 0x20 (space).


  ---  ---  ---


As mentioned, the only file I have tested this with is font10x.fnt, but I expect that it will probably work with the others ... please test :)

The original font10x.fnt file declares characters 0x20 -> 0xEF although the highest character image it contains is 0xE1.

To recompile a byte-for-byte identical .fnt file from the extracted .bmps you can create an empty (0 Byte length) file called "font10x_EF.bmp". This will force the compiler to declare the range 0x20 -> 0xEF. I don't know if there is any internal reason why WC2 requires this to be declared, I suspect there is not.

Anybody who is interested in this stuff please experiment and let me know if there are any issues  ... HF

                                                                                                                                                               :critter:


-- edit --

Source is HERE

Have changed this to use decimal file names so it can be compatible with iL's project.
« Last Edit: March 07, 2019, 09:05:20 PM by Lambchops »
its gooder to hax hard and NEVER get caught!

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1650
    • View Profile
Re: War2 fonts (.fnt)
« Reply #19 on: March 01, 2019, 10:19:50 AM »
OK, here it is.

This will extract all the characters out of a .fnt file into a bunch of individual .bmp files so you can edit them. Just drop a .fnt file onto War2FontTool.exe.

When you edit them (with MSPaint or whatever) make sure to copy the existing color values and not use any other colors. Any unknown colors will be removed.

You can add extra .bmps for missing chars (do this by copying an existing .bmp then rename and edit).

You can change the width/height of the bitmaps to resize the chars. The X/Y offsets are calculated automatically.

The green color will be transparent.

When you have finished editing the bitmaps, just drop any one of them onto War2FontTool.exe to compile them all into a .fnt file.
Wow, you are quick, that's a great project!
Just tried it, works fine for me!

Your idea about bmp export-import is absolutely right, looks like that is the only way to make it useful for people as a ready product.
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: War2 fonts (.fnt)
« Reply #20 on: March 01, 2019, 10:46:40 AM »
Just tried it, works fine for me!

Cool :fro: Thanks for testing :)  I hope it's useful.

Your idea about bmp export-import is absolutely right

So many bitmap editors already written - no point in re-inventing the wheel.


its gooder to hax hard and NEVER get caught!

Offline shesycompany

  • Death Knight
  • *********
  • Posts: 3587
  • retired, be in music section
    • View Profile
Re: War2 fonts (.fnt)
« Reply #21 on: March 01, 2019, 09:21:40 PM »
wow hell yea! paint editors is best for this stuff anyhow..works for me

Offline shesycompany

  • Death Knight
  • *********
  • Posts: 3587
  • retired, be in music section
    • View Profile
Re: War2 fonts (.fnt)
« Reply #22 on: March 02, 2019, 01:26:46 PM »
lol fnt12 they all work  but there u go some complicated language like chinese can do just like windows games... phrases in the text idk

lol man this is cool as hell

my jpg looks like crap overlook the artifacts

could be used for kids also


« Last Edit: March 02, 2019, 01:38:48 PM by easycompany »

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: War2 fonts (.fnt)
« Reply #23 on: March 02, 2019, 08:25:12 PM »
lol fnt12 they all work  but there u go some complicated language like chinese can do just like windows games... phrases in the text idk

lol man this is cool as hell

my jpg looks like crap overlook the artifacts

could be used for kids also



haha cool. We could add characters for common phrases like "gg no re" "get good newb" "wtf pard?" or "everyone rush 6" and use ALT+numbers.

Have you tested what happens if you make a much bigger character? ...like just one 50x50 char in the middle of the normal stuff?

its gooder to hax hard and NEVER get caught!

Offline shesycompany

  • Death Knight
  • *********
  • Posts: 3587
  • retired, be in music section
    • View Profile
Re: War2 fonts (.fnt)
« Reply #24 on: March 02, 2019, 10:16:26 PM »
yeah it'll more than likely crash 12x should go wider than that ill test in morning..
the message box is funky  it may can stay a height and goes as long as you want..but be so big boom crashed..still in blizzard code

pbr right now doubt i can hit save

Days of Thunder - Main Theme (2013 Extended Mix) - YouTube

u know them fucks at that sc1 site are all asm...hell the built my mini shit years ago :/ for use with sc1
« Last Edit: March 02, 2019, 10:38:41 PM by easycompany »

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1650
    • View Profile
Re: War2 fonts (.fnt)
« Reply #25 on: March 02, 2019, 10:28:15 PM »
I thought and just decided to continue working on my project: i need to make some improvements with my fonts:
- to compile fonts containing russian chars from russian fonts and other chars from english ones
- to add shadows to russian chars
- to add and probably fix some russian chars

I don't want to do that manually in bmp, i prefer to make most actions in c++ code.
At the same time i think working via .bmp is a very good idea.
So, my idea: to continue writing my code for exporting fnt to bmp and then to use your code to importing them back from .bmp to .fnt.

So, i stole your code working with bmp and added it to my project.
Also updated my project on bitbucket.

@Lambchops looks like your code and my code make different .bmp-files from the same fonts:
Differents touch palette only and increases from begin to end.
For example, i comparing mine and yours font10x_246.bmp (i changed char szBmpTmpl[] = "_%2.2X.bmp"; to char szBmpTmpl[] = "_%03d.bmp"; to make win sort files properly, that's the only change i made in your code):
Code: [Select]
0000042A: FC 00
0000042B: 00 C7
0000042E: FC 00
0000042F: FC 4A
00000432: FC 4A
00000433: FC 4A
As i understand, it's a palette, pixels begin from 00000436. And your code changes values from 1-st char to another, but my code gives similar values every time (and looks like they are similar with bmp8 array).
And i don't understand how that can happen: eighter you change the palette in bmp8 somehow (i didn't find that in your code) or that is a bug or something else i don't understand.
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: War2 fonts (.fnt)
« Reply #26 on: March 03, 2019, 09:00:53 AM »
I thought and just decided to continue working on my project: i need to make some improvements with my fonts:
- to compile fonts containing russian chars from russian fonts and other chars from english ones
- to add shadows to russian chars
- to add and probably fix some russian chars
I don't want to do that manually in bmp, i prefer to make most actions in c++ code.

Ok cool. I was thinking about doing something like this as an example, just for fixed pitch fonts where I could easily extract them from a screen grab.

At the same time i think working via .bmp is a very good idea.
So, my idea: to continue writing my code for exporting fnt to bmp and then to use your code to importing them back from .bmp to .fnt.

Ok, but my code is very dependant on the format being exactly what it is expecting, so the format would have to be exactly the same. It would probably be easier to just use my export code as it is already 100% compatible with the import code. idc it's up to you.

So, i stole your code working with bmp and added it to my project.
Also updated my project on bitbucket.

You're very welcome to re-use my code. Thanks for crediting me in the comments :)

@Lambchops looks like your code and my code make different .bmp-files from the same fonts:
Differents touch palette only and increases from begin to end.



OK.

What I did for the bitmap handling in this project was this:

I got a wc2 .pcx SS and converted it to a bitmap (8 bit palette based, as is the native format for the game).
Then I discarded the pixel data (made it all black) and resized it to 64x64 pixels. Then I just converted the entire file to a c-style declaration. *Have attached the original .bmp file just for interest's sake.

This way it has all the default values for the bitmap headers and the wc2 palette already in place AND it is defined in the .data section so it can be also be directly used as the actual buffer (for read and write).

You can see that nowhere in the code is any other memory allocated to hold the bitmap - the BITMAPFILEHEADER and BITMAPINFOHEADER pointers are cast direcly over this initialsed data declaration, the pixels are modified there, when loading the files are read and written over this same place and when saving this region is saved directly to a file.

This was just a conveniant way to handle the bitmaps as only one bitmap is ever in memory at one time, so they can all use the same space. Plus all the values are already initialised, so less work... also I can cheat and define things like the pixmap pointer and the actual line width as globals (again less work ;))


For example, i comparing mine and yours font10x_246.bmp (i changed char szBmpTmpl[] = "_%2.2X.bmp"; to char szBmpTmpl[] = "_%03d.bmp"; to make win sort files properly, that's the only change i made in your code):
Code: [Select]
0000042A: FC 00
0000042B: 00 C7
0000042E: FC 00
0000042F: FC 4A
00000432: FC 4A
00000433: FC 4A
As i understand, it's a palette, pixels begin from 00000436. And your code changes values from 1-st char to another, but my code gives similar values every time (and looks like they are similar with bmp8 array).
And i don't understand how that can happen: eighter you change the palette in bmp8 somehow (i didn't find that in your code) or that is a bug or something else i don't understand.

Yes for this case the pixmap always starts at offset 0x436, this is defined in BITMAPFILEHEADER.bfOffBits ( it's the 0x04360000 which is the 3rd DWORD in the declaration ). Add this value to the base address of the data and you have the address of the pixel data.

I'm not sure how you got the values you have posted (starting at 0000042A), but I can see what has occurred. You mention font10x_246.bmp. 246 = 0xF6 and the font10x.fnt file stops at 0xEF so I do not know the bitmap you are working with...

... that being said, yes this area holds the end of the palette.  0x042A...  should be FC:00:FC:FC:FC:FC as per the first column you have posted.

This area has obviously been overwritten by pixel data as 00, C7 and 4A are all values from the clrndx[] array. Notably 0x4A is the grey color I put in for the .fnt pixel value of 3, and as previously mentioned the value 3 does not appear in font10x.fnt ( I just picked a grey color and put it there because EC said it was grey ).

MS .bmp format has a couple of peculiarities:
- Each line of pixel data is DWORD aligned.
- The pixel data is stored starting with the bottom line first and the top line last.

As the blizzard guys (and any other sane people) work with pixels from the top down, all the Y co-ordinates must be inverted when converting from .fnt to .bmp and back again.

This is handled in get_pixel() and set_pixel() by the line:
Code: [Select]
BYTE* pptr = pixmap+(linew*(bmh-y-1))+x;
bmh-y-1 inverts the pixel position then this is multiplied by linew

linew is the actual size of a pixel line in memory, which may be different from the width of the bitmap due to the DWORD alignment.

This size is calculated by:
Code: [Select]
linew  = ((bmw+3)>>2)<<2;
This just ensures that the width is rounded up to the next 4-byte boundary.

.... so: back to the issue ...

If the palette is being overwritten then at some stage there is an extra line of pixels being written at the bottom of a bitmap that won't fit... i.e. the bitmap has been defined with a height of 8 (lines 0->7) but then some pixels have been written to line 8.

When writing to a bitmap, if it is first defined with init_bmp(w,h) and set_pixel() is only used with x = 0 -> (w-1)  and  y = 0 -> (h-1) then the palette should never be written to.

I don't know what you are extracting when this error occurs, if you post the file you are using then I can comment more specifically.

The .bmp routines I wrote specifically for this project, they were not written to be 'safe' for general purpose use.

For debugging purposes you could use something like:

Code: [Select]
void Bmp::set_pixel(int x,int y,int c){
    // set a pixel in the current bitmap
    BYTE* pptr = pixmap+(linew*(bmh-y-1))+x;
    if(x>=0&&y>=0&&x<bmw&&y<bmh){
        *pptr = c;
    }else{
        std::cout << "Invalid Pixel Write Location\n";
    }
}
Checked out your bitbucket you have done lots of cool stuff there, and for Warcraft II in general. PMd you some suggestions :)  Hope this is useful.


 --- edit ---

Added an extra check to stop over-write. I didn't notice this because I was still looking at previous extracted bitmaps from before this issue was introduced. Had 0 effect on functionality, but better fixed. Thanks @iL for testing.

« Last Edit: March 05, 2019, 09:27:01 PM by Lambchops »
its gooder to hax hard and NEVER get caught!

Offline shesycompany

  • Death Knight
  • *********
  • Posts: 3587
  • retired, be in music section
    • View Profile
Re: War2 fonts (.fnt)
« Reply #27 on: March 03, 2019, 01:40:53 PM »
ok there u go lamb ..long as im trying, tried some longer they was to long(it'll be a little square then)..

naw not messed with 50..got a idea though brb

with some modifications, i think one could change the interface to the language they wanted...

some kinda chinese example....  i think<--  :-X

im using 12x... 10x cant stretch as far so it seems.
« Last Edit: March 04, 2019, 10:07:31 AM by easycompany »

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: War2 fonts (.fnt)
« Reply #28 on: March 04, 2019, 05:10:11 AM »
ok there u go lamb ..

Cool, thanks man :)

It's increased the size of the space character. I thought this might happen:

Gold          separates          east          from          west

As there is no data for the 0x20 character it is basing the space width on FontHeader.MaxWidth  .... perhaps MaxWidth/2+1 or something.

Maybe MaxWidth could be independantly set to a smaller value ???
its gooder to hax hard and NEVER get caught!

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1650
    • View Profile
Re: War2 fonts (.fnt)
« Reply #29 on: March 04, 2019, 09:50:04 AM »
Ok, but my code is very dependant on the format being exactly what it is expecting, so the format would have to be exactly the same. It would probably be easier to just use my export code as it is already 100% compatible with the import code. idc it's up to you.
Sure, that's why i used your code in my project!

I got a wc2 .pcx SS and converted it to a bitmap (8 bit palette based, as is the native format for the game).
Then I discarded the pixel data (made it all black) and resized it to 64x64 pixels. Then I just converted the entire file to a c-style declaration. *Have attached the original .bmp file just for interest's sake.
Idea is simple and... perfect!
To export proper bmp-file you need nothing except to write it's pixels, wigth,height and decrease size to required value.

Thanks for such great tool and several great programming ideas!

UPD:
Also, i added a function to make a shadow (color 5) for letter, applied it to russian letters with no shadows, and looks like that's done for me.
I got 5 beautiful russian fonts as planned, so, no reason to continue working on this project for me.
Commited it into my bitbucket. You can use exe to unpack font to *.bmp (same format as Lambchops utility, with dec filenames instead of hex, just better for me). My project is useless without the source code again.
« Last Edit: March 04, 2019, 10:00:26 AM by iL »
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.