Skip to content

HG‐3 Image

Robert Jordan edited this page Mar 17, 2020 · 14 revisions

Some values unknown but still much more readable than other implementations

File Structure

The first 12 bytes of this header uses the same structure as HG-2 Image's header.

Data Type Value Description
char[4] "HG-3" File Signature
uint32 HeaderSize Size of this header, always 12
uint32 Version HG-3 version number: 0x300
Frame[>] Frames A find-by-offset set of frames for this image

About Version

The Version field is likely formatted as hex digits, but represented as a decimal version number. Because HG-2 Image's make use of 0x10, 0x20, and 0x25, its possible that 0x300 is used to avoid sort of conflicts.

Hex Dec Includes
0x300 v3.00 Only version, not actually checked by Cs2

StartPosition = stream.Position

Frame Structure

Position = StartPosition + FrameHeader.OffsetNext
StartPosition = stream.Position
do while FrameHeader.OffsetNext != 0

HG-3 images may have multiple frames of image data, each with their own dimensions and such. Each frame is looked by an ID. These IDs are always printed as a zero-padded 4-digit decimal number (however values larger than 9999 will print with more digits).

Oftentimes, multiple frames are all stored in one image for Menu assets where each frame is a different button or background, etc.

The frame header tells us the ID of the frame, which CatSystem2 looks for, and the offset to the next the next frame in the HG-3 image, if there is a next frame.

Data Type Value Description
uint32 OffsetNext Offset to the next frame
uint32 ID Identifier for the frame used in game
Tag[>] Tags A find-by-offset set of tags for this frame

TagStartPosition = stream.Position

Frame Tag Structure

Position = TagStartPosition + Tag.OffsetNext
TagStartPosition = stream.Position
do while Tag.OffsetNext != 0

Following the Frame Header, is a set of tags specific to the frame. Similar to Frame Header, each tag also has an OffsetNext that points to the next tag until there are no more in the frame. See Tags section for the documented structure of all known tags.

Data Type Value Description
char[8] TagName Name of the data structure following this tag
uint32 OffsetNext Offset to the next tag, 0 if no more tags in this frame
uint32 Length Length of this tag's data structure
byte[Tag.Length] TagData Tag-specific data

Tags

These are all the known tag types that can appear in a frame, some tags have a required order before or after other tags. These tags are only considered part of the current frame. Each tag type has a different way of reading the data. See below for a list of known tags and their structure.

Tag "stdinfo"

stdinfo contains basic information about the frame, such as dimensions, bit depth, offset, etc. This tag must always be the first tag in a frame (confirmed in assembly).

Data Type Value Description
uint32 Width Condensed width of the image (without transparency)
uint32 Height Condensed height of the image (without transparency)
uint32 BitDepth Number of bits per pixel, 24 or 32
int32 OffsetX Horizontal offset of the image from the left
int32 OffsetY Vertical offset of the image from the top
uint32 TotalWidth Total width of the image with OffsetX applied
uint32 TotalHeight Total height of the image with OffsetY applied
bool32 IsTransparent True if transparency is used in the image
int32 BaseX Horizontal center of the image, used for drawing in-game
int32 BaseY Vertical center of the image, used for drawing in-game

Tag "img####"

Where #### is replaced with a four digit number, padded with zeros.
A number other than 0000 has yet to be encountered, and it is unknown what this number is used for.
The binaries for reading HG-3 images don't hardcode the tag as img0000 so it must have some sort of use.

Specifies a standard image type that both HG-2 and HG-3 images use.

Data Type Value Description
uint32 Reserved Seems to always be zero
Possibly related to next img#### tag
uint32 Height Height of the image, same as Stdinfo.Height
uint32 CompressedDataLength Compressed length of unrle copy data
uint32 DecompressedDataLength Decompressed length of unrle copy data
uint32 CompressedCmdLength Compressed length of unrle copy cmd bits
uint32 DecompressedCmdLength Decompressed length of unrle copy cmd bits
byte[CompressedDataLength] UnrleData Compressed unrle copy data
byte[CompressedCmdLength] UnrleCmd Compressed unrle copy cmd bits

See HG‐X ProcessImage for how standard HG-2 and HG-3 image data is made readable.

Tag "img_jpg"

Specifies JPEG compressed image file data, that can optionally be combined with Tag "img_al".

Unlike other tag structures, this structure requires the Tag.Length field.

Data Type Value Description
byte[Tag.Length] JpegData Raw JPEG file data

When combined with Tag img_al, all alpha bytes for the JPEG image overwritten by Tag img_al's alpha bytes.

Tag "img_al"

Specifies image alpha data that is to be added to Tag "img_jpg".
This tag is only looked for after reading an img_jpg tag.

Unlike the output of Tag img#### + HG‐X ProcessImage, there is no padding for the stride of the alpha bytes.

Data Type Value Description
uint32 CompressedLength Compressed length of AlphaData bytes
uint32 DecompressedLength Decompressed length of AlphaData bytes
byte[CompressedLength] AlphaData Zlib compressed alpha bytes, one byte per pixel

Tag "img_wbp"

Specifies WEBP image file data.

Unlike other tag structures, this structure requires the Tag.Length field.

Data Type Value Description
byte[Tag.Length] WebPData Raw WEBP file data

Tag "ats####"

Where #### is replaced with a four digit number, padded with zeros.
The #### represents the ID of the attribute which is used to reference it in-game.

Specifies an Attribute, which is a set of coordinates, size, and color for drawing sprites on top of other sprites, such as the 💢 (anger) manpu.

Data Type Value Description
int32 X X coordinate of the attribute relative to the left of the current frame
int32 Y Y coordinate of the attribute relative to the top of the current frame
uint32 Width Width to draw the image with
uint32 Height Height to draw the image with
uint32 Color Color to draw the image with, Format: #AARRGGBB

Tag "cptype"

It is unknown what this tag specifies, but it is always present at the end of every frame's list of tags.

Data Type Value Description
uint32 Type Unknown, very rarely non-zero
Other known value is 3, found in CG menu images

Tag "imgmode"

It is unknown what this tag specifies. This tag is very uncommon, and may only be present in newer commercial versions of the CatSystem2 engine.

Data Type Value Description
bool32 Mode Common in newer games, present on CG.
Value is always 0 when present, defaults to 1
Clone this wiki locally