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.
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 (
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 - name of file
.img file itself has no special structure or header, just all the files in 2 KB blocks.
This format was also used in the PC version of Bully: Scholarship Edition.
Version 2 - GTA SA
Version 2 archives, introduced with GTA San Andreas, combine
.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.
Size of 8 bytes
4 byte - CHAR - “VER2” always 4 byte - DWORD - Number of files on list (n)
Size of 32 bytes
4 byte - DWORD - File offset, in blocks 2 byte - WORD - Streaming size in blocks 2 byte - WORD - File size in blocks 24 byte - CHAR - File name (0x00) terminated.
The streaming size is how many actual blocks the file takes in memory while the file size is how many blocks the file takes in the img archive. If file size is 0, streaming size will be used as file size. The stock img files never used file size (thus always 0), it's believed that this mechanism would be used for compression of files.
Entries should be in the same order as the files are in the archive, and there shouldn't be any empty block between files. This is because the game might read more than one file with a single system call. By not following this, the game might get unstable.
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 archive headers (see below). 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, yet optional.
The header of an unencrypted file always has a size of 20 bytes.
4 byte - DWORD - Identifier (0xA94E2A52 if the archive is not encrypted) 4 byte - DWORD - Version (always 3, if not the format would be differ) 4 byte - DWORD - Number of Items 4 byte - DWORD - Table Size (in bytes) 2 byte - WORD - Size of Table Items (needs to be always 0x10) 2 byte - WORD - Unknown
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
Item Names' length will be calculate as :
Table Size - (Number of Items * Item Size)
Next that string will be split by '\x0'
A resource type is identified by the 4b DWORD value:
- 0x01: Generic
- 0x08: Texture archive
- 0x20: Bounds
- 0x6E: Model file
- 0x24: xpfl
The header and directory (table) of IMG archives can be encrypted. This is usually the case if the 4 byte identifier at the start of the file seems invalid. Decryption is done via 16 repetitions of AES-128 in ECB mode.
Where FOO can be any name. The FOO.IMG (and FOO.DIR for GTA III and Vice City) must be created and placed within the
..\models folder in these examples. This method is primarily used for modifying version 2 of San Andreas, as well as for storing assets (models/textures/etc.) used in total conversions.
By default GTA San Andreas is able to load max of 8 archives (3 standard archives gta3.img, gta_int.img, player.img and 5 archives defined within default.dat or gta.dat). GTA VC is able to load max of 8 archives (one archive is hard-coded to be loaded - gta3.img) too. Using more than 8 archives crashes the game, although this can be fixed with fastman92's IMG Limit Adjuster.
|ImgEd – by Dan Strandberg|
|IMG Manager – by xmen|
|GTAGarage: Spark – by aru|
|IMG Tool – by Spooky|
|G-IMG – by REspawn|
|GTAForums: fastman92 IMG Console – by fastman92|
|GTAForums: IMG & Stream Limit Adjuster – by fastman92|
|GTAForums: GTA Stories IMG Tool – by HackMan128|
|SparkIV – by aru|
|OpenIV – by GooD-NTS|
|Shadow-Mapper – by Prince-Link|
Version 2 only
Version 3 only
|Grand Theft Auto IV|
|File Formats||.dat • .gxt • .ide • .img • .ipl • .nod • .sco • .rpf • .rrr • .wad • .wbd/.wbn • .wdd • .wdr • .wft • .whm • .wpl • .wtd|
|Documentation||Audio • Bink Video • Cryptography • Cutscenes • Image listing • Map Listing • Native functions • Paths • Scenarios • Saves • VTable • Weapons|
|Tools||ASI Loader • ENBSeries • G-Texture • GIMS • IV Needle • OpenIV • Scocl • SparkIV • XLiveLess • WPL Manager • X Mod Installer|
Alice • C++ Script Hook • .NET Script Hook
|Tutorials||Importing Textures with OpenIV • Importing Textures with SparkIV|
|Multiplayer||Four Multiplayer • IV Multiplayer • IV:Online|
|Modifications||GTA 3 HD Rage • GTA Vice City Rage • IV:SA • Gostown IV|
|Grand Theft Auto: San Andreas|
|File Formats||.col • .cfg • .cut • .dff • .dat • .fxp • .gxt • .ide • .ifp • .img • .ipl • nodes*.dat • .rep • .rrr • .scm • .set • .txd|
|Documentation||Audio • Cryptography • Cutscenes • Game memory • Handling.cfg • Map Listing • Mission Packs • Opcodes • Paths • Replays • Saves • Scripts|
|Tools||CLEO • Collision File Editor II • ENBSeries • G-Tools • IMG Tool • Limit Adjuster • Map Editor • San Andreas Audio Toolkit • Sanny Builder • TXD Workshop|
|Tutorials||San Andreas v2.0 Modding • How to create a mission • How to create a thread • How to use Map Editor|
|Modifications||Design Your Own Mission • Gostown Paradise • GTA: United • Myriad Islands|