Results 1 to 9 of 9

Thread: How to Add a Table Definition to PFM

  1. #1

    Icon4 How to Add a Table Definition to PFM

    First of all, you have to put the header definitions into the right header file (i.e. DBFileTypes_X.txt) where X defines the header version of the underlying DB file.

    You don't need to change any source code to add support for new files. That was part of the main idea

    Most DB files have the following layout:
    4 bytes header
    2 bytes GUID length
    72 bytes GUID
    4 bytes old header
    4 byte header version (unsigned integer)
    1 byte end of header flag
    4 byte number of data entries
    eof - 91 byte data entries

    all other layouts are considered as header version 0

    That was the easy part.
    Now you have to analyse the individual db files. You will need a hex editor and try to find the recurring scheme within the files.

    A simple example:
    Spoiler Alert, click show to read: 


    You'll quickly notice this file has header version 0. The four bytes starting at 0x4F (i.e. 03 00 00 00) tell you that there are three entries in this file and a quick look at the data following 0x53 (on the right side) show you that these three entries are simple strings.

    The correct entry in DBFileTypes_0.txt would therefore look like this:
    cai_agent_recruitment_types[TAB]unknown,string

    Now a more complex example:
    Spoiler Alert, click show to read: 


    Here, the four bytes at 0x52 tell you that the header version is 2 and one byte later, you learn that there are 24 entries (i.e. 18 00 00 00) in this file.
    With a bit of practise, you'll quickly see that the traits are stored as strings and are followed by an index (i.e. the number increases with every entry).

    The correct entry in DBFileTypes_2.txt would therefore look like this:
    avatar_traits[TAB]Trait IDRef,String;
    Index,UInt32

    Nota bene: If there is a semicolon at the end of a line, the next line will also be parsed!


    Finally, a word on data types. CA used only a limited number of types:
    UInt32: e.g. 03 00 00 00
    Single: e.g. 00 00 40 41 or 9A 99 99 3F
    Boolean: 01 or 00
    String: Any text (will always have two extra bytes for the string length in front of and is coded in UTF-8) e.g. "avatar" would be 06 00 61 00 76 00 61 00 74 00 61 00 72 00, where 06 00 is the length.


    I hope little guide helped to clarify the basics of adding new db files to PFM.

    If you have any questions, please feel free to ask.

  2. #2
    Hazbones's Avatar Senator
    Join Date
    May 2007
    Location
    Iwakuni, Japan
    Posts
    1,104

    Default Re: How to Add a Table Definiton to PFM

    Is this for the new Patch5 headers or still Patch4?

  3. #3

    Default Re: How to Add a Table Definiton to PFM

    Quote Originally Posted by Hazbones View Post
    Is this for the new Patch5 headers or still Patch4?
    This tutorial is for DB files. Pack files are something completely different. The guide is good for any patch.

  4. #4
    Hazbones's Avatar Senator
    Join Date
    May 2007
    Location
    Iwakuni, Japan
    Posts
    1,104

    Default Re: How to Add a Table Definiton to PFM

    Thanks for your help.

  5. #5
    Lord Baal's Avatar Praefectus
    Join Date
    Apr 2011
    Location
    Republica de Venezuela
    Posts
    6,704

    Default Re: How to Add a Table Definiton to PFM

    Sorry for being a noob, but what is this for? I mean, what can I do with this?
    PROUD TO BE A PESANT. And for the dimwitted, I know how to spell peasant. <== This blue things are links, you click them and magical things (like not ending up like a fool) happens.
    Visit my utterly wall of doom here.
    Do you wanna play SS 6.4 and take your time while at it? Play with my 12 turns per year here.
    Y también quieres jugar Stainless Steel 100% en español? Mira por aca.

  6. #6

    Default Re: How to Add a Table Definiton to PFM

    This will let you customize PFM, so you can open tables that the authors havn't yet put in.
    Last edited by Vragos; June 16, 2011 at 03:33 AM.

  7. #7
    Lord Baal's Avatar Praefectus
    Join Date
    Apr 2011
    Location
    Republica de Venezuela
    Posts
    6,704

    Default Re: How to Add a Table Definiton to PFM

    Of course! Now I get it.... please forgive such a idiotic question! I guess it was the late night that affected me...
    PROUD TO BE A PESANT. And for the dimwitted, I know how to spell peasant. <== This blue things are links, you click them and magical things (like not ending up like a fool) happens.
    Visit my utterly wall of doom here.
    Do you wanna play SS 6.4 and take your time while at it? Play with my 12 turns per year here.
    Y también quieres jugar Stainless Steel 100% en español? Mira por aca.

  8. #8

    Default Re: How to Add a Table Definiton to PFM

    One key additional datatype is "optional string". It can be very hard to distinguish an optional string from a boolean followed by a string. In PFM, an optional string is represented by the line:

    ->,Boolean,1;Field Name,string

    There is a single byte boolean; then in some records, this is followed by a string. It is used, obviously, to make the file slightly smaller for the case of a field which is very rarely used.

    EDIT: I have learned "->" is a convention, not a requirement of the PFM program. It can be any string. It "seems" that if the above line appears as a single line by itself, it always means an optional string. So if you want an actual boolean, followed by an actual string, you better put those on separate lines of the DBFileTypes_nn.txt file.
    Last edited by davidlallen; July 31, 2011 at 07:27 PM.

  9. #9

    Default Re: How to Add a Table Definiton to PFM

    Quote Originally Posted by davidlallen View Post
    (...)
    EDIT: I have learned "->" is a convention, not a requirement of the PFM program. It can be any string. It "seems" that if the above line appears as a single line by itself, it always means an optional string.
    You're absolutely right. I just use "->" to indicate an optional string (makes it faster to read the file). The important part is ",1". The latter tells PFM that the following field is optional (doesn't have to be a string though).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •