From 978ab7dee081c189ace4730ed54ab47212cc5e42 Mon Sep 17 00:00:00 2001 From: tyler27 Date: Sun, 7 Jan 2024 20:01:29 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=202004scap?= =?UTF-8?q?e/Client2@2b76cafe16641b3f1b56e07008c0c5da584fc2e2=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- playground.js | 2 +- viewer.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b275d52e..ba55e1fb 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,2 @@ /*! For license information please see index.js.LICENSE.txt */ -(()=>{"use strict";var t={621:(t,e,i)=>{t.exports=i.p+"9f86b5397894e28b5ae2.wasm"}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var a=e[s]={exports:{}};return t[s](a,a.exports,i),a.exports}i.m=t,i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.p="/Client2/",i.b=document.baseURI||self.location.href,(()=>{class t{index;constructor(t){this.index=t}decodeType=t=>{for(;;){const e=t.g1;if(0===e)break;this.decode(e,t)}}}class e{static crctable=new Int32Array(256);static CRC32_POLYNOMIAL=3988292384;static bitmask=new Uint32Array(33);static{for(let t=0;t<32;t++)e.bitmask[t]=(1<>>1^e.CRC32_POLYNOMIAL:i>>>=1;e.crctable[t]=i}}data;pos;bitPos=0;constructor(t){if(!t)throw new Error("Input src packet array was null!");this.data=t,this.pos=0}static alloc=t=>new e(0===t?new Uint8Array(100):1===t?new Uint8Array(5e3):new Uint8Array(3e4));get g1(){return this.data[this.pos++]}get g1b(){return this.data[this.pos++]<<24>>24}get g2(){return(this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g2b(){return this.data[this.pos++]<<8|this.data[this.pos++]}get g3(){return(this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4(){return(this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4s(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]}get g8(){return BigInt(this.g4)<<32n|BigInt(this.g4)}get gsmart(){return this.data[this.pos]<128?this.g1:this.g2-32768}get gsmarts(){return this.data[this.pos]<128?this.g1-64:this.g2-49152}get gjstr(){let t="";for(;10!=this.data[this.pos]&&this.posthis.data.subarray(t,t+e);p1=t=>{this.data[this.pos++]=t};p2=t=>{this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip2=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8};p3=t=>{this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};p4=t=>{this.data[this.pos++]=t>>>24,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip4=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>24};p8=t=>{this.p4(Number(t>>32n)),this.p4(Number(0xffffffffn&t))};pjstr=t=>{for(let e=0;e{for(let s=i;s{this.data[this.pos-t-1]=t};bits=()=>{this.bitPos=8*this.pos};bytes=()=>{this.pos=(this.bitPos+7)/8>>>0};gBit=t=>{let i=this.bitPos>>>3,s=8-(7&this.bitPos),r=0;for(this.bitPos+=t;t>s;s=8)r+=(this.data[i++]&e.bitmask[s])<>>s-t&e.bitmask[t],r}}class s{static instances=[];static unpack=t=>{const i=new e(t.read("base_head.dat")),r=new e(t.read("base_type.dat")),a=new e(t.read("base_label.dat")),n=i.g2;i.pos+=2;for(let t=0;t{const i=new e(t.read("frame_head.dat")),a=new e(t.read("frame_tran1.dat")),n=new e(t.read("frame_tran2.dat")),o=new e(t.read("frame_del.dat")),l=i.g2;i.pos+=2;const h=new Uint32Array(500),c=new Uint32Array(500),f=new Uint32Array(500),d=new Uint32Array(500);for(let t=0;t0){if(0!=u.types[t])for(let e=t-1;e>m;e--)if(0==u.types[e]){h[p]=e,c[p]=0,f[p]=0,d[p]=0,p++;break}h[p]=t;let i=0;3==u.types[h[p]]&&(i=128),c[p]=0==(1&e)?i:n.gsmart,f[p]=0==(2&e)?i:n.gsmart,d[p]=0==(4&e)?i:n.gsmart,m=t,p++}}e.length=p,e.bases=new Uint32Array(p),e.x=new Uint32Array(p),e.y=new Uint32Array(p),e.z=new Uint32Array(p);for(let t=0;t{const i=new e(t.read("seq.dat"));this.count=i.g2;for(let t=0;ta.instances[t];frameCount=0;frames=null;iframes=null;delay=null;replayoff=-1;labelGroups=null;stretches=!1;priority=5;mainhand=-1;offhand=-1;replaycount=99;duration=0;decode=(t,e)=>{if(1===t){this.frameCount=e.g1,this.frames=new Uint16Array(this.frameCount),this.iframes=new Uint16Array(this.frameCount),this.delay=new Uint16Array(this.frameCount);for(let t=0;t{const i=new e(t.read("loc.dat"));this.count=i.g2;for(let t=0;t0&&10==e.shapes[0]?1:0,e.ops.length>0&&(e.active=1))}};static get=t=>n.instances[t];models=null;shapes=null;name=null;desc=null;recol_s=null;recol_d=null;width=1;length=1;blockwalk=!0;blockrange=!0;active=-1;hillskew=!1;sharelight=!1;occlude=!1;anim=-1;hasalpha=!1;walloff=16;ambient=0;contrast=0;ops=[];mapfunction=-1;mapscene=-1;mirror=!1;shadow=!0;resizex=128;resizey=128;resizez=128;forceapproach=0;xoff=0;yoff=0;zoff=0;forcedecor=!1;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t),this.shapes=new Uint8Array(t);for(let i=0;i=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const i=new e(t.read("flo.dat"));this.count=i.g2;for(let t=0;to.instances[t];rgb=0;texture=-1;opcode3=!1;occludes=!0;name=null;decode=(t,e)=>{1===t?this.rgb=e.g3:2===t?this.texture=e.g1:3===t?this.opcode3=!0:5===t?this.occludes=!1:6===t?this.name=e.gjstr:console.log("Error unrecognised config code: ",t)}}class l{static pixels=new Int32Array;static width=0;static height=0;static top=0;static bottom=0;static left=0;static right=0;static boundX=0;static centerX=0;static centerY=0;static bind=(t,e,i)=>{this.pixels=t,this.width=e,this.height=i,this.setBounds(0,0,e,i)};static resetBounds=()=>{this.left=0,this.top=0,this.right=this.width,this.bottom=this.height,this.boundX=this.right-1,this.centerX=this.right/2};static setBounds=(t,e,i,s)=>{t<0&&(t=0),e<0&&(e=0),i>this.width&&(i=this.width),s>this.height&&(s=this.height),this.top=e,this.bottom=s,this.left=t,this.right=i,this.boundX=this.right-1,this.centerX=this.right/2,this.centerY=this.bottom/2};static clear=()=>{this.pixels.fill(0)};static drawRect=(t,e,i,s,r)=>{this.drawHorizontalLine(t,e,r,i),this.drawHorizontalLine(t,e+s-1,r,i),this.drawVerticalLine(t,e,r,s),this.drawVerticalLine(t+i-1,e,r,s)};static drawHorizontalLine=(t,e,i,s)=>{if(e=this.bottom)return;tthis.right&&(s=this.right-t);const r=t+e*this.width;for(let t=0;t{if(t=this.right)return;ethis.bottom&&(s=this.bottom-e);const r=t+e*this.width;for(let t=0;t{const a=Math.abs(i-t),n=Math.abs(s-e),o=t=this.left&&t=this.top&&e-n&&(h-=n,t+=o),i{const a=this.pixels;let n=t,o=e,l=t+i,h=e+s;nthis.right&&(l=this.right),h>this.bottom&&(h=this.bottom);const c=this.width;for(let t=o;tt.bits-e.bits||t.code-e.code));let a=0,n=-1;const o=[];let l;for(let t=0;t=t.length)throw RangeError("Out of bound");const i=t.slice();t.sort(((t,e)=>t-e));const s={};for(let e=t.length-1;e>=0;e-=1)s[t[e]]=e;const r=[];for(let e=0;enew Promise((e=>setTimeout(e,t))),g=async t=>new Uint8Array(await(await fetch(t)).arrayBuffer()),m=(t,e=!0,i=!0)=>{if(e){const e=Uint8Array.from(["B".charCodeAt(0),"Z".charCodeAt(0),"h".charCodeAt(0),"1".charCodeAt(0)]);if(i){const i=t;(t=new Uint8Array(e.length+t.length)).set(i,e.length)}t.set(e,0)}return function(t,e=!1){let i=0,s=0,r=0;const a=e=>{if(e>=32){const t=e>>1;return a(t)*(1<>r-e&n;return r-=e,s&=~(n<=49&&n<=57))throw new Error("Invalid blocksize");n-=48;let o=new Uint8Array(1.5*t.length),l=0,u=-1;for(;;){const n=a(48),g=0|a(32);if(54156738319193!==n){if(25779555029136===n){a(7&r);break}throw new Error("Invalid bz2 blocktype")}{if(a(1))throw new Error("do not support randomised");const n=a(24),m=[],p=a(16);for(let t=32768;t>0;t>>=1){if(!(p&t)){for(let t=0;t<16;t+=1)m.push(!1);continue}const e=a(16);for(let t=32768;t>0;t>>=1)m.push(!!(e&t))}const w=a(3);if(w<2||w>6)throw new Error("Invalid number of huffman groups");const b=a(15),y=[],v=Array.from({length:w},((t,e)=>e));for(let t=0;t=w)throw new Error("MTF table out of range");const e=v[t];for(let e=t;e>0;v[e]=v[--e]);y.push(e),v[0]=e}const x=m.reduce(((t,e)=>t+e),0)+2,C=[];for(let t=0;t20)throw new Error("Huffman group length outside range");for(;a(1);)t-=2*a(1)-1;e.push(t)}C.push(f(e))}const S=[];for(let t=0;t>r-e],A)){s&=c[r-=e],A=A.code;break}if(A>=0&&A<=1)0===_&&(O=1),_+=O<0;_-=1)P.push(t)}if(A===x-1)break;{const t=S[A-1];for(let t=A-1;t>0;S[t]=S[--t]);S[0]=t,P.push(t)}}}const M=d(P,n);let E=0;for(;E=o.length){const t=o;o=new Uint8Array(2*t.length),o.set(t)}for(let s=0;s>24^t)]),o[l]=t,l+=1}if(e){const t=-1^u;if(t!==g)throw new Error(`CRC mismatch: ${t} !== ${g}`);u=-1}}}return o.subarray(0,l)}(t)},p=(t,e,i,s,r)=>{for(;r--;)i[s++]=t[e++]};class w{pixels;width;height;cropX;cropY;cropW;cropH;constructor(t,e){this.pixels=new Int32Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromJpeg=async(t,e)=>{const i=t.read(e+".dat"),s=await(async t=>{if(!t)throw new Error("Input jpeg data was null!");255!==t[0]&&(t[0]=255);const e=document.createElement("img");e.src="data:image/jpeg;base64,"+btoa(String.fromCharCode(...t)),await new Promise((t=>e.onload=t));const i=document.createElement("canvas");i.width=e.naturalWidth,i.height=e.naturalHeight;const s=i.getContext("2d");if(!s)throw new Error("Canvas 2d not found!!!!!!!!");return s.drawImage(e,0,0),s.getImageData(0,0,i.width,i.height)})(i),r=new w(s.width,s.height),a=r.pixels,n=s.data;for(let t=0;t{const r=new e(t.read(i+".dat")),a=new e(t.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,l=a.g1,h=new Uint32Array(l),c=l-1;for(let t=0;t{t|=0,e|=0;let i=(t+=this.cropX)+(e+=this.cropY)*l.width,s=0,r=this.height,a=this.width,n=l.width-a,o=0;if(el.bottom&&(r-=e+r-l.bottom),tl.right){const e=t+a-l.right;a-=e,o+=e,n+=e}a>0&&r>0&&this.copyImageDraw(a,r,this.pixels,s,o,l.pixels,i,n)};drawAlpha=(t,e,i)=>{e|=0,i|=0;let s=(e+=this.cropX)+(i+=this.cropY)*l.width,r=0,a=this.height,n=this.width,o=l.width-n,h=0;if(il.bottom&&(a-=i+a-l.bottom),el.right){const t=e+n-l.right;n-=t,h+=t,o+=t}n>0&&a>0&&this.copyPixelsAlpha(n,a,this.pixels,r,h,l.pixels,s,o,t)};blitOpaque=(t,e)=>{t|=0,e|=0;let i=(t+=this.cropX)+(e+=this.cropY)*l.width,s=0,r=this.height,a=this.width,n=l.width-a,o=0;if(el.bottom&&(r-=e+r-l.bottom),tl.right){const e=t+a-l.right;a-=e,o+=e,n+=e}a>0&&r>0&&this.copyImageBlitOpaque(a,r,this.pixels,s,o,l.pixels,i,n)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;a+=t,a<1?a=1:a>255&&(a=255);let n=r>>8&255;n+=e,n<1?n=1:n>255&&(n=255);let o=255&r;o+=i,o<1?o=1:o>255&&(o=255),this.pixels[s]=(a<<16)+(n<<8)+o}}};copyImageBlitOpaque=(t,e,i,s,r,a,n,o)=>{const l=-(t>>2);t=-(3&t);for(let h=-e;h<0;h++){for(let t=l;t<0;t++)a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++];for(let e=t;e<0;e++)a[n++]=i[s++];n+=o,s+=r}};copyPixelsAlpha=(t,e,i,s,r,a,n,o,l)=>{const h=256-l;for(let c=-e;c<0;c++){for(let e=-t;e<0;e++){const t=i[s++];if(0==t)n++;else{const e=a[n];a[n++]=((16711935&t)*l+(16711935&e)*h&4278255360)+((65280&t)*l+(65280&e)*h&16711680)>>8}}n+=o,s+=r}};copyImageDraw=(t,e,i,s,r,a,n,o)=>{const l=-(t>>2);t=-(3&t);for(let h=-e;h<0;h++){for(let t=l;t<0;t++){let t=i[s++];0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t}for(let e=t;e<0;e++){const t=i[s++];0===t?n++:a[n++]=t}n+=o,s+=r}}}class b extends t{static count=0;static instances=[];static unpack=(t,i)=>{const s=new e(t.read("obj.dat"));this.count=s.g2;for(let t=0;tb.instances[t];static getIcon=(t,e)=>new w(32,32);model=0;name=null;desc=null;recol_s=null;recol_d=null;zoom2d=2e3;xan2d=0;yan2d=0;zan2d=0;xof2d=0;yof2d=0;code9=!1;code10=-1;stackable=!1;cost=1;members=!1;ops=[];iops=[];manwear=-1;manwear2=-1;manwearOffsetY=0;womanwear=-1;womanwear2=-1;womanwearOffsetY=0;manwear3=-1;womanwear3=-1;manhead=-1;manhead2=-1;womanhead=-1;womanhead2=-1;countobj=null;countco=null;certlink=-1;certtemplate=-1;decode=(t,e)=>{if(1===t)this.model=e.g2;else if(2===t)this.name=e.gjstr;else if(3===t)this.desc=e.gjstr;else if(4===t)this.zoom2d=e.g2;else if(5===t)this.xan2d=e.g2;else if(6===t)this.yan2d=e.g2;else if(7===t)this.xof2d=e.g2b,this.xof2d>32767&&(this.xof2d-=65536);else if(8===t)this.yof2d=e.g2b,this.yof2d>32767&&(this.yof2d-=65536);else if(9===t)this.code9=!0;else if(10===t)this.code10=e.g2;else if(11===t)this.stackable=!0;else if(12===t)this.cost=e.g4s;else if(16===t)this.members=!0;else if(23===t)this.manwear=e.g2,this.manwearOffsetY=e.g1b;else if(24===t)this.manwear2=e.g2;else if(25===t)this.womanwear=e.g2,this.womanwearOffsetY=e.g1b;else if(26===t)this.womanwear2=e.g2;else if(t>=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(t>=35&&t<40)this.iops[t-35]=e.gjstr;else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i=100&&t<110))throw new Error(`Unrecognized obj config code: ${t}`);this.countobj&&this.countco||(this.countobj=new Uint16Array(10),this.countco=new Uint16Array(10)),this.countobj[t-100]=e.g2,this.countco[t-100]=e.g2}};toCertificate=()=>{const t=b.get(this.certtemplate);this.model=t.model,this.zoom2d=t.zoom2d,this.xan2d=t.xan2d,this.yan2d=t.yan2d,this.zan2d=t.zan2d,this.xof2d=t.xof2d,this.yof2d=t.yof2d,this.recol_s=t.recol_s,this.recol_d=t.recol_d;const e=b.get(this.certlink);this.name=e.name,this.members=e.members,this.cost=e.cost;let i="a";const s=(e.name||"").toLowerCase().charAt(0);"a"!==s&&"e"!==s&&"i"!==s&&"o"!==s&&"u"!==s||(i="an"),this.desc=`Swap this note at any bank for ${i} ${e.name}.`,this.stackable=!0}}class y extends t{static count=0;static instances=[];static unpack=t=>{const i=new e(t.read("npc.dat"));this.count=i.g2;for(let t=0;ty.instances[t];name=null;desc=null;size=1;models=null;heads=null;hasanim=!1;readyanim=-1;walkanim=-1;walkanim_b=-1;walkanim_r=-1;walkanim_l=-1;hasalpha=!1;recol_s=null;recol_d=null;ops=[];code90=-1;code91=-1;code92=-1;visonmap=!0;vislevel=-1;resizeh=128;resizev=128;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=30&&t<40)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const i=new e(t.read("idk.dat"));this.count=i.g2;for(let t=0;tv.instances[t];type=-1;models=null;heads=new Uint16Array(5).fill(-1);recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);disable=!1;decode=(t,e)=>{if(1===t)this.type=e.g1;else if(2===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=40&&t<50)this.recol_s[t-40]=e.g2;else if(t>=50&&t<60)this.recol_d[t-50]=e.g2;else{if(!(t>=60&&t<70))throw new Error(`Unrecognized idk config code: ${t}`);this.heads[t-60]=e.g2}}}class x extends t{static count=0;static instances=[];static unpack=t=>{const i=new e(t.read("spotanim.dat"));this.count=i.g2;for(let t=0;tx.instances[t];model=0;anim=-1;seq=null;disposeAlpha=!1;recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);resizeh=128;resizev=128;orientation=0;ambient=0;contrast=0;decode=(t,e)=>{if(1==t)this.model=e.g2;else if(2==t)this.anim=e.g2,null!=a.instances&&(this.seq=a.instances[this.anim]);else if(3==t)this.disposeAlpha=!0;else if(4==t)this.resizeh=e.g2;else if(5==t)this.resizev=e.g2;else if(6==t)this.orientation=e.g2;else if(7==t)this.ambient=e.g1;else if(8==t)this.contrast=e.g1;else if(t>=40&&t<50)this.recol_s[t-40]=e.g2;else{if(!(t>=50&&t<60))throw new Error(`Unrecognized spotanim config code: ${t}`);this.recol_d[t-50]=e.g2}}}class C extends t{static count=0;static instances=[];static code3=[];static code3Count=0;static unpack=t=>{const i=new e(t.read("varp.dat"));this.count=i.g2;for(let t=0;tC.instances[t];code10=null;code1=0;code2=0;hasCode3=!1;code4=!0;clientcode=0;code7=0;code6=!1;code8=!1;decode(t,e){if(1==t)this.code1=e.g1;else if(2==t)this.code2=e.g1;else if(3==t)this.hasCode3=!0,C.code3[C.code3Count++]=this.index;else if(4==t)this.code4=!1;else if(5==t)this.clientcode=e.g2;else if(6==t)this.code6=!0;else if(7==t)this.code7=e.g4;else if(8==t)this.code8=!0;else{if(10!=t)throw new Error(`Error unrecognised config code: ${t}`);this.code10=e.gjstr}}}class S{pixels;width;height;cropX;cropY;cropW;cropH;palette=new Uint32Array(0);constructor(t,e){this.pixels=new Uint8Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromArchive=(t,i,s=0)=>{const r=new e(t?.read(i+".dat")),a=new e(t?.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,l=a.g1,h=new Uint32Array(l);for(let t=0;t{t|=0,e|=0;let r=(t+=this.cropX)+(e+=this.cropY)*l.width,a=0,n=this.height,o=this.width;-1!==i&&(o=i),-1!==s&&(n=s);let h=l.width-o,c=0;if(el.bottom&&(n-=e+n-l.bottom),tl.right){const e=t+o-l.right;o-=e,c+=e,h+=e}o>0&&n>0&&this.copyImage(o,n,this.pixels,a,c,l.pixels,r,h)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;r+=t,r<0?r=0:r>255&&(r=255);let a=this.palette[s]>>8&255;a+=e,a<0?a=0:a>255&&(a=255);let n=255&this.palette[s];n+=i,n<0?n=0:n>255&&(n=255),this.palette[s]=(r<<16)+(a<<8)+n}};copyImage=(t,e,i,s,r,a,n,o)=>{for(let l=0;l{this.lineOffset=new Int32Array(l.height);for(let t=0;t{this.lineOffset=new Int32Array(e);for(let i=0;i{this.textureCount=0;for(let e=0;e<50;e++)try{this.textures[e]=S.fromArchive(t,e.toString()),this.textureCount++}catch(t){}};static setBrightness=t=>{t+=.3*Math.random()-.15;let e=0;for(let i=0;i<512;i++){const s=i/8/64+.0078125,r=(7&i)/8+.0625;for(let i=0;i<128;i++){const a=i/128;let n=a,o=a,l=a;if(r){let t;t=a<.5?a*(1+r):a+r-a*r;const e=2*a-t;let i=s+.3333333333333333;i>1&&i--;let h=s-.3333333333333333;h<0&&h++,n=6*i<1?e+6*(t-e)*i:2*i<1?t:3*i<2?e+6*(.6666666666666666-i)*(t-e):e,o=6*s<1?e+6*(t-e)*s:2*s<1?t:3*s<2?e+6*(.6666666666666666-s)*(t-e):e,l=6*h<1?e+6*(t-e)*h:2*h<1?t:3*h<2?e+6*(.6666666666666666-h)*(t-e):e}let h=Math.trunc(256*n)<<16|Math.trunc(256*o)<<8|Math.trunc(256*l);h=this.setGamma(h,t),0===h&&(h=1),this.palette[e++]=h}}};static setGamma=(t,e)=>{let i=(t>>16)/256,s=(t>>8&255)/256,r=(255&t)/256;return i=Math.pow(i,e),s=Math.pow(s,e),r=Math.pow(r,e),Math.trunc(256*i)<<16|Math.trunc(256*s)<<8|Math.trunc(256*r)};static initPool=t=>{null==this.texelPool&&(this.poolSize=t,this.texelPool=[],this.activeTexels=[])};static fillGouraudTriangle=(t,e,i,s,r,a,n,o,h)=>{let c=0,f=0,d=0,u=0,g=0,m=0;if(r!=s&&(c=(e-t<<16)/(r-s),u=(o-n<<15)/(r-s)),a!=r&&(f=(i-e<<16)/(a-r),g=(h-o<<15)/(a-r)),a!=s&&(d=(t-i<<16)/(s-a),m=(n-h<<15)/(s-a)),s<=r&&s<=a){if(s>=l.bottom)return;if(r>l.bottom&&(r=l.bottom),a>l.bottom&&(a=l.bottom),rf){for(a-=r,r-=s,s=this.lineOffset[s];--r>=0;s+=l.width)this.drawGouraudScanline(l.pixels,s,i>>16,t>>16,h>>7,n>>7),i+=d,t+=c,h+=m,n+=u;for(;--a>=0;)this.drawGouraudScanline(l.pixels,s,i>>16,e>>16,h>>7,o>>7),i+=d,e+=f,h+=m,o+=g,s+=l.width;return}for(a-=r,r-=s,s=this.lineOffset[s];--r>=0;s+=l.width)this.drawGouraudScanline(l.pixels,s,t>>16,i>>16,n>>7,h>>7),i+=d,t+=c,h+=m,n+=u;for(;--a>=0;)this.drawGouraudScanline(l.pixels,s,e>>16,i>>16,o>>7,h>>7),i+=d,e+=f,h+=m,o+=g,s+=l.width;return}if(e=t<<=16,o=n<<=15,s<0&&(e-=d*s,t-=c*s,o-=m*s,n-=u*s,s=0),i<<=16,h<<=15,a<0&&(i-=f*a,h-=g*a,a=0),s!=a&&dc){for(r-=a,a-=s,s=this.lineOffset[s];--a>=0;s+=l.width)this.drawGouraudScanline(l.pixels,s,e>>16,t>>16,o>>7,n>>7),e+=d,t+=c,o+=m,n+=u;for(;--r>=0;)this.drawGouraudScanline(l.pixels,s,i>>16,t>>16,h>>7,n>>7),i+=f,t+=c,h+=g,n+=u,s+=l.width;return}for(r-=a,a-=s,s=this.lineOffset[s];--a>=0;s+=l.width)this.drawGouraudScanline(l.pixels,s,t>>16,e>>16,n>>7,o>>7),e+=d,t+=c,o+=m,n+=u;for(;--r>=0;)this.drawGouraudScanline(l.pixels,s,t>>16,i>>16,n>>7,h>>7),i+=f,t+=c,h+=g,n+=u,s+=l.width}else if(r<=a){if(r>=l.bottom)return;if(a>l.bottom&&(a=l.bottom),s>l.bottom&&(s=l.bottom),ad){for(s-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=l.width)this.drawGouraudScanline(l.pixels,r,t>>16,e>>16,n>>7,o>>7),t+=c,e+=f,n+=u,o+=g;for(;--s>=0;)this.drawGouraudScanline(l.pixels,r,t>>16,i>>16,n>>7,h>>7),t+=c,i+=d,n+=u,h+=m,r+=l.width;return}for(s-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=l.width)this.drawGouraudScanline(l.pixels,r,e>>16,t>>16,o>>7,n>>7),t+=c,e+=f,n+=u,o+=g;for(;--s>=0;)this.drawGouraudScanline(l.pixels,r,i>>16,t>>16,h>>7,n>>7),t+=c,i+=d,n+=u,h+=m,r+=l.width;return}if(i=e<<=16,h=o<<=15,r<0&&(i-=c*r,e-=f*r,h-=u*r,o-=g*r,r=0),t<<=16,n<<=15,s<0&&(t-=d*s,n-=m*s,s=0),c=0;r+=l.width)this.drawGouraudScanline(l.pixels,r,i>>16,e>>16,h>>7,o>>7),i+=c,e+=f,h+=u,o+=g;for(;--a>=0;)this.drawGouraudScanline(l.pixels,r,t>>16,e>>16,n>>7,o>>7),t+=d,e+=f,n+=m,o+=g,r+=l.width;return}for(a-=s,s-=r,r=this.lineOffset[r];--s>=0;r+=l.width)this.drawGouraudScanline(l.pixels,r,e>>16,i>>16,o>>7,h>>7),i+=c,e+=f,h+=u,o+=g;for(;--a>=0;)this.drawGouraudScanline(l.pixels,r,e>>16,t>>16,o>>7,n>>7),t+=d,e+=f,n+=m,o+=g,r+=l.width}else if(!(a>=l.bottom))if(s>l.bottom&&(s=l.bottom),r>l.bottom&&(r=l.bottom),s=0;a+=l.width)this.drawGouraudScanline(l.pixels,a,e>>16,i>>16,o>>7,h>>7),e+=f,i+=d,o+=g,h+=m;for(;--r>=0;)this.drawGouraudScanline(l.pixels,a,e>>16,t>>16,o>>7,n>>7),e+=f,t+=c,o+=g,n+=u,a+=l.width;return}for(r-=s,s-=a,a=this.lineOffset[a];--s>=0;a+=l.width)this.drawGouraudScanline(l.pixels,a,i>>16,e>>16,h>>7,o>>7),e+=f,i+=d,o+=g,h+=m;for(;--r>=0;)this.drawGouraudScanline(l.pixels,a,t>>16,e>>16,n>>7,o>>7),e+=f,t+=c,o+=g,n+=u,a+=l.width}else if(t=i<<=16,n=h<<=15,a<0&&(t-=f*a,i-=d*a,n-=g*a,h-=m*a,a=0),e<<=16,o<<=15,r<0&&(e-=c*r,o-=u*r,r=0),f=0;a+=l.width)this.drawGouraudScanline(l.pixels,a,t>>16,i>>16,n>>7,h>>7),t+=f,i+=d,n+=g,h+=m;for(;--s>=0;)this.drawGouraudScanline(l.pixels,a,e>>16,i>>16,o>>7,h>>7),e+=c,i+=d,o+=u,h+=m,a+=l.width}else{for(s-=r,r-=a,a=this.lineOffset[a];--r>=0;a+=l.width)this.drawGouraudScanline(l.pixels,a,i>>16,t>>16,h>>7,n>>7),t+=f,i+=d,n+=g,h+=m;for(;--s>=0;)this.drawGouraudScanline(l.pixels,a,i>>16,e>>16,h>>7,o>>7),e+=c,i+=d,o+=u,h+=m,a+=l.width}};static drawGouraudScanline=(t,e,i,s,r,a)=>{let n=0,o=0;if(this.jagged){let h=0;if(this.clipX){if(h=s-i>3?(a-r)/(s-i):0,s>l.right&&(s=l.right),i<0&&(r-=i*h,i=0),i>=s)return;e+=i,o=s-i>>2,h<<=2}else{if(i>=s)return;e+=i,o=s-i>>2,h=o>0?(a-r)*this.reciprocal15[o]>>15:0}if(0==this.alpha){for(;--o>=0;)n=this.palette[r>>8],r+=h,t[e++]=n,t[e++]=n,t[e++]=n,t[e++]=n;if(o=s-i&3,o>0){n=this.palette[r>>8];do{t[e++]=n}while(--o>0);return}}else{const a=this.alpha,l=256-this.alpha;for(;--o>=0;)n=this.palette[r>>8],r+=h,n=((16711935&n)*l>>8&16711935)+((65280&n)*l>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280);if(o=s-i&3,o>0){n=this.palette[r>>8],n=((16711935&n)*l>>8&16711935)+((65280&n)*l>>8&65280);do{t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280)}while(--o>0)}}return}if(i>=s)return;const h=(a-r)/(s-i);if(this.clipX&&(s>l.right&&(s=l.right),i<0&&(r-=i*h,i=0),i>=s))return;if(e+=i,o=s-i,0==this.alpha){do{t[e++]=this.palette[r>>8],r+=h}while(--o>0);return}const c=this.alpha,f=256-this.alpha;do{n=this.palette[r>>8],r+=h,n=((16711935&n)*f>>8&16711935)+((65280&n)*f>>8&65280),t[e++]=n+((16711935&t[e])*c>>8&16711935)+((65280&t[e])*c>>8&65280)}while(--o>0)};static fillTriangle=()=>{};static fillTexturedTriangle=()=>{}}class A{vertexCount=0;faceCount=0;texturedFaceCount=0;vertexFlagsOffset=-1;vertexXOffset=-1;vertexYOffset=-1;vertexZOffset=-1;vertexLabelsOffset=-1;faceVerticesOffset=-1;faceOrientationsOffset=-1;faceColorsOffset=-1;faceInfosOffset=-1;facePrioritiesOffset=0;faceAlphasOffset=-1;faceLabelsOffset=-1;faceTextureAxisOffset=-1}class k{x=0;y=0;z=0;w=0}class I{static metadata=null;static head=null;static face1=null;static face2=null;static face3=null;static face4=null;static face5=null;static point1=null;static point2=null;static point3=null;static point4=null;static point5=null;static vertex1=null;static vertex2=null;static axis=null;static faceClippedX=new Array(4096);static faceNearClipped=new Array(4096);static vertexScreenX=new Int32Array(4096);static vertexScreenY=new Int32Array(4096);static vertexScreenZ=new Int32Array(4096);static vertexViewSpaceX=new Int32Array(4096);static vertexViewSpaceY=new Int32Array(4096);static vertexViewSpaceZ=new Int32Array(4096);static tmpDepthFaceCount=new Int32Array(1500);static tmpDepthFaces=new Array(1500).fill(null).map((()=>new Int32Array(512)));static tmpPriorityFaceCount=new Int32Array(12);static tmpPriorityFaces=new Array(12).fill(null).map((()=>new Int32Array(2e3)));static tmpPriority10FaceDepth=new Int32Array(2e3);static tmpPriority11FaceDepth=new Int32Array(2e3);static tmpPriorityDepthSum=new Int32Array(12);static clippedX=new Int32Array(10);static clippedY=new Int32Array(10);static clippedColor=new Int32Array(10);static baseX=0;static baseY=0;static baseZ=0;static checkHover=!1;static mouseX=0;static mouseZ=0;static pickedCount=0;static pickedBitsets=new Int32Array(1e3);static unpack(t){try{I.head=new e(t.read("ob_head.dat")),I.face1=new e(t.read("ob_face1.dat")),I.face2=new e(t.read("ob_face2.dat")),I.face3=new e(t.read("ob_face3.dat")),I.face4=new e(t.read("ob_face4.dat")),I.face5=new e(t.read("ob_face5.dat")),I.point1=new e(t.read("ob_point1.dat")),I.point2=new e(t.read("ob_point2.dat")),I.point3=new e(t.read("ob_point3.dat")),I.point4=new e(t.read("ob_point4.dat")),I.point5=new e(t.read("ob_point5.dat")),I.vertex1=new e(t.read("ob_vertex1.dat")),I.vertex2=new e(t.read("ob_vertex2.dat")),I.axis=new e(t.read("ob_axis.dat")),I.head.pos=0,I.point1.pos=0,I.point2.pos=0,I.point3.pos=0,I.point4.pos=0,I.vertex1.pos=0,I.vertex2.pos=0;const i=I.head.g2;I.metadata=new Array(i+100);let s=0,r=0,a=0,n=0,o=0,l=0,h=0;for(let t=0;t127&&(e=127),127-e):((e=e*(127&t)>>7)<2?e=2:e>126&&(e=126),(65408&t)+e)}vertexCount=0;vertexX=null;vertexY=null;vertexZ=null;faceCount=0;faceVertexA=null;faceVertexB=null;faceVertexC=null;faceColorA=null;faceColorB=null;faceColorC=null;faceInfo=null;facePriority=null;faceAlpha=null;faceColor=null;priority=0;texturedFaceCount=0;texturedVertexA=null;texturedVertexB=null;texturedVertexC=null;minX=0;maxX=0;minZ=0;maxZ=0;radius=0;minY=0;maxY=0;maxDepth=0;minDepth=0;objRaise=0;vertexLabel=null;faceLabel=null;labelVertices=null;labelFaces=null;pickable=!1;vertexNormal=null;vertexNormalOriginal=null;constructor(t){if(null===I.head||null===I.face1||null===I.face2||null===I.face3||null===I.face4||null===I.face5||null===I.point1||null===I.point2||null===I.point3||null===I.point4||null===I.point5||null===I.vertex1||null===I.vertex2||null===I.axis)return;if(null===I.metadata)return;const e=I.metadata[t];if(void 0===e)return void console.log(`Error model:${t} not found!`);this.vertexCount=e.vertexCount,this.faceCount=e.faceCount,this.texturedFaceCount=e.texturedFaceCount,this.vertexX=new Int32Array(this.vertexCount),this.vertexY=new Int32Array(this.vertexCount),this.vertexZ=new Int32Array(this.vertexCount),this.faceVertexA=new Int32Array(this.faceCount),this.faceVertexB=new Int32Array(this.faceCount),this.faceVertexC=new Int32Array(this.faceCount),this.texturedVertexA=new Int32Array(this.texturedFaceCount),this.texturedVertexB=new Int32Array(this.texturedFaceCount),this.texturedVertexC=new Int32Array(this.texturedFaceCount),e.vertexLabelsOffset>=0&&(this.vertexLabel=new Int32Array(this.vertexCount)),e.faceInfosOffset>=0&&(this.faceInfo=new Int32Array(this.faceCount)),e.facePrioritiesOffset>=0?this.facePriority=new Int32Array(this.faceCount):this.priority=-e.facePrioritiesOffset-1,e.faceAlphasOffset>=0&&(this.faceAlpha=new Int32Array(this.faceCount)),e.faceLabelsOffset>=0&&(this.faceLabel=new Int32Array(this.faceCount)),this.faceColor=new Int32Array(this.faceCount),I.point1.pos=e.vertexFlagsOffset,I.point2.pos=e.vertexXOffset,I.point3.pos=e.vertexYOffset,I.point4.pos=e.vertexZOffset,I.point5.pos=e.vertexLabelsOffset;let i,s,r,a=0,n=0,o=0;for(let t=0;tthis.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)+.99),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsY(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.minY=0;for(let t=0;tthis.maxY&&(this.maxY=-e),e>this.minY&&(this.minY=e)}this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsAABB(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.radius=0,this.minY=0,this.minX=999999,this.maxX=-999999,this.maxZ=-99999,this.minZ=99999;for(let t=0;tthis.maxX&&(this.maxX=e),sthis.maxZ&&(this.maxZ=s),-i>this.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY))}}createLabelReferences(){}applyTransform(t){}rotateY90(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let t=0;t>16;this.vertexZ[t]=this.vertexY[t]*e+this.vertexZ[t]*i>>16,this.vertexY[t]=s}}translate(t,e,i){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let s=0;s>8;if(null!==this.faceColorA&&null!==this.faceColorB&&null!==this.faceColorC||(this.faceColorA=new Int32Array(this.faceCount),this.faceColorB=new Int32Array(this.faceCount),this.faceColorC=new Int32Array(this.faceCount)),null===this.vertexNormal){this.vertexNormal=new Array(this.vertexCount);for(let t=0;t8192||p>8192||w>8192||m<-8192||p<-8192||w<-8192;)m>>=1,p>>=1,w>>=1;let b=Math.sqrt(m*m+p*p+w*w);if(b<=0&&(b=1),m=256*m/b,p=256*p/b,w=256*w/b,null===this.faceInfo||0==(1&this.faceInfo[e])){let t=this.vertexNormal[a];t.x+=m,t.y+=p,t.z+=w,t.w++,t=this.vertexNormal[o],t.x+=m,t.y+=p,t.z+=w,t.w++,t=this.vertexNormal[l],t.x+=m,t.y+=p,t.z+=w,t.w++}else{const a=t+(i*m+s*p+r*w)/(n+n/2);this.faceColorA[e]=I.mulColorLightness(this.faceColor[e],a,this.faceInfo[e])}}if(a)this.applyLighting(t,e,i,s,r);else{this.vertexNormalOriginal=new Array(this.vertexCount);for(let t=0;t>16;for(let s=0;s>16,b=b*d-w*f>>16,w=p),0!==t&&(p=b*l-y*o>>16,y=b*o+y*l>>16,b=p),0!==e&&(p=y*h+w*c>>16,y=y*c-w*h>>16,w=p),w+=r,b+=a,y+=n,p=b*g-y*u>>16,y=b*u+y*g>>16,b=p,I.vertexScreenX[s]=T.centerX+(w<<9)/y,I.vertexScreenY[s]=T.centerY+(b<<9)/y,I.vertexScreenZ[s]=y-m,this.texturedFaceCount>0&&(I.vertexViewSpaceX[s]=w,I.vertexViewSpaceY[s]=b,I.vertexViewSpaceZ[s]=y)}this.draw2(!1,!1,0)}draw(t,e,i,s,r,a,n,o,l){}draw2(t,e,i){if(null===I.vertexScreenX||null===I.vertexScreenY||null===I.vertexScreenZ)return;if(null===I.vertexViewSpaceX||null===I.vertexViewSpaceY||null===I.vertexViewSpaceZ)return;if(null===I.faceNearClipped||null===I.faceClippedX)return;if(null===I.tmpDepthFaceCount||null===I.tmpDepthFaces||null===I.tmpPriorityFaces||null===I.tmpPriorityFaceCount||null===I.tmpPriorityDepthSum||null===I.tmpPriority10FaceDepth||null===I.tmpPriority11FaceDepth)return;if(null===this.faceVertexA||null===this.faceVertexB||null===this.faceVertexC)return;for(let t=0;tl.boundX||h>l.boundX||c>l.boundX;const u=Math.trunc((I.vertexScreenZ[r]+I.vertexScreenZ[a]+I.vertexScreenZ[n])/3+this.minDepth);I.tmpDepthFaces[u][I.tmpDepthFaceCount[u]++]=s}else{I.faceNearClipped[s]=!0;const t=Math.trunc((I.vertexScreenZ[r]+I.vertexScreenZ[a]+I.vertexScreenZ[n])/3+this.minDepth);I.tmpDepthFaces[t][I.tmpDepthFaceCount[t]++]=s}}if(null==this.facePriority){for(let t=this.maxDepth-1;t>=0;t--){const e=I.tmpDepthFaceCount[t];if(e<=0)continue;const i=I.tmpDepthFaces[t];for(let t=0;t=0;t--){const e=I.tmpDepthFaceCount[t];if(e>0){const i=I.tmpDepthFaces[t];for(let s=0;s0||I.tmpPriorityFaceCount[2]>0)&&(s=Math.trunc((I.tmpPriorityDepthSum[1]+I.tmpPriorityDepthSum[2])/(I.tmpPriorityFaceCount[1]+I.tmpPriorityFaceCount[2])));let r=0;(I.tmpPriorityFaceCount[3]>0||I.tmpPriorityFaceCount[4]>0)&&(r=Math.trunc((I.tmpPriorityDepthSum[3]+I.tmpPriorityDepthSum[4])/(I.tmpPriorityFaceCount[3]+I.tmpPriorityFaceCount[4])));let a=0;(I.tmpPriorityFaceCount[6]>0||I.tmpPriorityFaceCount[8]>0)&&(a=Math.trunc((I.tmpPriorityDepthSum[6]+I.tmpPriorityDepthSum[8])/(I.tmpPriorityFaceCount[6]+I.tmpPriorityFaceCount[8])));let n,o=0,h=I.tmpPriorityFaceCount[10],c=I.tmpPriorityFaces[10],f=I.tmpPriority10FaceDepth;o==h&&(o=0,h=I.tmpPriorityFaceCount[11],c=I.tmpPriorityFaces[11],f=I.tmpPriority11FaceDepth),n=os;)this.drawFace(c[o++]),o==h&&c!=I.tmpPriorityFaces[11]&&(o=0,h=I.tmpPriorityFaceCount[11],c=I.tmpPriorityFaces[11],f=I.tmpPriority11FaceDepth),n=or;)this.drawFace(c[o++]),o==h&&c!=I.tmpPriorityFaces[11]&&(o=0,h=I.tmpPriorityFaceCount[11],c=I.tmpPriorityFaces[11],f=I.tmpPriority11FaceDepth),n=oa;)this.drawFace(c[o++]),o==h&&c!=I.tmpPriorityFaces[11]&&(o=0,h=I.tmpPriorityFaceCount[11],c=I.tmpPriorityFaces[11],f=I.tmpPriority11FaceDepth),n=oa&&e>n&&e>o||t{const r=new e(t.read("data"));let a=-1;for(r.pos+=2;r.pos0){e.scriptComparator=new Uint8Array(n).fill(0),e.scriptOperand=new Uint16Array(n).fill(0);for(let t=0;t0){e.scripts=new Array(o).fill(null);for(let t=0;t0){const r=s.lastIndexOf(",");e.inventorySlotImage[t]=w.fromArchive(i,s,r)}}for(let t=0;t<5;t++)e.inventoryOptions[t]=r.gjstr,0===e.inventoryOptions[t]?.length&&(e.inventoryOptions[t]=null);e.spellAction=r.gjstr,e.spellName=r.gjstr,e.spellFlags=r.g2;break;case _.TYPE_RECT:e.fill=1===r.g1,e.color=r.g4,e.activeColor=r.g4,e.hoverColor=r.g4;break;case _.TYPE_TEXT:e.center=1===r.g1,e.font=s[r.g1],e.shadow=1===r.g1,e.text=r.gjstr,e.activeText=r.gjstr,e.color=r.g4,e.activeColor=r.g4,e.hoverColor=r.g4;break;case _.TYPE_SPRITE:{const t=r.gjstr;if(t.length>0){const s=t.lastIndexOf(",");e.image=w.fromArchive(i,t.substring(0,s),parseInt(t.substring(s+1)))}const s=r.gjstr;if(s.length>0){const t=s.lastIndexOf(",");e.image=w.fromArchive(i,s.substring(0,t),parseInt(s.substring(t+1)))}break}case _.TYPE_MODEL:{const t=r.g1;0!==t&&(e.model=this.getModel((t-1<<8)+r.g1));const i=r.g1;0!==i&&(e.activeModel=this.getModel((i-1<<8)+r.g1)),e.seqId=r.g1,0==e.seqId?e.seqId=-1:e.seqId=(e.seqId-1<<8)+r.g1,e.activeSeqId=r.g1,0==e.activeSeqId?e.activeSeqId=-1:e.activeSeqId=(e.activeSeqId-1<<8)+r.g1,e.modelZoom=r.g2,e.modelPitch=r.g2,e.modelYaw=r.g2;break}case _.TYPE_INVENTORY_TEXT:e.inventorySlotObjId=new Int32Array(e.width*e.height),e.inventorySlotObjCount=new Int32Array(e.width*e.height),e.center=1===r.g1,e.font=s[r.g1],e.shadow=1===r.g1,e.color=r.g4,e.inventoryMarginX=r.g2b,e.inventoryMarginY=r.g2b,e.inventoryInteractable=1===r.g1,e.inventoryOptions=new Array(5).fill(null);for(let t=0;t<5;t++)e.inventoryOptions[t]=r.gjstr}2!=e.optionType&&2!=e.type||(e.spellAction=r.gjstr,e.spellName=r.gjstr,e.spellFlags=r.g2),1!=e.optionType&&4!=e.optionType&&5!=e.optionType&&6!=e.optionType||(e.option=r.gjstr,0==e.option.length&&(1==e.optionType?e.option="Ok":4==e.optionType||5==e.optionType?e.option="Select":6==e.optionType&&(e.option="Continue")))}};static get=t=>_.instances[t];static getModel=t=>new I(t);id=-1;parentId=-1;type=-1;optionType=-1;contentType=0;width=0;height=0;delegateHover=-1;scriptComparator=null;scriptOperand=null;scripts=null;scrollableHeight=0;hide=!1;inventoryDraggable=!1;inventoryInteractable=!1;inventoryUsable=!1;inventoryMarginX=0;inventoryMarginY=0;inventorySlotOffsetX=null;inventorySlotOffsetY=null;inventorySlotImage=null;inventoryOptions=[];fill=!1;center=!1;font=null;shadow=!1;text=null;activeText=null;color=0;activeColor=0;hoverColor=0;image=null;activeImage=null;model=null;activeModel=null;seqId=-1;activeSeqId=-1;modelZoom=0;modelPitch=0;modelYaw=0;spellAction=null;spellName=null;spellFlags=-1;option=null;childId=null;childX=null;childY=null;x=0;y=0;scrollPosition=0;inventorySlotObjId=null;inventorySlotObjCount=null;seqFrame=0;getModel=(t,e,i)=>{let s=this.model;return i&&(s=this.activeModel),null==s?null:-1==t&&-1==e&&null==s.faceColor?s:null}}class O{canvas;ctx;image;pixels;width;height;constructor(t,e,i){const s=t.getContext("2d");if(!s)throw new Error("Canvas 2d not found!!!!!!!!");this.canvas=t,this.ctx=s,this.image=s.getImageData(0,0,e,i),this.pixels=new Int32Array(e*i),this.width=e,this.height=i,this.bind()}clear=()=>{this.pixels.fill(0)};bind=()=>{l.bind(this.pixels,this.width,this.height)};draw=(t,e)=>{this.#t(),this.ctx.putImageData(this.image,t,e)};#t=()=>{const t=this.image.data;for(let e=0;e>16&255,t[s+1]=i>>8&255,t[s+2]=i>>0&255,t[s+3]=255}}}class P{static CHARSET=[];static{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";for(let e=0;e<256;e++){let i=t.indexOf(String.fromCharCode(e));-1===i&&(i=74),P.CHARSET[e]=i}}pixels=[];charWidth=[];charHeight=[];clipX=[];clipY=[];charSpace=[];drawWidth=[];fontHeight=-1;static fromArchive=(t,i)=>{const s=new e(t.read(i+".dat")),r=new e(t.read("index.dat"));r.pos=s.g2+4;const a=r.g1;a>0&&(r.pos+=3*(a-1));const n=new P;for(let t=0;t<94;t++){n.clipX[t]=r.g1,n.clipY[t]=r.g1;const e=n.charWidth[t]=r.g2,i=n.charHeight[t]=r.g2,a=e*i;n.pixels[t]=new Uint8Array(a);const o=r.g1;if(0===o)for(let r=0;rn.fontHeight&&(n.fontHeight=i),n.clipX[t]=1,n.charSpace[t]=e+2;{let s=0;for(let r=i/7;r{t|=0,e|=0;const r=i.length;e-=this.fontHeight;for(let a=0;a{t|=0,e|=0;const a=i.length;e-=this.fontHeight;for(let n=0;n{const e=t.length;let i=0;for(let s=0;s{const r=e-this.fontHeight;for(let e=0;e{this.drawStringTaggable(t-this.stringWidth(i)/2,e,i,s,r)};drawStringCenter=(t,e,i,s)=>{this.draw(t-this.stringWidth(i)/2,e,i,s)};drawRight=(t,e,i,s,r=!0)=>{r&&this.draw(t-this.stringWidth(i)+1,e+1,i,0),this.draw(t-this.stringWidth(i),e,i,s)};drawChar=(t,e,i,s,r,a)=>{s|=0,r|=0;let n=(e|=0)+(i|=0)*l.width,o=l.width-s,h=0,c=0;if(i=l.bottom&&(r-=i+r+1-l.bottom),e=l.right){const t=e+s+1-l.right;s-=t,h+=t,o+=t}s>0&&r>0&&this.drawMask(s,r,t,c,h,l.pixels,n,o,a)};drawMask=(t,e,i,s,r,a,n,o,l)=>{const h=-((t|=0)>>2);t=-(3&t);for(let c=-(e|=0);c<0;c++){for(let t=h;t<0;t++)0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l;for(let e=t;e<0;e++)0==i[s++]?n++:a[n++]=l;n+=o,s+=r}};copyCharacter=(t,e,i,s,r,a)=>{i|=0,s|=0;let n=(t|=0)+(e|=0)*l.width,o=0,h=l.width-i,c=0;if(el.bottom&&(s-=e+s+1-l.bottom),tl.right){const e=t+i+1-l.right;i-=e,c+=e,h+=e}i>0&&s>0&&this.copyImageMasked(i,s,r,o,c,l.pixels,n,h,a)};copyImageMasked=(t,e,i,s,r,a,n,o,l)=>{for(let h=0;h{switch(t){case"red":return 16711680;case"gre":return 65280;case"blu":return 255;case"yel":return 16776960;case"cya":return 65535;case"mag":return 16711935;case"whi":return 16777215;case"bla":default:return 0;case"lre":return 16748608;case"dre":return 8388608;case"dbl":return 128;case"or1":return 16756736;case"or2":return 16740352;case"or3":return 16723968;case"gr1":return 12648192;case"gr2":return 8453888;case"gr3":return 4259584}}}class M{static loadUrl=async t=>new M(await g(t));static genHash=t=>{let e=0;t=t.toUpperCase();for(let i=0;i>>0;return e};buffer;compressedWhole;fileCount;fileHash;fileSizeInflated;fileSizeDeflated;fileOffset;constructor(t){const i=new e(t),s=i.g3;let r;if(s==i.g3)r=i,this.compressedWhole=!1;else{const t=i.gdata(i.pos,s);r=new e(new Uint8Array(m(t))),this.compressedWhole=!0}this.buffer=r,this.fileCount=r.g2,this.fileHash=[],this.fileSizeInflated=[],this.fileSizeDeflated=[],this.fileOffset=[];let a=r.pos+10*this.fileCount;for(let t=0;t{const e=M.genHash(t),i=this.fileHash.indexOf(e);return-1==i?null:this.readIndex(i)};readIndex=t=>{if(t<0||t>=this.fileCount)return null;if(this.compressedWhole)return this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);{const e=this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);return m(e)}}}class E{static PERIOD=new Uint16Array(["d","o","t"].join("").split("").map((t=>t.charCodeAt(0))));static AMPERSAT=new Uint16Array(["(","a",")"].join("").split("").map((t=>t.charCodeAt(0))));static SLASH=new Uint16Array(["s","l","a","s","h"].join("").split("").map((t=>t.charCodeAt(0))));static whitelist=["cook","cook's","cooks","seeks","sheet"];static tlds=[];static tldTypes=[];static bads=[];static badCombinations=[];static domains=[];static fragments=[];static unpack=t=>{const i=new e(t.read("fragmentsenc.txt")),s=new e(t.read("badenc.txt")),r=new e(t.read("domainenc.txt")),a=new e(t.read("tldlist.txt"));this.read(s,r,i,a)};static filter=t=>{const e=[...t];this.format(e);const i=e.join("").trim(),s=i.toLowerCase(),r=[...s];this.filterTlds(r),this.filterBadWords(r),this.filterDomains(r),this.filterFragments(r);for(let t=0;t{this.readBadWords(t),this.readDomains(e),this.readFragments(i),this.readTld(s)};static readTld=t=>{const e=t.g4;for(let i=0;it.g1))};static readBadWords=t=>{const e=t.g4;for(let i=0;it.g1));const e=new Array(t.g1).fill([]).map((()=>[t.g1b,t.g1b]));e.length>0&&(this.badCombinations[i]=e)}};static readDomains=t=>{const e=t.g4;for(let i=0;it.g1))};static readFragments=t=>{const e=t.g4;for(let i=0;i{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.PERIOD),this.filterBadCombinations(null,i,this.SLASH);for(let s=0;s{for(let e=0;e<2;e++)for(let e=this.bads.length-1;e>=0;e--)this.filterBadCombinations(this.badCombinations[e],t,this.bads[e])};static filterDomains=t=>{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.AMPERSAT),this.filterBadCombinations(null,i,this.PERIOD);for(let s=this.domains.length-1;s>=0;s--)this.filterDomain(i,e,this.domains[s],t)};static filterFragments=t=>{for(let e=0;e=0&&r{if(this.isNumericalChars(t))return!0;const e=this.getInteger(t),i=this.fragments,s=i.length;if(e===i[0]||e===i[s-1])return!0;let r=0,a=s-1;for(;r<=a;){const t=Math.floor((r+a)/2);if(e===i[t])return!0;e{if(t.length>6)return 0;let e=0;for(let i=0;i{for(let i=e;i=0;i++)if(this.isNumerical(t[i]))return i;return-1};static indexOfNonNumber=(t,e)=>{for(let i=t;i=0;i++)if(!this.isNumerical(e[i]))return i;return e.length};static getEmulatedDomainCharLen=(t,e,i)=>e==i||"o"==e&&"0"==i?1:"o"==e&&"("==i&&")"==t?2:"c"!=e||"("!=i&&"<"!=i&&"["!=i?"e"==e&&"€"==i||"s"==e&&"$"==i||"l"==e&&"i"==i?1:0:1;static filterDomain=(t,e,i,s)=>{const r=i.length,a=s.length;for(let n=0;n<=a-r;n++){const{matched:r,currentIndex:a}=this.findMatchingDomain(n,i,s);if(!r)continue;const o=this.prefixSymbolStatus(n,s,3,e,["@"]),l=this.suffixSymbolStatus(a-1,s,3,t,[".",","]);(o>2||l>2)&&this.maskChars(n,a,s)}};static findMatchingDomain=(t,e,i)=>{const s=e.length;let r=t,a=0;for(;r0)r+=l,a++;else{if(0===a)break;const i=this.getEmulatedDomainCharLen(o,String.fromCharCode(e[a-1]),n);if(i>0)r+=i,1===a&&t++;else{if(a>=s||!this.isSymbol(n))break;r++}}}return{matched:a>=s,currentIndex:r}};static filterBadCombinations=(t,e,i)=>{if(!(i.length>e.length))for(let s=0;s<=e.length-i.length;s++){let r=s;const{currentIndex:a,badIndex:n,hasSymbol:o,hasNumber:l,hasDigit:h}=this.processBadCharacters(e,i,r);r=a;let c=e[r],f=r+1=i.length)||l&&h)continue;let d,u=!0;if(o){let t=!1,i=!1;if((s-1<0||this.isSymbol(e[s-1])&&"'"!=e[s-1])&&(t=!0),(r>=e.length||this.isSymbol(e[r])&&"'"!=e[r])&&(i=!0),!t||!i){let i=!1;for(d=s-2,t&&(d=s);!i&&d=0&&(!this.isSymbol(e[d])||"'"==e[d])){const t=[];let s;for(s=0;s<3&&d+s=0&&(!this.isSymbol(e[d-1])||"'"==e[d-1])&&(r=!1),r&&!this.isBadFragment(t)&&(i=!0)}d++}i||(u=!1)}}else{c=" ",s-1>=0&&(c=e[s-1]),f=" ",r{let s=i,r=0,a=0,n=!1,o=!1,l=!1;for(;s=t.length||o&&l);){const h=t[s],c=s+10)1===f&&this.isNumerical(h)&&(o=!0),2===f&&(this.isNumerical(h)||this.isNumerical(c))&&(o=!0),s+=f,r++;else{if(0===r)break;let t;if((t=this.getEmulatedBadCharLen(c,String.fromCharCode(e[r-1]),h))>0)s+=t;else{if(r>=e.length||!this.isNotLowercaseAlpha(h))break;if(this.isSymbol(h)&&"'"!==h&&(n=!0),this.isNumerical(h)&&(l=!0),s++,a++,100*a/(s-i)>90)break}}}return{currentIndex:s,badIndex:r,hasSymbol:n,hasNumber:o,hasDigit:l}};static getEmulatedBadCharLen=(t,e,i)=>{if(e==i)return 1;if(e>="a"&&e<="m"){if("a"==e)return"4"!=i&&"@"!=i&&"^"!=i?"/"==i&&"\\"==t?2:0:1;if("b"==e)return"6"!=i&&"8"!=i?"1"==i&&"3"==t?2:0:1;if("c"==e)return"("!=i&&"<"!=i&&"{"!=i&&"["!=i?0:1;if("d"==e)return"["==i&&")"==t?2:0;if("e"==e)return"3"!=i&&"€"!=i?0:1;if("f"==e)return"p"==i&&"h"==t?2:"£"==i?1:0;if("g"==e)return"9"!=i&&"6"!=i?0:1;if("h"==e)return"#"==i?1:0;if("i"==e)return"y"!=i&&"l"!=i&&"j"!=i&&"1"!=i&&"!"!=i&&":"!=i&&";"!=i&&"|"!=i?0:1;if("j"==e)return 0;if("k"==e)return 0;if("l"==e)return"1"!=i&&"|"!=i&&"i"!=i?0:1;if("m"==e)return 0}if(e>="n"&&e<="z"){if("n"==e)return 0;if("o"==e)return"0"!=i&&"*"!=i?"("==i&&")"==t||"["==i&&"]"==t||"{"==i&&"}"==t||"<"==i&&">"==t?2:0:1;if("p"==e)return 0;if("q"==e)return 0;if("r"==e)return 0;if("s"==e)return"5"!=i&&"z"!=i&&"$"!=i&&"2"!=i?0:1;if("t"==e)return"7"!=i&&"+"!=i?0:1;if("u"==e)return"v"==i?1:"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("v"==e)return"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("w"==e)return"v"==i&&"v"==t?2:0;if("x"==e)return")"==i&&"("==t||"}"==i&&"{"==t||"]"==i&&"["==t||">"==i&&"<"==t?2:0;if("y"==e)return 0;if("z"==e)return 0}return e>="0"&&e<="9"?"0"==e?"o"==i||"O"==i?1:"("==i&&")"==t||"{"==i&&"}"==t||"["==i&&"]"==t?2:0:"1"==e&&"l"==i?1:0:","==e?"."==i?1:0:"."==e?","==i?1:0:"!"==e&&"i"==i?1:0};static comboMatches=(t,e,i)=>{let s=0,r=e.length-1;for(;s<=r;){const a=Math.floor((s+r)/2);if(e[a][0]===t&&e[a][1]===i)return!0;tthis.isLowercaseAlpha(t)?t.charCodeAt(0)+1-"a".charCodeAt(0):"'"==t?28:this.isNumerical(t)?t.charCodeAt(0)+29-"0".charCodeAt(0):27;static filterTld=(t,e,i,s,r)=>{if(!(s.length>i.length))for(let a=0;a<=i.length-s.length;a++){const{currentIndex:n,tldIndex:o}=this.processTlds(i,s,a);if(o0&&c>0&&(l=!0),2==e&&(h>2&&c>0||h>0&&c>2)&&(l=!0),3==e&&h>0&&c>2&&(l=!0),!l)continue;let f,d=a,u=n-1,g=!1;if(h>2){if(4==h)for(g=!1,f=a-1;f>=0;f--)if(g){if("*"!=r[f])break;d=f}else"*"==r[f]&&(d=f,g=!0);for(g=!1,f=d-1;f>=0;f--)if(g){if(this.isSymbol(i[f]))break;d=f}else this.isSymbol(i[f])||(g=!0,d=f)}if(c>2){if(4==c)for(g=!1,f=u+1;f{let s=0;for(;i0)i+=n,s++;else{if(0===s)break;let t;if((t=this.getEmulatedDomainCharLen(a,String.fromCharCode(e[s-1]),r))>0)i+=t;else{if(!this.isSymbol(r))break;i++}}}return{currentIndex:i,tldIndex:s}};static isSymbol=t=>!this.isAlpha(t)&&!this.isNumerical(t);static isNotLowercaseAlpha=t=>!this.isLowercaseAlpha(t)||"v"==t||"x"==t||"j"==t||"q"==t||"z"==t;static isAlpha=t=>this.isLowercaseAlpha(t)||this.isUppercaseAlpha(t);static isNumerical=t=>t>="0"&&t<="9";static isLowercaseAlpha=t=>t>="a"&&t<="z";static isUppercaseAlpha=t=>t>="A"&&t<="Z";static isNumericalChars=t=>{for(let e=0;e{for(let s=t;s{let i=0;for(let s=e-1;s>=0&&this.isSymbol(t[s]);s--)"*"===t[s]&&i++;return i};static maskedCountForwards=(t,e)=>{let i=0;for(let s=e+1;s(r?this.maskedCountBackwards(e,i):this.maskedCountForwards(e,i))>=s?4:this.isSymbol(r?t[i-1]:t[i+1])?1:0;static prefixSymbolStatus=(t,e,i,s,r)=>{if(0===t)return 2;for(let i=t-1;i>=0&&this.isSymbol(e[i]);i--)if(r.includes(e[i]))return 3;return this.maskedCharsStatus(e,s,t,i,!0)};static suffixSymbolStatus=(t,e,i,s,r)=>{if(t+1===e.length)return 2;for(let i=t+1;i{let e=0;for(let i=0;it>=" "&&t<=""||" "==t||"\n"==t||"\t"==t||"£"==t||"€"==t;static replaceUppercases=(t,e)=>{for(let i=0;i{let e=!0;for(let i=0;i{this.resizeToFit&&this.resize(window.innerWidth,window.innerHeight)}),!1),window.addEventListener("keydown",this.keyDown),window.addEventListener("keyup",this.keyUp),window.addEventListener("mousedown",this.mousePressed),await this.showProgress(0,"Loading..."),await this.load();for(let t=0;t<10;t++)this.otim[t]=Date.now();let t,e=0,i=256,s=1,r=0;for(;this.state>=0;){if(this.state>0&&(this.state--,0===this.state))return void this.shutdown();const a=i,n=s;i=300,s=1,t=Date.now();const o=this.otim[e];if(0===o?(i=a,s=n):t>o&&(i=Math.trunc(2560*this.deltime/(t-o))),i<25?i=25:i>256&&(i=256,s=Math.trunc(this.deltime-(t-o)/10)),this.otim[e]=t,e=(e+1)%10,s>1)for(let t=0;t<10;t++)0!==this.otim[t]&&(this.otim[t]+=s);for(s0&&(this.fps=Math.trunc(1e3*i/(256*this.deltime)));const l=performance.now();await this.draw(),this.frameTime[this.fpos]=(performance.now()-l)/1e3,this.fpos=(this.fpos+1)%this.frameTime.length}-1==this.state&&this.shutdown()}shutdown(){this.state=-2,this.unload()}setLoopRate(t){this.deltime=1e3/t}start(){this.state>=0&&(this.state=0)}stop(){this.state>=0&&(this.state=4e3/this.deltime)}destroy(){this.state=-1}async load(){}update(){}unload(){}async draw(){}refresh(){}async showProgress(t,e){const i=this.ctx,s=this.width,r=this.height;this.redrawScreen&&(i.fillStyle="black",i.clearRect(0,0,s,r),this.redrawScreen=!1);const a=r/2-18;i.fillStyle="rgb(140, 17, 17)",i.rect(s/2-152,a,304,34),i.fillRect(s/2-150,a+2,3*t,30),i.fillStyle="black",i.fillRect(s/2-150+3*t,a+2,300-3*t,30),i.font="bold 13px helvetica, sans-serif",i.textAlign="center",i.fillStyle="white",i.fillText(e,s/2,a+22),await u(5)}keyDown=t=>{this.idleCycles=0;const e=t.keyCode;let i=t.key.charCodeAt(0);83!==i&&(i<30&&(i=0),37==e?i=1:39==e?i=2:38==e?i=3:40==e?i=4:17==e?i=5:8==e||127==e?i=8:9==e?i=9:10==e?i=10:e>=112&&e<=123?i=e+1008-112:36==e?i=1e3:35==e?i=1001:33==e?i=1002:34==e&&(i=1003),i>0&&i<128&&(this.actionKey[i]=1),i>4&&(this.keyQueue[this.keyQueueWritePos]=i,this.keyQueueWritePos=this.keyQueueWritePos+1&127))};keyUp=t=>{this.idleCycles=0;let e=t.key.charCodeAt(0);"ArrowLeft"==t.key?e=1:"ArrowRight"==t.key?e=2:"ArrowUp"==t.key?e=3:"ArrowDown"==t.key&&(e=4),this.actionKey[e]=0};pollKey(){let t=-1;return this.keyQueueWritePos!=this.keyQueueReadPos&&(t=this.keyQueue[this.keyQueueReadPos],this.keyQueueReadPos=this.keyQueueReadPos+1&127),t}mousePressed=t=>{let e=t.x,i=t.y;const{top:s,left:r}=this.getInsets;e-=r,i-=s,this.idleCycles=0,this.mouseClickX=e,this.mouseClickY=i,2===t.buttons?(this.mouseClickButton=2,this.mouseButton=2):1===t.buttons&&(this.mouseClickButton=1,this.mouseButton=1)};get getInsets(){const t=this.canvas.getBoundingClientRect(),e=window.getComputedStyle(this.canvas),i=parseFloat(e.paddingLeft||"0"),s=parseFloat(e.paddingTop||"0"),r=parseFloat(e.borderLeftWidth||"0"),a=parseFloat(e.borderTopWidth||"0"),n=t.left+r+i;return{top:t.top+a+s,left:n}}get ms(){const t=this.frameTime.length;let e=0;for(let i=0;i{Object.getOwnPropertyDescriptor(r.ready,t)||Object.defineProperty(r.ready,t,{get:()=>W("You are getting "+t+" on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js"),set:()=>W("You are setting "+t+" on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js")})}));var a=Object.assign({},r),n=[],o="object"==typeof window,l="function"==typeof importScripts,h="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,c=!o&&!h&&!l;if(r.ENVIRONMENT)throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)");var f,d,u,g="";if(h){if("undefined"==typeof process||!process.release||"node"!==process.release.name)throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");var m,p;g=l?require("path").dirname(g)+"/":__dirname+"/";var w=()=>{p||(m=require("fs"),p=require("path"))};f=(t,e)=>(w(),t=p.normalize(t),m.readFileSync(t,e?void 0:"utf8")),u=t=>{var e=f(t,!0);return e.buffer||(e=new Uint8Array(e)),L(e.buffer),e},d=(t,e,i)=>{w(),t=p.normalize(t),m.readFile(t,(function(t,s){t?i(t):e(s.buffer)}))},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),n=process.argv.slice(2),process.on("uncaughtException",(function(t){if(!(t instanceof st))throw t})),process.on("unhandledRejection",(function(t){throw t})),r.inspect=function(){return"[Emscripten Module object]"}}else if(c){if("object"==typeof process&&"function"==typeof require||"object"==typeof window||"function"==typeof importScripts)throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");"undefined"!=typeof read&&(f=function(t){return read(t)}),u=function(t){let e;return"function"==typeof readbuffer?new Uint8Array(readbuffer(t)):(e=read(t,"binary"),L("object"==typeof e),e)},d=function(t,e,i){setTimeout((()=>e(u(t))),0)},"undefined"!=typeof scriptArgs?n=scriptArgs:void 0!==arguments&&(n=arguments),"undefined"!=typeof print&&("undefined"==typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!=typeof printErr?printErr:print)}else{if(!o&&!l)throw new Error("environment detection error");if(l?g=self.location.href:"undefined"!=typeof document&&document.currentScript&&(g=document.currentScript.src),F&&(g=F),g=0!==g.indexOf("blob:")?g.substr(0,g.replace(/[?#].*/,"").lastIndexOf("/")+1):"","object"!=typeof window&&"function"!=typeof importScripts)throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");f=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},l&&(u=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),d=(t,e,i)=>{var s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="arraybuffer",s.onload=()=>{200==s.status||0==s.status&&s.response?e(s.response):i()},s.onerror=i,s.send(null)}}r.print||console.log.bind(console);var b,y,v,x=r.printErr||console.warn.bind(console);function C(t,e){Object.getOwnPropertyDescriptor(r,t)||Object.defineProperty(r,t,{configurable:!0,get:function(){W("Module."+t+" has been replaced with plain "+e+" (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)")}})}function S(t){return"FS_createPath"===t||"FS_createDataFile"===t||"FS_createPreloadedFile"===t||"FS_unlink"===t||"addRunDependency"===t||"FS_createLazyFile"===t||"FS_createDevice"===t||"removeRunDependency"===t}Object.assign(r,a),a=null,b="fetchSettings",Object.getOwnPropertyDescriptor(r,b)&&W("`Module."+b+"` was supplied but `"+b+"` not included in INCOMING_MODULE_JS_API"),r.arguments&&(n=r.arguments),C("arguments","arguments_"),r.thisProgram&&r.thisProgram,C("thisProgram","thisProgram"),r.quit&&r.quit,C("quit","quit_"),L(void 0===r.memoryInitializerPrefixURL,"Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead"),L(void 0===r.pthreadMainPrefixURL,"Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead"),L(void 0===r.cdInitializerPrefixURL,"Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead"),L(void 0===r.filePackagePrefixURL,"Module.filePackagePrefixURL option was removed, use Module.locateFile instead"),L(void 0===r.read,"Module.read option was removed (modify read_ in JS)"),L(void 0===r.readAsync,"Module.readAsync option was removed (modify readAsync in JS)"),L(void 0===r.readBinary,"Module.readBinary option was removed (modify readBinary in JS)"),L(void 0===r.setWindowTitle,"Module.setWindowTitle option was removed (modify setWindowTitle in JS)"),L(void 0===r.TOTAL_MEMORY,"Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY"),C("read","read_"),C("readAsync","readAsync"),C("readBinary","readBinary"),C("setWindowTitle","setWindowTitle"),L(!c,"shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable."),r.wasmBinary&&(y=r.wasmBinary),C("wasmBinary","wasmBinary"),r.noExitRuntime,C("noExitRuntime","noExitRuntime"),"object"!=typeof WebAssembly&&W("no native wasm support detected");var T,A,k,I,_,O,P,M,E=!1;function L(t,e){t||W("Assertion failed"+(e?": "+e:""))}function B(t){T=t,r.HEAP8=A=new Int8Array(t),r.HEAP16=I=new Int16Array(t),r.HEAP32=_=new Int32Array(t),r.HEAPU8=k=new Uint8Array(t),r.HEAPU16=new Uint16Array(t),r.HEAPU32=O=new Uint32Array(t),r.HEAPF32=P=new Float32Array(t),r.HEAPF64=M=new Float64Array(t)}"undefined"!=typeof TextDecoder&&new TextDecoder("utf8");var R=5242880;r.TOTAL_STACK&&L(R===r.TOTAL_STACK,"the stack size can no longer be determined at runtime");var Y=r.INITIAL_MEMORY||16777216;function D(){if(!E){var t=ct(),e=O[t>>2],i=O[t+4>>2];34821223==e&&2310721022==i||W("Stack overflow! Stack cookie has been overwritten at 0x"+t.toString(16)+", expected hex dwords 0x89BACDFE and 0x2135467, but received 0x"+i.toString(16)+" 0x"+e.toString(16)),1668509029!==O[0]&&W("Runtime error: The application has corrupted its heap memory area (address zero)!")}}C("INITIAL_MEMORY","INITIAL_MEMORY"),L(Y>=R,"INITIAL_MEMORY should be larger than TOTAL_STACK, was "+Y+"! (TOTAL_STACK="+R+")"),L("undefined"!=typeof Int32Array&&"undefined"!=typeof Float64Array&&null!=Int32Array.prototype.subarray&&null!=Int32Array.prototype.set,"JS engine does not provide full typed array support"),L(!r.wasmMemory,"Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally"),L(16777216==Y,"Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically"),function(){var t=new Int16Array(1),e=new Int8Array(t.buffer);if(t[0]=25459,115!==e[0]||99!==e[1])throw"Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)"}();var U=[],G=[],H=[],X=!1;L(Math.imul,"This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),L(Math.fround,"This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),L(Math.clz32,"This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),L(Math.trunc,"This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill");var N=0,z=null,V=null,j={};function W(t){r.onAbort&&r.onAbort(t),x(t="Aborted("+t+")"),E=!0;var e=new WebAssembly.RuntimeError(t);throw s(e),e}var q={error:function(){W("Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM")},init:function(){q.error()},createDataFile:function(){q.error()},createPreloadedFile:function(){q.error()},createLazyFile:function(){q.error()},open:function(){q.error()},mkdev:function(){q.error()},registerDevice:function(){q.error()},analyzePath:function(){q.error()},loadFilesFromDB:function(){q.error()},ErrnoError:function(){q.error()}};r.FS_createDataFile=q.createDataFile,r.FS_createPreloadedFile=q.createPreloadedFile;var Z,$,K,J;function Q(t){return t.startsWith("data:application/octet-stream;base64,")}function tt(t){return t.startsWith("file://")}function et(t,e){return function(){var i=t,s=e;return e||(s=r.asm),L(X,"native function `"+i+"` called before runtime initialization"),s[t]||L(s[t],"exported native function `"+i+"` not found"),s[t].apply(null,arguments)}}function it(t){try{if(t==Z&&y)return new Uint8Array(y);if(u)return u(t);throw"both async and sync fetching of the wasm failed"}catch(t){W(t)}}function st(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function rt(t){for(;t.length>0;)t.shift()(r)}function at(t){at.shown||(at.shown={}),at.shown[t]||(at.shown[t]=1,h&&(t="warning: "+t),x(t))}function nt(t){try{return v.grow(t-T.byteLength+65535>>>16),B(v.buffer),1}catch(e){x("emscripten_realloc_buffer: Attempted to grow heap from "+T.byteLength+" bytes to "+t+" bytes, but got error: "+e)}}r.locateFile?Q(Z="tinymidipcm.wasm")||($=Z,Z=r.locateFile?r.locateFile($,g):g+$):Z=new URL(i(621),i.b).toString();var ot,lt={emscripten_memcpy_big:function(t,e,i){k.copyWithin(t,e,e+i)},emscripten_resize_heap:function(t){var e=k.length;L((t>>>=0)>e);var i,s=2147483648;if(t>s)return x("Cannot enlarge memory, asked to go up to "+t+" bytes, but the limit is "+s+" bytes!"),!1;for(var r=1;r<=4;r*=2){var a=e*(1+.2/r);a=Math.min(a,t+100663296);var n=Math.min(s,(i=Math.max(t,a))+(65536-i%65536)%65536);if(nt(n))return!0}return x("Failed to grow the heap from "+e+" bytes to "+n+" bytes, not enough memory!"),!1}},ht=(function(){var t,e={env:lt,wasi_snapshot_preview1:lt};function i(t,e){var i,s=t.exports;r.asm=s,L(v=r.asm.memory,"memory not found in wasm exports"),B(v.buffer),L(r.asm.__indirect_function_table,"table not found in wasm exports"),i=r.asm.__wasm_call_ctors,G.unshift(i),function(t){if(N--,r.monitorRunDependencies&&r.monitorRunDependencies(N),t?(L(j[t]),delete j[t]):x("warning: run dependency removed without ID"),0==N&&(null!==z&&(clearInterval(z),z=null),V)){var e=V;V=null,e()}}("wasm-instantiate")}t="wasm-instantiate",N++,r.monitorRunDependencies&&r.monitorRunDependencies(N),t?(L(!j[t]),j[t]=1,null===z&&"undefined"!=typeof setInterval&&(z=setInterval((function(){if(E)return clearInterval(z),void(z=null);var t=!1;for(var e in j)t||(t=!0,x("still waiting on run dependencies:")),x("dependency: "+e);t&&x("(end of list)")}),1e4))):x("warning: run dependency added without ID");var a=r;function n(t){L(r===a,"the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?"),a=null,i(t.instance)}function c(t){return function(){if(!y&&(o||l)){if("function"==typeof fetch&&!tt(Z))return fetch(Z,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw"failed to load wasm binary file at '"+Z+"'";return t.arrayBuffer()})).catch((function(){return it(Z)}));if(d)return new Promise((function(t,e){d(Z,(function(e){t(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return it(Z)}))}().then((function(t){return WebAssembly.instantiate(t,e)})).then((function(t){return t})).then(t,(function(t){x("failed to asynchronously prepare wasm: "+t),tt(Z)&&x("warning: Loading from a file URI ("+Z+") is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing"),W(t)}))}if(r.instantiateWasm)try{return r.instantiateWasm(e,i)}catch(t){x("Module.instantiateWasm callback failed with error: "+t),s(t)}(y||"function"!=typeof WebAssembly.instantiateStreaming||Q(Z)||tt(Z)||h||"function"!=typeof fetch?c(n):fetch(Z,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,e).then(n,(function(t){return x("wasm streaming compile failed: "+t),x("falling back to ArrayBuffer instantiation"),c(n)}))}))).catch(s)}(),r.___wasm_call_ctors=et("__wasm_call_ctors"),r._malloc=et("malloc"),r._free=et("free"),r._tsf_load_memory=et("tsf_load_memory"),r._tsf_close=et("tsf_close"),r._tsf_reset=et("tsf_reset"),r._tsf_set_output=et("tsf_set_output"),r._tsf_set_max_voices=et("tsf_set_max_voices"),r._realloc=et("realloc"),r._tsf_channel_set_presetnumber=et("tsf_channel_set_presetnumber"),r._tsf_channel_set_bank_preset=et("tsf_channel_set_bank_preset"),r._tml_load_memory=et("tml_load_memory"),r._midi_render=et("midi_render"),r.___errno_location=et("__errno_location"),r._fflush=et("fflush"),r._emscripten_stack_init=function(){return(ht=r._emscripten_stack_init=r.asm.emscripten_stack_init).apply(null,arguments)}),ct=(r._emscripten_stack_get_free=function(){return(r._emscripten_stack_get_free=r.asm.emscripten_stack_get_free).apply(null,arguments)},r._emscripten_stack_get_base=function(){return(r._emscripten_stack_get_base=r.asm.emscripten_stack_get_base).apply(null,arguments)},r._emscripten_stack_get_end=function(){return(ct=r._emscripten_stack_get_end=r.asm.emscripten_stack_get_end).apply(null,arguments)});function ft(t){function i(){ot||(ot=!0,r.calledRun=!0,E||(L(!X),X=!0,D(),rt(G),e(r),r.onRuntimeInitialized&&r.onRuntimeInitialized(),L(!r._main,'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]'),function(){if(D(),r.postRun)for("function"==typeof r.postRun&&(r.postRun=[r.postRun]);r.postRun.length;)t=r.postRun.shift(),H.unshift(t);var t;rt(H)}()))}var s;t=t||n,N>0||(ht(),L(0==(3&(s=ct()))),O[s>>2]=34821223,O[s+4>>2]=2310721022,O[0]=1668509029,function(){if(r.preRun)for("function"==typeof r.preRun&&(r.preRun=[r.preRun]);r.preRun.length;)t=r.preRun.shift(),U.unshift(t);var t;rt(U)}(),N>0||(r.setStatus?(r.setStatus("Running..."),setTimeout((function(){setTimeout((function(){r.setStatus("")}),1),i()}),1)):i(),D()))}if(r.stackSave=et("stackSave"),r.stackRestore=et("stackRestore"),r.stackAlloc=et("stackAlloc"),r.setValue=function(t,e,i="i8"){switch(i.endsWith("*")&&(i="*"),i){case"i1":case"i8":A[t>>0]=e;break;case"i16":I[t>>1]=e;break;case"i32":_[t>>2]=e;break;case"i64":J=[e>>>0,(K=e,+Math.abs(K)>=1?K>0?(0|Math.min(+Math.floor(K/4294967296),4294967295))>>>0:~~+Math.ceil((K-+(~~K>>>0))/4294967296)>>>0:0)],_[t>>2]=J[0],_[t+4>>2]=J[1];break;case"float":P[t>>2]=e;break;case"double":M[t>>3]=e;break;case"*":O[t>>2]=e;break;default:W("invalid type for setValue: "+i)}},r.getValue=function(t,e="i8"){switch(e.endsWith("*")&&(e="*"),e){case"i1":case"i8":return A[t>>0];case"i16":return I[t>>1];case"i32":case"i64":return _[t>>2];case"float":return P[t>>2];case"double":return M[t>>3];case"*":return O[t>>2];default:W("invalid type for getValue: "+e)}return null},["run","UTF8ArrayToString","UTF8ToString","stringToUTF8Array","stringToUTF8","lengthBytesUTF8","addOnPreRun","addOnInit","addOnPreMain","addOnExit","addOnPostRun","addRunDependency","removeRunDependency","FS_createFolder","FS_createPath","FS_createDataFile","FS_createPreloadedFile","FS_createLazyFile","FS_createLink","FS_createDevice","FS_unlink","getLEB","getFunctionTables","alignFunctionTables","registerFunctions","prettyPrint","getCompilerSetting","print","printErr","callMain","abort","keepRuntimeAlive","wasmMemory","stackAlloc","stackSave","stackRestore","getTempRet0","setTempRet0","writeStackCookie","checkStackCookie","ptrToString","zeroMemory","stringToNewUTF8","exitJS","getHeapMax","emscripten_realloc_buffer","ENV","ERRNO_CODES","ERRNO_MESSAGES","setErrNo","inetPton4","inetNtop4","inetPton6","inetNtop6","readSockaddr","writeSockaddr","DNS","getHostByName","Protocols","Sockets","getRandomDevice","warnOnce","traverseStack","UNWIND_CACHE","convertPCtoSourceLocation","readAsmConstArgsArray","readAsmConstArgs","mainThreadEM_ASM","jstoi_q","jstoi_s","getExecutableName","listenOnce","autoResumeAudioContext","dynCallLegacy","getDynCaller","dynCall","handleException","runtimeKeepalivePush","runtimeKeepalivePop","callUserCallback","maybeExit","safeSetTimeout","asmjsMangle","asyncLoad","alignMemory","mmapAlloc","writeI53ToI64","writeI53ToI64Clamped","writeI53ToI64Signaling","writeI53ToU64Clamped","writeI53ToU64Signaling","readI53FromI64","readI53FromU64","convertI32PairToI53","convertI32PairToI53Checked","convertU32PairToI53","getCFunc","ccall","cwrap","uleb128Encode","sigToWasmTypes","generateFuncType","convertJsFunctionToWasm","freeTableIndexes","functionsInTableMap","getEmptyTableSlot","updateTableMap","addFunction","removeFunction","reallyNegative","unSign","strLen","reSign","formatString","PATH","PATH_FS","intArrayFromString","intArrayToString","AsciiToString","stringToAscii","UTF16Decoder","UTF16ToString","stringToUTF16","lengthBytesUTF16","UTF32ToString","stringToUTF32","lengthBytesUTF32","allocateUTF8","allocateUTF8OnStack","writeStringToMemory","writeArrayToMemory","writeAsciiToMemory","SYSCALLS","getSocketFromFD","getSocketAddress","JSEvents","registerKeyEventCallback","specialHTMLTargets","maybeCStringToJsString","findEventTarget","findCanvasEventTarget","getBoundingClientRect","fillMouseEventData","registerMouseEventCallback","registerWheelEventCallback","registerUiEventCallback","registerFocusEventCallback","fillDeviceOrientationEventData","registerDeviceOrientationEventCallback","fillDeviceMotionEventData","registerDeviceMotionEventCallback","screenOrientation","fillOrientationChangeEventData","registerOrientationChangeEventCallback","fillFullscreenChangeEventData","registerFullscreenChangeEventCallback","JSEvents_requestFullscreen","JSEvents_resizeCanvasForFullscreen","registerRestoreOldStyle","hideEverythingExceptGivenElement","restoreHiddenElements","setLetterbox","currentFullscreenStrategy","restoreOldWindowedStyle","softFullscreenResizeWebGLRenderTarget","doRequestFullscreen","fillPointerlockChangeEventData","registerPointerlockChangeEventCallback","registerPointerlockErrorEventCallback","requestPointerLock","fillVisibilityChangeEventData","registerVisibilityChangeEventCallback","registerTouchEventCallback","fillGamepadEventData","registerGamepadEventCallback","registerBeforeUnloadEventCallback","fillBatteryEventData","battery","registerBatteryEventCallback","setCanvasElementSize","getCanvasElementSize","demangle","demangleAll","jsStackTrace","stackTrace","ExitStatus","getEnvStrings","checkWasiClock","flush_NO_FILESYSTEM","dlopenMissingError","createDyncallWrapper","setImmediateWrapped","clearImmediateWrapped","polyfillSetImmediate","uncaughtExceptionCount","exceptionLast","exceptionCaught","ExceptionInfo","exception_addRef","exception_decRef","Browser","setMainLoop","wget","FS","MEMFS","TTY","PIPEFS","SOCKFS","_setNetworkCallback","tempFixedLengthArray","miniTempWebGLFloatBuffers","heapObjectForWebGLType","heapAccessShiftForWebGLHeap","GL","emscriptenWebGLGet","computeUnpackAlignedImageSize","emscriptenWebGLGetTexPixelData","emscriptenWebGLGetUniform","webglGetUniformLocation","webglPrepareUniformLocationsBeforeFirstUse","webglGetLeftBracePos","emscriptenWebGLGetVertexAttrib","writeGLArray","AL","SDL_unicode","SDL_ttfContext","SDL_audio","SDL","SDL_gfx","GLUT","EGL","GLFW_Window","GLFW","GLEW","IDBStore","runAndAbortIfError","ALLOC_NORMAL","ALLOC_STACK","allocate"].forEach((function(t){Object.getOwnPropertyDescriptor(r,t)||Object.defineProperty(r,t,{configurable:!0,get:function(){var e="'"+t+"' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)";S(t)&&(e+=". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you"),W(e)}})})),["ptrToString","zeroMemory","stringToNewUTF8","exitJS","setErrNo","inetPton4","inetNtop4","inetPton6","inetNtop6","readSockaddr","writeSockaddr","getHostByName","getRandomDevice","traverseStack","convertPCtoSourceLocation","readAsmConstArgs","mainThreadEM_ASM","jstoi_q","jstoi_s","getExecutableName","listenOnce","autoResumeAudioContext","dynCallLegacy","getDynCaller","dynCall","runtimeKeepalivePush","runtimeKeepalivePop","callUserCallback","maybeExit","safeSetTimeout","asmjsMangle","asyncLoad","alignMemory","mmapAlloc","writeI53ToI64","writeI53ToI64Clamped","writeI53ToI64Signaling","writeI53ToU64Clamped","writeI53ToU64Signaling","readI53FromI64","readI53FromU64","convertI32PairToI53","convertI32PairToI53Checked","convertU32PairToI53","getCFunc","ccall","cwrap","uleb128Encode","sigToWasmTypes","generateFuncType","convertJsFunctionToWasm","getEmptyTableSlot","updateTableMap","addFunction","removeFunction","reallyNegative","unSign","strLen","reSign","formatString","intArrayFromString","intArrayToString","AsciiToString","stringToAscii","UTF16ToString","stringToUTF16","lengthBytesUTF16","UTF32ToString","stringToUTF32","lengthBytesUTF32","allocateUTF8","allocateUTF8OnStack","writeStringToMemory","writeAsciiToMemory","getSocketFromFD","getSocketAddress","registerKeyEventCallback","maybeCStringToJsString","findEventTarget","findCanvasEventTarget","getBoundingClientRect","fillMouseEventData","registerMouseEventCallback","registerWheelEventCallback","registerUiEventCallback","registerFocusEventCallback","fillDeviceOrientationEventData","registerDeviceOrientationEventCallback","fillDeviceMotionEventData","registerDeviceMotionEventCallback","screenOrientation","fillOrientationChangeEventData","registerOrientationChangeEventCallback","fillFullscreenChangeEventData","registerFullscreenChangeEventCallback","JSEvents_requestFullscreen","JSEvents_resizeCanvasForFullscreen","registerRestoreOldStyle","hideEverythingExceptGivenElement","restoreHiddenElements","setLetterbox","softFullscreenResizeWebGLRenderTarget","doRequestFullscreen","fillPointerlockChangeEventData","registerPointerlockChangeEventCallback","registerPointerlockErrorEventCallback","requestPointerLock","fillVisibilityChangeEventData","registerVisibilityChangeEventCallback","registerTouchEventCallback","fillGamepadEventData","registerGamepadEventCallback","registerBeforeUnloadEventCallback","fillBatteryEventData","battery","registerBatteryEventCallback","setCanvasElementSize","getCanvasElementSize","getEnvStrings","checkWasiClock","flush_NO_FILESYSTEM","createDyncallWrapper","setImmediateWrapped","clearImmediateWrapped","polyfillSetImmediate","ExceptionInfo","exception_addRef","exception_decRef","setMainLoop","_setNetworkCallback","heapObjectForWebGLType","heapAccessShiftForWebGLHeap","emscriptenWebGLGet","computeUnpackAlignedImageSize","emscriptenWebGLGetTexPixelData","emscriptenWebGLGetUniform","webglGetUniformLocation","webglPrepareUniformLocationsBeforeFirstUse","webglGetLeftBracePos","emscriptenWebGLGetVertexAttrib","writeGLArray","SDL_unicode","SDL_ttfContext","SDL_audio","GLFW_Window","runAndAbortIfError","ALLOC_NORMAL","ALLOC_STACK","allocate"].forEach((function(t){"undefined"==typeof globalThis||Object.getOwnPropertyDescriptor(globalThis,t)||Object.defineProperty(globalThis,t,{configurable:!0,get:function(){var e="`"+t+"` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line";S(t)&&(e+=". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you"),at(e)}})})),V=function t(){ot||ft(),ot||(V=t)},r.preInit)for("function"==typeof r.preInit&&(r.preInit=[r.preInit]);r.preInit.length>0;)r.preInit.pop()();return ft(),t.ready}),R=class{constructor(t={}){this.wasmModule=void 0,this.soundfontBufferPtr=0,this.soundfontPtr=0,this.midiBufferPtr=0,this.renderInterval=t.renderInterval||100,this.sampleRate=t.sampleRate||44100,this.channels=t.channels||2,this.gain=t.gain||0,t.bufferSize?this.bufferSize=t.bufferSize:this.setBufferDuration(1),this.onPCMData=t.onPCMData||(()=>{}),this.onRenderEnd=t.onRenderEnd||(()=>{}),this.renderTimer=void 0,this.test=0}async init(){if(!this.wasmModule){if("undefined"!=typeof process){const{dirname:t}=await import("path"),{createRequire:e}=await import("module");globalThis.__dirname=t("file:///home/runner/work/Client2/Client2/src/js/vendor/tinymidipcm/index.js"),globalThis.require=e("file:///home/runner/work/Client2/Client2/src/js/vendor/tinymidipcm/index.js")}this.wasmModule=await B(),this.pcmBufferPtr=this.wasmModule._malloc(this.bufferSize),this.msecsPtr=this.wasmModule._malloc(8)}}setBufferDuration(t){this.bufferSize=4*this.sampleRate*this.channels*t}ensureInitialized(){if(!this.wasmModule)throw new Error(`${this.constructor.name} not initalized. call .init()`)}setSoundfont(t){this.ensureInitialized();const{_malloc:e,_free:i,_tsf_load_memory:s,_tsf_set_output:r,_tsf_channel_set_bank_preset:a,_tsf_set_max_voices:n,_tsf_channel_set_presetnumber:o}=this.wasmModule;i(this.soundfontBufferPtr),this.soundfontBufferPtr=e(t.length),this.wasmModule.HEAPU8.set(t,this.soundfontBufferPtr),this.soundfontPtr=s(this.soundfontBufferPtr,t.length),r(this.soundfontPtr,2===this.channels?0:2,this.sampleRate,this.gain)}getPCMBuffer(){this.ensureInitialized();const t=new Uint8Array(this.bufferSize);return t.set(this.wasmModule.HEAPU8.subarray(this.pcmBufferPtr,this.pcmBufferPtr+this.bufferSize)),t}getMIDIMessagePtr(t){const{_malloc:e,_free:i,_tml_load_memory:s}=this.wasmModule;return i(this.midiBufferPtr),this.midiBufferPtr=e(t.length),this.wasmModule.HEAPU8.set(t,this.midiBufferPtr),s(this.midiBufferPtr,t.length)}renderMIDIMessage(t){const{_midi_render:e}=this.wasmModule;return e(this.soundfontPtr,t,this.channels,this.sampleRate,this.pcmBufferPtr,this.bufferSize,this.msecsPtr)}render(t){if(this.ensureInitialized(),!this.soundfontPtr)throw new Error("no soundfont buffer set. call .setSoundfont");window.clearTimeout(this.renderTimer);const{setValue:e,getValue:i}=this.wasmModule;e(this.msecsPtr,0,"double"),this.wasmModule._tsf_reset(this.soundfontPtr),this.wasmModule._tsf_channel_set_bank_preset(this.soundfontPtr,9,128,0),t[0]==="R".charCodeAt(0)&&(t=t.slice(20));let s=this.getMIDIMessagePtr(t);const r=()=>{s=this.renderMIDIMessage(s);const t=this.getPCMBuffer();this.onPCMData(t),s?this.renderTimer=setTimeout(r,this.renderInterval):this.onRenderEnd(i(this.msecsPtr,"double"))};this.renderTimer=setTimeout(r,16)}};!function(){window.AudioContext=window.AudioContext||window.webkitAudioContext,window.AudioContext&&(window.audioContext=new window.AudioContext);var t=function(e){if(window.audioContext){var i=window.audioContext.createBuffer(1,1,22050),s=window.audioContext.createBufferSource();s.buffer=i,s.connect(window.audioContext.destination),s.start?s.start(0):s.play?s.play(0):s.noteOn&&s.noteOn(0)}document.removeEventListener("touchstart",t),document.removeEventListener("touchend",t),document.removeEventListener("click",t)};document.addEventListener("touchstart",t),document.addEventListener("touchend",t),document.addEventListener("click",t)}(),(async()=>{let t=0,e=null,i=new Float32Array,s=window.audioContext.createGain();s.gain.value=.1,s.connect(window.audioContext.destination);let r=0,a=window.audioContext.currentTime,n=[];const o=new R({renderInterval:30,onPCMData:t=>{let e=new Float32Array(t.buffer),s=new Float32Array(i.length+e.length);s.set(i,0),s.set(e,i.length),i=s},onRenderEnd:e=>{t=Math.floor(r+Math.floor(e/1e3))},bufferSize:102400});await o.init();const l=await fetch("./SCC1_Florestan.sf2"),h=new Uint8Array(await l.arrayBuffer());function c(){if(!window.audioContext||!i.length)return;let r=window.audioContext.createBufferSource();r.onended=function(i){const s=Math.floor(window.audioContext.currentTime);t>0&&Math.abs(s-t)<=2&&(t=0,e&&window._tinyMidiPlay(e,-1))};const o=i.length/2,l=window.audioContext.createBuffer(2,o,44100);for(let t=0;t<2;t++){const e=l.getChannelData(t);let s=t;for(let t=0;t{if(f&&clearInterval(f),e=null,i=new Float32Array,n.length){let t=s.gain.value;s.gain.value=0,n.forEach((t=>{t.stop(window.audioContext.currentTime)})),n=[],s.gain.value=t}},window._tinyMidiVolume=(t=1)=>{s.gain.value=t},window._tinyMidiPlay=async(t,i=1)=>{t&&(await window._tinyMidiStop(),-1!=i&&window._tinyMidiVolume(i),e=t,r=window.audioContext.currentTime,a=window.audioContext.currentTime,f=setInterval(c,250),o.render(t))}})();class Y{static unpack=t=>{}}class D{static BASE37_LOOKUP=["_","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];static toBase37=t=>{t=t.trim();let e=0n;for(let i=0;i=65&&s<=90?e+=BigInt(s+1-65):s>=97&&s<=122?e+=BigInt(s+1-97):s>=48&&s<=57&&(e+=BigInt(s+27-48))}return e};static fromBase37=t=>{if(t<0n||t>=6582952005840035281n)return"invalid_name";if(t%37n==0n)return"invalid_name";let e=0;const i=[0,0,0,0,0,0,0,0,0,0,0,0];for(;0n!=t;){const s=t;t/=37n,i[11-e++]=Number(this.BASE37_LOOKUP[Number(s-37n*t)])}return i.slice(12-e).join("")};static toSentenceCase=t=>{const e=[...t.toLowerCase()];let i=!0;for(let t=0;t="a"&&s<="z"&&(e[t]=s.toUpperCase(),i=!1),"."!==s&&"!"!==s||(i=!0)}return e.join("")};static toAsterisks=t=>{let e="";for(let i=0;i{if(0==t.length)return t;const e=[...t];for(let t=0;t="a"&&e[t+1]<="z"&&(e[t+1]=String.fromCharCode(e[t+1].charCodeAt(0)+"A".charCodeAt(0)-97)));return e[0]>="a"&&e[0]<="z"&&(e[0]=String.fromCharCode(e[0].charCodeAt(0)+"A".charCodeAt(0)-97)),e.join("")}}class U{static visibilityMatrix=[];static viewportLeft=0;static viewportTop=0;static viewportRight=0;static viewportBottom=0;static viewportCenterX=0;static viewportCenterY=0;static sinEyePitch=0;static cosEyePitch=0;static sinEyeYaw=0;static cosEyeYaw=0;static{this.visibilityMatrix=new Array(8);for(let t=0;t<8;t++){this.visibilityMatrix[t]=new Array(32);for(let e=0;e<32;e++){this.visibilityMatrix[t][e]=new Array(51);for(let i=0;i<51;i++)this.visibilityMatrix[t][e][i]=new Array(51).fill(!1)}}}static init=(t,e,i,s,r)=>{this.viewportLeft=0,this.viewportTop=0,this.viewportRight=t,this.viewportBottom=e,this.viewportCenterX=t/2,this.viewportCenterY=e/2;const a=new Array(9);for(let t=0;t<9;t++){a[t]=new Array(32);for(let e=0;e<32;e++){a[t][e]=new Array(53);for(let i=0;i<53;i++)a[t][e][i]=new Array(53).fill(!1)}}for(let t=128;t<=384;t+=32)for(let e=0;e<2048;e+=64){this.sinEyePitch=T.sin[t],this.cosEyePitch=T.cos[t],this.sinEyeYaw=T.sin[e],this.cosEyeYaw=T.cos[e];const n=(t-128)/32,o=e/64;for(let t=-26;t<=26;t++)for(let e=-26;e<=26;e++){const l=128*t,h=128*e;let c=!1;for(let t=-i;t<=s;t+=128)if(this.testPoint(l,h,r[n]+t)){c=!0;break}a[n][o][t+25+1][e+25+1]=c}}for(let t=0;t<8;t++)for(let e=0;e<32;e++)for(let i=-25;i<25;i++)for(let s=-25;s<25;s++){let r=!1;t:for(let n=-1;n<=1;n++)for(let o=-1;o<=1;o++){if(a[t][e][i+n+25+1][s+o+25+1]){r=!0;break t}if(a[t][(e+1)%31][i+n+25+1][s+o+25+1]){r=!0;break t}if(a[t+1][e][i+n+25+1][s+o+25+1]){r=!0;break t}if(a[t+1][(e+1)%31][i+n+25+1][s+o+25+1]){r=!0;break t}}this.visibilityMatrix[t][e][i+25][s+25]=r}};static testPoint=(t,e,i)=>{const s=e*this.sinEyeYaw+t*this.cosEyeYaw>>16,r=e*this.cosEyeYaw-t*this.sinEyeYaw>>16,a=i*this.sinEyePitch+r*this.cosEyePitch>>16,n=i*this.cosEyePitch-r*this.sinEyePitch>>16;if(a<50||a>3500)return!1;const o=this.viewportCenterX+(s<<9)/a,l=this.viewportCenterY+(n<<9)/a;return o>=this.viewportLeft&&o<=this.viewportRight&&l>=this.viewportTop&&l<=this.viewportBottom}}class G extends L{static HOST="https://w2.225.2004scape.org";static CHARSET="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";static MEMBERS=!0;static LOW_MEMORY=!1;SCROLLBAR_TRACK=2301979;SCROLLBAR_GRIP_FOREGROUND=5063219;SCROLLBAR_GRIP_HIGHLIGHT=7759444;SCROLLBAR_GRIP_LOWLIGHT=3353893;alreadyStarted=!1;errorStarted=!1;errorLoading=!1;errorHost=!1;loopCycle=0;ingame=!1;archiveChecksums=[];redrawTitleBackground=!0;titleScreenState=0;titleLoginField=0;titleArchive=null;imageTitle2=null;imageTitle3=null;imageTitle4=null;imageTitle0=null;imageTitle1=null;imageTitle5=null;imageTitle6=null;imageTitle7=null;imageTitle8=null;imageTitlebox=null;imageTitlebutton=null;loginMessage0="";loginMessage1="";username="";password="";fontPlain11=null;fontPlain12=null;fontBold12=null;fontQuill8=null;imageRunes=[];flameActive=!1;imageFlamesLeft=null;imageFlamesRight=null;flameBuffer1=[];flameBuffer0=[];flameBuffer3=[];flameBuffer2=[];flameGradient=[];flameGradient0=[];flameGradient1=[];flameGradient2=[];flameLineOffset=[];flameCycle0=0;flameGradientCycle0=0;flameGradientCycle1=0;flamesInterval=null;areaSidebar=null;areaMapback=null;areaViewport=null;areaChatback=null;areaBackbase1=null;areaBackbase2=null;areaBackhmid1=null;areaBackleft1=null;areaBackleft2=null;areaBackright1=null;areaBackright2=null;areaBacktop1=null;areaBacktop2=null;areaBackvmid1=null;areaBackvmid2=null;areaBackvmid3=null;areaBackhmid2=null;areaChatbackOffsets=null;areaSidebarOffsets=null;areaViewportOffsets=null;compassMaskLineOffsets=new Uint16Array(33);compassMaskLineLengths=new Uint16Array(33);minimapMaskLineOffsets=new Uint16Array(151);minimapMaskLineLengths=new Uint16Array(151);imageInvback=null;imageChatback=null;imageMapback=null;imageBackbase1=null;imageBackbase2=null;imageBackhmid1=null;imageSideicons=[];imageCompass=null;imageMapscene=[];imageMapfunction=[];imageHitmarks=[];imageHeadicons=[];imageMapflag=null;imageCrosses=[];imageMapdot0=null;imageMapdot1=null;imageMapdot2=null;imageMapdot3=null;imageScrollbar0=null;imageScrollbar1=null;imageRedstone1=null;imageRedstone2=null;imageRedstone3=null;imageRedstone1h=null;imageRedstone2h=null;imageRedstone1v=null;imageRedstone2v=null;imageRedstone3v=null;imageRedstone1hv=null;imageRedstone2hv=null;redrawSidebar=!1;redrawChatback=!1;redrawSideicons=!1;redrawPrivacySettings=!1;dragCycles=0;sceneState=0;sceneDelta=0;menuVisible=!1;menuArea=0;menuX=0;menuY=0;menuWidth=0;menuHeight=0;menuSize=0;menuOption=[];sidebarInterfaceId=-1;chatInterfaceId=-1;chatInterface=new _;chatScrollHeight=78;chatScrollOffset=0;modalMessage=null;flashingTab=-1;selectedTab=3;tabInterfaceId=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];publicChatSetting=0;privateChatSetting=0;tradeChatSetting=0;scrollGrabbed=!1;scrollInputPadding=0;showSocialInput=!1;socialMessage="";socialInput="";chatbackInput="";chatbackInputOpen=!1;stickyChatInterfaceId=-1;messageText=[];messageSender=[];messageType=[];splitPrivateChat=0;chatTyped="";viewportHoveredInterfaceIndex=0;sidebarHoveredInterfaceIndex=0;chatHoveredInterfaceIndex=0;objDragInterfaceId=0;objDragSlot=0;objDragArea=0;objGrabX=0;objGrabY=0;objDragCycles=0;selectedArea=0;selectedItem=0;selectedInterface=0;selectedCycle=0;pressedContinueOption=!1;runFlames=()=>{this.flameActive&&(this.updateFlames(),this.updateFlames(),this.drawFlames())};load=async()=>{if(this.alreadyStarted)this.errorStarted=!0;else{this.alreadyStarted=!0;try{await this.showProgress(10,"Connecting to fileserver");const t=new e(await g(`${G.HOST}/crc`));for(let e=0;e<9;e++)this.archiveChecksums[e]=t.g4;await this.setMidi("scape_main",12345678),this.titleArchive=await this.loadArchive("title","title screen",this.archiveChecksums[1],10),this.fontPlain11=P.fromArchive(this.titleArchive,"p11"),this.fontPlain12=P.fromArchive(this.titleArchive,"p12"),this.fontBold12=P.fromArchive(this.titleArchive,"b12"),this.fontQuill8=P.fromArchive(this.titleArchive,"q8"),await this.loadTitleBackground(),this.loadTitleImages();const i=await this.loadArchive("config","config",this.archiveChecksums[2],15),l=await this.loadArchive("interface","interface",this.archiveChecksums[3],20),h=await this.loadArchive("media","2d graphics",this.archiveChecksums[4],30),c=await this.loadArchive("models","3d graphics",this.archiveChecksums[5],40),f=await this.loadArchive("textures","textures",this.archiveChecksums[6],60),d=await this.loadArchive("wordenc","chat system",this.archiveChecksums[7],65),u=await this.loadArchive("sounds","sound effects",this.archiveChecksums[8],70);await this.showProgress(75,"Unpacking media"),this.imageInvback=S.fromArchive(h,"invback",0),this.imageChatback=S.fromArchive(h,"chatback",0),this.imageMapback=S.fromArchive(h,"mapback",0),this.imageBackbase1=S.fromArchive(h,"backbase1",0),this.imageBackbase2=S.fromArchive(h,"backbase2",0),this.imageBackhmid1=S.fromArchive(h,"backhmid1",0);for(let t=0;t<13;t++)this.imageSideicons[t]=S.fromArchive(h,"sideicons",t);this.imageCompass=w.fromArchive(h,"compass",0);try{for(let t=0;t<50;t++)this.imageMapscene[t]=S.fromArchive(h,"mapscene",t)}catch(t){}try{for(let t=0;t<50;t++)this.imageMapfunction[t]=w.fromArchive(h,"mapfunction",t)}catch(t){}try{for(let t=0;t<20;t++)this.imageHitmarks[t]=w.fromArchive(h,"hitmarks",t)}catch(t){}try{for(let t=0;t<20;t++)this.imageHeadicons[t]=w.fromArchive(h,"headicons",t)}catch(t){}this.imageMapflag=w.fromArchive(h,"mapflag",0);for(let t=0;t<8;t++)this.imageCrosses[t]=w.fromArchive(h,"cross",t);this.imageMapdot0=w.fromArchive(h,"mapdots",0),this.imageMapdot1=w.fromArchive(h,"mapdots",1),this.imageMapdot2=w.fromArchive(h,"mapdots",2),this.imageMapdot3=w.fromArchive(h,"mapdots",3),this.imageScrollbar0=S.fromArchive(h,"scrollbar",0),this.imageScrollbar1=S.fromArchive(h,"scrollbar",1),this.imageRedstone1=S.fromArchive(h,"redstone1",0),this.imageRedstone2=S.fromArchive(h,"redstone2",0),this.imageRedstone3=S.fromArchive(h,"redstone3",0),this.imageRedstone1h=S.fromArchive(h,"redstone1",0),this.imageRedstone1h?.flipHorizontally(),this.imageRedstone2h=S.fromArchive(h,"redstone2",0),this.imageRedstone2h?.flipHorizontally(),this.imageRedstone1v=S.fromArchive(h,"redstone1",0),this.imageRedstone1v?.flipVertically(),this.imageRedstone2v=S.fromArchive(h,"redstone2",0),this.imageRedstone2v?.flipVertically(),this.imageRedstone3v=S.fromArchive(h,"redstone3",0),this.imageRedstone3v?.flipVertically(),this.imageRedstone1hv=S.fromArchive(h,"redstone1",0),this.imageRedstone1hv?.flipHorizontally(),this.imageRedstone1hv?.flipVertically(),this.imageRedstone2hv=S.fromArchive(h,"redstone2",0),this.imageRedstone2hv?.flipHorizontally(),this.imageRedstone2hv?.flipVertically();const m=this.canvas,p=w.fromArchive(h,"backleft1",0);this.areaBackleft1=new O(m,p.width,p.height),p.blitOpaque(0,0);const A=w.fromArchive(h,"backleft2",0);this.areaBackleft2=new O(m,A.width,A.height),A.blitOpaque(0,0);const k=w.fromArchive(h,"backright1",0);this.areaBackright1=new O(m,k.width,k.height),k.blitOpaque(0,0);const M=w.fromArchive(h,"backright2",0);this.areaBackright2=new O(m,M.width,M.height),M.blitOpaque(0,0);const L=w.fromArchive(h,"backtop1",0);this.areaBacktop1=new O(m,L.width,L.height),L.blitOpaque(0,0);const F=w.fromArchive(h,"backtop2",0);this.areaBacktop2=new O(m,F.width,F.height),F.blitOpaque(0,0);const B=w.fromArchive(h,"backvmid1",0);this.areaBackvmid1=new O(m,B.width,B.height),B.blitOpaque(0,0);const R=w.fromArchive(h,"backvmid2",0);this.areaBackvmid2=new O(m,R.width,R.height),R.blitOpaque(0,0);const D=w.fromArchive(h,"backvmid3",0);this.areaBackvmid3=new O(m,D.width,D.height),D.blitOpaque(0,0);const H=w.fromArchive(h,"backhmid2",0);this.areaBackhmid2=new O(m,H.width,H.height),H.blitOpaque(0,0);const X=Math.trunc(21*Math.random())-10,N=Math.trunc(21*Math.random())-10,z=Math.trunc(21*Math.random())-10,V=Math.trunc(41*Math.random())-20;for(let t=0;t<50;t++)null!=this.imageMapfunction[t]&&this.imageMapfunction[t].translate(X+V,N+V,z+V),null!=this.imageMapscene[t]&&this.imageMapscene[t].translate(X+V,N+V,z+V);await this.showProgress(80,"Unpacking textures"),T.unpackTextures(f),T.setBrightness(.8),T.initPool(20),await this.showProgress(83,"Unpacking models"),I.unpack(c),s.unpack(c),r.unpack(c),await this.showProgress(86,"Unpacking config"),a.unpack(i),n.unpack(i),o.unpack(i),b.unpack(i,G.MEMBERS),y.unpack(i),v.unpack(i),x.unpack(i),C.unpack(i),G.LOW_MEMORY||(await this.showProgress(90,"Unpacking sounds"),Y.unpack(u)),await this.showProgress(92,"Unpacking interfaces"),_.unpack(l,h,[this.fontPlain11,this.fontPlain12,this.fontBold12,this.fontQuill8]),await this.showProgress(97,"Preparing game engine");for(let t=0;t<33;t++){let e=999,i=0;for(let s=0;s<35;s++)if(0==this.imageMapback.pixels[s+t*this.imageMapback.width])999==e&&(e=s);else if(999!=e){i=s;break}this.compassMaskLineOffsets[t]=e,this.compassMaskLineLengths[t]=i-e}for(let t=9;t<160;t++){let e=999,i=0;for(let s=10;s<168;s++)if(0==this.imageMapback.pixels[s+t*this.imageMapback.width]&&(s>34||t>34))999==e&&(e=s);else if(999!=e){i=s;break}this.minimapMaskLineOffsets[t-9]=e-21,this.minimapMaskLineLengths[t-9]=i-e}T.init3D(479,96),this.areaChatbackOffsets=T.lineOffset,T.init3D(190,261),this.areaSidebarOffsets=T.lineOffset,T.init3D(512,334),this.areaViewportOffsets=T.lineOffset;const j=new Int32Array(9);for(let t=0;t<9;t++){const e=32*t+128+15,i=3*e+600,s=T.sin[e];j[t]=i*s>>16}U.init(512,334,500,800,j),E.unpack(d)}catch(t){console.error(t),this.errorLoading=!0}}};update=()=>{this.errorStarted||this.errorLoading||this.errorHost||(this.loopCycle++,this.ingame?this.updateGame():this.updateTitleScreen())};draw=async()=>{this.errorStarted||this.errorLoading||this.errorHost?this.drawError():(this.ingame?this.drawGame():await this.drawTitleScreen(),this.dragCycles=0)};refresh=()=>{this.redrawTitleBackground=!0};showProgress=async(t,e)=>{console.log(`${t}%: ${e}`),await this.loadTitle(),this.titleArchive?(this.imageTitle4?.bind(),this.fontBold12?.drawStringCenter(180,54,"RuneScape is loading - please wait...",16777215),l.drawRect(28,62,304,34,9179409),l.drawRect(29,63,302,32,0),l.fillRect(30,64,3*t,30,9179409),l.fillRect(30+3*t,64,300-3*t,30,0),this.fontBold12?.drawStringCenter(180,85,e,16777215),this.imageTitle4?.draw(214,186),this.redrawTitleBackground&&(this.redrawTitleBackground=!1,this.flameActive||(this.imageTitle0?.draw(0,0),this.imageTitle1?.draw(661,0)),this.imageTitle2?.draw(128,0),this.imageTitle3?.draw(214,386),this.imageTitle5?.draw(0,265),this.imageTitle6?.draw(574,265),this.imageTitle7?.draw(128,186),this.imageTitle8?.draw(574,186)),await u(5)):await super.showProgress(t,e)};loadTitle=async()=>{if(null===this.imageTitle2){this.drawArea=null,this.areaChatback=null,this.areaMapback=null,this.areaSidebar=null,this.areaViewport=null,this.areaBackbase1=null,this.areaBackbase2=null,this.areaBackhmid1=null;const t=this.canvas;this.imageTitle0=new O(t,128,265),l.clear(),this.imageTitle1=new O(t,128,265),l.clear(),this.imageTitle2=new O(t,533,186),l.clear(),this.imageTitle3=new O(t,360,146),l.clear(),this.imageTitle4=new O(t,360,200),l.clear(),this.imageTitle5=new O(t,214,267),l.clear(),this.imageTitle6=new O(t,215,267),l.clear(),this.imageTitle7=new O(t,86,79),l.clear(),this.imageTitle8=new O(t,87,79),l.clear(),null!==this.titleArchive&&(await this.loadTitleBackground(),this.loadTitleImages()),this.redrawTitleBackground=!0}};loadTitleBackground=async()=>{if(!this.titleArchive)return;const t=await w.fromJpeg(this.titleArchive,"title");this.imageTitle0?.bind(),t.blitOpaque(0,0),this.imageTitle1?.bind(),t.blitOpaque(-661,0),this.imageTitle2?.bind(),t.blitOpaque(-128,0),this.imageTitle3?.bind(),t.blitOpaque(-214,-386),this.imageTitle4?.bind(),t.blitOpaque(-214,-186),this.imageTitle5?.bind(),t.blitOpaque(0,-265),this.imageTitle6?.bind(),t.blitOpaque(-128,-186),this.imageTitle7?.bind(),t.blitOpaque(-128,-186),this.imageTitle8?.bind(),t.blitOpaque(-574,-186),t.flipHorizontally(),this.imageTitle0?.bind(),t.blitOpaque(394,0),this.imageTitle1?.bind(),t.blitOpaque(-267,0),this.imageTitle2?.bind(),t.blitOpaque(266,0),this.imageTitle3?.bind(),t.blitOpaque(180,-386),this.imageTitle4?.bind(),t.blitOpaque(180,-186),this.imageTitle5?.bind(),t.blitOpaque(394,-265),this.imageTitle6?.bind(),t.blitOpaque(-180,-265),this.imageTitle7?.bind(),t.blitOpaque(212,-186),this.imageTitle8?.bind(),t.blitOpaque(-180,-186);const e=w.fromArchive(this.titleArchive,"logo");this.imageTitle2?.bind(),e.draw(this.width/2-e.width/2-128,18)};updateFlameBuffer=t=>{for(let t=0;t<32768;t++)this.flameBuffer0[t]=0;for(let t=0;t<5e3;t++){const t=Math.trunc(128*Math.random()*256);this.flameBuffer0[t]=Math.trunc(256*Math.random())}for(let t=0;t<20;t++){for(let t=1;t{if(this.titleArchive){this.imageTitlebox=S.fromArchive(this.titleArchive,"titlebox"),this.imageTitlebutton=S.fromArchive(this.titleArchive,"titlebutton");for(let t=0;t<12;t++)this.imageRunes[t]=S.fromArchive(this.titleArchive,"runes",t);this.imageFlamesLeft=new w(128,265),this.imageFlamesRight=new w(128,265),this.imageTitle0&&p(this.imageTitle0.pixels,0,this.imageFlamesLeft.pixels,0,33920),this.imageTitle1&&p(this.imageTitle1.pixels,0,this.imageFlamesRight.pixels,0,33920),this.flameGradient0=[];for(let t=0;t<64;t++)this.flameGradient0[t]=262144*t;for(let t=0;t<64;t++)this.flameGradient0[t+64]=1024*t+16711680;for(let t=0;t<64;t++)this.flameGradient0[t+128]=4*t+16776960;for(let t=0;t<64;t++)this.flameGradient0[t+192]=16777215;this.flameGradient1=[];for(let t=0;t<64;t++)this.flameGradient1[t]=1024*t;for(let t=0;t<64;t++)this.flameGradient1[t+64]=4*t+65280;for(let t=0;t<64;t++)this.flameGradient1[t+128]=262144*t+65535;for(let t=0;t<64;t++)this.flameGradient1[t+192]=16777215;this.flameGradient2=[];for(let t=0;t<64;t++)this.flameGradient2[t]=4*t;for(let t=0;t<64;t++)this.flameGradient2[t+64]=262144*t+255;for(let t=0;t<64;t++)this.flameGradient2[t+128]=1024*t+16711935;for(let t=0;t<64;t++)this.flameGradient2[t+192]=16777215;this.flameGradient=[],this.flameBuffer0=[],this.flameBuffer1=[],this.updateFlameBuffer(null),this.flameBuffer3=[],this.flameBuffer2=[],this.showProgress(10,"Connecting to fileserver").then((()=>{this.flameActive||(this.flameActive=!0,this.flamesInterval=setInterval(this.runFlames,35))}))}};updateTitleScreen=()=>{if(0===this.titleScreenState){let t=this.width/2-80,e=this.height/2+20;e+=20,1==this.mouseClickButton&&this.mouseClickX>=t-75&&this.mouseClickX<=t+75&&this.mouseClickY>=e-20&&this.mouseClickY<=e+20&&(this.titleScreenState=3,this.titleLoginField=0),t=this.width/2+80,1==this.mouseClickButton&&this.mouseClickX>=t-75&&this.mouseClickX<=t+75&&this.mouseClickY>=e-20&&this.mouseClickY<=e+20&&(this.loginMessage0="",this.loginMessage1="Enter your username & password.",this.titleScreenState=2,this.titleLoginField=0)}else if(2==this.titleScreenState){let t=this.height/2-40;t+=30,t+=25,1==this.mouseClickButton&&this.mouseClickY>=t-15&&this.mouseClickY=t-15&&this.mouseClickY=e-75&&this.mouseClickX<=e+75&&this.mouseClickY>=i-20&&this.mouseClickY<=i+20&&this.login(this.username,this.password,!1).then((()=>{})),e=this.width/2+80,1==this.mouseClickButton&&this.mouseClickX>=e-75&&this.mouseClickX<=e+75&&this.mouseClickY>=i-20&&this.mouseClickY<=i+20&&(this.titleScreenState=0,this.username="",this.password="");;){const t=this.pollKey();if(-1==t)return;let e=!1;for(let i=0;i0&&(this.username=this.username.substring(0,this.username.length-1)),9!=t&&10!=t&&13!=t||(this.titleLoginField=1),e&&(this.username=this.username+String.fromCharCode(t)),this.username.length>12&&(this.username=this.username.substring(0,12))):1==this.titleLoginField&&(8==t&&this.password.length>0&&(this.password=this.password.substring(0,this.password.length-1)),9!=t&&10!=t&&13!=t||(this.titleLoginField=0),e&&(this.password=this.password+String.fromCharCode(t)),this.password.length>20&&(this.password=this.password.substring(0,20)))}}else if(3==this.titleScreenState){const t=this.width/2;let e=this.height/2+50;e+=20,1==this.mouseClickButton&&this.mouseClickX>=t-75&&this.mouseClickX<=t+75&&this.mouseClickY>=e-20&&this.mouseClickY<=e+20&&(this.titleScreenState=0)}};drawTitleScreen=async()=>{if(await this.loadTitle(),this.imageTitle4?.bind(),this.imageTitlebox?.draw(0,0),0===this.titleScreenState){let t=180,e=80;this.fontBold12?.drawStringTaggableCenter(t,e,"Welcome to RuneScape",4294967040,!0),t=100,e=120,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"New user",4294967295,!0),t=260,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"Existing User",4294967295,!0)}else if(2===this.titleScreenState){let t=100,e=60;0===this.loginMessage0.length?(this.fontBold12?.drawStringTaggableCenter(180,e-15,this.loginMessage0,16776960,!0),this.fontBold12?.drawStringTaggableCenter(180,e,this.loginMessage1,16776960,!0),e+=30):(this.fontBold12?.drawStringTaggableCenter(180,e-7,this.loginMessage1,16776960,!0),e+=30),this.fontBold12?.drawStringTaggable(90,e,`Username: ${this.username}${0==this.titleLoginField&&this.loopCycle%40<20?"@yel@|":""}`,16777215,!0),e+=15,this.fontBold12?.drawStringTaggable(92,e,`Password: ${D.toAsterisks(this.password)}${1==this.titleLoginField&&this.loopCycle%40<20?"@yel@|":""}`,16777215,!0),e=150,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"Login",16777215,!0),t=260,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"Cancel",16777215,!0)}else if(3==this.titleScreenState){this.fontBold12?.drawStringTaggableCenter(180,16776960,"Create a free account",40,!0);const t=180;let e=65;this.fontBold12?.drawStringTaggableCenter(180,e,"To create a new account you need to",16777215,!0),e+=15,this.fontBold12?.drawStringTaggableCenter(180,e,"go back to the main RuneScape webpage",16777215,!0),e+=15,this.fontBold12?.drawStringTaggableCenter(180,e,"and choose the red 'create account'",16777215,!0),e+=15,this.fontBold12?.drawStringTaggableCenter(180,e,"button at the top right of that page.",16777215,!0),e=150,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"Cancel",16777215,!0)}this.imageTitle4?.draw(214,186),this.redrawTitleBackground&&(this.redrawTitleBackground=!1,this.imageTitle2?.draw(128,0),this.imageTitle3?.draw(214,386),this.imageTitle5?.draw(0,265),this.imageTitle6?.draw(574,265),this.imageTitle7?.draw(128,186),this.imageTitle8?.draw(574,186))};login=async(t,e,i)=>{try{this.ingame=!0,this.prepareGameScreen()}catch(t){this.loginMessage0="",this.loginMessage1="Error connecting to server."}};updateGame=()=>{this.ingame&&(this.sceneDelta++,1!=this.mouseButton&&1!=this.mouseClickButton||this.dragCycles++)};drawGame=()=>{this.redrawTitleBackground&&(this.redrawTitleBackground=!1,this.areaBackleft1?.draw(0,11),this.areaBackleft2?.draw(0,375),this.areaBackright1?.draw(729,5),this.areaBackright2?.draw(752,231),this.areaBacktop1?.draw(0,0),this.areaBacktop2?.draw(561,0),this.areaBackvmid1?.draw(520,11),this.areaBackvmid2?.draw(520,231),this.areaBackvmid3?.draw(501,375),this.areaBackhmid2?.draw(0,345),this.redrawSidebar=!0,this.redrawChatback=!0,this.redrawSideicons=!0,this.redrawPrivacySettings=!0,2!=this.sceneState&&(this.areaViewport?.draw(8,11),this.areaMapback?.draw(561,5))),2==this.sceneState&&this.drawScene(),this.menuVisible&&1==this.menuArea&&(this.redrawSidebar=!0);let t=!1;if(-1!=this.sidebarInterfaceId&&(t=this.updateInterfaceAnimation(this.sidebarInterfaceId,this.sceneDelta),t&&(this.redrawSidebar=!0)),2==this.selectedArea&&(this.redrawSidebar=!0),2==this.objDragArea&&(this.redrawSidebar=!0),this.redrawSidebar&&(this.drawSidebar(),this.redrawSidebar=!1),-1==this.chatInterfaceId){this.chatInterface.scrollPosition=this.chatScrollHeight-this.chatScrollOffset-77,this.mouseX>453&&this.mouseX<565&&this.mouseY>350&&this.handleScrollInput(this.mouseX-22,this.mouseY-375,this.chatScrollHeight,77,!1,463,0,this.chatInterface);let t=this.chatScrollHeight-this.chatInterface.scrollPosition-77;t<0&&(t=0),t>this.chatScrollHeight-77&&(t=this.chatScrollHeight-77),this.chatScrollOffset!=t&&(this.chatScrollOffset=t,this.redrawChatback=!0)}-1!=this.chatInterfaceId&&(t=this.updateInterfaceAnimation(this.chatInterfaceId,this.sceneDelta),t&&(this.redrawChatback=!0)),3==this.selectedArea&&(this.redrawChatback=!0),3==this.objDragArea&&(this.redrawChatback=!0),null!=this.modalMessage&&(this.redrawChatback=!0),this.menuVisible&&2==this.menuArea&&(this.redrawChatback=!0),this.redrawChatback&&(this.drawChatback(),this.redrawChatback=!1),2==this.sceneState&&(this.drawMinimap(),this.areaMapback?.draw(561,5)),-1!=this.flashingTab&&(this.redrawSideicons=!0),this.redrawSideicons&&(this.redrawSideicons=!1,this.areaBackhmid1?.bind(),this.imageBackhmid1?.draw(0,0),-1==this.sidebarInterfaceId&&(-1!=this.tabInterfaceId[this.selectedTab]&&(0==this.selectedTab?this.imageRedstone1?.draw(29,30):1==this.selectedTab?this.imageRedstone2?.draw(59,29):2==this.selectedTab?this.imageRedstone2?.draw(87,29):3==this.selectedTab?this.imageRedstone3?.draw(115,29):4==this.selectedTab?this.imageRedstone2h?.draw(156,29):5==this.selectedTab?this.imageRedstone2h?.draw(184,29):6==this.selectedTab&&this.imageRedstone1h?.draw(212,30)),-1!=this.tabInterfaceId[0]&&(0!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[0].draw(35,34),-1!=this.tabInterfaceId[1]&&(1!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[1].draw(59,32),-1!=this.tabInterfaceId[2]&&(2!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[2].draw(86,32),-1!=this.tabInterfaceId[3]&&(3!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[3].draw(121,33),-1!=this.tabInterfaceId[4]&&(4!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[4].draw(157,34),-1!=this.tabInterfaceId[5]&&(5!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[5].draw(185,32),-1!=this.tabInterfaceId[6]&&(6!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[6].draw(212,34)),this.areaBackhmid1?.draw(520,165),this.areaBackbase2?.bind(),this.imageBackbase2?.draw(0,0),-1==this.sidebarInterfaceId&&(-1!=this.tabInterfaceId[this.selectedTab]&&(7==this.selectedTab?this.imageRedstone1v?.draw(49,0):8==this.selectedTab?this.imageRedstone2v?.draw(81,0):9==this.selectedTab?this.imageRedstone2v?.draw(108,0):10==this.selectedTab?this.imageRedstone3v?.draw(136,1):11==this.selectedTab?this.imageRedstone2hv?.draw(178,0):12==this.selectedTab?this.imageRedstone2hv?.draw(205,0):13==this.selectedTab&&this.imageRedstone1hv?.draw(233,0)),-1!=this.tabInterfaceId[8]&&(8!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[7].draw(80,2),-1!=this.tabInterfaceId[9]&&(9!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[8].draw(107,3),-1!=this.tabInterfaceId[10]&&(10!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[9].draw(142,4),-1!=this.tabInterfaceId[11]&&(11!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[10].draw(179,2),-1!=this.tabInterfaceId[12]&&(12!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[11].draw(206,2),-1!=this.tabInterfaceId[13]&&(13!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[12].draw(230,2)),this.areaBackbase2?.draw(501,492),this.areaViewport?.bind()),this.redrawPrivacySettings&&(this.redrawPrivacySettings=!1,this.areaBackbase1?.bind(),this.imageBackbase1?.draw(0,0),this.fontPlain12?.drawStringTaggableCenter(57,33,"Public chat",16777215,!0),0==this.publicChatSetting&&this.fontPlain12?.drawStringTaggableCenter(57,46,"On",65280,!0),1==this.publicChatSetting&&this.fontPlain12?.drawStringTaggableCenter(57,46,"Friends",16776960,!0),2==this.publicChatSetting&&this.fontPlain12?.drawStringTaggableCenter(57,46,"Off",16711680,!0),3==this.publicChatSetting&&this.fontPlain12?.drawStringTaggableCenter(57,46,"Hide",65535,!0),this.fontPlain12?.drawStringTaggableCenter(186,33,"Private chat",16777215,!0),0==this.privateChatSetting&&this.fontPlain12?.drawStringTaggableCenter(186,46,"On",65280,!0),1==this.privateChatSetting&&this.fontPlain12?.drawStringTaggableCenter(186,46,"Friends",16776960,!0),2==this.privateChatSetting&&this.fontPlain12?.drawStringTaggableCenter(186,46,"Off",16711680,!0),this.fontPlain12?.drawStringTaggableCenter(326,33,"Trade/duel",16777215,!0),0==this.tradeChatSetting&&this.fontPlain12?.drawStringTaggableCenter(326,46,"On",65280,!0),1==this.tradeChatSetting&&this.fontPlain12?.drawStringTaggableCenter(326,46,"Friends",16776960,!0),2==this.tradeChatSetting&&this.fontPlain12?.drawStringTaggableCenter(326,46,"Off",16711680,!0),this.fontPlain12?.drawStringTaggableCenter(462,38,"Report abuse",16777215,!0),this.areaBackbase1?.draw(0,471),this.areaViewport?.bind()),this.sceneDelta=0};drawScene=()=>{};drawSidebar=()=>{};drawChatback=()=>{if(this.areaChatback?.bind(),this.areaChatbackOffsets&&(T.lineOffset=this.areaChatbackOffsets),this.imageChatback?.draw(0,0),this.showSocialInput)this.fontBold12?.drawStringCenter(239,40,this.socialMessage,0),this.fontBold12?.drawStringCenter(239,60,this.socialInput+"*",128);else if(this.chatbackInputOpen)this.fontBold12?.drawStringCenter(239,40,"Enter amount:",0),this.fontBold12?.drawStringCenter(239,60,this.chatbackInput+"*",128);else if(null!=this.modalMessage)this.fontBold12?.drawStringCenter(239,40,this.modalMessage,0),this.fontBold12?.drawStringCenter(239,60,"Click to continue",128);else if(-1!=this.chatInterfaceId)this.drawInterface(_.instances[this.chatInterfaceId],0,0,0);else if(-1==this.stickyChatInterfaceId){const t=this.fontPlain12;let e=0;l.setBounds(77,463,0,0);for(let i=0;i<100;i++)if(null!=this.messageText[i]){const s=this.messageType[i],r=this.chatScrollOffset+70-14*e;0===s&&(r>0&&r<110&&t?.drawString(4,r,this.messageText[i],0),e++),1===s&&(r>0&&r<110&&(t?.drawString(4,r,this.messageSender[i]+":",16777215),t?.drawString(t.stringWidth(this.messageSender[i])+12,r,this.messageText[i],255)),e++),2===s&&(0==this.publicChatSetting||1==this.publicChatSetting&&this.isFriend(this.messageSender[i]))&&(r>0&&r<110&&(t?.drawString(4,r,this.messageSender[i]+":",0),t?.drawString(t.stringWidth(this.messageSender[i])+12,r,this.messageText[i],255)),e++),3!==s&&7!==s||0!=this.splitPrivateChat||!(7==s||0==this.privateChatSetting||1==this.privateChatSetting&&this.isFriend(this.messageSender[i]))||(r>0&&r<110&&(t?.drawString(4,r,"From "+this.messageSender[i]+":",0),t?.drawString(t.stringWidth("From "+this.messageSender[i])+12,r,this.messageText[i],8388608)),e++),4===s&&(0==this.tradeChatSetting||1==this.tradeChatSetting&&this.isFriend(this.messageSender[i]))&&(r>0&&r<110&&t?.drawString(4,r,this.messageSender[i]+" "+this.messageText[i],8388736),e++),5===s&&0==this.splitPrivateChat&&this.privateChatSetting<2&&(r>0&&r<110&&t?.drawString(4,r,this.messageText[i],8388608),e++),6===s&&0==this.splitPrivateChat&&this.privateChatSetting<2&&(r>0&&r<110&&(t?.drawString(4,r,"To "+this.messageSender[i]+":",0),t?.drawString(t.stringWidth("To "+this.messageSender[i])+12,r,this.messageText[i],8388608)),e++),8===s&&(0==this.tradeChatSetting||1==this.tradeChatSetting&&this.isFriend(this.messageSender[i]))&&(r>0&&r<110&&t?.drawString(4,r,this.messageSender[i]+" "+this.messageText[i],13350793),e++)}l.resetBounds(),this.chatScrollHeight=14*e+7,this.chatScrollHeight<78&&(this.chatScrollHeight=78),this.drawScrollbar(463,0,this.chatScrollHeight-this.chatScrollOffset-77,this.chatScrollHeight,77),t?.drawString(4,90,D.formatName(this.username)+":",0),t?.drawString(t.stringWidth(this.username+": ")+6,90,this.chatTyped+"*",255),l.drawHorizontalLine(0,77,0,479)}else this.drawInterface(_.instances[this.stickyChatInterfaceId],0,0,0);this.menuVisible&&2==this.menuArea&&this.drawMenu(),this.areaChatback?.draw(22,375),this.areaViewport?.bind(),this.areaViewportOffsets&&(T.lineOffset=this.areaViewportOffsets)};drawScrollbar=(t,e,i,s,r)=>{this.imageScrollbar0?.draw(t,e),this.imageScrollbar1?.draw(t,e+r-16),l.fillRect(t,e+16,16,r-32,this.SCROLLBAR_TRACK);let a=(r-32)*r/s|0;a<8&&(a=8);const n=(r-a-32)*i/(s-r)|0;l.fillRect(t,e+n+16,16,a,this.SCROLLBAR_GRIP_FOREGROUND),l.drawVerticalLine(t,e+n+16,this.SCROLLBAR_GRIP_HIGHLIGHT,a),l.drawVerticalLine(t+1,e+n+16,this.SCROLLBAR_GRIP_HIGHLIGHT,a),l.drawHorizontalLine(t,e+n+16,this.SCROLLBAR_GRIP_HIGHLIGHT,16),l.drawHorizontalLine(t,e+n+17,this.SCROLLBAR_GRIP_HIGHLIGHT,16),l.drawVerticalLine(t+15,e+n+16,this.SCROLLBAR_GRIP_LOWLIGHT,a),l.drawVerticalLine(t+14,e+n+17,this.SCROLLBAR_GRIP_LOWLIGHT,a-1),l.drawHorizontalLine(t,e+n+a+15,this.SCROLLBAR_GRIP_LOWLIGHT,16),l.drawHorizontalLine(t+1,e+n+a+14,this.SCROLLBAR_GRIP_LOWLIGHT,15)};drawInterface=(t,e,i,s)=>{if(0!=t.type||null==t.childId||t.hide&&this.viewportHoveredInterfaceIndex!=t.id&&this.sidebarHoveredInterfaceIndex!=t.id&&this.chatHoveredInterfaceIndex!=t.id)return;const r=l.left,n=l.top,o=l.right,h=l.bottom;l.setBounds(i+t.height,e+t.width,i,e);const c=t.childId.length;for(let r=0;r0&&this.updateInterfaceContent(h),0==h.type)h.scrollPosition>h.scrollableHeight-h.height&&(h.scrollPosition=h.scrollableHeight-h.height),h.scrollPosition<0&&(h.scrollPosition=0),this.drawInterface(h,n,o,h.scrollPosition),h.scrollableHeight>h.height&&this.drawScrollbar(n+h.width,o,h.scrollPosition,h.scrollableHeight,h.height);else if(2==h.type){let t=0;for(let e=0;e0){let e=0,i=0;const a=h.inventorySlotObjId[t]-1;if(s>=-32&&s<=512&&r>=-32&&r<=334||0!=this.objDragArea&&this.objDragSlot==t){const n=b.getIcon(a,h.inventorySlotObjCount[t]);if(0!=this.objDragArea&&this.objDragSlot==t&&this.objDragInterfaceId==h.id?(e=this.mouseX-this.objGrabX,i=this.mouseY-this.objGrabY,e<5&&e>-5&&(e=0),i<5&&i>-5&&(i=0),this.objDragCycles<5&&(e=0,i=0),n.drawAlpha(128,s+e,r+i)):0!=this.selectedArea&&this.selectedItem==t&&this.selectedInterface==h.id?n.drawAlpha(128,s,r):n.draw(s,r),33==n.cropW||1!=h.inventorySlotObjCount[t]){const a=h.inventorySlotObjCount[t];this.fontPlain11?.drawString(s+e+1,r+10+i,this.formatObjCount(a),0),this.fontPlain11?.drawString(s+e,r+9+i,this.formatObjCount(a),16776960)}}}else if(null!=h.inventorySlotImage&&t<20){const e=h.inventorySlotImage[t];null!=e&&e.draw(s,r)}t++}}else if(3==h.type)h.fill?l.fillRect(n,o,h.color,h.width,h.height):l.drawRect(n,o,h.color,h.width,h.height);else if(4==h.type){const t=h.font;let e=h.color,i=h.text;if(this.chatHoveredInterfaceIndex!=h.id&&this.sidebarHoveredInterfaceIndex!=h.id&&this.viewportHoveredInterfaceIndex!=h.id||0==h.hoverColor||(e=h.hoverColor),this.executeInterfaceScript(h)&&(e=h.activeColor,h.activeText&&h.activeText.length>0&&(i=h.activeText)),6==h.optionType&&this.pressedContinueOption&&(i="Please wait...",e=h.color),!t||!i)continue;for(let s=o+t.fontHeight;i.length>0;s+=t.fontHeight){if(-1!=i.indexOf("%")){for(;;){const t=i.indexOf("%1");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,0))+i.substring(t+2)}for(;;){const t=i.indexOf("%2");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,1))+i.substring(t+2)}for(;;){const t=i.indexOf("%3");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,2))+i.substring(t+2)}for(;;){const t=i.indexOf("%4");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,3))+i.substring(t+2)}for(;;){const t=i.indexOf("%5");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,4))+i.substring(t+2)}}const r=i.indexOf("\\n");let a;-1!=r?(a=i.substring(0,r),i=i.substring(r+2)):(a=i,i=""),h.center?t.drawStringTaggableCenter(n+h.width/2,s,a,e,h.shadow):t.drawStringTaggable(n,s,a,e,h.shadow)}}else if(5==h.type){let t;t=this.executeInterfaceScript(h)?h.activeImage:h.image,null!=t&&t.draw(n,o)}else if(6==h.type){const t=T.centerX,e=T.centerY;T.centerX=n+h.width/2,T.centerY=o+h.height/2;const i=T.sin[h.modelPitch]*h.modelZoom>>16,s=T.cos[h.modelPitch]*h.modelZoom>>16,r=this.executeInterfaceScript(h);let l;l=r?h.activeSeqId:h.seqId;let c=null;if(-1==l)c=h.getModel(-1,-1,r);else{const t=a.instances[l];t.frames&&t.iframes&&(c=h.getModel(t.frames[h.seqFrame],t.iframes[h.seqFrame],r))}c&&c.drawSimple(0,h.modelYaw,0,h.modelPitch,0,i,s),T.centerX=t,T.centerY=e}else if(7==h.type){const t=h.font;if(!t||!h.inventorySlotObjId||!h.inventorySlotObjCount)continue;let e=0;for(let i=0;i0){const r=b.get(h.inventorySlotObjId[e]-1);let a=r.name;if((r.stackable||1!=h.inventorySlotObjCount[e])&&(a=a+" x"+this.formatObjCountTagged(h.inventorySlotObjCount[e])),!a)continue;const l=n+s*(h.inventoryMarginX+115),c=o+i*(h.inventoryMarginY+12);h.center?t.drawStringTaggableCenter(l+h.width/2,c,a,h.color,h.shadow):t.drawStringTaggable(l,c,a,h.color,h.shadow)}e++}}}l.setBounds(h,o,n,r)};drawMinimap=()=>{};drawMenu=()=>{const t=this.menuX,e=this.menuY,i=this.menuWidth,s=this.menuHeight,r=6116423;l.fillRect(t,e,i,s,r),l.fillRect(t+1,e+1,i-2,16,0),l.drawRect(t+1,e+18,i-2,s-19,0),this.fontBold12?.drawString(t+3,e+14,"Choose Option",r);let a=this.mouseX,n=this.mouseY;0==this.menuArea&&(a-=8,n-=11),1==this.menuArea&&(a-=562,n-=231),2==this.menuArea&&(a-=22,n-=375);for(let s=0;st&&ar-13&&n!1;handleScrollInput=(t,e,i,s,r,a,n,o)=>{if(this.scrollGrabbed?this.scrollInputPadding=32:this.scrollInputPadding=0,this.scrollGrabbed=!1,t>=a&&t=n&&e=a&&t=n+s-16&&e=a-this.scrollInputPadding&&t=n+16&&e0){let t=(s-32)*s/i;t<8&&(t=8);const a=e-n-t/2-16,l=s-t-32;o.scrollPosition=(i-s)*a/l,r&&(this.redrawSidebar=!0),this.scrollGrabbed=!0}};prepareGameScreen=()=>{if(null==this.areaChatback){this.unloadTitle(),this.drawArea=null,this.imageTitle2=null,this.imageTitle3=null,this.imageTitle4=null,this.imageTitle0=null,this.imageTitle1=null,this.imageTitle5=null,this.imageTitle6=null,this.imageTitle7=null,this.imageTitle8=null;const t=this.canvas;this.areaChatback=new O(t,479,96),this.areaMapback=new O(t,168,160),l.clear(),this.imageMapback?.draw(0,0),this.areaSidebar=new O(t,190,261),this.areaViewport=new O(t,512,334),l.clear(),this.areaBackbase1=new O(t,501,61),this.areaBackbase2=new O(t,288,40),this.areaBackhmid1=new O(t,269,66),this.redrawTitleBackground=!0}};isFriend=t=>!1;getIntString=t=>t<999999999?String(t):"*";formatObjCountTagged=t=>{let e=String(t);for(let t=e.length-3;t>0;t-=3)e=e.substring(0,t)+","+e.substring(t);return e.length>8?e="@gre@"+e.substring(0,e.length-8)+" million @whi@("+e+")":e.length>4&&(e="@cya@"+e.substring(0,e.length-4)+"K @whi@("+e+")")," "+e};formatObjCount=t=>t<1e5?String(t):t<1e7?Math.floor(t/1e3)+"K":Math.floor(t/1e6)+"M";executeClientscript1=(t,e)=>{if(null==t.scripts||e>=t.scripts.length)return-2;try{return-1}catch(t){return-1}};executeInterfaceScript=t=>{if(!t.scriptComparator||!t.scriptOperand)return!1;for(let e=0;e=s)return!1}else if(3==t.scriptComparator[e]){if(i<=s)return!1}else if(4==t.scriptComparator[e]){if(i==s)return!1}else if(i!=s)return!1}return!0};updateInterfaceContent=t=>{};unloadTitle=()=>{this.flameActive=!1,this.flamesInterval&&(clearInterval(this.flamesInterval),this.flamesInterval=null),this.imageTitlebox=null,this.imageTitlebutton=null,this.imageRunes=[],this.flameGradient=[],this.flameGradient0=[],this.flameGradient1=[],this.flameGradient2=[],this.flameBuffer0=[],this.flameBuffer1=[],this.flameBuffer3=[],this.flameBuffer2=[],this.imageFlamesLeft=null,this.imageFlamesRight=null};loadArchive=async(t,e,i,s)=>{await this.showProgress(s,`Requesting ${e}`);const r=await M.loadUrl(`${G.HOST}/${t}${i}`);return await this.showProgress(s,`Loading ${e} - 100%`),r};setMidi=async(t,i)=>{const s=new e(await g(`${G.HOST}/${t.replaceAll(" ","_")}_${i}.mid`));var r;r=m(s.data,!0,!1),window._tinyMidiPlay&&window._tinyMidiPlay(r,.75)};drawError=()=>{if(this.ctx.fillStyle="black",this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.setLoopRate(1),this.errorLoading){this.flameActive=!1,this.ctx.font="bold 16px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="yellow";let t=35;this.ctx.fillText("Sorry, an error has occured whilst loading RuneScape",30,t),t+=50,this.ctx.fillStyle="white",this.ctx.fillText("To fix this try the following (in order):",30,t),t+=50,this.ctx.font="bold 12px helvetica, sans-serif",this.ctx.fillText("1: Try closing ALL open web-browser windows, and reloading",30,t),t+=30,this.ctx.fillText("2: Try clearing your web-browsers cache from tools->internet options",30,t),t+=30,this.ctx.fillText("3: Try using a different game-world",30,t),t+=30,this.ctx.fillText("4: Try rebooting your computer",30,t),t+=30,this.ctx.fillText("5: Try selecting a different version of Java from the play-game menu",30,t)}if(this.errorHost&&(this.flameActive=!1,this.ctx.font="bold 20px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="white",this.ctx.fillText("Error - unable to load game!",50,50),this.ctx.fillText("To play RuneScape make sure you play from",50,100),this.ctx.fillText("https://2004scape.org",50,150)),this.errorStarted){this.flameActive=!1,this.ctx.font="bold 13px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="yellow";let t=35;this.ctx.fillText("Error a copy of RuneScape already appears to be loaded",30,t),t+=50,this.ctx.fillStyle="white",this.ctx.fillText("To fix this try the following (in order):",30,t),t+=50,this.ctx.font="bold 12px helvetica, sans-serif",this.ctx.fillText("1: Try closing ALL open web-browser windows, and reloading",30,t),t+=30,this.ctx.fillText("2: Try rebooting your computer, and reloading",30,t)}};updateFlames=()=>{for(let t=10;t<117;t++)Math.trunc(100*Math.random())<50&&(this.flameBuffer3[t+32512]=255);for(let t=0;t<100;t++){const t=Math.trunc(124*Math.random()+2)+(Math.trunc(128*Math.random()+128)<<7);this.flameBuffer3[t]=192}for(let t=1;t<255;t++)for(let e=1;e<127;e++){const i=e+(t<<7);this.flameBuffer2[i]=(this.flameBuffer3[i-1]+this.flameBuffer3[i+1]+this.flameBuffer3[i-128]+this.flameBuffer3[i+128])/4|0}if(this.flameCycle0+=128,this.flameCycle0>32768){this.flameCycle0-=32768;const t=Math.trunc(12*Math.random());this.updateFlameBuffer(this.imageRunes[t])}for(let t=1;t<255;t++)for(let e=1;e<127;e++){const i=e+(t<<7);let s=this.flameBuffer2[i+128]-this.flameBuffer0[i+this.flameCycle0&32767]/5|0;s<0&&(s=0),this.flameBuffer3[i]=s}for(let t=0;t<255;t++)this.flameLineOffset[t]=this.flameLineOffset[t+1];if(this.flameLineOffset[255]=16*Math.sin(this.loopCycle/14)+14*Math.sin(this.loopCycle/15)+12*Math.sin(this.loopCycle/16)|0,this.flameGradientCycle0>0&&(this.flameGradientCycle0-=4),this.flameGradientCycle1>0&&(this.flameGradientCycle1-=4),0==this.flameGradientCycle0&&0==this.flameGradientCycle1){const t=Math.trunc(2e3*Math.random());0==t?this.flameGradientCycle0=1024:1==t&&(this.flameGradientCycle1=1024)}};mix=(t,e,i)=>{const s=256-e;return((16711935&t)*s+(16711935&i)*e&4278255360)+((65280&t)*s+(65280&i)*e&16711680)>>8};drawFlames=()=>{const t=256;if(this.flameGradientCycle0>0)for(let t=0;t<256;t++)this.flameGradientCycle0>768?this.flameGradient[t]=this.mix(this.flameGradient0[t],1024-this.flameGradientCycle0,this.flameGradient1[t]):this.flameGradientCycle0>256?this.flameGradient[t]=this.flameGradient1[t]:this.flameGradient[t]=this.mix(this.flameGradient1[t],256-this.flameGradientCycle0,this.flameGradient0[t]);else if(this.flameGradientCycle1>0)for(let t=0;t<256;t++)this.flameGradientCycle1>768?this.flameGradient[t]=this.mix(this.flameGradient0[t],1024-this.flameGradientCycle1,this.flameGradient2[t]):this.flameGradientCycle1>256?this.flameGradient[t]=this.flameGradient2[t]:this.flameGradient[t]=this.mix(this.flameGradient2[t],256-this.flameGradientCycle1,this.flameGradient0[t]);else for(let t=0;t<256;t++)this.flameGradient[t]=this.flameGradient0[t];for(let t=0;t<33920;t++)this.imageTitle0&&this.imageFlamesLeft&&(this.imageTitle0.pixels[t]=this.imageFlamesLeft.pixels[t]);let e=0,i=1152;for(let s=1;s<255;s++){let r=22+(this.flameLineOffset[s]*(t-s)/t|0);r<0&&(r=0),e+=r;for(let t=r;t<128;t++){let t=0|this.flameBuffer3[e++];if(0==t)i++;else{const e=t,s=256-t;if(t=this.flameGradient[t],this.imageTitle0){const r=this.imageTitle0.pixels[i];this.imageTitle0.pixels[i++]=((16711935&t)*e+(16711935&r)*s&4278255360)+((65280&t)*e+(65280&r)*s&16711680)>>8}}}i+=r}this.imageTitle0?.draw(0,0);for(let t=0;t<33920;t++)this.imageTitle1&&this.imageFlamesRight&&(this.imageTitle1.pixels[t]=this.imageFlamesRight.pixels[t]);e=0,i=1176;for(let s=1;s<255;s++){const r=this.flameLineOffset[s]*(t-s)/t|0,a=103-r;i+=r;for(let t=0;t>8}}}e+=128-a,i+=128-a-r}this.imageTitle1?.draw(661,0)}}(new G).run().then((()=>{}))})()})(); \ No newline at end of file +(()=>{"use strict";var t={621:(t,e,i)=>{t.exports=i.p+"9f86b5397894e28b5ae2.wasm"}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var a=e[s]={exports:{}};return t[s](a,a.exports,i),a.exports}i.m=t,i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.p="/Client2/",i.b=document.baseURI||self.location.href,(()=>{class t{index;constructor(t){this.index=t}decodeType=t=>{for(;;){const e=t.g1;if(0===e)break;this.decode(e,t)}}}class e{static crctable=new Int32Array(256);static CRC32_POLYNOMIAL=3988292384;static bitmask=new Uint32Array(33);static{for(let t=0;t<32;t++)e.bitmask[t]=(1<>>1^e.CRC32_POLYNOMIAL:i>>>=1;e.crctable[t]=i}}data;pos;bitPos=0;constructor(t){if(!t)throw new Error("Input src packet array was null!");this.data=t,this.pos=0}static alloc=t=>new e(0===t?new Uint8Array(100):1===t?new Uint8Array(5e3):new Uint8Array(3e4));get g1(){return this.data[this.pos++]}get g1b(){return this.data[this.pos++]<<24>>24}get g2(){return(this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g2b(){return this.data[this.pos++]<<8|this.data[this.pos++]}get g3(){return(this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4(){return(this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4s(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]}get g8(){return BigInt(this.g4)<<32n|BigInt(this.g4)}get gsmart(){return this.data[this.pos]<128?this.g1:this.g2-32768}get gsmarts(){return this.data[this.pos]<128?this.g1-64:this.g2-49152}get gjstr(){let t="";for(;10!=this.data[this.pos]&&this.posthis.data.subarray(t,t+e);p1=t=>{this.data[this.pos++]=t};p2=t=>{this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip2=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8};p3=t=>{this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};p4=t=>{this.data[this.pos++]=t>>>24,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip4=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>24};p8=t=>{this.p4(Number(t>>32n)),this.p4(Number(0xffffffffn&t))};pjstr=t=>{for(let e=0;e{for(let s=i;s{this.data[this.pos-t-1]=t};bits=()=>{this.bitPos=8*this.pos};bytes=()=>{this.pos=(this.bitPos+7)/8>>>0};gBit=t=>{let i=this.bitPos>>>3,s=8-(7&this.bitPos),r=0;for(this.bitPos+=t;t>s;s=8)r+=(this.data[i++]&e.bitmask[s])<>>s-t&e.bitmask[t],r}}class s{static instances=[];static unpack=t=>{const i=new e(t.read("base_head.dat")),r=new e(t.read("base_type.dat")),a=new e(t.read("base_label.dat")),n=i.g2;i.pos+=2;for(let t=0;t{const i=new e(t.read("frame_head.dat")),a=new e(t.read("frame_tran1.dat")),n=new e(t.read("frame_tran2.dat")),o=new e(t.read("frame_del.dat")),l=i.g2;i.pos+=2;const h=new Uint32Array(500),c=new Uint32Array(500),f=new Uint32Array(500),d=new Uint32Array(500);for(let t=0;t0){if(0!=u.types[t])for(let e=t-1;e>m;e--)if(0==u.types[e]){h[p]=e,c[p]=0,f[p]=0,d[p]=0,p++;break}h[p]=t;let i=0;3==u.types[h[p]]&&(i=128),c[p]=0==(1&e)?i:n.gsmart,f[p]=0==(2&e)?i:n.gsmart,d[p]=0==(4&e)?i:n.gsmart,m=t,p++}}e.length=p,e.bases=new Uint32Array(p),e.x=new Uint32Array(p),e.y=new Uint32Array(p),e.z=new Uint32Array(p);for(let t=0;t{const i=new e(t.read("seq.dat"));this.count=i.g2;for(let t=0;ta.instances[t];frameCount=0;frames=null;iframes=null;delay=null;replayoff=-1;labelGroups=null;stretches=!1;priority=5;mainhand=-1;offhand=-1;replaycount=99;duration=0;decode=(t,e)=>{if(1===t){this.frameCount=e.g1,this.frames=new Uint16Array(this.frameCount),this.iframes=new Uint16Array(this.frameCount),this.delay=new Uint16Array(this.frameCount);for(let t=0;t{const i=new e(t.read("loc.dat"));this.count=i.g2;for(let t=0;t0&&10==e.shapes[0]?1:0,e.ops.length>0&&(e.active=1))}};static get=t=>n.instances[t];models=null;shapes=null;name=null;desc=null;recol_s=null;recol_d=null;width=1;length=1;blockwalk=!0;blockrange=!0;active=-1;hillskew=!1;sharelight=!1;occlude=!1;anim=-1;hasalpha=!1;walloff=16;ambient=0;contrast=0;ops=[];mapfunction=-1;mapscene=-1;mirror=!1;shadow=!0;resizex=128;resizey=128;resizez=128;forceapproach=0;xoff=0;yoff=0;zoff=0;forcedecor=!1;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t),this.shapes=new Uint8Array(t);for(let i=0;i=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const i=new e(t.read("flo.dat"));this.count=i.g2;for(let t=0;to.instances[t];rgb=0;texture=-1;opcode3=!1;occludes=!0;name=null;decode=(t,e)=>{1===t?this.rgb=e.g3:2===t?this.texture=e.g1:3===t?this.opcode3=!0:5===t?this.occludes=!1:6===t?this.name=e.gjstr:console.log("Error unrecognised config code: ",t)}}class l{static pixels=new Int32Array;static width=0;static height=0;static top=0;static bottom=0;static left=0;static right=0;static boundX=0;static centerX=0;static centerY=0;static bind=(t,e,i)=>{this.pixels=t,this.width=e,this.height=i,this.setBounds(0,0,e,i)};static resetBounds=()=>{this.left=0,this.top=0,this.right=this.width,this.bottom=this.height,this.boundX=this.right-1,this.centerX=this.right/2};static setBounds=(t,e,i,s)=>{t<0&&(t=0),e<0&&(e=0),i>this.width&&(i=this.width),s>this.height&&(s=this.height),this.top=e,this.bottom=s,this.left=t,this.right=i,this.boundX=this.right-1,this.centerX=this.right/2,this.centerY=this.bottom/2};static clear=()=>{this.pixels.fill(0)};static drawRect=(t,e,i,s,r)=>{this.drawHorizontalLine(t,e,r,i),this.drawHorizontalLine(t,e+s-1,r,i),this.drawVerticalLine(t,e,r,s),this.drawVerticalLine(t+i-1,e,r,s)};static drawHorizontalLine=(t,e,i,s)=>{if(e=this.bottom)return;tthis.right&&(s=this.right-t);const r=t+e*this.width;for(let t=0;t{if(t=this.right)return;ethis.bottom&&(s=this.bottom-e);const r=t+e*this.width;for(let t=0;t{const a=Math.abs(i-t),n=Math.abs(s-e),o=t=this.left&&t=this.top&&e-n&&(h-=n,t+=o),i{const a=this.pixels;let n=t,o=e,l=t+i,h=e+s;nthis.right&&(l=this.right),h>this.bottom&&(h=this.bottom);const c=this.width;for(let t=o;tt.bits-e.bits||t.code-e.code));let a=0,n=-1;const o=[];let l;for(let t=0;t=t.length)throw RangeError("Out of bound");const i=t.slice();t.sort(((t,e)=>t-e));const s={};for(let e=t.length-1;e>=0;e-=1)s[t[e]]=e;const r=[];for(let e=0;enew Promise((e=>setTimeout(e,t))),g=async t=>new Uint8Array(await(await fetch(t)).arrayBuffer()),m=(t,e=!0,i=!0)=>{if(e){const e=Uint8Array.from(["B".charCodeAt(0),"Z".charCodeAt(0),"h".charCodeAt(0),"1".charCodeAt(0)]);if(i){const i=t;(t=new Uint8Array(e.length+t.length)).set(i,e.length)}t.set(e,0)}return function(t,e=!1){let i=0,s=0,r=0;const a=e=>{if(e>=32){const t=e>>1;return a(t)*(1<>r-e&n;return r-=e,s&=~(n<=49&&n<=57))throw new Error("Invalid blocksize");n-=48;let o=new Uint8Array(1.5*t.length),l=0,u=-1;for(;;){const n=a(48),g=0|a(32);if(54156738319193!==n){if(25779555029136===n){a(7&r);break}throw new Error("Invalid bz2 blocktype")}{if(a(1))throw new Error("do not support randomised");const n=a(24),m=[],p=a(16);for(let t=32768;t>0;t>>=1){if(!(p&t)){for(let t=0;t<16;t+=1)m.push(!1);continue}const e=a(16);for(let t=32768;t>0;t>>=1)m.push(!!(e&t))}const w=a(3);if(w<2||w>6)throw new Error("Invalid number of huffman groups");const b=a(15),y=[],v=Array.from({length:w},((t,e)=>e));for(let t=0;t=w)throw new Error("MTF table out of range");const e=v[t];for(let e=t;e>0;v[e]=v[--e]);y.push(e),v[0]=e}const x=m.reduce(((t,e)=>t+e),0)+2,C=[];for(let t=0;t20)throw new Error("Huffman group length outside range");for(;a(1);)t-=2*a(1)-1;e.push(t)}C.push(f(e))}const S=[];for(let t=0;t>r-e],A)){s&=c[r-=e],A=A.code;break}if(A>=0&&A<=1)0===_&&(O=1),_+=O<0;_-=1)P.push(t)}if(A===x-1)break;{const t=S[A-1];for(let t=A-1;t>0;S[t]=S[--t]);S[0]=t,P.push(t)}}}const M=d(P,n);let E=0;for(;E=o.length){const t=o;o=new Uint8Array(2*t.length),o.set(t)}for(let s=0;s>24^t)]),o[l]=t,l+=1}if(e){const t=-1^u;if(t!==g)throw new Error(`CRC mismatch: ${t} !== ${g}`);u=-1}}}return o.subarray(0,l)}(t)},p=(t,e,i,s,r)=>{for(;r--;)i[s++]=t[e++]};class w{pixels;width;height;cropX;cropY;cropW;cropH;constructor(t,e){this.pixels=new Int32Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromJpeg=async(t,e)=>{const i=t.read(e+".dat"),s=await(async t=>{if(!t)throw new Error("Input jpeg data was null!");255!==t[0]&&(t[0]=255);const e=document.createElement("img");e.src="data:image/jpeg;base64,"+btoa(String.fromCharCode(...t)),await new Promise((t=>e.onload=t));const i=document.createElement("canvas");i.width=e.naturalWidth,i.height=e.naturalHeight;const s=i.getContext("2d");if(!s)throw new Error("Canvas 2d not found!!!!!!!!");return s.drawImage(e,0,0),s.getImageData(0,0,i.width,i.height)})(i),r=new w(s.width,s.height),a=r.pixels,n=s.data;for(let t=0;t{const r=new e(t.read(i+".dat")),a=new e(t.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,l=a.g1,h=new Uint32Array(l),c=l-1;for(let t=0;t{t|=0,e|=0;let i=(t+=this.cropX)+(e+=this.cropY)*l.width,s=0,r=this.height,a=this.width,n=l.width-a,o=0;if(el.bottom&&(r-=e+r-l.bottom),tl.right){const e=t+a-l.right;a-=e,o+=e,n+=e}a>0&&r>0&&this.copyImageDraw(a,r,this.pixels,s,o,l.pixels,i,n)};drawAlpha=(t,e,i)=>{e|=0,i|=0;let s=(e+=this.cropX)+(i+=this.cropY)*l.width,r=0,a=this.height,n=this.width,o=l.width-n,h=0;if(il.bottom&&(a-=i+a-l.bottom),el.right){const t=e+n-l.right;n-=t,h+=t,o+=t}n>0&&a>0&&this.copyPixelsAlpha(n,a,this.pixels,r,h,l.pixels,s,o,t)};blitOpaque=(t,e)=>{t|=0,e|=0;let i=(t+=this.cropX)+(e+=this.cropY)*l.width,s=0,r=this.height,a=this.width,n=l.width-a,o=0;if(el.bottom&&(r-=e+r-l.bottom),tl.right){const e=t+a-l.right;a-=e,o+=e,n+=e}a>0&&r>0&&this.copyImageBlitOpaque(a,r,this.pixels,s,o,l.pixels,i,n)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;a+=t,a<1?a=1:a>255&&(a=255);let n=r>>8&255;n+=e,n<1?n=1:n>255&&(n=255);let o=255&r;o+=i,o<1?o=1:o>255&&(o=255),this.pixels[s]=(a<<16)+(n<<8)+o}}};copyImageBlitOpaque=(t,e,i,s,r,a,n,o)=>{const l=-(t>>2);t=-(3&t);for(let h=-e;h<0;h++){for(let t=l;t<0;t++)a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++];for(let e=t;e<0;e++)a[n++]=i[s++];n+=o,s+=r}};copyPixelsAlpha=(t,e,i,s,r,a,n,o,l)=>{const h=256-l;for(let c=-e;c<0;c++){for(let e=-t;e<0;e++){const t=i[s++];if(0==t)n++;else{const e=a[n];a[n++]=((16711935&t)*l+(16711935&e)*h&4278255360)+((65280&t)*l+(65280&e)*h&16711680)>>8}}n+=o,s+=r}};copyImageDraw=(t,e,i,s,r,a,n,o)=>{const l=-(t>>2);t=-(3&t);for(let h=-e;h<0;h++){for(let t=l;t<0;t++){let t=i[s++];0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t}for(let e=t;e<0;e++){const t=i[s++];0===t?n++:a[n++]=t}n+=o,s+=r}}}class b extends t{static count=0;static instances=[];static unpack=(t,i)=>{const s=new e(t.read("obj.dat"));this.count=s.g2;for(let t=0;tb.instances[t];static getIcon=(t,e)=>new w(32,32);model=0;name=null;desc=null;recol_s=null;recol_d=null;zoom2d=2e3;xan2d=0;yan2d=0;zan2d=0;xof2d=0;yof2d=0;code9=!1;code10=-1;stackable=!1;cost=1;members=!1;ops=[];iops=[];manwear=-1;manwear2=-1;manwearOffsetY=0;womanwear=-1;womanwear2=-1;womanwearOffsetY=0;manwear3=-1;womanwear3=-1;manhead=-1;manhead2=-1;womanhead=-1;womanhead2=-1;countobj=null;countco=null;certlink=-1;certtemplate=-1;decode=(t,e)=>{if(1===t)this.model=e.g2;else if(2===t)this.name=e.gjstr;else if(3===t)this.desc=e.gjstr;else if(4===t)this.zoom2d=e.g2;else if(5===t)this.xan2d=e.g2;else if(6===t)this.yan2d=e.g2;else if(7===t)this.xof2d=e.g2b,this.xof2d>32767&&(this.xof2d-=65536);else if(8===t)this.yof2d=e.g2b,this.yof2d>32767&&(this.yof2d-=65536);else if(9===t)this.code9=!0;else if(10===t)this.code10=e.g2;else if(11===t)this.stackable=!0;else if(12===t)this.cost=e.g4s;else if(16===t)this.members=!0;else if(23===t)this.manwear=e.g2,this.manwearOffsetY=e.g1b;else if(24===t)this.manwear2=e.g2;else if(25===t)this.womanwear=e.g2,this.womanwearOffsetY=e.g1b;else if(26===t)this.womanwear2=e.g2;else if(t>=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(t>=35&&t<40)this.iops[t-35]=e.gjstr;else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i=100&&t<110))throw new Error(`Unrecognized obj config code: ${t}`);this.countobj&&this.countco||(this.countobj=new Uint16Array(10),this.countco=new Uint16Array(10)),this.countobj[t-100]=e.g2,this.countco[t-100]=e.g2}};toCertificate=()=>{const t=b.get(this.certtemplate);this.model=t.model,this.zoom2d=t.zoom2d,this.xan2d=t.xan2d,this.yan2d=t.yan2d,this.zan2d=t.zan2d,this.xof2d=t.xof2d,this.yof2d=t.yof2d,this.recol_s=t.recol_s,this.recol_d=t.recol_d;const e=b.get(this.certlink);this.name=e.name,this.members=e.members,this.cost=e.cost;let i="a";const s=(e.name||"").toLowerCase().charAt(0);"a"!==s&&"e"!==s&&"i"!==s&&"o"!==s&&"u"!==s||(i="an"),this.desc=`Swap this note at any bank for ${i} ${e.name}.`,this.stackable=!0}}class y extends t{static count=0;static instances=[];static unpack=t=>{const i=new e(t.read("npc.dat"));this.count=i.g2;for(let t=0;ty.instances[t];name=null;desc=null;size=1;models=null;heads=null;hasanim=!1;readyanim=-1;walkanim=-1;walkanim_b=-1;walkanim_r=-1;walkanim_l=-1;hasalpha=!1;recol_s=null;recol_d=null;ops=[];code90=-1;code91=-1;code92=-1;visonmap=!0;vislevel=-1;resizeh=128;resizev=128;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=30&&t<40)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const i=new e(t.read("idk.dat"));this.count=i.g2;for(let t=0;tv.instances[t];type=-1;models=null;heads=new Uint16Array(5).fill(-1);recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);disable=!1;decode=(t,e)=>{if(1===t)this.type=e.g1;else if(2===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=40&&t<50)this.recol_s[t-40]=e.g2;else if(t>=50&&t<60)this.recol_d[t-50]=e.g2;else{if(!(t>=60&&t<70))throw new Error(`Unrecognized idk config code: ${t}`);this.heads[t-60]=e.g2}}}class x extends t{static count=0;static instances=[];static unpack=t=>{const i=new e(t.read("spotanim.dat"));this.count=i.g2;for(let t=0;tx.instances[t];model=0;anim=-1;seq=null;disposeAlpha=!1;recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);resizeh=128;resizev=128;orientation=0;ambient=0;contrast=0;decode=(t,e)=>{if(1==t)this.model=e.g2;else if(2==t)this.anim=e.g2,null!=a.instances&&(this.seq=a.instances[this.anim]);else if(3==t)this.disposeAlpha=!0;else if(4==t)this.resizeh=e.g2;else if(5==t)this.resizev=e.g2;else if(6==t)this.orientation=e.g2;else if(7==t)this.ambient=e.g1;else if(8==t)this.contrast=e.g1;else if(t>=40&&t<50)this.recol_s[t-40]=e.g2;else{if(!(t>=50&&t<60))throw new Error(`Unrecognized spotanim config code: ${t}`);this.recol_d[t-50]=e.g2}}}class C extends t{static count=0;static instances=[];static code3=[];static code3Count=0;static unpack=t=>{const i=new e(t.read("varp.dat"));this.count=i.g2;for(let t=0;tC.instances[t];code10=null;code1=0;code2=0;hasCode3=!1;code4=!0;clientcode=0;code7=0;code6=!1;code8=!1;decode(t,e){if(1==t)this.code1=e.g1;else if(2==t)this.code2=e.g1;else if(3==t)this.hasCode3=!0,C.code3[C.code3Count++]=this.index;else if(4==t)this.code4=!1;else if(5==t)this.clientcode=e.g2;else if(6==t)this.code6=!0;else if(7==t)this.code7=e.g4;else if(8==t)this.code8=!0;else{if(10!=t)throw new Error(`Error unrecognised config code: ${t}`);this.code10=e.gjstr}}}class S{pixels;width;height;cropX;cropY;cropW;cropH;palette=new Uint32Array(0);constructor(t,e){this.pixels=new Uint8Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromArchive=(t,i,s=0)=>{const r=new e(t?.read(i+".dat")),a=new e(t?.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,l=a.g1,h=new Uint32Array(l);for(let t=0;t{t|=0,e|=0;let r=(t+=this.cropX)+(e+=this.cropY)*l.width,a=0,n=this.height,o=this.width;-1!==i&&(o=i),-1!==s&&(n=s);let h=l.width-o,c=0;if(el.bottom&&(n-=e+n-l.bottom),tl.right){const e=t+o-l.right;o-=e,c+=e,h+=e}o>0&&n>0&&this.copyImage(o,n,this.pixels,a,c,l.pixels,r,h)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;r+=t,r<0?r=0:r>255&&(r=255);let a=this.palette[s]>>8&255;a+=e,a<0?a=0:a>255&&(a=255);let n=255&this.palette[s];n+=i,n<0?n=0:n>255&&(n=255),this.palette[s]=(r<<16)+(a<<8)+n}};copyImage=(t,e,i,s,r,a,n,o)=>{for(let l=0;l{this.lineOffset=new Int32Array(l.height);for(let t=0;t{this.lineOffset=new Int32Array(e);for(let i=0;i{this.textureCount=0;for(let e=0;e<50;e++)try{this.textures[e]=S.fromArchive(t,e.toString()),this.textureCount++}catch(t){}};static setBrightness=t=>{t+=.3*Math.random()-.15;let e=0;for(let i=0;i<512;i++){const s=i/8/64+.0078125,r=(7&i)/8+.0625;for(let i=0;i<128;i++){const a=i/128;let n=a,o=a,l=a;if(r){let t;t=a<.5?a*(1+r):a+r-a*r;const e=2*a-t;let i=s+.3333333333333333;i>1&&i--;let h=s-.3333333333333333;h<0&&h++,n=6*i<1?e+6*(t-e)*i:2*i<1?t:3*i<2?e+6*(.6666666666666666-i)*(t-e):e,o=6*s<1?e+6*(t-e)*s:2*s<1?t:3*s<2?e+6*(.6666666666666666-s)*(t-e):e,l=6*h<1?e+6*(t-e)*h:2*h<1?t:3*h<2?e+6*(.6666666666666666-h)*(t-e):e}let h=Math.trunc(256*n)<<16|Math.trunc(256*o)<<8|Math.trunc(256*l);h=this.setGamma(h,t),0===h&&(h=1),this.palette[e++]=h}}};static setGamma=(t,e)=>{let i=(t>>16)/256,s=(t>>8&255)/256,r=(255&t)/256;return i=Math.pow(i,e),s=Math.pow(s,e),r=Math.pow(r,e),Math.trunc(256*i)<<16|Math.trunc(256*s)<<8|Math.trunc(256*r)};static initPool=t=>{null==this.texelPool&&(this.poolSize=t,this.texelPool=[],this.activeTexels=[])};static fillGouraudTriangle=(t,e,i,s,r,a,n,o,h)=>{let c=0,f=0,d=0,u=0,g=0,m=0;if(r!=s&&(c=(e-t<<16)/(r-s),u=(o-n<<15)/(r-s)),a!=r&&(f=(i-e<<16)/(a-r),g=(h-o<<15)/(a-r)),a!=s&&(d=(t-i<<16)/(s-a),m=(n-h<<15)/(s-a)),s<=r&&s<=a){if(s>=l.bottom)return;if(r>l.bottom&&(r=l.bottom),a>l.bottom&&(a=l.bottom),rf){for(a-=r,r-=s,s=this.lineOffset[s];--r>=0;s+=l.width)this.drawGouraudScanline(l.pixels,s,i>>16,t>>16,h>>7,n>>7),i+=d,t+=c,h+=m,n+=u;for(;--a>=0;)this.drawGouraudScanline(l.pixels,s,i>>16,e>>16,h>>7,o>>7),i+=d,e+=f,h+=m,o+=g,s+=l.width;return}for(a-=r,r-=s,s=this.lineOffset[s];--r>=0;s+=l.width)this.drawGouraudScanline(l.pixels,s,t>>16,i>>16,n>>7,h>>7),i+=d,t+=c,h+=m,n+=u;for(;--a>=0;)this.drawGouraudScanline(l.pixels,s,e>>16,i>>16,o>>7,h>>7),i+=d,e+=f,h+=m,o+=g,s+=l.width;return}if(e=t<<=16,o=n<<=15,s<0&&(e-=d*s,t-=c*s,o-=m*s,n-=u*s,s=0),i<<=16,h<<=15,a<0&&(i-=f*a,h-=g*a,a=0),s!=a&&dc){for(r-=a,a-=s,s=this.lineOffset[s];--a>=0;s+=l.width)this.drawGouraudScanline(l.pixels,s,e>>16,t>>16,o>>7,n>>7),e+=d,t+=c,o+=m,n+=u;for(;--r>=0;)this.drawGouraudScanline(l.pixels,s,i>>16,t>>16,h>>7,n>>7),i+=f,t+=c,h+=g,n+=u,s+=l.width;return}for(r-=a,a-=s,s=this.lineOffset[s];--a>=0;s+=l.width)this.drawGouraudScanline(l.pixels,s,t>>16,e>>16,n>>7,o>>7),e+=d,t+=c,o+=m,n+=u;for(;--r>=0;)this.drawGouraudScanline(l.pixels,s,t>>16,i>>16,n>>7,h>>7),i+=f,t+=c,h+=g,n+=u,s+=l.width}else if(r<=a){if(r>=l.bottom)return;if(a>l.bottom&&(a=l.bottom),s>l.bottom&&(s=l.bottom),ad){for(s-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=l.width)this.drawGouraudScanline(l.pixels,r,t>>16,e>>16,n>>7,o>>7),t+=c,e+=f,n+=u,o+=g;for(;--s>=0;)this.drawGouraudScanline(l.pixels,r,t>>16,i>>16,n>>7,h>>7),t+=c,i+=d,n+=u,h+=m,r+=l.width;return}for(s-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=l.width)this.drawGouraudScanline(l.pixels,r,e>>16,t>>16,o>>7,n>>7),t+=c,e+=f,n+=u,o+=g;for(;--s>=0;)this.drawGouraudScanline(l.pixels,r,i>>16,t>>16,h>>7,n>>7),t+=c,i+=d,n+=u,h+=m,r+=l.width;return}if(i=e<<=16,h=o<<=15,r<0&&(i-=c*r,e-=f*r,h-=u*r,o-=g*r,r=0),t<<=16,n<<=15,s<0&&(t-=d*s,n-=m*s,s=0),c=0;r+=l.width)this.drawGouraudScanline(l.pixels,r,i>>16,e>>16,h>>7,o>>7),i+=c,e+=f,h+=u,o+=g;for(;--a>=0;)this.drawGouraudScanline(l.pixels,r,t>>16,e>>16,n>>7,o>>7),t+=d,e+=f,n+=m,o+=g,r+=l.width;return}for(a-=s,s-=r,r=this.lineOffset[r];--s>=0;r+=l.width)this.drawGouraudScanline(l.pixels,r,e>>16,i>>16,o>>7,h>>7),i+=c,e+=f,h+=u,o+=g;for(;--a>=0;)this.drawGouraudScanline(l.pixels,r,e>>16,t>>16,o>>7,n>>7),t+=d,e+=f,n+=m,o+=g,r+=l.width}else if(!(a>=l.bottom))if(s>l.bottom&&(s=l.bottom),r>l.bottom&&(r=l.bottom),s=0;a+=l.width)this.drawGouraudScanline(l.pixels,a,e>>16,i>>16,o>>7,h>>7),e+=f,i+=d,o+=g,h+=m;for(;--r>=0;)this.drawGouraudScanline(l.pixels,a,e>>16,t>>16,o>>7,n>>7),e+=f,t+=c,o+=g,n+=u,a+=l.width;return}for(r-=s,s-=a,a=this.lineOffset[a];--s>=0;a+=l.width)this.drawGouraudScanline(l.pixels,a,i>>16,e>>16,h>>7,o>>7),e+=f,i+=d,o+=g,h+=m;for(;--r>=0;)this.drawGouraudScanline(l.pixels,a,t>>16,e>>16,n>>7,o>>7),e+=f,t+=c,o+=g,n+=u,a+=l.width}else if(t=i<<=16,n=h<<=15,a<0&&(t-=f*a,i-=d*a,n-=g*a,h-=m*a,a=0),e<<=16,o<<=15,r<0&&(e-=c*r,o-=u*r,r=0),f=0;a+=l.width)this.drawGouraudScanline(l.pixels,a,t>>16,i>>16,n>>7,h>>7),t+=f,i+=d,n+=g,h+=m;for(;--s>=0;)this.drawGouraudScanline(l.pixels,a,e>>16,i>>16,o>>7,h>>7),e+=c,i+=d,o+=u,h+=m,a+=l.width}else{for(s-=r,r-=a,a=this.lineOffset[a];--r>=0;a+=l.width)this.drawGouraudScanline(l.pixels,a,i>>16,t>>16,h>>7,n>>7),t+=f,i+=d,n+=g,h+=m;for(;--s>=0;)this.drawGouraudScanline(l.pixels,a,i>>16,e>>16,h>>7,o>>7),e+=c,i+=d,o+=u,h+=m,a+=l.width}};static drawGouraudScanline=(t,e,i,s,r,a)=>{let n=0,o=0;if(this.jagged){let h=0;if(this.clipX){if(h=s-i>3?(a-r)/(s-i):0,s>l.right&&(s=l.right),i<0&&(r-=i*h,i=0),i>=s)return;e+=i,o=s-i>>2,h<<=2}else{if(i>=s)return;e+=i,o=s-i>>2,h=o>0?(a-r)*this.reciprocal15[o]>>15:0}if(0==this.alpha){for(;--o>=0;)n=this.palette[r>>8],r+=h,t[e++]=n,t[e++]=n,t[e++]=n,t[e++]=n;if(o=s-i&3,o>0){n=this.palette[r>>8];do{t[e++]=n}while(--o>0);return}}else{const a=this.alpha,l=256-this.alpha;for(;--o>=0;)n=this.palette[r>>8],r+=h,n=((16711935&n)*l>>8&16711935)+((65280&n)*l>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280);if(o=s-i&3,o>0){n=this.palette[r>>8],n=((16711935&n)*l>>8&16711935)+((65280&n)*l>>8&65280);do{t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280)}while(--o>0)}}return}if(i>=s)return;const h=(a-r)/(s-i);if(this.clipX&&(s>l.right&&(s=l.right),i<0&&(r-=i*h,i=0),i>=s))return;if(e+=i,o=s-i,0==this.alpha){do{t[e++]=this.palette[r>>8],r+=h}while(--o>0);return}const c=this.alpha,f=256-this.alpha;do{n=this.palette[r>>8],r+=h,n=((16711935&n)*f>>8&16711935)+((65280&n)*f>>8&65280),t[e++]=n+((16711935&t[e])*c>>8&16711935)+((65280&t[e])*c>>8&65280)}while(--o>0)};static fillTriangle=()=>{};static fillTexturedTriangle=()=>{}}class A{vertexCount=0;faceCount=0;texturedFaceCount=0;vertexFlagsOffset=-1;vertexXOffset=-1;vertexYOffset=-1;vertexZOffset=-1;vertexLabelsOffset=-1;faceVerticesOffset=-1;faceOrientationsOffset=-1;faceColorsOffset=-1;faceInfosOffset=-1;facePrioritiesOffset=0;faceAlphasOffset=-1;faceLabelsOffset=-1;faceTextureAxisOffset=-1}class k{x=0;y=0;z=0;w=0}class I{static metadata=null;static head=null;static face1=null;static face2=null;static face3=null;static face4=null;static face5=null;static point1=null;static point2=null;static point3=null;static point4=null;static point5=null;static vertex1=null;static vertex2=null;static axis=null;static faceClippedX=new Array(4096);static faceNearClipped=new Array(4096);static vertexScreenX=new Int32Array(4096);static vertexScreenY=new Int32Array(4096);static vertexScreenZ=new Int32Array(4096);static vertexViewSpaceX=new Int32Array(4096);static vertexViewSpaceY=new Int32Array(4096);static vertexViewSpaceZ=new Int32Array(4096);static tmpDepthFaceCount=new Int32Array(1500);static tmpDepthFaces=new Array(1500).fill(null).map((()=>new Int32Array(512)));static tmpPriorityFaceCount=new Int32Array(12);static tmpPriorityFaces=new Array(12).fill(null).map((()=>new Int32Array(2e3)));static tmpPriority10FaceDepth=new Int32Array(2e3);static tmpPriority11FaceDepth=new Int32Array(2e3);static tmpPriorityDepthSum=new Int32Array(12);static clippedX=new Int32Array(10);static clippedY=new Int32Array(10);static clippedColor=new Int32Array(10);static baseX=0;static baseY=0;static baseZ=0;static checkHover=!1;static mouseX=0;static mouseZ=0;static pickedCount=0;static pickedBitsets=new Int32Array(1e3);static unpack(t){try{I.head=new e(t.read("ob_head.dat")),I.face1=new e(t.read("ob_face1.dat")),I.face2=new e(t.read("ob_face2.dat")),I.face3=new e(t.read("ob_face3.dat")),I.face4=new e(t.read("ob_face4.dat")),I.face5=new e(t.read("ob_face5.dat")),I.point1=new e(t.read("ob_point1.dat")),I.point2=new e(t.read("ob_point2.dat")),I.point3=new e(t.read("ob_point3.dat")),I.point4=new e(t.read("ob_point4.dat")),I.point5=new e(t.read("ob_point5.dat")),I.vertex1=new e(t.read("ob_vertex1.dat")),I.vertex2=new e(t.read("ob_vertex2.dat")),I.axis=new e(t.read("ob_axis.dat")),I.head.pos=0,I.point1.pos=0,I.point2.pos=0,I.point3.pos=0,I.point4.pos=0,I.vertex1.pos=0,I.vertex2.pos=0;const i=I.head.g2;I.metadata=new Array(i+100);let s=0,r=0,a=0,n=0,o=0,l=0,h=0;for(let t=0;t127&&(e=127),127-e):((e=e*(127&t)>>7)<2?e=2:e>126&&(e=126),(65408&t)+e)}vertexCount=0;vertexX=null;vertexY=null;vertexZ=null;faceCount=0;faceVertexA=null;faceVertexB=null;faceVertexC=null;faceColorA=null;faceColorB=null;faceColorC=null;faceInfo=null;facePriority=null;faceAlpha=null;faceColor=null;priority=0;texturedFaceCount=0;texturedVertexA=null;texturedVertexB=null;texturedVertexC=null;minX=0;maxX=0;minZ=0;maxZ=0;radius=0;minY=0;maxY=0;maxDepth=0;minDepth=0;objRaise=0;vertexLabel=null;faceLabel=null;labelVertices=null;labelFaces=null;pickable=!1;vertexNormal=null;vertexNormalOriginal=null;constructor(t){if(null===I.head||null===I.face1||null===I.face2||null===I.face3||null===I.face4||null===I.face5||null===I.point1||null===I.point2||null===I.point3||null===I.point4||null===I.point5||null===I.vertex1||null===I.vertex2||null===I.axis)return;if(null===I.metadata)return;const e=I.metadata[t];if(void 0===e)return void console.log(`Error model:${t} not found!`);this.vertexCount=e.vertexCount,this.faceCount=e.faceCount,this.texturedFaceCount=e.texturedFaceCount,this.vertexX=new Int32Array(this.vertexCount),this.vertexY=new Int32Array(this.vertexCount),this.vertexZ=new Int32Array(this.vertexCount),this.faceVertexA=new Int32Array(this.faceCount),this.faceVertexB=new Int32Array(this.faceCount),this.faceVertexC=new Int32Array(this.faceCount),this.texturedVertexA=new Int32Array(this.texturedFaceCount),this.texturedVertexB=new Int32Array(this.texturedFaceCount),this.texturedVertexC=new Int32Array(this.texturedFaceCount),e.vertexLabelsOffset>=0&&(this.vertexLabel=new Int32Array(this.vertexCount)),e.faceInfosOffset>=0&&(this.faceInfo=new Int32Array(this.faceCount)),e.facePrioritiesOffset>=0?this.facePriority=new Int32Array(this.faceCount):this.priority=-e.facePrioritiesOffset-1,e.faceAlphasOffset>=0&&(this.faceAlpha=new Int32Array(this.faceCount)),e.faceLabelsOffset>=0&&(this.faceLabel=new Int32Array(this.faceCount)),this.faceColor=new Int32Array(this.faceCount),I.point1.pos=e.vertexFlagsOffset,I.point2.pos=e.vertexXOffset,I.point3.pos=e.vertexYOffset,I.point4.pos=e.vertexZOffset,I.point5.pos=e.vertexLabelsOffset;let i,s,r,a=0,n=0,o=0;for(let t=0;tthis.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)+.99),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsY(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.minY=0;for(let t=0;tthis.maxY&&(this.maxY=-e),e>this.minY&&(this.minY=e)}this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsAABB(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.radius=0,this.minY=0,this.minX=999999,this.maxX=-999999,this.maxZ=-99999,this.minZ=99999;for(let t=0;tthis.maxX&&(this.maxX=e),sthis.maxZ&&(this.maxZ=s),-i>this.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY))}}createLabelReferences(){}applyTransform(t){}rotateY90(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let t=0;t>16;this.vertexZ[t]=this.vertexY[t]*e+this.vertexZ[t]*i>>16,this.vertexY[t]=s}}translate(t,e,i){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let s=0;s>8;if(null!==this.faceColorA&&null!==this.faceColorB&&null!==this.faceColorC||(this.faceColorA=new Int32Array(this.faceCount),this.faceColorB=new Int32Array(this.faceCount),this.faceColorC=new Int32Array(this.faceCount)),null===this.vertexNormal){this.vertexNormal=new Array(this.vertexCount);for(let t=0;t8192||p>8192||w>8192||m<-8192||p<-8192||w<-8192;)m>>=1,p>>=1,w>>=1;let b=Math.sqrt(m*m+p*p+w*w);if(b<=0&&(b=1),m=256*m/b,p=256*p/b,w=256*w/b,null===this.faceInfo||0==(1&this.faceInfo[e])){let t=this.vertexNormal[a];t.x+=m,t.y+=p,t.z+=w,t.w++,t=this.vertexNormal[o],t.x+=m,t.y+=p,t.z+=w,t.w++,t=this.vertexNormal[l],t.x+=m,t.y+=p,t.z+=w,t.w++}else{const a=t+(i*m+s*p+r*w)/(n+n/2);this.faceColorA[e]=I.mulColorLightness(this.faceColor[e],a,this.faceInfo[e])}}if(a)this.applyLighting(t,e,i,s,r);else{this.vertexNormalOriginal=new Array(this.vertexCount);for(let t=0;t>16;for(let s=0;s>16,b=b*d-w*f>>16,w=p),0!==t&&(p=b*l-y*o>>16,y=b*o+y*l>>16,b=p),0!==e&&(p=y*h+w*c>>16,y=y*c-w*h>>16,w=p),w+=r,b+=a,y+=n,p=b*g-y*u>>16,y=b*u+y*g>>16,b=p,I.vertexScreenX[s]=T.centerX+(w<<9)/y,I.vertexScreenY[s]=T.centerY+(b<<9)/y,I.vertexScreenZ[s]=y-m,this.texturedFaceCount>0&&(I.vertexViewSpaceX[s]=w,I.vertexViewSpaceY[s]=b,I.vertexViewSpaceZ[s]=y)}this.draw2(!1,!1,0)}draw(t,e,i,s,r,a,n,o,l){}draw2(t,e,i){if(null===I.vertexScreenX||null===I.vertexScreenY||null===I.vertexScreenZ)return;if(null===I.vertexViewSpaceX||null===I.vertexViewSpaceY||null===I.vertexViewSpaceZ)return;if(null===I.faceNearClipped||null===I.faceClippedX)return;if(null===I.tmpDepthFaceCount||null===I.tmpDepthFaces||null===I.tmpPriorityFaces||null===I.tmpPriorityFaceCount||null===I.tmpPriorityDepthSum||null===I.tmpPriority10FaceDepth||null===I.tmpPriority11FaceDepth)return;if(null===this.faceVertexA||null===this.faceVertexB||null===this.faceVertexC)return;for(let t=0;tl.boundX||h>l.boundX||c>l.boundX;const u=Math.trunc((I.vertexScreenZ[r]+I.vertexScreenZ[a]+I.vertexScreenZ[n])/3+this.minDepth);I.tmpDepthFaces[u][I.tmpDepthFaceCount[u]++]=s}else{I.faceNearClipped[s]=!0;const t=Math.trunc((I.vertexScreenZ[r]+I.vertexScreenZ[a]+I.vertexScreenZ[n])/3+this.minDepth);I.tmpDepthFaces[t][I.tmpDepthFaceCount[t]++]=s}}if(null==this.facePriority){for(let t=this.maxDepth-1;t>=0;t--){const e=I.tmpDepthFaceCount[t];if(e<=0)continue;const i=I.tmpDepthFaces[t];for(let t=0;t=0;t--){const e=I.tmpDepthFaceCount[t];if(e>0){const i=I.tmpDepthFaces[t];for(let s=0;s0||I.tmpPriorityFaceCount[2]>0)&&(s=Math.trunc((I.tmpPriorityDepthSum[1]+I.tmpPriorityDepthSum[2])/(I.tmpPriorityFaceCount[1]+I.tmpPriorityFaceCount[2])));let r=0;(I.tmpPriorityFaceCount[3]>0||I.tmpPriorityFaceCount[4]>0)&&(r=Math.trunc((I.tmpPriorityDepthSum[3]+I.tmpPriorityDepthSum[4])/(I.tmpPriorityFaceCount[3]+I.tmpPriorityFaceCount[4])));let a=0;(I.tmpPriorityFaceCount[6]>0||I.tmpPriorityFaceCount[8]>0)&&(a=Math.trunc((I.tmpPriorityDepthSum[6]+I.tmpPriorityDepthSum[8])/(I.tmpPriorityFaceCount[6]+I.tmpPriorityFaceCount[8])));let n,o=0,h=I.tmpPriorityFaceCount[10],c=I.tmpPriorityFaces[10],f=I.tmpPriority10FaceDepth;o==h&&(o=0,h=I.tmpPriorityFaceCount[11],c=I.tmpPriorityFaces[11],f=I.tmpPriority11FaceDepth),n=os;)this.drawFace(c[o++]),o==h&&c!=I.tmpPriorityFaces[11]&&(o=0,h=I.tmpPriorityFaceCount[11],c=I.tmpPriorityFaces[11],f=I.tmpPriority11FaceDepth),n=or;)this.drawFace(c[o++]),o==h&&c!=I.tmpPriorityFaces[11]&&(o=0,h=I.tmpPriorityFaceCount[11],c=I.tmpPriorityFaces[11],f=I.tmpPriority11FaceDepth),n=oa;)this.drawFace(c[o++]),o==h&&c!=I.tmpPriorityFaces[11]&&(o=0,h=I.tmpPriorityFaceCount[11],c=I.tmpPriorityFaces[11],f=I.tmpPriority11FaceDepth),n=oa&&e>n&&e>o||t{const r=new e(t.read("data"));let a=-1;for(r.pos+=2;r.pos0){e.scriptComparator=new Uint8Array(n).fill(0),e.scriptOperand=new Uint16Array(n).fill(0);for(let t=0;t0){e.scripts=new Array(o).fill(null);for(let t=0;t0){const r=s.lastIndexOf(",");e.inventorySlotImage[t]=w.fromArchive(i,s,r)}}for(let t=0;t<5;t++)e.inventoryOptions[t]=r.gjstr,0===e.inventoryOptions[t]?.length&&(e.inventoryOptions[t]=null);e.spellAction=r.gjstr,e.spellName=r.gjstr,e.spellFlags=r.g2;break;case _.TYPE_RECT:e.fill=1===r.g1,e.color=r.g4,e.activeColor=r.g4,e.hoverColor=r.g4;break;case _.TYPE_TEXT:e.center=1===r.g1,e.font=s[r.g1],e.shadow=1===r.g1,e.text=r.gjstr,e.activeText=r.gjstr,e.color=r.g4,e.activeColor=r.g4,e.hoverColor=r.g4;break;case _.TYPE_SPRITE:{const t=r.gjstr;if(t.length>0){const s=t.lastIndexOf(",");e.image=w.fromArchive(i,t.substring(0,s),parseInt(t.substring(s+1)))}const s=r.gjstr;if(s.length>0){const t=s.lastIndexOf(",");e.image=w.fromArchive(i,s.substring(0,t),parseInt(s.substring(t+1)))}break}case _.TYPE_MODEL:{const t=r.g1;0!==t&&(e.model=this.getModel((t-1<<8)+r.g1));const i=r.g1;0!==i&&(e.activeModel=this.getModel((i-1<<8)+r.g1)),e.seqId=r.g1,0==e.seqId?e.seqId=-1:e.seqId=(e.seqId-1<<8)+r.g1,e.activeSeqId=r.g1,0==e.activeSeqId?e.activeSeqId=-1:e.activeSeqId=(e.activeSeqId-1<<8)+r.g1,e.modelZoom=r.g2,e.modelPitch=r.g2,e.modelYaw=r.g2;break}case _.TYPE_INVENTORY_TEXT:e.inventorySlotObjId=new Int32Array(e.width*e.height),e.inventorySlotObjCount=new Int32Array(e.width*e.height),e.center=1===r.g1,e.font=s[r.g1],e.shadow=1===r.g1,e.color=r.g4,e.inventoryMarginX=r.g2b,e.inventoryMarginY=r.g2b,e.inventoryInteractable=1===r.g1,e.inventoryOptions=new Array(5).fill(null);for(let t=0;t<5;t++)e.inventoryOptions[t]=r.gjstr}2!=e.optionType&&2!=e.type||(e.spellAction=r.gjstr,e.spellName=r.gjstr,e.spellFlags=r.g2),1!=e.optionType&&4!=e.optionType&&5!=e.optionType&&6!=e.optionType||(e.option=r.gjstr,0==e.option.length&&(1==e.optionType?e.option="Ok":4==e.optionType||5==e.optionType?e.option="Select":6==e.optionType&&(e.option="Continue")))}};static get=t=>_.instances[t];static getModel=t=>new I(t);id=-1;parentId=-1;type=-1;optionType=-1;contentType=0;width=0;height=0;delegateHover=-1;scriptComparator=null;scriptOperand=null;scripts=null;scrollableHeight=0;hide=!1;inventoryDraggable=!1;inventoryInteractable=!1;inventoryUsable=!1;inventoryMarginX=0;inventoryMarginY=0;inventorySlotOffsetX=null;inventorySlotOffsetY=null;inventorySlotImage=null;inventoryOptions=[];fill=!1;center=!1;font=null;shadow=!1;text=null;activeText=null;color=0;activeColor=0;hoverColor=0;image=null;activeImage=null;model=null;activeModel=null;seqId=-1;activeSeqId=-1;modelZoom=0;modelPitch=0;modelYaw=0;spellAction=null;spellName=null;spellFlags=-1;option=null;childId=null;childX=null;childY=null;x=0;y=0;scrollPosition=0;inventorySlotObjId=null;inventorySlotObjCount=null;seqFrame=0;getModel=(t,e,i)=>{let s=this.model;return i&&(s=this.activeModel),null==s?null:-1==t&&-1==e&&null==s.faceColor?s:null}}class O{canvas;ctx;image;pixels;width;height;constructor(t,e,i){const s=t.getContext("2d");if(!s)throw new Error("Canvas 2d not found!!!!!!!!");this.canvas=t,this.ctx=s,this.image=s.getImageData(0,0,e,i),this.pixels=new Int32Array(e*i),this.width=e,this.height=i,this.bind()}clear=()=>{this.pixels.fill(0)};bind=()=>{l.bind(this.pixels,this.width,this.height)};draw=(t,e)=>{this.#t(),this.ctx.putImageData(this.image,t,e)};#t=()=>{const t=this.image.data;for(let e=0;e>16&255,t[s+1]=i>>8&255,t[s+2]=i>>0&255,t[s+3]=255}}}class P{static CHARSET=[];static{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";for(let e=0;e<256;e++){let i=t.indexOf(String.fromCharCode(e));-1===i&&(i=74),P.CHARSET[e]=i}}pixels=[];charWidth=[];charHeight=[];clipX=[];clipY=[];charSpace=[];drawWidth=[];fontHeight=-1;static fromArchive=(t,i)=>{const s=new e(t.read(i+".dat")),r=new e(t.read("index.dat"));r.pos=s.g2+4;const a=r.g1;a>0&&(r.pos+=3*(a-1));const n=new P;for(let t=0;t<94;t++){n.clipX[t]=r.g1,n.clipY[t]=r.g1;const e=n.charWidth[t]=r.g2,i=n.charHeight[t]=r.g2,a=e*i;n.pixels[t]=new Uint8Array(a);const o=r.g1;if(0===o)for(let r=0;rn.fontHeight&&(n.fontHeight=i),n.clipX[t]=1,n.charSpace[t]=e+2;{let s=0;for(let r=i/7;r{t|=0,e|=0;const r=i.length;e-=this.fontHeight;for(let a=0;a{t|=0,e|=0;const a=i.length;e-=this.fontHeight;for(let n=0;n{const e=t.length;let i=0;for(let s=0;s{const r=e-this.fontHeight;for(let e=0;e{this.drawStringTaggable(t-this.stringWidth(i)/2,e,i,s,r)};drawStringCenter=(t,e,i,s)=>{this.draw(t-this.stringWidth(i)/2,e,i,s)};drawRight=(t,e,i,s,r=!0)=>{r&&this.draw(t-this.stringWidth(i)+1,e+1,i,0),this.draw(t-this.stringWidth(i),e,i,s)};drawChar=(t,e,i,s,r,a)=>{s|=0,r|=0;let n=(e|=0)+(i|=0)*l.width,o=l.width-s,h=0,c=0;if(i=l.bottom&&(r-=i+r+1-l.bottom),e=l.right){const t=e+s+1-l.right;s-=t,h+=t,o+=t}s>0&&r>0&&this.drawMask(s,r,t,c,h,l.pixels,n,o,a)};drawMask=(t,e,i,s,r,a,n,o,l)=>{const h=-((t|=0)>>2);t=-(3&t);for(let c=-(e|=0);c<0;c++){for(let t=h;t<0;t++)0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l;for(let e=t;e<0;e++)0==i[s++]?n++:a[n++]=l;n+=o,s+=r}};copyCharacter=(t,e,i,s,r,a)=>{i|=0,s|=0;let n=(t|=0)+(e|=0)*l.width,o=0,h=l.width-i,c=0;if(el.bottom&&(s-=e+s+1-l.bottom),tl.right){const e=t+i+1-l.right;i-=e,c+=e,h+=e}i>0&&s>0&&this.copyImageMasked(i,s,r,o,c,l.pixels,n,h,a)};copyImageMasked=(t,e,i,s,r,a,n,o,l)=>{for(let h=0;h{switch(t){case"red":return 16711680;case"gre":return 65280;case"blu":return 255;case"yel":return 16776960;case"cya":return 65535;case"mag":return 16711935;case"whi":return 16777215;case"bla":default:return 0;case"lre":return 16748608;case"dre":return 8388608;case"dbl":return 128;case"or1":return 16756736;case"or2":return 16740352;case"or3":return 16723968;case"gr1":return 12648192;case"gr2":return 8453888;case"gr3":return 4259584}}}class M{static loadUrl=async t=>new M(await g(t));static genHash=t=>{let e=0;t=t.toUpperCase();for(let i=0;i>>0;return e};buffer;compressedWhole;fileCount;fileHash;fileSizeInflated;fileSizeDeflated;fileOffset;constructor(t){const i=new e(t),s=i.g3;let r;if(s==i.g3)r=i,this.compressedWhole=!1;else{const t=i.gdata(i.pos,s);r=new e(new Uint8Array(m(t))),this.compressedWhole=!0}this.buffer=r,this.fileCount=r.g2,this.fileHash=[],this.fileSizeInflated=[],this.fileSizeDeflated=[],this.fileOffset=[];let a=r.pos+10*this.fileCount;for(let t=0;t{const e=M.genHash(t),i=this.fileHash.indexOf(e);return-1==i?null:this.readIndex(i)};readIndex=t=>{if(t<0||t>=this.fileCount)return null;if(this.compressedWhole)return this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);{const e=this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);return m(e)}}}class E{static PERIOD=new Uint16Array(["d","o","t"].join("").split("").map((t=>t.charCodeAt(0))));static AMPERSAT=new Uint16Array(["(","a",")"].join("").split("").map((t=>t.charCodeAt(0))));static SLASH=new Uint16Array(["s","l","a","s","h"].join("").split("").map((t=>t.charCodeAt(0))));static whitelist=["cook","cook's","cooks","seeks","sheet"];static tlds=[];static tldTypes=[];static bads=[];static badCombinations=[];static domains=[];static fragments=[];static unpack=t=>{const i=new e(t.read("fragmentsenc.txt")),s=new e(t.read("badenc.txt")),r=new e(t.read("domainenc.txt")),a=new e(t.read("tldlist.txt"));this.read(s,r,i,a)};static filter=t=>{const e=[...t];this.format(e);const i=e.join("").trim(),s=i.toLowerCase(),r=[...s];this.filterTlds(r),this.filterBadWords(r),this.filterDomains(r),this.filterFragments(r);for(let t=0;t{this.readBadWords(t),this.readDomains(e),this.readFragments(i),this.readTld(s)};static readTld=t=>{const e=t.g4;for(let i=0;it.g1))};static readBadWords=t=>{const e=t.g4;for(let i=0;it.g1));const e=new Array(t.g1).fill([]).map((()=>[t.g1b,t.g1b]));e.length>0&&(this.badCombinations[i]=e)}};static readDomains=t=>{const e=t.g4;for(let i=0;it.g1))};static readFragments=t=>{const e=t.g4;for(let i=0;i{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.PERIOD),this.filterBadCombinations(null,i,this.SLASH);for(let s=0;s{for(let e=0;e<2;e++)for(let e=this.bads.length-1;e>=0;e--)this.filterBadCombinations(this.badCombinations[e],t,this.bads[e])};static filterDomains=t=>{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.AMPERSAT),this.filterBadCombinations(null,i,this.PERIOD);for(let s=this.domains.length-1;s>=0;s--)this.filterDomain(i,e,this.domains[s],t)};static filterFragments=t=>{for(let e=0;e=0&&r{if(this.isNumericalChars(t))return!0;const e=this.getInteger(t),i=this.fragments,s=i.length;if(e===i[0]||e===i[s-1])return!0;let r=0,a=s-1;for(;r<=a;){const t=Math.floor((r+a)/2);if(e===i[t])return!0;e{if(t.length>6)return 0;let e=0;for(let i=0;i{for(let i=e;i=0;i++)if(this.isNumerical(t[i]))return i;return-1};static indexOfNonNumber=(t,e)=>{for(let i=t;i=0;i++)if(!this.isNumerical(e[i]))return i;return e.length};static getEmulatedDomainCharLen=(t,e,i)=>e==i||"o"==e&&"0"==i?1:"o"==e&&"("==i&&")"==t?2:"c"!=e||"("!=i&&"<"!=i&&"["!=i?"e"==e&&"€"==i||"s"==e&&"$"==i||"l"==e&&"i"==i?1:0:1;static filterDomain=(t,e,i,s)=>{const r=i.length,a=s.length;for(let n=0;n<=a-r;n++){const{matched:r,currentIndex:a}=this.findMatchingDomain(n,i,s);if(!r)continue;const o=this.prefixSymbolStatus(n,s,3,e,["@"]),l=this.suffixSymbolStatus(a-1,s,3,t,[".",","]);(o>2||l>2)&&this.maskChars(n,a,s)}};static findMatchingDomain=(t,e,i)=>{const s=e.length;let r=t,a=0;for(;r0)r+=l,a++;else{if(0===a)break;const i=this.getEmulatedDomainCharLen(o,String.fromCharCode(e[a-1]),n);if(i>0)r+=i,1===a&&t++;else{if(a>=s||!this.isSymbol(n))break;r++}}}return{matched:a>=s,currentIndex:r}};static filterBadCombinations=(t,e,i)=>{if(!(i.length>e.length))for(let s=0;s<=e.length-i.length;s++){let r=s;const{currentIndex:a,badIndex:n,hasSymbol:o,hasNumber:l,hasDigit:h}=this.processBadCharacters(e,i,r);r=a;let c=e[r],f=r+1=i.length)||l&&h)continue;let d,u=!0;if(o){let t=!1,i=!1;if((s-1<0||this.isSymbol(e[s-1])&&"'"!=e[s-1])&&(t=!0),(r>=e.length||this.isSymbol(e[r])&&"'"!=e[r])&&(i=!0),!t||!i){let i=!1;for(d=s-2,t&&(d=s);!i&&d=0&&(!this.isSymbol(e[d])||"'"==e[d])){const t=[];let s;for(s=0;s<3&&d+s=0&&(!this.isSymbol(e[d-1])||"'"==e[d-1])&&(r=!1),r&&!this.isBadFragment(t)&&(i=!0)}d++}i||(u=!1)}}else{c=" ",s-1>=0&&(c=e[s-1]),f=" ",r{let s=i,r=0,a=0,n=!1,o=!1,l=!1;for(;s=t.length||o&&l);){const h=t[s],c=s+10)1===f&&this.isNumerical(h)&&(o=!0),2===f&&(this.isNumerical(h)||this.isNumerical(c))&&(o=!0),s+=f,r++;else{if(0===r)break;let t;if((t=this.getEmulatedBadCharLen(c,String.fromCharCode(e[r-1]),h))>0)s+=t;else{if(r>=e.length||!this.isNotLowercaseAlpha(h))break;if(this.isSymbol(h)&&"'"!==h&&(n=!0),this.isNumerical(h)&&(l=!0),s++,a++,100*a/(s-i)>90)break}}}return{currentIndex:s,badIndex:r,hasSymbol:n,hasNumber:o,hasDigit:l}};static getEmulatedBadCharLen=(t,e,i)=>{if(e==i)return 1;if(e>="a"&&e<="m"){if("a"==e)return"4"!=i&&"@"!=i&&"^"!=i?"/"==i&&"\\"==t?2:0:1;if("b"==e)return"6"!=i&&"8"!=i?"1"==i&&"3"==t?2:0:1;if("c"==e)return"("!=i&&"<"!=i&&"{"!=i&&"["!=i?0:1;if("d"==e)return"["==i&&")"==t?2:0;if("e"==e)return"3"!=i&&"€"!=i?0:1;if("f"==e)return"p"==i&&"h"==t?2:"£"==i?1:0;if("g"==e)return"9"!=i&&"6"!=i?0:1;if("h"==e)return"#"==i?1:0;if("i"==e)return"y"!=i&&"l"!=i&&"j"!=i&&"1"!=i&&"!"!=i&&":"!=i&&";"!=i&&"|"!=i?0:1;if("j"==e)return 0;if("k"==e)return 0;if("l"==e)return"1"!=i&&"|"!=i&&"i"!=i?0:1;if("m"==e)return 0}if(e>="n"&&e<="z"){if("n"==e)return 0;if("o"==e)return"0"!=i&&"*"!=i?"("==i&&")"==t||"["==i&&"]"==t||"{"==i&&"}"==t||"<"==i&&">"==t?2:0:1;if("p"==e)return 0;if("q"==e)return 0;if("r"==e)return 0;if("s"==e)return"5"!=i&&"z"!=i&&"$"!=i&&"2"!=i?0:1;if("t"==e)return"7"!=i&&"+"!=i?0:1;if("u"==e)return"v"==i?1:"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("v"==e)return"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("w"==e)return"v"==i&&"v"==t?2:0;if("x"==e)return")"==i&&"("==t||"}"==i&&"{"==t||"]"==i&&"["==t||">"==i&&"<"==t?2:0;if("y"==e)return 0;if("z"==e)return 0}return e>="0"&&e<="9"?"0"==e?"o"==i||"O"==i?1:"("==i&&")"==t||"{"==i&&"}"==t||"["==i&&"]"==t?2:0:"1"==e&&"l"==i?1:0:","==e?"."==i?1:0:"."==e?","==i?1:0:"!"==e&&"i"==i?1:0};static comboMatches=(t,e,i)=>{let s=0,r=e.length-1;for(;s<=r;){const a=Math.floor((s+r)/2);if(e[a][0]===t&&e[a][1]===i)return!0;tthis.isLowercaseAlpha(t)?t.charCodeAt(0)+1-"a".charCodeAt(0):"'"==t?28:this.isNumerical(t)?t.charCodeAt(0)+29-"0".charCodeAt(0):27;static filterTld=(t,e,i,s,r)=>{if(!(s.length>i.length))for(let a=0;a<=i.length-s.length;a++){const{currentIndex:n,tldIndex:o}=this.processTlds(i,s,a);if(o0&&c>0&&(l=!0),2==e&&(h>2&&c>0||h>0&&c>2)&&(l=!0),3==e&&h>0&&c>2&&(l=!0),!l)continue;let f,d=a,u=n-1,g=!1;if(h>2){if(4==h)for(g=!1,f=a-1;f>=0;f--)if(g){if("*"!=r[f])break;d=f}else"*"==r[f]&&(d=f,g=!0);for(g=!1,f=d-1;f>=0;f--)if(g){if(this.isSymbol(i[f]))break;d=f}else this.isSymbol(i[f])||(g=!0,d=f)}if(c>2){if(4==c)for(g=!1,f=u+1;f{let s=0;for(;i0)i+=n,s++;else{if(0===s)break;let t;if((t=this.getEmulatedDomainCharLen(a,String.fromCharCode(e[s-1]),r))>0)i+=t;else{if(!this.isSymbol(r))break;i++}}}return{currentIndex:i,tldIndex:s}};static isSymbol=t=>!this.isAlpha(t)&&!this.isNumerical(t);static isNotLowercaseAlpha=t=>!this.isLowercaseAlpha(t)||"v"==t||"x"==t||"j"==t||"q"==t||"z"==t;static isAlpha=t=>this.isLowercaseAlpha(t)||this.isUppercaseAlpha(t);static isNumerical=t=>t>="0"&&t<="9";static isLowercaseAlpha=t=>t>="a"&&t<="z";static isUppercaseAlpha=t=>t>="A"&&t<="Z";static isNumericalChars=t=>{for(let e=0;e{for(let s=t;s{let i=0;for(let s=e-1;s>=0&&this.isSymbol(t[s]);s--)"*"===t[s]&&i++;return i};static maskedCountForwards=(t,e)=>{let i=0;for(let s=e+1;s(r?this.maskedCountBackwards(e,i):this.maskedCountForwards(e,i))>=s?4:this.isSymbol(r?t[i-1]:t[i+1])?1:0;static prefixSymbolStatus=(t,e,i,s,r)=>{if(0===t)return 2;for(let i=t-1;i>=0&&this.isSymbol(e[i]);i--)if(r.includes(e[i]))return 3;return this.maskedCharsStatus(e,s,t,i,!0)};static suffixSymbolStatus=(t,e,i,s,r)=>{if(t+1===e.length)return 2;for(let i=t+1;i{let e=0;for(let i=0;it>=" "&&t<=""||" "==t||"\n"==t||"\t"==t||"£"==t||"€"==t;static replaceUppercases=(t,e)=>{for(let i=0;i{let e=!0;for(let i=0;i{this.resizeToFit&&this.resize(window.innerWidth,window.innerHeight)}),!1),window.addEventListener("keydown",this.keyDown),window.addEventListener("keyup",this.keyUp),window.addEventListener("mousedown",this.mousePressed),this.canvas.oncontextmenu=t=>{t.preventDefault()},await this.showProgress(0,"Loading..."),await this.load();for(let t=0;t<10;t++)this.otim[t]=Date.now();let t,e=0,i=256,s=1,r=0;for(;this.state>=0;){if(this.state>0&&(this.state--,0===this.state))return void this.shutdown();const a=i,n=s;i=300,s=1,t=Date.now();const o=this.otim[e];if(0===o?(i=a,s=n):t>o&&(i=Math.trunc(2560*this.deltime/(t-o))),i<25?i=25:i>256&&(i=256,s=Math.trunc(this.deltime-(t-o)/10)),this.otim[e]=t,e=(e+1)%10,s>1)for(let t=0;t<10;t++)0!==this.otim[t]&&(this.otim[t]+=s);for(s0&&(this.fps=Math.trunc(1e3*i/(256*this.deltime)));const l=performance.now();await this.draw(),this.frameTime[this.fpos]=(performance.now()-l)/1e3,this.fpos=(this.fpos+1)%this.frameTime.length}-1==this.state&&this.shutdown()}shutdown(){this.state=-2,this.unload()}setLoopRate(t){this.deltime=1e3/t}start(){this.state>=0&&(this.state=0)}stop(){this.state>=0&&(this.state=4e3/this.deltime)}destroy(){this.state=-1}async load(){}update(){}unload(){}async draw(){}refresh(){}async showProgress(t,e){const i=this.ctx,s=this.width,r=this.height;this.redrawScreen&&(i.fillStyle="black",i.clearRect(0,0,s,r),this.redrawScreen=!1);const a=r/2-18;i.fillStyle="rgb(140, 17, 17)",i.rect(s/2-152,a,304,34),i.fillRect(s/2-150,a+2,3*t,30),i.fillStyle="black",i.fillRect(s/2-150+3*t,a+2,300-3*t,30),i.font="bold 13px helvetica, sans-serif",i.textAlign="center",i.fillStyle="white",i.fillText(e,s/2,a+22),await u(5)}keyDown=t=>{this.idleCycles=0;const e=t.keyCode;let i=t.key.charCodeAt(0);83!==i&&(i<30&&(i=0),37==e?i=1:39==e?i=2:38==e?i=3:40==e?i=4:17==e?i=5:8==e||127==e?i=8:9==e?i=9:10==e?i=10:e>=112&&e<=123?i=e+1008-112:36==e?i=1e3:35==e?i=1001:33==e?i=1002:34==e&&(i=1003),i>0&&i<128&&(this.actionKey[i]=1),i>4&&(this.keyQueue[this.keyQueueWritePos]=i,this.keyQueueWritePos=this.keyQueueWritePos+1&127))};keyUp=t=>{this.idleCycles=0;let e=t.key.charCodeAt(0);"ArrowLeft"==t.key?e=1:"ArrowRight"==t.key?e=2:"ArrowUp"==t.key?e=3:"ArrowDown"==t.key&&(e=4),this.actionKey[e]=0};pollKey(){let t=-1;return this.keyQueueWritePos!=this.keyQueueReadPos&&(t=this.keyQueue[this.keyQueueReadPos],this.keyQueueReadPos=this.keyQueueReadPos+1&127),t}mousePressed=t=>{let e=t.x,i=t.y;const{top:s,left:r}=this.getInsets;e-=r,i-=s,this.idleCycles=0,this.mouseClickX=e,this.mouseClickY=i,2===t.buttons?(this.mouseClickButton=2,this.mouseButton=2):1===t.buttons&&(this.mouseClickButton=1,this.mouseButton=1)};get getInsets(){const t=this.canvas.getBoundingClientRect(),e=window.getComputedStyle(this.canvas),i=parseFloat(e.paddingLeft||"0"),s=parseFloat(e.paddingTop||"0"),r=parseFloat(e.borderLeftWidth||"0"),a=parseFloat(e.borderTopWidth||"0"),n=t.left+r+i;return{top:t.top+a+s,left:n}}get ms(){const t=this.frameTime.length;let e=0;for(let i=0;i{Object.getOwnPropertyDescriptor(r.ready,t)||Object.defineProperty(r.ready,t,{get:()=>W("You are getting "+t+" on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js"),set:()=>W("You are setting "+t+" on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js")})}));var a=Object.assign({},r),n=[],o="object"==typeof window,l="function"==typeof importScripts,h="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,c=!o&&!h&&!l;if(r.ENVIRONMENT)throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)");var f,d,u,g="";if(h){if("undefined"==typeof process||!process.release||"node"!==process.release.name)throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");var m,p;g=l?require("path").dirname(g)+"/":__dirname+"/";var w=()=>{p||(m=require("fs"),p=require("path"))};f=(t,e)=>(w(),t=p.normalize(t),m.readFileSync(t,e?void 0:"utf8")),u=t=>{var e=f(t,!0);return e.buffer||(e=new Uint8Array(e)),L(e.buffer),e},d=(t,e,i)=>{w(),t=p.normalize(t),m.readFile(t,(function(t,s){t?i(t):e(s.buffer)}))},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),n=process.argv.slice(2),process.on("uncaughtException",(function(t){if(!(t instanceof st))throw t})),process.on("unhandledRejection",(function(t){throw t})),r.inspect=function(){return"[Emscripten Module object]"}}else if(c){if("object"==typeof process&&"function"==typeof require||"object"==typeof window||"function"==typeof importScripts)throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");"undefined"!=typeof read&&(f=function(t){return read(t)}),u=function(t){let e;return"function"==typeof readbuffer?new Uint8Array(readbuffer(t)):(e=read(t,"binary"),L("object"==typeof e),e)},d=function(t,e,i){setTimeout((()=>e(u(t))),0)},"undefined"!=typeof scriptArgs?n=scriptArgs:void 0!==arguments&&(n=arguments),"undefined"!=typeof print&&("undefined"==typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!=typeof printErr?printErr:print)}else{if(!o&&!l)throw new Error("environment detection error");if(l?g=self.location.href:"undefined"!=typeof document&&document.currentScript&&(g=document.currentScript.src),F&&(g=F),g=0!==g.indexOf("blob:")?g.substr(0,g.replace(/[?#].*/,"").lastIndexOf("/")+1):"","object"!=typeof window&&"function"!=typeof importScripts)throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");f=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},l&&(u=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),d=(t,e,i)=>{var s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="arraybuffer",s.onload=()=>{200==s.status||0==s.status&&s.response?e(s.response):i()},s.onerror=i,s.send(null)}}r.print||console.log.bind(console);var b,y,v,x=r.printErr||console.warn.bind(console);function C(t,e){Object.getOwnPropertyDescriptor(r,t)||Object.defineProperty(r,t,{configurable:!0,get:function(){W("Module."+t+" has been replaced with plain "+e+" (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)")}})}function S(t){return"FS_createPath"===t||"FS_createDataFile"===t||"FS_createPreloadedFile"===t||"FS_unlink"===t||"addRunDependency"===t||"FS_createLazyFile"===t||"FS_createDevice"===t||"removeRunDependency"===t}Object.assign(r,a),a=null,b="fetchSettings",Object.getOwnPropertyDescriptor(r,b)&&W("`Module."+b+"` was supplied but `"+b+"` not included in INCOMING_MODULE_JS_API"),r.arguments&&(n=r.arguments),C("arguments","arguments_"),r.thisProgram&&r.thisProgram,C("thisProgram","thisProgram"),r.quit&&r.quit,C("quit","quit_"),L(void 0===r.memoryInitializerPrefixURL,"Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead"),L(void 0===r.pthreadMainPrefixURL,"Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead"),L(void 0===r.cdInitializerPrefixURL,"Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead"),L(void 0===r.filePackagePrefixURL,"Module.filePackagePrefixURL option was removed, use Module.locateFile instead"),L(void 0===r.read,"Module.read option was removed (modify read_ in JS)"),L(void 0===r.readAsync,"Module.readAsync option was removed (modify readAsync in JS)"),L(void 0===r.readBinary,"Module.readBinary option was removed (modify readBinary in JS)"),L(void 0===r.setWindowTitle,"Module.setWindowTitle option was removed (modify setWindowTitle in JS)"),L(void 0===r.TOTAL_MEMORY,"Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY"),C("read","read_"),C("readAsync","readAsync"),C("readBinary","readBinary"),C("setWindowTitle","setWindowTitle"),L(!c,"shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable."),r.wasmBinary&&(y=r.wasmBinary),C("wasmBinary","wasmBinary"),r.noExitRuntime,C("noExitRuntime","noExitRuntime"),"object"!=typeof WebAssembly&&W("no native wasm support detected");var T,A,k,I,_,O,P,M,E=!1;function L(t,e){t||W("Assertion failed"+(e?": "+e:""))}function B(t){T=t,r.HEAP8=A=new Int8Array(t),r.HEAP16=I=new Int16Array(t),r.HEAP32=_=new Int32Array(t),r.HEAPU8=k=new Uint8Array(t),r.HEAPU16=new Uint16Array(t),r.HEAPU32=O=new Uint32Array(t),r.HEAPF32=P=new Float32Array(t),r.HEAPF64=M=new Float64Array(t)}"undefined"!=typeof TextDecoder&&new TextDecoder("utf8");var R=5242880;r.TOTAL_STACK&&L(R===r.TOTAL_STACK,"the stack size can no longer be determined at runtime");var Y=r.INITIAL_MEMORY||16777216;function D(){if(!E){var t=ct(),e=O[t>>2],i=O[t+4>>2];34821223==e&&2310721022==i||W("Stack overflow! Stack cookie has been overwritten at 0x"+t.toString(16)+", expected hex dwords 0x89BACDFE and 0x2135467, but received 0x"+i.toString(16)+" 0x"+e.toString(16)),1668509029!==O[0]&&W("Runtime error: The application has corrupted its heap memory area (address zero)!")}}C("INITIAL_MEMORY","INITIAL_MEMORY"),L(Y>=R,"INITIAL_MEMORY should be larger than TOTAL_STACK, was "+Y+"! (TOTAL_STACK="+R+")"),L("undefined"!=typeof Int32Array&&"undefined"!=typeof Float64Array&&null!=Int32Array.prototype.subarray&&null!=Int32Array.prototype.set,"JS engine does not provide full typed array support"),L(!r.wasmMemory,"Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally"),L(16777216==Y,"Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically"),function(){var t=new Int16Array(1),e=new Int8Array(t.buffer);if(t[0]=25459,115!==e[0]||99!==e[1])throw"Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)"}();var U=[],G=[],H=[],X=!1;L(Math.imul,"This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),L(Math.fround,"This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),L(Math.clz32,"This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),L(Math.trunc,"This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill");var N=0,z=null,V=null,j={};function W(t){r.onAbort&&r.onAbort(t),x(t="Aborted("+t+")"),E=!0;var e=new WebAssembly.RuntimeError(t);throw s(e),e}var q={error:function(){W("Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM")},init:function(){q.error()},createDataFile:function(){q.error()},createPreloadedFile:function(){q.error()},createLazyFile:function(){q.error()},open:function(){q.error()},mkdev:function(){q.error()},registerDevice:function(){q.error()},analyzePath:function(){q.error()},loadFilesFromDB:function(){q.error()},ErrnoError:function(){q.error()}};r.FS_createDataFile=q.createDataFile,r.FS_createPreloadedFile=q.createPreloadedFile;var Z,$,K,J;function Q(t){return t.startsWith("data:application/octet-stream;base64,")}function tt(t){return t.startsWith("file://")}function et(t,e){return function(){var i=t,s=e;return e||(s=r.asm),L(X,"native function `"+i+"` called before runtime initialization"),s[t]||L(s[t],"exported native function `"+i+"` not found"),s[t].apply(null,arguments)}}function it(t){try{if(t==Z&&y)return new Uint8Array(y);if(u)return u(t);throw"both async and sync fetching of the wasm failed"}catch(t){W(t)}}function st(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function rt(t){for(;t.length>0;)t.shift()(r)}function at(t){at.shown||(at.shown={}),at.shown[t]||(at.shown[t]=1,h&&(t="warning: "+t),x(t))}function nt(t){try{return v.grow(t-T.byteLength+65535>>>16),B(v.buffer),1}catch(e){x("emscripten_realloc_buffer: Attempted to grow heap from "+T.byteLength+" bytes to "+t+" bytes, but got error: "+e)}}r.locateFile?Q(Z="tinymidipcm.wasm")||($=Z,Z=r.locateFile?r.locateFile($,g):g+$):Z=new URL(i(621),i.b).toString();var ot,lt={emscripten_memcpy_big:function(t,e,i){k.copyWithin(t,e,e+i)},emscripten_resize_heap:function(t){var e=k.length;L((t>>>=0)>e);var i,s=2147483648;if(t>s)return x("Cannot enlarge memory, asked to go up to "+t+" bytes, but the limit is "+s+" bytes!"),!1;for(var r=1;r<=4;r*=2){var a=e*(1+.2/r);a=Math.min(a,t+100663296);var n=Math.min(s,(i=Math.max(t,a))+(65536-i%65536)%65536);if(nt(n))return!0}return x("Failed to grow the heap from "+e+" bytes to "+n+" bytes, not enough memory!"),!1}},ht=(function(){var t,e={env:lt,wasi_snapshot_preview1:lt};function i(t,e){var i,s=t.exports;r.asm=s,L(v=r.asm.memory,"memory not found in wasm exports"),B(v.buffer),L(r.asm.__indirect_function_table,"table not found in wasm exports"),i=r.asm.__wasm_call_ctors,G.unshift(i),function(t){if(N--,r.monitorRunDependencies&&r.monitorRunDependencies(N),t?(L(j[t]),delete j[t]):x("warning: run dependency removed without ID"),0==N&&(null!==z&&(clearInterval(z),z=null),V)){var e=V;V=null,e()}}("wasm-instantiate")}t="wasm-instantiate",N++,r.monitorRunDependencies&&r.monitorRunDependencies(N),t?(L(!j[t]),j[t]=1,null===z&&"undefined"!=typeof setInterval&&(z=setInterval((function(){if(E)return clearInterval(z),void(z=null);var t=!1;for(var e in j)t||(t=!0,x("still waiting on run dependencies:")),x("dependency: "+e);t&&x("(end of list)")}),1e4))):x("warning: run dependency added without ID");var a=r;function n(t){L(r===a,"the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?"),a=null,i(t.instance)}function c(t){return function(){if(!y&&(o||l)){if("function"==typeof fetch&&!tt(Z))return fetch(Z,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw"failed to load wasm binary file at '"+Z+"'";return t.arrayBuffer()})).catch((function(){return it(Z)}));if(d)return new Promise((function(t,e){d(Z,(function(e){t(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return it(Z)}))}().then((function(t){return WebAssembly.instantiate(t,e)})).then((function(t){return t})).then(t,(function(t){x("failed to asynchronously prepare wasm: "+t),tt(Z)&&x("warning: Loading from a file URI ("+Z+") is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing"),W(t)}))}if(r.instantiateWasm)try{return r.instantiateWasm(e,i)}catch(t){x("Module.instantiateWasm callback failed with error: "+t),s(t)}(y||"function"!=typeof WebAssembly.instantiateStreaming||Q(Z)||tt(Z)||h||"function"!=typeof fetch?c(n):fetch(Z,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,e).then(n,(function(t){return x("wasm streaming compile failed: "+t),x("falling back to ArrayBuffer instantiation"),c(n)}))}))).catch(s)}(),r.___wasm_call_ctors=et("__wasm_call_ctors"),r._malloc=et("malloc"),r._free=et("free"),r._tsf_load_memory=et("tsf_load_memory"),r._tsf_close=et("tsf_close"),r._tsf_reset=et("tsf_reset"),r._tsf_set_output=et("tsf_set_output"),r._tsf_set_max_voices=et("tsf_set_max_voices"),r._realloc=et("realloc"),r._tsf_channel_set_presetnumber=et("tsf_channel_set_presetnumber"),r._tsf_channel_set_bank_preset=et("tsf_channel_set_bank_preset"),r._tml_load_memory=et("tml_load_memory"),r._midi_render=et("midi_render"),r.___errno_location=et("__errno_location"),r._fflush=et("fflush"),r._emscripten_stack_init=function(){return(ht=r._emscripten_stack_init=r.asm.emscripten_stack_init).apply(null,arguments)}),ct=(r._emscripten_stack_get_free=function(){return(r._emscripten_stack_get_free=r.asm.emscripten_stack_get_free).apply(null,arguments)},r._emscripten_stack_get_base=function(){return(r._emscripten_stack_get_base=r.asm.emscripten_stack_get_base).apply(null,arguments)},r._emscripten_stack_get_end=function(){return(ct=r._emscripten_stack_get_end=r.asm.emscripten_stack_get_end).apply(null,arguments)});function ft(t){function i(){ot||(ot=!0,r.calledRun=!0,E||(L(!X),X=!0,D(),rt(G),e(r),r.onRuntimeInitialized&&r.onRuntimeInitialized(),L(!r._main,'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]'),function(){if(D(),r.postRun)for("function"==typeof r.postRun&&(r.postRun=[r.postRun]);r.postRun.length;)t=r.postRun.shift(),H.unshift(t);var t;rt(H)}()))}var s;t=t||n,N>0||(ht(),L(0==(3&(s=ct()))),O[s>>2]=34821223,O[s+4>>2]=2310721022,O[0]=1668509029,function(){if(r.preRun)for("function"==typeof r.preRun&&(r.preRun=[r.preRun]);r.preRun.length;)t=r.preRun.shift(),U.unshift(t);var t;rt(U)}(),N>0||(r.setStatus?(r.setStatus("Running..."),setTimeout((function(){setTimeout((function(){r.setStatus("")}),1),i()}),1)):i(),D()))}if(r.stackSave=et("stackSave"),r.stackRestore=et("stackRestore"),r.stackAlloc=et("stackAlloc"),r.setValue=function(t,e,i="i8"){switch(i.endsWith("*")&&(i="*"),i){case"i1":case"i8":A[t>>0]=e;break;case"i16":I[t>>1]=e;break;case"i32":_[t>>2]=e;break;case"i64":J=[e>>>0,(K=e,+Math.abs(K)>=1?K>0?(0|Math.min(+Math.floor(K/4294967296),4294967295))>>>0:~~+Math.ceil((K-+(~~K>>>0))/4294967296)>>>0:0)],_[t>>2]=J[0],_[t+4>>2]=J[1];break;case"float":P[t>>2]=e;break;case"double":M[t>>3]=e;break;case"*":O[t>>2]=e;break;default:W("invalid type for setValue: "+i)}},r.getValue=function(t,e="i8"){switch(e.endsWith("*")&&(e="*"),e){case"i1":case"i8":return A[t>>0];case"i16":return I[t>>1];case"i32":case"i64":return _[t>>2];case"float":return P[t>>2];case"double":return M[t>>3];case"*":return O[t>>2];default:W("invalid type for getValue: "+e)}return null},["run","UTF8ArrayToString","UTF8ToString","stringToUTF8Array","stringToUTF8","lengthBytesUTF8","addOnPreRun","addOnInit","addOnPreMain","addOnExit","addOnPostRun","addRunDependency","removeRunDependency","FS_createFolder","FS_createPath","FS_createDataFile","FS_createPreloadedFile","FS_createLazyFile","FS_createLink","FS_createDevice","FS_unlink","getLEB","getFunctionTables","alignFunctionTables","registerFunctions","prettyPrint","getCompilerSetting","print","printErr","callMain","abort","keepRuntimeAlive","wasmMemory","stackAlloc","stackSave","stackRestore","getTempRet0","setTempRet0","writeStackCookie","checkStackCookie","ptrToString","zeroMemory","stringToNewUTF8","exitJS","getHeapMax","emscripten_realloc_buffer","ENV","ERRNO_CODES","ERRNO_MESSAGES","setErrNo","inetPton4","inetNtop4","inetPton6","inetNtop6","readSockaddr","writeSockaddr","DNS","getHostByName","Protocols","Sockets","getRandomDevice","warnOnce","traverseStack","UNWIND_CACHE","convertPCtoSourceLocation","readAsmConstArgsArray","readAsmConstArgs","mainThreadEM_ASM","jstoi_q","jstoi_s","getExecutableName","listenOnce","autoResumeAudioContext","dynCallLegacy","getDynCaller","dynCall","handleException","runtimeKeepalivePush","runtimeKeepalivePop","callUserCallback","maybeExit","safeSetTimeout","asmjsMangle","asyncLoad","alignMemory","mmapAlloc","writeI53ToI64","writeI53ToI64Clamped","writeI53ToI64Signaling","writeI53ToU64Clamped","writeI53ToU64Signaling","readI53FromI64","readI53FromU64","convertI32PairToI53","convertI32PairToI53Checked","convertU32PairToI53","getCFunc","ccall","cwrap","uleb128Encode","sigToWasmTypes","generateFuncType","convertJsFunctionToWasm","freeTableIndexes","functionsInTableMap","getEmptyTableSlot","updateTableMap","addFunction","removeFunction","reallyNegative","unSign","strLen","reSign","formatString","PATH","PATH_FS","intArrayFromString","intArrayToString","AsciiToString","stringToAscii","UTF16Decoder","UTF16ToString","stringToUTF16","lengthBytesUTF16","UTF32ToString","stringToUTF32","lengthBytesUTF32","allocateUTF8","allocateUTF8OnStack","writeStringToMemory","writeArrayToMemory","writeAsciiToMemory","SYSCALLS","getSocketFromFD","getSocketAddress","JSEvents","registerKeyEventCallback","specialHTMLTargets","maybeCStringToJsString","findEventTarget","findCanvasEventTarget","getBoundingClientRect","fillMouseEventData","registerMouseEventCallback","registerWheelEventCallback","registerUiEventCallback","registerFocusEventCallback","fillDeviceOrientationEventData","registerDeviceOrientationEventCallback","fillDeviceMotionEventData","registerDeviceMotionEventCallback","screenOrientation","fillOrientationChangeEventData","registerOrientationChangeEventCallback","fillFullscreenChangeEventData","registerFullscreenChangeEventCallback","JSEvents_requestFullscreen","JSEvents_resizeCanvasForFullscreen","registerRestoreOldStyle","hideEverythingExceptGivenElement","restoreHiddenElements","setLetterbox","currentFullscreenStrategy","restoreOldWindowedStyle","softFullscreenResizeWebGLRenderTarget","doRequestFullscreen","fillPointerlockChangeEventData","registerPointerlockChangeEventCallback","registerPointerlockErrorEventCallback","requestPointerLock","fillVisibilityChangeEventData","registerVisibilityChangeEventCallback","registerTouchEventCallback","fillGamepadEventData","registerGamepadEventCallback","registerBeforeUnloadEventCallback","fillBatteryEventData","battery","registerBatteryEventCallback","setCanvasElementSize","getCanvasElementSize","demangle","demangleAll","jsStackTrace","stackTrace","ExitStatus","getEnvStrings","checkWasiClock","flush_NO_FILESYSTEM","dlopenMissingError","createDyncallWrapper","setImmediateWrapped","clearImmediateWrapped","polyfillSetImmediate","uncaughtExceptionCount","exceptionLast","exceptionCaught","ExceptionInfo","exception_addRef","exception_decRef","Browser","setMainLoop","wget","FS","MEMFS","TTY","PIPEFS","SOCKFS","_setNetworkCallback","tempFixedLengthArray","miniTempWebGLFloatBuffers","heapObjectForWebGLType","heapAccessShiftForWebGLHeap","GL","emscriptenWebGLGet","computeUnpackAlignedImageSize","emscriptenWebGLGetTexPixelData","emscriptenWebGLGetUniform","webglGetUniformLocation","webglPrepareUniformLocationsBeforeFirstUse","webglGetLeftBracePos","emscriptenWebGLGetVertexAttrib","writeGLArray","AL","SDL_unicode","SDL_ttfContext","SDL_audio","SDL","SDL_gfx","GLUT","EGL","GLFW_Window","GLFW","GLEW","IDBStore","runAndAbortIfError","ALLOC_NORMAL","ALLOC_STACK","allocate"].forEach((function(t){Object.getOwnPropertyDescriptor(r,t)||Object.defineProperty(r,t,{configurable:!0,get:function(){var e="'"+t+"' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)";S(t)&&(e+=". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you"),W(e)}})})),["ptrToString","zeroMemory","stringToNewUTF8","exitJS","setErrNo","inetPton4","inetNtop4","inetPton6","inetNtop6","readSockaddr","writeSockaddr","getHostByName","getRandomDevice","traverseStack","convertPCtoSourceLocation","readAsmConstArgs","mainThreadEM_ASM","jstoi_q","jstoi_s","getExecutableName","listenOnce","autoResumeAudioContext","dynCallLegacy","getDynCaller","dynCall","runtimeKeepalivePush","runtimeKeepalivePop","callUserCallback","maybeExit","safeSetTimeout","asmjsMangle","asyncLoad","alignMemory","mmapAlloc","writeI53ToI64","writeI53ToI64Clamped","writeI53ToI64Signaling","writeI53ToU64Clamped","writeI53ToU64Signaling","readI53FromI64","readI53FromU64","convertI32PairToI53","convertI32PairToI53Checked","convertU32PairToI53","getCFunc","ccall","cwrap","uleb128Encode","sigToWasmTypes","generateFuncType","convertJsFunctionToWasm","getEmptyTableSlot","updateTableMap","addFunction","removeFunction","reallyNegative","unSign","strLen","reSign","formatString","intArrayFromString","intArrayToString","AsciiToString","stringToAscii","UTF16ToString","stringToUTF16","lengthBytesUTF16","UTF32ToString","stringToUTF32","lengthBytesUTF32","allocateUTF8","allocateUTF8OnStack","writeStringToMemory","writeAsciiToMemory","getSocketFromFD","getSocketAddress","registerKeyEventCallback","maybeCStringToJsString","findEventTarget","findCanvasEventTarget","getBoundingClientRect","fillMouseEventData","registerMouseEventCallback","registerWheelEventCallback","registerUiEventCallback","registerFocusEventCallback","fillDeviceOrientationEventData","registerDeviceOrientationEventCallback","fillDeviceMotionEventData","registerDeviceMotionEventCallback","screenOrientation","fillOrientationChangeEventData","registerOrientationChangeEventCallback","fillFullscreenChangeEventData","registerFullscreenChangeEventCallback","JSEvents_requestFullscreen","JSEvents_resizeCanvasForFullscreen","registerRestoreOldStyle","hideEverythingExceptGivenElement","restoreHiddenElements","setLetterbox","softFullscreenResizeWebGLRenderTarget","doRequestFullscreen","fillPointerlockChangeEventData","registerPointerlockChangeEventCallback","registerPointerlockErrorEventCallback","requestPointerLock","fillVisibilityChangeEventData","registerVisibilityChangeEventCallback","registerTouchEventCallback","fillGamepadEventData","registerGamepadEventCallback","registerBeforeUnloadEventCallback","fillBatteryEventData","battery","registerBatteryEventCallback","setCanvasElementSize","getCanvasElementSize","getEnvStrings","checkWasiClock","flush_NO_FILESYSTEM","createDyncallWrapper","setImmediateWrapped","clearImmediateWrapped","polyfillSetImmediate","ExceptionInfo","exception_addRef","exception_decRef","setMainLoop","_setNetworkCallback","heapObjectForWebGLType","heapAccessShiftForWebGLHeap","emscriptenWebGLGet","computeUnpackAlignedImageSize","emscriptenWebGLGetTexPixelData","emscriptenWebGLGetUniform","webglGetUniformLocation","webglPrepareUniformLocationsBeforeFirstUse","webglGetLeftBracePos","emscriptenWebGLGetVertexAttrib","writeGLArray","SDL_unicode","SDL_ttfContext","SDL_audio","GLFW_Window","runAndAbortIfError","ALLOC_NORMAL","ALLOC_STACK","allocate"].forEach((function(t){"undefined"==typeof globalThis||Object.getOwnPropertyDescriptor(globalThis,t)||Object.defineProperty(globalThis,t,{configurable:!0,get:function(){var e="`"+t+"` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line";S(t)&&(e+=". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you"),at(e)}})})),V=function t(){ot||ft(),ot||(V=t)},r.preInit)for("function"==typeof r.preInit&&(r.preInit=[r.preInit]);r.preInit.length>0;)r.preInit.pop()();return ft(),t.ready}),R=class{constructor(t={}){this.wasmModule=void 0,this.soundfontBufferPtr=0,this.soundfontPtr=0,this.midiBufferPtr=0,this.renderInterval=t.renderInterval||100,this.sampleRate=t.sampleRate||44100,this.channels=t.channels||2,this.gain=t.gain||0,t.bufferSize?this.bufferSize=t.bufferSize:this.setBufferDuration(1),this.onPCMData=t.onPCMData||(()=>{}),this.onRenderEnd=t.onRenderEnd||(()=>{}),this.renderTimer=void 0,this.test=0}async init(){if(!this.wasmModule){if("undefined"!=typeof process){const{dirname:t}=await import("path"),{createRequire:e}=await import("module");globalThis.__dirname=t("file:///home/runner/work/Client2/Client2/src/js/vendor/tinymidipcm/index.js"),globalThis.require=e("file:///home/runner/work/Client2/Client2/src/js/vendor/tinymidipcm/index.js")}this.wasmModule=await B(),this.pcmBufferPtr=this.wasmModule._malloc(this.bufferSize),this.msecsPtr=this.wasmModule._malloc(8)}}setBufferDuration(t){this.bufferSize=4*this.sampleRate*this.channels*t}ensureInitialized(){if(!this.wasmModule)throw new Error(`${this.constructor.name} not initalized. call .init()`)}setSoundfont(t){this.ensureInitialized();const{_malloc:e,_free:i,_tsf_load_memory:s,_tsf_set_output:r,_tsf_channel_set_bank_preset:a,_tsf_set_max_voices:n,_tsf_channel_set_presetnumber:o}=this.wasmModule;i(this.soundfontBufferPtr),this.soundfontBufferPtr=e(t.length),this.wasmModule.HEAPU8.set(t,this.soundfontBufferPtr),this.soundfontPtr=s(this.soundfontBufferPtr,t.length),r(this.soundfontPtr,2===this.channels?0:2,this.sampleRate,this.gain)}getPCMBuffer(){this.ensureInitialized();const t=new Uint8Array(this.bufferSize);return t.set(this.wasmModule.HEAPU8.subarray(this.pcmBufferPtr,this.pcmBufferPtr+this.bufferSize)),t}getMIDIMessagePtr(t){const{_malloc:e,_free:i,_tml_load_memory:s}=this.wasmModule;return i(this.midiBufferPtr),this.midiBufferPtr=e(t.length),this.wasmModule.HEAPU8.set(t,this.midiBufferPtr),s(this.midiBufferPtr,t.length)}renderMIDIMessage(t){const{_midi_render:e}=this.wasmModule;return e(this.soundfontPtr,t,this.channels,this.sampleRate,this.pcmBufferPtr,this.bufferSize,this.msecsPtr)}render(t){if(this.ensureInitialized(),!this.soundfontPtr)throw new Error("no soundfont buffer set. call .setSoundfont");window.clearTimeout(this.renderTimer);const{setValue:e,getValue:i}=this.wasmModule;e(this.msecsPtr,0,"double"),this.wasmModule._tsf_reset(this.soundfontPtr),this.wasmModule._tsf_channel_set_bank_preset(this.soundfontPtr,9,128,0),t[0]==="R".charCodeAt(0)&&(t=t.slice(20));let s=this.getMIDIMessagePtr(t);const r=()=>{s=this.renderMIDIMessage(s);const t=this.getPCMBuffer();this.onPCMData(t),s?this.renderTimer=setTimeout(r,this.renderInterval):this.onRenderEnd(i(this.msecsPtr,"double"))};this.renderTimer=setTimeout(r,16)}};!function(){window.AudioContext=window.AudioContext||window.webkitAudioContext,window.AudioContext&&(window.audioContext=new window.AudioContext);var t=function(e){if(window.audioContext){var i=window.audioContext.createBuffer(1,1,22050),s=window.audioContext.createBufferSource();s.buffer=i,s.connect(window.audioContext.destination),s.start?s.start(0):s.play?s.play(0):s.noteOn&&s.noteOn(0)}document.removeEventListener("touchstart",t),document.removeEventListener("touchend",t),document.removeEventListener("click",t)};document.addEventListener("touchstart",t),document.addEventListener("touchend",t),document.addEventListener("click",t)}(),(async()=>{let t=0,e=null,i=new Float32Array,s=window.audioContext.createGain();s.gain.value=.1,s.connect(window.audioContext.destination);let r=0,a=window.audioContext.currentTime,n=[];const o=new R({renderInterval:30,onPCMData:t=>{let e=new Float32Array(t.buffer),s=new Float32Array(i.length+e.length);s.set(i,0),s.set(e,i.length),i=s},onRenderEnd:e=>{t=Math.floor(r+Math.floor(e/1e3))},bufferSize:102400});await o.init();const l=await fetch("./SCC1_Florestan.sf2"),h=new Uint8Array(await l.arrayBuffer());function c(){if(!window.audioContext||!i.length)return;let r=window.audioContext.createBufferSource();r.onended=function(i){const s=Math.floor(window.audioContext.currentTime);t>0&&Math.abs(s-t)<=2&&(t=0,e&&window._tinyMidiPlay(e,-1))};const o=i.length/2,l=window.audioContext.createBuffer(2,o,44100);for(let t=0;t<2;t++){const e=l.getChannelData(t);let s=t;for(let t=0;t{if(f&&clearInterval(f),e=null,i=new Float32Array,n.length){let t=s.gain.value;s.gain.value=0,n.forEach((t=>{t.stop(window.audioContext.currentTime)})),n=[],s.gain.value=t}},window._tinyMidiVolume=(t=1)=>{s.gain.value=t},window._tinyMidiPlay=async(t,i=1)=>{t&&(await window._tinyMidiStop(),-1!=i&&window._tinyMidiVolume(i),e=t,r=window.audioContext.currentTime,a=window.audioContext.currentTime,f=setInterval(c,250),o.render(t))}})();class Y{static unpack=t=>{}}class D{static BASE37_LOOKUP=["_","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];static toBase37=t=>{t=t.trim();let e=0n;for(let i=0;i=65&&s<=90?e+=BigInt(s+1-65):s>=97&&s<=122?e+=BigInt(s+1-97):s>=48&&s<=57&&(e+=BigInt(s+27-48))}return e};static fromBase37=t=>{if(t<0n||t>=6582952005840035281n)return"invalid_name";if(t%37n==0n)return"invalid_name";let e=0;const i=[0,0,0,0,0,0,0,0,0,0,0,0];for(;0n!=t;){const s=t;t/=37n,i[11-e++]=Number(this.BASE37_LOOKUP[Number(s-37n*t)])}return i.slice(12-e).join("")};static toSentenceCase=t=>{const e=[...t.toLowerCase()];let i=!0;for(let t=0;t="a"&&s<="z"&&(e[t]=s.toUpperCase(),i=!1),"."!==s&&"!"!==s||(i=!0)}return e.join("")};static toAsterisks=t=>{let e="";for(let i=0;i{if(0==t.length)return t;const e=[...t];for(let t=0;t="a"&&e[t+1]<="z"&&(e[t+1]=String.fromCharCode(e[t+1].charCodeAt(0)+"A".charCodeAt(0)-97)));return e[0]>="a"&&e[0]<="z"&&(e[0]=String.fromCharCode(e[0].charCodeAt(0)+"A".charCodeAt(0)-97)),e.join("")}}class U{static visibilityMatrix=[];static viewportLeft=0;static viewportTop=0;static viewportRight=0;static viewportBottom=0;static viewportCenterX=0;static viewportCenterY=0;static sinEyePitch=0;static cosEyePitch=0;static sinEyeYaw=0;static cosEyeYaw=0;static{this.visibilityMatrix=new Array(8);for(let t=0;t<8;t++){this.visibilityMatrix[t]=new Array(32);for(let e=0;e<32;e++){this.visibilityMatrix[t][e]=new Array(51);for(let i=0;i<51;i++)this.visibilityMatrix[t][e][i]=new Array(51).fill(!1)}}}static init=(t,e,i,s,r)=>{this.viewportLeft=0,this.viewportTop=0,this.viewportRight=t,this.viewportBottom=e,this.viewportCenterX=t/2,this.viewportCenterY=e/2;const a=new Array(9);for(let t=0;t<9;t++){a[t]=new Array(32);for(let e=0;e<32;e++){a[t][e]=new Array(53);for(let i=0;i<53;i++)a[t][e][i]=new Array(53).fill(!1)}}for(let t=128;t<=384;t+=32)for(let e=0;e<2048;e+=64){this.sinEyePitch=T.sin[t],this.cosEyePitch=T.cos[t],this.sinEyeYaw=T.sin[e],this.cosEyeYaw=T.cos[e];const n=(t-128)/32,o=e/64;for(let t=-26;t<=26;t++)for(let e=-26;e<=26;e++){const l=128*t,h=128*e;let c=!1;for(let t=-i;t<=s;t+=128)if(this.testPoint(l,h,r[n]+t)){c=!0;break}a[n][o][t+25+1][e+25+1]=c}}for(let t=0;t<8;t++)for(let e=0;e<32;e++)for(let i=-25;i<25;i++)for(let s=-25;s<25;s++){let r=!1;t:for(let n=-1;n<=1;n++)for(let o=-1;o<=1;o++){if(a[t][e][i+n+25+1][s+o+25+1]){r=!0;break t}if(a[t][(e+1)%31][i+n+25+1][s+o+25+1]){r=!0;break t}if(a[t+1][e][i+n+25+1][s+o+25+1]){r=!0;break t}if(a[t+1][(e+1)%31][i+n+25+1][s+o+25+1]){r=!0;break t}}this.visibilityMatrix[t][e][i+25][s+25]=r}};static testPoint=(t,e,i)=>{const s=e*this.sinEyeYaw+t*this.cosEyeYaw>>16,r=e*this.cosEyeYaw-t*this.sinEyeYaw>>16,a=i*this.sinEyePitch+r*this.cosEyePitch>>16,n=i*this.cosEyePitch-r*this.sinEyePitch>>16;if(a<50||a>3500)return!1;const o=this.viewportCenterX+(s<<9)/a,l=this.viewportCenterY+(n<<9)/a;return o>=this.viewportLeft&&o<=this.viewportRight&&l>=this.viewportTop&&l<=this.viewportBottom}}class G extends L{static HOST="https://w2.225.2004scape.org";static CHARSET="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";static MEMBERS=!0;static LOW_MEMORY=!1;SCROLLBAR_TRACK=2301979;SCROLLBAR_GRIP_FOREGROUND=5063219;SCROLLBAR_GRIP_HIGHLIGHT=7759444;SCROLLBAR_GRIP_LOWLIGHT=3353893;alreadyStarted=!1;errorStarted=!1;errorLoading=!1;errorHost=!1;loopCycle=0;ingame=!1;archiveChecksums=[];redrawTitleBackground=!0;titleScreenState=0;titleLoginField=0;titleArchive=null;imageTitle2=null;imageTitle3=null;imageTitle4=null;imageTitle0=null;imageTitle1=null;imageTitle5=null;imageTitle6=null;imageTitle7=null;imageTitle8=null;imageTitlebox=null;imageTitlebutton=null;loginMessage0="";loginMessage1="";username="";password="";fontPlain11=null;fontPlain12=null;fontBold12=null;fontQuill8=null;imageRunes=[];flameActive=!1;imageFlamesLeft=null;imageFlamesRight=null;flameBuffer1=[];flameBuffer0=[];flameBuffer3=[];flameBuffer2=[];flameGradient=[];flameGradient0=[];flameGradient1=[];flameGradient2=[];flameLineOffset=[];flameCycle0=0;flameGradientCycle0=0;flameGradientCycle1=0;flamesInterval=null;areaSidebar=null;areaMapback=null;areaViewport=null;areaChatback=null;areaBackbase1=null;areaBackbase2=null;areaBackhmid1=null;areaBackleft1=null;areaBackleft2=null;areaBackright1=null;areaBackright2=null;areaBacktop1=null;areaBacktop2=null;areaBackvmid1=null;areaBackvmid2=null;areaBackvmid3=null;areaBackhmid2=null;areaChatbackOffsets=null;areaSidebarOffsets=null;areaViewportOffsets=null;compassMaskLineOffsets=new Uint16Array(33);compassMaskLineLengths=new Uint16Array(33);minimapMaskLineOffsets=new Uint16Array(151);minimapMaskLineLengths=new Uint16Array(151);imageInvback=null;imageChatback=null;imageMapback=null;imageBackbase1=null;imageBackbase2=null;imageBackhmid1=null;imageSideicons=[];imageCompass=null;imageMapscene=[];imageMapfunction=[];imageHitmarks=[];imageHeadicons=[];imageMapflag=null;imageCrosses=[];imageMapdot0=null;imageMapdot1=null;imageMapdot2=null;imageMapdot3=null;imageScrollbar0=null;imageScrollbar1=null;imageRedstone1=null;imageRedstone2=null;imageRedstone3=null;imageRedstone1h=null;imageRedstone2h=null;imageRedstone1v=null;imageRedstone2v=null;imageRedstone3v=null;imageRedstone1hv=null;imageRedstone2hv=null;redrawSidebar=!1;redrawChatback=!1;redrawSideicons=!1;redrawPrivacySettings=!1;dragCycles=0;sceneState=0;sceneDelta=0;menuVisible=!1;menuArea=0;menuX=0;menuY=0;menuWidth=0;menuHeight=0;menuSize=0;menuOption=[];sidebarInterfaceId=-1;chatInterfaceId=-1;chatInterface=new _;chatScrollHeight=78;chatScrollOffset=0;modalMessage=null;flashingTab=-1;selectedTab=3;tabInterfaceId=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];publicChatSetting=0;privateChatSetting=0;tradeChatSetting=0;scrollGrabbed=!1;scrollInputPadding=0;showSocialInput=!1;socialMessage="";socialInput="";chatbackInput="";chatbackInputOpen=!1;stickyChatInterfaceId=-1;messageText=[];messageSender=[];messageType=[];splitPrivateChat=0;chatTyped="";viewportHoveredInterfaceIndex=0;sidebarHoveredInterfaceIndex=0;chatHoveredInterfaceIndex=0;objDragInterfaceId=0;objDragSlot=0;objDragArea=0;objGrabX=0;objGrabY=0;objDragCycles=0;selectedArea=0;selectedItem=0;selectedInterface=0;selectedCycle=0;pressedContinueOption=!1;runFlames=()=>{this.flameActive&&(this.updateFlames(),this.updateFlames(),this.drawFlames())};load=async()=>{if(this.alreadyStarted)this.errorStarted=!0;else{this.alreadyStarted=!0;try{await this.showProgress(10,"Connecting to fileserver");const t=new e(await g(`${G.HOST}/crc`));for(let e=0;e<9;e++)this.archiveChecksums[e]=t.g4;await this.setMidi("scape_main",12345678),this.titleArchive=await this.loadArchive("title","title screen",this.archiveChecksums[1],10),this.fontPlain11=P.fromArchive(this.titleArchive,"p11"),this.fontPlain12=P.fromArchive(this.titleArchive,"p12"),this.fontBold12=P.fromArchive(this.titleArchive,"b12"),this.fontQuill8=P.fromArchive(this.titleArchive,"q8"),await this.loadTitleBackground(),this.loadTitleImages();const i=await this.loadArchive("config","config",this.archiveChecksums[2],15),l=await this.loadArchive("interface","interface",this.archiveChecksums[3],20),h=await this.loadArchive("media","2d graphics",this.archiveChecksums[4],30),c=await this.loadArchive("models","3d graphics",this.archiveChecksums[5],40),f=await this.loadArchive("textures","textures",this.archiveChecksums[6],60),d=await this.loadArchive("wordenc","chat system",this.archiveChecksums[7],65),u=await this.loadArchive("sounds","sound effects",this.archiveChecksums[8],70);await this.showProgress(75,"Unpacking media"),this.imageInvback=S.fromArchive(h,"invback",0),this.imageChatback=S.fromArchive(h,"chatback",0),this.imageMapback=S.fromArchive(h,"mapback",0),this.imageBackbase1=S.fromArchive(h,"backbase1",0),this.imageBackbase2=S.fromArchive(h,"backbase2",0),this.imageBackhmid1=S.fromArchive(h,"backhmid1",0);for(let t=0;t<13;t++)this.imageSideicons[t]=S.fromArchive(h,"sideicons",t);this.imageCompass=w.fromArchive(h,"compass",0);try{for(let t=0;t<50;t++)this.imageMapscene[t]=S.fromArchive(h,"mapscene",t)}catch(t){}try{for(let t=0;t<50;t++)this.imageMapfunction[t]=w.fromArchive(h,"mapfunction",t)}catch(t){}try{for(let t=0;t<20;t++)this.imageHitmarks[t]=w.fromArchive(h,"hitmarks",t)}catch(t){}try{for(let t=0;t<20;t++)this.imageHeadicons[t]=w.fromArchive(h,"headicons",t)}catch(t){}this.imageMapflag=w.fromArchive(h,"mapflag",0);for(let t=0;t<8;t++)this.imageCrosses[t]=w.fromArchive(h,"cross",t);this.imageMapdot0=w.fromArchive(h,"mapdots",0),this.imageMapdot1=w.fromArchive(h,"mapdots",1),this.imageMapdot2=w.fromArchive(h,"mapdots",2),this.imageMapdot3=w.fromArchive(h,"mapdots",3),this.imageScrollbar0=S.fromArchive(h,"scrollbar",0),this.imageScrollbar1=S.fromArchive(h,"scrollbar",1),this.imageRedstone1=S.fromArchive(h,"redstone1",0),this.imageRedstone2=S.fromArchive(h,"redstone2",0),this.imageRedstone3=S.fromArchive(h,"redstone3",0),this.imageRedstone1h=S.fromArchive(h,"redstone1",0),this.imageRedstone1h?.flipHorizontally(),this.imageRedstone2h=S.fromArchive(h,"redstone2",0),this.imageRedstone2h?.flipHorizontally(),this.imageRedstone1v=S.fromArchive(h,"redstone1",0),this.imageRedstone1v?.flipVertically(),this.imageRedstone2v=S.fromArchive(h,"redstone2",0),this.imageRedstone2v?.flipVertically(),this.imageRedstone3v=S.fromArchive(h,"redstone3",0),this.imageRedstone3v?.flipVertically(),this.imageRedstone1hv=S.fromArchive(h,"redstone1",0),this.imageRedstone1hv?.flipHorizontally(),this.imageRedstone1hv?.flipVertically(),this.imageRedstone2hv=S.fromArchive(h,"redstone2",0),this.imageRedstone2hv?.flipHorizontally(),this.imageRedstone2hv?.flipVertically();const m=this.canvas,p=w.fromArchive(h,"backleft1",0);this.areaBackleft1=new O(m,p.width,p.height),p.blitOpaque(0,0);const A=w.fromArchive(h,"backleft2",0);this.areaBackleft2=new O(m,A.width,A.height),A.blitOpaque(0,0);const k=w.fromArchive(h,"backright1",0);this.areaBackright1=new O(m,k.width,k.height),k.blitOpaque(0,0);const M=w.fromArchive(h,"backright2",0);this.areaBackright2=new O(m,M.width,M.height),M.blitOpaque(0,0);const L=w.fromArchive(h,"backtop1",0);this.areaBacktop1=new O(m,L.width,L.height),L.blitOpaque(0,0);const F=w.fromArchive(h,"backtop2",0);this.areaBacktop2=new O(m,F.width,F.height),F.blitOpaque(0,0);const B=w.fromArchive(h,"backvmid1",0);this.areaBackvmid1=new O(m,B.width,B.height),B.blitOpaque(0,0);const R=w.fromArchive(h,"backvmid2",0);this.areaBackvmid2=new O(m,R.width,R.height),R.blitOpaque(0,0);const D=w.fromArchive(h,"backvmid3",0);this.areaBackvmid3=new O(m,D.width,D.height),D.blitOpaque(0,0);const H=w.fromArchive(h,"backhmid2",0);this.areaBackhmid2=new O(m,H.width,H.height),H.blitOpaque(0,0);const X=Math.trunc(21*Math.random())-10,N=Math.trunc(21*Math.random())-10,z=Math.trunc(21*Math.random())-10,V=Math.trunc(41*Math.random())-20;for(let t=0;t<50;t++)null!=this.imageMapfunction[t]&&this.imageMapfunction[t].translate(X+V,N+V,z+V),null!=this.imageMapscene[t]&&this.imageMapscene[t].translate(X+V,N+V,z+V);await this.showProgress(80,"Unpacking textures"),T.unpackTextures(f),T.setBrightness(.8),T.initPool(20),await this.showProgress(83,"Unpacking models"),I.unpack(c),s.unpack(c),r.unpack(c),await this.showProgress(86,"Unpacking config"),a.unpack(i),n.unpack(i),o.unpack(i),b.unpack(i,G.MEMBERS),y.unpack(i),v.unpack(i),x.unpack(i),C.unpack(i),G.LOW_MEMORY||(await this.showProgress(90,"Unpacking sounds"),Y.unpack(u)),await this.showProgress(92,"Unpacking interfaces"),_.unpack(l,h,[this.fontPlain11,this.fontPlain12,this.fontBold12,this.fontQuill8]),await this.showProgress(97,"Preparing game engine");for(let t=0;t<33;t++){let e=999,i=0;for(let s=0;s<35;s++)if(0==this.imageMapback.pixels[s+t*this.imageMapback.width])999==e&&(e=s);else if(999!=e){i=s;break}this.compassMaskLineOffsets[t]=e,this.compassMaskLineLengths[t]=i-e}for(let t=9;t<160;t++){let e=999,i=0;for(let s=10;s<168;s++)if(0==this.imageMapback.pixels[s+t*this.imageMapback.width]&&(s>34||t>34))999==e&&(e=s);else if(999!=e){i=s;break}this.minimapMaskLineOffsets[t-9]=e-21,this.minimapMaskLineLengths[t-9]=i-e}T.init3D(479,96),this.areaChatbackOffsets=T.lineOffset,T.init3D(190,261),this.areaSidebarOffsets=T.lineOffset,T.init3D(512,334),this.areaViewportOffsets=T.lineOffset;const j=new Int32Array(9);for(let t=0;t<9;t++){const e=32*t+128+15,i=3*e+600,s=T.sin[e];j[t]=i*s>>16}U.init(512,334,500,800,j),E.unpack(d)}catch(t){console.error(t),this.errorLoading=!0}}};update=()=>{this.errorStarted||this.errorLoading||this.errorHost||(this.loopCycle++,this.ingame?this.updateGame():this.updateTitleScreen())};draw=async()=>{this.errorStarted||this.errorLoading||this.errorHost?this.drawError():(this.ingame?this.drawGame():await this.drawTitleScreen(),this.dragCycles=0)};refresh=()=>{this.redrawTitleBackground=!0};showProgress=async(t,e)=>{console.log(`${t}%: ${e}`),await this.loadTitle(),this.titleArchive?(this.imageTitle4?.bind(),this.fontBold12?.drawStringCenter(180,54,"RuneScape is loading - please wait...",16777215),l.drawRect(28,62,304,34,9179409),l.drawRect(29,63,302,32,0),l.fillRect(30,64,3*t,30,9179409),l.fillRect(30+3*t,64,300-3*t,30,0),this.fontBold12?.drawStringCenter(180,85,e,16777215),this.imageTitle4?.draw(214,186),this.redrawTitleBackground&&(this.redrawTitleBackground=!1,this.flameActive||(this.imageTitle0?.draw(0,0),this.imageTitle1?.draw(661,0)),this.imageTitle2?.draw(128,0),this.imageTitle3?.draw(214,386),this.imageTitle5?.draw(0,265),this.imageTitle6?.draw(574,265),this.imageTitle7?.draw(128,186),this.imageTitle8?.draw(574,186)),await u(5)):await super.showProgress(t,e)};loadTitle=async()=>{if(null===this.imageTitle2){this.drawArea=null,this.areaChatback=null,this.areaMapback=null,this.areaSidebar=null,this.areaViewport=null,this.areaBackbase1=null,this.areaBackbase2=null,this.areaBackhmid1=null;const t=this.canvas;this.imageTitle0=new O(t,128,265),l.clear(),this.imageTitle1=new O(t,128,265),l.clear(),this.imageTitle2=new O(t,533,186),l.clear(),this.imageTitle3=new O(t,360,146),l.clear(),this.imageTitle4=new O(t,360,200),l.clear(),this.imageTitle5=new O(t,214,267),l.clear(),this.imageTitle6=new O(t,215,267),l.clear(),this.imageTitle7=new O(t,86,79),l.clear(),this.imageTitle8=new O(t,87,79),l.clear(),null!==this.titleArchive&&(await this.loadTitleBackground(),this.loadTitleImages()),this.redrawTitleBackground=!0}};loadTitleBackground=async()=>{if(!this.titleArchive)return;const t=await w.fromJpeg(this.titleArchive,"title");this.imageTitle0?.bind(),t.blitOpaque(0,0),this.imageTitle1?.bind(),t.blitOpaque(-661,0),this.imageTitle2?.bind(),t.blitOpaque(-128,0),this.imageTitle3?.bind(),t.blitOpaque(-214,-386),this.imageTitle4?.bind(),t.blitOpaque(-214,-186),this.imageTitle5?.bind(),t.blitOpaque(0,-265),this.imageTitle6?.bind(),t.blitOpaque(-128,-186),this.imageTitle7?.bind(),t.blitOpaque(-128,-186),this.imageTitle8?.bind(),t.blitOpaque(-574,-186),t.flipHorizontally(),this.imageTitle0?.bind(),t.blitOpaque(394,0),this.imageTitle1?.bind(),t.blitOpaque(-267,0),this.imageTitle2?.bind(),t.blitOpaque(266,0),this.imageTitle3?.bind(),t.blitOpaque(180,-386),this.imageTitle4?.bind(),t.blitOpaque(180,-186),this.imageTitle5?.bind(),t.blitOpaque(394,-265),this.imageTitle6?.bind(),t.blitOpaque(-180,-265),this.imageTitle7?.bind(),t.blitOpaque(212,-186),this.imageTitle8?.bind(),t.blitOpaque(-180,-186);const e=w.fromArchive(this.titleArchive,"logo");this.imageTitle2?.bind(),e.draw(this.width/2-e.width/2-128,18)};updateFlameBuffer=t=>{for(let t=0;t<32768;t++)this.flameBuffer0[t]=0;for(let t=0;t<5e3;t++){const t=Math.trunc(128*Math.random()*256);this.flameBuffer0[t]=Math.trunc(256*Math.random())}for(let t=0;t<20;t++){for(let t=1;t{if(this.titleArchive){this.imageTitlebox=S.fromArchive(this.titleArchive,"titlebox"),this.imageTitlebutton=S.fromArchive(this.titleArchive,"titlebutton");for(let t=0;t<12;t++)this.imageRunes[t]=S.fromArchive(this.titleArchive,"runes",t);this.imageFlamesLeft=new w(128,265),this.imageFlamesRight=new w(128,265),this.imageTitle0&&p(this.imageTitle0.pixels,0,this.imageFlamesLeft.pixels,0,33920),this.imageTitle1&&p(this.imageTitle1.pixels,0,this.imageFlamesRight.pixels,0,33920),this.flameGradient0=[];for(let t=0;t<64;t++)this.flameGradient0[t]=262144*t;for(let t=0;t<64;t++)this.flameGradient0[t+64]=1024*t+16711680;for(let t=0;t<64;t++)this.flameGradient0[t+128]=4*t+16776960;for(let t=0;t<64;t++)this.flameGradient0[t+192]=16777215;this.flameGradient1=[];for(let t=0;t<64;t++)this.flameGradient1[t]=1024*t;for(let t=0;t<64;t++)this.flameGradient1[t+64]=4*t+65280;for(let t=0;t<64;t++)this.flameGradient1[t+128]=262144*t+65535;for(let t=0;t<64;t++)this.flameGradient1[t+192]=16777215;this.flameGradient2=[];for(let t=0;t<64;t++)this.flameGradient2[t]=4*t;for(let t=0;t<64;t++)this.flameGradient2[t+64]=262144*t+255;for(let t=0;t<64;t++)this.flameGradient2[t+128]=1024*t+16711935;for(let t=0;t<64;t++)this.flameGradient2[t+192]=16777215;this.flameGradient=[],this.flameBuffer0=[],this.flameBuffer1=[],this.updateFlameBuffer(null),this.flameBuffer3=[],this.flameBuffer2=[],this.showProgress(10,"Connecting to fileserver").then((()=>{this.flameActive||(this.flameActive=!0,this.flamesInterval=setInterval(this.runFlames,35))}))}};updateTitleScreen=()=>{if(0===this.titleScreenState){let t=this.width/2-80,e=this.height/2+20;e+=20,1==this.mouseClickButton&&this.mouseClickX>=t-75&&this.mouseClickX<=t+75&&this.mouseClickY>=e-20&&this.mouseClickY<=e+20&&(this.titleScreenState=3,this.titleLoginField=0),t=this.width/2+80,1==this.mouseClickButton&&this.mouseClickX>=t-75&&this.mouseClickX<=t+75&&this.mouseClickY>=e-20&&this.mouseClickY<=e+20&&(this.loginMessage0="",this.loginMessage1="Enter your username & password.",this.titleScreenState=2,this.titleLoginField=0)}else if(2==this.titleScreenState){let t=this.height/2-40;t+=30,t+=25,1==this.mouseClickButton&&this.mouseClickY>=t-15&&this.mouseClickY=t-15&&this.mouseClickY=e-75&&this.mouseClickX<=e+75&&this.mouseClickY>=i-20&&this.mouseClickY<=i+20&&this.login(this.username,this.password,!1).then((()=>{})),e=this.width/2+80,1==this.mouseClickButton&&this.mouseClickX>=e-75&&this.mouseClickX<=e+75&&this.mouseClickY>=i-20&&this.mouseClickY<=i+20&&(this.titleScreenState=0,this.username="",this.password="");;){const t=this.pollKey();if(-1==t)return;let e=!1;for(let i=0;i0&&(this.username=this.username.substring(0,this.username.length-1)),9!=t&&10!=t&&13!=t||(this.titleLoginField=1),e&&(this.username=this.username+String.fromCharCode(t)),this.username.length>12&&(this.username=this.username.substring(0,12))):1==this.titleLoginField&&(8==t&&this.password.length>0&&(this.password=this.password.substring(0,this.password.length-1)),9!=t&&10!=t&&13!=t||(this.titleLoginField=0),e&&(this.password=this.password+String.fromCharCode(t)),this.password.length>20&&(this.password=this.password.substring(0,20)))}}else if(3==this.titleScreenState){const t=this.width/2;let e=this.height/2+50;e+=20,1==this.mouseClickButton&&this.mouseClickX>=t-75&&this.mouseClickX<=t+75&&this.mouseClickY>=e-20&&this.mouseClickY<=e+20&&(this.titleScreenState=0)}};drawTitleScreen=async()=>{if(await this.loadTitle(),this.imageTitle4?.bind(),this.imageTitlebox?.draw(0,0),0===this.titleScreenState){let t=180,e=80;this.fontBold12?.drawStringTaggableCenter(t,e,"Welcome to RuneScape",4294967040,!0),t=100,e=120,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"New user",4294967295,!0),t=260,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"Existing User",4294967295,!0)}else if(2===this.titleScreenState){let t=100,e=60;0===this.loginMessage0.length?(this.fontBold12?.drawStringTaggableCenter(180,e-15,this.loginMessage0,16776960,!0),this.fontBold12?.drawStringTaggableCenter(180,e,this.loginMessage1,16776960,!0),e+=30):(this.fontBold12?.drawStringTaggableCenter(180,e-7,this.loginMessage1,16776960,!0),e+=30),this.fontBold12?.drawStringTaggable(90,e,`Username: ${this.username}${0==this.titleLoginField&&this.loopCycle%40<20?"@yel@|":""}`,16777215,!0),e+=15,this.fontBold12?.drawStringTaggable(92,e,`Password: ${D.toAsterisks(this.password)}${1==this.titleLoginField&&this.loopCycle%40<20?"@yel@|":""}`,16777215,!0),e=150,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"Login",16777215,!0),t=260,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"Cancel",16777215,!0)}else if(3==this.titleScreenState){this.fontBold12?.drawStringTaggableCenter(180,16776960,"Create a free account",40,!0);const t=180;let e=65;this.fontBold12?.drawStringTaggableCenter(180,e,"To create a new account you need to",16777215,!0),e+=15,this.fontBold12?.drawStringTaggableCenter(180,e,"go back to the main RuneScape webpage",16777215,!0),e+=15,this.fontBold12?.drawStringTaggableCenter(180,e,"and choose the red 'create account'",16777215,!0),e+=15,this.fontBold12?.drawStringTaggableCenter(180,e,"button at the top right of that page.",16777215,!0),e=150,this.imageTitlebutton?.draw(t-73,e-20),this.fontBold12?.drawStringTaggableCenter(t,e+5,"Cancel",16777215,!0)}this.imageTitle4?.draw(214,186),this.redrawTitleBackground&&(this.redrawTitleBackground=!1,this.imageTitle2?.draw(128,0),this.imageTitle3?.draw(214,386),this.imageTitle5?.draw(0,265),this.imageTitle6?.draw(574,265),this.imageTitle7?.draw(128,186),this.imageTitle8?.draw(574,186))};login=async(t,e,i)=>{try{this.ingame=!0,this.prepareGameScreen()}catch(t){this.loginMessage0="",this.loginMessage1="Error connecting to server."}};updateGame=()=>{this.ingame&&(this.sceneDelta++,1!=this.mouseButton&&1!=this.mouseClickButton||this.dragCycles++)};drawGame=()=>{this.redrawTitleBackground&&(this.redrawTitleBackground=!1,this.areaBackleft1?.draw(0,11),this.areaBackleft2?.draw(0,375),this.areaBackright1?.draw(729,5),this.areaBackright2?.draw(752,231),this.areaBacktop1?.draw(0,0),this.areaBacktop2?.draw(561,0),this.areaBackvmid1?.draw(520,11),this.areaBackvmid2?.draw(520,231),this.areaBackvmid3?.draw(501,375),this.areaBackhmid2?.draw(0,345),this.redrawSidebar=!0,this.redrawChatback=!0,this.redrawSideicons=!0,this.redrawPrivacySettings=!0,2!=this.sceneState&&(this.areaViewport?.draw(8,11),this.areaMapback?.draw(561,5))),2==this.sceneState&&this.drawScene(),this.menuVisible&&1==this.menuArea&&(this.redrawSidebar=!0);let t=!1;if(-1!=this.sidebarInterfaceId&&(t=this.updateInterfaceAnimation(this.sidebarInterfaceId,this.sceneDelta),t&&(this.redrawSidebar=!0)),2==this.selectedArea&&(this.redrawSidebar=!0),2==this.objDragArea&&(this.redrawSidebar=!0),this.redrawSidebar&&(this.drawSidebar(),this.redrawSidebar=!1),-1==this.chatInterfaceId){this.chatInterface.scrollPosition=this.chatScrollHeight-this.chatScrollOffset-77,this.mouseX>453&&this.mouseX<565&&this.mouseY>350&&this.handleScrollInput(this.mouseX-22,this.mouseY-375,this.chatScrollHeight,77,!1,463,0,this.chatInterface);let t=this.chatScrollHeight-this.chatInterface.scrollPosition-77;t<0&&(t=0),t>this.chatScrollHeight-77&&(t=this.chatScrollHeight-77),this.chatScrollOffset!=t&&(this.chatScrollOffset=t,this.redrawChatback=!0)}-1!=this.chatInterfaceId&&(t=this.updateInterfaceAnimation(this.chatInterfaceId,this.sceneDelta),t&&(this.redrawChatback=!0)),3==this.selectedArea&&(this.redrawChatback=!0),3==this.objDragArea&&(this.redrawChatback=!0),null!=this.modalMessage&&(this.redrawChatback=!0),this.menuVisible&&2==this.menuArea&&(this.redrawChatback=!0),this.redrawChatback&&(this.drawChatback(),this.redrawChatback=!1),2==this.sceneState&&(this.drawMinimap(),this.areaMapback?.draw(561,5)),-1!=this.flashingTab&&(this.redrawSideicons=!0),this.redrawSideicons&&(this.redrawSideicons=!1,this.areaBackhmid1?.bind(),this.imageBackhmid1?.draw(0,0),-1==this.sidebarInterfaceId&&(-1!=this.tabInterfaceId[this.selectedTab]&&(0==this.selectedTab?this.imageRedstone1?.draw(29,30):1==this.selectedTab?this.imageRedstone2?.draw(59,29):2==this.selectedTab?this.imageRedstone2?.draw(87,29):3==this.selectedTab?this.imageRedstone3?.draw(115,29):4==this.selectedTab?this.imageRedstone2h?.draw(156,29):5==this.selectedTab?this.imageRedstone2h?.draw(184,29):6==this.selectedTab&&this.imageRedstone1h?.draw(212,30)),-1!=this.tabInterfaceId[0]&&(0!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[0].draw(35,34),-1!=this.tabInterfaceId[1]&&(1!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[1].draw(59,32),-1!=this.tabInterfaceId[2]&&(2!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[2].draw(86,32),-1!=this.tabInterfaceId[3]&&(3!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[3].draw(121,33),-1!=this.tabInterfaceId[4]&&(4!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[4].draw(157,34),-1!=this.tabInterfaceId[5]&&(5!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[5].draw(185,32),-1!=this.tabInterfaceId[6]&&(6!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[6].draw(212,34)),this.areaBackhmid1?.draw(520,165),this.areaBackbase2?.bind(),this.imageBackbase2?.draw(0,0),-1==this.sidebarInterfaceId&&(-1!=this.tabInterfaceId[this.selectedTab]&&(7==this.selectedTab?this.imageRedstone1v?.draw(49,0):8==this.selectedTab?this.imageRedstone2v?.draw(81,0):9==this.selectedTab?this.imageRedstone2v?.draw(108,0):10==this.selectedTab?this.imageRedstone3v?.draw(136,1):11==this.selectedTab?this.imageRedstone2hv?.draw(178,0):12==this.selectedTab?this.imageRedstone2hv?.draw(205,0):13==this.selectedTab&&this.imageRedstone1hv?.draw(233,0)),-1!=this.tabInterfaceId[8]&&(8!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[7].draw(80,2),-1!=this.tabInterfaceId[9]&&(9!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[8].draw(107,3),-1!=this.tabInterfaceId[10]&&(10!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[9].draw(142,4),-1!=this.tabInterfaceId[11]&&(11!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[10].draw(179,2),-1!=this.tabInterfaceId[12]&&(12!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[11].draw(206,2),-1!=this.tabInterfaceId[13]&&(13!=this.flashingTab||this.loopCycle%20<10)&&this.imageSideicons[12].draw(230,2)),this.areaBackbase2?.draw(501,492),this.areaViewport?.bind()),this.redrawPrivacySettings&&(this.redrawPrivacySettings=!1,this.areaBackbase1?.bind(),this.imageBackbase1?.draw(0,0),this.fontPlain12?.drawStringTaggableCenter(57,33,"Public chat",16777215,!0),0==this.publicChatSetting&&this.fontPlain12?.drawStringTaggableCenter(57,46,"On",65280,!0),1==this.publicChatSetting&&this.fontPlain12?.drawStringTaggableCenter(57,46,"Friends",16776960,!0),2==this.publicChatSetting&&this.fontPlain12?.drawStringTaggableCenter(57,46,"Off",16711680,!0),3==this.publicChatSetting&&this.fontPlain12?.drawStringTaggableCenter(57,46,"Hide",65535,!0),this.fontPlain12?.drawStringTaggableCenter(186,33,"Private chat",16777215,!0),0==this.privateChatSetting&&this.fontPlain12?.drawStringTaggableCenter(186,46,"On",65280,!0),1==this.privateChatSetting&&this.fontPlain12?.drawStringTaggableCenter(186,46,"Friends",16776960,!0),2==this.privateChatSetting&&this.fontPlain12?.drawStringTaggableCenter(186,46,"Off",16711680,!0),this.fontPlain12?.drawStringTaggableCenter(326,33,"Trade/duel",16777215,!0),0==this.tradeChatSetting&&this.fontPlain12?.drawStringTaggableCenter(326,46,"On",65280,!0),1==this.tradeChatSetting&&this.fontPlain12?.drawStringTaggableCenter(326,46,"Friends",16776960,!0),2==this.tradeChatSetting&&this.fontPlain12?.drawStringTaggableCenter(326,46,"Off",16711680,!0),this.fontPlain12?.drawStringTaggableCenter(462,38,"Report abuse",16777215,!0),this.areaBackbase1?.draw(0,471),this.areaViewport?.bind()),this.sceneDelta=0};drawScene=()=>{};drawSidebar=()=>{};drawChatback=()=>{if(this.areaChatback?.bind(),this.areaChatbackOffsets&&(T.lineOffset=this.areaChatbackOffsets),this.imageChatback?.draw(0,0),this.showSocialInput)this.fontBold12?.drawStringCenter(239,40,this.socialMessage,0),this.fontBold12?.drawStringCenter(239,60,this.socialInput+"*",128);else if(this.chatbackInputOpen)this.fontBold12?.drawStringCenter(239,40,"Enter amount:",0),this.fontBold12?.drawStringCenter(239,60,this.chatbackInput+"*",128);else if(null!=this.modalMessage)this.fontBold12?.drawStringCenter(239,40,this.modalMessage,0),this.fontBold12?.drawStringCenter(239,60,"Click to continue",128);else if(-1!=this.chatInterfaceId)this.drawInterface(_.instances[this.chatInterfaceId],0,0,0);else if(-1==this.stickyChatInterfaceId){const t=this.fontPlain12;let e=0;l.setBounds(77,463,0,0);for(let i=0;i<100;i++)if(null!=this.messageText[i]){const s=this.messageType[i],r=this.chatScrollOffset+70-14*e;0===s&&(r>0&&r<110&&t?.drawString(4,r,this.messageText[i],0),e++),1===s&&(r>0&&r<110&&(t?.drawString(4,r,this.messageSender[i]+":",16777215),t?.drawString(t.stringWidth(this.messageSender[i])+12,r,this.messageText[i],255)),e++),2===s&&(0==this.publicChatSetting||1==this.publicChatSetting&&this.isFriend(this.messageSender[i]))&&(r>0&&r<110&&(t?.drawString(4,r,this.messageSender[i]+":",0),t?.drawString(t.stringWidth(this.messageSender[i])+12,r,this.messageText[i],255)),e++),3!==s&&7!==s||0!=this.splitPrivateChat||!(7==s||0==this.privateChatSetting||1==this.privateChatSetting&&this.isFriend(this.messageSender[i]))||(r>0&&r<110&&(t?.drawString(4,r,"From "+this.messageSender[i]+":",0),t?.drawString(t.stringWidth("From "+this.messageSender[i])+12,r,this.messageText[i],8388608)),e++),4===s&&(0==this.tradeChatSetting||1==this.tradeChatSetting&&this.isFriend(this.messageSender[i]))&&(r>0&&r<110&&t?.drawString(4,r,this.messageSender[i]+" "+this.messageText[i],8388736),e++),5===s&&0==this.splitPrivateChat&&this.privateChatSetting<2&&(r>0&&r<110&&t?.drawString(4,r,this.messageText[i],8388608),e++),6===s&&0==this.splitPrivateChat&&this.privateChatSetting<2&&(r>0&&r<110&&(t?.drawString(4,r,"To "+this.messageSender[i]+":",0),t?.drawString(t.stringWidth("To "+this.messageSender[i])+12,r,this.messageText[i],8388608)),e++),8===s&&(0==this.tradeChatSetting||1==this.tradeChatSetting&&this.isFriend(this.messageSender[i]))&&(r>0&&r<110&&t?.drawString(4,r,this.messageSender[i]+" "+this.messageText[i],13350793),e++)}l.resetBounds(),this.chatScrollHeight=14*e+7,this.chatScrollHeight<78&&(this.chatScrollHeight=78),this.drawScrollbar(463,0,this.chatScrollHeight-this.chatScrollOffset-77,this.chatScrollHeight,77),t?.drawString(4,90,D.formatName(this.username)+":",0),t?.drawString(t.stringWidth(this.username+": ")+6,90,this.chatTyped+"*",255),l.drawHorizontalLine(0,77,0,479)}else this.drawInterface(_.instances[this.stickyChatInterfaceId],0,0,0);this.menuVisible&&2==this.menuArea&&this.drawMenu(),this.areaChatback?.draw(22,375),this.areaViewport?.bind(),this.areaViewportOffsets&&(T.lineOffset=this.areaViewportOffsets)};drawScrollbar=(t,e,i,s,r)=>{this.imageScrollbar0?.draw(t,e),this.imageScrollbar1?.draw(t,e+r-16),l.fillRect(t,e+16,16,r-32,this.SCROLLBAR_TRACK);let a=(r-32)*r/s|0;a<8&&(a=8);const n=(r-a-32)*i/(s-r)|0;l.fillRect(t,e+n+16,16,a,this.SCROLLBAR_GRIP_FOREGROUND),l.drawVerticalLine(t,e+n+16,this.SCROLLBAR_GRIP_HIGHLIGHT,a),l.drawVerticalLine(t+1,e+n+16,this.SCROLLBAR_GRIP_HIGHLIGHT,a),l.drawHorizontalLine(t,e+n+16,this.SCROLLBAR_GRIP_HIGHLIGHT,16),l.drawHorizontalLine(t,e+n+17,this.SCROLLBAR_GRIP_HIGHLIGHT,16),l.drawVerticalLine(t+15,e+n+16,this.SCROLLBAR_GRIP_LOWLIGHT,a),l.drawVerticalLine(t+14,e+n+17,this.SCROLLBAR_GRIP_LOWLIGHT,a-1),l.drawHorizontalLine(t,e+n+a+15,this.SCROLLBAR_GRIP_LOWLIGHT,16),l.drawHorizontalLine(t+1,e+n+a+14,this.SCROLLBAR_GRIP_LOWLIGHT,15)};drawInterface=(t,e,i,s)=>{if(0!=t.type||null==t.childId||t.hide&&this.viewportHoveredInterfaceIndex!=t.id&&this.sidebarHoveredInterfaceIndex!=t.id&&this.chatHoveredInterfaceIndex!=t.id)return;const r=l.left,n=l.top,o=l.right,h=l.bottom;l.setBounds(i+t.height,e+t.width,i,e);const c=t.childId.length;for(let r=0;r0&&this.updateInterfaceContent(h),0==h.type)h.scrollPosition>h.scrollableHeight-h.height&&(h.scrollPosition=h.scrollableHeight-h.height),h.scrollPosition<0&&(h.scrollPosition=0),this.drawInterface(h,n,o,h.scrollPosition),h.scrollableHeight>h.height&&this.drawScrollbar(n+h.width,o,h.scrollPosition,h.scrollableHeight,h.height);else if(2==h.type){let t=0;for(let e=0;e0){let e=0,i=0;const a=h.inventorySlotObjId[t]-1;if(s>=-32&&s<=512&&r>=-32&&r<=334||0!=this.objDragArea&&this.objDragSlot==t){const n=b.getIcon(a,h.inventorySlotObjCount[t]);if(0!=this.objDragArea&&this.objDragSlot==t&&this.objDragInterfaceId==h.id?(e=this.mouseX-this.objGrabX,i=this.mouseY-this.objGrabY,e<5&&e>-5&&(e=0),i<5&&i>-5&&(i=0),this.objDragCycles<5&&(e=0,i=0),n.drawAlpha(128,s+e,r+i)):0!=this.selectedArea&&this.selectedItem==t&&this.selectedInterface==h.id?n.drawAlpha(128,s,r):n.draw(s,r),33==n.cropW||1!=h.inventorySlotObjCount[t]){const a=h.inventorySlotObjCount[t];this.fontPlain11?.drawString(s+e+1,r+10+i,this.formatObjCount(a),0),this.fontPlain11?.drawString(s+e,r+9+i,this.formatObjCount(a),16776960)}}}else if(null!=h.inventorySlotImage&&t<20){const e=h.inventorySlotImage[t];null!=e&&e.draw(s,r)}t++}}else if(3==h.type)h.fill?l.fillRect(n,o,h.color,h.width,h.height):l.drawRect(n,o,h.color,h.width,h.height);else if(4==h.type){const t=h.font;let e=h.color,i=h.text;if(this.chatHoveredInterfaceIndex!=h.id&&this.sidebarHoveredInterfaceIndex!=h.id&&this.viewportHoveredInterfaceIndex!=h.id||0==h.hoverColor||(e=h.hoverColor),this.executeInterfaceScript(h)&&(e=h.activeColor,h.activeText&&h.activeText.length>0&&(i=h.activeText)),6==h.optionType&&this.pressedContinueOption&&(i="Please wait...",e=h.color),!t||!i)continue;for(let s=o+t.fontHeight;i.length>0;s+=t.fontHeight){if(-1!=i.indexOf("%")){for(;;){const t=i.indexOf("%1");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,0))+i.substring(t+2)}for(;;){const t=i.indexOf("%2");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,1))+i.substring(t+2)}for(;;){const t=i.indexOf("%3");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,2))+i.substring(t+2)}for(;;){const t=i.indexOf("%4");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,3))+i.substring(t+2)}for(;;){const t=i.indexOf("%5");if(-1==t)break;i=i.substring(0,t)+this.getIntString(this.executeClientscript1(h,4))+i.substring(t+2)}}const r=i.indexOf("\\n");let a;-1!=r?(a=i.substring(0,r),i=i.substring(r+2)):(a=i,i=""),h.center?t.drawStringTaggableCenter(n+h.width/2,s,a,e,h.shadow):t.drawStringTaggable(n,s,a,e,h.shadow)}}else if(5==h.type){let t;t=this.executeInterfaceScript(h)?h.activeImage:h.image,null!=t&&t.draw(n,o)}else if(6==h.type){const t=T.centerX,e=T.centerY;T.centerX=n+h.width/2,T.centerY=o+h.height/2;const i=T.sin[h.modelPitch]*h.modelZoom>>16,s=T.cos[h.modelPitch]*h.modelZoom>>16,r=this.executeInterfaceScript(h);let l;l=r?h.activeSeqId:h.seqId;let c=null;if(-1==l)c=h.getModel(-1,-1,r);else{const t=a.instances[l];t.frames&&t.iframes&&(c=h.getModel(t.frames[h.seqFrame],t.iframes[h.seqFrame],r))}c&&c.drawSimple(0,h.modelYaw,0,h.modelPitch,0,i,s),T.centerX=t,T.centerY=e}else if(7==h.type){const t=h.font;if(!t||!h.inventorySlotObjId||!h.inventorySlotObjCount)continue;let e=0;for(let i=0;i0){const r=b.get(h.inventorySlotObjId[e]-1);let a=r.name;if((r.stackable||1!=h.inventorySlotObjCount[e])&&(a=a+" x"+this.formatObjCountTagged(h.inventorySlotObjCount[e])),!a)continue;const l=n+s*(h.inventoryMarginX+115),c=o+i*(h.inventoryMarginY+12);h.center?t.drawStringTaggableCenter(l+h.width/2,c,a,h.color,h.shadow):t.drawStringTaggable(l,c,a,h.color,h.shadow)}e++}}}l.setBounds(h,o,n,r)};drawMinimap=()=>{};drawMenu=()=>{const t=this.menuX,e=this.menuY,i=this.menuWidth,s=this.menuHeight,r=6116423;l.fillRect(t,e,i,s,r),l.fillRect(t+1,e+1,i-2,16,0),l.drawRect(t+1,e+18,i-2,s-19,0),this.fontBold12?.drawString(t+3,e+14,"Choose Option",r);let a=this.mouseX,n=this.mouseY;0==this.menuArea&&(a-=8,n-=11),1==this.menuArea&&(a-=562,n-=231),2==this.menuArea&&(a-=22,n-=375);for(let s=0;st&&ar-13&&n!1;handleScrollInput=(t,e,i,s,r,a,n,o)=>{if(this.scrollGrabbed?this.scrollInputPadding=32:this.scrollInputPadding=0,this.scrollGrabbed=!1,t>=a&&t=n&&e=a&&t=n+s-16&&e=a-this.scrollInputPadding&&t=n+16&&e0){let t=(s-32)*s/i;t<8&&(t=8);const a=e-n-t/2-16,l=s-t-32;o.scrollPosition=(i-s)*a/l,r&&(this.redrawSidebar=!0),this.scrollGrabbed=!0}};prepareGameScreen=()=>{if(null==this.areaChatback){this.unloadTitle(),this.drawArea=null,this.imageTitle2=null,this.imageTitle3=null,this.imageTitle4=null,this.imageTitle0=null,this.imageTitle1=null,this.imageTitle5=null,this.imageTitle6=null,this.imageTitle7=null,this.imageTitle8=null;const t=this.canvas;this.areaChatback=new O(t,479,96),this.areaMapback=new O(t,168,160),l.clear(),this.imageMapback?.draw(0,0),this.areaSidebar=new O(t,190,261),this.areaViewport=new O(t,512,334),l.clear(),this.areaBackbase1=new O(t,501,61),this.areaBackbase2=new O(t,288,40),this.areaBackhmid1=new O(t,269,66),this.redrawTitleBackground=!0}};isFriend=t=>!1;getIntString=t=>t<999999999?String(t):"*";formatObjCountTagged=t=>{let e=String(t);for(let t=e.length-3;t>0;t-=3)e=e.substring(0,t)+","+e.substring(t);return e.length>8?e="@gre@"+e.substring(0,e.length-8)+" million @whi@("+e+")":e.length>4&&(e="@cya@"+e.substring(0,e.length-4)+"K @whi@("+e+")")," "+e};formatObjCount=t=>t<1e5?String(t):t<1e7?Math.floor(t/1e3)+"K":Math.floor(t/1e6)+"M";executeClientscript1=(t,e)=>{if(null==t.scripts||e>=t.scripts.length)return-2;try{return-1}catch(t){return-1}};executeInterfaceScript=t=>{if(!t.scriptComparator||!t.scriptOperand)return!1;for(let e=0;e=s)return!1}else if(3==t.scriptComparator[e]){if(i<=s)return!1}else if(4==t.scriptComparator[e]){if(i==s)return!1}else if(i!=s)return!1}return!0};updateInterfaceContent=t=>{};unloadTitle=()=>{this.flameActive=!1,this.flamesInterval&&(clearInterval(this.flamesInterval),this.flamesInterval=null),this.imageTitlebox=null,this.imageTitlebutton=null,this.imageRunes=[],this.flameGradient=[],this.flameGradient0=[],this.flameGradient1=[],this.flameGradient2=[],this.flameBuffer0=[],this.flameBuffer1=[],this.flameBuffer3=[],this.flameBuffer2=[],this.imageFlamesLeft=null,this.imageFlamesRight=null};loadArchive=async(t,e,i,s)=>{await this.showProgress(s,`Requesting ${e}`);const r=await M.loadUrl(`${G.HOST}/${t}${i}`);return await this.showProgress(s,`Loading ${e} - 100%`),r};setMidi=async(t,i)=>{const s=new e(await g(`${G.HOST}/${t.replaceAll(" ","_")}_${i}.mid`));var r;r=m(s.data,!0,!1),window._tinyMidiPlay&&window._tinyMidiPlay(r,.75)};drawError=()=>{if(this.ctx.fillStyle="black",this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.setLoopRate(1),this.errorLoading){this.flameActive=!1,this.ctx.font="bold 16px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="yellow";let t=35;this.ctx.fillText("Sorry, an error has occured whilst loading RuneScape",30,t),t+=50,this.ctx.fillStyle="white",this.ctx.fillText("To fix this try the following (in order):",30,t),t+=50,this.ctx.font="bold 12px helvetica, sans-serif",this.ctx.fillText("1: Try closing ALL open web-browser windows, and reloading",30,t),t+=30,this.ctx.fillText("2: Try clearing your web-browsers cache from tools->internet options",30,t),t+=30,this.ctx.fillText("3: Try using a different game-world",30,t),t+=30,this.ctx.fillText("4: Try rebooting your computer",30,t),t+=30,this.ctx.fillText("5: Try selecting a different version of Java from the play-game menu",30,t)}if(this.errorHost&&(this.flameActive=!1,this.ctx.font="bold 20px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="white",this.ctx.fillText("Error - unable to load game!",50,50),this.ctx.fillText("To play RuneScape make sure you play from",50,100),this.ctx.fillText("https://2004scape.org",50,150)),this.errorStarted){this.flameActive=!1,this.ctx.font="bold 13px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="yellow";let t=35;this.ctx.fillText("Error a copy of RuneScape already appears to be loaded",30,t),t+=50,this.ctx.fillStyle="white",this.ctx.fillText("To fix this try the following (in order):",30,t),t+=50,this.ctx.font="bold 12px helvetica, sans-serif",this.ctx.fillText("1: Try closing ALL open web-browser windows, and reloading",30,t),t+=30,this.ctx.fillText("2: Try rebooting your computer, and reloading",30,t)}};updateFlames=()=>{for(let t=10;t<117;t++)Math.trunc(100*Math.random())<50&&(this.flameBuffer3[t+32512]=255);for(let t=0;t<100;t++){const t=Math.trunc(124*Math.random()+2)+(Math.trunc(128*Math.random()+128)<<7);this.flameBuffer3[t]=192}for(let t=1;t<255;t++)for(let e=1;e<127;e++){const i=e+(t<<7);this.flameBuffer2[i]=(this.flameBuffer3[i-1]+this.flameBuffer3[i+1]+this.flameBuffer3[i-128]+this.flameBuffer3[i+128])/4|0}if(this.flameCycle0+=128,this.flameCycle0>32768){this.flameCycle0-=32768;const t=Math.trunc(12*Math.random());this.updateFlameBuffer(this.imageRunes[t])}for(let t=1;t<255;t++)for(let e=1;e<127;e++){const i=e+(t<<7);let s=this.flameBuffer2[i+128]-this.flameBuffer0[i+this.flameCycle0&32767]/5|0;s<0&&(s=0),this.flameBuffer3[i]=s}for(let t=0;t<255;t++)this.flameLineOffset[t]=this.flameLineOffset[t+1];if(this.flameLineOffset[255]=16*Math.sin(this.loopCycle/14)+14*Math.sin(this.loopCycle/15)+12*Math.sin(this.loopCycle/16)|0,this.flameGradientCycle0>0&&(this.flameGradientCycle0-=4),this.flameGradientCycle1>0&&(this.flameGradientCycle1-=4),0==this.flameGradientCycle0&&0==this.flameGradientCycle1){const t=Math.trunc(2e3*Math.random());0==t?this.flameGradientCycle0=1024:1==t&&(this.flameGradientCycle1=1024)}};mix=(t,e,i)=>{const s=256-e;return((16711935&t)*s+(16711935&i)*e&4278255360)+((65280&t)*s+(65280&i)*e&16711680)>>8};drawFlames=()=>{const t=256;if(this.flameGradientCycle0>0)for(let t=0;t<256;t++)this.flameGradientCycle0>768?this.flameGradient[t]=this.mix(this.flameGradient0[t],1024-this.flameGradientCycle0,this.flameGradient1[t]):this.flameGradientCycle0>256?this.flameGradient[t]=this.flameGradient1[t]:this.flameGradient[t]=this.mix(this.flameGradient1[t],256-this.flameGradientCycle0,this.flameGradient0[t]);else if(this.flameGradientCycle1>0)for(let t=0;t<256;t++)this.flameGradientCycle1>768?this.flameGradient[t]=this.mix(this.flameGradient0[t],1024-this.flameGradientCycle1,this.flameGradient2[t]):this.flameGradientCycle1>256?this.flameGradient[t]=this.flameGradient2[t]:this.flameGradient[t]=this.mix(this.flameGradient2[t],256-this.flameGradientCycle1,this.flameGradient0[t]);else for(let t=0;t<256;t++)this.flameGradient[t]=this.flameGradient0[t];for(let t=0;t<33920;t++)this.imageTitle0&&this.imageFlamesLeft&&(this.imageTitle0.pixels[t]=this.imageFlamesLeft.pixels[t]);let e=0,i=1152;for(let s=1;s<255;s++){let r=22+(this.flameLineOffset[s]*(t-s)/t|0);r<0&&(r=0),e+=r;for(let t=r;t<128;t++){let t=0|this.flameBuffer3[e++];if(0==t)i++;else{const e=t,s=256-t;if(t=this.flameGradient[t],this.imageTitle0){const r=this.imageTitle0.pixels[i];this.imageTitle0.pixels[i++]=((16711935&t)*e+(16711935&r)*s&4278255360)+((65280&t)*e+(65280&r)*s&16711680)>>8}}}i+=r}this.imageTitle0?.draw(0,0);for(let t=0;t<33920;t++)this.imageTitle1&&this.imageFlamesRight&&(this.imageTitle1.pixels[t]=this.imageFlamesRight.pixels[t]);e=0,i=1176;for(let s=1;s<255;s++){const r=this.flameLineOffset[s]*(t-s)/t|0,a=103-r;i+=r;for(let t=0;t>8}}}e+=128-a,i+=128-a-r}this.imageTitle1?.draw(661,0)}}(new G).run().then((()=>{}))})()})(); \ No newline at end of file diff --git a/playground.js b/playground.js index dcfb9c9c..88b791d8 100644 --- a/playground.js +++ b/playground.js @@ -1,2 +1,2 @@ /*! For license information please see playground.js.LICENSE.txt */ -(()=>{"use strict";class t{static pixels=new Int32Array;static width=0;static height=0;static top=0;static bottom=0;static left=0;static right=0;static boundX=0;static centerX=0;static centerY=0;static bind=(t,e,i)=>{this.pixels=t,this.width=e,this.height=i,this.setBounds(0,0,e,i)};static resetBounds=()=>{this.left=0,this.top=0,this.right=this.width,this.bottom=this.height,this.boundX=this.right-1,this.centerX=this.right/2};static setBounds=(t,e,i,s)=>{t<0&&(t=0),e<0&&(e=0),i>this.width&&(i=this.width),s>this.height&&(s=this.height),this.top=e,this.bottom=s,this.left=t,this.right=i,this.boundX=this.right-1,this.centerX=this.right/2,this.centerY=this.bottom/2};static clear=()=>{this.pixels.fill(0)};static drawRect=(t,e,i,s,r)=>{this.drawHorizontalLine(t,e,r,i),this.drawHorizontalLine(t,e+s-1,r,i),this.drawVerticalLine(t,e,r,s),this.drawVerticalLine(t+i-1,e,r,s)};static drawHorizontalLine=(t,e,i,s)=>{if(e=this.bottom)return;tthis.right&&(s=this.right-t);const r=t+e*this.width;for(let t=0;t{if(t=this.right)return;ethis.bottom&&(s=this.bottom-e);const r=t+e*this.width;for(let t=0;t{const a=Math.abs(i-t),n=Math.abs(s-e),o=t=this.left&&t=this.top&&e-n&&(l-=n,t+=o),i{const a=this.pixels;let n=t,o=e,h=t+i,l=e+s;nthis.right&&(h=this.right),l>this.bottom&&(l=this.bottom);const c=this.width;for(let t=o;t{this.pixels.fill(0)};bind=()=>{t.bind(this.pixels,this.width,this.height)};draw=(t,e)=>{this.#t(),this.ctx.putImageData(this.image,t,e)};#t=()=>{const t=this.image.data;for(let e=0;e>16&255,t[s+1]=i>>8&255,t[s+2]=i>>0&255,t[s+3]=255}}}class i{static crctable=new Int32Array(256);static CRC32_POLYNOMIAL=3988292384;static bitmask=new Uint32Array(33);static{for(let t=0;t<32;t++)i.bitmask[t]=(1<>>1^i.CRC32_POLYNOMIAL:e>>>=1;i.crctable[t]=e}}data;pos;bitPos=0;constructor(t){if(!t)throw new Error("Input src packet array was null!");this.data=t,this.pos=0}static alloc=t=>new i(0===t?new Uint8Array(100):1===t?new Uint8Array(5e3):new Uint8Array(3e4));get g1(){return this.data[this.pos++]}get g1b(){return this.data[this.pos++]<<24>>24}get g2(){return(this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g2b(){return this.data[this.pos++]<<8|this.data[this.pos++]}get g3(){return(this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4(){return(this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4s(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]}get g8(){return BigInt(this.g4)<<32n|BigInt(this.g4)}get gsmart(){return this.data[this.pos]<128?this.g1:this.g2-32768}get gsmarts(){return this.data[this.pos]<128?this.g1-64:this.g2-49152}get gjstr(){let t="";for(;10!=this.data[this.pos]&&this.posthis.data.subarray(t,t+e);p1=t=>{this.data[this.pos++]=t};p2=t=>{this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip2=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8};p3=t=>{this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};p4=t=>{this.data[this.pos++]=t>>>24,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip4=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>24};p8=t=>{this.p4(Number(t>>32n)),this.p4(Number(0xffffffffn&t))};pjstr=t=>{for(let e=0;e{for(let s=i;s{this.data[this.pos-t-1]=t};bits=()=>{this.bitPos=8*this.pos};bytes=()=>{this.pos=(this.bitPos+7)/8>>>0};gBit=t=>{let e=this.bitPos>>>3,s=8-(7&this.bitPos),r=0;for(this.bitPos+=t;t>s;s=8)r+=(this.data[e++]&i.bitmask[s])<>>s-t&i.bitmask[t],r}}class s{pixels;width;height;cropX;cropY;cropW;cropH;palette=new Uint32Array(0);constructor(t,e){this.pixels=new Uint8Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromArchive=(t,e,r=0)=>{const a=new i(t?.read(e+".dat")),n=new i(t?.read("index.dat"));n.pos=a.g2;const o=n.g2,h=n.g2,l=n.g1,c=new Uint32Array(l);for(let t=0;t{e|=0,i|=0;let a=(e+=this.cropX)+(i+=this.cropY)*t.width,n=0,o=this.height,h=this.width;-1!==s&&(h=s),-1!==r&&(o=r);let l=t.width-h,c=0;if(it.bottom&&(o-=i+o-t.bottom),et.right){const i=e+h-t.right;h-=i,c+=i,l+=i}h>0&&o>0&&this.copyImage(h,o,this.pixels,n,c,t.pixels,a,l)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;r+=t,r<0?r=0:r>255&&(r=255);let a=this.palette[s]>>8&255;a+=e,a<0?a=0:a>255&&(a=255);let n=255&this.palette[s];n+=i,n<0?n=0:n>255&&(n=255),this.palette[s]=(r<<16)+(a<<8)+n}};copyImage=(t,e,i,s,r,a,n,o)=>{for(let h=0;h{this.lineOffset=new Int32Array(t.height);for(let e=0;e{this.lineOffset=new Int32Array(e);for(let i=0;i{this.textureCount=0;for(let e=0;e<50;e++)try{this.textures[e]=s.fromArchive(t,e.toString()),this.textureCount++}catch(t){}};static setBrightness=t=>{t+=.3*Math.random()-.15;let e=0;for(let i=0;i<512;i++){const s=i/8/64+.0078125,r=(7&i)/8+.0625;for(let i=0;i<128;i++){const a=i/128;let n=a,o=a,h=a;if(r){let t;t=a<.5?a*(1+r):a+r-a*r;const e=2*a-t;let i=s+.3333333333333333;i>1&&i--;let l=s-.3333333333333333;l<0&&l++,n=6*i<1?e+6*(t-e)*i:2*i<1?t:3*i<2?e+6*(.6666666666666666-i)*(t-e):e,o=6*s<1?e+6*(t-e)*s:2*s<1?t:3*s<2?e+6*(.6666666666666666-s)*(t-e):e,h=6*l<1?e+6*(t-e)*l:2*l<1?t:3*l<2?e+6*(.6666666666666666-l)*(t-e):e}let l=Math.trunc(256*n)<<16|Math.trunc(256*o)<<8|Math.trunc(256*h);l=this.setGamma(l,t),0===l&&(l=1),this.palette[e++]=l}}};static setGamma=(t,e)=>{let i=(t>>16)/256,s=(t>>8&255)/256,r=(255&t)/256;return i=Math.pow(i,e),s=Math.pow(s,e),r=Math.pow(r,e),Math.trunc(256*i)<<16|Math.trunc(256*s)<<8|Math.trunc(256*r)};static initPool=t=>{null==this.texelPool&&(this.poolSize=t,this.texelPool=[],this.activeTexels=[])};static fillGouraudTriangle=(e,i,s,r,a,n,o,h,l)=>{let c=0,f=0,d=0,u=0,p=0,g=0;if(a!=r&&(c=(i-e<<16)/(a-r),u=(h-o<<15)/(a-r)),n!=a&&(f=(s-i<<16)/(n-a),p=(l-h<<15)/(n-a)),n!=r&&(d=(e-s<<16)/(r-n),g=(o-l<<15)/(r-n)),r<=a&&r<=n){if(r>=t.bottom)return;if(a>t.bottom&&(a=t.bottom),n>t.bottom&&(n=t.bottom),af){for(n-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=t.width)this.drawGouraudScanline(t.pixels,r,s>>16,e>>16,l>>7,o>>7),s+=d,e+=c,l+=g,o+=u;for(;--n>=0;)this.drawGouraudScanline(t.pixels,r,s>>16,i>>16,l>>7,h>>7),s+=d,i+=f,l+=g,h+=p,r+=t.width;return}for(n-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=t.width)this.drawGouraudScanline(t.pixels,r,e>>16,s>>16,o>>7,l>>7),s+=d,e+=c,l+=g,o+=u;for(;--n>=0;)this.drawGouraudScanline(t.pixels,r,i>>16,s>>16,h>>7,l>>7),s+=d,i+=f,l+=g,h+=p,r+=t.width;return}if(i=e<<=16,h=o<<=15,r<0&&(i-=d*r,e-=c*r,h-=g*r,o-=u*r,r=0),s<<=16,l<<=15,n<0&&(s-=f*n,l-=p*n,n=0),r!=n&&dc){for(a-=n,n-=r,r=this.lineOffset[r];--n>=0;r+=t.width)this.drawGouraudScanline(t.pixels,r,i>>16,e>>16,h>>7,o>>7),i+=d,e+=c,h+=g,o+=u;for(;--a>=0;)this.drawGouraudScanline(t.pixels,r,s>>16,e>>16,l>>7,o>>7),s+=f,e+=c,l+=p,o+=u,r+=t.width;return}for(a-=n,n-=r,r=this.lineOffset[r];--n>=0;r+=t.width)this.drawGouraudScanline(t.pixels,r,e>>16,i>>16,o>>7,h>>7),i+=d,e+=c,h+=g,o+=u;for(;--a>=0;)this.drawGouraudScanline(t.pixels,r,e>>16,s>>16,o>>7,l>>7),s+=f,e+=c,l+=p,o+=u,r+=t.width}else if(a<=n){if(a>=t.bottom)return;if(n>t.bottom&&(n=t.bottom),r>t.bottom&&(r=t.bottom),nd){for(r-=n,n-=a,a=this.lineOffset[a];--n>=0;a+=t.width)this.drawGouraudScanline(t.pixels,a,e>>16,i>>16,o>>7,h>>7),e+=c,i+=f,o+=u,h+=p;for(;--r>=0;)this.drawGouraudScanline(t.pixels,a,e>>16,s>>16,o>>7,l>>7),e+=c,s+=d,o+=u,l+=g,a+=t.width;return}for(r-=n,n-=a,a=this.lineOffset[a];--n>=0;a+=t.width)this.drawGouraudScanline(t.pixels,a,i>>16,e>>16,h>>7,o>>7),e+=c,i+=f,o+=u,h+=p;for(;--r>=0;)this.drawGouraudScanline(t.pixels,a,s>>16,e>>16,l>>7,o>>7),e+=c,s+=d,o+=u,l+=g,a+=t.width;return}if(s=i<<=16,l=h<<=15,a<0&&(s-=c*a,i-=f*a,l-=u*a,h-=p*a,a=0),e<<=16,o<<=15,r<0&&(e-=d*r,o-=g*r,r=0),c=0;a+=t.width)this.drawGouraudScanline(t.pixels,a,s>>16,i>>16,l>>7,h>>7),s+=c,i+=f,l+=u,h+=p;for(;--n>=0;)this.drawGouraudScanline(t.pixels,a,e>>16,i>>16,o>>7,h>>7),e+=d,i+=f,o+=g,h+=p,a+=t.width;return}for(n-=r,r-=a,a=this.lineOffset[a];--r>=0;a+=t.width)this.drawGouraudScanline(t.pixels,a,i>>16,s>>16,h>>7,l>>7),s+=c,i+=f,l+=u,h+=p;for(;--n>=0;)this.drawGouraudScanline(t.pixels,a,i>>16,e>>16,h>>7,o>>7),e+=d,i+=f,o+=g,h+=p,a+=t.width}else if(!(n>=t.bottom))if(r>t.bottom&&(r=t.bottom),a>t.bottom&&(a=t.bottom),r=0;n+=t.width)this.drawGouraudScanline(t.pixels,n,i>>16,s>>16,h>>7,l>>7),i+=f,s+=d,h+=p,l+=g;for(;--a>=0;)this.drawGouraudScanline(t.pixels,n,i>>16,e>>16,h>>7,o>>7),i+=f,e+=c,h+=p,o+=u,n+=t.width;return}for(a-=r,r-=n,n=this.lineOffset[n];--r>=0;n+=t.width)this.drawGouraudScanline(t.pixels,n,s>>16,i>>16,l>>7,h>>7),i+=f,s+=d,h+=p,l+=g;for(;--a>=0;)this.drawGouraudScanline(t.pixels,n,e>>16,i>>16,o>>7,h>>7),i+=f,e+=c,h+=p,o+=u,n+=t.width}else if(e=s<<=16,o=l<<=15,n<0&&(e-=f*n,s-=d*n,o-=p*n,l-=g*n,n=0),i<<=16,h<<=15,a<0&&(i-=c*a,h-=u*a,a=0),f=0;n+=t.width)this.drawGouraudScanline(t.pixels,n,e>>16,s>>16,o>>7,l>>7),e+=f,s+=d,o+=p,l+=g;for(;--r>=0;)this.drawGouraudScanline(t.pixels,n,i>>16,s>>16,h>>7,l>>7),i+=c,s+=d,h+=u,l+=g,n+=t.width}else{for(r-=a,a-=n,n=this.lineOffset[n];--a>=0;n+=t.width)this.drawGouraudScanline(t.pixels,n,s>>16,e>>16,l>>7,o>>7),e+=f,s+=d,o+=p,l+=g;for(;--r>=0;)this.drawGouraudScanline(t.pixels,n,s>>16,i>>16,l>>7,h>>7),i+=c,s+=d,h+=u,l+=g,n+=t.width}};static drawGouraudScanline=(e,i,s,r,a,n)=>{let o=0,h=0;if(this.jagged){let l=0;if(this.clipX){if(l=r-s>3?(n-a)/(r-s):0,r>t.right&&(r=t.right),s<0&&(a-=s*l,s=0),s>=r)return;i+=s,h=r-s>>2,l<<=2}else{if(s>=r)return;i+=s,h=r-s>>2,l=h>0?(n-a)*this.reciprocal15[h]>>15:0}if(0==this.alpha){for(;--h>=0;)o=this.palette[a>>8],a+=l,e[i++]=o,e[i++]=o,e[i++]=o,e[i++]=o;if(h=r-s&3,h>0){o=this.palette[a>>8];do{e[i++]=o}while(--h>0);return}}else{const t=this.alpha,n=256-this.alpha;for(;--h>=0;)o=this.palette[a>>8],a+=l,o=((16711935&o)*n>>8&16711935)+((65280&o)*n>>8&65280),e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280),e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280),e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280),e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280);if(h=r-s&3,h>0){o=this.palette[a>>8],o=((16711935&o)*n>>8&16711935)+((65280&o)*n>>8&65280);do{e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280)}while(--h>0)}}return}if(s>=r)return;const l=(n-a)/(r-s);if(this.clipX&&(r>t.right&&(r=t.right),s<0&&(a-=s*l,s=0),s>=r))return;if(i+=s,h=r-s,0==this.alpha){do{e[i++]=this.palette[a>>8],a+=l}while(--h>0);return}const c=this.alpha,f=256-this.alpha;do{o=this.palette[a>>8],a+=l,o=((16711935&o)*f>>8&16711935)+((65280&o)*f>>8&65280),e[i++]=o+((16711935&e[i])*c>>8&16711935)+((65280&e[i])*c>>8&65280)}while(--h>0)};static fillTriangle=()=>{};static fillTexturedTriangle=()=>{}}const a=[0,79764919,159529838,222504665,319059676,398814059,445009330,507990021,638119352,583659535,797628118,726387553,890018660,835552979,1015980042,944750013,1276238704,1221641927,1167319070,1095957929,1595256236,1540665371,1452775106,1381403509,1780037320,1859660671,1671105958,1733955601,2031960084,2111593891,1889500026,1952343757,2552477408,2632100695,2443283854,2506133561,2334638140,2414271883,2191915858,2254759653,3190512472,3135915759,3081330742,3009969537,2905550212,2850959411,2762807018,2691435357,3560074640,3505614887,3719321342,3648080713,3342211916,3287746299,3467911202,3396681109,4063920168,4143685023,4223187782,4286162673,3779000052,3858754371,3904687514,3967668269,881225847,809987520,1023691545,969234094,662832811,591600412,771767749,717299826,311336399,374308984,453813921,533576470,25881363,88864420,134795389,214552010,2023205639,2086057648,1897238633,1976864222,1804852699,1867694188,1645340341,1724971778,1587496639,1516133128,1461550545,1406951526,1302016099,1230646740,1142491917,1087903418,2896545431,2825181984,2770861561,2716262478,3215044683,3143675388,3055782693,3001194130,2326604591,2389456536,2200899649,2280525302,2578013683,2640855108,2418763421,2498394922,3769900519,3832873040,3912640137,3992402750,4088425275,4151408268,4197601365,4277358050,3334271071,3263032808,3476998961,3422541446,3585640067,3514407732,3694837229,3640369242,1762451694,1842216281,1619975040,1682949687,2047383090,2127137669,1938468188,2001449195,1325665622,1271206113,1183200824,1111960463,1543535498,1489069629,1434599652,1363369299,622672798,568075817,748617968,677256519,907627842,853037301,1067152940,995781531,51762726,131386257,177728840,240578815,269590778,349224269,429104020,491947555,4046411278,4126034873,4172115296,4234965207,3794477266,3874110821,3953728444,4016571915,3609705398,3555108353,3735388376,3664026991,3290680682,3236090077,3449943556,3378572211,3174993278,3120533705,3032266256,2961025959,2923101090,2868635157,2813903052,2742672763,2604032198,2683796849,2461293480,2524268063,2284983834,2364738477,2175806836,2238787779,1569362073,1498123566,1409854455,1355396672,1317987909,1246755826,1192025387,1137557660,2072149281,2135122070,1912620623,1992383480,1753615357,1816598090,1627664531,1707420964,295390185,358241886,404320391,483945776,43990325,106832002,186451547,266083308,932423249,861060070,1041341759,986742920,613929101,542559546,756411363,701822548,3316196985,3244833742,3425377559,3370778784,3601682597,3530312978,3744426955,3689838204,3819031489,3881883254,3928223919,4007849240,4037393693,4100235434,4180117107,4259748804,2310601993,2373574846,2151335527,2231098320,2596047829,2659030626,2470359227,2550115596,2947551409,2876312838,2788305887,2733848168,3165939309,3094707162,3040238851,2985771188],n=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215,33554431,67108863,134217727,268435455,536870911,1073741823,-2147483648];function o(t){const e=[];for(let i=0;it.bits-e.bits||t.code-e.code));let a=0,n=-1;const o=[];let h;for(let t=0;t=t.length)throw RangeError("Out of bound");const i=t.slice();t.sort(((t,e)=>t-e));const s={};for(let e=t.length-1;e>=0;e-=1)s[t[e]]=e;const r=[];for(let e=0;enew Promise((e=>setTimeout(e,t))),c=async t=>new Uint8Array(await(await fetch(t)).arrayBuffer()),f=(t,e=!0,i=!0)=>{if(e){const e=Uint8Array.from(["B".charCodeAt(0),"Z".charCodeAt(0),"h".charCodeAt(0),"1".charCodeAt(0)]);if(i){const i=t;(t=new Uint8Array(e.length+t.length)).set(i,e.length)}t.set(e,0)}return function(t,e=!1){let i=0,s=0,r=0;const l=e=>{if(e>=32){const t=e>>1;return l(t)*(1<>r-e&a;return r-=e,s&=~(a<=49&&c<=57))throw new Error("Invalid blocksize");c-=48;let f=new Uint8Array(1.5*t.length),d=0,u=-1;for(;;){const c=l(48),p=0|l(32);if(54156738319193!==c){if(25779555029136===c){l(7&r);break}throw new Error("Invalid bz2 blocktype")}{if(l(1))throw new Error("do not support randomised");const c=l(24),g=[],m=l(16);for(let t=32768;t>0;t>>=1){if(!(m&t)){for(let t=0;t<16;t+=1)g.push(!1);continue}const e=l(16);for(let t=32768;t>0;t>>=1)g.push(!!(e&t))}const w=l(3);if(w<2||w>6)throw new Error("Invalid number of huffman groups");const x=l(15),y=[],v=Array.from({length:w},((t,e)=>e));for(let t=0;t=w)throw new Error("MTF table out of range");const e=v[t];for(let e=t;e>0;v[e]=v[--e]);y.push(e),v[0]=e}const C=g.reduce(((t,e)=>t+e),0)+2,b=[];for(let t=0;t20)throw new Error("Huffman group length outside range");for(;l(1);)t-=2*l(1)-1;e.push(t)}b.push(o(e))}const A=[];for(let t=0;t>r-e],P)){s&=n[r-=e],P=P.code;break}if(P>=0&&P<=1)0===Y&&(O=1),Y+=O<0;Y-=1)X.push(t)}if(P===C-1)break;{const t=A[P-1];for(let t=P-1;t>0;A[t]=A[--t]);A[0]=t,X.push(t)}}}const F=h(X,c);let T=0;for(;T=f.length){const t=f;f=new Uint8Array(2*t.length),f.set(t)}for(let s=0;s>24^t)]),f[d]=t,d+=1}if(e){const t=-1^u;if(t!==p)throw new Error(`CRC mismatch: ${t} !== ${p}`);u=-1}}}return f.subarray(0,d)}(t)};class d{static getParameter(t){return new URLSearchParams(window.location.search).get(t)??""}static setParameter(t,e){const i=new URL(window.location.toString());i.searchParams.set(t,e),window.history.pushState(null,"",i.toString())}canvas;ctx;drawArea=null;state=0;deltime=20;mindel=1;otim=[];fps=0;fpos=0;frameTime=[];redrawScreen=!0;resizeToFit=!1;idleCycles=0;mouseButton=0;mouseX=0;mouseY=0;mouseClickButton=0;mouseClickX=0;mouseClickY=0;actionKey=[];keyQueue=[];keyQueueReadPos=0;keyQueueWritePos=0;constructor(t=!1){const e=document.getElementById("canvas");if(!e)throw new Error("Canvas not found!!!!!!!!");const i=e.getContext("2d");if(!i)throw new Error("Canvas 2d not found!!!!!!!!");this.canvas=e,this.ctx=i,this.resizeToFit=t,this.resizeToFit?this.resize(window.innerWidth,window.innerHeight):this.resize(e.width,e.height)}get width(){return this.canvas.width}get height(){return this.canvas.height}resize(t,i){const s=this.canvas;s.width=t,s.height=i,this.drawArea=new e(s,t,i),r.init2D()}async run(){window.addEventListener("resize",(()=>{this.resizeToFit&&this.resize(window.innerWidth,window.innerHeight)}),!1),window.addEventListener("keydown",this.keyDown),window.addEventListener("keyup",this.keyUp),window.addEventListener("mousedown",this.mousePressed),await this.showProgress(0,"Loading..."),await this.load();for(let t=0;t<10;t++)this.otim[t]=Date.now();let t,e=0,i=256,s=1,r=0;for(;this.state>=0;){if(this.state>0&&(this.state--,0===this.state))return void this.shutdown();const a=i,n=s;i=300,s=1,t=Date.now();const o=this.otim[e];if(0===o?(i=a,s=n):t>o&&(i=Math.trunc(2560*this.deltime/(t-o))),i<25?i=25:i>256&&(i=256,s=Math.trunc(this.deltime-(t-o)/10)),this.otim[e]=t,e=(e+1)%10,s>1)for(let t=0;t<10;t++)0!==this.otim[t]&&(this.otim[t]+=s);for(s0&&(this.fps=Math.trunc(1e3*i/(256*this.deltime)));const h=performance.now();await this.draw(),this.frameTime[this.fpos]=(performance.now()-h)/1e3,this.fpos=(this.fpos+1)%this.frameTime.length}-1==this.state&&this.shutdown()}shutdown(){this.state=-2,this.unload()}setLoopRate(t){this.deltime=1e3/t}start(){this.state>=0&&(this.state=0)}stop(){this.state>=0&&(this.state=4e3/this.deltime)}destroy(){this.state=-1}async load(){}update(){}unload(){}async draw(){}refresh(){}async showProgress(t,e){const i=this.ctx,s=this.width,r=this.height;this.redrawScreen&&(i.fillStyle="black",i.clearRect(0,0,s,r),this.redrawScreen=!1);const a=r/2-18;i.fillStyle="rgb(140, 17, 17)",i.rect(s/2-152,a,304,34),i.fillRect(s/2-150,a+2,3*t,30),i.fillStyle="black",i.fillRect(s/2-150+3*t,a+2,300-3*t,30),i.font="bold 13px helvetica, sans-serif",i.textAlign="center",i.fillStyle="white",i.fillText(e,s/2,a+22),await l(5)}keyDown=t=>{this.idleCycles=0;const e=t.keyCode;let i=t.key.charCodeAt(0);83!==i&&(i<30&&(i=0),37==e?i=1:39==e?i=2:38==e?i=3:40==e?i=4:17==e?i=5:8==e||127==e?i=8:9==e?i=9:10==e?i=10:e>=112&&e<=123?i=e+1008-112:36==e?i=1e3:35==e?i=1001:33==e?i=1002:34==e&&(i=1003),i>0&&i<128&&(this.actionKey[i]=1),i>4&&(this.keyQueue[this.keyQueueWritePos]=i,this.keyQueueWritePos=this.keyQueueWritePos+1&127))};keyUp=t=>{this.idleCycles=0;let e=t.key.charCodeAt(0);"ArrowLeft"==t.key?e=1:"ArrowRight"==t.key?e=2:"ArrowUp"==t.key?e=3:"ArrowDown"==t.key&&(e=4),this.actionKey[e]=0};pollKey(){let t=-1;return this.keyQueueWritePos!=this.keyQueueReadPos&&(t=this.keyQueue[this.keyQueueReadPos],this.keyQueueReadPos=this.keyQueueReadPos+1&127),t}mousePressed=t=>{let e=t.x,i=t.y;const{top:s,left:r}=this.getInsets;e-=r,i-=s,this.idleCycles=0,this.mouseClickX=e,this.mouseClickY=i,2===t.buttons?(this.mouseClickButton=2,this.mouseButton=2):1===t.buttons&&(this.mouseClickButton=1,this.mouseButton=1)};get getInsets(){const t=this.canvas.getBoundingClientRect(),e=window.getComputedStyle(this.canvas),i=parseFloat(e.paddingLeft||"0"),s=parseFloat(e.paddingTop||"0"),r=parseFloat(e.borderLeftWidth||"0"),a=parseFloat(e.borderTopWidth||"0"),n=t.left+r+i;return{top:t.top+a+s,left:n}}get ms(){const t=this.frameTime.length;let e=0;for(let i=0;i{for(;;){const e=t.g1;if(0===e)break;this.decode(e,t)}}}class p{static instances=[];static unpack=t=>{const e=new i(t.read("base_head.dat")),s=new i(t.read("base_type.dat")),r=new i(t.read("base_label.dat")),a=e.g2;e.pos+=2;for(let t=0;t{const e=new i(t.read("frame_head.dat")),s=new i(t.read("frame_tran1.dat")),r=new i(t.read("frame_tran2.dat")),a=new i(t.read("frame_del.dat")),n=e.g2;e.pos+=2;const o=new Uint32Array(500),h=new Uint32Array(500),l=new Uint32Array(500),c=new Uint32Array(500);for(let t=0;t0){if(0!=f.types[t])for(let e=t-1;e>u;e--)if(0==f.types[e]){o[m]=e,h[m]=0,l[m]=0,c[m]=0,m++;break}o[m]=t;let i=0;3==f.types[o[m]]&&(i=128),h[m]=0==(1&e)?i:r.gsmart,l[m]=0==(2&e)?i:r.gsmart,c[m]=0==(4&e)?i:r.gsmart,u=t,m++}}i.length=m,i.bases=new Uint32Array(m),i.x=new Uint32Array(m),i.y=new Uint32Array(m),i.z=new Uint32Array(m);for(let t=0;t{const e=new i(t.read("seq.dat"));this.count=e.g2;for(let t=0;tm.instances[t];frameCount=0;frames=null;iframes=null;delay=null;replayoff=-1;labelGroups=null;stretches=!1;priority=5;mainhand=-1;offhand=-1;replaycount=99;duration=0;decode=(t,e)=>{if(1===t){this.frameCount=e.g1,this.frames=new Uint16Array(this.frameCount),this.iframes=new Uint16Array(this.frameCount),this.delay=new Uint16Array(this.frameCount);for(let t=0;t{const e=new i(t.read("loc.dat"));this.count=e.g2;for(let t=0;t0&&10==i.shapes[0]?1:0,i.ops.length>0&&(i.active=1))}};static get=t=>w.instances[t];models=null;shapes=null;name=null;desc=null;recol_s=null;recol_d=null;width=1;length=1;blockwalk=!0;blockrange=!0;active=-1;hillskew=!1;sharelight=!1;occlude=!1;anim=-1;hasalpha=!1;walloff=16;ambient=0;contrast=0;ops=[];mapfunction=-1;mapscene=-1;mirror=!1;shadow=!0;resizex=128;resizey=128;resizez=128;forceapproach=0;xoff=0;yoff=0;zoff=0;forcedecor=!1;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t),this.shapes=new Uint8Array(t);for(let i=0;i=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const e=new i(t.read("flo.dat"));this.count=e.g2;for(let t=0;tx.instances[t];rgb=0;texture=-1;opcode3=!1;occludes=!0;name=null;decode=(t,e)=>{1===t?this.rgb=e.g3:2===t?this.texture=e.g1:3===t?this.opcode3=!0:5===t?this.occludes=!1:6===t?this.name=e.gjstr:console.log("Error unrecognised config code: ",t)}}class y{pixels;width;height;cropX;cropY;cropW;cropH;constructor(t,e){this.pixels=new Int32Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromJpeg=async(t,e)=>{const i=t.read(e+".dat"),s=await(async t=>{if(!t)throw new Error("Input jpeg data was null!");255!==t[0]&&(t[0]=255);const e=document.createElement("img");e.src="data:image/jpeg;base64,"+btoa(String.fromCharCode(...t)),await new Promise((t=>e.onload=t));const i=document.createElement("canvas");i.width=e.naturalWidth,i.height=e.naturalHeight;const s=i.getContext("2d");if(!s)throw new Error("Canvas 2d not found!!!!!!!!");return s.drawImage(e,0,0),s.getImageData(0,0,i.width,i.height)})(i),r=new y(s.width,s.height),a=r.pixels,n=s.data;for(let t=0;t{const r=new i(t.read(e+".dat")),a=new i(t.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,h=a.g1,l=new Uint32Array(h),c=h-1;for(let t=0;t{e|=0,i|=0;let s=(e+=this.cropX)+(i+=this.cropY)*t.width,r=0,a=this.height,n=this.width,o=t.width-n,h=0;if(it.bottom&&(a-=i+a-t.bottom),et.right){const i=e+n-t.right;n-=i,h+=i,o+=i}n>0&&a>0&&this.copyImageDraw(n,a,this.pixels,r,h,t.pixels,s,o)};drawAlpha=(e,i,s)=>{i|=0,s|=0;let r=(i+=this.cropX)+(s+=this.cropY)*t.width,a=0,n=this.height,o=this.width,h=t.width-o,l=0;if(st.bottom&&(n-=s+n-t.bottom),it.right){const e=i+o-t.right;o-=e,l+=e,h+=e}o>0&&n>0&&this.copyPixelsAlpha(o,n,this.pixels,a,l,t.pixels,r,h,e)};blitOpaque=(e,i)=>{e|=0,i|=0;let s=(e+=this.cropX)+(i+=this.cropY)*t.width,r=0,a=this.height,n=this.width,o=t.width-n,h=0;if(it.bottom&&(a-=i+a-t.bottom),et.right){const i=e+n-t.right;n-=i,h+=i,o+=i}n>0&&a>0&&this.copyImageBlitOpaque(n,a,this.pixels,r,h,t.pixels,s,o)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;a+=t,a<1?a=1:a>255&&(a=255);let n=r>>8&255;n+=e,n<1?n=1:n>255&&(n=255);let o=255&r;o+=i,o<1?o=1:o>255&&(o=255),this.pixels[s]=(a<<16)+(n<<8)+o}}};copyImageBlitOpaque=(t,e,i,s,r,a,n,o)=>{const h=-(t>>2);t=-(3&t);for(let l=-e;l<0;l++){for(let t=h;t<0;t++)a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++];for(let e=t;e<0;e++)a[n++]=i[s++];n+=o,s+=r}};copyPixelsAlpha=(t,e,i,s,r,a,n,o,h)=>{const l=256-h;for(let c=-e;c<0;c++){for(let e=-t;e<0;e++){const t=i[s++];if(0==t)n++;else{const e=a[n];a[n++]=((16711935&t)*h+(16711935&e)*l&4278255360)+((65280&t)*h+(65280&e)*l&16711680)>>8}}n+=o,s+=r}};copyImageDraw=(t,e,i,s,r,a,n,o)=>{const h=-(t>>2);t=-(3&t);for(let l=-e;l<0;l++){for(let t=h;t<0;t++){let t=i[s++];0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t}for(let e=t;e<0;e++){const t=i[s++];0===t?n++:a[n++]=t}n+=o,s+=r}}}class v extends u{static count=0;static instances=[];static unpack=(t,e)=>{const s=new i(t.read("obj.dat"));this.count=s.g2;for(let t=0;tv.instances[t];static getIcon=(t,e)=>new y(32,32);model=0;name=null;desc=null;recol_s=null;recol_d=null;zoom2d=2e3;xan2d=0;yan2d=0;zan2d=0;xof2d=0;yof2d=0;code9=!1;code10=-1;stackable=!1;cost=1;members=!1;ops=[];iops=[];manwear=-1;manwear2=-1;manwearOffsetY=0;womanwear=-1;womanwear2=-1;womanwearOffsetY=0;manwear3=-1;womanwear3=-1;manhead=-1;manhead2=-1;womanhead=-1;womanhead2=-1;countobj=null;countco=null;certlink=-1;certtemplate=-1;decode=(t,e)=>{if(1===t)this.model=e.g2;else if(2===t)this.name=e.gjstr;else if(3===t)this.desc=e.gjstr;else if(4===t)this.zoom2d=e.g2;else if(5===t)this.xan2d=e.g2;else if(6===t)this.yan2d=e.g2;else if(7===t)this.xof2d=e.g2b,this.xof2d>32767&&(this.xof2d-=65536);else if(8===t)this.yof2d=e.g2b,this.yof2d>32767&&(this.yof2d-=65536);else if(9===t)this.code9=!0;else if(10===t)this.code10=e.g2;else if(11===t)this.stackable=!0;else if(12===t)this.cost=e.g4s;else if(16===t)this.members=!0;else if(23===t)this.manwear=e.g2,this.manwearOffsetY=e.g1b;else if(24===t)this.manwear2=e.g2;else if(25===t)this.womanwear=e.g2,this.womanwearOffsetY=e.g1b;else if(26===t)this.womanwear2=e.g2;else if(t>=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(t>=35&&t<40)this.iops[t-35]=e.gjstr;else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i=100&&t<110))throw new Error(`Unrecognized obj config code: ${t}`);this.countobj&&this.countco||(this.countobj=new Uint16Array(10),this.countco=new Uint16Array(10)),this.countobj[t-100]=e.g2,this.countco[t-100]=e.g2}};toCertificate=()=>{const t=v.get(this.certtemplate);this.model=t.model,this.zoom2d=t.zoom2d,this.xan2d=t.xan2d,this.yan2d=t.yan2d,this.zan2d=t.zan2d,this.xof2d=t.xof2d,this.yof2d=t.yof2d,this.recol_s=t.recol_s,this.recol_d=t.recol_d;const e=v.get(this.certlink);this.name=e.name,this.members=e.members,this.cost=e.cost;let i="a";const s=(e.name||"").toLowerCase().charAt(0);"a"!==s&&"e"!==s&&"i"!==s&&"o"!==s&&"u"!==s||(i="an"),this.desc=`Swap this note at any bank for ${i} ${e.name}.`,this.stackable=!0}}class C extends u{static count=0;static instances=[];static unpack=t=>{const e=new i(t.read("npc.dat"));this.count=e.g2;for(let t=0;tC.instances[t];name=null;desc=null;size=1;models=null;heads=null;hasanim=!1;readyanim=-1;walkanim=-1;walkanim_b=-1;walkanim_r=-1;walkanim_l=-1;hasalpha=!1;recol_s=null;recol_d=null;ops=[];code90=-1;code91=-1;code92=-1;visonmap=!0;vislevel=-1;resizeh=128;resizev=128;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=30&&t<40)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const e=new i(t.read("idk.dat"));this.count=e.g2;for(let t=0;tb.instances[t];type=-1;models=null;heads=new Uint16Array(5).fill(-1);recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);disable=!1;decode=(t,e)=>{if(1===t)this.type=e.g1;else if(2===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=40&&t<50)this.recol_s[t-40]=e.g2;else if(t>=50&&t<60)this.recol_d[t-50]=e.g2;else{if(!(t>=60&&t<70))throw new Error(`Unrecognized idk config code: ${t}`);this.heads[t-60]=e.g2}}}class A extends u{static count=0;static instances=[];static unpack=t=>{const e=new i(t.read("spotanim.dat"));this.count=e.g2;for(let t=0;tA.instances[t];model=0;anim=-1;seq=null;disposeAlpha=!1;recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);resizeh=128;resizev=128;orientation=0;ambient=0;contrast=0;decode=(t,e)=>{if(1==t)this.model=e.g2;else if(2==t)this.anim=e.g2,null!=m.instances&&(this.seq=m.instances[this.anim]);else if(3==t)this.disposeAlpha=!0;else if(4==t)this.resizeh=e.g2;else if(5==t)this.resizev=e.g2;else if(6==t)this.orientation=e.g2;else if(7==t)this.ambient=e.g1;else if(8==t)this.contrast=e.g1;else if(t>=40&&t<50)this.recol_s[t-40]=e.g2;else{if(!(t>=50&&t<60))throw new Error(`Unrecognized spotanim config code: ${t}`);this.recol_d[t-50]=e.g2}}}class S extends u{static count=0;static instances=[];static code3=[];static code3Count=0;static unpack=t=>{const e=new i(t.read("varp.dat"));this.count=e.g2;for(let t=0;tS.instances[t];code10=null;code1=0;code2=0;hasCode3=!1;code4=!0;clientcode=0;code7=0;code6=!1;code8=!1;decode(t,e){if(1==t)this.code1=e.g1;else if(2==t)this.code2=e.g1;else if(3==t)this.hasCode3=!0,S.code3[S.code3Count++]=this.index;else if(4==t)this.code4=!1;else if(5==t)this.clientcode=e.g2;else if(6==t)this.code6=!0;else if(7==t)this.code7=e.g4;else if(8==t)this.code8=!0;else{if(10!=t)throw new Error(`Error unrecognised config code: ${t}`);this.code10=e.gjstr}}}class P{vertexCount=0;faceCount=0;texturedFaceCount=0;vertexFlagsOffset=-1;vertexXOffset=-1;vertexYOffset=-1;vertexZOffset=-1;vertexLabelsOffset=-1;faceVerticesOffset=-1;faceOrientationsOffset=-1;faceColorsOffset=-1;faceInfosOffset=-1;facePrioritiesOffset=0;faceAlphasOffset=-1;faceLabelsOffset=-1;faceTextureAxisOffset=-1}class I{x=0;y=0;z=0;w=0}class k{static metadata=null;static head=null;static face1=null;static face2=null;static face3=null;static face4=null;static face5=null;static point1=null;static point2=null;static point3=null;static point4=null;static point5=null;static vertex1=null;static vertex2=null;static axis=null;static faceClippedX=new Array(4096);static faceNearClipped=new Array(4096);static vertexScreenX=new Int32Array(4096);static vertexScreenY=new Int32Array(4096);static vertexScreenZ=new Int32Array(4096);static vertexViewSpaceX=new Int32Array(4096);static vertexViewSpaceY=new Int32Array(4096);static vertexViewSpaceZ=new Int32Array(4096);static tmpDepthFaceCount=new Int32Array(1500);static tmpDepthFaces=new Array(1500).fill(null).map((()=>new Int32Array(512)));static tmpPriorityFaceCount=new Int32Array(12);static tmpPriorityFaces=new Array(12).fill(null).map((()=>new Int32Array(2e3)));static tmpPriority10FaceDepth=new Int32Array(2e3);static tmpPriority11FaceDepth=new Int32Array(2e3);static tmpPriorityDepthSum=new Int32Array(12);static clippedX=new Int32Array(10);static clippedY=new Int32Array(10);static clippedColor=new Int32Array(10);static baseX=0;static baseY=0;static baseZ=0;static checkHover=!1;static mouseX=0;static mouseZ=0;static pickedCount=0;static pickedBitsets=new Int32Array(1e3);static unpack(t){try{k.head=new i(t.read("ob_head.dat")),k.face1=new i(t.read("ob_face1.dat")),k.face2=new i(t.read("ob_face2.dat")),k.face3=new i(t.read("ob_face3.dat")),k.face4=new i(t.read("ob_face4.dat")),k.face5=new i(t.read("ob_face5.dat")),k.point1=new i(t.read("ob_point1.dat")),k.point2=new i(t.read("ob_point2.dat")),k.point3=new i(t.read("ob_point3.dat")),k.point4=new i(t.read("ob_point4.dat")),k.point5=new i(t.read("ob_point5.dat")),k.vertex1=new i(t.read("ob_vertex1.dat")),k.vertex2=new i(t.read("ob_vertex2.dat")),k.axis=new i(t.read("ob_axis.dat")),k.head.pos=0,k.point1.pos=0,k.point2.pos=0,k.point3.pos=0,k.point4.pos=0,k.vertex1.pos=0,k.vertex2.pos=0;const e=k.head.g2;k.metadata=new Array(e+100);let s=0,r=0,a=0,n=0,o=0,h=0,l=0;for(let t=0;t127&&(e=127),127-e):((e=e*(127&t)>>7)<2?e=2:e>126&&(e=126),(65408&t)+e)}vertexCount=0;vertexX=null;vertexY=null;vertexZ=null;faceCount=0;faceVertexA=null;faceVertexB=null;faceVertexC=null;faceColorA=null;faceColorB=null;faceColorC=null;faceInfo=null;facePriority=null;faceAlpha=null;faceColor=null;priority=0;texturedFaceCount=0;texturedVertexA=null;texturedVertexB=null;texturedVertexC=null;minX=0;maxX=0;minZ=0;maxZ=0;radius=0;minY=0;maxY=0;maxDepth=0;minDepth=0;objRaise=0;vertexLabel=null;faceLabel=null;labelVertices=null;labelFaces=null;pickable=!1;vertexNormal=null;vertexNormalOriginal=null;constructor(t){if(null===k.head||null===k.face1||null===k.face2||null===k.face3||null===k.face4||null===k.face5||null===k.point1||null===k.point2||null===k.point3||null===k.point4||null===k.point5||null===k.vertex1||null===k.vertex2||null===k.axis)return;if(null===k.metadata)return;const e=k.metadata[t];if(void 0===e)return void console.log(`Error model:${t} not found!`);this.vertexCount=e.vertexCount,this.faceCount=e.faceCount,this.texturedFaceCount=e.texturedFaceCount,this.vertexX=new Int32Array(this.vertexCount),this.vertexY=new Int32Array(this.vertexCount),this.vertexZ=new Int32Array(this.vertexCount),this.faceVertexA=new Int32Array(this.faceCount),this.faceVertexB=new Int32Array(this.faceCount),this.faceVertexC=new Int32Array(this.faceCount),this.texturedVertexA=new Int32Array(this.texturedFaceCount),this.texturedVertexB=new Int32Array(this.texturedFaceCount),this.texturedVertexC=new Int32Array(this.texturedFaceCount),e.vertexLabelsOffset>=0&&(this.vertexLabel=new Int32Array(this.vertexCount)),e.faceInfosOffset>=0&&(this.faceInfo=new Int32Array(this.faceCount)),e.facePrioritiesOffset>=0?this.facePriority=new Int32Array(this.faceCount):this.priority=-e.facePrioritiesOffset-1,e.faceAlphasOffset>=0&&(this.faceAlpha=new Int32Array(this.faceCount)),e.faceLabelsOffset>=0&&(this.faceLabel=new Int32Array(this.faceCount)),this.faceColor=new Int32Array(this.faceCount),k.point1.pos=e.vertexFlagsOffset,k.point2.pos=e.vertexXOffset,k.point3.pos=e.vertexYOffset,k.point4.pos=e.vertexZOffset,k.point5.pos=e.vertexLabelsOffset;let i,s,r,a=0,n=0,o=0;for(let t=0;tthis.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)+.99),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsY(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.minY=0;for(let t=0;tthis.maxY&&(this.maxY=-e),e>this.minY&&(this.minY=e)}this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsAABB(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.radius=0,this.minY=0,this.minX=999999,this.maxX=-999999,this.maxZ=-99999,this.minZ=99999;for(let t=0;tthis.maxX&&(this.maxX=e),sthis.maxZ&&(this.maxZ=s),-i>this.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY))}}createLabelReferences(){}applyTransform(t){}rotateY90(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let t=0;t>16;this.vertexZ[t]=this.vertexY[t]*e+this.vertexZ[t]*i>>16,this.vertexY[t]=s}}translate(t,e,i){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let s=0;s>8;if(null!==this.faceColorA&&null!==this.faceColorB&&null!==this.faceColorC||(this.faceColorA=new Int32Array(this.faceCount),this.faceColorB=new Int32Array(this.faceCount),this.faceColorC=new Int32Array(this.faceCount)),null===this.vertexNormal){this.vertexNormal=new Array(this.vertexCount);for(let t=0;t8192||m>8192||w>8192||g<-8192||m<-8192||w<-8192;)g>>=1,m>>=1,w>>=1;let x=Math.sqrt(g*g+m*m+w*w);if(x<=0&&(x=1),g=256*g/x,m=256*m/x,w=256*w/x,null===this.faceInfo||0==(1&this.faceInfo[e])){let t=this.vertexNormal[a];t.x+=g,t.y+=m,t.z+=w,t.w++,t=this.vertexNormal[o],t.x+=g,t.y+=m,t.z+=w,t.w++,t=this.vertexNormal[h],t.x+=g,t.y+=m,t.z+=w,t.w++}else{const a=t+(i*g+s*m+r*w)/(n+n/2);this.faceColorA[e]=k.mulColorLightness(this.faceColor[e],a,this.faceInfo[e])}}if(a)this.applyLighting(t,e,i,s,r);else{this.vertexNormalOriginal=new Array(this.vertexCount);for(let t=0;t>16;for(let s=0;s>16,y=y*u-x*d>>16,x=w),0!==t&&(w=y*l-v*h>>16,v=y*h+v*l>>16,y=w),0!==e&&(w=v*c+x*f>>16,v=v*f-x*c>>16,x=w),x+=a,y+=n,v+=o,w=y*g-v*p>>16,v=y*p+v*g>>16,y=w,k.vertexScreenX[s]=r.centerX+(x<<9)/v,k.vertexScreenY[s]=r.centerY+(y<<9)/v,k.vertexScreenZ[s]=v-m,this.texturedFaceCount>0&&(k.vertexViewSpaceX[s]=x,k.vertexViewSpaceY[s]=y,k.vertexViewSpaceZ[s]=v)}this.draw2(!1,!1,0)}draw(t,e,i,s,r,a,n,o,h){}draw2(e,i,s){if(null===k.vertexScreenX||null===k.vertexScreenY||null===k.vertexScreenZ)return;if(null===k.vertexViewSpaceX||null===k.vertexViewSpaceY||null===k.vertexViewSpaceZ)return;if(null===k.faceNearClipped||null===k.faceClippedX)return;if(null===k.tmpDepthFaceCount||null===k.tmpDepthFaces||null===k.tmpPriorityFaces||null===k.tmpPriorityFaceCount||null===k.tmpPriorityDepthSum||null===k.tmpPriority10FaceDepth||null===k.tmpPriority11FaceDepth)return;if(null===this.faceVertexA||null===this.faceVertexB||null===this.faceVertexC)return;for(let t=0;tt.boundX||l>t.boundX||c>t.boundX;const u=Math.trunc((k.vertexScreenZ[a]+k.vertexScreenZ[n]+k.vertexScreenZ[o])/3+this.minDepth);k.tmpDepthFaces[u][k.tmpDepthFaceCount[u]++]=r}else{k.faceNearClipped[r]=!0;const t=Math.trunc((k.vertexScreenZ[a]+k.vertexScreenZ[n]+k.vertexScreenZ[o])/3+this.minDepth);k.tmpDepthFaces[t][k.tmpDepthFaceCount[t]++]=r}}if(null==this.facePriority){for(let t=this.maxDepth-1;t>=0;t--){const e=k.tmpDepthFaceCount[t];if(e<=0)continue;const i=k.tmpDepthFaces[t];for(let t=0;t=0;t--){const e=k.tmpDepthFaceCount[t];if(e>0){const i=k.tmpDepthFaces[t];for(let s=0;s0||k.tmpPriorityFaceCount[2]>0)&&(r=Math.trunc((k.tmpPriorityDepthSum[1]+k.tmpPriorityDepthSum[2])/(k.tmpPriorityFaceCount[1]+k.tmpPriorityFaceCount[2])));let a=0;(k.tmpPriorityFaceCount[3]>0||k.tmpPriorityFaceCount[4]>0)&&(a=Math.trunc((k.tmpPriorityDepthSum[3]+k.tmpPriorityDepthSum[4])/(k.tmpPriorityFaceCount[3]+k.tmpPriorityFaceCount[4])));let n=0;(k.tmpPriorityFaceCount[6]>0||k.tmpPriorityFaceCount[8]>0)&&(n=Math.trunc((k.tmpPriorityDepthSum[6]+k.tmpPriorityDepthSum[8])/(k.tmpPriorityFaceCount[6]+k.tmpPriorityFaceCount[8])));let o,h=0,l=k.tmpPriorityFaceCount[10],c=k.tmpPriorityFaces[10],f=k.tmpPriority10FaceDepth;h==l&&(h=0,l=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),o=hr;)this.drawFace(c[h++]),h==l&&c!=k.tmpPriorityFaces[11]&&(h=0,l=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),o=ha;)this.drawFace(c[h++]),h==l&&c!=k.tmpPriorityFaces[11]&&(h=0,l=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),o=hn;)this.drawFace(c[h++]),h==l&&c!=k.tmpPriorityFaces[11]&&(h=0,l=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),o=ha&&e>n&&e>o||t{const r=new i(t.read("data"));let a=-1;for(r.pos+=2;r.pos0){i.scriptComparator=new Uint8Array(n).fill(0),i.scriptOperand=new Uint16Array(n).fill(0);for(let t=0;t0){i.scripts=new Array(o).fill(null);for(let t=0;t0){const r=s.lastIndexOf(",");i.inventorySlotImage[t]=y.fromArchive(e,s,r)}}for(let t=0;t<5;t++)i.inventoryOptions[t]=r.gjstr,0===i.inventoryOptions[t]?.length&&(i.inventoryOptions[t]=null);i.spellAction=r.gjstr,i.spellName=r.gjstr,i.spellFlags=r.g2;break;case Y.TYPE_RECT:i.fill=1===r.g1,i.color=r.g4,i.activeColor=r.g4,i.hoverColor=r.g4;break;case Y.TYPE_TEXT:i.center=1===r.g1,i.font=s[r.g1],i.shadow=1===r.g1,i.text=r.gjstr,i.activeText=r.gjstr,i.color=r.g4,i.activeColor=r.g4,i.hoverColor=r.g4;break;case Y.TYPE_SPRITE:{const t=r.gjstr;if(t.length>0){const s=t.lastIndexOf(",");i.image=y.fromArchive(e,t.substring(0,s),parseInt(t.substring(s+1)))}const s=r.gjstr;if(s.length>0){const t=s.lastIndexOf(",");i.image=y.fromArchive(e,s.substring(0,t),parseInt(s.substring(t+1)))}break}case Y.TYPE_MODEL:{const t=r.g1;0!==t&&(i.model=this.getModel((t-1<<8)+r.g1));const e=r.g1;0!==e&&(i.activeModel=this.getModel((e-1<<8)+r.g1)),i.seqId=r.g1,0==i.seqId?i.seqId=-1:i.seqId=(i.seqId-1<<8)+r.g1,i.activeSeqId=r.g1,0==i.activeSeqId?i.activeSeqId=-1:i.activeSeqId=(i.activeSeqId-1<<8)+r.g1,i.modelZoom=r.g2,i.modelPitch=r.g2,i.modelYaw=r.g2;break}case Y.TYPE_INVENTORY_TEXT:i.inventorySlotObjId=new Int32Array(i.width*i.height),i.inventorySlotObjCount=new Int32Array(i.width*i.height),i.center=1===r.g1,i.font=s[r.g1],i.shadow=1===r.g1,i.color=r.g4,i.inventoryMarginX=r.g2b,i.inventoryMarginY=r.g2b,i.inventoryInteractable=1===r.g1,i.inventoryOptions=new Array(5).fill(null);for(let t=0;t<5;t++)i.inventoryOptions[t]=r.gjstr}2!=i.optionType&&2!=i.type||(i.spellAction=r.gjstr,i.spellName=r.gjstr,i.spellFlags=r.g2),1!=i.optionType&&4!=i.optionType&&5!=i.optionType&&6!=i.optionType||(i.option=r.gjstr,0==i.option.length&&(1==i.optionType?i.option="Ok":4==i.optionType||5==i.optionType?i.option="Select":6==i.optionType&&(i.option="Continue")))}};static get=t=>Y.instances[t];static getModel=t=>new k(t);id=-1;parentId=-1;type=-1;optionType=-1;contentType=0;width=0;height=0;delegateHover=-1;scriptComparator=null;scriptOperand=null;scripts=null;scrollableHeight=0;hide=!1;inventoryDraggable=!1;inventoryInteractable=!1;inventoryUsable=!1;inventoryMarginX=0;inventoryMarginY=0;inventorySlotOffsetX=null;inventorySlotOffsetY=null;inventorySlotImage=null;inventoryOptions=[];fill=!1;center=!1;font=null;shadow=!1;text=null;activeText=null;color=0;activeColor=0;hoverColor=0;image=null;activeImage=null;model=null;activeModel=null;seqId=-1;activeSeqId=-1;modelZoom=0;modelPitch=0;modelYaw=0;spellAction=null;spellName=null;spellFlags=-1;option=null;childId=null;childX=null;childY=null;x=0;y=0;scrollPosition=0;inventorySlotObjId=null;inventorySlotObjCount=null;seqFrame=0;getModel=(t,e,i)=>{let s=this.model;return i&&(s=this.activeModel),null==s?null:-1==t&&-1==e&&null==s.faceColor?s:null}}class O{static CHARSET=[];static{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";for(let e=0;e<256;e++){let i=t.indexOf(String.fromCharCode(e));-1===i&&(i=74),O.CHARSET[e]=i}}pixels=[];charWidth=[];charHeight=[];clipX=[];clipY=[];charSpace=[];drawWidth=[];fontHeight=-1;static fromArchive=(t,e)=>{const s=new i(t.read(e+".dat")),r=new i(t.read("index.dat"));r.pos=s.g2+4;const a=r.g1;a>0&&(r.pos+=3*(a-1));const n=new O;for(let t=0;t<94;t++){n.clipX[t]=r.g1,n.clipY[t]=r.g1;const e=n.charWidth[t]=r.g2,i=n.charHeight[t]=r.g2,a=e*i;n.pixels[t]=new Uint8Array(a);const o=r.g1;if(0===o)for(let r=0;rn.fontHeight&&(n.fontHeight=i),n.clipX[t]=1,n.charSpace[t]=e+2;{let s=0;for(let r=i/7;r{t|=0,e|=0;const r=i.length;e-=this.fontHeight;for(let a=0;a{t|=0,e|=0;const a=i.length;e-=this.fontHeight;for(let n=0;n{const e=t.length;let i=0;for(let s=0;s{const r=e-this.fontHeight;for(let e=0;e{this.drawStringTaggable(t-this.stringWidth(i)/2,e,i,s,r)};drawStringCenter=(t,e,i,s)=>{this.draw(t-this.stringWidth(i)/2,e,i,s)};drawRight=(t,e,i,s,r=!0)=>{r&&this.draw(t-this.stringWidth(i)+1,e+1,i,0),this.draw(t-this.stringWidth(i),e,i,s)};drawChar=(e,i,s,r,a,n)=>{r|=0,a|=0;let o=(i|=0)+(s|=0)*t.width,h=t.width-r,l=0,c=0;if(s=t.bottom&&(a-=s+a+1-t.bottom),i=t.right){const e=i+r+1-t.right;r-=e,l+=e,h+=e}r>0&&a>0&&this.drawMask(r,a,e,c,l,t.pixels,o,h,n)};drawMask=(t,e,i,s,r,a,n,o,h)=>{const l=-((t|=0)>>2);t=-(3&t);for(let c=-(e|=0);c<0;c++){for(let t=l;t<0;t++)0==i[s++]?n++:a[n++]=h,0==i[s++]?n++:a[n++]=h,0==i[s++]?n++:a[n++]=h,0==i[s++]?n++:a[n++]=h;for(let e=t;e<0;e++)0==i[s++]?n++:a[n++]=h;n+=o,s+=r}};copyCharacter=(e,i,s,r,a,n)=>{s|=0,r|=0;let o=(e|=0)+(i|=0)*t.width,h=0,l=t.width-s,c=0;if(it.bottom&&(r-=i+r+1-t.bottom),et.right){const i=e+s+1-t.right;s-=i,c+=i,l+=i}s>0&&r>0&&this.copyImageMasked(s,r,a,h,c,t.pixels,o,l,n)};copyImageMasked=(t,e,i,s,r,a,n,o,h)=>{for(let l=0;l{switch(t){case"red":return 16711680;case"gre":return 65280;case"blu":return 255;case"yel":return 16776960;case"cya":return 65535;case"mag":return 16711935;case"whi":return 16777215;case"bla":default:return 0;case"lre":return 16748608;case"dre":return 8388608;case"dbl":return 128;case"or1":return 16756736;case"or2":return 16740352;case"or3":return 16723968;case"gr1":return 12648192;case"gr2":return 8453888;case"gr3":return 4259584}}}class X{static loadUrl=async t=>new X(await c(t));static genHash=t=>{let e=0;t=t.toUpperCase();for(let i=0;i>>0;return e};buffer;compressedWhole;fileCount;fileHash;fileSizeInflated;fileSizeDeflated;fileOffset;constructor(t){const e=new i(t),s=e.g3;let r;if(s==e.g3)r=e,this.compressedWhole=!1;else{const t=e.gdata(e.pos,s);r=new i(new Uint8Array(f(t))),this.compressedWhole=!0}this.buffer=r,this.fileCount=r.g2,this.fileHash=[],this.fileSizeInflated=[],this.fileSizeDeflated=[],this.fileOffset=[];let a=r.pos+10*this.fileCount;for(let t=0;t{const e=X.genHash(t),i=this.fileHash.indexOf(e);return-1==i?null:this.readIndex(i)};readIndex=t=>{if(t<0||t>=this.fileCount)return null;if(this.compressedWhole)return this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);{const e=this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);return f(e)}}}class F{static PERIOD=new Uint16Array(["d","o","t"].join("").split("").map((t=>t.charCodeAt(0))));static AMPERSAT=new Uint16Array(["(","a",")"].join("").split("").map((t=>t.charCodeAt(0))));static SLASH=new Uint16Array(["s","l","a","s","h"].join("").split("").map((t=>t.charCodeAt(0))));static whitelist=["cook","cook's","cooks","seeks","sheet"];static tlds=[];static tldTypes=[];static bads=[];static badCombinations=[];static domains=[];static fragments=[];static unpack=t=>{const e=new i(t.read("fragmentsenc.txt")),s=new i(t.read("badenc.txt")),r=new i(t.read("domainenc.txt")),a=new i(t.read("tldlist.txt"));this.read(s,r,e,a)};static filter=t=>{const e=[...t];this.format(e);const i=e.join("").trim(),s=i.toLowerCase(),r=[...s];this.filterTlds(r),this.filterBadWords(r),this.filterDomains(r),this.filterFragments(r);for(let t=0;t{this.readBadWords(t),this.readDomains(e),this.readFragments(i),this.readTld(s)};static readTld=t=>{const e=t.g4;for(let i=0;it.g1))};static readBadWords=t=>{const e=t.g4;for(let i=0;it.g1));const e=new Array(t.g1).fill([]).map((()=>[t.g1b,t.g1b]));e.length>0&&(this.badCombinations[i]=e)}};static readDomains=t=>{const e=t.g4;for(let i=0;it.g1))};static readFragments=t=>{const e=t.g4;for(let i=0;i{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.PERIOD),this.filterBadCombinations(null,i,this.SLASH);for(let s=0;s{for(let e=0;e<2;e++)for(let e=this.bads.length-1;e>=0;e--)this.filterBadCombinations(this.badCombinations[e],t,this.bads[e])};static filterDomains=t=>{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.AMPERSAT),this.filterBadCombinations(null,i,this.PERIOD);for(let s=this.domains.length-1;s>=0;s--)this.filterDomain(i,e,this.domains[s],t)};static filterFragments=t=>{for(let e=0;e=0&&r{if(this.isNumericalChars(t))return!0;const e=this.getInteger(t),i=this.fragments,s=i.length;if(e===i[0]||e===i[s-1])return!0;let r=0,a=s-1;for(;r<=a;){const t=Math.floor((r+a)/2);if(e===i[t])return!0;e{if(t.length>6)return 0;let e=0;for(let i=0;i{for(let i=e;i=0;i++)if(this.isNumerical(t[i]))return i;return-1};static indexOfNonNumber=(t,e)=>{for(let i=t;i=0;i++)if(!this.isNumerical(e[i]))return i;return e.length};static getEmulatedDomainCharLen=(t,e,i)=>e==i||"o"==e&&"0"==i?1:"o"==e&&"("==i&&")"==t?2:"c"!=e||"("!=i&&"<"!=i&&"["!=i?"e"==e&&"€"==i||"s"==e&&"$"==i||"l"==e&&"i"==i?1:0:1;static filterDomain=(t,e,i,s)=>{const r=i.length,a=s.length;for(let n=0;n<=a-r;n++){const{matched:r,currentIndex:a}=this.findMatchingDomain(n,i,s);if(!r)continue;const o=this.prefixSymbolStatus(n,s,3,e,["@"]),h=this.suffixSymbolStatus(a-1,s,3,t,[".",","]);(o>2||h>2)&&this.maskChars(n,a,s)}};static findMatchingDomain=(t,e,i)=>{const s=e.length;let r=t,a=0;for(;r0)r+=h,a++;else{if(0===a)break;const i=this.getEmulatedDomainCharLen(o,String.fromCharCode(e[a-1]),n);if(i>0)r+=i,1===a&&t++;else{if(a>=s||!this.isSymbol(n))break;r++}}}return{matched:a>=s,currentIndex:r}};static filterBadCombinations=(t,e,i)=>{if(!(i.length>e.length))for(let s=0;s<=e.length-i.length;s++){let r=s;const{currentIndex:a,badIndex:n,hasSymbol:o,hasNumber:h,hasDigit:l}=this.processBadCharacters(e,i,r);r=a;let c=e[r],f=r+1=i.length)||h&&l)continue;let d,u=!0;if(o){let t=!1,i=!1;if((s-1<0||this.isSymbol(e[s-1])&&"'"!=e[s-1])&&(t=!0),(r>=e.length||this.isSymbol(e[r])&&"'"!=e[r])&&(i=!0),!t||!i){let i=!1;for(d=s-2,t&&(d=s);!i&&d=0&&(!this.isSymbol(e[d])||"'"==e[d])){const t=[];let s;for(s=0;s<3&&d+s=0&&(!this.isSymbol(e[d-1])||"'"==e[d-1])&&(r=!1),r&&!this.isBadFragment(t)&&(i=!0)}d++}i||(u=!1)}}else{c=" ",s-1>=0&&(c=e[s-1]),f=" ",r{let s=i,r=0,a=0,n=!1,o=!1,h=!1;for(;s=t.length||o&&h);){const l=t[s],c=s+10)1===f&&this.isNumerical(l)&&(o=!0),2===f&&(this.isNumerical(l)||this.isNumerical(c))&&(o=!0),s+=f,r++;else{if(0===r)break;let t;if((t=this.getEmulatedBadCharLen(c,String.fromCharCode(e[r-1]),l))>0)s+=t;else{if(r>=e.length||!this.isNotLowercaseAlpha(l))break;if(this.isSymbol(l)&&"'"!==l&&(n=!0),this.isNumerical(l)&&(h=!0),s++,a++,100*a/(s-i)>90)break}}}return{currentIndex:s,badIndex:r,hasSymbol:n,hasNumber:o,hasDigit:h}};static getEmulatedBadCharLen=(t,e,i)=>{if(e==i)return 1;if(e>="a"&&e<="m"){if("a"==e)return"4"!=i&&"@"!=i&&"^"!=i?"/"==i&&"\\"==t?2:0:1;if("b"==e)return"6"!=i&&"8"!=i?"1"==i&&"3"==t?2:0:1;if("c"==e)return"("!=i&&"<"!=i&&"{"!=i&&"["!=i?0:1;if("d"==e)return"["==i&&")"==t?2:0;if("e"==e)return"3"!=i&&"€"!=i?0:1;if("f"==e)return"p"==i&&"h"==t?2:"£"==i?1:0;if("g"==e)return"9"!=i&&"6"!=i?0:1;if("h"==e)return"#"==i?1:0;if("i"==e)return"y"!=i&&"l"!=i&&"j"!=i&&"1"!=i&&"!"!=i&&":"!=i&&";"!=i&&"|"!=i?0:1;if("j"==e)return 0;if("k"==e)return 0;if("l"==e)return"1"!=i&&"|"!=i&&"i"!=i?0:1;if("m"==e)return 0}if(e>="n"&&e<="z"){if("n"==e)return 0;if("o"==e)return"0"!=i&&"*"!=i?"("==i&&")"==t||"["==i&&"]"==t||"{"==i&&"}"==t||"<"==i&&">"==t?2:0:1;if("p"==e)return 0;if("q"==e)return 0;if("r"==e)return 0;if("s"==e)return"5"!=i&&"z"!=i&&"$"!=i&&"2"!=i?0:1;if("t"==e)return"7"!=i&&"+"!=i?0:1;if("u"==e)return"v"==i?1:"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("v"==e)return"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("w"==e)return"v"==i&&"v"==t?2:0;if("x"==e)return")"==i&&"("==t||"}"==i&&"{"==t||"]"==i&&"["==t||">"==i&&"<"==t?2:0;if("y"==e)return 0;if("z"==e)return 0}return e>="0"&&e<="9"?"0"==e?"o"==i||"O"==i?1:"("==i&&")"==t||"{"==i&&"}"==t||"["==i&&"]"==t?2:0:"1"==e&&"l"==i?1:0:","==e?"."==i?1:0:"."==e?","==i?1:0:"!"==e&&"i"==i?1:0};static comboMatches=(t,e,i)=>{let s=0,r=e.length-1;for(;s<=r;){const a=Math.floor((s+r)/2);if(e[a][0]===t&&e[a][1]===i)return!0;tthis.isLowercaseAlpha(t)?t.charCodeAt(0)+1-"a".charCodeAt(0):"'"==t?28:this.isNumerical(t)?t.charCodeAt(0)+29-"0".charCodeAt(0):27;static filterTld=(t,e,i,s,r)=>{if(!(s.length>i.length))for(let a=0;a<=i.length-s.length;a++){const{currentIndex:n,tldIndex:o}=this.processTlds(i,s,a);if(o0&&c>0&&(h=!0),2==e&&(l>2&&c>0||l>0&&c>2)&&(h=!0),3==e&&l>0&&c>2&&(h=!0),!h)continue;let f,d=a,u=n-1,p=!1;if(l>2){if(4==l)for(p=!1,f=a-1;f>=0;f--)if(p){if("*"!=r[f])break;d=f}else"*"==r[f]&&(d=f,p=!0);for(p=!1,f=d-1;f>=0;f--)if(p){if(this.isSymbol(i[f]))break;d=f}else this.isSymbol(i[f])||(p=!0,d=f)}if(c>2){if(4==c)for(p=!1,f=u+1;f{let s=0;for(;i0)i+=n,s++;else{if(0===s)break;let t;if((t=this.getEmulatedDomainCharLen(a,String.fromCharCode(e[s-1]),r))>0)i+=t;else{if(!this.isSymbol(r))break;i++}}}return{currentIndex:i,tldIndex:s}};static isSymbol=t=>!this.isAlpha(t)&&!this.isNumerical(t);static isNotLowercaseAlpha=t=>!this.isLowercaseAlpha(t)||"v"==t||"x"==t||"j"==t||"q"==t||"z"==t;static isAlpha=t=>this.isLowercaseAlpha(t)||this.isUppercaseAlpha(t);static isNumerical=t=>t>="0"&&t<="9";static isLowercaseAlpha=t=>t>="a"&&t<="z";static isUppercaseAlpha=t=>t>="A"&&t<="Z";static isNumericalChars=t=>{for(let e=0;e{for(let s=t;s{let i=0;for(let s=e-1;s>=0&&this.isSymbol(t[s]);s--)"*"===t[s]&&i++;return i};static maskedCountForwards=(t,e)=>{let i=0;for(let s=e+1;s(r?this.maskedCountBackwards(e,i):this.maskedCountForwards(e,i))>=s?4:this.isSymbol(r?t[i-1]:t[i+1])?1:0;static prefixSymbolStatus=(t,e,i,s,r)=>{if(0===t)return 2;for(let i=t-1;i>=0&&this.isSymbol(e[i]);i--)if(r.includes(e[i]))return 3;return this.maskedCharsStatus(e,s,t,i,!0)};static suffixSymbolStatus=(t,e,i,s,r)=>{if(t+1===e.length)return 2;for(let i=t+1;i{let e=0;for(let i=0;it>=" "&&t<=""||" "==t||"\n"==t||"\t"==t||"£"==t||"€"==t;static replaceUppercases=(t,e)=>{for(let i=0;i{let e=!0;for(let i=0;i{}}class B extends d{static HOST="https://w2.225.2004scape.org";fontPlain11=null;fontPlain12=null;fontBold12=null;fontQuill8=null;lastHistoryRefresh=0;historyRefresh=!0;constructor(){super(!0)}load=async()=>{await this.showProgress(10,"Connecting to fileserver");const t=new i(await c(`${B.HOST}/crc`)),e=[];for(let i=0;i<9;i++)e[i]=t.g4;const s=await this.loadArchive("title","title screen",e[1],10);this.fontPlain11=O.fromArchive(s,"p11"),this.fontPlain12=O.fromArchive(s,"p12"),this.fontBold12=O.fromArchive(s,"b12"),this.fontQuill8=O.fromArchive(s,"q8");const a=await this.loadArchive("config","config",e[2],15),n=await this.loadArchive("interface","interface",e[3],20),o=await this.loadArchive("media","2d graphics",e[4],30),h=await this.loadArchive("models","3d graphics",e[5],40),l=await this.loadArchive("textures","textures",e[6],60),f=await this.loadArchive("wordenc","chat system",e[7],65),d=await this.loadArchive("sounds","sound effects",e[8],70);await this.showProgress(75,"Unpacking media"),await this.showProgress(80,"Unpacking textures"),r.unpackTextures(l),r.setBrightness(.8),r.initPool(20),await this.showProgress(83,"Unpacking models"),k.unpack(h),p.unpack(h),g.unpack(h),await this.showProgress(86,"Unpacking config"),m.unpack(a),w.unpack(a),x.unpack(a),v.unpack(a,!0),C.unpack(a),b.unpack(a),A.unpack(a),S.unpack(a),await this.showProgress(90,"Unpacking sounds"),T.unpack(d),await this.showProgress(92,"Unpacking interfaces"),Y.unpack(n,o,[this.fontPlain11,this.fontPlain12,this.fontBold12,this.fontQuill8]),await this.showProgress(97,"Preparing game engine"),F.unpack(f),this.drawArea?.bind(),r.init2D()};update=()=>{this.updateKeysPressed(),this.updateKeysHeld(),this.lastHistoryRefresh++,this.lastHistoryRefresh>50&&(this.historyRefresh&&(d.setParameter("model",this.model.id.toString()),d.setParameter("x",this.model.pitch.toString()),d.setParameter("y",this.model.yaw.toString()),d.setParameter("z",this.model.roll.toString()),d.setParameter("eyeX",this.camera.x.toString()),d.setParameter("eyeY",this.camera.y.toString()),d.setParameter("eyeZ",this.camera.z.toString()),d.setParameter("eyePitch",this.camera.pitch.toString()),this.historyRefresh=!1),this.lastHistoryRefresh=0)};draw=async()=>{t.clear(),t.fillRect(0,0,this.width,this.height,5592405);const e=new k(this.model.id);if(e.calculateNormals(64,850,-30,-50,-30,!0),e.drawSimple(this.model.pitch,this.model.yaw,this.model.roll,this.camera.pitch,this.camera.x,this.camera.y,this.camera.z),this.fontBold12){this.fontBold12.drawRight(this.width,this.fontBold12.fontHeight,`FPS: ${this.fps}`,16776960),this.fontBold12.drawRight(this.width,this.height,`${this.model.pitch},${this.model.yaw},${this.model.roll},${this.camera.pitch},${this.camera.x},${this.camera.z},${this.camera.y}`,16776960);let t=this.fontBold12.fontHeight;this.fontBold12.draw(0,t,`Model: ${this.model.id}`,16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"Controls:",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"r - reset camera and model rotation + movement speed",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"1 and 2 - change model",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"[ and ] - adjust movement speed",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"left and right - adjust model yaw",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"up and down - adjust model pitch",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,". and / - adjust model roll",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"w and s - move camera along z axis",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"a and d - move camera along x axis",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"q and e - move camera along y axis",16776960)}this.drawArea?.draw(0,0)};async loadArchive(t,e,i,s){await this.showProgress(s,`Requesting ${e}`);const r=await X.loadUrl(`${B.HOST}/${t}${i}`);return await this.showProgress(s,`Loading ${e} - 100%`),r}modifier=2;model={id:parseInt(d.getParameter("model"))||0,pitch:parseInt(d.getParameter("x"))||0,yaw:parseInt(d.getParameter("y"))||0,roll:parseInt(d.getParameter("z"))||0};camera={x:parseInt(d.getParameter("eyeX"))||0,y:parseInt(d.getParameter("eyeY"))||0,z:parseInt(d.getParameter("eyeZ"))||420,pitch:parseInt(d.getParameter("eyePitch"))||0};updateKeysPressed(){for(;;){const t=this.pollKey();if(-1===t)break;t==="r".charCodeAt(0)?(this.modifier=2,this.model={id:this.model.id,pitch:0,yaw:0,roll:0},this.camera={x:0,y:0,z:420,pitch:0},this.historyRefresh=!0):t==="1".charCodeAt(0)?(this.model.id--,this.model.id<0&&k.metadata&&(this.model.id=k.metadata.length-100-1),this.historyRefresh=!0):t==="2".charCodeAt(0)&&(this.model.id++,k.metadata&&this.model.id>=k.metadata.length-100&&(this.model.id=0),this.historyRefresh=!0)}}updateKeysHeld(){this.actionKey["[".charCodeAt(0)]?this.modifier--:this.actionKey["]".charCodeAt(0)]&&this.modifier++,this.actionKey[1]?(this.model.yaw+=this.modifier,this.historyRefresh=!0):this.actionKey[2]&&(this.model.yaw-=this.modifier,this.historyRefresh=!0),this.actionKey[3]?(this.model.pitch-=this.modifier,this.historyRefresh=!0):this.actionKey[4]&&(this.model.pitch+=this.modifier,this.historyRefresh=!0),this.actionKey[".".charCodeAt(0)]?(this.model.roll+=this.modifier,this.historyRefresh=!0):this.actionKey["/".charCodeAt(0)]&&(this.model.roll-=this.modifier,this.historyRefresh=!0),this.actionKey["w".charCodeAt(0)]?(this.camera.z-=this.modifier,this.historyRefresh=!0):this.actionKey["s".charCodeAt(0)]&&(this.camera.z+=this.modifier,this.historyRefresh=!0),this.actionKey["a".charCodeAt(0)]?(this.camera.x-=this.modifier,this.historyRefresh=!0):this.actionKey["d".charCodeAt(0)]&&(this.camera.x+=this.modifier,this.historyRefresh=!0),this.actionKey["q".charCodeAt(0)]?(this.camera.y-=this.modifier,this.historyRefresh=!0):this.actionKey["e".charCodeAt(0)]&&(this.camera.y+=this.modifier,this.historyRefresh=!0),this.model.pitch=2047&this.model.pitch,this.model.yaw=2047&this.model.yaw,this.model.roll=2047&this.model.roll}}(new B).run().then((()=>{}))})(); \ No newline at end of file +(()=>{"use strict";class t{static pixels=new Int32Array;static width=0;static height=0;static top=0;static bottom=0;static left=0;static right=0;static boundX=0;static centerX=0;static centerY=0;static bind=(t,e,i)=>{this.pixels=t,this.width=e,this.height=i,this.setBounds(0,0,e,i)};static resetBounds=()=>{this.left=0,this.top=0,this.right=this.width,this.bottom=this.height,this.boundX=this.right-1,this.centerX=this.right/2};static setBounds=(t,e,i,s)=>{t<0&&(t=0),e<0&&(e=0),i>this.width&&(i=this.width),s>this.height&&(s=this.height),this.top=e,this.bottom=s,this.left=t,this.right=i,this.boundX=this.right-1,this.centerX=this.right/2,this.centerY=this.bottom/2};static clear=()=>{this.pixels.fill(0)};static drawRect=(t,e,i,s,r)=>{this.drawHorizontalLine(t,e,r,i),this.drawHorizontalLine(t,e+s-1,r,i),this.drawVerticalLine(t,e,r,s),this.drawVerticalLine(t+i-1,e,r,s)};static drawHorizontalLine=(t,e,i,s)=>{if(e=this.bottom)return;tthis.right&&(s=this.right-t);const r=t+e*this.width;for(let t=0;t{if(t=this.right)return;ethis.bottom&&(s=this.bottom-e);const r=t+e*this.width;for(let t=0;t{const a=Math.abs(i-t),n=Math.abs(s-e),o=t=this.left&&t=this.top&&e-n&&(l-=n,t+=o),i{const a=this.pixels;let n=t,o=e,h=t+i,l=e+s;nthis.right&&(h=this.right),l>this.bottom&&(l=this.bottom);const c=this.width;for(let t=o;t{this.pixels.fill(0)};bind=()=>{t.bind(this.pixels,this.width,this.height)};draw=(t,e)=>{this.#t(),this.ctx.putImageData(this.image,t,e)};#t=()=>{const t=this.image.data;for(let e=0;e>16&255,t[s+1]=i>>8&255,t[s+2]=i>>0&255,t[s+3]=255}}}class i{static crctable=new Int32Array(256);static CRC32_POLYNOMIAL=3988292384;static bitmask=new Uint32Array(33);static{for(let t=0;t<32;t++)i.bitmask[t]=(1<>>1^i.CRC32_POLYNOMIAL:e>>>=1;i.crctable[t]=e}}data;pos;bitPos=0;constructor(t){if(!t)throw new Error("Input src packet array was null!");this.data=t,this.pos=0}static alloc=t=>new i(0===t?new Uint8Array(100):1===t?new Uint8Array(5e3):new Uint8Array(3e4));get g1(){return this.data[this.pos++]}get g1b(){return this.data[this.pos++]<<24>>24}get g2(){return(this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g2b(){return this.data[this.pos++]<<8|this.data[this.pos++]}get g3(){return(this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4(){return(this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4s(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]}get g8(){return BigInt(this.g4)<<32n|BigInt(this.g4)}get gsmart(){return this.data[this.pos]<128?this.g1:this.g2-32768}get gsmarts(){return this.data[this.pos]<128?this.g1-64:this.g2-49152}get gjstr(){let t="";for(;10!=this.data[this.pos]&&this.posthis.data.subarray(t,t+e);p1=t=>{this.data[this.pos++]=t};p2=t=>{this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip2=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8};p3=t=>{this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};p4=t=>{this.data[this.pos++]=t>>>24,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip4=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>24};p8=t=>{this.p4(Number(t>>32n)),this.p4(Number(0xffffffffn&t))};pjstr=t=>{for(let e=0;e{for(let s=i;s{this.data[this.pos-t-1]=t};bits=()=>{this.bitPos=8*this.pos};bytes=()=>{this.pos=(this.bitPos+7)/8>>>0};gBit=t=>{let e=this.bitPos>>>3,s=8-(7&this.bitPos),r=0;for(this.bitPos+=t;t>s;s=8)r+=(this.data[e++]&i.bitmask[s])<>>s-t&i.bitmask[t],r}}class s{pixels;width;height;cropX;cropY;cropW;cropH;palette=new Uint32Array(0);constructor(t,e){this.pixels=new Uint8Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromArchive=(t,e,r=0)=>{const a=new i(t?.read(e+".dat")),n=new i(t?.read("index.dat"));n.pos=a.g2;const o=n.g2,h=n.g2,l=n.g1,c=new Uint32Array(l);for(let t=0;t{e|=0,i|=0;let a=(e+=this.cropX)+(i+=this.cropY)*t.width,n=0,o=this.height,h=this.width;-1!==s&&(h=s),-1!==r&&(o=r);let l=t.width-h,c=0;if(it.bottom&&(o-=i+o-t.bottom),et.right){const i=e+h-t.right;h-=i,c+=i,l+=i}h>0&&o>0&&this.copyImage(h,o,this.pixels,n,c,t.pixels,a,l)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;r+=t,r<0?r=0:r>255&&(r=255);let a=this.palette[s]>>8&255;a+=e,a<0?a=0:a>255&&(a=255);let n=255&this.palette[s];n+=i,n<0?n=0:n>255&&(n=255),this.palette[s]=(r<<16)+(a<<8)+n}};copyImage=(t,e,i,s,r,a,n,o)=>{for(let h=0;h{this.lineOffset=new Int32Array(t.height);for(let e=0;e{this.lineOffset=new Int32Array(e);for(let i=0;i{this.textureCount=0;for(let e=0;e<50;e++)try{this.textures[e]=s.fromArchive(t,e.toString()),this.textureCount++}catch(t){}};static setBrightness=t=>{t+=.3*Math.random()-.15;let e=0;for(let i=0;i<512;i++){const s=i/8/64+.0078125,r=(7&i)/8+.0625;for(let i=0;i<128;i++){const a=i/128;let n=a,o=a,h=a;if(r){let t;t=a<.5?a*(1+r):a+r-a*r;const e=2*a-t;let i=s+.3333333333333333;i>1&&i--;let l=s-.3333333333333333;l<0&&l++,n=6*i<1?e+6*(t-e)*i:2*i<1?t:3*i<2?e+6*(.6666666666666666-i)*(t-e):e,o=6*s<1?e+6*(t-e)*s:2*s<1?t:3*s<2?e+6*(.6666666666666666-s)*(t-e):e,h=6*l<1?e+6*(t-e)*l:2*l<1?t:3*l<2?e+6*(.6666666666666666-l)*(t-e):e}let l=Math.trunc(256*n)<<16|Math.trunc(256*o)<<8|Math.trunc(256*h);l=this.setGamma(l,t),0===l&&(l=1),this.palette[e++]=l}}};static setGamma=(t,e)=>{let i=(t>>16)/256,s=(t>>8&255)/256,r=(255&t)/256;return i=Math.pow(i,e),s=Math.pow(s,e),r=Math.pow(r,e),Math.trunc(256*i)<<16|Math.trunc(256*s)<<8|Math.trunc(256*r)};static initPool=t=>{null==this.texelPool&&(this.poolSize=t,this.texelPool=[],this.activeTexels=[])};static fillGouraudTriangle=(e,i,s,r,a,n,o,h,l)=>{let c=0,f=0,d=0,u=0,p=0,g=0;if(a!=r&&(c=(i-e<<16)/(a-r),u=(h-o<<15)/(a-r)),n!=a&&(f=(s-i<<16)/(n-a),p=(l-h<<15)/(n-a)),n!=r&&(d=(e-s<<16)/(r-n),g=(o-l<<15)/(r-n)),r<=a&&r<=n){if(r>=t.bottom)return;if(a>t.bottom&&(a=t.bottom),n>t.bottom&&(n=t.bottom),af){for(n-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=t.width)this.drawGouraudScanline(t.pixels,r,s>>16,e>>16,l>>7,o>>7),s+=d,e+=c,l+=g,o+=u;for(;--n>=0;)this.drawGouraudScanline(t.pixels,r,s>>16,i>>16,l>>7,h>>7),s+=d,i+=f,l+=g,h+=p,r+=t.width;return}for(n-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=t.width)this.drawGouraudScanline(t.pixels,r,e>>16,s>>16,o>>7,l>>7),s+=d,e+=c,l+=g,o+=u;for(;--n>=0;)this.drawGouraudScanline(t.pixels,r,i>>16,s>>16,h>>7,l>>7),s+=d,i+=f,l+=g,h+=p,r+=t.width;return}if(i=e<<=16,h=o<<=15,r<0&&(i-=d*r,e-=c*r,h-=g*r,o-=u*r,r=0),s<<=16,l<<=15,n<0&&(s-=f*n,l-=p*n,n=0),r!=n&&dc){for(a-=n,n-=r,r=this.lineOffset[r];--n>=0;r+=t.width)this.drawGouraudScanline(t.pixels,r,i>>16,e>>16,h>>7,o>>7),i+=d,e+=c,h+=g,o+=u;for(;--a>=0;)this.drawGouraudScanline(t.pixels,r,s>>16,e>>16,l>>7,o>>7),s+=f,e+=c,l+=p,o+=u,r+=t.width;return}for(a-=n,n-=r,r=this.lineOffset[r];--n>=0;r+=t.width)this.drawGouraudScanline(t.pixels,r,e>>16,i>>16,o>>7,h>>7),i+=d,e+=c,h+=g,o+=u;for(;--a>=0;)this.drawGouraudScanline(t.pixels,r,e>>16,s>>16,o>>7,l>>7),s+=f,e+=c,l+=p,o+=u,r+=t.width}else if(a<=n){if(a>=t.bottom)return;if(n>t.bottom&&(n=t.bottom),r>t.bottom&&(r=t.bottom),nd){for(r-=n,n-=a,a=this.lineOffset[a];--n>=0;a+=t.width)this.drawGouraudScanline(t.pixels,a,e>>16,i>>16,o>>7,h>>7),e+=c,i+=f,o+=u,h+=p;for(;--r>=0;)this.drawGouraudScanline(t.pixels,a,e>>16,s>>16,o>>7,l>>7),e+=c,s+=d,o+=u,l+=g,a+=t.width;return}for(r-=n,n-=a,a=this.lineOffset[a];--n>=0;a+=t.width)this.drawGouraudScanline(t.pixels,a,i>>16,e>>16,h>>7,o>>7),e+=c,i+=f,o+=u,h+=p;for(;--r>=0;)this.drawGouraudScanline(t.pixels,a,s>>16,e>>16,l>>7,o>>7),e+=c,s+=d,o+=u,l+=g,a+=t.width;return}if(s=i<<=16,l=h<<=15,a<0&&(s-=c*a,i-=f*a,l-=u*a,h-=p*a,a=0),e<<=16,o<<=15,r<0&&(e-=d*r,o-=g*r,r=0),c=0;a+=t.width)this.drawGouraudScanline(t.pixels,a,s>>16,i>>16,l>>7,h>>7),s+=c,i+=f,l+=u,h+=p;for(;--n>=0;)this.drawGouraudScanline(t.pixels,a,e>>16,i>>16,o>>7,h>>7),e+=d,i+=f,o+=g,h+=p,a+=t.width;return}for(n-=r,r-=a,a=this.lineOffset[a];--r>=0;a+=t.width)this.drawGouraudScanline(t.pixels,a,i>>16,s>>16,h>>7,l>>7),s+=c,i+=f,l+=u,h+=p;for(;--n>=0;)this.drawGouraudScanline(t.pixels,a,i>>16,e>>16,h>>7,o>>7),e+=d,i+=f,o+=g,h+=p,a+=t.width}else if(!(n>=t.bottom))if(r>t.bottom&&(r=t.bottom),a>t.bottom&&(a=t.bottom),r=0;n+=t.width)this.drawGouraudScanline(t.pixels,n,i>>16,s>>16,h>>7,l>>7),i+=f,s+=d,h+=p,l+=g;for(;--a>=0;)this.drawGouraudScanline(t.pixels,n,i>>16,e>>16,h>>7,o>>7),i+=f,e+=c,h+=p,o+=u,n+=t.width;return}for(a-=r,r-=n,n=this.lineOffset[n];--r>=0;n+=t.width)this.drawGouraudScanline(t.pixels,n,s>>16,i>>16,l>>7,h>>7),i+=f,s+=d,h+=p,l+=g;for(;--a>=0;)this.drawGouraudScanline(t.pixels,n,e>>16,i>>16,o>>7,h>>7),i+=f,e+=c,h+=p,o+=u,n+=t.width}else if(e=s<<=16,o=l<<=15,n<0&&(e-=f*n,s-=d*n,o-=p*n,l-=g*n,n=0),i<<=16,h<<=15,a<0&&(i-=c*a,h-=u*a,a=0),f=0;n+=t.width)this.drawGouraudScanline(t.pixels,n,e>>16,s>>16,o>>7,l>>7),e+=f,s+=d,o+=p,l+=g;for(;--r>=0;)this.drawGouraudScanline(t.pixels,n,i>>16,s>>16,h>>7,l>>7),i+=c,s+=d,h+=u,l+=g,n+=t.width}else{for(r-=a,a-=n,n=this.lineOffset[n];--a>=0;n+=t.width)this.drawGouraudScanline(t.pixels,n,s>>16,e>>16,l>>7,o>>7),e+=f,s+=d,o+=p,l+=g;for(;--r>=0;)this.drawGouraudScanline(t.pixels,n,s>>16,i>>16,l>>7,h>>7),i+=c,s+=d,h+=u,l+=g,n+=t.width}};static drawGouraudScanline=(e,i,s,r,a,n)=>{let o=0,h=0;if(this.jagged){let l=0;if(this.clipX){if(l=r-s>3?(n-a)/(r-s):0,r>t.right&&(r=t.right),s<0&&(a-=s*l,s=0),s>=r)return;i+=s,h=r-s>>2,l<<=2}else{if(s>=r)return;i+=s,h=r-s>>2,l=h>0?(n-a)*this.reciprocal15[h]>>15:0}if(0==this.alpha){for(;--h>=0;)o=this.palette[a>>8],a+=l,e[i++]=o,e[i++]=o,e[i++]=o,e[i++]=o;if(h=r-s&3,h>0){o=this.palette[a>>8];do{e[i++]=o}while(--h>0);return}}else{const t=this.alpha,n=256-this.alpha;for(;--h>=0;)o=this.palette[a>>8],a+=l,o=((16711935&o)*n>>8&16711935)+((65280&o)*n>>8&65280),e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280),e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280),e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280),e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280);if(h=r-s&3,h>0){o=this.palette[a>>8],o=((16711935&o)*n>>8&16711935)+((65280&o)*n>>8&65280);do{e[i++]=o+((16711935&e[i])*t>>8&16711935)+((65280&e[i])*t>>8&65280)}while(--h>0)}}return}if(s>=r)return;const l=(n-a)/(r-s);if(this.clipX&&(r>t.right&&(r=t.right),s<0&&(a-=s*l,s=0),s>=r))return;if(i+=s,h=r-s,0==this.alpha){do{e[i++]=this.palette[a>>8],a+=l}while(--h>0);return}const c=this.alpha,f=256-this.alpha;do{o=this.palette[a>>8],a+=l,o=((16711935&o)*f>>8&16711935)+((65280&o)*f>>8&65280),e[i++]=o+((16711935&e[i])*c>>8&16711935)+((65280&e[i])*c>>8&65280)}while(--h>0)};static fillTriangle=()=>{};static fillTexturedTriangle=()=>{}}const a=[0,79764919,159529838,222504665,319059676,398814059,445009330,507990021,638119352,583659535,797628118,726387553,890018660,835552979,1015980042,944750013,1276238704,1221641927,1167319070,1095957929,1595256236,1540665371,1452775106,1381403509,1780037320,1859660671,1671105958,1733955601,2031960084,2111593891,1889500026,1952343757,2552477408,2632100695,2443283854,2506133561,2334638140,2414271883,2191915858,2254759653,3190512472,3135915759,3081330742,3009969537,2905550212,2850959411,2762807018,2691435357,3560074640,3505614887,3719321342,3648080713,3342211916,3287746299,3467911202,3396681109,4063920168,4143685023,4223187782,4286162673,3779000052,3858754371,3904687514,3967668269,881225847,809987520,1023691545,969234094,662832811,591600412,771767749,717299826,311336399,374308984,453813921,533576470,25881363,88864420,134795389,214552010,2023205639,2086057648,1897238633,1976864222,1804852699,1867694188,1645340341,1724971778,1587496639,1516133128,1461550545,1406951526,1302016099,1230646740,1142491917,1087903418,2896545431,2825181984,2770861561,2716262478,3215044683,3143675388,3055782693,3001194130,2326604591,2389456536,2200899649,2280525302,2578013683,2640855108,2418763421,2498394922,3769900519,3832873040,3912640137,3992402750,4088425275,4151408268,4197601365,4277358050,3334271071,3263032808,3476998961,3422541446,3585640067,3514407732,3694837229,3640369242,1762451694,1842216281,1619975040,1682949687,2047383090,2127137669,1938468188,2001449195,1325665622,1271206113,1183200824,1111960463,1543535498,1489069629,1434599652,1363369299,622672798,568075817,748617968,677256519,907627842,853037301,1067152940,995781531,51762726,131386257,177728840,240578815,269590778,349224269,429104020,491947555,4046411278,4126034873,4172115296,4234965207,3794477266,3874110821,3953728444,4016571915,3609705398,3555108353,3735388376,3664026991,3290680682,3236090077,3449943556,3378572211,3174993278,3120533705,3032266256,2961025959,2923101090,2868635157,2813903052,2742672763,2604032198,2683796849,2461293480,2524268063,2284983834,2364738477,2175806836,2238787779,1569362073,1498123566,1409854455,1355396672,1317987909,1246755826,1192025387,1137557660,2072149281,2135122070,1912620623,1992383480,1753615357,1816598090,1627664531,1707420964,295390185,358241886,404320391,483945776,43990325,106832002,186451547,266083308,932423249,861060070,1041341759,986742920,613929101,542559546,756411363,701822548,3316196985,3244833742,3425377559,3370778784,3601682597,3530312978,3744426955,3689838204,3819031489,3881883254,3928223919,4007849240,4037393693,4100235434,4180117107,4259748804,2310601993,2373574846,2151335527,2231098320,2596047829,2659030626,2470359227,2550115596,2947551409,2876312838,2788305887,2733848168,3165939309,3094707162,3040238851,2985771188],n=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215,33554431,67108863,134217727,268435455,536870911,1073741823,-2147483648];function o(t){const e=[];for(let i=0;it.bits-e.bits||t.code-e.code));let a=0,n=-1;const o=[];let h;for(let t=0;t=t.length)throw RangeError("Out of bound");const i=t.slice();t.sort(((t,e)=>t-e));const s={};for(let e=t.length-1;e>=0;e-=1)s[t[e]]=e;const r=[];for(let e=0;enew Promise((e=>setTimeout(e,t))),c=async t=>new Uint8Array(await(await fetch(t)).arrayBuffer()),f=(t,e=!0,i=!0)=>{if(e){const e=Uint8Array.from(["B".charCodeAt(0),"Z".charCodeAt(0),"h".charCodeAt(0),"1".charCodeAt(0)]);if(i){const i=t;(t=new Uint8Array(e.length+t.length)).set(i,e.length)}t.set(e,0)}return function(t,e=!1){let i=0,s=0,r=0;const l=e=>{if(e>=32){const t=e>>1;return l(t)*(1<>r-e&a;return r-=e,s&=~(a<=49&&c<=57))throw new Error("Invalid blocksize");c-=48;let f=new Uint8Array(1.5*t.length),d=0,u=-1;for(;;){const c=l(48),p=0|l(32);if(54156738319193!==c){if(25779555029136===c){l(7&r);break}throw new Error("Invalid bz2 blocktype")}{if(l(1))throw new Error("do not support randomised");const c=l(24),g=[],m=l(16);for(let t=32768;t>0;t>>=1){if(!(m&t)){for(let t=0;t<16;t+=1)g.push(!1);continue}const e=l(16);for(let t=32768;t>0;t>>=1)g.push(!!(e&t))}const w=l(3);if(w<2||w>6)throw new Error("Invalid number of huffman groups");const x=l(15),y=[],v=Array.from({length:w},((t,e)=>e));for(let t=0;t=w)throw new Error("MTF table out of range");const e=v[t];for(let e=t;e>0;v[e]=v[--e]);y.push(e),v[0]=e}const C=g.reduce(((t,e)=>t+e),0)+2,b=[];for(let t=0;t20)throw new Error("Huffman group length outside range");for(;l(1);)t-=2*l(1)-1;e.push(t)}b.push(o(e))}const A=[];for(let t=0;t>r-e],P)){s&=n[r-=e],P=P.code;break}if(P>=0&&P<=1)0===Y&&(O=1),Y+=O<0;Y-=1)X.push(t)}if(P===C-1)break;{const t=A[P-1];for(let t=P-1;t>0;A[t]=A[--t]);A[0]=t,X.push(t)}}}const F=h(X,c);let T=0;for(;T=f.length){const t=f;f=new Uint8Array(2*t.length),f.set(t)}for(let s=0;s>24^t)]),f[d]=t,d+=1}if(e){const t=-1^u;if(t!==p)throw new Error(`CRC mismatch: ${t} !== ${p}`);u=-1}}}return f.subarray(0,d)}(t)};class d{static getParameter(t){return new URLSearchParams(window.location.search).get(t)??""}static setParameter(t,e){const i=new URL(window.location.toString());i.searchParams.set(t,e),window.history.pushState(null,"",i.toString())}canvas;ctx;drawArea=null;state=0;deltime=20;mindel=1;otim=[];fps=0;fpos=0;frameTime=[];redrawScreen=!0;resizeToFit=!1;idleCycles=0;mouseButton=0;mouseX=0;mouseY=0;mouseClickButton=0;mouseClickX=0;mouseClickY=0;actionKey=[];keyQueue=[];keyQueueReadPos=0;keyQueueWritePos=0;constructor(t=!1){const e=document.getElementById("canvas");if(!e)throw new Error("Canvas not found!!!!!!!!");const i=e.getContext("2d");if(!i)throw new Error("Canvas 2d not found!!!!!!!!");this.canvas=e,this.ctx=i,this.resizeToFit=t,this.resizeToFit?this.resize(window.innerWidth,window.innerHeight):this.resize(e.width,e.height)}get width(){return this.canvas.width}get height(){return this.canvas.height}resize(t,i){const s=this.canvas;s.width=t,s.height=i,this.drawArea=new e(s,t,i),r.init2D()}async run(){window.addEventListener("resize",(()=>{this.resizeToFit&&this.resize(window.innerWidth,window.innerHeight)}),!1),window.addEventListener("keydown",this.keyDown),window.addEventListener("keyup",this.keyUp),window.addEventListener("mousedown",this.mousePressed),this.canvas.oncontextmenu=t=>{t.preventDefault()},await this.showProgress(0,"Loading..."),await this.load();for(let t=0;t<10;t++)this.otim[t]=Date.now();let t,e=0,i=256,s=1,r=0;for(;this.state>=0;){if(this.state>0&&(this.state--,0===this.state))return void this.shutdown();const a=i,n=s;i=300,s=1,t=Date.now();const o=this.otim[e];if(0===o?(i=a,s=n):t>o&&(i=Math.trunc(2560*this.deltime/(t-o))),i<25?i=25:i>256&&(i=256,s=Math.trunc(this.deltime-(t-o)/10)),this.otim[e]=t,e=(e+1)%10,s>1)for(let t=0;t<10;t++)0!==this.otim[t]&&(this.otim[t]+=s);for(s0&&(this.fps=Math.trunc(1e3*i/(256*this.deltime)));const h=performance.now();await this.draw(),this.frameTime[this.fpos]=(performance.now()-h)/1e3,this.fpos=(this.fpos+1)%this.frameTime.length}-1==this.state&&this.shutdown()}shutdown(){this.state=-2,this.unload()}setLoopRate(t){this.deltime=1e3/t}start(){this.state>=0&&(this.state=0)}stop(){this.state>=0&&(this.state=4e3/this.deltime)}destroy(){this.state=-1}async load(){}update(){}unload(){}async draw(){}refresh(){}async showProgress(t,e){const i=this.ctx,s=this.width,r=this.height;this.redrawScreen&&(i.fillStyle="black",i.clearRect(0,0,s,r),this.redrawScreen=!1);const a=r/2-18;i.fillStyle="rgb(140, 17, 17)",i.rect(s/2-152,a,304,34),i.fillRect(s/2-150,a+2,3*t,30),i.fillStyle="black",i.fillRect(s/2-150+3*t,a+2,300-3*t,30),i.font="bold 13px helvetica, sans-serif",i.textAlign="center",i.fillStyle="white",i.fillText(e,s/2,a+22),await l(5)}keyDown=t=>{this.idleCycles=0;const e=t.keyCode;let i=t.key.charCodeAt(0);83!==i&&(i<30&&(i=0),37==e?i=1:39==e?i=2:38==e?i=3:40==e?i=4:17==e?i=5:8==e||127==e?i=8:9==e?i=9:10==e?i=10:e>=112&&e<=123?i=e+1008-112:36==e?i=1e3:35==e?i=1001:33==e?i=1002:34==e&&(i=1003),i>0&&i<128&&(this.actionKey[i]=1),i>4&&(this.keyQueue[this.keyQueueWritePos]=i,this.keyQueueWritePos=this.keyQueueWritePos+1&127))};keyUp=t=>{this.idleCycles=0;let e=t.key.charCodeAt(0);"ArrowLeft"==t.key?e=1:"ArrowRight"==t.key?e=2:"ArrowUp"==t.key?e=3:"ArrowDown"==t.key&&(e=4),this.actionKey[e]=0};pollKey(){let t=-1;return this.keyQueueWritePos!=this.keyQueueReadPos&&(t=this.keyQueue[this.keyQueueReadPos],this.keyQueueReadPos=this.keyQueueReadPos+1&127),t}mousePressed=t=>{let e=t.x,i=t.y;const{top:s,left:r}=this.getInsets;e-=r,i-=s,this.idleCycles=0,this.mouseClickX=e,this.mouseClickY=i,2===t.buttons?(this.mouseClickButton=2,this.mouseButton=2):1===t.buttons&&(this.mouseClickButton=1,this.mouseButton=1)};get getInsets(){const t=this.canvas.getBoundingClientRect(),e=window.getComputedStyle(this.canvas),i=parseFloat(e.paddingLeft||"0"),s=parseFloat(e.paddingTop||"0"),r=parseFloat(e.borderLeftWidth||"0"),a=parseFloat(e.borderTopWidth||"0"),n=t.left+r+i;return{top:t.top+a+s,left:n}}get ms(){const t=this.frameTime.length;let e=0;for(let i=0;i{for(;;){const e=t.g1;if(0===e)break;this.decode(e,t)}}}class p{static instances=[];static unpack=t=>{const e=new i(t.read("base_head.dat")),s=new i(t.read("base_type.dat")),r=new i(t.read("base_label.dat")),a=e.g2;e.pos+=2;for(let t=0;t{const e=new i(t.read("frame_head.dat")),s=new i(t.read("frame_tran1.dat")),r=new i(t.read("frame_tran2.dat")),a=new i(t.read("frame_del.dat")),n=e.g2;e.pos+=2;const o=new Uint32Array(500),h=new Uint32Array(500),l=new Uint32Array(500),c=new Uint32Array(500);for(let t=0;t0){if(0!=f.types[t])for(let e=t-1;e>u;e--)if(0==f.types[e]){o[m]=e,h[m]=0,l[m]=0,c[m]=0,m++;break}o[m]=t;let i=0;3==f.types[o[m]]&&(i=128),h[m]=0==(1&e)?i:r.gsmart,l[m]=0==(2&e)?i:r.gsmart,c[m]=0==(4&e)?i:r.gsmart,u=t,m++}}i.length=m,i.bases=new Uint32Array(m),i.x=new Uint32Array(m),i.y=new Uint32Array(m),i.z=new Uint32Array(m);for(let t=0;t{const e=new i(t.read("seq.dat"));this.count=e.g2;for(let t=0;tm.instances[t];frameCount=0;frames=null;iframes=null;delay=null;replayoff=-1;labelGroups=null;stretches=!1;priority=5;mainhand=-1;offhand=-1;replaycount=99;duration=0;decode=(t,e)=>{if(1===t){this.frameCount=e.g1,this.frames=new Uint16Array(this.frameCount),this.iframes=new Uint16Array(this.frameCount),this.delay=new Uint16Array(this.frameCount);for(let t=0;t{const e=new i(t.read("loc.dat"));this.count=e.g2;for(let t=0;t0&&10==i.shapes[0]?1:0,i.ops.length>0&&(i.active=1))}};static get=t=>w.instances[t];models=null;shapes=null;name=null;desc=null;recol_s=null;recol_d=null;width=1;length=1;blockwalk=!0;blockrange=!0;active=-1;hillskew=!1;sharelight=!1;occlude=!1;anim=-1;hasalpha=!1;walloff=16;ambient=0;contrast=0;ops=[];mapfunction=-1;mapscene=-1;mirror=!1;shadow=!0;resizex=128;resizey=128;resizez=128;forceapproach=0;xoff=0;yoff=0;zoff=0;forcedecor=!1;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t),this.shapes=new Uint8Array(t);for(let i=0;i=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const e=new i(t.read("flo.dat"));this.count=e.g2;for(let t=0;tx.instances[t];rgb=0;texture=-1;opcode3=!1;occludes=!0;name=null;decode=(t,e)=>{1===t?this.rgb=e.g3:2===t?this.texture=e.g1:3===t?this.opcode3=!0:5===t?this.occludes=!1:6===t?this.name=e.gjstr:console.log("Error unrecognised config code: ",t)}}class y{pixels;width;height;cropX;cropY;cropW;cropH;constructor(t,e){this.pixels=new Int32Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromJpeg=async(t,e)=>{const i=t.read(e+".dat"),s=await(async t=>{if(!t)throw new Error("Input jpeg data was null!");255!==t[0]&&(t[0]=255);const e=document.createElement("img");e.src="data:image/jpeg;base64,"+btoa(String.fromCharCode(...t)),await new Promise((t=>e.onload=t));const i=document.createElement("canvas");i.width=e.naturalWidth,i.height=e.naturalHeight;const s=i.getContext("2d");if(!s)throw new Error("Canvas 2d not found!!!!!!!!");return s.drawImage(e,0,0),s.getImageData(0,0,i.width,i.height)})(i),r=new y(s.width,s.height),a=r.pixels,n=s.data;for(let t=0;t{const r=new i(t.read(e+".dat")),a=new i(t.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,h=a.g1,l=new Uint32Array(h),c=h-1;for(let t=0;t{e|=0,i|=0;let s=(e+=this.cropX)+(i+=this.cropY)*t.width,r=0,a=this.height,n=this.width,o=t.width-n,h=0;if(it.bottom&&(a-=i+a-t.bottom),et.right){const i=e+n-t.right;n-=i,h+=i,o+=i}n>0&&a>0&&this.copyImageDraw(n,a,this.pixels,r,h,t.pixels,s,o)};drawAlpha=(e,i,s)=>{i|=0,s|=0;let r=(i+=this.cropX)+(s+=this.cropY)*t.width,a=0,n=this.height,o=this.width,h=t.width-o,l=0;if(st.bottom&&(n-=s+n-t.bottom),it.right){const e=i+o-t.right;o-=e,l+=e,h+=e}o>0&&n>0&&this.copyPixelsAlpha(o,n,this.pixels,a,l,t.pixels,r,h,e)};blitOpaque=(e,i)=>{e|=0,i|=0;let s=(e+=this.cropX)+(i+=this.cropY)*t.width,r=0,a=this.height,n=this.width,o=t.width-n,h=0;if(it.bottom&&(a-=i+a-t.bottom),et.right){const i=e+n-t.right;n-=i,h+=i,o+=i}n>0&&a>0&&this.copyImageBlitOpaque(n,a,this.pixels,r,h,t.pixels,s,o)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;a+=t,a<1?a=1:a>255&&(a=255);let n=r>>8&255;n+=e,n<1?n=1:n>255&&(n=255);let o=255&r;o+=i,o<1?o=1:o>255&&(o=255),this.pixels[s]=(a<<16)+(n<<8)+o}}};copyImageBlitOpaque=(t,e,i,s,r,a,n,o)=>{const h=-(t>>2);t=-(3&t);for(let l=-e;l<0;l++){for(let t=h;t<0;t++)a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++];for(let e=t;e<0;e++)a[n++]=i[s++];n+=o,s+=r}};copyPixelsAlpha=(t,e,i,s,r,a,n,o,h)=>{const l=256-h;for(let c=-e;c<0;c++){for(let e=-t;e<0;e++){const t=i[s++];if(0==t)n++;else{const e=a[n];a[n++]=((16711935&t)*h+(16711935&e)*l&4278255360)+((65280&t)*h+(65280&e)*l&16711680)>>8}}n+=o,s+=r}};copyImageDraw=(t,e,i,s,r,a,n,o)=>{const h=-(t>>2);t=-(3&t);for(let l=-e;l<0;l++){for(let t=h;t<0;t++){let t=i[s++];0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t}for(let e=t;e<0;e++){const t=i[s++];0===t?n++:a[n++]=t}n+=o,s+=r}}}class v extends u{static count=0;static instances=[];static unpack=(t,e)=>{const s=new i(t.read("obj.dat"));this.count=s.g2;for(let t=0;tv.instances[t];static getIcon=(t,e)=>new y(32,32);model=0;name=null;desc=null;recol_s=null;recol_d=null;zoom2d=2e3;xan2d=0;yan2d=0;zan2d=0;xof2d=0;yof2d=0;code9=!1;code10=-1;stackable=!1;cost=1;members=!1;ops=[];iops=[];manwear=-1;manwear2=-1;manwearOffsetY=0;womanwear=-1;womanwear2=-1;womanwearOffsetY=0;manwear3=-1;womanwear3=-1;manhead=-1;manhead2=-1;womanhead=-1;womanhead2=-1;countobj=null;countco=null;certlink=-1;certtemplate=-1;decode=(t,e)=>{if(1===t)this.model=e.g2;else if(2===t)this.name=e.gjstr;else if(3===t)this.desc=e.gjstr;else if(4===t)this.zoom2d=e.g2;else if(5===t)this.xan2d=e.g2;else if(6===t)this.yan2d=e.g2;else if(7===t)this.xof2d=e.g2b,this.xof2d>32767&&(this.xof2d-=65536);else if(8===t)this.yof2d=e.g2b,this.yof2d>32767&&(this.yof2d-=65536);else if(9===t)this.code9=!0;else if(10===t)this.code10=e.g2;else if(11===t)this.stackable=!0;else if(12===t)this.cost=e.g4s;else if(16===t)this.members=!0;else if(23===t)this.manwear=e.g2,this.manwearOffsetY=e.g1b;else if(24===t)this.manwear2=e.g2;else if(25===t)this.womanwear=e.g2,this.womanwearOffsetY=e.g1b;else if(26===t)this.womanwear2=e.g2;else if(t>=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(t>=35&&t<40)this.iops[t-35]=e.gjstr;else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i=100&&t<110))throw new Error(`Unrecognized obj config code: ${t}`);this.countobj&&this.countco||(this.countobj=new Uint16Array(10),this.countco=new Uint16Array(10)),this.countobj[t-100]=e.g2,this.countco[t-100]=e.g2}};toCertificate=()=>{const t=v.get(this.certtemplate);this.model=t.model,this.zoom2d=t.zoom2d,this.xan2d=t.xan2d,this.yan2d=t.yan2d,this.zan2d=t.zan2d,this.xof2d=t.xof2d,this.yof2d=t.yof2d,this.recol_s=t.recol_s,this.recol_d=t.recol_d;const e=v.get(this.certlink);this.name=e.name,this.members=e.members,this.cost=e.cost;let i="a";const s=(e.name||"").toLowerCase().charAt(0);"a"!==s&&"e"!==s&&"i"!==s&&"o"!==s&&"u"!==s||(i="an"),this.desc=`Swap this note at any bank for ${i} ${e.name}.`,this.stackable=!0}}class C extends u{static count=0;static instances=[];static unpack=t=>{const e=new i(t.read("npc.dat"));this.count=e.g2;for(let t=0;tC.instances[t];name=null;desc=null;size=1;models=null;heads=null;hasanim=!1;readyanim=-1;walkanim=-1;walkanim_b=-1;walkanim_r=-1;walkanim_l=-1;hasalpha=!1;recol_s=null;recol_d=null;ops=[];code90=-1;code91=-1;code92=-1;visonmap=!0;vislevel=-1;resizeh=128;resizev=128;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=30&&t<40)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const e=new i(t.read("idk.dat"));this.count=e.g2;for(let t=0;tb.instances[t];type=-1;models=null;heads=new Uint16Array(5).fill(-1);recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);disable=!1;decode=(t,e)=>{if(1===t)this.type=e.g1;else if(2===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=40&&t<50)this.recol_s[t-40]=e.g2;else if(t>=50&&t<60)this.recol_d[t-50]=e.g2;else{if(!(t>=60&&t<70))throw new Error(`Unrecognized idk config code: ${t}`);this.heads[t-60]=e.g2}}}class A extends u{static count=0;static instances=[];static unpack=t=>{const e=new i(t.read("spotanim.dat"));this.count=e.g2;for(let t=0;tA.instances[t];model=0;anim=-1;seq=null;disposeAlpha=!1;recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);resizeh=128;resizev=128;orientation=0;ambient=0;contrast=0;decode=(t,e)=>{if(1==t)this.model=e.g2;else if(2==t)this.anim=e.g2,null!=m.instances&&(this.seq=m.instances[this.anim]);else if(3==t)this.disposeAlpha=!0;else if(4==t)this.resizeh=e.g2;else if(5==t)this.resizev=e.g2;else if(6==t)this.orientation=e.g2;else if(7==t)this.ambient=e.g1;else if(8==t)this.contrast=e.g1;else if(t>=40&&t<50)this.recol_s[t-40]=e.g2;else{if(!(t>=50&&t<60))throw new Error(`Unrecognized spotanim config code: ${t}`);this.recol_d[t-50]=e.g2}}}class S extends u{static count=0;static instances=[];static code3=[];static code3Count=0;static unpack=t=>{const e=new i(t.read("varp.dat"));this.count=e.g2;for(let t=0;tS.instances[t];code10=null;code1=0;code2=0;hasCode3=!1;code4=!0;clientcode=0;code7=0;code6=!1;code8=!1;decode(t,e){if(1==t)this.code1=e.g1;else if(2==t)this.code2=e.g1;else if(3==t)this.hasCode3=!0,S.code3[S.code3Count++]=this.index;else if(4==t)this.code4=!1;else if(5==t)this.clientcode=e.g2;else if(6==t)this.code6=!0;else if(7==t)this.code7=e.g4;else if(8==t)this.code8=!0;else{if(10!=t)throw new Error(`Error unrecognised config code: ${t}`);this.code10=e.gjstr}}}class P{vertexCount=0;faceCount=0;texturedFaceCount=0;vertexFlagsOffset=-1;vertexXOffset=-1;vertexYOffset=-1;vertexZOffset=-1;vertexLabelsOffset=-1;faceVerticesOffset=-1;faceOrientationsOffset=-1;faceColorsOffset=-1;faceInfosOffset=-1;facePrioritiesOffset=0;faceAlphasOffset=-1;faceLabelsOffset=-1;faceTextureAxisOffset=-1}class I{x=0;y=0;z=0;w=0}class k{static metadata=null;static head=null;static face1=null;static face2=null;static face3=null;static face4=null;static face5=null;static point1=null;static point2=null;static point3=null;static point4=null;static point5=null;static vertex1=null;static vertex2=null;static axis=null;static faceClippedX=new Array(4096);static faceNearClipped=new Array(4096);static vertexScreenX=new Int32Array(4096);static vertexScreenY=new Int32Array(4096);static vertexScreenZ=new Int32Array(4096);static vertexViewSpaceX=new Int32Array(4096);static vertexViewSpaceY=new Int32Array(4096);static vertexViewSpaceZ=new Int32Array(4096);static tmpDepthFaceCount=new Int32Array(1500);static tmpDepthFaces=new Array(1500).fill(null).map((()=>new Int32Array(512)));static tmpPriorityFaceCount=new Int32Array(12);static tmpPriorityFaces=new Array(12).fill(null).map((()=>new Int32Array(2e3)));static tmpPriority10FaceDepth=new Int32Array(2e3);static tmpPriority11FaceDepth=new Int32Array(2e3);static tmpPriorityDepthSum=new Int32Array(12);static clippedX=new Int32Array(10);static clippedY=new Int32Array(10);static clippedColor=new Int32Array(10);static baseX=0;static baseY=0;static baseZ=0;static checkHover=!1;static mouseX=0;static mouseZ=0;static pickedCount=0;static pickedBitsets=new Int32Array(1e3);static unpack(t){try{k.head=new i(t.read("ob_head.dat")),k.face1=new i(t.read("ob_face1.dat")),k.face2=new i(t.read("ob_face2.dat")),k.face3=new i(t.read("ob_face3.dat")),k.face4=new i(t.read("ob_face4.dat")),k.face5=new i(t.read("ob_face5.dat")),k.point1=new i(t.read("ob_point1.dat")),k.point2=new i(t.read("ob_point2.dat")),k.point3=new i(t.read("ob_point3.dat")),k.point4=new i(t.read("ob_point4.dat")),k.point5=new i(t.read("ob_point5.dat")),k.vertex1=new i(t.read("ob_vertex1.dat")),k.vertex2=new i(t.read("ob_vertex2.dat")),k.axis=new i(t.read("ob_axis.dat")),k.head.pos=0,k.point1.pos=0,k.point2.pos=0,k.point3.pos=0,k.point4.pos=0,k.vertex1.pos=0,k.vertex2.pos=0;const e=k.head.g2;k.metadata=new Array(e+100);let s=0,r=0,a=0,n=0,o=0,h=0,l=0;for(let t=0;t127&&(e=127),127-e):((e=e*(127&t)>>7)<2?e=2:e>126&&(e=126),(65408&t)+e)}vertexCount=0;vertexX=null;vertexY=null;vertexZ=null;faceCount=0;faceVertexA=null;faceVertexB=null;faceVertexC=null;faceColorA=null;faceColorB=null;faceColorC=null;faceInfo=null;facePriority=null;faceAlpha=null;faceColor=null;priority=0;texturedFaceCount=0;texturedVertexA=null;texturedVertexB=null;texturedVertexC=null;minX=0;maxX=0;minZ=0;maxZ=0;radius=0;minY=0;maxY=0;maxDepth=0;minDepth=0;objRaise=0;vertexLabel=null;faceLabel=null;labelVertices=null;labelFaces=null;pickable=!1;vertexNormal=null;vertexNormalOriginal=null;constructor(t){if(null===k.head||null===k.face1||null===k.face2||null===k.face3||null===k.face4||null===k.face5||null===k.point1||null===k.point2||null===k.point3||null===k.point4||null===k.point5||null===k.vertex1||null===k.vertex2||null===k.axis)return;if(null===k.metadata)return;const e=k.metadata[t];if(void 0===e)return void console.log(`Error model:${t} not found!`);this.vertexCount=e.vertexCount,this.faceCount=e.faceCount,this.texturedFaceCount=e.texturedFaceCount,this.vertexX=new Int32Array(this.vertexCount),this.vertexY=new Int32Array(this.vertexCount),this.vertexZ=new Int32Array(this.vertexCount),this.faceVertexA=new Int32Array(this.faceCount),this.faceVertexB=new Int32Array(this.faceCount),this.faceVertexC=new Int32Array(this.faceCount),this.texturedVertexA=new Int32Array(this.texturedFaceCount),this.texturedVertexB=new Int32Array(this.texturedFaceCount),this.texturedVertexC=new Int32Array(this.texturedFaceCount),e.vertexLabelsOffset>=0&&(this.vertexLabel=new Int32Array(this.vertexCount)),e.faceInfosOffset>=0&&(this.faceInfo=new Int32Array(this.faceCount)),e.facePrioritiesOffset>=0?this.facePriority=new Int32Array(this.faceCount):this.priority=-e.facePrioritiesOffset-1,e.faceAlphasOffset>=0&&(this.faceAlpha=new Int32Array(this.faceCount)),e.faceLabelsOffset>=0&&(this.faceLabel=new Int32Array(this.faceCount)),this.faceColor=new Int32Array(this.faceCount),k.point1.pos=e.vertexFlagsOffset,k.point2.pos=e.vertexXOffset,k.point3.pos=e.vertexYOffset,k.point4.pos=e.vertexZOffset,k.point5.pos=e.vertexLabelsOffset;let i,s,r,a=0,n=0,o=0;for(let t=0;tthis.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)+.99),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsY(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.minY=0;for(let t=0;tthis.maxY&&(this.maxY=-e),e>this.minY&&(this.minY=e)}this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsAABB(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.radius=0,this.minY=0,this.minX=999999,this.maxX=-999999,this.maxZ=-99999,this.minZ=99999;for(let t=0;tthis.maxX&&(this.maxX=e),sthis.maxZ&&(this.maxZ=s),-i>this.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY))}}createLabelReferences(){}applyTransform(t){}rotateY90(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let t=0;t>16;this.vertexZ[t]=this.vertexY[t]*e+this.vertexZ[t]*i>>16,this.vertexY[t]=s}}translate(t,e,i){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let s=0;s>8;if(null!==this.faceColorA&&null!==this.faceColorB&&null!==this.faceColorC||(this.faceColorA=new Int32Array(this.faceCount),this.faceColorB=new Int32Array(this.faceCount),this.faceColorC=new Int32Array(this.faceCount)),null===this.vertexNormal){this.vertexNormal=new Array(this.vertexCount);for(let t=0;t8192||m>8192||w>8192||g<-8192||m<-8192||w<-8192;)g>>=1,m>>=1,w>>=1;let x=Math.sqrt(g*g+m*m+w*w);if(x<=0&&(x=1),g=256*g/x,m=256*m/x,w=256*w/x,null===this.faceInfo||0==(1&this.faceInfo[e])){let t=this.vertexNormal[a];t.x+=g,t.y+=m,t.z+=w,t.w++,t=this.vertexNormal[o],t.x+=g,t.y+=m,t.z+=w,t.w++,t=this.vertexNormal[h],t.x+=g,t.y+=m,t.z+=w,t.w++}else{const a=t+(i*g+s*m+r*w)/(n+n/2);this.faceColorA[e]=k.mulColorLightness(this.faceColor[e],a,this.faceInfo[e])}}if(a)this.applyLighting(t,e,i,s,r);else{this.vertexNormalOriginal=new Array(this.vertexCount);for(let t=0;t>16;for(let s=0;s>16,y=y*u-x*d>>16,x=w),0!==t&&(w=y*l-v*h>>16,v=y*h+v*l>>16,y=w),0!==e&&(w=v*c+x*f>>16,v=v*f-x*c>>16,x=w),x+=a,y+=n,v+=o,w=y*g-v*p>>16,v=y*p+v*g>>16,y=w,k.vertexScreenX[s]=r.centerX+(x<<9)/v,k.vertexScreenY[s]=r.centerY+(y<<9)/v,k.vertexScreenZ[s]=v-m,this.texturedFaceCount>0&&(k.vertexViewSpaceX[s]=x,k.vertexViewSpaceY[s]=y,k.vertexViewSpaceZ[s]=v)}this.draw2(!1,!1,0)}draw(t,e,i,s,r,a,n,o,h){}draw2(e,i,s){if(null===k.vertexScreenX||null===k.vertexScreenY||null===k.vertexScreenZ)return;if(null===k.vertexViewSpaceX||null===k.vertexViewSpaceY||null===k.vertexViewSpaceZ)return;if(null===k.faceNearClipped||null===k.faceClippedX)return;if(null===k.tmpDepthFaceCount||null===k.tmpDepthFaces||null===k.tmpPriorityFaces||null===k.tmpPriorityFaceCount||null===k.tmpPriorityDepthSum||null===k.tmpPriority10FaceDepth||null===k.tmpPriority11FaceDepth)return;if(null===this.faceVertexA||null===this.faceVertexB||null===this.faceVertexC)return;for(let t=0;tt.boundX||l>t.boundX||c>t.boundX;const u=Math.trunc((k.vertexScreenZ[a]+k.vertexScreenZ[n]+k.vertexScreenZ[o])/3+this.minDepth);k.tmpDepthFaces[u][k.tmpDepthFaceCount[u]++]=r}else{k.faceNearClipped[r]=!0;const t=Math.trunc((k.vertexScreenZ[a]+k.vertexScreenZ[n]+k.vertexScreenZ[o])/3+this.minDepth);k.tmpDepthFaces[t][k.tmpDepthFaceCount[t]++]=r}}if(null==this.facePriority){for(let t=this.maxDepth-1;t>=0;t--){const e=k.tmpDepthFaceCount[t];if(e<=0)continue;const i=k.tmpDepthFaces[t];for(let t=0;t=0;t--){const e=k.tmpDepthFaceCount[t];if(e>0){const i=k.tmpDepthFaces[t];for(let s=0;s0||k.tmpPriorityFaceCount[2]>0)&&(r=Math.trunc((k.tmpPriorityDepthSum[1]+k.tmpPriorityDepthSum[2])/(k.tmpPriorityFaceCount[1]+k.tmpPriorityFaceCount[2])));let a=0;(k.tmpPriorityFaceCount[3]>0||k.tmpPriorityFaceCount[4]>0)&&(a=Math.trunc((k.tmpPriorityDepthSum[3]+k.tmpPriorityDepthSum[4])/(k.tmpPriorityFaceCount[3]+k.tmpPriorityFaceCount[4])));let n=0;(k.tmpPriorityFaceCount[6]>0||k.tmpPriorityFaceCount[8]>0)&&(n=Math.trunc((k.tmpPriorityDepthSum[6]+k.tmpPriorityDepthSum[8])/(k.tmpPriorityFaceCount[6]+k.tmpPriorityFaceCount[8])));let o,h=0,l=k.tmpPriorityFaceCount[10],c=k.tmpPriorityFaces[10],f=k.tmpPriority10FaceDepth;h==l&&(h=0,l=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),o=hr;)this.drawFace(c[h++]),h==l&&c!=k.tmpPriorityFaces[11]&&(h=0,l=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),o=ha;)this.drawFace(c[h++]),h==l&&c!=k.tmpPriorityFaces[11]&&(h=0,l=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),o=hn;)this.drawFace(c[h++]),h==l&&c!=k.tmpPriorityFaces[11]&&(h=0,l=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),o=ha&&e>n&&e>o||t{const r=new i(t.read("data"));let a=-1;for(r.pos+=2;r.pos0){i.scriptComparator=new Uint8Array(n).fill(0),i.scriptOperand=new Uint16Array(n).fill(0);for(let t=0;t0){i.scripts=new Array(o).fill(null);for(let t=0;t0){const r=s.lastIndexOf(",");i.inventorySlotImage[t]=y.fromArchive(e,s,r)}}for(let t=0;t<5;t++)i.inventoryOptions[t]=r.gjstr,0===i.inventoryOptions[t]?.length&&(i.inventoryOptions[t]=null);i.spellAction=r.gjstr,i.spellName=r.gjstr,i.spellFlags=r.g2;break;case Y.TYPE_RECT:i.fill=1===r.g1,i.color=r.g4,i.activeColor=r.g4,i.hoverColor=r.g4;break;case Y.TYPE_TEXT:i.center=1===r.g1,i.font=s[r.g1],i.shadow=1===r.g1,i.text=r.gjstr,i.activeText=r.gjstr,i.color=r.g4,i.activeColor=r.g4,i.hoverColor=r.g4;break;case Y.TYPE_SPRITE:{const t=r.gjstr;if(t.length>0){const s=t.lastIndexOf(",");i.image=y.fromArchive(e,t.substring(0,s),parseInt(t.substring(s+1)))}const s=r.gjstr;if(s.length>0){const t=s.lastIndexOf(",");i.image=y.fromArchive(e,s.substring(0,t),parseInt(s.substring(t+1)))}break}case Y.TYPE_MODEL:{const t=r.g1;0!==t&&(i.model=this.getModel((t-1<<8)+r.g1));const e=r.g1;0!==e&&(i.activeModel=this.getModel((e-1<<8)+r.g1)),i.seqId=r.g1,0==i.seqId?i.seqId=-1:i.seqId=(i.seqId-1<<8)+r.g1,i.activeSeqId=r.g1,0==i.activeSeqId?i.activeSeqId=-1:i.activeSeqId=(i.activeSeqId-1<<8)+r.g1,i.modelZoom=r.g2,i.modelPitch=r.g2,i.modelYaw=r.g2;break}case Y.TYPE_INVENTORY_TEXT:i.inventorySlotObjId=new Int32Array(i.width*i.height),i.inventorySlotObjCount=new Int32Array(i.width*i.height),i.center=1===r.g1,i.font=s[r.g1],i.shadow=1===r.g1,i.color=r.g4,i.inventoryMarginX=r.g2b,i.inventoryMarginY=r.g2b,i.inventoryInteractable=1===r.g1,i.inventoryOptions=new Array(5).fill(null);for(let t=0;t<5;t++)i.inventoryOptions[t]=r.gjstr}2!=i.optionType&&2!=i.type||(i.spellAction=r.gjstr,i.spellName=r.gjstr,i.spellFlags=r.g2),1!=i.optionType&&4!=i.optionType&&5!=i.optionType&&6!=i.optionType||(i.option=r.gjstr,0==i.option.length&&(1==i.optionType?i.option="Ok":4==i.optionType||5==i.optionType?i.option="Select":6==i.optionType&&(i.option="Continue")))}};static get=t=>Y.instances[t];static getModel=t=>new k(t);id=-1;parentId=-1;type=-1;optionType=-1;contentType=0;width=0;height=0;delegateHover=-1;scriptComparator=null;scriptOperand=null;scripts=null;scrollableHeight=0;hide=!1;inventoryDraggable=!1;inventoryInteractable=!1;inventoryUsable=!1;inventoryMarginX=0;inventoryMarginY=0;inventorySlotOffsetX=null;inventorySlotOffsetY=null;inventorySlotImage=null;inventoryOptions=[];fill=!1;center=!1;font=null;shadow=!1;text=null;activeText=null;color=0;activeColor=0;hoverColor=0;image=null;activeImage=null;model=null;activeModel=null;seqId=-1;activeSeqId=-1;modelZoom=0;modelPitch=0;modelYaw=0;spellAction=null;spellName=null;spellFlags=-1;option=null;childId=null;childX=null;childY=null;x=0;y=0;scrollPosition=0;inventorySlotObjId=null;inventorySlotObjCount=null;seqFrame=0;getModel=(t,e,i)=>{let s=this.model;return i&&(s=this.activeModel),null==s?null:-1==t&&-1==e&&null==s.faceColor?s:null}}class O{static CHARSET=[];static{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";for(let e=0;e<256;e++){let i=t.indexOf(String.fromCharCode(e));-1===i&&(i=74),O.CHARSET[e]=i}}pixels=[];charWidth=[];charHeight=[];clipX=[];clipY=[];charSpace=[];drawWidth=[];fontHeight=-1;static fromArchive=(t,e)=>{const s=new i(t.read(e+".dat")),r=new i(t.read("index.dat"));r.pos=s.g2+4;const a=r.g1;a>0&&(r.pos+=3*(a-1));const n=new O;for(let t=0;t<94;t++){n.clipX[t]=r.g1,n.clipY[t]=r.g1;const e=n.charWidth[t]=r.g2,i=n.charHeight[t]=r.g2,a=e*i;n.pixels[t]=new Uint8Array(a);const o=r.g1;if(0===o)for(let r=0;rn.fontHeight&&(n.fontHeight=i),n.clipX[t]=1,n.charSpace[t]=e+2;{let s=0;for(let r=i/7;r{t|=0,e|=0;const r=i.length;e-=this.fontHeight;for(let a=0;a{t|=0,e|=0;const a=i.length;e-=this.fontHeight;for(let n=0;n{const e=t.length;let i=0;for(let s=0;s{const r=e-this.fontHeight;for(let e=0;e{this.drawStringTaggable(t-this.stringWidth(i)/2,e,i,s,r)};drawStringCenter=(t,e,i,s)=>{this.draw(t-this.stringWidth(i)/2,e,i,s)};drawRight=(t,e,i,s,r=!0)=>{r&&this.draw(t-this.stringWidth(i)+1,e+1,i,0),this.draw(t-this.stringWidth(i),e,i,s)};drawChar=(e,i,s,r,a,n)=>{r|=0,a|=0;let o=(i|=0)+(s|=0)*t.width,h=t.width-r,l=0,c=0;if(s=t.bottom&&(a-=s+a+1-t.bottom),i=t.right){const e=i+r+1-t.right;r-=e,l+=e,h+=e}r>0&&a>0&&this.drawMask(r,a,e,c,l,t.pixels,o,h,n)};drawMask=(t,e,i,s,r,a,n,o,h)=>{const l=-((t|=0)>>2);t=-(3&t);for(let c=-(e|=0);c<0;c++){for(let t=l;t<0;t++)0==i[s++]?n++:a[n++]=h,0==i[s++]?n++:a[n++]=h,0==i[s++]?n++:a[n++]=h,0==i[s++]?n++:a[n++]=h;for(let e=t;e<0;e++)0==i[s++]?n++:a[n++]=h;n+=o,s+=r}};copyCharacter=(e,i,s,r,a,n)=>{s|=0,r|=0;let o=(e|=0)+(i|=0)*t.width,h=0,l=t.width-s,c=0;if(it.bottom&&(r-=i+r+1-t.bottom),et.right){const i=e+s+1-t.right;s-=i,c+=i,l+=i}s>0&&r>0&&this.copyImageMasked(s,r,a,h,c,t.pixels,o,l,n)};copyImageMasked=(t,e,i,s,r,a,n,o,h)=>{for(let l=0;l{switch(t){case"red":return 16711680;case"gre":return 65280;case"blu":return 255;case"yel":return 16776960;case"cya":return 65535;case"mag":return 16711935;case"whi":return 16777215;case"bla":default:return 0;case"lre":return 16748608;case"dre":return 8388608;case"dbl":return 128;case"or1":return 16756736;case"or2":return 16740352;case"or3":return 16723968;case"gr1":return 12648192;case"gr2":return 8453888;case"gr3":return 4259584}}}class X{static loadUrl=async t=>new X(await c(t));static genHash=t=>{let e=0;t=t.toUpperCase();for(let i=0;i>>0;return e};buffer;compressedWhole;fileCount;fileHash;fileSizeInflated;fileSizeDeflated;fileOffset;constructor(t){const e=new i(t),s=e.g3;let r;if(s==e.g3)r=e,this.compressedWhole=!1;else{const t=e.gdata(e.pos,s);r=new i(new Uint8Array(f(t))),this.compressedWhole=!0}this.buffer=r,this.fileCount=r.g2,this.fileHash=[],this.fileSizeInflated=[],this.fileSizeDeflated=[],this.fileOffset=[];let a=r.pos+10*this.fileCount;for(let t=0;t{const e=X.genHash(t),i=this.fileHash.indexOf(e);return-1==i?null:this.readIndex(i)};readIndex=t=>{if(t<0||t>=this.fileCount)return null;if(this.compressedWhole)return this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);{const e=this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);return f(e)}}}class F{static PERIOD=new Uint16Array(["d","o","t"].join("").split("").map((t=>t.charCodeAt(0))));static AMPERSAT=new Uint16Array(["(","a",")"].join("").split("").map((t=>t.charCodeAt(0))));static SLASH=new Uint16Array(["s","l","a","s","h"].join("").split("").map((t=>t.charCodeAt(0))));static whitelist=["cook","cook's","cooks","seeks","sheet"];static tlds=[];static tldTypes=[];static bads=[];static badCombinations=[];static domains=[];static fragments=[];static unpack=t=>{const e=new i(t.read("fragmentsenc.txt")),s=new i(t.read("badenc.txt")),r=new i(t.read("domainenc.txt")),a=new i(t.read("tldlist.txt"));this.read(s,r,e,a)};static filter=t=>{const e=[...t];this.format(e);const i=e.join("").trim(),s=i.toLowerCase(),r=[...s];this.filterTlds(r),this.filterBadWords(r),this.filterDomains(r),this.filterFragments(r);for(let t=0;t{this.readBadWords(t),this.readDomains(e),this.readFragments(i),this.readTld(s)};static readTld=t=>{const e=t.g4;for(let i=0;it.g1))};static readBadWords=t=>{const e=t.g4;for(let i=0;it.g1));const e=new Array(t.g1).fill([]).map((()=>[t.g1b,t.g1b]));e.length>0&&(this.badCombinations[i]=e)}};static readDomains=t=>{const e=t.g4;for(let i=0;it.g1))};static readFragments=t=>{const e=t.g4;for(let i=0;i{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.PERIOD),this.filterBadCombinations(null,i,this.SLASH);for(let s=0;s{for(let e=0;e<2;e++)for(let e=this.bads.length-1;e>=0;e--)this.filterBadCombinations(this.badCombinations[e],t,this.bads[e])};static filterDomains=t=>{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.AMPERSAT),this.filterBadCombinations(null,i,this.PERIOD);for(let s=this.domains.length-1;s>=0;s--)this.filterDomain(i,e,this.domains[s],t)};static filterFragments=t=>{for(let e=0;e=0&&r{if(this.isNumericalChars(t))return!0;const e=this.getInteger(t),i=this.fragments,s=i.length;if(e===i[0]||e===i[s-1])return!0;let r=0,a=s-1;for(;r<=a;){const t=Math.floor((r+a)/2);if(e===i[t])return!0;e{if(t.length>6)return 0;let e=0;for(let i=0;i{for(let i=e;i=0;i++)if(this.isNumerical(t[i]))return i;return-1};static indexOfNonNumber=(t,e)=>{for(let i=t;i=0;i++)if(!this.isNumerical(e[i]))return i;return e.length};static getEmulatedDomainCharLen=(t,e,i)=>e==i||"o"==e&&"0"==i?1:"o"==e&&"("==i&&")"==t?2:"c"!=e||"("!=i&&"<"!=i&&"["!=i?"e"==e&&"€"==i||"s"==e&&"$"==i||"l"==e&&"i"==i?1:0:1;static filterDomain=(t,e,i,s)=>{const r=i.length,a=s.length;for(let n=0;n<=a-r;n++){const{matched:r,currentIndex:a}=this.findMatchingDomain(n,i,s);if(!r)continue;const o=this.prefixSymbolStatus(n,s,3,e,["@"]),h=this.suffixSymbolStatus(a-1,s,3,t,[".",","]);(o>2||h>2)&&this.maskChars(n,a,s)}};static findMatchingDomain=(t,e,i)=>{const s=e.length;let r=t,a=0;for(;r0)r+=h,a++;else{if(0===a)break;const i=this.getEmulatedDomainCharLen(o,String.fromCharCode(e[a-1]),n);if(i>0)r+=i,1===a&&t++;else{if(a>=s||!this.isSymbol(n))break;r++}}}return{matched:a>=s,currentIndex:r}};static filterBadCombinations=(t,e,i)=>{if(!(i.length>e.length))for(let s=0;s<=e.length-i.length;s++){let r=s;const{currentIndex:a,badIndex:n,hasSymbol:o,hasNumber:h,hasDigit:l}=this.processBadCharacters(e,i,r);r=a;let c=e[r],f=r+1=i.length)||h&&l)continue;let d,u=!0;if(o){let t=!1,i=!1;if((s-1<0||this.isSymbol(e[s-1])&&"'"!=e[s-1])&&(t=!0),(r>=e.length||this.isSymbol(e[r])&&"'"!=e[r])&&(i=!0),!t||!i){let i=!1;for(d=s-2,t&&(d=s);!i&&d=0&&(!this.isSymbol(e[d])||"'"==e[d])){const t=[];let s;for(s=0;s<3&&d+s=0&&(!this.isSymbol(e[d-1])||"'"==e[d-1])&&(r=!1),r&&!this.isBadFragment(t)&&(i=!0)}d++}i||(u=!1)}}else{c=" ",s-1>=0&&(c=e[s-1]),f=" ",r{let s=i,r=0,a=0,n=!1,o=!1,h=!1;for(;s=t.length||o&&h);){const l=t[s],c=s+10)1===f&&this.isNumerical(l)&&(o=!0),2===f&&(this.isNumerical(l)||this.isNumerical(c))&&(o=!0),s+=f,r++;else{if(0===r)break;let t;if((t=this.getEmulatedBadCharLen(c,String.fromCharCode(e[r-1]),l))>0)s+=t;else{if(r>=e.length||!this.isNotLowercaseAlpha(l))break;if(this.isSymbol(l)&&"'"!==l&&(n=!0),this.isNumerical(l)&&(h=!0),s++,a++,100*a/(s-i)>90)break}}}return{currentIndex:s,badIndex:r,hasSymbol:n,hasNumber:o,hasDigit:h}};static getEmulatedBadCharLen=(t,e,i)=>{if(e==i)return 1;if(e>="a"&&e<="m"){if("a"==e)return"4"!=i&&"@"!=i&&"^"!=i?"/"==i&&"\\"==t?2:0:1;if("b"==e)return"6"!=i&&"8"!=i?"1"==i&&"3"==t?2:0:1;if("c"==e)return"("!=i&&"<"!=i&&"{"!=i&&"["!=i?0:1;if("d"==e)return"["==i&&")"==t?2:0;if("e"==e)return"3"!=i&&"€"!=i?0:1;if("f"==e)return"p"==i&&"h"==t?2:"£"==i?1:0;if("g"==e)return"9"!=i&&"6"!=i?0:1;if("h"==e)return"#"==i?1:0;if("i"==e)return"y"!=i&&"l"!=i&&"j"!=i&&"1"!=i&&"!"!=i&&":"!=i&&";"!=i&&"|"!=i?0:1;if("j"==e)return 0;if("k"==e)return 0;if("l"==e)return"1"!=i&&"|"!=i&&"i"!=i?0:1;if("m"==e)return 0}if(e>="n"&&e<="z"){if("n"==e)return 0;if("o"==e)return"0"!=i&&"*"!=i?"("==i&&")"==t||"["==i&&"]"==t||"{"==i&&"}"==t||"<"==i&&">"==t?2:0:1;if("p"==e)return 0;if("q"==e)return 0;if("r"==e)return 0;if("s"==e)return"5"!=i&&"z"!=i&&"$"!=i&&"2"!=i?0:1;if("t"==e)return"7"!=i&&"+"!=i?0:1;if("u"==e)return"v"==i?1:"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("v"==e)return"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("w"==e)return"v"==i&&"v"==t?2:0;if("x"==e)return")"==i&&"("==t||"}"==i&&"{"==t||"]"==i&&"["==t||">"==i&&"<"==t?2:0;if("y"==e)return 0;if("z"==e)return 0}return e>="0"&&e<="9"?"0"==e?"o"==i||"O"==i?1:"("==i&&")"==t||"{"==i&&"}"==t||"["==i&&"]"==t?2:0:"1"==e&&"l"==i?1:0:","==e?"."==i?1:0:"."==e?","==i?1:0:"!"==e&&"i"==i?1:0};static comboMatches=(t,e,i)=>{let s=0,r=e.length-1;for(;s<=r;){const a=Math.floor((s+r)/2);if(e[a][0]===t&&e[a][1]===i)return!0;tthis.isLowercaseAlpha(t)?t.charCodeAt(0)+1-"a".charCodeAt(0):"'"==t?28:this.isNumerical(t)?t.charCodeAt(0)+29-"0".charCodeAt(0):27;static filterTld=(t,e,i,s,r)=>{if(!(s.length>i.length))for(let a=0;a<=i.length-s.length;a++){const{currentIndex:n,tldIndex:o}=this.processTlds(i,s,a);if(o0&&c>0&&(h=!0),2==e&&(l>2&&c>0||l>0&&c>2)&&(h=!0),3==e&&l>0&&c>2&&(h=!0),!h)continue;let f,d=a,u=n-1,p=!1;if(l>2){if(4==l)for(p=!1,f=a-1;f>=0;f--)if(p){if("*"!=r[f])break;d=f}else"*"==r[f]&&(d=f,p=!0);for(p=!1,f=d-1;f>=0;f--)if(p){if(this.isSymbol(i[f]))break;d=f}else this.isSymbol(i[f])||(p=!0,d=f)}if(c>2){if(4==c)for(p=!1,f=u+1;f{let s=0;for(;i0)i+=n,s++;else{if(0===s)break;let t;if((t=this.getEmulatedDomainCharLen(a,String.fromCharCode(e[s-1]),r))>0)i+=t;else{if(!this.isSymbol(r))break;i++}}}return{currentIndex:i,tldIndex:s}};static isSymbol=t=>!this.isAlpha(t)&&!this.isNumerical(t);static isNotLowercaseAlpha=t=>!this.isLowercaseAlpha(t)||"v"==t||"x"==t||"j"==t||"q"==t||"z"==t;static isAlpha=t=>this.isLowercaseAlpha(t)||this.isUppercaseAlpha(t);static isNumerical=t=>t>="0"&&t<="9";static isLowercaseAlpha=t=>t>="a"&&t<="z";static isUppercaseAlpha=t=>t>="A"&&t<="Z";static isNumericalChars=t=>{for(let e=0;e{for(let s=t;s{let i=0;for(let s=e-1;s>=0&&this.isSymbol(t[s]);s--)"*"===t[s]&&i++;return i};static maskedCountForwards=(t,e)=>{let i=0;for(let s=e+1;s(r?this.maskedCountBackwards(e,i):this.maskedCountForwards(e,i))>=s?4:this.isSymbol(r?t[i-1]:t[i+1])?1:0;static prefixSymbolStatus=(t,e,i,s,r)=>{if(0===t)return 2;for(let i=t-1;i>=0&&this.isSymbol(e[i]);i--)if(r.includes(e[i]))return 3;return this.maskedCharsStatus(e,s,t,i,!0)};static suffixSymbolStatus=(t,e,i,s,r)=>{if(t+1===e.length)return 2;for(let i=t+1;i{let e=0;for(let i=0;it>=" "&&t<=""||" "==t||"\n"==t||"\t"==t||"£"==t||"€"==t;static replaceUppercases=(t,e)=>{for(let i=0;i{let e=!0;for(let i=0;i{}}class B extends d{static HOST="https://w2.225.2004scape.org";fontPlain11=null;fontPlain12=null;fontBold12=null;fontQuill8=null;lastHistoryRefresh=0;historyRefresh=!0;constructor(){super(!0)}load=async()=>{await this.showProgress(10,"Connecting to fileserver");const t=new i(await c(`${B.HOST}/crc`)),e=[];for(let i=0;i<9;i++)e[i]=t.g4;const s=await this.loadArchive("title","title screen",e[1],10);this.fontPlain11=O.fromArchive(s,"p11"),this.fontPlain12=O.fromArchive(s,"p12"),this.fontBold12=O.fromArchive(s,"b12"),this.fontQuill8=O.fromArchive(s,"q8");const a=await this.loadArchive("config","config",e[2],15),n=await this.loadArchive("interface","interface",e[3],20),o=await this.loadArchive("media","2d graphics",e[4],30),h=await this.loadArchive("models","3d graphics",e[5],40),l=await this.loadArchive("textures","textures",e[6],60),f=await this.loadArchive("wordenc","chat system",e[7],65),d=await this.loadArchive("sounds","sound effects",e[8],70);await this.showProgress(75,"Unpacking media"),await this.showProgress(80,"Unpacking textures"),r.unpackTextures(l),r.setBrightness(.8),r.initPool(20),await this.showProgress(83,"Unpacking models"),k.unpack(h),p.unpack(h),g.unpack(h),await this.showProgress(86,"Unpacking config"),m.unpack(a),w.unpack(a),x.unpack(a),v.unpack(a,!0),C.unpack(a),b.unpack(a),A.unpack(a),S.unpack(a),await this.showProgress(90,"Unpacking sounds"),T.unpack(d),await this.showProgress(92,"Unpacking interfaces"),Y.unpack(n,o,[this.fontPlain11,this.fontPlain12,this.fontBold12,this.fontQuill8]),await this.showProgress(97,"Preparing game engine"),F.unpack(f),this.drawArea?.bind(),r.init2D()};update=()=>{this.updateKeysPressed(),this.updateKeysHeld(),this.lastHistoryRefresh++,this.lastHistoryRefresh>50&&(this.historyRefresh&&(d.setParameter("model",this.model.id.toString()),d.setParameter("x",this.model.pitch.toString()),d.setParameter("y",this.model.yaw.toString()),d.setParameter("z",this.model.roll.toString()),d.setParameter("eyeX",this.camera.x.toString()),d.setParameter("eyeY",this.camera.y.toString()),d.setParameter("eyeZ",this.camera.z.toString()),d.setParameter("eyePitch",this.camera.pitch.toString()),this.historyRefresh=!1),this.lastHistoryRefresh=0)};draw=async()=>{t.clear(),t.fillRect(0,0,this.width,this.height,5592405);const e=new k(this.model.id);if(e.calculateNormals(64,850,-30,-50,-30,!0),e.drawSimple(this.model.pitch,this.model.yaw,this.model.roll,this.camera.pitch,this.camera.x,this.camera.y,this.camera.z),this.fontBold12){this.fontBold12.drawRight(this.width,this.fontBold12.fontHeight,`FPS: ${this.fps}`,16776960),this.fontBold12.drawRight(this.width,this.height,`${this.model.pitch},${this.model.yaw},${this.model.roll},${this.camera.pitch},${this.camera.x},${this.camera.z},${this.camera.y}`,16776960);let t=this.fontBold12.fontHeight;this.fontBold12.draw(0,t,`Model: ${this.model.id}`,16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"Controls:",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"r - reset camera and model rotation + movement speed",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"1 and 2 - change model",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"[ and ] - adjust movement speed",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"left and right - adjust model yaw",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"up and down - adjust model pitch",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,". and / - adjust model roll",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"w and s - move camera along z axis",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"a and d - move camera along x axis",16776960),t+=this.fontBold12.fontHeight,this.fontBold12.draw(0,t,"q and e - move camera along y axis",16776960)}this.drawArea?.draw(0,0)};async loadArchive(t,e,i,s){await this.showProgress(s,`Requesting ${e}`);const r=await X.loadUrl(`${B.HOST}/${t}${i}`);return await this.showProgress(s,`Loading ${e} - 100%`),r}modifier=2;model={id:parseInt(d.getParameter("model"))||0,pitch:parseInt(d.getParameter("x"))||0,yaw:parseInt(d.getParameter("y"))||0,roll:parseInt(d.getParameter("z"))||0};camera={x:parseInt(d.getParameter("eyeX"))||0,y:parseInt(d.getParameter("eyeY"))||0,z:parseInt(d.getParameter("eyeZ"))||420,pitch:parseInt(d.getParameter("eyePitch"))||0};updateKeysPressed(){for(;;){const t=this.pollKey();if(-1===t)break;t==="r".charCodeAt(0)?(this.modifier=2,this.model={id:this.model.id,pitch:0,yaw:0,roll:0},this.camera={x:0,y:0,z:420,pitch:0},this.historyRefresh=!0):t==="1".charCodeAt(0)?(this.model.id--,this.model.id<0&&k.metadata&&(this.model.id=k.metadata.length-100-1),this.historyRefresh=!0):t==="2".charCodeAt(0)&&(this.model.id++,k.metadata&&this.model.id>=k.metadata.length-100&&(this.model.id=0),this.historyRefresh=!0)}}updateKeysHeld(){this.actionKey["[".charCodeAt(0)]?this.modifier--:this.actionKey["]".charCodeAt(0)]&&this.modifier++,this.actionKey[1]?(this.model.yaw+=this.modifier,this.historyRefresh=!0):this.actionKey[2]&&(this.model.yaw-=this.modifier,this.historyRefresh=!0),this.actionKey[3]?(this.model.pitch-=this.modifier,this.historyRefresh=!0):this.actionKey[4]&&(this.model.pitch+=this.modifier,this.historyRefresh=!0),this.actionKey[".".charCodeAt(0)]?(this.model.roll+=this.modifier,this.historyRefresh=!0):this.actionKey["/".charCodeAt(0)]&&(this.model.roll-=this.modifier,this.historyRefresh=!0),this.actionKey["w".charCodeAt(0)]?(this.camera.z-=this.modifier,this.historyRefresh=!0):this.actionKey["s".charCodeAt(0)]&&(this.camera.z+=this.modifier,this.historyRefresh=!0),this.actionKey["a".charCodeAt(0)]?(this.camera.x-=this.modifier,this.historyRefresh=!0):this.actionKey["d".charCodeAt(0)]&&(this.camera.x+=this.modifier,this.historyRefresh=!0),this.actionKey["q".charCodeAt(0)]?(this.camera.y-=this.modifier,this.historyRefresh=!0):this.actionKey["e".charCodeAt(0)]&&(this.camera.y+=this.modifier,this.historyRefresh=!0),this.model.pitch=2047&this.model.pitch,this.model.yaw=2047&this.model.yaw,this.model.roll=2047&this.model.roll}}(new B).run().then((()=>{}))})(); \ No newline at end of file diff --git a/viewer.js b/viewer.js index 0493a81e..bd2647fa 100644 --- a/viewer.js +++ b/viewer.js @@ -1,2 +1,2 @@ /*! For license information please see viewer.js.LICENSE.txt */ -(()=>{"use strict";class t{index;constructor(t){this.index=t}decodeType=t=>{for(;;){const e=t.g1;if(0===e)break;this.decode(e,t)}}}class e{static crctable=new Int32Array(256);static CRC32_POLYNOMIAL=3988292384;static bitmask=new Uint32Array(33);static{for(let t=0;t<32;t++)e.bitmask[t]=(1<>>1^e.CRC32_POLYNOMIAL:i>>>=1;e.crctable[t]=i}}data;pos;bitPos=0;constructor(t){if(!t)throw new Error("Input src packet array was null!");this.data=t,this.pos=0}static alloc=t=>new e(0===t?new Uint8Array(100):1===t?new Uint8Array(5e3):new Uint8Array(3e4));get g1(){return this.data[this.pos++]}get g1b(){return this.data[this.pos++]<<24>>24}get g2(){return(this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g2b(){return this.data[this.pos++]<<8|this.data[this.pos++]}get g3(){return(this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4(){return(this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4s(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]}get g8(){return BigInt(this.g4)<<32n|BigInt(this.g4)}get gsmart(){return this.data[this.pos]<128?this.g1:this.g2-32768}get gsmarts(){return this.data[this.pos]<128?this.g1-64:this.g2-49152}get gjstr(){let t="";for(;10!=this.data[this.pos]&&this.posthis.data.subarray(t,t+e);p1=t=>{this.data[this.pos++]=t};p2=t=>{this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip2=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8};p3=t=>{this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};p4=t=>{this.data[this.pos++]=t>>>24,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip4=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>24};p8=t=>{this.p4(Number(t>>32n)),this.p4(Number(0xffffffffn&t))};pjstr=t=>{for(let e=0;e{for(let s=i;s{this.data[this.pos-t-1]=t};bits=()=>{this.bitPos=8*this.pos};bytes=()=>{this.pos=(this.bitPos+7)/8>>>0};gBit=t=>{let i=this.bitPos>>>3,s=8-(7&this.bitPos),r=0;for(this.bitPos+=t;t>s;s=8)r+=(this.data[i++]&e.bitmask[s])<>>s-t&e.bitmask[t],r}}class i{static instances=[];static unpack=t=>{const s=new e(t.read("base_head.dat")),r=new e(t.read("base_type.dat")),a=new e(t.read("base_label.dat")),n=s.g2;s.pos+=2;for(let t=0;t{const r=new e(t.read("frame_head.dat")),a=new e(t.read("frame_tran1.dat")),n=new e(t.read("frame_tran2.dat")),o=new e(t.read("frame_del.dat")),l=r.g2;r.pos+=2;const h=new Uint32Array(500),c=new Uint32Array(500),f=new Uint32Array(500),d=new Uint32Array(500);for(let t=0;t0){if(0!=u.types[t])for(let e=t-1;e>g;e--)if(0==u.types[e]){h[m]=e,c[m]=0,f[m]=0,d[m]=0,m++;break}h[m]=t;let i=0;3==u.types[h[m]]&&(i=128),c[m]=0==(1&e)?i:n.gsmart,f[m]=0==(2&e)?i:n.gsmart,d[m]=0==(4&e)?i:n.gsmart,g=t,m++}}e.length=m,e.bases=new Uint32Array(m),e.x=new Uint32Array(m),e.y=new Uint32Array(m),e.z=new Uint32Array(m);for(let t=0;t{const i=new e(t.read("seq.dat"));this.count=i.g2;for(let t=0;tr.instances[t];frameCount=0;frames=null;iframes=null;delay=null;replayoff=-1;labelGroups=null;stretches=!1;priority=5;mainhand=-1;offhand=-1;replaycount=99;duration=0;decode=(t,e)=>{if(1===t){this.frameCount=e.g1,this.frames=new Uint16Array(this.frameCount),this.iframes=new Uint16Array(this.frameCount),this.delay=new Uint16Array(this.frameCount);for(let t=0;t{const i=new e(t.read("loc.dat"));this.count=i.g2;for(let t=0;t0&&10==e.shapes[0]?1:0,e.ops.length>0&&(e.active=1))}};static get=t=>a.instances[t];models=null;shapes=null;name=null;desc=null;recol_s=null;recol_d=null;width=1;length=1;blockwalk=!0;blockrange=!0;active=-1;hillskew=!1;sharelight=!1;occlude=!1;anim=-1;hasalpha=!1;walloff=16;ambient=0;contrast=0;ops=[];mapfunction=-1;mapscene=-1;mirror=!1;shadow=!0;resizex=128;resizey=128;resizez=128;forceapproach=0;xoff=0;yoff=0;zoff=0;forcedecor=!1;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t),this.shapes=new Uint8Array(t);for(let i=0;i=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const i=new e(t.read("flo.dat"));this.count=i.g2;for(let t=0;tn.instances[t];rgb=0;texture=-1;opcode3=!1;occludes=!0;name=null;decode=(t,e)=>{1===t?this.rgb=e.g3:2===t?this.texture=e.g1:3===t?this.opcode3=!0:5===t?this.occludes=!1:6===t?this.name=e.gjstr:console.log("Error unrecognised config code: ",t)}}class o{static pixels=new Int32Array;static width=0;static height=0;static top=0;static bottom=0;static left=0;static right=0;static boundX=0;static centerX=0;static centerY=0;static bind=(t,e,i)=>{this.pixels=t,this.width=e,this.height=i,this.setBounds(0,0,e,i)};static resetBounds=()=>{this.left=0,this.top=0,this.right=this.width,this.bottom=this.height,this.boundX=this.right-1,this.centerX=this.right/2};static setBounds=(t,e,i,s)=>{t<0&&(t=0),e<0&&(e=0),i>this.width&&(i=this.width),s>this.height&&(s=this.height),this.top=e,this.bottom=s,this.left=t,this.right=i,this.boundX=this.right-1,this.centerX=this.right/2,this.centerY=this.bottom/2};static clear=()=>{this.pixels.fill(0)};static drawRect=(t,e,i,s,r)=>{this.drawHorizontalLine(t,e,r,i),this.drawHorizontalLine(t,e+s-1,r,i),this.drawVerticalLine(t,e,r,s),this.drawVerticalLine(t+i-1,e,r,s)};static drawHorizontalLine=(t,e,i,s)=>{if(e=this.bottom)return;tthis.right&&(s=this.right-t);const r=t+e*this.width;for(let t=0;t{if(t=this.right)return;ethis.bottom&&(s=this.bottom-e);const r=t+e*this.width;for(let t=0;t{const a=Math.abs(i-t),n=Math.abs(s-e),o=t=this.left&&t=this.top&&e-n&&(h-=n,t+=o),i{const a=this.pixels;let n=t,o=e,l=t+i,h=e+s;nthis.right&&(l=this.right),h>this.bottom&&(h=this.bottom);const c=this.width;for(let t=o;tt.bits-e.bits||t.code-e.code));let a=0,n=-1;const o=[];let l;for(let t=0;t=t.length)throw RangeError("Out of bound");const i=t.slice();t.sort(((t,e)=>t-e));const s={};for(let e=t.length-1;e>=0;e-=1)s[t[e]]=e;const r=[];for(let e=0;enew Promise((e=>setTimeout(e,t))),u=async t=>new Uint8Array(await(await fetch(t)).arrayBuffer()),p=(t,e=!0,i=!0)=>{if(e){const e=Uint8Array.from(["B".charCodeAt(0),"Z".charCodeAt(0),"h".charCodeAt(0),"1".charCodeAt(0)]);if(i){const i=t;(t=new Uint8Array(e.length+t.length)).set(i,e.length)}t.set(e,0)}return function(t,e=!1){let i=0,s=0,r=0;const a=e=>{if(e>=32){const t=e>>1;return a(t)*(1<>r-e&n;return r-=e,s&=~(n<=49&&n<=57))throw new Error("Invalid blocksize");n-=48;let o=new Uint8Array(1.5*t.length),d=0,u=-1;for(;;){const n=a(48),p=0|a(32);if(54156738319193!==n){if(25779555029136===n){a(7&r);break}throw new Error("Invalid bz2 blocktype")}{if(a(1))throw new Error("do not support randomised");const n=a(24),g=[],m=a(16);for(let t=32768;t>0;t>>=1){if(!(m&t)){for(let t=0;t<16;t+=1)g.push(!1);continue}const e=a(16);for(let t=32768;t>0;t>>=1)g.push(!!(e&t))}const w=a(3);if(w<2||w>6)throw new Error("Invalid number of huffman groups");const x=a(15),y=[],v=Array.from({length:w},((t,e)=>e));for(let t=0;t=w)throw new Error("MTF table out of range");const e=v[t];for(let e=t;e>0;v[e]=v[--e]);y.push(e),v[0]=e}const C=g.reduce(((t,e)=>t+e),0)+2,b=[];for(let t=0;t20)throw new Error("Huffman group length outside range");for(;a(1);)t-=2*a(1)-1;e.push(t)}b.push(c(e))}const A=[];for(let t=0;t>r-e],k)){s&=h[r-=e],k=k.code;break}if(k>=0&&k<=1)0===Y&&(O=1),Y+=O<0;Y-=1)T.push(t)}if(k===C-1)break;{const t=A[k-1];for(let t=k-1;t>0;A[t]=A[--t]);A[0]=t,T.push(t)}}}const X=f(T,n);let F=0;for(;F=o.length){const t=o;o=new Uint8Array(2*t.length),o.set(t)}for(let s=0;s>24^t)]),o[d]=t,d+=1}if(e){const t=-1^u;if(t!==p)throw new Error(`CRC mismatch: ${t} !== ${p}`);u=-1}}}return o.subarray(0,d)}(t)};class g{pixels;width;height;cropX;cropY;cropW;cropH;constructor(t,e){this.pixels=new Int32Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromJpeg=async(t,e)=>{const i=t.read(e+".dat"),s=await(async t=>{if(!t)throw new Error("Input jpeg data was null!");255!==t[0]&&(t[0]=255);const e=document.createElement("img");e.src="data:image/jpeg;base64,"+btoa(String.fromCharCode(...t)),await new Promise((t=>e.onload=t));const i=document.createElement("canvas");i.width=e.naturalWidth,i.height=e.naturalHeight;const s=i.getContext("2d");if(!s)throw new Error("Canvas 2d not found!!!!!!!!");return s.drawImage(e,0,0),s.getImageData(0,0,i.width,i.height)})(i),r=new g(s.width,s.height),a=r.pixels,n=s.data;for(let t=0;t{const r=new e(t.read(i+".dat")),a=new e(t.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,l=a.g1,h=new Uint32Array(l),c=l-1;for(let t=0;t{t|=0,e|=0;let i=(t+=this.cropX)+(e+=this.cropY)*o.width,s=0,r=this.height,a=this.width,n=o.width-a,l=0;if(eo.bottom&&(r-=e+r-o.bottom),to.right){const e=t+a-o.right;a-=e,l+=e,n+=e}a>0&&r>0&&this.copyImageDraw(a,r,this.pixels,s,l,o.pixels,i,n)};drawAlpha=(t,e,i)=>{e|=0,i|=0;let s=(e+=this.cropX)+(i+=this.cropY)*o.width,r=0,a=this.height,n=this.width,l=o.width-n,h=0;if(io.bottom&&(a-=i+a-o.bottom),eo.right){const t=e+n-o.right;n-=t,h+=t,l+=t}n>0&&a>0&&this.copyPixelsAlpha(n,a,this.pixels,r,h,o.pixels,s,l,t)};blitOpaque=(t,e)=>{t|=0,e|=0;let i=(t+=this.cropX)+(e+=this.cropY)*o.width,s=0,r=this.height,a=this.width,n=o.width-a,l=0;if(eo.bottom&&(r-=e+r-o.bottom),to.right){const e=t+a-o.right;a-=e,l+=e,n+=e}a>0&&r>0&&this.copyImageBlitOpaque(a,r,this.pixels,s,l,o.pixels,i,n)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;a+=t,a<1?a=1:a>255&&(a=255);let n=r>>8&255;n+=e,n<1?n=1:n>255&&(n=255);let o=255&r;o+=i,o<1?o=1:o>255&&(o=255),this.pixels[s]=(a<<16)+(n<<8)+o}}};copyImageBlitOpaque=(t,e,i,s,r,a,n,o)=>{const l=-(t>>2);t=-(3&t);for(let h=-e;h<0;h++){for(let t=l;t<0;t++)a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++];for(let e=t;e<0;e++)a[n++]=i[s++];n+=o,s+=r}};copyPixelsAlpha=(t,e,i,s,r,a,n,o,l)=>{const h=256-l;for(let c=-e;c<0;c++){for(let e=-t;e<0;e++){const t=i[s++];if(0==t)n++;else{const e=a[n];a[n++]=((16711935&t)*l+(16711935&e)*h&4278255360)+((65280&t)*l+(65280&e)*h&16711680)>>8}}n+=o,s+=r}};copyImageDraw=(t,e,i,s,r,a,n,o)=>{const l=-(t>>2);t=-(3&t);for(let h=-e;h<0;h++){for(let t=l;t<0;t++){let t=i[s++];0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t}for(let e=t;e<0;e++){const t=i[s++];0===t?n++:a[n++]=t}n+=o,s+=r}}}class m extends t{static count=0;static instances=[];static unpack=(t,i)=>{const s=new e(t.read("obj.dat"));this.count=s.g2;for(let t=0;tm.instances[t];static getIcon=(t,e)=>new g(32,32);model=0;name=null;desc=null;recol_s=null;recol_d=null;zoom2d=2e3;xan2d=0;yan2d=0;zan2d=0;xof2d=0;yof2d=0;code9=!1;code10=-1;stackable=!1;cost=1;members=!1;ops=[];iops=[];manwear=-1;manwear2=-1;manwearOffsetY=0;womanwear=-1;womanwear2=-1;womanwearOffsetY=0;manwear3=-1;womanwear3=-1;manhead=-1;manhead2=-1;womanhead=-1;womanhead2=-1;countobj=null;countco=null;certlink=-1;certtemplate=-1;decode=(t,e)=>{if(1===t)this.model=e.g2;else if(2===t)this.name=e.gjstr;else if(3===t)this.desc=e.gjstr;else if(4===t)this.zoom2d=e.g2;else if(5===t)this.xan2d=e.g2;else if(6===t)this.yan2d=e.g2;else if(7===t)this.xof2d=e.g2b,this.xof2d>32767&&(this.xof2d-=65536);else if(8===t)this.yof2d=e.g2b,this.yof2d>32767&&(this.yof2d-=65536);else if(9===t)this.code9=!0;else if(10===t)this.code10=e.g2;else if(11===t)this.stackable=!0;else if(12===t)this.cost=e.g4s;else if(16===t)this.members=!0;else if(23===t)this.manwear=e.g2,this.manwearOffsetY=e.g1b;else if(24===t)this.manwear2=e.g2;else if(25===t)this.womanwear=e.g2,this.womanwearOffsetY=e.g1b;else if(26===t)this.womanwear2=e.g2;else if(t>=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(t>=35&&t<40)this.iops[t-35]=e.gjstr;else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i=100&&t<110))throw new Error(`Unrecognized obj config code: ${t}`);this.countobj&&this.countco||(this.countobj=new Uint16Array(10),this.countco=new Uint16Array(10)),this.countobj[t-100]=e.g2,this.countco[t-100]=e.g2}};toCertificate=()=>{const t=m.get(this.certtemplate);this.model=t.model,this.zoom2d=t.zoom2d,this.xan2d=t.xan2d,this.yan2d=t.yan2d,this.zan2d=t.zan2d,this.xof2d=t.xof2d,this.yof2d=t.yof2d,this.recol_s=t.recol_s,this.recol_d=t.recol_d;const e=m.get(this.certlink);this.name=e.name,this.members=e.members,this.cost=e.cost;let i="a";const s=(e.name||"").toLowerCase().charAt(0);"a"!==s&&"e"!==s&&"i"!==s&&"o"!==s&&"u"!==s||(i="an"),this.desc=`Swap this note at any bank for ${i} ${e.name}.`,this.stackable=!0}}class w extends t{static count=0;static instances=[];static unpack=t=>{const i=new e(t.read("npc.dat"));this.count=i.g2;for(let t=0;tw.instances[t];name=null;desc=null;size=1;models=null;heads=null;hasanim=!1;readyanim=-1;walkanim=-1;walkanim_b=-1;walkanim_r=-1;walkanim_l=-1;hasalpha=!1;recol_s=null;recol_d=null;ops=[];code90=-1;code91=-1;code92=-1;visonmap=!0;vislevel=-1;resizeh=128;resizev=128;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=30&&t<40)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const i=new e(t.read("idk.dat"));this.count=i.g2;for(let t=0;tx.instances[t];type=-1;models=null;heads=new Uint16Array(5).fill(-1);recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);disable=!1;decode=(t,e)=>{if(1===t)this.type=e.g1;else if(2===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=40&&t<50)this.recol_s[t-40]=e.g2;else if(t>=50&&t<60)this.recol_d[t-50]=e.g2;else{if(!(t>=60&&t<70))throw new Error(`Unrecognized idk config code: ${t}`);this.heads[t-60]=e.g2}}}class y extends t{static count=0;static instances=[];static unpack=t=>{const i=new e(t.read("spotanim.dat"));this.count=i.g2;for(let t=0;ty.instances[t];model=0;anim=-1;seq=null;disposeAlpha=!1;recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);resizeh=128;resizev=128;orientation=0;ambient=0;contrast=0;decode=(t,e)=>{if(1==t)this.model=e.g2;else if(2==t)this.anim=e.g2,null!=r.instances&&(this.seq=r.instances[this.anim]);else if(3==t)this.disposeAlpha=!0;else if(4==t)this.resizeh=e.g2;else if(5==t)this.resizev=e.g2;else if(6==t)this.orientation=e.g2;else if(7==t)this.ambient=e.g1;else if(8==t)this.contrast=e.g1;else if(t>=40&&t<50)this.recol_s[t-40]=e.g2;else{if(!(t>=50&&t<60))throw new Error(`Unrecognized spotanim config code: ${t}`);this.recol_d[t-50]=e.g2}}}class v extends t{static count=0;static instances=[];static code3=[];static code3Count=0;static unpack=t=>{const i=new e(t.read("varp.dat"));this.count=i.g2;for(let t=0;tv.instances[t];code10=null;code1=0;code2=0;hasCode3=!1;code4=!0;clientcode=0;code7=0;code6=!1;code8=!1;decode(t,e){if(1==t)this.code1=e.g1;else if(2==t)this.code2=e.g1;else if(3==t)this.hasCode3=!0,v.code3[v.code3Count++]=this.index;else if(4==t)this.code4=!1;else if(5==t)this.clientcode=e.g2;else if(6==t)this.code6=!0;else if(7==t)this.code7=e.g4;else if(8==t)this.code8=!0;else{if(10!=t)throw new Error(`Error unrecognised config code: ${t}`);this.code10=e.gjstr}}}class C{pixels;width;height;cropX;cropY;cropW;cropH;palette=new Uint32Array(0);constructor(t,e){this.pixels=new Uint8Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromArchive=(t,i,s=0)=>{const r=new e(t?.read(i+".dat")),a=new e(t?.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,l=a.g1,h=new Uint32Array(l);for(let t=0;t{t|=0,e|=0;let r=(t+=this.cropX)+(e+=this.cropY)*o.width,a=0,n=this.height,l=this.width;-1!==i&&(l=i),-1!==s&&(n=s);let h=o.width-l,c=0;if(eo.bottom&&(n-=e+n-o.bottom),to.right){const e=t+l-o.right;l-=e,c+=e,h+=e}l>0&&n>0&&this.copyImage(l,n,this.pixels,a,c,o.pixels,r,h)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;r+=t,r<0?r=0:r>255&&(r=255);let a=this.palette[s]>>8&255;a+=e,a<0?a=0:a>255&&(a=255);let n=255&this.palette[s];n+=i,n<0?n=0:n>255&&(n=255),this.palette[s]=(r<<16)+(a<<8)+n}};copyImage=(t,e,i,s,r,a,n,o)=>{for(let l=0;l{this.lineOffset=new Int32Array(o.height);for(let t=0;t{this.lineOffset=new Int32Array(e);for(let i=0;i{this.textureCount=0;for(let e=0;e<50;e++)try{this.textures[e]=C.fromArchive(t,e.toString()),this.textureCount++}catch(t){}};static setBrightness=t=>{t+=.3*Math.random()-.15;let e=0;for(let i=0;i<512;i++){const s=i/8/64+.0078125,r=(7&i)/8+.0625;for(let i=0;i<128;i++){const a=i/128;let n=a,o=a,l=a;if(r){let t;t=a<.5?a*(1+r):a+r-a*r;const e=2*a-t;let i=s+.3333333333333333;i>1&&i--;let h=s-.3333333333333333;h<0&&h++,n=6*i<1?e+6*(t-e)*i:2*i<1?t:3*i<2?e+6*(.6666666666666666-i)*(t-e):e,o=6*s<1?e+6*(t-e)*s:2*s<1?t:3*s<2?e+6*(.6666666666666666-s)*(t-e):e,l=6*h<1?e+6*(t-e)*h:2*h<1?t:3*h<2?e+6*(.6666666666666666-h)*(t-e):e}let h=Math.trunc(256*n)<<16|Math.trunc(256*o)<<8|Math.trunc(256*l);h=this.setGamma(h,t),0===h&&(h=1),this.palette[e++]=h}}};static setGamma=(t,e)=>{let i=(t>>16)/256,s=(t>>8&255)/256,r=(255&t)/256;return i=Math.pow(i,e),s=Math.pow(s,e),r=Math.pow(r,e),Math.trunc(256*i)<<16|Math.trunc(256*s)<<8|Math.trunc(256*r)};static initPool=t=>{null==this.texelPool&&(this.poolSize=t,this.texelPool=[],this.activeTexels=[])};static fillGouraudTriangle=(t,e,i,s,r,a,n,l,h)=>{let c=0,f=0,d=0,u=0,p=0,g=0;if(r!=s&&(c=(e-t<<16)/(r-s),u=(l-n<<15)/(r-s)),a!=r&&(f=(i-e<<16)/(a-r),p=(h-l<<15)/(a-r)),a!=s&&(d=(t-i<<16)/(s-a),g=(n-h<<15)/(s-a)),s<=r&&s<=a){if(s>=o.bottom)return;if(r>o.bottom&&(r=o.bottom),a>o.bottom&&(a=o.bottom),rf){for(a-=r,r-=s,s=this.lineOffset[s];--r>=0;s+=o.width)this.drawGouraudScanline(o.pixels,s,i>>16,t>>16,h>>7,n>>7),i+=d,t+=c,h+=g,n+=u;for(;--a>=0;)this.drawGouraudScanline(o.pixels,s,i>>16,e>>16,h>>7,l>>7),i+=d,e+=f,h+=g,l+=p,s+=o.width;return}for(a-=r,r-=s,s=this.lineOffset[s];--r>=0;s+=o.width)this.drawGouraudScanline(o.pixels,s,t>>16,i>>16,n>>7,h>>7),i+=d,t+=c,h+=g,n+=u;for(;--a>=0;)this.drawGouraudScanline(o.pixels,s,e>>16,i>>16,l>>7,h>>7),i+=d,e+=f,h+=g,l+=p,s+=o.width;return}if(e=t<<=16,l=n<<=15,s<0&&(e-=d*s,t-=c*s,l-=g*s,n-=u*s,s=0),i<<=16,h<<=15,a<0&&(i-=f*a,h-=p*a,a=0),s!=a&&dc){for(r-=a,a-=s,s=this.lineOffset[s];--a>=0;s+=o.width)this.drawGouraudScanline(o.pixels,s,e>>16,t>>16,l>>7,n>>7),e+=d,t+=c,l+=g,n+=u;for(;--r>=0;)this.drawGouraudScanline(o.pixels,s,i>>16,t>>16,h>>7,n>>7),i+=f,t+=c,h+=p,n+=u,s+=o.width;return}for(r-=a,a-=s,s=this.lineOffset[s];--a>=0;s+=o.width)this.drawGouraudScanline(o.pixels,s,t>>16,e>>16,n>>7,l>>7),e+=d,t+=c,l+=g,n+=u;for(;--r>=0;)this.drawGouraudScanline(o.pixels,s,t>>16,i>>16,n>>7,h>>7),i+=f,t+=c,h+=p,n+=u,s+=o.width}else if(r<=a){if(r>=o.bottom)return;if(a>o.bottom&&(a=o.bottom),s>o.bottom&&(s=o.bottom),ad){for(s-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=o.width)this.drawGouraudScanline(o.pixels,r,t>>16,e>>16,n>>7,l>>7),t+=c,e+=f,n+=u,l+=p;for(;--s>=0;)this.drawGouraudScanline(o.pixels,r,t>>16,i>>16,n>>7,h>>7),t+=c,i+=d,n+=u,h+=g,r+=o.width;return}for(s-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=o.width)this.drawGouraudScanline(o.pixels,r,e>>16,t>>16,l>>7,n>>7),t+=c,e+=f,n+=u,l+=p;for(;--s>=0;)this.drawGouraudScanline(o.pixels,r,i>>16,t>>16,h>>7,n>>7),t+=c,i+=d,n+=u,h+=g,r+=o.width;return}if(i=e<<=16,h=l<<=15,r<0&&(i-=c*r,e-=f*r,h-=u*r,l-=p*r,r=0),t<<=16,n<<=15,s<0&&(t-=d*s,n-=g*s,s=0),c=0;r+=o.width)this.drawGouraudScanline(o.pixels,r,i>>16,e>>16,h>>7,l>>7),i+=c,e+=f,h+=u,l+=p;for(;--a>=0;)this.drawGouraudScanline(o.pixels,r,t>>16,e>>16,n>>7,l>>7),t+=d,e+=f,n+=g,l+=p,r+=o.width;return}for(a-=s,s-=r,r=this.lineOffset[r];--s>=0;r+=o.width)this.drawGouraudScanline(o.pixels,r,e>>16,i>>16,l>>7,h>>7),i+=c,e+=f,h+=u,l+=p;for(;--a>=0;)this.drawGouraudScanline(o.pixels,r,e>>16,t>>16,l>>7,n>>7),t+=d,e+=f,n+=g,l+=p,r+=o.width}else if(!(a>=o.bottom))if(s>o.bottom&&(s=o.bottom),r>o.bottom&&(r=o.bottom),s=0;a+=o.width)this.drawGouraudScanline(o.pixels,a,e>>16,i>>16,l>>7,h>>7),e+=f,i+=d,l+=p,h+=g;for(;--r>=0;)this.drawGouraudScanline(o.pixels,a,e>>16,t>>16,l>>7,n>>7),e+=f,t+=c,l+=p,n+=u,a+=o.width;return}for(r-=s,s-=a,a=this.lineOffset[a];--s>=0;a+=o.width)this.drawGouraudScanline(o.pixels,a,i>>16,e>>16,h>>7,l>>7),e+=f,i+=d,l+=p,h+=g;for(;--r>=0;)this.drawGouraudScanline(o.pixels,a,t>>16,e>>16,n>>7,l>>7),e+=f,t+=c,l+=p,n+=u,a+=o.width}else if(t=i<<=16,n=h<<=15,a<0&&(t-=f*a,i-=d*a,n-=p*a,h-=g*a,a=0),e<<=16,l<<=15,r<0&&(e-=c*r,l-=u*r,r=0),f=0;a+=o.width)this.drawGouraudScanline(o.pixels,a,t>>16,i>>16,n>>7,h>>7),t+=f,i+=d,n+=p,h+=g;for(;--s>=0;)this.drawGouraudScanline(o.pixels,a,e>>16,i>>16,l>>7,h>>7),e+=c,i+=d,l+=u,h+=g,a+=o.width}else{for(s-=r,r-=a,a=this.lineOffset[a];--r>=0;a+=o.width)this.drawGouraudScanline(o.pixels,a,i>>16,t>>16,h>>7,n>>7),t+=f,i+=d,n+=p,h+=g;for(;--s>=0;)this.drawGouraudScanline(o.pixels,a,i>>16,e>>16,h>>7,l>>7),e+=c,i+=d,l+=u,h+=g,a+=o.width}};static drawGouraudScanline=(t,e,i,s,r,a)=>{let n=0,l=0;if(this.jagged){let h=0;if(this.clipX){if(h=s-i>3?(a-r)/(s-i):0,s>o.right&&(s=o.right),i<0&&(r-=i*h,i=0),i>=s)return;e+=i,l=s-i>>2,h<<=2}else{if(i>=s)return;e+=i,l=s-i>>2,h=l>0?(a-r)*this.reciprocal15[l]>>15:0}if(0==this.alpha){for(;--l>=0;)n=this.palette[r>>8],r+=h,t[e++]=n,t[e++]=n,t[e++]=n,t[e++]=n;if(l=s-i&3,l>0){n=this.palette[r>>8];do{t[e++]=n}while(--l>0);return}}else{const a=this.alpha,o=256-this.alpha;for(;--l>=0;)n=this.palette[r>>8],r+=h,n=((16711935&n)*o>>8&16711935)+((65280&n)*o>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280);if(l=s-i&3,l>0){n=this.palette[r>>8],n=((16711935&n)*o>>8&16711935)+((65280&n)*o>>8&65280);do{t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280)}while(--l>0)}}return}if(i>=s)return;const h=(a-r)/(s-i);if(this.clipX&&(s>o.right&&(s=o.right),i<0&&(r-=i*h,i=0),i>=s))return;if(e+=i,l=s-i,0==this.alpha){do{t[e++]=this.palette[r>>8],r+=h}while(--l>0);return}const c=this.alpha,f=256-this.alpha;do{n=this.palette[r>>8],r+=h,n=((16711935&n)*f>>8&16711935)+((65280&n)*f>>8&65280),t[e++]=n+((16711935&t[e])*c>>8&16711935)+((65280&t[e])*c>>8&65280)}while(--l>0)};static fillTriangle=()=>{};static fillTexturedTriangle=()=>{}}class A{vertexCount=0;faceCount=0;texturedFaceCount=0;vertexFlagsOffset=-1;vertexXOffset=-1;vertexYOffset=-1;vertexZOffset=-1;vertexLabelsOffset=-1;faceVerticesOffset=-1;faceOrientationsOffset=-1;faceColorsOffset=-1;faceInfosOffset=-1;facePrioritiesOffset=0;faceAlphasOffset=-1;faceLabelsOffset=-1;faceTextureAxisOffset=-1}class S{x=0;y=0;z=0;w=0}class k{static metadata=null;static head=null;static face1=null;static face2=null;static face3=null;static face4=null;static face5=null;static point1=null;static point2=null;static point3=null;static point4=null;static point5=null;static vertex1=null;static vertex2=null;static axis=null;static faceClippedX=new Array(4096);static faceNearClipped=new Array(4096);static vertexScreenX=new Int32Array(4096);static vertexScreenY=new Int32Array(4096);static vertexScreenZ=new Int32Array(4096);static vertexViewSpaceX=new Int32Array(4096);static vertexViewSpaceY=new Int32Array(4096);static vertexViewSpaceZ=new Int32Array(4096);static tmpDepthFaceCount=new Int32Array(1500);static tmpDepthFaces=new Array(1500).fill(null).map((()=>new Int32Array(512)));static tmpPriorityFaceCount=new Int32Array(12);static tmpPriorityFaces=new Array(12).fill(null).map((()=>new Int32Array(2e3)));static tmpPriority10FaceDepth=new Int32Array(2e3);static tmpPriority11FaceDepth=new Int32Array(2e3);static tmpPriorityDepthSum=new Int32Array(12);static clippedX=new Int32Array(10);static clippedY=new Int32Array(10);static clippedColor=new Int32Array(10);static baseX=0;static baseY=0;static baseZ=0;static checkHover=!1;static mouseX=0;static mouseZ=0;static pickedCount=0;static pickedBitsets=new Int32Array(1e3);static unpack(t){try{k.head=new e(t.read("ob_head.dat")),k.face1=new e(t.read("ob_face1.dat")),k.face2=new e(t.read("ob_face2.dat")),k.face3=new e(t.read("ob_face3.dat")),k.face4=new e(t.read("ob_face4.dat")),k.face5=new e(t.read("ob_face5.dat")),k.point1=new e(t.read("ob_point1.dat")),k.point2=new e(t.read("ob_point2.dat")),k.point3=new e(t.read("ob_point3.dat")),k.point4=new e(t.read("ob_point4.dat")),k.point5=new e(t.read("ob_point5.dat")),k.vertex1=new e(t.read("ob_vertex1.dat")),k.vertex2=new e(t.read("ob_vertex2.dat")),k.axis=new e(t.read("ob_axis.dat")),k.head.pos=0,k.point1.pos=0,k.point2.pos=0,k.point3.pos=0,k.point4.pos=0,k.vertex1.pos=0,k.vertex2.pos=0;const i=k.head.g2;k.metadata=new Array(i+100);let s=0,r=0,a=0,n=0,o=0,l=0,h=0;for(let t=0;t127&&(e=127),127-e):((e=e*(127&t)>>7)<2?e=2:e>126&&(e=126),(65408&t)+e)}vertexCount=0;vertexX=null;vertexY=null;vertexZ=null;faceCount=0;faceVertexA=null;faceVertexB=null;faceVertexC=null;faceColorA=null;faceColorB=null;faceColorC=null;faceInfo=null;facePriority=null;faceAlpha=null;faceColor=null;priority=0;texturedFaceCount=0;texturedVertexA=null;texturedVertexB=null;texturedVertexC=null;minX=0;maxX=0;minZ=0;maxZ=0;radius=0;minY=0;maxY=0;maxDepth=0;minDepth=0;objRaise=0;vertexLabel=null;faceLabel=null;labelVertices=null;labelFaces=null;pickable=!1;vertexNormal=null;vertexNormalOriginal=null;constructor(t){if(null===k.head||null===k.face1||null===k.face2||null===k.face3||null===k.face4||null===k.face5||null===k.point1||null===k.point2||null===k.point3||null===k.point4||null===k.point5||null===k.vertex1||null===k.vertex2||null===k.axis)return;if(null===k.metadata)return;const e=k.metadata[t];if(void 0===e)return void console.log(`Error model:${t} not found!`);this.vertexCount=e.vertexCount,this.faceCount=e.faceCount,this.texturedFaceCount=e.texturedFaceCount,this.vertexX=new Int32Array(this.vertexCount),this.vertexY=new Int32Array(this.vertexCount),this.vertexZ=new Int32Array(this.vertexCount),this.faceVertexA=new Int32Array(this.faceCount),this.faceVertexB=new Int32Array(this.faceCount),this.faceVertexC=new Int32Array(this.faceCount),this.texturedVertexA=new Int32Array(this.texturedFaceCount),this.texturedVertexB=new Int32Array(this.texturedFaceCount),this.texturedVertexC=new Int32Array(this.texturedFaceCount),e.vertexLabelsOffset>=0&&(this.vertexLabel=new Int32Array(this.vertexCount)),e.faceInfosOffset>=0&&(this.faceInfo=new Int32Array(this.faceCount)),e.facePrioritiesOffset>=0?this.facePriority=new Int32Array(this.faceCount):this.priority=-e.facePrioritiesOffset-1,e.faceAlphasOffset>=0&&(this.faceAlpha=new Int32Array(this.faceCount)),e.faceLabelsOffset>=0&&(this.faceLabel=new Int32Array(this.faceCount)),this.faceColor=new Int32Array(this.faceCount),k.point1.pos=e.vertexFlagsOffset,k.point2.pos=e.vertexXOffset,k.point3.pos=e.vertexYOffset,k.point4.pos=e.vertexZOffset,k.point5.pos=e.vertexLabelsOffset;let i,s,r,a=0,n=0,o=0;for(let t=0;tthis.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)+.99),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsY(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.minY=0;for(let t=0;tthis.maxY&&(this.maxY=-e),e>this.minY&&(this.minY=e)}this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsAABB(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.radius=0,this.minY=0,this.minX=999999,this.maxX=-999999,this.maxZ=-99999,this.minZ=99999;for(let t=0;tthis.maxX&&(this.maxX=e),sthis.maxZ&&(this.maxZ=s),-i>this.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY))}}createLabelReferences(){}applyTransform(t){}rotateY90(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let t=0;t>16;this.vertexZ[t]=this.vertexY[t]*e+this.vertexZ[t]*i>>16,this.vertexY[t]=s}}translate(t,e,i){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let s=0;s>8;if(null!==this.faceColorA&&null!==this.faceColorB&&null!==this.faceColorC||(this.faceColorA=new Int32Array(this.faceCount),this.faceColorB=new Int32Array(this.faceCount),this.faceColorC=new Int32Array(this.faceCount)),null===this.vertexNormal){this.vertexNormal=new Array(this.vertexCount);for(let t=0;t8192||m>8192||w>8192||g<-8192||m<-8192||w<-8192;)g>>=1,m>>=1,w>>=1;let x=Math.sqrt(g*g+m*m+w*w);if(x<=0&&(x=1),g=256*g/x,m=256*m/x,w=256*w/x,null===this.faceInfo||0==(1&this.faceInfo[e])){let t=this.vertexNormal[a];t.x+=g,t.y+=m,t.z+=w,t.w++,t=this.vertexNormal[o],t.x+=g,t.y+=m,t.z+=w,t.w++,t=this.vertexNormal[l],t.x+=g,t.y+=m,t.z+=w,t.w++}else{const a=t+(i*g+s*m+r*w)/(n+n/2);this.faceColorA[e]=k.mulColorLightness(this.faceColor[e],a,this.faceInfo[e])}}if(a)this.applyLighting(t,e,i,s,r);else{this.vertexNormalOriginal=new Array(this.vertexCount);for(let t=0;t>16;for(let s=0;s>16,x=x*d-w*f>>16,w=m),0!==t&&(m=x*l-y*o>>16,y=x*o+y*l>>16,x=m),0!==e&&(m=y*h+w*c>>16,y=y*c-w*h>>16,w=m),w+=r,x+=a,y+=n,m=x*p-y*u>>16,y=x*u+y*p>>16,x=m,k.vertexScreenX[s]=b.centerX+(w<<9)/y,k.vertexScreenY[s]=b.centerY+(x<<9)/y,k.vertexScreenZ[s]=y-g,this.texturedFaceCount>0&&(k.vertexViewSpaceX[s]=w,k.vertexViewSpaceY[s]=x,k.vertexViewSpaceZ[s]=y)}this.draw2(!1,!1,0)}draw(t,e,i,s,r,a,n,o,l){}draw2(t,e,i){if(null===k.vertexScreenX||null===k.vertexScreenY||null===k.vertexScreenZ)return;if(null===k.vertexViewSpaceX||null===k.vertexViewSpaceY||null===k.vertexViewSpaceZ)return;if(null===k.faceNearClipped||null===k.faceClippedX)return;if(null===k.tmpDepthFaceCount||null===k.tmpDepthFaces||null===k.tmpPriorityFaces||null===k.tmpPriorityFaceCount||null===k.tmpPriorityDepthSum||null===k.tmpPriority10FaceDepth||null===k.tmpPriority11FaceDepth)return;if(null===this.faceVertexA||null===this.faceVertexB||null===this.faceVertexC)return;for(let t=0;to.boundX||h>o.boundX||c>o.boundX;const u=Math.trunc((k.vertexScreenZ[r]+k.vertexScreenZ[a]+k.vertexScreenZ[n])/3+this.minDepth);k.tmpDepthFaces[u][k.tmpDepthFaceCount[u]++]=s}else{k.faceNearClipped[s]=!0;const t=Math.trunc((k.vertexScreenZ[r]+k.vertexScreenZ[a]+k.vertexScreenZ[n])/3+this.minDepth);k.tmpDepthFaces[t][k.tmpDepthFaceCount[t]++]=s}}if(null==this.facePriority){for(let t=this.maxDepth-1;t>=0;t--){const e=k.tmpDepthFaceCount[t];if(e<=0)continue;const i=k.tmpDepthFaces[t];for(let t=0;t=0;t--){const e=k.tmpDepthFaceCount[t];if(e>0){const i=k.tmpDepthFaces[t];for(let s=0;s0||k.tmpPriorityFaceCount[2]>0)&&(s=Math.trunc((k.tmpPriorityDepthSum[1]+k.tmpPriorityDepthSum[2])/(k.tmpPriorityFaceCount[1]+k.tmpPriorityFaceCount[2])));let r=0;(k.tmpPriorityFaceCount[3]>0||k.tmpPriorityFaceCount[4]>0)&&(r=Math.trunc((k.tmpPriorityDepthSum[3]+k.tmpPriorityDepthSum[4])/(k.tmpPriorityFaceCount[3]+k.tmpPriorityFaceCount[4])));let a=0;(k.tmpPriorityFaceCount[6]>0||k.tmpPriorityFaceCount[8]>0)&&(a=Math.trunc((k.tmpPriorityDepthSum[6]+k.tmpPriorityDepthSum[8])/(k.tmpPriorityFaceCount[6]+k.tmpPriorityFaceCount[8])));let n,l=0,h=k.tmpPriorityFaceCount[10],c=k.tmpPriorityFaces[10],f=k.tmpPriority10FaceDepth;l==h&&(l=0,h=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),n=ls;)this.drawFace(c[l++]),l==h&&c!=k.tmpPriorityFaces[11]&&(l=0,h=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),n=lr;)this.drawFace(c[l++]),l==h&&c!=k.tmpPriorityFaces[11]&&(l=0,h=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),n=la;)this.drawFace(c[l++]),l==h&&c!=k.tmpPriorityFaces[11]&&(l=0,h=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),n=la&&e>n&&e>o||t{const r=new e(t.read("data"));let a=-1;for(r.pos+=2;r.pos0){e.scriptComparator=new Uint8Array(n).fill(0),e.scriptOperand=new Uint16Array(n).fill(0);for(let t=0;t0){e.scripts=new Array(o).fill(null);for(let t=0;t0){const r=s.lastIndexOf(",");e.inventorySlotImage[t]=g.fromArchive(i,s,r)}}for(let t=0;t<5;t++)e.inventoryOptions[t]=r.gjstr,0===e.inventoryOptions[t]?.length&&(e.inventoryOptions[t]=null);e.spellAction=r.gjstr,e.spellName=r.gjstr,e.spellFlags=r.g2;break;case P.TYPE_RECT:e.fill=1===r.g1,e.color=r.g4,e.activeColor=r.g4,e.hoverColor=r.g4;break;case P.TYPE_TEXT:e.center=1===r.g1,e.font=s[r.g1],e.shadow=1===r.g1,e.text=r.gjstr,e.activeText=r.gjstr,e.color=r.g4,e.activeColor=r.g4,e.hoverColor=r.g4;break;case P.TYPE_SPRITE:{const t=r.gjstr;if(t.length>0){const s=t.lastIndexOf(",");e.image=g.fromArchive(i,t.substring(0,s),parseInt(t.substring(s+1)))}const s=r.gjstr;if(s.length>0){const t=s.lastIndexOf(",");e.image=g.fromArchive(i,s.substring(0,t),parseInt(s.substring(t+1)))}break}case P.TYPE_MODEL:{const t=r.g1;0!==t&&(e.model=this.getModel((t-1<<8)+r.g1));const i=r.g1;0!==i&&(e.activeModel=this.getModel((i-1<<8)+r.g1)),e.seqId=r.g1,0==e.seqId?e.seqId=-1:e.seqId=(e.seqId-1<<8)+r.g1,e.activeSeqId=r.g1,0==e.activeSeqId?e.activeSeqId=-1:e.activeSeqId=(e.activeSeqId-1<<8)+r.g1,e.modelZoom=r.g2,e.modelPitch=r.g2,e.modelYaw=r.g2;break}case P.TYPE_INVENTORY_TEXT:e.inventorySlotObjId=new Int32Array(e.width*e.height),e.inventorySlotObjCount=new Int32Array(e.width*e.height),e.center=1===r.g1,e.font=s[r.g1],e.shadow=1===r.g1,e.color=r.g4,e.inventoryMarginX=r.g2b,e.inventoryMarginY=r.g2b,e.inventoryInteractable=1===r.g1,e.inventoryOptions=new Array(5).fill(null);for(let t=0;t<5;t++)e.inventoryOptions[t]=r.gjstr}2!=e.optionType&&2!=e.type||(e.spellAction=r.gjstr,e.spellName=r.gjstr,e.spellFlags=r.g2),1!=e.optionType&&4!=e.optionType&&5!=e.optionType&&6!=e.optionType||(e.option=r.gjstr,0==e.option.length&&(1==e.optionType?e.option="Ok":4==e.optionType||5==e.optionType?e.option="Select":6==e.optionType&&(e.option="Continue")))}};static get=t=>P.instances[t];static getModel=t=>new k(t);id=-1;parentId=-1;type=-1;optionType=-1;contentType=0;width=0;height=0;delegateHover=-1;scriptComparator=null;scriptOperand=null;scripts=null;scrollableHeight=0;hide=!1;inventoryDraggable=!1;inventoryInteractable=!1;inventoryUsable=!1;inventoryMarginX=0;inventoryMarginY=0;inventorySlotOffsetX=null;inventorySlotOffsetY=null;inventorySlotImage=null;inventoryOptions=[];fill=!1;center=!1;font=null;shadow=!1;text=null;activeText=null;color=0;activeColor=0;hoverColor=0;image=null;activeImage=null;model=null;activeModel=null;seqId=-1;activeSeqId=-1;modelZoom=0;modelPitch=0;modelYaw=0;spellAction=null;spellName=null;spellFlags=-1;option=null;childId=null;childX=null;childY=null;x=0;y=0;scrollPosition=0;inventorySlotObjId=null;inventorySlotObjCount=null;seqFrame=0;getModel=(t,e,i)=>{let s=this.model;return i&&(s=this.activeModel),null==s?null:-1==t&&-1==e&&null==s.faceColor?s:null}}class I{static CHARSET=[];static{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";for(let e=0;e<256;e++){let i=t.indexOf(String.fromCharCode(e));-1===i&&(i=74),I.CHARSET[e]=i}}pixels=[];charWidth=[];charHeight=[];clipX=[];clipY=[];charSpace=[];drawWidth=[];fontHeight=-1;static fromArchive=(t,i)=>{const s=new e(t.read(i+".dat")),r=new e(t.read("index.dat"));r.pos=s.g2+4;const a=r.g1;a>0&&(r.pos+=3*(a-1));const n=new I;for(let t=0;t<94;t++){n.clipX[t]=r.g1,n.clipY[t]=r.g1;const e=n.charWidth[t]=r.g2,i=n.charHeight[t]=r.g2,a=e*i;n.pixels[t]=new Uint8Array(a);const o=r.g1;if(0===o)for(let r=0;rn.fontHeight&&(n.fontHeight=i),n.clipX[t]=1,n.charSpace[t]=e+2;{let s=0;for(let r=i/7;r{t|=0,e|=0;const r=i.length;e-=this.fontHeight;for(let a=0;a{t|=0,e|=0;const a=i.length;e-=this.fontHeight;for(let n=0;n{const e=t.length;let i=0;for(let s=0;s{const r=e-this.fontHeight;for(let e=0;e{this.drawStringTaggable(t-this.stringWidth(i)/2,e,i,s,r)};drawStringCenter=(t,e,i,s)=>{this.draw(t-this.stringWidth(i)/2,e,i,s)};drawRight=(t,e,i,s,r=!0)=>{r&&this.draw(t-this.stringWidth(i)+1,e+1,i,0),this.draw(t-this.stringWidth(i),e,i,s)};drawChar=(t,e,i,s,r,a)=>{s|=0,r|=0;let n=(e|=0)+(i|=0)*o.width,l=o.width-s,h=0,c=0;if(i=o.bottom&&(r-=i+r+1-o.bottom),e=o.right){const t=e+s+1-o.right;s-=t,h+=t,l+=t}s>0&&r>0&&this.drawMask(s,r,t,c,h,o.pixels,n,l,a)};drawMask=(t,e,i,s,r,a,n,o,l)=>{const h=-((t|=0)>>2);t=-(3&t);for(let c=-(e|=0);c<0;c++){for(let t=h;t<0;t++)0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l;for(let e=t;e<0;e++)0==i[s++]?n++:a[n++]=l;n+=o,s+=r}};copyCharacter=(t,e,i,s,r,a)=>{i|=0,s|=0;let n=(t|=0)+(e|=0)*o.width,l=0,h=o.width-i,c=0;if(eo.bottom&&(s-=e+s+1-o.bottom),to.right){const e=t+i+1-o.right;i-=e,c+=e,h+=e}i>0&&s>0&&this.copyImageMasked(i,s,r,l,c,o.pixels,n,h,a)};copyImageMasked=(t,e,i,s,r,a,n,o,l)=>{for(let h=0;h{switch(t){case"red":return 16711680;case"gre":return 65280;case"blu":return 255;case"yel":return 16776960;case"cya":return 65535;case"mag":return 16711935;case"whi":return 16777215;case"bla":default:return 0;case"lre":return 16748608;case"dre":return 8388608;case"dbl":return 128;case"or1":return 16756736;case"or2":return 16740352;case"or3":return 16723968;case"gr1":return 12648192;case"gr2":return 8453888;case"gr3":return 4259584}}}class Y{static loadUrl=async t=>new Y(await u(t));static genHash=t=>{let e=0;t=t.toUpperCase();for(let i=0;i>>0;return e};buffer;compressedWhole;fileCount;fileHash;fileSizeInflated;fileSizeDeflated;fileOffset;constructor(t){const i=new e(t),s=i.g3;let r;if(s==i.g3)r=i,this.compressedWhole=!1;else{const t=i.gdata(i.pos,s);r=new e(new Uint8Array(p(t))),this.compressedWhole=!0}this.buffer=r,this.fileCount=r.g2,this.fileHash=[],this.fileSizeInflated=[],this.fileSizeDeflated=[],this.fileOffset=[];let a=r.pos+10*this.fileCount;for(let t=0;t{const e=Y.genHash(t),i=this.fileHash.indexOf(e);return-1==i?null:this.readIndex(i)};readIndex=t=>{if(t<0||t>=this.fileCount)return null;if(this.compressedWhole)return this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);{const e=this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);return p(e)}}}class O{static PERIOD=new Uint16Array(["d","o","t"].join("").split("").map((t=>t.charCodeAt(0))));static AMPERSAT=new Uint16Array(["(","a",")"].join("").split("").map((t=>t.charCodeAt(0))));static SLASH=new Uint16Array(["s","l","a","s","h"].join("").split("").map((t=>t.charCodeAt(0))));static whitelist=["cook","cook's","cooks","seeks","sheet"];static tlds=[];static tldTypes=[];static bads=[];static badCombinations=[];static domains=[];static fragments=[];static unpack=t=>{const i=new e(t.read("fragmentsenc.txt")),s=new e(t.read("badenc.txt")),r=new e(t.read("domainenc.txt")),a=new e(t.read("tldlist.txt"));this.read(s,r,i,a)};static filter=t=>{const e=[...t];this.format(e);const i=e.join("").trim(),s=i.toLowerCase(),r=[...s];this.filterTlds(r),this.filterBadWords(r),this.filterDomains(r),this.filterFragments(r);for(let t=0;t{this.readBadWords(t),this.readDomains(e),this.readFragments(i),this.readTld(s)};static readTld=t=>{const e=t.g4;for(let i=0;it.g1))};static readBadWords=t=>{const e=t.g4;for(let i=0;it.g1));const e=new Array(t.g1).fill([]).map((()=>[t.g1b,t.g1b]));e.length>0&&(this.badCombinations[i]=e)}};static readDomains=t=>{const e=t.g4;for(let i=0;it.g1))};static readFragments=t=>{const e=t.g4;for(let i=0;i{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.PERIOD),this.filterBadCombinations(null,i,this.SLASH);for(let s=0;s{for(let e=0;e<2;e++)for(let e=this.bads.length-1;e>=0;e--)this.filterBadCombinations(this.badCombinations[e],t,this.bads[e])};static filterDomains=t=>{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.AMPERSAT),this.filterBadCombinations(null,i,this.PERIOD);for(let s=this.domains.length-1;s>=0;s--)this.filterDomain(i,e,this.domains[s],t)};static filterFragments=t=>{for(let e=0;e=0&&r{if(this.isNumericalChars(t))return!0;const e=this.getInteger(t),i=this.fragments,s=i.length;if(e===i[0]||e===i[s-1])return!0;let r=0,a=s-1;for(;r<=a;){const t=Math.floor((r+a)/2);if(e===i[t])return!0;e{if(t.length>6)return 0;let e=0;for(let i=0;i{for(let i=e;i=0;i++)if(this.isNumerical(t[i]))return i;return-1};static indexOfNonNumber=(t,e)=>{for(let i=t;i=0;i++)if(!this.isNumerical(e[i]))return i;return e.length};static getEmulatedDomainCharLen=(t,e,i)=>e==i||"o"==e&&"0"==i?1:"o"==e&&"("==i&&")"==t?2:"c"!=e||"("!=i&&"<"!=i&&"["!=i?"e"==e&&"€"==i||"s"==e&&"$"==i||"l"==e&&"i"==i?1:0:1;static filterDomain=(t,e,i,s)=>{const r=i.length,a=s.length;for(let n=0;n<=a-r;n++){const{matched:r,currentIndex:a}=this.findMatchingDomain(n,i,s);if(!r)continue;const o=this.prefixSymbolStatus(n,s,3,e,["@"]),l=this.suffixSymbolStatus(a-1,s,3,t,[".",","]);(o>2||l>2)&&this.maskChars(n,a,s)}};static findMatchingDomain=(t,e,i)=>{const s=e.length;let r=t,a=0;for(;r0)r+=l,a++;else{if(0===a)break;const i=this.getEmulatedDomainCharLen(o,String.fromCharCode(e[a-1]),n);if(i>0)r+=i,1===a&&t++;else{if(a>=s||!this.isSymbol(n))break;r++}}}return{matched:a>=s,currentIndex:r}};static filterBadCombinations=(t,e,i)=>{if(!(i.length>e.length))for(let s=0;s<=e.length-i.length;s++){let r=s;const{currentIndex:a,badIndex:n,hasSymbol:o,hasNumber:l,hasDigit:h}=this.processBadCharacters(e,i,r);r=a;let c=e[r],f=r+1=i.length)||l&&h)continue;let d,u=!0;if(o){let t=!1,i=!1;if((s-1<0||this.isSymbol(e[s-1])&&"'"!=e[s-1])&&(t=!0),(r>=e.length||this.isSymbol(e[r])&&"'"!=e[r])&&(i=!0),!t||!i){let i=!1;for(d=s-2,t&&(d=s);!i&&d=0&&(!this.isSymbol(e[d])||"'"==e[d])){const t=[];let s;for(s=0;s<3&&d+s=0&&(!this.isSymbol(e[d-1])||"'"==e[d-1])&&(r=!1),r&&!this.isBadFragment(t)&&(i=!0)}d++}i||(u=!1)}}else{c=" ",s-1>=0&&(c=e[s-1]),f=" ",r{let s=i,r=0,a=0,n=!1,o=!1,l=!1;for(;s=t.length||o&&l);){const h=t[s],c=s+10)1===f&&this.isNumerical(h)&&(o=!0),2===f&&(this.isNumerical(h)||this.isNumerical(c))&&(o=!0),s+=f,r++;else{if(0===r)break;let t;if((t=this.getEmulatedBadCharLen(c,String.fromCharCode(e[r-1]),h))>0)s+=t;else{if(r>=e.length||!this.isNotLowercaseAlpha(h))break;if(this.isSymbol(h)&&"'"!==h&&(n=!0),this.isNumerical(h)&&(l=!0),s++,a++,100*a/(s-i)>90)break}}}return{currentIndex:s,badIndex:r,hasSymbol:n,hasNumber:o,hasDigit:l}};static getEmulatedBadCharLen=(t,e,i)=>{if(e==i)return 1;if(e>="a"&&e<="m"){if("a"==e)return"4"!=i&&"@"!=i&&"^"!=i?"/"==i&&"\\"==t?2:0:1;if("b"==e)return"6"!=i&&"8"!=i?"1"==i&&"3"==t?2:0:1;if("c"==e)return"("!=i&&"<"!=i&&"{"!=i&&"["!=i?0:1;if("d"==e)return"["==i&&")"==t?2:0;if("e"==e)return"3"!=i&&"€"!=i?0:1;if("f"==e)return"p"==i&&"h"==t?2:"£"==i?1:0;if("g"==e)return"9"!=i&&"6"!=i?0:1;if("h"==e)return"#"==i?1:0;if("i"==e)return"y"!=i&&"l"!=i&&"j"!=i&&"1"!=i&&"!"!=i&&":"!=i&&";"!=i&&"|"!=i?0:1;if("j"==e)return 0;if("k"==e)return 0;if("l"==e)return"1"!=i&&"|"!=i&&"i"!=i?0:1;if("m"==e)return 0}if(e>="n"&&e<="z"){if("n"==e)return 0;if("o"==e)return"0"!=i&&"*"!=i?"("==i&&")"==t||"["==i&&"]"==t||"{"==i&&"}"==t||"<"==i&&">"==t?2:0:1;if("p"==e)return 0;if("q"==e)return 0;if("r"==e)return 0;if("s"==e)return"5"!=i&&"z"!=i&&"$"!=i&&"2"!=i?0:1;if("t"==e)return"7"!=i&&"+"!=i?0:1;if("u"==e)return"v"==i?1:"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("v"==e)return"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("w"==e)return"v"==i&&"v"==t?2:0;if("x"==e)return")"==i&&"("==t||"}"==i&&"{"==t||"]"==i&&"["==t||">"==i&&"<"==t?2:0;if("y"==e)return 0;if("z"==e)return 0}return e>="0"&&e<="9"?"0"==e?"o"==i||"O"==i?1:"("==i&&")"==t||"{"==i&&"}"==t||"["==i&&"]"==t?2:0:"1"==e&&"l"==i?1:0:","==e?"."==i?1:0:"."==e?","==i?1:0:"!"==e&&"i"==i?1:0};static comboMatches=(t,e,i)=>{let s=0,r=e.length-1;for(;s<=r;){const a=Math.floor((s+r)/2);if(e[a][0]===t&&e[a][1]===i)return!0;tthis.isLowercaseAlpha(t)?t.charCodeAt(0)+1-"a".charCodeAt(0):"'"==t?28:this.isNumerical(t)?t.charCodeAt(0)+29-"0".charCodeAt(0):27;static filterTld=(t,e,i,s,r)=>{if(!(s.length>i.length))for(let a=0;a<=i.length-s.length;a++){const{currentIndex:n,tldIndex:o}=this.processTlds(i,s,a);if(o0&&c>0&&(l=!0),2==e&&(h>2&&c>0||h>0&&c>2)&&(l=!0),3==e&&h>0&&c>2&&(l=!0),!l)continue;let f,d=a,u=n-1,p=!1;if(h>2){if(4==h)for(p=!1,f=a-1;f>=0;f--)if(p){if("*"!=r[f])break;d=f}else"*"==r[f]&&(d=f,p=!0);for(p=!1,f=d-1;f>=0;f--)if(p){if(this.isSymbol(i[f]))break;d=f}else this.isSymbol(i[f])||(p=!0,d=f)}if(c>2){if(4==c)for(p=!1,f=u+1;f{let s=0;for(;i0)i+=n,s++;else{if(0===s)break;let t;if((t=this.getEmulatedDomainCharLen(a,String.fromCharCode(e[s-1]),r))>0)i+=t;else{if(!this.isSymbol(r))break;i++}}}return{currentIndex:i,tldIndex:s}};static isSymbol=t=>!this.isAlpha(t)&&!this.isNumerical(t);static isNotLowercaseAlpha=t=>!this.isLowercaseAlpha(t)||"v"==t||"x"==t||"j"==t||"q"==t||"z"==t;static isAlpha=t=>this.isLowercaseAlpha(t)||this.isUppercaseAlpha(t);static isNumerical=t=>t>="0"&&t<="9";static isLowercaseAlpha=t=>t>="a"&&t<="z";static isUppercaseAlpha=t=>t>="A"&&t<="Z";static isNumericalChars=t=>{for(let e=0;e{for(let s=t;s{let i=0;for(let s=e-1;s>=0&&this.isSymbol(t[s]);s--)"*"===t[s]&&i++;return i};static maskedCountForwards=(t,e)=>{let i=0;for(let s=e+1;s(r?this.maskedCountBackwards(e,i):this.maskedCountForwards(e,i))>=s?4:this.isSymbol(r?t[i-1]:t[i+1])?1:0;static prefixSymbolStatus=(t,e,i,s,r)=>{if(0===t)return 2;for(let i=t-1;i>=0&&this.isSymbol(e[i]);i--)if(r.includes(e[i]))return 3;return this.maskedCharsStatus(e,s,t,i,!0)};static suffixSymbolStatus=(t,e,i,s,r)=>{if(t+1===e.length)return 2;for(let i=t+1;i{let e=0;for(let i=0;it>=" "&&t<=""||" "==t||"\n"==t||"\t"==t||"£"==t||"€"==t;static replaceUppercases=(t,e)=>{for(let i=0;i{let e=!0;for(let i=0;i{this.pixels.fill(0)};bind=()=>{o.bind(this.pixels,this.width,this.height)};draw=(t,e)=>{this.#t(),this.ctx.putImageData(this.image,t,e)};#t=()=>{const t=this.image.data;for(let e=0;e>16&255,t[s+1]=i>>8&255,t[s+2]=i>>0&255,t[s+3]=255}}}class X{static getParameter(t){return new URLSearchParams(window.location.search).get(t)??""}static setParameter(t,e){const i=new URL(window.location.toString());i.searchParams.set(t,e),window.history.pushState(null,"",i.toString())}canvas;ctx;drawArea=null;state=0;deltime=20;mindel=1;otim=[];fps=0;fpos=0;frameTime=[];redrawScreen=!0;resizeToFit=!1;idleCycles=0;mouseButton=0;mouseX=0;mouseY=0;mouseClickButton=0;mouseClickX=0;mouseClickY=0;actionKey=[];keyQueue=[];keyQueueReadPos=0;keyQueueWritePos=0;constructor(t=!1){const e=document.getElementById("canvas");if(!e)throw new Error("Canvas not found!!!!!!!!");const i=e.getContext("2d");if(!i)throw new Error("Canvas 2d not found!!!!!!!!");this.canvas=e,this.ctx=i,this.resizeToFit=t,this.resizeToFit?this.resize(window.innerWidth,window.innerHeight):this.resize(e.width,e.height)}get width(){return this.canvas.width}get height(){return this.canvas.height}resize(t,e){const i=this.canvas;i.width=t,i.height=e,this.drawArea=new T(i,t,e),b.init2D()}async run(){window.addEventListener("resize",(()=>{this.resizeToFit&&this.resize(window.innerWidth,window.innerHeight)}),!1),window.addEventListener("keydown",this.keyDown),window.addEventListener("keyup",this.keyUp),window.addEventListener("mousedown",this.mousePressed),await this.showProgress(0,"Loading..."),await this.load();for(let t=0;t<10;t++)this.otim[t]=Date.now();let t,e=0,i=256,s=1,r=0;for(;this.state>=0;){if(this.state>0&&(this.state--,0===this.state))return void this.shutdown();const a=i,n=s;i=300,s=1,t=Date.now();const o=this.otim[e];if(0===o?(i=a,s=n):t>o&&(i=Math.trunc(2560*this.deltime/(t-o))),i<25?i=25:i>256&&(i=256,s=Math.trunc(this.deltime-(t-o)/10)),this.otim[e]=t,e=(e+1)%10,s>1)for(let t=0;t<10;t++)0!==this.otim[t]&&(this.otim[t]+=s);for(s0&&(this.fps=Math.trunc(1e3*i/(256*this.deltime)));const l=performance.now();await this.draw(),this.frameTime[this.fpos]=(performance.now()-l)/1e3,this.fpos=(this.fpos+1)%this.frameTime.length}-1==this.state&&this.shutdown()}shutdown(){this.state=-2,this.unload()}setLoopRate(t){this.deltime=1e3/t}start(){this.state>=0&&(this.state=0)}stop(){this.state>=0&&(this.state=4e3/this.deltime)}destroy(){this.state=-1}async load(){}update(){}unload(){}async draw(){}refresh(){}async showProgress(t,e){const i=this.ctx,s=this.width,r=this.height;this.redrawScreen&&(i.fillStyle="black",i.clearRect(0,0,s,r),this.redrawScreen=!1);const a=r/2-18;i.fillStyle="rgb(140, 17, 17)",i.rect(s/2-152,a,304,34),i.fillRect(s/2-150,a+2,3*t,30),i.fillStyle="black",i.fillRect(s/2-150+3*t,a+2,300-3*t,30),i.font="bold 13px helvetica, sans-serif",i.textAlign="center",i.fillStyle="white",i.fillText(e,s/2,a+22),await d(5)}keyDown=t=>{this.idleCycles=0;const e=t.keyCode;let i=t.key.charCodeAt(0);83!==i&&(i<30&&(i=0),37==e?i=1:39==e?i=2:38==e?i=3:40==e?i=4:17==e?i=5:8==e||127==e?i=8:9==e?i=9:10==e?i=10:e>=112&&e<=123?i=e+1008-112:36==e?i=1e3:35==e?i=1001:33==e?i=1002:34==e&&(i=1003),i>0&&i<128&&(this.actionKey[i]=1),i>4&&(this.keyQueue[this.keyQueueWritePos]=i,this.keyQueueWritePos=this.keyQueueWritePos+1&127))};keyUp=t=>{this.idleCycles=0;let e=t.key.charCodeAt(0);"ArrowLeft"==t.key?e=1:"ArrowRight"==t.key?e=2:"ArrowUp"==t.key?e=3:"ArrowDown"==t.key&&(e=4),this.actionKey[e]=0};pollKey(){let t=-1;return this.keyQueueWritePos!=this.keyQueueReadPos&&(t=this.keyQueue[this.keyQueueReadPos],this.keyQueueReadPos=this.keyQueueReadPos+1&127),t}mousePressed=t=>{let e=t.x,i=t.y;const{top:s,left:r}=this.getInsets;e-=r,i-=s,this.idleCycles=0,this.mouseClickX=e,this.mouseClickY=i,2===t.buttons?(this.mouseClickButton=2,this.mouseButton=2):1===t.buttons&&(this.mouseClickButton=1,this.mouseButton=1)};get getInsets(){const t=this.canvas.getBoundingClientRect(),e=window.getComputedStyle(this.canvas),i=parseFloat(e.paddingLeft||"0"),s=parseFloat(e.paddingTop||"0"),r=parseFloat(e.borderLeftWidth||"0"),a=parseFloat(e.borderTopWidth||"0"),n=t.left+r+i;return{top:t.top+a+s,left:n}}get ms(){const t=this.frameTime.length;let e=0;for(let i=0;i{}}class D extends X{static HOST="https://w2.225.2004scape.org";static REPO="https://raw.githubusercontent.com/2004scape/Server/main";alreadyStarted=!1;errorStarted=!1;errorLoading=!1;errorHost=!1;loopCycle=0;ingame=!1;archiveChecksums=[];fontPlain11=null;fontPlain12=null;fontBold12=null;fontQuill8=null;packfiles=[];inputSpeedMultiplier=2;model={id:parseInt(X.getParameter("model"))||0,pitch:parseInt(X.getParameter("x"))||0,yaw:parseInt(X.getParameter("y"))||0,roll:parseInt(X.getParameter("z"))||0,built:null};camera={x:parseInt(X.getParameter("eyeX"))||0,y:parseInt(X.getParameter("eyeY"))||0,z:parseInt(X.getParameter("eyeZ"))||420,pitch:parseInt(X.getParameter("eyePitch"))||0};async loadPack(t){const e=new Map,i=await(async t=>(await fetch(t)).text())(t),s=i.split("\n");for(let t=0;t{if(this.alreadyStarted)this.errorStarted=!0;else{this.alreadyStarted=!0;try{await this.showProgress(10,"Connecting to fileserver");const t=new e(await u(`${D.HOST}/crc`));for(let e=0;e<9;e++)this.archiveChecksums[e]=t.g4;const o=await this.loadArchive("title","title screen",this.archiveChecksums[1],10);this.fontPlain11=I.fromArchive(o,"p11"),this.fontPlain12=I.fromArchive(o,"p12"),this.fontBold12=I.fromArchive(o,"b12"),this.fontQuill8=I.fromArchive(o,"q8");const l=await this.loadArchive("config","config",this.archiveChecksums[2],15),h=await this.loadArchive("interface","interface",this.archiveChecksums[3],20),c=await this.loadArchive("media","2d graphics",this.archiveChecksums[4],30),f=await this.loadArchive("models","3d graphics",this.archiveChecksums[5],40),d=await this.loadArchive("textures","textures",this.archiveChecksums[6],60),p=await this.loadArchive("wordenc","chat system",this.archiveChecksums[7],65),g=await this.loadArchive("sounds","sound effects",this.archiveChecksums[8],70);await this.showProgress(75,"Unpacking media"),await this.showProgress(80,"Unpacking textures"),b.unpackTextures(d),b.setBrightness(.8),b.initPool(20),await this.showProgress(83,"Unpacking models"),k.unpack(f),i.unpack(f),s.unpack(f),await this.showProgress(86,"Unpacking config"),r.unpack(l),a.unpack(l),n.unpack(l),m.unpack(l,!0),w.unpack(l),x.unpack(l),y.unpack(l),v.unpack(l),await this.showProgress(90,"Unpacking sounds"),F.unpack(g),await this.showProgress(92,"Unpacking interfaces"),P.unpack(h,c,[this.fontPlain11,this.fontPlain12,this.fontBold12,this.fontQuill8]),await this.showProgress(97,"Preparing game engine"),O.unpack(p),await this.showProgress(100,"Getting ready to start..."),this.drawArea?.bind(),b.init2D(),await this.showModels()}catch(t){this.errorLoading=!0,console.error(t)}}};update=()=>{this.errorStarted||this.errorLoading||this.errorHost||this.loopCycle++};draw=async()=>{this.errorStarted||this.errorLoading||this.errorHost?this.drawErrorScreen():(o.clear(),o.fillRect(0,0,this.width,this.height,0),null===this.model.built&&(this.model.built=new k(this.model.id)),this.model.built.calculateNormals(64,850,-30,-50,-30,!0),this.model.built.drawSimple(this.model.pitch,this.model.yaw,this.model.roll,this.camera.pitch,this.camera.x,this.camera.y,this.camera.z),this.fontBold12?.drawRight(this.width-1,this.fontBold12.fontHeight,`FPS: ${this.fps}`,16776960),this.fontBold12?.draw(1,this.fontBold12.fontHeight,`ID: ${this.model.id}`,16776960),this.drawArea?.draw(0,0))};showProgress=async(t,e)=>{console.log(`${t}%: ${e}`),await super.showProgress(t,e)};async loadArchive(t,e,i,s){await this.showProgress(s,`Requesting ${e}`);const r=await Y.loadUrl(`${D.HOST}/${t}${i}`);return await this.showProgress(s,`Loading ${e} - 100%`),r}drawErrorScreen(){if(this.ctx&&this.canvas){if(this.ctx.fillStyle="black",this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.setLoopRate(1),this.errorLoading){this.ctx.font="bold 16px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="yellow";let t=35;this.ctx.fillText("Sorry, an error has occured whilst loading RuneScape",30,t),t+=50,this.ctx.fillStyle="white",this.ctx.fillText("To fix this try the following (in order):",30,t),t+=50,this.ctx.font="bold 12px helvetica, sans-serif",this.ctx.fillText("1: Try closing ALL open web-browser windows, and reloading",30,t),t+=30,this.ctx.fillText("2: Try clearing your web-browsers cache from tools->internet options",30,t),t+=30,this.ctx.fillText("3: Try using a different game-world",30,t),t+=30,this.ctx.fillText("4: Try rebooting your computer",30,t),t+=30,this.ctx.fillText("5: Try selecting a different version of Java from the play-game menu",30,t)}if(this.errorHost&&(this.ctx.font="bold 20px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="white",this.ctx.fillText("Error - unable to load game!",50,50),this.ctx.fillText("To play RuneScape make sure you play from",50,100),this.ctx.fillText("https://2004scape.org",50,150)),this.errorStarted){this.ctx.font="bold 13px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="yellow";let t=35;this.ctx.fillText("Error a copy of RuneScape already appears to be loaded",30,t),t+=50,this.ctx.fillStyle="white",this.ctx.fillText("To fix this try the following (in order):",30,t),t+=50,this.ctx.font="bold 12px helvetica, sans-serif",this.ctx.fillText("1: Try closing ALL open web-browser windows, and reloading",30,t),t+=30,this.ctx.fillText("2: Try rebooting your computer, and reloading",30,t)}}}async showModels(){this.packfiles[0]=await this.loadPack(`${D.REPO}/data/pack/model.pack`);const t=document.getElementById("leftPanel");if(t){t.innerHTML="";{const i=document.createElement("input");i.type="search",i.placeholder="Search",i.oninput=()=>{const t=i.value.toLowerCase().replaceAll(" ","_");for(let i=0;i-1?s.style.display="":s.style.display="none"}},t.appendChild(i)}const e=document.createElement("ul");e.className="list-group",t.appendChild(e);for(const[t,i]of this.packfiles[0]){const s=document.createElement("li");s.id=i,s.className="list-group-item",0==t&&(s.className+=" active"),s.innerText=i,s.onclick=()=>{const i=e.querySelector(".active");i&&(i.className="list-group-item"),s.className="list-group-item active",this.model.id=t,this.model.built=new k(this.model.id)},e.appendChild(s)}}}}(new D).run().then((()=>{}))})(); \ No newline at end of file +(()=>{"use strict";class t{index;constructor(t){this.index=t}decodeType=t=>{for(;;){const e=t.g1;if(0===e)break;this.decode(e,t)}}}class e{static crctable=new Int32Array(256);static CRC32_POLYNOMIAL=3988292384;static bitmask=new Uint32Array(33);static{for(let t=0;t<32;t++)e.bitmask[t]=(1<>>1^e.CRC32_POLYNOMIAL:i>>>=1;e.crctable[t]=i}}data;pos;bitPos=0;constructor(t){if(!t)throw new Error("Input src packet array was null!");this.data=t,this.pos=0}static alloc=t=>new e(0===t?new Uint8Array(100):1===t?new Uint8Array(5e3):new Uint8Array(3e4));get g1(){return this.data[this.pos++]}get g1b(){return this.data[this.pos++]<<24>>24}get g2(){return(this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g2b(){return this.data[this.pos++]<<8|this.data[this.pos++]}get g3(){return(this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4(){return(this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++])>>>0}get g4s(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]}get g8(){return BigInt(this.g4)<<32n|BigInt(this.g4)}get gsmart(){return this.data[this.pos]<128?this.g1:this.g2-32768}get gsmarts(){return this.data[this.pos]<128?this.g1-64:this.g2-49152}get gjstr(){let t="";for(;10!=this.data[this.pos]&&this.posthis.data.subarray(t,t+e);p1=t=>{this.data[this.pos++]=t};p2=t=>{this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip2=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8};p3=t=>{this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};p4=t=>{this.data[this.pos++]=t>>>24,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t};ip4=t=>{this.data[this.pos++]=t,this.data[this.pos++]=t>>>8,this.data[this.pos++]=t>>>16,this.data[this.pos++]=t>>>24};p8=t=>{this.p4(Number(t>>32n)),this.p4(Number(0xffffffffn&t))};pjstr=t=>{for(let e=0;e{for(let s=i;s{this.data[this.pos-t-1]=t};bits=()=>{this.bitPos=8*this.pos};bytes=()=>{this.pos=(this.bitPos+7)/8>>>0};gBit=t=>{let i=this.bitPos>>>3,s=8-(7&this.bitPos),r=0;for(this.bitPos+=t;t>s;s=8)r+=(this.data[i++]&e.bitmask[s])<>>s-t&e.bitmask[t],r}}class i{static instances=[];static unpack=t=>{const s=new e(t.read("base_head.dat")),r=new e(t.read("base_type.dat")),a=new e(t.read("base_label.dat")),n=s.g2;s.pos+=2;for(let t=0;t{const r=new e(t.read("frame_head.dat")),a=new e(t.read("frame_tran1.dat")),n=new e(t.read("frame_tran2.dat")),o=new e(t.read("frame_del.dat")),l=r.g2;r.pos+=2;const h=new Uint32Array(500),c=new Uint32Array(500),f=new Uint32Array(500),d=new Uint32Array(500);for(let t=0;t0){if(0!=u.types[t])for(let e=t-1;e>g;e--)if(0==u.types[e]){h[m]=e,c[m]=0,f[m]=0,d[m]=0,m++;break}h[m]=t;let i=0;3==u.types[h[m]]&&(i=128),c[m]=0==(1&e)?i:n.gsmart,f[m]=0==(2&e)?i:n.gsmart,d[m]=0==(4&e)?i:n.gsmart,g=t,m++}}e.length=m,e.bases=new Uint32Array(m),e.x=new Uint32Array(m),e.y=new Uint32Array(m),e.z=new Uint32Array(m);for(let t=0;t{const i=new e(t.read("seq.dat"));this.count=i.g2;for(let t=0;tr.instances[t];frameCount=0;frames=null;iframes=null;delay=null;replayoff=-1;labelGroups=null;stretches=!1;priority=5;mainhand=-1;offhand=-1;replaycount=99;duration=0;decode=(t,e)=>{if(1===t){this.frameCount=e.g1,this.frames=new Uint16Array(this.frameCount),this.iframes=new Uint16Array(this.frameCount),this.delay=new Uint16Array(this.frameCount);for(let t=0;t{const i=new e(t.read("loc.dat"));this.count=i.g2;for(let t=0;t0&&10==e.shapes[0]?1:0,e.ops.length>0&&(e.active=1))}};static get=t=>a.instances[t];models=null;shapes=null;name=null;desc=null;recol_s=null;recol_d=null;width=1;length=1;blockwalk=!0;blockrange=!0;active=-1;hillskew=!1;sharelight=!1;occlude=!1;anim=-1;hasalpha=!1;walloff=16;ambient=0;contrast=0;ops=[];mapfunction=-1;mapscene=-1;mirror=!1;shadow=!0;resizex=128;resizey=128;resizez=128;forceapproach=0;xoff=0;yoff=0;zoff=0;forcedecor=!1;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t),this.shapes=new Uint8Array(t);for(let i=0;i=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const i=new e(t.read("flo.dat"));this.count=i.g2;for(let t=0;tn.instances[t];rgb=0;texture=-1;opcode3=!1;occludes=!0;name=null;decode=(t,e)=>{1===t?this.rgb=e.g3:2===t?this.texture=e.g1:3===t?this.opcode3=!0:5===t?this.occludes=!1:6===t?this.name=e.gjstr:console.log("Error unrecognised config code: ",t)}}class o{static pixels=new Int32Array;static width=0;static height=0;static top=0;static bottom=0;static left=0;static right=0;static boundX=0;static centerX=0;static centerY=0;static bind=(t,e,i)=>{this.pixels=t,this.width=e,this.height=i,this.setBounds(0,0,e,i)};static resetBounds=()=>{this.left=0,this.top=0,this.right=this.width,this.bottom=this.height,this.boundX=this.right-1,this.centerX=this.right/2};static setBounds=(t,e,i,s)=>{t<0&&(t=0),e<0&&(e=0),i>this.width&&(i=this.width),s>this.height&&(s=this.height),this.top=e,this.bottom=s,this.left=t,this.right=i,this.boundX=this.right-1,this.centerX=this.right/2,this.centerY=this.bottom/2};static clear=()=>{this.pixels.fill(0)};static drawRect=(t,e,i,s,r)=>{this.drawHorizontalLine(t,e,r,i),this.drawHorizontalLine(t,e+s-1,r,i),this.drawVerticalLine(t,e,r,s),this.drawVerticalLine(t+i-1,e,r,s)};static drawHorizontalLine=(t,e,i,s)=>{if(e=this.bottom)return;tthis.right&&(s=this.right-t);const r=t+e*this.width;for(let t=0;t{if(t=this.right)return;ethis.bottom&&(s=this.bottom-e);const r=t+e*this.width;for(let t=0;t{const a=Math.abs(i-t),n=Math.abs(s-e),o=t=this.left&&t=this.top&&e-n&&(h-=n,t+=o),i{const a=this.pixels;let n=t,o=e,l=t+i,h=e+s;nthis.right&&(l=this.right),h>this.bottom&&(h=this.bottom);const c=this.width;for(let t=o;tt.bits-e.bits||t.code-e.code));let a=0,n=-1;const o=[];let l;for(let t=0;t=t.length)throw RangeError("Out of bound");const i=t.slice();t.sort(((t,e)=>t-e));const s={};for(let e=t.length-1;e>=0;e-=1)s[t[e]]=e;const r=[];for(let e=0;enew Promise((e=>setTimeout(e,t))),u=async t=>new Uint8Array(await(await fetch(t)).arrayBuffer()),p=(t,e=!0,i=!0)=>{if(e){const e=Uint8Array.from(["B".charCodeAt(0),"Z".charCodeAt(0),"h".charCodeAt(0),"1".charCodeAt(0)]);if(i){const i=t;(t=new Uint8Array(e.length+t.length)).set(i,e.length)}t.set(e,0)}return function(t,e=!1){let i=0,s=0,r=0;const a=e=>{if(e>=32){const t=e>>1;return a(t)*(1<>r-e&n;return r-=e,s&=~(n<=49&&n<=57))throw new Error("Invalid blocksize");n-=48;let o=new Uint8Array(1.5*t.length),d=0,u=-1;for(;;){const n=a(48),p=0|a(32);if(54156738319193!==n){if(25779555029136===n){a(7&r);break}throw new Error("Invalid bz2 blocktype")}{if(a(1))throw new Error("do not support randomised");const n=a(24),g=[],m=a(16);for(let t=32768;t>0;t>>=1){if(!(m&t)){for(let t=0;t<16;t+=1)g.push(!1);continue}const e=a(16);for(let t=32768;t>0;t>>=1)g.push(!!(e&t))}const w=a(3);if(w<2||w>6)throw new Error("Invalid number of huffman groups");const x=a(15),y=[],v=Array.from({length:w},((t,e)=>e));for(let t=0;t=w)throw new Error("MTF table out of range");const e=v[t];for(let e=t;e>0;v[e]=v[--e]);y.push(e),v[0]=e}const C=g.reduce(((t,e)=>t+e),0)+2,b=[];for(let t=0;t20)throw new Error("Huffman group length outside range");for(;a(1);)t-=2*a(1)-1;e.push(t)}b.push(c(e))}const A=[];for(let t=0;t>r-e],k)){s&=h[r-=e],k=k.code;break}if(k>=0&&k<=1)0===Y&&(O=1),Y+=O<0;Y-=1)T.push(t)}if(k===C-1)break;{const t=A[k-1];for(let t=k-1;t>0;A[t]=A[--t]);A[0]=t,T.push(t)}}}const X=f(T,n);let F=0;for(;F=o.length){const t=o;o=new Uint8Array(2*t.length),o.set(t)}for(let s=0;s>24^t)]),o[d]=t,d+=1}if(e){const t=-1^u;if(t!==p)throw new Error(`CRC mismatch: ${t} !== ${p}`);u=-1}}}return o.subarray(0,d)}(t)};class g{pixels;width;height;cropX;cropY;cropW;cropH;constructor(t,e){this.pixels=new Int32Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromJpeg=async(t,e)=>{const i=t.read(e+".dat"),s=await(async t=>{if(!t)throw new Error("Input jpeg data was null!");255!==t[0]&&(t[0]=255);const e=document.createElement("img");e.src="data:image/jpeg;base64,"+btoa(String.fromCharCode(...t)),await new Promise((t=>e.onload=t));const i=document.createElement("canvas");i.width=e.naturalWidth,i.height=e.naturalHeight;const s=i.getContext("2d");if(!s)throw new Error("Canvas 2d not found!!!!!!!!");return s.drawImage(e,0,0),s.getImageData(0,0,i.width,i.height)})(i),r=new g(s.width,s.height),a=r.pixels,n=s.data;for(let t=0;t{const r=new e(t.read(i+".dat")),a=new e(t.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,l=a.g1,h=new Uint32Array(l),c=l-1;for(let t=0;t{t|=0,e|=0;let i=(t+=this.cropX)+(e+=this.cropY)*o.width,s=0,r=this.height,a=this.width,n=o.width-a,l=0;if(eo.bottom&&(r-=e+r-o.bottom),to.right){const e=t+a-o.right;a-=e,l+=e,n+=e}a>0&&r>0&&this.copyImageDraw(a,r,this.pixels,s,l,o.pixels,i,n)};drawAlpha=(t,e,i)=>{e|=0,i|=0;let s=(e+=this.cropX)+(i+=this.cropY)*o.width,r=0,a=this.height,n=this.width,l=o.width-n,h=0;if(io.bottom&&(a-=i+a-o.bottom),eo.right){const t=e+n-o.right;n-=t,h+=t,l+=t}n>0&&a>0&&this.copyPixelsAlpha(n,a,this.pixels,r,h,o.pixels,s,l,t)};blitOpaque=(t,e)=>{t|=0,e|=0;let i=(t+=this.cropX)+(e+=this.cropY)*o.width,s=0,r=this.height,a=this.width,n=o.width-a,l=0;if(eo.bottom&&(r-=e+r-o.bottom),to.right){const e=t+a-o.right;a-=e,l+=e,n+=e}a>0&&r>0&&this.copyImageBlitOpaque(a,r,this.pixels,s,l,o.pixels,i,n)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;a+=t,a<1?a=1:a>255&&(a=255);let n=r>>8&255;n+=e,n<1?n=1:n>255&&(n=255);let o=255&r;o+=i,o<1?o=1:o>255&&(o=255),this.pixels[s]=(a<<16)+(n<<8)+o}}};copyImageBlitOpaque=(t,e,i,s,r,a,n,o)=>{const l=-(t>>2);t=-(3&t);for(let h=-e;h<0;h++){for(let t=l;t<0;t++)a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++],a[n++]=i[s++];for(let e=t;e<0;e++)a[n++]=i[s++];n+=o,s+=r}};copyPixelsAlpha=(t,e,i,s,r,a,n,o,l)=>{const h=256-l;for(let c=-e;c<0;c++){for(let e=-t;e<0;e++){const t=i[s++];if(0==t)n++;else{const e=a[n];a[n++]=((16711935&t)*l+(16711935&e)*h&4278255360)+((65280&t)*l+(65280&e)*h&16711680)>>8}}n+=o,s+=r}};copyImageDraw=(t,e,i,s,r,a,n,o)=>{const l=-(t>>2);t=-(3&t);for(let h=-e;h<0;h++){for(let t=l;t<0;t++){let t=i[s++];0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t,t=i[s++],0===t?n++:a[n++]=t}for(let e=t;e<0;e++){const t=i[s++];0===t?n++:a[n++]=t}n+=o,s+=r}}}class m extends t{static count=0;static instances=[];static unpack=(t,i)=>{const s=new e(t.read("obj.dat"));this.count=s.g2;for(let t=0;tm.instances[t];static getIcon=(t,e)=>new g(32,32);model=0;name=null;desc=null;recol_s=null;recol_d=null;zoom2d=2e3;xan2d=0;yan2d=0;zan2d=0;xof2d=0;yof2d=0;code9=!1;code10=-1;stackable=!1;cost=1;members=!1;ops=[];iops=[];manwear=-1;manwear2=-1;manwearOffsetY=0;womanwear=-1;womanwear2=-1;womanwearOffsetY=0;manwear3=-1;womanwear3=-1;manhead=-1;manhead2=-1;womanhead=-1;womanhead2=-1;countobj=null;countco=null;certlink=-1;certtemplate=-1;decode=(t,e)=>{if(1===t)this.model=e.g2;else if(2===t)this.name=e.gjstr;else if(3===t)this.desc=e.gjstr;else if(4===t)this.zoom2d=e.g2;else if(5===t)this.xan2d=e.g2;else if(6===t)this.yan2d=e.g2;else if(7===t)this.xof2d=e.g2b,this.xof2d>32767&&(this.xof2d-=65536);else if(8===t)this.yof2d=e.g2b,this.yof2d>32767&&(this.yof2d-=65536);else if(9===t)this.code9=!0;else if(10===t)this.code10=e.g2;else if(11===t)this.stackable=!0;else if(12===t)this.cost=e.g4s;else if(16===t)this.members=!0;else if(23===t)this.manwear=e.g2,this.manwearOffsetY=e.g1b;else if(24===t)this.manwear2=e.g2;else if(25===t)this.womanwear=e.g2,this.womanwearOffsetY=e.g1b;else if(26===t)this.womanwear2=e.g2;else if(t>=30&&t<35)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(t>=35&&t<40)this.iops[t-35]=e.gjstr;else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i=100&&t<110))throw new Error(`Unrecognized obj config code: ${t}`);this.countobj&&this.countco||(this.countobj=new Uint16Array(10),this.countco=new Uint16Array(10)),this.countobj[t-100]=e.g2,this.countco[t-100]=e.g2}};toCertificate=()=>{const t=m.get(this.certtemplate);this.model=t.model,this.zoom2d=t.zoom2d,this.xan2d=t.xan2d,this.yan2d=t.yan2d,this.zan2d=t.zan2d,this.xof2d=t.xof2d,this.yof2d=t.yof2d,this.recol_s=t.recol_s,this.recol_d=t.recol_d;const e=m.get(this.certlink);this.name=e.name,this.members=e.members,this.cost=e.cost;let i="a";const s=(e.name||"").toLowerCase().charAt(0);"a"!==s&&"e"!==s&&"i"!==s&&"o"!==s&&"u"!==s||(i="an"),this.desc=`Swap this note at any bank for ${i} ${e.name}.`,this.stackable=!0}}class w extends t{static count=0;static instances=[];static unpack=t=>{const i=new e(t.read("npc.dat"));this.count=i.g2;for(let t=0;tw.instances[t];name=null;desc=null;size=1;models=null;heads=null;hasanim=!1;readyanim=-1;walkanim=-1;walkanim_b=-1;walkanim_r=-1;walkanim_l=-1;hasalpha=!1;recol_s=null;recol_d=null;ops=[];code90=-1;code91=-1;code92=-1;visonmap=!0;vislevel=-1;resizeh=128;resizev=128;decode=(t,e)=>{if(1===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=30&&t<40)this.ops[t-30]=e.gjstr,"hidden"===this.ops[t-30]&&(this.ops[t-30]=null);else if(40===t){const t=e.g1;this.recol_s=new Uint16Array(t),this.recol_d=new Uint16Array(t);for(let i=0;i{const i=new e(t.read("idk.dat"));this.count=i.g2;for(let t=0;tx.instances[t];type=-1;models=null;heads=new Uint16Array(5).fill(-1);recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);disable=!1;decode=(t,e)=>{if(1===t)this.type=e.g1;else if(2===t){const t=e.g1;this.models=new Uint16Array(t);for(let i=0;i=40&&t<50)this.recol_s[t-40]=e.g2;else if(t>=50&&t<60)this.recol_d[t-50]=e.g2;else{if(!(t>=60&&t<70))throw new Error(`Unrecognized idk config code: ${t}`);this.heads[t-60]=e.g2}}}class y extends t{static count=0;static instances=[];static unpack=t=>{const i=new e(t.read("spotanim.dat"));this.count=i.g2;for(let t=0;ty.instances[t];model=0;anim=-1;seq=null;disposeAlpha=!1;recol_s=new Uint16Array(6);recol_d=new Uint16Array(6);resizeh=128;resizev=128;orientation=0;ambient=0;contrast=0;decode=(t,e)=>{if(1==t)this.model=e.g2;else if(2==t)this.anim=e.g2,null!=r.instances&&(this.seq=r.instances[this.anim]);else if(3==t)this.disposeAlpha=!0;else if(4==t)this.resizeh=e.g2;else if(5==t)this.resizev=e.g2;else if(6==t)this.orientation=e.g2;else if(7==t)this.ambient=e.g1;else if(8==t)this.contrast=e.g1;else if(t>=40&&t<50)this.recol_s[t-40]=e.g2;else{if(!(t>=50&&t<60))throw new Error(`Unrecognized spotanim config code: ${t}`);this.recol_d[t-50]=e.g2}}}class v extends t{static count=0;static instances=[];static code3=[];static code3Count=0;static unpack=t=>{const i=new e(t.read("varp.dat"));this.count=i.g2;for(let t=0;tv.instances[t];code10=null;code1=0;code2=0;hasCode3=!1;code4=!0;clientcode=0;code7=0;code6=!1;code8=!1;decode(t,e){if(1==t)this.code1=e.g1;else if(2==t)this.code2=e.g1;else if(3==t)this.hasCode3=!0,v.code3[v.code3Count++]=this.index;else if(4==t)this.code4=!1;else if(5==t)this.clientcode=e.g2;else if(6==t)this.code6=!0;else if(7==t)this.code7=e.g4;else if(8==t)this.code8=!0;else{if(10!=t)throw new Error(`Error unrecognised config code: ${t}`);this.code10=e.gjstr}}}class C{pixels;width;height;cropX;cropY;cropW;cropH;palette=new Uint32Array(0);constructor(t,e){this.pixels=new Uint8Array(t*e),this.width=this.cropW=t,this.height=this.cropH=e,this.cropX=this.cropY=0}static fromArchive=(t,i,s=0)=>{const r=new e(t?.read(i+".dat")),a=new e(t?.read("index.dat"));a.pos=r.g2;const n=a.g2,o=a.g2,l=a.g1,h=new Uint32Array(l);for(let t=0;t{t|=0,e|=0;let r=(t+=this.cropX)+(e+=this.cropY)*o.width,a=0,n=this.height,l=this.width;-1!==i&&(l=i),-1!==s&&(n=s);let h=o.width-l,c=0;if(eo.bottom&&(n-=e+n-o.bottom),to.right){const e=t+l-o.right;l-=e,c+=e,h+=e}l>0&&n>0&&this.copyImage(l,n,this.pixels,a,c,o.pixels,r,h)};flipHorizontally=()=>{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{const t=this.pixels,e=this.width,i=this.height;for(let s=0;s{for(let s=0;s>16&255;r+=t,r<0?r=0:r>255&&(r=255);let a=this.palette[s]>>8&255;a+=e,a<0?a=0:a>255&&(a=255);let n=255&this.palette[s];n+=i,n<0?n=0:n>255&&(n=255),this.palette[s]=(r<<16)+(a<<8)+n}};copyImage=(t,e,i,s,r,a,n,o)=>{for(let l=0;l{this.lineOffset=new Int32Array(o.height);for(let t=0;t{this.lineOffset=new Int32Array(e);for(let i=0;i{this.textureCount=0;for(let e=0;e<50;e++)try{this.textures[e]=C.fromArchive(t,e.toString()),this.textureCount++}catch(t){}};static setBrightness=t=>{t+=.3*Math.random()-.15;let e=0;for(let i=0;i<512;i++){const s=i/8/64+.0078125,r=(7&i)/8+.0625;for(let i=0;i<128;i++){const a=i/128;let n=a,o=a,l=a;if(r){let t;t=a<.5?a*(1+r):a+r-a*r;const e=2*a-t;let i=s+.3333333333333333;i>1&&i--;let h=s-.3333333333333333;h<0&&h++,n=6*i<1?e+6*(t-e)*i:2*i<1?t:3*i<2?e+6*(.6666666666666666-i)*(t-e):e,o=6*s<1?e+6*(t-e)*s:2*s<1?t:3*s<2?e+6*(.6666666666666666-s)*(t-e):e,l=6*h<1?e+6*(t-e)*h:2*h<1?t:3*h<2?e+6*(.6666666666666666-h)*(t-e):e}let h=Math.trunc(256*n)<<16|Math.trunc(256*o)<<8|Math.trunc(256*l);h=this.setGamma(h,t),0===h&&(h=1),this.palette[e++]=h}}};static setGamma=(t,e)=>{let i=(t>>16)/256,s=(t>>8&255)/256,r=(255&t)/256;return i=Math.pow(i,e),s=Math.pow(s,e),r=Math.pow(r,e),Math.trunc(256*i)<<16|Math.trunc(256*s)<<8|Math.trunc(256*r)};static initPool=t=>{null==this.texelPool&&(this.poolSize=t,this.texelPool=[],this.activeTexels=[])};static fillGouraudTriangle=(t,e,i,s,r,a,n,l,h)=>{let c=0,f=0,d=0,u=0,p=0,g=0;if(r!=s&&(c=(e-t<<16)/(r-s),u=(l-n<<15)/(r-s)),a!=r&&(f=(i-e<<16)/(a-r),p=(h-l<<15)/(a-r)),a!=s&&(d=(t-i<<16)/(s-a),g=(n-h<<15)/(s-a)),s<=r&&s<=a){if(s>=o.bottom)return;if(r>o.bottom&&(r=o.bottom),a>o.bottom&&(a=o.bottom),rf){for(a-=r,r-=s,s=this.lineOffset[s];--r>=0;s+=o.width)this.drawGouraudScanline(o.pixels,s,i>>16,t>>16,h>>7,n>>7),i+=d,t+=c,h+=g,n+=u;for(;--a>=0;)this.drawGouraudScanline(o.pixels,s,i>>16,e>>16,h>>7,l>>7),i+=d,e+=f,h+=g,l+=p,s+=o.width;return}for(a-=r,r-=s,s=this.lineOffset[s];--r>=0;s+=o.width)this.drawGouraudScanline(o.pixels,s,t>>16,i>>16,n>>7,h>>7),i+=d,t+=c,h+=g,n+=u;for(;--a>=0;)this.drawGouraudScanline(o.pixels,s,e>>16,i>>16,l>>7,h>>7),i+=d,e+=f,h+=g,l+=p,s+=o.width;return}if(e=t<<=16,l=n<<=15,s<0&&(e-=d*s,t-=c*s,l-=g*s,n-=u*s,s=0),i<<=16,h<<=15,a<0&&(i-=f*a,h-=p*a,a=0),s!=a&&dc){for(r-=a,a-=s,s=this.lineOffset[s];--a>=0;s+=o.width)this.drawGouraudScanline(o.pixels,s,e>>16,t>>16,l>>7,n>>7),e+=d,t+=c,l+=g,n+=u;for(;--r>=0;)this.drawGouraudScanline(o.pixels,s,i>>16,t>>16,h>>7,n>>7),i+=f,t+=c,h+=p,n+=u,s+=o.width;return}for(r-=a,a-=s,s=this.lineOffset[s];--a>=0;s+=o.width)this.drawGouraudScanline(o.pixels,s,t>>16,e>>16,n>>7,l>>7),e+=d,t+=c,l+=g,n+=u;for(;--r>=0;)this.drawGouraudScanline(o.pixels,s,t>>16,i>>16,n>>7,h>>7),i+=f,t+=c,h+=p,n+=u,s+=o.width}else if(r<=a){if(r>=o.bottom)return;if(a>o.bottom&&(a=o.bottom),s>o.bottom&&(s=o.bottom),ad){for(s-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=o.width)this.drawGouraudScanline(o.pixels,r,t>>16,e>>16,n>>7,l>>7),t+=c,e+=f,n+=u,l+=p;for(;--s>=0;)this.drawGouraudScanline(o.pixels,r,t>>16,i>>16,n>>7,h>>7),t+=c,i+=d,n+=u,h+=g,r+=o.width;return}for(s-=a,a-=r,r=this.lineOffset[r];--a>=0;r+=o.width)this.drawGouraudScanline(o.pixels,r,e>>16,t>>16,l>>7,n>>7),t+=c,e+=f,n+=u,l+=p;for(;--s>=0;)this.drawGouraudScanline(o.pixels,r,i>>16,t>>16,h>>7,n>>7),t+=c,i+=d,n+=u,h+=g,r+=o.width;return}if(i=e<<=16,h=l<<=15,r<0&&(i-=c*r,e-=f*r,h-=u*r,l-=p*r,r=0),t<<=16,n<<=15,s<0&&(t-=d*s,n-=g*s,s=0),c=0;r+=o.width)this.drawGouraudScanline(o.pixels,r,i>>16,e>>16,h>>7,l>>7),i+=c,e+=f,h+=u,l+=p;for(;--a>=0;)this.drawGouraudScanline(o.pixels,r,t>>16,e>>16,n>>7,l>>7),t+=d,e+=f,n+=g,l+=p,r+=o.width;return}for(a-=s,s-=r,r=this.lineOffset[r];--s>=0;r+=o.width)this.drawGouraudScanline(o.pixels,r,e>>16,i>>16,l>>7,h>>7),i+=c,e+=f,h+=u,l+=p;for(;--a>=0;)this.drawGouraudScanline(o.pixels,r,e>>16,t>>16,l>>7,n>>7),t+=d,e+=f,n+=g,l+=p,r+=o.width}else if(!(a>=o.bottom))if(s>o.bottom&&(s=o.bottom),r>o.bottom&&(r=o.bottom),s=0;a+=o.width)this.drawGouraudScanline(o.pixels,a,e>>16,i>>16,l>>7,h>>7),e+=f,i+=d,l+=p,h+=g;for(;--r>=0;)this.drawGouraudScanline(o.pixels,a,e>>16,t>>16,l>>7,n>>7),e+=f,t+=c,l+=p,n+=u,a+=o.width;return}for(r-=s,s-=a,a=this.lineOffset[a];--s>=0;a+=o.width)this.drawGouraudScanline(o.pixels,a,i>>16,e>>16,h>>7,l>>7),e+=f,i+=d,l+=p,h+=g;for(;--r>=0;)this.drawGouraudScanline(o.pixels,a,t>>16,e>>16,n>>7,l>>7),e+=f,t+=c,l+=p,n+=u,a+=o.width}else if(t=i<<=16,n=h<<=15,a<0&&(t-=f*a,i-=d*a,n-=p*a,h-=g*a,a=0),e<<=16,l<<=15,r<0&&(e-=c*r,l-=u*r,r=0),f=0;a+=o.width)this.drawGouraudScanline(o.pixels,a,t>>16,i>>16,n>>7,h>>7),t+=f,i+=d,n+=p,h+=g;for(;--s>=0;)this.drawGouraudScanline(o.pixels,a,e>>16,i>>16,l>>7,h>>7),e+=c,i+=d,l+=u,h+=g,a+=o.width}else{for(s-=r,r-=a,a=this.lineOffset[a];--r>=0;a+=o.width)this.drawGouraudScanline(o.pixels,a,i>>16,t>>16,h>>7,n>>7),t+=f,i+=d,n+=p,h+=g;for(;--s>=0;)this.drawGouraudScanline(o.pixels,a,i>>16,e>>16,h>>7,l>>7),e+=c,i+=d,l+=u,h+=g,a+=o.width}};static drawGouraudScanline=(t,e,i,s,r,a)=>{let n=0,l=0;if(this.jagged){let h=0;if(this.clipX){if(h=s-i>3?(a-r)/(s-i):0,s>o.right&&(s=o.right),i<0&&(r-=i*h,i=0),i>=s)return;e+=i,l=s-i>>2,h<<=2}else{if(i>=s)return;e+=i,l=s-i>>2,h=l>0?(a-r)*this.reciprocal15[l]>>15:0}if(0==this.alpha){for(;--l>=0;)n=this.palette[r>>8],r+=h,t[e++]=n,t[e++]=n,t[e++]=n,t[e++]=n;if(l=s-i&3,l>0){n=this.palette[r>>8];do{t[e++]=n}while(--l>0);return}}else{const a=this.alpha,o=256-this.alpha;for(;--l>=0;)n=this.palette[r>>8],r+=h,n=((16711935&n)*o>>8&16711935)+((65280&n)*o>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280),t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280);if(l=s-i&3,l>0){n=this.palette[r>>8],n=((16711935&n)*o>>8&16711935)+((65280&n)*o>>8&65280);do{t[e++]=n+((16711935&t[e])*a>>8&16711935)+((65280&t[e])*a>>8&65280)}while(--l>0)}}return}if(i>=s)return;const h=(a-r)/(s-i);if(this.clipX&&(s>o.right&&(s=o.right),i<0&&(r-=i*h,i=0),i>=s))return;if(e+=i,l=s-i,0==this.alpha){do{t[e++]=this.palette[r>>8],r+=h}while(--l>0);return}const c=this.alpha,f=256-this.alpha;do{n=this.palette[r>>8],r+=h,n=((16711935&n)*f>>8&16711935)+((65280&n)*f>>8&65280),t[e++]=n+((16711935&t[e])*c>>8&16711935)+((65280&t[e])*c>>8&65280)}while(--l>0)};static fillTriangle=()=>{};static fillTexturedTriangle=()=>{}}class A{vertexCount=0;faceCount=0;texturedFaceCount=0;vertexFlagsOffset=-1;vertexXOffset=-1;vertexYOffset=-1;vertexZOffset=-1;vertexLabelsOffset=-1;faceVerticesOffset=-1;faceOrientationsOffset=-1;faceColorsOffset=-1;faceInfosOffset=-1;facePrioritiesOffset=0;faceAlphasOffset=-1;faceLabelsOffset=-1;faceTextureAxisOffset=-1}class S{x=0;y=0;z=0;w=0}class k{static metadata=null;static head=null;static face1=null;static face2=null;static face3=null;static face4=null;static face5=null;static point1=null;static point2=null;static point3=null;static point4=null;static point5=null;static vertex1=null;static vertex2=null;static axis=null;static faceClippedX=new Array(4096);static faceNearClipped=new Array(4096);static vertexScreenX=new Int32Array(4096);static vertexScreenY=new Int32Array(4096);static vertexScreenZ=new Int32Array(4096);static vertexViewSpaceX=new Int32Array(4096);static vertexViewSpaceY=new Int32Array(4096);static vertexViewSpaceZ=new Int32Array(4096);static tmpDepthFaceCount=new Int32Array(1500);static tmpDepthFaces=new Array(1500).fill(null).map((()=>new Int32Array(512)));static tmpPriorityFaceCount=new Int32Array(12);static tmpPriorityFaces=new Array(12).fill(null).map((()=>new Int32Array(2e3)));static tmpPriority10FaceDepth=new Int32Array(2e3);static tmpPriority11FaceDepth=new Int32Array(2e3);static tmpPriorityDepthSum=new Int32Array(12);static clippedX=new Int32Array(10);static clippedY=new Int32Array(10);static clippedColor=new Int32Array(10);static baseX=0;static baseY=0;static baseZ=0;static checkHover=!1;static mouseX=0;static mouseZ=0;static pickedCount=0;static pickedBitsets=new Int32Array(1e3);static unpack(t){try{k.head=new e(t.read("ob_head.dat")),k.face1=new e(t.read("ob_face1.dat")),k.face2=new e(t.read("ob_face2.dat")),k.face3=new e(t.read("ob_face3.dat")),k.face4=new e(t.read("ob_face4.dat")),k.face5=new e(t.read("ob_face5.dat")),k.point1=new e(t.read("ob_point1.dat")),k.point2=new e(t.read("ob_point2.dat")),k.point3=new e(t.read("ob_point3.dat")),k.point4=new e(t.read("ob_point4.dat")),k.point5=new e(t.read("ob_point5.dat")),k.vertex1=new e(t.read("ob_vertex1.dat")),k.vertex2=new e(t.read("ob_vertex2.dat")),k.axis=new e(t.read("ob_axis.dat")),k.head.pos=0,k.point1.pos=0,k.point2.pos=0,k.point3.pos=0,k.point4.pos=0,k.vertex1.pos=0,k.vertex2.pos=0;const i=k.head.g2;k.metadata=new Array(i+100);let s=0,r=0,a=0,n=0,o=0,l=0,h=0;for(let t=0;t127&&(e=127),127-e):((e=e*(127&t)>>7)<2?e=2:e>126&&(e=126),(65408&t)+e)}vertexCount=0;vertexX=null;vertexY=null;vertexZ=null;faceCount=0;faceVertexA=null;faceVertexB=null;faceVertexC=null;faceColorA=null;faceColorB=null;faceColorC=null;faceInfo=null;facePriority=null;faceAlpha=null;faceColor=null;priority=0;texturedFaceCount=0;texturedVertexA=null;texturedVertexB=null;texturedVertexC=null;minX=0;maxX=0;minZ=0;maxZ=0;radius=0;minY=0;maxY=0;maxDepth=0;minDepth=0;objRaise=0;vertexLabel=null;faceLabel=null;labelVertices=null;labelFaces=null;pickable=!1;vertexNormal=null;vertexNormalOriginal=null;constructor(t){if(null===k.head||null===k.face1||null===k.face2||null===k.face3||null===k.face4||null===k.face5||null===k.point1||null===k.point2||null===k.point3||null===k.point4||null===k.point5||null===k.vertex1||null===k.vertex2||null===k.axis)return;if(null===k.metadata)return;const e=k.metadata[t];if(void 0===e)return void console.log(`Error model:${t} not found!`);this.vertexCount=e.vertexCount,this.faceCount=e.faceCount,this.texturedFaceCount=e.texturedFaceCount,this.vertexX=new Int32Array(this.vertexCount),this.vertexY=new Int32Array(this.vertexCount),this.vertexZ=new Int32Array(this.vertexCount),this.faceVertexA=new Int32Array(this.faceCount),this.faceVertexB=new Int32Array(this.faceCount),this.faceVertexC=new Int32Array(this.faceCount),this.texturedVertexA=new Int32Array(this.texturedFaceCount),this.texturedVertexB=new Int32Array(this.texturedFaceCount),this.texturedVertexC=new Int32Array(this.texturedFaceCount),e.vertexLabelsOffset>=0&&(this.vertexLabel=new Int32Array(this.vertexCount)),e.faceInfosOffset>=0&&(this.faceInfo=new Int32Array(this.faceCount)),e.facePrioritiesOffset>=0?this.facePriority=new Int32Array(this.faceCount):this.priority=-e.facePrioritiesOffset-1,e.faceAlphasOffset>=0&&(this.faceAlpha=new Int32Array(this.faceCount)),e.faceLabelsOffset>=0&&(this.faceLabel=new Int32Array(this.faceCount)),this.faceColor=new Int32Array(this.faceCount),k.point1.pos=e.vertexFlagsOffset,k.point2.pos=e.vertexXOffset,k.point3.pos=e.vertexYOffset,k.point4.pos=e.vertexZOffset,k.point5.pos=e.vertexLabelsOffset;let i,s,r,a=0,n=0,o=0;for(let t=0;tthis.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)+.99),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsY(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.minY=0;for(let t=0;tthis.maxY&&(this.maxY=-e),e>this.minY&&(this.minY=e)}this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)+.99),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY)+.99)}}calculateBoundsAABB(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ){this.maxY=0,this.radius=0,this.minY=0,this.minX=999999,this.maxX=-999999,this.maxZ=-99999,this.minZ=99999;for(let t=0;tthis.maxX&&(this.maxX=e),sthis.maxZ&&(this.maxZ=s),-i>this.maxY&&(this.maxY=-i),i>this.minY&&(this.minY=i);const r=e*e+s*s;r>this.radius&&(this.radius=r)}this.radius=Math.trunc(Math.sqrt(this.radius)),this.minDepth=Math.trunc(Math.sqrt(this.radius*this.radius+this.maxY*this.maxY)),this.maxDepth=this.minDepth+Math.trunc(Math.sqrt(this.radius*this.radius+this.minY*this.minY))}}createLabelReferences(){}applyTransform(t){}rotateY90(){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let t=0;t>16;this.vertexZ[t]=this.vertexY[t]*e+this.vertexZ[t]*i>>16,this.vertexY[t]=s}}translate(t,e,i){if(null!==this.vertexX&&null!==this.vertexY&&null!==this.vertexZ)for(let s=0;s>8;if(null!==this.faceColorA&&null!==this.faceColorB&&null!==this.faceColorC||(this.faceColorA=new Int32Array(this.faceCount),this.faceColorB=new Int32Array(this.faceCount),this.faceColorC=new Int32Array(this.faceCount)),null===this.vertexNormal){this.vertexNormal=new Array(this.vertexCount);for(let t=0;t8192||m>8192||w>8192||g<-8192||m<-8192||w<-8192;)g>>=1,m>>=1,w>>=1;let x=Math.sqrt(g*g+m*m+w*w);if(x<=0&&(x=1),g=256*g/x,m=256*m/x,w=256*w/x,null===this.faceInfo||0==(1&this.faceInfo[e])){let t=this.vertexNormal[a];t.x+=g,t.y+=m,t.z+=w,t.w++,t=this.vertexNormal[o],t.x+=g,t.y+=m,t.z+=w,t.w++,t=this.vertexNormal[l],t.x+=g,t.y+=m,t.z+=w,t.w++}else{const a=t+(i*g+s*m+r*w)/(n+n/2);this.faceColorA[e]=k.mulColorLightness(this.faceColor[e],a,this.faceInfo[e])}}if(a)this.applyLighting(t,e,i,s,r);else{this.vertexNormalOriginal=new Array(this.vertexCount);for(let t=0;t>16;for(let s=0;s>16,x=x*d-w*f>>16,w=m),0!==t&&(m=x*l-y*o>>16,y=x*o+y*l>>16,x=m),0!==e&&(m=y*h+w*c>>16,y=y*c-w*h>>16,w=m),w+=r,x+=a,y+=n,m=x*p-y*u>>16,y=x*u+y*p>>16,x=m,k.vertexScreenX[s]=b.centerX+(w<<9)/y,k.vertexScreenY[s]=b.centerY+(x<<9)/y,k.vertexScreenZ[s]=y-g,this.texturedFaceCount>0&&(k.vertexViewSpaceX[s]=w,k.vertexViewSpaceY[s]=x,k.vertexViewSpaceZ[s]=y)}this.draw2(!1,!1,0)}draw(t,e,i,s,r,a,n,o,l){}draw2(t,e,i){if(null===k.vertexScreenX||null===k.vertexScreenY||null===k.vertexScreenZ)return;if(null===k.vertexViewSpaceX||null===k.vertexViewSpaceY||null===k.vertexViewSpaceZ)return;if(null===k.faceNearClipped||null===k.faceClippedX)return;if(null===k.tmpDepthFaceCount||null===k.tmpDepthFaces||null===k.tmpPriorityFaces||null===k.tmpPriorityFaceCount||null===k.tmpPriorityDepthSum||null===k.tmpPriority10FaceDepth||null===k.tmpPriority11FaceDepth)return;if(null===this.faceVertexA||null===this.faceVertexB||null===this.faceVertexC)return;for(let t=0;to.boundX||h>o.boundX||c>o.boundX;const u=Math.trunc((k.vertexScreenZ[r]+k.vertexScreenZ[a]+k.vertexScreenZ[n])/3+this.minDepth);k.tmpDepthFaces[u][k.tmpDepthFaceCount[u]++]=s}else{k.faceNearClipped[s]=!0;const t=Math.trunc((k.vertexScreenZ[r]+k.vertexScreenZ[a]+k.vertexScreenZ[n])/3+this.minDepth);k.tmpDepthFaces[t][k.tmpDepthFaceCount[t]++]=s}}if(null==this.facePriority){for(let t=this.maxDepth-1;t>=0;t--){const e=k.tmpDepthFaceCount[t];if(e<=0)continue;const i=k.tmpDepthFaces[t];for(let t=0;t=0;t--){const e=k.tmpDepthFaceCount[t];if(e>0){const i=k.tmpDepthFaces[t];for(let s=0;s0||k.tmpPriorityFaceCount[2]>0)&&(s=Math.trunc((k.tmpPriorityDepthSum[1]+k.tmpPriorityDepthSum[2])/(k.tmpPriorityFaceCount[1]+k.tmpPriorityFaceCount[2])));let r=0;(k.tmpPriorityFaceCount[3]>0||k.tmpPriorityFaceCount[4]>0)&&(r=Math.trunc((k.tmpPriorityDepthSum[3]+k.tmpPriorityDepthSum[4])/(k.tmpPriorityFaceCount[3]+k.tmpPriorityFaceCount[4])));let a=0;(k.tmpPriorityFaceCount[6]>0||k.tmpPriorityFaceCount[8]>0)&&(a=Math.trunc((k.tmpPriorityDepthSum[6]+k.tmpPriorityDepthSum[8])/(k.tmpPriorityFaceCount[6]+k.tmpPriorityFaceCount[8])));let n,l=0,h=k.tmpPriorityFaceCount[10],c=k.tmpPriorityFaces[10],f=k.tmpPriority10FaceDepth;l==h&&(l=0,h=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),n=ls;)this.drawFace(c[l++]),l==h&&c!=k.tmpPriorityFaces[11]&&(l=0,h=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),n=lr;)this.drawFace(c[l++]),l==h&&c!=k.tmpPriorityFaces[11]&&(l=0,h=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),n=la;)this.drawFace(c[l++]),l==h&&c!=k.tmpPriorityFaces[11]&&(l=0,h=k.tmpPriorityFaceCount[11],c=k.tmpPriorityFaces[11],f=k.tmpPriority11FaceDepth),n=la&&e>n&&e>o||t{const r=new e(t.read("data"));let a=-1;for(r.pos+=2;r.pos0){e.scriptComparator=new Uint8Array(n).fill(0),e.scriptOperand=new Uint16Array(n).fill(0);for(let t=0;t0){e.scripts=new Array(o).fill(null);for(let t=0;t0){const r=s.lastIndexOf(",");e.inventorySlotImage[t]=g.fromArchive(i,s,r)}}for(let t=0;t<5;t++)e.inventoryOptions[t]=r.gjstr,0===e.inventoryOptions[t]?.length&&(e.inventoryOptions[t]=null);e.spellAction=r.gjstr,e.spellName=r.gjstr,e.spellFlags=r.g2;break;case P.TYPE_RECT:e.fill=1===r.g1,e.color=r.g4,e.activeColor=r.g4,e.hoverColor=r.g4;break;case P.TYPE_TEXT:e.center=1===r.g1,e.font=s[r.g1],e.shadow=1===r.g1,e.text=r.gjstr,e.activeText=r.gjstr,e.color=r.g4,e.activeColor=r.g4,e.hoverColor=r.g4;break;case P.TYPE_SPRITE:{const t=r.gjstr;if(t.length>0){const s=t.lastIndexOf(",");e.image=g.fromArchive(i,t.substring(0,s),parseInt(t.substring(s+1)))}const s=r.gjstr;if(s.length>0){const t=s.lastIndexOf(",");e.image=g.fromArchive(i,s.substring(0,t),parseInt(s.substring(t+1)))}break}case P.TYPE_MODEL:{const t=r.g1;0!==t&&(e.model=this.getModel((t-1<<8)+r.g1));const i=r.g1;0!==i&&(e.activeModel=this.getModel((i-1<<8)+r.g1)),e.seqId=r.g1,0==e.seqId?e.seqId=-1:e.seqId=(e.seqId-1<<8)+r.g1,e.activeSeqId=r.g1,0==e.activeSeqId?e.activeSeqId=-1:e.activeSeqId=(e.activeSeqId-1<<8)+r.g1,e.modelZoom=r.g2,e.modelPitch=r.g2,e.modelYaw=r.g2;break}case P.TYPE_INVENTORY_TEXT:e.inventorySlotObjId=new Int32Array(e.width*e.height),e.inventorySlotObjCount=new Int32Array(e.width*e.height),e.center=1===r.g1,e.font=s[r.g1],e.shadow=1===r.g1,e.color=r.g4,e.inventoryMarginX=r.g2b,e.inventoryMarginY=r.g2b,e.inventoryInteractable=1===r.g1,e.inventoryOptions=new Array(5).fill(null);for(let t=0;t<5;t++)e.inventoryOptions[t]=r.gjstr}2!=e.optionType&&2!=e.type||(e.spellAction=r.gjstr,e.spellName=r.gjstr,e.spellFlags=r.g2),1!=e.optionType&&4!=e.optionType&&5!=e.optionType&&6!=e.optionType||(e.option=r.gjstr,0==e.option.length&&(1==e.optionType?e.option="Ok":4==e.optionType||5==e.optionType?e.option="Select":6==e.optionType&&(e.option="Continue")))}};static get=t=>P.instances[t];static getModel=t=>new k(t);id=-1;parentId=-1;type=-1;optionType=-1;contentType=0;width=0;height=0;delegateHover=-1;scriptComparator=null;scriptOperand=null;scripts=null;scrollableHeight=0;hide=!1;inventoryDraggable=!1;inventoryInteractable=!1;inventoryUsable=!1;inventoryMarginX=0;inventoryMarginY=0;inventorySlotOffsetX=null;inventorySlotOffsetY=null;inventorySlotImage=null;inventoryOptions=[];fill=!1;center=!1;font=null;shadow=!1;text=null;activeText=null;color=0;activeColor=0;hoverColor=0;image=null;activeImage=null;model=null;activeModel=null;seqId=-1;activeSeqId=-1;modelZoom=0;modelPitch=0;modelYaw=0;spellAction=null;spellName=null;spellFlags=-1;option=null;childId=null;childX=null;childY=null;x=0;y=0;scrollPosition=0;inventorySlotObjId=null;inventorySlotObjCount=null;seqFrame=0;getModel=(t,e,i)=>{let s=this.model;return i&&(s=this.activeModel),null==s?null:-1==t&&-1==e&&null==s.faceColor?s:null}}class I{static CHARSET=[];static{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";for(let e=0;e<256;e++){let i=t.indexOf(String.fromCharCode(e));-1===i&&(i=74),I.CHARSET[e]=i}}pixels=[];charWidth=[];charHeight=[];clipX=[];clipY=[];charSpace=[];drawWidth=[];fontHeight=-1;static fromArchive=(t,i)=>{const s=new e(t.read(i+".dat")),r=new e(t.read("index.dat"));r.pos=s.g2+4;const a=r.g1;a>0&&(r.pos+=3*(a-1));const n=new I;for(let t=0;t<94;t++){n.clipX[t]=r.g1,n.clipY[t]=r.g1;const e=n.charWidth[t]=r.g2,i=n.charHeight[t]=r.g2,a=e*i;n.pixels[t]=new Uint8Array(a);const o=r.g1;if(0===o)for(let r=0;rn.fontHeight&&(n.fontHeight=i),n.clipX[t]=1,n.charSpace[t]=e+2;{let s=0;for(let r=i/7;r{t|=0,e|=0;const r=i.length;e-=this.fontHeight;for(let a=0;a{t|=0,e|=0;const a=i.length;e-=this.fontHeight;for(let n=0;n{const e=t.length;let i=0;for(let s=0;s{const r=e-this.fontHeight;for(let e=0;e{this.drawStringTaggable(t-this.stringWidth(i)/2,e,i,s,r)};drawStringCenter=(t,e,i,s)=>{this.draw(t-this.stringWidth(i)/2,e,i,s)};drawRight=(t,e,i,s,r=!0)=>{r&&this.draw(t-this.stringWidth(i)+1,e+1,i,0),this.draw(t-this.stringWidth(i),e,i,s)};drawChar=(t,e,i,s,r,a)=>{s|=0,r|=0;let n=(e|=0)+(i|=0)*o.width,l=o.width-s,h=0,c=0;if(i=o.bottom&&(r-=i+r+1-o.bottom),e=o.right){const t=e+s+1-o.right;s-=t,h+=t,l+=t}s>0&&r>0&&this.drawMask(s,r,t,c,h,o.pixels,n,l,a)};drawMask=(t,e,i,s,r,a,n,o,l)=>{const h=-((t|=0)>>2);t=-(3&t);for(let c=-(e|=0);c<0;c++){for(let t=h;t<0;t++)0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l,0==i[s++]?n++:a[n++]=l;for(let e=t;e<0;e++)0==i[s++]?n++:a[n++]=l;n+=o,s+=r}};copyCharacter=(t,e,i,s,r,a)=>{i|=0,s|=0;let n=(t|=0)+(e|=0)*o.width,l=0,h=o.width-i,c=0;if(eo.bottom&&(s-=e+s+1-o.bottom),to.right){const e=t+i+1-o.right;i-=e,c+=e,h+=e}i>0&&s>0&&this.copyImageMasked(i,s,r,l,c,o.pixels,n,h,a)};copyImageMasked=(t,e,i,s,r,a,n,o,l)=>{for(let h=0;h{switch(t){case"red":return 16711680;case"gre":return 65280;case"blu":return 255;case"yel":return 16776960;case"cya":return 65535;case"mag":return 16711935;case"whi":return 16777215;case"bla":default:return 0;case"lre":return 16748608;case"dre":return 8388608;case"dbl":return 128;case"or1":return 16756736;case"or2":return 16740352;case"or3":return 16723968;case"gr1":return 12648192;case"gr2":return 8453888;case"gr3":return 4259584}}}class Y{static loadUrl=async t=>new Y(await u(t));static genHash=t=>{let e=0;t=t.toUpperCase();for(let i=0;i>>0;return e};buffer;compressedWhole;fileCount;fileHash;fileSizeInflated;fileSizeDeflated;fileOffset;constructor(t){const i=new e(t),s=i.g3;let r;if(s==i.g3)r=i,this.compressedWhole=!1;else{const t=i.gdata(i.pos,s);r=new e(new Uint8Array(p(t))),this.compressedWhole=!0}this.buffer=r,this.fileCount=r.g2,this.fileHash=[],this.fileSizeInflated=[],this.fileSizeDeflated=[],this.fileOffset=[];let a=r.pos+10*this.fileCount;for(let t=0;t{const e=Y.genHash(t),i=this.fileHash.indexOf(e);return-1==i?null:this.readIndex(i)};readIndex=t=>{if(t<0||t>=this.fileCount)return null;if(this.compressedWhole)return this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);{const e=this.buffer.gdata(this.fileOffset[t],this.fileOffset[t]+this.fileSizeDeflated[t]);return p(e)}}}class O{static PERIOD=new Uint16Array(["d","o","t"].join("").split("").map((t=>t.charCodeAt(0))));static AMPERSAT=new Uint16Array(["(","a",")"].join("").split("").map((t=>t.charCodeAt(0))));static SLASH=new Uint16Array(["s","l","a","s","h"].join("").split("").map((t=>t.charCodeAt(0))));static whitelist=["cook","cook's","cooks","seeks","sheet"];static tlds=[];static tldTypes=[];static bads=[];static badCombinations=[];static domains=[];static fragments=[];static unpack=t=>{const i=new e(t.read("fragmentsenc.txt")),s=new e(t.read("badenc.txt")),r=new e(t.read("domainenc.txt")),a=new e(t.read("tldlist.txt"));this.read(s,r,i,a)};static filter=t=>{const e=[...t];this.format(e);const i=e.join("").trim(),s=i.toLowerCase(),r=[...s];this.filterTlds(r),this.filterBadWords(r),this.filterDomains(r),this.filterFragments(r);for(let t=0;t{this.readBadWords(t),this.readDomains(e),this.readFragments(i),this.readTld(s)};static readTld=t=>{const e=t.g4;for(let i=0;it.g1))};static readBadWords=t=>{const e=t.g4;for(let i=0;it.g1));const e=new Array(t.g1).fill([]).map((()=>[t.g1b,t.g1b]));e.length>0&&(this.badCombinations[i]=e)}};static readDomains=t=>{const e=t.g4;for(let i=0;it.g1))};static readFragments=t=>{const e=t.g4;for(let i=0;i{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.PERIOD),this.filterBadCombinations(null,i,this.SLASH);for(let s=0;s{for(let e=0;e<2;e++)for(let e=this.bads.length-1;e>=0;e--)this.filterBadCombinations(this.badCombinations[e],t,this.bads[e])};static filterDomains=t=>{const e=[...t],i=[...t];this.filterBadCombinations(null,e,this.AMPERSAT),this.filterBadCombinations(null,i,this.PERIOD);for(let s=this.domains.length-1;s>=0;s--)this.filterDomain(i,e,this.domains[s],t)};static filterFragments=t=>{for(let e=0;e=0&&r{if(this.isNumericalChars(t))return!0;const e=this.getInteger(t),i=this.fragments,s=i.length;if(e===i[0]||e===i[s-1])return!0;let r=0,a=s-1;for(;r<=a;){const t=Math.floor((r+a)/2);if(e===i[t])return!0;e{if(t.length>6)return 0;let e=0;for(let i=0;i{for(let i=e;i=0;i++)if(this.isNumerical(t[i]))return i;return-1};static indexOfNonNumber=(t,e)=>{for(let i=t;i=0;i++)if(!this.isNumerical(e[i]))return i;return e.length};static getEmulatedDomainCharLen=(t,e,i)=>e==i||"o"==e&&"0"==i?1:"o"==e&&"("==i&&")"==t?2:"c"!=e||"("!=i&&"<"!=i&&"["!=i?"e"==e&&"€"==i||"s"==e&&"$"==i||"l"==e&&"i"==i?1:0:1;static filterDomain=(t,e,i,s)=>{const r=i.length,a=s.length;for(let n=0;n<=a-r;n++){const{matched:r,currentIndex:a}=this.findMatchingDomain(n,i,s);if(!r)continue;const o=this.prefixSymbolStatus(n,s,3,e,["@"]),l=this.suffixSymbolStatus(a-1,s,3,t,[".",","]);(o>2||l>2)&&this.maskChars(n,a,s)}};static findMatchingDomain=(t,e,i)=>{const s=e.length;let r=t,a=0;for(;r0)r+=l,a++;else{if(0===a)break;const i=this.getEmulatedDomainCharLen(o,String.fromCharCode(e[a-1]),n);if(i>0)r+=i,1===a&&t++;else{if(a>=s||!this.isSymbol(n))break;r++}}}return{matched:a>=s,currentIndex:r}};static filterBadCombinations=(t,e,i)=>{if(!(i.length>e.length))for(let s=0;s<=e.length-i.length;s++){let r=s;const{currentIndex:a,badIndex:n,hasSymbol:o,hasNumber:l,hasDigit:h}=this.processBadCharacters(e,i,r);r=a;let c=e[r],f=r+1=i.length)||l&&h)continue;let d,u=!0;if(o){let t=!1,i=!1;if((s-1<0||this.isSymbol(e[s-1])&&"'"!=e[s-1])&&(t=!0),(r>=e.length||this.isSymbol(e[r])&&"'"!=e[r])&&(i=!0),!t||!i){let i=!1;for(d=s-2,t&&(d=s);!i&&d=0&&(!this.isSymbol(e[d])||"'"==e[d])){const t=[];let s;for(s=0;s<3&&d+s=0&&(!this.isSymbol(e[d-1])||"'"==e[d-1])&&(r=!1),r&&!this.isBadFragment(t)&&(i=!0)}d++}i||(u=!1)}}else{c=" ",s-1>=0&&(c=e[s-1]),f=" ",r{let s=i,r=0,a=0,n=!1,o=!1,l=!1;for(;s=t.length||o&&l);){const h=t[s],c=s+10)1===f&&this.isNumerical(h)&&(o=!0),2===f&&(this.isNumerical(h)||this.isNumerical(c))&&(o=!0),s+=f,r++;else{if(0===r)break;let t;if((t=this.getEmulatedBadCharLen(c,String.fromCharCode(e[r-1]),h))>0)s+=t;else{if(r>=e.length||!this.isNotLowercaseAlpha(h))break;if(this.isSymbol(h)&&"'"!==h&&(n=!0),this.isNumerical(h)&&(l=!0),s++,a++,100*a/(s-i)>90)break}}}return{currentIndex:s,badIndex:r,hasSymbol:n,hasNumber:o,hasDigit:l}};static getEmulatedBadCharLen=(t,e,i)=>{if(e==i)return 1;if(e>="a"&&e<="m"){if("a"==e)return"4"!=i&&"@"!=i&&"^"!=i?"/"==i&&"\\"==t?2:0:1;if("b"==e)return"6"!=i&&"8"!=i?"1"==i&&"3"==t?2:0:1;if("c"==e)return"("!=i&&"<"!=i&&"{"!=i&&"["!=i?0:1;if("d"==e)return"["==i&&")"==t?2:0;if("e"==e)return"3"!=i&&"€"!=i?0:1;if("f"==e)return"p"==i&&"h"==t?2:"£"==i?1:0;if("g"==e)return"9"!=i&&"6"!=i?0:1;if("h"==e)return"#"==i?1:0;if("i"==e)return"y"!=i&&"l"!=i&&"j"!=i&&"1"!=i&&"!"!=i&&":"!=i&&";"!=i&&"|"!=i?0:1;if("j"==e)return 0;if("k"==e)return 0;if("l"==e)return"1"!=i&&"|"!=i&&"i"!=i?0:1;if("m"==e)return 0}if(e>="n"&&e<="z"){if("n"==e)return 0;if("o"==e)return"0"!=i&&"*"!=i?"("==i&&")"==t||"["==i&&"]"==t||"{"==i&&"}"==t||"<"==i&&">"==t?2:0:1;if("p"==e)return 0;if("q"==e)return 0;if("r"==e)return 0;if("s"==e)return"5"!=i&&"z"!=i&&"$"!=i&&"2"!=i?0:1;if("t"==e)return"7"!=i&&"+"!=i?0:1;if("u"==e)return"v"==i?1:"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("v"==e)return"\\"==i&&"/"==t||"\\"==i&&"|"==t||"|"==i&&"/"==t?2:0;if("w"==e)return"v"==i&&"v"==t?2:0;if("x"==e)return")"==i&&"("==t||"}"==i&&"{"==t||"]"==i&&"["==t||">"==i&&"<"==t?2:0;if("y"==e)return 0;if("z"==e)return 0}return e>="0"&&e<="9"?"0"==e?"o"==i||"O"==i?1:"("==i&&")"==t||"{"==i&&"}"==t||"["==i&&"]"==t?2:0:"1"==e&&"l"==i?1:0:","==e?"."==i?1:0:"."==e?","==i?1:0:"!"==e&&"i"==i?1:0};static comboMatches=(t,e,i)=>{let s=0,r=e.length-1;for(;s<=r;){const a=Math.floor((s+r)/2);if(e[a][0]===t&&e[a][1]===i)return!0;tthis.isLowercaseAlpha(t)?t.charCodeAt(0)+1-"a".charCodeAt(0):"'"==t?28:this.isNumerical(t)?t.charCodeAt(0)+29-"0".charCodeAt(0):27;static filterTld=(t,e,i,s,r)=>{if(!(s.length>i.length))for(let a=0;a<=i.length-s.length;a++){const{currentIndex:n,tldIndex:o}=this.processTlds(i,s,a);if(o0&&c>0&&(l=!0),2==e&&(h>2&&c>0||h>0&&c>2)&&(l=!0),3==e&&h>0&&c>2&&(l=!0),!l)continue;let f,d=a,u=n-1,p=!1;if(h>2){if(4==h)for(p=!1,f=a-1;f>=0;f--)if(p){if("*"!=r[f])break;d=f}else"*"==r[f]&&(d=f,p=!0);for(p=!1,f=d-1;f>=0;f--)if(p){if(this.isSymbol(i[f]))break;d=f}else this.isSymbol(i[f])||(p=!0,d=f)}if(c>2){if(4==c)for(p=!1,f=u+1;f{let s=0;for(;i0)i+=n,s++;else{if(0===s)break;let t;if((t=this.getEmulatedDomainCharLen(a,String.fromCharCode(e[s-1]),r))>0)i+=t;else{if(!this.isSymbol(r))break;i++}}}return{currentIndex:i,tldIndex:s}};static isSymbol=t=>!this.isAlpha(t)&&!this.isNumerical(t);static isNotLowercaseAlpha=t=>!this.isLowercaseAlpha(t)||"v"==t||"x"==t||"j"==t||"q"==t||"z"==t;static isAlpha=t=>this.isLowercaseAlpha(t)||this.isUppercaseAlpha(t);static isNumerical=t=>t>="0"&&t<="9";static isLowercaseAlpha=t=>t>="a"&&t<="z";static isUppercaseAlpha=t=>t>="A"&&t<="Z";static isNumericalChars=t=>{for(let e=0;e{for(let s=t;s{let i=0;for(let s=e-1;s>=0&&this.isSymbol(t[s]);s--)"*"===t[s]&&i++;return i};static maskedCountForwards=(t,e)=>{let i=0;for(let s=e+1;s(r?this.maskedCountBackwards(e,i):this.maskedCountForwards(e,i))>=s?4:this.isSymbol(r?t[i-1]:t[i+1])?1:0;static prefixSymbolStatus=(t,e,i,s,r)=>{if(0===t)return 2;for(let i=t-1;i>=0&&this.isSymbol(e[i]);i--)if(r.includes(e[i]))return 3;return this.maskedCharsStatus(e,s,t,i,!0)};static suffixSymbolStatus=(t,e,i,s,r)=>{if(t+1===e.length)return 2;for(let i=t+1;i{let e=0;for(let i=0;it>=" "&&t<=""||" "==t||"\n"==t||"\t"==t||"£"==t||"€"==t;static replaceUppercases=(t,e)=>{for(let i=0;i{let e=!0;for(let i=0;i{this.pixels.fill(0)};bind=()=>{o.bind(this.pixels,this.width,this.height)};draw=(t,e)=>{this.#t(),this.ctx.putImageData(this.image,t,e)};#t=()=>{const t=this.image.data;for(let e=0;e>16&255,t[s+1]=i>>8&255,t[s+2]=i>>0&255,t[s+3]=255}}}class X{static getParameter(t){return new URLSearchParams(window.location.search).get(t)??""}static setParameter(t,e){const i=new URL(window.location.toString());i.searchParams.set(t,e),window.history.pushState(null,"",i.toString())}canvas;ctx;drawArea=null;state=0;deltime=20;mindel=1;otim=[];fps=0;fpos=0;frameTime=[];redrawScreen=!0;resizeToFit=!1;idleCycles=0;mouseButton=0;mouseX=0;mouseY=0;mouseClickButton=0;mouseClickX=0;mouseClickY=0;actionKey=[];keyQueue=[];keyQueueReadPos=0;keyQueueWritePos=0;constructor(t=!1){const e=document.getElementById("canvas");if(!e)throw new Error("Canvas not found!!!!!!!!");const i=e.getContext("2d");if(!i)throw new Error("Canvas 2d not found!!!!!!!!");this.canvas=e,this.ctx=i,this.resizeToFit=t,this.resizeToFit?this.resize(window.innerWidth,window.innerHeight):this.resize(e.width,e.height)}get width(){return this.canvas.width}get height(){return this.canvas.height}resize(t,e){const i=this.canvas;i.width=t,i.height=e,this.drawArea=new T(i,t,e),b.init2D()}async run(){window.addEventListener("resize",(()=>{this.resizeToFit&&this.resize(window.innerWidth,window.innerHeight)}),!1),window.addEventListener("keydown",this.keyDown),window.addEventListener("keyup",this.keyUp),window.addEventListener("mousedown",this.mousePressed),this.canvas.oncontextmenu=t=>{t.preventDefault()},await this.showProgress(0,"Loading..."),await this.load();for(let t=0;t<10;t++)this.otim[t]=Date.now();let t,e=0,i=256,s=1,r=0;for(;this.state>=0;){if(this.state>0&&(this.state--,0===this.state))return void this.shutdown();const a=i,n=s;i=300,s=1,t=Date.now();const o=this.otim[e];if(0===o?(i=a,s=n):t>o&&(i=Math.trunc(2560*this.deltime/(t-o))),i<25?i=25:i>256&&(i=256,s=Math.trunc(this.deltime-(t-o)/10)),this.otim[e]=t,e=(e+1)%10,s>1)for(let t=0;t<10;t++)0!==this.otim[t]&&(this.otim[t]+=s);for(s0&&(this.fps=Math.trunc(1e3*i/(256*this.deltime)));const l=performance.now();await this.draw(),this.frameTime[this.fpos]=(performance.now()-l)/1e3,this.fpos=(this.fpos+1)%this.frameTime.length}-1==this.state&&this.shutdown()}shutdown(){this.state=-2,this.unload()}setLoopRate(t){this.deltime=1e3/t}start(){this.state>=0&&(this.state=0)}stop(){this.state>=0&&(this.state=4e3/this.deltime)}destroy(){this.state=-1}async load(){}update(){}unload(){}async draw(){}refresh(){}async showProgress(t,e){const i=this.ctx,s=this.width,r=this.height;this.redrawScreen&&(i.fillStyle="black",i.clearRect(0,0,s,r),this.redrawScreen=!1);const a=r/2-18;i.fillStyle="rgb(140, 17, 17)",i.rect(s/2-152,a,304,34),i.fillRect(s/2-150,a+2,3*t,30),i.fillStyle="black",i.fillRect(s/2-150+3*t,a+2,300-3*t,30),i.font="bold 13px helvetica, sans-serif",i.textAlign="center",i.fillStyle="white",i.fillText(e,s/2,a+22),await d(5)}keyDown=t=>{this.idleCycles=0;const e=t.keyCode;let i=t.key.charCodeAt(0);83!==i&&(i<30&&(i=0),37==e?i=1:39==e?i=2:38==e?i=3:40==e?i=4:17==e?i=5:8==e||127==e?i=8:9==e?i=9:10==e?i=10:e>=112&&e<=123?i=e+1008-112:36==e?i=1e3:35==e?i=1001:33==e?i=1002:34==e&&(i=1003),i>0&&i<128&&(this.actionKey[i]=1),i>4&&(this.keyQueue[this.keyQueueWritePos]=i,this.keyQueueWritePos=this.keyQueueWritePos+1&127))};keyUp=t=>{this.idleCycles=0;let e=t.key.charCodeAt(0);"ArrowLeft"==t.key?e=1:"ArrowRight"==t.key?e=2:"ArrowUp"==t.key?e=3:"ArrowDown"==t.key&&(e=4),this.actionKey[e]=0};pollKey(){let t=-1;return this.keyQueueWritePos!=this.keyQueueReadPos&&(t=this.keyQueue[this.keyQueueReadPos],this.keyQueueReadPos=this.keyQueueReadPos+1&127),t}mousePressed=t=>{let e=t.x,i=t.y;const{top:s,left:r}=this.getInsets;e-=r,i-=s,this.idleCycles=0,this.mouseClickX=e,this.mouseClickY=i,2===t.buttons?(this.mouseClickButton=2,this.mouseButton=2):1===t.buttons&&(this.mouseClickButton=1,this.mouseButton=1)};get getInsets(){const t=this.canvas.getBoundingClientRect(),e=window.getComputedStyle(this.canvas),i=parseFloat(e.paddingLeft||"0"),s=parseFloat(e.paddingTop||"0"),r=parseFloat(e.borderLeftWidth||"0"),a=parseFloat(e.borderTopWidth||"0"),n=t.left+r+i;return{top:t.top+a+s,left:n}}get ms(){const t=this.frameTime.length;let e=0;for(let i=0;i{}}class D extends X{static HOST="https://w2.225.2004scape.org";static REPO="https://raw.githubusercontent.com/2004scape/Server/main";alreadyStarted=!1;errorStarted=!1;errorLoading=!1;errorHost=!1;loopCycle=0;ingame=!1;archiveChecksums=[];fontPlain11=null;fontPlain12=null;fontBold12=null;fontQuill8=null;packfiles=[];inputSpeedMultiplier=2;model={id:parseInt(X.getParameter("model"))||0,pitch:parseInt(X.getParameter("x"))||0,yaw:parseInt(X.getParameter("y"))||0,roll:parseInt(X.getParameter("z"))||0,built:null};camera={x:parseInt(X.getParameter("eyeX"))||0,y:parseInt(X.getParameter("eyeY"))||0,z:parseInt(X.getParameter("eyeZ"))||420,pitch:parseInt(X.getParameter("eyePitch"))||0};async loadPack(t){const e=new Map,i=await(async t=>(await fetch(t)).text())(t),s=i.split("\n");for(let t=0;t{if(this.alreadyStarted)this.errorStarted=!0;else{this.alreadyStarted=!0;try{await this.showProgress(10,"Connecting to fileserver");const t=new e(await u(`${D.HOST}/crc`));for(let e=0;e<9;e++)this.archiveChecksums[e]=t.g4;const o=await this.loadArchive("title","title screen",this.archiveChecksums[1],10);this.fontPlain11=I.fromArchive(o,"p11"),this.fontPlain12=I.fromArchive(o,"p12"),this.fontBold12=I.fromArchive(o,"b12"),this.fontQuill8=I.fromArchive(o,"q8");const l=await this.loadArchive("config","config",this.archiveChecksums[2],15),h=await this.loadArchive("interface","interface",this.archiveChecksums[3],20),c=await this.loadArchive("media","2d graphics",this.archiveChecksums[4],30),f=await this.loadArchive("models","3d graphics",this.archiveChecksums[5],40),d=await this.loadArchive("textures","textures",this.archiveChecksums[6],60),p=await this.loadArchive("wordenc","chat system",this.archiveChecksums[7],65),g=await this.loadArchive("sounds","sound effects",this.archiveChecksums[8],70);await this.showProgress(75,"Unpacking media"),await this.showProgress(80,"Unpacking textures"),b.unpackTextures(d),b.setBrightness(.8),b.initPool(20),await this.showProgress(83,"Unpacking models"),k.unpack(f),i.unpack(f),s.unpack(f),await this.showProgress(86,"Unpacking config"),r.unpack(l),a.unpack(l),n.unpack(l),m.unpack(l,!0),w.unpack(l),x.unpack(l),y.unpack(l),v.unpack(l),await this.showProgress(90,"Unpacking sounds"),F.unpack(g),await this.showProgress(92,"Unpacking interfaces"),P.unpack(h,c,[this.fontPlain11,this.fontPlain12,this.fontBold12,this.fontQuill8]),await this.showProgress(97,"Preparing game engine"),O.unpack(p),await this.showProgress(100,"Getting ready to start..."),this.drawArea?.bind(),b.init2D(),await this.showModels()}catch(t){this.errorLoading=!0,console.error(t)}}};update=()=>{this.errorStarted||this.errorLoading||this.errorHost||this.loopCycle++};draw=async()=>{this.errorStarted||this.errorLoading||this.errorHost?this.drawErrorScreen():(o.clear(),o.fillRect(0,0,this.width,this.height,0),null===this.model.built&&(this.model.built=new k(this.model.id)),this.model.built.calculateNormals(64,850,-30,-50,-30,!0),this.model.built.drawSimple(this.model.pitch,this.model.yaw,this.model.roll,this.camera.pitch,this.camera.x,this.camera.y,this.camera.z),this.fontBold12?.drawRight(this.width-1,this.fontBold12.fontHeight,`FPS: ${this.fps}`,16776960),this.fontBold12?.draw(1,this.fontBold12.fontHeight,`ID: ${this.model.id}`,16776960),this.drawArea?.draw(0,0))};showProgress=async(t,e)=>{console.log(`${t}%: ${e}`),await super.showProgress(t,e)};async loadArchive(t,e,i,s){await this.showProgress(s,`Requesting ${e}`);const r=await Y.loadUrl(`${D.HOST}/${t}${i}`);return await this.showProgress(s,`Loading ${e} - 100%`),r}drawErrorScreen(){if(this.ctx&&this.canvas){if(this.ctx.fillStyle="black",this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.setLoopRate(1),this.errorLoading){this.ctx.font="bold 16px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="yellow";let t=35;this.ctx.fillText("Sorry, an error has occured whilst loading RuneScape",30,t),t+=50,this.ctx.fillStyle="white",this.ctx.fillText("To fix this try the following (in order):",30,t),t+=50,this.ctx.font="bold 12px helvetica, sans-serif",this.ctx.fillText("1: Try closing ALL open web-browser windows, and reloading",30,t),t+=30,this.ctx.fillText("2: Try clearing your web-browsers cache from tools->internet options",30,t),t+=30,this.ctx.fillText("3: Try using a different game-world",30,t),t+=30,this.ctx.fillText("4: Try rebooting your computer",30,t),t+=30,this.ctx.fillText("5: Try selecting a different version of Java from the play-game menu",30,t)}if(this.errorHost&&(this.ctx.font="bold 20px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="white",this.ctx.fillText("Error - unable to load game!",50,50),this.ctx.fillText("To play RuneScape make sure you play from",50,100),this.ctx.fillText("https://2004scape.org",50,150)),this.errorStarted){this.ctx.font="bold 13px helvetica, sans-serif",this.ctx.textAlign="left",this.ctx.fillStyle="yellow";let t=35;this.ctx.fillText("Error a copy of RuneScape already appears to be loaded",30,t),t+=50,this.ctx.fillStyle="white",this.ctx.fillText("To fix this try the following (in order):",30,t),t+=50,this.ctx.font="bold 12px helvetica, sans-serif",this.ctx.fillText("1: Try closing ALL open web-browser windows, and reloading",30,t),t+=30,this.ctx.fillText("2: Try rebooting your computer, and reloading",30,t)}}}async showModels(){this.packfiles[0]=await this.loadPack(`${D.REPO}/data/pack/model.pack`);const t=document.getElementById("leftPanel");if(t){t.innerHTML="";{const i=document.createElement("input");i.type="search",i.placeholder="Search",i.oninput=()=>{const t=i.value.toLowerCase().replaceAll(" ","_");for(let i=0;i-1?s.style.display="":s.style.display="none"}},t.appendChild(i)}const e=document.createElement("ul");e.className="list-group",t.appendChild(e);for(const[t,i]of this.packfiles[0]){const s=document.createElement("li");s.id=i,s.className="list-group-item",0==t&&(s.className+=" active"),s.innerText=i,s.onclick=()=>{const i=e.querySelector(".active");i&&(i.className="list-group-item"),s.className="list-group-item active",this.model.id=t,this.model.built=new k(this.model.id)},e.appendChild(s)}}}}(new D).run().then((()=>{}))})(); \ No newline at end of file