edit binary fnt/dds file

Textures, recreate headers, conversions, algorithms and parsing of image files
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

edit binary fnt/dds file

Post by saeid0034 »

Hi i want a way to edit l.a. noire font for add some new character to it
its possible to add new character to it?
original dds like this
Image

this is example font
Last edited by saeid0034 on Tue Apr 14, 2020 11:24 am, edited 1 time in total.
Allen
Posts: 156
Joined: Tue Sep 01, 2015 9:44 am

Re: edit binary fnt/dds file

Post by Allen »

If you know programming or are familiar with 010 hex editor data type, this binary template format will help you.

Code: Select all

//------------------------------------------------
//--- 010 Editor v9.0.2 Binary Template
//
//      File: L.A. Noire .fnt
//   Authors: Allen
//   Version:
//   Purpose:
//  Category:
// File Mask:
//  ID Bytes:
//   History:
//------------------------------------------------
char    BFM3[4];//BFM\x3

struct{
    byte    chunkID;//1
    int     chunkDataSize;
    short   u1;//size?
    short   u2;//?
    short   stretchH;
    byte    smooth;
    byte    padding[4];
    byte    spacing[2];
    byte    outline;
    string  fontName;
}chunk1;

struct{
    byte    chunkID;//2
    int     chunkDataSize;
    short   lineHeight;
    short   base;
    short   imageWidth;//dds file is 32bpp rgba8888 format
    short   imageHeight;
    byte    pages;
    short   packed;
    byte    alphaChnl;
    byte    redChnl;
    byte    greenChnl;
    byte    buleChnl;
}chunk2;
local int i;
struct{
    byte    chunkID;//3
    int     chunkDataSize;
    for (i=0;i<chunk2.pages;i++)
    {
        struct{
        string  fontImageName;
        }imageName;
    }

}chunk3;
struct{
    byte    chunkID;//4
    int     chunkDataSize;
    struct{
        int   charEncode;//unicode
        short x1;
        short y1;
        short width;
        short height;
        short xoffset;
        short yoffset;
        short xadvance;
        byte  page;
        byte  chnl;
    }index[chunkDataSize/20]<optimize=false>;
}chunk4;
if (FTell()<FileSize())
{
struct{
    byte    chunkID;//5
    int     chunkDataSize;
    struct{
        wstring charEncode1;//first
        wstring charEncode2;//second
        short amount;//kerning
    }kernings[chunkDataSize/10];
}chunk5;
}
Last edited by Allen on Wed Apr 15, 2020 3:58 am, edited 1 time in total.
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

Re: edit binary fnt/dds file

Post by saeid0034 »

Allen wrote:If you know programming or are familiar with 010 hex editor data type, this binary template format will help you.

Code: Select all

//------------------------------------------------
//--- 010 Editor v9.0.2 Binary Template
//
//      File: L.A. Noire .fnt
//   Authors: Allen
//------------------------------------------------
char    BFM3[4];//BFM\x3

struct{
    byte    chunkID;//1
    int     chunkDataSize;
    short   u1;
    short   u2;
    short   u3;
    byte    u4[8];
    string  unkStr;
}chunk1;

struct{
    byte    chunkID;//2
    int     chunkDataSize;
    short   u1;
    short   u2;
    short   imageWidth;//dds file is 32bpp rgba8888 format
    short   imageHeight;
    byte    u3;
    byte    u4[2];
    int     u5;
}chunk2;
struct{
    byte    chunkID;//3
    int     chunkDataSize;
    string  fontImageName;
}chunk3;
struct{
    byte    chunkID;//4
    int     chunkDataSize;
    struct{
        int   charEncode;//unicode
        short x1;
        short y1;
        short width;//base rectangle
        short height;//base rectangle
        short xoffset;//+ is left offset, - is right offset
        short yoffset;//+ is up offset, - is down offset
        short showWidth;
        short unk;//0xf00
    }index[chunkDataSize/20]<optimize=false>;
}chunk4;

struct{
    byte    chunkID;//5
    int     chunkDataSize;
    struct{
        wstring charEncode1;
        wstring charEncode2;
        short distance_offset;//Character spacing, pixels
    }table[chunkDataSize/10];
}chunk5;

tnx im not very familler with hex editing
but i will cheak
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

Re: edit binary fnt/dds file

Post by saeid0034 »

im want to add some value to original fnt
its possible with your template?
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

Re: edit binary fnt/dds file

Post by saeid0034 »

Allen wrote:If you know programming or are familiar with 010 hex editor data type, this binary template format will help you.

Code: Select all

//------------------------------------------------
//--- 010 Editor v9.0.2 Binary Template
//
//      File: L.A. Noire .fnt
//   Authors: Allen
//------------------------------------------------
char    BFM3[4];//BFM\x3

struct{
    byte    chunkID;//1
    int     chunkDataSize;
    short   u1;
    short   u2;
    short   u3;
    byte    u4[8];
    string  unkStr;
}chunk1;

struct{
    byte    chunkID;//2
    int     chunkDataSize;
    short   u1;
    short   u2;
    short   imageWidth;//dds file is 32bpp rgba8888 format
    short   imageHeight;
    byte    u3;
    byte    u4[2];
    int     u5;
}chunk2;
struct{
    byte    chunkID;//3
    int     chunkDataSize;
    string  fontImageName;
}chunk3;
struct{
    byte    chunkID;//4
    int     chunkDataSize;
    struct{
        int   charEncode;//unicode
        short x1;
        short y1;
        short width;//base rectangle
        short height;//base rectangle
        short xoffset;//+ is left offset, - is right offset
        short yoffset;//+ is up offset, - is down offset
        short showWidth;
        short unk;//0xf00
    }index[chunkDataSize/20]<optimize=false>;
}chunk4;

struct{
    byte    chunkID;//5
    int     chunkDataSize;
    struct{
        wstring charEncode1;
        wstring charEncode2;
        short distance_offset;//Character spacing, pixels
    }table[chunkDataSize/10];
}chunk5;

in sime fnt file your temple give me this error
Annotation 2020-04-13 153319.png
Allen
Posts: 156
Joined: Tue Sep 01, 2015 9:44 am

Re: edit binary fnt/dds file

Post by Allen »

saeid0034 wrote:in sime fnt file your temple give me this error
Annotation 2020-04-13 153319.png

Your file is only 1620 bytes, of course, it will be wrong, it is not complete, it is offset at 0x59, and the data size of chunk4 is 0x3c8c (15500). So this is not a template error, it is yours.

Here is an example, I only added 2 characters manually: 可能.

fnt part:
chunk4 is a character information table.
at offset 0x59:
change chunkDataSize 8680 to 8720.
Because the one-letter information table occupies 20 bytes.

at offset 0x2245:(the chunk4 end offset)
insert 40 bytes.
re-run binary template.
In the template, go to the end of CHUNK4 and find the newly added 2 pieces of data. You will find that all are 0. We enter the relevant data in the template.


You will find that it has been added correctly.

dds part:

Use the reference line function of PS to obtain the relevant coordinate data and input it into the fnt file. Save the new DDS font.
Note**: save 32bpp format.

char part:
Save the character you want to add as UNICODE text, and then open it with a hex editor, excluding the BOM header 2 bytes, the remaining bytes every 2 bytes is an encoding.
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

Re: edit binary fnt/dds file

Post by saeid0034 »

Allen wrote:
saeid0034 wrote:in sime fnt file your temple give me this error
Annotation 2020-04-13 153319.png

Your file is only 1620 bytes, of course, it will be wrong, it is not complete, it is offset at 0x59, and the data size of chunk4 is 0x3c8c (15500). So this is not a template error, it is yours.

Here is an example, I only added 2 characters manually: 可能.

fnt part:
chunk4 is a character information table.
at offset 0x59:
change chunkDataSize 8680 to 8720.
Because the one-letter information table occupies 20 bytes.

at offset 0x2245:(the chunk4 end offset)
insert 40 bytes.
re-run binary template.
In the template, go to the end of CHUNK4 and find the newly added 2 pieces of data. You will find that all are 0. We enter the relevant data in the template.


You will find that it has been added correctly.

dds part:

Use the reference line function of PS to obtain the relevant coordinate data and input it into the fnt file. Save the new DDS font.
Note**: save 32bpp format.

char part:
Save the character you want to add as UNICODE text, and then open it with a hex editor, excluding the BOM header 2 bytes, the remaining bytes every 2 bytes is an encoding.

tnx for this good guide
only one more Question
I need to increase the size of the dds file to 1024x1024 to add all my character to it
after that i need to edit all char location again then after that add my char to fnt?
Allen
Posts: 156
Joined: Tue Sep 01, 2015 9:44 am

Re: edit binary fnt/dds file

Post by Allen »

If you expand the picture, if the original characters are still in the original position, then you do not need to change all the characters, only need to care about your newly added characters.
Because the coordinate value is an absolute value, no matter how you extend it, it will not be disturbed.

In CHUNK2 you need to modify the corresponding width and height information.
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

Re: edit binary fnt/dds file

Post by saeid0034 »

Allen wrote:If you expand the picture, if the original characters are still in the original position, then you do not need to change all the characters, only need to care about your newly added characters.
Because the coordinate value is an absolute value, no matter how you extend it, it will not be disturbed.

In CHUNK2 you need to modify the corresponding width and height information.

tnx man
you really saved me
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

Re: edit binary fnt/dds file

Post by saeid0034 »

Allen wrote:If you expand the picture, if the original characters are still in the original position, then you do not need to change all the characters, only need to care about your newly added characters.
Because the coordinate value is an absolute value, no matter how you extend it, it will not be disturbed.

In CHUNK2 you need to modify the corresponding width and height information.

Is there no way to automate the process of changing values?
i need to change values in 10 file, And doing all this manually takes a long time (very long)
I tried to do it manually
After an hour and a half, only 100 of the 433 completed (in one file)
Allen
Posts: 156
Joined: Tue Sep 01, 2015 9:44 am

Re: edit binary fnt/dds file

Post by Allen »

saeid0034 wrote:Is there no way to automate the process of changing values?
i need to change values in 10 file, And doing all this manually takes a long time (very long)
I tried to do it manually
After an hour and a half, only 100 of the 433 completed (in one file)

I will write a tool for you. Yesterday I received your private message. You said that your new font was generated by BMFONT. I read the binary FNT format generated by BMFONT today. It turned out to be the same format as the game using fnt. That is to say, the format of the game is BMFONT. However, there are a lot of custom icons, so all we have to do is add new characters, not create new ones.

I will upload a tool later to add a new fnt index to the game's existing fnt file.
Don't forget the alpha channel when merging pictures, because the alpha channel determines which part of the character is displayed.

I will only support fnt binary files generated by BMFont v1.14beta64 version.
BMfont 64bit executable for v1.14 beta (1.65MB, 2019/11/15)
http://www.angelcode.com/products/bmfont/bmfont64.exe
v1.13 Can't run on my computer.

I have updated the format template.
viewtopic.php?f=7&t=13442#p55856
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

Re: edit binary fnt/dds file

Post by saeid0034 »

Allen wrote:
saeid0034 wrote:Is there no way to automate the process of changing values?
i need to change values in 10 file, And doing all this manually takes a long time (very long)
I tried to do it manually
After an hour and a half, only 100 of the 433 completed (in one file)

I will write a tool for you. Yesterday I received your private message. You said that your new font was generated by BMFONT. I read the binary FNT format generated by BMFONT today. It turned out to be the same format as the game using fnt. That is to say, the format of the game is BMFONT. However, there are a lot of custom icons, so all we have to do is add new characters, not create new ones.

I will upload a tool later to add a new fnt index to the game's existing fnt file.
Don't forget the alpha channel when merging pictures, because the alpha channel determines which part of the character is displayed.

I will only support fnt binary files generated by BMFont v1.14beta64 version.
BMfont 64bit executable for v1.14 beta (1.65MB, 2019/11/15)
http://www.angelcode.com/products/bmfont/bmfont64.exe
v1.13 Can't run on my computer.

I have updated the format template.
viewtopic.php?f=7&t=13442#p55856

Thank you very much
it seems that the only hard part is editing font that also contains icons ...
Other fonts can be Built directly with bmfont
Allen
Posts: 156
Joined: Tue Sep 01, 2015 9:44 am

Re: edit binary fnt/dds file

Post by Allen »

This is a tool you can test, all values are generated based on BMFONT, except for the y value and the image height value, the other has not been modified. I just merge FNT files.
FntTool.zip
saeid0034
Posts: 40
Joined: Sat Mar 14, 2020 7:17 pm

Re: edit binary fnt/dds file

Post by saeid0034 »

Allen wrote:This is a tool you can test, all values are generated based on BMFONT, except for the y value and the image height value, the other has not been modified. I just merge FNT files.
FntTool.zip

Thank you very much
Do I have to manually change these two values (y and height)? (add 512 to to all old cahr -y- value)
----edit----
i read your tool help, and now i understand everything
tnx man