mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-05 07:18:29 +08:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
(window.webpackJsonp=window.webpackJsonp||[]).push([[6],{"/UnV":function(t,i,s){"use strict";s.d(i,"a",(function(){return r}));const e=s("rwco").c.get("core/data_formats/parsing/afs"),n=5457473;function r(t){if(t.u32()!==n)return e.error("Not an AFS archive."),[];const i=t.u16();t.seek(2);const s=[];for(let e=0;e<i;e++){const i=t.u32(),e=t.u32();s.push({offset:i,size:e})}const r=[];for(const{offset:i,size:e}of s)t.seek_start(i),r.push(t.array_buffer(e));return r}},"4/Uj":function(t,i,s){"use strict";s.r(i),s.d(i,"TextureStore",(function(){return d}));var e=s("ouMO"),n=s("yub1"),r=s("Sa3/"),o=s("NRxM"),h=s("bcBH"),u=s("kcKQ"),_=s("rwco"),a=s("wtpc"),f=s("/UnV"),c=function(t,i,s,e){return new(s||(s=Promise))((function(n,r){function o(t){try{u(e.next(t))}catch(t){r(t)}}function h(t){try{u(e.throw(t))}catch(t){r(t)}}function u(t){var i;t.done?n(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(o,h)}u((e=e.apply(t,i||[])).next())}))};const l=_.c.get("viewer/stores/TextureStore");class d extends u.a{constructor(){super(...arguments),this._textures=Object(e.c)(),this.textures=this._textures,this.load_file=t=>c(this,void 0,void 0,(function*(){try{const i=Object(a.f)(t.name).toLowerCase(),s=yield Object(r.a)(t);if("xvm"===i){const t=Object(n.a)(new o.a(s,h.a.Little));this._textures.splice(0,1/0,...t.textures)}else if("afs"===i){const t=Object(f.a)(new o.a(s,h.a.Little)),i=[];for(const s of t){const t=Object(n.a)(new o.a(s,h.a.Little));i.push(...t.textures)}this._textures.val=i}}catch(t){l.error("Couldn't read file.",t)}}))}}},"9Ykw":function(t,i,s){"use strict";function e(t){const i=[];for(;t.bytes_left;){const s=t.u32(),e=t.u32();if(e>t.bytes_left)break;i.push({type:s,data:t.take(e)})}return i}s.d(i,"a",(function(){return e}))},"9dYx":function(t,i,s){"use strict";var e=s("bcBH");class n{constructor(t,i){this._position=0,this.endianness=t,this.offset=i}get position(){return this._position}get endianness(){return this.little_endian?e.a.Little:e.a.Big}set endianness(t){this.little_endian=t===e.a.Little}get bytes_left(){return this.size-this.position}seek(t){return this.seek_start(this.position+t)}seek_start(t){if(t<0||t>this.size)throw new Error(`Offset ${t} is out of bounds.`);return this._position=t,this}seek_end(t){if(t<0||t>this.size)throw new Error(`Offset ${t} is out of bounds.`);return this._position=this.size-t,this}u8(){return this.u8_at(this._position++)}u8_at(t){return this.check_offset(t,1),this.dv.getUint8(this.offset+t)}u16(){const t=this.u16_at(this.position);return this._position+=2,t}u16_at(t){return this.check_offset(t,2),this.dv.getUint16(this.offset+t,this.little_endian)}u32(){const t=this.u32_at(this.position);return this._position+=4,t}u32_at(t){return this.check_offset(t,4),this.dv.getUint32(this.offset+t,this.little_endian)}i8(){return this.i8_at(this._position++)}i8_at(t){return this.check_offset(t,1),this.dv.getInt8(this.offset+t)}i16(){const t=this.i16_at(this.position);return this._position+=2,t}i16_at(t){return this.check_offset(t,2),this.dv.getInt16(this.offset+t,this.little_endian)}i32(){const t=this.i32_at(this.position);return this._position+=4,t}i32_at(t){return this.check_offset(t,4),this.dv.getInt32(this.offset+t,this.little_endian)}f32(){const t=this.f32_at(this.position);return this._position+=4,t}f32_at(t){return this.check_offset(t,4),this.dv.getFloat32(this.offset+t,this.little_endian)}u8_array(t){this.check_size("n",t,t);const i=[];for(let s=0;s<t;++s)i.push(this.dv.getUint8(this.offset+this._position++));return i}u16_array(t){this.check_size("n",t,2*t);const i=[];for(let s=0;s<t;++s)i.push(this.dv.getUint16(this.offset+this.position,this.little_endian)),this._position+=2;return i}u32_array(t){this.check_size("n",t,4*t);const i=[];for(let s=0;s<t;++s)i.push(this.dv.getUint32(this.offset+this.position,this.little_endian)),this._position+=4;return i}i32_array(t){this.check_size("n",t,4*t);const i=[];for(let s=0;s<t;++s)i.push(this.dv.getInt32(this.offset+this.position,this.little_endian)),this._position+=4;return i}vec2_f32(){return{x:this.f32(),y:this.f32()}}vec3_f32(){return{x:this.f32(),y:this.f32(),z:this.f32()}}string_ascii(t,i,s){const e=[];for(let n=0;n<t;n++){const r=this.u8();if(i&&0===r){s&&this.seek(t-n-1);break}e.push(r)}return String.fromCodePoint(...e)}string_utf16(t,i,s){const e=[],n=Math.floor(t/2);for(let t=0;t<n;t++){const r=this.u16();if(i&&0===r){s&&this.seek(2*(n-t-1));break}e.push(r)}return String.fromCodePoint(...e)}string_ascii_at(t,i,s){const e=[];for(let n=0;n<i;n++){const i=this.u8_at(t+n);if(s&&0===i)break;e.push(i)}return String.fromCodePoint(...e)}string_utf16_at(t,i,s){const e=[],n=Math.floor(i/2);for(let i=0;i<n;i++){const n=this.u16_at(t+2*i);if(s&&0===n)break;e.push(n)}return String.fromCodePoint(...e)}array_buffer(t=this.size-this.position){this.check_size("size",t,t);const i=this.backing_buffer.slice(this.offset+this.position,this.offset+this.position+t);return this._position+=t,i}copy_to_uint8_array(t,i=this.size-this.position){return this.check_size("size",i,i),t.set(new Uint8Array(this.backing_buffer,this.offset+this.position,i)),this._position+=i,this}check_size(t,i,s){if(s<0||s>this.size-this.position)throw new Error(`${t} ${i} is out of bounds.`)}check_offset(t,i){if(t<0||t+i>this.size)throw new Error(`Offset ${t} is out of bounds.`)}}s.d(i,"a",(function(){return r}));class r extends n{write_u8(t){return this.write_u8_at(this.position,t),this._position+=1,this}write_u16(t){return this.write_u16_at(this.position,t),this._position+=2,this}write_u32(t){return this.write_u32_at(this.position,t),this._position+=4,this}write_i8(t){return this.write_i8_at(this.position,t),this._position+=1,this}write_i16(t){return this.write_i16_at(this.position,t),this._position+=2,this}write_i32(t){return this.write_i32_at(this.position,t),this._position+=4,this}write_f32(t){return this.write_f32_at(this.position,t),this._position+=4,this}write_u8_array(t){return this.write_u8_array_at(this.position,t),this._position+=t.length,this}write_u16_array(t){return this.write_u16_array_at(this.position,t),this._position+=2*t.length,this}write_u32_array(t){return this.write_u32_array_at(this.position,t),this._position+=4*t.length,this}write_i32_array(t){return this.write_i32_array_at(this.position,t),this._position+=4*t.length,this}write_vec2_f32(t){return this.write_vec2_f32_at(this.position,t),this._position+=8,this}write_vec3_f32(t){return this.write_vec3_f32_at(this.position,t),this._position+=12,this}write_cursor(t){const i=t.size-t.position;return this.ensure_size(i),t.copy_to_uint8_array(new Uint8Array(this.backing_buffer,this.offset+this.position,i),i),this._position+=i,this}write_string_ascii(t,i){return this.write_string_ascii_at(this.position,t,i),this._position+=i,this}write_string_utf16(t,i){return this.write_string_utf16_at(this.position,t,i),this._position+=i,this}write_u8_at(t,i){return this.ensure_size(1,t),this.dv.setUint8(t,i),this}write_u16_at(t,i){return this.ensure_size(2,t),this.dv.setUint16(t,i,this.little_endian),this}write_u32_at(t,i){return this.ensure_size(4,t),this.dv.setUint32(t,i,this.little_endian),this}write_i8_at(t,i){return this.ensure_size(1,t),this.dv.setInt8(t,i),this}write_i16_at(t,i){return this.ensure_size(2,t),this.dv.setInt16(t,i,this.little_endian),this}write_i32_at(t,i){return this.ensure_size(4,t),this.dv.setInt32(t,i,this.little_endian),this}write_f32_at(t,i){return this.ensure_size(4,t),this.dv.setFloat32(t,i,this.little_endian),this}write_u8_array_at(t,i){return this.ensure_size(i.length,t),new Uint8Array(this.backing_buffer,this.offset+t).set(new Uint8Array(i)),this}write_u16_array_at(t,i){this.ensure_size(2*i.length,t);const s=i.length;for(let e=0;e<s;e++)this.write_u16_at(t+2*e,i[e]);return this}write_u32_array_at(t,i){this.ensure_size(4*i.length,t);const s=i.length;for(let e=0;e<s;e++)this.write_u32_at(t+4*e,i[e]);return this}write_i32_array_at(t,i){this.ensure_size(4*i.length,t);const s=i.length;for(let e=0;e<s;e++)this.write_i32_at(t+4*e,i[e]);return this}write_vec2_f32_at(t,i){return this.ensure_size(8,t),this.dv.setFloat32(t,i.x,this.little_endian),this.dv.setFloat32(t+4,i.y,this.little_endian),this}write_vec3_f32_at(t,i){return this.ensure_size(12,t),this.dv.setFloat32(t,i.x,this.little_endian),this.dv.setFloat32(t+4,i.y,this.little_endian),this.dv.setFloat32(t+8,i.z,this.little_endian),this}write_string_ascii_at(t,i,s){this.ensure_size(s,t);const e=Math.min(s,i.length);for(let s=0;s<e;s++)this.write_u8_at(t+s,i.codePointAt(s));const n=s-e;for(let i=0;i<n;i++)this.write_u8_at(t+e+i,0);return this}write_string_utf16_at(t,i,s){this.ensure_size(s,t);const e=Math.floor(s/2),n=Math.min(e,i.length);for(let s=0;s<n;s++)this.write_u16_at(t+2*s,i.codePointAt(s));const r=e-n;for(let i=0;i<r;i++)this.write_u16_at(t+2*n+2*i,0);return this}ensure_size(t,i=this.position){const s=this.size-i;if(t>s)throw new Error(`${t} Bytes required but only ${s} available.`)}}},NRxM:function(t,i,s){"use strict";s.d(i,"a",(function(){return n}));var e=s("9dYx");class n extends e.a{constructor(t,i,s=0,e=t.byteLength-s){super(i,s),this._size=e,this.backing_buffer=t,this.dv=new DataView(t,0,t.byteLength)}get size(){return this._size}set size(t){if(t>this.backing_buffer.byteLength-this.offset)throw new Error(`Size ${t} is out of bounds.`);this._size=t}take(t){const i=this.offset+this.position,s=new n(this.backing_buffer,this.endianness,i,t);return this._position+=t,s}}},"Sa3/":function(t,i,s){"use strict";s.d(i,"a",(function(){return n}));var e=function(t,i,s,e){return new(s||(s=Promise))((function(n,r){function o(t){try{u(e.next(t))}catch(t){r(t)}}function h(t){try{u(e.throw(t))}catch(t){r(t)}}function u(t){var i;t.done?n(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(o,h)}u((e=e.apply(t,i||[])).next())}))};function n(t){return e(this,void 0,void 0,(function*(){return new Promise((i,s)=>{const e=new FileReader;e.addEventListener("loadend",()=>{e.result instanceof ArrayBuffer?i(e.result):s(new Error("Couldn't read file."))}),e.readAsArrayBuffer(t)})}))}},bcBH:function(t,i,s){"use strict";var e;s.d(i,"a",(function(){return e})),function(t){t[t.Little=0]="Little",t[t.Big=1]="Big"}(e||(e={}))},yub1:function(t,i,s){"use strict";s.d(i,"a",(function(){return h}));var e=s("9Ykw");const n=s("rwco").c.get("core/data_formats/parsing/ninja/texture"),r=1213027928,o=1414682200;function h(t){const i=Object(e.a)(t),s=i.find(t=>t.type===r),h=s&&function(t){return{texture_count:t.u16()}}(s.data),u=i.filter(t=>t.type===o).map(t=>(function(t){const i=t.u32(),s=t.u32(),e=t.u32(),n=t.u16(),r=t.u16(),o=t.u32();return t.seek(36),{id:e,format:[i,s],width:n,height:r,size:o,data:t.array_buffer(o)}})(t.data));return h&&h.texture_count!==u.length&&n.warn(`Found ${u.length} textures instead of ${h.texture_count} as defined in the header.`),{textures:u}}}}]); |