Informations on Heroes of Might and Magic 2 AGG format

This is what I could learn about the format of the data, present in the file Heroes2.agg. Most of the information on this page was retrieve from internet.

main aggregate file

The following is the description of James Koppel:

Aggregate files consist of the binary contents of various files concatenated together uncompressed, with a small amount of metadata.

A file's ID is a 32-bit hash of its filename computed by the following C function or equivalent:

int hash(char* filename) {
    unsigned int a = 0;
    int b = 0;
    for(int i = strlen(filename)-1; i>=0; i--){
        char c = toupper(filename[i]);
        a=(a<<5)+(a>>25);
        b+=c;
        a+=b+c;
    }
    return a;
}
    

James also release a program in java to extends and create AGG files.

files in the aggregate

The files includes in the aggregate file are the data of the games.

They are of type :

Most of the informations bellow on the formats of these files were extract for the study of the code of fheroes2.

icn format for sprites

All the numbers are encoded in little-endians.

The icn file contains a number n of images, we will name sprites. This is the structure of the file :

icn sprite header

icn sprite data

Each sprite's pixel has a color taken from a "palette". The palette is an array of 256 colors defined in the file "kb.pal". The format of this file is describe above. The pixel can also be a shadow pixel. The shadow color will be represented by a black pixel with an alpha channel of 64 (0 represents a fully transparent color, and 255 represents a fully opaque color).

The following sheme is repeated many times, describing how to fill pixels. By default a pixel will be transparent.

Scheme for normal sprite

There is one byte for command followed by 0 or more bytes of data. The command byte can be :

Scheme for monochromatic shape

The pixels can only be in two states (transparent or black). So the rules are simplified.

Command bytes are :