Decoding - .LIB Files

 

 

This section has information about the construction of the game files and how to edit them. If you know something about a that there is no information available about, please contribute! Provided are documents, descriptions and tools allowing you to edit the files.


The information here is based on The Peasants Rebellion, unless otherwise stated!

 


Overview

 

Contents: Most of the text displayed in the game are stored in these files.
Status: 99%
Contributors: Lewin
legionary2
Zomis
Documents: Lewin doc.gif
Tools: legionary2 download.png
Lewin download.png

 

 

Construction

 

 

Once again, I'm better off copying the document Lewin wrote.

 

 


 

 

 

Lewin's Descriptions of the Knights and Merchants text (LIB) files


Introduction


To get the values that I will be talking about in this file, you should get the ordinal value of the byte. In Delphi that would be ord(); e.g. 'u' has an ordinal value of 75, and ÿ is 255

For all the examples here I am using the English setup.lib

 

 

Header


The first two byte set the total number of strings. Add the value of the first byte onto the second bytes X 256. Here are the formulas:

 

N means Number of strings
B1 means Byte 1
B2 means Byte 2




 

N = B1+(B2*256)

And for when you save it:

B1 = N mod 256
B2 = N div 256


The next two bytes are the index for the last string in the file. Use the same code as above to get the values. Don't worry about these yet, I will come to them later.

The next 4 bytes are unknown. For my decoder I remember them and save them as the same value as when I loaded them. They are normally 0, but the Russian and Dutch setup.lib files are different. If you know what they are or have a clue them please email me.

 

 

Indexes


Then the indexes start. They are two byte pars just like described above for the number of bytes. Each value is the location of the current string plus it's length plus 1 for the separator, starting from where the real strings being. So for the first value in the English setup.lib, “unused”, the number is 7. As it is the first string the location of it is 0, so that is 0 plus the length 6 plus one for the separator = 7. The next string, “Campaign 'The Shattered Kingdom'” has a location of 7, and a length of 32, plus 1 for the separator = 40. And so it continues throughout the file.

 

 

Index for the last string


You might notice that there are one less indexes than strings. This is because the index for the last string in the file is stored in the header, as the third and fourth bytes. Why this is done I don't understand, but that is how it is.

 

 

Deleted strings


In the index you will notice byte pars with a value of 255. (FF in hexadecimal) These string don't actually exist, but they are still counted in the number of strings from the header. The first one is at the one hundred and twenty second byte par in setup.lib. If you're planning to make a tool to edit these files then DON'T JUST IGNORE THEM!! As indexes are used in game to extract strings, deleting these will change the index, making the wrong text be displayed everywhere. So remember what strings are blank (for saving) and hide them if you like, but what ever you do don't delete them!
If, however you wish to allow editing of these strings, instructions are bellow.
NOTE: Unless you plan to edit these strings then I recommend you skip this section.

 

 

Editing Deleted Strings


For some ridicules reason that I cannot understand, you cannot simply enable these deleted strings. (change the value to something real) I’ll try to explain it as best I can. A disabled string is placed one earlier in the index. So when you enable an FF byte par, you must move them forward 1 space. I explain it in a diagram:

 

   Red   1 
   Green   2 
   Blue (DISABLED)   3 
   Orange (DISABLED)   4 
   Purple   5 

  Here is an example list of strings. Blue and orange are disabled. (they are FF in the index)

 

   Red   1 
   Blue (ENABLED)   2 
   Orange (ENABLED)   3 
   Green   4 
   Purple   5 

Here is the same list of strings once Blue and Orange have been enabled. See the difference? That’s right, both the newly enabled strings have been moved up one place. If they were to be disabled then you would need to move them back down again.


Note: Disabled strings don’t appear as text later on in the file, they are just ignored.


 

Text


At the end of the header the text begins. The strings are separated by a 0. (in ordinal or hexadecimal) As ASCII the separator looks like a dot. This separator is also counted in indexing. So the first bit in ASCII reads:

 

unused.Campaign 'The Shattered Kingdom'.Campaign 'The Peasants Rebellion'.Play Tutorial.Play Single Map.

This is the start of the menu text. (except for unused, don't ask me why they have that as a string!)


 

New Lines


To put a new line, (line break, like pressing enter on the keyboard) use the character | (vertical bar, on the backslash key) The game will automatically replace these with new lines.



Non-breaking spaces


The character 127 (7F in hexadecimal) is a kind of non-breaking space. I don't completely understand what they are for, but that are used in the in-game messages to make sure that you don't end up with extra new lines.



Incorrect value set by The Barbarian/The Knight's Editor


Interestingly, Service Release 2 (fan made patch by The Barbarian and The Knight) also introduced a new incorrect value to the LIB files. They are not there in versions before 1.58, so I am assuming that is where they are from. However, they are not a big problem as KaM ignores all unknown values. Still, I thought I'd explain it here so you don't get confused. The incorrect value is the normal way of placing a new line in Windows, hexadecimal 0D or Ordinal 13. You can either ignore these, or delete them. It will still look the same in KaM.



End of the file (footer)


The file ends with two 0 value byte, including the separator one from the last string. So the end of the file should look like this: <0_Value><0_Value>


If you correct any mistakes or add anything, please send it to me.



Copyright 2007 Lewin Hodgman.


Contact:


Email: REMOVED (Download document to see)

Website: http://lewin.hodgman.id.au/

This file can be publicly published for free only, so long as my name is on it.
This file can be edited/fixed/changed to make it more relevant as needed, as long as I am notified.