CHUI file format
    Applies to:
    BG1, BG1: TotS, BG2, BG2: ToB, PST, IWD, IWD:HoW, IWD:TotL, IWD2
    General Description
    
      This file format describes the layout of the GUI screens (the graphics for the screens are held in MOS and BAM files).
    
    Detailed Description
    
    
    
    | Offset | Size (data type) | Description | 
|---|---|---|
| 0x0000 | 4 (char array) | Signature ('CHUI') | 
| 0x0004 | 4 (char array) | Version ('V1 ') | 
| 0x0008 | 4 (dword) | Count of windows | 
| 0x000c | 4 (dword) | Offset (from start of file) to controls table | 
| 0x0010 | 4 (dword) | Offset (from start of file) to window entries | 
| Offset | Size (data type) | Description | 
|---|---|---|
| 0x0000 | 2 (word) | Window ID | 
| 0x0002 | 2 (unknown) | Unknown | 
| 0x0004 | 2 (word) | X coordinate | 
| 0x0006 | 2 (word) | Y coordinate | 
| 0x0008 | 2 (word) | Width | 
| 0x000a | 2 (word) | Height | 
| 0x000c | 2 (word) | Background flag (0=No background, 1=Background) | 
| 0x000e | 2 (word) | Count of controls in this window | 
| 0x0010 | 8 (resref) | Background file (MOS) | 
| 0x0018 | 2 (word) | Index of first control in this window | 
| 0x001a | 2 (word) | Unknown | 
| Offset | Size (data type) | Description | 
|---|---|---|
| 0x0000 | 4 (dword) | Offset to control structure | 
| 0x0004 | 4 (dword) | Length of control structure | 
Each control has a separate structure describing it however they all have a common structure prepended, which dictates basic control settings (e.g. position, type).
The known control types are:
- Type 0: Buttons/toggle buttons/pixmaps
 - Type 2: Slider Control
 - Type 3: TextEdit field
 - Type 5: TextArea
 - Type 6: Label
 - Type 7: Scrollbar
 
| Offset | Size (data type) | Description | 
|---|---|---|
| 0x0000 | 4 (dword) | Control ID | 
| 0x0004 | 2 (word) | X coordinate (relative to containing window) | 
| 0x0006 | 2 (word) | Y coordinate (relative to containing window) | 
| 0x0008 | 2 (word) | Width | 
| 0x000a | 2 (word) | Height | 
| 0x000c | 1 (byte) | Type | 
| 0x000d | 1 (byte) | Unknown | 
| Offset | Size (data type) | Description | 
|---|---|---|
| 0x0000 | 14 (common section) | Common fields | 
| 0x000e | 8 (resref) | Button image (BAM) | 
| 0x0016 | 1 (byte) | Animation cycle | 
| 0x0017 | 1 (byte) | Button text justification flags:
                
  | 
          
| 0x0018 | 1 (byte) | Frame index from BAM file: Button unpressed | 
| 0x0019 | 1 (byte) | Anchor coordinate X 1 | 
| 0x001a | 1 (byte) | Frame index from BAM file: Button pressed | 
| 0x001b | 1 (byte) | Anchor coordinate X 2 | 
| 0x001c | 1 (byte) | Frame index from BAM file: Button selected | 
| 0x001d | 1 (byte) | Anchor coordinate Y 1 | 
| 0x001e | 1 (byte) | Frame index from BAM file: Button disabled | 
| 0x001f | 1 (byte) | Anchor coordinate Y 2 | 
| Offset | Size (data type) | Description | 
|---|---|---|
| 0x0000 | 14 (common section) | Common fields | 
| 0x000e | 8 (resref) | Slider image background (MOS) | 
| 0x0016 | 8 (resref) | Slider image (knob) (BAM) | 
| 0x001e | 2 (word) | Cycle number | 
| 0x0020 | 2 (word) | Frame index from BAM file: Slider ungrabbed | 
| 0x0022 | 2 (word) | Frame index from BAM file: Slider grabbed | 
| 0x0024 | 2 (word) | Knob X offset | 
| 0x0026 | 2 (word) | Knob Y offset | 
| 0x0028 | 2 (word) | Knob jump width | 
| 0x002a | 2 (word) | Knob jump count | 
| 0x002c | 2 (word) | Unknown | 
| 0x002e | 2 (word) | Unknown | 
| 0x0030 | 2 (word) | Unknown | 
| 0x0032 | 2 (word) | Unknown | 
| Offset | Size (data type) | Description | 
|---|---|---|
| 0x0000 | 14 (common section) | Common fields | 
| 0x000e | 8 (resref) | MOS file (background #1) | 
| 0x0016 | 8 (resref) | MOS file (background #2) | 
| 0x001e | 8 (resref) | MOS file (background #3) | 
| 0x0026 | 8 (resref) | BAM file (cursor) | 
| 0x002e | 2 (word) | Carot animation cycle | 
| 0x0030 | 2 (word) | Carot animation frame | 
| 0x0032 | 2 (word) | X coordinate | 
| 0x0034 | 2 (word) | Y coordinate | 
| 0x0036 | 4 (dword) | Control Id of scrollbar attached to this control (0xFFFFFFFF = none) | 
| 0x003a | 8 (resref) | BAM file (font) | 
| 0x0042 | 2 (word) | Unknown | 
| 0x0044 | 32 (ASCII) | Initial text | 
| 0x0064 | 2 (word) | Maximum input length | 
| 0x0066 | 4 (dword) | Text case
              
  | 
          
| Offset | Size (data type) | Description | 
|---|---|---|
| 0x0000 | 14 (common section) | Common fields | 
| 0x000e | 8 (resref) | BAM file font (initials) | 
| 0x0016 | 8 (resref) | BAM file font (main text) | 
| 0x001e | 4 (RGBA colour) | Colour #1 | 
| 0x0022 | 4 (RGBA colour) | Colour #2 | 
| 0x0026 | 4 (RGBA colour) | Colour #3 | 
| 0x002a | 4 (control ID) | Control ID of scroll bar attached to this control (0xFFFFFFFF = none) | 
| Offset | Size (datatype) | Description | 
|---|---|---|
| 0x0000 | 14 (common section) | Common fields | 
| 0x000e | 4 (strref) | Initial text () | 
| 0x0012 | 8 (resref) | BAM file (font) | 
| 0x001a | 4 (RGBA colour) | Colour #1 | 
| 0x001e | 4 (RGBA colour) | Colour #2 | 
| 0x0022 | 2 (word) | Subtype (justification)
  | 
          
| Offset | Size (datatype) | Description | 
|---|---|---|
| 0x0000 | 14 (common section) | Common fields | 
| 0x000e | 8 (resref) | BAM file | 
| 0x0016 | 2 (word) | Cycle number | 
| 0x0018 | 2 (word) | Frame index from BAM file : up-arrow, unpressed | 
| 0x001a | 2 (word) | Frame index from BAM file : up-arrow, pressed | 
| 0x001c | 2 (word) | Frame index from BAM file : down-arrow, unpressed | 
| 0x001e | 2 (word) | Frame index from BAM file : down-arrow, pressed | 
| 0x0020 | 2 (word) | Frame index from BAM file: trough | 
| 0x0022 | 2 (word) | Frame index from BAM file: slider | 
| 0x0024 | 4 (control ID) | Control ID of text area attached to this control (0xFFFFFFFF = none) |