// // sdat.js //-------------------- // Reads sdat archives. // Right now this just loads literally every resource in the sdat since in js there is no such thing as half loading a // file from local storage, so why not just load it once and store in a usable format. // // by RHY3756547 // // includes: gl-matrix.js (glMatrix 2.0) // window.sdat = function(input) { var t = this; this.sections = {}; this.load = load; function load(input) { t.buffer = input; var view = new DataView(input); var header = null; var offset = 0; var stamp = readChar(view, 0x0)+readChar(view, 0x1)+readChar(view, 0x2)+readChar(view, 0x3); if (stamp != "SDAT") throw "SDAT invalid. Expected SDAT, found "+stamp; var unknown1 = view.getUint32(0x4, true); var filesize = view.getUint32(0x8, true); var headsize = view.getUint16(0xC, true); var numSections = view.getUint16(0xE, true); var sectionOffsets = []; var sectionSizes = []; for (var i=3; i>-1; i--) { //reverse order so we can process files into js objects var off = (view.getUint32(0x10+i*8, true)); var size = (view.getUint32(0x14+i*8, true)); if (size != 0) readSection(view, off); } } function readSection(view, off) { var stamp = "$"+readChar(view, off)+readChar(view, off+1)+readChar(view, off+2)+readChar(view, off+3); if (sectionFunc[stamp] != null) t.sections[stamp] = sectionFunc[stamp](view, off+8); else console.error("Invalid section in SDAT! No handler for section type "+stamp.substr(1, 4)); } var sectionFunc = {} sectionFunc["$SYMB"] = function(view, off) { } sectionFunc["$INFO"] = function(view, off) { var obj = []; for (var i=0; i<8; i++) { var relOff = off+view.getUint32(off+i*4, true)-8; var count = view.getUint32(relOff, true); obj[i] = []; relOff += 4; var last = null; for (var j=0; j