Skip to content

ZenGin Script Binaries

Quick Infos

Type: Script Format
Format Name: DAT
File Extension: .DAT
Class Name: zCParser
Encoding: Binary

ZenGin DAT files contain symbols and bytecode used by the VM of the engine. DAT files are the result of Daedalus script compilation process.

Format Description

Compiled scripts are stored in a binary file which contains the following data. Also refer to the Datatype Reference for general information about often used datatypes.

DAT Structure
struct DatFile {
    byte version;

    uint symbolCount;
    uint symbolIds[/* symbolCount */]; // (1)
    zCPar_Symbol symbolTable[/* symbolCount */];

    uint bytecodeSize;
    byte bytecode[/* bytecodeSize */]; // (2)
};
  1. Symbol IDs sorted lexicographically
  2. Read bytecode page for more info about this data.

Symbol

struct zCPar_Symbol {
    byte isNamed; // (1) 
    SymbolName name;

    SymbolParameters params;
    SymbolCodeSpan span;
    SymbolData data;
    int parent; // (2)
};
  1. Does this symbol have a name
  2. Parent type, -1 means None

Symbol Name

struct SymbolName {
    string name;
};
struct SymbolName {};

Symbol Parameters

struct SymbolParameters {
    int offset; // (1)
    uint count: 12; // (2)
    zPAR_TYPE type: 4;
    zPAR_FLAG flags: 6;
    uint space: 1;
    uint reserved: 9;
};

enum zPAR_TYPE: uint {
    VOID = 0,
    FLOAT = 1,
    INT = 2,
    STRING = 3,
    CLASS = 4,
    FUNC = 5,
    PROTOTYPE = 6,
    INSTANCE = 7,
};

// Parameter bitflags
enum zPAR_FLAG: uint {
    CONST = 1,
    RETURN = 2,
    CLASSVAR = 4,
    EXTERNAL = 8,
    MERGED = 16
};
  1. Depending on type either Offset (ClassVar), Size (Class) or ReturnType (Func)
  2. How many sub items does this symbol have

Symbol Code Span

This is span debug information, pointing at the source daedalus script

struct SymbolCodeSpan {
    uint fileIndex: 19;
    uint reserved: 13;
    uint lineStart: 19;
    uint reserved: 13;
    uint lineCount: 19;
    uint reserved: 13;
    uint charStart: 24; // (1)
    uint reserved: 8;
    uint charCount: 24; // (2)
    uint reserved: 8;
};
  1. Points to a byte of a source code file at which the span starts
  2. Determines how many bytes does the span starting at charStart has

Symbol Data

This depends on params.flags, if CLASSVAR flag is set this data will always be 0 sized.

It also depends on params.type of the symbol.

struct SymbolData {
    float value[/* params.count */];
};
struct SymbolData {
    int value[/* params.count */];
};
struct SymbolData {
    string value[/* params.count */];
};

Warning

Some mods don't terminate those strings correctly, look at this code and the issue related to it.

struct SymbolData {
    int classOffset;
};
struct SymbolData {
    int address;
};
struct SymbolData {}
struct SymbolData {}