// // nkm.js //-------------------- // Loads nkm files and provides a variety of functions for accessing and using the data. // // nkm files usually drive the game logic of tracks (checkpoints, ai waypoints, objects on track) so it's pretty // crucial to have this up and running. // // by RHY3756547 // // includes: gl-matrix.js (glMatrix 2.0) // window.nkm = function(input, mkwii) { //todo, support versions for other games (MKWii etc) this.load = load; var thisObj = this; var handlers = []; window.onmousemove = function(evt) { mouseX = evt.pageX; mouseY = evt.pageY; } this.scopeEval = function(code) {return eval(code)} //for debug purposes function load(buffer, mkwii) { var view = new DataView(buffer); thisObj.stamp = readChar(view, 0x0)+readChar(view, 0x1)+readChar(view, 0x2)+readChar(view, 0x3); thisObj.version = view.getUint16(0x4, true); var n = view.getUint16(0x6, true); var off = 8; var sections = {}; for (var i=0; i<(n-8)/4; i++) { var soff = view.getUint32(off, true); var section = readSection(view, soff+n) sections[section.type] = section; off += 4; } thisObj.sections = sections; } function readSection(view, off) { var obj = {}; obj.type = readChar(view, off+0x0)+readChar(view, off+0x1)+readChar(view, off+0x2)+readChar(view, off+0x3); if (obj.type == "STAG") { handlers["STAG"](view, off, obj); } else { var handler = handlers[obj.type]; if (handler == null) { console.error("Unknown NKM section type "+obj.type+"!"); return obj; } var entN = view.getUint32(off+0x4, true); off += 0x8; var entries = []; for (var i=0; i>5)&31, (dat>>10)&31]; return col; } function readChar(view, offset) { return String.fromCharCode(view.getUint8(offset)); } if (input != null) { if (typeof input == "string") { var xml = new XMLHttpRequest(); xml.responseType = "arraybuffer"; xml.open("GET", input, true); xml.onload = function() { load(xml.response); } xml.send(); } else { load(input, mkwii); } } }