Difference between revisions of "Packages"

From SimsWiki
Jump to: navigation, search
(0xC0 - 0xDF: Put Sims 2 infront of SimCity 4)
(Double Redirect)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This article describes the specifics of the package format used in [[SimCity 4]] and [[The Sims 2]].
+
#REDIRECT [[DatabasePackedFile]]
 
+
=Format=
+
(see [[DBPF]])
+
 
+
=Compression=
+
The idea behind the compression is to reuse previously decoded strings. For example, if the word "heureka" occurs twice in a file, the second occurence would be encoded by pointing to the first.
+
 
+
The compression is done by defining control characters that tells three things:
+
#How many characters of plain text that follows that should be appended to the output.
+
#How many characters that should be read from the already decoded text (and appended to the output)
+
#At which offset in the already decoded text to read the characters.
+
 
+
Thus, the algorithm to decompress these files goes like this:
+
 
+
Read file size at offset 0
+
Seek to offset 9
+
while not end of file is reached do
+
{
+
- Read next control character.
+
- (Depending on control character read 0-3 more bytes that are a part of the control character.)
+
- Figure out how many characters that should be read and from where by inspecting the control character.
+
- Read 0-n characters from source and append them to the output.
+
- Copy 0-n characters from somewhere in the output to the end of the output.
+
}
+
 
+
There are 4 types of control characters which are used with different restrictions of how many characters that can be read and from how far behind these can be read. The following conventions are used to describe them:
+
 
+
;CC length
+
:Length of control character.
+
;Num plain text
+
:Number of chars immediately after the control character that should be read and appended to output.
+
;Num to copy
+
:Number of chars that should be copied from somewhere in the already decoded output and added to the end of the output.
+
;Copy offset
+
:Where to start reading characters when copying from somewhere in the already decoded output.
+
:This is given as an offset from the current end of the output buffer, i.e. an offset of 0 means that you should copy the last character in the output and append it to the output. And offset of 1 means that you should copy the second-to-last character.
+
;byte0
+
:first byte of control character.
+
;Bits
+
:Bits of the control character.
+
:*p - num plain text
+
:*c - num to copy
+
:*o - copy offset
+
:*i - identifier.
+
 
+
Note: It can sometimes be confusing when a control character states that you should copy for example 10 characters 5 steps from the end of the output. Clearly, you cannot read more than 5 characters before you reach the end of the buffer. The solution is to read and write one character at the time. Each time you read a character you copy it to the end thereby increasing the size of the output. By doing this, even offset 0 is possible and would result in duplicating the last character a number of times. This is utilized by the compression to recreate repeating text, for example bars of repeating dashes
+
 
+
This is the simplest form of control character. The only thing it does is telling how many plain text characters that follows. The formula for this is: (C - 0x7F) * 4. Thus a value of 0xE0 means that you should read 4 characters of plain text and append to the output.
+
 
+
==0x00 - 0x7F==
+
 
+
CC length: 2 bytes
+
Num plain text: byte0 & 0x03
+
Num to copy: ( (byte0 & 0x1C) > > 2) + 3
+
Copy offset: ( (byte0 & 0x60) < < 3) + byte1 + 1
+
 
+
Bits: 0oocccpp oooooooo
+
Num plain text limit: 0-3
+
Num to copy limit: 3-11
+
Maximum Offset: 1023
+
 
+
 
+
==0x80 - 0xBF==
+
 
+
CC length: 3 bytes
+
Num plain text: ((byte1 & 0xC0) > > 6 ) & 0x03
+
Num to copy: (byte0 & 0x3F) + 4
+
Copy offset: ( (byte1 & 0x3F) < < 8 ) + byte2 + 1
+
 
+
Bits: 10cccccc ppoooooo oooooooo
+
Num plain text limit: 0-3
+
Num to copy limit: 4-67
+
Maximum Offset: 16383
+
 
+
 
+
==0xC0 - 0xDF==
+
This format differes depending on the game.
+
 
+
===Sims 2===
+
CC length: 4 bytes
+
Num plain text: byte0 & 0x03
+
Num to copy: ( (byte0 & 0x0C) < < 6 )  + byte3 + 5
+
Copy offset: ((byte0 & 0x10) < < 12 ) + (byte1 < < 8 ) + byte2 + 1
+
 
+
Bits: 110occpp oooooooo oooooooo cccccccc
+
Num plain text limit: 0-3
+
Num to copy limit: 5-1028
+
Maximum Offset: 131072
+
 
+
===SimCity 4===
+
CC length: 4 bytes
+
Num plain text: byte0 & 0x03
+
Num to copy: ( (byte0 & 0x1C) < < 6 )  + byte3 + 5
+
Copy offset: (byte1 < < 8) + byte2
+
 
+
Bits: 110cccpp oooooooo oooooooo cccccccc
+
Num plain text limit: 0-3
+
Num to copy limit: 5-2047
+
Maximum Offset: 65535
+
 
+
==0xE0 - 0xFF==
+
 
+
CC length: 1 byte
+
Num plain text: ((byte0 & 0x1F) < < 2 ) + 4
+
Num to copy: 0
+
Copy offset: -
+
 
+
Bits: 111ppppp
+
Num plain text limit: 4-128
+
Num to copy limit: 0
+
Maximum Offset: -
+
 
+
=Directory Files=
+
Directory files are one of the newer filetypes I found about the beginning of May. Their purpose is to spead up the loading of a DAT file by showing exactly what is compressed inside it. They are directories of all the compressed files in an archive. This luckily makes their structure fairly simple.
+
 
+
;repeated
+
;DWORD
+
:Type ID of the file
+
;DWORD
+
:Group ID of the file
+
;DWORD
+
:Instance ID of the file
+
;DWORD
+
:Instance2/Resource ID (only in new index format dbpfs)
+
;DWORD
+
:Size of the decompressed file in Hex
+
 
+
These files are found as DIR/Directory by the reader and are automatically modified by it during changes to dat files.
+
 
+
It is HIGHLY reccommended that you modify the Directory after editing any compressed file before saving the dat if you are working manually in hex or making your own program.
+
 
+
See [[E86B1EEF]].
+
 
+
{{OldWikiEntryCleaned}}
+
 
+
[[Category:Modding]]
+
[[Category:InternalFormats]]
+

Latest revision as of 10:18, 6 September 2010

  1. REDIRECT DatabasePackedFile
Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox