-
Notifications
You must be signed in to change notification settings - Fork 0
IMG
In GTA *.img archives, game models, textures, collision files, binary IPL files, vehicle and pedestrian paths, animations, and external scripts are usually stored.
An IMG archive has the .img extension. These archives are divided into versions, and their formats are similar to each other, except for the version used by GTA IV.
Version 1 archives consist of two files:
IMG - file archive containing the actual game resources.
Usually has the *.img extension.
DIR - directory for the archive contents.
Contains information about the files stored inside the IMG.
Usually has the *.dir extension.
The *.img format was designed for use on DVD or CD. This is probably where its internal name, CDIMAGE, comes from. Because of this, file sizes and file offsets are aligned to a DVD sector, which is 2048 bytes.
Even if a file is smaller than 2 KB, such as 218 bytes, it still takes 2 KB inside the archive.
Files in the archive are usually:
not sorted
not compressed
stored one after another
not arranged in a tree hierarchy
To find the total number of entries, or files, in a *.img archive, divide the size of the DIR file by 32.
The DIR contents are an array of 32-byte entries.
Each entry is repeated n times, where n is the total number of entries:
4 bytes DWORD file offset in the *.img archive, in blocks, relative to the start of the archive
4 bytes DWORD file size in the *.img archive, in blocks
24 bytes CHAR[24] file name
As mentioned earlier, files inside the IMG archive are stored in 2 KB blocks.
In GTA LCS and GTA VCS, only these archives belong to Version 1:
CUTS.IMG
MOCAP.IMG
GTA3PS2.IMG
GTA3PSP.IMG
GTA3PSPHR.IMG
All other archives belong to Version 1A.
This format is also used in other games, for example Bully: Scholarship Edition.
GTA3PS2.IMG, GTA3PSP.IMG, and GTA3PSPHR.IMG have their own special case: they do not have the DIR file described above as a separate visible file. This is because the game loads these archives through several DIR files: one for animation objects, one for dynamic objects, and one for textures.
Using gta_vc.dat or gta.dat, custom IMG archives can be attached to the game.
The format is:
CDIMAGE MODELS\FOO.IMG
The IMG and DIR must have the same name and must be located in the ..\models\ directory.
The only special feature of this version of the *.img archive is the lack of a DIR file.
The only thing it still has in common with Version 1 is that files are aligned to the sector size, which is 2048 bytes.
Files are loaded from the archive through jumps, or offsets, from certain points in the leading file, the master WRLD, into the archive's dependent files, the slave WRLD files.
To unpack the full contents of these archives, the master WRLD must be unpacked from the archive with the .lvz extension. This can be done with any Zlib unpacker, for example the one built into Stories WRLD Tool.
After that, the start tables for the slave WRLD files and their subordinate radar textures must be found. These tables can be used to determine which part of the map the contents of a slave WRLD belong to.
Each 32-byte row is the global header of a slave WRLD. At the end, it contains an offset to the continuation in the *.img archive with the same name as the LVZ.
Automatic unpacking of these archives is performed by the unimg utility.
Extracting WRLD files from *.img, as well as viewing and extracting resources from WRLD files, is implemented in Stories WRLD Tool.
Viewing and editing textures in WRLD is possible with GTA Stories Texture Explorer.
Theoretically, a DIR file can be built for such an archive. To create one, either extract the file table from game.dtz, or build a nameless DIR based on searching for file headers, for example with YAIE.
Version 2 archives, used in GTA San Andreas, are a combined DIR and IMG in one *.img file.
The file table has the same structure as in Version 1, but it is located at the beginning of the *.img file.
Files are also stored in 2 KB blocks.
File offsets are specified from the beginning of the archive itself, not from the end of the file list.
4 bytes CHAR[4] archive signature, always "VER2"
4 bytes DWORD total number of entries, or files
Each entry is repeated n times, where n is the total number of entries:
4 bytes DWORD file offset in the archive, in blocks
4 bytes DWORD file size, in blocks
24 bytes CHAR[24] file name
The drawback of this format is that it is inconvenient to expand.
If too many files are added, the directory starts being written over the first files in the archive. Because of that, the first files need to be moved to the end of the archive.
Using gta.dat, custom IMG archives can be attached to the game.
The format is:
IMG MODELS\FOO.IMG
By default, GTA San Andreas supports 8 IMG archives, 5 of which can be attached through gta.dat.
This limit can be raised with IMG Limit Adjuster.
This version of the archive has a more complex structure.
The only thing it has in common with the older versions is that files are aligned to the sector size, which is 2048 bytes.
The archive directory may be encrypted.
The file header is always 20 bytes.
4 bytes DWORD identifier, 0xA94E2A52.
If this field has a different value, the archive is encrypted.
4 bytes DWORD version, always 3
4 bytes DWORD object count
4 bytes DWORD directory size, in bytes
2 bytes WORD directory entry size.
This must always be 0x10.
2 bytes WORD unknown
The archive directory consists of two parts:
file descriptors
file names
File descriptors contain the offset and size of each file inside the archive.
Depending on how the file is loaded, the descriptor fields may differ.
For RSC files, the size and number of allocated memory blocks, or pages, are specified.
For normal files, the total length is specified.
The descriptor format, RSC or non-RSC, can be determined by the highest bit of the dwLength field. For RSC files, this bit is 1.
First comes an array of 16-byte descriptors:
Size Field name Purpose RSC files Other files
4 bytes DWORD dwLength object size in memory flags field from the RSC header object size
4 bytes DWORD dwVersion resource version version field from the RSC header unused
4 bytes DWORD dwOffset position in IMG offset in blocks offset in blocks
2 bytes WORD wSectorCount object size on disk block count block count
2 bytes WORD wPaddingSize object size on disk PaddingSize + bit 13 set PaddingSize
PaddingSize is the size of unused space in the last block.
After the descriptors come the file names, separated by \x00, or a null byte, in the same order as the descriptors.
If the archive identifier is not 0xA94E2A52, the archive is considered encrypted.
To read such an archive, read the header, which is 20 bytes, but decrypt only the first 16 bytes.
After that, check the identifier again.
If the identifier is correct, read the directory. The directory size is taken from the decrypted header.
Then decrypt the directory, rounding the size down to a multiple of 16.
For example, if the specified size is 259 bytes, only the first 256 bytes are decrypted.
The encryption is the standard encryption used by GTA IV: AES.