mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-05 07:18:29 +08:00
1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{455:function(t,e,i){"use strict";function s(t,e){return{success:!0,value:t,problems:null!=e?e:[]}}function r(t){return{success:!1,problems:null!=t?t:[]}}function n(t){if(t.success)return t.value;throw new Error(t.problems.join("\n"))}function o(t){return new u(t)}i.d(e,"c",(function(){return s})),i.d(e,"a",(function(){return r})),i.d(e,"d",(function(){return n})),i.d(e,"b",(function(){return o}));class u{constructor(t){this.logger=t,this.problems=[]}add_problem(t,e,i,s){return this.logger.log(t,i,s),this.problems.push({severity:t,ui_message:e}),this}add_result(t){return this.problems.push(...t.problems),this}success(t){return s(t,this.problems)}failure(){return r(this.problems)}}},459:function(t,e,i){"use strict";var s;i.d(e,"a",(function(){return s})),function(t){t[t.Little=0]="Little",t[t.Big=1]="Big"}(s||(s={}))},468:function(t,e,i){"use strict";i.d(e,"a",(function(){return r}));var s=i(488);class r extends s.a{constructor(t,e,i=0,s=t.byteLength-i){super(e,i),this._size=s,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 e=this.offset+this.position,i=new r(this.backing_buffer,this.endianness,e,t);return this._position+=t,i}}},482:function(t,e,i){"use strict";i.d(e,"a",(function(){return u})),i.d(e,"b",(function(){return h}));var s=i(455),r=i(23),n=i(27);const o=r.a.get("core/data_formats/parsing/iff");function u(t,e=!1){return a(t,e,[],(t,e,i)=>({type:e,data:t.take(i)}))}function h(t,e=!1){return a(t,e,[],(t,e,i)=>({type:e,size:i}))}function a(t,e,i,r){const u=Object(s.b)(o);let h=!1;for(;t.bytes_left>=8;){const s=t.u32(),o=t.position,a=t.u32();if(a>t.bytes_left){h=!0,e||u.add_problem(0===i.length?n.b.Error:n.b.Warning,"Invalid IFF format.",`Size ${a} was too large (only ${t.bytes_left} bytes left) at position ${o}.`);break}i.push(r(t,s,a))}return h&&0===i.length?u.failure():u.success(i)}},483:function(t,e,i){"use strict";i.d(e,"a",(function(){return r})),i.d(e,"b",(function(){return n}));var s=i(2);function r(t){return new Promise(e=>{var i,r;const n=Object(s.m)({type:"file"});n.accept=null!==(i=null==t?void 0:t.accept)&&void 0!==i?i:"",n.multiple=null!==(r=null==t?void 0:t.multiple)&&void 0!==r&&r,n.onchange=()=>{n.files&&n.files.length?e([...n.files]):e([])},n.click()})}function n(t){return new Promise((e,i)=>{const s=new FileReader;s.addEventListener("loadend",()=>{s.result instanceof ArrayBuffer?e(s.result):i(new Error("Couldn't read file."))}),s.readAsArrayBuffer(t)})}},484:function(t,e,i){"use strict";i.d(e,"a",(function(){return r}));var s=i(488);class r extends s.a{constructor(t,e,i=0,s=t.size-i){if(i<0||i>t.size)throw new Error(`Offset ${i} is out of bounds.`);if(s<0||i+s>t.size)throw new Error(`Size ${s} is out of bounds.`);super(e,i),this.buffer=t,this._size=s}get size(){return this._size}set size(t){t>this._size?this.ensure_size(t-this.position):this._size=t}get backing_buffer(){return this.buffer.backing_buffer}get dv(){return this.buffer.view}take(t){this.check_size("size",t,t);const e=this.offset+this.position,i=new r(this.buffer,this.endianness,e,t);return this._position+=t,i}ensure_size(t,e=this.position){const i=e+t-this._size;i>0&&(this._size+=i,this.buffer.size<this.offset+this._size&&(this.buffer.size=this.offset+this._size))}}},488:function(t,e,i){"use strict";i.d(e,"a",(function(){return n}));var s=i(459);class r{constructor(t,e){this._position=0,this.endianness=t,this.offset=e}get position(){return this._position}get endianness(){return this.little_endian?s.a.Little:s.a.Big}set endianness(t){this.little_endian=t===s.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 e=[];for(let i=0;i<t;++i)e.push(this.dv.getUint8(this.offset+this._position++));return e}u16_array(t){this.check_size("n",t,2*t);const e=[];for(let i=0;i<t;++i)e.push(this.dv.getUint16(this.offset+this.position,this.little_endian)),this._position+=2;return e}u32_array(t){this.check_size("n",t,4*t);const e=[];for(let i=0;i<t;++i)e.push(this.dv.getUint32(this.offset+this.position,this.little_endian)),this._position+=4;return e}i32_array(t){this.check_size("n",t,4*t);const e=[];for(let i=0;i<t;++i)e.push(this.dv.getInt32(this.offset+this.position,this.little_endian)),this._position+=4;return e}vec2_f32(){return{x:this.f32(),y:this.f32()}}vec3_f32(){return{x:this.f32(),y:this.f32(),z:this.f32()}}string_ascii(t,e,i){const s=[];for(let r=0;r<t;r++){const n=this.u8();if(e&&0===n){i&&this.seek(t-r-1);break}s.push(n)}return String.fromCodePoint(...s)}string_utf16(t,e,i){const s=[],r=Math.floor(t/2);for(let t=0;t<r;t++){const n=this.u16();if(e&&0===n){i&&this.seek(2*(r-t-1));break}s.push(n)}return String.fromCodePoint(...s)}string_ascii_at(t,e,i){const s=[];for(let r=0;r<e;r++){const e=this.u8_at(t+r);if(i&&0===e)break;s.push(e)}return String.fromCodePoint(...s)}string_utf16_at(t,e,i){const s=[],r=Math.floor(e/2);for(let e=0;e<r;e++){const r=this.u16_at(t+2*e);if(i&&0===r)break;s.push(r)}return String.fromCodePoint(...s)}array_buffer(t=this.size-this.position){this.check_size("size",t,t);const e=this.backing_buffer.slice(this.offset+this.position,this.offset+this.position+t);return this._position+=t,e}copy_to_uint8_array(t,e=this.size-this.position){return this.check_size("size",e,e),t.set(new Uint8Array(this.backing_buffer,this.offset+this.position,e)),this._position+=e,this}check_size(t,e,i){if(i<0||i>this.size-this.position)throw new Error(`${t} ${e} is out of bounds.`)}check_offset(t,e){if(t<0||t+e>this.size)throw new Error(`Offset ${t} is out of bounds.`)}}class n extends r{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 e=t.size-t.position;return this.ensure_size(e),t.copy_to_uint8_array(new Uint8Array(this.backing_buffer,this.offset+this.position,e),e),this._position+=e,this}write_string_ascii(t,e){return this.write_string_ascii_at(this.position,t,e),this._position+=e,this}write_string_utf16(t,e){return this.write_string_utf16_at(this.position,t,e),this._position+=e,this}write_u8_at(t,e){return this.ensure_size(1,t),this.dv.setUint8(t,e),this}write_u16_at(t,e){return this.ensure_size(2,t),this.dv.setUint16(t,e,this.little_endian),this}write_u32_at(t,e){return this.ensure_size(4,t),this.dv.setUint32(t,e,this.little_endian),this}write_i8_at(t,e){return this.ensure_size(1,t),this.dv.setInt8(t,e),this}write_i16_at(t,e){return this.ensure_size(2,t),this.dv.setInt16(t,e,this.little_endian),this}write_i32_at(t,e){return this.ensure_size(4,t),this.dv.setInt32(t,e,this.little_endian),this}write_f32_at(t,e){return this.ensure_size(4,t),this.dv.setFloat32(t,e,this.little_endian),this}write_u8_array_at(t,e){return this.ensure_size(e.length,t),new Uint8Array(this.backing_buffer,this.offset+t).set(new Uint8Array(e)),this}write_u16_array_at(t,e){this.ensure_size(2*e.length,t);const i=e.length;for(let s=0;s<i;s++)this.write_u16_at(t+2*s,e[s]);return this}write_u32_array_at(t,e){this.ensure_size(4*e.length,t);const i=e.length;for(let s=0;s<i;s++)this.write_u32_at(t+4*s,e[s]);return this}write_i32_array_at(t,e){this.ensure_size(4*e.length,t);const i=e.length;for(let s=0;s<i;s++)this.write_i32_at(t+4*s,e[s]);return this}write_vec2_f32_at(t,e){return this.ensure_size(8,t),this.dv.setFloat32(t,e.x,this.little_endian),this.dv.setFloat32(t+4,e.y,this.little_endian),this}write_vec3_f32_at(t,e){return this.ensure_size(12,t),this.dv.setFloat32(t,e.x,this.little_endian),this.dv.setFloat32(t+4,e.y,this.little_endian),this.dv.setFloat32(t+8,e.z,this.little_endian),this}write_string_ascii_at(t,e,i){this.ensure_size(i,t);const s=Math.min(i,e.length);for(let i=0;i<s;i++)this.write_u8_at(t+i,e.codePointAt(i));const r=i-s;for(let e=0;e<r;e++)this.write_u8_at(t+s+e,0);return this}write_string_utf16_at(t,e,i){this.ensure_size(i,t);const s=Math.floor(i/2),r=Math.min(s,e.length);for(let i=0;i<r;i++)this.write_u16_at(t+2*i,e.codePointAt(i));const n=s-r;for(let e=0;e<n;e++)this.write_u16_at(t+2*r+2*e,0);return this}ensure_size(t,e=this.position){const i=this.size-e;if(t>i)throw new Error(`${t} Bytes required but only ${i} available.`)}}},497:function(t,e,i){"use strict";i.d(e,"a",(function(){return s}));class s{constructor(t=8192){this._size=0,this._buffer=new ArrayBuffer(t),this._data_view=new DataView(this._buffer)}get size(){return this._size}set size(t){if(t<0)throw new Error("Size should be non-negative.");this.ensure_capacity(t),this._size=t}get capacity(){return this._buffer.byteLength}get backing_buffer(){return this._buffer}get view(){return this._data_view}sub_view(t,e){return new DataView(this._buffer,t,e)}ensure_capacity(t){if(t>this.capacity){let e=this.capacity||t;do{e*=2}while(e<t);const i=new ArrayBuffer(e);new Uint8Array(i).set(new Uint8Array(this._buffer,0,this.size)),this._buffer=i,this._data_view=new DataView(this._buffer)}}}},518:function(t,e,i){"use strict";i.d(e,"a",(function(){return _})),i.d(e,"b",(function(){return f}));var s=i(482),r=i(23),n=i(455),o=i(27);const u=r.a.get("core/data_formats/parsing/ninja/texture"),h=1213027928,a=1414682200;function _(t){const e=Object(s.b)(t,!0);return t.seek_start(0),e.success&&null!=e.value.find(t=>t.type===h||t.type===a)}function f(t){const e=Object(s.a)(t);if(!e.success)return e;const i=Object(n.b)(u);i.add_result(e);const r=e.value,_=r.find(t=>t.type===h),f=_&&function(t){return{texture_count:t.u16()}}(_.data),l=r.filter(t=>t.type===a).map(t=>(function(t){const e=t.u32(),i=t.u32(),s=t.u32(),r=t.u16(),n=t.u16(),o=t.u32();return t.seek(36),{id:s,format:[e,i],width:r,height:n,size:o,data:t.array_buffer(o)}})(t.data));return f||0!==l.length?(f&&f.texture_count!==l.length&&i.add_problem(o.b.Warning,"Corrupted XVM file.",`Found ${l.length} textures instead of ${f.texture_count} as defined in the header.`),i.success({textures:l})):(i.add_problem(o.b.Error,"Corrupted XVM file.","No header and no XVRT chunks found."),i.failure())}},549:function(t,e,i){"use strict";i.d(e,"a",(function(){return o}));var s=i(484),r=i(497);const n=i(23).a.get("core/data_formats/compression/prs/decompress");function o(t){const e=new u(t);for(;;)if(1===e.read_flag_bit())e.copy_u8();else{let t,i;if(0===e.read_flag_bit())t=e.read_flag_bit()<<1,t|=e.read_flag_bit(),t+=2,i=e.read_u8()-256;else{if(i=e.read_u16(),0===i)break;t=7&i,i>>>=3,0===t?(t=e.read_u8(),t+=1):t+=2,i-=8192}e.offset_copy(i,t)}return e.dst.seek_start(0)}class u{constructor(t){this.src=t,this.dst=new s.a(new r.a(Math.floor(1.5*t.size)),t.endianness),this.flags=0,this.flag_bits_left=0}read_flag_bit(){0===this.flag_bits_left&&(this.flags=this.read_u8(),this.flag_bits_left=8);const t=1&this.flags;return this.flags>>>=1,this.flag_bits_left-=1,t}copy_u8(){this.dst.write_u8(this.read_u8())}read_u8(){return this.src.u8()}read_u16(){return this.src.u16()}offset_copy(t,e){(t<-8192||t>0)&&n.error(`offset was ${t}, should be between -8192 and 0.`),(e<1||e>256)&&n.error(`length was ${e}, should be between 1 and 256.`);const i=Math.min(-t,e);this.dst.seek(t);const s=this.dst.take(i);this.dst.seek(-t-i);for(let t=0;t<Math.floor(e/i);++t)this.dst.write_cursor(s),s.seek_start(0);this.dst.write_cursor(s.take(e%i))}}},551:function(t,e,i){"use strict";i.d(e,"a",(function(){return h}));var s=i(23),r=i(455),n=i(27);const o=s.a.get("core/data_formats/parsing/afs"),u=5457473;function h(t){const e=Object(r.b)(o);if(t.bytes_left<8)return e.add_problem(n.b.Error,"AFS archive is corrupted.","Too small to be an AFS archive.").failure();if(t.u32()!==u)return e.add_problem(n.b.Error,"AFS archive is corrupted.","Magic bytes not present.").failure();const i=t.u16();t.seek(2);const s=[];for(let r=1;r<=i;r++){if(t.bytes_left<8){e.add_problem(n.b.Warning,`AFS file entry ${r} is invalid.`,`Couldn't read file entry ${r}, only ${t.bytes_left} bytes left.`);break}const i=t.u32(),o=t.u32();if(i>t.size)e.add_problem(n.b.Warning,`AFS file entry ${r} is invalid.`,`Invalid file offset ${i} for entry ${r}.`);else if(i+o>t.size)e.add_problem(n.b.Warning,`AFS file entry ${r} is invalid.`,`File size ${o} (offset: ${i}) of entry ${r} too large.`);else{const e=t.position;t.seek_start(i),s.push(t.array_buffer(o)),t.seek_start(e)}}return e.success(s)}},838:function(t,e,i){"use strict";i.r(e),i.d(e,"TextureController",(function(){return g}));var s=i(141),r=i(40),n=i(483),o=i(518),u=i(468),h=i(459),a=i(551),_=i(23),f=i(14),l=i(549),c=i(455),d=i(27),p=function(t,e,i,s){return new(i||(i=Promise))((function(r,n){function o(t){try{h(s.next(t))}catch(t){n(t)}}function u(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,u)}h((s=s.apply(t,e||[])).next())}))};const b=_.a.get("viewer/controllers/TextureController");class g extends s.a{constructor(){super(...arguments),this._textures=Object(f.c)(),this._result_dialog_visible=Object(f.e)(!1),this._result=Object(f.e)(void 0),this._result_problems_message=Object(f.e)(""),this._result_error_message=Object(f.e)(""),this.textures=this._textures,this.result_dialog_visible=this._result_dialog_visible,this.result=this._result,this.result_problems_message=this._result_problems_message,this.result_error_message=this._result_error_message,this.load_file=t=>p(this,void 0,void 0,(function*(){this._result_problems_message.val=`Encountered some problems while opening "${t.name}".`,this._result_error_message.val=`Couldn't open "${t.name}".`;try{const e=Object(r.g)(t.name).toLowerCase(),i=yield Object(n.b)(t),s=new u.a(i,h.a.Little);if("xvm"===e){const t=Object(o.b)(s);this.set_result(t),t.success&&(this._textures.val=t.value.textures)}else if("afs"===e){const t=Object(c.b)(b),e=Object(a.a)(s);if(t.add_result(e),e.success){const i=e.value.flatMap(e=>{var i,s,r,n;const a=new u.a(e,h.a.Little);if(Object(o.a)(a)){const e=Object(o.b)(a);return t.add_result(e),null!==(s=null===(i=e.value)||void 0===i?void 0:i.textures)&&void 0!==s?s:[]}{const e=Object(o.b)(Object(l.a)(a.seek_start(0)));return t.add_result(e),null!==(n=null===(r=e.value)||void 0===r?void 0:r.textures)&&void 0!==n?n:[]}});i.length?this.set_result(t.success(i)):this.set_result(t.failure()),this._textures.val=i}else this.set_result(t.failure())}else b.debug(`Unsupported file extension in filename "${t.name}".`),this.set_result(Object(c.a)([{severity:d.b.Error,ui_message:"Unsupported file type."}]))}catch(t){b.error("Couldn't read file.",t),this.set_result(Object(c.a)())}})),this.dismiss_result_dialog=()=>{this._result_dialog_visible.val=!1}}set_result(t){this._result.val=t,t.problems.length&&(this._result_dialog_visible.val=!0)}}}}]); |