.agg file format of Heroes of Might and Magic: JavaScript parsing library

Application

Heroes of Might and Magic

File extension

agg

This page hosts a formal specification of .agg file format of Heroes of Might and Magic using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

JavaScript source code to parse .agg file format of Heroes of Might and Magic

HeroesOfMightAndMagicAgg.js

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

var HeroesOfMightAndMagicAgg = (function() {
  function HeroesOfMightAndMagicAgg(_io, _parent, _root) {
    this._io = _io;
    this._parent = _parent;
    this._root = _root || this;

    this._read();
  }
  HeroesOfMightAndMagicAgg.prototype._read = function() {
    this.numFiles = this._io.readU2le();
    this.entries = new Array(this.numFiles);
    for (var i = 0; i < this.numFiles; i++) {
      this.entries[i] = new Entry(this._io, this, this._root);
    }
  }

  var Entry = HeroesOfMightAndMagicAgg.Entry = (function() {
    function Entry(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    Entry.prototype._read = function() {
      this.hash = this._io.readU2le();
      this.offset = this._io.readU4le();
      this.size = this._io.readU4le();
      this.size2 = this._io.readU4le();
    }
    Object.defineProperty(Entry.prototype, 'body', {
      get: function() {
        if (this._m_body !== undefined)
          return this._m_body;
        var _pos = this._io.pos;
        this._io.seek(this.offset);
        this._m_body = this._io.readBytes(this.size);
        this._io.seek(_pos);
        return this._m_body;
      }
    });

    return Entry;
  })();

  var Filename = HeroesOfMightAndMagicAgg.Filename = (function() {
    function Filename(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    Filename.prototype._read = function() {
      this.str = KaitaiStream.bytesToStr(this._io.readBytesTerm(0, false, true, true), "ASCII");
    }

    return Filename;
  })();
  Object.defineProperty(HeroesOfMightAndMagicAgg.prototype, 'filenames', {
    get: function() {
      if (this._m_filenames !== undefined)
        return this._m_filenames;
      var _pos = this._io.pos;
      this._io.seek((this.entries[this.entries.length - 1].offset + this.entries[this.entries.length - 1].size));
      this._raw__m_filenames = new Array(this.numFiles);
      this._m_filenames = new Array(this.numFiles);
      for (var i = 0; i < this.numFiles; i++) {
        this._raw__m_filenames[i] = this._io.readBytes(15);
        var _io__raw__m_filenames = new KaitaiStream(this._raw__m_filenames[i]);
        this._m_filenames[i] = new Filename(_io__raw__m_filenames, this, this._root);
      }
      this._io.seek(_pos);
      return this._m_filenames;
    }
  });

  return HeroesOfMightAndMagicAgg;
})();

// Export for amd environments
if (typeof define === 'function' && define.amd) {
  define('HeroesOfMightAndMagicAgg', [], function() {
    return HeroesOfMightAndMagicAgg;
  });
}

// Export for CommonJS
if (typeof module === 'object' && module && module.exports) {
  module.exports = HeroesOfMightAndMagicAgg;
}