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([[10],{"/UnV":function(t,i,e){"use strict";e.d(i,"a",(function(){return h}));var s=e("rwco"),r=e("BAAx"),n=e("5cb6");const o=s.a.get("core/data_formats/parsing/afs"),a=5457473;function h(t){const i=Object(r.b)(o);if(t.bytes_left<8)return i.add_problem(n.b.Error,"AFS archive is corrupted.","Too small to be an AFS archive.").failure();if(t.u32()!==a)return i.add_problem(n.b.Error,"AFS archive is corrupted.","Magic bytes not present.").failure();const e=t.u16();t.seek(2);const s=[];for(let r=1;r<=e;r++){if(t.bytes_left<8){i.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 e=t.u32(),o=t.u32();if(e>t.size)i.add_problem(n.b.Warning,`AFS file entry ${r} is invalid.`,`Invalid file offset ${e} for entry ${r}.`);else if(e+o>t.size)i.add_problem(n.b.Warning,`AFS file entry ${r} is invalid.`,`File size ${o} (offset: ${e}) of entry ${r} too large.`);else{const i=t.position;t.seek_start(e),s.push(t.array_buffer(o)),t.seek_start(i)}}return i.success(s)}},"/Wax":function(t,i,e){"use strict";e.d(i,"a",(function(){return r}));var s=e("9dYx");class r extends s.a{constructor(t,i,e=0,s=t.size-e){if(e<0||e>t.size)throw new Error(`Offset ${e} is out of bounds.`);if(s<0||e+s>t.size)throw new Error(`Size ${s} is out of bounds.`);super(i,e),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 i=this.offset+this.position,e=new r(this.buffer,this.endianness,i,t);return this._position+=t,e}ensure_size(t,i=this.position){const e=i+t-this._size;e>0&&(this._size+=e,this.buffer.size<this.offset+this._size&&(this.buffer.size=this.offset+this._size))}}},"9dYx":function(t,i,e){"use strict";var s=e("bcBH");class r{constructor(t,i){this._position=0,this.endianness=t,this.offset=i}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 i=[];for(let e=0;e<t;++e)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 e=0;e<t;++e)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 e=0;e<t;++e)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 e=0;e<t;++e)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,e){const s=[];for(let r=0;r<t;r++){const n=this.u8();if(i&&0===n){e&&this.seek(t-r-1);break}s.push(n)}return String.fromCodePoint(...s)}string_utf16(t,i,e){const s=[],r=Math.floor(t/2);for(let t=0;t<r;t++){const n=this.u16();if(i&&0===n){e&&this.seek(2*(r-t-1));break}s.push(n)}return String.fromCodePoint(...s)}string_ascii_at(t,i,e){const s=[];for(let r=0;r<i;r++){const i=this.u8_at(t+r);if(e&&0===i)break;s.push(i)}return String.fromCodePoint(...s)}string_utf16_at(t,i,e){const s=[],r=Math.floor(i/2);for(let i=0;i<r;i++){const r=this.u16_at(t+2*i);if(e&&0===r)break;s.push(r)}return String.fromCodePoint(...s)}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,e){if(e<0||e>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.`)}}e.d(i,"a",(function(){return n}));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 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 e=i.length;for(let s=0;s<e;s++)this.write_u16_at(t+2*s,i[s]);return this}write_u32_array_at(t,i){this.ensure_size(4*i.length,t);const e=i.length;for(let s=0;s<e;s++)this.write_u32_at(t+4*s,i[s]);return this}write_i32_array_at(t,i){this.ensure_size(4*i.length,t);const e=i.length;for(let s=0;s<e;s++)this.write_i32_at(t+4*s,i[s]);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,e){this.ensure_size(e,t);const s=Math.min(e,i.length);for(let e=0;e<s;e++)this.write_u8_at(t+e,i.codePointAt(e));const r=e-s;for(let i=0;i<r;i++)this.write_u8_at(t+s+i,0);return this}write_string_utf16_at(t,i,e){this.ensure_size(e,t);const s=Math.floor(e/2),r=Math.min(s,i.length);for(let e=0;e<r;e++)this.write_u16_at(t+2*e,i.codePointAt(e));const n=s-r;for(let i=0;i<n;i++)this.write_u16_at(t+2*r+2*i,0);return this}ensure_size(t,i=this.position){const e=this.size-i;if(t>e)throw new Error(`${t} Bytes required but only ${e} available.`)}}},Ea9h:function(t,i,e){"use strict";e.r(i),e.d(i,"ModelToolBarController",(function(){return g}));var s=e("mKaR"),r=e("iPoI"),n=e("NRxM"),o=e("bcBH"),a=e("kwt4"),h=e("VwSi"),_=e("yub1"),u=e("/UnV"),f=e("rwco"),c=e("IMNf"),l=e("BAAx"),d=e("5cb6"),b=e("ouMO"),p=function(t,i,e,s){return new(e||(e=Promise))((function(r,n){function o(t){try{h(s.next(t))}catch(t){n(t)}}function a(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,a)}h((s=s.apply(t,i||[])).next())}))};const w=f.a.get("viewer/controllers/model/ModelToolBarController");class g extends s.a{constructor(t){super(),this.store=t,this._result_dialog_visible=Object(b.e)(!1),this._result=Object(b.e)(void 0),this._result_problems_message=Object(b.e)(""),this._result_error_message=Object(b.e)(""),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.set_show_skeleton=t=>{this.store.set_show_skeleton(t)},this.set_animation_playing=t=>{this.store.set_animation_playing(t)},this.set_animation_frame_rate=t=>{this.store.set_animation_frame_rate(t)},this.set_animation_frame=t=>{this.store.set_animation_frame(t)},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 i=yield Object(r.b)(t),e=new n.a(i,o.a.Little);if(t.name.endsWith(".nj")){const t=Object(a.c)(e);this.set_result(t),t.success&&this.store.set_current_nj_object(t.value[0])}else if(t.name.endsWith(".xj")){const t=Object(a.d)(e);this.set_result(t),t.success&&this.store.set_current_nj_object(t.value[0])}else if(t.name.endsWith(".njm")){this.store.set_current_animation(void 0),this.store.set_current_nj_motion(void 0);const t=this.store.current_nj_object.val;t?(this.set_animation_playing(!0),this.store.set_current_nj_motion(Object(h.c)(e,t.bone_count())),this.set_result(Object(l.c)(void 0))):this.set_result(Object(l.a)([{severity:d.b.Error,ui_message:"No model to animate"}]))}else if(t.name.endsWith(".xvm")){const t=Object(_.b)(e);this.set_result(t),t.success?this.store.set_current_textures(t.value.textures):this.store.set_current_textures([])}else if(t.name.endsWith(".afs")){const t=Object(l.b)(w),i=Object(u.a)(e);if(t.add_result(i),i.success){const e=i.value.flatMap(i=>{var e,s,r,a;const h=new n.a(i,o.a.Little);if(Object(_.a)(h)){const i=Object(_.b)(h);return t.add_result(i),null!=(s=null===(e=i.value)||void 0===e?void 0:e.textures)?s:[]}{const i=Object(_.b)(Object(c.a)(h.seek_start(0)));return t.add_result(i),null!=(a=null===(r=i.value)||void 0===r?void 0:r.textures)?a:[]}});e.length?this.set_result(t.success(e)):this.set_result(t.failure()),this.store.set_current_textures(e)}else this.set_result(t.failure())}else w.debug(`Unsupported file extension in filename "${t.name}".`),this.set_result(Object(l.a)([{severity:d.b.Error,ui_message:"Unsupported file type."}]))}catch(t){w.error("Couldn't read file.",t),this.set_result(Object(l.a)())}})),this.dismiss_result_dialog=()=>{this._result_dialog_visible.val=!1},this.show_skeleton=t.show_skeleton,this.animation_frame_count=t.animation_frame_count,this.animation_frame_count_label=t.animation_frame_count.map(t=>`/ ${t}`),this.animation_controls_enabled=t.current_nj_motion.map(t=>null!=t),this.animation_playing=t.animation_playing,this.animation_frame_rate=t.animation_frame_rate,this.animation_frame=t.animation_frame.map(t=>Math.round(t))}set_result(t){this._result.val=t,t.problems.length&&(this._result_dialog_visible.val=!0)}}},IMNf:function(t,i,e){"use strict";e.d(i,"a",(function(){return o}));var s=e("/Wax"),r=e("tjEv");const n=e("rwco").a.get("core/data_formats/compression/prs/decompress");function o(t){const i=new a(t);for(;;)if(1===i.read_flag_bit())i.copy_u8();else{let t,e;if(0===i.read_flag_bit())t=i.read_flag_bit()<<1,t|=i.read_flag_bit(),t+=2,e=i.read_u8()-256;else{if(e=i.read_u16(),0===e)break;t=7&e,e>>>=3,0===t?(t=i.read_u8(),t+=1):t+=2,e-=8192}i.offset_copy(e,t)}return i.dst.seek_start(0)}class a{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,i){(t<-8192||t>0)&&n.error(`offset was ${t}, should be between -8192 and 0.`),(i<1||i>256)&&n.error(`length was ${i}, should be between 1 and 256.`);const e=Math.min(-t,i);this.dst.seek(t);const s=this.dst.take(e);this.dst.seek(-t-e);for(let t=0;t<Math.floor(i/e);++t)this.dst.write_cursor(s),s.seek_start(0);this.dst.write_cursor(s.take(i%e))}}},NRxM:function(t,i,e){"use strict";e.d(i,"a",(function(){return r}));var s=e("9dYx");class r extends s.a{constructor(t,i,e=0,s=t.byteLength-e){super(i,e),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 i=this.offset+this.position,e=new r(this.backing_buffer,this.endianness,i,t);return this._position+=t,e}}},bcBH:function(t,i,e){"use strict";var s;e.d(i,"a",(function(){return s})),function(t){t[t.Little=0]="Little",t[t.Big=1]="Big"}(s||(s={}))},iPoI:function(t,i,e){"use strict";e.d(i,"a",(function(){return r})),e.d(i,"b",(function(){return n}));var s=e("FXpb");function r(t){return new Promise(i=>{var e,r,n,o;const a=Object(s.m)({type:"file"});a.accept=null!=(r=null===(e=t)||void 0===e?void 0:e.accept)?r:"",a.multiple=null!=(o=null===(n=t)||void 0===n?void 0:n.multiple)&&o,a.onchange=()=>{a.files&&a.files.length?i([...a.files]):i([])},a.click()})}function n(t){return new Promise((i,e)=>{const s=new FileReader;s.addEventListener("loadend",()=>{s.result instanceof ArrayBuffer?i(s.result):e(new Error("Couldn't read file."))}),s.readAsArrayBuffer(t)})}},tjEv:function(t,i,e){"use strict";e.d(i,"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,i){return new DataView(this._buffer,t,i)}ensure_capacity(t){if(t>this.capacity){let i=this.capacity||t;do{i*=2}while(i<t);const e=new ArrayBuffer(i);new Uint8Array(e).set(new Uint8Array(this._buffer,0,this.size)),this._buffer=e,this._data_view=new DataView(this._buffer)}}}},yub1:function(t,i,e){"use strict";e.d(i,"a",(function(){return u})),e.d(i,"b",(function(){return f}));var s=e("9Ykw"),r=e("rwco"),n=e("BAAx"),o=e("5cb6");const a=r.a.get("core/data_formats/parsing/ninja/texture"),h=1213027928,_=1414682200;function u(t){const i=Object(s.b)(t,!0);return t.seek_start(0),i.success&&null!=i.value.find(t=>t.type===h||t.type===_)}function f(t){const i=Object(s.a)(t);if(!i.success)return i;const e=Object(n.b)(a);e.add_result(i);const r=i.value,u=r.find(t=>t.type===h),f=u&&function(t){return{texture_count:t.u16()}}(u.data),c=r.filter(t=>t.type===_).map(t=>(function(t){const i=t.u32(),e=t.u32(),s=t.u32(),r=t.u16(),n=t.u16(),o=t.u32();return t.seek(36),{id:s,format:[i,e],width:r,height:n,size:o,data:t.array_buffer(o)}})(t.data));return f||0!==c.length?(f&&f.texture_count!==c.length&&e.add_problem(o.b.Warning,"Corrupted XVM file.",`Found ${c.length} textures instead of ${f.texture_count} as defined in the header.`),e.success({textures:c})):(e.add_problem(o.b.Error,"Corrupted XVM file.","No header and no XVRT chunks found."),e.failure())}}}]); |