Difference between revisions of "IMG archive"

From GTAMods Wiki
Jump to navigation Jump to search
(Version 3 - GTA IV)
(Version 3 - GTA IV)
Line 37: Line 37:
 
=== Version 3 - GTA IV ===
 
=== Version 3 - GTA IV ===
  
GTA IV introduced yet another <code>.img</code> file format.
+
GTA IV introduced yet another <code>.img</code> file format. Not only the format is new, also there can be encrypted archives. The internal IMG parser of the game works with 2 kb buffers, which means that the 2 kb bounds from earlier versions (blocks) are still present.
Identifier will be equals to 0xA94E2A52 if the archive is non-encrypted
 
  
Header 20 bytes<br>
+
==== IMG Header ====
  4 byte - DWORD      - Identifier
 
  4 byte - DWORD      - Version
 
  4 byte - DWORD      - Items Counts
 
  4 byte - DWORD      - Table Size
 
  2 byte - WORD      - Table Item Size (16 always)
 
  2 byte - WORD      - Unknown
 
  
Table
+
The header of an unencrypted file allways has a size of '''20 bytes'''.
  Each Item 16 bytes
 
    4 byte - DWORD      - File Size
 
    4 byte - DWORD      - Resource Type
 
    4 byte - DWORD      - Offset (in block)
 
    2 byte - WORD      - Used Blocks
 
    2 byte - WORD      - Padding
 
  File Names - Table Size - (Items Count * Item Size)
 
  
 +
4 byte - DWORD      - Identifier (0xA94E2A52 if the archive is not encrypted)
 +
4 byte - DWORD      - Version
 +
4 byte - DWORD      - Number of entries
 +
4 byte - DWORD      - Tablesize (in bytes)
 +
2 byte - WORD      - Size of tableitems (needs to be allways 0x10)
 +
2 byte - WORD      - Unknown
  
 +
==== IMG Table ====
 +
 +
The table holds information about the items. Each item header has a size of '''16 bytes''' .
 +
 +
4 byte - DWORD      - Itemsize (in bytes)
 +
4 byte - DWORD      - Resource type
 +
4 byte - DWORD      - Offset (in blocks)
 +
2 byte - WORD      - Used Blocks
 +
2 byte - WORD      - Padding
 +
 +
A ressource type is identified by the 4b DWORD value:
 +
* 0x01: Generic
 +
* 0x08: Texture archive
 +
* 0x20: Bounds
 +
* 0x6E: Model file
 +
* 0x24: xpfl
 +
 +
<!--File Names - Table Size - (Items Count * Item Size)-->
  
 
{{file-stub}}
 
{{file-stub}}
 
[[Category:Other Formats]][[Category:GTA 3]][[Category:GTA VC]][[Category:GTA SA]][[Category:GTA 4]]
 
[[Category:Other Formats]][[Category:GTA 3]][[Category:GTA VC]][[Category:GTA SA]][[Category:GTA 4]]

Revision as of 19:10, 18 January 2009

GTA's most commonly used archive files are known by the extension .img. They have a very simple format and currently exist in multiple versions.

Structure

Version 1 - GTA III & VC

Version 1 archives, used in GTA III and Vice City, are actually split up into two files: the content directory (.dir) and the actual archive (.img).

The directory is a list of files, each with name, offset and size of the file. The values for offset and size have to be multiplied by 2048, since files are aligned to 2 KB boundaries. This means that even a file with only 123 byte content will take up 2 KB in the archive. Files are stored (usually) unsorted, uncompressed and linear (no directory tree).

First you have to find out the number of entries (n). Just divide the filesize of the .dir file by 32 and you will get it.

There is no Header, like in V2 (San Andreas) Files!

Entry: (repeated n times)
4 byte - DWORD - offset of file inside archive (in blocks) 4 byte - DWORD - size of file (in blocks) 24 byte - CHAR[24] - name of file

The .img file itself has no special structure or header, just all the files in 2 KB blocks.

Version 2 - GTA SA

Version 2 archives, introduced with GTA San Andreas, combine .dir and .img files into one .img file. The directory has the same format as in version 1, but is located at the beginning of the archive. Files are again aligned to 2 KB boundaries. File offsets are relative to the start of the whole archive, not to the end of the file list.

Header:
4 byte - CHAR[4] - FourCC, always "VER2" 4 byte - DWORD - number of entries (n)
Entry: (repeated n times)
4 byte - DWORD - offset of file inside archive (in blocks) 4 byte - DWORD - size of file (in blocks) 24 byte - CHAR[24] - name of file

A major drawback of this format is the complicated extendability. If you have to add many files, it might happen that you run out of space for the directory, and have to move the first file(s) to the end.

Version 3 - GTA IV

GTA IV introduced yet another .img file format. Not only the format is new, also there can be encrypted archives. The internal IMG parser of the game works with 2 kb buffers, which means that the 2 kb bounds from earlier versions (blocks) are still present.

IMG Header

The header of an unencrypted file allways has a size of 20 bytes.

4 byte - DWORD      - Identifier (0xA94E2A52 if the archive is not encrypted)
4 byte - DWORD      - Version
4 byte - DWORD      - Number of entries
4 byte - DWORD      - Tablesize (in bytes)
2 byte - WORD       - Size of tableitems (needs to be allways 0x10)
2 byte - WORD       - Unknown

IMG Table

The table holds information about the items. Each item header has a size of 16 bytes .

4 byte - DWORD      - Itemsize (in bytes)
4 byte - DWORD      - Resource type
4 byte - DWORD      - Offset (in blocks)
2 byte - WORD       - Used Blocks
2 byte - WORD       - Padding

A ressource type is identified by the 4b DWORD value:

  • 0x01: Generic
  • 0x08: Texture archive
  • 0x20: Bounds
  • 0x6E: Model file
  • 0x24: xpfl