Difference between revisions of "IMG archive"

From GTAMods Wiki
Jump to navigation Jump to search
m (Version 1 - GTA3 & VC)
(Version 1 - GTA3 & VC)
Line 12: Line 12:
  
 
First you have to found out the <strong>number of entries (n)</strong>.
 
First you have to found out the <strong>number of entries (n)</strong>.
Just divide the filesize of the .dir file through 32 and you will get it.
+
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!
 
There is no Header, like in V2 (San Andreas) Files!

Revision as of 21:14, 26 July 2006

Introduction

GTA's archive files are known by the extension .img, have a very simple format, and currently exist in two versions. Archived files are stored in 2 KB blocks, unsorted, uncompressed and linear (no directory tree).

Structure

Version 1 - GTA3 & 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.

First you have to found 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.