diff --git a/worker.js b/worker.js index b2936ec5..4a6db82a 100644 --- a/worker.js +++ b/worker.js @@ -1 +1 @@ -var e,t,i,r,s=Object.create,n=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,h=(e=>'undefined'!=typeof require?require:'undefined'!=typeof Proxy?new Proxy(e,{get:(e,t)=>('undefined'!=typeof require?require:e)[t]}):e)((function(e){if('undefined'!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')})),d=(e,t)=>function(){return t||(0,e[o(e)[0]])((t={exports:{}}).exports,t),t.exports},u=d({'node_modules/node-forge/lib/forge.js'(e,t){t.exports={options:{usePureJavaScript:!1}}}}),p=d({'node_modules/node-forge/lib/baseN.js'(e,t){var i={};t.exports=i;var r={};i.encode=function(e,t,i){if('string'!=typeof t)throw new TypeError('"alphabet" must be a string.');if(void 0!==i&&'number'!=typeof i)throw new TypeError('"maxline" must be a number.');var r='';if(e instanceof Uint8Array){var s=0,n=t.length,a=t.charAt(0),o=[0];for(s=0;s0;)o.push(l%n),l=l/n|0}for(s=0;0===e[s]&&s=0;--s)r+=t[o[s]]}else r=function(e,t){var i=0,r=t.length,s=t.charAt(0),n=[0];for(i=0;i0;)n.push(o%r),o=o/r|0}var c='';for(i=0;0===e.at(i)&&i=0;--i)c+=t[n[i]];return c}(e,t);if(i){var h=new RegExp('.{1,'+i+'}','g');r=r.match(h).join('\r\n')}return r},i.decode=function(e,t){if('string'!=typeof e)throw new TypeError('"input" must be a string.');if('string'!=typeof t)throw new TypeError('"alphabet" must be a string.');var i=r[t];if(!i){i=r[t]=[];for(var s=0;s>=8;for(;h>0;)o.push(255&h),h>>=8}for(var d=0;e[d]===a&&d15?(i=Date.now(),a(e)):(t.push(e),1===t.length&&n.setAttribute('a',r=!r))}}s.nextTick=s.setImmediate}(),s.isNodejs='undefined'!=typeof process&&process.versions&&process.versions.node,s.globalScope=s.isNodejs?global:'undefined'==typeof self?window:self,s.isArray=Array.isArray||function(e){return'[object Array]'===Object.prototype.toString.call(e)},s.isArrayBuffer=function(e){return'undefined'!=typeof ArrayBuffer&&e instanceof ArrayBuffer},s.isArrayBufferView=function(e){return e&&s.isArrayBuffer(e.buffer)&&void 0!==e.byteLength},s.ByteBuffer=a,s.ByteStringBuffer=a;s.ByteStringBuffer.prototype._optimizeConstructedString=function(e){this._constructedStringLength+=e,this._constructedStringLength>4096&&(this.data.substr(0,1),this._constructedStringLength=0)},s.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read},s.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0},s.ByteStringBuffer.prototype.putByte=function(e){return this.putBytes(String.fromCharCode(e))},s.ByteStringBuffer.prototype.fillWithByte=function(e,t){e=String.fromCharCode(e);for(var i=this.data;t>0;)1&t&&(i+=e),(t>>>=1)>0&&(e+=e);return this.data=i,this._optimizeConstructedString(t),this},s.ByteStringBuffer.prototype.putBytes=function(e){return this.data+=e,this._optimizeConstructedString(e.length),this},s.ByteStringBuffer.prototype.putString=function(e){return this.putBytes(s.encodeUtf8(e))},s.ByteStringBuffer.prototype.putInt16=function(e){return this.putBytes(String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},s.ByteStringBuffer.prototype.putInt24=function(e){return this.putBytes(String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},s.ByteStringBuffer.prototype.putInt32=function(e){return this.putBytes(String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},s.ByteStringBuffer.prototype.putInt16Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255))},s.ByteStringBuffer.prototype.putInt24Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255))},s.ByteStringBuffer.prototype.putInt32Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>24&255))},s.ByteStringBuffer.prototype.putInt=function(e,t){n(t);var i='';do{t-=8,i+=String.fromCharCode(e>>t&255)}while(t>0);return this.putBytes(i)},s.ByteStringBuffer.prototype.putSignedInt=function(e,t){return e<0&&(e+=2<0);return t},s.ByteStringBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),i=2<=i&&(t-=i<<1),t},s.ByteStringBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t='':(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},s.ByteStringBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},s.ByteStringBuffer.prototype.at=function(e){return this.data.charCodeAt(this.read+e)},s.ByteStringBuffer.prototype.setAt=function(e,t){return this.data=this.data.substr(0,this.read+e)+String.fromCharCode(t)+this.data.substr(this.read+e+1),this},s.ByteStringBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},s.ByteStringBuffer.prototype.copy=function(){var e=s.createBuffer(this.data);return e.read=this.read,e},s.ByteStringBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},s.ByteStringBuffer.prototype.clear=function(){return this.data='',this.read=0,this},s.ByteStringBuffer.prototype.truncate=function(e){var t=Math.max(0,this.length()-e);return this.data=this.data.substr(this.read,t),this.read=0,this},s.ByteStringBuffer.prototype.toHex=function(){for(var e='',t=this.read;t=e)return this;t=Math.max(t||this.growSize,e);var i=new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength),r=new Uint8Array(this.length()+t);return r.set(i),this.data=new DataView(r.buffer),this},s.DataBuffer.prototype.putByte=function(e){return this.accommodate(1),this.data.setUint8(this.write++,e),this},s.DataBuffer.prototype.fillWithByte=function(e,t){this.accommodate(t);for(var i=0;i>8&65535),this.data.setInt8(this.write,e>>16&255),this.write+=3,this},s.DataBuffer.prototype.putInt32=function(e){return this.accommodate(4),this.data.setInt32(this.write,e),this.write+=4,this},s.DataBuffer.prototype.putInt16Le=function(e){return this.accommodate(2),this.data.setInt16(this.write,e,!0),this.write+=2,this},s.DataBuffer.prototype.putInt24Le=function(e){return this.accommodate(3),this.data.setInt8(this.write,e>>16&255),this.data.setInt16(this.write,e>>8&65535,!0),this.write+=3,this},s.DataBuffer.prototype.putInt32Le=function(e){return this.accommodate(4),this.data.setInt32(this.write,e,!0),this.write+=4,this},s.DataBuffer.prototype.putInt=function(e,t){n(t),this.accommodate(t/8);do{t-=8,this.data.setInt8(this.write++,e>>t&255)}while(t>0);return this},s.DataBuffer.prototype.putSignedInt=function(e,t){return n(t),this.accommodate(t/8),e<0&&(e+=2<0);return t},s.DataBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),i=2<=i&&(t-=i<<1),t},s.DataBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t='':(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},s.DataBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},s.DataBuffer.prototype.at=function(e){return this.data.getUint8(this.read+e)},s.DataBuffer.prototype.setAt=function(e,t){return this.data.setUint8(e,t),this},s.DataBuffer.prototype.last=function(){return this.data.getUint8(this.write-1)},s.DataBuffer.prototype.copy=function(){return new s.DataBuffer(this)},s.DataBuffer.prototype.compact=function(){if(this.read>0){var e=new Uint8Array(this.data.buffer,this.read),t=new Uint8Array(e.byteLength);t.set(e),this.data=new DataView(t),this.write-=this.read,this.read=0}return this},s.DataBuffer.prototype.clear=function(){return this.data=new DataView(new ArrayBuffer(0)),this.read=this.write=0,this},s.DataBuffer.prototype.truncate=function(e){return this.write=Math.max(0,this.length()-e),this.read=Math.min(this.read,this.write),this},s.DataBuffer.prototype.toHex=function(){for(var e='',t=this.read;t0;)1&t&&(i+=e),(t>>>=1)>0&&(e+=e);return i},s.xorBytes=function(e,t,i){for(var r='',s='',n='',a=0,o=0;i>0;--i,++a)s=e.charCodeAt(a)^t.charCodeAt(a),o>=10&&(r+=n,n='',o=0),n+=String.fromCharCode(s),++o;return r+=n},s.hexToBytes=function(e){var t='',i=0;for(!0&e.length&&(i=1,t+=String.fromCharCode(parseInt(e[0],16)));i>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e)};var o='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',c=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],l='123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';s.encode64=function(e,t){for(var i,r,s,n='',a='',c=0;c>2),n+=o.charAt((3&i)<<4|r>>4),isNaN(r)?n+='==':(n+=o.charAt((15&r)<<2|s>>6),n+=isNaN(s)?'=':o.charAt(63&s)),t&&n.length>t&&(a+=n.substr(0,t)+'\r\n',n=n.substr(t));return a+=n},s.decode64=function(e){e=e.replace(/[^A-Za-z0-9\+\/\=]/g,'');for(var t,i,r,s,n='',a=0;a>4),64!==r&&(n+=String.fromCharCode((15&i)<<4|r>>2),64!==s&&(n+=String.fromCharCode((3&r)<<6|s)));return n},s.encodeUtf8=function(e){return unescape(encodeURIComponent(e))},s.decodeUtf8=function(e){return decodeURIComponent(escape(e))},s.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:r.encode,decode:r.decode}},s.binary.raw.encode=function(e){return String.fromCharCode.apply(null,e)},s.binary.raw.decode=function(e,t,i){var r=t;r||(r=new Uint8Array(e.length));for(var s=i=i||0,n=0;n>2),n+=o.charAt((3&i)<<4|r>>4),isNaN(r)?n+='==':(n+=o.charAt((15&r)<<2|s>>6),n+=isNaN(s)?'=':o.charAt(63&s)),t&&n.length>t&&(a+=n.substr(0,t)+'\r\n',n=n.substr(t));return a+=n},s.binary.base64.decode=function(e,t,i){var r,s,n,a,o=t;o||(o=new Uint8Array(3*Math.ceil(e.length/4))),e=e.replace(/[^A-Za-z0-9\+\/\=]/g,'');for(var l=0,h=i=i||0;l>4,64!==n&&(o[h++]=(15&s)<<4|n>>2,64!==a&&(o[h++]=(3&n)<<6|a));return t?h-i:o.subarray(0,h)},s.binary.base58.encode=function(e,t){return s.binary.baseN.encode(e,l,t)},s.binary.base58.decode=function(e,t){return s.binary.baseN.decode(e,l,t)},s.text={utf8:{},utf16:{}},s.text.utf8.encode=function(e,t,i){e=s.encodeUtf8(e);var r=t;r||(r=new Uint8Array(e.length));for(var n=i=i||0,a=0;a0&&n.push(i),a=r.lastIndex;var o=t[0][1];switch(o){case's':case'o':s');break;case'%':n.push('%');break;default:n.push('<%'+o+'?>')}}return n.push(e.substring(a)),n.join('')},s.formatNumber=function(e,t,i,r){var s=e,n=isNaN(t=Math.abs(t))?2:t,a=void 0===i?',':i,o=void 0===r?'.':r,c=s<0?'-':'',l=parseInt(s=Math.abs(+s||0).toFixed(n),10)+'',h=l.length>3?l.length%3:0;return c+(h?l.substr(0,h)+o:'')+l.substr(h).replace(/(\d{3})(?=\d)/g,'$1'+o)+(n?a+Math.abs(s-l).toFixed(n).slice(2):'')},s.formatSize=function(e){return e=e>=1073741824?s.formatNumber(e/1073741824,2,'.','')+' GiB':e>=1048576?s.formatNumber(e/1048576,2,'.','')+' MiB':e>=1024?s.formatNumber(e/1024,0)+' KiB':s.formatNumber(e,0)+' bytes'},s.bytesFromIP=function(e){return-1!==e.indexOf('.')?s.bytesFromIPv4(e):-1!==e.indexOf(':')?s.bytesFromIPv6(e):null},s.bytesFromIPv4=function(e){if(4!==(e=e.split('.')).length)return null;for(var t=s.createBuffer(),i=0;ii[r].end-i[r].start&&(r=i.length-1)):i.push({start:c,end:c})}t.push(a)}if(i.length>0){var l=i[r];l.end-l.start>0&&(t.splice(l.start,l.end-l.start+1,''),0===l.start&&t.unshift(''),7===l.end&&t.push(''))}return t.join(':')},s.estimateCores=function(e,t){if('function'==typeof e&&(t=e,e={}),e=e||{},'cores'in s&&!e.update)return t(null,s.cores);if('undefined'!=typeof navigator&&'hardwareConcurrency'in navigator&&navigator.hardwareConcurrency>0)return s.cores=navigator.hardwareConcurrency,t(null,s.cores);if('undefined'==typeof Worker)return s.cores=1,t(null,s.cores);if('undefined'==typeof Blob)return s.cores=2,t(null,s.cores);var i=URL.createObjectURL(new Blob(['(',function(){self.addEventListener('message',(function(e){for(var t=Date.now(),i=t+4;Date.now()o.st&&s.sts.st&&o.st4){var r=e;e=i.util.createBuffer();for(var s=0;s0))return!0;for(var r=0;r0))return!0;for(var r=0;r0)return!1;var i=e.length(),r=e.at(i-1);return!(r>this.blockSize<<2)&&(e.truncate(r),!0)},r.cbc=function(e){e=e||{},this.name='CBC',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},r.cbc.prototype.start=function(e){if(null===e.iv){if(!this._prev)throw new Error('Invalid IV parameter.');this._iv=this._prev.slice(0)}else{if(!('iv'in e))throw new Error('Invalid IV parameter.');this._iv=s(e.iv,this.blockSize),this._prev=this._iv.slice(0)}},r.cbc.prototype.encrypt=function(e,t,i){if(e.length()0))return!0;for(var r=0;r0))return!0;for(var r=0;r0)return!1;var i=e.length(),r=e.at(i-1);return!(r>this.blockSize<<2)&&(e.truncate(r),!0)},r.cfb=function(e){e=e||{},this.name='CFB',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},r.cfb.prototype.start=function(e){if(!('iv'in e))throw new Error('Invalid IV parameter.');this._iv=s(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},r.cfb.prototype.encrypt=function(e,t,i){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var s=0;s0&&(n=this.blockSize-n),this._partialOutput.clear();for(s=0;s0)e.read-=this.blockSize;else for(s=0;s0&&this._partialOutput.getBytes(this._partialBytes),n>0&&!i)return t.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=n,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},r.cfb.prototype.decrypt=function(e,t,i){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var s=0;s0&&(n=this.blockSize-n),this._partialOutput.clear();for(s=0;s0)e.read-=this.blockSize;else for(s=0;s0&&this._partialOutput.getBytes(this._partialBytes),n>0&&!i)return t.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=n,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},r.ofb=function(e){e=e||{},this.name='OFB',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},r.ofb.prototype.start=function(e){if(!('iv'in e))throw new Error('Invalid IV parameter.');this._iv=s(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},r.ofb.prototype.encrypt=function(e,t,i){var r=e.length();if(0===e.length())return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var s=0;s0&&(n=this.blockSize-n),this._partialOutput.clear();for(s=0;s0)e.read-=this.blockSize;else for(s=0;s0&&this._partialOutput.getBytes(this._partialBytes),n>0&&!i)return t.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=n,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},r.ofb.prototype.decrypt=r.ofb.prototype.encrypt,r.ctr=function(e){e=e||{},this.name='CTR',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},r.ctr.prototype.start=function(e){if(!('iv'in e))throw new Error('Invalid IV parameter.');this._iv=s(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},r.ctr.prototype.encrypt=function(e,t,i){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var s=0;s0&&(a=this.blockSize-a),this._partialOutput.clear();for(s=0;s0&&(e.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),a>0&&!i)return t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=a,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}n(this._inBlock)},r.ctr.prototype.decrypt=r.ctr.prototype.encrypt,r.gcm=function(e){e=e||{},this.name='GCM',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0,this._R=3774873600},r.gcm.prototype.start=function(e){if(!('iv'in e))throw new Error('Invalid IV parameter.');var t,r=i.util.createBuffer(e.iv);if(this._cipherLength=0,t='additionalData'in e?i.util.createBuffer(e.additionalData):i.util.createBuffer(),this._tagLength='tagLength'in e?e.tagLength:128,this._tag=null,e.decrypt&&(this._tag=i.util.createBuffer(e.tag).getBytes(),this._tag.length!==this._tagLength/8))throw new Error('Authentication tag does not match tag length.');this._hashBlock=new Array(this._ints),this.tag=null,this._hashSubkey=new Array(this._ints),this.cipher.encrypt([0,0,0,0],this._hashSubkey),this.componentBits=4,this._m=this.generateHashTable(this._hashSubkey,this.componentBits);var s=r.length();if(12===s)this._j0=[r.getInt32(),r.getInt32(),r.getInt32(),1];else{for(this._j0=[0,0,0,0];r.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[r.getInt32(),r.getInt32(),r.getInt32(),r.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(a(8*s)))}this._inBlock=this._j0.slice(0),n(this._inBlock),this._partialBytes=0,t=i.util.createBuffer(t),this._aDataLength=a(8*t.length());var o=t.length()%this.blockSize;for(o&&t.fillWithByte(0,this.blockSize-o),this._s=[0,0,0,0];t.length()>0;)this._s=this.ghash(this._hashSubkey,this._s,[t.getInt32(),t.getInt32(),t.getInt32(),t.getInt32()])},r.gcm.prototype.encrypt=function(e,t,i){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize){for(var s=0;s0&&(a=this.blockSize-a),this._partialOutput.clear();for(s=0;s0&&this._partialOutput.getBytes(this._partialBytes),a>0&&!i)return e.read-=this.blockSize,t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=a,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}this._s=this.ghash(this._hashSubkey,this._s,this._outBlock),n(this._inBlock)},r.gcm.prototype.decrypt=function(e,t,i){var r=e.length();if(r0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),n(this._inBlock),this._hashBlock[0]=e.getInt32(),this._hashBlock[1]=e.getInt32(),this._hashBlock[2]=e.getInt32(),this._hashBlock[3]=e.getInt32(),this._s=this.ghash(this._hashSubkey,this._s,this._hashBlock);for(var s=0;s0;--r)t[r]=e[r]>>>1|(1&e[r-1])<<31;t[0]=e[0]>>>1,i&&(t[0]^=this._R)},r.gcm.prototype.tableMultiply=function(e){for(var t=[0,0,0,0],i=0;i<32;++i){var r=e[i/8|0]>>>4*(7-i%8)&15,s=this._m[i][r];t[0]^=s[0],t[1]^=s[1],t[2]^=s[2],t[3]^=s[3]}return t},r.gcm.prototype.ghash=function(e,t,i){return t[0]^=i[0],t[1]^=i[1],t[2]^=i[2],t[3]^=i[3],this.tableMultiply(t)},r.gcm.prototype.generateHashTable=function(e,t){for(var i=8/t,r=4*i,s=16*i,n=new Array(s),a=0;a>>1,s=new Array(i);s[r]=e.slice(0);for(var n=r>>>1;n>0;)this.pow(s[2*n],s[n]=[]),n>>=1;for(n=2;n>>=2;for(s=0;s>8^255&d^99,s[g]=d,n[d]=g,p=(u=e[d])<<24^d<<16^d<<8^d^u,f=((i=e[g])^(r=e[i])^(h=e[r]))<<24^(g^h)<<16^(g^r^h)<<8^g^i^h;for(var y=0;y<4;++y)o[y][g]=p,c[y][d]=f,p=p<<24|p>>>8,f=f<<24|f>>>8;0===g?g=m=1:(g=i^e[e[e[i^h]]],m^=e[e[m]])}}function d(e,t){for(var i,r=e.slice(0),n=1,o=r.length,l=4*(o+6+1),h=o;h>>16&255]<<24^s[i>>>8&255]<<16^s[255&i]<<8^s[i>>>24]^a[n]<<24,n++):o>6&&h%o==4&&(i=s[i>>>24]<<24^s[i>>>16&255]<<16^s[i>>>8&255]<<8^s[255&i]),r[h]=r[h-o]^i;if(t){for(var d,u=c[0],p=c[1],f=c[2],g=c[3],m=r.slice(0),y=(h=0,(l=r.length)-4);h>>24]]^p[s[d>>>16&255]]^f[s[d>>>8&255]]^g[s[255&d]];r=m}return r}function p(e,t,i,r){var a,l,h,d,u,p,f,g,m,y,E,_,A=e.length/4-1;r?(a=c[0],l=c[1],h=c[2],d=c[3],u=n):(a=o[0],l=o[1],h=o[2],d=o[3],u=s),p=t[0]^e[0],f=t[r?3:1]^e[1],g=t[2]^e[2],m=t[r?1:3]^e[3];for(var v=3,T=1;T>>24]^l[f>>>16&255]^h[g>>>8&255]^d[255&m]^e[++v],E=a[f>>>24]^l[g>>>16&255]^h[m>>>8&255]^d[255&p]^e[++v],_=a[g>>>24]^l[m>>>16&255]^h[p>>>8&255]^d[255&f]^e[++v],m=a[m>>>24]^l[p>>>16&255]^h[f>>>8&255]^d[255&g]^e[++v],p=y,f=E,g=_;i[0]=u[p>>>24]<<24^u[f>>>16&255]<<16^u[g>>>8&255]<<8^u[255&m]^e[++v],i[r?3:1]=u[f>>>24]<<24^u[g>>>16&255]<<16^u[m>>>8&255]<<8^u[255&p]^e[++v],i[2]=u[g>>>24]<<24^u[m>>>16&255]<<16^u[p>>>8&255]<<8^u[255&f]^e[++v],i[r?1:3]=u[m>>>24]<<24^u[p>>>16&255]<<16^u[f>>>8&255]<<8^u[255&g]^e[++v]}function y(e){var t,r='AES-'+((e=e||{}).mode||'CBC').toUpperCase(),s=(t=e.decrypt?i.cipher.createDecipher(r,e.key):i.cipher.createCipher(r,e.key)).start;return t.start=function(e,r){var n=null;r instanceof i.util.ByteBuffer&&(n=r,r={}),(r=r||{}).output=n,r.iv=e,s.call(t,r)},t}}}),E=d({'node_modules/node-forge/lib/oids.js'(e,t){var i=u();i.pki=i.pki||{};var r=t.exports=i.pki.oids=i.oids=i.oids||{};function s(e,t){r[e]=t,r[t]=e}function n(e,t){r[e]=t}s('1.2.840.113549.1.1.1','rsaEncryption'),s('1.2.840.113549.1.1.4','md5WithRSAEncryption'),s('1.2.840.113549.1.1.5','sha1WithRSAEncryption'),s('1.2.840.113549.1.1.7','RSAES-OAEP'),s('1.2.840.113549.1.1.8','mgf1'),s('1.2.840.113549.1.1.9','pSpecified'),s('1.2.840.113549.1.1.10','RSASSA-PSS'),s('1.2.840.113549.1.1.11','sha256WithRSAEncryption'),s('1.2.840.113549.1.1.12','sha384WithRSAEncryption'),s('1.2.840.113549.1.1.13','sha512WithRSAEncryption'),s('1.3.101.112','EdDSA25519'),s('1.2.840.10040.4.3','dsa-with-sha1'),s('1.3.14.3.2.7','desCBC'),s('1.3.14.3.2.26','sha1'),s('1.3.14.3.2.29','sha1WithRSASignature'),s('2.16.840.1.101.3.4.2.1','sha256'),s('2.16.840.1.101.3.4.2.2','sha384'),s('2.16.840.1.101.3.4.2.3','sha512'),s('2.16.840.1.101.3.4.2.4','sha224'),s('2.16.840.1.101.3.4.2.5','sha512-224'),s('2.16.840.1.101.3.4.2.6','sha512-256'),s('1.2.840.113549.2.2','md2'),s('1.2.840.113549.2.5','md5'),s('1.2.840.113549.1.7.1','data'),s('1.2.840.113549.1.7.2','signedData'),s('1.2.840.113549.1.7.3','envelopedData'),s('1.2.840.113549.1.7.4','signedAndEnvelopedData'),s('1.2.840.113549.1.7.5','digestedData'),s('1.2.840.113549.1.7.6','encryptedData'),s('1.2.840.113549.1.9.1','emailAddress'),s('1.2.840.113549.1.9.2','unstructuredName'),s('1.2.840.113549.1.9.3','contentType'),s('1.2.840.113549.1.9.4','messageDigest'),s('1.2.840.113549.1.9.5','signingTime'),s('1.2.840.113549.1.9.6','counterSignature'),s('1.2.840.113549.1.9.7','challengePassword'),s('1.2.840.113549.1.9.8','unstructuredAddress'),s('1.2.840.113549.1.9.14','extensionRequest'),s('1.2.840.113549.1.9.20','friendlyName'),s('1.2.840.113549.1.9.21','localKeyId'),s('1.2.840.113549.1.9.22.1','x509Certificate'),s('1.2.840.113549.1.12.10.1.1','keyBag'),s('1.2.840.113549.1.12.10.1.2','pkcs8ShroudedKeyBag'),s('1.2.840.113549.1.12.10.1.3','certBag'),s('1.2.840.113549.1.12.10.1.4','crlBag'),s('1.2.840.113549.1.12.10.1.5','secretBag'),s('1.2.840.113549.1.12.10.1.6','safeContentsBag'),s('1.2.840.113549.1.5.13','pkcs5PBES2'),s('1.2.840.113549.1.5.12','pkcs5PBKDF2'),s('1.2.840.113549.1.12.1.1','pbeWithSHAAnd128BitRC4'),s('1.2.840.113549.1.12.1.2','pbeWithSHAAnd40BitRC4'),s('1.2.840.113549.1.12.1.3','pbeWithSHAAnd3-KeyTripleDES-CBC'),s('1.2.840.113549.1.12.1.4','pbeWithSHAAnd2-KeyTripleDES-CBC'),s('1.2.840.113549.1.12.1.5','pbeWithSHAAnd128BitRC2-CBC'),s('1.2.840.113549.1.12.1.6','pbewithSHAAnd40BitRC2-CBC'),s('1.2.840.113549.2.7','hmacWithSHA1'),s('1.2.840.113549.2.8','hmacWithSHA224'),s('1.2.840.113549.2.9','hmacWithSHA256'),s('1.2.840.113549.2.10','hmacWithSHA384'),s('1.2.840.113549.2.11','hmacWithSHA512'),s('1.2.840.113549.3.7','des-EDE3-CBC'),s('2.16.840.1.101.3.4.1.2','aes128-CBC'),s('2.16.840.1.101.3.4.1.22','aes192-CBC'),s('2.16.840.1.101.3.4.1.42','aes256-CBC'),s('2.5.4.3','commonName'),s('2.5.4.4','surname'),s('2.5.4.5','serialNumber'),s('2.5.4.6','countryName'),s('2.5.4.7','localityName'),s('2.5.4.8','stateOrProvinceName'),s('2.5.4.9','streetAddress'),s('2.5.4.10','organizationName'),s('2.5.4.11','organizationalUnitName'),s('2.5.4.12','title'),s('2.5.4.13','description'),s('2.5.4.15','businessCategory'),s('2.5.4.17','postalCode'),s('2.5.4.42','givenName'),s('1.3.6.1.4.1.311.60.2.1.2','jurisdictionOfIncorporationStateOrProvinceName'),s('1.3.6.1.4.1.311.60.2.1.3','jurisdictionOfIncorporationCountryName'),s('2.16.840.1.113730.1.1','nsCertType'),s('2.16.840.1.113730.1.13','nsComment'),n('2.5.29.1','authorityKeyIdentifier'),n('2.5.29.2','keyAttributes'),n('2.5.29.3','certificatePolicies'),n('2.5.29.4','keyUsageRestriction'),n('2.5.29.5','policyMapping'),n('2.5.29.6','subtreesConstraint'),n('2.5.29.7','subjectAltName'),n('2.5.29.8','issuerAltName'),n('2.5.29.9','subjectDirectoryAttributes'),n('2.5.29.10','basicConstraints'),n('2.5.29.11','nameConstraints'),n('2.5.29.12','policyConstraints'),n('2.5.29.13','basicConstraints'),s('2.5.29.14','subjectKeyIdentifier'),s('2.5.29.15','keyUsage'),n('2.5.29.16','privateKeyUsagePeriod'),s('2.5.29.17','subjectAltName'),s('2.5.29.18','issuerAltName'),s('2.5.29.19','basicConstraints'),n('2.5.29.20','cRLNumber'),n('2.5.29.21','cRLReason'),n('2.5.29.22','expirationDate'),n('2.5.29.23','instructionCode'),n('2.5.29.24','invalidityDate'),n('2.5.29.25','cRLDistributionPoints'),n('2.5.29.26','issuingDistributionPoint'),n('2.5.29.27','deltaCRLIndicator'),n('2.5.29.28','issuingDistributionPoint'),n('2.5.29.29','certificateIssuer'),n('2.5.29.30','nameConstraints'),s('2.5.29.31','cRLDistributionPoints'),s('2.5.29.32','certificatePolicies'),n('2.5.29.33','policyMappings'),n('2.5.29.34','policyConstraints'),s('2.5.29.35','authorityKeyIdentifier'),n('2.5.29.36','policyConstraints'),s('2.5.29.37','extKeyUsage'),n('2.5.29.46','freshestCRL'),n('2.5.29.54','inhibitAnyPolicy'),s('1.3.6.1.4.1.11129.2.4.2','timestampList'),s('1.3.6.1.5.5.7.1.1','authorityInfoAccess'),s('1.3.6.1.5.5.7.3.1','serverAuth'),s('1.3.6.1.5.5.7.3.2','clientAuth'),s('1.3.6.1.5.5.7.3.3','codeSigning'),s('1.3.6.1.5.5.7.3.4','emailProtection'),s('1.3.6.1.5.5.7.3.8','timeStamping')}}),_=d({'node_modules/node-forge/lib/asn1.js'(e,t){var i=u();f(),E();var r=t.exports=i.asn1=i.asn1||{};function s(e,t,i){if(i>t){var r=new Error('Too few bytes to parse DER.');throw r.available=e.length(),r.remaining=t,r.requested=i,r}}r.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},r.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30},r.create=function(e,t,s,n,a){if(i.util.isArray(n)){for(var o=[],c=0;ct){if(a.strict){var f=new Error('Too few bytes to read ASN.1 value.');throw f.available=e.length(),f.remaining=t,f.requested=p,f}p=t}var g=!(32&~c);if(g)if(d=[],void 0===p)for(;;){if(s(e,t,2),e.bytes(2)===String.fromCharCode(0,0)){e.getBytes(2),t-=2;break}o=e.length(),d.push(n(e,t,i+1,a)),t-=o-e.length()}else for(;p>0;)o=e.length(),d.push(n(e,p,i+1,a)),t-=o-e.length(),p-=o-e.length();if(void 0===d&&l===r.Class.UNIVERSAL&&h===r.Type.BITSTRING&&(u=e.bytes(p)),void 0===d&&a.decodeBitStrings&&l===r.Class.UNIVERSAL&&h===r.Type.BITSTRING&&p>1){var m=e.read,y=t,E=0;if(h===r.Type.BITSTRING&&(s(e,t,1),E=e.getByte(),t--),0===E)try{o=e.length();var _=n(e,t,i+1,{strict:!0,decodeBitStrings:!0}),A=o-e.length();t-=A,h==r.Type.BITSTRING&&A++;var v=_.tagClass;A!==p||v!==r.Class.UNIVERSAL&&v!==r.Class.CONTEXT_SPECIFIC||(d=[_])}catch(e){}void 0===d&&(e.read=m,t=y)}if(void 0===d){if(void 0===p){if(a.strict)throw new Error('Non-constructed ASN.1 object of indefinite length.');p=t}if(h===r.Type.BMPSTRING)for(d='';p>0;p-=2)s(e,t,2),d+=String.fromCharCode(e.getInt16()),t-=2;else d=e.getBytes(p),t-=p}var T=void 0===u?null:{bitStringContents:u};return r.create(l,h,g,d,T)}r.fromDer=function(e,t){void 0===t&&(t={strict:!0,parseAllBytes:!0,decodeBitStrings:!0}),'boolean'==typeof t&&(t={strict:t,parseAllBytes:!0,decodeBitStrings:!0}),'strict'in t||(t.strict=!0),'parseAllBytes'in t||(t.parseAllBytes=!0),'decodeBitStrings'in t||(t.decodeBitStrings=!0),'string'==typeof e&&(e=i.util.createBuffer(e));var r=e.length(),s=n(e,e.length(),0,t);if(t.parseAllBytes&&0!==e.length()){var a=new Error('Unparsed DER bytes remain after ASN.1 parsing.');throw a.byteCount=r,a.remaining=e.length(),a}return s},r.toDer=function(e){var t=i.util.createBuffer(),s=e.tagClass|e.type,n=i.util.createBuffer(),a=!1;if('bitStringContents'in e&&(a=!0,e.original&&(a=r.equals(e,e.original))),a)n.putBytes(e.bitStringContents);else if(e.composed){e.constructed?s|=32:n.putByte(0);for(var o=0;o1)||(0!==e.value.charCodeAt(0)||128&e.value.charCodeAt(1))&&(255!==e.value.charCodeAt(0)||128&~e.value.charCodeAt(1))?n.putBytes(e.value):n.putBytes(e.value.substr(1));if(t.putByte(s),n.length()<=127)t.putByte(127&n.length());else{var c=n.length(),l='';do{l+=String.fromCharCode(255&c),c>>>=8}while(c>0);t.putByte(128|l.length);for(o=l.length-1;o>=0;--o)t.putByte(l.charCodeAt(o))}return t.putBuffer(n),t},r.oidToDer=function(e){var t,r,s,n,a=e.split('.'),o=i.util.createBuffer();o.putByte(40*parseInt(a[0],10)+parseInt(a[1],10));for(var c=2;c>>=7,t||(n|=128),r.push(n),t=!1}while(s>0);for(var l=r.length-1;l>=0;--l)o.putByte(r[l])}return o},r.derToOid=function(e){var t;'string'==typeof e&&(e=i.util.createBuffer(e));var r=e.getByte();t=Math.floor(r/40)+'.'+r%40;for(var s=0;e.length()>0;)s<<=7,128&(r=e.getByte())?s+=127&r:(t+='.'+(s+r),s=0);return t},r.utcTimeToDate=function(e){var t=new Date,i=parseInt(e.substr(0,2),10);i=i>=50?1900+i:2e3+i;var r=parseInt(e.substr(2,2),10)-1,s=parseInt(e.substr(4,2),10),n=parseInt(e.substr(6,2),10),a=parseInt(e.substr(8,2),10),o=0;if(e.length>11){var c=e.charAt(10),l=10;'+'!==c&&'-'!==c&&(o=parseInt(e.substr(10,2),10),l+=2)}if(t.setUTCFullYear(i,r,s),t.setUTCHours(n,a,o,0),l&&('+'===(c=e.charAt(l))||'-'===c)){var h=60*parseInt(e.substr(l+1,2),10)+parseInt(e.substr(l+4,2),10);h*=6e4,'+'===c?t.setTime(+t-h):t.setTime(+t+h)}return t},r.generalizedTimeToDate=function(e){var t=new Date,i=parseInt(e.substr(0,4),10),r=parseInt(e.substr(4,2),10)-1,s=parseInt(e.substr(6,2),10),n=parseInt(e.substr(8,2),10),a=parseInt(e.substr(10,2),10),o=parseInt(e.substr(12,2),10),c=0,l=0,h=!1;'Z'===e.charAt(e.length-1)&&(h=!0);var d=e.length-5,u=e.charAt(d);'+'!==u&&'-'!==u||(l=60*parseInt(e.substr(d+1,2),10)+parseInt(e.substr(d+4,2),10),l*=6e4,'+'===u&&(l*=-1),h=!0);return'.'===e.charAt(14)&&(c=1e3*parseFloat(e.substr(14),10)),h?(t.setUTCFullYear(i,r,s),t.setUTCHours(n,a,o,c),t.setTime(+t+l)):(t.setFullYear(i,r,s),t.setHours(n,a,o,c)),t},r.dateToUtcTime=function(e){if('string'==typeof e)return e;var t='',i=[];i.push((''+e.getUTCFullYear()).substr(2)),i.push(''+(e.getUTCMonth()+1)),i.push(''+e.getUTCDate()),i.push(''+e.getUTCHours()),i.push(''+e.getUTCMinutes()),i.push(''+e.getUTCSeconds());for(var r=0;r=-128&&e<128)return t.putSignedInt(e,8);if(e>=-32768&&e<32768)return t.putSignedInt(e,16);if(e>=-8388608&&e<8388608)return t.putSignedInt(e,24);if(e>=-2147483648&&e<2147483648)return t.putSignedInt(e,32);var r=new Error('Integer too large; max is 32-bits.');throw r.integer=e,r},r.derToInteger=function(e){'string'==typeof e&&(e=i.util.createBuffer(e));var t=8*e.length();if(t>32)throw new Error('Integer too large; max is 32-bits.');return e.getSignedInt(t)},r.validate=function(e,t,s,n){var a=!1;if(e.tagClass!==t.tagClass&&void 0!==t.tagClass||e.type!==t.type&&void 0!==t.type)n&&(e.tagClass!==t.tagClass&&n.push('['+t.name+'] Expected tag class "'+t.tagClass+'", got "'+e.tagClass+'"'),e.type!==t.type&&n.push('['+t.name+'] Expected type "'+t.type+'", got "'+e.type+'"'));else if(e.constructed===t.constructed||void 0===t.constructed){if(a=!0,t.value&&i.util.isArray(t.value))for(var o=0,c=0;a&&c0&&(n+='\n');for(var o='',c=0;c1?n+='0x'+i.util.bytesToHex(e.value.slice(1)):n+='(none)',e.value.length>0){var u=e.value.charCodeAt(0);1==u?n+=' (1 unused bit shown)':u>1&&(n+=' ('+u+' unused bits shown)')}}else if(e.type===r.Type.OCTETSTRING)a.test(e.value)||(n+='('+e.value+') '),n+='0x'+i.util.bytesToHex(e.value);else if(e.type===r.Type.UTF8)try{n+=i.util.decodeUtf8(e.value)}catch(t){if('URI malformed'!==t.message)throw t;n+='0x'+i.util.bytesToHex(e.value)+' (malformed UTF8)'}else e.type===r.Type.PRINTABLESTRING||e.type===r.Type.IA5String?n+=e.value:a.test(e.value)?n+='0x'+i.util.bytesToHex(e.value):0===e.value.length?n+='[null]':n+=e.value}return n}}}),A=d({'node_modules/node-forge/lib/md.js'(e,t){var i=u();t.exports=i.md=i.md||{},i.md.algorithms=i.md.algorithms||{}}}),v=d({'node_modules/node-forge/lib/hmac.js'(e,t){var i=u();A(),f(),(t.exports=i.hmac=i.hmac||{}).create=function(){var e=null,t=null,r=null,s=null,n={start:function(n,a){if(null!==n)if('string'==typeof n){if(!((n=n.toLowerCase())in i.md.algorithms))throw new Error('Unknown hash algorithm "'+n+'"');t=i.md.algorithms[n].create()}else t=n;if(null===a)a=e;else{if('string'==typeof a)a=i.util.createBuffer(a);else if(i.util.isArray(a)){var o=a;a=i.util.createBuffer();for(var c=0;ct.blockLength&&(t.start(),t.update(a.bytes()),a=t.digest()),r=i.util.createBuffer(),s=i.util.createBuffer(),l=a.length();for(c=0;c>>0,a>>>0];for(var o=h.fullMessageLength.length-1;o>=0;--o)h.fullMessageLength[o]+=a[1],a[1]=a[0]+(h.fullMessageLength[o]/4294967296>>>0),h.fullMessageLength[o]=h.fullMessageLength[o]>>>0,a[0]=a[1]/4294967296>>>0;return t.putBytes(s),l(e,r,t),(t.read>2048||0===t.length())&&t.compact(),h},h.digest=function(){var n=i.util.createBuffer();n.putBytes(t.bytes());var a=h.fullMessageLength[h.fullMessageLength.length-1]+h.messageLengthSize&h.blockLength-1;n.putBytes(s.substr(0,h.blockLength-a));for(var o,c=0,d=h.fullMessageLength.length-1;d>=0;--d)c=(o=8*h.fullMessageLength[d]+c)/4294967296>>>0,n.putInt32Le(o>>>0);var u={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3};l(u,r,n);var p=i.util.createBuffer();return p.putInt32Le(u.h0),p.putInt32Le(u.h1),p.putInt32Le(u.h2),p.putInt32Le(u.h3),p},h};var s=null,n=null,a=null,o=null,c=!1;function l(e,t,i){for(var r,s,c,l,h,d,u,p=i.length();p>=64;){for(s=e.h0,c=e.h1,l=e.h2,h=e.h3,u=0;u<16;++u)t[u]=i.getInt32Le(),r=s+(h^c&(l^h))+o[u]+t[u],s=h,h=l,l=c,c+=r<<(d=a[u])|r>>>32-d;for(;u<32;++u)r=s+(l^h&(c^l))+o[u]+t[n[u]],s=h,h=l,l=c,c+=r<<(d=a[u])|r>>>32-d;for(;u<48;++u)r=s+(c^l^h)+o[u]+t[n[u]],s=h,h=l,l=c,c+=r<<(d=a[u])|r>>>32-d;for(;u<64;++u)r=s+(l^(c|~h))+o[u]+t[n[u]],s=h,h=l,l=c,c+=r<<(d=a[u])|r>>>32-d;e.h0=e.h0+s|0,e.h1=e.h1+c|0,e.h2=e.h2+l|0,e.h3=e.h3+h|0,p-=64}}}}),C=d({'node_modules/node-forge/lib/pem.js'(e,t){var i=u();f();var r=t.exports=i.pem=i.pem||{};function s(e){for(var t=e.name+': ',i=[],r=function(e,t){return' '+t},s=0;s65&&-1!==a){var o=t[a];','===o?(++a,t=t.substr(0,a)+'\r\n '+t.substr(a)):t=t.substr(0,a)+'\r\n'+o+t.substr(a+1),n=s-a-1,a=-1,++s}else' '!==t[s]&&'\t'!==t[s]&&','!==t[s]||(a=s);return t}function n(e){return e.replace(/^\s+/,'')}r.encode=function(e,t){t=t||{};var r,n='-----BEGIN '+e.type+'-----\r\n';if(e.procType&&(n+=s(r={name:'Proc-Type',values:[String(e.procType.version),e.procType.type]})),e.contentDomain&&(n+=s(r={name:'Content-Domain',values:[e.contentDomain]})),e.dekInfo&&(r={name:'DEK-Info',values:[e.dekInfo.algorithm]},e.dekInfo.parameters&&r.values.push(e.dekInfo.parameters),n+=s(r)),e.headers)for(var a=0;a8?3:1,y=[],E=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],_=0,A=0;A>>4^T))<<4,v^=t=65535&((T^=t)>>>-16^v),v^=(t=858993459&(v>>>2^(T^=t<<-16)))<<2,v^=t=65535&((T^=t)>>>-16^v),v^=(t=1431655765&(v>>>1^(T^=t<<-16)))<<1,v^=t=16711935&((T^=t)>>>8^v),t=(v^=(t=1431655765&(v>>>1^(T^=t<<8)))<<1)<<8|(T^=t)>>>20&240,v=T<<24|T<<8&16711680|T>>>8&65280|T>>>24&240,T=t;for(var C=0;C>>26,T=T<<2|T>>>26):(v=v<<1|v>>>27,T=T<<1|T>>>27),T&=-15;var I=i[(v&=-15)>>>28]|r[v>>>24&15]|s[v>>>20&15]|n[v>>>16&15]|a[v>>>12&15]|o[v>>>8&15]|c[v>>>4&15],S=l[T>>>28]|h[T>>>24&15]|d[T>>>20&15]|u[T>>>16&15]|p[T>>>12&15]|f[T>>>8&15]|g[T>>>4&15];t=65535&(S>>>16^I),y[_++]=I^t,y[_++]=S^t<<16}}return y}(t),this._init=!0}},r('DES-ECB',i.cipher.modes.ecb),r('DES-CBC',i.cipher.modes.cbc),r('DES-CFB',i.cipher.modes.cfb),r('DES-OFB',i.cipher.modes.ofb),r('DES-CTR',i.cipher.modes.ctr),r('3DES-ECB',i.cipher.modes.ecb),r('3DES-CBC',i.cipher.modes.cbc),r('3DES-CFB',i.cipher.modes.cfb),r('3DES-OFB',i.cipher.modes.ofb),r('3DES-CTR',i.cipher.modes.ctr);var s=[16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756],n=[-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344],a=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584],o=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],c=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],l=[536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312],h=[2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],d=[268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696];function p(e,t,i,r){var u,p,f=32===e.length?3:9;u=3===f?r?[30,-2,-2]:[0,32,2]:r?[94,62,-2,32,64,2,30,-2,-2]:[0,32,2,62,30,-2,64,96,2];var g=t[0],m=t[1];g^=(p=252645135&(g>>>4^m))<<4,g^=(p=65535&(g>>>16^(m^=p)))<<16,g^=p=858993459&((m^=p)>>>2^g),g^=p=16711935&((m^=p<<2)>>>8^g),g=(g^=(p=1431655765&(g>>>1^(m^=p<<8)))<<1)<<1|g>>>31,m=(m^=p)<<1|m>>>31;for(var y=0;y>>4|m<<28)^e[A+1];p=g,g=m,m=p^(n[v>>>24&63]|o[v>>>16&63]|l[v>>>8&63]|d[63&v]|s[T>>>24&63]|a[T>>>16&63]|c[T>>>8&63]|h[63&T])}p=g,g=m,m=p}m=m>>>1|m<<31,m^=p=1431655765&((g=g>>>1|g<<31)>>>1^m),m^=(p=16711935&(m>>>8^(g^=p<<1)))<<8,m^=(p=858993459&(m>>>2^(g^=p)))<<2,m^=p=65535&((g^=p)>>>16^m),m^=p=252645135&((g^=p<<16)>>>4^m),g^=p<<4,i[0]=g,i[1]=m}function y(e){var t,r='DES-'+((e=e||{}).mode||'CBC').toUpperCase(),s=(t=e.decrypt?i.cipher.createDecipher(r,e.key):i.cipher.createCipher(r,e.key)).start;return t.start=function(e,r){var n=null;r instanceof i.util.ByteBuffer&&(n=r,r={}),(r=r||{}).output=n,r.iv=e,s.call(t,r)},t}}}),S=d({'node_modules/node-forge/lib/pbkdf2.js'(e,t){var i=u();v(),A(),f();var r,s=i.pkcs5=i.pkcs5||{};i.util.isNodejs&&!i.options.usePureJavaScript&&(r=h('crypto')),t.exports=i.pbkdf2=s.pbkdf2=function(e,t,s,n,a,o){if('function'==typeof a&&(o=a,a=null),i.util.isNodejs&&!i.options.usePureJavaScript&&r.pbkdf2&&(null===a||'object'!=typeof a)&&(r.pbkdf2Sync.length>4||!a||'sha1'===a))return'string'!=typeof a&&(a='sha1'),e=Buffer.from(e,'binary'),t=Buffer.from(t,'binary'),o?4===r.pbkdf2Sync.length?r.pbkdf2(e,t,s,n,(function(e,t){if(e)return o(e);o(null,t.toString('binary'))})):r.pbkdf2(e,t,s,n,a,(function(e,t){if(e)return o(e);o(null,t.toString('binary'))})):4===r.pbkdf2Sync.length?r.pbkdf2Sync(e,t,s,n).toString('binary'):r.pbkdf2Sync(e,t,s,n,a).toString('binary');if(null==a&&(a='sha1'),'string'==typeof a){if(!(a in i.md.algorithms))throw new Error('Unknown hash algorithm: '+a);a=i.md[a].create()}var c=a.digestLength;if(n>4294967295*c){var l=new Error('Derived key is too long.');if(o)return o(l);throw l}var h=Math.ceil(n/c),d=n-(h-1)*c,u=i.hmac.create();u.start(a,e);var p,f,g,m='';if(!o){for(var y=1;y<=h;++y){u.start(null,null),u.update(t),u.update(i.util.int32ToBytes(y)),p=g=u.digest().getBytes();for(var E=2;E<=s;++E)u.start(null,null),u.update(g),f=u.digest().getBytes(),p=i.util.xorBytes(p,f,c),g=f;m+=yh)return o(null,m);u.start(null,null),u.update(t),u.update(i.util.int32ToBytes(y)),p=g=u.digest().getBytes(),E=2,A()}function A(){if(E<=s)return u.start(null,null),u.update(g),f=u.digest().getBytes(),p=i.util.xorBytes(p,f,c),g=f,++E,i.util.setImmediate(A);m+=y>>0,a>>>0];for(var l=c.fullMessageLength.length-1;l>=0;--l)c.fullMessageLength[l]+=a[1],a[1]=a[0]+(c.fullMessageLength[l]/4294967296>>>0),c.fullMessageLength[l]=c.fullMessageLength[l]>>>0,a[0]=a[1]/4294967296>>>0;return t.putBytes(s),o(e,r,t),(t.read>2048||0===t.length())&&t.compact(),c},c.digest=function(){var n=i.util.createBuffer();n.putBytes(t.bytes());var a,l=c.fullMessageLength[c.fullMessageLength.length-1]+c.messageLengthSize&c.blockLength-1;n.putBytes(s.substr(0,c.blockLength-l));for(var h=8*c.fullMessageLength[0],d=0;d>>0,n.putInt32(h>>>0),h=a>>>0;n.putInt32(h);var u={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4,h5:e.h5,h6:e.h6,h7:e.h7};o(u,r,n);var p=i.util.createBuffer();return p.putInt32(u.h0),p.putInt32(u.h1),p.putInt32(u.h2),p.putInt32(u.h3),p.putInt32(u.h4),p.putInt32(u.h5),p.putInt32(u.h6),p.putInt32(u.h7),p},c};var s=null,n=!1,a=null;function o(e,t,i){for(var r,s,n,o,c,l,h,d,u,p,f,g,m,y=i.length();y>=64;){for(c=0;c<16;++c)t[c]=i.getInt32();for(;c<64;++c)r=((r=t[c-2])>>>17|r<<15)^(r>>>19|r<<13)^r>>>10,s=((s=t[c-15])>>>7|s<<25)^(s>>>18|s<<14)^s>>>3,t[c]=r+t[c-7]+s+t[c-16]|0;for(l=e.h0,h=e.h1,d=e.h2,u=e.h3,p=e.h4,f=e.h5,g=e.h6,m=e.h7,c=0;c<64;++c)n=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),o=l&h|d&(l^h),r=m+((p>>>6|p<<26)^(p>>>11|p<<21)^(p>>>25|p<<7))+(g^p&(f^g))+a[c]+t[c],m=g,g=f,f=p,p=u+r>>>0,u=d,d=h,h=l,l=r+(s=n+o)>>>0;e.h0=e.h0+l|0,e.h1=e.h1+h|0,e.h2=e.h2+d|0,e.h3=e.h3+u|0,e.h4=e.h4+p|0,e.h5=e.h5+f|0,e.h6=e.h6+g|0,e.h7=e.h7+m|0,y-=64}}}}),N=d({'node_modules/node-forge/lib/prng.js'(e,t){var i=u();f();var r=null;!i.util.isNodejs||i.options.usePureJavaScript||process.versions['node-webkit']||(r=h('crypto')),(t.exports=i.prng=i.prng||{}).create=function(e){for(var t={plugin:e,key:null,seed:null,time:null,reseeds:0,generated:0,keyBytes:''},s=e.md,n=new Array(32),a=0;a<32;++a)n[a]=s.create();function o(){if(t.pools[0].messageLength>=32)return c();var e=32-t.pools[0].messageLength<<5;t.collect(t.seedFileSync(e)),c()}function c(){t.reseeds=4294967295===t.reseeds?0:t.reseeds+1;var e=t.plugin.md.create();e.update(t.keyBytes);for(var i=1,r=0;r<32;++r)t.reseeds%i==0&&(e.update(t.pools[r].digest().getBytes()),t.pools[r].start()),i<<=1;t.keyBytes=e.digest().getBytes(),e.start(),e.update(t.keyBytes);var s=e.digest().getBytes();t.key=t.plugin.formatKey(t.keyBytes),t.seed=t.plugin.formatSeed(s),t.generated=0}function l(e){var t=null,r=i.util.globalScope,s=r.crypto||r.msCrypto;s&&s.getRandomValues&&(t=function(e){return s.getRandomValues(e)});var n=i.util.createBuffer();if(t)for(;n.length()>16)))<<16,u=4294967295&(h=(2147483647&(h+=l>>15))+(h>>31));for(c=0;c<3;++c)d=u>>>(c<<3),d^=Math.floor(256*Math.random()),n.putByte(255&d)}return n.getBytes(e)}return t.pools=n,t.pool=0,t.generate=function(e,r){if(!r)return t.generateSync(e);var s=t.plugin.cipher,n=t.plugin.increment,a=t.plugin.formatKey,o=t.plugin.formatSeed,l=i.util.createBuffer();t.key=null,function h(d){if(d)return r(d);if(l.length()>=e)return r(null,l.getBytes(e));t.generated>1048575&&(t.key=null);if(null===t.key)return i.util.nextTick((function(){!function(e){if(t.pools[0].messageLength>=32)return c(),e();var i=32-t.pools[0].messageLength<<5;t.seedFile(i,(function(i,r){if(i)return e(i);t.collect(r),c(),e()}))}(h)}));var u=s(t.key,t.seed);t.generated+=u.length,l.putBytes(u),t.key=a(s(t.key,n(t.seed))),t.seed=o(s(t.key,t.seed)),i.util.setImmediate(h)}()},t.generateSync=function(e){var r=t.plugin.cipher,s=t.plugin.increment,n=t.plugin.formatKey,a=t.plugin.formatSeed;t.key=null;for(var c=i.util.createBuffer();c.length()1048575&&(t.key=null),null===t.key&&o();var l=r(t.key,t.seed);t.generated+=l.length,c.putBytes(l),t.key=n(r(t.key,s(t.seed))),t.seed=a(r(t.key,t.seed))}return c.getBytes(e)},r?(t.seedFile=function(e,t){r.randomBytes(e,(function(e,i){if(e)return t(e);t(null,i.toString())}))},t.seedFileSync=function(e){return r.randomBytes(e).toString()}):(t.seedFile=function(e,t){try{t(null,l(e))}catch(e){t(e)}},t.seedFileSync=l),t.collect=function(e){for(var i=e.length,r=0;r>s&255);t.collect(r)},t.registerWorker=function(e){if(e===self)t.seedFile=function(e,t){self.addEventListener('message',(function e(i){var r=i.data;r.forge&&r.forge.prng&&(self.removeEventListener('message',e),t(r.forge.prng.err,r.forge.prng.bytes))})),self.postMessage({forge:{prng:{needed:e}}})};else{e.addEventListener('message',(function(i){var r=i.data;r.forge&&r.forge.prng&&t.seedFile(r.forge.prng.needed,(function(t,i){e.postMessage({forge:{prng:{err:t,bytes:i}}})}))}))}},t}}}),L=d({'node_modules/node-forge/lib/random.js'(e,t){var i=u();y(),O(),N(),f(),i.random&&i.random.getBytes?t.exports=i.random:function(e){var r={},s=new Array(4),n=i.util.createBuffer();function a(){var e=i.prng.create(r);return e.getBytes=function(t,i){return e.generate(t,i)},e.getBytesSync=function(t){return e.generate(t)},e}r.formatKey=function(e){var t=i.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),i.aes._expandKey(e,!1)},r.formatSeed=function(e){var t=i.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),e},r.cipher=function(e,t){return i.aes._updateBlock(e,t,s,!1),n.putInt32(s[0]),n.putInt32(s[1]),n.putInt32(s[2]),n.putInt32(s[3]),n.getBytes()},r.increment=function(e){return++e[3],e},r.md=i.md.sha256;var o=a(),c=null,l=i.util.globalScope,h=l.crypto||l.msCrypto;if(h&&h.getRandomValues&&(c=function(e){return h.getRandomValues(e)}),i.options.usePureJavaScript||!i.util.isNodejs&&!c){if('undefined'==typeof window||window.document,o.collectInt(+new Date,32),'undefined'!=typeof navigator){var d='';for(var u in navigator)try{'string'==typeof navigator[u]&&(d+=navigator[u])}catch(e){}o.collect(d),d=null}e&&(e().mousemove((function(e){o.collectInt(e.clientX,16),o.collectInt(e.clientY,16)})),e().keypress((function(e){o.collectInt(e.charCode,8)})))}if(i.random)for(var u in o)i.random[u]=o[u];else i.random=o;i.random.createInstance=a,t.exports=i.random}('undefined'!=typeof jQuery?jQuery:null)}}),P=d({'node_modules/node-forge/lib/rc2.js'(e,t){var i=u();f();var r=[217,120,249,196,25,221,181,237,40,233,253,121,74,160,216,157,198,126,55,131,43,118,83,142,98,76,100,136,68,139,251,162,23,154,89,245,135,179,79,19,97,69,109,141,9,129,125,50,189,143,64,235,134,183,123,11,240,149,33,34,92,107,78,130,84,214,101,147,206,96,178,28,115,86,192,20,167,140,241,220,18,117,202,31,59,190,228,209,66,61,212,48,163,60,182,38,111,191,14,218,70,105,7,87,39,242,29,155,188,148,67,3,248,17,199,246,144,239,62,231,6,195,213,47,200,102,30,215,8,232,234,222,128,82,238,247,132,170,114,172,53,77,106,42,150,26,210,113,90,21,73,116,75,159,208,94,4,24,164,236,194,224,65,110,15,81,203,204,36,145,175,80,161,244,112,57,153,124,58,133,35,184,180,122,252,2,54,91,37,85,151,49,45,93,250,152,227,138,146,174,5,223,41,16,103,108,186,201,211,0,230,207,225,158,168,44,99,22,1,63,88,226,137,169,13,56,52,27,171,51,255,176,187,72,12,95,185,177,205,46,197,243,219,71,229,165,156,119,10,166,32,104,254,127,193,173],s=[1,2,3,5],n=function(e,t){return e<>16-t},a=function(e,t){return(65535&e)>>t|e<<16-t&65535};t.exports=i.rc2=i.rc2||{},i.rc2.expandKey=function(e,t){'string'==typeof e&&(e=i.util.createBuffer(e)),t=t||128;var s,n=e,a=e.length(),o=t,c=Math.ceil(o/8),l=255>>(7&o);for(s=a;s<128;s++)n.putByte(r[n.at(s-1)+n.at(s-a)&255]);for(n.setAt(128-c,r[n.at(128-c)&l]),s=127-c;s>=0;s--)n.setAt(s,r[n.at(s+1)^n.at(s+c)]);return n};var o=function(e,t,r){var o,c,l,h,d=!1,u=null,p=null,f=null,g=[];for(e=i.rc2.expandKey(e,t),l=0;l<64;l++)g.push(e.getInt16Le());r?(o=function(e){for(l=0;l<4;l++)e[l]+=g[h]+(e[(l+3)%4]&e[(l+2)%4])+(~e[(l+3)%4]&e[(l+1)%4]),e[l]=n(e[l],s[l]),h++},c=function(e){for(l=0;l<4;l++)e[l]+=g[63&e[(l+3)%4]]}):(o=function(e){for(l=3;l>=0;l--)e[l]=a(e[l],s[l]),e[l]-=g[h]+(e[(l+3)%4]&e[(l+2)%4])+(~e[(l+3)%4]&e[(l+1)%4]),h--},c=function(e){for(l=3;l>=0;l--)e[l]-=g[63&e[(l+3)%4]]});var m=function(e){var t=[];for(l=0;l<4;l++){var i=u.getInt16Le();null!==f&&(r?i^=f.getInt16Le():f.putInt16Le(i)),t.push(65535&i)}h=r?0:63;for(var s=0;s=8;)m([[5,o],[1,c],[6,o],[1,c],[5,o]])},finish:function(e){var t=!0;if(r)if(e)t=e(8,u,!r);else{var i=8===u.length()?8:8-u.length();u.fillWithByte(i,i)}if(t&&(d=!0,y.update()),!r&&(t=0===u.length()))if(e)t=e(8,p,!r);else{var s=p.length(),n=p.at(s-1);n>s?t=!1:p.truncate(n)}return t}}};i.rc2.startEncrypting=function(e,t,r){var s=i.rc2.createEncryptionCipher(e,128);return s.start(t,r),s},i.rc2.createEncryptionCipher=function(e,t){return o(e,t,!0)},i.rc2.startDecrypting=function(e,t,r){var s=i.rc2.createDecryptionCipher(e,128);return s.start(t,r),s},i.rc2.createDecryptionCipher=function(e,t){return o(e,t,!1)}}}),w=d({'node_modules/node-forge/lib/jsbn.js'(e,t){var i,r=u();t.exports=r.jsbn=r.jsbn||{};function s(e,t,i){this.data=[],null!=e&&('number'==typeof e?this.fromNumber(e,t,i):null==t&&'string'!=typeof e?this.fromString(e,256):this.fromString(e,t))}function n(){return new s(null)}function a(e,t,i,r,s,n){for(var a=16383&t,o=t>>14;--n>=0;){var c=16383&this.data[e],l=this.data[e++]>>14,h=o*c+l*a;s=((c=a*c+((16383&h)<<14)+i.data[r]+s)>>28)+(h>>14)+o*l,i.data[r++]=268435455&c}return s}r.jsbn.BigInteger=s,'undefined'==typeof navigator?(s.prototype.am=a,i=28):'Microsoft Internet Explorer'==navigator.appName?(s.prototype.am=function(e,t,i,r,s,n){for(var a=32767&t,o=t>>15;--n>=0;){var c=32767&this.data[e],l=this.data[e++]>>15,h=o*c+l*a;s=((c=a*c+((32767&h)<<15)+i.data[r]+(1073741823&s))>>>30)+(h>>>15)+o*l+(s>>>30),i.data[r++]=1073741823&c}return s},i=30):'Netscape'!=navigator.appName?(s.prototype.am=function(e,t,i,r,s,n){for(;--n>=0;){var a=t*this.data[e++]+i.data[r]+s;s=Math.floor(a/67108864),i.data[r++]=67108863&a}return s},i=26):(s.prototype.am=a,i=28),s.prototype.DB=i,s.prototype.DM=(1<>>16)&&(e=t,i+=16),0!=(t=e>>8)&&(e=t,i+=8),0!=(t=e>>4)&&(e=t,i+=4),0!=(t=e>>2)&&(e=t,i+=2),0!=(t=e>>1)&&(e=t,i+=1),i}function g(e){this.m=e}function m(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,t+=16),255&e||(e>>=8,t+=8),15&e||(e>>=4,t+=4),3&e||(e>>=2,t+=2),1&e||++t,t}function T(e){for(var t=0;0!=e;)e&=e-1,++t;return t}function C(){}function I(e){return e}function S(e){this.r2=n(),this.q3=n(),s.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}g.prototype.convert=function(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e},g.prototype.revert=function(e){return e},g.prototype.reduce=function(e){e.divRemTo(this.m,null,e)},g.prototype.mulTo=function(e,t,i){e.multiplyTo(t,i),this.reduce(i)},g.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},m.prototype.convert=function(e){var t=n();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(s.ZERO)>0&&this.m.subTo(t,t),t},m.prototype.revert=function(e){var t=n();return e.copyTo(t),this.reduce(t),t},m.prototype.reduce=function(e){for(;e.t<=this.mt2;)e.data[e.t++]=0;for(var t=0;t>15)*this.mpl&this.um)<<15)&e.DM;for(i=t+this.m.t,e.data[i]+=this.m.am(0,r,e,t,0,this.m.t);e.data[i]>=e.DV;)e.data[i]-=e.DV,e.data[++i]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},m.prototype.mulTo=function(e,t,i){e.multiplyTo(t,i),this.reduce(i)},m.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},s.prototype.copyTo=function(e){for(var t=this.t-1;t>=0;--t)e.data[t]=this.data[t];e.t=this.t,e.s=this.s},s.prototype.fromInt=function(e){this.t=1,this.s=e<0?-1:0,e>0?this.data[0]=e:e<-1?this.data[0]=e+this.DV:this.t=0},s.prototype.fromString=function(e,t){var i;if(16==t)i=4;else if(8==t)i=3;else if(256==t)i=8;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return void this.fromRadix(e,t);i=2}this.t=0,this.s=0;for(var r=e.length,n=!1,a=0;--r>=0;){var o=8==i?255&e[r]:d(e,r);o<0?'-'==e.charAt(r)&&(n=!0):(n=!1,0==a?this.data[this.t++]=o:a+i>this.DB?(this.data[this.t-1]|=(o&(1<>this.DB-a):this.data[this.t-1]|=o<=this.DB&&(a-=this.DB))}8==i&&128&e[0]&&(this.s=-1,a>0&&(this.data[this.t-1]|=(1<0&&this.data[this.t-1]==e;)--this.t},s.prototype.dlShiftTo=function(e,t){var i;for(i=this.t-1;i>=0;--i)t.data[i+e]=this.data[i];for(i=e-1;i>=0;--i)t.data[i]=0;t.t=this.t+e,t.s=this.s},s.prototype.drShiftTo=function(e,t){for(var i=e;i=0;--i)t.data[i+a+1]=this.data[i]>>s|o,o=(this.data[i]&n)<=0;--i)t.data[i]=0;t.data[a]=o,t.t=this.t+a+1,t.s=this.s,t.clamp()},s.prototype.rShiftTo=function(e,t){t.s=this.s;var i=Math.floor(e/this.DB);if(i>=this.t)t.t=0;else{var r=e%this.DB,s=this.DB-r,n=(1<>r;for(var a=i+1;a>r;r>0&&(t.data[this.t-i-1]|=(this.s&n)<>=this.DB;if(e.t>=this.DB;r+=this.s}else{for(r+=this.s;i>=this.DB;r-=e.s}t.s=r<0?-1:0,r<-1?t.data[i++]=this.DV+r:r>0&&(t.data[i++]=r),t.t=i,t.clamp()},s.prototype.multiplyTo=function(e,t){var i=this.abs(),r=e.abs(),n=i.t;for(t.t=n+r.t;--n>=0;)t.data[n]=0;for(n=0;n=0;)e.data[i]=0;for(i=0;i=t.DV&&(e.data[i+t.t]-=t.DV,e.data[i+t.t+1]=1)}e.t>0&&(e.data[e.t-1]+=t.am(i,t.data[i],e,2*i,0,1)),e.s=0,e.clamp()},s.prototype.divRemTo=function(e,t,i){var r=e.abs();if(!(r.t<=0)){var a=this.abs();if(a.t0?(r.lShiftTo(h,o),a.lShiftTo(h,i)):(r.copyTo(o),a.copyTo(i));var d=o.t,u=o.data[d-1];if(0!=u){var p=u*(1<1?o.data[d-2]>>this.F2:0),g=this.FV/p,m=(1<=0&&(i.data[i.t++]=1,i.subTo(A,i)),s.ONE.dlShiftTo(d,A),A.subTo(o,o);o.t=0;){var v=i.data[--E]==u?this.DM:Math.floor(i.data[E]*g+(i.data[E-1]+y)*m);if((i.data[E]+=o.am(0,v,i,_,0,d))0&&i.rShiftTo(h,i),c<0&&s.ZERO.subTo(i,i)}}},s.prototype.invDigit=function(){if(this.t<1)return 0;var e=this.data[0];if(!(1&e))return 0;var t=3&e;return(t=(t=(t=(t=t*(2-(15&e)*t)&15)*(2-(255&e)*t)&255)*(2-((65535&e)*t&65535))&65535)*(2-e*t%this.DV)%this.DV)>0?this.DV-t:-t},s.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},s.prototype.exp=function(e,t){if(e>4294967295||e<1)return s.ONE;var i=n(),r=n(),a=t.convert(this),o=f(e)-1;for(a.copyTo(i);--o>=0;)if(t.sqrTo(i,r),(e&1<0)t.mulTo(r,a,i);else{var c=i;i=r,r=c}return t.revert(i)},s.prototype.toString=function(e){if(this.s<0)return'-'+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)return this.toRadix(e);t=2}var i,r=(1<0)for(o>o)>0&&(s=!0,n=h(i));a>=0;)o>(o+=this.DB-t)):(i=this.data[a]>>(o-=t)&r,o<=0&&(o+=this.DB,--a)),i>0&&(s=!0),s&&(n+=h(i));return s?n:'0'},s.prototype.negate=function(){var e=n();return s.ZERO.subTo(this,e),e},s.prototype.abs=function(){return this.s<0?this.negate():this},s.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var i=this.t;if(0!=(t=i-e.t))return this.s<0?-t:t;for(;--i>=0;)if(0!=(t=this.data[i]-e.data[i]))return t;return 0},s.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+f(this.data[this.t-1]^this.s&this.DM)},s.prototype.mod=function(e){var t=n();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(s.ZERO)>0&&e.subTo(t,t),t},s.prototype.modPowInt=function(e,t){var i;return i=e<256||t.isEven()?new g(t):new m(t),this.exp(e,i)},s.ZERO=p(0),s.ONE=p(1),C.prototype.convert=I,C.prototype.revert=I,C.prototype.mulTo=function(e,t,i){e.multiplyTo(t,i)},C.prototype.sqrTo=function(e,t){e.squareTo(t)},S.prototype.convert=function(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=n();return e.copyTo(t),this.reduce(t),t},S.prototype.revert=function(e){return e},S.prototype.reduce=function(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)},S.prototype.mulTo=function(e,t,i){e.multiplyTo(t,i),this.reduce(i)},S.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)};var O=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509],N=(1<<26)/O[O.length-1];s.prototype.chunkSize=function(e){return Math.floor(Math.LN2*this.DB/Math.log(e))},s.prototype.toRadix=function(e){if(null==e&&(e=10),0==this.signum()||e<2||e>36)return'0';var t=this.chunkSize(e),i=Math.pow(e,t),r=p(i),s=n(),a=n(),o='';for(this.divRemTo(r,s,a);s.signum()>0;)o=(i+a.intValue()).toString(e).substr(1)+o,s.divRemTo(r,s,a);return a.intValue().toString(e)+o},s.prototype.fromRadix=function(e,t){this.fromInt(0),null==t&&(t=10);for(var i=this.chunkSize(t),r=Math.pow(t,i),n=!1,a=0,o=0,c=0;c=i&&(this.dMultiply(r),this.dAddOffset(o,0),a=0,o=0))}a>0&&(this.dMultiply(Math.pow(t,a)),this.dAddOffset(o,0)),n&&s.ZERO.subTo(this,this)},s.prototype.fromNumber=function(e,t,i){if('number'==typeof t)if(e<2)this.fromInt(1);else for(this.fromNumber(e,i),this.testBit(e-1)||this.bitwiseTo(s.ONE.shiftLeft(e-1),E,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(s.ONE.shiftLeft(e-1),this);else{var r=new Array,n=7&e;r.length=1+(e>>3),t.nextBytes(r),n>0?r[0]&=(1<>=this.DB;if(e.t>=this.DB;r+=this.s}else{for(r+=this.s;i>=this.DB;r+=e.s}t.s=r<0?-1:0,r>0?t.data[i++]=r:r<-1&&(t.data[i++]=this.DV+r),t.t=i,t.clamp()},s.prototype.dMultiply=function(e){this.data[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()},s.prototype.dAddOffset=function(e,t){if(0!=e){for(;this.t<=t;)this.data[this.t++]=0;for(this.data[t]+=e;this.data[t]>=this.DV;)this.data[t]-=this.DV,++t>=this.t&&(this.data[this.t++]=0),++this.data[t]}},s.prototype.multiplyLowerTo=function(e,t,i){var r,s=Math.min(this.t+e.t,t);for(i.s=0,i.t=s;s>0;)i.data[--s]=0;for(r=i.t-this.t;s=0;)i.data[r]=0;for(r=Math.max(t-this.t,0);r0)if(0==t)i=this.data[0]%e;else for(var r=this.t-1;r>=0;--r)i=(t*i+this.data[r])%e;return i},s.prototype.millerRabin=function(e){var t=this.subtract(s.ONE),i=t.getLowestSetBit();if(i<=0)return!1;for(var r,n=t.shiftRight(i),a={nextBytes:function(e){for(var t=0;t=0);var c=r.modPow(n,this);if(0!=c.compareTo(s.ONE)&&0!=c.compareTo(t)){for(var l=1;l++>24},s.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},s.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},s.prototype.toByteArray=function(){var e=this.t,t=new Array;t[0]=this.s;var i,r=this.DB-e*this.DB%8,s=0;if(e-- >0)for(r>r)!=(this.s&this.DM)>>r&&(t[s++]=i|this.s<=0;)r<8?(i=(this.data[e]&(1<>(r+=this.DB-8)):(i=this.data[e]>>(r-=8)&255,r<=0&&(r+=this.DB,--e)),128&i&&(i|=-256),0==s&&(128&this.s)!=(128&i)&&++s,(s>0||i!=this.s)&&(t[s++]=i);return t},s.prototype.equals=function(e){return 0==this.compareTo(e)},s.prototype.min=function(e){return this.compareTo(e)<0?this:e},s.prototype.max=function(e){return this.compareTo(e)>0?this:e},s.prototype.and=function(e){var t=n();return this.bitwiseTo(e,y,t),t},s.prototype.or=function(e){var t=n();return this.bitwiseTo(e,E,t),t},s.prototype.xor=function(e){var t=n();return this.bitwiseTo(e,_,t),t},s.prototype.andNot=function(e){var t=n();return this.bitwiseTo(e,A,t),t},s.prototype.not=function(){for(var e=n(),t=0;t=this.t?0!=this.s:!!(this.data[t]&1<1){var d=n();for(r.sqrTo(o[1],d);c<=h;)o[c]=n(),r.mulTo(d,o[c-2],o[c]),c+=2}var u,y,E=e.t-1,_=!0,A=n();for(s=f(e.data[E])-1;E>=0;){for(s>=l?u=e.data[E]>>s-l&h:(u=(e.data[E]&(1<0&&(u|=e.data[E-1]>>this.DB+s-l)),c=i;!(1&u);)u>>=1,--c;if((s-=c)<0&&(s+=this.DB,--E),_)o[u].copyTo(a),_=!1;else{for(;c>1;)r.sqrTo(a,A),r.sqrTo(A,a),c-=2;c>0?r.sqrTo(a,A):(y=a,a=A,A=y),r.mulTo(A,o[u],a)}for(;E>=0&&!(e.data[E]&1<=0?(i.subTo(r,i),t&&n.subTo(o,n),a.subTo(c,a)):(r.subTo(i,r),t&&o.subTo(n,o),c.subTo(a,c))}return 0!=r.compareTo(s.ONE)?s.ZERO:c.compareTo(e)>=0?c.subtract(e):c.signum()<0?(c.addTo(e,c),c.signum()<0?c.add(e):c):c},s.prototype.pow=function(e){return this.exp(e,new C)},s.prototype.gcd=function(e){var t=this.s<0?this.negate():this.clone(),i=e.s<0?e.negate():e.clone();if(t.compareTo(i)<0){var r=t;t=i,i=r}var s=t.getLowestSetBit(),n=i.getLowestSetBit();if(n<0)return t;for(s0&&(t.rShiftTo(n,t),i.rShiftTo(n,i));t.signum()>0;)(s=t.getLowestSetBit())>0&&t.rShiftTo(s,t),(s=i.getLowestSetBit())>0&&i.rShiftTo(s,i),t.compareTo(i)>=0?(t.subTo(i,t),t.rShiftTo(1,t)):(i.subTo(t,i),i.rShiftTo(1,i));return n>0&&i.lShiftTo(n,i),i},s.prototype.isProbablePrime=function(e){var t,i=this.abs();if(1==i.t&&i.data[0]<=O[O.length-1]){for(t=0;t>>0,c>>>0];for(var l=o.fullMessageLength.length-1;l>=0;--l)o.fullMessageLength[l]+=c[1],c[1]=c[0]+(o.fullMessageLength[l]/4294967296>>>0),o.fullMessageLength[l]=o.fullMessageLength[l]>>>0,c[0]=c[1]/4294967296>>>0;return t.putBytes(s),a(e,r,t),(t.read>2048||0===t.length())&&t.compact(),o},o.digest=function(){var n=i.util.createBuffer();n.putBytes(t.bytes());var c,l=o.fullMessageLength[o.fullMessageLength.length-1]+o.messageLengthSize&o.blockLength-1;n.putBytes(s.substr(0,o.blockLength-l));for(var h=8*o.fullMessageLength[0],d=0;d>>0,n.putInt32(h>>>0),h=c>>>0;n.putInt32(h);var u={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4};a(u,r,n);var p=i.util.createBuffer();return p.putInt32(u.h0),p.putInt32(u.h1),p.putInt32(u.h2),p.putInt32(u.h3),p.putInt32(u.h4),p},o};var s=null,n=!1;function a(e,t,i){for(var r,s,n,a,o,c,l,h=i.length();h>=64;){for(s=e.h0,n=e.h1,a=e.h2,o=e.h3,c=e.h4,l=0;l<16;++l)r=i.getInt32(),t[l]=r,r=(s<<5|s>>>27)+(o^n&(a^o))+c+1518500249+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<20;++l)r=(r=t[l-3]^t[l-8]^t[l-14]^t[l-16])<<1|r>>>31,t[l]=r,r=(s<<5|s>>>27)+(o^n&(a^o))+c+1518500249+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<32;++l)r=(r=t[l-3]^t[l-8]^t[l-14]^t[l-16])<<1|r>>>31,t[l]=r,r=(s<<5|s>>>27)+(n^a^o)+c+1859775393+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<40;++l)r=(r=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|r>>>30,t[l]=r,r=(s<<5|s>>>27)+(n^a^o)+c+1859775393+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<60;++l)r=(r=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|r>>>30,t[l]=r,r=(s<<5|s>>>27)+(n&a|o&(n^a))+c+2400959708+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<80;++l)r=(r=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|r>>>30,t[l]=r,r=(s<<5|s>>>27)+(n^a^o)+c+3395469782+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;e.h0=e.h0+s|0,e.h1=e.h1+n|0,e.h2=e.h2+a|0,e.h3=e.h3+o|0,e.h4=e.h4+c|0,h-=64}}}}),R=d({'node_modules/node-forge/lib/pkcs1.js'(e,t){var i=u();f(),L(),b();var r=t.exports=i.pkcs1=i.pkcs1||{};function s(e,t,r){r||(r=i.md.sha1.create());for(var s='',n=Math.ceil(t/r.digestLength),a=0;a>24&255,a>>16&255,a>>8&255,255&a);r.start(),r.update(e+o),s+=r.digest().getBytes()}return s.substring(0,t)}r.encode_rsa_oaep=function(e,t,r){var n,a,o,c;'string'==typeof r?(n=r,a=arguments[3]||void 0,o=arguments[4]||void 0):r&&(n=r.label||void 0,a=r.seed||void 0,o=r.md||void 0,r.mgf1&&r.mgf1.md&&(c=r.mgf1.md)),o?o.start():o=i.md.sha1.create(),c||(c=o);var l=Math.ceil(e.n.bitLength()/8),h=l-2*o.digestLength-2;if(t.length>h)throw(m=new Error('RSAES-OAEP input message length is too long.')).length=t.length,m.maxLength=h,m;n||(n=''),o.update(n,'raw');for(var d=o.digest(),u='',p=h-t.length,f=0;fe&&(a=l(e,t));var p=a.toString(16);s.target.postMessage({hex:p,workLoad:h}),a.dAddOffset(d,0)}}}p()}(e,t,s,n);return o(e,t,s,n)}(e,c,n.options,s);throw new Error('Invalid prime generation algorithm: '+n.name)}}function o(e,t,i,r){var s=l(e,t),n=function(e){return e<=100?27:e<=150?18:e<=200?15:e<=250?12:e<=300?9:e<=350?8:e<=400?7:e<=500?6:e<=600?5:e<=800?4:e<=1250?3:2}(s.bitLength());'millerRabinTests'in i&&(n=i.millerRabinTests);var a=10;'maxBlockTime'in i&&(a=i.maxBlockTime),c(s,e,t,0,n,a,r)}function c(e,t,r,n,a,o,h){var d=+new Date;do{if(e.bitLength()>t&&(e=l(t,r)),e.isProbablePrime(a))return h(null,e);e.dAddOffset(s[n++%8],0)}while(o<0||+new Date-d=0||!n.gcd(t.n).equals(i.ONE));for(var a=(e=e.multiply(n.modPow(t.e,t.n)).mod(t.n)).mod(t.p).modPow(t.dP,t.p),o=e.mod(t.q).modPow(t.dQ,t.q);a.compareTo(o)<0;)a=a.add(t.p);var c=a.subtract(o).multiply(t.qInv).mod(t.p).multiply(t.q).add(o);return c=c.multiply(n.modInverse(t.n)).mod(t.n)};function v(e,t,i){var s=r.util.createBuffer(),n=Math.ceil(t.n.bitLength()/8);if(e.length>n-11){var a=new Error('Message is too long for PKCS#1 v1.5 padding.');throw a.length=e.length,a.max=n-11,a}s.putByte(0),s.putByte(i);var o,c=n-3-e.length;if(0===i||1===i){o=0===i?0:255;for(var l=0;l0;){var h=0,d=r.random.getBytes(c);for(l=0;l1;){if(255!==a.getByte()){--a.read;break}++l}else if(2===c)for(l=0;a.length()>1;){if(0===a.getByte()){--a.read;break}++l}if(0!==a.getByte()||l!==n-3-a.length())throw new Error('Encryption block is invalid.');return a.getBytes()}function C(e){var t=e.toString(16);t[0]>='8'&&(t='00'+t);var i=r.util.hexToBytes(t);return!(i.length>1)||(0!==i.charCodeAt(0)||128&i.charCodeAt(1))&&(255!==i.charCodeAt(0)||128&~i.charCodeAt(1))?i:i.substr(1)}function I(e){return e<=100?27:e<=150?18:e<=200?15:e<=250?12:e<=300?9:e<=350?8:e<=400?7:e<=500?6:e<=600?5:e<=800?4:e<=1250?3:2}function S(e){return r.util.isNodejs&&'function'==typeof s[e]}function O(e){return void 0!==a.globalScope&&'object'==typeof a.globalScope.crypto&&'object'==typeof a.globalScope.crypto.subtle&&'function'==typeof a.globalScope.crypto.subtle[e]}function N(e){return void 0!==a.globalScope&&'object'==typeof a.globalScope.msCrypto&&'object'==typeof a.globalScope.msCrypto.subtle&&'function'==typeof a.globalScope.msCrypto.subtle[e]}function P(e){for(var t=r.util.hexToBytes(e.toString(16)),i=new Uint8Array(t.length),s=0;s0;)h.putByte(0),--d;return h.putBytes(r.util.hexToBytes(l)),h.getBytes()},o.rsa.decrypt=function(e,t,s,n){var a=Math.ceil(t.n.bitLength()/8);if(e.length!==a){var o=new Error('Encrypted message length is invalid.');throw o.length=e.length,o.expected=a,o}var c=new i(r.util.createBuffer(e).toHex(),16);if(c.compareTo(t.n)>=0)throw new Error('Encrypted message is invalid.');for(var l=A(c,t,s).toString(16),h=r.util.createBuffer(),d=a-Math.ceil(l.length/2);d>0;)h.putByte(0),--d;return h.putBytes(r.util.hexToBytes(l)),!1!==n?T(h.getBytes(),t,s):h.getBytes()},o.rsa.createKeyPairGenerationState=function(e,t,s){'string'==typeof e&&(e=parseInt(e,10)),e=e||2048;var n,a=(s=s||{}).prng||r.random,o={nextBytes:function(e){for(var t=a.getBytesSync(e.length),i=0;i>1,pBits:e-(e>>1),pqState:0,num:null,keys:null}).e.fromInt(n.eInt),n},o.rsa.stepKeyPairGenerationState=function(e,t){'algorithm'in e||(e.algorithm='PRIMEINC');var r=new i(null);r.fromInt(30);for(var s,n=0,a=function(e,t){return e|t},l=+new Date,h=0;null===e.keys&&(t<=0||hd?e.pqState=0:e.num.isProbablePrime(I(e.num.bitLength()))?++e.pqState:e.num.dAddOffset(c[n++%8],0):2===e.pqState?e.pqState=0===e.num.subtract(i.ONE).gcd(e.e).compareTo(i.ONE)?3:0:3===e.pqState&&(e.pqState=0,null===e.p?e.p=e.num:e.q=e.num,null!==e.p&&null!==e.q&&++e.state,e.num=null)}else if(1===e.state)e.p.compareTo(e.q)<0&&(e.num=e.p,e.p=e.q,e.q=e.num),++e.state;else if(2===e.state)e.p1=e.p.subtract(i.ONE),e.q1=e.q.subtract(i.ONE),e.phi=e.p1.multiply(e.q1),++e.state;else if(3===e.state)0===e.phi.gcd(e.e).compareTo(i.ONE)?++e.state:(e.p=null,e.q=null,e.state=0);else if(4===e.state)e.n=e.p.multiply(e.q),e.n.bitLength()===e.bits?++e.state:(e.q=null,e.state=0);else if(5===e.state){var p=e.e.modInverse(e.phi);e.keys={privateKey:o.rsa.setPrivateKey(e.n,e.e,p,e.p,e.q,p.mod(e.p1),p.mod(e.q1),e.q.modInverse(e.p)),publicKey:o.rsa.setPublicKey(e.n,e.e)}}h+=(s=+new Date)-l,l=s}return null!==e.keys},o.rsa.generateKeyPair=function(e,t,c,l){if(1===arguments.length?'object'==typeof e?(c=e,e=void 0):'function'==typeof e&&(l=e,e=void 0):2===arguments.length?'number'==typeof e?'function'==typeof t?(l=t,t=void 0):'number'!=typeof t&&(c=t,t=void 0):(c=e,l=t,e=void 0,t=void 0):3===arguments.length&&('number'==typeof t?'function'==typeof c&&(l=c,c=void 0):(l=c,c=t,t=void 0)),c=c||{},void 0===e&&(e=c.bits||2048),void 0===t&&(t=c.e||65537),!r.options.usePureJavaScript&&!c.prng&&e>=256&&e<=16384&&(65537===t||3===t))if(l){if(S('generateKeyPair'))return s.generateKeyPair('rsa',{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:'spki',format:'pem'},privateKeyEncoding:{type:'pkcs8',format:'pem'}},(function(e,t,i){if(e)return l(e);l(null,{privateKey:o.privateKeyFromPem(i),publicKey:o.publicKeyFromPem(t)})}));if(O('generateKey')&&O('exportKey'))return a.globalScope.crypto.subtle.generateKey({name:'RSASSA-PKCS1-v1_5',modulusLength:e,publicExponent:P(t),hash:{name:'SHA-256'}},!0,['sign','verify']).then((function(e){return a.globalScope.crypto.subtle.exportKey('pkcs8',e.privateKey)})).then(void 0,(function(e){l(e)})).then((function(e){if(e){var t=o.privateKeyFromAsn1(n.fromDer(r.util.createBuffer(e)));l(null,{privateKey:t,publicKey:o.setRsaPublicKey(t.n,t.e)})}}));if(N('generateKey')&&N('exportKey')){var h=a.globalScope.msCrypto.subtle.generateKey({name:'RSASSA-PKCS1-v1_5',modulusLength:e,publicExponent:P(t),hash:{name:'SHA-256'}},!0,['sign','verify']);return h.oncomplete=function(e){var t=e.target.result,i=a.globalScope.msCrypto.subtle.exportKey('pkcs8',t.privateKey);i.oncomplete=function(e){var t=e.target.result,i=o.privateKeyFromAsn1(n.fromDer(r.util.createBuffer(t)));l(null,{privateKey:i,publicKey:o.setRsaPublicKey(i.n,i.e)})},i.onerror=function(e){l(e)}},void(h.onerror=function(e){l(e)})}}else if(S('generateKeyPairSync')){var d=s.generateKeyPairSync('rsa',{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:'spki',format:'pem'},privateKeyEncoding:{type:'pkcs8',format:'pem'}});return{privateKey:o.privateKeyFromPem(d.privateKey),publicKey:o.publicKeyFromPem(d.publicKey)}}var u=o.rsa.createKeyPairGenerationState(e,t,c);if(!l)return o.rsa.stepKeyPairGenerationState(u,0),u.keys;!function(e,t,s){'function'==typeof t&&(s=t,t={});t=t||{};var n={algorithm:{name:t.algorithm||'PRIMEINC',options:{workers:t.workers||2,workLoad:t.workLoad||100,workerScript:t.workerScript}}};'prng'in t&&(n.prng=t.prng);function a(){c(e.pBits,(function(t,i){return t?s(t):(e.p=i,null!==e.q?l(t,e.q):void c(e.qBits,l))}))}function c(e,t){r.prime.generateProbablePrime(e,n,t)}function l(t,r){if(t)return s(t);if(e.q=r,e.p.compareTo(e.q)<0){var n=e.p;e.p=e.q,e.q=n}if(0!==e.p.subtract(i.ONE).gcd(e.e).compareTo(i.ONE))return e.p=null,void a();if(0!==e.q.subtract(i.ONE).gcd(e.e).compareTo(i.ONE))return e.q=null,void c(e.qBits,l);if(e.p1=e.p.subtract(i.ONE),e.q1=e.q.subtract(i.ONE),e.phi=e.p1.multiply(e.q1),0!==e.phi.gcd(e.e).compareTo(i.ONE))return e.p=e.q=null,void a();if(e.n=e.p.multiply(e.q),e.n.bitLength()!==e.bits)return e.q=null,void c(e.qBits,l);var h=e.e.modInverse(e.phi);e.keys={privateKey:o.rsa.setPrivateKey(e.n,e.e,h,e.p,e.q,h.mod(e.p1),h.mod(e.q1),e.q.modInverse(e.p)),publicKey:o.rsa.setPublicKey(e.n,e.e)},s(null,e.keys)}a()}(u,c,l)},o.setRsaPublicKey=o.rsa.setPublicKey=function(e,t){var i={n:e,e:t,encrypt:function(e,t,s){if('string'==typeof t?t=t.toUpperCase():void 0===t&&(t='RSAES-PKCS1-V1_5'),'RSAES-PKCS1-V1_5'===t)t={encode:function(e,t,i){return v(e,t,2).getBytes()}};else if('RSA-OAEP'===t||'RSAES-OAEP'===t)t={encode:function(e,t){return r.pkcs1.encode_rsa_oaep(t,e,s)}};else if(-1!==['RAW','NONE','NULL',null].indexOf(t))t={encode:function(e){return e}};else if('string'==typeof t)throw new Error('Unsupported encryption scheme: "'+t+'".');var n=t.encode(e,i,!0);return o.rsa.encrypt(n,i,!0)},verify:function(e,t,s,a){'string'==typeof s?s=s.toUpperCase():void 0===s&&(s='RSASSA-PKCS1-V1_5'),void 0===a&&(a={_parseAllDigestBytes:!0}),'_parseAllDigestBytes'in a||(a._parseAllDigestBytes=!0),'RSASSA-PKCS1-V1_5'===s?s={verify:function(e,t){t=T(t,i,!0);var s=n.fromDer(t,{parseAllBytes:a._parseAllDigestBytes}),o={},c=[];if(!n.validate(s,m,o,c))throw(l=new Error('ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value.')).errors=c,l;var l,h=n.derToOid(o.algorithmIdentifier);if(h!==r.oids.md2&&h!==r.oids.md5&&h!==r.oids.sha1&&h!==r.oids.sha224&&h!==r.oids.sha256&&h!==r.oids.sha384&&h!==r.oids.sha512&&h!==r.oids['sha512-224']&&h!==r.oids['sha512-256'])throw(l=new Error('Unknown RSASSA-PKCS1-v1_5 DigestAlgorithm identifier.')).oid=h,l;if((h===r.oids.md2||h===r.oids.md5)&&!('parameters'in o))throw new Error('ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value. Missing algorithm identifer NULL parameters.');return e===o.digest}}:'NONE'!==s&&'NULL'!==s&&null!==s||(s={verify:function(e,t){return e===(t=T(t,i,!0))}});var c=o.rsa.decrypt(t,i,!0,!1);return s.verify(e,c,i.n.bitLength())}};return i},o.setRsaPrivateKey=o.rsa.setPrivateKey=function(e,t,i,s,n,a,c,l){var h={n:e,e:t,d:i,p:s,q:n,dP:a,dQ:c,qInv:l,decrypt:function(e,t,i){'string'==typeof t?t=t.toUpperCase():void 0===t&&(t='RSAES-PKCS1-V1_5');var s=o.rsa.decrypt(e,h,!1,!1);if('RSAES-PKCS1-V1_5'===t)t={decode:T};else if('RSA-OAEP'===t||'RSAES-OAEP'===t)t={decode:function(e,t){return r.pkcs1.decode_rsa_oaep(t,e,i)}};else{if(-1===['RAW','NONE','NULL',null].indexOf(t))throw new Error('Unsupported encryption scheme: "'+t+'".');t={decode:function(e){return e}}}return t.decode(s,h,!1)},sign:function(e,t){var i=!1;'string'==typeof t&&(t=t.toUpperCase()),void 0===t||'RSASSA-PKCS1-V1_5'===t?(t={encode:y},i=1):'NONE'!==t&&'NULL'!==t&&null!==t||(t={encode:function(){return e}},i=1);var r=t.encode(e,h.n.bitLength());return o.rsa.encrypt(r,h,i)}};return h},o.wrapRsaPrivateKey=function(e){return n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,n.integerToDer(0).getBytes()),n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.OID,!1,n.oidToDer(o.oids.rsaEncryption).getBytes()),n.create(n.Class.UNIVERSAL,n.Type.NULL,!1,'')]),n.create(n.Class.UNIVERSAL,n.Type.OCTETSTRING,!1,n.toDer(e).getBytes())])},o.privateKeyFromAsn1=function(e){var t,s,a,c,h,u,p,f,g={},m=[];if(n.validate(e,l,g,m)&&(e=n.fromDer(r.util.createBuffer(g.privateKey))),g={},m=[],!n.validate(e,d,g,m)){var y=new Error('Cannot read private key. ASN.1 object does not contain an RSAPrivateKey.');throw y.errors=m,y}return t=r.util.createBuffer(g.privateKeyModulus).toHex(),s=r.util.createBuffer(g.privateKeyPublicExponent).toHex(),a=r.util.createBuffer(g.privateKeyPrivateExponent).toHex(),c=r.util.createBuffer(g.privateKeyPrime1).toHex(),h=r.util.createBuffer(g.privateKeyPrime2).toHex(),u=r.util.createBuffer(g.privateKeyExponent1).toHex(),p=r.util.createBuffer(g.privateKeyExponent2).toHex(),f=r.util.createBuffer(g.privateKeyCoefficient).toHex(),o.setRsaPrivateKey(new i(t,16),new i(s,16),new i(a,16),new i(c,16),new i(h,16),new i(u,16),new i(p,16),new i(f,16))},o.privateKeyToAsn1=o.privateKeyToRSAPrivateKey=function(e){return n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,n.integerToDer(0).getBytes()),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.n)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.e)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.d)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.p)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.q)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.dP)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.dQ)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.qInv))])},o.publicKeyFromAsn1=function(e){var t={},s=[];if(n.validate(e,g,t,s)){var a,c=n.derToOid(t.publicKeyOid);if(c!==o.oids.rsaEncryption)throw(a=new Error('Cannot read public key. Unknown OID.')).oid=c,a;e=t.rsaPublicKey}if(s=[],!n.validate(e,p,t,s))throw(a=new Error('Cannot read public key. ASN.1 object does not contain an RSAPublicKey.')).errors=s,a;var l=r.util.createBuffer(t.publicKeyModulus).toHex(),h=r.util.createBuffer(t.publicKeyExponent).toHex();return o.setRsaPublicKey(new i(l,16),new i(h,16))},o.publicKeyToAsn1=o.publicKeyToSubjectPublicKeyInfo=function(e){return n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.OID,!1,n.oidToDer(o.oids.rsaEncryption).getBytes()),n.create(n.Class.UNIVERSAL,n.Type.NULL,!1,'')]),n.create(n.Class.UNIVERSAL,n.Type.BITSTRING,!1,[o.publicKeyToRSAPublicKey(e)])])},o.publicKeyToRSAPublicKey=function(e){return n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.n)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.e))])}}}),D=d({'node_modules/node-forge/lib/pbe.js'(e,t){var i,r=u();y(),_(),I(),A(),E(),S(),C(),L(),P(),U(),f(),void 0===i&&(i=r.jsbn.BigInteger);var s=r.asn1,n=r.pki=r.pki||{};t.exports=n.pbe=r.pbe=r.pbe||{};var a=n.oids,o={name:'EncryptedPrivateKeyInfo',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'EncryptedPrivateKeyInfo.encryptionAlgorithm',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'AlgorithmIdentifier.algorithm',tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:'encryptionOid'},{name:'AlgorithmIdentifier.parameters',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,captureAsn1:'encryptionParams'}]},{name:'EncryptedPrivateKeyInfo.encryptedData',tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:'encryptedData'}]},c={name:'PBES2Algorithms',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'PBES2Algorithms.keyDerivationFunc',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'PBES2Algorithms.keyDerivationFunc.oid',tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:'kdfOid'},{name:'PBES2Algorithms.params',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'PBES2Algorithms.params.salt',tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:'kdfSalt'},{name:'PBES2Algorithms.params.iterationCount',tagClass:s.Class.UNIVERSAL,type:s.Type.INTEGER,constructed:!1,capture:'kdfIterationCount'},{name:'PBES2Algorithms.params.keyLength',tagClass:s.Class.UNIVERSAL,type:s.Type.INTEGER,constructed:!1,optional:!0,capture:'keyLength'},{name:'PBES2Algorithms.params.prf',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,optional:!0,value:[{name:'PBES2Algorithms.params.prf.algorithm',tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:'prfOid'}]}]}]},{name:'PBES2Algorithms.encryptionScheme',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'PBES2Algorithms.encryptionScheme.oid',tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:'encOid'},{name:'PBES2Algorithms.encryptionScheme.iv',tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:'encIv'}]}]},l={name:'pkcs-12PbeParams',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'pkcs-12PbeParams.salt',tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:'salt'},{name:'pkcs-12PbeParams.iterations',tagClass:s.Class.UNIVERSAL,type:s.Type.INTEGER,constructed:!1,capture:'iterations'}]};function h(e,t){return e.start().update(t).digest().getBytes()}function d(e){var t;if(e){if(!(t=n.oids[s.derToOid(e)])){var i=new Error('Unsupported PRF OID.');throw i.oid=e,i.supported=['hmacWithSHA1','hmacWithSHA224','hmacWithSHA256','hmacWithSHA384','hmacWithSHA512'],i}}else t='hmacWithSHA1';return p(t)}function p(e){var t=r.md;switch(e){case'hmacWithSHA224':t=r.md.sha512;case'hmacWithSHA1':case'hmacWithSHA256':case'hmacWithSHA384':case'hmacWithSHA512':e=e.substr(8).toLowerCase();break;default:var i=new Error('Unsupported PRF algorithm.');throw i.algorithm=e,i.supported=['hmacWithSHA1','hmacWithSHA224','hmacWithSHA256','hmacWithSHA384','hmacWithSHA512'],i}if(!t||!(e in t))throw new Error('Unknown hash algorithm: '+e);return t[e].create()}n.encryptPrivateKeyInfo=function(e,t,i){(i=i||{}).saltSize=i.saltSize||8,i.count=i.count||2048,i.algorithm=i.algorithm||'aes128',i.prfAlgorithm=i.prfAlgorithm||'sha1';var o,c,l,h=r.random.getBytesSync(i.saltSize),d=i.count,u=s.integerToDer(d);if(0===i.algorithm.indexOf('aes')||'des'===i.algorithm){var f,g,m;switch(i.algorithm){case'aes128':o=16,f=16,g=a['aes128-CBC'],m=r.aes.createEncryptionCipher;break;case'aes192':o=24,f=16,g=a['aes192-CBC'],m=r.aes.createEncryptionCipher;break;case'aes256':o=32,f=16,g=a['aes256-CBC'],m=r.aes.createEncryptionCipher;break;case'des':o=8,f=8,g=a.desCBC,m=r.des.createEncryptionCipher;break;default:throw(T=new Error('Cannot encrypt private key. Unknown encryption algorithm.')).algorithm=i.algorithm,T}var y='hmacWith'+i.prfAlgorithm.toUpperCase(),E=p(y),_=r.pkcs5.pbkdf2(t,h,d,o,E),A=r.random.getBytesSync(f);(C=m(_)).start(A),C.update(s.toDer(e)),C.finish(),l=C.output.getBytes();var v=function(e,t,i,a){var o=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,e),s.create(s.Class.UNIVERSAL,s.Type.INTEGER,!1,t.getBytes())]);'hmacWithSHA1'!==a&&o.value.push(s.create(s.Class.UNIVERSAL,s.Type.INTEGER,!1,r.util.hexToBytes(i.toString(16))),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(n.oids[a]).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.NULL,!1,'')]));return o}(h,u,o,y);c=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(a.pkcs5PBES2).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(a.pkcs5PBKDF2).getBytes()),v]),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(g).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,A)])])])}else{var T;if('3des'!==i.algorithm)throw(T=new Error('Cannot encrypt private key. Unknown encryption algorithm.')).algorithm=i.algorithm,T;o=24;var C,I=new r.util.ByteBuffer(h);_=n.pbe.generatePkcs12Key(t,I,1,d,o),A=n.pbe.generatePkcs12Key(t,I,2,d,o);(C=r.des.createEncryptionCipher(_)).start(A),C.update(s.toDer(e)),C.finish(),l=C.output.getBytes(),c=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(a['pbeWithSHAAnd3-KeyTripleDES-CBC']).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,h),s.create(s.Class.UNIVERSAL,s.Type.INTEGER,!1,u.getBytes())])])}return s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[c,s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,l)])},n.decryptPrivateKeyInfo=function(e,t){var i=null,a={},c=[];if(!s.validate(e,o,a,c)){var l=new Error('Cannot read encrypted private key. ASN.1 object is not a supported EncryptedPrivateKeyInfo.');throw l.errors=c,l}var h=s.derToOid(a.encryptionOid),d=n.pbe.getCipher(h,a.encryptionParams,t),u=r.util.createBuffer(a.encryptedData);return d.update(u),d.finish()&&(i=s.fromDer(d.output)),i},n.encryptedPrivateKeyToPem=function(e,t){var i={type:'ENCRYPTED PRIVATE KEY',body:s.toDer(e).getBytes()};return r.pem.encode(i,{maxline:t})},n.encryptedPrivateKeyFromPem=function(e){var t=r.pem.decode(e)[0];if('ENCRYPTED PRIVATE KEY'!==t.type){var i=new Error('Could not convert encrypted private key from PEM; PEM header type is "ENCRYPTED PRIVATE KEY".');throw i.headerType=t.type,i}if(t.procType&&'ENCRYPTED'===t.procType.type)throw new Error('Could not convert encrypted private key from PEM; PEM is encrypted.');return s.fromDer(t.body)},n.encryptRsaPrivateKey=function(e,t,i){if(!(i=i||{}).legacy){var a=n.wrapRsaPrivateKey(n.privateKeyToAsn1(e));return a=n.encryptPrivateKeyInfo(a,t,i),n.encryptedPrivateKeyToPem(a)}var o,c,l,h;switch(i.algorithm){case'aes128':o='AES-128-CBC',l=16,c=r.random.getBytesSync(16),h=r.aes.createEncryptionCipher;break;case'aes192':o='AES-192-CBC',l=24,c=r.random.getBytesSync(16),h=r.aes.createEncryptionCipher;break;case'aes256':o='AES-256-CBC',l=32,c=r.random.getBytesSync(16),h=r.aes.createEncryptionCipher;break;case'3des':o='DES-EDE3-CBC',l=24,c=r.random.getBytesSync(8),h=r.des.createEncryptionCipher;break;case'des':o='DES-CBC',l=8,c=r.random.getBytesSync(8),h=r.des.createEncryptionCipher;break;default:var d=new Error('Could not encrypt RSA private key; unsupported encryption algorithm "'+i.algorithm+'".');throw d.algorithm=i.algorithm,d}var u=h(r.pbe.opensslDeriveBytes(t,c.substr(0,8),l));u.start(c),u.update(s.toDer(n.privateKeyToAsn1(e))),u.finish();var p={type:'RSA PRIVATE KEY',procType:{version:'4',type:'ENCRYPTED'},dekInfo:{algorithm:o,parameters:r.util.bytesToHex(c).toUpperCase()},body:u.output.getBytes()};return r.pem.encode(p)},n.decryptRsaPrivateKey=function(e,t){var i=null,a=r.pem.decode(e)[0];if('ENCRYPTED PRIVATE KEY'!==a.type&&'PRIVATE KEY'!==a.type&&'RSA PRIVATE KEY'!==a.type)throw(l=new Error('Could not convert private key from PEM; PEM header type is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".')).headerType=l,l;if(a.procType&&'ENCRYPTED'===a.procType.type){var o,c;switch(a.dekInfo.algorithm){case'DES-CBC':o=8,c=r.des.createDecryptionCipher;break;case'DES-EDE3-CBC':o=24,c=r.des.createDecryptionCipher;break;case'AES-128-CBC':o=16,c=r.aes.createDecryptionCipher;break;case'AES-192-CBC':o=24,c=r.aes.createDecryptionCipher;break;case'AES-256-CBC':o=32,c=r.aes.createDecryptionCipher;break;case'RC2-40-CBC':o=5,c=function(e){return r.rc2.createDecryptionCipher(e,40)};break;case'RC2-64-CBC':o=8,c=function(e){return r.rc2.createDecryptionCipher(e,64)};break;case'RC2-128-CBC':o=16,c=function(e){return r.rc2.createDecryptionCipher(e,128)};break;default:var l;throw(l=new Error('Could not decrypt private key; unsupported encryption algorithm "'+a.dekInfo.algorithm+'".')).algorithm=a.dekInfo.algorithm,l}var h=r.util.hexToBytes(a.dekInfo.parameters),d=c(r.pbe.opensslDeriveBytes(t,h.substr(0,8),o));if(d.start(h),d.update(r.util.createBuffer(a.body)),!d.finish())return i;i=d.output.getBytes()}else i=a.body;return null!==(i='ENCRYPTED PRIVATE KEY'===a.type?n.decryptPrivateKeyInfo(s.fromDer(i),t):s.fromDer(i))&&(i=n.privateKeyFromAsn1(i)),i},n.pbe.generatePkcs12Key=function(e,t,i,s,n,a){var o,c;if(null==a){if(!('sha1'in r.md))throw new Error('"sha1" hash algorithm unavailable.');a=r.md.sha1.create()}var l=a.digestLength,h=a.blockLength,d=new r.util.ByteBuffer,u=new r.util.ByteBuffer;if(null!=e){for(c=0;c=0;c--)P>>=8,P+=S.at(c)+L.at(c),L.setAt(c,255&P);N.putBuffer(L)}A=N,d.putBuffer(C)}return d.truncate(d.length()-n),d},n.pbe.getCipher=function(e,t,i){switch(e){case n.oids.pkcs5PBES2:return n.pbe.getCipherForPBES2(e,t,i);case n.oids['pbeWithSHAAnd3-KeyTripleDES-CBC']:case n.oids['pbewithSHAAnd40BitRC2-CBC']:return n.pbe.getCipherForPKCS12PBE(e,t,i);default:var r=new Error('Cannot read encrypted PBE data block. Unsupported OID.');throw r.oid=e,r.supportedOids=['pkcs5PBES2','pbeWithSHAAnd3-KeyTripleDES-CBC','pbewithSHAAnd40BitRC2-CBC'],r}},n.pbe.getCipherForPBES2=function(e,t,i){var a,o={},l=[];if(!s.validate(t,c,o,l))throw(a=new Error('Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.')).errors=l,a;if((e=s.derToOid(o.kdfOid))!==n.oids.pkcs5PBKDF2)throw(a=new Error('Cannot read encrypted private key. Unsupported key derivation function OID.')).oid=e,a.supportedOids=['pkcs5PBKDF2'],a;if((e=s.derToOid(o.encOid))!==n.oids['aes128-CBC']&&e!==n.oids['aes192-CBC']&&e!==n.oids['aes256-CBC']&&e!==n.oids['des-EDE3-CBC']&&e!==n.oids.desCBC)throw(a=new Error('Cannot read encrypted private key. Unsupported encryption scheme OID.')).oid=e,a.supportedOids=['aes128-CBC','aes192-CBC','aes256-CBC','des-EDE3-CBC','desCBC'],a;var h,u,p=o.kdfSalt,f=r.util.createBuffer(o.kdfIterationCount);switch(f=f.getInt(f.length()<<3),n.oids[e]){case'aes128-CBC':h=16,u=r.aes.createDecryptionCipher;break;case'aes192-CBC':h=24,u=r.aes.createDecryptionCipher;break;case'aes256-CBC':h=32,u=r.aes.createDecryptionCipher;break;case'des-EDE3-CBC':h=24,u=r.des.createDecryptionCipher;break;case'desCBC':h=8,u=r.des.createDecryptionCipher}var g=d(o.prfOid),m=r.pkcs5.pbkdf2(i,p,f,h,g),y=o.encIv,E=u(m);return E.start(y),E},n.pbe.getCipherForPKCS12PBE=function(e,t,i){var a={},o=[];if(!s.validate(t,l,a,o))throw(g=new Error('Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.')).errors=o,g;var c,h,u,p=r.util.createBuffer(a.salt),f=r.util.createBuffer(a.iterations);switch(f=f.getInt(f.length()<<3),e){case n.oids['pbeWithSHAAnd3-KeyTripleDES-CBC']:c=24,h=8,u=r.des.startDecrypting;break;case n.oids['pbewithSHAAnd40BitRC2-CBC']:c=5,h=8,u=function(e,t){var i=r.rc2.createDecryptionCipher(e,40);return i.start(t,null),i};break;default:var g;throw(g=new Error('Cannot read PKCS #12 PBE data block. Unsupported OID.')).oid=e,g}var m=d(a.prfOid),y=n.pbe.generatePkcs12Key(i,p,1,f,c,m);return m.start(),u(y,n.pbe.generatePkcs12Key(i,p,2,f,h,m))},n.pbe.opensslDeriveBytes=function(e,t,i,s){if(null==s){if(!('md5'in r.md))throw new Error('"md5" hash algorithm unavailable.');s=r.md.md5.create()}null===t&&(t='');for(var n=[h(s,e+t)],a=16,o=1;a>8*u-d&255;return(A=String.fromCharCode(A.charCodeAt(0)&~v)+A.substr(1))+g+String.fromCharCode(188)},verify:function(e,a,o){var c,l=o-1,h=Math.ceil(l/8);if(a=a.substr(-h),h>8*h-l&255;if(u.charCodeAt(0)&f)throw new Error('Bits beyond keysize not zero as expected.');var g=s.generate(p,d),m='';for(c=0;c128)throw new Error('Invalid "nsComment" content.');e.value=r.create(r.Class.UNIVERSAL,r.Type.IA5STRING,!1,e.comment)}else if('subjectKeyIdentifier'===e.name&&t.cert){var p=t.cert.generateSubjectKeyIdentifier();e.subjectKeyIdentifier=p.toHex(),e.value=r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,p.getBytes())}else if('authorityKeyIdentifier'===e.name&&t.cert){e.value=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[]);h=e.value.value;if(e.keyIdentifier){var f=!0===e.keyIdentifier?t.cert.generateSubjectKeyIdentifier().getBytes():e.keyIdentifier;h.push(r.create(r.Class.CONTEXT_SPECIFIC,0,!1,f))}if(e.authorityCertIssuer){var g=[r.create(r.Class.CONTEXT_SPECIFIC,4,!0,[T(!0===e.authorityCertIssuer?t.cert.issuer:e.authorityCertIssuer)])];h.push(r.create(r.Class.CONTEXT_SPECIFIC,1,!0,g))}if(e.serialNumber){var m=i.util.hexToBytes(!0===e.serialNumber?t.cert.serialNumber:e.serialNumber);h.push(r.create(r.Class.CONTEXT_SPECIFIC,2,!1,m))}}else if('cRLDistributionPoints'===e.name){e.value=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[]);h=e.value.value;var y,E=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[]),_=r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[]);for(u=0;u2)throw new Error('Cannot read notBefore/notAfter validity times; more than two times were provided in the certificate.');if(d.length<2)throw new Error('Cannot read notBefore/notAfter validity times; they were not provided as either UTCTime or GeneralizedTime.');if(l.validity.notBefore=d[0],l.validity.notAfter=d[1],l.tbsCertificate=n.tbsCertificate,t){l.md=m({signatureOid:l.signatureOid,type:'certificate'});var u=r.toDer(l.tbsCertificate);l.md.update(u.getBytes())}var f=i.md.sha1.create(),y=r.toDer(n.certIssuer);f.update(y.getBytes()),l.issuer.getField=function(e){return p(l.issuer,e)},l.issuer.addField=function(e){S([e]),l.issuer.attributes.push(e)},l.issuer.attributes=s.RDNAttributesAsArray(n.certIssuer),n.certIssuerUniqueId&&(l.issuer.uniqueId=n.certIssuerUniqueId),l.issuer.hash=f.digest().toHex();var E=i.md.sha1.create(),_=r.toDer(n.certSubject);return E.update(_.getBytes()),l.subject.getField=function(e){return p(l.subject,e)},l.subject.addField=function(e){S([e]),l.subject.attributes.push(e)},l.subject.attributes=s.RDNAttributesAsArray(n.certSubject),n.certSubjectUniqueId&&(l.subject.uniqueId=n.certSubjectUniqueId),l.subject.hash=E.digest().toHex(),n.certExtensions?l.extensions=s.certificateExtensionsFromAsn1(n.certExtensions):l.extensions=[],l.publicKey=s.publicKeyFromAsn1(n.subjectPublicKeyInfo),l},s.certificateExtensionsFromAsn1=function(e){for(var t=[],i=0;i1&&(s=c.value.charCodeAt(1),a=c.value.length>2?c.value.charCodeAt(2):0),t.digitalSignature=!(128&~s),t.nonRepudiation=!(64&~s),t.keyEncipherment=!(32&~s),t.dataEncipherment=!(16&~s),t.keyAgreement=!(8&~s),t.keyCertSign=!(4&~s),t.cRLSign=!(2&~s),t.encipherOnly=!(1&~s),t.decipherOnly=!(128&~a)}else if('basicConstraints'===t.name){(c=r.fromDer(t.value)).value.length>0&&c.value[0].type===r.Type.BOOLEAN?t.cA=0!==c.value[0].value.charCodeAt(0):t.cA=!1;var o=null;c.value.length>0&&c.value[0].type===r.Type.INTEGER?o=c.value[0].value:c.value.length>1&&(o=c.value[1].value),null!==o&&(t.pathLenConstraint=r.derToInteger(o))}else if('extKeyUsage'===t.name)for(var c=r.fromDer(t.value),l=0;l1&&(s=c.value.charCodeAt(1)),t.client=!(128&~s),t.server=!(64&~s),t.email=!(32&~s),t.objsign=!(16&~s),t.reserved=!(8&~s),t.sslCA=!(4&~s),t.emailCA=!(2&~s),t.objCA=!(1&~s)}else if('subjectAltName'===t.name||'issuerAltName'===t.name){var d;t.altNames=[];c=r.fromDer(t.value);for(var u=0;u=P&&e0&&a.value.push(s.certificateExtensionsToAsn1(e.extensions)),a},s.getCertificationRequestInfo=function(e){return r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.INTEGER,!1,r.integerToDer(e.version).getBytes()),T(e.subject),s.publicKeyToAsn1(e.publicKey),L(e)])},s.distinguishedNameToAsn1=function(e){return T(e)},s.certificateToAsn1=function(e){var t=e.tbsCertificate||s.getTBSCertificate(e);return r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[t,r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(e.signatureOid).getBytes()),N(e.signatureOid,e.signatureParameters)]),r.create(r.Class.UNIVERSAL,r.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},s.certificateExtensionsToAsn1=function(e){var t=r.create(r.Class.CONTEXT_SPECIFIC,3,!0,[]),i=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[]);t.value.push(i);for(var n=0;nh.validity.notAfter)&&(c={message:'Certificate is not valid yet or has expired.',error:s.certificateError.certificate_expired,notBefore:h.validity.notBefore,notAfter:h.validity.notAfter,now:a}),null===c){if(null===(d=t[0]||e.getIssuer(h))&&h.isIssuer(h)&&(u=!0,d=h),d){var p=d;i.util.isArray(p)||(p=[p]);for(var f=!1;!f&&p.length>0;){d=p.shift();try{f=d.verify(h)}catch(e){}}f||(c={message:'Certificate signature is invalid.',error:s.certificateError.bad_certificate})}null!==c||d&&!u||e.hasCertificate(h)||(c={message:'Certificate is not trusted.',error:s.certificateError.unknown_ca})}if(null===c&&d&&!h.isIssuer(d)&&(c={message:'Certificate issuer is invalid.',error:s.certificateError.bad_certificate}),null===c)for(var g={keyUsage:!0,basicConstraints:!0},m=0;null===c&&mE.pathLenConstraint&&(c={message:'Certificate basicConstraints pathLenConstraint violated.',error:s.certificateError.bad_certificate})}var A=null===c||c.error,v=r.verify?r.verify(A,l,n):A;if(!0!==v)throw!0===A&&(c={message:'The application rejected the certificate.',error:s.certificateError.bad_certificate}),(v||0===v)&&('object'!=typeof v||i.util.isArray(v)?'string'==typeof v&&(c.error=v):(v.message&&(c.message=v.message),v.error&&(c.error=v.error))),c;c=null,o=!1,++l}while(t.length>0);return!0}}}),V=d({'node_modules/node-forge/lib/pkcs12.js'(e,t){var i=u();_(),v(),E(),k(),D(),L(),U(),b(),f(),H();var r=i.asn1,s=i.pki,n=t.exports=i.pkcs12=i.pkcs12||{},a={name:'ContentInfo',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'ContentInfo.contentType',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'contentType'},{name:'ContentInfo.content',tagClass:r.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:'content'}]},o={name:'PFX',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'PFX.version',tagClass:r.Class.UNIVERSAL,type:r.Type.INTEGER,constructed:!1,capture:'version'},a,{name:'PFX.macData',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:'mac',value:[{name:'PFX.macData.mac',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'PFX.macData.mac.digestAlgorithm',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'PFX.macData.mac.digestAlgorithm.algorithm',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'macAlgorithm'},{name:'PFX.macData.mac.digestAlgorithm.parameters',tagClass:r.Class.UNIVERSAL,captureAsn1:'macAlgorithmParameters'}]},{name:'PFX.macData.mac.digest',tagClass:r.Class.UNIVERSAL,type:r.Type.OCTETSTRING,constructed:!1,capture:'macDigest'}]},{name:'PFX.macData.macSalt',tagClass:r.Class.UNIVERSAL,type:r.Type.OCTETSTRING,constructed:!1,capture:'macSalt'},{name:'PFX.macData.iterations',tagClass:r.Class.UNIVERSAL,type:r.Type.INTEGER,constructed:!1,optional:!0,capture:'macIterations'}]}]},c={name:'SafeBag',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'SafeBag.bagId',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'bagId'},{name:'SafeBag.bagValue',tagClass:r.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:'bagValue'},{name:'SafeBag.bagAttributes',tagClass:r.Class.UNIVERSAL,type:r.Type.SET,constructed:!0,optional:!0,capture:'bagAttributes'}]},l={name:'Attribute',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'Attribute.attrId',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'oid'},{name:'Attribute.attrValues',tagClass:r.Class.UNIVERSAL,type:r.Type.SET,constructed:!0,capture:'values'}]},h={name:'CertBag',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'CertBag.certId',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'certId'},{name:'CertBag.certValue',tagClass:r.Class.CONTEXT_SPECIFIC,constructed:!0,value:[{name:'CertBag.certValue[0]',tagClass:r.Class.UNIVERSAL,type:r.Class.OCTETSTRING,constructed:!1,capture:'cert'}]}]};function d(e,t,i,r){for(var s=[],n=0;n=0&&s.push(o):s.push(o))}return s}function p(e){if(e.composed||e.constructed){for(var t=i.util.createBuffer(),r=0;r0&&(c=r.create(r.Class.UNIVERSAL,r.Type.SET,!0,d));var u=[],p=[];null!==t&&(p=i.util.isArray(t)?t:[t]);for(var f=[],g=0;g0){var _=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,f),A=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.data).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,r.toDer(_).getBytes())])]);u.push(A)}var v=null;if(null!==e){var T=s.wrapRsaPrivateKey(s.privateKeyToAsn1(e));v=null===a?r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.keyBag).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[T]),c]):r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.pkcs8ShroudedKeyBag).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[s.encryptPrivateKeyInfo(T,a,o)]),c]);var C=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[v]),I=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.data).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,r.toDer(C).getBytes())])]);u.push(I)}var S,O=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,u);if(o.useMac){var N=i.md.sha1.create(),L=new i.util.ByteBuffer(i.random.getBytes(o.saltSize)),P=o.count,w=(e=n.generateKey(a,L,3,P,20),i.hmac.create());w.start(N,e),w.update(r.toDer(O).getBytes());var b=w.getMac();S=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.sha1).getBytes()),r.create(r.Class.UNIVERSAL,r.Type.NULL,!1,'')]),r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,b.getBytes())]),r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,L.getBytes()),r.create(r.Class.UNIVERSAL,r.Type.INTEGER,!1,r.integerToDer(P).getBytes())])}return r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.INTEGER,!1,r.integerToDer(3).getBytes()),r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.data).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,r.toDer(O).getBytes())])]),S])},n.generateKey=i.pbe.generatePkcs12Key}}),G=d({'node_modules/node-forge/lib/pki.js'(e,t){var i=u();_(),E(),D(),C(),S(),V(),F(),U(),f(),H();var r=i.asn1,s=t.exports=i.pki=i.pki||{};s.pemToDer=function(e){var t=i.pem.decode(e)[0];if(t.procType&&'ENCRYPTED'===t.procType.type)throw new Error('Could not convert PEM to DER; PEM is encrypted.');return i.util.createBuffer(t.body)},s.privateKeyFromPem=function(e){var t=i.pem.decode(e)[0];if('PRIVATE KEY'!==t.type&&'RSA PRIVATE KEY'!==t.type){var n=new Error('Could not convert private key from PEM; PEM header type is not "PRIVATE KEY" or "RSA PRIVATE KEY".');throw n.headerType=t.type,n}if(t.procType&&'ENCRYPTED'===t.procType.type)throw new Error('Could not convert private key from PEM; PEM is encrypted.');var a=r.fromDer(t.body);return s.privateKeyFromAsn1(a)},s.privateKeyToPem=function(e,t){var n={type:'RSA PRIVATE KEY',body:r.toDer(s.privateKeyToAsn1(e)).getBytes()};return i.pem.encode(n,{maxline:t})},s.privateKeyInfoToPem=function(e,t){var s={type:'PRIVATE KEY',body:r.toDer(e).getBytes()};return i.pem.encode(s,{maxline:t})}}}),W=d({'node_modules/node-forge/lib/tls.js'(e,t){var i=u();_(),v(),T(),C(),G(),L(),b(),f();var r=function(e,t,r,s){var n=i.util.createBuffer(),a=e.length>>1,o=a+(1&e.length),c=e.substr(0,o),l=e.substr(a,o),h=i.util.createBuffer(),d=i.hmac.create();r=t+r;var u=Math.ceil(s/16),p=Math.ceil(s/20);d.start('MD5',c);var f=i.util.createBuffer();h.putBytes(r);for(var g=0;g0&&(c.queue(e,c.createAlert(e,{level:c.Alert.Level.warning,description:c.Alert.Description.no_renegotiation})),c.flush(e)),e.process()},c.parseHelloMessage=function(e,t,r){var s=null,n=e.entity===c.ConnectionEnd.client;if(r<38)e.error(e,{message:n?'Invalid ServerHello message. Message too short.':'Invalid ClientHello message. Message too short.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}});else{var o=t.fragment,l=o.length();if(s={version:{major:o.getByte(),minor:o.getByte()},random:i.util.createBuffer(o.getBytes(32)),session_id:a(o,1),extensions:[]},n?(s.cipher_suite=o.getBytes(2),s.compression_method=o.getByte()):(s.cipher_suites=a(o,2),s.compression_methods=a(o,1)),(l=r-(l-o.length()))>0){for(var h=a(o,2);h.length()>0;)s.extensions.push({type:[h.getByte(),h.getByte()],data:a(h,2)});if(!n)for(var d=0;d0;){if(0!==p.getByte())break;e.session.extensions.server_name.serverNameList.push(a(p,2).getBytes())}}}if(e.session.version&&(s.version.major!==e.session.version.major||s.version.minor!==e.session.version.minor))return e.error(e,{message:'TLS version change is disallowed during renegotiation.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.protocol_version}});if(n)e.session.cipherSuite=c.getCipherSuite(s.cipher_suite);else for(var f=i.util.createBuffer(s.cipher_suites.bytes());f.length()>0&&(e.session.cipherSuite=c.getCipherSuite(f.getBytes(2)),null===e.session.cipherSuite););if(null===e.session.cipherSuite)return e.error(e,{message:'No cipher suites in common.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.handshake_failure},cipherSuite:i.util.bytesToHex(s.cipher_suite)});e.session.compressionMethod=n?s.compression_method:c.CompressionMethod.none}return s},c.createSecurityParameters=function(e,t){var i=e.entity===c.ConnectionEnd.client,r=t.random.bytes(),s=i?e.session.sp.client_random:r,n=i?r:c.createRandom().getBytes();e.session.sp={entity:e.entity,prf_algorithm:c.PRFAlgorithm.tls_prf_sha256,bulk_cipher_algorithm:null,cipher_type:null,enc_key_length:null,block_length:null,fixed_iv_length:null,record_iv_length:null,mac_algorithm:null,mac_length:null,mac_key_length:null,compression_algorithm:e.session.compressionMethod,pre_master_secret:null,master_secret:null,client_random:s,server_random:n}},c.handleServerHello=function(e,t,i){var r=c.parseHelloMessage(e,t,i);if(!e.fail){if(!(r.version.minor<=e.version.minor))return e.error(e,{message:'Incompatible TLS version.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.protocol_version}});e.version.minor=r.version.minor,e.session.version=e.version;var s=r.session_id.bytes();s.length>0&&s===e.session.id?(e.expect=g,e.session.resuming=!0,e.session.sp.server_random=r.random.bytes()):(e.expect=l,e.session.resuming=!1,c.createSecurityParameters(e,r)),e.session.id=s,e.process()}},c.handleClientHello=function(e,t,r){var s=c.parseHelloMessage(e,t,r);if(!e.fail){var n=s.session_id.bytes(),a=null;if(e.sessionCache&&(null===(a=e.sessionCache.getSession(n))?n='':(a.version.major!==s.version.major||a.version.minor>s.version.minor)&&(a=null,n='')),0===n.length&&(n=i.random.getBytes(32)),e.session.id=n,e.session.clientHelloVersion=s.version,e.session.sp={},a)e.version=e.session.version=a.version,e.session.sp=a.sp;else{for(var o,l=1;l0;)s=a(l.certificate_list,3),n=i.asn1.fromDer(s),s=i.pki.certificateFromAsn1(n,!0),d.push(s)}catch(t){return e.error(e,{message:'Could not parse certificate list.',cause:t,send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.bad_certificate}})}var u=e.entity===c.ConnectionEnd.client;!u&&!0!==e.verifyClient||0!==d.length?0===d.length?e.expect=u?h:I:(u?e.session.serverCertificate=d[0]:e.session.clientCertificate=d[0],c.verifyCertificateChain(e,d)&&(e.expect=u?h:I)):e.error(e,{message:u?'No server certificate provided.':'No client certificate provided.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}}),e.process()},c.handleServerKeyExchange=function(e,t,i){if(i>0)return e.error(e,{message:'Invalid key parameters. Only RSA is supported.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.unsupported_certificate}});e.expect=d,e.process()},c.handleClientKeyExchange=function(e,t,r){if(r<48)return e.error(e,{message:'Invalid key parameters. Only RSA is supported.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.unsupported_certificate}});var s=t.fragment,n={enc_pre_master_secret:a(s,2).getBytes()},o=null;if(e.getPrivateKey)try{o=e.getPrivateKey(e,e.session.serverCertificate),o=i.pki.privateKeyFromPem(o)}catch(t){e.error(e,{message:'Could not get private key.',cause:t,send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.internal_error}})}if(null===o)return e.error(e,{message:'No private key set.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.internal_error}});try{var l=e.session.sp;l.pre_master_secret=o.decrypt(n.enc_pre_master_secret);var h=e.session.clientHelloVersion;if(h.major!==l.pre_master_secret.charCodeAt(0)||h.minor!==l.pre_master_secret.charCodeAt(1))throw new Error('TLS version rollback attack detected.')}catch(e){l.pre_master_secret=i.random.getBytes(48)}e.expect=O,null!==e.session.clientCertificate&&(e.expect=S),e.process()},c.handleCertificateRequest=function(e,t,i){if(i<3)return e.error(e,{message:'Invalid CertificateRequest. Message too short.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}});var r=t.fragment,s={certificate_types:a(r,1),certificate_authorities:a(r,2)};e.session.certificateRequest=s,e.expect=p,e.process()},c.handleCertificateVerify=function(e,t,r){if(r<2)return e.error(e,{message:'Invalid CertificateVerify. Message too short.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}});var s=t.fragment;s.read-=4;var n=s.bytes();s.read+=4;var o={signature:a(s,2).getBytes()},l=i.util.createBuffer();l.putBuffer(e.session.md5.digest()),l.putBuffer(e.session.sha1.digest()),l=l.getBytes();try{if(!e.session.clientCertificate.publicKey.verify(l,o.signature,'NONE'))throw new Error('CertificateVerify signature does not match.');e.session.md5.update(n),e.session.sha1.update(n)}catch(t){return e.error(e,{message:'Bad signature in CertificateVerify.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.handshake_failure}})}e.expect=O,e.process()},c.handleServerHelloDone=function(e,t,r){if(r>0)return e.error(e,{message:'Invalid ServerHelloDone message. Invalid length.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.record_overflow}});if(null===e.serverCertificate){var s={message:'No server certificate provided. Not enough security.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.insufficient_security}},n=e.verify(e,s.alert.description,0,[]);if(!0!==n)return(n||0===n)&&('object'!=typeof n||i.util.isArray(n)?'number'==typeof n&&(s.alert.description=n):(n.message&&(s.message=n.message),n.alert&&(s.alert.description=n.alert))),e.error(e,s)}null!==e.session.certificateRequest&&(t=c.createRecord(e,{type:c.ContentType.handshake,data:c.createCertificate(e)}),c.queue(e,t)),t=c.createRecord(e,{type:c.ContentType.handshake,data:c.createClientKeyExchange(e)}),c.queue(e,t),e.expect=E;var a=function(e,t){null!==e.session.certificateRequest&&null!==e.session.clientCertificate&&c.queue(e,c.createRecord(e,{type:c.ContentType.handshake,data:c.createCertificateVerify(e,t)})),c.queue(e,c.createRecord(e,{type:c.ContentType.change_cipher_spec,data:c.createChangeCipherSpec()})),e.state.pending=c.createConnectionState(e),e.state.current.write=e.state.pending.write,c.queue(e,c.createRecord(e,{type:c.ContentType.handshake,data:c.createFinished(e)})),e.expect=g,c.flush(e),e.process()};if(null===e.session.certificateRequest||null===e.session.clientCertificate)return a(e,null);c.getClientSignature(e,a)},c.handleChangeCipherSpec=function(e,t){if(1!==t.fragment.getByte())return e.error(e,{message:'Invalid ChangeCipherSpec message received.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}});var i=e.entity===c.ConnectionEnd.client;(e.session.resuming&&i||!e.session.resuming&&!i)&&(e.state.pending=c.createConnectionState(e)),e.state.current.read=e.state.pending.read,(!e.session.resuming&&i||e.session.resuming&&!i)&&(e.state.pending=null),e.expect=i?m:N,e.process()},c.handleFinished=function(e,t,s){var n=t.fragment;n.read-=4;var a=n.bytes();n.read+=4;var o=t.fragment.getBytes();(n=i.util.createBuffer()).putBuffer(e.session.md5.digest()),n.putBuffer(e.session.sha1.digest());var l=e.entity===c.ConnectionEnd.client,h=l?'server finished':'client finished',d=e.session.sp;if((n=r(d.master_secret,h,n.getBytes(),12)).getBytes()!==o)return e.error(e,{message:'Invalid verify_data in Finished message.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.decrypt_error}});e.session.md5.update(a),e.session.sha1.update(a),(e.session.resuming&&l||!e.session.resuming&&!l)&&(c.queue(e,c.createRecord(e,{type:c.ContentType.change_cipher_spec,data:c.createChangeCipherSpec()})),e.state.current.write=e.state.pending.write,e.state.pending=null,c.queue(e,c.createRecord(e,{type:c.ContentType.handshake,data:c.createFinished(e)}))),e.expect=l?y:P,e.handshaking=!1,++e.handshakes,e.peerCertificate=l?e.session.serverCertificate:e.session.clientCertificate,c.flush(e),e.isConnected=!0,e.connected(e),e.process()},c.handleAlert=function(e,t){var i,r=t.fragment,s={level:r.getByte(),description:r.getByte()};switch(s.description){case c.Alert.Description.close_notify:i='Connection closed.';break;case c.Alert.Description.unexpected_message:i='Unexpected message.';break;case c.Alert.Description.bad_record_mac:i='Bad record MAC.';break;case c.Alert.Description.decryption_failed:i='Decryption failed.';break;case c.Alert.Description.record_overflow:i='Record overflow.';break;case c.Alert.Description.decompression_failure:i='Decompression failed.';break;case c.Alert.Description.handshake_failure:i='Handshake failure.';break;case c.Alert.Description.bad_certificate:i='Bad certificate.';break;case c.Alert.Description.unsupported_certificate:i='Unsupported certificate.';break;case c.Alert.Description.certificate_revoked:i='Certificate revoked.';break;case c.Alert.Description.certificate_expired:i='Certificate expired.';break;case c.Alert.Description.certificate_unknown:i='Certificate unknown.';break;case c.Alert.Description.illegal_parameter:i='Illegal parameter.';break;case c.Alert.Description.unknown_ca:i='Unknown certificate authority.';break;case c.Alert.Description.access_denied:i='Access denied.';break;case c.Alert.Description.decode_error:i='Decode error.';break;case c.Alert.Description.decrypt_error:i='Decrypt error.';break;case c.Alert.Description.export_restriction:i='Export restriction.';break;case c.Alert.Description.protocol_version:i='Unsupported protocol version.';break;case c.Alert.Description.insufficient_security:i='Insufficient security.';break;case c.Alert.Description.internal_error:i='Internal error.';break;case c.Alert.Description.user_canceled:i='User canceled.';break;case c.Alert.Description.no_renegotiation:i='Renegotiation not supported.';break;default:i='Unknown error.'}if(s.description===c.Alert.Description.close_notify)return e.close();e.error(e,{message:i,send:!1,origin:e.entity===c.ConnectionEnd.client?'server':'client',alert:s}),e.process()},c.handleHandshake=function(e,t){var r=t.fragment,s=r.getByte(),n=r.getInt24();if(n>r.length())return e.fragmented=t,t.fragment=i.util.createBuffer(),r.read-=4,e.process();e.fragmented=null,r.read-=4;var a=r.bytes(n+4);r.read+=4,s in j[e.entity][e.expect]?(e.entity!==c.ConnectionEnd.server||e.open||e.fail||(e.handshaking=!0,e.session={version:null,extensions:{server_name:{serverNameList:[]}},cipherSuite:null,compressionMethod:null,serverCertificate:null,clientCertificate:null,md5:i.md.md5.create(),sha1:i.md.sha1.create()}),s!==c.HandshakeType.hello_request&&s!==c.HandshakeType.certificate_verify&&s!==c.HandshakeType.finished&&(e.session.md5.update(a),e.session.sha1.update(a)),j[e.entity][e.expect][s](e,t,n)):c.handleUnexpected(e,t)},c.handleApplicationData=function(e,t){e.data.putBuffer(t.fragment),e.dataReady(e),e.process()},c.handleHeartbeat=function(e,t){var r=t.fragment,s=r.getByte(),n=r.getInt16(),a=r.getBytes(n);if(s===c.HeartbeatMessageType.heartbeat_request){if(e.handshaking||n>a.length)return e.process();c.queue(e,c.createRecord(e,{type:c.ContentType.heartbeat,data:c.createHeartbeat(c.HeartbeatMessageType.heartbeat_response,a)})),c.flush(e)}else if(s===c.HeartbeatMessageType.heartbeat_response){if(a!==e.expectedHeartbeatPayload)return e.process();e.heartbeatReceived&&e.heartbeatReceived(e,i.util.createBuffer(a))}e.process()};var l=1,h=2,d=3,p=4,g=5,m=6,y=7,E=8,A=1,I=2,S=3,O=4,N=5,P=6,w=c.handleUnexpected,R=c.handleChangeCipherSpec,B=c.handleAlert,U=c.handleHandshake,D=c.handleApplicationData,k=c.handleHeartbeat,M=[];M[c.ConnectionEnd.client]=[[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[R,B,w,w,k],[w,B,U,w,k],[w,B,U,D,k],[w,B,U,w,k]],M[c.ConnectionEnd.server]=[[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[R,B,w,w,k],[w,B,U,w,k],[w,B,U,D,k],[w,B,U,w,k]];var x=c.handleHelloRequest,F=c.handleServerHello,H=c.handleCertificate,V=c.handleServerKeyExchange,W=c.handleCertificateRequest,K=c.handleServerHelloDone,z=c.handleFinished,j=[];j[c.ConnectionEnd.client]=[[w,w,F,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,H,V,W,K,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,V,W,K,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,W,K,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,K,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,z],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w]];var Y=c.handleClientHello,q=c.handleClientKeyExchange,Q=c.handleCertificateVerify;j[c.ConnectionEnd.server]=[[w,Y,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,H,w,w,w,w,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,q,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,Q,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,z],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w]],c.generateKeys=function(e,t){var i=r,s=t.client_random+t.server_random;e.session.resuming||(t.master_secret=i(t.pre_master_secret,'master secret',s,48).bytes(),t.pre_master_secret=null),s=t.server_random+t.client_random;var n=2*t.mac_key_length+2*t.enc_key_length,a=e.version.major===c.Versions.TLS_1_0.major&&e.version.minor===c.Versions.TLS_1_0.minor;a&&(n+=2*t.fixed_iv_length);var o=i(t.master_secret,'key expansion',s,n),l={client_write_MAC_key:o.getBytes(t.mac_key_length),server_write_MAC_key:o.getBytes(t.mac_key_length),client_write_key:o.getBytes(t.enc_key_length),server_write_key:o.getBytes(t.enc_key_length)};return a&&(l.client_write_IV=o.getBytes(t.fixed_iv_length),l.server_write_IV=o.getBytes(t.fixed_iv_length)),l},c.createConnectionState=function(e){var t=e.entity===c.ConnectionEnd.client,i=function(){var e={sequenceNumber:[0,0],macKey:null,macLength:0,macFunction:null,cipherState:null,cipherFunction:function(e){return!0},compressionState:null,compressFunction:function(e){return!0},updateSequenceNumber:function(){4294967295===e.sequenceNumber[1]?(e.sequenceNumber[1]=0,++e.sequenceNumber[0]):++e.sequenceNumber[1]}};return e},r={read:i(),write:i()};if(r.read.update=function(e,t){return r.read.cipherFunction(t,r.read)?r.read.compressFunction(e,t,r.read)||e.error(e,{message:'Could not decompress record.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.decompression_failure}}):e.error(e,{message:'Could not decrypt record or bad MAC.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.bad_record_mac}}),!e.fail},r.write.update=function(e,t){return r.write.compressFunction(e,t,r.write)?r.write.cipherFunction(t,r.write)||e.error(e,{message:'Could not encrypt record.',send:!1,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.internal_error}}):e.error(e,{message:'Could not compress record.',send:!1,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.internal_error}}),!e.fail},e.session){var a=e.session.sp;switch(e.session.cipherSuite.initSecurityParameters(a),a.keys=c.generateKeys(e,a),r.read.macKey=t?a.keys.server_write_MAC_key:a.keys.client_write_MAC_key,r.write.macKey=t?a.keys.client_write_MAC_key:a.keys.server_write_MAC_key,e.session.cipherSuite.initConnectionState(r,e,a),a.compression_algorithm){case c.CompressionMethod.none:break;case c.CompressionMethod.deflate:r.read.compressFunction=n,r.write.compressFunction=s;break;default:throw new Error('Unsupported compression algorithm.')}}return r},c.createRandom=function(){var e=new Date,t=+e+6e4*e.getTimezoneOffset(),r=i.util.createBuffer();return r.putInt32(t),r.putBytes(i.random.getBytes(28)),r},c.createRecord=function(e,t){return t.data?{type:t.type,version:{major:e.version.major,minor:e.version.minor},length:t.data.length(),fragment:t.data}:null},c.createAlert=function(e,t){var r=i.util.createBuffer();return r.putByte(t.level),r.putByte(t.description),c.createRecord(e,{type:c.ContentType.alert,data:r})},c.createClientHello=function(e){e.session.clientHelloVersion={major:e.version.major,minor:e.version.minor};for(var t=i.util.createBuffer(),r=0;r0&&(f+=2);var g=e.session.id,m=g.length+1+2+4+28+2+n+1+l+f,y=i.util.createBuffer();return y.putByte(c.HandshakeType.client_hello),y.putInt24(m),y.putByte(e.version.major),y.putByte(e.version.minor),y.putBytes(e.session.sp.client_random),o(y,1,i.util.createBuffer(g)),o(y,2,t),o(y,1,a),f>0&&o(y,2,h),y},c.createServerHello=function(e){var t=e.session.id,r=t.length+1+2+4+28+2+1,s=i.util.createBuffer();return s.putByte(c.HandshakeType.server_hello),s.putInt24(r),s.putByte(e.version.major),s.putByte(e.version.minor),s.putBytes(e.session.sp.server_random),o(s,1,i.util.createBuffer(t)),s.putByte(e.session.cipherSuite.id[0]),s.putByte(e.session.cipherSuite.id[1]),s.putByte(e.session.compressionMethod),s},c.createCertificate=function(e){var t,r=e.entity===c.ConnectionEnd.client,s=null;e.getCertificate&&(t=r?e.session.certificateRequest:e.session.extensions.server_name.serverNameList,s=e.getCertificate(e,t));var n=i.util.createBuffer();if(null!==s)try{i.util.isArray(s)||(s=[s]);for(var a=null,l=0;lc.MaxFragment;)s.push(c.createRecord(e,{type:t.type,data:i.util.createBuffer(n.slice(0,c.MaxFragment))})),n=n.slice(c.MaxFragment);n.length>0&&s.push(c.createRecord(e,{type:t.type,data:i.util.createBuffer(n)}))}for(var a=0;a0&&(s=r.order[0]),null!==s&&s in r.cache)for(var n in t=r.cache[s],delete r.cache[s],r.order)if(r.order[n]===s){r.order.splice(n,1);break}return t},r.setSession=function(e,t){if(r.order.length===r.capacity){var s=r.order.shift();delete r.cache[s]}s=i.util.bytesToHex(e);r.order.push(s),r.cache[s]=t}}return r},c.createConnection=function(e){var t=null;t=e.caStore?i.util.isArray(e.caStore)?i.pki.createCaStore(e.caStore):e.caStore:i.pki.createCaStore();var r=e.cipherSuites||null;if(null===r)for(var s in r=[],c.CipherSuites)r.push(c.CipherSuites[s]);var n=e.server?c.ConnectionEnd.server:c.ConnectionEnd.client,a=e.sessionCache?c.createSessionCache(e.sessionCache):null,o={version:{major:c.Version.major,minor:c.Version.minor},entity:n,sessionId:e.sessionId,caStore:t,sessionCache:a,cipherSuites:r,connected:e.connected,virtualHost:e.virtualHost||null,verifyClient:e.verifyClient||!1,verify:e.verify||function(e,t,i,r){return t},verifyOptions:e.verifyOptions||{},getCertificate:e.getCertificate||null,getPrivateKey:e.getPrivateKey||null,getSignature:e.getSignature||null,input:i.util.createBuffer(),tlsData:i.util.createBuffer(),data:i.util.createBuffer(),tlsDataReady:e.tlsDataReady,dataReady:e.dataReady,heartbeatReceived:e.heartbeatReceived,closed:e.closed,error:function(t,i){i.origin=i.origin||(t.entity===c.ConnectionEnd.client?'client':'server'),i.send&&(c.queue(t,c.createAlert(t,i.alert)),c.flush(t));var r=!1!==i.fatal;r&&(t.fail=!0),e.error(t,i),r&&t.close(!1)},deflate:e.deflate||null,inflate:e.inflate||null,reset:function(e){o.version={major:c.Version.major,minor:c.Version.minor},o.record=null,o.session=null,o.peerCertificate=null,o.state={pending:null,current:null},o.expect=(o.entity,c.ConnectionEnd.client,0),o.fragmented=null,o.records=[],o.open=!1,o.handshakes=0,o.handshaking=!1,o.isConnected=!1,o.fail=!(e||void 0===e),o.input.clear(),o.tlsData.clear(),o.data.clear(),o.state.current=c.createConnectionState(o)}};o.reset();return o.handshake=function(e){if(o.entity!==c.ConnectionEnd.client)o.error(o,{message:'Cannot initiate handshake as a server.',fatal:!1});else if(o.handshaking)o.error(o,{message:'Handshake already in progress.',fatal:!1});else{o.fail&&!o.open&&0===o.handshakes&&(o.fail=!1),o.handshaking=!0;var t=null;(e=e||'').length>0&&(o.sessionCache&&(t=o.sessionCache.getSession(e)),null===t&&(e='')),0===e.length&&o.sessionCache&&null!==(t=o.sessionCache.getSession())&&(e=t.id),o.session={id:e,version:null,cipherSuite:null,compressionMethod:null,serverCertificate:null,certificateRequest:null,clientCertificate:null,sp:{},md5:i.md.md5.create(),sha1:i.md.sha1.create()},t&&(o.version=t.version,o.session.sp=t.sp),o.session.sp.client_random=c.createRandom().getBytes(),o.open=!0,c.queue(o,c.createRecord(o,{type:c.ContentType.handshake,data:c.createClientHello(o)})),c.flush(o)}},o.process=function(e){var t,r,s,n,a=0;return e&&o.input.putBytes(e),o.fail||(null!==o.record&&o.record.ready&&o.record.fragment.isEmpty()&&(o.record=null),null===o.record&&(a=function(e){var t=0,r=e.input,s=r.length();if(s<5)t=5-s;else{e.record={type:r.getByte(),version:{major:r.getByte(),minor:r.getByte()},length:r.getInt16(),fragment:i.util.createBuffer(),ready:!1};var n=e.record.version.major===e.version.major;n&&e.session&&e.session.version&&(n=e.record.version.minor===e.version.minor),n||e.error(e,{message:'Incompatible TLS version.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.protocol_version}})}return t}(o)),o.fail||null===o.record||o.record.ready||(a=function(e){var t=0,i=e.input,r=i.length();return r=r.Versions.TLS_1_1.minor&&c.output.putBytes(s),c.update(e.fragment),c.finish(a)&&(e.fragment=c.output,e.length=e.fragment.length(),n=!0),n}function a(e,t,i){if(!i){var r=e-t.length()%e;t.fillWithByte(r-1,r)}return!0}function o(e,t,i){var r=!0;if(i){for(var s=t.length(),n=t.last(),a=s-1-n;a=c?(e.fragment=a.output.getBytes(h-c),l=a.output.getBytes(c)):e.fragment=a.output.getBytes(),e.fragment=i.util.createBuffer(e.fragment),e.length=e.fragment.length();var d=t.macFunction(t.macKey,t.sequenceNumber,e);return t.updateSequenceNumber(),n=function(e,t,r){var s=i.hmac.create();return s.start('SHA1',e),s.update(t),t=s.digest().getBytes(),s.start(null,null),s.update(r),r=s.digest().getBytes(),t===r}(t.macKey,l,d)&&n,n}r.CipherSuites.TLS_RSA_WITH_AES_128_CBC_SHA={id:[0,47],name:'TLS_RSA_WITH_AES_128_CBC_SHA',initSecurityParameters:function(e){e.bulk_cipher_algorithm=r.BulkCipherAlgorithm.aes,e.cipher_type=r.CipherType.block,e.enc_key_length=16,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=r.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:s},r.CipherSuites.TLS_RSA_WITH_AES_256_CBC_SHA={id:[0,53],name:'TLS_RSA_WITH_AES_256_CBC_SHA',initSecurityParameters:function(e){e.bulk_cipher_algorithm=r.BulkCipherAlgorithm.aes,e.cipher_type=r.CipherType.block,e.enc_key_length=32,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=r.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:s}}}),z=d({'node_modules/node-forge/lib/sha512.js'(e,t){var i=u();A(),f();var r=t.exports=i.sha512=i.sha512||{};i.md.sha512=i.md.algorithms.sha512=r;var s=i.sha384=i.sha512.sha384=i.sha512.sha384||{};s.create=function(){return r.create('SHA-384')},i.md.sha384=i.md.algorithms.sha384=s,i.sha512.sha256=i.sha512.sha256||{create:function(){return r.create('SHA-512/256')}},i.md['sha512/256']=i.md.algorithms['sha512/256']=i.sha512.sha256,i.sha512.sha224=i.sha512.sha224||{create:function(){return r.create('SHA-512/224')}},i.md['sha512/224']=i.md.algorithms['sha512/224']=i.sha512.sha224,r.create=function(e){if(a||(n=String.fromCharCode(128),n+=i.util.fillString(String.fromCharCode(0),128),o=[[1116352408,3609767458],[1899447441,602891725],[3049323471,3964484399],[3921009573,2173295548],[961987163,4081628472],[1508970993,3053834265],[2453635748,2937671579],[2870763221,3664609560],[3624381080,2734883394],[310598401,1164996542],[607225278,1323610764],[1426881987,3590304994],[1925078388,4068182383],[2162078206,991336113],[2614888103,633803317],[3248222580,3479774868],[3835390401,2666613458],[4022224774,944711139],[264347078,2341262773],[604807628,2007800933],[770255983,1495990901],[1249150122,1856431235],[1555081692,3175218132],[1996064986,2198950837],[2554220882,3999719339],[2821834349,766784016],[2952996808,2566594879],[3210313671,3203337956],[3336571891,1034457026],[3584528711,2466948901],[113926993,3758326383],[338241895,168717936],[666307205,1188179964],[773529912,1546045734],[1294757372,1522805485],[1396182291,2643833823],[1695183700,2343527390],[1986661051,1014477480],[2177026350,1206759142],[2456956037,344077627],[2730485921,1290863460],[2820302411,3158454273],[3259730800,3505952657],[3345764771,106217008],[3516065817,3606008344],[3600352804,1432725776],[4094571909,1467031594],[275423344,851169720],[430227734,3100823752],[506948616,1363258195],[659060556,3750685593],[883997877,3785050280],[958139571,3318307427],[1322822218,3812723403],[1537002063,2003034995],[1747873779,3602036899],[1955562222,1575990012],[2024104815,1125592928],[2227730452,2716904306],[2361852424,442776044],[2428436474,593698344],[2756734187,3733110249],[3204031479,2999351573],[3329325298,3815920427],[3391569614,3928383900],[3515267271,566280711],[3940187606,3454069534],[4118630271,4000239992],[116418474,1914138554],[174292421,2731055270],[289380356,3203993006],[460393269,320620315],[685471733,587496836],[852142971,1086792851],[1017036298,365543100],[1126000580,2618297676],[1288033470,3409855158],[1501505948,4234509866],[1607167915,987167468],[1816402316,1246189591]],(c={})['SHA-512']=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]],c['SHA-384']=[[3418070365,3238371032],[1654270250,914150663],[2438529370,812702999],[355462360,4144912697],[1731405415,4290775857],[2394180231,1750603025],[3675008525,1694076839],[1203062813,3204075428]],c['SHA-512/256']=[[573645204,4230739756],[2673172387,3360449730],[596883563,1867755857],[2520282905,1497426621],[2519219938,2827943907],[3193839141,1401305490],[721525244,746961066],[246885852,2177182882]],c['SHA-512/224']=[[2352822216,424955298],[1944164710,2312950998],[502970286,855612546],[1738396948,1479516111],[258812777,2077511080],[2011393907,79989058],[1067287976,1780299464],[286451373,2446758561]],a=!0),void 0===e&&(e='SHA-512'),!(e in c))throw new Error('Invalid SHA-512 algorithm: '+e);for(var t=c[e],r=null,s=i.util.createBuffer(),h=new Array(80),d=0;d<80;++d)h[d]=new Array(2);var u=64;switch(e){case'SHA-384':u=48;break;case'SHA-512/256':u=32;break;case'SHA-512/224':u=28}var p={algorithm:e.replace('-','').toLowerCase(),blockLength:128,digestLength:u,messageLength:0,fullMessageLength:null,messageLengthSize:16,start:function(){p.messageLength=0,p.fullMessageLength=p.messageLength128=[];for(var e=p.messageLengthSize/4,n=0;n>>0,n>>>0];for(var a=p.fullMessageLength.length-1;a>=0;--a)p.fullMessageLength[a]+=n[1],n[1]=n[0]+(p.fullMessageLength[a]/4294967296>>>0),p.fullMessageLength[a]=p.fullMessageLength[a]>>>0,n[0]=n[1]/4294967296>>>0;return s.putBytes(e),l(r,h,s),(s.read>2048||0===s.length())&&s.compact(),p},p.digest=function(){var t=i.util.createBuffer();t.putBytes(s.bytes());var a,o=p.fullMessageLength[p.fullMessageLength.length-1]+p.messageLengthSize&p.blockLength-1;t.putBytes(n.substr(0,p.blockLength-o));for(var c=8*p.fullMessageLength[0],d=0;d>>0,t.putInt32(c>>>0),c=a>>>0;t.putInt32(c);var u=new Array(r.length);for(d=0;d=128;){for(w=0;w<16;++w)t[w][0]=i.getInt32()>>>0,t[w][1]=i.getInt32()>>>0;for(;w<80;++w)r=(((b=(B=t[w-2])[0])>>>19|(R=B[1])<<13)^(R>>>29|b<<3)^b>>>6)>>>0,s=((b<<13|R>>>19)^(R<<3|b>>>29)^(b<<26|R>>>6))>>>0,n=(((b=(D=t[w-15])[0])>>>1|(R=D[1])<<31)^(b>>>8|R<<24)^b>>>7)>>>0,a=((b<<31|R>>>1)^(b<<24|R>>>8)^(b<<25|R>>>7))>>>0,U=t[w-7],k=t[w-16],R=s+U[1]+a+k[1],t[w][0]=r+U[0]+n+k[0]+(R/4294967296>>>0)>>>0,t[w][1]=R>>>0;for(f=e[0][0],g=e[0][1],m=e[1][0],y=e[1][1],E=e[2][0],_=e[2][1],A=e[3][0],v=e[3][1],T=e[4][0],C=e[4][1],I=e[5][0],S=e[5][1],O=e[6][0],N=e[6][1],L=e[7][0],P=e[7][1],w=0;w<80;++w)h=((T>>>14|C<<18)^(T>>>18|C<<14)^(C>>>9|T<<23))>>>0,d=(O^T&(I^O))>>>0,c=((f>>>28|g<<4)^(g>>>2|f<<30)^(g>>>7|f<<25))>>>0,l=((f<<4|g>>>28)^(g<<30|f>>>2)^(g<<25|f>>>7))>>>0,u=(f&m|E&(f^m))>>>0,p=(g&y|_&(g^y))>>>0,R=P+(((T<<18|C>>>14)^(T<<14|C>>>18)^(C<<23|T>>>9))>>>0)+((N^C&(S^N))>>>0)+o[w][1]+t[w][1],r=L+h+d+o[w][0]+t[w][0]+(R/4294967296>>>0)>>>0,s=R>>>0,n=c+u+((R=l+p)/4294967296>>>0)>>>0,a=R>>>0,L=O,P=N,O=I,N=S,I=T,S=C,T=A+r+((R=v+s)/4294967296>>>0)>>>0,C=R>>>0,A=E,v=_,E=m,_=y,m=f,y=g,f=r+n+((R=s+a)/4294967296>>>0)>>>0,g=R>>>0;R=e[0][1]+g,e[0][0]=e[0][0]+f+(R/4294967296>>>0)>>>0,e[0][1]=R>>>0,R=e[1][1]+y,e[1][0]=e[1][0]+m+(R/4294967296>>>0)>>>0,e[1][1]=R>>>0,R=e[2][1]+_,e[2][0]=e[2][0]+E+(R/4294967296>>>0)>>>0,e[2][1]=R>>>0,R=e[3][1]+v,e[3][0]=e[3][0]+A+(R/4294967296>>>0)>>>0,e[3][1]=R>>>0,R=e[4][1]+C,e[4][0]=e[4][0]+T+(R/4294967296>>>0)>>>0,e[4][1]=R>>>0,R=e[5][1]+S,e[5][0]=e[5][0]+I+(R/4294967296>>>0)>>>0,e[5][1]=R>>>0,R=e[6][1]+N,e[6][0]=e[6][0]+O+(R/4294967296>>>0)>>>0,e[6][1]=R>>>0,R=e[7][1]+P,e[7][0]=e[7][0]+L+(R/4294967296>>>0)>>>0,e[7][1]=R>>>0,M-=128}}}}),j=d({'node_modules/node-forge/lib/asn1-validator.js'(e){var t=u();_();var i=t.asn1;e.privateKeyValidator={name:'PrivateKeyInfo',tagClass:i.Class.UNIVERSAL,type:i.Type.SEQUENCE,constructed:!0,value:[{name:'PrivateKeyInfo.version',tagClass:i.Class.UNIVERSAL,type:i.Type.INTEGER,constructed:!1,capture:'privateKeyVersion'},{name:'PrivateKeyInfo.privateKeyAlgorithm',tagClass:i.Class.UNIVERSAL,type:i.Type.SEQUENCE,constructed:!0,value:[{name:'AlgorithmIdentifier.algorithm',tagClass:i.Class.UNIVERSAL,type:i.Type.OID,constructed:!1,capture:'privateKeyOid'}]},{name:'PrivateKeyInfo',tagClass:i.Class.UNIVERSAL,type:i.Type.OCTETSTRING,constructed:!1,capture:'privateKey'}]},e.publicKeyValidator={name:'SubjectPublicKeyInfo',tagClass:i.Class.UNIVERSAL,type:i.Type.SEQUENCE,constructed:!0,captureAsn1:'subjectPublicKeyInfo',value:[{name:'SubjectPublicKeyInfo.AlgorithmIdentifier',tagClass:i.Class.UNIVERSAL,type:i.Type.SEQUENCE,constructed:!0,value:[{name:'AlgorithmIdentifier.algorithm',tagClass:i.Class.UNIVERSAL,type:i.Type.OID,constructed:!1,capture:'publicKeyOid'}]},{tagClass:i.Class.UNIVERSAL,type:i.Type.BITSTRING,constructed:!1,composed:!0,captureBitStringValue:'ed25519PublicKey'}]}}}),Y=d({'node_modules/node-forge/lib/ed25519.js'(e,t){var i=u();w(),L(),z(),f();var r,s=j(),n=s.publicKeyValidator,a=s.privateKeyValidator;void 0===r&&(r=i.jsbn.BigInteger);var o=i.util.ByteBuffer,c='undefined'==typeof Buffer?Uint8Array:Buffer;i.pki=i.pki||{},t.exports=i.pki.ed25519=i.ed25519=i.ed25519||{};var l=i.ed25519;function h(e){var t=e.message;if(t instanceof Uint8Array||t instanceof c)return t;var i=e.encoding;if(void 0===t){if(!e.md)throw new TypeError('"options.message" or "options.md" not specified.');t=e.md.digest().getBytes(),i='binary'}if('string'==typeof t&&!i)throw new TypeError('"options.encoding" must be "binary" or "utf8".');if('string'==typeof t){if('undefined'!=typeof Buffer)return Buffer.from(t,i);t=new o(t,i)}else if(!(t instanceof o))throw new TypeError('"options.message" must be a node.js Buffer, a Uint8Array, a forge ByteBuffer, or a string with "options.encoding" specifying its encoding.');for(var r=new c(t.length()),s=0;s=0;--i)V(r,r),1!==i&&G(r,r,t);for(i=0;i<16;++i)e[i]=r[i]}(i,i),G(i,i,s),G(i,i,n),G(i,i,n),G(e[0],i,n),V(r,e[0]),G(r,r,n),P(r,s)&&G(e[0],e[0],A);if(V(r,e[0]),G(r,r,n),P(r,s))return-1;R(e[0])===t[31]>>7&&H(e[0],d,e[0]);return G(e[3],e[0],e[1]),0}(o,r))return-1;for(s=0;s=0};var d=x(),p=x([1]),g=x([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),m=x([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),y=x([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),E=x([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),_=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]),A=x([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function v(e,t){var r=i.md.sha512.create(),s=new o(e);r.update(s.getBytes(t),'binary');var n=r.digest().getBytes();if('undefined'!=typeof Buffer)return Buffer.from(n,'binary');for(var a=new c(l.constants.HASH_BYTE_LENGTH),h=0;h<64;++h)a[h]=n.charCodeAt(h);return a}function T(e,t){var i,r,s,n;for(r=63;r>=32;--r){for(i=0,s=r-32,n=r-12;s>8,t[s]-=256*i;t[s]+=i,t[r]=0}for(i=0,s=0;s<32;++s)t[s]+=i-(t[31]>>4)*_[s],i=t[s]>>8,t[s]&=255;for(s=0;s<32;++s)t[s]-=i*_[s];for(r=0;r<32;++r)t[r+1]+=t[r]>>8,e[r]=255&t[r]}function C(e){for(var t=new Float64Array(64),i=0;i<64;++i)t[i]=e[i],e[i]=0;T(e,t)}function I(e,t){var i=x(),r=x(),s=x(),n=x(),a=x(),o=x(),c=x(),l=x(),h=x();H(i,e[1],e[0]),H(h,t[1],t[0]),G(i,i,h),F(r,e[0],e[1]),F(h,t[0],t[1]),G(r,r,h),G(s,e[3],t[3]),G(s,s,m),G(n,e[2],t[2]),F(n,n,n),H(a,r,i),H(o,n,s),F(c,n,s),F(l,r,i),G(e[0],a,o),G(e[1],l,c),G(e[2],c,o),G(e[3],a,l)}function S(e,t,i){for(var r=0;r<4;++r)M(e[r],t[r],i)}function O(e,t){var i=x(),r=x(),s=x();!function(e,t){var i,r=x();for(i=0;i<16;++i)r[i]=t[i];for(i=253;i>=0;--i)V(r,r),2!==i&&4!==i&&G(r,r,t);for(i=0;i<16;++i)e[i]=r[i]}(s,t[2]),G(i,t[0],s),G(r,t[1],s),N(e,r),e[31]^=R(i)<<7}function N(e,t){var i,r,s,n=x(),a=x();for(i=0;i<16;++i)a[i]=t[i];for(k(a),k(a),k(a),r=0;r<2;++r){for(n[0]=a[0]-65517,i=1;i<15;++i)n[i]=a[i]-65535-(n[i-1]>>16&1),n[i-1]&=65535;n[15]=a[15]-32767-(n[14]>>16&1),s=n[15]>>16&1,n[14]&=65535,M(a,n,1-s)}for(i=0;i<16;i++)e[2*i]=255&a[i],e[2*i+1]=a[i]>>8}function P(e,t){var i=new c(32),r=new c(32);return N(i,e),N(r,t),b(i,0,r,0)}function b(e,t,i,r){return function(e,t,i,r,s){var n,a=0;for(n=0;n>>8)-1}(e,t,i,r,32)}function R(e){var t=new c(32);return N(t,e),1&t[0]}function B(e,t,i){var r,s;for(D(e[0],d),D(e[1],p),D(e[2],p),D(e[3],d),s=255;s>=0;--s)S(e,t,r=i[s/8|0]>>(7&s)&1),I(t,e),I(e,e),S(e,t,r)}function U(e,t){var i=[x(),x(),x(),x()];D(i[0],y),D(i[1],E),D(i[2],p),G(i[3],y,E),B(e,i,t)}function D(e,t){var i;for(i=0;i<16;i++)e[i]=0|t[i]}function k(e){var t,i,r=1;for(t=0;t<16;++t)i=e[t]+r+65535,r=Math.floor(i/65536),e[t]=i-65536*r;e[0]+=r-1+37*(r-1)}function M(e,t,i){for(var r,s=~(i-1),n=0;n<16;++n)r=s&(e[n]^t[n]),e[n]^=r,t[n]^=r}function x(e){var t,i=new Float64Array(16);if(e)for(t=0;t0&&(a=i.util.fillString(String.fromCharCode(0),c)+a),{encapsulation:t.encrypt(a,'NONE'),key:e.generate(a,n)}},decrypt:function(t,i,r){var s=t.decrypt(i,'NONE');return e.generate(s,r)}};return n},i.kem.kdf1=function(e,t){s(this,e,0,t||e.digestLength)},i.kem.kdf2=function(e,t){s(this,e,1,t||e.digestLength)}}}),Q=d({'node_modules/node-forge/lib/log.js'(e,t){var i=u();f(),t.exports=i.log=i.log||{},i.log.levels=['none','error','warning','info','debug','verbose','max'];var r,s,n,a,o,c,l,h={},d=[],p=null;for(i.log.LEVEL_LOCKED=2,i.log.NO_LEVEL_CHECK=4,i.log.INTERPOLATE=8,n=0;n0){for(var s=r.create(r.Class.CONTEXT_SPECIFIC,1,!0,[]),n=0;n=s&&a0&&a.value[0].value.push(r.create(r.Class.CONTEXT_SPECIFIC,0,!0,t)),n.length>0&&a.value[0].value.push(r.create(r.Class.CONTEXT_SPECIFIC,1,!0,n)),a.value[0].value.push(r.create(r.Class.UNIVERSAL,r.Type.SET,!0,e.signerInfos)),r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(e.type).getBytes()),a])},addSigner:function(t){var r=t.issuer,s=t.serialNumber;if(t.certificate){var n=t.certificate;'string'==typeof n&&(n=i.pki.certificateFromPem(n)),r=n.issuer.attributes,s=n.serialNumber}var a=t.key;if(!a)throw new Error('Could not add PKCS#7 signer; no private key specified.');'string'==typeof a&&(a=i.pki.privateKeyFromPem(a));var o=t.digestAlgorithm||i.pki.oids.sha1;switch(o){case i.pki.oids.sha1:case i.pki.oids.sha256:case i.pki.oids.sha384:case i.pki.oids.sha512:case i.pki.oids.md5:break;default:throw new Error('Could not add PKCS#7 signer; unknown message digest algorithm: '+o)}var c=t.authenticatedAttributes||[];if(c.length>0){for(var l=!1,h=!1,d=0;d='8'&&(r='00'+r);var s=i.util.hexToBytes(r);e.putInt32(s.length),e.putBytes(s)}function n(e,t){e.putInt32(t.length),e.putString(t)}function a(){for(var e=i.md.sha1.create(),t=arguments.length,r=0;r{for(var i in t)n(e,i,{get:t[i],enumerable:!0})})(ee,{jingles:()=>i,maps:()=>e,serverMaps:()=>r,songs:()=>t});var te,ie,re,se,ne,ae,oe=(te={'src/lostcity/server/PreloadedDirs.ts'(){e=['l29_75','l30_75','l31_75','l32_70','l32_71','l32_72','l32_73','l32_74','l32_75','l33_70','l33_71','l33_72','l33_73','l33_74','l33_75','l33_76','l34_70','l34_71','l34_72','l34_73','l34_74','l34_75','l34_76','l35_20','l35_75','l35_76','l36_146','l36_147','l36_148','l36_149','l36_150','l36_153','l36_154','l36_52','l36_53','l36_54','l36_72','l36_73','l36_74','l36_75','l36_76','l37_146','l37_147','l37_148','l37_149','l37_150','l37_151','l37_152','l37_153','l37_154','l37_48','l37_49','l37_50','l37_51','l37_52','l37_53','l37_54','l37_55','l37_72','l37_73','l37_74','l37_75','l38_146','l38_147','l38_148','l38_149','l38_150','l38_151','l38_152','l38_153','l38_154','l38_155','l38_45','l38_46','l38_47','l38_48','l38_49','l38_50','l38_51','l38_52','l38_53','l38_54','l38_55','l38_72','l38_73','l38_74','l39_147','l39_148','l39_149','l39_150','l39_151','l39_152','l39_153','l39_154','l39_155','l39_45','l39_46','l39_47','l39_48','l39_49','l39_50','l39_51','l39_52','l39_53','l39_54','l39_55','l39_72','l39_73','l39_74','l39_75','l39_76','l40_147','l40_148','l40_149','l40_150','l40_151','l40_152','l40_153','l40_154','l40_45','l40_46','l40_47','l40_48','l40_49','l40_50','l40_51','l40_52','l40_53','l40_54','l40_55','l40_72','l40_73','l40_74','l40_75','l40_76','l41_146','l41_149','l41_151','l41_152','l41_153','l41_154','l41_45','l41_46','l41_47','l41_48','l41_49','l41_50','l41_51','l41_52','l41_53','l41_54','l41_55','l41_56','l41_72','l41_73','l41_74','l41_75','l42_144','l42_145','l42_146','l42_151','l42_152','l42_153','l42_49','l42_50','l42_51','l42_52','l42_53','l42_54','l42_55','l42_56','l42_72','l42_73','l42_74','l42_75','l43_144','l43_145','l43_146','l43_153','l43_154','l43_45','l43_46','l43_47','l43_48','l43_49','l43_50','l43_51','l43_52','l43_53','l43_54','l43_55','l43_56','l43_72','l43_73','l43_74','l43_75','l44_144','l44_145','l44_146','l44_148','l44_149','l44_150','l44_151','l44_152','l44_153','l44_154','l44_155','l44_45','l44_46','l44_47','l44_48','l44_49','l44_50','l44_51','l44_52','l44_53','l44_54','l44_55','l44_72','l44_73','l44_74','l44_75','l45_145','l45_146','l45_148','l45_150','l45_151','l45_152','l45_153','l45_154','l45_155','l45_45','l45_46','l45_47','l45_48','l45_49','l45_50','l45_51','l45_52','l45_53','l45_54','l45_55','l45_56','l45_57','l45_58','l45_59','l45_60','l45_61','l45_62','l45_73','l45_74','l45_75','l45_76','l46_149','l46_150','l46_152','l46_153','l46_154','l46_161','l46_45','l46_46','l46_47','l46_48','l46_49','l46_50','l46_51','l46_52','l46_53','l46_54','l46_55','l46_56','l46_57','l46_58','l46_59','l46_60','l46_61','l46_62','l46_75','l47_148','l47_149','l47_150','l47_152','l47_153','l47_160','l47_161','l47_47','l47_48','l47_49','l47_50','l47_51','l47_52','l47_53','l47_54','l47_55','l47_56','l47_57','l47_58','l47_59','l47_60','l47_61','l47_62','l47_75','l48_148','l48_149','l48_152','l48_153','l48_154','l48_155','l48_156','l48_47','l48_48','l48_49','l48_50','l48_51','l48_52','l48_53','l48_54','l48_55','l48_56','l48_57','l48_58','l48_59','l48_60','l48_61','l48_62','l49_148','l49_149','l49_153','l49_154','l49_155','l49_156','l49_46','l49_47','l49_48','l49_49','l49_50','l49_51','l49_52','l49_53','l49_54','l49_55','l49_56','l49_57','l49_58','l49_59','l49_60','l49_61','l49_62','l50_149','l50_150','l50_152','l50_153','l50_154','l50_46','l50_47','l50_48','l50_49','l50_50','l50_51','l50_52','l50_53','l50_54','l50_55','l50_56','l50_57','l50_58','l50_59','l50_60','l50_61','l50_62','l51_147','l51_154','l51_46','l51_47','l51_48','l51_49','l51_50','l51_51','l51_52','l51_53','l51_54','l51_55','l51_56','l51_57','l51_58','l51_59','l51_60','l51_61','l51_62','l52_152','l52_153','l52_154','l52_46','l52_47','l52_48','l52_49','l52_50','l52_51','l52_52','l52_53','l52_54','l52_55','l52_56','l52_57','l52_58','l52_59','l52_60','l52_61','l52_62','l53_49','l53_50','l53_51','l53_52','l53_53','m29_75','m30_75','m31_75','m32_70','m32_71','m32_72','m32_73','m32_74','m32_75','m33_70','m33_71','m33_72','m33_73','m33_74','m33_75','m33_76','m34_70','m34_71','m34_72','m34_73','m34_74','m34_75','m34_76','m35_20','m35_75','m35_76','m36_146','m36_147','m36_148','m36_149','m36_150','m36_153','m36_154','m36_52','m36_53','m36_54','m36_72','m36_73','m36_74','m36_75','m36_76','m37_146','m37_147','m37_148','m37_149','m37_150','m37_151','m37_152','m37_153','m37_154','m37_48','m37_49','m37_50','m37_51','m37_52','m37_53','m37_54','m37_55','m37_72','m37_73','m37_74','m37_75','m38_146','m38_147','m38_148','m38_149','m38_150','m38_151','m38_152','m38_153','m38_154','m38_155','m38_45','m38_46','m38_47','m38_48','m38_49','m38_50','m38_51','m38_52','m38_53','m38_54','m38_55','m38_72','m38_73','m38_74','m39_147','m39_148','m39_149','m39_150','m39_151','m39_152','m39_153','m39_154','m39_155','m39_45','m39_46','m39_47','m39_48','m39_49','m39_50','m39_51','m39_52','m39_53','m39_54','m39_55','m39_72','m39_73','m39_74','m39_75','m39_76','m40_147','m40_148','m40_149','m40_150','m40_151','m40_152','m40_153','m40_154','m40_45','m40_46','m40_47','m40_48','m40_49','m40_50','m40_51','m40_52','m40_53','m40_54','m40_55','m40_72','m40_73','m40_74','m40_75','m40_76','m41_146','m41_149','m41_151','m41_152','m41_153','m41_154','m41_45','m41_46','m41_47','m41_48','m41_49','m41_50','m41_51','m41_52','m41_53','m41_54','m41_55','m41_56','m41_72','m41_73','m41_74','m41_75','m42_144','m42_145','m42_146','m42_151','m42_152','m42_153','m42_49','m42_50','m42_51','m42_52','m42_53','m42_54','m42_55','m42_56','m42_72','m42_73','m42_74','m42_75','m43_144','m43_145','m43_146','m43_153','m43_154','m43_45','m43_46','m43_47','m43_48','m43_49','m43_50','m43_51','m43_52','m43_53','m43_54','m43_55','m43_56','m43_72','m43_73','m43_74','m43_75','m44_144','m44_145','m44_146','m44_148','m44_149','m44_150','m44_151','m44_152','m44_153','m44_154','m44_155','m44_45','m44_46','m44_47','m44_48','m44_49','m44_50','m44_51','m44_52','m44_53','m44_54','m44_55','m44_72','m44_73','m44_74','m44_75','m45_145','m45_146','m45_148','m45_150','m45_151','m45_152','m45_153','m45_154','m45_155','m45_45','m45_46','m45_47','m45_48','m45_49','m45_50','m45_51','m45_52','m45_53','m45_54','m45_55','m45_56','m45_57','m45_58','m45_59','m45_60','m45_61','m45_62','m45_73','m45_74','m45_75','m45_76','m46_149','m46_150','m46_152','m46_153','m46_154','m46_161','m46_45','m46_46','m46_47','m46_48','m46_49','m46_50','m46_51','m46_52','m46_53','m46_54','m46_55','m46_56','m46_57','m46_58','m46_59','m46_60','m46_61','m46_62','m46_75','m47_148','m47_149','m47_150','m47_152','m47_153','m47_160','m47_161','m47_47','m47_48','m47_49','m47_50','m47_51','m47_52','m47_53','m47_54','m47_55','m47_56','m47_57','m47_58','m47_59','m47_60','m47_61','m47_62','m47_75','m48_148','m48_149','m48_152','m48_153','m48_154','m48_155','m48_156','m48_47','m48_48','m48_49','m48_50','m48_51','m48_52','m48_53','m48_54','m48_55','m48_56','m48_57','m48_58','m48_59','m48_60','m48_61','m48_62','m49_148','m49_149','m49_153','m49_154','m49_155','m49_156','m49_46','m49_47','m49_48','m49_49','m49_50','m49_51','m49_52','m49_53','m49_54','m49_55','m49_56','m49_57','m49_58','m49_59','m49_60','m49_61','m49_62','m50_149','m50_150','m50_152','m50_153','m50_154','m50_46','m50_47','m50_48','m50_49','m50_50','m50_51','m50_52','m50_53','m50_54','m50_55','m50_56','m50_57','m50_58','m50_59','m50_60','m50_61','m50_62','m51_147','m51_154','m51_46','m51_47','m51_48','m51_49','m51_50','m51_51','m51_52','m51_53','m51_54','m51_55','m51_56','m51_57','m51_58','m51_59','m51_60','m51_61','m51_62','m52_152','m52_153','m52_154','m52_46','m52_47','m52_48','m52_49','m52_50','m52_51','m52_52','m52_53','m52_54','m52_55','m52_56','m52_57','m52_58','m52_59','m52_60','m52_61','m52_62','m53_49','m53_50','m53_51','m53_52','m53_53'],t=['adventure.mid','al_kharid.mid','alone.mid','ambience_2.mid','ambience_3.mid','ambience_4.mid','ambient_jungle.mid','arabian.mid','arabian2.mid','arabian3.mid','arabique.mid','army_of_darkness.mid','arrival.mid','attack1.mid','attack2.mid','attack3.mid','attack4.mid','attack5.mid','attack6.mid','attention.mid','autumn_voyage.mid','background2.mid','ballad_of_enchantment.mid','baroque.mid','beyond.mid','big_chords.mid','book_of_spells.mid','camelot.mid','cave_background1.mid','cavern.mid','cellar_song1.mid','chain_of_command.mid','chompy_hunt.mid','close_quarters.mid','crystal_cave.mid','crystal_sword.mid','cursed.mid','dangerous.mid','dark2.mid','deep_wildy.mid','desert_voyage.mid','doorways.mid','dream1.mid','duel_arena.mid','dunjun.mid','egypt.mid','emotion.mid','emperor.mid','escape.mid','expanse.mid','expecting.mid','expedition.mid','fade_test.mid','faerie.mid','fanfare.mid','fanfare2.mid','fanfare3.mid','fishing.mid','flute_salad.mid','forbidden.mid','forever.mid','game_intro_1.mid','gaol.mid','garden.mid','gnome.mid','gnome_king.mid','gnome_theme.mid','gnome_village.mid','gnome_village2.mid','gnomeball.mid','greatness.mid','grumpy.mid','harmony.mid','harmony2.mid','heart_and_mind.mid','high_seas.mid','horizon.mid','iban.mid','ice_melody.mid','in_the_manor.mid','inspiration.mid','intrepid.mid','jolly-r.mid','jungle_island.mid','jungly1.mid','jungly2.mid','jungly3.mid','knightly.mid','landlubber.mid','lasting.mid','legion.mid','lightness.mid','lightwalk.mid','lonesome.mid','long_ago.mid','long_way_home.mid','lullaby.mid','mage_arena.mid','magic_dance.mid','magical_journey.mid','march2.mid','medieval.mid','mellow.mid','miles_away.mid','miracle_dance.mid','monarch_waltz.mid','moody.mid','neverland.mid','newbie_melody.mid','nightfall.mid','nomad.mid','null.mid','organ_music_1.mid','organ_music_2.mid','oriental.mid','overture.mid','parade.mid','quest.mid','regal2.mid','reggae.mid','reggae2.mid','riverside.mid','royale.mid','rune_essence.mid','sad_meadow.mid','scape_cave.mid','scape_main.mid','scape_sad1.mid','scape_soft.mid','scape_wild1.mid','sea_shanty.mid','sea_shanty2.mid','serenade.mid','serene.mid','shine.mid','shining.mid','silence.mid','soundscape.mid','spirit.mid','splendour.mid','spooky2.mid','spooky_jungle.mid','starlight.mid','start.mid','still_night.mid','talking_forest.mid','the_desert.mid','the_shadow.mid','the_tower.mid','theme.mid','tomorrow.mid','trawler.mid','trawler_minor.mid','tree_spirits.mid','tribal.mid','tribal2.mid','tribal_background.mid','trinity.mid','troubled.mid','undercurrent.mid','underground.mid','understanding.mid','unknown_land.mid','upass1.mid','upcoming.mid','venture.mid','venture2.mid','vision.mid','voodoo_cult.mid','voyage.mid','wander.mid','waterfall.mid','wilderness2.mid','wilderness3.mid','wilderness4.mid','witching.mid','wolf_mountain.mid','wonder.mid','wonderous.mid','workshop.mid','yesteryear.mid','zealot.mid'],i=['advance agility.mid','advance attack.mid','advance attack2.mid','advance cooking.mid','advance cooking2.mid','advance crafting.mid','advance crafting2.mid','advance defense.mid','advance defense2.mid','advance firemarking.mid','advance firemarking2.mid','advance fishing.mid','advance fishing2.mid','advance fletching.mid','advance fletching2.mid','advance herblaw.mid','advance herblaw2.mid','advance hitpoints.mid','advance hitpoints2.mid','advance magic.mid','advance magic2.mid','advance mining.mid','advance mining2.mid','advance prayer.mid','advance prayer2.mid','advance ranged.mid','advance ranged2.mid','advance runecraft.mid','advance runecraft2.mid','advance smithing.mid','advance smithing2.mid','advance strength.mid','advance strength2.mid','advance thieving.mid','advance thieving2.mid','advance woodcutting.mid','advance woodcutting2.mid','death.mid','death2.mid','dice lose.mid','dice win.mid','duel start.mid','duel win2.mid','quest complete 1.mid','quest complete 2.mid','quest complete 3.mid','sailing journey.mid','treasure hunt win.mid'],r=['m29_75','m30_75','m31_75','m32_70','m32_71','m32_72','m32_73','m32_74','m32_75','m33_70','m33_71','m33_72','m33_73','m33_74','m33_75','m33_76','m34_70','m34_71','m34_72','m34_73','m34_74','m34_75','m34_76','m35_20','m35_75','m35_76','m36_146','m36_147','m36_148','m36_149','m36_150','m36_153','m36_154','m36_52','m36_53','m36_54','m36_72','m36_73','m36_74','m36_75','m36_76','m37_146','m37_147','m37_148','m37_149','m37_150','m37_151','m37_152','m37_153','m37_154','m37_48','m37_49','m37_50','m37_51','m37_52','m37_53','m37_54','m37_55','m37_72','m37_73','m37_74','m37_75','m38_146','m38_147','m38_148','m38_149','m38_150','m38_151','m38_152','m38_153','m38_154','m38_155','m38_45','m38_46','m38_47','m38_48','m38_49','m38_50','m38_51','m38_52','m38_53','m38_54','m38_55','m38_72','m38_73','m38_74','m39_147','m39_148','m39_149','m39_150','m39_151','m39_152','m39_153','m39_154','m39_155','m39_45','m39_46','m39_47','m39_48','m39_49','m39_50','m39_51','m39_52','m39_53','m39_54','m39_55','m39_72','m39_73','m39_74','m39_75','m39_76','m40_147','m40_148','m40_149','m40_150','m40_151','m40_152','m40_153','m40_154','m40_45','m40_46','m40_47','m40_48','m40_49','m40_50','m40_51','m40_52','m40_53','m40_54','m40_55','m40_72','m40_73','m40_74','m40_75','m40_76','m41_146','m41_149','m41_151','m41_152','m41_153','m41_154','m41_45','m41_46','m41_47','m41_48','m41_49','m41_50','m41_51','m41_52','m41_53','m41_54','m41_55','m41_56','m41_72','m41_73','m41_74','m41_75','m42_144','m42_145','m42_146','m42_151','m42_152','m42_153','m42_49','m42_50','m42_51','m42_52','m42_53','m42_54','m42_55','m42_56','m42_72','m42_73','m42_74','m42_75','m43_144','m43_145','m43_146','m43_153','m43_154','m43_45','m43_46','m43_47','m43_48','m43_49','m43_50','m43_51','m43_52','m43_53','m43_54','m43_55','m43_56','m43_72','m43_73','m43_74','m43_75','m44_144','m44_145','m44_146','m44_148','m44_149','m44_150','m44_151','m44_152','m44_153','m44_154','m44_155','m44_45','m44_46','m44_47','m44_48','m44_49','m44_50','m44_51','m44_52','m44_53','m44_54','m44_55','m44_72','m44_73','m44_74','m44_75','m45_145','m45_146','m45_148','m45_150','m45_151','m45_152','m45_153','m45_154','m45_155','m45_45','m45_46','m45_47','m45_48','m45_49','m45_50','m45_51','m45_52','m45_53','m45_54','m45_55','m45_56','m45_57','m45_58','m45_59','m45_60','m45_61','m45_62','m45_73','m45_74','m45_75','m45_76','m46_149','m46_150','m46_152','m46_153','m46_154','m46_161','m46_45','m46_46','m46_47','m46_48','m46_49','m46_50','m46_51','m46_52','m46_53','m46_54','m46_55','m46_56','m46_57','m46_58','m46_59','m46_60','m46_61','m46_62','m46_75','m47_148','m47_149','m47_150','m47_152','m47_153','m47_160','m47_161','m47_47','m47_48','m47_49','m47_50','m47_51','m47_52','m47_53','m47_54','m47_55','m47_56','m47_57','m47_58','m47_59','m47_60','m47_61','m47_62','m47_75','m48_148','m48_149','m48_152','m48_153','m48_154','m48_155','m48_156','m48_47','m48_48','m48_49','m48_50','m48_51','m48_52','m48_53','m48_54','m48_55','m48_56','m48_57','m48_58','m48_59','m48_60','m48_61','m48_62','m49_148','m49_149','m49_153','m49_154','m49_155','m49_156','m49_46','m49_47','m49_48','m49_49','m49_50','m49_51','m49_52','m49_53','m49_54','m49_55','m49_56','m49_57','m49_58','m49_59','m49_60','m49_61','m49_62','m50_149','m50_150','m50_152','m50_153','m50_154','m50_46','m50_47','m50_48','m50_49','m50_50','m50_51','m50_52','m50_53','m50_54','m50_55','m50_56','m50_57','m50_58','m50_59','m50_60','m50_61','m50_62','m51_147','m51_154','m51_46','m51_47','m51_48','m51_49','m51_50','m51_51','m51_52','m51_53','m51_54','m51_55','m51_56','m51_57','m51_58','m51_59','m51_60','m51_61','m51_62','m52_152','m52_153','m52_154','m52_46','m52_47','m52_48','m52_49','m52_50','m52_51','m52_52','m52_53','m52_54','m52_55','m52_56','m52_57','m52_58','m52_59','m52_60','m52_61','m52_62','m53_49','m53_50','m53_51','m53_52','m53_53']}},function(){return te&&(ie=(0,te[o(te)[0]])(te=0)),ie}),ce=!0;'undefined'!=typeof process&&(({FORCE_COLOR:re,NODE_DISABLE_COLORS:se,NO_COLOR:ne,TERM:ae}=process.env||{}),ce=process.stdout&&process.stdout.isTTY);var le={enabled:!se&&null==ne&&'dumb'!==ae&&(null!=re&&'0'!==re||ce),reset:de(0,0),bold:de(1,22),dim:de(2,22),italic:de(3,23),underline:de(4,24),inverse:de(7,27),hidden:de(8,28),strikethrough:de(9,29),black:de(30,39),red:de(31,39),green:de(32,39),yellow:de(33,39),blue:de(34,39),magenta:de(35,39),cyan:de(36,39),white:de(37,39),gray:de(90,39),grey:de(90,39),bgBlack:de(40,49),bgRed:de(41,49),bgGreen:de(42,49),bgYellow:de(43,49),bgBlue:de(44,49),bgMagenta:de(45,49),bgCyan:de(46,49),bgWhite:de(47,49)};function he(e,t){let i,r=0,s='',n='';for(;r=65&&r<=90?t+=BigInt(r+1-65):r>=97&&r<=122?t+=BigInt(r+1-97):r>=48&&r<=57&&(t+=BigInt(r+27-48))}return t}var fe=['_','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'];function ge(e){if(e<0n||e>=6582952005840035281n)return'invalid_name';if(e%37n===0n)return'invalid_name';let t=0;const i=Array(12);for(;0n!==e;){const r=e;e/=37n,i[11-t++]=fe[Number(r-37n*e)]}return i.slice(12-t).join('')}function me(e){return t=function(e){return ge(pe(e))}(e).replaceAll('_',' '),t.replace(/\w\S*/g,(e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()));var t}var ye,Ee,_e,Ae,ve=(ye=J(),Ee=1,_e=null!=ye?s(c(ye)):{},((e,t,i,r)=>{if(t&&'object'==typeof t||'function'==typeof t)for(let s of o(t))l.call(e,s)||s===i||n(e,s,{get:()=>t[s],enumerable:!(r=a(t,s))||r.enumerable});return e})(!Ee&&ye&&ye.__esModule?_e:n(_e,'default',{value:ye,enumerable:!0}),ye)),Te=class{key;next;prev;constructor(){this.key=0n,this.next=this,this.prev=this}unlink(){this.prev&&this.next&&(this.prev.next=this.next,this.next.prev=this.prev,this.next=null,this.prev=null)}},Ce=class{sentinel;cursor=null;constructor(){const e=new Te;e.next=e,e.prev=e,this.sentinel=e}addTail(e){e.prev&&e.unlink(),e.prev=this.sentinel.prev,e.next=this.sentinel,e.prev&&(e.prev.next=e),e.next.prev=e}addHead(e){e.prev&&e.unlink(),e.prev=this.sentinel,e.next=this.sentinel.next,e.prev.next=e,e.next&&(e.next.prev=e)}removeHead(){const e=this.sentinel.next;return e===this.sentinel?null:(e?.unlink(),e)}head(){const e=this.sentinel.next;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.next||null,e)}tail(){const e=this.sentinel.prev;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.prev||null,e)}next(){const e=this.cursor;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.next||null,e)}prev(){const e=this.cursor;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.prev||null,e)}clear(){for(;;){const e=this.sentinel.next;if(e===this.sentinel)return;e?.unlink()}}},Ie=class extends Te{nextHashable;prevHashable;constructor(){super(),this.nextHashable=this,this.prevHashable=this}uncache(){this.prevHashable&&this.nextHashable&&(this.prevHashable.nextHashable=this.nextHashable,this.nextHashable.prevHashable=this.prevHashable,this.nextHashable=null,this.prevHashable=null)}},Se=ve.default.jsbn.BigInteger,Oe=class e extends Ie{static crctable=new Int32Array(256);static bitmask=new Uint32Array(33);static crc32b=3988292384;static{for(let e=0;e<32;e++)this.bitmask[e]=(1<>>=1:t=t>>>1^this.crc32b;this.crctable[e]=t}}static getcrc(e,t,i){let r=4294967295;for(let s=t;s>>8^this.crctable[255&(r^e[s])];return~r}static checkcrc(t,i,r,s=0){return e.getcrc(t,i,r)==s}static alloc(t){let i=null;return 0===t&&this.cacheMinCount>0?(i=this.cacheMin.removeHead(),this.cacheMinCount--):1===t&&this.cacheMidCount>0?(i=this.cacheMid.removeHead(),this.cacheMidCount--):2===t&&this.cacheMaxCount>0?(i=this.cacheMax.removeHead(),this.cacheMaxCount--):3===t&&this.cacheBigCount>0?(i=this.cacheBig.removeHead(),this.cacheBigCount--):4===t&&this.cacheHugeCount>0?(i=this.cacheHuge.removeHead(),this.cacheHugeCount--):5===t&&this.cacheUnimaginableCount>0&&(i=this.cacheUnimaginable.removeHead(),this.cacheUnimaginableCount--),null!==i?(i.pos=0,i.bitPos=0,i):new e(0===t?new Uint8Array(100):1===t?new Uint8Array(5e3):2===t?new Uint8Array(3e4):3===t?new Uint8Array(1e5):4===t?new Uint8Array(5e5):5===t?new Uint8Array(2e6):new Uint8Array(t))}static load(t,i=!1){const r=new e(new Uint8Array(fs.readFileSync(t)));return i&&(r.pos=r.data.length),r}static async loadAsync(t,i=!1){const r=new e(new Uint8Array(await(await fetch(t)).arrayBuffer()));return i&&(r.pos=r.data.length),r}static cacheMinCount=0;static cacheMidCount=0;static cacheMaxCount=0;static cacheBigCount=0;static cacheHugeCount=0;static cacheUnimaginableCount=0;static cacheMin=new Ce;static cacheMid=new Ce;static cacheMax=new Ce;static cacheBig=new Ce;static cacheHuge=new Ce;static cacheUnimaginable=new Ce;data;#e;pos;bitPos;constructor(e){super(),this.data=e,this.#e=new DataView(this.data.buffer),this.pos=0,this.bitPos=0}get available(){return this.data.length-this.pos}get length(){return this.data.length}release(){this.pos=0,this.bitPos=0,100===this.data.length&&e.cacheMinCount<1e3?(e.cacheMin.addTail(this),e.cacheMinCount++):5e3===this.data.length&&e.cacheMidCount<250?(e.cacheMid.addTail(this),e.cacheMidCount++):3e4===this.data.length&&e.cacheMaxCount<50?(e.cacheMax.addTail(this),e.cacheMaxCount++):1e5===this.data.length&&e.cacheBigCount<10?(e.cacheBig.addTail(this),e.cacheBigCount++):5e5===this.data.length&&e.cacheHugeCount<5?(e.cacheHuge.addTail(this),e.cacheHugeCount++):2e6===this.data.length&&e.cacheUnimaginableCount<2&&(e.cacheUnimaginable.addTail(this),e.cacheUnimaginableCount++)}save(e,t=this.pos,i=0){if('undefined'==typeof self){const r=path.dirname(e);fs.existsSync(r)||fs.mkdirSync(r,{recursive:!0}),fs.writeFileSync(e,this.data.subarray(i,i+t))}else{const r=new Blob([this.data.subarray(i,i+t)],{type:'application/octet-stream'}),s=URL.createObjectURL(r);self.postMessage({type:'save',value:s,path:e})}}p1(e){this.#e.setUint8(this.pos++,e)}p2(e){this.#e.setUint16(this.pos,e),this.pos+=2}ip2(e){this.#e.setUint16(this.pos,e,!0),this.pos+=2}p3(e){this.#e.setUint8(this.pos++,e>>16),this.#e.setUint16(this.pos,e),this.pos+=2}p4(e){this.#e.setInt32(this.pos,e),this.pos+=4}ip4(e){this.#e.setInt32(this.pos,e,!0),this.pos+=4}p8(e){this.#e.setBigInt64(this.pos,e),this.pos+=8}pbool(e){this.p1(e?1:0)}pjstr(e,t=10){const i=e.length;for(let t=0;t=64)this.p1(e+64);else{if(!(e<16384&&e>=-16384))throw new Error('Error psmarts out of range: '+e);this.p2(e+49152)}}psmart(e){if(e>=0&&e<128)this.p1(e);else{if(!(e>=0&&e<32768))throw new Error('Error psmart out of range: '+e);this.p2(e+32768)}}g1(){return this.#e.getUint8(this.pos++)}g1b(){return this.#e.getInt8(this.pos++)}g2(){return this.pos+=2,this.#e.getUint16(this.pos-2)}g2s(){return this.pos+=2,this.#e.getInt16(this.pos-2)}ig2(){return this.pos+=2,this.#e.getUint16(this.pos-2,!0)}g3(){const e=this.#e.getUint8(this.pos++)<<16|this.#e.getUint16(this.pos);return this.pos+=2,e}g4(){return this.pos+=4,this.#e.getInt32(this.pos-4)}ig4(){return this.pos+=4,this.#e.getInt32(this.pos-4,!0)}g8(){return this.pos+=8,this.#e.getBigInt64(this.pos-8)}gbool(){return 1===this.g1()}gjstr(e=10){const t=this.data.length;let i,r='';for(;(i=this.#e.getUint8(this.pos++))!==e&&this.pos>>3}gBit(t){let i=this.bitPos>>>3,r=8-(7&this.bitPos),s=0;for(this.bitPos+=t;t>r;r=8)s+=(this.#e.getUint8(i++)&e.bitmask[r])<>>r-t&e.bitmask[t],s}pBit(e,t){const i=this.bitPos;this.bitPos+=e;let r=i>>>3,s=8-(7&i);const n=this.#e;for(;e>s;s=8){const i=(1<>>e-s&i),e-=s}const a=s-e,o=(1<0;){const t=e.g1();if(0===t)break;this.decode(t,e)}}},Le=class e extends Ne{static configNames=new Map;static configs=[];static load(e){if(!fs2.existsSync(`${e}/server/category.dat`))return void console.log('Warning: No category.dat found.');const t=Oe.load(`${e}/server/category.dat`);this.parse(t)}static async loadAsync(e){if(!(await fetch(`${e}/server/category.dat`)).ok)return void console.log('Warning: No category.dat found.');const t=await Oe.loadAsync(`${e}/server/category.dat`);this.parse(t)}static parse(t){e.configNames=new Map,e.configs=[];const i=t.g2();for(let r=0;re.tableId===t))}tableId=0;types=[];columnValues=[];decode(e,t){if(3===e){const e=t.g1();this.types=new Array(e),this.columnValues=new Array(e);for(let e=t.g1();255!=e;e=t.g1()){const i=new Array(t.g1());for(let e=0;e{i=e,r=t}));['_BZ2_bzBuffToBuffDecompress','_BZ2_bzBuffToBuffCompress','_malloc','_free','_memory','___indirect_function_table','onRuntimeInitialized'].forEach((e=>{Object.getOwnPropertyDescriptor(n,e)||Object.defineProperty(n,e,{get:()=>z('You are getting '+e+' 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:()=>z('You are setting '+e+' 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'==typeof window,o='function'==typeof importScripts,c='object'==typeof process&&'object'==typeof process.versions&&'string'==typeof process.versions.node,l=!a&&!c&&!o;if(s.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)');if(c){const{createRequire:e}=await import('module');var h=e(import.meta.url)}var d,u,p,f=Object.assign({},s),g=(e,t)=>{throw t},m='';if(c){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 y=process.versions.node,E=y.split('.').slice(0,3);if((E=1e4*E[0]+100*E[1]+1*E[2].split('-')[0])<16e4)throw new Error('This emscripten-generated code requires node v16.0.0 (detected v'+y+')');var _=h('fs'),A=h('path');m=h('url').fileURLToPath(new URL('./',import.meta.url)),d=(e,t)=>(e=Q(e)?new URL(e):A.normalize(e),_.readFileSync(e,t?void 0:'utf8')),p=e=>{var t=d(e,!0);return t.buffer||(t=new Uint8Array(t)),U(t.buffer),t},u=(e,t,i,r=!0)=>{e=Q(e)?new URL(e):A.normalize(e),_.readFile(e,r?void 0:'utf8',((e,s)=>{e?i(e):t(r?s.buffer:s)}))},!s.thisProgram&&process.argv.length>1&&process.argv[1].replace(/\\/g,'/'),process.argv.slice(2),g=(e,t)=>{throw process.exitCode=e,t}}else if(l){if('object'==typeof process&&'function'==typeof h||'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?)')}else{if(!a&&!o)throw new Error('environment detection error');if(o?m=self.location.href:'undefined'!=typeof document&&document.currentScript&&(m=document.currentScript.src),Ae&&(m=Ae),m=m.startsWith('blob:')?'':m.substr(0,m.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?)');d=e=>{var t=new XMLHttpRequest;return t.open('GET',e,!1),t.send(null),t.responseText},o&&(p=e=>{var t=new XMLHttpRequest;return t.open('GET',e,!1),t.responseType='arraybuffer',t.send(null),new Uint8Array(t.response)}),u=(e,t,i)=>{var r=new XMLHttpRequest;r.open('GET',e,!0),r.responseType='arraybuffer',r.onload=()=>{200==r.status||0==r.status&&r.response?t(r.response):i()},r.onerror=i,r.send(null)}}var v,T,C,I=s.print||console.log.bind(console),S=s.printErr||console.error.bind(console);Object.assign(s,f),f=null,v='fetchSettings',Object.getOwnPropertyDescriptor(s,v)&&z(`\`Module.${v}\` was supplied but \`${v}\` not included in INCOMING_MODULE_JS_API`),s.arguments&&s.arguments,ee('arguments','arguments_'),s.thisProgram&&s.thisProgram,ee('thisProgram','thisProgram'),s.quit&&(g=s.quit),ee('quit','quit_'),U(void 0===s.memoryInitializerPrefixURL,'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead'),U(void 0===s.pthreadMainPrefixURL,'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead'),U(void 0===s.cdInitializerPrefixURL,'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead'),U(void 0===s.filePackagePrefixURL,'Module.filePackagePrefixURL option was removed, use Module.locateFile instead'),U(void 0===s.read,'Module.read option was removed (modify read_ in JS)'),U(void 0===s.readAsync,'Module.readAsync option was removed (modify readAsync in JS)'),U(void 0===s.readBinary,'Module.readBinary option was removed (modify readBinary in JS)'),U(void 0===s.setWindowTitle,'Module.setWindowTitle option was removed (modify emscripten_set_window_title in JS)'),U(void 0===s.TOTAL_MEMORY,'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY'),ee('asm','wasmExports'),ee('read','read_'),ee('readAsync','readAsync'),ee('readBinary','readBinary'),ee('setWindowTitle','setWindowTitle'),U(!l,'shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.'),s.wasmBinary&&(T=s.wasmBinary),ee('wasmBinary','wasmBinary'),'object'!=typeof WebAssembly&&S('no native wasm support detected');var O,N,L,P,w,b,R,B=!1;function U(e,t){e||z('Assertion failed'+(t?': '+t:''))}function D(){var e=C.buffer;s.HEAP8=O=new Int8Array(e),s.HEAP16=L=new Int16Array(e),s.HEAPU8=N=new Uint8Array(e),s.HEAPU16=new Uint16Array(e),s.HEAP32=P=new Int32Array(e),s.HEAPU32=w=new Uint32Array(e),s.HEAPF32=b=new Float32Array(e),s.HEAPF64=R=new Float64Array(e)}function k(){if(!B){var e=Ce();0==e&&(e+=4);var t=w[e>>2],i=w[e+4>>2];34821223==t&&2310721022==i||z(`Stack overflow! Stack cookie has been overwritten at ${ce(e)}, expected hex dwords 0x89BACDFE and 0x2135467, but received ${ce(i)} ${ce(t)}`),1668509029!=w[0]&&z('Runtime error: The application has corrupted its heap memory area (address zero)!')}}U(!s.STACK_SIZE,'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time'),U('undefined'!=typeof Int32Array&&'undefined'!=typeof Float64Array&&null!=Int32Array.prototype.subarray&&null!=Int32Array.prototype.set,'JS engine does not provide full typed array support'),U(!s.wasmMemory,'Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally'),U(!s.INITIAL_MEMORY,'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically'),function(){var e=new Int16Array(1),t=new Int8Array(e.buffer);if(e[0]=25459,115!==t[0]||99!==t[1])throw'Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)'}();var M=[],x=[],F=[],H=!1;U(Math.imul,'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'),U(Math.fround,'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'),U(Math.clz32,'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'),U(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 V=0,G=null,W=null,K={};function z(e){s.onAbort?.(e),S(e='Aborted('+e+')'),B=!0;var t=new WebAssembly.RuntimeError(e);throw r(t),t}var j={error(){z('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(){j.error()},createDataFile(){j.error()},createPreloadedFile(){j.error()},createLazyFile(){j.error()},open(){j.error()},mkdev(){j.error()},registerDevice(){j.error()},analyzePath(){j.error()},ErrnoError(){j.error()}};s.FS_createDataFile=j.createDataFile,s.FS_createPreloadedFile=j.createPreloadedFile;var Y,q=e=>e.startsWith("data:application/octet-stream;base64,"),Q=e=>e.startsWith('file://');function $(e,t){return(...i)=>{U(H,`native function \`${e}\` called before runtime initialization`);var r=_e[e];return U(r,`exported native function \`${e}\` not found`),U(i.length<=t,`native function \`${e}\` called with ${i.length} args but expects ${t}`),r(...i)}}function Z(){if(s.locateFile){var e='bzip2.wasm';return q(e)?e:(t=e,s.locateFile?s.locateFile(t,m):m+t)}var t;return new URL('bzip2.wasm',import.meta.url).href}function X(e){if(e==Y&&T)return new Uint8Array(T);if(p)return p(e);throw'both async and sync fetching of the wasm failed'}function J(e,t,i){return function(e){if(!T&&(a||o)){if('function'==typeof fetch&&!Q(e))return fetch(e,{credentials:'same-origin'}).then((t=>{if(!t.ok)throw`failed to load wasm binary file at '${e}'`;return t.arrayBuffer()})).catch((()=>X(e)));if(u)return new Promise(((t,i)=>{u(e,(e=>t(new Uint8Array(e))),i)}))}return Promise.resolve().then((()=>X(e)))}(e).then((e=>WebAssembly.instantiate(e,t))).then(i,(e=>{S(`failed to asynchronously prepare wasm: ${e}`),Q(Y)&&S(`warning: Loading from a file URI (${Y}) 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`),z(e)}))}function ee(e,t,i=!0){Object.getOwnPropertyDescriptor(s,e)||Object.defineProperty(s,e,{configurable:!0,get(){z(`\`Module.${e}\` has been replaced by \`${t}\``+(i?' (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 te(e){return'FS_createPath'===e||'FS_createDataFile'===e||'FS_createPreloadedFile'===e||'FS_unlink'===e||'addRunDependency'===e||'FS_createLazyFile'===e||'FS_createDevice'===e||'removeRunDependency'===e}function ie(e,t){'undefined'!=typeof globalThis&&Object.defineProperty(globalThis,e,{configurable:!0,get(){le(`\`${e}\` is not longer defined by emscripten. ${t}`)}})}function re(e){Object.getOwnPropertyDescriptor(s,e)||Object.defineProperty(s,e,{configurable:!0,get(){var t=`'${e}' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`;te(e)&&(t+='. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you'),z(t)}})}function se(e){this.name='ExitStatus',this.message=`Program terminated with exit(${e})`,this.status=e}ie('buffer','Please use HEAP8.buffer or wasmMemory.buffer'),ie('asm','Please use wasmExports instead');var ne,ae=e=>{for(;e.length>0;)e.shift()(s)},oe=s.noExitRuntime||!0,ce=e=>(U('number'==typeof e),'0x'+(e>>>=0).toString(16).padStart(8,'0')),le=e=>{le.shown||={},le.shown[e]||(le.shown[e]=1,c&&(e='warning: '+e),S(e))},he=e=>{var t=C.buffer,i=(e-t.byteLength+65535)/65536;try{return C.grow(i),D(),1}catch(i){S(`growMemory: Attempted to grow heap from ${t.byteLength} bytes to ${e} bytes, but got error: ${i}`)}},de=()=>oe||!1,ue=(e,t)=>{if(function(){var e=I,t=S,i=!1;I=S=e=>{i=!0};try{ye()}catch(e){}I=e,S=t,i&&(le('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the Emscripten FAQ), or make sure to emit a newline when you printf etc.'),le('(this may also be due to not including full filesystem support - try building with -sFORCE_FILESYSTEM)'))}(),de()&&!t){var i=`program exited (with status: ${e}), but keepRuntimeAlive() is set (counter=0) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;r(i),S(i)}var n;n=e,de()||(s.onExit?.(n),B=!0),g(n,new se(n))},pe='undefined'!=typeof TextDecoder?new TextDecoder('utf8'):void 0,fe=(e,t,i)=>{for(var r=t+i,s=t;e[s]&&!(s>=r);)++s;if(s-t>16&&e.buffer&&pe)return pe.decode(e.subarray(t,s));for(var n='';t>10,56320|1023&l)}}else n+=String.fromCharCode((31&a)<<6|o)}else n+=String.fromCharCode(a)}return n},ge=[null,[],[]],me=(e,t)=>{var i=ge[e];U(i),0===t||10===t?((1===e?I:S)(fe(i,0)),i.length=0):i.push(t)},ye=()=>{ve(0),ge[1].length&&me(1,10),ge[2].length&&me(2,10)},Ee={_emscripten_memcpy_js:(e,t,i)=>N.copyWithin(e,t,t+i),emscripten_resize_heap:e=>{var t=N.length;U((e>>>=0)>t);var i=2147483648;if(e>i)return S(`Cannot enlarge memory, requested ${e} bytes, but the limit is 2147483648 bytes!`),!1;for(var r,s,n=1;n<=4;n*=2){var a=t*(1+.2/n);a=Math.min(a,e+100663296);var o=Math.min(i,(r=Math.max(e,a))+((s=65536)-r%s)%s);if(he(o))return!0}return S(`Failed to grow the heap from ${t} bytes to ${o} bytes, not enough memory!`),!1},exit:ue,fd_close:e=>{z('fd_close called without SYSCALLS_REQUIRE_FILESYSTEM')},fd_seek:function(e,t,i,r,s){var n,a;return a=i,U((n=t)==n>>>0||n==(0|n)),U(a===(0|a)),70},fd_write:(e,t,i,r)=>{for(var s=0,n=0;n>2],o=w[t+4>>2];t+=8;for(var c=0;c>2]=s,0}},_e=function(){var e,t={env:Ee,wasi_snapshot_preview1:Ee};function i(e,t){var i;return _e=e.exports,U(C=_e.memory,'memory not found in wasm exports'),D(),i=_e.__wasm_call_ctors,x.unshift(i),function(e){if(V--,s.monitorRunDependencies?.(V),e?(U(K[e]),delete K[e]):S('warning: run dependency removed without ID'),0==V&&(null!==G&&(clearInterval(G),G=null),W)){var t=W;W=null,t()}}('wasm-instantiate'),_e}e='wasm-instantiate',V++,s.monitorRunDependencies?.(V),e?(U(!K[e]),K[e]=1,null===G&&'undefined'!=typeof setInterval&&(G=setInterval((()=>{if(B)return clearInterval(G),void(G=null);var e=!1;for(var t in K)e||(e=!0,S('still waiting on run dependencies:')),S(`dependency: ${t}`);e&&S('(end of list)')}),1e4))):S('warning: run dependency added without ID');var n,a,o,l,h=s;if(s.instantiateWasm)try{return s.instantiateWasm(t,i)}catch(e){S(`Module.instantiateWasm callback failed with error: ${e}`),r(e)}return Y||(Y=Z()),(n=T,a=Y,o=t,l=function(e){U(s===h,'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?'),h=null,i(e.instance)},n||'function'!=typeof WebAssembly.instantiateStreaming||q(a)||Q(a)||c||'function'!=typeof fetch?J(a,o,l):fetch(a,{credentials:'same-origin'}).then((e=>WebAssembly.instantiateStreaming(e,o).then(l,(function(e){return S(`wasm streaming compile failed: ${e}`),S('falling back to ArrayBuffer instantiation'),J(a,o,l)}))))).catch(r),{}}(),ve=($('__wasm_call_ctors',0),s._malloc=$('malloc',1),s._free=$('free',1),$('fflush',1)),Te=(s._BZ2_bzBuffToBuffCompress=$('BZ2_bzBuffToBuffCompress',7),s._BZ2_bzBuffToBuffDecompress=$('BZ2_bzBuffToBuffDecompress',6),()=>(Te=_e.emscripten_stack_init)()),Ce=()=>(Ce=_e.emscripten_stack_get_end)();function Ie(){var e;Te(),U(!(3&(e=Ce()))),0==e&&(e+=4),w[e>>2]=34821223,w[e+4>>2]=2310721022,w[0]=1668509029}function Se(){function e(){ne||(ne=!0,s.calledRun=!0,B||(U(!H),H=!0,k(),ae(x),i(s),s.onRuntimeInitialized&&s.onRuntimeInitialized(),U(!s._main,'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]'),function(){if(k(),s.postRun)for('function'==typeof s.postRun&&(s.postRun=[s.postRun]);s.postRun.length;)e=s.postRun.shift(),F.unshift(e);var e;ae(F)}()))}V>0||(Ie(),function(){if(s.preRun)for('function'==typeof s.preRun&&(s.preRun=[s.preRun]);s.preRun.length;)e=s.preRun.shift(),M.unshift(e);var e;ae(M)}(),V>0||(s.setStatus?(s.setStatus('Running...'),setTimeout((function(){setTimeout((function(){s.setStatus('')}),1),e()}),1)):e(),k()))}if(s.dynCall_jiji=$('dynCall_jiji',5),s.setValue=function(e,t,i="i8"){switch(i.endsWith('*')&&(i='*'),i){case'i1':case'i8':O[e]=t;break;case'i16':L[e>>1]=t;break;case'i32':P[e>>2]=t;break;case'i64':z('to do setValue(i64) use WASM_BIGINT');case'float':b[e>>2]=t;break;case'double':R[e>>3]=t;break;case'*':w[e>>2]=t;break;default:z(`invalid type for setValue: ${i}`)}},s.getValue=function(e,t="i8"){switch(t.endsWith('*')&&(t='*'),t){case'i1':case'i8':return O[e];case'i16':return L[e>>1];case'i32':return P[e>>2];case'i64':z('to do getValue(i64) use WASM_BIGINT');case'float':return b[e>>2];case'double':return R[e>>3];case'*':return w[e>>2];default:z(`invalid type for getValue: ${t}`)}},['writeI53ToI64','writeI53ToI64Clamped','writeI53ToI64Signaling','writeI53ToU64Clamped','writeI53ToU64Signaling','readI53FromI64','readI53FromU64','convertI32PairToI53','convertU32PairToI53','stackAlloc','getTempRet0','setTempRet0','zeroMemory','isLeapYear','ydayFromDate','arraySum','addDays','inetPton4','inetNtop4','inetPton6','inetNtop6','readSockaddr','writeSockaddr','initRandomFill','randomFill','emscriptenLog','readEmAsmArgs','jstoi_q','getExecutableName','listenOnce','autoResumeAudioContext','dynCallLegacy','getDynCaller','dynCall','handleException','runtimeKeepalivePush','runtimeKeepalivePop','callUserCallback','maybeExit','asmjsMangle','asyncLoad','alignMemory','mmapAlloc','HandleAllocator','getNativeTypeSize','STACK_SIZE','STACK_ALIGN','POINTER_SIZE','ASSERTIONS','getCFunc','ccall','cwrap','uleb128Encode','sigToWasmTypes','generateFuncType','convertJsFunctionToWasm','getEmptyTableSlot','updateTableMap','getFunctionAddress','addFunction','removeFunction','reallyNegative','unSign','strLen','reSign','formatString','stringToUTF8Array','stringToUTF8','lengthBytesUTF8','intArrayFromString','intArrayToString','AsciiToString','stringToAscii','UTF16ToString','stringToUTF16','lengthBytesUTF16','UTF32ToString','stringToUTF32','lengthBytesUTF32','stringToNewUTF8','stringToUTF8OnStack','writeArrayToMemory','registerKeyEventCallback','maybeCStringToJsString','findEventTarget','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','jsStackTrace','getCallstack','convertPCtoSourceLocation','getEnvStrings','checkWasiClock','wasiRightsToMuslOFlags','wasiOFlagsToMuslOFlags','createDyncallWrapper','safeSetTimeout','setImmediateWrapped','clearImmediateWrapped','polyfillSetImmediate','getPromise','makePromise','idsToPromises','makePromiseCallback','ExceptionInfo','findMatchingCatch','Browser_asyncPrepareDataCounter','setMainLoop','getSocketFromFD','getSocketAddress','FS_createPreloadedFile','FS_modeStringToFlags','FS_getMode','FS_stdin_getChar','FS_createDataFile','FS_unlink','FS_mkdirTree','_setNetworkCallback','heapObjectForWebGLType','toTypedArrayIndex','webgl_enable_ANGLE_instanced_arrays','webgl_enable_OES_vertex_array_object','webgl_enable_WEBGL_draw_buffers','webgl_enable_WEBGL_multi_draw','emscriptenWebGLGet','computeUnpackAlignedImageSize','colorChannelsInGlTextureFormat','emscriptenWebGLGetTexPixelData','emscriptenWebGLGetUniform','webglGetUniformLocation','webglPrepareUniformLocationsBeforeFirstUse','webglGetLeftBracePos','emscriptenWebGLGetVertexAttrib','__glGetActiveAttribOrUniform','writeGLArray','registerWebGlEventCallback','runAndAbortIfError','ALLOC_NORMAL','ALLOC_STACK','allocate','writeStringToMemory','writeAsciiToMemory','setErrNo','demangle','stackTrace'].forEach((function(e){'undefined'==typeof globalThis||Object.getOwnPropertyDescriptor(globalThis,e)||Object.defineProperty(globalThis,e,{configurable:!0,get(){var t=`\`${e}\` 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`,i=e;i.startsWith('_')||(i='$'+e),t+=` (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='${i}')`,te(e)&&(t+='. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you'),le(t)}}),re(e)})),['run','addOnPreRun','addOnInit','addOnPreMain','addOnExit','addOnPostRun','addRunDependency','removeRunDependency','FS_createFolder','FS_createPath','FS_createLazyFile','FS_createLink','FS_createDevice','FS_readFile','out','err','callMain','abort','wasmMemory','wasmExports','writeStackCookie','checkStackCookie','convertI32PairToI53Checked','stackSave','stackRestore','ptrToString','exitJS','getHeapMax','growMemory','ENV','MONTH_DAYS_REGULAR','MONTH_DAYS_LEAP','MONTH_DAYS_REGULAR_CUMULATIVE','MONTH_DAYS_LEAP_CUMULATIVE','ERRNO_CODES','ERRNO_MESSAGES','DNS','Protocols','Sockets','timers','warnOnce','readEmAsmArgsArray','jstoi_s','keepRuntimeAlive','wasmTable','noExitRuntime','freeTableIndexes','functionsInTableMap','PATH','PATH_FS','UTF8Decoder','UTF8ArrayToString','UTF8ToString','UTF16Decoder','JSEvents','specialHTMLTargets','findCanvasEventTarget','currentFullscreenStrategy','restoreOldWindowedStyle','UNWIND_CACHE','ExitStatus','flush_NO_FILESYSTEM','promiseMap','uncaughtExceptionCount','exceptionLast','exceptionCaught','Browser','getPreloadedImageData__data','wget','SYSCALLS','preloadPlugins','FS_stdin_getChar_buffer','FS','MEMFS','TTY','PIPEFS','SOCKFS','tempFixedLengthArray','miniTempWebGLFloatBuffers','miniTempWebGLIntBuffers','GL','AL','GLUT','EGL','GLEW','IDBStore','SDL','SDL_gfx','allocateUTF8','allocateUTF8OnStack'].forEach(re),W=function e(){ne||Se(),ne||(W=e)},s.preInit)for('function'==typeof s.preInit&&(s.preInit=[s.preInit]);s.preInit.length>0;)s.preInit.pop()();Se(),t=n;for(const t of Object.keys(s))t in e||Object.defineProperty(e,t,{configurable:!0,get(){z(`Access to module property ('${t}') is no longer possible via the module constructor argument; Instead, use the result of the module constructor.`)}});return t}),Ue=Be,De={'-2':'BZ_PARAM_ERROR: incorrect parameters','-3':"BZ_MEM_ERROR: couldn't allocate enough memory",'-4':'BZ_DATA_ERROR: data integrity error when decompressing','-5':'BZ_DATA_ERROR_MAGIC: compressed data has incorrect header','-7':'BZ_UNEXPECTED_EOF: compressed data ends too early','-8':'BZ_OUTBUFF_FULL: destination buffer is full'},ke=new class{constructor(){this.wasmModule=void 0}async init(){if(!this.wasmModule){if('undefined'!=typeof process){const{dirname:e}=await import('path'),{createRequire:t}=await import('module');globalThis.__dirname=e(import.meta.url),globalThis.require=t(import.meta.url)}this.wasmModule=await Ue()}}ensureInitialized(){if(!this.wasmModule)throw new Error(`${this.constructor.name} not initalized. call .init()`)}handleError(e,t,i){if(0===e)return;this.wasmModule._free(t),this.wasmModule._free(i);const r=De[e];if(r)throw new Error(r);throw new Error(`error code: ${e}`)}createWASMBuffers(e,t){const{_malloc:i,setValue:r,HEAPU8:s}=this.wasmModule,n=i(e.length);s.set(e,n);const a=i(t),o=i(t);return r(o,t,'i32'),{sourcePtr:n,destPtr:a,destLengthPtr:o}}createBuffer(e,t){const{_free:i,getValue:r,HEAPU8:s}=this.wasmModule,n=r(t,'i32'),a=new Uint8Array(n);return a.set(s.subarray(e,e+n)),i(e),i(t),a}decompress(e,t,i=!1,r=!1){if(r&&(t=e[0]<<24|e[1]<<16|e[2]<<8|e[3],e[0]='B'.charCodeAt(0),e[1]='Z'.charCodeAt(0),e[2]='h'.charCodeAt(0),e[3]='1'.charCodeAt(0),i=!1),i){const t=new Uint8Array(e.length+4);t[0]='B'.charCodeAt(0),t[1]='Z'.charCodeAt(0),t[2]='h'.charCodeAt(0),t[3]='1'.charCodeAt(0),t.set(e,4),e=t}this.ensureInitialized();const{sourcePtr:s,destPtr:n,destLengthPtr:a}=this.createWASMBuffers(e,t),o=this.wasmModule._BZ2_bzBuffToBuffDecompress(n,a,s,e.length,0,0);return this.wasmModule._free(s),this.handleError(o,n,a),this.createBuffer(n,a)}compress(e,t=!1,i=!1,r=1,s=0){if(this.ensureInitialized(),s||(s=e.length+1024),s<128&&(s=128),r<=0||r>9)throw new RangeError('blockSize should be between 1-9');const{sourcePtr:n,destPtr:a,destLengthPtr:o}=this.createWASMBuffers(e,s),c=this.wasmModule._BZ2_bzBuffToBuffCompress(a,o,n,e.length,r,0,30);this.wasmModule._free(n),this.handleError(c,a,o);const l=this.createBuffer(a,o);return t&&(l[0]=e.length>>24&255,l[1]=e.length>>16&255,l[2]=e.length>>8&255,l[3]=255&e.length),i?l.subarray(4):l}};await ke.init();var Me=ke;function xe(e){let t=0;e=e.toUpperCase();for(let i=0;ie===this.fileHash[t]));-1!==r&&(this.fileName[t]=He[r]),this.fileUnpackedSize[t]=e.g3(),this.filePackedSize[t]=e.g3(),this.filePos[t]=i,i+=this.filePackedSize[t]}}get(e){if(e<0||e>=this.fileCount)return null;if(null===this.data)throw new Error('Jagfile data is not loaded');const t=this.data.subarray(this.filePos[e],this.filePos[e]+this.filePackedSize[e]);return this.unpacked?new Oe(t):new Oe(Me.decompress(t,this.fileUnpackedSize[e],!0))}read(e){const t=xe(e);for(let e=0;ee===t.hash));if(t.write){if(-1===i&&(i=this.fileCount++,this.fileHash[i]=t.hash,this.fileName[i]=t.name),!t.data)throw new Error('Cannot write without data');this.fileUnpackedSize[i]=t.data.length,this.filePackedSize[i]=t.data.length,this.filePos[i]=-1,this.fileWrite[i]=t.data}if(t.delete&&-1!==i&&(this.fileHash.splice(i,1),this.fileName.splice(i,1),this.fileUnpackedSize.splice(i,1),this.filePackedSize.splice(i,1),this.filePos.splice(i,1),this.fileCount--),t.rename&&-1!==i){if(!t.newHash)throw new Error('Cannot rename without newHash');if(!t.newName)throw new Error('Cannot rename without newName');this.fileHash[i]=t.newHash,this.fileName[i]=t.newName}this.fileQueue.splice(e,1),e--}let r=1===this.fileCount;t&&r&&(r=!1),i.p2(this.fileCount);for(let e=0;e/?\\| ";for(let i=0;i<256;i++){let r=t.indexOf(String.fromCharCode(i));-1==r&&(r=74),e.CHAR_LOOKUP[i]=r}}static load(t){const i=Fe.load(`${t}/client/title`);e.instances[0]=new e(i,'p11'),e.instances[1]=new e(i,'p12'),e.instances[2]=new e(i,'b12'),e.instances[3]=new e(i,'q8')}static async loadAsync(t){const i=await Fe.loadAsync(`${t}/client/title`);e.instances[0]=new e(i,'p11'),e.instances[1]=new e(i,'p12'),e.instances[2]=new e(i,'b12'),e.instances[3]=new e(i,'q8')}static get(t){return e.instances[t]}static get count(){return this.instances.length}charMask=new Array(94);charMaskWidth=new Uint8Array(94);charMaskHeight=new Uint8Array(94);charOffsetX=new Uint8Array(94);charOffsetY=new Uint8Array(94);charAdvance=new Uint8Array(95);drawWidth=new Uint8Array(256);height=0;constructor(t,i){const r=t.read(`${i}.dat`),s=t.read('index.dat');if(!r||!s)return;s.pos=r.g2()+4;const n=s.g1();n>0&&(s.pos+=3*(n-1));for(let e=0;e<94;e++){this.charOffsetX[e]=s.g1(),this.charOffsetY[e]=s.g1();const t=this.charMaskWidth[e]=s.g2(),i=this.charMaskHeight[e]=s.g2(),n=s.g1(),a=t*i;if(this.charMask[e]=new Uint8Array(a),0==n)for(let t=0;tthis.height&&(this.height=i),this.charOffsetX[e]=1,this.charAdvance[e]=t+2;let o=0;for(let r=Math.floor(i/7);r0;){if(this.stringWidth(e)<=t&&-1===e.indexOf('|')){i.push(e);break}let r=e.length;for(let i=0;it)break;r=i}else if('|'===e[i]){r=i;break}i.push(e.substring(0,r)),e=e.substring(r+1)}return i}},We=(e=>(e[e.OFF=0]='OFF',e[e.OUTSIDE_WILDERNESS=1]='OUTSIDE_WILDERNESS',e))(We||{}),Ke=We,ze=(e=>(e[e.OFF=0]='OFF',e[e.PLAYER=1]='PLAYER',e[e.NPC=2]='NPC',e[e.OBJ=3]='OBJ',e[e.SCENERY=4]='SCENERY',e))(ze||{}),je=ze,Ye=(e=>(e[e.KEEPHUNTING=0]='KEEPHUNTING',e[e.PAUSEHUNT=1]='PAUSEHUNT',e))(Ye||{}),qe=Ye,Qe=(e=>(e[e.OFF=0]='OFF',e[e.LINEOFSIGHT=1]='LINEOFSIGHT',e[e.LINEOFWALK=2]='LINEOFWALK',e))(Qe||{}),$e=Qe,Ze=(e=>(e[e.NULL=-1]='NULL',e[e.NONE=0]='NONE',e[e.WANDER=1]='WANDER',e[e.PATROL=2]='PATROL',e[e.PLAYERESCAPE=3]='PLAYERESCAPE',e[e.PLAYERFOLLOW=4]='PLAYERFOLLOW',e[e.PLAYERFACE=5]='PLAYERFACE',e[e.PLAYERFACECLOSE=6]='PLAYERFACECLOSE',e[e.OPPLAYER1=7]='OPPLAYER1',e[e.OPPLAYER2=8]='OPPLAYER2',e[e.OPPLAYER3=9]='OPPLAYER3',e[e.OPPLAYER4=10]='OPPLAYER4',e[e.OPPLAYER5=11]='OPPLAYER5',e[e.APPLAYER1=12]='APPLAYER1',e[e.APPLAYER2=13]='APPLAYER2',e[e.APPLAYER3=14]='APPLAYER3',e[e.APPLAYER4=15]='APPLAYER4',e[e.APPLAYER5=16]='APPLAYER5',e[e.OPLOC1=17]='OPLOC1',e[e.OPLOC2=18]='OPLOC2',e[e.OPLOC3=19]='OPLOC3',e[e.OPLOC4=20]='OPLOC4',e[e.OPLOC5=21]='OPLOC5',e[e.APLOC1=22]='APLOC1',e[e.APLOC2=23]='APLOC2',e[e.APLOC3=24]='APLOC3',e[e.APLOC4=25]='APLOC4',e[e.APLOC5=26]='APLOC5',e[e.OPOBJ1=27]='OPOBJ1',e[e.OPOBJ2=28]='OPOBJ2',e[e.OPOBJ3=29]='OPOBJ3',e[e.OPOBJ4=30]='OPOBJ4',e[e.OPOBJ5=31]='OPOBJ5',e[e.APOBJ1=32]='APOBJ1',e[e.APOBJ2=33]='APOBJ2',e[e.APOBJ3=34]='APOBJ3',e[e.APOBJ4=35]='APOBJ4',e[e.APOBJ5=36]='APOBJ5',e[e.OPNPC1=37]='OPNPC1',e[e.OPNPC2=38]='OPNPC2',e[e.OPNPC3=39]='OPNPC3',e[e.OPNPC4=40]='OPNPC4',e[e.OPNPC5=41]='OPNPC5',e[e.APNPC1=42]='APNPC1',e[e.APNPC2=43]='APNPC2',e[e.APNPC3=44]='APNPC3',e[e.APNPC4=45]='APNPC4',e[e.APNPC5=46]='APNPC5',e[e.QUEUE1=47]='QUEUE1',e[e.QUEUE2=48]='QUEUE2',e[e.QUEUE3=49]='QUEUE3',e[e.QUEUE4=50]='QUEUE4',e[e.QUEUE5=51]='QUEUE5',e[e.QUEUE6=52]='QUEUE6',e[e.QUEUE7=53]='QUEUE7',e[e.QUEUE8=54]='QUEUE8',e[e.QUEUE9=55]='QUEUE9',e[e.QUEUE10=56]='QUEUE10',e[e.QUEUE11=57]='QUEUE11',e[e.QUEUE12=58]='QUEUE12',e[e.QUEUE13=59]='QUEUE13',e[e.QUEUE14=60]='QUEUE14',e[e.QUEUE15=61]='QUEUE15',e[e.QUEUE16=62]='QUEUE16',e[e.QUEUE17=63]='QUEUE17',e[e.QUEUE18=64]='QUEUE18',e[e.QUEUE19=65]='QUEUE19',e[e.QUEUE20=66]='QUEUE20',e))(Ze||{}),Xe=Ze,Je=class e extends Ne{static configNames=new Map;static configs=[];static load(e){if(!fs6.existsSync(`${e}/server/hunt.dat`))return void console.log('Warning: No hunt.dat found.');const t=Oe.load(`${e}/server/hunt.dat`);this.parse(t)}static async loadAsync(e){if(!(await fetch(`${e}/server/hunt.dat`)).ok)return void console.log('Warning: No hunt.dat found.');const t=await Oe.loadAsync(`${e}/server/hunt.dat`);this.parse(t)}static parse(t){e.configNames=new Map,e.configs=[];const i=t.g2();for(let r=0;r=40&&e<50)this.recol_s[e-40]=t.g2();else if(e>=50&&e<60)this.recol_d[e-50]=t.g2();else if(e>=60&&e<70)this.heads[e-60]=t.g2();else{if(250!==e)throw new Error(`Unrecognized idk config code: ${e}`);this.debugname=t.gjstr()}}},tt=class e{static TYPE_LAYER=0;static TYPE_UNUSED=1;static TYPE_INVENTORY=2;static TYPE_RECT=3;static TYPE_TEXT=4;static TYPE_SPRITE=5;static TYPE_MODEL=6;static TYPE_INVENTORY_TEXT=7;static NO_BUTTON=0;static BUTTON=1;static TARGET_BUTTON=2;static CLOSE_BUTTON=3;static TOGGLE_BUTTON=4;static SELECT_BUTTON=5;static PAUSE_BUTTON=6;static componentNames=new Map;static components=[];static load(e){if(!fs8.existsSync(`${e}/server/interface.dat`))return void console.log('Warning: No interface.dat found.');const t=Oe.load(`${e}/server/interface.dat`);this.parse(t)}static async loadAsync(e){if(!(await fetch(`${e}/server/interface.dat`)).ok)return void console.log('Warning: No interface.dat found.');const t=await Oe.loadAsync(`${e}/server/interface.dat`);this.parse(t)}static parse(t){this.componentNames=new Map,this.components=[],t.g2();let i=-1;for(;t.available>0;){let r=t.g2();65535===r&&(i=t.g2(),r=t.g2());const s=new e;s.id=r,s.rootLayer=i,s.comName=t.gjstr(),s.overlay=t.gbool(),s.type=t.g1(),s.buttonType=t.g1(),s.clientCode=t.g2(),s.width=t.g2(),s.height=t.g2(),s.overLayer=t.g1(),0==s.overLayer?s.overLayer=-1:s.overLayer=(s.overLayer-1<<8)+t.g1();const n=t.g1();if(n>0){s.scriptComparator=new Uint8Array(n).fill(0),s.scriptOperand=new Uint16Array(n).fill(0);for(let e=0;e0){s.scripts=new Array(a).fill(null);for(let e=0;e0&&10===r.shapes[0]?1:0,r.op&&r.op.length>0&&(r.active=1)),e.configs[i]=r,r.debugname&&e.configNames.set(r.debugname,i)}}static get(t){return e.configs[t]}static getId(t){return e.configNames.get(t)??-1}static getByName(e){const t=this.getId(e);return void 0===t||-1===t?null:this.get(t)}static get count(){return this.configs.length}models=null;shapes=null;name=null;desc=null;recol_s=null;recol_d=null;width=1;length=1;blockwalk=!0;blockrange=!0;active=0;hillskew=!1;sharelight=!1;occlude=!1;anim=-1;hasalpha=!1;wallwidth=16;ambient=0;contrast=0;op=null;mapfunction=-1;mapscene=-1;mirror=!1;shadow=!0;resizex=128;resizey=128;resizez=128;forceapproach=0;xoff=0;yoff=0;zoff=0;forcedecor=!1;category=-1;params=new Map;decode(e,t){if(1===e){const e=t.g1();this.models=new Uint16Array(e),this.shapes=new Uint8Array(e);for(let i=0;i=30&&e<35)this.op||(this.op=new Array(5).fill(null)),this.op[e-30]=t.gjstr(),'hidden'===this.op[e-30]&&(this.op[e-30]=null);else if(40===e){const e=t.g1();this.recol_s=new Uint16Array(e),this.recol_d=new Uint16Array(e);for(let i=0;i=1&&e<5)this.len[e-1]=t.g2();else{if(250!==e)throw new Error(`Unrecognized mesanim config code: ${e}`);this.debugname=t.gjstr()}}},ct=(e=>(e[e.NONE=0]='NONE',e[e.NPC=1]='NPC',e[e.ALL=2]='ALL',e))(ct||{}),lt=ct,ht=(e=>(e[e.NORMAL=0]='NORMAL',e[e.BLOCKED=1]='BLOCKED',e[e.BLOCKED_NORMAL=2]='BLOCKED_NORMAL',e[e.INDOORS=3]='INDOORS',e[e.OUTDOORS=4]='OUTDOORS',e[e.NOMOVE=5]='NOMOVE',e[e.PASSTHRU=6]='PASSTHRU',e))(ht||{}),dt=ht,ut=(e=>(e[e.ATTACK=0]='ATTACK',e[e.DEFENCE=1]='DEFENCE',e[e.STRENGTH=2]='STRENGTH',e[e.HITPOINTS=3]='HITPOINTS',e[e.RANGED=4]='RANGED',e[e.MAGIC=5]='MAGIC',e))(ut||{}),pt=ut,ft=class e extends Ne{static configNames=new Map;static configs=[];static load(e){if(!fs12.existsSync(`${e}/server/npc.dat`))return void console.log('Warning: No npc.dat found.');const t=Oe.load(`${e}/server/npc.dat`),i=Fe.load(`${e}/client/config`);this.parse(t,i)}static async loadAsync(e){if(!(await fetch(`${e}/server/npc.dat`)).ok)return void console.log('Warning: No npc.dat found.');const t=await Oe.loadAsync(`${e}/server/npc.dat`),i=await Fe.loadAsync(`${e}/client/config`);this.parse(t,i)}static parse(t,i){e.configNames=new Map,e.configs=[];const r=t.g2(),s=i.read('npc.dat');s.pos=2;for(let i=0;i=30&&e<40)this.op||(this.op=new Array(5).fill(null)),this.op[e-30]=t.gjstr(),'hidden'===this.op[e-30]&&(this.op[e-30]=null);else if(40===e){const e=t.g1();this.recol_s=new Uint16Array(e),this.recol_d=new Uint16Array(e);for(let i=0;i{gt.get(t)?.autodisable&&i.params.delete(t)})))}}static get(t){return e.configs[t]}static getId(t){return e.configNames.get(t)??-1}static getByName(e){const t=this.getId(e);return-1===t?null:this.get(t)}static get count(){return this.configs.length}static getWearPosId(e){switch(e){case'hat':return 0;case'back':return 1;case'front':return 2;case'righthand':return 3;case'torso':return 4;case'lefthand':return 5;case'arms':return 6;case'legs':return 7;case'head':return 8;case'hands':return 9;case'feet':return 10;case'jaw':return 11;case'ring':return 12;case'quiver':return 13;default:return-1}}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;op=null;iop=null;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;wearpos=-1;wearpos2=-1;wearpos3=-1;weight=0;category=-1;dummyitem=0;tradeable=!1;respawnrate=100;params=new Map;decode(e,t){if(1===e)this.model=t.g2();else if(2===e)this.name=t.gjstr();else if(3===e)this.desc=t.gjstr();else if(4===e)this.zoom2d=t.g2();else if(5===e)this.xan2d=t.g2();else if(6===e)this.yan2d=t.g2();else if(7===e)this.xof2d=t.g2s();else if(8===e)this.yof2d=t.g2s();else if(9===e)this.code9=!0;else if(10===e)this.code10=t.g2();else if(11===e)this.stackable=!0;else if(12===e)this.cost=t.g4();else if(13===e)this.wearpos=t.g1();else if(14===e)this.wearpos2=t.g1();else if(16===e)this.members=!0;else if(23===e)this.manwear=t.g2(),this.manwearOffsetY=t.g1b();else if(24===e)this.manwear2=t.g2();else if(25===e)this.womanwear=t.g2(),this.womanwearOffsetY=t.g1b();else if(26===e)this.womanwear2=t.g2();else if(27===e)this.wearpos3=t.g1();else if(e>=30&&e<35)this.op||(this.op=new Array(5).fill(null)),this.op[e-30]=t.gjstr();else if(e>=35&&e<40)this.iop||(this.iop=new Array(5).fill(null)),this.iop[e-35]=t.gjstr();else if(40===e){const e=t.g1();this.recol_s=new Uint16Array(e),this.recol_d=new Uint16Array(e);for(let i=0;i=100&&e<110)this.countobj&&this.countco||(this.countobj=new Uint16Array(10),this.countco=new Uint16Array(10)),this.countobj[e-100]=t.g2(),this.countco[e-100]=t.g2();else if(200===e)this.tradeable=!0;else if(201===e)this.respawnrate=t.g2();else if(249===e)this.params=nt(t);else{if(250!==e)throw new Error(`Unrecognized obj config code: ${e}`);this.debugname=t.gjstr()}}toCertificate(){const t=e.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 i=e.get(this.certlink);this.name=i.name,this.members=i.members,this.cost=i.cost,this.tradeable=i.tradeable;let r='a';const s=(i.name||'').toLowerCase().charAt(0);'a'!==s&&'e'!==s&&'i'!==s&&'o'!==s&&'u'!==s||(r='an'),this.desc=`Swap this note at any bank for ${r} ${i.name}.`,this.stackable=!0}},Ct=class e{static instances=[];static load(e){if(!fs15.existsSync(`${e}/server/frame_del.dat`))return void console.log('Warning: No frame_del.dat found.');const t=Oe.load(`${e}/server/frame_del.dat`);this.parse(t)}static async loadAsync(e){if(!(await fetch(`${e}/server/frame_del.dat`)).ok)return void console.log('Warning: No frame_del.dat found.');const t=await Oe.loadAsync(`${e}/server/frame_del.dat`);this.parse(t)}static parse(t){e.instances=[];for(let i=0;i=0&&s6)return 0;let t=0;for(let i=0;i=0;i++)if(Bt.isNumerical(e[i]))return i;return-1}indexOfNonNumber(e,t){for(let i=e;i=0;i++)if(!Bt.isNumerical(t[i]))return i;return t.length}},wt=class{wordEncFragments;bads=[];badCombinations=[];constructor(e){this.wordEncFragments=e}filter(e){for(let t=0;t<2;t++)for(let t=this.bads.length-1;t>=0;t--)this.filterBadCombinations(this.badCombinations[t],e,this.bads[t])}filterBadCombinations(e,t,i){if(!(i.length>t.length))for(let r=0;r<=t.length-i.length;r++){let s=r;const{currentIndex:n,badIndex:a,hasSymbol:o,hasNumber:c,hasDigit:l}=this.processBadCharacters(t,i,s);s=n;let h=t[s],d=s+1=i.length)||c&&l)continue;let u,p=!0;if(o){let e=!1,i=!1;if((r-1<0||Bt.isSymbol(t[r-1])&&"'"!=t[r-1])&&(e=!0),(s>=t.length||Bt.isSymbol(t[s])&&"'"!=t[s])&&(i=!0),!e||!i){let i=!1;for(u=r-2,e&&(u=r);!i&&u=0&&(!Bt.isSymbol(t[u])||"'"==t[u])){const e=[];let r;for(r=0;r<3&&u+r=0&&(!Bt.isSymbol(t[u-1])||"'"==t[u-1])&&(s=!1),s&&!this.wordEncFragments.isBadFragment(e)&&(i=!0)}u++}i||(p=!1)}}else{h=' ',r-1>=0&&(h=t[r-1]),d=' ',s=e.length||o&&c);){const l=e[r],h=r+10)1===d&&Bt.isNumerical(l)&&(o=!0),2===d&&(Bt.isNumerical(l)||Bt.isNumerical(h))&&(o=!0),r+=d,s++;else{if(0===s)break;let e;if((e=this.getEmulatedBadCharLen(h,String.fromCharCode(t[s-1]),l))>0)r+=e;else{if(s>=t.length||!Bt.isNotLowercaseAlpha(l))break;if(Bt.isSymbol(l)&&"'"!==l&&(a=!0),Bt.isNumerical(l)&&(c=!0),r++,n++,(100*n/(r-i)|0)>90)break}}}return{currentIndex:r,badIndex:s,hasSymbol:a,hasNumber:o,hasDigit:c}}getEmulatedBadCharLen(e,t,i){if(t==i)return 1;if(t>='a'&&t<='m'){if('a'==t)return'4'!=i&&'@'!=i&&'^'!=i?'/'==i&&'\\'==e?2:0:1;if('b'==t)return'6'!=i&&'8'!=i?'1'==i&&'3'==e?2:0:1;if('c'==t)return'('!=i&&'<'!=i&&'{'!=i&&'['!=i?0:1;if('d'==t)return'['==i&&')'==e?2:0;if('e'==t)return'3'!=i&&'€'!=i?0:1;if('f'==t)return'p'==i&&'h'==e?2:'£'==i?1:0;if('g'==t)return'9'!=i&&'6'!=i?0:1;if('h'==t)return'#'==i?1:0;if('i'==t)return'y'!=i&&'l'!=i&&'j'!=i&&'1'!=i&&'!'!=i&&':'!=i&&';'!=i&&'|'!=i?0:1;if('j'==t)return 0;if('k'==t)return 0;if('l'==t)return'1'!=i&&'|'!=i&&'i'!=i?0:1;if('m'==t)return 0}if(t>='n'&&t<='z'){if('n'==t)return 0;if('o'==t)return'0'!=i&&'*'!=i?'('==i&&')'==e||'['==i&&']'==e||'{'==i&&'}'==e||'<'==i&&'>'==e?2:0:1;if('p'==t)return 0;if('q'==t)return 0;if('r'==t)return 0;if('s'==t)return'5'!=i&&'z'!=i&&'$'!=i&&'2'!=i?0:1;if('t'==t)return'7'!=i&&'+'!=i?0:1;if('u'==t)return'v'==i?1:'\\'==i&&'/'==e||'\\'==i&&'|'==e||'|'==i&&'/'==e?2:0;if('v'==t)return'\\'==i&&'/'==e||'\\'==i&&'|'==e||'|'==i&&'/'==e?2:0;if('w'==t)return'v'==i&&'v'==e?2:0;if('x'==t)return')'==i&&'('==e||'}'==i&&'{'==e||']'==i&&'['==e||'>'==i&&'<'==e?2:0;if('y'==t)return 0;if('z'==t)return 0}return t>='0'&&t<='9'?'0'==t?'o'==i||'O'==i?1:'('==i&&')'==e||'{'==i&&'}'==e||'['==i&&']'==e?2:0:'1'==t&&'l'==i?1:0:','==t?'.'==i?1:0:'.'==t?','==i?1:0:'!'==t&&'i'==i?1:0}comboMatches(e,t,i){let r=0,s=t.length-1;for(;r<=s;){const n=(r+s)/2|0;if(t[n][0]===e&&t[n][1]===i)return!0;e=0;r--)this.filterDomain(i,t,this.domains[r],e)}getEmulatedDomainCharLen(e,t,i){return t==i||'o'==t&&'0'==i?1:'o'==t&&'('==i&&')'==e?2:'c'!=t||'('!=i&&'<'!=i&&'['!=i?'e'==t&&'€'==i||'s'==t&&'$'==i||'l'==t&&'i'==i?1:0:1}filterDomain(e,t,i,r){const s=i.length,n=r.length;for(let a=0;a<=n-s;a++){const{matched:s,currentIndex:n}=this.findMatchingDomain(a,i,r);if(!s)continue;const o=Bt.prefixSymbolStatus(a,r,3,t,['@']),c=Bt.suffixSymbolStatus(n-1,r,3,e,['.',',']);(o>2||c>2)&&Bt.maskChars(a,n,r)}}findMatchingDomain(e,t,i){const r=t.length;let s=e,n=0;for(;s0)s+=c,n++;else{if(0===n)break;const i=this.getEmulatedDomainCharLen(o,String.fromCharCode(t[n-1]),a);if(i>0)s+=i,1===n&&e++;else{if(n>=r||!Bt.isSymbol(a))break;s++}}}return{matched:n>=r,currentIndex:s}}},Rt=class{wordEncBadWords;wordEncDomains;tlds=[];tldTypes=[];constructor(e,t){this.wordEncBadWords=e,this.wordEncDomains=t}filter(e){const t=[...e],i=[...e];this.wordEncBadWords.filterBadCombinations(null,t,Bt.PERIOD),this.wordEncBadWords.filterBadCombinations(null,i,Bt.SLASH);for(let r=0;ri.length))for(let n=0;n<=i.length-r.length;n++){const{currentIndex:a,tldIndex:o}=this.processTlds(i,r,n);if(o0&&h>0&&(c=!0),2==t&&(l>2&&h>0||l>0&&h>2)&&(c=!0),3==t&&l>0&&h>2&&(c=!0),!c)continue;let d,u=n,p=a-1,f=!1;if(l>2){if(4==l)for(f=!1,d=n-1;d>=0;d--)if(f){if('*'!=s[d])break;u=d}else'*'==s[d]&&(u=d,f=!0);for(f=!1,d=u-1;d>=0;d--)if(f){if(Bt.isSymbol(i[d]))break;u=d}else Bt.isSymbol(i[d])||(f=!0,u=d)}if(h>2){if(4==h)for(f=!1,d=p+1;d0)i+=a,r++;else{if(0===r)break;let e;if((e=this.wordEncDomains.getEmulatedDomainCharLen(n,String.fromCharCode(t[r-1]),s))>0)i+=e;else{if(!Bt.isSymbol(s))break;i++}}}return{currentIndex:i,tldIndex:r}}},Bt=class e{static PERIOD=new Uint16Array(['d','o','t'].join('').split('').map((e=>e.charCodeAt(0))));static AMPERSAT=new Uint16Array(['(','a',')'].join('').split('').map((e=>e.charCodeAt(0))));static SLASH=new Uint16Array(['s','l','a','s','h'].join('').split('').map((e=>e.charCodeAt(0))));static wordEncFragments=new Pt;static wordEncBadWords=new wt(this.wordEncFragments);static wordEncDomains=new bt(this.wordEncBadWords);static wordEncTlds=new Rt(this.wordEncBadWords,this.wordEncDomains);static whitelist=['cook',"cook's",'cooks','seeks','sheet'];static async load(e){if(!fs21.existsSync(`${e}/client/wordenc`))return void console.log('Warning: No wordenc found.');const t=Fe.load(`${e}/client/wordenc`);this.readAll(t)}static async loadAsync(e){if(!(await fetch(`${e}/client/wordenc`)).ok)return void console.log('Warning: No wordenc found.');const t=await Fe.loadAsync(`${e}/client/wordenc`);this.readAll(t)}static readAll(e){const t=e.read('fragmentsenc.txt');if(!t)return void console.log('Warning: No fragmentsenc found.');const i=e.read('badenc.txt');if(!i)return void console.log('Warning: No badenc found.');const r=e.read('domainenc.txt');if(!r)return void console.log('Warning: No domainenc found.');const s=e.read('tldlist.txt');s?(this.decodeBadEnc(i),this.decodeDomainEnc(r),this.decodeFragmentsEnc(t),this.decodeTldList(s)):console.log('Warning: No tldlist found.')}static filter(e){const t=[...e];this.format(t);const i=t.join('').trim(),r=i.toLowerCase(),s=[...r];this.wordEncTlds.filter(s),this.wordEncBadWords.filter(s),this.wordEncDomains.filter(s),this.wordEncFragments.filter(s);for(let e=0;e='0'&&e<='9'}static isLowercaseAlpha(e){return e>='a'&&e<='z'}static isUppercaseAlpha(e){return e>='A'&&e<='Z'}static isNumericalChars(e){for(let t=0;t=0&&e.isSymbol(t[s]);s--)'*'===t[s]&&r++;return r}static maskedCountForwards(e,t){let i=0;for(let r=t+1;r=r?4:this.isSymbol(s?e[i-1]:e[i+1])?1:0}static prefixSymbolStatus(t,i,r,s,n){if(0===t)return 2;for(let r=t-1;r>=0&&e.isSymbol(i[r]);r--)if(n.includes(i[r]))return 3;return e.maskedCharsStatus(i,s,t,r,!0)}static suffixSymbolStatus(t,i,r,s,n){if(t+1===i.length)return 2;for(let r=t+1;re.g1()))}static decodeBadEnc(e){const t=e.g4();for(let i=0;ie.g1()));const t=new Array(e.g1()).fill([]).map((()=>[e.g1b(),e.g1b()]));t.length>0&&(this.wordEncBadWords.badCombinations[i]=t)}}static decodeDomainEnc(e){const t=e.g4();for(let i=0;ie.g1()))}static decodeFragmentsEnc(e){const t=e.g4();for(let i=0;i=' '&&e<=''||' '==e||'\n'==e||'\t'==e||'£'==e||'€'==e}static replaceUppercases(e,t){for(let i=0;i=40&&e<50)this.recol_s[e-40]=t.g2();else if(e>=50&&e<60)this.recol_d[e-50]=t.g2();else{if(250!==e)throw new Error(`Unrecognized spotanim config code: ${e}`);this.debugname=t.gjstr()}}},Dt=(e=>(e[e.ActivePlayer=0]='ActivePlayer',e[e.ActivePlayer2=1]='ActivePlayer2',e[e.ProtectedActivePlayer=2]='ProtectedActivePlayer',e[e.ProtectedActivePlayer2=3]='ProtectedActivePlayer2',e[e.ActiveNpc=4]='ActiveNpc',e[e.ActiveNpc2=5]='ActiveNpc2',e[e.ActiveLoc=6]='ActiveLoc',e[e.ActiveLoc2=7]='ActiveLoc2',e[e.ActiveObj=8]='ActiveObj',e[e.ActiveObj2=9]='ActiveObj2',e[e._LAST=10]='_LAST',e))(Dt||{}),kt=[4,5],Mt=[6,7],xt=[8,9],Ft=[0,1],Ht=[2,3];function Vt(e,t){return function(i){'number'==typeof e?i.pointerCheck(e):i.pointerCheck(e[i.intOperand]),t(i)}}var Gt=Dt,Wt=(e=>(e[e.PUSH_CONSTANT_INT=0]='PUSH_CONSTANT_INT',e[e.PUSH_VARP=1]='PUSH_VARP',e[e.POP_VARP=2]='POP_VARP',e[e.PUSH_CONSTANT_STRING=3]='PUSH_CONSTANT_STRING',e[e.PUSH_VARN=4]='PUSH_VARN',e[e.POP_VARN=5]='POP_VARN',e[e.BRANCH=6]='BRANCH',e[e.BRANCH_NOT=7]='BRANCH_NOT',e[e.BRANCH_EQUALS=8]='BRANCH_EQUALS',e[e.BRANCH_LESS_THAN=9]='BRANCH_LESS_THAN',e[e.BRANCH_GREATER_THAN=10]='BRANCH_GREATER_THAN',e[e.PUSH_VARS=11]='PUSH_VARS',e[e.POP_VARS=12]='POP_VARS',e[e.RETURN=21]='RETURN',e[e.GOSUB=22]='GOSUB',e[e.JUMP=23]='JUMP',e[e.SWITCH=24]='SWITCH',e[e.BRANCH_LESS_THAN_OR_EQUALS=31]='BRANCH_LESS_THAN_OR_EQUALS',e[e.BRANCH_GREATER_THAN_OR_EQUALS=32]='BRANCH_GREATER_THAN_OR_EQUALS',e[e.PUSH_INT_LOCAL=33]='PUSH_INT_LOCAL',e[e.POP_INT_LOCAL=34]='POP_INT_LOCAL',e[e.PUSH_STRING_LOCAL=35]='PUSH_STRING_LOCAL',e[e.POP_STRING_LOCAL=36]='POP_STRING_LOCAL',e[e.JOIN_STRING=37]='JOIN_STRING',e[e.POP_INT_DISCARD=38]='POP_INT_DISCARD',e[e.POP_STRING_DISCARD=39]='POP_STRING_DISCARD',e[e.GOSUB_WITH_PARAMS=40]='GOSUB_WITH_PARAMS',e[e.JUMP_WITH_PARAMS=41]='JUMP_WITH_PARAMS',e[e.DEFINE_ARRAY=44]='DEFINE_ARRAY',e[e.PUSH_ARRAY_INT=45]='PUSH_ARRAY_INT',e[e.POP_ARRAY_INT=46]='POP_ARRAY_INT',e[e.COORDX=1e3]='COORDX',e[e.COORDY=1001]='COORDY',e[e.COORDZ=1002]='COORDZ',e[e.DISTANCE=1003]='DISTANCE',e[e.HUNTALL=1004]='HUNTALL',e[e.HUNTNEXT=1005]='HUNTNEXT',e[e.INZONE=1006]='INZONE',e[e.LINEOFSIGHT=1007]='LINEOFSIGHT',e[e.LINEOFWALK=1008]='LINEOFWALK',e[e.MAP_BLOCKED=1009]='MAP_BLOCKED',e[e.MAP_INDOORS=1010]='MAP_INDOORS',e[e.MAP_CLOCK=1011]='MAP_CLOCK',e[e.MAP_LOCADDUNSAFE=1012]='MAP_LOCADDUNSAFE',e[e.MAP_MEMBERS=1013]='MAP_MEMBERS',e[e.MAP_PLAYERCOUNT=1014]='MAP_PLAYERCOUNT',e[e.MOVECOORD=1015]='MOVECOORD',e[e.PLAYERCOUNT=1016]='PLAYERCOUNT',e[e.PROJANIM_MAP=1017]='PROJANIM_MAP',e[e.PROJANIM_NPC=1018]='PROJANIM_NPC',e[e.PROJANIM_PL=1019]='PROJANIM_PL',e[e.SEQLENGTH=1020]='SEQLENGTH',e[e.SPLIT_GET=1021]='SPLIT_GET',e[e.SPLIT_GETANIM=1022]='SPLIT_GETANIM',e[e.SPLIT_INIT=1023]='SPLIT_INIT',e[e.SPLIT_LINECOUNT=1024]='SPLIT_LINECOUNT',e[e.SPLIT_PAGECOUNT=1025]='SPLIT_PAGECOUNT',e[e.SPOTANIM_MAP=1026]='SPOTANIM_MAP',e[e.STAT_RANDOM=1027]='STAT_RANDOM',e[e.STRUCT_PARAM=1028]='STRUCT_PARAM',e[e.WORLD_DELAY=1029]='WORLD_DELAY',e[e.NPCCOUNT=1030]='NPCCOUNT',e[e.ZONECOUNT=1031]='ZONECOUNT',e[e.LOCCOUNT=1032]='LOCCOUNT',e[e.OBJCOUNT=1033]='OBJCOUNT',e[e.ALLOWDESIGN=2e3]='ALLOWDESIGN',e[e.ANIM=2001]='ANIM',e[e.BAS_READYANIM=2002]='BAS_READYANIM',e[e.BAS_RUNNING=2003]='BAS_RUNNING',e[e.BAS_TURNONSPOT=2004]='BAS_TURNONSPOT',e[e.BAS_WALK_B=2005]='BAS_WALK_B',e[e.BAS_WALK_F=2006]='BAS_WALK_F',e[e.BAS_WALK_L=2007]='BAS_WALK_L',e[e.BAS_WALK_R=2008]='BAS_WALK_R',e[e.BUFFER_FULL=2009]='BUFFER_FULL',e[e.BUILDAPPEARANCE=2010]='BUILDAPPEARANCE',e[e.BUSY=2011]='BUSY',e[e.CAM_LOOKAT=2012]='CAM_LOOKAT',e[e.CAM_MOVETO=2013]='CAM_MOVETO',e[e.CAM_RESET=2014]='CAM_RESET',e[e.CAM_SHAKE=2015]='CAM_SHAKE',e[e.CLEARQUEUE=2016]='CLEARQUEUE',e[e.CLEARSOFTTIMER=2017]='CLEARSOFTTIMER',e[e.CLEARTIMER=2018]='CLEARTIMER',e[e.COORD=2019]='COORD',e[e.DAMAGE=2020]='DAMAGE',e[e.DISPLAYNAME=2021]='DISPLAYNAME',e[e.FACESQUARE=2022]='FACESQUARE',e[e.FINDUID=2023]='FINDUID',e[e.GENDER=2024]='GENDER',e[e.GETQUEUE=2025]='GETQUEUE',e[e.GIVEXP=2026]='GIVEXP',e[e.HEADICONS_GET=2027]='HEADICONS_GET',e[e.HEADICONS_SET=2028]='HEADICONS_SET',e[e.HEALENERGY=2029]='HEALENERGY',e[e.HINT_COORD=2030]='HINT_COORD',e[e.HINT_NPC=2031]='HINT_NPC',e[e.HINT_PLAYER=2032]='HINT_PLAYER',e[e.HINT_STOP=2033]='HINT_STOP',e[e.IF_CLOSE=2034]='IF_CLOSE',e[e.IF_CLOSESTICKY=2035]='IF_CLOSESTICKY',e[e.IF_MULTIZONE=2036]='IF_MULTIZONE',e[e.IF_OPENCHAT=2037]='IF_OPENCHAT',e[e.IF_OPENCHATSTICKY=2038]='IF_OPENCHATSTICKY',e[e.IF_OPENMAINMODAL=2039]='IF_OPENMAINMODAL',e[e.IF_OPENMAINMODALSIDEOVERLAY=2040]='IF_OPENMAINMODALSIDEOVERLAY',e[e.IF_OPENSIDEOVERLAY=2041]='IF_OPENSIDEOVERLAY',e[e.IF_SETANIM=2042]='IF_SETANIM',e[e.IF_SETCOLOUR=2043]='IF_SETCOLOUR',e[e.IF_SETHIDE=2044]='IF_SETHIDE',e[e.IF_SETMODEL=2045]='IF_SETMODEL',e[e.IF_SETRECOL=2046]='IF_SETRECOL',e[e.IF_SETNPCHEAD=2047]='IF_SETNPCHEAD',e[e.IF_SETOBJECT=2048]='IF_SETOBJECT',e[e.IF_SETPLAYERHEAD=2049]='IF_SETPLAYERHEAD',e[e.IF_SETPOSITION=2050]='IF_SETPOSITION',e[e.IF_SETRESUMEBUTTONS=2051]='IF_SETRESUMEBUTTONS',e[e.IF_SETTAB=2052]='IF_SETTAB',e[e.IF_SETTABACTIVE=2053]='IF_SETTABACTIVE',e[e.IF_SETTABFLASH=2054]='IF_SETTABFLASH',e[e.IF_SETTEXT=2055]='IF_SETTEXT',e[e.LAST_LOGIN_INFO=2056]='LAST_LOGIN_INFO',e[e.LAST_COM=2057]='LAST_COM',e[e.LAST_INT=2058]='LAST_INT',e[e.LAST_ITEM=2059]='LAST_ITEM',e[e.LAST_SLOT=2060]='LAST_SLOT',e[e.LAST_TARGETSLOT=2061]='LAST_TARGETSLOT',e[e.LAST_USEITEM=2062]='LAST_USEITEM',e[e.LAST_USESLOT=2063]='LAST_USESLOT',e[e.LONGQUEUE=2064]='LONGQUEUE',e[e.MES=2065]='MES',e[e.MIDI_JINGLE=2066]='MIDI_JINGLE',e[e.MIDI_SONG=2067]='MIDI_SONG',e[e.NAME=2068]='NAME',e[e.P_APRANGE=2069]='P_APRANGE',e[e.P_ARRIVEDELAY=2070]='P_ARRIVEDELAY',e[e.P_COUNTDIALOG=2071]='P_COUNTDIALOG',e[e.P_DELAY=2072]='P_DELAY',e[e.P_EXACTMOVE=2073]='P_EXACTMOVE',e[e.P_FINDUID=2074]='P_FINDUID',e[e.P_LOCMERGE=2075]='P_LOCMERGE',e[e.P_LOGOUT=2076]='P_LOGOUT',e[e.P_OPHELD=2077]='P_OPHELD',e[e.P_OPLOC=2078]='P_OPLOC',e[e.P_OPNPC=2079]='P_OPNPC',e[e.P_OPNPCT=2080]='P_OPNPCT',e[e.P_OPOBJ=2081]='P_OPOBJ',e[e.P_OPPLAYER=2082]='P_OPPLAYER',e[e.P_OPPLAYERT=2083]='P_OPPLAYERT',e[e.P_PAUSEBUTTON=2084]='P_PAUSEBUTTON',e[e.P_STOPACTION=2085]='P_STOPACTION',e[e.P_TELEJUMP=2086]='P_TELEJUMP',e[e.P_TELEPORT=2087]='P_TELEPORT',e[e.P_WALK=2088]='P_WALK',e[e.PLAYER_FINDALLZONE=2089]='PLAYER_FINDALLZONE',e[e.PLAYER_FINDNEXT=2090]='PLAYER_FINDNEXT',e[e.QUEUE=2091]='QUEUE',e[e.SAY=2092]='SAY',e[e.WALKTRIGGER=2093]='WALKTRIGGER',e[e.SETTIMER=2094]='SETTIMER',e[e.SOFTTIMER=2095]='SOFTTIMER',e[e.SOUND_SYNTH=2096]='SOUND_SYNTH',e[e.SPOTANIM_PL=2097]='SPOTANIM_PL',e[e.STAFFMODLEVEL=2098]='STAFFMODLEVEL',e[e.STAT=2099]='STAT',e[e.STAT_ADD=2100]='STAT_ADD',e[e.STAT_BASE=2101]='STAT_BASE',e[e.STAT_HEAL=2102]='STAT_HEAL',e[e.STAT_SUB=2103]='STAT_SUB',e[e.STRONGQUEUE=2104]='STRONGQUEUE',e[e.UID=2105]='UID',e[e.WEAKQUEUE=2106]='WEAKQUEUE',e[e.IF_OPENMAINOVERLAY=2107]='IF_OPENMAINOVERLAY',e[e.AFK_EVENT=2108]='AFK_EVENT',e[e.LOWMEMORY=2109]='LOWMEMORY',e[e.SETIDKIT=2110]='SETIDKIT',e[e.P_CLEARPENDINGACTION=2111]='P_CLEARPENDINGACTION',e[e.GETWALKTRIGGER=2112]='GETWALKTRIGGER',e[e.BUSY2=2113]='BUSY2',e[e.FINDHERO=2114]='FINDHERO',e[e.BOTH_HEROPOINTS=2115]='BOTH_HEROPOINTS',e[e.SETGENDER=2116]='SETGENDER',e[e.SETSKINCOLOUR=2117]='SETSKINCOLOUR',e[e.P_ANIMPROTECT=2118]='P_ANIMPROTECT',e[e.RUNENERGY=2119]='RUNENERGY',e[e.WEIGHT=2120]='WEIGHT',e[e.LAST_COORD=2121]='LAST_COORD',e[e.NPC_ADD=2500]='NPC_ADD',e[e.NPC_ANIM=2501]='NPC_ANIM',e[e.NPC_BASESTAT=2502]='NPC_BASESTAT',e[e.NPC_CATEGORY=2503]='NPC_CATEGORY',e[e.NPC_CHANGETYPE=2504]='NPC_CHANGETYPE',e[e.NPC_COORD=2505]='NPC_COORD',e[e.NPC_DAMAGE=2506]='NPC_DAMAGE',e[e.NPC_DEL=2507]='NPC_DEL',e[e.NPC_DELAY=2508]='NPC_DELAY',e[e.NPC_FACESQUARE=2509]='NPC_FACESQUARE',e[e.NPC_FIND=2510]='NPC_FIND',e[e.NPC_FINDALLANY=2511]='NPC_FINDALLANY',e[e.NPC_FINDEXACT=2512]='NPC_FINDEXACT',e[e.NPC_FINDHERO=2513]='NPC_FINDHERO',e[e.NPC_FINDALLZONE=2514]='NPC_FINDALLZONE',e[e.NPC_FINDNEXT=2515]='NPC_FINDNEXT',e[e.NPC_FINDUID=2516]='NPC_FINDUID',e[e.NPC_GETMODE=2517]='NPC_GETMODE',e[e.NPC_HEROPOINTS=2518]='NPC_HEROPOINTS',e[e.NPC_NAME=2519]='NPC_NAME',e[e.NPC_PARAM=2520]='NPC_PARAM',e[e.NPC_QUEUE=2521]='NPC_QUEUE',e[e.NPC_RANGE=2522]='NPC_RANGE',e[e.NPC_SAY=2523]='NPC_SAY',e[e.NPC_HUNTALL=2524]='NPC_HUNTALL',e[e.NPC_HUNTNEXT=2525]='NPC_HUNTNEXT',e[e.NPC_SETHUNT=2526]='NPC_SETHUNT',e[e.NPC_SETHUNTMODE=2527]='NPC_SETHUNTMODE',e[e.NPC_SETMODE=2528]='NPC_SETMODE',e[e.NPC_WALKTRIGGER=2529]='NPC_WALKTRIGGER',e[e.NPC_SETTIMER=2530]='NPC_SETTIMER',e[e.NPC_STAT=2531]='NPC_STAT',e[e.NPC_STATADD=2532]='NPC_STATADD',e[e.NPC_STATHEAL=2533]='NPC_STATHEAL',e[e.NPC_STATSUB=2534]='NPC_STATSUB',e[e.NPC_TELE=2535]='NPC_TELE',e[e.NPC_TYPE=2536]='NPC_TYPE',e[e.NPC_UID=2537]='NPC_UID',e[e.SPOTANIM_NPC=2538]='SPOTANIM_NPC',e[e.NPC_WALK=2539]='NPC_WALK',e[e.NPC_ATTACKRANGE=2540]='NPC_ATTACKRANGE',e[e.LOC_ADD=3e3]='LOC_ADD',e[e.LOC_ANGLE=3001]='LOC_ANGLE',e[e.LOC_ANIM=3002]='LOC_ANIM',e[e.LOC_CATEGORY=3003]='LOC_CATEGORY',e[e.LOC_CHANGE=3004]='LOC_CHANGE',e[e.LOC_COORD=3005]='LOC_COORD',e[e.LOC_DEL=3006]='LOC_DEL',e[e.LOC_FIND=3007]='LOC_FIND',e[e.LOC_FINDALLZONE=3008]='LOC_FINDALLZONE',e[e.LOC_FINDNEXT=3009]='LOC_FINDNEXT',e[e.LOC_NAME=3010]='LOC_NAME',e[e.LOC_PARAM=3011]='LOC_PARAM',e[e.LOC_SHAPE=3012]='LOC_SHAPE',e[e.LOC_TYPE=3013]='LOC_TYPE',e[e.OBJ_ADD=3500]='OBJ_ADD',e[e.OBJ_ADDALL=3501]='OBJ_ADDALL',e[e.OBJ_COORD=3502]='OBJ_COORD',e[e.OBJ_COUNT=3503]='OBJ_COUNT',e[e.OBJ_DEL=3504]='OBJ_DEL',e[e.OBJ_NAME=3505]='OBJ_NAME',e[e.OBJ_PARAM=3506]='OBJ_PARAM',e[e.OBJ_TAKEITEM=3507]='OBJ_TAKEITEM',e[e.OBJ_TYPE=3508]='OBJ_TYPE',e[e.NC_CATEGORY=4e3]='NC_CATEGORY',e[e.NC_DEBUGNAME=4001]='NC_DEBUGNAME',e[e.NC_DESC=4002]='NC_DESC',e[e.NC_NAME=4003]='NC_NAME',e[e.NC_OP=4004]='NC_OP',e[e.NC_PARAM=4005]='NC_PARAM',e[e.LC_CATEGORY=4100]='LC_CATEGORY',e[e.LC_DEBUGNAME=4101]='LC_DEBUGNAME',e[e.LC_DESC=4102]='LC_DESC',e[e.LC_NAME=4103]='LC_NAME',e[e.LC_OP=4104]='LC_OP',e[e.LC_PARAM=4105]='LC_PARAM',e[e.LC_WIDTH=4106]='LC_WIDTH',e[e.LC_LENGTH=4107]='LC_LENGTH',e[e.OC_CATEGORY=4200]='OC_CATEGORY',e[e.OC_CERT=4201]='OC_CERT',e[e.OC_COST=4202]='OC_COST',e[e.OC_DEBUGNAME=4203]='OC_DEBUGNAME',e[e.OC_DESC=4204]='OC_DESC',e[e.OC_IOP=4205]='OC_IOP',e[e.OC_MEMBERS=4206]='OC_MEMBERS',e[e.OC_NAME=4207]='OC_NAME',e[e.OC_OP=4208]='OC_OP',e[e.OC_PARAM=4209]='OC_PARAM',e[e.OC_STACKABLE=4210]='OC_STACKABLE',e[e.OC_TRADEABLE=4211]='OC_TRADEABLE',e[e.OC_UNCERT=4212]='OC_UNCERT',e[e.OC_WEARPOS2=4213]='OC_WEARPOS2',e[e.OC_WEARPOS3=4214]='OC_WEARPOS3',e[e.OC_WEARPOS=4215]='OC_WEARPOS',e[e.OC_WEIGHT=4216]='OC_WEIGHT',e[e.INV_ALLSTOCK=4300]='INV_ALLSTOCK',e[e.INV_SIZE=4301]='INV_SIZE',e[e.INV_STOCKBASE=4302]='INV_STOCKBASE',e[e.INV_ADD=4303]='INV_ADD',e[e.INV_CHANGESLOT=4304]='INV_CHANGESLOT',e[e.INV_CLEAR=4305]='INV_CLEAR',e[e.INV_DEL=4306]='INV_DEL',e[e.INV_DELSLOT=4307]='INV_DELSLOT',e[e.INV_DROPITEM=4308]='INV_DROPITEM',e[e.INV_DROPSLOT=4309]='INV_DROPSLOT',e[e.INV_FREESPACE=4310]='INV_FREESPACE',e[e.INV_GETNUM=4311]='INV_GETNUM',e[e.INV_GETOBJ=4312]='INV_GETOBJ',e[e.INV_ITEMSPACE=4313]='INV_ITEMSPACE',e[e.INV_ITEMSPACE2=4314]='INV_ITEMSPACE2',e[e.INV_MOVEFROMSLOT=4315]='INV_MOVEFROMSLOT',e[e.INV_MOVETOSLOT=4316]='INV_MOVETOSLOT',e[e.BOTH_MOVEINV=4317]='BOTH_MOVEINV',e[e.INV_MOVEITEM=4318]='INV_MOVEITEM',e[e.INV_MOVEITEM_CERT=4319]='INV_MOVEITEM_CERT',e[e.INV_MOVEITEM_UNCERT=4320]='INV_MOVEITEM_UNCERT',e[e.INV_SETSLOT=4321]='INV_SETSLOT',e[e.INV_TOTAL=4322]='INV_TOTAL',e[e.INV_TOTALCAT=4323]='INV_TOTALCAT',e[e.INV_TRANSMIT=4324]='INV_TRANSMIT',e[e.INVOTHER_TRANSMIT=4325]='INVOTHER_TRANSMIT',e[e.INV_STOPTRANSMIT=4326]='INV_STOPTRANSMIT',e[e.BOTH_DROPSLOT=4327]='BOTH_DROPSLOT',e[e.INV_DROPALL=4328]='INV_DROPALL',e[e.INV_TOTALPARAM=4329]='INV_TOTALPARAM',e[e.INV_TOTALPARAM_STACK=4330]='INV_TOTALPARAM_STACK',e[e.ENUM=4400]='ENUM',e[e.ENUM_GETOUTPUTCOUNT=4401]='ENUM_GETOUTPUTCOUNT',e[e.APPEND_NUM=4500]='APPEND_NUM',e[e.APPEND=4501]='APPEND',e[e.APPEND_SIGNNUM=4502]='APPEND_SIGNNUM',e[e.LOWERCASE=4503]='LOWERCASE',e[e.TEXT_GENDER=4504]='TEXT_GENDER',e[e.TOSTRING=4505]='TOSTRING',e[e.COMPARE=4506]='COMPARE',e[e.TEXT_SWITCH=4507]='TEXT_SWITCH',e[e.APPEND_CHAR=4508]='APPEND_CHAR',e[e.STRING_LENGTH=4509]='STRING_LENGTH',e[e.SUBSTRING=4510]='SUBSTRING',e[e.STRING_INDEXOF_CHAR=4511]='STRING_INDEXOF_CHAR',e[e.STRING_INDEXOF_STRING=4512]='STRING_INDEXOF_STRING',e[e.ADD=4600]='ADD',e[e.SUB=4601]='SUB',e[e.MULTIPLY=4602]='MULTIPLY',e[e.DIVIDE=4603]='DIVIDE',e[e.RANDOM=4604]='RANDOM',e[e.RANDOMINC=4605]='RANDOMINC',e[e.INTERPOLATE=4606]='INTERPOLATE',e[e.ADDPERCENT=4607]='ADDPERCENT',e[e.SETBIT=4608]='SETBIT',e[e.CLEARBIT=4609]='CLEARBIT',e[e.TESTBIT=4610]='TESTBIT',e[e.MODULO=4611]='MODULO',e[e.POW=4612]='POW',e[e.INVPOW=4613]='INVPOW',e[e.AND=4614]='AND',e[e.OR=4615]='OR',e[e.MIN=4616]='MIN',e[e.MAX=4617]='MAX',e[e.SCALE=4618]='SCALE',e[e.BITCOUNT=4619]='BITCOUNT',e[e.TOGGLEBIT=4620]='TOGGLEBIT',e[e.SETBIT_RANGE=4621]='SETBIT_RANGE',e[e.CLEARBIT_RANGE=4622]='CLEARBIT_RANGE',e[e.GETBIT_RANGE=4623]='GETBIT_RANGE',e[e.SETBIT_RANGE_TOINT=4624]='SETBIT_RANGE_TOINT',e[e.SIN_DEG=4625]='SIN_DEG',e[e.COS_DEG=4626]='COS_DEG',e[e.ATAN2_DEG=4627]='ATAN2_DEG',e[e.ABS=4628]='ABS',e[e.DB_FIND_WITH_COUNT=7500]='DB_FIND_WITH_COUNT',e[e.DB_FINDNEXT=7501]='DB_FINDNEXT',e[e.DB_GETFIELD=7502]='DB_GETFIELD',e[e.DB_GETFIELDCOUNT=7503]='DB_GETFIELDCOUNT',e[e.DB_LISTALL_WITH_COUNT=7504]='DB_LISTALL_WITH_COUNT',e[e.DB_GETROWTABLE=7505]='DB_GETROWTABLE',e[e.DB_FINDBYINDEX=7506]='DB_FINDBYINDEX',e[e.DB_FIND_REFINE_WITH_COUNT=7507]='DB_FIND_REFINE_WITH_COUNT',e[e.DB_FIND=7508]='DB_FIND',e[e.DB_FIND_REFINE=7509]='DB_FIND_REFINE',e[e.DB_LISTALL=7510]='DB_LISTALL',e[e.ERROR=1e4]='ERROR',e[e.MAP_PRODUCTION=10001]='MAP_PRODUCTION',e[e.MAP_LASTCLOCK=10002]='MAP_LASTCLOCK',e[e.MAP_LASTWORLD=10003]='MAP_LASTWORLD',e[e.MAP_LASTCLIENTIN=10004]='MAP_LASTCLIENTIN',e[e.MAP_LASTNPC=10005]='MAP_LASTNPC',e[e.MAP_LASTPLAYER=10006]='MAP_LASTPLAYER',e[e.MAP_LASTLOGOUT=10007]='MAP_LASTLOGOUT',e[e.MAP_LASTLOGIN=10008]='MAP_LASTLOGIN',e[e.MAP_LASTZONE=10009]='MAP_LASTZONE',e[e.MAP_LASTCLIENTOUT=10010]='MAP_LASTCLIENTOUT',e[e.MAP_LASTCLEANUP=10011]='MAP_LASTCLEANUP',e[e.MAP_LASTBANDWIDTHIN=10012]='MAP_LASTBANDWIDTHIN',e[e.MAP_LASTBANDWIDTHOUT=10013]='MAP_LASTBANDWIDTHOUT',e))(Wt||{}),Kt=Wt,zt=class e{info={scriptName:'',sourceFilePath:'',lookupKey:-1,parameterTypes:[],pcs:[],lines:[]};id;intLocalCount=0;stringLocalCount=0;intArgCount=0;stringArgCount=0;switchTables=[];opcodes=[];intOperands=[];stringOperands=[];static isLargeOperand(e){if(e>100)return!1;switch(e){case Kt.RETURN:case Kt.POP_INT_DISCARD:case Kt.POP_STRING_DISCARD:case Kt.GOSUB:case Kt.JUMP:return!1}return!0}static decode(t,i){const r=i.data.length;if(r<16)throw new Error('Invalid script file (minimum length)');i.pos=r-2;const s=r-i.g2()-12-2;if(s<0||s>=r)throw new Error('Invalid script file (bad trailer pos)');i.pos=s;const n=new e(t);i.g4();n.intLocalCount=i.g2(),n.stringLocalCount=i.g2(),n.intArgCount=i.g2(),n.stringArgCount=i.g2();const a=i.g1();for(let e=0;ei.pos;){const t=i.g2();t===Kt.PUSH_CONSTANT_STRING?n.stringOperands[l]=i.gjstr(0):e.isLargeOperand(t)?n.intOperands[l]=i.g4():n.intOperands[l]=i.g1(),n.opcodes[l++]=t}return n}constructor(e){this.id=e}get name(){return this.info.scriptName}get fileName(){return path2.basename(this.info.sourceFilePath)}lineNumber(e){for(let t=0;te)return this.info.lines[t-1];return this.info.lines[this.info.lines.length-1]}},jt=class e{static COMPILER_VERSION=18;static scripts=[];static scriptLookup=new Map;static scriptNames=new Map;static load(e){const t=Oe.load(`${e}/server/script.dat`),i=Oe.load(`${e}/server/script.idx`);return this.parse(t,i)}static async loadAsync(e){const t=await Oe.loadAsync(`${e}/server/script.dat`),i=await Oe.loadAsync(`${e}/server/script.idx`);return this.parse(t,i)}static parse(t,i){t.data.length&&i.data.length||(console.log('\nFatal: No script.dat or script.idx found. Please run the server:build script.'),process.exit(1));const r=t.g2();i.pos+=2;t.g4()!==e.COMPILER_VERSION&&(console.error('\nFatal: Scripts were compiled with an older RuneScript compiler. Please update it, try `npm run build` and then restart the server.'),process.exit(1));const s=new Array(r),n=new Map,a=new Map;let o=0;for(let e=0;e=0;i--)t[i]=this.popInt();return t}pushInt(e){this.intStack[this.isp++]=qt(e)}popString(){return this.stringStack[--this.ssp]??''}popStrings(e){const t=Array(e);for(let i=e-1;i>=0;i--)t[i]=this.popString();return t}pushString(e){this.stringStack[this.ssp++]=e}reset(){this.pc=-1,this.frames=[],this.fp=0,this.intStack=[],this.isp=0,this.stringStack=[],this.ssp=0,this.intLocals=[],this.stringLocals=[],this.pointers=0}},Zt=class{requested=0;completed=0;items=[];constructor(e,t=0,i=[]){this.requested=e,this.completed=t,this.items=i}getLeftOver(){return this.requested-this.completed}hasSucceeded(){return this.completed==this.requested}hasFailed(){return!this.hasSucceeded()}revert(e){for(let t=0;tt&&t.id==e))}hasAt(e,t){const i=this.items[e];return i&&i.id==t}get nextFreeSlot(){return this.items.indexOf(null,0)}get freeSlotCount(){return this.items.filter((e=>null==e)).length}get occupiedSlotCount(){return this.items.filter((e=>null!=e)).length}get isFull(){return this.occupiedSlotCount==this.capacity}get isEmpty(){return 0==this.occupiedSlotCount}get hasAny(){return this.items.some((e=>null!=e))}get hasSpace(){return-1!=this.nextFreeSlot}get itemsFiltered(){return this.items.filter((e=>null!=e))}getItemCount(t){let i=0;for(let e=0;et&&t.id==e))}removeAll(){this.items.fill(null,0,this.capacity),this.update=!0}add(t,i=1,r=-1,s=!0,n=!1,a=!1){const o=Tt.get(t),c=!0===it.get(this.type).stockobj?.includes(t),l=!n&&this.stackType!=e.NEVER_STACK&&(o.stackable||this.stackType==e.ALWAYS_STACK);let h=0;if(l&&(h=this.getItemCount(t)),h==e.STACK_LIMIT)return new Zt(i,0,[]);const d=this.freeSlotCount;if(0==d&&(!l||l&&0==h&&!c))return new Zt(i,0,[]);if(s){if(l&&h>e.STACK_LIMIT-i)return new Zt(i,0,[]);if(!l&&i>d)return new Zt(i,0,[])}else{if(l&&h==e.STACK_LIMIT)return new Zt(i,0,[]);if(!l&&0==d)return new Zt(i,0,[])}let u=0;const p=[];if(l){let s=this.getItemIndex(t);if(-1==s&&(s=-1==r?this.nextFreeSlot:this.items.indexOf(null,r),-1==s))return new Zt(i,u,[]);const n=this.get(s)?.count??0,o=Math.min(e.STACK_LIMIT,n+i),c={id:t,count:o};a||this.set(s,c),p.push({slot:s,item:c}),u=o-n}else{for(let e=Math.max(0,r);e=i)break}}return new Zt(i,u,p)}remove(e,t=1,i=-1,r=!1){const s=this.getItemCount(e),n=!0===it.get(this.type).stockobj?.includes(e);if(r&&s=t)break}if(null!=c&&a=t)break}return a>0&&(this.update=!0),new Zt(t,a,o)}delete(e){this.items[e]=null,this.update=!0}swap(e,t){const i=this.items[e];this.set(e,this.items[t]),this.set(t,i)}shift(){this.items.sort(((e,t)=>null===e||null===t?+(null===e)-+(null===t):+(e>t)||-(e=0&&e=0)&&(c={id:o.certlink,count:a});const l=e.add(c.id,c.count,r,!1);if(0==l.completed)return null;const h=this.remove(t.id,l.completed,i,!1);return 0==h.completed?null:h}};async function Jt(e,t={}){const i={env:Object.assign(Object.create(globalThis),t.env||{},{abort(e,t,i,r){e=o(e>>>0),t=o(t>>>0),i>>>=0,r>>>=0,(()=>{throw Error(`${e} in ${t}:${i}:${r}`)})()},seed:()=>Date.now()*Math.random()})},{exports:r}=await WebAssembly.instantiate(e,i),s=r.memory||t.env.memory,n=Object.setPrototypeOf({findPath(e,t,i,s,n,a,o,l,d,u,p,f,g,m){return p=p?1:0,r.__setArgumentsLength(arguments.length),c(h,2,r.findPath(e,t,i,s,n,a,o,l,d,u,p,f,g,m)>>>0)},findNaivePath(e,t,i,s,n,a,o,l,d,u,p){return r.__setArgumentsLength(arguments.length),c(h,2,r.findNaivePath(e,t,i,s,n,a,o,l,d,u,p)>>>0)},changeFloor(e,t,i,s){s=s?1:0,r.changeFloor(e,t,i,s)},changeLoc(e,t,i,s,n,a,o,c){a=a?1:0,o=o?1:0,c=c?1:0,r.changeLoc(e,t,i,s,n,a,o,c)},changeNpc(e,t,i,s,n){n=n?1:0,r.changeNpc(e,t,i,s,n)},changePlayer(e,t,i,s,n){n=n?1:0,r.changePlayer(e,t,i,s,n)},changeRoof(e,t,i,s){s=s?1:0,r.changeRoof(e,t,i,s)},changeWall(e,t,i,s,n,a,o,c){a=a?1:0,o=o?1:0,c=c?1:0,r.changeWall(e,t,i,s,n,a,o,c)},allocateIfAbsent:(e,t,i)=>c(h,2,r.allocateIfAbsent(e,t,i)>>>0),isZoneAllocated:(e,t,i)=>0!=r.isZoneAllocated(e,t,i),isFlagged:(e,t,i,s)=>0!=r.isFlagged(e,t,i,s),canTravel(e,t,i,s,n,a,o,c){return r.__setArgumentsLength(arguments.length),0!=r.canTravel(e,t,i,s,n,a,o,c)},hasLineOfSight(e,t,i,s,n,a,o,c,l,h){return r.__setArgumentsLength(arguments.length),0!=r.hasLineOfSight(e,t,i,s,n,a,o,c,l,h)},hasLineOfWalk(e,t,i,s,n,a,o,c,l,h){return r.__setArgumentsLength(arguments.length),0!=r.hasLineOfWalk(e,t,i,s,n,a,o,c,l,h)},lineOfSight(e,t,i,s,n,a,o,l,d,u){return r.__setArgumentsLength(arguments.length),c(h,2,r.lineOfSight(e,t,i,s,n,a,o,l,d,u)>>>0)},lineOfWalk(e,t,i,s,n,a,o,l,d,u){return r.__setArgumentsLength(arguments.length),c(h,2,r.lineOfWalk(e,t,i,s,n,a,o,l,d,u)>>>0)},reached(e,t,i,s,n,a,o,c,l,h,d){return r.__setArgumentsLength(arguments.length),0!=r.reached(e,t,i,s,n,a,o,c,l,h,d)},__collides:(e,t,i,s,n,a,o,c)=>0!=r.__collides(e,t,i,s,n,a,o,c),__reachRectangle1:(e,t,i,s,n,a,o,c)=>0!=r.__reachRectangle1(e,t,i,s,n,a,o,c),__reachRectangleN:(e,t,i,s,n,a,o,c,l,h)=>0!=r.__reachRectangleN(e,t,i,s,n,a,o,c,l,h),__reachRectangle:(e,t,i,s,n,a,o,c,l,h)=>0!=r.__reachRectangle(e,t,i,s,n,a,o,c,l,h),__reachExclusiveRectangle:(e,t,i,s,n,a,o,c,l,h)=>0!=r.__reachExclusiveRectangle(e,t,i,s,n,a,o,c,l,h),CollisionFlag:(a={},a[a.NULL=r['CollisionFlag.NULL'].valueOf()]='NULL',a[a.OPEN=r['CollisionFlag.OPEN'].valueOf()]='OPEN',a[a.WALL_NORTH_WEST=r['CollisionFlag.WALL_NORTH_WEST'].valueOf()]='WALL_NORTH_WEST',a[a.WALL_NORTH=r['CollisionFlag.WALL_NORTH'].valueOf()]='WALL_NORTH',a[a.WALL_NORTH_EAST=r['CollisionFlag.WALL_NORTH_EAST'].valueOf()]='WALL_NORTH_EAST',a[a.WALL_EAST=r['CollisionFlag.WALL_EAST'].valueOf()]='WALL_EAST',a[a.WALL_SOUTH_EAST=r['CollisionFlag.WALL_SOUTH_EAST'].valueOf()]='WALL_SOUTH_EAST',a[a.WALL_SOUTH=r['CollisionFlag.WALL_SOUTH'].valueOf()]='WALL_SOUTH',a[a.WALL_SOUTH_WEST=r['CollisionFlag.WALL_SOUTH_WEST'].valueOf()]='WALL_SOUTH_WEST',a[a.WALL_WEST=r['CollisionFlag.WALL_WEST'].valueOf()]='WALL_WEST',a[a.LOC=r['CollisionFlag.LOC'].valueOf()]='LOC',a[a.WALL_NORTH_WEST_PROJ_BLOCKER=r['CollisionFlag.WALL_NORTH_WEST_PROJ_BLOCKER'].valueOf()]='WALL_NORTH_WEST_PROJ_BLOCKER',a[a.WALL_NORTH_PROJ_BLOCKER=r['CollisionFlag.WALL_NORTH_PROJ_BLOCKER'].valueOf()]='WALL_NORTH_PROJ_BLOCKER',a[a.WALL_NORTH_EAST_PROJ_BLOCKER=r['CollisionFlag.WALL_NORTH_EAST_PROJ_BLOCKER'].valueOf()]='WALL_NORTH_EAST_PROJ_BLOCKER',a[a.WALL_EAST_PROJ_BLOCKER=r['CollisionFlag.WALL_EAST_PROJ_BLOCKER'].valueOf()]='WALL_EAST_PROJ_BLOCKER',a[a.WALL_SOUTH_EAST_PROJ_BLOCKER=r['CollisionFlag.WALL_SOUTH_EAST_PROJ_BLOCKER'].valueOf()]='WALL_SOUTH_EAST_PROJ_BLOCKER',a[a.WALL_SOUTH_PROJ_BLOCKER=r['CollisionFlag.WALL_SOUTH_PROJ_BLOCKER'].valueOf()]='WALL_SOUTH_PROJ_BLOCKER',a[a.WALL_SOUTH_WEST_PROJ_BLOCKER=r['CollisionFlag.WALL_SOUTH_WEST_PROJ_BLOCKER'].valueOf()]='WALL_SOUTH_WEST_PROJ_BLOCKER',a[a.WALL_WEST_PROJ_BLOCKER=r['CollisionFlag.WALL_WEST_PROJ_BLOCKER'].valueOf()]='WALL_WEST_PROJ_BLOCKER',a[a.LOC_PROJ_BLOCKER=r['CollisionFlag.LOC_PROJ_BLOCKER'].valueOf()]='LOC_PROJ_BLOCKER',a[a.FLOOR_DECORATION=r['CollisionFlag.FLOOR_DECORATION'].valueOf()]='FLOOR_DECORATION',a[a.NPC=r['CollisionFlag.NPC'].valueOf()]='NPC',a[a.PLAYER=r['CollisionFlag.PLAYER'].valueOf()]='PLAYER',a[a.FLOOR=r['CollisionFlag.FLOOR'].valueOf()]='FLOOR',a[a.WALL_NORTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.WALL_NORTH_WEST_ROUTE_BLOCKER'].valueOf()]='WALL_NORTH_WEST_ROUTE_BLOCKER',a[a.WALL_NORTH_ROUTE_BLOCKER=r['CollisionFlag.WALL_NORTH_ROUTE_BLOCKER'].valueOf()]='WALL_NORTH_ROUTE_BLOCKER',a[a.WALL_NORTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.WALL_NORTH_EAST_ROUTE_BLOCKER'].valueOf()]='WALL_NORTH_EAST_ROUTE_BLOCKER',a[a.WALL_EAST_ROUTE_BLOCKER=r['CollisionFlag.WALL_EAST_ROUTE_BLOCKER'].valueOf()]='WALL_EAST_ROUTE_BLOCKER',a[a.WALL_SOUTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.WALL_SOUTH_EAST_ROUTE_BLOCKER'].valueOf()]='WALL_SOUTH_EAST_ROUTE_BLOCKER',a[a.WALL_SOUTH_ROUTE_BLOCKER=r['CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER'].valueOf()]='WALL_SOUTH_ROUTE_BLOCKER',a[a.WALL_SOUTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.WALL_SOUTH_WEST_ROUTE_BLOCKER'].valueOf()]='WALL_SOUTH_WEST_ROUTE_BLOCKER',a[a.WALL_WEST_ROUTE_BLOCKER=r['CollisionFlag.WALL_WEST_ROUTE_BLOCKER'].valueOf()]='WALL_WEST_ROUTE_BLOCKER',a[a.LOC_ROUTE_BLOCKER=r['CollisionFlag.LOC_ROUTE_BLOCKER'].valueOf()]='LOC_ROUTE_BLOCKER',a[a.ROOF=r['CollisionFlag.ROOF'].valueOf()]='ROOF',a[a.FLOOR_BLOCKED=r['CollisionFlag.FLOOR_BLOCKED'].valueOf()]='FLOOR_BLOCKED',a[a.WALK_BLOCKED=r['CollisionFlag.WALK_BLOCKED'].valueOf()]='WALK_BLOCKED',a[a.BLOCK_WEST=r['CollisionFlag.BLOCK_WEST'].valueOf()]='BLOCK_WEST',a[a.BLOCK_EAST=r['CollisionFlag.BLOCK_EAST'].valueOf()]='BLOCK_EAST',a[a.BLOCK_SOUTH=r['CollisionFlag.BLOCK_SOUTH'].valueOf()]='BLOCK_SOUTH',a[a.BLOCK_NORTH=r['CollisionFlag.BLOCK_NORTH'].valueOf()]='BLOCK_NORTH',a[a.BLOCK_SOUTH_WEST=r['CollisionFlag.BLOCK_SOUTH_WEST'].valueOf()]='BLOCK_SOUTH_WEST',a[a.BLOCK_SOUTH_EAST=r['CollisionFlag.BLOCK_SOUTH_EAST'].valueOf()]='BLOCK_SOUTH_EAST',a[a.BLOCK_NORTH_WEST=r['CollisionFlag.BLOCK_NORTH_WEST'].valueOf()]='BLOCK_NORTH_WEST',a[a.BLOCK_NORTH_EAST=r['CollisionFlag.BLOCK_NORTH_EAST'].valueOf()]='BLOCK_NORTH_EAST',a[a.BLOCK_NORTH_AND_SOUTH_EAST=r['CollisionFlag.BLOCK_NORTH_AND_SOUTH_EAST'].valueOf()]='BLOCK_NORTH_AND_SOUTH_EAST',a[a.BLOCK_NORTH_AND_SOUTH_WEST=r['CollisionFlag.BLOCK_NORTH_AND_SOUTH_WEST'].valueOf()]='BLOCK_NORTH_AND_SOUTH_WEST',a[a.BLOCK_NORTH_EAST_AND_WEST=r['CollisionFlag.BLOCK_NORTH_EAST_AND_WEST'].valueOf()]='BLOCK_NORTH_EAST_AND_WEST',a[a.BLOCK_SOUTH_EAST_AND_WEST=r['CollisionFlag.BLOCK_SOUTH_EAST_AND_WEST'].valueOf()]='BLOCK_SOUTH_EAST_AND_WEST',a[a.BLOCK_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_WEST_ROUTE_BLOCKER',a[a.BLOCK_EAST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_EAST_ROUTE_BLOCKER'].valueOf()]='BLOCK_EAST_ROUTE_BLOCKER',a[a.BLOCK_SOUTH_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_SOUTH_ROUTE_BLOCKER'].valueOf()]='BLOCK_SOUTH_ROUTE_BLOCKER',a[a.BLOCK_NORTH_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_ROUTE_BLOCKER',a[a.BLOCK_SOUTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_SOUTH_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_SOUTH_WEST_ROUTE_BLOCKER',a[a.BLOCK_SOUTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_SOUTH_EAST_ROUTE_BLOCKER'].valueOf()]='BLOCK_SOUTH_EAST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_WEST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_EAST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_EAST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_AND_SOUTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_AND_SOUTH_EAST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_AND_SOUTH_EAST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_AND_SOUTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_AND_SOUTH_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_AND_SOUTH_WEST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_EAST_AND_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_EAST_AND_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_EAST_AND_WEST_ROUTE_BLOCKER',a[a.BLOCK_SOUTH_EAST_AND_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_SOUTH_EAST_AND_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_SOUTH_EAST_AND_WEST_ROUTE_BLOCKER',a),LocShape:(e=>(e[e.WALL_STRAIGHT=r['LocShape.WALL_STRAIGHT'].valueOf()]='WALL_STRAIGHT',e[e.WALL_DIAGONAL_CORNER=r['LocShape.WALL_DIAGONAL_CORNER'].valueOf()]='WALL_DIAGONAL_CORNER',e[e.WALL_L=r['LocShape.WALL_L'].valueOf()]='WALL_L',e[e.WALL_SQUARE_CORNER=r['LocShape.WALL_SQUARE_CORNER'].valueOf()]='WALL_SQUARE_CORNER',e[e.WALLDECOR_STRAIGHT_NOOFFSET=r['LocShape.WALLDECOR_STRAIGHT_NOOFFSET'].valueOf()]='WALLDECOR_STRAIGHT_NOOFFSET',e[e.WALLDECOR_STRAIGHT_OFFSET=r['LocShape.WALLDECOR_STRAIGHT_OFFSET'].valueOf()]='WALLDECOR_STRAIGHT_OFFSET',e[e.WALLDECOR_DIAGONAL_OFFSET=r['LocShape.WALLDECOR_DIAGONAL_OFFSET'].valueOf()]='WALLDECOR_DIAGONAL_OFFSET',e[e.WALLDECOR_DIAGONAL_NOOFFSET=r['LocShape.WALLDECOR_DIAGONAL_NOOFFSET'].valueOf()]='WALLDECOR_DIAGONAL_NOOFFSET',e[e.WALLDECOR_DIAGONAL_BOTH=r['LocShape.WALLDECOR_DIAGONAL_BOTH'].valueOf()]='WALLDECOR_DIAGONAL_BOTH',e[e.WALL_DIAGONAL=r['LocShape.WALL_DIAGONAL'].valueOf()]='WALL_DIAGONAL',e[e.CENTREPIECE_STRAIGHT=r['LocShape.CENTREPIECE_STRAIGHT'].valueOf()]='CENTREPIECE_STRAIGHT',e[e.CENTREPIECE_DIAGONAL=r['LocShape.CENTREPIECE_DIAGONAL'].valueOf()]='CENTREPIECE_DIAGONAL',e[e.ROOF_STRAIGHT=r['LocShape.ROOF_STRAIGHT'].valueOf()]='ROOF_STRAIGHT',e[e.ROOF_DIAGONAL_WITH_ROOFEDGE=r['LocShape.ROOF_DIAGONAL_WITH_ROOFEDGE'].valueOf()]='ROOF_DIAGONAL_WITH_ROOFEDGE',e[e.ROOF_DIAGONAL=r['LocShape.ROOF_DIAGONAL'].valueOf()]='ROOF_DIAGONAL',e[e.ROOF_L_CONCAVE=r['LocShape.ROOF_L_CONCAVE'].valueOf()]='ROOF_L_CONCAVE',e[e.ROOF_L_CONVEX=r['LocShape.ROOF_L_CONVEX'].valueOf()]='ROOF_L_CONVEX',e[e.ROOF_FLAT=r['LocShape.ROOF_FLAT'].valueOf()]='ROOF_FLAT',e[e.ROOFEDGE_STRAIGHT=r['LocShape.ROOFEDGE_STRAIGHT'].valueOf()]='ROOFEDGE_STRAIGHT',e[e.ROOFEDGE_DIAGONAL_CORNER=r['LocShape.ROOFEDGE_DIAGONAL_CORNER'].valueOf()]='ROOFEDGE_DIAGONAL_CORNER',e[e.ROOFEDGE_L=r['LocShape.ROOFEDGE_L'].valueOf()]='ROOFEDGE_L',e[e.ROOFEDGE_SQUARE_CORNER=r['LocShape.ROOFEDGE_SQUARE_CORNER'].valueOf()]='ROOFEDGE_SQUARE_CORNER',e[e.GROUND_DECOR=r['LocShape.GROUND_DECOR'].valueOf()]='GROUND_DECOR',e))({}),LocAngle:(e=>(e[e.WEST=r['LocAngle.WEST'].valueOf()]='WEST',e[e.NORTH=r['LocAngle.NORTH'].valueOf()]='NORTH',e[e.EAST=r['LocAngle.EAST'].valueOf()]='EAST',e[e.SOUTH=r['LocAngle.SOUTH'].valueOf()]='SOUTH',e))({}),CollisionType:(e=>(e[e.NORMAL=r['CollisionType.NORMAL'].valueOf()]='NORMAL',e[e.BLOCKED=r['CollisionType.BLOCKED'].valueOf()]='BLOCKED',e[e.INDOORS=r['CollisionType.INDOORS'].valueOf()]='INDOORS',e[e.OUTDOORS=r['CollisionType.OUTDOORS'].valueOf()]='OUTDOORS',e[e.LINE_OF_SIGHT=r['CollisionType.LINE_OF_SIGHT'].valueOf()]='LINE_OF_SIGHT',e))({}),LocLayer:(e=>(e[e.WALL=r['LocLayer.WALL'].valueOf()]='WALL',e[e.WALL_DECOR=r['LocLayer.WALL_DECOR'].valueOf()]='WALL_DECOR',e[e.GROUND=r['LocLayer.GROUND'].valueOf()]='GROUND',e[e.GROUND_DECOR=r['LocLayer.GROUND_DECOR'].valueOf()]='GROUND_DECOR',e))({}),BlockAccessFlag:(e=>(e[e.BLOCK_NORTH=r['BlockAccessFlag.BLOCK_NORTH'].valueOf()]='BLOCK_NORTH',e[e.BLOCK_EAST=r['BlockAccessFlag.BLOCK_EAST'].valueOf()]='BLOCK_EAST',e[e.BLOCK_SOUTH=r['BlockAccessFlag.BLOCK_SOUTH'].valueOf()]='BLOCK_SOUTH',e[e.BLOCK_WEST=r['BlockAccessFlag.BLOCK_WEST'].valueOf()]='BLOCK_WEST',e))({})},r);var a;function o(e){if(!e)return null;const t=e+new Uint32Array(s.buffer)[e-4>>>2]>>>1,i=new Uint16Array(s.buffer);let r=e>>>1,n='';for(;t-r>1024;)n+=String.fromCharCode(...i.subarray(r,r+=1024));return n+String.fromCharCode(...i.subarray(r,t))}function c(e,t,i){if(!i)return null;const r=function(e){try{return l.getUint32(e,!0)}catch{return l=new DataView(s.buffer),l.getUint32(e,!0)}}(i-4)>>>t,n=new Array(r);for(let s=0;s>>0));return n}let l=new DataView(s.buffer);function h(e){try{return l.getInt32(e,!0)}catch{return l=new DataView(s.buffer),l.getInt32(e,!0)}}return n}var{memory:ei,findPath:ti,findNaivePath:ii,changeFloor:ri,changeLoc:si,changeNpc:ni,changePlayer:ai,changeRoof:oi,changeWall:ci,allocateIfAbsent:li,deallocateIfPresent:hi,isZoneAllocated:di,isFlagged:ui,canTravel:pi,hasLineOfSight:fi,hasLineOfWalk:gi,lineOfSight:mi,lineOfWalk:yi,reached:Ei,locShapeLayer:_i,__get:Ai,__set:vi,__add:Ti,__remove:Ci,__rotate:Ii,__rotateFlags:Si,__collides:Oi,__reachRectangle1:Ni,__reachRectangleN:Li,__alteredRotation:Pi,__reachRectangle:wi,__reachExclusiveRectangle:bi,CollisionFlag:Ri,LocShape:Bi,LocAngle:Ui,CollisionType:Di,LocLayer:ki,BlockAccessFlag:Mi}=await(async e=>Jt(await(async()=>{try{return await globalThis.WebAssembly.compileStreaming(globalThis.fetch(e))}catch{return globalThis.WebAssembly.compile(await(await import('node:fs/promises')).readFile(e))}})(),{}))(new URL('rsmod-pathfinder.wasm',import.meta.url)),xi=0,Fi=1,Hi=2,Vi=3,Gi=4,Wi=5,Ki=6,zi=7,ji={zone:e=>e>>3,zoneCenter:e=>ji.zone(e)-6,zoneOrigin:e=>ji.zoneCenter(e)<<3,mapsquare:e=>e>>6,local:(e,t)=>e-(ji.zoneCenter(t)<<3),face:(e,t,i,r)=>e!=i?e>i?t>r?Wi:tr?zi:tr?Ki:te+ji.deltaX(t),moveZ:(e,t)=>e+ji.deltaZ(t),distanceTo(e,t){const i=ji.closest(e,t),r=ji.closest(t,e);return Math.max(Math.abs(i.x-r.x),Math.abs(i.z-r.z))},closest(e,t){const i=e.x+e.width-1,r=e.z+e.length-1;return{x:t.x<=e.x?e.x:t.x>=i?i:t.x,z:t.z<=e.z?e.z:t.z>=r?r:t.z}},distanceToSW(e,t){const i=Math.abs(e.x-t.x),r=Math.abs(e.z-t.z);return Math.max(i,r)},isWithinDistanceSW:(e,t,i)=>!(Math.abs(e.x-t.x)>i||Math.abs(e.z-t.z)>i),deltaX(e){switch(e){case zi:case Hi:case Gi:return 1;case Wi:case xi:case Vi:return-1}return 0},deltaZ(e){switch(e){case xi:case Hi:case Fi:return 1;case Wi:case zi:case Ki:return-1}return 0},unpackCoord:e=>({level:e>>28&3,x:e>>14&16383,z:16383&e}),packCoord:(e,t,i)=>16383&i|(16383&t)<<14|(3&e)<<28,packZoneCoord:(e,t)=>(7&e)<<4|7&t,intersects:(e,t,i,r,s,n,a,o)=>!(s>=e+i||s+a<=e||n>=t+r||n+o<=t),formatString:(e,t,i,r="_")=>e+r+(t>>6)+r+(i>>6)+r+(63&t)+r+(63&i)},Yi=(e=>(e[e.BLOCK=0]='BLOCK',e[e.DAMAGE=1]='DAMAGE',e[e.POISON=2]='POISON',e))(Yi||{}),qi=Yi,Qi=(e=>(e[e.ATTACK=0]='ATTACK',e[e.DEFENCE=1]='DEFENCE',e[e.STRENGTH=2]='STRENGTH',e[e.HITPOINTS=3]='HITPOINTS',e[e.RANGED=4]='RANGED',e[e.PRAYER=5]='PRAYER',e[e.MAGIC=6]='MAGIC',e[e.COOKING=7]='COOKING',e[e.WOODCUTTING=8]='WOODCUTTING',e[e.FLETCHING=9]='FLETCHING',e[e.FISHING=10]='FISHING',e[e.FIREMAKING=11]='FIREMAKING',e[e.CRAFTING=12]='CRAFTING',e[e.SMITHING=13]='SMITHING',e[e.MINING=14]='MINING',e[e.HERBLORE=15]='HERBLORE',e[e.AGILITY=16]='AGILITY',e[e.THIEVING=17]='THIEVING',e[e.STAT18=18]='STAT18',e[e.STAT19=19]='STAT19',e[e.RUNECRAFT=20]='RUNECRAFT',e))(Qi||{}),$i=Qi,Zi=class{type;count;name;constructor(e,t,i){this.type=e,this.count=t,this.name=i}validate(e){if(this.count(e))return this.type(e);throw new Error(`An input for a ${this.name} type was not valid to use. Input was ${e}.`)}},Xi=class{min;max;name;constructor(e,t,i){this.min=e,this.max=t,this.name=i}validate(e){if(e>=this.min&&e<=this.max)return e;throw new Error(`An input for a ${this.name} was out of range. Range should be: ${this.min} to ${this.max}. Input was ${e}.`)}},Ji=new class{validate(e){if(-1!==e)return e;throw Error('An input number was null(-1).')}},er=new class{validate(e){if(e.length>0)return e;throw Error('An input string was null(-1).')}},tr=new Zi(at.get,(e=>e>=0&&e=this.min&&e<=this.max)return ji.unpackCoord(e);throw new Error(`An input for a ${this.name} was out of range. Range should be: ${this.min} to ${this.max}. Input was ${e}.`)}}(0,2147483647,'Coord'),ar=new Zi(gt.get,(e=>e>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&e=50)throw new Error('stack overflow');e.frames[e.fp++]={script:e.script,pc:e.pc,intLocals:e.intLocals,stringLocals:e.stringLocals};const i=jt.get(t);if(!i)throw new Error(`unable to find proc ${i}`);kr(e,i)}function Dr(e,t){const i=jt.get(t);if(!i)throw new Error(`unable to find label ${t}`);e.debugFrames[e.debugFp++]={script:e.script,pc:e.pc},kr(e,i),e.fp=0,e.frames=[]}function kr(e,t){e.script=t,e.pc=-1,e.intLocals=e.popInts(t.intArgCount),e.stringLocals=e.popStrings(t.stringArgCount)}var Mr,xr={[Kt.PUSH_CONSTANT_INT]:e=>{e.pushInt(e.intOperand)},[Kt.PUSH_CONSTANT_STRING]:e=>{e.pushString(e.stringOperand)},[Kt.PUSH_VARP]:e=>{const t=e.intOperand>>16&1;if(t&&!e._activePlayer2)throw new Error('No secondary active_player.');if(!t&&!e._activePlayer)throw new Error('No active_player.');const i=Br(65535&e.intOperand,Cr);i.type===Pe.STRING?e.pushString(t?e._activePlayer2.getVar(i.id):e._activePlayer.getVar(i.id)):e.pushInt(t?e._activePlayer2.getVar(i.id):e._activePlayer.getVar(i.id))},[Kt.POP_VARP]:e=>{const t=e.intOperand>>16&1;if(t&&!e._activePlayer2)throw new Error('No secondary active_player.');if(!t&&!e._activePlayer)throw new Error('No active_player.');const i=Br(65535&e.intOperand,Cr);if(!e.pointerGet(Ht[t])&&i.protect)throw new Error(`%${i.debugname} requires protected access`);if(i.type===Pe.STRING){const r=e.popString();t?e._activePlayer2.setVar(i.id,r):e._activePlayer.setVar(i.id,r)}else{const r=e.popInt();t?e._activePlayer2.setVar(i.id,r):e._activePlayer.setVar(i.id,r)}},[Kt.PUSH_VARN]:e=>{const t=e.intOperand>>16&1;if(t&&!e._activeNpc2)throw new Error('No secondary active_npc.');if(!t&&!e._activeNpc)throw new Error('No active_npc.');const i=Br(65535&e.intOperand,Ir);i.type===Pe.STRING?e.pushString(t?e._activeNpc2.getVar(i.id):e._activeNpc.getVar(i.id)):e.pushInt(t?e._activeNpc2.getVar(i.id):e._activeNpc.getVar(i.id))},[Kt.POP_VARN]:e=>{const t=e.intOperand>>16&1;if(t&&!e._activeNpc2)throw new Error('No secondary active_npc.');if(!t&&!e._activeNpc)throw new Error('No active_npc.');const i=Br(65535&e.intOperand,Ir);if(i.type===Pe.STRING){const r=e.popInt();t?e._activeNpc2.setVar(i.id,r):e._activeNpc.setVar(i.id,r)}else{const r=e.popInt();t?e._activeNpc2.setVar(i.id,r):e._activeNpc.setVar(i.id,r)}},[Kt.PUSH_INT_LOCAL]:e=>{e.pushInt(e.intLocals[e.intOperand])},[Kt.POP_INT_LOCAL]:e=>{e.intLocals[e.intOperand]=e.popInt()},[Kt.PUSH_STRING_LOCAL]:e=>{e.pushString(e.stringLocals[e.intOperand])},[Kt.POP_STRING_LOCAL]:e=>{e.stringLocals[e.intOperand]=e.popString()},[Kt.BRANCH]:e=>{e.pc+=e.intOperand},[Kt.BRANCH_NOT]:e=>{const t=e.popInt();e.popInt()!==t&&(e.pc+=e.intOperand)},[Kt.BRANCH_EQUALS]:e=>{const t=e.popInt();e.popInt()===t&&(e.pc+=e.intOperand)},[Kt.BRANCH_LESS_THAN]:e=>{const t=e.popInt();e.popInt(){const t=e.popInt();e.popInt()>t&&(e.pc+=e.intOperand)},[Kt.BRANCH_LESS_THAN_OR_EQUALS]:e=>{const t=e.popInt();e.popInt()<=t&&(e.pc+=e.intOperand)},[Kt.BRANCH_GREATER_THAN_OR_EQUALS]:e=>{const t=e.popInt();e.popInt()>=t&&(e.pc+=e.intOperand)},[Kt.POP_INT_DISCARD]:e=>{e.isp--},[Kt.POP_STRING_DISCARD]:e=>{e.ssp--},[Kt.RETURN]:e=>{if(0===e.fp)return void(e.execution=$t.FINISHED);const t=e.frames[--e.fp];e.pc=t.pc,e.script=t.script,e.intLocals=t.intLocals,e.stringLocals=t.stringLocals},[Kt.JOIN_STRING]:e=>{const t=e.intOperand,i=[];for(let r=0;r{Ur(e,e.popInt())},[Kt.GOSUB_WITH_PARAMS]:e=>{Ur(e,e.intOperand)},[Kt.JUMP]:e=>{Dr(e,e.popInt())},[Kt.JUMP_WITH_PARAMS]:e=>{Dr(e,e.intOperand)},[Kt.DEFINE_ARRAY]:e=>{throw new Error('unimplemented')},[Kt.PUSH_ARRAY_INT]:e=>{throw new Error('unimplemented')},[Kt.POP_ARRAY_INT]:e=>{throw new Error('unimplemented')},[Kt.SWITCH]:e=>{const t=e.popInt(),i=e.script.switchTables[e.intOperand];if(void 0===i)return;const r=i[t];r&&(e.pc+=r)},[Kt.PUSH_VARS]:e=>{const t=Br(65535&e.intOperand,Sr);t.type===Pe.STRING?e.pushString(Zl.varsString[t.id]??''):e.pushInt(Zl.vars[t.id])},[Kt.POP_VARS]:e=>{const t=Br(65535&e.intOperand,Sr);t.type===Pe.STRING?Zl.varsString[t.id]=e.popString():Zl.vars[t.id]=e.popInt()}},Fr=xr,Hr={[Kt.DB_FIND_WITH_COUNT]:e=>{throw new Error('unimplemented')},[Kt.DB_FINDNEXT]:e=>{if(!e.dbTable)throw new Error('No table selected');e.dbRow+1>=e.dbRowQuery.length?e.pushInt(-1):(e.dbRow++,e.pushInt(Br(e.dbRowQuery[e.dbRow],Pr).id))},[Kt.DB_GETFIELD]:e=>{const[t,i,r]=e.popInts(3),s=i>>12&65535,n=i>>4&127,a=Br(t,Pr),o=Br(s,wr);let c;c=a.tableId!==s?o.getDefault(n):a.getValue(n,r);const l=o.types[n];for(let t=0;t{const[t,i]=e.popInts(2),r=i>>12&65535,s=i>>4&127,n=Br(t,Pr),a=Br(r,wr);n.tableId===r?e.pushInt(n.columnValues[s].length/a.types[s].length):e.pushInt(0)},[Kt.DB_LISTALL_WITH_COUNT]:e=>{throw new Error('unimplemented')},[Kt.DB_GETROWTABLE]:e=>{e.pushInt(Br(e.popInt(),Pr).tableId)},[Kt.DB_FINDBYINDEX]:e=>{throw new Error('unimplemented')},[Kt.DB_FIND_REFINE_WITH_COUNT]:e=>{throw new Error('unimplemented')},[Kt.DB_FIND]:e=>{const t=2==e.popInt()?e.popString():e.popInt(),i=e.popInt(),r=i>>12&65535,s=i>>4&127;e.dbTable=Br(r,wr),e.dbRow=-1,e.dbRowQuery=[];const n=be.getInTable(r);for(let i=0;i{const t=2==e.popInt()?e.popString():e.popInt(),i=e.popInt(),r=i>>12&65535,s=i>>4&127,n=[],a=be.getInTable(r);for(let e=0;e{throw new Error('unimplemented')}},Vr=(e=>(e[e.CYCLE=0]='CYCLE',e[e.WORLD=1]='WORLD',e[e.CLIENT_IN=2]='CLIENT_IN',e[e.NPC=3]='NPC',e[e.PLAYER=4]='PLAYER',e[e.LOGOUT=5]='LOGOUT',e[e.LOGIN=6]='LOGIN',e[e.ZONE=7]='ZONE',e[e.CLIENT_OUT=8]='CLIENT_OUT',e[e.CLEANUP=9]='CLEANUP',e[e.BANDWIDTH_IN=10]='BANDWIDTH_IN',e[e.BANDWIDTH_OUT=11]='BANDWIDTH_OUT',e))(Vr||{}),Gr=Vr,Wr={[Kt.ERROR]:e=>{throw new Error(e.popString())},[Kt.MAP_PRODUCTION]:e=>{e.pushInt(vt.NODE_PRODUCTION?1:0)},[Kt.MAP_LASTCLOCK]:e=>{e.pushInt(Zl.lastCycleStats[Gr.CYCLE])},[Kt.MAP_LASTWORLD]:e=>{e.pushInt(Zl.lastCycleStats[Gr.WORLD])},[Kt.MAP_LASTCLIENTIN]:e=>{e.pushInt(Zl.lastCycleStats[Gr.CLIENT_IN])},[Kt.MAP_LASTNPC]:e=>{e.pushInt(Zl.lastCycleStats[Gr.NPC])},[Kt.MAP_LASTPLAYER]:e=>{e.pushInt(Zl.lastCycleStats[Gr.PLAYER])},[Kt.MAP_LASTLOGOUT]:e=>{e.pushInt(Zl.lastCycleStats[Gr.LOGOUT])},[Kt.MAP_LASTLOGIN]:e=>{e.pushInt(Zl.lastCycleStats[Gr.LOGIN])},[Kt.MAP_LASTZONE]:e=>{e.pushInt(Zl.lastCycleStats[Gr.ZONE])},[Kt.MAP_LASTCLIENTOUT]:e=>{e.pushInt(Zl.lastCycleStats[Gr.CLIENT_OUT])},[Kt.MAP_LASTCLEANUP]:e=>{e.pushInt(Zl.lastCycleStats[Gr.CLEANUP])},[Kt.MAP_LASTBANDWIDTHIN]:e=>{e.pushInt(Zl.lastCycleStats[Gr.BANDWIDTH_IN])},[Kt.MAP_LASTBANDWIDTHOUT]:e=>{e.pushInt(Zl.lastCycleStats[Gr.BANDWIDTH_OUT])}},Kr={[Kt.ENUM]:e=>{const[t,i,r,s]=e.popInts(4),n=Br(r,gr);if(n.inputtype!==t||n.outputtype!==i)throw new Error(`Type validation error: ${n.debugname} key: ${s}. Expected input: ${t} got: ${n.inputtype}. Expected output: ${i} got: ${n.outputtype}`);const a=n.values.get(s);'string'==typeof a?e.pushString(a??n.defaultString):e.pushInt(a??n.defaultInt)},[Kt.ENUM_GETOUTPUTCOUNT]:e=>{e.pushInt(Br(e.popInt(),gr).values.size)}},zr=Kr,jr=(e=>(e[e.FOREVER=0]='FOREVER',e[e.RESPAWN=1]='RESPAWN',e[e.DESPAWN=2]='DESPAWN',e))(jr||{}),Yr=jr,qr=class{level;x;z;width;length;lifecycle;lifecycleTick=-1;lastLifecycleTick=-1;constructor(e,t,i,r,s,n){this.level=e,this.x=t,this.z=i,this.width=r,this.length=s,this.lifecycle=n}updateLifeCycle(e){return this.lifecycleTick===e&&this.lifecycle!==Yr.FOREVER}checkLifeCycle(e){return this.lifecycle===Yr.FOREVER||(this.lifecycle===Yr.RESPAWN?this.lifecycleTicke)}setLifeCycle(e){this.lifecycleTick=e,this.lastLifecycleTick=Zl.currentTick}},Qr=class extends qr{resetEntity(e){}},$r=class extends Qr{type;count;receiverId=-1;reveal=-1;constructor(e,t,i,r,s,n){super(e,t,i,1,1,r),this.type=s,this.count=n}},Zr={[Kt.INV_ALLSTOCK]:e=>{const t=Br(e.popInt(),Er);e.pushInt(t.allstock?1:0)},[Kt.INV_SIZE]:e=>{const t=Br(e.popInt(),Er);e.pushInt(t.size)},[Kt.INV_STOCKBASE]:e=>{const[t,i]=e.popInts(2),r=Br(t,Er),s=Br(i,mr);if(!r.stockobj||!r.stockcount)return void e.pushInt(-1);const n=r.stockobj.indexOf(s.id);e.pushInt(n>=0?r.stockcount[n]:-1)},[Kt.INV_ADD]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3),s=Br(t,Er),n=Br(i,mr);if(Br(r,yr),!e.pointerGet(Ht[e.intOperand])&&s.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${s.debugname}`);if(!s.dummyinv&&0!==n.dummyitem)throw new Error(`dummyitem in non-dummyinv: ${n.debugname} -> ${s.debugname}`);const a=e.activePlayer,o=r-a.invAdd(s.id,n.id,r,!1);if(o>0)if(n.stackable&&1!==o)Zl.addObj(new $r(a.level,a.x,a.z,Yr.DESPAWN,n.id,o),a.pid,200);else for(let e=0;e{const[t,i,r,s]=e.popInts(4);throw new Error('unimplemented')})),[Kt.INV_CLEAR]:Vt(Ft,(e=>{const t=Br(e.popInt(),Er);if(!e.pointerGet(Ht[e.intOperand])&&t.protect&&t.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${t.debugname}`);e.activePlayer.invClear(t.id)})),[Kt.INV_DEL]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3),s=Br(t,Er),n=Br(i,mr);if(Br(r,yr),!e.pointerGet(Ht[e.intOperand])&&s.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${s.debugname}`);e.activePlayer.invDel(s.id,n.id,r)})),[Kt.INV_DELSLOT]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);if(!e.pointerGet(Ht[e.intOperand])&&r.protect&&r.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${r.debugname}`);e.activePlayer.invGetSlot(r.id,i)&&e.activePlayer.invDelSlot(r.id,i)})),[Kt.INV_DROPITEM]:Vt(Ft,(e=>{const[t,i,r,s,n]=e.popInts(5),a=Br(t,Er),o=Br(i,nr),c=Br(r,mr);if(Br(s,yr),Br(n,sr),!e.pointerGet(Ht[e.intOperand])&&a.protect&&a.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);const l=e.activePlayer,h=l.invDel(a.id,c.id,s);if(0==h)return;l.playerLog('Dropped item from',a.debugname,c.debugname);const d=new $r(o.level,o.x,o.z,Yr.DESPAWN,c.id,h);Zl.addObj(d,l.pid,n),e.activeObj=d,e.pointerAdd(xt[e.intOperand])})),[Kt.INV_DROPSLOT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er);Br(s,sr);const a=Br(i,nr);if(!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);const o=e.activePlayer.invGetSlot(n.id,r);if(!o)throw new Error('$slot is empty');const c=e.activePlayer,l=c.invDel(n.id,o.id,o.count,r);if(0===l)return;const h=Tt.get(o.id);if(c.playerLog('Dropped item from',n.debugname,h.debugname),h.stackable&&1!==l){const t=new $r(a.level,a.x,a.z,Yr.DESPAWN,o.id,l);Zl.addObj(t,c.pid,s),e.activeObj=t,e.pointerAdd(xt[e.intOperand])}else for(let t=0;t{const t=Br(e.popInt(),Er);e.pushInt(e.activePlayer.invFreeSpace(t.id))})),[Kt.INV_GETNUM]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);e.pushInt(e.activePlayer.invGetSlot(r.id,i)?.count??0)})),[Kt.INV_GETOBJ]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);e.pushInt(e.activePlayer.invGetSlot(r.id,i)?.id??-1)})),[Kt.INV_ITEMSPACE]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,mr);if(Br(r,yr),s<0||s>n.size)throw new Error(`$count is out of range: ${r}`);e.pushInt(0===e.activePlayer.invItemSpace(n.id,a.id,r,s)?1:0)})),[Kt.INV_ITEMSPACE2]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,mr);Br(r,yr),e.pushInt(e.activePlayer.invItemSpace(n.id,a.id,r,s))})),[Kt.INV_MOVEFROMSLOT]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3),s=Br(t,Er),n=Br(i,Er);if(!e.pointerGet(Ht[e.intOperand])&&s.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${s.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&n.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);const a=e.activePlayer,{overflow:o,fromObj:c}=a.invMoveFromSlot(s.id,n.id,r);if(o>0){if(Tt.get(c).stackable&&1!==o)Zl.addObj(new $r(a.level,a.x,a.z,Yr.DESPAWN,c,o),a.pid,200);else for(let e=0;e{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,Er);if(!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&a.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);e.activePlayer.invMoveToSlot(n.id,a.id,r,s)})),[Kt.BOTH_MOVEINV]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er),s=Br(i,Er),n=1==e.intOperand,a=n?e._activePlayer2:e._activePlayer,o=n?e._activePlayer:e._activePlayer2;if(!a||!o)throw new Error('player is null');if(!e.pointerGet(Ht[n?1:0])&&r.protect&&r.scope!==it.SCOPE_SHARED)throw new Error(`$from_inv requires protected access: ${r.debugname}`);if(!e.pointerGet(Ht[n?0:1])&&s.protect&&r.scope!==it.SCOPE_SHARED)throw new Error(`$to_inv requires protected access: ${s.debugname}`);const c=a.getInventory(t),l=o.getInventory(i);if(!c||!l)throw new Error('inv is null');for(let e=0;e{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,Er),o=Br(r,mr);if(Br(s,yr),!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&a.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);const c=e.activePlayer,l=c.invDel(n.id,o.id,s);if(0==l)return;const h=s-c.invAdd(a.id,o.id,l,!1);if(h>0)if(o.stackable&&1!==h)Zl.addObj(new $r(c.level,c.x,c.z,Yr.DESPAWN,o.id,h),c.pid,200);else for(let e=0;e{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,Er),o=Br(r,mr);if(Br(s,yr),!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&a.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);const c=e.activePlayer,l=c.invDel(n.id,o.id,s);if(0==l)return;let h=o.id;-1===o.certtemplate&&o.certlink>=0&&(h=o.certlink);const d=s-c.invAdd(a.id,h,l,!1);d>0&&Zl.addObj(new $r(c.level,c.x,c.z,Yr.DESPAWN,h,d),c.pid,200)})),[Kt.INV_MOVEITEM_UNCERT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,Er),o=Br(r,mr);if(Br(s,yr),!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&a.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);const c=e.activePlayer,l=c.invDel(n.id,o.id,s);0!=l&&(o.certtemplate>=0&&o.certlink>=0?c.invAdd(a.id,o.certlink,l):c.invAdd(a.id,o.id,l))})),[Kt.INV_SETSLOT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(r,mr);if(Br(s,yr),!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!n.dummyinv&&0!==a.dummyitem)throw new Error(`dummyitem in non-dummyinv: ${a.debugname} -> ${n.debugname}`);e.activePlayer.invSet(n.id,a.id,s,i)})),[Kt.INV_TOTAL]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);-1!==i?e.pushInt(e.activePlayer.invTotal(r.id,i)):e.pushInt(0)})),[Kt.INV_TOTALCAT]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er),s=Br(i,_r);e.pushInt(e.activePlayer.invTotalCat(r.id,s.id))})),[Kt.INV_TRANSMIT]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);Br(i,Ji),e.activePlayer.invListenOnCom(r.id,i,e.activePlayer.uid)})),[Kt.INVOTHER_TRANSMIT]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,Ji);const s=Br(i,Er);Br(r,Ji),e.activePlayer.invListenOnCom(s.id,r,t)})),[Kt.INV_STOPTRANSMIT]:Vt(Ft,(e=>{const t=Br(e.popInt(),Ji);e.activePlayer.invStopListenOnCom(t)})),[Kt.BOTH_DROPSLOT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er);Br(s,sr);const a=Br(i,nr),o=1==e.intOperand,c=o?e._activePlayer2:e._activePlayer,l=o?e._activePlayer:e._activePlayer2;if(!c||!l)throw new Error('player is null');if(!e.pointerGet(Ht[o?1:0])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`inv requires protected access: ${n.debugname}`);const h=c.invGetSlot(n.id,r);if(!h)throw new Error('$slot is empty');const d=c.invDel(n.id,h.id,h.count,r);if(0===d)return;const u=Tt.get(h.id);c.playerLog('Dropped item from',n.debugname,u.debugname),u.tradeable&&Zl.addObj(new $r(a.level,a.x,a.z,Yr.DESPAWN,h.id,d),l.pid,s)})),[Kt.INV_DROPALL]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3),s=Br(t,Er);Br(r,sr);const n=Br(i,nr);if(!e.pointerGet(Ht[e.intOperand])&&s.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${s.debugname}`);const a=e.activePlayer.getInventory(s.id);if(a)for(let e=0;e{const[t,i]=e.popInts(2);e.pushInt(e.activePlayer.invTotalParam(t,i))})),[Kt.INV_TOTALPARAM_STACK]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);e.pushInt(e.activePlayer.invTotalParamStack(t,i))}))},Xr=(e=>(e[e.ZONE=0]='ZONE',e[e.DISTANCE=1]='DISTANCE',e))(Xr||{}),Jr=Xr,es=class{iterator;tick;constructor(e){this.iterator=this.generator(),this.tick=e}[Symbol.iterator](){return this.iterator}next(){return this.iterator.next()}},ts=class extends es{x;z;level;minX;maxX;minZ;maxZ;distance;checkVis;checkType;checkCategory;type;constructor(e,t,i,r,s,n,a,o,c){super(e);const l=ji.zone(i),h=ji.zone(r),d=1+s/8|0;this.x=i,this.z=r,this.level=t,this.maxX=l+d,this.minX=l-d,this.maxZ=h+d,this.minZ=h-d,this.distance=s,this.checkVis=n,this.checkType=a,this.checkCategory=o,this.type=c}*generator(){for(let e=this.maxX;e>=this.minX;e--){const t=e<<3;for(let e=this.maxZ;e>=this.minZ;e--){const i=e<<3;if(this.type===je.PLAYER)for(const e of Zl.getZone(t,i,this.level).getAllPlayersSafe()){if(Zl.currentTick>this.tick)throw new Error('[HuntIterator] tried to use an old iterator. Create a new iterator instead.');ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e)}else if(this.type===je.NPC)for(const e of Zl.getZone(t,i,this.level).getAllNpcsSafe()){if(Zl.currentTick>this.tick)throw new Error('[HuntIterator] tried to use an old iterator. Create a new iterator instead.');if(-1!==this.checkType&&e.type!==this.checkType)continue;const t=ft.get(e.type);-1!==this.checkCategory&&t.category!==this.checkCategory||t.op&&t.op[1]&&(ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e))}else if(this.type===je.OBJ)for(const e of Zl.getZone(t,i,this.level).getAllObjsSafe()){if(Zl.currentTick>this.tick)throw new Error('[HuntIterator] tried to use an old iterator. Create a new iterator instead.');if(-1!==this.checkType&&e.type!==this.checkType)continue;const t=Tt.get(e.type);-1!==this.checkCategory&&t.category!==this.checkCategory||(ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e))}else if(this.type===je.SCENERY)for(const e of Zl.getZone(t,i,this.level).getAllLocsSafe()){if(Zl.currentTick>this.tick)throw new Error('[HuntIterator] tried to use an old iterator. Create a new iterator instead.');if(-1!==this.checkType&&e.type!==this.checkType)continue;const t=at.get(e.type);-1!==this.checkCategory&&t.category!==this.checkCategory||(ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e))}}}}},is=class extends es{level;x;z;minX;maxX;minZ;maxZ;distance;checkVis;type;constructor(e,t,i,r,s,n,a){super(e);const o=ji.zone(i),c=ji.zone(r),l=1+s/8|0;this.x=i,this.z=r,this.level=t,this.maxX=o+l,this.minX=o-l,this.maxZ=c+l,this.minZ=c-l,this.distance=s,this.checkVis=n,this.type=a}*generator(){if(this.type===Jr.ZONE)for(const e of Zl.getZone(this.x,this.z,this.level).getAllNpcsSafe()){if(Zl.currentTick>this.tick)throw new Error('[NpcIterator] tried to use an old iterator. Create a new iterator instead.');yield e}else if(this.type===Jr.DISTANCE)for(let e=this.maxX;e>=this.minX;e--){const t=e<<3;for(let e=this.maxZ;e>=this.minZ;e--){const i=e<<3;for(const e of Zl.getZone(t,i,this.level).getAllNpcsSafe()){if(Zl.currentTick>this.tick)throw new Error('[NpcIterator] tried to use an old iterator. Create a new iterator instead.');ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e)}}}}},rs=class extends es{level;x;z;constructor(e,t,i,r){super(e),this.level=t,this.x=i,this.z=r}*generator(){for(const e of Zl.getZone(this.x,this.z,this.level).getAllLocsSafe()){if(Zl.currentTick>this.tick)throw new Error('[LocIterator] tried to use an old iterator. Create a new iterator instead.');yield e}}},ss=class extends Qr{info;constructor(e,t,i,r,s,n,a,o,c){super(e,t,i,r,s,n),this.info=16383&a|(31&o)<<14|(3&c)<<19}get type(){return 16383&this.info}get shape(){return this.info>>14&31}get angle(){return this.info>>19&3}},ns={[Kt.LOC_ADD]:e=>{const[t,i,r,s,n]=e.popInts(5),a=Br(t,nr),o=Br(i,tr),c=Br(r,ir),l=Br(s,rr);Br(n,sr);const h=new ss(a.level,a.x,a.z,o.width,o.length,Yr.DESPAWN,o.id,l,c),d=Zl.getZone(a.x,a.z,a.level).getLocsUnsafe(ji.packZoneCoord(a.x,a.z));for(const e of d)if(e!==h&&e.angle===c&&e.shape===l){Zl.removeLoc(e,n);break}Zl.addLoc(h,n),e.activeLoc=h,e.pointerAdd(Mt[e.intOperand])},[Kt.LOC_ANGLE]:Vt(Mt,(e=>{e.pushInt(Br(e.activeLoc.angle,ir))})),[Kt.LOC_ANIM]:Vt(Mt,(e=>{const t=Br(e.popInt(),Tr);Zl.animLoc(e.activeLoc,t.id)})),[Kt.LOC_CATEGORY]:Vt(Mt,(e=>{e.pushInt(Br(e.activeLoc.type,tr).category)})),[Kt.LOC_CHANGE]:Vt(Mt,(e=>{const[t,i]=e.popInts(2),r=Br(t,tr);Br(i,sr),Zl.removeLoc(e.activeLoc,i);const{level:s,x:n,z:a,angle:o,shape:c}=e.activeLoc,l=new ss(s,n,a,r.width,r.length,Yr.DESPAWN,r.id,c,o),h=Zl.getZone(n,a,s).getLocsUnsafe(ji.packZoneCoord(n,a));for(const e of h)if(e!==l&&e.angle===o&&e.shape===c){Zl.removeLoc(e,i);break}Zl.addLoc(l,i),e.activeLoc=l,e.pointerAdd(Mt[e.intOperand])})),[Kt.LOC_COORD]:Vt(Mt,(e=>{const t=e.activeLoc;e.pushInt(ji.packCoord(t.level,t.x,t.z))})),[Kt.LOC_DEL]:Vt(Mt,(e=>{const t=Br(e.popInt(),sr),{level:i,x:r,z:s,angle:n,shape:a}=e.activeLoc,o=Zl.getZone(r,s,i).getLocsUnsafe(ji.packZoneCoord(r,s));for(const i of o)if(i!==e.activeLoc&&i.angle===n&&i.shape===a){Zl.removeLoc(i,t);break}Zl.removeLoc(e.activeLoc,t)})),[Kt.LOC_FIND]:e=>{const[t,i]=e.popInts(2),r=Br(i,tr),s=Br(t,nr),n=Zl.getLoc(s.x,s.z,s.level,r.id);n?(e.activeLoc=n,e.pointerAdd(Mt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.LOC_FINDALLZONE]:e=>{const t=Br(e.popInt(),nr);e.locIterator=new rs(Zl.currentTick,t.level,t.x,t.z),e._activeLoc&&(e._activeLoc2=e._activeLoc,e.pointerAdd(Gt.ActiveLoc2))},[Kt.LOC_FINDNEXT]:e=>{const t=e.locIterator?.next();t&&!t.done?(e.activeLoc=t.value,e.pointerAdd(Mt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.LOC_PARAM]:Vt(Mt,(e=>{const t=Br(e.popInt(),ar),i=Br(e.activeLoc.type,tr);t.isString()?e.pushString(rt(t.id,i,t.defaultString)):e.pushInt(st(t.id,i,t.defaultInt))})),[Kt.LOC_TYPE]:Vt(Mt,(e=>{e.pushInt(Br(e.activeLoc.type,tr).id)})),[Kt.LOC_NAME]:Vt(Mt,(e=>{e.pushString(Br(e.activeLoc.type,tr).name??'null')})),[Kt.LOC_SHAPE]:Vt(Mt,(e=>{e.pushInt(Br(e.activeLoc.shape,rr))}))},as={[Kt.LC_NAME]:e=>{const t=Br(e.popInt(),tr);e.pushString(t.name??t.debugname??'null')},[Kt.LC_PARAM]:e=>{const[t,i]=e.popInts(2),r=Br(t,tr),s=Br(i,ar);s.isString()?e.pushString(rt(s.id,r,s.defaultString)):e.pushInt(st(s.id,r,s.defaultInt))},[Kt.LC_CATEGORY]:e=>{e.pushInt(Br(e.popInt(),tr).category)},[Kt.LC_DESC]:e=>{e.pushString(Br(e.popInt(),tr).desc??'null')},[Kt.LC_DEBUGNAME]:e=>{e.pushString(Br(e.popInt(),tr).debugname??'null')},[Kt.LC_WIDTH]:e=>{e.pushInt(Br(e.popInt(),tr).width)},[Kt.LC_LENGTH]:e=>{e.pushInt(Br(e.popInt(),tr).length)}},os=(e=>(e[e.PROC=0]='PROC',e[e.LABEL=1]='LABEL',e[e.DEBUGPROC=2]='DEBUGPROC',e[e.APNPC1=3]='APNPC1',e[e.APNPC2=4]='APNPC2',e[e.APNPC3=5]='APNPC3',e[e.APNPC4=6]='APNPC4',e[e.APNPC5=7]='APNPC5',e[e.APNPCU=8]='APNPCU',e[e.APNPCT=9]='APNPCT',e[e.OPNPC1=10]='OPNPC1',e[e.OPNPC2=11]='OPNPC2',e[e.OPNPC3=12]='OPNPC3',e[e.OPNPC4=13]='OPNPC4',e[e.OPNPC5=14]='OPNPC5',e[e.OPNPCU=15]='OPNPCU',e[e.OPNPCT=16]='OPNPCT',e[e.AI_APNPC1=17]='AI_APNPC1',e[e.AI_APNPC2=18]='AI_APNPC2',e[e.AI_APNPC3=19]='AI_APNPC3',e[e.AI_APNPC4=20]='AI_APNPC4',e[e.AI_APNPC5=21]='AI_APNPC5',e[e.AI_OPNPC1=24]='AI_OPNPC1',e[e.AI_OPNPC2=25]='AI_OPNPC2',e[e.AI_OPNPC3=26]='AI_OPNPC3',e[e.AI_OPNPC4=27]='AI_OPNPC4',e[e.AI_OPNPC5=28]='AI_OPNPC5',e[e.APOBJ1=31]='APOBJ1',e[e.APOBJ2=32]='APOBJ2',e[e.APOBJ3=33]='APOBJ3',e[e.APOBJ4=34]='APOBJ4',e[e.APOBJ5=35]='APOBJ5',e[e.APOBJU=36]='APOBJU',e[e.APOBJT=37]='APOBJT',e[e.OPOBJ1=38]='OPOBJ1',e[e.OPOBJ2=39]='OPOBJ2',e[e.OPOBJ3=40]='OPOBJ3',e[e.OPOBJ4=41]='OPOBJ4',e[e.OPOBJ5=42]='OPOBJ5',e[e.OPOBJU=43]='OPOBJU',e[e.OPOBJT=44]='OPOBJT',e[e.AI_APOBJ1=45]='AI_APOBJ1',e[e.AI_APOBJ2=46]='AI_APOBJ2',e[e.AI_APOBJ3=47]='AI_APOBJ3',e[e.AI_APOBJ4=48]='AI_APOBJ4',e[e.AI_APOBJ5=49]='AI_APOBJ5',e[e.AI_OPOBJ1=52]='AI_OPOBJ1',e[e.AI_OPOBJ2=53]='AI_OPOBJ2',e[e.AI_OPOBJ3=54]='AI_OPOBJ3',e[e.AI_OPOBJ4=55]='AI_OPOBJ4',e[e.AI_OPOBJ5=56]='AI_OPOBJ5',e[e.APLOC1=59]='APLOC1',e[e.APLOC2=60]='APLOC2',e[e.APLOC3=61]='APLOC3',e[e.APLOC4=62]='APLOC4',e[e.APLOC5=63]='APLOC5',e[e.APLOCU=64]='APLOCU',e[e.APLOCT=65]='APLOCT',e[e.OPLOC1=66]='OPLOC1',e[e.OPLOC2=67]='OPLOC2',e[e.OPLOC3=68]='OPLOC3',e[e.OPLOC4=69]='OPLOC4',e[e.OPLOC5=70]='OPLOC5',e[e.OPLOCU=71]='OPLOCU',e[e.OPLOCT=72]='OPLOCT',e[e.AI_APLOC1=73]='AI_APLOC1',e[e.AI_APLOC2=74]='AI_APLOC2',e[e.AI_APLOC3=75]='AI_APLOC3',e[e.AI_APLOC4=76]='AI_APLOC4',e[e.AI_APLOC5=77]='AI_APLOC5',e[e.AI_OPLOC1=80]='AI_OPLOC1',e[e.AI_OPLOC2=81]='AI_OPLOC2',e[e.AI_OPLOC3=82]='AI_OPLOC3',e[e.AI_OPLOC4=83]='AI_OPLOC4',e[e.AI_OPLOC5=84]='AI_OPLOC5',e[e.APPLAYER1=87]='APPLAYER1',e[e.APPLAYER2=88]='APPLAYER2',e[e.APPLAYER3=89]='APPLAYER3',e[e.APPLAYER4=90]='APPLAYER4',e[e.APPLAYER5=91]='APPLAYER5',e[e.APPLAYERU=92]='APPLAYERU',e[e.APPLAYERT=93]='APPLAYERT',e[e.OPPLAYER1=94]='OPPLAYER1',e[e.OPPLAYER2=95]='OPPLAYER2',e[e.OPPLAYER3=96]='OPPLAYER3',e[e.OPPLAYER4=97]='OPPLAYER4',e[e.OPPLAYER5=98]='OPPLAYER5',e[e.OPPLAYERU=99]='OPPLAYERU',e[e.OPPLAYERT=100]='OPPLAYERT',e[e.AI_APPLAYER1=101]='AI_APPLAYER1',e[e.AI_APPLAYER2=102]='AI_APPLAYER2',e[e.AI_APPLAYER3=103]='AI_APPLAYER3',e[e.AI_APPLAYER4=104]='AI_APPLAYER4',e[e.AI_APPLAYER5=105]='AI_APPLAYER5',e[e.AI_OPPLAYER1=108]='AI_OPPLAYER1',e[e.AI_OPPLAYER2=109]='AI_OPPLAYER2',e[e.AI_OPPLAYER3=110]='AI_OPPLAYER3',e[e.AI_OPPLAYER4=111]='AI_OPPLAYER4',e[e.AI_OPPLAYER5=112]='AI_OPPLAYER5',e[e.QUEUE=116]='QUEUE',e[e.AI_QUEUE1=117]='AI_QUEUE1',e[e.AI_QUEUE2=118]='AI_QUEUE2',e[e.AI_QUEUE3=119]='AI_QUEUE3',e[e.AI_QUEUE4=120]='AI_QUEUE4',e[e.AI_QUEUE5=121]='AI_QUEUE5',e[e.AI_QUEUE6=122]='AI_QUEUE6',e[e.AI_QUEUE7=123]='AI_QUEUE7',e[e.AI_QUEUE8=124]='AI_QUEUE8',e[e.AI_QUEUE9=125]='AI_QUEUE9',e[e.AI_QUEUE10=126]='AI_QUEUE10',e[e.AI_QUEUE11=127]='AI_QUEUE11',e[e.AI_QUEUE12=128]='AI_QUEUE12',e[e.AI_QUEUE13=129]='AI_QUEUE13',e[e.AI_QUEUE14=130]='AI_QUEUE14',e[e.AI_QUEUE15=131]='AI_QUEUE15',e[e.AI_QUEUE16=132]='AI_QUEUE16',e[e.AI_QUEUE17=133]='AI_QUEUE17',e[e.AI_QUEUE18=134]='AI_QUEUE18',e[e.AI_QUEUE19=135]='AI_QUEUE19',e[e.AI_QUEUE20=136]='AI_QUEUE20',e[e.SOFTTIMER=137]='SOFTTIMER',e[e.TIMER=138]='TIMER',e[e.AI_TIMER=139]='AI_TIMER',e[e.OPHELD1=140]='OPHELD1',e[e.OPHELD2=141]='OPHELD2',e[e.OPHELD3=142]='OPHELD3',e[e.OPHELD4=143]='OPHELD4',e[e.OPHELD5=144]='OPHELD5',e[e.OPHELDU=145]='OPHELDU',e[e.OPHELDT=146]='OPHELDT',e[e.IF_BUTTON=147]='IF_BUTTON',e[e.INV_BUTTON1=148]='INV_BUTTON1',e[e.INV_BUTTON2=149]='INV_BUTTON2',e[e.INV_BUTTON3=150]='INV_BUTTON3',e[e.INV_BUTTON4=151]='INV_BUTTON4',e[e.INV_BUTTON5=152]='INV_BUTTON5',e[e.INV_BUTTOND=153]='INV_BUTTOND',e[e.IF_CLOSE=154]='IF_CLOSE',e[e.LOGIN=155]='LOGIN',e[e.LOGOUT=156]='LOGOUT',e[e.TUTORIAL_CLICKSIDE=157]='TUTORIAL_CLICKSIDE',e[e.MOVE=158]='MOVE',e[e.WALKTRIGGER=159]='WALKTRIGGER',e[e.AI_WALKTRIGGER=160]='AI_WALKTRIGGER',e[e.LEVELUP=161]='LEVELUP',e))(os||{});(Mr=os||(os={})).toString=function(e){return Mr[e].toLowerCase()};var cs=os,ls=(e=>(e[e.SCRIPT=0]='SCRIPT',e[e.ENGINE=1]='ENGINE',e))(ls||{}),hs=ls,ds={[Kt.NPC_FINDUID]:e=>{const t=e.popInt(),i=65535&t,r=t>>16&65535,s=Zl.getNpc(i);s&&s.type===r?(e.activeNpc=s,e.pointerAdd(kt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.NPC_ADD]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr),n=Br(i,or);Br(r,sr);const a=new kl(s.level,s.x,s.z,n.size,n.size,Yr.DESPAWN,Zl.getNextNid(),n.id,n.moverestrict,n.blockwalk);Zl.addNpc(a,r),e.activeNpc=a,e.pointerAdd(kt[e.intOperand])},[Kt.NPC_ANIM]:Vt(kt,(e=>{const t=Br(e.popInt(),Ji),i=e.popInt();e.activeNpc.playAnimation(i,t)})),[Kt.NPC_BASESTAT]:Vt(kt,(e=>{const t=Br(e.popInt(),cr);e.pushInt(e.activeNpc.baseLevels[t])})),[Kt.NPC_CATEGORY]:Vt(kt,(e=>{e.pushInt(Br(e.activeNpc.type,or).category)})),[Kt.NPC_COORD]:Vt(kt,(e=>{const t=e.activeNpc;e.pushInt(ji.packCoord(t.level,t.x,t.z))})),[Kt.NPC_DEL]:Vt(kt,(e=>{Zl.removeNpc(e.activeNpc,Br(e.activeNpc.type,or).respawnrate)})),[Kt.NPC_DELAY]:Vt(kt,(e=>{e.activeNpc.delay=Zl.currentTick+Br(e.popInt(),Ji)+1,e.execution=$t.NPC_SUSPENDED})),[Kt.NPC_FACESQUARE]:Vt(kt,(e=>{const t=Br(e.popInt(),nr);e.activeNpc.faceSquare(t.x,t.z)})),[Kt.NPC_FINDEXACT]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,or);e.npcIterator=new is(Zl.currentTick,r.level,r.x,r.z,0,0,Jr.ZONE);for(const t of e.npcIterator)if(t.type===s.id&&t.x===r.x&&t.level===r.level&&t.z===r.z)return e.activeNpc=t,e.pointerAdd(kt[e.intOperand]),void e.pushInt(1);e.pushInt(0)},[Kt.NPC_FINDHERO]:Vt(kt,(e=>{const t=e.activeNpc.findHero();if(-1===t)return void e.pushInt(0);const i=Zl.getPlayerByUid(t);i?(e.activePlayer=i,e.pointerAdd(Gt.ActivePlayer),e.pushInt(1)):e.pushInt(0)})),[Kt.NPC_PARAM]:Vt(kt,(e=>{const t=Br(e.popInt(),ar),i=Br(e.activeNpc.type,or);t.isString()?e.pushString(rt(t.id,i,t.defaultString)):e.pushInt(st(t.id,i,t.defaultInt))})),[Kt.NPC_QUEUE]:Vt(kt,(e=>{const t=Br(e.popInt(),Ji),i=e.popInt(),r=Br(e.popInt(),hr),s=Br(e.activeNpc.type,or),n=jt.getByTrigger(cs.AI_QUEUE1+r-1,s.id,s.category);n&&e.activeNpc.enqueueScript(n,t,i)})),[Kt.NPC_RANGE]:Vt(kt,(e=>{const t=Br(e.popInt(),nr),i=e.activeNpc;t.level!==i.level?e.pushInt(-1):e.pushInt(ji.distanceTo(i,{x:t.x,z:t.z,width:1,length:1}))})),[Kt.NPC_SAY]:Vt(kt,(e=>{e.activeNpc.say(e.popString())})),[Kt.NPC_SETHUNT]:Vt(kt,(e=>{e.activeNpc.huntrange=Br(e.popInt(),Ji)})),[Kt.NPC_SETHUNTMODE]:Vt(kt,(e=>{e.activeNpc.huntMode=Br(e.popInt(),dr).id})),[Kt.NPC_SETMODE]:Vt(kt,(e=>{const t=Br(e.popInt(),ur);if(e.activeNpc.clearWaypoints(),t===Xe.NULL||t===Xe.NONE||t===Xe.WANDER||t===Xe.PATROL)return e.activeNpc.clearInteraction(),void(e.activeNpc.targetOp=t);let i;e.activeNpc.targetOp=t,i=t>=Xe.OPNPC1?e._activeNpc2:t>=Xe.OPOBJ1?e._activeObj:t>=Xe.OPLOC1?e._activeLoc:e._activePlayer,i?i instanceof kl||i instanceof $r||i instanceof ss?e.activeNpc.setInteraction(hs.SCRIPT,i,t,{type:i.type,com:-1}):e.activeNpc.setInteraction(hs.SCRIPT,i,t):e.activeNpc.noMode()})),[Kt.NPC_STAT]:Vt(kt,(e=>{const t=Br(e.popInt(),cr);e.pushInt(e.activeNpc.levels[t])})),[Kt.NPC_STATHEAL]:Vt(kt,(e=>{const[t,i,r]=e.popInts(3);Br(t,cr),Br(i,Ji),Br(r,Ji);const s=e.activeNpc,n=s.baseLevels[t],a=s.levels[t],o=a+(i+a*r/100);s.levels[t]=Math.min(o,n),0===t&&s.levels[t]===s.baseLevels[t]&&s.resetHeroPoints()})),[Kt.NPC_TYPE]:Vt(kt,(e=>{e.pushInt(Br(e.activeNpc.type,or).id)})),[Kt.NPC_DAMAGE]:Vt(kt,(e=>{const t=Br(e.popInt(),Ji),i=Br(e.popInt(),pr);e.activeNpc.applyDamage(t,i)})),[Kt.NPC_NAME]:Vt(kt,(e=>{e.pushString(Br(e.activeNpc.type,or).name??'null')})),[Kt.NPC_UID]:Vt(kt,(e=>{e.pushInt(e.activeNpc.uid)})),[Kt.NPC_SETTIMER]:Vt(kt,(e=>{e.activeNpc.setTimer(Br(e.popInt(),Ji))})),[Kt.SPOTANIM_NPC]:Vt(kt,(e=>{const t=Br(e.popInt(),Ji),i=Br(e.popInt(),Ji),r=Br(e.popInt(),fr);e.activeNpc.spotanim(r.id,i,t)})),[Kt.NPC_FIND]:e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,nr),a=Br(i,or);Br(r,Ji);const o=Br(s,vr);let c,l=r;const h=new is(Zl.currentTick,n.level,n.x,n.z,r,o,Jr.DISTANCE);for(const e of h)if(e&&e.type===a.id){const t=ji.distanceToSW(n,e);t<=l&&(c=e,l=t)}c?(e.activeNpc=c,e.pointerAdd(kt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.NPC_FINDALLANY]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr);Br(i,Ji);const n=Br(r,vr);e.npcIterator=new is(Zl.currentTick,s.level,s.x,s.z,i,n,Jr.DISTANCE),e._activeNpc&&(e._activeNpc2=e._activeNpc,e.pointerAdd(Gt.ActiveNpc2))},[Kt.NPC_FINDALLZONE]:e=>{const t=Br(e.popInt(),nr);e.npcIterator=new is(Zl.currentTick,t.level,t.x,t.z,0,0,Jr.ZONE),e._activeNpc&&(e._activeNpc2=e._activeNpc,e.pointerAdd(Gt.ActiveNpc2))},[Kt.NPC_FINDNEXT]:e=>{const t=e.npcIterator?.next();t&&!t.done?(e.activeNpc=t.value,e.pointerAdd(kt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.NPC_TELE]:Vt(kt,(e=>{const t=Br(e.popInt(),nr);e.activeNpc.teleport(t.x,t.z,t.level)})),[Kt.NPC_WALK]:Vt(kt,(e=>{const t=Br(e.popInt(),nr);e.activeNpc.queueWaypoint(t.x,t.z)})),[Kt.NPC_CHANGETYPE]:Vt(kt,(e=>{e.activeNpc.changeType(Br(e.popInt(),or).id)})),[Kt.NPC_GETMODE]:Vt(kt,(e=>{e.pushInt(e.activeNpc.targetOp)})),[Kt.NPC_HEROPOINTS]:Vt([Gt.ActivePlayer,...kt],(e=>{e.activeNpc.addHero(e.activePlayer.uid,Br(e.popInt(),Ji))})),[Kt.NPC_WALKTRIGGER]:Vt(kt,(e=>{const[t,i]=e.popInts(2);Br(t,hr),e.activeNpc.walktrigger=t-1,e.activeNpc.walktriggerArg=i})),[Kt.NPC_STATADD]:Vt(kt,(e=>{const[t,i,r]=e.popInts(3);Br(t,cr),Br(i,Ji),Br(r,Ji);const s=e.activeNpc,n=s.levels[t],a=n+(i+n*r/100);s.levels[t]=Math.min(a,255),0===t&&s.levels[t]>=s.baseLevels[t]&&s.resetHeroPoints()})),[Kt.NPC_STATSUB]:Vt(kt,(e=>{const[t,i,r]=e.popInts(3);Br(t,cr),Br(i,Ji),Br(r,Ji);const s=e.activeNpc,n=s.levels[t],a=n-(i+n*r/100);s.levels[t]=Math.max(a,0)})),[Kt.NPC_ATTACKRANGE]:Vt(kt,(e=>{e.pushInt(Br(e.activeNpc.type,or).attackrange)}))},us=ds,ps={[Kt.NC_NAME]:e=>{const t=Br(e.popInt(),or);e.pushString(t.name??t.debugname??'null')},[Kt.NC_PARAM]:e=>{const[t,i]=e.popInts(2),r=Br(t,or),s=Br(i,ar);s.isString()?e.pushString(rt(i,r,s.defaultString)):e.pushInt(st(i,r,s.defaultInt))},[Kt.NC_CATEGORY]:e=>{e.pushInt(Br(e.popInt(),or).category)},[Kt.NC_DESC]:e=>{e.pushString(Br(e.popInt(),or).desc??'null')},[Kt.NC_DEBUGNAME]:e=>{e.pushString(Br(e.popInt(),or).debugname??'null')},[Kt.NC_OP]:e=>{const[t,i]=e.popInts(2),r=Br(t,or);Br(i,Ji),r.op?e.pushString(r.op[i-1]??''):e.pushString('')}},gs=class{static _sin=new Int32Array(16384);static _cos=new Int32Array(16384);static{const e=.0003834951969714103;for(let t=0;t<16384;t++)this._sin[t]=16384*Math.sin(t*e)|0,this._cos[t]=16384*Math.cos(t*e)|0}static radians(e){return(16383&e)/16384*6.283185307179586}static atan2(e,t){return 16383&Math.round(2607.5945876176133*Math.atan2(e,t))}static sin(e){return this._sin[16383&e]}static cos(e){return this._cos[16383&e]}},ms={[Kt.ADD]:e=>{const t=e.popInt(),i=e.popInt();e.pushInt(i+t)},[Kt.SUB]:e=>{const t=e.popInt(),i=e.popInt();e.pushInt(i-t)},[Kt.MULTIPLY]:e=>{const t=e.popInt(),i=e.popInt();e.pushInt(i*t)},[Kt.DIVIDE]:e=>{const t=e.popInt(),i=e.popInt();e.pushInt(i/t)},[Kt.RANDOM]:e=>{const t=e.popInt();e.pushInt(Math.random()*t)},[Kt.RANDOMINC]:e=>{const t=e.popInt();e.pushInt(Math.random()*(t+1))},[Kt.INTERPOLATE]:e=>{const[t,i,r,s,n]=e.popInts(5),a=Math.floor((i-t)/(s-r))*(n-r)+t;e.pushInt(a)},[Kt.ADDPERCENT]:e=>{const[t,i]=e.popInts(2);e.pushInt(t*i/100+t|0)},[Kt.SETBIT]:e=>{const[t,i]=e.popInts(2);e.pushInt(t|1<{const[t,i]=e.popInts(2);e.pushInt(t&~(1<{const[t,i]=e.popInts(2);e.pushInt(t&1<{const[t,i]=e.popInts(2);e.pushInt(t%i)},[Kt.POW]:e=>{const[t,i]=e.popInts(2);e.pushInt(Math.pow(t,i))},[Kt.INVPOW]:e=>{const[t,i]=e.popInts(2);if(0===t||0===i)e.pushInt(0);else switch(i){case 1:return void e.pushInt(t);case 2:return void e.pushInt(Math.sqrt(t));case 3:return void e.pushInt(Math.cbrt(t));case 4:return void e.pushInt(Math.sqrt(Math.sqrt(t)));default:return void e.pushInt(Math.pow(t,1/i))}},[Kt.AND]:e=>{const[t,i]=e.popInts(2);e.pushInt(t&i)},[Kt.OR]:e=>{const[t,i]=e.popInts(2);e.pushInt(t|i)},[Kt.MIN]:e=>{const[t,i]=e.popInts(2);e.pushInt(Math.min(t,i))},[Kt.MAX]:e=>{const[t,i]=e.popInts(2);e.pushInt(Math.max(t,i))},[Kt.SCALE]:e=>{const[t,i,r]=e.popInts(3);e.pushInt(t*r/i)},[Kt.BITCOUNT]:e=>{var t;e.pushInt((t=e.popInt(),16843009*((t=(858993459&(t-=t>>1&1431655765))+(t>>2&858993459))+(t>>4)&252645135)>>24))},[Kt.TOGGLEBIT]:e=>{const[t,i]=e.popInts(2);e.pushInt(t^1<{const[t,i,r]=e.popInts(3);e.pushInt(function(e,t,i){return e|Yt[i-t+1]<{const[t,i,r]=e.popInts(3);e.pushInt(Qt(t,i,r))},[Kt.GETBIT_RANGE]:e=>{const[t,i,r]=e.popInts(3),s=31-r;e.pushInt(t<>>i+s)},[Kt.SETBIT_RANGE_TOINT]:e=>{const[t,i,r,s]=e.popInts(4),n=Qt(t,r,s),a=Yt[s-r+1];let o=i;i>a&&(o=a),e.pushInt(n|o<{e.pushInt(gs.sin(e.popInt()))},[Kt.COS_DEG]:e=>{e.pushInt(gs.cos(e.popInt()))},[Kt.ATAN2_DEG]:e=>{e.pushInt(gs.atan2(e.popInt(),e.popInt()))},[Kt.ABS]:e=>{e.pushInt(Math.abs(e.popInt()))}},ys=ms,Es={[Kt.OBJ_ADD]:e=>{const[t,i,r,s]=e.popInts(4);if(-1===i||-1===r)return;const n=Br(i,mr);Br(s,sr);const a=Br(t,nr);if(Br(r,yr),0!==n.dummyitem)throw new Error(`attempted to add dummy item: ${n.debugname}`);if(!n.members||vt.NODE_MEMBERS)if(n.stackable&&1!==r){const t=new $r(a.level,a.x,a.z,Yr.DESPAWN,i,r);Zl.addObj(t,e.activePlayer.pid,s),e.activeObj=t,e.pointerAdd(xt[e.intOperand])}else for(let t=0;t{const[t,i,r,s]=e.popInts(4);if(-1===i||-1===r)return;const n=Br(i,mr);Br(s,sr);const a=Br(t,nr);if(Br(r,yr),0!==n.dummyitem)throw new Error(`attempted to add dummy item: ${n.debugname}`);if(!n.members||vt.NODE_MEMBERS)if(n.stackable&&1!==r){const t=new $r(a.level,a.x,a.z,Yr.DESPAWN,i,r);Zl.addObj(t,-1,s),e.activeObj=t,e.pointerAdd(xt[e.intOperand])}else for(let t=0;t{const t=Br(e.popInt(),ar),i=Br(e.activeObj.type,mr);t.isString()?e.pushString(rt(t.id,i,t.defaultString)):e.pushInt(st(t.id,i,t.defaultInt))},[Kt.OBJ_NAME]:e=>{const t=Br(e.activeObj.type,mr);e.pushString(t.name??t.debugname??'null')},[Kt.OBJ_DEL]:e=>{const t=Tt.get(e.activeObj.type).respawnrate;e.pointerGet(Ft[e.intOperand]),Zl.removeObj(e.activeObj,t)},[Kt.OBJ_COUNT]:e=>{e.pushInt(Br(e.activeObj.count,yr))},[Kt.OBJ_TYPE]:e=>{e.pushInt(Br(e.activeObj.type,mr).id)},[Kt.OBJ_TAKEITEM]:e=>{const t=Br(e.popInt(),Er),i=e.activeObj,r=Tt.get(i.type),s=Zl.getZone(i.x,i.z,i.level);for(const n of s.getObjsSafe(ji.packZoneCoord(i.x,i.z)))if(n.type===i.type&&n.count===i.count&&(-1===n.receiverId||n.receiverId===e.activePlayer.pid)){if(e.activePlayer.playerLog('Picked up item',r.debugname),e.activePlayer.invAdd(t.id,i.type,i.count),i.lifecycle===Yr.RESPAWN){Zl.removeObj(i,r.respawnrate);break}if(i.lifecycle===Yr.DESPAWN){Zl.removeObj(i,0);break}}},[Kt.OBJ_COORD]:e=>{const t=e.activeObj;e.pushInt(ji.packCoord(t.level,t.x,t.z))}},_s={[Kt.OC_NAME]:e=>{const t=Br(e.popInt(),mr);e.pushString(t.name??t.debugname??'null')},[Kt.OC_PARAM]:e=>{const[t,i]=e.popInts(2),r=Br(t,mr),s=Br(i,ar);s.isString()?e.pushString(rt(s.id,r,s.defaultString)):e.pushInt(st(s.id,r,s.defaultInt))},[Kt.OC_CATEGORY]:e=>{e.pushInt(Br(e.popInt(),mr).category)},[Kt.OC_DESC]:e=>{e.pushString(Br(e.popInt(),mr).desc??'null')},[Kt.OC_MEMBERS]:e=>{e.pushInt(Br(e.popInt(),mr).members?1:0)},[Kt.OC_WEIGHT]:e=>{e.pushInt(Br(e.popInt(),mr).weight)},[Kt.OC_WEARPOS]:e=>{e.pushInt(Br(e.popInt(),mr).wearpos)},[Kt.OC_WEARPOS2]:e=>{e.pushInt(Br(e.popInt(),mr).wearpos2)},[Kt.OC_WEARPOS3]:e=>{e.pushInt(Br(e.popInt(),mr).wearpos3)},[Kt.OC_COST]:e=>{e.pushInt(Br(e.popInt(),mr).cost)},[Kt.OC_TRADEABLE]:e=>{e.pushInt(Br(e.popInt(),mr).tradeable?1:0)},[Kt.OC_DEBUGNAME]:e=>{e.pushString(Br(e.popInt(),mr).debugname??'null')},[Kt.OC_CERT]:e=>{const t=Br(e.popInt(),mr);-1==t.certtemplate&&t.certlink>=0?e.pushInt(t.certlink):e.pushInt(t.id)},[Kt.OC_UNCERT]:e=>{const t=Br(e.popInt(),mr);t.certtemplate>=0&&t.certlink>=0?e.pushInt(t.certlink):e.pushInt(t.id)},[Kt.OC_STACKABLE]:e=>{e.pushInt(Br(e.popInt(),mr).stackable?1:0)}},As=class extends Te{type;script;args;delay;lastInt=0;constructor(e,t,i,r){super(),this.type=e,this.script=t,this.args=i,this.delay=r}},vs=class extends Te{script;delay;constructor(e,t){super(),this.script=e,this.delay=t}},Ts=class e{constructor(t,i){this.id=t,this.length=i,e.all.push(this),e.byId[t]=this}static all=[];static byId=[];static IF_OPENCHATMODAL=new e(14,2);static IF_OPENMAINSIDEMODAL=new e(28,4);static IF_CLOSE=new e(129,0);static IF_OPENSIDEOVERLAY=new e(167,3);static IF_OPENMAINMODAL=new e(168,2);static IF_OPENSIDEMODAL=new e(195,2);static IF_SETCOLOUR=new e(2,4);static IF_SETHIDE=new e(26,3);static IF_SETOBJECT=new e(46,6);static IF_SHOWSIDE=new e(84,1);static IF_SETMODEL=new e(87,4);static IF_SETRECOL=new e(103,6);static IF_SETANIM=new e(146,4);static IF_SETPLAYERHEAD=new e(197,2);static IF_SETTEXT=new e(201,-2);static IF_SETNPCHEAD=new e(204,4);static IF_SETPOSITION=new e(209,6);static TUTORIAL_FLASHSIDE=new e(126,1);static TUTORIAL_OPENCHAT=new e(185,2);static UPDATE_INV_STOP_TRANSMIT=new e(15,2);static UPDATE_INV_FULL=new e(98,-2);static UPDATE_INV_PARTIAL=new e(213,-2);static CAM_LOOKAT=new e(74,6);static CAM_SHAKE=new e(13,4);static CAM_MOVETO=new e(3,6);static CAM_RESET=new e(239,0);static NPC_INFO=new e(1,-2);static PLAYER_INFO=new e(184,-2);static FINISH_TRACKING=new e(133,0);static ENABLE_TRACKING=new e(226,0);static MESSAGE_GAME=new e(4,-1);static UPDATE_IGNORELIST=new e(21,-2);static CHAT_FILTER_SETTINGS=new e(32,3);static MESSAGE_PRIVATE=new e(41,-1);static UPDATE_FRIENDLIST=new e(152,9);static UNSET_MAP_FLAG=new e(19,0);static UPDATE_RUNWEIGHT=new e(22,2);static HINT_ARROW=new e(25,6);static UPDATE_REBOOT_TIMER=new e(43,2);static UPDATE_STAT=new e(44,6);static UPDATE_RUNENERGY=new e(68,1);static RESET_ANIMS=new e(136,0);static UPDATE_UID192=new e(139,2);static LAST_LOGIN_INFO=new e(140,9);static LOGOUT=new e(142,0);static P_COUNTDIALOG=new e(243,0);static SET_MULTIWAY=new e(254,1);static DATA_LOC_DONE=new e(20,2);static DATA_LAND_DONE=new e(80,2);static DATA_LAND=new e(132,-2);static DATA_LOC=new e(220,-2);static REBUILD_NORMAL=new e(237,-2);static VARP_SMALL=new e(150,3);static VARP_LARGE=new e(175,6);static RESET_CLIENT_VARCACHE=new e(193,0);static SYNTH_SOUND=new e(12,5);static MIDI_SONG=new e(54,-1);static MIDI_JINGLE=new e(212,-2);static UPDATE_ZONE_PARTIAL_FOLLOWS=new e(7,2);static UPDATE_ZONE_FULL_FOLLOWS=new e(135,2);static UPDATE_ZONE_PARTIAL_ENCLOSED=new e(162,-2)},Cs=(e=>(e[e.STATIONARY=0]='STATIONARY',e[e.CRAWL=1]='CRAWL',e[e.WALK=2]='WALK',e[e.RUN=3]='RUN',e[e.INSTANT=4]='INSTANT',e))(Cs||{}),Is=Cs,Ss=(e=>(e[e.SMART=0]='SMART',e[e.NAIVE=1]='NAIVE',e[e.FLY=2]='FLY',e))(Ss||{}),Os=Ss,Ns=class e extends qr{moveRestrict;blockWalk;moveStrategy;coordmask;entitymask;moveSpeed=Is.INSTANT;walkDir=-1;runDir=-1;waypointIndex=-1;waypoints=new Int32Array(25);lastX=-1;lastZ=-1;lastLevel=-1;tele=!1;jump=!1;lastStepX=-1;lastStepZ=-1;stepsTaken=0;lastInt=-1;lastCrawl=!1;walktrigger=-1;walktriggerArg=0;interacted=!1;repathed=!1;target=null;targetOp=-1;targetSubject={type:-1,com:-1};targetX=-1;targetZ=-1;apRange=10;apRangeCalled=!1;alreadyFacedEntity=!1;mask=0;exactStartX=-1;exactStartZ=-1;exactEndX=-1;exactEndZ=-1;exactMoveStart=-1;exactMoveEnd=-1;exactMoveDirection=-1;faceX=-1;faceZ=-1;orientationX=-1;orientationZ=-1;faceEntity=-1;damageTaken=-1;damageType=-1;animId=-1;animDelay=-1;chat=null;graphicId=-1;graphicHeight=-1;graphicDelay=-1;constructor(e,t,i,r,s,n,a,o,c,l,h){super(e,t,i,r,s,n),this.moveRestrict=a,this.blockWalk=o,this.moveStrategy=c,this.coordmask=l,this.entitymask=h,this.lastStepX=t-1,this.lastStepZ=i}processMovement(){return!(!this.hasWaypoints()||this.moveSpeed===Is.STATIONARY||this.moveSpeed===Is.INSTANT)&&(this.moveSpeed===Is.CRAWL?(this.lastCrawl=!this.lastCrawl,this.lastCrawl&&-1===this.walkDir&&(this.walkDir=this.validateAndAdvanceStep()),!0):(-1===this.walkDir&&(this.walkDir=this.validateAndAdvanceStep(),this.moveSpeed===Is.RUN&&-1!==this.walkDir&&-1===this.runDir&&(this.runDir=this.validateAndAdvanceStep())),!0))}refreshZonePresence(e,t,i){if(this.x!=e||this.z!==t||this.level!==i){switch(this.blockWalk){case lt.NPC:Zl.gameMap.changeNpcCollision(this.width,e,t,i,!1),Zl.gameMap.changeNpcCollision(this.width,this.x,this.z,this.level,!0);break;case lt.ALL:Zl.gameMap.changeNpcCollision(this.width,e,t,i,!1),Zl.gameMap.changeNpcCollision(this.width,this.x,this.z,this.level,!0),Zl.gameMap.changePlayerCollision(this.width,e,t,i,!1),Zl.gameMap.changePlayerCollision(this.width,this.x,this.z,this.level,!0)}this.lastStepX=e,this.lastStepZ=t}ji.zone(e)===ji.zone(this.x)&&ji.zone(t)===ji.zone(this.z)&&i==this.level||(Zl.getZone(e,t,i).leave(this),Zl.getZone(this.x,this.z,this.level).enter(this))}validateAndAdvanceStep(){const e=this.takeStep();if(null===e)return-1;if(-1===e)return this.waypointIndex--,-1!=this.waypointIndex?this.validateAndAdvanceStep():-1;const t=this.x,i=this.z;return this.x=ji.moveX(this.x,e),this.z=ji.moveZ(this.z,e),this.orientationX=2*ji.moveX(this.x,e)+1,this.orientationZ=2*ji.moveZ(this.z,e)+1,this.stepsTaken++,this.refreshZonePresence(t,i,this.level),e}queueWaypoint(e,t){this.waypoints[0]=ji.packCoord(0,e,t),this.waypointIndex=0}queueWaypoints(e){let t=-1;for(let i=e.length-1,r=0;i>=0&&r2&&(this.jump=!0)}convertMovementDir(){let e=this.walkDir,t=this.runDir,i=this.moveSpeed===Is.INSTANT;const r=ji.distanceTo(this,{x:this.lastX,z:this.lastZ,width:this.width,length:this.length});if(i&&!this.jump&&r<=2){if(2===r){const i=(this.x+this.lastX)/2|0,r=(this.z+this.lastZ)/2|0;e=ji.face(this.lastX,this.lastZ,i,r),t=ji.face(i,r,this.x,this.z)}else e=ji.face(this.lastX,this.lastZ,this.x,this.z),t=-1;i=!1}this.walkDir=e,this.runDir=t,this.tele=i}hasWaypoints(){return-1!==this.waypointIndex}isLastOrNoWaypoint(){return this.waypointIndex<=0}inOperableDistance(t){if(t.level!==this.level)return!1;if(t instanceof e)return Ei(this.level,this.x,this.z,t.x,t.z,t.width,t.length,this.width,-1,-2);if(t instanceof ss){const e=at.get(t.type).forceapproach;return Ei(this.level,this.x,this.z,t.x,t.z,t.width,t.length,this.width,t.angle,t.shape,e)}const i=Ei(this.level,this.x,this.z,t.x,t.z,t.width,t.length,this.width,0,-2);return ui(t.x,t.z,t.level,Ri.WALK_BLOCKED)?i:!(this.hasWaypoints()||!i)||Ei(this.level,this.x,this.z,t.x,t.z,t.width,t.length,this.width,0,-1)}inApproachDistance(t,i){return i.level===this.level&&(!(i instanceof e&&ji.intersects(this.x,this.z,this.width,this.length,i.x,i.z,i.width,i.length))&&(ji.distanceTo(this,i)<=t&&fi(this.level,this.x,this.z,i.x,i.z,this.width,this.length,i.width,i.length,Ri.PLAYER)))}pathToMoveClick(e,t){if(this.moveStrategy===Os.SMART)if(t){const{x:t,z:i}=ji.unpackCoord(e[0]);this.queueWaypoints(ti(this.level,this.x,this.z,t,i))}else this.queueWaypoints(e);else{const{x:t,z:i}=ji.unpackCoord(e[e.length-1]);this.queueWaypoint(t,i)}}pathToPathingTarget(){this.target&&this.target instanceof e&&this.isLastOrNoWaypoint()&&(this.targetOp!==cs.APPLAYER3&&this.targetOp!==cs.OPPLAYER3?this.pathToTarget():this.queueWaypoint(this.target.lastStepX,this.target.lastStepZ))}pathToTarget(){if(!this.target)return;this.targetX=this.target.x,this.targetZ=this.target.z;const t=2*this.target.x+this.target.width,i=2*this.target.z+this.target.length;if(this.orientationX=t,this.orientationZ=i,this.moveStrategy===Os.SMART)if(this.target instanceof e)this.queueWaypoints(ti(this.level,this.x,this.z,this.target.x,this.target.z,this.width,this.target.width,this.target.length,0,-2));else if(this.target instanceof ss){const e=at.get(this.target.type).forceapproach;this.queueWaypoints(ti(this.level,this.x,this.z,this.target.x,this.target.z,this.width,this.target.width,this.target.length,this.target.angle,this.target.shape,!0,e))}else this.queueWaypoints(ti(this.level,this.x,this.z,this.target.x,this.target.z));else if(this.moveStrategy===Os.NAIVE){const t=this.getCollisionStrategy();if(null===t)return;const i=this.blockWalkFlag();if(i===Ri.NULL)return;this.target instanceof e?this.queueWaypoints(ii(this.level,this.x,this.z,this.target.x,this.target.z,this.width,this.length,this.target.width,this.target.length,i,t)):this.queueWaypoint(this.target.x,this.target.z)}else{if(null===this.getCollisionStrategy())return;if(this.blockWalkFlag()===Ri.NULL)return;this.queueWaypoint(this.target.x,this.target.z)}}setInteraction(e,t,i,r){this.target=t,this.targetOp=i,this.targetSubject=r??{type:-1,com:-1},this.targetX=t.x,this.targetZ=t.z,this.apRange=10,this.apRangeCalled=!1;const s=2*t.x+t.width,n=2*t.z+t.length;if(this.orientationX=s,this.orientationZ=n,t instanceof Do){const e=t.pid+32768;this.faceEntity!==e&&(this.faceEntity=e,this.mask|=this.entitymask)}else if(t instanceof kl){const e=t.nid;this.faceEntity!==e&&(this.faceEntity=e,this.mask|=this.entitymask)}else this.faceX===s&&this.faceZ===n||(this.faceX=s,this.faceZ=n,this.mask|=this.coordmask);e===hs.SCRIPT&&this.pathToTarget()}clearInteraction(){this.target=null,this.targetOp=-1,this.targetSubject={type:-1,com:-1},this.targetX=-1,this.targetZ=-1,this.apRange=10,this.apRangeCalled=!1,this.alreadyFacedEntity=!0}getCollisionStrategy(){return this.moveRestrict===dt.NORMAL?Di.NORMAL:this.moveRestrict===dt.BLOCKED?Di.BLOCKED:this.moveRestrict===dt.BLOCKED_NORMAL?Di.LINE_OF_SIGHT:this.moveRestrict===dt.INDOORS?Di.INDOORS:this.moveRestrict===dt.OUTDOORS?Di.OUTDOORS:this.moveRestrict===dt.NOMOVE?null:this.moveRestrict===dt.PASSTHRU?Di.NORMAL:null}resetPathingEntity(){this.moveSpeed=this.defaultMoveSpeed(),this.walkDir=-1,this.runDir=-1,this.jump=!1,this.tele=!1,this.lastX=this.x,this.lastZ=this.z,this.lastLevel=this.level,this.stepsTaken=0,this.interacted=!1,this.apRangeCalled=!1,this.mask=0,this.exactStartX=-1,this.exactStartZ=-1,this.exactEndX=-1,this.exactEndZ=-1,this.exactMoveStart=-1,this.exactMoveEnd=-1,this.exactMoveDirection=-1,this.animId=-1,this.animDelay=-1,this.animId=-1,this.animDelay=-1,this.chat=null,this.damageTaken=-1,this.damageType=-1,this.graphicId=-1,this.graphicHeight=-1,this.graphicDelay=-1,this.alreadyFacedEntity&&!this.target&&-1!==this.faceEntity&&(this.mask|=this.entitymask,this.faceEntity=-1,this.alreadyFacedEntity=!1)}takeStep(){if(-1===this.waypointIndex)return null;const e=this.x,t=this.z,{x:i,z:r}=ji.unpackCoord(this.waypoints[this.waypointIndex]),s=ji.face(e,t,i,r),n=ji.deltaX(s),a=ji.deltaZ(s);if(0==n&&0==a)return-1;const o=this.getCollisionStrategy();if(null===o)return-1;const c=this.blockWalkFlag();return c===Ri.NULL?-1:this.moveStrategy===Os.FLY||pi(this.level,this.x,this.z,n,a,this.width,c,o)?s:0!=n&&pi(this.level,this.x,this.z,n,0,this.width,c,o)?ji.face(e,t,i,t):0!=a&&pi(this.level,this.x,this.z,0,a,this.width,c,o)?ji.face(e,t,e,r):null}},Ls=class{sentinel;cursor=null;constructor(){const e=new Ie;e.nextHashable=e,e.prevHashable=e,this.sentinel=e}push(e){e.prevHashable&&e.uncache(),e.prevHashable=this.sentinel.prevHashable,e.nextHashable=this.sentinel,e.prevHashable&&(e.prevHashable.nextHashable=e),e.nextHashable.prevHashable=e}pop(){const e=this.sentinel.nextHashable;return e===this.sentinel?null:(e?.uncache(),e)}head(){const e=this.sentinel.nextHashable;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.nextHashable||null,e)}next(){const e=this.cursor;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.nextHashable||null,e)}clear(){for(;;){const e=this.sentinel.next;if(e==this.sentinel)return;e&&e.unlink()}}},Ps=new Map,ws=new Map;var bs=class extends Ie{},Rs=class e{static LOW=new e;static HIGH=new e},Bs=class extends bs{priority=Rs.LOW},Us=class extends bs{constructor(e){super(),this.uid=e}priority=Rs.HIGH},Ds=class extends bs{priority=Rs.HIGH},ks=class extends bs{priority=Rs.HIGH},Ms=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},xs=class extends bs{constructor(e){super(),this.component=e}priority=Rs.HIGH},Fs=class extends bs{constructor(e,t){super(),this.varp=e,this.value=t}priority=Rs.HIGH},Hs=class extends bs{constructor(e,t){super(),this.varp=e,this.value=t}priority=Rs.HIGH},Vs=class extends bs{constructor(e,t,i){super(),this.name=e,this.crc=t,this.length=i}priority=Rs.LOW},Gs=class extends bs{constructor(e,t){super(),this.delay=e,this.data=t}priority=Rs.LOW},Ws=class extends bs{constructor(e,t){super(),this.component=e,this.tab=t}priority=Rs.LOW},Ks=class extends bs{priority=Rs.HIGH},zs=class extends bs{constructor(e,t,i,r,s,n){super(),this.type=e,this.nid=t,this.pid=i,this.x=r,this.z=s,this.y=n}priority=Rs.LOW},js=class extends bs{constructor(e,t,i,r){super(),this.lastLoginIp=e,this.daysSinceLogin=t,this.daysSinceRecoveryChange=i,this.unreadMessageCount=r}priority=Rs.LOW},Ys=class extends bs{constructor(e){super(),this.msg=e}priority=Rs.HIGH},qs=class{type;receiverId;message;constructor(e,t,i){this.type=e,this.receiverId=t,this.message=i}},Qs=(e=>(e[e.ENCLOSED=0]='ENCLOSED',e[e.FOLLOWS=1]='FOLLOWS',e))(Qs||{}),$s=Qs,Zs=class extends bs{constructor(e,t,i,r,s){super(),this.zoneX=e,this.zoneZ=t,this.originX=i,this.originZ=r,this.data=s}priority=Rs.HIGH},Xs=class extends bs{constructor(e,t,i,r){super(),this.zoneX=e,this.zoneZ=t,this.originX=i,this.originZ=r}priority=Rs.HIGH},Js=class extends bs{constructor(e,t,i,r){super(),this.zoneX=e,this.zoneZ=t,this.originX=i,this.originZ=r}priority=Rs.HIGH},en=class extends bs{constructor(e){super(),this.coord=e}priority=Rs.HIGH},tn=class extends en{constructor(e,t,i){super(e),this.coord=e,this.obj=t,this.count=i}},rn=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.loc=t,this.shape=i,this.angle=r}},sn=class extends en{constructor(e,t,i){super(e),this.coord=e,this.shape=t,this.angle=i}},nn=class extends en{constructor(e,t,i,r,s,n,a,o,c,l,h,d){super(ji.packZoneCoord(e,t)),this.srcX=e,this.srcZ=t,this.dstX=i,this.dstZ=r,this.target=s,this.spotanim=n,this.srcHeight=a,this.dstHeight=o,this.startDelay=c,this.endDelay=l,this.peak=h,this.arc=d}},an=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.spotanim=t,this.height=i,this.delay=r}},on=class extends en{constructor(e,t){super(e),this.coord=e,this.obj=t}},cn=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.obj=t,this.oldCount=i,this.newCount=r}},ln=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.obj=t,this.count=i,this.receiverId=r}},hn=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.shape=t,this.angle=i,this.seq=r}},dn=class extends en{constructor(e,t,i,r,s,n,a,o,c,l,h,d){super(ji.packZoneCoord(e,t)),this.srcX=e,this.srcZ=t,this.shape=i,this.angle=r,this.locId=s,this.startCycle=n,this.endCycle=a,this.pid=o,this.east=c,this.south=l,this.west=h,this.north=d}},un=class{test(e){return this.prot.length}},pn=class extends un{prot=Ts.IF_OPENCHATMODAL;encode(e,t){e.p2(t.component)}},fn=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},gn=class extends bs{constructor(e,t,i,r,s,n,a,o,c,l,h,d,u,p,f){super(),this.buildArea=e,this.level=t,this.x=i,this.z=r,this.originX=s,this.originZ=n,this.uid=a,this.mask=o,this.tele=c,this.jump=l,this.walkDir=h,this.runDir=d,this.deltaX=u,this.deltaZ=p,this.changedLevel=f}priority=Rs.HIGH;accumulator=0},mn=class e extends un{static BITS_NEW=23;static BITS_IDLE=1;static BITS_RUN=10;static BITS_WALK=7;static BITS_EXTENDED=3;static BYTES_LIMIT=4997;prot=Ts.PLAYER_INFO;encode(e,t){const i=t.buildArea;t.changedLevel||t.deltaX>i.viewDistance||t.deltaZ>i.viewDistance?(i.players.clear(),i.lastResize=0,i.viewDistance=wo.PREFERRED_VIEW_DISTANCE):i.resize(),this.writeLocalPlayer(e,t),this.writePlayers(e,t),this.writeNewPlayers(e,t);const r=i.extendedInfo;if(r.size>0)for(const i of r){const r=Zl.getPlayerByUid(i.id);r?this.writeExtendedInfo(r,t,e,i.id===t.uid,i.added):e.p1(0)}i.clearExtended()}test(t){return e.BYTES_LIMIT}willFit(t,i,r,s){return(i.bitPos+r+7>>>3)+(t.accumulator+s)<=e.BYTES_LIMIT}writeLocalPlayer(e,t){const{buildArea:i,uid:r,level:s,x:n,z:a,tele:o,jump:c,walkDir:l,runDir:h}=t,d=Zl.getPlayerByUid(r);if(!d)return;const u=this.calculateExtendedInfo(d,t,!0,!1),p=u>0;e.bits(),e.pBit(1,o||-1!==h||-1!==l||p?1:0),o?(e.pBit(2,3),e.pBit(2,s),e.pBit(7,ji.local(n,d.originX)),e.pBit(7,ji.local(a,d.originZ)),e.pBit(1,c?1:0),e.pBit(1,p?1:0)):-1!==h?(e.pBit(2,2),e.pBit(3,l),e.pBit(3,h),e.pBit(1,p?1:0)):-1!==l?(e.pBit(2,1),e.pBit(3,l),e.pBit(1,p?1:0)):p&&e.pBit(2,0),p&&(i.extendedInfo.add({id:r,added:!1}),t.accumulator+=u)}writePlayers(t,i){const r=i.buildArea;t.pBit(8,r.players.size);for(const s of r.players){const n=Zl.getPlayerByUid(s);if(!n||n.tele||n.level!==i.level||!ji.isWithinDistanceSW(i,n,r.viewDistance)||!n.checkLifeCycle(Zl.currentTick)){t.pBit(1,1),t.pBit(2,3),r.players.delete(s);continue}const a=this.calculateExtendedInfo(n,i,!1,!1);let o=a>0;const{walkDir:c,runDir:l}=n;let h=e.BITS_IDLE;-1!==l?h=e.BITS_RUN:-1!==c?h=e.BITS_WALK:o&&(h=e.BITS_EXTENDED),this.willFit(i,t,h,a)||(o=!1),t.pBit(1,-1!==l||-1!==c||o?1:0),-1!==l?(t.pBit(2,2),t.pBit(3,c),t.pBit(3,l),t.pBit(1,o?1:0)):-1!==c?(t.pBit(2,1),t.pBit(3,c),t.pBit(1,o?1:0)):o&&t.pBit(2,0),o&&(r.extendedInfo.add({id:s,added:!1}),i.accumulator+=a)}}writeNewPlayers(t,i){const r=i.buildArea;for(const s of r.getNearbyPlayers(i.uid,i.x,i.z,i.originX,i.originZ)){const n=this.calculateExtendedInfo(s,i,!1,!0),a=n>0;if(!this.willFit(i,t,e.BITS_NEW+11,n))break;t.pBit(11,s.pid),t.pBit(5,s.x-i.x),t.pBit(5,s.z-i.z),t.pBit(1,s.jump?1:0),t.pBit(1,a?1:0),a&&(r.extendedInfo.add({id:s.uid,added:!0}),i.accumulator+=n),r.players.add(s.uid)}r.extendedInfo.size>0&&t.pBit(11,2047),t.bytes()}writeExtendedInfo(e,t,i,r=!1,s=!1){let n=e.mask;s&&(-1===e.orientationX&&-1===e.faceX||(n|=Do.FACE_COORD),-1!==e.faceEntity&&(n|=Do.FACE_ENTITY)),r&&n&Do.CHAT&&(n&=~Do.CHAT),t.buildArea.hasAppearance(e.uid,e.lastAppearance)||!e.appearance?n&=~Do.APPEARANCE:n|=Do.APPEARANCE,n>255&&(n|=Do.BIG_UPDATE),i.p1(255&n),n&Do.BIG_UPDATE&&i.p1(n>>8),n&Do.APPEARANCE&&(i.p1(e.appearance.length),i.pdata(e.appearance,0,e.appearance.length),t.buildArea.saveAppearance(e.uid,e.lastAppearance)),n&Do.ANIM&&(i.p2(e.animId),i.p1(e.animDelay)),n&Do.FACE_ENTITY&&(-1!==e.faceEntity&&(e.alreadyFacedEntity=!0),i.p2(e.faceEntity)),n&Do.SAY&&i.pjstr(e.chat??''),n&Do.DAMAGE&&(i.p1(e.damageTaken),i.p1(e.damageType),i.p1(e.levels[$i.HITPOINTS]),i.p1(e.baseLevels[$i.HITPOINTS])),n&Do.FACE_COORD&&(s&&-1!==e.orientationX?(i.p2(e.orientationX),i.p2(e.orientationZ)):(i.p2(e.faceX),i.p2(e.faceZ))),n&Do.CHAT&&(i.p1(e.messageColor),i.p1(e.messageEffect),i.p1(e.messageType),i.p1(e.message.length),i.pdata(e.message,0,e.message.length)),n&Do.SPOTANIM&&(i.p2(e.graphicId),i.p2(e.graphicHeight),i.p2(e.graphicDelay)),n&Do.EXACT_MOVE&&(i.p1(e.exactStartX-ji.zoneOrigin(t.originX)),i.p1(e.exactStartZ-ji.zoneOrigin(t.originZ)),i.p1(e.exactEndX-ji.zoneOrigin(t.originX)),i.p1(e.exactEndZ-ji.zoneOrigin(t.originZ)),i.p2(e.exactMoveStart),i.p2(e.exactMoveEnd),i.p1(e.exactMoveDirection))}calculateExtendedInfo(e,t,i=!1,r=!1){let s=0,n=e.mask;return r&&(-1===e.orientationX&&-1===e.faceX||(n|=Do.FACE_COORD),-1!==e.faceEntity&&(n|=Do.FACE_ENTITY)),i&&n&Do.CHAT&&(n&=~Do.CHAT),t.buildArea.hasAppearance(e.uid,e.lastAppearance)||!e.appearance?n&=~Do.APPEARANCE:n|=Do.APPEARANCE,n>255&&(n|=Do.BIG_UPDATE),0===n?0:(s+=1,n&Do.BIG_UPDATE&&(s+=1),n&Do.APPEARANCE&&(s+=1+e.appearance.length),n&Do.ANIM&&(s+=3),n&Do.FACE_ENTITY&&(s+=2),n&Do.SAY&&(s+=1+e.chat.length),n&Do.DAMAGE&&(s+=4),n&Do.FACE_COORD&&(s+=4),n&Do.CHAT&&(s+=4+e.message.length),n&Do.SPOTANIM&&(s+=6),n&Do.EXACT_MOVE&&(s+=9),s)}},yn=class extends bs{constructor(e,t){super(),this.zoneX=e,this.zoneZ=t}priority=Rs.HIGH;get mapsquares(){const e=this.zoneX-6,t=this.zoneX+6,i=this.zoneZ-6,r=this.zoneZ+6,s=new Set;for(let n=e;n<=t;n++){const e=ji.mapsquare(n<<3);for(let t=i;t<=r;t++){const i=ji.mapsquare(t<<3);s.add(e<<8|i)}}return s}},En=class extends un{prot=Ts.REBUILD_NORMAL;encode(e,t){e.p2(t.zoneX),e.p2(t.zoneZ);for(const i of t.mapsquares){const t=i>>8,r=255&i;e.p1(t),e.p1(r),e.p4(ws.get(`m${t}_${r}`)??0),e.p4(ws.get(`l${t}_${r}`)??0)}}test(e){return 4+10*e.mapsquares.size}},_n=class extends bs{constructor(e,t,i,r,s){super(),this.x=e,this.z=t,this.offset=i,this.length=r,this.data=s}priority=Rs.HIGH},An=class extends un{prot=Ts.DATA_LAND;encode(e,t){e.p1(t.x),e.p1(t.z),e.p2(t.offset),e.p2(t.length),e.pdata(t.data,0,t.data.length)}test(e){return 6+e.data.length}},vn=class extends bs{constructor(e,t){super(),this.x=e,this.z=t}priority=Rs.HIGH},Tn=class extends un{prot=Ts.DATA_LAND_DONE;encode(e,t){e.p1(t.x),e.p1(t.z)}},Cn=class extends bs{constructor(e,t,i,r,s){super(),this.x=e,this.z=t,this.offset=i,this.length=r,this.data=s}priority=Rs.HIGH},In=class extends un{prot=Ts.DATA_LOC;encode(e,t){e.p1(t.x),e.p1(t.z),e.p2(t.offset),e.p2(t.length),e.pdata(t.data,0,t.data.length)}test(e){return 6+e.data.length}},Sn=class extends bs{constructor(e,t){super(),this.x=e,this.z=t}priority=Rs.HIGH},On=class extends un{prot=Ts.DATA_LOC_DONE;encode(e,t){e.p1(t.x),e.p1(t.z)}},Nn=class extends bs{constructor(e,t,i,r,s){super(),this.x=e,this.z=t,this.height=i,this.speed=r,this.multiplier=s}priority=Rs.LOW},Ln=class extends un{prot=Ts.CAM_LOOKAT;encode(e,t){e.p1(t.x),e.p1(t.z),e.p2(t.height),e.p1(t.speed),e.p1(t.multiplier)}},Pn=class extends bs{constructor(e,t,i,r,s){super(),this.x=e,this.z=t,this.height=i,this.speed=r,this.multiplier=s}priority=Rs.LOW},wn=class extends un{prot=Ts.CAM_MOVETO;encode(e,t){e.p1(t.x),e.p1(t.z),e.p2(t.height),e.p1(t.speed),e.p1(t.multiplier)}},bn=class extends bs{priority=Rs.LOW},Rn=class extends un{prot=Ts.CAM_RESET;encode(e,t){}},Bn=class extends bs{constructor(e,t,i,r){super(),this.type=e,this.jitter=t,this.amplitude=i,this.frequency=r}priority=Rs.LOW},Un=class extends un{prot=Ts.CAM_SHAKE;encode(e,t){e.p1(t.type),e.p1(t.jitter),e.p1(t.amplitude),e.p1(t.frequency)}},Dn=class extends bs{constructor(e,t,i){super(),this.publicChat=e,this.privateChat=t,this.tradeDuel=i}priority=Rs.HIGH},kn=class extends un{prot=Ts.CHAT_FILTER_SETTINGS;encode(e,t){e.p1(t.publicChat),e.p1(t.privateChat),e.p1(t.tradeDuel)}},Mn=class extends bs{priority=Rs.LOW},xn=class extends un{prot=Ts.ENABLE_TRACKING;encode(e,t){}},Fn=class extends bs{priority=Rs.LOW},Hn=class extends un{prot=Ts.FINISH_TRACKING;encode(e,t){}},Vn=class extends un{prot=Ts.HINT_ARROW;encode(e,t){const{type:i,nid:r,pid:s,x:n,z:a,y:o}=t;1===i?(e.p1(i),e.p2(r),e.p2(0),e.p1(0)):i>=2&&i<=6?(e.p1(i),e.p2(n),e.p2(a),e.p1(o)):10===i?(e.p1(i),e.p2(s),e.p2(0),e.p1(0)):-1===i&&(e.p1(-1),e.p2(0),e.p2(0),e.p1(0))}},Gn=class extends un{prot=Ts.IF_CLOSE;encode(e,t){}},Wn=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},Kn=class extends un{prot=Ts.IF_OPENMAINMODAL;encode(e,t){e.p2(t.component)}},zn=class extends bs{constructor(e,t){super(),this.main=e,this.side=t}priority=Rs.LOW},jn=class extends un{prot=Ts.IF_OPENMAINSIDEMODAL;encode(e,t){e.p2(t.main),e.p2(t.side)}},Yn=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},qn=class extends un{prot=Ts.IF_OPENSIDEMODAL;encode(e,t){e.p2(t.component)}},Qn=class extends un{prot=Ts.IF_OPENSIDEOVERLAY;encode(e,t){e.p2(t.component),e.p1(t.tab)}},$n=class extends bs{constructor(e,t){super(),this.component=e,this.seq=t}priority=Rs.LOW},Zn=class extends un{prot=Ts.IF_SETANIM;encode(e,t){e.p2(t.component),e.p2(t.seq)}},Xn=class extends bs{constructor(e,t){super(),this.component=e,this.colour=t}priority=Rs.LOW},Jn=class extends un{prot=Ts.IF_SETCOLOUR;encode(e,t){e.p2(t.component),e.p2(t.colour)}},ea=class extends bs{constructor(e,t){super(),this.component=e,this.hidden=t}priority=Rs.LOW},ta=class extends un{prot=Ts.IF_SETHIDE;encode(e,t){e.p2(t.component),e.pbool(t.hidden)}},ia=class extends bs{constructor(e,t){super(),this.component=e,this.model=t}priority=Rs.LOW},ra=class extends un{prot=Ts.IF_SETMODEL;encode(e,t){e.p2(t.component),e.p2(t.model)}},sa=class extends bs{constructor(e,t){super(),this.component=e,this.npc=t}priority=Rs.LOW},na=class extends un{prot=Ts.IF_SETNPCHEAD;encode(e,t){e.p2(t.component),e.p2(t.npc)}},aa=class extends bs{constructor(e,t,i){super(),this.component=e,this.obj=t,this.scale=i}priority=Rs.LOW},oa=class extends un{prot=Ts.IF_SETOBJECT;encode(e,t){e.p2(t.component),e.p2(t.obj),e.p2(t.scale)}},ca=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},la=class extends un{prot=Ts.IF_SETPLAYERHEAD;encode(e,t){e.p2(t.component)}},ha=class extends bs{constructor(e,t,i){super(),this.component=e,this.x=t,this.y=i}priority=Rs.LOW},da=class extends un{prot=Ts.IF_SETPOSITION;encode(e,t){e.p2(t.component),e.p2(t.x),e.p2(t.y)}},ua=class extends bs{constructor(e,t,i){super(),this.component=e,this.src=t,this.dst=i}priority=Rs.LOW},pa=class extends un{prot=Ts.IF_SETRECOL;encode(e,t){e.p2(t.component),e.p2(t.src),e.p2(t.dst)}},fa=class extends bs{constructor(e,t){super(),this.component=e,this.text=t}priority=Rs.LOW},ga=class extends un{prot=Ts.IF_SETTEXT;encode(e,t){e.p2(t.component),e.pjstr(t.text)}test(e){return 3+e.text.length}},ma=class extends bs{constructor(e){super(),this.tab=e}priority=Rs.LOW},ya=class extends un{prot=Ts.IF_SHOWSIDE;encode(e,t){e.p1(t.tab)}},Ea=class extends un{prot=Ts.LAST_LOGIN_INFO;encode(e,t){e.p4(t.lastLoginIp),e.p2(t.daysSinceLogin),e.p1(t.daysSinceRecoveryChange),e.p2(t.unreadMessageCount)}},_a=class e extends Ts{static LOC_MERGE=new e(23,14);static LOC_ANIM=new e(42,4);static OBJ_DEL=new e(49,3);static OBJ_REVEAL=new e(50,7);static LOC_ADD_CHANGE=new e(59,4);static MAP_PROJANIM=new e(69,15);static LOC_DEL=new e(76,2);static OBJ_COUNT=new e(151,7);static MAP_ANIM=new e(191,6);static OBJ_ADD=new e(223,5)},Aa=class extends un{enclose(e){const t=new Oe(new Uint8Array(1+this.prot.length));return t.p1(this.prot.id),this.encode(t,e),t.data}},va=class extends Aa{prot=_a.LOC_ADD_CHANGE;encode(e,t){e.p1(t.coord),e.p1(t.shape<<2|3&t.angle),e.p2(t.loc)}},Ta=class extends Aa{prot=_a.LOC_ANIM;encode(e,t){e.p1(t.coord),e.p1(t.shape<<2|3&t.angle),e.p2(t.seq)}},Ca=class extends Aa{prot=_a.LOC_DEL;encode(e,t){e.p1(t.coord),e.p1(t.shape<<2|3&t.angle)}},Ia=class extends Aa{prot=_a.LOC_MERGE;encode(e,t){e.p1(t.coord),e.p1(t.shape<<2|3&t.angle),e.p2(t.locId),e.p2(t.startCycle),e.p2(t.endCycle),e.p2(t.pid),e.p1(t.east-t.srcX),e.p1(t.south-t.srcZ),e.p1(t.west-t.srcX),e.p1(t.north-t.srcZ)}},Sa=class extends bs{priority=Rs.HIGH},Oa=class extends un{prot=Ts.LOGOUT;encode(e,t){}},Na=class extends Aa{prot=_a.MAP_ANIM;encode(e,t){e.p1(t.coord),e.p2(t.spotanim),e.p1(t.height),e.p2(t.delay)}},La=class extends Aa{prot=_a.MAP_PROJANIM;encode(e,t){e.p1(t.coord),e.p1(t.dstX-t.srcX),e.p1(t.dstZ-t.srcZ),e.p2(t.target),e.p2(t.spotanim),e.p1(t.srcHeight),e.p1(t.dstHeight),e.p2(t.startDelay),e.p2(t.endDelay),e.p1(t.peak),e.p1(t.arc)}},Pa=class extends un{prot=Ts.MESSAGE_GAME;encode(e,t){e.pjstr(t.msg)}test(e){return 1+e.msg.length}},wa=class{static CHAR_LOOKUP=[" ","e","t","a","o","i","h","n","s","r","d","l","u","m","w","c","y","f","g","p","b","v","k","x","j","q","z","0","1","2","3","4","5","6","7","8","9"," ","!","?",".",",",":",";","(",")","-","&","*","\\","'","@","#","+","=","£","$","%",'"',"[","]"];static unpack(e,t){const i=[];let r,s=0,n=-1;for(let a=0;a>4&15,-1!==n?(i[s++]=this.CHAR_LOOKUP[(n<<4)+r-195],n=-1):r<13?i[s++]=this.CHAR_LOOKUP[r]:n=r,r=15&t,-1!=n?(i[s++]=this.CHAR_LOOKUP[(n<<4)+r-195],n=-1):r<13?i[s++]=this.CHAR_LOOKUP[r]:n=r}return this.toSentenceCase(i.slice(0,s).join(''))}static pack(e,t){t.length>80&&(t=t.substring(0,80)),t=t.toLowerCase();let i=-1;for(let r=0;r12&&(n+=195),-1==i?n<13?i=n:e.p1(n):n<13?(e.p1((i<<4)+n),i=-1):(e.p1((i<<4)+(n>>4)),i=15&n)}-1!=i&&e.p1(i<<4)}static toSentenceCase(e){const t=[...e.toLowerCase()];let i=!0;for(let e=0;e='a'&&r<='z'&&(t[e]=r.toUpperCase(),i=!1),'.'!==r&&'!'!==r||(i=!0)}return t.join('')}},ba=class extends un{prot=Ts.MESSAGE_PRIVATE;encode(e,t){e.p8(t.from),e.p4(t.messageId),e.p1(t.staffModLevel),wa.pack(e,Bt.filter(t.msg))}test(e){return 14+e.msg.length}},Ra=class extends bs{constructor(e,t,i,r){super(),this.from=e,this.messageId=t,this.staffModLevel=i,this.msg=r}priority=Rs.HIGH},Ba=class extends un{prot=Ts.MIDI_JINGLE;encode(e,t){e.p2(t.delay),e.p4(t.data.length),e.pdata(t.data,0,t.data.length)}test(e){return 6+e.data.length}},Ua=class extends un{prot=Ts.MIDI_SONG;encode(e,t){e.pjstr(t.name),e.p4(t.crc),e.p4(t.length)}test(e){return 1+e.name.length+4+4}},Da=class extends Aa{prot=_a.OBJ_ADD;encode(e,t){e.p1(t.coord),e.p2(t.obj),e.p2(Math.min(t.count,65535))}},ka=class extends Aa{prot=_a.OBJ_COUNT;encode(e,t){e.p1(t.coord),e.p2(t.obj),e.p2(Math.min(t.oldCount,65535)),e.p2(Math.min(t.newCount,65535))}},Ma=class extends Aa{prot=_a.OBJ_DEL;encode(e,t){e.p1(t.coord),e.p2(t.obj)}},xa=class extends Aa{prot=_a.OBJ_REVEAL;encode(e,t){e.p1(t.coord),e.p2(t.obj),e.p2(Math.min(t.count,65535)),e.p2(t.receiverId)}},Fa=class extends bs{priority=Rs.LOW},Ha=class extends un{prot=Ts.P_COUNTDIALOG;encode(e,t){}},Va=class extends un{prot=Ts.RESET_ANIMS;encode(e,t){}},Ga=class extends un{prot=Ts.RESET_CLIENT_VARCACHE;encode(e,t){}},Wa=class extends bs{constructor(e){super(),this.hidden=e}priority=Rs.LOW},Ka=class extends un{prot=Ts.SET_MULTIWAY;encode(e,t){e.pbool(t.hidden)}},za=class extends bs{constructor(e,t,i){super(),this.synth=e,this.loops=t,this.delay=i}priority=Rs.LOW},ja=class extends un{prot=Ts.SYNTH_SOUND;encode(e,t){e.p2(t.synth),e.p1(t.loops),e.p2(t.delay)}},Ya=class extends bs{constructor(e){super(),this.tab=e}priority=Rs.LOW},qa=class extends un{prot=Ts.TUTORIAL_FLASHSIDE;encode(e,t){e.p1(t.tab)}},Qa=class extends un{prot=Ts.TUTORIAL_OPENCHAT;encode(e,t){e.p2(t.component)}},$a=class extends un{prot=Ts.UNSET_MAP_FLAG;encode(e,t){}},Za=class extends bs{constructor(e,t){super(),this.name=e,this.nodeId=t}priority=Rs.LOW},Xa=class extends un{prot=Ts.UPDATE_FRIENDLIST;encode(e,t){e.p8(t.name),e.p1(t.nodeId)}},Ja=class extends bs{constructor(e){super(),this.names=e}priority=Rs.LOW},eo=class extends un{prot=Ts.UPDATE_IGNORELIST;encode(e,t){for(const i of t.names)e.p8(i)}test(e){return 8*e.names.length}},to=class extends bs{constructor(e,t){super(),this.component=e,this.inv=t}priority=Rs.HIGH},io=class extends un{prot=Ts.UPDATE_INV_FULL;encode(e,t){const{component:i,inv:r}=t,s=tt.get(i),n=Math.min(r.capacity,s.width*s.height);e.p2(i),e.p1(n);for(let t=0;t=255?(e.p1(255),e.p4(i.count)):e.p1(i.count)):(e.p2(0),e.p1(0))}}test(e){const{component:t,inv:i}=e,r=tt.get(t),s=Math.min(i.capacity,r.width*r.height);let n=0;n+=3;for(let e=0;e=255?n+=5:n+=1):n+=3}return n}},ro=class extends bs{constructor(e,t,...i){super(),this.component=e,this.inv=t,this.slots=i}priority=Rs.HIGH;slots},so=class extends un{prot=Ts.UPDATE_INV_PARTIAL;encode(e,t){const{component:i,inv:r}=t;e.p2(i);for(const i of t.slots){const t=r.get(i);e.p1(i),t?(e.p2(t.id+1),t.count>=255?(e.p1(255),e.p4(t.count)):e.p1(t.count)):(e.p2(0),e.p1(0))}}test(e){const{inv:t}=e;let i=0;i+=2;for(const r of e.slots){const e=t.get(r);i+=1,e?(i+=2,e.count>=255?i+=5:i+=1):i+=3}return i}},no=class extends un{prot=Ts.UPDATE_INV_STOP_TRANSMIT;encode(e,t){e.p2(t.component)}},ao=class extends bs{constructor(e){super(),this.energy=e}priority=Rs.LOW},oo=class extends un{prot=Ts.UPDATE_RUNENERGY;encode(e,t){e.p1(t.energy/100|0)}},co=class extends bs{constructor(e){super(),this.kg=e}priority=Rs.LOW},lo=class extends un{prot=Ts.UPDATE_RUNWEIGHT;encode(e,t){e.p2(t.kg)}},ho=class extends bs{constructor(e,t,i){super(),this.stat=e,this.exp=t,this.level=i}priority=Rs.LOW},uo=class extends un{prot=Ts.UPDATE_STAT;encode(e,t){e.p1(t.stat),e.p4(t.exp/10|0),e.p1(t.level)}},po=class extends un{prot=Ts.UPDATE_UID192;encode(e,t){e.p2(t.uid)}},fo=class extends un{prot=Ts.UPDATE_ZONE_FULL_FOLLOWS;encode(e,t){e.p1((t.zoneX<<3)-ji.zoneOrigin(t.originX)),e.p1((t.zoneZ<<3)-ji.zoneOrigin(t.originZ))}},go=class extends un{prot=Ts.UPDATE_ZONE_PARTIAL_FOLLOWS;encode(e,t){e.p1((t.zoneX<<3)-ji.zoneOrigin(t.originX)),e.p1((t.zoneZ<<3)-ji.zoneOrigin(t.originZ))}},mo=class extends un{prot=Ts.UPDATE_ZONE_PARTIAL_ENCLOSED;encode(e,t){e.p1((t.zoneX<<3)-ji.zoneOrigin(t.originX)),e.p1((t.zoneZ<<3)-ji.zoneOrigin(t.originZ)),e.pdata(t.data,0,t.data.length)}test(e){return 2+e.data.length}},yo=class extends un{prot=Ts.VARP_LARGE;encode(e,t){e.p2(t.varp),e.p4(t.value)}},Eo=class extends un{prot=Ts.VARP_SMALL;encode(e,t){e.p2(t.varp),e.p1(t.value)}},_o=class extends bs{constructor(e,t,i,r,s,n,a,o,c){super(),this.buildArea=e,this.level=t,this.x=i,this.z=r,this.originX=s,this.originZ=n,this.deltaX=a,this.deltaZ=o,this.changedLevel=c}priority=Rs.HIGH;accumulator=0},Ao=class e extends un{static BITS_NEW=35;static BITS_IDLE=1;static BITS_RUN=10;static BITS_WALK=7;static BITS_EXTENDED=3;static BYTES_LIMIT=4997;prot=Ts.NPC_INFO;encode(e,t){const i=t.buildArea;(t.changedLevel||t.deltaX>i.viewDistance||t.deltaZ>i.viewDistance)&&i.npcs.clear(),this.writeNpcs(e,t),this.writeNewNpcs(e,t);const r=i.extendedInfo;if(r.size>0)for(const t of r){const i=Zl.getNpc(t.id);i?this.writeExtendedInfo(i,e,t.added):e.p1(0)}i.clearExtended()}test(t){return e.BYTES_LIMIT}willFit(t,i,r,s){return(i.bitPos+r+7>>>3)+(t.accumulator+s)<=e.BYTES_LIMIT}writeNpcs(t,i){const r=i.buildArea;t.bits(),t.pBit(8,r.npcs.size);for(const s of r.npcs){const n=Zl.getNpc(s);if(!n||n.tele||n.level!==i.level||!ji.isWithinDistanceSW(i,n,15)||!n.checkLifeCycle(Zl.currentTick)){t.pBit(1,1),t.pBit(2,3),r.npcs.delete(s);continue}const a=this.calculateExtendedInfo(n,!1);let o=a>0;const{walkDir:c,runDir:l}=n;let h=e.BITS_IDLE;-1!==l?h=e.BITS_RUN:-1!==c?h=e.BITS_WALK:o&&(h=e.BITS_EXTENDED),this.willFit(i,t,h,a)||(o=!1),t.pBit(1,-1!==l||-1!==c||o?1:0),-1!==l?(t.pBit(2,2),t.pBit(3,c),t.pBit(3,l),t.pBit(1,o?1:0)):-1!==c?(t.pBit(2,1),t.pBit(3,c),t.pBit(1,o?1:0)):o&&t.pBit(2,0),o&&(r.extendedInfo.add({id:s,added:!1}),i.accumulator+=a)}}writeNewNpcs(t,i){const r=i.buildArea;for(const s of r.getNearbyNpcs(i.x,i.z,i.originX,i.originZ)){const n=this.calculateExtendedInfo(s,!0),a=n>0;if(!this.willFit(i,t,e.BITS_NEW+13,n))break;t.pBit(13,s.nid),t.pBit(11,s.type),t.pBit(5,s.x-i.x),t.pBit(5,s.z-i.z),t.pBit(1,a?1:0),a&&(r.extendedInfo.add({id:s.nid,added:!0}),i.accumulator+=n),r.npcs.add(s.nid)}r.extendedInfo.size>0&&t.pBit(13,8191),t.bytes()}writeExtendedInfo(e,t,i){let r=e.mask;i&&(-1===e.orientationX&&-1===e.faceX||(r|=kl.FACE_COORD),-1!==e.faceEntity&&(r|=kl.FACE_ENTITY)),t.p1(r),r&kl.ANIM&&(t.p2(e.animId),t.p1(e.animDelay)),r&kl.FACE_ENTITY&&(-1!==e.faceEntity&&(e.alreadyFacedEntity=!0),t.p2(e.faceEntity)),r&kl.SAY&&t.pjstr(e.chat??''),r&kl.DAMAGE&&(t.p1(e.damageTaken),t.p1(e.damageType),t.p1(e.levels[pt.HITPOINTS]),t.p1(e.baseLevels[pt.HITPOINTS])),r&kl.CHANGE_TYPE&&t.p2(e.type),r&kl.SPOTANIM&&(t.p2(e.graphicId),t.p2(e.graphicHeight),t.p2(e.graphicDelay)),r&kl.FACE_COORD&&(i&&-1!=e.orientationX?(t.p2(e.orientationX),t.p2(e.orientationZ)):(t.p2(e.faceX),t.p2(e.faceZ)))}calculateExtendedInfo(e,t){let i=0,r=e.mask;return t&&(-1===e.orientationX&&-1===e.faceX||(r|=kl.FACE_COORD),-1!==e.faceEntity&&(r|=kl.FACE_ENTITY)),0===r?0:(i+=1,r&kl.ANIM&&(i+=3),r&kl.FACE_ENTITY&&(i+=2),r&kl.SAY&&(i+=1+e.chat.length),r&kl.DAMAGE&&(i+=4),r&kl.CHANGE_TYPE&&(i+=2),r&kl.SPOTANIM&&(i+=6),r&kl.FACE_COORD&&(i+=4),i)}},vo=class extends bs{constructor(e){super(),this.ticks=e}priority=Rs.LOW},To=class extends un{prot=Ts.UPDATE_REBOOT_TIMER;encode(e,t){e.p2(t.ticks)}},Co=new class{encoders=new Map;bind(e,t){if(this.encoders.has(e))throw new Error(`[ServerProtRepository] Already defines a ${e.name}.`);this.encoders.set(e,t)}constructor(){this.bind(Nn,new Ln),this.bind(Pn,new wn),this.bind(bn,new Rn),this.bind(Bn,new Un),this.bind(Dn,new kn),this.bind(_n,new An),this.bind(vn,new Tn),this.bind(Cn,new In),this.bind(Sn,new On),this.bind(Mn,new xn),this.bind(Fn,new Hn),this.bind(zs,new Vn),this.bind(Bs,new Gn),this.bind(fn,new pn),this.bind(Wn,new Kn),this.bind(zn,new jn),this.bind(Yn,new qn),this.bind(Ws,new Qn),this.bind($n,new Zn),this.bind(Xn,new Jn),this.bind(ea,new ta),this.bind(ia,new ra),this.bind(sa,new na),this.bind(aa,new oa),this.bind(ca,new la),this.bind(ha,new da),this.bind(ua,new pa),this.bind(fa,new ga),this.bind(ma,new ya),this.bind(js,new Ea),this.bind(rn,new va),this.bind(hn,new Ta),this.bind(sn,new Ca),this.bind(dn,new Ia),this.bind(Sa,new Oa),this.bind(an,new Na),this.bind(nn,new La),this.bind(Ys,new Pa),this.bind(Ra,new ba),this.bind(Gs,new Ba),this.bind(Vs,new Ua),this.bind(_o,new Ao),this.bind(tn,new Da),this.bind(cn,new ka),this.bind(on,new Ma),this.bind(ln,new xa),this.bind(Fa,new Ha),this.bind(gn,new mn),this.bind(yn,new En),this.bind(Ds,new Va),this.bind(ks,new Ga),this.bind(Wa,new Ka),this.bind(za,new ja),this.bind(Ya,new qa),this.bind(Ms,new Qa),this.bind(Ks,new $a),this.bind(Za,new Xa),this.bind(Ja,new eo),this.bind(to,new io),this.bind(ro,new so),this.bind(xs,new no),this.bind(ao,new oo),this.bind(co,new lo),this.bind(vo,new To),this.bind(ho,new uo),this.bind(Us,new po),this.bind(Xs,new fo),this.bind(Zs,new mo),this.bind(Js,new go),this.bind(Hs,new yo),this.bind(Fs,new Eo)}getEncoder(e){return this.encoders.get(e.constructor)}getZoneEncoder(e){return this.encoders.get(e.constructor)}},Io=class extends Array{capacity;onFilled;constructor(e,t){super(),this.capacity=e,this.onFilled=t}*stack(e){const t=this[e];if(void 0!==t)for(let e=0;e=0;e--)yield i[e];else for(let e=0;er&&(r=t,i=e)}return i}nextBottomAll(){let e,t=Number.POSITIVE_INFINITY;for(let i=0;ir&&(r=s,i=e)}return i}nextBottomAll(){let e,t=Number.POSITIVE_INFINITY;for(let i=0;i>3,this.z=i.z>>3,this.level=i.level,this.events=new Set,this.players=new Set,this.npcs=new Set,this.locs=new So(e.LOCS,(e=>Zl.removeLoc(e,100))),this.objs=new Oo(e.OBJS,(e=>Zl.removeObj(e,100))),this.entityEvents=new Map}enter(e){e instanceof Do?(this.players.add(e.uid),Zl.getZoneGrid(this.level).flag(this.x,this.z)):e instanceof kl&&this.npcs.add(e.nid)}leave(e){e instanceof Do?(this.players.delete(e.uid),0===this.players.size&&Zl.getZoneGrid(this.level).unflag(this.x,this.z)):e instanceof kl&&this.npcs.delete(e.nid)}tick(e){let t;do{t=!1;for(const i of this.getAllObjsUnsafe())i.updateLifeCycle(e)&&i.lastLifecycleTick!==e&&(i.lifecycle===Yr.DESPAWN?-1!==i.receiverId?Zl.revealObj(i):(Zl.removeObj(i,0),t=!0):i.lifecycle===Yr.RESPAWN&&(Zl.addObj(i,-1,0),t=!0));for(const i of this.getAllLocsUnsafe())i.updateLifeCycle(e)&&i.lastLifecycleTick!==e&&(i.lifecycle===Yr.DESPAWN?(Zl.removeLoc(i,0),t=!0):i.lifecycle===Yr.RESPAWN&&(Zl.addLoc(i,0),t=!0))}while(t)}computeShared(){this.shared=null;let e=0;const t=[];for(const i of this.events.values()){if(i.type!==$s.ENCLOSED)continue;const r=Co.getZoneEncoder(i.message);if(void 0===r)continue;const s=r.enclose(i.message);t.push(s),e+=s.length}if(0===t.length||0===e)return;const i=new Uint8Array(e);let r=0;for(const e of t)i.set(e,r),r+=e.length;this.shared=i}writeFullFollows(e){e.write(new Xs(this.x,this.z,e.originX,e.originZ));for(const t of this.getAllObjsUnsafe(!0))-1!==t.receiverId&&t.receiverId!==e.pid||(e.write(new Js(this.x,this.z,e.originX,e.originZ)),(t.lifecycle===Yr.DESPAWN&&t.checkLifeCycle(Zl.currentTick)||t.lifecycle===Yr.RESPAWN&&t.checkLifeCycle(Zl.currentTick))&&e.write(new tn(ji.packZoneCoord(t.x,t.z),t.type,t.count)));for(const t of this.getAllLocsUnsafe(!0))t.lifecycle===Yr.DESPAWN&&t.checkLifeCycle(Zl.currentTick)?e.write(new rn(ji.packZoneCoord(t.x,t.z),t.type,t.shape,t.angle)):t.lifecycle!==Yr.RESPAWN||t.checkLifeCycle(Zl.currentTick)||e.write(new sn(ji.packZoneCoord(t.x,t.z),t.shape,t.angle))}writePartialEncloses(e){this.shared&&e.write(new Zs(this.x,this.z,e.originX,e.originZ,this.shared))}writePartialFollows(e){if(0!==this.events.size){e.write(new Js(this.x,this.z,e.originX,e.originZ));for(const t of this.events)t.type===$s.FOLLOWS&&(-1!==t.receiverId&&t.receiverId!==e.pid||e.write(t.message))}}reset(){this.events.clear(),this.entityEvents.clear()}addStaticLoc(e){const t=ji.packZoneCoord(e.x,e.z);this.locs.addLast(t,e,!0),this.totalLocs++,this.locs.sortStack(t,!0)}addStaticObj(e){const t=ji.packZoneCoord(e.x,e.z);this.objs.addLast(t,e,!0),this.totalObjs++,this.objs.sortStack(t,!0)}appendEvent(e,t){this.events.add(t);const i=this.entityEvents.get(e);void 0!==i?this.entityEvents.set(e,i.concat(t)):this.entityEvents.set(e,[t])}addLoc(e){const t=ji.packZoneCoord(e.x,e.z);e.lifecycle===Yr.DESPAWN&&(this.locs.addLast(t,e),this.totalLocs++),this.locs.sortStack(t),this.appendEvent(e,new qs($s.ENCLOSED,-1,new rn(t,e.type,e.shape,e.angle)))}removeLoc(e){const t=ji.packZoneCoord(e.x,e.z);e.lifecycle===Yr.DESPAWN&&(this.locs.remove(t,e),this.totalLocs--),this.locs.sortStack(t);const i=this.entityEvents.get(e);if(void 0!==i){for(let e=0;e>this.INT_BITS);grid;constructor(t=e.DEFAULT_GRID_SIZE){this.grid=new Int32Array(t)}index(t,i){return t<>>e.INT_BITS}flag(t,i){this.grid[this.index(t,i)]|=1<<(i&e.INT_BITS_FLAG)}unflag(t,i){this.grid[this.index(t,i)]&=~(1<<(i&e.INT_BITS_FLAG))}isFlagged(t,i,r){const s=Math.max(0,t-r),n=Math.min(e.GRID_SIZE-1,t+r),a=Math.max(0,i-r),o=Math.min(e.GRID_SIZE-1,i+r),c=e.INT_BITS_FLAG,l=a&~c,h=o>>>e.INT_BITS<o&&(s=r&(1<>>a-t),0!==n)return!0}return!1}},Po=class e{static zoneIndex(e,t,i){return e>>3&2047|(t>>3&2047)<<11|(3&i)<<22}static unpackIndex(e){return{x:(2047&e)<<3,z:(e>>11&2047)<<3,level:e>>22}}zones;grids;constructor(){this.zones=new Map,this.grids=new Map}zone(t,i,r){const s=e.zoneIndex(t,i,r);let n=this.zones.get(s);return void 0===n&&(n=new No(s),this.zones.set(s,n)),n}zoneByIndex(e){let t=this.zones.get(e);return void 0===t&&(t=new No(e),this.zones.set(e,t)),t}grid(e){let t=this.grids.get(e);return void 0===t&&(t=new Lo,this.grids.set(e,t)),t}zoneCount(){return this.zones.size}locCount(){let e=0;for(const t of this.zones.values())e+=t.totalLocs;return e}objCount(){let e=0;for(const t of this.zones.values())e+=t.totalObjs;return e}},wo=class e{static INTERVAL=10;static PREFERRED_PLAYERS=250;static PREFERRED_NPCS=255;static PREFERRED_VIEW_DISTANCE=15;npcs;players;loadedZones;activeZones;extendedInfo;appearances;forceViewDistance=!1;viewDistance=e.PREFERRED_VIEW_DISTANCE;lastResize=0;constructor(){this.npcs=new Set,this.players=new Set,this.loadedZones=new Set,this.activeZones=new Set,this.extendedInfo=new Set,this.appearances=new Map}resize(){if(!this.forceViewDistance)return this.players.size>=e.PREFERRED_PLAYERS?(this.viewDistance>1&&this.viewDistance--,void(this.lastResize=0)):void(++this.lastResize>=e.INTERVAL&&(this.viewDistance=e.PREFERRED_PLAYERS)break e;this.players.has(o.uid)||o.uid!==t&&(yield o)}}*getNearbyNpcs(t,i,r,s){e:for(const n of this.proximitySort(t,i,this.activeZones))for(const a of this.getNearby(Zl.getZoneIndex(n).getAllNpcsSafe(),t,i,r,s,15)){if(this.npcs.size>=e.PREFERRED_NPCS)break e;this.npcs.has(a.nid)||(yield a)}}*getNearby(e,t,i,r,s,n){const a=r-48,o=r+48,c=s+48,l=s-48;for(const r of e)r.x<=a||r.x>=o||r.z>=c||r.z<=l||ji.isWithinDistanceSW({x:t,z:i},r,n)&&(yield r)}proximitySort(e,t,i){return Array.from(i.values()).map((i=>this.zoneToDistance(i,e,t))).sort(((e,t)=>e.distance-t.distance)).map((({zoneIndex:e})=>e))}zoneToDistance(e,t,i){const r=Po.unpackIndex(e);return{zoneIndex:e,distance:Math.abs(r.x-t)+Math.abs(r.z-i)}}},bo=new Int32Array(99),Ro=0;for(let e=0;e<99;e++){const t=e+1;Ro+=Math.floor(t+300*Math.pow(2,t/7)),bo[e]=10*Math.floor(Ro/4)}function Bo(e){for(let t=98;t>=0;t--)if(e>=bo[t])return Math.min(t+2,99);return 1}function Uo(e){return bo[e-2]}var Do=class e extends Ns{static APPEARANCE=1;static ANIM=2;static FACE_ENTITY=4;static SAY=8;static DAMAGE=16;static FACE_COORD=32;static CHAT=64;static BIG_UPDATE=128;static SPOTANIM=256;static EXACT_MOVE=512;static SKILLS=['attack','defence','strength','hitpoints','ranged','prayer','magic','cooking','woodcutting','fletching','fishing','firemaking','crafting','smithing','mining','herblore','agility','thieving','stat18','stat19','runecraft'];static DESIGN_BODY_COLORS=[[6798,107,10283,16,4797,7744,5799,4634,33697,22433,2983,54193],[8741,12,64030,43162,7735,8404,1701,38430,24094,10153,56621,4783,1341,16578,35003,25239],[25238,8742,12,64030,43162,7735,8404,1701,38430,24094,10153,56621,4783,1341,16578,35003],[4626,11146,6439,12,4758,10270],[4550,4537,5681,5673,5790,6806,8076,4574]];save(){const e=Oe.alloc(1);e.p2(8196),e.p2(3),e.p2(this.x),e.p2(this.z),e.p1(this.level);for(let t=0;t<7;t++)e.p1(this.body[t]);for(let t=0;t<5;t++)e.p1(this.colors[t]);e.p1(this.gender),e.p2(this.runenergy),e.p4(this.playtime);for(let t=0;t<21;t++)e.p4(this.stats[t]),e.p1(this.levels[t]);e.p2(this.vars.length);for(let t=0;t=255?(e.p1(255),e.p4(i.count)):e.p1(i.count)):e.p2(0)}t++}}e.data[i]=t,e.p1(this.afkZones.length);for(let t=0;tt&&t.uid===e));if(-1!==i)return void(this.heroPoints[i].points+=t);const r=this.heroPoints.findIndex((e=>e&&-1===e.uid));-1===r||(this.heroPoints[r]={uid:e,points:t})}findHero(){return this.heroPoints.sort(((e,t)=>t.points-e.points)),this.heroPoints[0]?.uid??-1}resetEntity(e){e&&(this.faceX=-1,this.faceZ=-1,this.orientationX=-1,this.orientationZ=-1),super.resetPathingEntity(),this.repathed=!1,this.protect=!1,this.messageColor=null,this.messageEffect=null,this.messageType=null,this.message=null}onLogin(){this.playerLog('Logging in'),this.write(new Bs),this.write(new Us(this.pid)),this.unsetMapFlag(),this.write(new Ds),this.resetHeroPoints(),this.write(new ks);for(let e=0;e1){const e=Math.floor(this.runweight/1e3),t=67+67*Math.min(Math.max(e,0),64)/64|0;this.runenergy=Math.max(this.runenergy-t,0)}}recoverEnergy(e){if(!this.delayed()&&(!e||this.moveSpeed!==Is.RUN)&&this.runenergy<1e4){const e=8+(this.baseLevels[$i.AGILITY]/9|0);this.runenergy=Math.min(this.runenergy+e,1e4)}}blockWalkFlag(){return Ri.PLAYER}defaultMoveSpeed(){return this.getVar(Nt.PLAYER_RUN)?Is.RUN:Is.WALK}closeSticky(){if(-1!==this.modalSticky){const e=jt.getByTrigger(cs.IF_CLOSE,this.modalSticky);e&&this.enqueueScript(e,1),this.modalSticky=-1,this.write(new Ms(-1))}}closeModal(){if(this.receivedFirstClose){if(this.weakQueue.clear(),this.delayed()||(this.protect=!1),0!==this.modalState){if(-1!==this.modalTop){const e=jt.getByTrigger(cs.IF_CLOSE,this.modalTop);e&&this.enqueueScript(e,1),this.modalTop=-1}if(-1!==this.modalBottom){const e=jt.getByTrigger(cs.IF_CLOSE,this.modalBottom);e&&this.enqueueScript(e,1),this.modalBottom=-1}if(-1!==this.modalSidebar){const e=jt.getByTrigger(cs.IF_CLOSE,this.modalSidebar);e&&this.enqueueScript(e,1),this.modalSidebar=-1}this.modalState=0,this.refreshModalClose=!0}}else this.receivedFirstClose=!0}delayed(){return this.delay>Zl.currentTick}containsModalInterface(){return!(1&~this.modalState&&2&~this.modalState&&16&~this.modalState)}busy(){return this.delayed()||this.containsModalInterface()}canAccess(){return!this.protect&&!this.busy()}enqueueScript(e,t=0,i=0,r=[]){const s=new As(t,e,r,i);1===t?(s.delay=0,this.engineQueue.addTail(s)):2===t?this.weakQueue.addTail(s):this.queue.addTail(s)}processQueues(){let e=!1;for(let t=this.queue.head();null!==t;t=this.queue.next())if(3===t.type){e=!0;break}e&&this.closeModal(),this.processQueue(),this.processWeakQueue()}processQueue(){for(let e=this.queue.head();null!==e;e=this.queue.next()){3===e.type&&this.closeModal();const t=e.delay--;if(this.canAccess()&&t<=0){const t=Dl.init(e.script,this,null,e.args);this.executeScript(t,!0),e.unlink()}}}processWeakQueue(){for(let e=this.weakQueue.head();null!==e;e=this.weakQueue.next()){const t=e.delay--;if(this.canAccess()&&t<=0){const t=Dl.init(e.script,this,null,e.args);this.executeScript(t,!0),e.unlink()}}}setTimer(e,t,i=[],r){const s=t.id,n={type:e,script:t,args:i,interval:r,clock:r};this.timers.set(s,n)}clearTimer(e){this.timers.delete(e)}processTimers(e){for(const t of this.timers.values())if(e===t.type&&--t.clock<=0&&(1===t.type||this.canAccess())){t.clock=t.interval;const e=Dl.init(t.script,this,null,t.args);this.runScript(e,0===t.type)}}stopAction(){this.clearPendingAction(),this.unsetMapFlag()}clearPendingAction(){this.clearInteraction(),this.closeModal()}hasInteraction(){return null!==this.target}getOpTrigger(){if(!this.target)return null;let e=-1,t=-1;if(this.target instanceof kl||this.target instanceof ss||this.target instanceof $r){const i=this.target instanceof kl?ft.get(this.target.type):this.target instanceof ss?at.get(this.target.type):Tt.get(this.target.type);e=i.id,t=i.category}return-1!==this.targetSubject.type&&(e=this.targetSubject.type),-1!==this.targetSubject.com&&(e=this.targetSubject.com),jt.getByTrigger(this.targetOp+7,e,t)??null}getApTrigger(){if(!this.target)return null;let e=-1,t=-1;if(this.target instanceof kl||this.target instanceof ss||this.target instanceof $r){const i=this.target instanceof kl?ft.get(this.target.type):this.target instanceof ss?at.get(this.target.type):Tt.get(this.target.type);e=i.id,t=i.category}return-1!==this.targetSubject.type&&(e=this.targetSubject.type),-1!==this.targetSubject.com&&(e=this.targetSubject.com),jt.getByTrigger(this.targetOp,e,t)??null}processInteraction(){if(null===this.target||!this.canAccess())return void this.updateMovement();if(this.target.level!==this.level)return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof kl&&(void 0===Zl.getNpc(this.target.nid)||this.target.delayed()))return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof kl&&-1!==this.targetSubject.type&&null===Zl.getNpcByUid(this.targetSubject.type<<16|this.target.nid))return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof $r&&null===Zl.getObj(this.target.x,this.target.z,this.level,this.target.type,this.pid))return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof ss&&null===Zl.getLoc(this.target.x,this.target.z,this.level,this.target.type))return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof e&&null===Zl.getPlayerByUid(this.target.uid))return this.clearInteraction(),void this.unsetMapFlag();if(this.targetOp===cs.APPLAYER3||this.targetOp===cs.OPPLAYER3){return void(this.updateMovement(!1)&&(this.alreadyFacedEntity=!1,this.lastMovement=Zl.currentTick+1))}const t=this.getOpTrigger(),i=this.getApTrigger();if(t&&this.target instanceof Ns&&this.inOperableDistance(this.target)){const e=this.target;this.target=null,this.executeScript(Dl.init(t,this,e),!0),null===this.target&&this.unsetMapFlag(),this.interacted=!0,this.clearWaypoints()}else if(i&&this.inApproachDistance(this.apRange,this.target)){const e=this.target;this.target=null,this.executeScript(Dl.init(i,this,e),!0),this.apRangeCalled?this.target=e:(this.clearWaypoints(),this.interacted=!0),null===this.target&&this.unsetMapFlag()}else if(this.target instanceof Ns&&this.inOperableDistance(this.target)){if(vt.NODE_DEBUG&&!t&&!i){let e='_';this.target instanceof kl?e=-1!==this.targetSubject.com&&this.targetOp===cs.APNPCT||this.targetOp===cs.OPNPCT?tt.get(this.targetSubject.com)?.comName??this.targetSubject.toString():ft.get(this.target.type)?.debugname??this.target.type.toString():this.target instanceof ss?e=at.get(this.target.type)?.debugname??this.target.type.toString():this.target instanceof $r?e=Tt.get(this.target.type)?.debugname??this.target.type.toString():-1!==this.targetSubject.com&&this.targetOp===cs.APNPCT||this.targetOp===cs.APPLAYERT||this.targetOp===cs.APLOCT||this.targetOp===cs.APOBJT?e=tt.get(this.targetSubject.com)?.comName??this.targetSubject.toString():-1!==this.targetSubject.type&&(e=Tt.get(this.targetSubject.type)?.debugname??this.targetSubject.toString()),this.messageGame(`No trigger for [${cs[this.targetOp+7].toLowerCase()},${e}]`)}this.target=null,this.messageGame('Nothing interesting happens.'),this.interacted=!0,this.clearWaypoints()}const r=this.updateMovement();if(r&&(this.alreadyFacedEntity=!1,this.lastMovement=Zl.currentTick+1),this.target&&(!this.interacted||this.apRangeCalled))if(this.interacted=!1,t&&(this.target instanceof Ns||!r)&&this.inOperableDistance(this.target)){const e=this.target;this.target=null,this.executeScript(Dl.init(t,this,e),!0),null===this.target&&this.unsetMapFlag(),this.interacted=!0,this.clearWaypoints()}else if(i&&this.inApproachDistance(this.apRange,this.target)){this.apRangeCalled=!1;const e=this.target;this.target=null,this.executeScript(Dl.init(i,this,e),!0),this.apRangeCalled?this.target=e:(this.clearWaypoints(),this.interacted=!0),null===this.target&&this.unsetMapFlag()}else if((this.target instanceof Ns||!r)&&this.inOperableDistance(this.target)){if(!vt.NODE_PRODUCTION&&!t&&!i){let e='_';this.target instanceof kl?e=ft.get(this.target.type)?.debugname??this.target.type.toString():this.target instanceof ss?e=at.get(this.target.type)?.debugname??this.target.type.toString():this.target instanceof $r?e=Tt.get(this.target.type)?.debugname??this.target.type.toString():-1!==this.targetSubject.com&&this.targetOp===cs.APNPCT||this.targetOp===cs.APPLAYERT||this.targetOp===cs.APLOCT||this.targetOp===cs.APOBJT?e=tt.get(this.targetSubject.com)?.comName??this.targetSubject.toString():-1!==this.targetSubject.type&&(e=Tt.get(this.targetSubject.type)?.debugname??this.targetSubject.toString()),this.messageGame(`No trigger for [${cs[this.targetOp+7].toLowerCase()},${e}]`)}this.target=null,this.messageGame('Nothing interesting happens.'),this.interacted=!0,this.clearWaypoints()}if(!this.interactWalkTrigger&&-1!==this.walktrigger&&!this.protect&&!this.delayed()){const e=jt.get(this.walktrigger);if(this.walktrigger=-1,e){const t=Dl.init(e,this);this.interactWalkTrigger=!0,this.unsetMapFlag(),this.runScript(t,!0)}}this.interacted||this.hasWaypoints()||r||(this.messageGame("I can't reach that!"),this.clearInteraction()),this.interacted&&!this.apRangeCalled&&null===this.target&&this.clearInteraction()}getAppearanceInSlot(e){let t=-1;return 8===e?t=this.body[0]:11===e?t=this.body[1]:4===e?t=this.body[2]:6===e?t=this.body[3]:9===e?t=this.body[4]:7===e?t=this.body[5]:10===e&&(t=this.body[6]),-1===t?0:256+t}getCombatLevel(){const e=.25*(this.baseLevels[$i.DEFENCE]+this.baseLevels[$i.HITPOINTS]+Math.floor(this.baseLevels[$i.PRAYER]/2)),t=.325*(this.baseLevels[$i.ATTACK]+this.baseLevels[$i.STRENGTH]),i=.325*(Math.floor(this.baseLevels[$i.RANGED]/2)+this.baseLevels[$i.RANGED]),r=.325*(Math.floor(this.baseLevels[$i.MAGIC]/2)+this.baseLevels[$i.MAGIC]);return Math.floor(e+Math.max(t,i,r))}generateAppearance(t){const i=Oe.alloc(0);i.p1(this.gender),i.p1(this.headicons);const r=[];let s=this.getInventory(t);s||(s=new Xt(it.WORN,0));for(let e=0;ei.type===e&&i.com===t)))return;it.get(e).scope===it.SCOPE_SHARED&&(i=-1),this.invListeners.push({type:e,com:t,source:i,firstSeen:!0})}invStopListenOnCom(e){const t=this.invListeners.findIndex((t=>t.com===e));-1!==t&&(this.invListeners.splice(t,1),this.write(new xs(e)))}invGetSlot(e,t){const i=this.getInventory(e);if(!i)throw new Error('invGetSlot: Invalid inventory type: '+e);if(!i.validSlot(t))throw new Error('invGetSlot: Invalid slot: '+t);return i.get(t)}invClear(e){const t=this.getInventory(e);if(!t)throw new Error('invClear: Invalid inventory type: '+e);t.removeAll()}invAdd(e,t,i,r=!0){const s=this.getInventory(e);if(!s)throw new Error('invAdd: Invalid inventory type: '+e);return s.add(t,i,-1,r).completed}invSet(e,t,i,r){const s=this.getInventory(e);if(!s)throw new Error('invSet: Invalid inventory type: '+e);if(!s.validSlot(r))throw new Error('invSet: Invalid slot: '+r);s.set(r,{id:t,count:i})}invDel(e,t,i,r=-1){const s=this.getInventory(e);if(!s)throw new Error('invDel: Invalid inventory type: '+e);if(r<-1||r>=this.invSize(e))throw new Error('invDel: Invalid beginSlot: '+r);return s.remove(t,i,r).completed}invDelSlot(e,t){const i=this.getInventory(e);if(!i)throw new Error('invDelSlot: Invalid inventory type: '+e);if(!i.validSlot(t))throw new Error('invDelSlot: Invalid slot: '+t);i.delete(t)}invSize(e){const t=this.getInventory(e);if(!t)throw new Error('invSize: Invalid inventory type: '+e);return t.capacity}invTotal(e,t){const i=this.getInventory(e);if(!i)throw new Error('invTotal: Invalid inventory type: '+e);return i.getItemCount(t)}invFreeSpace(e){const t=this.getInventory(e);if(!t)throw new Error('invFreeSpace: Invalid inventory type: '+e);return t.freeSlotCount}invItemSpace(e,t,i,r){const s=this.getInventory(e);if(!s)throw new Error('invItemSpace: Invalid inventory type: '+e);const n=Tt.get(t);let a=t;if(n.certtemplate>=0&&n.certlink>=0&&(a=n.certlink),n.stackable||a!=t||s.stackType==Xt.ALWAYS_STACK){const r=!0===it.get(e).stockobj?.includes(t);return 0!=this.invTotal(e,t)||0!=this.invFreeSpace(e)||r?Math.max(0,i-(Xt.STACK_LIMIT-this.invTotal(e,t))):i}return Math.max(0,i-(this.invFreeSpace(e)-(this.invSize(e)-r)))}invMoveToSlot(e,t,i,r){const s=this.getInventory(e);if(!s)throw new Error('invMoveToSlot: Invalid inventory type: '+e);if(!s.validSlot(i))throw new Error('invMoveToSlot: Invalid from slot: '+i);const n=this.getInventory(t);if(!n)throw new Error('invMoveToSlot: Invalid inventory type: '+t);if(!n.validSlot(r))throw new Error('invMoveToSlot: Invalid to slot: '+r);const a=this.invGetSlot(e,i);if(!a)throw new Error(`invMoveToSlot: Invalid from obj was null. This means the obj does not exist at this slot: ${i}`);const o=this.invGetSlot(t,r);this.invSet(t,a.id,a.count,r),o?this.invSet(e,o.id,o.count,i):this.invDelSlot(e,i)}invMoveFromSlot(e,t,i){const r=this.getInventory(e);if(!r)throw new Error('invMoveFromSlot: Invalid inventory type: '+e);if(!this.getInventory(t))throw new Error('invMoveFromSlot: Invalid inventory type: '+t);if(!r.validSlot(i))throw new Error('invMoveFromSlot: Invalid from slot: '+i);const s=this.invGetSlot(e,i);if(!s)throw new Error(`invMoveFromSlot: Invalid from obj was null. This means the obj does not exist at this slot: ${i}`);return this.invDelSlot(e,i),{overflow:s.count-this.invAdd(t,s.id,s.count,!1),fromObj:s.id}}invTotalCat(e,t){const i=this.getInventory(e);if(!i)throw new Error('invTotalCat: Invalid inventory type: '+e);return i.itemsFiltered.filter((e=>Tt.get(e.id).category==t)).reduce(((e,t)=>e+t.count),0)}_invTotalParam(e,t,i){const r=this.getInventory(e);if(!r)throw new Error('invTotalParam: Invalid inventory type: '+e);const s=gt.get(t);let n=0;for(let e=0;e=Tt.count)continue;const a=Tt.get(t.id),o=st(s.id,a,s.defaultInt);n+=i?t.count*o:o}return n}invTotalParam(e,t){return this._invTotalParam(e,t,!1)}invTotalParamStack(e,t){return this._invTotalParam(e,t,!0)}getVar(e){const t=Nt.get(e);return t.type===Pe.STRING?this.varsString[t.id]:this.vars[t.id]}setVar(e,t){const i=Nt.get(e);i.type===Pe.STRING&&'string'==typeof t?this.varsString[i.id]=t:'number'==typeof t&&(this.vars[i.id]=t,i.transmit&&this.writeVarp(e,t))}writeVarp(e,t){t>=-128&&t<=127?this.write(new Fs(e,t)):this.write(new Hs(e,t))}addXp(e,t){if(t<0)throw new Error(`Invalid xp parameter for addXp call: Stat was: ${e}, Exp was: ${t}`);if(0==t)return;const i=Number(vt.NODE_XPRATE)||1;this.stats[e]+=t*i,this.stats[e]>2e9&&(this.stats[e]=2e9);const r=this.baseLevels[e];if(this.levels[e]===this.baseLevels[e]&&(this.levels[e]=Bo(this.stats[e])),this.baseLevels[e]=Bo(this.stats[e]),this.baseLevels[e]>r){this.levels[e]=It.count||this.animProtect||(-1==t||-1==this.animId||It.get(t).priority>It.get(this.animId).priority||0===It.get(this.animId).priority)&&(this.animId=t,this.animDelay=i,this.mask|=e.ANIM)}spotanim(t,i,r){this.graphicId=t,this.graphicHeight=i,this.graphicDelay=r,this.mask|=e.SPOTANIM}applyDamage(t,i){this.damageTaken=t,this.damageType=i;const r=this.levels[$i.HITPOINTS];r-t<=0?(this.levels[$i.HITPOINTS]=0,this.damageTaken=r):this.levels[$i.HITPOINTS]=r-t,this.mask|=e.DAMAGE}say(t){this.chat=t,this.mask|=e.SAY}faceSquare(t,i){this.faceX=2*t+1,this.faceZ=2*i+1,this.orientationX=this.faceX,this.orientationZ=this.faceZ,this.mask|=e.FACE_COORD}playSong(e){if(!(e=e.toLowerCase().replaceAll(' ','_')))return;const t=Ps.get(e+'.mid'),i=ws.get(e+'.mid');if(t&&i){const r=t.length;this.write(new Vs(e,i,r))}}playJingle(e,t){if(!(t=t.toLowerCase().replaceAll('_',' ')))return;const i=Ps.get(t+'.mid');i&&this.write(new Gs(e,i))}openMainModal(e){4&this.modalState&&(this.write(new Bs),this.modalState&=-5,this.modalSidebar=-1),this.modalState|=1,this.modalTop=e,this.refreshModal=!0}openChat(e){this.modalState|=2,this.modalBottom=e,this.refreshModal=!0}openSideOverlay(e){this.modalState|=4,this.modalSidebar=e,this.refreshModal=!0}openChatSticky(e){this.write(new Ms(e)),this.modalState|=8,this.modalSticky=e}openMainModalSideOverlay(e,t){this.modalState|=1,this.modalTop=e,this.modalState|=4,this.modalSidebar=t,this.refreshModal=!0}exactMove(t,i,r,s,n,a,o){this.exactStartX=t,this.exactStartZ=i,this.exactEndX=r,this.exactEndZ=s,this.exactMoveStart=n,this.exactMoveEnd=a,this.exactMoveDirection=o,this.mask|=e.EXACT_MOVE,this.x=r,this.z=s,this.lastStepX=this.x-1,this.lastStepZ=this.z}setTab(e,t){this.overlaySide[t]=e,this.write(new Ws(e,t))}isComponentVisible(e){return this.modalTop===e.rootLayer||this.modalBottom===e.rootLayer||this.modalSidebar===e.rootLayer||-1!==this.overlaySide.findIndex((t=>t===e.rootLayer))||this.modalSticky===e.rootLayer}updateAfkZones(){if(this.lastAfkZone=Math.min(1e3,this.lastAfkZone+1),this.withinAfkZone())return;const e=ji.packCoord(0,this.x-10,this.z-10);this.moveSpeed===Is.INSTANT&&this.jump?this.afkZones[1]=e:this.afkZones[1]=this.afkZones[0],this.afkZones[0]=e,this.lastAfkZone=0}zonesAfk(){return 1e3===this.lastAfkZone}withinAfkZone(){for(let e=0;e=2944&&this.x<3392&&this.z>=3520&&this.z<6400||this.x>=2944&&this.x<3392&&this.z>=9920&&this.z<12800}runScript(e,t=!1,i=!1){if(!i&&t&&(this.protect||this.delayed()))return-1;t&&(e.pointerAdd(Gt.ProtectedActivePlayer),this.protect=!0);const r=Dl.execute(e);return t&&(this.protect=!1),e.pointerGet(Gt.ProtectedActivePlayer)&&e._activePlayer&&(e.pointerRemove(Gt.ProtectedActivePlayer),e._activePlayer.protect=!1),e.pointerGet(Gt.ProtectedActivePlayer2)&&e._activePlayer2&&(e.pointerRemove(Gt.ProtectedActivePlayer2),e._activePlayer2.protect=!1),r}executeScript(e,t=!1,i=!1){const r=this.runScript(e,t,i);-1!==r&&(r!==$t.FINISHED&&r!==$t.ABORTED?r===$t.WORLD_SUSPENDED?Zl.enqueueScript(e,e.popInt()):r===$t.NPC_SUSPENDED?e.activeNpc.activeScript=e:(e.activePlayer.activeScript=e,e.activePlayer.protect=t):e===this.activeScript&&(this.activeScript=null,1&this.modalState||this.closeModal()))}wrappedMessageGame(e){const t=Ge.get(1).split(e,456);for(const e of t)this.messageGame(e)}write(e){e.priority===Rs.HIGH?this.highPriorityOut.push(e):this.lowPriorityOut.push(e)}unsetMapFlag(){this.clearWaypoints(),this.write(new Ks)}hintNpc(e){this.write(new zs(1,e,0,0,0,0))}hintTile(e,t,i,r){this.write(new zs(e,0,0,t,i,r))}hintPlayer(e){this.write(new zs(10,0,e,0,0,0))}stopHint(){this.write(new zs(-1,0,0,0,0,0))}lastLoginInfo(e,t,i,r){this.write(new js(e,t,i,r)),this.modalState|=16}logout(){}terminate(){}messageGame(e){this.write(new Ys(e))}},ko=class e{constructor(t,i,r){this.index=t,this.id=i,this.length=r,e.all[t]=this,e.byId[i]=this}static all=[];static byId=[];static REBUILD_GETMAPS=new e(4,150,-1);static NO_TIMEOUT=new e(6,108,0);static IDLE_TIMER=new e(30,70,0);static EVENT_TRACKING=new e(34,81,-2);static EVENT_CAMERA_POSITION=new e(35,189,6);static ANTICHEAT_OPLOGIC1=new e(60,7,4);static ANTICHEAT_OPLOGIC2=new e(61,88,4);static ANTICHEAT_OPLOGIC3=new e(62,30,3);static ANTICHEAT_OPLOGIC4=new e(63,176,2);static ANTICHEAT_OPLOGIC5=new e(64,220,0);static ANTICHEAT_OPLOGIC6=new e(65,66,4);static ANTICHEAT_OPLOGIC7=new e(66,17,4);static ANTICHEAT_OPLOGIC8=new e(67,2,2);static ANTICHEAT_OPLOGIC9=new e(68,238,1);static ANTICHEAT_CYCLELOGIC1=new e(70,233,1);static ANTICHEAT_CYCLELOGIC2=new e(71,146,-1);static ANTICHEAT_CYCLELOGIC3=new e(74,215,3);static ANTICHEAT_CYCLELOGIC4=new e(72,236,4);static ANTICHEAT_CYCLELOGIC5=new e(75,85,0);static ANTICHEAT_CYCLELOGIC6=new e(73,219,-1);static OPOBJ1=new e(80,140,6);static OPOBJ2=new e(81,40,6);static OPOBJ3=new e(82,200,6);static OPOBJ4=new e(83,178,6);static OPOBJ5=new e(84,247,6);static OPOBJT=new e(88,138,8);static OPOBJU=new e(89,239,12);static OPNPC1=new e(100,194,2);static OPNPC2=new e(101,8,2);static OPNPC3=new e(102,27,2);static OPNPC4=new e(103,113,2);static OPNPC5=new e(104,100,2);static OPNPCT=new e(108,134,4);static OPNPCU=new e(109,202,8);static OPLOC1=new e(120,245,6);static OPLOC2=new e(121,172,6);static OPLOC3=new e(122,96,6);static OPLOC4=new e(123,97,6);static OPLOC5=new e(124,116,6);static OPLOCT=new e(128,9,8);static OPLOCU=new e(129,75,12);static OPPLAYER1=new e(140,164,2);static OPPLAYER2=new e(141,53,2);static OPPLAYER3=new e(142,185,2);static OPPLAYER4=new e(143,206,2);static OPPLAYERT=new e(148,177,4);static OPPLAYERU=new e(149,248,8);static OPHELD1=new e(160,195,6);static OPHELD2=new e(161,71,6);static OPHELD3=new e(162,133,6);static OPHELD4=new e(163,157,6);static OPHELD5=new e(164,211,6);static OPHELDT=new e(168,48,8);static OPHELDU=new e(169,130,12);static INV_BUTTON1=new e(190,31,6);static INV_BUTTON2=new e(191,59,6);static INV_BUTTON3=new e(192,212,6);static INV_BUTTON4=new e(193,38,6);static INV_BUTTON5=new e(194,6,6);static IF_BUTTON=new e(200,155,2);static RESUME_PAUSEBUTTON=new e(201,235,2);static CLOSE_MODAL=new e(202,231,0);static RESUME_P_COUNTDIALOG=new e(203,237,4);static TUTORIAL_CLICKSIDE=new e(204,175,1);static MOVE_OPCLICK=new e(242,93,-1);static BUG_REPORT=new e(243,190,10);static MOVE_MINIMAPCLICK=new e(244,165,-1);static INV_BUTTOND=new e(245,159,6);static IGNORELIST_DEL=new e(246,171,8);static IGNORELIST_ADD=new e(247,79,8);static IF_PLAYERDESIGN=new e(248,52,13);static CHAT_SETMODE=new e(249,244,3);static MESSAGE_PRIVATE=new e(250,148,-1);static FRIENDLIST_DEL=new e(251,11,8);static FRIENDLIST_ADD=new e(252,118,8);static CLIENT_CHEAT=new e(253,4,-1);static MESSAGE_PUBLIC=new e(254,158,-1);static MOVE_GAMECLICK=new e(255,181,-1)},Mo=class{},xo=class{},Fo=class e{constructor(e,t){this.id=e,this.limit=t}static CLIENT_EVENT=new e(0,20);static USER_EVENT=new e(1,5)},Ho=class extends xo{constructor(e){super(),this.input=e}category=Fo.USER_EVENT},Vo=class extends Mo{prot=ko.CLIENT_CHEAT;decode(e){const t=e.gjstr();return new Ho(t)}},Go=class extends xo{category=Fo.USER_EVENT},Wo=class extends Mo{prot=ko.CLOSE_MODAL;decode(){return new Go}},Ko=class extends xo{category=Fo.CLIENT_EVENT},zo=class extends Mo{prot=ko.IDLE_TIMER;decode(){return new Ko}},jo=class extends xo{constructor(e){super(),this.component=e}category=Fo.USER_EVENT},Yo=class extends Mo{prot=ko.IF_BUTTON;decode(e){const t=e.g2();return new jo(t)}},qo=class extends xo{constructor(e,t,i){super(),this.gender=e,this.idkit=t,this.color=i}category=Fo.USER_EVENT},Qo=class extends Mo{prot=ko.IF_PLAYERDESIGN;decode(e){const t=e.g1(),i=[];for(let t=0;t<7;t++)i[t]=e.g1(),255===i[t]&&(i[t]=-1);const r=[];for(let t=0;t<5;t++)r[t]=e.g1();return new qo(t,i,r)}},$o=class extends xo{constructor(e,t,i,r){super(),this.op=e,this.obj=t,this.slot=i,this.component=r}category=Fo.USER_EVENT},Zo=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new $o(this.op,t,i,r)}},Xo=class extends xo{constructor(e,t,i){super(),this.component=e,this.slot=t,this.targetSlot=i}category=Fo.USER_EVENT},Jo=class extends Mo{prot=ko.INV_BUTTOND;decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new Xo(t,i,r)}},ec=class extends xo{constructor(e,t){super(),this.username=e,this.input=t}category=Fo.USER_EVENT},tc=class extends Mo{prot=ko.MESSAGE_PRIVATE;decode(e){const t=e.g8(),i=wa.unpack(e,e.length-8);return new ec(t,i)}},ic=class extends xo{constructor(e,t,i){super(),this.input=e,this.color=t,this.effect=i}category=Fo.USER_EVENT},rc=class extends Mo{prot=ko.MESSAGE_PUBLIC;decode(e){const t=e.g1(),i=e.g1(),r=wa.unpack(e,e.length-2);return new ic(r,t,i)}},sc=class extends xo{constructor(e,t,i,r){super(),this.op=e,this.obj=t,this.slot=i,this.component=r}category=Fo.USER_EVENT},nc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new sc(this.op,t,i,r)}},ac=class extends xo{constructor(e,t,i,r){super(),this.obj=e,this.slot=t,this.component=i,this.spellComponent=r}category=Fo.USER_EVENT},oc=class extends Mo{prot=ko.OPHELDT;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new ac(t,i,r,s)}},cc=class extends xo{constructor(e,t,i,r,s,n){super(),this.obj=e,this.slot=t,this.component=i,this.useObj=r,this.useSlot=s,this.useComponent=n}category=Fo.USER_EVENT},lc=class extends Mo{prot=ko.OPHELDU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2(),n=e.g2(),a=e.g2();return new cc(t,i,r,s,n,a)}},hc=class extends xo{constructor(e,t,i,r){super(),this.op=e,this.x=t,this.z=i,this.loc=r}category=Fo.USER_EVENT},dc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new hc(this.op,t,i,r)}},uc=class extends xo{constructor(e,t,i,r){super(),this.x=e,this.z=t,this.loc=i,this.spellComponent=r}category=Fo.USER_EVENT},pc=class extends Mo{prot=ko.OPLOCT;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new uc(t,i,r,s)}},fc=class extends xo{constructor(e,t,i,r,s,n){super(),this.x=e,this.z=t,this.loc=i,this.useObj=r,this.useSlot=s,this.useComponent=n}category=Fo.USER_EVENT},gc=class extends Mo{prot=ko.OPLOCU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2(),n=e.g2(),a=e.g2();return new fc(t,i,r,s,n,a)}},mc=class extends xo{constructor(e,t){super(),this.op=e,this.nid=t}category=Fo.USER_EVENT},yc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2();return new mc(this.op,t)}},Ec=class extends xo{constructor(e,t){super(),this.nid=e,this.spellComponent=t}category=Fo.USER_EVENT},_c=class extends Mo{prot=ko.OPNPCT;decode(e){const t=e.g2(),i=e.g2();return new Ec(t,i)}},Ac=class extends xo{constructor(e,t,i,r){super(),this.nid=e,this.useObj=t,this.useSlot=i,this.useComponent=r}category=Fo.USER_EVENT},vc=class extends Mo{prot=ko.OPNPCU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new Ac(t,i,r,s)}},Tc=class extends xo{constructor(e,t,i,r){super(),this.op=e,this.x=t,this.z=i,this.obj=r}category=Fo.USER_EVENT},Cc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new Tc(this.op,t,i,r)}},Ic=class extends xo{constructor(e,t,i,r){super(),this.x=e,this.z=t,this.obj=i,this.spellComponent=r}category=Fo.USER_EVENT},Sc=class extends Mo{prot=ko.OPOBJT;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new Ic(t,i,r,s)}},Oc=class extends xo{constructor(e,t,i,r,s,n){super(),this.x=e,this.z=t,this.obj=i,this.useObj=r,this.useSlot=s,this.useComponent=n}category=Fo.USER_EVENT},Nc=class extends Mo{prot=ko.OPOBJU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2(),n=e.g2(),a=e.g2();return new Oc(t,i,r,s,n,a)}},Lc=class extends xo{constructor(e,t){super(),this.op=e,this.pid=t}category=Fo.USER_EVENT},Pc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2();return new Lc(this.op,t)}},wc=class extends xo{constructor(e,t){super(),this.pid=e,this.spellComponent=t}category=Fo.USER_EVENT},bc=class extends Mo{prot=ko.OPPLAYERT;decode(e){const t=e.g2(),i=e.g2();return new wc(t,i)}},Rc=class extends xo{constructor(e,t,i,r){super(),this.pid=e,this.useObj=t,this.useSlot=i,this.useComponent=r}category=Fo.USER_EVENT},Bc=class extends Mo{prot=ko.OPPLAYERU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new Rc(t,i,r,s)}},Uc=class extends xo{constructor(e){super(),this.maps=e}category=Fo.USER_EVENT},Dc=class extends Mo{prot=ko.REBUILD_GETMAPS;decode(e){const t=[],i=e.length/3;for(let r=0;re.com===n));if(!o)return!1;const c=t.getInventoryFromListener(o);if(!c||!c.validSlot(s)||!c.hasAt(s,r))return!1;if(t.delayed())return!1;let l;t.lastItem=r,t.lastSlot=s,l=1===i?cs.INV_BUTTON1:2===i?cs.INV_BUTTON2:3===i?cs.INV_BUTTON3:4===i?cs.INV_BUTTON4:cs.INV_BUTTON5;const h=jt.getByTrigger(l,n,-1);if(h){const e=tt.get(a.rootLayer);t.executeScript(Dl.init(h,t),0==e.overlay)}else vt.NODE_DEBUG&&t.messageGame(`No trigger for [${cs.toString(l)},${a.comName}]`);return!0}},Kc=class e{static TCP=0;static WEBSOCKET=1;socket=null;type=-1;state=-1;remoteAddress;totalBytesRead=0;totalBytesWritten=0;uniqueId='undefined'==typeof self?randomUUID():'https:'===self.location.protocol?self.crypto.randomUUID():'0';encryptor=null;decryptor=null;in=new Uint8Array(5e3);inOffset=0;inCount=new Uint8Array(256);out=new Oe(new Uint8Array(5e3));player=null;constructor(t,i,r=e.TCP,s=-1){this.socket=t,this.remoteAddress=i,this.type=r,this.state=s}isTCP(){return this.type===e.TCP}isWebSocket(){return this.type===e.WEBSOCKET}send(e){if('undefined'==typeof self){if(!this.socket)return;this.totalBytesWritten+=e.length,this.isTCP()?this.socket.write(e):this.isWebSocket()&&this.socket.send(e)}else this.totalBytesWritten+=e.length,self.postMessage(e)}close(){if('undefined'==typeof self){if(!this.socket)return;setTimeout((()=>{this.isTCP()?this.socket.end():this.isWebSocket()&&this.socket.close()}),100)}else setTimeout((()=>{self.close()}),100)}terminate(){if('undefined'==typeof self){if(!this.socket)return;this.isTCP()?this.socket.destroy():this.isWebSocket()&&this.socket.terminate()}else self.close()}reset(){this.inOffset=0,this.inCount.fill(0)}writeImmediate(e){this.send(e)}flush(){const e=this.out;0!==e.pos&&(this.send(e.data.subarray(0,e.pos)),e.pos=0)}},zc=class extends Kc{constructor(){super(null,'')}isTCP(){return this.type===Kc.TCP}isWebSocket(){return this.type===Kc.WEBSOCKET}send(e){this.socket}close(){this.socket}terminate(){this.socket}reset(){this.inOffset=0,this.inCount.fill(0)}},jc=class e{static loadFromFile(t){const i=ge(pe(t));let r;return r=fs24.existsSync(`data/players/${i}.sav`)?Oe.load(`data/players/${i}.sav`):new Oe(new Uint8Array),e.load(t,r,null)}static load(e,t,i){const r=pe(e),s=ge(r),n=i?new Il(s,r,i):new Do(s,r);if(vt.NODE_PRODUCTION?void 0!==vt.NODE_STAFF.find((e=>e===s))&&(n.staffModLevel=3):n.staffModLevel=3,t.data.length<2){for(let e=0;e<21;e++)n.stats[e]=0,n.baseLevels[e]=1,n.levels[e]=1;return n.stats[$i.HITPOINTS]=Uo(10),n.baseLevels[$i.HITPOINTS]=10,n.levels[$i.HITPOINTS]=10,n}if(8196!==t.g2())throw new Error('Invalid player save');const a=t.g2();if(a>3)throw new Error('Unsupported player save format');t.pos=t.data.length-4;if(t.g4()!=Oe.getcrc(t.data,0,t.data.length-4))throw new Error('Player save corrupted');t.pos=4,n.x=t.g2(),n.z=t.g2(),n.level=t.g1();for(let e=0;e<7;e++)n.body[e]=t.g1(),255===n.body[e]&&(n.body[e]=-1);for(let e=0;e<5;e++)n.colors[e]=t.g1();n.gender=t.g1(),n.runenergy=t.g2(),n.playtime=a>=2?t.g4():t.g2();for(let e=0;e<21;e++)n.stats[e]=t.g4(),n.baseLevels[e]=Bo(n.stats[e]),n.levels[e]=t.g1();const o=t.g2();for(let e=0;e=3){const e=t.g1();for(let i=0;i80)return!1;const{input:i}=e,r=i.toLowerCase().split(' '),s=r.shift();if(void 0===s||s.length<=0)return!1;if(t.playerLog('Cheat ran',i),t.staffModLevel>=3)if('reload'!==s||'undefined'!=typeof self||vt.NODE_PRODUCTION)if('rebuild'!==s||vt.NODE_PRODUCTION){if('serverdrop'===s)t.terminate();else if('bench'===s){const e=Date.now();for(let e=0;e<1e5;e++)ti(t.level,t.x,t.z,t.x,t.z+10);const i=Date.now();console.log(`took = ${i-e} ms`)}else if('bots'===s){t.messageGame('Adding bots');for(let e=0;e<1999;e++){const t=jc.load(`bot${e}`,new Oe(new Uint8Array),new zc);Zl.addPlayer(t)}}else if('lightbots'===s){t.messageGame('Adding lightweight bots');for(let e=0;e<1999;e++){const t=jc.load(`bot${e}`,new Oe(new Uint8Array),null);Zl.addPlayer(t)}}else if('teleall'===s){t.messageGame('Teleporting all players');for(const e of Zl.players){e.closeModal();do{const t=Math.floor(64*Math.random())+3200,i=Math.floor(64*Math.random())+3200;e.teleJump(t+Math.floor(64*Math.random())-32,i+Math.floor(64*Math.random())-32,0)}while(ui(e.x,e.z,e.level,Ri.WALK_BLOCKED))}}else if('moveall'===s){t.messageGame('Moving all players'),console.time('moveall');for(const e of Zl.players)e.closeModal(),e.queueWaypoints(ti(e.level,e.x,e.z,32+(e.x>>>6<<6),32+(e.z>>>6<<6)));console.timeEnd('moveall')}else if('speed'===s){if(r.length<1)return t.messageGame('Usage: ::speed '),!1;const e=yt(r.shift(),20);if(e<20)return t.messageGame('::speed input was too low.'),!1;t.messageGame(`World speed was changed to ${e}ms`),Zl.tickRate=e}else if('fly'===s)t.moveStrategy===Os.FLY?t.moveStrategy=Os.SMART:t.moveStrategy=Os.FLY,t.messageGame(`Fly is on? ${t.moveStrategy===Os.FLY}`);else if('naive'===s)t.moveStrategy===Os.NAIVE?t.moveStrategy=Os.SMART:t.moveStrategy=Os.NAIVE,t.messageGame(`Naive is on? ${t.moveStrategy===Os.NAIVE}`);else if('teleto'===s){if(r.length<1)return!1;const e=Zl.getPlayerByUsername(r[0]);if(!e)return t.messageGame(`${r[0]} is not logged in.`),!1;t.teleJump(e.x,e.z,e.level)}else if('teleother'===s){if(r.length<1)return!1;const e=Zl.getPlayerByUsername(r[0]);if(!e)return t.messageGame(`${r[0]} is not logged in.`),!1;e.teleJump(t.x,t.z,t.level)}else if('setvarother'===s){if(r.length<3)return!1;const e=Zl.getPlayerByUsername(r[0]);if(!e)return t.messageGame(`${r[0]} is not logged in.`),!1;const i=Nt.getId(r[1]),s=Math.max(-2147483648,Math.min(yt(r[2],0),2147483647));if(-1===i)return!1;e.setVar(i,s),t.messageGame('set '+r[1]+': to '+s+' on '+e.username)}else if('shutdown'===s){if(r.length<1)return!1;Zl.rebootTimer(yt(r[0],50))}}else Zl.devThread.postMessage({type:'pack'});else{Zl.reload();const e=jt.load('data/pack');t.messageGame(`Reloaded ${e} scripts.`)}if(vt.NODE_ALLOW_CHEATS||t.staffModLevel>=2)if('tele'===s){if(r.length<1)return!1;if('up'===r[0])t.teleJump(t.x,t.z,t.level+1),t.messageGame('::tele '+ji.formatString(t.level,t.x,t.z,','));else if('down'===r[0])t.teleJump(t.x,t.z,t.level-1),t.messageGame('::tele '+ji.formatString(t.level,t.x,t.z,','));else if(-1===r[0].indexOf(','))t.teleJump(yt(r[0],3200),yt(r[1],3200),yt(r[2],t.level));else{const e=r[0].split(',');if(5!==e.length)return!1;const i=yt(e[0],0),s=yt(e[1],50),n=yt(e[2],50),a=yt(e[3],0),o=yt(e[4],0);if(i<0||i>3||s<0||s>255||n<0||n>255||a<0||a>63||o<0||o>63)return!1;t.teleJump((s<<6)+a,(n<<6)+o,i)}}else if('setvar'===s){if(r.length<2)return!1;const e=Nt.getId(r[0]),i=Math.max(-2147483648,Math.min(yt(r[1],0),2147483647));if(-1===e)return!1;t.setVar(e,i),t.messageGame('set '+r[0]+': to '+i)}else if('random'===s)t.afkEventReady=!0;else if('minme'===s)for(let e=0;e '),!1;const e=Do.SKILLS.indexOf(r[0]);if(-1===e)return t.messageGame(`Unknown stat ${r[0]}`),!1;const i=10*parseInt(r[1]);t.stats[e]=i}else if('setstat'===s){if(r.length<2)return!1;const e=Do.SKILLS.indexOf(r[0]);if(-1===e)return!1;t.setLevel(e,parseInt(r[1]))}else if('advancestat'===s){if(r.length<1)return!1;const e=Do.SKILLS.indexOf(r[0]),i=Math.min(99,Math.max(1,yt(r[1],1)));if(-1===e)return!1;t.setLevel(e,t.baseLevels[e]+i)}else if('getvar'===s){if(r.length<1)return!1;const e=Nt.getId(r[0]);if(-1===e)return!1;const i=t.getVar(e);t.messageGame('get '+r[0]+': '+i)}else if('give'===s){if(r.length<1)return!1;const e=Tt.getId(r[0]),i=Math.max(1,Math.min(yt(r[1],1),2147483647));if(-1===e)return!1;t.invAdd(it.INV,e,i,!1)}if((vt.NODE_ALLOW_CHEATS||t.staffModLevel>=1)&&'getcoord'===s&&t.messageGame(ji.formatString(t.level,t.x,t.z,'_')),vt.NODE_ALLOW_CHEATS||t.staffModLevel>=2){const e=jt.getByName(`[debugproc,${s}]`);if(!e)return!1;const n=new Array(e.info.parameterTypes.length).fill(-1);for(let t=0;t1)return!1;let n=!0;for(let e=0;e<7;e++){let t=e;if(1===i&&(t+=7),8==t&&-1===r[e])continue;const s=et.get(r[e]);if(!s||s.disable||s.type!=t){n=!1;break}}if(!n)return!1;for(let e=0;e<5;e++)if(s[e]>=Do.DESIGN_BODY_COLORS[e].length){n=!1;break}return!!n&&(t.gender=i,t.body=r,t.colors=s,t.generateAppearance(it.WORN),!0)}},Xc=class extends Gc{handle(e,t){const{component:i,slot:r,targetSlot:s}=e,n=tt.get(i);if(void 0===n||!t.isComponentVisible(n))return!1;const a=t.invListeners.find((e=>e.com===i));if(!a)return!1;const o=t.getInventoryFromListener(a);if(!(o&&o.validSlot(r)&&o.get(r)&&o.validSlot(s)))return!1;if(t.delayed())return t.write(new ro(i,o,r,s)),!1;t.lastSlot=r,t.lastTargetSlot=s;const c=jt.getByTrigger(cs.INV_BUTTOND,i);if(c){const e=tt.get(n.rootLayer);t.executeScript(Dl.init(c,t),0==e.overlay)}else vt.NODE_DEBUG&&t.messageGame(`No trigger for [inv_buttond,${n.comName}]`);return!0}},Jc=class extends Gc{handle(e,t){return!0}},el=class extends Gc{handle(e,t){const{color:i,effect:r,input:s}=e;if(i<0||i>11||r<0||r>2||s.length>100)return!1;t.messageColor=i,t.messageEffect=r,t.messageType=0;const n=Oe.alloc(0);return wa.pack(n,Bt.filter(s)),t.message=new Uint8Array(n.pos),n.pos=0,n.gdata(t.message,0,t.message.length),n.release(),t.mask|=Do.CHAT,!0}},tl=class extends Gc{handle(e,t){const{obj:i,slot:r,component:s}=e,n=tt.get(s);if(void 0===n||!t.isComponentVisible(n))return!1;const a=Tt.get(i);if(5!==e.op&&(a.iop&&!a.iop[e.op-1]||!a.iop))return!1;const o=t.invListeners.find((e=>e.com===s));if(!o)return!1;const c=t.getInventoryFromListener(o);if(!c||!c.validSlot(r)||!c.hasAt(r,i))return!1;if(t.delayed())return!1;let l;t.lastItem=i,t.lastSlot=r,t.clearInteraction(),t.closeModal(),l=1===e.op?cs.OPHELD1:2===e.op?cs.OPHELD2:3===e.op?cs.OPHELD3:4===e.op?cs.OPHELD4:cs.OPHELD5;const h=jt.getByTrigger(l,a.id,a.category);return h?t.executeScript(Dl.init(h,t),!0):vt.NODE_DEBUG&&t.messageGame(`No trigger for [${cs.toString(l)},${a.debugname}]`),!0}},il=class extends Gc{handle(e,t){const{obj:i,slot:r,component:s,spellComponent:n}=e,a=tt.get(s);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=tt.get(s);if(void 0===o||!t.isComponentVisible(o))return t.unsetMapFlag(),!1;const c=t.invListeners.find((e=>e.com===s));if(!c)return t.unsetMapFlag(),!1;const l=t.getInventoryFromListener(c);if(!l||!l.validSlot(r)||!l.hasAt(r,i))return t.unsetMapFlag(),!1;if(t.delayed())return t.unsetMapFlag(),!1;t.lastItem=i,t.lastSlot=r,t.clearInteraction(),t.closeModal();const h=jt.getByTrigger(cs.OPHELDT,n,-1);return h?t.executeScript(Dl.init(h,t),!0):(vt.NODE_DEBUG&&t.messageGame(`No trigger for [opheldt,${o.comName}]`),t.messageGame('Nothing interesting happens.')),!0}},rl=class extends Gc{handle(e,t){const{obj:i,slot:r,component:s,useObj:n,useSlot:a,useComponent:o}=e,c=tt.get(s);if(void 0===c||!t.isComponentVisible(c))return t.unsetMapFlag(),!1;const l=tt.get(s);if(void 0===l||!t.isComponentVisible(l))return t.unsetMapFlag(),!1;{const e=t.invListeners.find((e=>e.com===s));if(!e)return t.unsetMapFlag(),!1;const n=t.getInventoryFromListener(e);if(!n||!n.validSlot(r)||!n.hasAt(r,i))return t.unsetMapFlag(),!1}{const e=t.invListeners.find((e=>e.com===o));if(!e)return t.unsetMapFlag(),!1;const i=t.getInventoryFromListener(e);if(!i||!i.validSlot(a)||!i.hasAt(a,n))return t.unsetMapFlag(),!1}if(t.delayed())return t.unsetMapFlag(),!1;t.lastItem=i,t.lastSlot=r,t.lastUseItem=n,t.lastUseSlot=a;const h=Tt.get(t.lastItem),d=Tt.get(t.lastUseItem);if((h.members||d.members)&&!vt.NODE_MEMBERS)return t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1;let u=jt.getByTriggerSpecific(cs.OPHELDU,h.id,-1);u||(u=jt.getByTriggerSpecific(cs.OPHELDU,d.id,-1),[t.lastItem,t.lastUseItem]=[t.lastUseItem,t.lastItem],[t.lastSlot,t.lastUseSlot]=[t.lastUseSlot,t.lastSlot]);const p=-1!==h.category?Le.get(h.category):null;!u&&p&&(u=jt.getByTriggerSpecific(cs.OPHELDU,-1,p.id));const f=-1!==d.category?Le.get(d.category):null;return!u&&f&&(u=jt.getByTriggerSpecific(cs.OPHELDU,-1,f.id),[t.lastItem,t.lastUseItem]=[t.lastUseItem,t.lastItem],[t.lastSlot,t.lastUseSlot]=[t.lastUseSlot,t.lastSlot]),t.clearInteraction(),t.closeModal(),u?t.executeScript(Dl.init(u,t),!0):(vt.NODE_DEBUG&&t.messageGame(`No trigger for [opheldu,${h.debugname}]`),t.messageGame('Nothing interesting happens.')),!0}},sl=class extends Gc{handle(e,t){const{x:i,z:r,loc:s}=e;if(t.delayed())return t.unsetMapFlag(),!1;const n=t.originX-52,a=t.originX+52,o=t.originZ+52,c=t.originZ-52;if(ia||ro)return!1;const l=Zl.getLoc(i,r,t.level,s);if(!l)return t.unsetMapFlag(),!1;const h=at.get(l.type);if(!h.op||!h.op[e.op-1])return t.unsetMapFlag(),!1;let d;return d=1===e.op?cs.APLOC1:2===e.op?cs.APLOC2:3===e.op?cs.APLOC3:4===e.op?cs.APLOC4:cs.APLOC5,t.clearPendingAction(),t.setInteraction(hs.ENGINE,l,d),t.opcalled=!0,!0}},nl=class extends Gc{handle(e,t){const{x:i,z:r,loc:s,spellComponent:n}=e;if(t.delayed())return t.unsetMapFlag(),!1;const a=tt.get(n);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=t.originX-52,c=t.originX+52,l=t.originZ+52,h=t.originZ-52;if(ic||rl)return t.unsetMapFlag(),!1;const d=Zl.getLoc(i,r,t.level,s);return d?(t.clearPendingAction(),t.setInteraction(hs.ENGINE,d,cs.APLOCT,{type:d.type,com:n}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},al=class extends Gc{handle(e,t){const{x:i,z:r,loc:s,useObj:n,useSlot:a,useComponent:o}=e;if(t.delayed())return t.unsetMapFlag(),!1;const c=tt.get(o);if(void 0===c||!t.isComponentVisible(c))return t.unsetMapFlag(),!1;const l=t.originX-52,h=t.originX+52,d=t.originZ+52,u=t.originZ-52;if(ih||rd)return t.unsetMapFlag(),!1;const p=t.invListeners.find((e=>e.com===o));if(!p)return t.unsetMapFlag(),!1;const f=t.getInventoryFromListener(p);if(!f||!f.validSlot(a)||!f.hasAt(a,n))return t.unsetMapFlag(),!1;const g=Zl.getLoc(i,r,t.level,s);return g?Tt.get(n).members&&!vt.NODE_MEMBERS?(t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1):(t.lastUseItem=n,t.lastUseSlot=a,t.clearPendingAction(),t.setInteraction(hs.ENGINE,g,cs.APLOCU),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},ol=class extends Gc{handle(e,t){const{nid:i}=e;if(t.delayed())return t.unsetMapFlag(),!1;const r=Zl.getNpc(i);if(!r||r.delayed())return t.unsetMapFlag(),!1;if(!t.buildArea.npcs.has(r.nid))return t.unsetMapFlag(),!1;const s=ft.get(r.type);if(!s.op||!s.op[e.op-1])return t.unsetMapFlag(),!1;let n;return n=1===e.op?cs.APNPC1:2===e.op?cs.APNPC2:3===e.op?cs.APNPC3:4===e.op?cs.APNPC4:cs.APNPC5,t.clearPendingAction(),t.setInteraction(hs.ENGINE,r,n,{type:r.type,com:-1}),t.opcalled=!0,!0}},cl=class extends Gc{handle(e,t){const{nid:i,spellComponent:r}=e;if(t.delayed())return t.unsetMapFlag(),!1;const s=tt.get(r);if(void 0===s||!t.isComponentVisible(s))return t.unsetMapFlag(),!1;const n=Zl.getNpc(i);return!n||n.delayed()?(t.unsetMapFlag(),!1):t.buildArea.npcs.has(n.nid)?(t.clearPendingAction(),t.setInteraction(hs.ENGINE,n,cs.APNPCT,{type:n.type,com:r}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},ll=class extends Gc{handle(e,t){const{nid:i,useObj:r,useSlot:s,useComponent:n}=e;if(t.delayed())return t.unsetMapFlag(),!1;const a=tt.get(n);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=t.invListeners.find((e=>e.com===n));if(!o)return t.unsetMapFlag(),!1;const c=t.getInventoryFromListener(o);if(!c||!c.validSlot(s)||!c.hasAt(s,r))return t.unsetMapFlag(),!1;const l=Zl.getNpc(i);return!l||l.delayed()?(t.unsetMapFlag(),!1):t.buildArea.npcs.has(l.nid)?Tt.get(r).members&&!vt.NODE_MEMBERS?(t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1):(t.lastUseItem=r,t.lastUseSlot=s,t.clearPendingAction(),t.setInteraction(hs.ENGINE,l,cs.APNPCU,{type:l.type,com:-1}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},hl=class extends Gc{handle(e,t){const{x:i,z:r,obj:s}=e;if(t.delayed())return t.unsetMapFlag(),!1;const n=t.originX-52,a=t.originX+52,o=t.originZ+52,c=t.originZ-52;if(ia||ro)return t.unsetMapFlag(),!1;const l=Zl.getObj(i,r,t.level,s,t.pid);if(!l)return t.unsetMapFlag(),!1;const h=Tt.get(l.type);if(1===e.op&&(h.op&&!h.op[0]||!h.op)||4===e.op&&(h.op&&!h.op[3]||!h.op))return t.unsetMapFlag(),!1;let d;return d=1===e.op?cs.APOBJ1:2===e.op?cs.APOBJ2:3===e.op?cs.APOBJ3:4===e.op?cs.APOBJ4:cs.APOBJ5,t.clearPendingAction(),t.setInteraction(hs.ENGINE,l,d),t.opcalled=!0,!0}},dl=class extends Gc{handle(e,t){const{x:i,z:r,obj:s,spellComponent:n}=e;if(t.delayed())return t.unsetMapFlag(),!1;const a=tt.get(n);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=t.originX-52,c=t.originX+52,l=t.originZ+52,h=t.originZ-52;if(ic||rl)return t.unsetMapFlag(),!1;const d=Zl.getObj(i,r,t.level,s,t.pid);return d?(t.clearPendingAction(),t.setInteraction(hs.ENGINE,d,cs.APOBJT,{type:d.type,com:n}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},ul=class extends Gc{handle(e,t){const{x:i,z:r,obj:s,useObj:n,useSlot:a,useComponent:o}=e;if(t.delayed())return t.unsetMapFlag(),!1;const c=tt.get(o);if(void 0===c||!t.isComponentVisible(c))return t.unsetMapFlag(),!1;const l=t.originX-52,h=t.originX+52,d=t.originZ+52,u=t.originZ-52;if(ih||rd)return t.unsetMapFlag(),!1;const p=t.invListeners.find((e=>e.com===o));if(!p)return t.unsetMapFlag(),!1;const f=t.getInventoryFromListener(p);if(!f||!f.validSlot(a)||!f.hasAt(a,n))return t.unsetMapFlag(),!1;const g=Zl.getObj(i,r,t.level,s,t.pid);return g?Tt.get(n).members&&!vt.NODE_MEMBERS?(t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1):(t.lastUseItem=n,t.lastUseSlot=a,t.clearPendingAction(),t.setInteraction(hs.ENGINE,g,cs.APOBJU),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},pl=class extends Gc{handle(e,t){const{pid:i}=e;if(t.delayed())return t.unsetMapFlag(),!1;const r=Zl.getPlayer(i);if(!r)return t.unsetMapFlag(),!1;if(!t.buildArea.players.has(r.uid))return t.unsetMapFlag(),!1;let s;return s=1===e.op?cs.APPLAYER1:2===e.op?cs.APPLAYER2:3===e.op?cs.APPLAYER3:cs.APPLAYER4,t.clearPendingAction(),t.setInteraction(hs.ENGINE,r,s),t.opcalled=!0,!0}},fl=class extends Gc{handle(e,t){const{pid:i,spellComponent:r}=e;if(t.delayed())return t.unsetMapFlag(),!1;const s=tt.get(r);if(void 0===s||!t.isComponentVisible(s))return t.unsetMapFlag(),!1;const n=Zl.getPlayer(i);return n&&t.buildArea.players.has(n.uid)?(t.clearPendingAction(),t.setInteraction(hs.ENGINE,n,cs.APPLAYERT,{type:-1,com:r}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},gl=class extends Gc{handle(e,t){const{pid:i,useObj:r,useSlot:s,useComponent:n}=e;if(t.delayed())return t.unsetMapFlag(),!1;const a=tt.get(n);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=t.invListeners.find((e=>e.com===n));if(!o)return t.unsetMapFlag(),!1;const c=t.getInventoryFromListener(o);if(!c||!c.validSlot(s)||!c.hasAt(s,r))return t.unsetMapFlag(),!1;const l=Zl.getPlayer(i);return l&&t.buildArea.players.has(l.uid)?Tt.get(r).members&&!vt.NODE_MEMBERS?(t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1):(t.lastUseSlot=s,t.clearPendingAction(),t.setInteraction(hs.ENGINE,l,cs.APPLAYERU,{type:r,com:-1}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},ml=class extends Gc{handle(e,t){const{maps:i}=e;for(let e=0;e13)return!1;const r=jt.getByTriggerSpecific(cs.TUTORIAL_CLICKSIDE,-1,-1);return r&&t.executeScript(Dl.init(r,t),!0),!0}},Al=class extends xo{constructor(e,t,i){super(),this.path=e,this.ctrlHeld=t,this.opClick=i}category=Fo.USER_EVENT},vl=class extends Mo{constructor(e){super(),this.prot=e}decode(e){const t=e.g1(),i=e.g2(),r=e.g2(),s=this.prot===ko.MOVE_MINIMAPCLICK?14:0,n=e.available-s>>1,a=[{x:i,z:r}];for(let t=1;t<=n&&t<25;t++)a.push({x:i+e.g1b(),z:r+e.g1b()});return new Al(a,t,this.prot===ko.MOVE_OPCLICK)}},Tl=class extends Gc{handle(e,t){const i=e.path[0];if(t.delayed()||e.ctrlHeld<0||e.ctrlHeld>1||ji.distanceToSW(t,{x:i.x,z:i.z})>104)return t.unsetMapFlag(),t.userPath=[],!1;if(vt.NODE_CLIENT_ROUTEFINDER){t.userPath=[];for(let i=0;ie;){const t=ko.byId[this.client.in[e++]];let i=t.length;-1==i?i=this.client.in[e++]:-2==i&&(i=this.client.in[e++]<<8|this.client.in[e++]);const r=new Oe(this.client.in.slice(e,e+i));e+=i;const s=Cl.getDecoder(t);if(s){const e=s.decode(r),i=Cl.getHandler(t);i&&i.handle(e,this)}}this.client?.reset()}encodeOut(){if(this.client){(this.modalTop!==this.lastModalTop||this.modalBottom!==this.lastModalBottom||this.modalSidebar!==this.lastModalSidebar||this.refreshModalClose)&&(this.refreshModalClose&&this.write(new Bs),this.refreshModalClose=!1,this.lastModalTop=this.modalTop,this.lastModalBottom=this.modalBottom,this.lastModalSidebar=this.modalSidebar),this.refreshModal&&(1&~this.modalState||4&~this.modalState?1&~this.modalState?2&~this.modalState?4&~this.modalState||this.write(new Yn(this.modalSidebar)):this.write(new fn(this.modalBottom)):this.write(new Wn(this.modalTop)):this.write(new zn(this.modalTop,this.modalSidebar)),this.refreshModal=!1);for(let e=this.highPriorityOut.head();e;e=this.highPriorityOut.next())this.writeInner(e),e.uncache();for(let e=this.lowPriorityOut.head();e;e=this.lowPriorityOut.next())this.writeInner(e),e.uncache();this.client.flush()}}writeInner(e){const t=this.client;if(!t)return;const i=Co.getEncoder(e);if(!i)return void console.error('No encoder for message',e);const r=i.prot,s=t.out,n=1+(-1===r.length?1:-2===r.length?2:0)+i.test(e);s.pos+n>=s.length&&t.flush();const a=s.pos;s.p1(r.id),-1===r.length?s.pos+=1:-2===r.length&&(s.pos+=2);const o=s.pos;i.encode(s,e),-1===r.length?s.psize1(s.pos-o):-2===r.length&&s.psize2(s.pos-o),t.encryptor&&(s.data[a]=s.data[a]+t.encryptor.nextInt()&255),Zl.cycleStats[Gr.BANDWIDTH_OUT]+=s.pos-a}logout(){this.writeInner(new Sa),this.client?.flush()}terminate(){this.client?.terminate(),this.client=null}playerLog(e,...t){'undefined'==typeof self&&(t.length>0?fs25.appendFileSync(`data/players/${this.username}.log`,`[${(new Date).toISOString().split('T')[0]} ${this.client?.remoteAddress}]: ${e} ${t.join(' ')}\n`):fs25.appendFileSync(`data/players/${this.username}.log`,`[${(new Date).toISOString().split('T')[0]} ${this.client?.remoteAddress}]: ${e}\n`))}updateMap(){const e=this.buildArea.loadedZones,t=this.buildArea.activeZones,i=ji.zone(this.originX)-4<<3,r=ji.zone(this.originX)+5<<3,s=ji.zone(this.originZ)+5<<3,n=ji.zone(this.originZ)-4<<3;(this.xr-1||this.z>s-1)&&(this.write(new yn(ji.zone(this.x),ji.zone(this.z))),this.originX=this.x,this.originZ=this.z,e.clear());for(let e=this.cameraPackets.head();null!==e;e=this.cameraPackets.next()){const t=e.camX-ji.zoneOrigin(this.originX),i=e.camZ-ji.zoneOrigin(this.originZ);e.type===Ts.CAM_MOVETO?this.write(new Pn(t,i,e.height,e.rotationSpeed,e.rotationMultiplier)):e.type===Ts.CAM_LOOKAT&&this.write(new Nn(t,i,e.height,e.rotationSpeed,e.rotationMultiplier)),e.unlink()}this.moveSpeed===Is.INSTANT&&this.jump&&e.clear(),t.clear();const a=ji.zone(this.x),o=ji.zone(this.z),c=ji.zone(this.originX)-6,l=ji.zone(this.originX)+6,h=ji.zone(this.originZ)+6,d=ji.zone(this.originZ)-6;for(let e=a-3;e<=a+3;e++)for(let i=o-3;i<=o+3;i++)el||i>h||i243?t>>=4:i>217?t>>=3:i>192?t>>=2:i>179&&(t>>=1),((255&e)>>2<<10)+(t>>5<<7)+(i>>1)}static rgb15to24(e){return((e>>10&31)<<3<<16)+((e>>5&31)<<3<<8)+((31&e)<<3)}static rgb15toHsl16(t){const i=(t>>10&31)/31,r=(t>>5&31)/31,s=(31&t)/31;return e.rgbToHsl(i,r,s)}static rgb24to15(e){return((e>>16&255)>>3<<10)+((e>>8&255)>>3<<5)+((255&e)>>3)}static rgb24toHsl16(t){const i=(t>>16&255)/256,r=(t>>8&255)/256,s=(255&t)/256;return e.rgbToHsl(i,r,s)}static rgbToHsl(t,i,r){let s=t;in&&(n=i),r>n&&(n=r);let a=0,o=0;const c=(s+n)/2;s!==n&&(c<.5?o=(n-s)/(n+s):c>=.5&&(o=(n-s)/(2-n-s)),t===n?a=(i-r)/(n-s):i===n?a=(r-t)/(n-s)+2:r===n&&(a=(t-i)/(n-s)+4)),a/=6;const l=256*a|0;let h=256*o|0,d=256*c|0;return h<0?h=0:h>255&&(h=255),d<0?d=0:d>255&&(d=255),e.hsl24to16(l,h,d)}static RGB15_HSL16=new Int32Array(32768);static{for(let t=0;t<32768;t++)e.RGB15_HSL16[t]=e.rgb15toHsl16(t)}static reverseHsl(t){const i=[];for(let r=0;r<32768;r++)e.RGB15_HSL16[r]===t&&i.push(r);return i}},Ll={[Kt.FINDUID]:e=>{const t=e.popInt(),i=Zl.getPlayerByUid(t);i?(e.activePlayer=i,e.pointerAdd(Ft[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.P_FINDUID]:e=>{const t=e.popInt()>>>0,i=Zl.getPlayerByUid(t);e.pointerGet(Ht[e.intOperand])&&e.activePlayer.uid===t?e.pushInt(1):i&&i.canAccess()?(e.activePlayer=i,e.pointerAdd(Ft[e.intOperand]),e.pointerAdd(Ht[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.STRONGQUEUE]:Vt(Ft,(e=>{const t=Pl(e),i=Br(e.popInt(),Ji),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find queue script: ${r}`);e.activePlayer.enqueueScript(s,3,i,t)})),[Kt.WEAKQUEUE]:Vt(Ft,(e=>{const t=Pl(e),i=Br(e.popInt(),Ji),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find queue script: ${r}`);e.activePlayer.enqueueScript(s,2,i,t)})),[Kt.QUEUE]:Vt(Ft,(e=>{const t=Pl(e),i=Br(e.popInt(),Ji),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find queue script: ${r}`);e.activePlayer.enqueueScript(s,0,i,t)})),[Kt.ANIM]:Vt(Ft,(e=>{const t=e.popInt(),i=e.popInt();e.activePlayer.playAnimation(i,t)})),[Kt.BUFFER_FULL]:Vt(Ft,(e=>{throw new Error('unimplemented')})),[Kt.BUILDAPPEARANCE]:Vt(Ft,(e=>{e.activePlayer.generateAppearance(Br(e.popInt(),Er).id)})),[Kt.CAM_LOOKAT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,nr);e.activePlayer.cameraPackets.addTail(new Ol(Ts.CAM_LOOKAT,n.x,n.z,i,r,s))})),[Kt.CAM_MOVETO]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,nr);e.activePlayer.cameraPackets.addTail(new Ol(Ts.CAM_MOVETO,n.x,n.z,i,r,s))})),[Kt.CAM_SHAKE]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4);e.activePlayer.write(new Bn(t,i,r,s))})),[Kt.CAM_RESET]:Vt(Ft,(e=>{e.activePlayer.write(new bn)})),[Kt.COORD]:Vt(Ft,(e=>{const t=e.activePlayer;e.pushInt(ji.packCoord(t.level,t.x,t.z))})),[Kt.DISPLAYNAME]:Vt(Ft,(e=>{e.pushString(e.activePlayer.displayName)})),[Kt.FACESQUARE]:Vt(Ft,(e=>{const t=Br(e.popInt(),nr);e.activePlayer.faceSquare(t.x,t.z)})),[Kt.IF_CLOSE]:Vt(Ft,(e=>{e.activePlayer.closeModal()})),[Kt.LAST_COM]:e=>{e.pushInt(e.activePlayer.lastCom)},[Kt.LAST_INT]:e=>{e.pushInt(e.lastInt)},[Kt.LAST_ITEM]:e=>{if(![cs.OPHELD1,cs.OPHELD2,cs.OPHELD3,cs.OPHELD4,cs.OPHELD5,cs.OPHELDU,cs.OPHELDT,cs.INV_BUTTON1,cs.INV_BUTTON2,cs.INV_BUTTON3,cs.INV_BUTTON4,cs.INV_BUTTON5].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastItem)},[Kt.LAST_SLOT]:e=>{if(![cs.OPHELD1,cs.OPHELD2,cs.OPHELD3,cs.OPHELD4,cs.OPHELD5,cs.OPHELDU,cs.OPHELDT,cs.INV_BUTTON1,cs.INV_BUTTON2,cs.INV_BUTTON3,cs.INV_BUTTON4,cs.INV_BUTTON5,cs.INV_BUTTOND].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastSlot)},[Kt.LAST_USEITEM]:e=>{if(![cs.OPHELDU,cs.APOBJU,cs.APLOCU,cs.APNPCU,cs.APPLAYERU,cs.OPOBJU,cs.OPLOCU,cs.OPNPCU,cs.OPPLAYERU].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastUseItem)},[Kt.LAST_USESLOT]:e=>{if(![cs.OPHELDU,cs.APOBJU,cs.APLOCU,cs.APNPCU,cs.APPLAYERU,cs.OPOBJU,cs.OPLOCU,cs.OPNPCU,cs.OPPLAYERU].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastUseSlot)},[Kt.MES]:Vt(Ft,(e=>{const t=e.popString();e.activePlayer.messageGame(t)})),[Kt.NAME]:Vt(Ft,(e=>{e.pushString(e.activePlayer.username)})),[Kt.P_APRANGE]:Vt(Ht,(e=>{e.activePlayer.apRange=Br(e.popInt(),Ji),e.activePlayer.apRangeCalled=!0})),[Kt.P_ARRIVEDELAY]:Vt(Ht,(e=>{e.activePlayer.lastMovement{e.activePlayer.write(new Fa),e.execution=$t.COUNTDIALOG})),[Kt.P_DELAY]:Vt(Ht,(e=>{e.activePlayer.delay=Zl.currentTick+Br(e.popInt(),Ji)+1,e.execution=$t.SUSPENDED})),[Kt.P_OPHELD]:Vt(Ht,(e=>{throw new Error('unimplemented')})),[Kt.P_OPLOC]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji)-1;if(t<0||t>=5)throw new Error(`Invalid oploc: ${t+1}`);e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,e.activeLoc,cs.APLOC1+t)})),[Kt.P_OPNPC]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji)-1;if(t<0||t>=5)throw new Error(`Invalid opnpc: ${t+1}`);e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,e.activeNpc,cs.APNPC1+t,{type:e.activeNpc.type,com:-1})})),[Kt.P_OPNPCT]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji);e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,e.activeNpc,cs.APNPCT,{type:e.activeNpc.type,com:t})})),[Kt.P_PAUSEBUTTON]:Vt(Ht,(e=>{e.execution=$t.PAUSEBUTTON})),[Kt.P_STOPACTION]:Vt(Ht,(e=>{e.activePlayer.stopAction()})),[Kt.P_CLEARPENDINGACTION]:Vt(Ht,(e=>{e.activePlayer.clearPendingAction()})),[Kt.P_TELEJUMP]:Vt(Ht,(e=>{const t=Br(e.popInt(),nr);e.activePlayer.teleJump(t.x,t.z,t.level)})),[Kt.P_TELEPORT]:Vt(Ht,(e=>{const t=Br(e.popInt(),nr);e.activePlayer.teleport(t.x,t.z,t.level)})),[Kt.P_WALK]:Vt(Ht,(e=>{const t=Br(e.popInt(),nr),i=e.activePlayer;i.queueWaypoints(ti(i.level,i.x,i.z,t.x,t.z,i.width,i.width,i.length)),i.updateMovement(!1)})),[Kt.SAY]:Vt(Ft,(e=>{e.activePlayer.say(e.popString())})),[Kt.SOUND_SYNTH]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);e.activePlayer.write(new za(t,i,r))})),[Kt.STAFFMODLEVEL]:Vt(Ft,(e=>{e.pushInt(e.activePlayer.staffModLevel)})),[Kt.STAT]:Vt(Ft,(e=>{const t=Br(e.popInt(),lr);e.pushInt(e.activePlayer.levels[t])})),[Kt.STAT_BASE]:Vt(Ft,(e=>{const t=Br(e.popInt(),lr);e.pushInt(e.activePlayer.baseLevels[t])})),[Kt.STAT_ADD]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,lr),Br(i,Ji),Br(r,Ji);const s=e.activePlayer,n=s.levels[t],a=n+(i+n*r/100);s.levels[t]=Math.min(a,255),3===t&&s.levels[3]>=s.baseLevels[3]&&s.resetHeroPoints()})),[Kt.STAT_SUB]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,lr),Br(i,Ji),Br(r,Ji);const s=e.activePlayer,n=s.levels[t],a=n-(i+n*r/100);s.levels[t]=Math.max(a,0)})),[Kt.SPOTANIM_PL]:Vt(Ft,(e=>{const t=Br(e.popInt(),Ji),i=e.popInt(),r=Br(e.popInt(),fr);e.activePlayer.spotanim(r.id,i,t)})),[Kt.STAT_HEAL]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,lr),Br(i,Ji),Br(r,Ji);const s=e.activePlayer,n=s.baseLevels[t],a=s.levels[t],o=a+(i+a*r/100);s.levels[t]=Math.max(Math.min(o,n),a),3===t&&s.levels[3]>=s.baseLevels[3]&&s.resetHeroPoints()})),[Kt.UID]:Vt(Ft,(e=>{e.pushInt(e.activePlayer.uid)})),[Kt.P_LOGOUT]:Vt(Ht,(e=>{e.activePlayer.logoutRequested=!0})),[Kt.IF_SETCOLOUR]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.write(new Xn(t,Nl.rgb24to15(i)))})),[Kt.IF_OPENCHAT]:Vt(Ft,(e=>{e.activePlayer.openChat(Br(e.popInt(),Ji))})),[Kt.IF_OPENMAINMODALSIDEOVERLAY]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.openMainModalSideOverlay(t,i)})),[Kt.IF_SETHIDE]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.write(new ea(t,1===i))})),[Kt.IF_SETOBJECT]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,Ji),Br(i,mr),Br(r,Ji),e.activePlayer.write(new aa(t,i,r))})),[Kt.IF_SETTABACTIVE]:Vt(Ft,(e=>{e.activePlayer.write(new ma(Br(e.popInt(),Ji)))})),[Kt.IF_SETMODEL]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.write(new ia(t,i))})),[Kt.IF_SETRECOL]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,Ji),e.activePlayer.write(new ua(t,i,r))})),[Kt.IF_SETTABFLASH]:Vt(Ft,(e=>{e.activePlayer.write(new Ya(Br(e.popInt(),Ji)))})),[Kt.IF_SETANIM]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),-1!==i&&e.activePlayer.write(new $n(t,i))})),[Kt.IF_SETTAB]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(i,Ji),e.activePlayer.setTab(t,i)})),[Kt.IF_OPENMAINMODAL]:Vt(Ft,(e=>{e.activePlayer.openMainModal(Br(e.popInt(),Ji))})),[Kt.IF_OPENCHATSTICKY]:Vt(Ft,(e=>{e.activePlayer.openChatSticky(Br(e.popInt(),Ji))})),[Kt.IF_OPENSIDEOVERLAY]:Vt(Ft,(e=>{e.activePlayer.openSideOverlay(Br(e.popInt(),Ji))})),[Kt.IF_SETPLAYERHEAD]:Vt(Ft,(e=>{e.activePlayer.write(new ca(Br(e.popInt(),Ji)))})),[Kt.IF_SETTEXT]:Vt(Ft,(e=>{const t=e.popString(),i=Br(e.popInt(),Ji);e.activePlayer.write(new fa(i,t))})),[Kt.IF_SETNPCHEAD]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,or),e.activePlayer.write(new sa(t,i))})),[Kt.IF_SETPOSITION]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,Ji),e.activePlayer.write(new ha(t,i,r))})),[Kt.IF_MULTIZONE]:Vt(Ft,(e=>{e.activePlayer.write(new Wa(1===Br(e.popInt(),Ji)))})),[Kt.GIVEXP]:Vt(Ht,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.addXp(t,i)})),[Kt.DAMAGE]:e=>{const t=Br(e.popInt(),Ji),i=Br(e.popInt(),pr),r=Br(e.popInt(),Ji),s=Zl.getPlayerByUid(r);s&&s.applyDamage(t,i)},[Kt.IF_SETRESUMEBUTTONS]:Vt(Ft,(e=>{const[t,i,r,s,n]=e.popInts(5);e.activePlayer.resumeButtons=[t,i,r,s,n]})),[Kt.TEXT_GENDER]:Vt(Ft,(e=>{const[t,i]=e.popStrings(2);0==e.activePlayer.gender?e.pushString(t):e.pushString(i)})),[Kt.MIDI_SONG]:e=>{e.activePlayer.playSong(Br(e.popString(),er))},[Kt.MIDI_JINGLE]:e=>{const t=Br(e.popInt(),Ji),i=Br(e.popString(),er);e.activePlayer.playJingle(t,i)},[Kt.SOFTTIMER]:Vt(Ft,(e=>{const t=Pl(e),i=e.popInt(),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find timer script: ${r}`);e.activePlayer.setTimer(1,s,t,i)})),[Kt.CLEARSOFTTIMER]:Vt(Ft,(e=>{e.activePlayer.clearTimer(e.popInt())})),[Kt.SETTIMER]:Vt(Ft,(e=>{const t=Pl(e),i=e.popInt(),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find timer script: ${r}`);e.activePlayer.setTimer(0,s,t,i)})),[Kt.CLEARTIMER]:Vt(Ft,(e=>{e.activePlayer.clearTimer(e.popInt())})),[Kt.HINT_COORD]:e=>{const[t,i,r]=e.popInts(3),s=Br(i,nr);e.activePlayer.hintTile(t,s.x,s.z,r)},[Kt.HINT_STOP]:e=>{e.activePlayer.stopHint()},[Kt.IF_CLOSESTICKY]:e=>{e.activePlayer.closeSticky()},[Kt.P_EXACTMOVE]:Vt(Ht,(e=>{const[t,i,r,s,n]=e.popInts(5),a=Br(t,nr),o=Br(i,nr);e.activePlayer.unsetMapFlag(),e.activePlayer.exactMove(a.x,a.z,o.x,o.z,r,s,n)})),[Kt.BUSY]:e=>{e.pushInt(e.activePlayer.busy()?1:0)},[Kt.BUSY2]:e=>{e.pushInt(e.activePlayer.hasInteraction()||e.activePlayer.hasWaypoints()?1:0)},[Kt.GETQUEUE]:e=>{const t=e.popInt();let i=0;for(let r=e.activePlayer.queue.head();null!==r;r=e.activePlayer.queue.next())r.script.id===t&&i++;for(let r=e.activePlayer.weakQueue.head();null!==r;r=e.activePlayer.weakQueue.next())r.script.id===t&&i++;e.pushInt(i)},[Kt.P_LOCMERGE]:Vt(Ht,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(r,nr),a=Br(s,nr);Zl.mergeLoc(e.activeLoc,e.activePlayer,t,i,n.z,n.x,a.z,a.x)})),[Kt.LAST_LOGIN_INFO]:e=>{const t=e.activePlayer;if(!Sl(t)||null===t.client)return;const i=t.client.remoteAddress;if(null==i)return;const r=new Uint32Array(new Uint8Array(i.split('.').map((e=>parseInt(e)))).reverse().buffer)[0];t.lastLoginInfo(r,0,201,0)},[Kt.BAS_READYANIM]:e=>{e.activePlayer.basReadyAnim=Br(e.popInt(),Tr).id},[Kt.BAS_TURNONSPOT]:e=>{e.activePlayer.basTurnOnSpot=Br(e.popInt(),Tr).id},[Kt.BAS_WALK_F]:e=>{e.activePlayer.basWalkForward=Br(e.popInt(),Tr).id},[Kt.BAS_WALK_B]:e=>{e.activePlayer.basWalkBackward=Br(e.popInt(),Tr).id},[Kt.BAS_WALK_L]:e=>{e.activePlayer.basWalkLeft=Br(e.popInt(),Tr).id},[Kt.BAS_WALK_R]:e=>{e.activePlayer.basWalkRight=Br(e.popInt(),Tr).id},[Kt.BAS_RUNNING]:e=>{const t=e.popInt();e.activePlayer.basRunning=-1!==t?Br(t,Tr).id:-1},[Kt.GENDER]:e=>{e.pushInt(e.activePlayer.gender)},[Kt.HINT_NPC]:e=>{e.activePlayer.hintNpc(Br(e.popInt(),Ji))},[Kt.HINT_PLAYER]:e=>{const t=Br(e.popInt(),Ji),i=Zl.getPlayerByUid(t);i&&e.activePlayer.hintPlayer(i.pid)},[Kt.HEADICONS_GET]:e=>{e.pushInt(e.activePlayer.headicons)},[Kt.HEADICONS_SET]:e=>{e.activePlayer.headicons=Br(e.popInt(),Ji)},[Kt.P_OPOBJ]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji)-1;if(t<0||t>=5)throw new Error(`Invalid opobj: ${t+1}`);e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,e.activeObj,cs.APOBJ1+t)})),[Kt.P_OPPLAYER]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji)-1;if(t<0||t>=5)throw new Error(`Invalid opplayer: ${t+1}`);const i=e._activePlayer2;i&&(e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,i,cs.APPLAYER1+t))})),[Kt.ALLOWDESIGN]:e=>{e.activePlayer.allowDesign=1===Br(e.popInt(),Ji)},[Kt.LAST_TARGETSLOT]:e=>{if(![cs.INV_BUTTOND].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastTargetSlot)},[Kt.WALKTRIGGER]:e=>{e.activePlayer.walktrigger=e.popInt()},[Kt.GETWALKTRIGGER]:e=>{e.pushInt(e.activePlayer.walktrigger)},[Kt.CLEARQUEUE]:e=>{const t=e.popInt();for(let i=e.activePlayer.queue.head();null!==i;i=e.activePlayer.queue.next())i.script.id===t&&i.unlink();for(let i=e.activePlayer.weakQueue.head();null!==i;i=e.activePlayer.weakQueue.next())i.script.id===t&&i.unlink()},[Kt.HEALENERGY]:e=>{const t=Br(e.popInt(),Ji),i=e.activePlayer;i.runenergy=Math.min(Math.max(i.runenergy+t,0),1e4)},[Kt.AFK_EVENT]:e=>{e.pushInt(e.activePlayer.afkEventReady?1:0),e.activePlayer.afkEventReady=!1},[Kt.LOWMEMORY]:e=>{e.pushInt(e.activePlayer.lowMemory?1:0)},[Kt.SETIDKIT]:e=>{const[t,i]=e.popInts(2),r=Br(t,Ar);let s=r.type;1===e.activePlayer.gender&&(s-=7),e.activePlayer.body[s]=r.id;let n=r.type;1===e.activePlayer.gender&&(n-=7);let a=-1;0===n||1===n?a=0:2===n||3===n?a=1:4===n||(5===n?a=2:6===n&&(a=3)),-1!==a&&(e.activePlayer.colors[a]=i)},[Kt.SETGENDER]:e=>{const t=Br(e.popInt(),br);for(let i=0;i<7;i++){e.activePlayer.body[i]=-1;for(let r=0;r{const t=Br(e.popInt(),Rr);e.activePlayer.colors[4]=t},[Kt.P_OPPLAYERT]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji),i=e._activePlayer2;i&&(e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,i,cs.APPLAYERT,{type:-1,com:t}))})),[Kt.FINDHERO]:Vt(Ft,(e=>{const t=e.activePlayer.findHero();if(-1===t)return void e.pushInt(0);const i=Zl.getPlayerByUid(t);i?(e._activePlayer2=i,e.pointerAdd(Gt.ActivePlayer2),e.pushInt(1)):e.pushInt(0)})),[Kt.BOTH_HEROPOINTS]:Vt(Ft,(e=>{const t=Br(e.popInt(),Ji),i=1===e.intOperand,r=i?e._activePlayer2:e._activePlayer,s=i?e._activePlayer:e._activePlayer2;if(!r||!s)throw new Error('player is null');s.addHero(r.uid,t)})),[Kt.P_ANIMPROTECT]:Vt(Ht,(e=>{e.activePlayer.animProtect=Br(e.popInt(),Ji)})),[Kt.RUNENERGY]:Vt(Ft,(e=>{const t=e.activePlayer;e.pushInt(t.runenergy)})),[Kt.WEIGHT]:Vt(Ht,(e=>{e.pushInt(e.activePlayer.runweight)})),[Kt.LAST_COORD]:Vt(Ft,(e=>{e.pushInt(ji.packCoord(e.activePlayer.level,e.activePlayer.lastX,e.activePlayer.lastZ))}))};function Pl(e){const t=e.popString(),i=[];for(let r=t.length-1;r>=0;r--){const s=t.charAt(r);i[r]='s'===s?e.popString():e.popInt()}return i}var wl=Ll,bl={[Kt.MAP_CLOCK]:e=>{e.pushInt(Zl.currentTick)},[Kt.MAP_MEMBERS]:e=>{e.pushInt(vt.NODE_MEMBERS?1:0)},[Kt.MAP_PLAYERCOUNT]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,nr);let n=0;for(let e=Math.floor(r.x/8);e<=Math.ceil(s.x/8);e++)for(let t=Math.floor(r.z/8);t<=Math.ceil(s.z/8);t++)for(const i of Zl.getZone(e<<3,t<<3,r.level).getAllPlayersSafe())i.x>=r.x&&i.x<=s.x&&i.z>=r.z&&i.z<=s.z&&n++;e.pushInt(n)},[Kt.HUNTALL]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr);Br(i,Ji);const n=Br(r,vr);e.huntIterator=new ts(Zl.currentTick,s.level,s.x,s.z,i,n,-1,-1,je.PLAYER)},[Kt.HUNTNEXT]:e=>{const t=e.huntIterator?.next();if(t&&!t.done){if(!(t.value instanceof Do))throw new Error('[ServerOps] huntnext command must result instance of Player.');e.activePlayer=t.value,e.pointerAdd(Ft[e.intOperand]),e.pushInt(1)}else e.pushInt(0)},[Kt.NPC_HUNTALL]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr);Br(i,Ji);const n=Br(r,vr);e.huntIterator=new ts(Zl.currentTick,s.level,s.x,s.z,i,n,-1,-1,je.NPC)},[Kt.NPC_HUNTNEXT]:e=>{const t=e.huntIterator?.next();if(t&&!t.done){if(!(t.value instanceof kl))throw new Error('[ServerOps] npc_huntnext command must result instance of Npc.');e.activeNpc=t.value,e.pointerAdd(kt[e.intOperand]),e.pushInt(1)}else e.pushInt(0)},[Kt.INZONE]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr),n=Br(i,nr),a=Br(r,nr);a.xn.x||a.leveln.level||a.zn.z?e.pushInt(0):e.pushInt(1)},[Kt.LINEOFWALK]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,nr);r.level===s.level?e.pushInt(gi(r.level,r.x,r.z,s.x,s.z,1,1,1,1)?1:0):e.pushInt(0)},[Kt.STAT_RANDOM]:e=>{const[t,i,r]=e.popInts(3),s=Math.floor(i*(99-t)/98)+Math.floor(r*(t-1)/98)+1,n=Math.floor(256*Math.random());e.pushInt(s>n?1:0)},[Kt.SPOTANIM_MAP]:e=>{const[t,i,r,s]=e.popInts(4),n=Br(i,nr),a=Br(t,fr);Zl.animMap(n.level,n.x,n.z,a.id,r,s)},[Kt.DISTANCE]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,nr);e.pushInt(ji.distanceToSW(r,s))},[Kt.MOVECOORD]:e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,nr);e.pushInt(ji.packCoord(n.level+r,n.x+i,n.z+s))},[Kt.SEQLENGTH]:e=>{e.pushInt(Br(e.popInt(),Tr).duration)},[Kt.SPLIT_INIT]:e=>{const[t,i,r]=e.popInts(3);let s=e.popString();const n=Br(r,Or);if(s.startsWith('')){const t=s.substring(3,s.indexOf('>'));e.splitMesanim=ot.getId(t),s=s.substring(s.indexOf('>')+1)}else e.splitMesanim=-1;e.splitPages=[];const a=n.split(s,t);for(;a.length>0;)e.splitPages.push(a.splice(0,i))},[Kt.SPLIT_GET]:e=>{const[t,i]=e.popInts(2);e.pushString(e.splitPages[t][i])},[Kt.SPLIT_PAGECOUNT]:e=>{e.pushInt(e.splitPages.length)},[Kt.SPLIT_LINECOUNT]:e=>{const t=e.popInt();e.pushInt(e.splitPages[t].length)},[Kt.SPLIT_GETANIM]:e=>{const t=e.popInt();-1!==e.splitMesanim?e.pushInt(Br(e.splitMesanim,Nr).len[e.splitPages[t].length-1]):e.pushInt(-1)},[Kt.STRUCT_PARAM]:e=>{const[t,i]=e.popInts(2),r=Br(i,ar),s=Br(t,Lr);r.isString()?e.pushString(rt(r.id,s,r.defaultString)):e.pushInt(st(r.id,s,r.defaultInt))},[Kt.COORDX]:e=>{e.pushInt(Br(e.popInt(),nr).x)},[Kt.COORDY]:e=>{e.pushInt(Br(e.popInt(),nr).level)},[Kt.COORDZ]:e=>{e.pushInt(Br(e.popInt(),nr).z)},[Kt.PLAYERCOUNT]:e=>{e.pushInt(Zl.getTotalPlayers())},[Kt.MAP_BLOCKED]:e=>{const t=Br(e.popInt(),nr);e.pushInt(ui(t.x,t.z,t.level,Ri.WALK_BLOCKED)?1:0)},[Kt.MAP_INDOORS]:e=>{const t=Br(e.popInt(),nr);e.pushInt(ui(t.x,t.z,t.level,Ri.ROOF)?1:0)},[Kt.LINEOFSIGHT]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,nr);r.level===s.level?e.pushInt(fi(r.level,r.x,r.z,s.x,s.z,1,1,1,1)?1:0):e.pushInt(0)},[Kt.WORLD_DELAY]:e=>{e.execution=$t.WORLD_SUSPENDED},[Kt.PROJANIM_PL]:e=>{const[t,i,r,s,n,a,o,c,l]=e.popInts(9),h=Br(t,nr),d=Br(r,fr),u=Zl.getPlayerByUid(i);if(!u)throw new Error(`attempted to use invalid player uid: ${i}`);Zl.mapProjAnim(h.level,h.x,h.z,u.x,u.z,-u.pid-1,d.id,s+100,n+100,a,o,c,l)},[Kt.PROJANIM_NPC]:e=>{const[t,i,r,s,n,a,o,c,l]=e.popInts(9),h=Br(t,nr),d=Br(r,fr),u=65535&i,p=Zl.getNpc(u);if(!p)throw new Error(`attempted to use invalid npc uid: ${i}`);Zl.mapProjAnim(h.level,h.x,h.z,p.x,p.z,p.nid+1,d.id,s+100,n+100,a,o,c,l)},[Kt.PROJANIM_MAP]:e=>{const[t,i,r,s,n,a,o,c,l]=e.popInts(9),h=Br(r,fr),d=Br(t,nr),u=Br(i,nr);Zl.mapProjAnim(d.level,d.x,d.z,u.x,u.z,0,h.id,s+100,n,a,o,c,l)},[Kt.MAP_LOCADDUNSAFE]:e=>{const t=Br(e.popInt(),nr);for(const i of Zl.getZone(t.x,t.z,t.level).getAllLocsUnsafe()){if(1!==Br(i.type,tr).active)continue;const r=_i(i.shape);if(i.checkLifeCycle(Zl.currentTick)||r!==ki.WALL)if(r===ki.WALL){if(i.x===t.x&&i.z===t.z)return void e.pushInt(1)}else if(r===ki.GROUND){const r=i.angle===Ui.NORTH||i.angle===Ui.SOUTH?i.length:i.width,s=i.angle===Ui.NORTH||i.angle===Ui.SOUTH?i.width:i.length;for(let n=0;n{e.pushInt(Zl.getTotalNpcs())},[Kt.ZONECOUNT]:e=>{e.pushInt(Zl.getTotalZones())},[Kt.LOCCOUNT]:e=>{e.pushInt(Zl.getTotalLocs())},[Kt.OBJCOUNT]:e=>{e.pushInt(Zl.getTotalObjs())}},Rl=bl,Bl={[Kt.APPEND_NUM]:e=>{const t=e.popString(),i=e.popInt();e.pushString(t+i)},[Kt.APPEND]:e=>{const[t,i]=e.popStrings(2);e.pushString(t+i)},[Kt.APPEND_SIGNNUM]:e=>{const t=e.popString(),i=e.popInt();i>=0?e.pushString(`${t}+${i}`):e.pushString(t+i)},[Kt.LOWERCASE]:e=>{e.pushString(e.popString().toLowerCase())},[Kt.TOSTRING]:e=>{e.pushString(e.popInt().toString())},[Kt.COMPARE]:e=>{const[t,i]=e.popStrings(2);e.pushInt(function(e,t){const i=e.length,r=t.length,s=Math.min(i,r);let n=0;for(;n{const t=e.popInt(),[i,r]=e.popStrings(2);e.pushString(1===t?i:r)},[Kt.APPEND_CHAR]:e=>{const t=e.popString(),i=e.popInt();e.pushString(t+String.fromCharCode(i))},[Kt.STRING_LENGTH]:e=>{e.pushInt(e.popString().length)},[Kt.SUBSTRING]:e=>{const t=e.popString(),[i,r]=e.popInts(2);e.pushString(t.substring(i,r))},[Kt.STRING_INDEXOF_CHAR]:e=>{const t=e.popString(),i=String.fromCharCode(e.popInt());e.pushInt(t.indexOf(i))},[Kt.STRING_INDEXOF_STRING]:e=>{const t=e.popString(),i=e.popString();e.pushInt(t.indexOf(i))}};var Ul=Bl,Dl=class e{static HANDLERS={...Fr,...Rl,...wl,...us,...ns,...Es,...ps,...as,..._s,...Zr,...zr,...Ul,...ys,...Hr,...Wr};static init(e,t=null,i=null,r=[]){const s=new $t(e,r);return s.self=t,t instanceof Do?(s._activePlayer=t,s.pointerAdd(Gt.ActivePlayer)):t instanceof kl?(s._activeNpc=t,s.pointerAdd(Gt.ActiveNpc)):t instanceof ss?(s._activeLoc=t,s.pointerAdd(Gt.ActiveLoc)):t instanceof $r&&(s._activeObj=t,s.pointerAdd(Gt.ActiveObj)),i instanceof Do?t instanceof Do?(s._activePlayer2=i,s.pointerAdd(Gt.ActivePlayer2)):(s._activePlayer=i,s.pointerAdd(Gt.ActivePlayer)):i instanceof kl?t instanceof kl?(s._activeNpc2=i,s.pointerAdd(Gt.ActiveNpc2)):(s._activeNpc=i,s.pointerAdd(Gt.ActiveNpc)):i instanceof ss?t instanceof ss?(s._activeLoc2=i,s.pointerAdd(Gt.ActiveLoc2)):(s._activeLoc=i,s.pointerAdd(Gt.ActiveLoc)):i instanceof $r&&(t instanceof $r?(s._activeObj2=i,s.pointerAdd(Gt.ActiveObj2)):(s._activeObj=i,s.pointerAdd(Gt.ActiveObj))),s}static execute(t,i=!1,r=!1){if(!t||!t.script||!t.script.info)return $t.ABORTED;try{i&&t.reset(),t.execution!==$t.RUNNING&&t.executionHistory.push(t.execution),t.execution=$t.RUNNING;const s=1e3*performance.now();for(;t.execution===$t.RUNNING;){if(t.pc>=t.script.opcodes.length||t.pc<-1)throw new Error('Invalid program counter: '+t.pc+', max expected: '+t.script.opcodes.length);if(!r&&t.opcount>5e5)throw new Error('Too many instructions');t.opcount++,e.executeInner(t,t.script.opcodes[++t.pc])}const n=1e3*performance.now()-s|0;if(vt.NODE_DEBUG_PROFILE&&n>1e3){const e=`Warning [cpu time]: Script: ${t.script.info.scriptName}, time: ${n}us, opcount: ${t.opcount}`;t.self instanceof Do?t.self.wrappedMessageGame(e):console.warn(e)}}catch(e){if(t.pc>=0&&t.pc>16&1:i<=Kt.POP_ARRAY_INT&&(r=0),e.message=Kt[i].toLowerCase()+' '+e.message,r&&(e.message='.'+e.message)}if(t.self instanceof Do){t.self.wrappedMessageGame(`script error: ${e.message}`),t.self.wrappedMessageGame(`file: ${path3.basename(t.script.info.sourceFilePath)}`),t.self.wrappedMessageGame(''),t.self.wrappedMessageGame('stack backtrace:'),t.self.wrappedMessageGame(` 1: ${t.script.name} - ${t.script.fileName}:${t.script.lineNumber(t.pc)}`);let i=1;for(let e=t.fp;e>0;e--){const r=t.frames[e];r&&(i++,t.self.wrappedMessageGame(` ${i}: ${r.script.name} - ${r.script.fileName}:${r.script.lineNumber(r.pc)}`))}for(let e=t.debugFp;e>=0;e--){const r=t.debugFrames[e];r&&(i++,t.self.wrappedMessageGame(` ${i}: ${r.script.name} - ${r.script.fileName}:${r.script.lineNumber(r.pc)}`))}}console.error(`script error: ${e.message}`),console.error(`file: ${path3.basename(t.script.info.sourceFilePath)}`),console.error(''),console.error('stack backtrace:'),console.error(` 1: ${t.script.name} - ${t.script.fileName}:${t.script.lineNumber(t.pc)}`);let i=1;for(let e=t.fp;e>0;e--){const r=t.frames[e];r&&(i++,console.error(` ${i}: ${r.script.name} - ${r.script.fileName}:${r.script.lineNumber(r.pc)}`))}for(let e=t.debugFp;e>=0;e--){const r=t.debugFrames[e];r&&(i++,console.error(` ${i}: ${r.script.name} - ${r.script.fileName}:${r.script.lineNumber(r.pc)}`))}t.execution=$t.ABORTED}return t.execution}static executeInner(t,i){const r=e.HANDLERS[i];if(!r)throw new Error(`Unknown opcode ${i}`);r(t)}},kl=class e extends Ns{static ANIM=2;static FACE_ENTITY=4;static SAY=8;static DAMAGE=16;static CHANGE_TYPE=32;static SPOTANIM=64;static FACE_COORD=128;nid;type;uid;origType;startX;startZ;levels=new Uint8Array(6);baseLevels=new Uint8Array(6);vars;varsString;activeScript=null;delay=0;queue=new Ce;timerInterval=0;timerClock=0;huntMode=-1;nextHuntTick=-1;huntrange=5;nextPatrolTick=-1;nextPatrolPoint=0;delayedPatrol=!1;heroPoints=new Array(16);constructor(t,i,r,s,n,a,o,c,l,h){super(t,i,r,s,n,a,l,h,Os.NAIVE,e.FACE_COORD,e.FACE_ENTITY),this.nid=o,this.type=c,this.uid=c<<16|o,this.startX=this.x,this.startZ=this.z,this.origType=c;const d=ft.get(c);for(let e=0;et&&t.uid===e));if(-1!==i)return void(this.heroPoints[i].points+=t);const r=this.heroPoints.findIndex((e=>e&&-1===e.uid));-1===r||(this.heroPoints[r]={uid:e,points:t})}findHero(){return this.heroPoints.sort(((e,t)=>t.points-e.points)),this.heroPoints[0]?.uid??-1}getVar(e){const t=Ot.get(e);return t.type===Pe.STRING?this.varsString[t.id]:this.vars[t.id]}setVar(e,t){const i=Ot.get(e);i.type===Pe.STRING&&'string'==typeof t?this.varsString[i.id]=t:'number'==typeof t&&(this.vars[i.id]=t)}resetEntity(e){if(e){this.type=this.origType,this.uid=this.type<<16|this.nid,this.faceX=-1,this.faceZ=-1,this.orientationX=-1,this.orientationZ=-1;for(let e=0;et.maxrange&&e>t.maxrange)return!1}if(this.targetOp>=Xe.OPPLAYER1&&this.targetOp<=Xe.OPPLAYER5){const e=Math.abs(this.target.x-this.startX),i=Math.abs(this.target.z-this.startZ);if(Math.max(e,i)>t.maxrange+1)return this.defaultMode(),!1;if(e===t.maxrange+1&&i===t.maxrange+1)return this.defaultMode(),!1}else if(this.targetOp>=Xe.APPLAYER1&&this.targetOp<=Xe.APPLAYER5&&ji.distanceToSW(this.target,{x:this.startX,z:this.startZ})>t.maxrange+t.attackrange)return this.defaultMode(),!1}if(e&&this.target instanceof Ns&&!this.interacted&&-1===this.walktrigger&&this.pathToPathingTarget(),-1!==this.walktrigger){const e=ft.get(this.type),t=jt.getByTrigger(cs.AI_QUEUE1+this.walktrigger,e.id,e.category);if(this.walktrigger=-1,t){const e=Dl.init(t,this,null,[this.walktriggerArg]);Dl.execute(e)}}return this.moveSpeed!==Is.INSTANT&&(this.moveSpeed=this.defaultMoveSpeed()),super.processMovement()}blockWalkFlag(){return this.moveRestrict===dt.NORMAL?Ri.NPC:this.moveRestrict===dt.BLOCKED?Ri.OPEN:this.moveRestrict===dt.BLOCKED_NORMAL||this.moveRestrict===dt.INDOORS||this.moveRestrict===dt.OUTDOORS?Ri.NPC:this.moveRestrict===dt.NOMOVE?Ri.NULL:this.moveRestrict===dt.PASSTHRU?Ri.OPEN:Ri.NULL}defaultMoveSpeed(){return Is.WALK}delayed(){return this.delay>Zl.currentTick}setTimer(e){this.timerInterval=e,this.timerClock=0}executeScript(e){if(!e)return;const t=Dl.execute(e);t!==$t.FINISHED&&t!==$t.ABORTED?t===$t.WORLD_SUSPENDED?Zl.enqueueScript(e,e.popInt()):t===$t.NPC_SUSPENDED?e.activeNpc.activeScript=e:e.activePlayer.activeScript=e:e===this.activeScript&&(this.activeScript=null),e.pointerGet(Gt.ProtectedActivePlayer)&&e._activePlayer&&(e._activePlayer.protect=!1,e.pointerRemove(Gt.ProtectedActivePlayer)),e.pointerGet(Gt.ProtectedActivePlayer2)&&e._activePlayer2&&(e._activePlayer2.protect=!1,e.pointerRemove(Gt.ProtectedActivePlayer2))}processTimers(){if(0!==this.timerInterval&&++this.timerClock>=this.timerInterval){this.timerClock=0;const e=ft.get(this.type),t=jt.getByTrigger(cs.AI_TIMER,e.id,e.category);t&&this.executeScript(Dl.init(t,this))}}processQueue(){for(let e=this.queue.head();null!==e;e=this.queue.next())if(this.delayed()||e.delay--,!this.delayed()&&e.delay<=0){const t=Dl.init(e.script,this,null,e.args);t.lastInt=e.lastInt,this.executeScript(t),e.unlink()}}enqueueScript(e,t=0,i=0){const r=new As(0,e,[],t);r.lastInt=i,this.queue.addTail(r)}randomWalk(e){const t=Math.round(Math.random()*(2*e)-e),i=Math.round(Math.random()*(2*e)-e),r=this.startX+t,s=this.startZ+i;r===this.x&&s===this.z||this.queueWaypoint(r,s)}processNpcModes(){this.targetOp===Xe.NULL?this.defaultMode():this.targetOp===Xe.NONE?this.noMode():this.targetOp===Xe.WANDER?this.wanderMode():this.targetOp===Xe.PATROL?this.patrolMode():this.targetOp===Xe.PLAYERESCAPE?this.playerEscapeMode():this.targetOp===Xe.PLAYERFOLLOW?this.playerFollowMode():this.targetOp===Xe.PLAYERFACE?this.playerFaceMode():this.targetOp===Xe.PLAYERFACECLOSE?this.playerFaceCloseMode():this.aiMode()}noMode(){this.clearInteraction(),this.updateMovement(!1),this.targetOp=Xe.NONE}defaultMode(){this.clearInteraction(),this.updateMovement(!1);const e=ft.get(this.type);this.targetOp=e.defaultmode}wanderMode(){const e=ft.get(this.type);e.moverestrict!==dt.NOMOVE&&Math.random()<.125&&this.randomWalk(e.wanderrange),this.updateMovement(!1)}patrolMode(){const e=ft.get(this.type),t=e.patrolCoord,i=e.patrolDelay[this.nextPatrolPoint];let r=ji.unpackCoord(t[this.nextPatrolPoint]);this.updateMovement(!1),this.hasWaypoints()||this.target||this.queueWaypoint(r.x,r.z),(this.x!==r.x||this.z!==r.z)&&Zl.currentTick>=this.nextPatrolTick&&this.teleport(r.x,r.z,r.level),this.x!==r.x||this.z!==r.z||this.delayedPatrol||(this.nextPatrolTick=Zl.currentTick+i,this.delayedPatrol=!0),this.nextPatrolTick>Zl.currentTick||(this.nextPatrolPoint=(this.nextPatrolPoint+1)%t.length,this.nextPatrolTick=Zl.currentTick+30,this.delayedPatrol=!1,r=ji.unpackCoord(t[this.nextPatrolPoint]),this.queueWaypoint(r.x,r.z))}playerEscapeMode(){if(!this.target)return void this.defaultMode();if(!(this.target instanceof Do))throw new Error('[Npc] Target must be a Player for playerescape mode.');if(null===Zl.getPlayerByUid(this.target.uid))return void this.defaultMode();if(ji.distanceToSW(this,this.target)>25)return void this.defaultMode();let e,t;this.target.x>=this.x&&this.target.z>=this.z?(e=Wi,t=Ri.WALL_SOUTH|Ri.WALL_WEST):this.target.x>=this.x&&this.target.z=this.z?(e=zi,t=Ri.WALL_SOUTH|Ri.WALL_EAST):(e=Hi,t=Ri.WALL_NORTH|Ri.WALL_EAST);const i=ji.moveX(this.x,e),r=ji.moveZ(this.z,e);if(ui(i,r,this.level,t))return void this.defaultMode();const s={x:i,z:r,level:this.level};if(ji.distanceToSW(s,{x:this.startX,z:this.startZ})e.maxrange?this.defaultMode():this.updateMovement(!1)}playerFaceCloseMode(){if(this.target){if(!(this.target instanceof Do))throw new Error('[Npc] Target must be a Player for playerfaceclose mode.');null!=Zl.getPlayerByUid(this.target.uid)&&this.level===this.target.level?ji.distanceTo(this,this.target)>1?this.defaultMode():this.updateMovement(!1):this.defaultMode()}else this.defaultMode()}aiMode(){if(this.delayed()||!this.target)return void this.defaultMode();if(this.target.level!==this.level)return void this.defaultMode();if(this.target instanceof e&&(void 0===Zl.getNpc(this.target.nid)||this.target.delayed()))return void this.defaultMode();if(this.target instanceof e&&-1!==this.targetSubject.type&&null===Zl.getNpcByUid(this.targetSubject.type<<16|this.target.nid))return void this.defaultMode();if(this.target instanceof $r&&null===Zl.getObj(this.target.x,this.target.z,this.level,this.target.type,-1))return void this.defaultMode();if(this.target instanceof ss&&null===Zl.getLoc(this.target.x,this.target.z,this.level,this.target.type))return void this.defaultMode();if(this.target instanceof Do&&null===Zl.getPlayerByUid(this.target.uid))return void this.defaultMode();const t=ft.get(this.type),i=this.targetOp>=Xe.APNPC1&&this.targetOp<=Xe.APNPC5||this.targetOp>=Xe.APPLAYER1&&this.targetOp<=Xe.APPLAYER5||this.targetOp>=Xe.APLOC1&&this.targetOp<=Xe.APLOC5||this.targetOp>=Xe.APOBJ1&&this.targetOp<=Xe.APOBJ5,r=!i,s=this.getTrigger();s&&r&&this.inOperableDistance(this.target)&&this.target instanceof Ns||s&&i&&this.inApproachDistance(t.attackrange,this.target)?(this.executeScript(Dl.init(s,this,this.target)),this.interacted=!0,this.clearWaypoints()):this.inOperableDistance(this.target)&&this.target instanceof Ns&&(this.target=null,this.interacted=!0,this.clearWaypoints());const n=this.updateMovement();n&&(this.alreadyFacedEntity=!1),this.target&&!this.interacted&&(this.interacted=!1,s&&r&&this.inOperableDistance(this.target)&&(this.target instanceof Ns||!n)||s&&i&&this.inApproachDistance(t.attackrange,this.target)?(this.executeScript(Dl.init(s,this,this.target)),this.interacted=!0,this.clearWaypoints()):this.inOperableDistance(this.target)&&(this.target instanceof Ns||!n)&&(this.target=null,this.interacted=!0,this.clearWaypoints()))}getTrigger(){const e=this.getTriggerForMode(this.targetOp);return e?jt.getByTrigger(e,this.type,-1)??null:null}getTriggerForMode(e){return e===Xe.OPPLAYER1?cs.AI_OPPLAYER1:e===Xe.OPPLAYER2?cs.AI_OPPLAYER2:e===Xe.OPPLAYER3?cs.AI_OPPLAYER3:e===Xe.OPPLAYER4?cs.AI_OPPLAYER4:e===Xe.OPPLAYER5?cs.AI_OPPLAYER5:e===Xe.APPLAYER1?cs.AI_APPLAYER1:e===Xe.APPLAYER2?cs.AI_APPLAYER2:e===Xe.APPLAYER3?cs.AI_APPLAYER3:e===Xe.APPLAYER4?cs.AI_APPLAYER4:e===Xe.APPLAYER5?cs.AI_APPLAYER5:e===Xe.OPLOC1?cs.AI_OPLOC1:e===Xe.OPLOC2?cs.AI_OPLOC2:e===Xe.OPLOC3?cs.AI_OPLOC3:e===Xe.OPLOC4?cs.AI_OPLOC4:e===Xe.OPLOC5?cs.AI_OPLOC5:e===Xe.APLOC1?cs.AI_APLOC1:e===Xe.APLOC2?cs.AI_APLOC2:e===Xe.APLOC3?cs.AI_APLOC3:e===Xe.APLOC4?cs.AI_APLOC4:e===Xe.APLOC5?cs.AI_APLOC5:e===Xe.OPOBJ1?cs.AI_OPOBJ1:e===Xe.OPOBJ2?cs.AI_OPOBJ2:e===Xe.OPOBJ3?cs.AI_OPOBJ3:e===Xe.OPOBJ4?cs.AI_OPOBJ4:e===Xe.OPOBJ5?cs.AI_OPOBJ5:e===Xe.APOBJ1?cs.AI_APOBJ1:e===Xe.APOBJ2?cs.AI_APOBJ2:e===Xe.APOBJ3?cs.AI_APOBJ3:e===Xe.APOBJ4?cs.AI_APOBJ4:e===Xe.APOBJ5?cs.AI_APOBJ5:e===Xe.OPNPC1?cs.AI_OPNPC1:e===Xe.OPNPC2?cs.AI_OPNPC2:e===Xe.OPNPC3?cs.AI_OPNPC3:e===Xe.OPNPC4?cs.AI_OPNPC4:e===Xe.OPNPC5?cs.AI_OPNPC5:e===Xe.APNPC1?cs.AI_APNPC1:e===Xe.APNPC2?cs.AI_APNPC2:e===Xe.APNPC3?cs.AI_APNPC3:e===Xe.APNPC4?cs.AI_APNPC4:e===Xe.APNPC5?cs.AI_APNPC5:e===Xe.QUEUE1?cs.AI_QUEUE1:e===Xe.QUEUE2?cs.AI_QUEUE2:e===Xe.QUEUE3?cs.AI_QUEUE3:e===Xe.QUEUE4?cs.AI_QUEUE4:e===Xe.QUEUE5?cs.AI_QUEUE5:e===Xe.QUEUE6?cs.AI_QUEUE6:e===Xe.QUEUE7?cs.AI_QUEUE7:e===Xe.QUEUE8?cs.AI_QUEUE8:e===Xe.QUEUE9?cs.AI_QUEUE9:e===Xe.QUEUE10?cs.AI_QUEUE10:e===Xe.QUEUE11?cs.AI_QUEUE11:e===Xe.QUEUE12?cs.AI_QUEUE12:e===Xe.QUEUE13?cs.AI_QUEUE13:e===Xe.QUEUE14?cs.AI_QUEUE14:e===Xe.QUEUE15?cs.AI_QUEUE15:e===Xe.QUEUE16?cs.AI_QUEUE16:e===Xe.QUEUE17?cs.AI_QUEUE17:e===Xe.QUEUE18?cs.AI_QUEUE18:e===Xe.QUEUE19?cs.AI_QUEUE19:e===Xe.QUEUE20?cs.AI_QUEUE20:null}huntAll(){if(this.nextHuntTick>Zl.currentTick)return;const e=Je.get(this.huntMode);if(e.type===je.OFF)return;if(e.nobodyNear===qe.PAUSEHUNT&&!Zl.getZoneGrid(this.level).isFlagged(ji.zone(this.x),ji.zone(this.z),5))return;if(!e.findKeepHunting&&null!==this.target)return;let t;if(t=e.type===je.PLAYER?this.huntPlayers(e):e.type===je.NPC?this.huntNpcs(e):e.type===je.OBJ?this.huntObjs(e):this.huntLocs(e),t.length>0){const i=t[Math.floor(Math.random()*t.length)];this.setInteraction(hs.SCRIPT,i,e.findNewMode)}this.nextHuntTick=Zl.currentTick+e.rate}huntPlayers(e){const t=ft.get(this.type),i=[],r=new ts(Zl.currentTick,this.level,this.x,this.z,this.huntrange,e.checkVis,-1,-1,je.PLAYER),s=e.findNewMode>=Xe.OPPLAYER1&&e.findNewMode<=Xe.OPPLAYER5;for(const n of r){if(!(n instanceof Do))throw new Error('[Npc] huntAll must be of type Player here.');if(s){const e=Math.abs(n.x-this.startX),i=Math.abs(n.z-this.startZ);if(Math.max(e,i)>t.maxrange+1)continue;if(e===t.maxrange+1&&i===t.maxrange+1)continue}else if(ji.distanceToSW(n,{x:this.startX,z:this.startZ})>t.maxrange+t.attackrange)continue;if((!e.checkAfk||!n.zonesAfk())&&((e.checkNotTooStrong!==Ke.OUTSIDE_WILDERNESS||n.isInWilderness()||!(n.combatLevel>2*t.vislevel))&&!(-1!==e.checkNotCombat&&n.getVar(e.checkNotCombat)+8>Zl.currentTick||-1!==e.checkNotCombatSelf&&this.getVar(e.checkNotCombatSelf)>=Zl.currentTick))){if(-1!==e.checkInv){let t=0;if(-1!==e.checkObj?t=n.invTotal(e.checkInv,e.checkObj):-1!==e.checkObjParam&&(t=n.invTotalParam(e.checkInv,e.checkObjParam)),te.checkInvMaxQuantity)continue}e.checkNotBusy&&n.busy()||i.push(n)}}return i}huntNpcs(e){return Array.from(new ts(Zl.currentTick,this.level,this.x,this.z,this.huntrange,e.checkVis,e.checkNpc,e.checkCategory,je.NPC))}huntObjs(e){return Array.from(new ts(Zl.currentTick,this.level,this.x,this.z,this.huntrange,e.checkVis,e.checkObj,e.checkCategory,je.OBJ))}huntLocs(e){return Array.from(new ts(Zl.currentTick,this.level,this.x,this.z,this.huntrange,e.checkVis,e.checkLoc,e.checkCategory,je.SCENERY))}playAnimation(t,i){t>=It.count||(-1==t||-1==this.animId||It.get(t).priority>It.get(this.animId).priority||0===It.get(this.animId).priority)&&(this.animId=t,this.animDelay=i,this.mask|=e.ANIM)}spotanim(t,i,r){this.graphicId=t,this.graphicHeight=i,this.graphicDelay=r,this.mask|=e.SPOTANIM}applyDamage(t,i){this.damageTaken=t,this.damageType=i;const r=this.levels[pt.HITPOINTS];r-t<=0?(this.levels[pt.HITPOINTS]=0,this.damageTaken=r):this.levels[pt.HITPOINTS]=r-t,this.mask|=e.DAMAGE}say(t){t&&(this.chat=t,this.mask|=e.SAY)}faceSquare(t,i){this.faceX=2*t+1,this.faceZ=2*i+1,this.orientationX=this.faceX,this.orientationZ=this.faceZ,this.mask|=e.FACE_COORD}changeType(t){this.type=t,this.mask|=e.CHANGE_TYPE,this.uid=t<<16|this.nid;const i=ft.get(t);this.setTimer(i.timer)}},Ml=class e{static OPEN=0;static BLOCKED=1;static BRIDGE=2;static ROOF=4;static WALL=8;static LOWMEMORY=16;static Y=4;static X=64;static Z=64;static MAPSQUARE=e.X*e.Y*e.Z;init(t){console.time('Loading game map');const i='data/pack/server/maps/',r=fs26.readdirSync(i).filter((e=>'m'===e[0]));for(let s=0;s(oe(),ee))),s=r.map((async r=>{console.log('init ',r);const[s,n]=r.substring(1).split('_').map(Number),a=s<<6,o=n<<6,[c,l,h,d]=await Promise.all([Oe.loadAsync(`${i}n${s}_${n}`),await Oe.loadAsync(`${i}o${s}_${n}`),await Oe.loadAsync(`${i}m${s}_${n}`),await Oe.loadAsync(`${i}l${s}_${n}`)]);this.decodeNpcs(c,a,o),this.decodeObjs(l,a,o,t);const u=new Int8Array(e.MAPSQUARE);this.decodeLands(u,h,a,o),this.decodeLocs(u,d,a,o,t)}));await Promise.all(s),console.timeEnd('Loading game map')}changeLandCollision(e,t,i,r){ri(e,t,i,r)}changeLocCollision(e,t,i,r,s,n,a,o,c,l){const h=_i(e);h===ki.WALL?ci(a,o,c,t,e,i,!1,l):h===ki.GROUND?t===Ui.NORTH||t===Ui.SOUTH?si(a,o,c,r,s,i,!1,l):si(a,o,c,s,r,i,!1,l):h===ki.GROUND_DECOR&&1===n&&ri(a,o,c,l)}changeNpcCollision(e,t,i,r,s){ni(t,i,r,e,s)}changePlayerCollision(e,t,i,r,s){ai(t,i,r,e,s)}changeRoofCollision(e,t,i,r){oi(e,t,i,r)}decodeNpcs(e,t,i){for(;e.available>0;){const{x:r,z:s,level:n}=this.unpackCoord(e.g2()),a=t+r,o=i+s,c=e.g1();for(let t=0;t0;){const{x:s,z:n,level:a}=this.unpackCoord(e.g2()),o=t+s,c=i+n,l=e.g1();for(let t=0;t>2,E=3&u,_=o+r,A=h+s;n.zone(_,A,p).addStaticLoc(new ss(p,_,A,g,m,Yr.RESPAWN,a,y,E)),f.blockwalk&&this.changeLocCollision(y,E,f.blockrange,m,g,f.active,_,A,p,!0)}o=i.gsmart()}}packCoord(e,t,i){return 63&t|(63&e)<<6|(3&i)<<12}unpackCoord(e){return{x:e>>6&63,z:63&e,level:e>>12&3}}},xl=class{count=0;rsl=new Int32Array(256);mem=new Int32Array(256);a=0;b=0;c=0;constructor(e=[0,0,0,0]){for(let t=0;t>>2,s+=t,i+=r,i^=r<<8,n+=i,r+=s,r^=s>>>16,a+=r,s+=n,s^=n<<10,o+=s,n+=a,n^=a>>>4,e+=n,a+=o,a^=o<<8,t+=a,o+=e,o^=e>>>9,i+=o,e+=t;for(let c=0;c<256;c+=8)e+=this.rsl[c],t+=this.rsl[c+1],i+=this.rsl[c+2],r+=this.rsl[c+3],s+=this.rsl[c+4],n+=this.rsl[c+5],a+=this.rsl[c+6],o+=this.rsl[c+7],e^=t<<11,r+=e,t+=i,t^=i>>>2,s+=t,i+=r,i^=r<<8,n+=i,r+=s,r^=s>>>16,a+=r,s+=n,s^=n<<10,o+=s,n+=a,n^=a>>>4,e+=n,a+=o,a^=o<<8,t+=a,o+=e,o^=e>>>9,i+=o,e+=t,this.mem[c]=e,this.mem[c+1]=t,this.mem[c+2]=i,this.mem[c+3]=r,this.mem[c+4]=s,this.mem[c+5]=n,this.mem[c+6]=a,this.mem[c+7]=o;for(let c=0;c<256;c+=8)e+=this.mem[c],t+=this.mem[c+1],i+=this.mem[c+2],r+=this.mem[c+3],s+=this.mem[c+4],n+=this.mem[c+5],a+=this.mem[c+6],o+=this.mem[c+7],e^=t<<11,r+=e,t+=i,t^=i>>>2,s+=t,i+=r,i^=r<<8,n+=i,r+=s,r^=s>>>16,a+=r,s+=n,s^=n<<10,o+=s,n+=a,n^=a>>>4,e+=n,a+=o,a^=o<<8,t+=a,o+=e,o^=e>>>9,i+=o,e+=t,this.mem[c]=e,this.mem[c+1]=t,this.mem[c+2]=i,this.mem[c+3]=r,this.mem[c+4]=s,this.mem[c+5]=n,this.mem[c+6]=a,this.mem[c+7]=o;this.isaac(),this.count=256}isaac(){this.c++,this.b+=this.c;for(let e=0;e<256;e++){const t=this.mem[e];switch(3&e){case 0:this.a^=this.a<<13;break;case 1:this.a^=this.a>>>6;break;case 2:this.a^=this.a<<2;break;case 3:this.a^=this.a>>>16}let i;this.a+=this.mem[e+128&255],this.mem[e]=i=this.mem[t>>>2&255]+this.a+this.b,this.rsl[e]=this.b=this.mem[i>>>8>>>2&255]+t}}nextInt(){return 0==this.count--&&(this.isaac(),this.count=255),this.rsl[this.count]}};function Fl(e){return'undefined'==typeof self?new NodeWorker(e):new Worker(e,{type:'module'})}var Hl=class{static SUCCESSFUL=Uint8Array.from([2]);static INVALID_USER_OR_PASS=Uint8Array.from([3]);static ACCOUNT_DISABLED=Uint8Array.from([4]);static LOGGED_IN=Uint8Array.from([5]);static SERVER_UPDATED=Uint8Array.from([6]);static WORLD_FULL=Uint8Array.from([7]);static LOGIN_SERVER_OFFLINE=Uint8Array.from([8]);static LOGIN_LIMIT_EXCEEDED=Uint8Array.from([9]);static UNABLE_TO_CONNECT=Uint8Array.from([10]);static LOGIN_REJECTED=Uint8Array.from([11]);static NEED_MEMBERS_ACCOUNT=Uint8Array.from([12]);static COULD_NOT_COMPLETE=Uint8Array.from([13]);static SERVER_UPDATING=Uint8Array.from([14]);static RECONNECTING=Uint8Array.from([15]);static LOGIN_ATTEMPTS_EXCEEDED=Uint8Array.from([16]);static STANDING_IN_MEMBERS=Uint8Array.from([17]);static STAFF_MOD_LEVEL=Uint8Array.from([18])},Vl=new Oe(new Uint8Array(36)),Gl=[],Wl=0;function Kl(e){if(!fs28.existsSync(e))return;const t=Oe.load(e),i=Oe.getcrc(t.data,0,t.data.length);Gl.push(i),Vl.p4(i)}function zl(){Gl=[],Vl.pos=0,Vl.p4(0),Kl('data/pack/client/title'),Kl('data/pack/client/config'),Kl('data/pack/client/interface'),Kl('data/pack/client/media'),Kl('data/pack/client/models'),Kl('data/pack/client/textures'),Kl('data/pack/client/wordenc'),Kl('data/pack/client/sounds'),Wl=Oe.getcrc(Vl.data,0,Vl.data.length)}async function jl(e){if(!(await fetch(e)).ok)return;const t=await Oe.loadAsync(e),i=Oe.getcrc(t.data,0,t.data.length);Gl.push(i),Vl.p4(i)}'undefined'==typeof self?fs28.existsSync('data/pack/client/')&&zl():(await fetch('data/pack/client/crc')).ok&&await async function(){Gl=[],Vl.pos=0,Vl.p4(0),await jl('data/pack/client/title'),await jl('data/pack/client/config'),await jl('data/pack/client/interface'),await jl('data/pack/client/media'),await jl('data/pack/client/models'),await jl('data/pack/client/textures'),await jl('data/pack/client/wordenc'),await jl('data/pack/client/sounds'),Wl=Oe.getcrc(Vl.data,0,Vl.data.length)}();var Yl=new class{loginThread=Fl('undefined'==typeof self?'./src/lostcity/server/LoginThread.ts':'LoginThread.js');loginRequests=new Map;logoutRequests=new Set;constructor(){const e=e=>{try{this.onMessage(e)}catch(e){console.error('Login Thread:',e)}};'undefined'==typeof self?this.loginThread instanceof NodeWorker2&&this.loginThread.on('message',e):this.loginThread instanceof Worker&&(this.loginThread.onmessage=e)}async readIn(e,t){const i=t.g1();if(16===i){const r=t.g1();if(t.available=2e3)return r.writeImmediate(Hl.WORLD_FULL),void r.close();if(Zl.shutdownTick>-1&&Zl.currentTick-Zl.shutdownTick>0)return r.writeImmediate(Hl.SERVER_UPDATING),void r.close();if(!vt.LOGIN_KEY)for(const e of Zl.players)if(e.username===a)return r.writeImmediate(Hl.LOGGED_IN),void r.close();r.decryptor=new xl(n);for(let e=0;e<4;e++)n[e]+=50;r.encryptor=new xl(n);const c=jc.load(a,new Oe(o),r);c.lowMemory=!!(1&s),c.webClient=r.isWebSocket(),Zl.addPlayer(c);break}case'logoutreply':{const{username:t}=e,i=Zl.getPlayerByUsername(t);i&&(Zl.getZone(i.x,i.z,i.level).leave(i),Zl.players.remove(i.pid),i.pid=-1,i.terminate(),this.logoutRequests.delete(i.username37));break}default:throw new Error('Unknown message type: '+e.type)}else switch(e.data.type){case'loginreply':{const{status:t,socket:i}=e.data,r=this.loginRequests.get(i);if(!r)return;if(this.loginRequests.delete(i),2!==t[0])return r.writeImmediate(t),void r.close();const{info:s,seed:n,username:a,save:o}=e.data;if(Zl.getTotalPlayers()>=2e3)return r.writeImmediate(Hl.WORLD_FULL),void r.close();if(Zl.shutdownTick>-1&&Zl.currentTick-Zl.shutdownTick>0)return r.writeImmediate(Hl.SERVER_UPDATING),void r.close();if(!vt.LOGIN_KEY)for(const e of Zl.players)if(e.username===a)return r.writeImmediate(Hl.LOGGED_IN),void r.close();r.decryptor=new xl(n);for(let e=0;e<4;e++)n[e]+=50;r.encryptor=new xl(n);const c=jc.load(a,new Oe(o),r);c.lowMemory=!!(1&s),c.webClient=!0,Zl.addPlayer(c);break}case'logoutreply':{const{username:t}=e.data,i=Zl.getPlayerByUsername(t);i&&(Zl.getZone(i.x,i.z,i.level).leave(i),Zl.players.remove(i.pid),i.pid=-1,i.terminate(),this.logoutRequests.delete(i.username37));break}default:throw new Error('Unknown message type: '+e.data.type)}}},ql=class extends Array{free;indexPadding;ids;lastUsedIndex=0;constructor(e,t){super(e),this.ids=new Int32Array(e).fill(-1),this.free=new Set(Array.from({length:e},((e,t)=>t))),this.indexPadding=t}next(e=!1,t=this.lastUsedIndex+1){const i=this.ids.length;for(let e=t;e(oe(),ee))),r=t;for(let e=0;e{'done'===e.type&&(this.devRebuilding=!1,this.reload())})),this.devThread.on('exit',(()=>{this.devRebuilding=!1,this.stopDevWatcher(),-1===this.shutdownTick&&(this.broadcastMes('Error while rebuilding - see console for more info.'),this.startDevWatcher())})),this.devWatcher=new Watcher('./data/src',{recursive:!0}),this.devWatcher.on('add',(e=>{if(e.endsWith('.pack'))return;const t=fs29.statSync(e);this.devMTime.set(e,t.mtimeMs)})),this.devWatcher.on('change',(e=>{if(e.endsWith('.pack'))return;const t=fs29.statSync(e),i=this.devMTime.get(e);i&&i>=t.mtimeMs||(this.devMTime.set(e,t.mtimeMs),this.devRebuilding||(console.log('dev:',path4.basename(e),'was edited'),this.devRebuilding=!0,this.broadcastMes('Rebuilding, please wait...'),this.devThread||(this.devThread=Fl('./src/lostcity/server/DevThread.ts')),this.devThread.postMessage({type:'pack'})))}))}stopDevWatcher(){this.devWatcher&&this.devWatcher.close(),this.devThread&&(this.devThread.terminate(),this.devThread=null)}rebootTimer(e){this.shutdownTick=this.currentTick+e,this.stopDevWatcher();for(const e of this.players)e.write(new vo(this.shutdownTick-this.currentTick))}async cycle(t=!0){const i=Date.now();this.processWorld(),await this.processClientsIn(),this.processNpcs(),await this.processPlayers(),await this.processLogouts(),await this.processLogins(),this.processZones(),this.processMovementDirections(),await this.processClientsOut(),this.processCleanup();const r=this.currentTick;r%e.LOGIN_PINGRATE==0&&this.heartbeat(),this.shutdownTick>-1&&r>=this.shutdownTick&&await this.processShutdown(),r%e.PLAYER_SAVERATE==0&&r>0&&this.savePlayers(),this.currentTick++,this.cycleStats[Gr.CYCLE]=Date.now()-i,this.lastCycleStats[Gr.CYCLE]=this.cycleStats[Gr.CYCLE],this.lastCycleStats[Gr.WORLD]=this.cycleStats[Gr.WORLD],this.lastCycleStats[Gr.CLIENT_IN]=this.cycleStats[Gr.CLIENT_IN],this.lastCycleStats[Gr.NPC]=this.cycleStats[Gr.NPC],this.lastCycleStats[Gr.PLAYER]=this.cycleStats[Gr.PLAYER],this.lastCycleStats[Gr.LOGOUT]=this.cycleStats[Gr.LOGOUT],this.lastCycleStats[Gr.LOGIN]=this.cycleStats[Gr.LOGIN],this.lastCycleStats[Gr.ZONE]=this.cycleStats[Gr.ZONE],this.lastCycleStats[Gr.CLIENT_OUT]=this.cycleStats[Gr.CLIENT_OUT],this.lastCycleStats[Gr.CLEANUP]=this.cycleStats[Gr.CLEANUP],this.lastCycleStats[Gr.BANDWIDTH_IN]=this.cycleStats[Gr.BANDWIDTH_IN],this.lastCycleStats[Gr.BANDWIDTH_OUT]=this.cycleStats[Gr.BANDWIDTH_OUT],t&&setTimeout(this.cycle.bind(this),this.tickRate-this.cycleStats[Gr.CYCLE]),vt.NODE_DEBUG_PROFILE&&(console.log(`tick ${this.currentTick} took ${this.cycleStats[Gr.CYCLE]}ms: ${this.getTotalPlayers()} players`),console.log(`${this.cycleStats[Gr.WORLD]} ms world | ${this.cycleStats[Gr.CLIENT_IN]} ms client in | ${this.cycleStats[Gr.NPC]} ms npcs | ${this.cycleStats[Gr.PLAYER]} ms players | ${this.cycleStats[Gr.LOGOUT]} ms logout | ${this.cycleStats[Gr.LOGIN]} ms login | ${this.cycleStats[Gr.ZONE]} ms zones | ${this.cycleStats[Gr.CLIENT_OUT]} ms client out | ${this.cycleStats[Gr.CLEANUP]} ms cleanup`),console.log('----'))}processWorld(){const t=Date.now(),i=this.currentTick;for(let e=this.queue.head();e;e=this.queue.next()){if(e.delay-- >0)continue;const t=e.script;try{const i=Dl.execute(t);e.unlink(),i===$t.SUSPENDED?t.activePlayer.activeScript=t:i===$t.NPC_SUSPENDED?t.activeNpc.activeScript=t:i===$t.WORLD_SUSPENDED&&this.enqueueScript(t,t.popInt())}catch(e){console.error(e)}}if(i%e.AFK_EVENTRATE==0)for(const e of this.players)e.afkEventReady=Math.random()<(e.zonesAfk()?.1666:.0833);for(const e of this.npcs)e.updateLifeCycle(i)&&(e.lifecycle===Yr.RESPAWN?this.addNpc(e,-1):e.lifecycle===Yr.DESPAWN&&this.removeNpc(e,-1));for(const e of this.npcs)e.checkLifeCycle(i)&&!e.delayed()&&-1!==e.huntMode&&e.huntAll();this.cycleStats[Gr.WORLD]=Date.now()-t}async processClientsIn(){const e=Date.now();this.cycleStats[Gr.BANDWIDTH_IN]=0;for(const e of this.players)if(Sl(e))try{e.decodeIn()}catch(t){console.error(t),await this.removePlayer(e)}for(const e of this.players)if(Sl(e)){if(e.userPath.length>0||e.opcalled){if(e.delayed()){e.unsetMapFlag();continue}if((!e.target||e.target instanceof ss||e.target instanceof $r)&&-1!==e.faceEntity&&(e.faceEntity=-1,e.mask|=Do.FACE_ENTITY),e.opcalled&&(0===e.userPath.length||!vt.NODE_CLIENT_ROUTEFINDER)){e.pathToTarget();continue}e.pathToMoveClick(e.userPath,!vt.NODE_CLIENT_ROUTEFINDER)}e.target instanceof Do&&(e.targetOp===cs.APPLAYER3||e.targetOp===cs.OPPLAYER3)&&(ji.distanceToSW(e,e.target)<=25?e.pathToPathingTarget():e.clearWaypoints())}this.cycleStats[Gr.CLIENT_IN]=Date.now()-e}processNpcs(){const e=Date.now();for(const e of this.npcs)if(e.checkLifeCycle(this.currentTick))try{if(e.delayed())continue;if(e.activeScript&&e.executeScript(e.activeScript),!e.checkLifeCycle(this.currentTick))continue;e.processTimers(),e.processQueue(),e.processNpcModes(),e.validateDistanceWalked()}catch(t){console.error(t),this.removeNpc(e,-1)}this.cycleStats[Gr.NPC]=Date.now()-e}async processPlayers(){const t=Date.now();for(const t of this.players)try{t.playtime++,t.activeScript&&!t.delayed()&&t.activeScript.execution===$t.SUSPENDED&&t.executeScript(t.activeScript,!0),t.processQueues(),t.processTimers(0),t.processTimers(1),t.processEngineQueue(),t.processInteraction(),t.mask&Do.EXACT_MOVE||t.validateDistanceWalked(),this.shutdownTick=e.TIMEOUT_IDLE_TICKS&&(t.logoutRequested=!0),t.logoutRequested&&t.closeModal()}catch(e){console.error(e),await this.removePlayer(t)}this.cycleStats[Gr.PLAYER]=Date.now()-t}async processLogouts(){const t=Date.now();for(const t of this.players)if(vt.NODE_SOCKET_TIMEOUT&&this.currentTick-t.lastResponse>=e.TIMEOUT_LOGOUT_TICKS&&(t.queue.clear(),t.weakQueue.clear(),t.engineQueue.clear(),t.clearInteraction(),t.closeModal(),t.unsetMapFlag(),t.logoutRequested=!0,t.setVar(Nt.LASTCOMBAT,0)),t.logoutRequested)if(null===t.queue.head()){const e=jt.getByTriggerSpecific(cs.LOGOUT,-1,-1);if(!e){console.error('LOGOUT TRIGGER IS BROKEN!');continue}const i=Dl.init(e,t);i.pointerAdd(Gt.ProtectedActivePlayer),Dl.execute(i);0===i.popInt()&&(t.logoutRequested=!1),t.logoutRequested&&await this.removePlayer(t)}else t.messageGame('[DEBUG]: Waiting for queue to empty before logging out.');this.cycleStats[Gr.LOGOUT]=Date.now()-t}async processLogins(){const e=Date.now();e:for(const e of this.newPlayers){for(const t of this.players)if(e.username===t.username){Sl(e)&&e.client&&(e.client.send(Hl.LOGGED_IN),e.client.close());continue e}let t;try{t=this.getNextPid(Sl(e)?e.client:null)}catch(t){Sl(e)&&(e.client?.send(Hl.WORLD_FULL),e.client?.close());continue}this.players.set(t,e),e.pid=t,e.uid=(Number(0x1fffffn&e.username37)<<11|e.pid)>>>0,e.tele=!0,this.getZone(e.x,e.z,e.level).enter(e),e.onLogin(),this.shutdownTick>-1&&e.write(new vo(this.shutdownTick-this.currentTick)),Sl(e)&&e.client&&(e.client.state=1,e.staffModLevel>=2?e.client.send(Hl.STAFF_MOD_LEVEL):e.client.send(Hl.SUCCESSFUL))}this.newPlayers.clear(),this.cycleStats[Gr.LOGIN]=Date.now()-e}processZones(){const e=Date.now(),t=this.currentTick,i=this.zonesTracking.get(t);if(void 0!==i)for(const e of i)e.tick(t);this.computeSharedEvents(),this.cycleStats[Gr.ZONE]=Date.now()-e}processMovementDirections(){for(const e of this.players)e.convertMovementDir();for(const e of this.npcs)e.convertMovementDir()}async processClientsOut(){const e=Date.now();this.cycleStats[Gr.BANDWIDTH_OUT]=0;for(const e of this.players)if(Sl(e))try{e.updateMap(),e.updatePlayers(),e.updateNpcs(),e.updateZones(),e.updateInvs(),e.updateStats(),e.updateAfkZones(),e.encodeOut()}catch(t){console.error(t),await this.removePlayer(e)}else e.highPriorityOut.clear(),e.lowPriorityOut.clear();this.cycleStats[Gr.CLIENT_OUT]=Date.now()-e}processCleanup(){const t=Date.now(),i=this.currentTick,r=this.zonesTracking.get(i);if(void 0!==r)for(const e of r)e.reset();this.zonesTracking.delete(i);for(const e of this.players){e.resetEntity(!1);for(const t of e.invs.values())t&&(t.update=!1)}for(const e of this.npcs)e.checkLifeCycle(i)&&e.resetEntity(!1);for(const t of this.invs){t.update=!1;const r=it.get(t.type);if(r.restock&&r.stockcount&&r.stockrate)for(let s=0;sr.stockcount[s]&&i%r.stockrate[s]==0||r.allstock&&!r.stockcount[s]&&i%e.INV_STOCKRATE==0)&&(t.remove(n?.id,1,s,!0),t.update=!0))}}this.cycleStats[Gr.CLEANUP]=Date.now()-t}heartbeat(){const e=[];for(const t of this.players)e.push(t.username37);Yl.loginThread.postMessage({type:'heartbeat',players:e})}async processShutdown(){const t=this.currentTick-this.shutdownTick;if(this.getTotalPlayers()){for(const e of this.players)e.logoutRequested=!0,Sl(e)&&(e.logout(),e.client&&t>2&&e.client.close());if(this.npcs.reset(),t>2){if(console.log('Super fast shutdown initiated...'),this.tickRate>e.SHUTDOWN_TICKRATE&&(this.tickRate=e.SHUTDOWN_TICKRATE),t>e.SHUTDOWN_TICKS){for(const e of this.players)await this.removePlayer(e);this.tickRate=e.NORMAL_TICKRATE}vt.NODE_PRODUCTION||process.exit(0)}}else process.exit(0)}savePlayers(){if('undefined'==typeof self)for(const e of this.players)e.save().release()}enqueueScript(e,t=0){this.queue.addTail(new vs(e,t+1))}getInventory(e){if(-1===e)return null;for(const t of this.invs)if(t.type===e)return t;const t=Xt.fromType(e);return this.invs.add(t),t}getZone(e,t,i){return this.zoneMap.zone(e,t,i)}getZoneIndex(e){return this.zoneMap.zoneByIndex(e)}getZoneGrid(e){return this.zoneMap.grid(e)}computeSharedEvents(){const e=new Set;for(const t of this.players)if(Sl(t))for(const i of t.buildArea.loadedZones)e.add(i);for(const t of e)this.getZoneIndex(t).computeShared()}addNpc(e,t){this.npcs.set(e.nid,e),e.x=e.startX,e.z=e.startZ;switch(this.getZone(e.x,e.z,e.level).enter(e),e.blockWalk){case lt.NPC:this.gameMap.changeNpcCollision(e.width,e.x,e.z,e.level,!0);break;case lt.ALL:this.gameMap.changeNpcCollision(e.width,e.x,e.z,e.level,!0),this.gameMap.changePlayerCollision(e.width,e.x,e.z,e.level,!0)}e.resetEntity(!0),e.playAnimation(-1,0),e.setLifeCycle(this.currentTick+t)}removeNpc(e,t){switch(this.getZone(e.x,e.z,e.level).leave(e),e.blockWalk){case lt.NPC:this.gameMap.changeNpcCollision(e.width,e.x,e.z,e.level,!1);break;case lt.ALL:this.gameMap.changeNpcCollision(e.width,e.x,e.z,e.level,!1),this.gameMap.changePlayerCollision(e.width,e.x,e.z,e.level,!1)}e.lifecycle===Yr.DESPAWN?this.npcs.remove(e.nid):e.lifecycle===Yr.RESPAWN&&e.setLifeCycle(this.currentTick+t)}getLoc(e,t,i,r){return this.getZone(e,t,i).getLoc(e,t,r)}getObj(e,t,i,r,s){return this.getZone(e,t,i).getObj(e,t,r,s)}trackZone(e,t){let i;const r=this.zonesTracking.get(e);i=r||new Set,i.add(t),this.zonesTracking.set(e,i)}addLoc(e,t){const i=at.get(e.type);i.blockwalk&&this.gameMap.changeLocCollision(e.shape,e.angle,i.blockrange,i.length,i.width,i.active,e.x,e.z,e.level,!0);const r=this.getZone(e.x,e.z,e.level);r.addLoc(e),e.setLifeCycle(this.currentTick+t),this.trackZone(this.currentTick+t,r),this.trackZone(this.currentTick,r)}mergeLoc(e,t,i,r,s,n,a,o){const c=this.getZone(e.x,e.z,e.level);c.mergeLoc(e,t,i,r,s,n,a,o),this.trackZone(this.currentTick,c)}animLoc(e,t){const i=this.getZone(e.x,e.z,e.level);i.animLoc(e,t),this.trackZone(this.currentTick,i)}removeLoc(e,t){const i=at.get(e.type);i.blockwalk&&this.gameMap.changeLocCollision(e.shape,e.angle,i.blockrange,i.length,i.width,i.active,e.x,e.z,e.level,!1);const r=this.getZone(e.x,e.z,e.level);r.removeLoc(e),e.setLifeCycle(this.currentTick+t),this.trackZone(this.currentTick+t,r),this.trackZone(this.currentTick,r)}addObj(e,t,i){const r=Tt.get(e.type),s=this.getObj(e.x,e.z,e.level,e.type,t);if(s&&s.lifecycle===Yr.DESPAWN&&e.lifecycle===Yr.DESPAWN){const i=e.count+s.count;if(r.stackable&&i<=Xt.STACK_LIMIT)return void this.changeObj(s,t,i)}const n=this.getZone(e.x,e.z,e.level);n.addObj(e,t),-1!==t&&r.tradeable?(e.setLifeCycle(this.currentTick+100),this.trackZone(this.currentTick+100,n),this.trackZone(this.currentTick,n),e.receiverId=t,e.reveal=i):(e.setLifeCycle(this.currentTick+i),this.trackZone(this.currentTick+i,n),this.trackZone(this.currentTick,n))}revealObj(e){const t=e.reveal,i=this.getZone(e.x,e.z,e.level);i.revealObj(e,e.receiverId),e.setLifeCycle(this.currentTick+t),this.trackZone(this.currentTick+t,i),this.trackZone(this.currentTick,i)}changeObj(e,t,i){const r=this.getZone(e.x,e.z,e.level);r.changeObj(e,t,e.count,i),this.trackZone(this.currentTick,r)}removeObj(e,t){const i=this.getZone(e.x,e.z,e.level);i.removeObj(e),e.setLifeCycle(this.currentTick+t),this.trackZone(this.currentTick+t,i),this.trackZone(this.currentTick,i)}animMap(e,t,i,r,s,n){const a=this.getZone(t,i,e);a.animMap(t,i,r,s,n),this.trackZone(this.currentTick,a)}mapProjAnim(e,t,i,r,s,n,a,o,c,l,h,d,u){const p=this.getZone(t,i,e);p.mapProjAnim(t,i,r,s,n,a,o,c,l,h,d,u),this.trackZone(this.currentTick,p)}async readIn(e,t){for(;t.available>0;){const i=t.pos;let r=t.g1();if(e.decryptor&&(r=r-e.decryptor.nextInt()&255,t.data[i]=r),void 0===ko.byId[r])return e.state=-1,void e.close();let s=ko.byId[r].length;if(-1===s?s=t.g1():-2===s&&(s=t.g2()),t.available5)continue;const n=new Uint8Array(t.pos-i),a=t.pos;t.pos=i,t.gdata(n,0,n.length),t.pos=a,e.in.set(n,e.inOffset),e.inOffset+=t.pos-i}}addPlayer(e){this.newPlayers.add(e)}async removePlayer(e){-1!==e.pid&&(e.playerLog('Logging out'),Sl(e)&&(e.logout(),e.client.close(),e.client=null),Yl.logout(e))}getPlayer(e){return this.players.get(e)}getPlayerByUid(e){const t=2047&e,i=e>>11&2097151,r=this.getPlayer(t);return r?Number(0x1fffffn&r.username37)!==i?null:r:null}getPlayerByUsername(e){const t=pe(e);for(const e of this.players)if(e.username37===t)return e;for(const e of this.newPlayers)if(e.username37===t)return e}getTotalPlayers(){return this.players.count}getTotalNpcs(){return this.npcs.count}getTotalZones(){return this.zoneMap.zoneCount()}getTotalLocs(){return this.zoneMap.locCount()}getTotalObjs(){return this.zoneMap.objCount()}getNpc(e){return this.npcs.get(e)}getNpcByUid(e){const t=65535&e,i=e>>16&65535,r=this.getNpc(t);return r&&r.type===i?r:null}getNextNid(){return this.npcs.next()}getNextPid(e=null){if(e){const t=e.remoteAddress.split('.'),i=parseInt(t[3])%20*100;return this.players.next(!0,i)}return this.players.next()}};await Zl.start(),(new class{socket=new Kc(null,'127.0.0.1');constructor(){}start(){const e=new Oe(new Uint8Array(8));e.p4(Math.floor(4294967295*Math.random())),e.p4(Math.floor(4294967295*Math.random())),this.socket.send(e.data),self.onmessage=async e=>{const t=new Oe(new Uint8Array(e.data));e.data.type;try{1===this.socket.state?await Zl.readIn(this.socket,t):await Yl.readIn(this.socket,t)}catch(e){this.socket.close()}}}}).start(); \ No newline at end of file +var e,t,i,r,s=Object.create,n=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,h=(e=>'undefined'!=typeof require?require:'undefined'!=typeof Proxy?new Proxy(e,{get:(e,t)=>('undefined'!=typeof require?require:e)[t]}):e)((function(e){if('undefined'!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')})),d=(e,t)=>function(){return t||(0,e[o(e)[0]])((t={exports:{}}).exports,t),t.exports},u=d({'node_modules/node-forge/lib/forge.js'(e,t){t.exports={options:{usePureJavaScript:!1}}}}),p=d({'node_modules/node-forge/lib/baseN.js'(e,t){var i={};t.exports=i;var r={};i.encode=function(e,t,i){if('string'!=typeof t)throw new TypeError('"alphabet" must be a string.');if(void 0!==i&&'number'!=typeof i)throw new TypeError('"maxline" must be a number.');var r='';if(e instanceof Uint8Array){var s=0,n=t.length,a=t.charAt(0),o=[0];for(s=0;s0;)o.push(l%n),l=l/n|0}for(s=0;0===e[s]&&s=0;--s)r+=t[o[s]]}else r=function(e,t){var i=0,r=t.length,s=t.charAt(0),n=[0];for(i=0;i0;)n.push(o%r),o=o/r|0}var c='';for(i=0;0===e.at(i)&&i=0;--i)c+=t[n[i]];return c}(e,t);if(i){var h=new RegExp('.{1,'+i+'}','g');r=r.match(h).join('\r\n')}return r},i.decode=function(e,t){if('string'!=typeof e)throw new TypeError('"input" must be a string.');if('string'!=typeof t)throw new TypeError('"alphabet" must be a string.');var i=r[t];if(!i){i=r[t]=[];for(var s=0;s>=8;for(;h>0;)o.push(255&h),h>>=8}for(var d=0;e[d]===a&&d15?(i=Date.now(),a(e)):(t.push(e),1===t.length&&n.setAttribute('a',r=!r))}}s.nextTick=s.setImmediate}(),s.isNodejs='undefined'!=typeof process&&process.versions&&process.versions.node,s.globalScope=s.isNodejs?global:'undefined'==typeof self?window:self,s.isArray=Array.isArray||function(e){return'[object Array]'===Object.prototype.toString.call(e)},s.isArrayBuffer=function(e){return'undefined'!=typeof ArrayBuffer&&e instanceof ArrayBuffer},s.isArrayBufferView=function(e){return e&&s.isArrayBuffer(e.buffer)&&void 0!==e.byteLength},s.ByteBuffer=a,s.ByteStringBuffer=a;s.ByteStringBuffer.prototype._optimizeConstructedString=function(e){this._constructedStringLength+=e,this._constructedStringLength>4096&&(this.data.substr(0,1),this._constructedStringLength=0)},s.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read},s.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0},s.ByteStringBuffer.prototype.putByte=function(e){return this.putBytes(String.fromCharCode(e))},s.ByteStringBuffer.prototype.fillWithByte=function(e,t){e=String.fromCharCode(e);for(var i=this.data;t>0;)1&t&&(i+=e),(t>>>=1)>0&&(e+=e);return this.data=i,this._optimizeConstructedString(t),this},s.ByteStringBuffer.prototype.putBytes=function(e){return this.data+=e,this._optimizeConstructedString(e.length),this},s.ByteStringBuffer.prototype.putString=function(e){return this.putBytes(s.encodeUtf8(e))},s.ByteStringBuffer.prototype.putInt16=function(e){return this.putBytes(String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},s.ByteStringBuffer.prototype.putInt24=function(e){return this.putBytes(String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},s.ByteStringBuffer.prototype.putInt32=function(e){return this.putBytes(String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},s.ByteStringBuffer.prototype.putInt16Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255))},s.ByteStringBuffer.prototype.putInt24Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255))},s.ByteStringBuffer.prototype.putInt32Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>24&255))},s.ByteStringBuffer.prototype.putInt=function(e,t){n(t);var i='';do{t-=8,i+=String.fromCharCode(e>>t&255)}while(t>0);return this.putBytes(i)},s.ByteStringBuffer.prototype.putSignedInt=function(e,t){return e<0&&(e+=2<0);return t},s.ByteStringBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),i=2<=i&&(t-=i<<1),t},s.ByteStringBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t='':(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},s.ByteStringBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},s.ByteStringBuffer.prototype.at=function(e){return this.data.charCodeAt(this.read+e)},s.ByteStringBuffer.prototype.setAt=function(e,t){return this.data=this.data.substr(0,this.read+e)+String.fromCharCode(t)+this.data.substr(this.read+e+1),this},s.ByteStringBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},s.ByteStringBuffer.prototype.copy=function(){var e=s.createBuffer(this.data);return e.read=this.read,e},s.ByteStringBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},s.ByteStringBuffer.prototype.clear=function(){return this.data='',this.read=0,this},s.ByteStringBuffer.prototype.truncate=function(e){var t=Math.max(0,this.length()-e);return this.data=this.data.substr(this.read,t),this.read=0,this},s.ByteStringBuffer.prototype.toHex=function(){for(var e='',t=this.read;t=e)return this;t=Math.max(t||this.growSize,e);var i=new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength),r=new Uint8Array(this.length()+t);return r.set(i),this.data=new DataView(r.buffer),this},s.DataBuffer.prototype.putByte=function(e){return this.accommodate(1),this.data.setUint8(this.write++,e),this},s.DataBuffer.prototype.fillWithByte=function(e,t){this.accommodate(t);for(var i=0;i>8&65535),this.data.setInt8(this.write,e>>16&255),this.write+=3,this},s.DataBuffer.prototype.putInt32=function(e){return this.accommodate(4),this.data.setInt32(this.write,e),this.write+=4,this},s.DataBuffer.prototype.putInt16Le=function(e){return this.accommodate(2),this.data.setInt16(this.write,e,!0),this.write+=2,this},s.DataBuffer.prototype.putInt24Le=function(e){return this.accommodate(3),this.data.setInt8(this.write,e>>16&255),this.data.setInt16(this.write,e>>8&65535,!0),this.write+=3,this},s.DataBuffer.prototype.putInt32Le=function(e){return this.accommodate(4),this.data.setInt32(this.write,e,!0),this.write+=4,this},s.DataBuffer.prototype.putInt=function(e,t){n(t),this.accommodate(t/8);do{t-=8,this.data.setInt8(this.write++,e>>t&255)}while(t>0);return this},s.DataBuffer.prototype.putSignedInt=function(e,t){return n(t),this.accommodate(t/8),e<0&&(e+=2<0);return t},s.DataBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),i=2<=i&&(t-=i<<1),t},s.DataBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t='':(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},s.DataBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},s.DataBuffer.prototype.at=function(e){return this.data.getUint8(this.read+e)},s.DataBuffer.prototype.setAt=function(e,t){return this.data.setUint8(e,t),this},s.DataBuffer.prototype.last=function(){return this.data.getUint8(this.write-1)},s.DataBuffer.prototype.copy=function(){return new s.DataBuffer(this)},s.DataBuffer.prototype.compact=function(){if(this.read>0){var e=new Uint8Array(this.data.buffer,this.read),t=new Uint8Array(e.byteLength);t.set(e),this.data=new DataView(t),this.write-=this.read,this.read=0}return this},s.DataBuffer.prototype.clear=function(){return this.data=new DataView(new ArrayBuffer(0)),this.read=this.write=0,this},s.DataBuffer.prototype.truncate=function(e){return this.write=Math.max(0,this.length()-e),this.read=Math.min(this.read,this.write),this},s.DataBuffer.prototype.toHex=function(){for(var e='',t=this.read;t0;)1&t&&(i+=e),(t>>>=1)>0&&(e+=e);return i},s.xorBytes=function(e,t,i){for(var r='',s='',n='',a=0,o=0;i>0;--i,++a)s=e.charCodeAt(a)^t.charCodeAt(a),o>=10&&(r+=n,n='',o=0),n+=String.fromCharCode(s),++o;return r+=n},s.hexToBytes=function(e){var t='',i=0;for(!0&e.length&&(i=1,t+=String.fromCharCode(parseInt(e[0],16)));i>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e)};var o='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',c=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],l='123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';s.encode64=function(e,t){for(var i,r,s,n='',a='',c=0;c>2),n+=o.charAt((3&i)<<4|r>>4),isNaN(r)?n+='==':(n+=o.charAt((15&r)<<2|s>>6),n+=isNaN(s)?'=':o.charAt(63&s)),t&&n.length>t&&(a+=n.substr(0,t)+'\r\n',n=n.substr(t));return a+=n},s.decode64=function(e){e=e.replace(/[^A-Za-z0-9\+\/\=]/g,'');for(var t,i,r,s,n='',a=0;a>4),64!==r&&(n+=String.fromCharCode((15&i)<<4|r>>2),64!==s&&(n+=String.fromCharCode((3&r)<<6|s)));return n},s.encodeUtf8=function(e){return unescape(encodeURIComponent(e))},s.decodeUtf8=function(e){return decodeURIComponent(escape(e))},s.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:r.encode,decode:r.decode}},s.binary.raw.encode=function(e){return String.fromCharCode.apply(null,e)},s.binary.raw.decode=function(e,t,i){var r=t;r||(r=new Uint8Array(e.length));for(var s=i=i||0,n=0;n>2),n+=o.charAt((3&i)<<4|r>>4),isNaN(r)?n+='==':(n+=o.charAt((15&r)<<2|s>>6),n+=isNaN(s)?'=':o.charAt(63&s)),t&&n.length>t&&(a+=n.substr(0,t)+'\r\n',n=n.substr(t));return a+=n},s.binary.base64.decode=function(e,t,i){var r,s,n,a,o=t;o||(o=new Uint8Array(3*Math.ceil(e.length/4))),e=e.replace(/[^A-Za-z0-9\+\/\=]/g,'');for(var l=0,h=i=i||0;l>4,64!==n&&(o[h++]=(15&s)<<4|n>>2,64!==a&&(o[h++]=(3&n)<<6|a));return t?h-i:o.subarray(0,h)},s.binary.base58.encode=function(e,t){return s.binary.baseN.encode(e,l,t)},s.binary.base58.decode=function(e,t){return s.binary.baseN.decode(e,l,t)},s.text={utf8:{},utf16:{}},s.text.utf8.encode=function(e,t,i){e=s.encodeUtf8(e);var r=t;r||(r=new Uint8Array(e.length));for(var n=i=i||0,a=0;a0&&n.push(i),a=r.lastIndex;var o=t[0][1];switch(o){case's':case'o':s');break;case'%':n.push('%');break;default:n.push('<%'+o+'?>')}}return n.push(e.substring(a)),n.join('')},s.formatNumber=function(e,t,i,r){var s=e,n=isNaN(t=Math.abs(t))?2:t,a=void 0===i?',':i,o=void 0===r?'.':r,c=s<0?'-':'',l=parseInt(s=Math.abs(+s||0).toFixed(n),10)+'',h=l.length>3?l.length%3:0;return c+(h?l.substr(0,h)+o:'')+l.substr(h).replace(/(\d{3})(?=\d)/g,'$1'+o)+(n?a+Math.abs(s-l).toFixed(n).slice(2):'')},s.formatSize=function(e){return e=e>=1073741824?s.formatNumber(e/1073741824,2,'.','')+' GiB':e>=1048576?s.formatNumber(e/1048576,2,'.','')+' MiB':e>=1024?s.formatNumber(e/1024,0)+' KiB':s.formatNumber(e,0)+' bytes'},s.bytesFromIP=function(e){return-1!==e.indexOf('.')?s.bytesFromIPv4(e):-1!==e.indexOf(':')?s.bytesFromIPv6(e):null},s.bytesFromIPv4=function(e){if(4!==(e=e.split('.')).length)return null;for(var t=s.createBuffer(),i=0;ii[r].end-i[r].start&&(r=i.length-1)):i.push({start:c,end:c})}t.push(a)}if(i.length>0){var l=i[r];l.end-l.start>0&&(t.splice(l.start,l.end-l.start+1,''),0===l.start&&t.unshift(''),7===l.end&&t.push(''))}return t.join(':')},s.estimateCores=function(e,t){if('function'==typeof e&&(t=e,e={}),e=e||{},'cores'in s&&!e.update)return t(null,s.cores);if('undefined'!=typeof navigator&&'hardwareConcurrency'in navigator&&navigator.hardwareConcurrency>0)return s.cores=navigator.hardwareConcurrency,t(null,s.cores);if('undefined'==typeof Worker)return s.cores=1,t(null,s.cores);if('undefined'==typeof Blob)return s.cores=2,t(null,s.cores);var i=URL.createObjectURL(new Blob(['(',function(){self.addEventListener('message',(function(e){for(var t=Date.now(),i=t+4;Date.now()o.st&&s.sts.st&&o.st4){var r=e;e=i.util.createBuffer();for(var s=0;s0))return!0;for(var r=0;r0))return!0;for(var r=0;r0)return!1;var i=e.length(),r=e.at(i-1);return!(r>this.blockSize<<2)&&(e.truncate(r),!0)},r.cbc=function(e){e=e||{},this.name='CBC',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},r.cbc.prototype.start=function(e){if(null===e.iv){if(!this._prev)throw new Error('Invalid IV parameter.');this._iv=this._prev.slice(0)}else{if(!('iv'in e))throw new Error('Invalid IV parameter.');this._iv=s(e.iv,this.blockSize),this._prev=this._iv.slice(0)}},r.cbc.prototype.encrypt=function(e,t,i){if(e.length()0))return!0;for(var r=0;r0))return!0;for(var r=0;r0)return!1;var i=e.length(),r=e.at(i-1);return!(r>this.blockSize<<2)&&(e.truncate(r),!0)},r.cfb=function(e){e=e||{},this.name='CFB',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},r.cfb.prototype.start=function(e){if(!('iv'in e))throw new Error('Invalid IV parameter.');this._iv=s(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},r.cfb.prototype.encrypt=function(e,t,i){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var s=0;s0&&(n=this.blockSize-n),this._partialOutput.clear();for(s=0;s0)e.read-=this.blockSize;else for(s=0;s0&&this._partialOutput.getBytes(this._partialBytes),n>0&&!i)return t.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=n,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},r.cfb.prototype.decrypt=function(e,t,i){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var s=0;s0&&(n=this.blockSize-n),this._partialOutput.clear();for(s=0;s0)e.read-=this.blockSize;else for(s=0;s0&&this._partialOutput.getBytes(this._partialBytes),n>0&&!i)return t.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=n,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},r.ofb=function(e){e=e||{},this.name='OFB',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},r.ofb.prototype.start=function(e){if(!('iv'in e))throw new Error('Invalid IV parameter.');this._iv=s(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},r.ofb.prototype.encrypt=function(e,t,i){var r=e.length();if(0===e.length())return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var s=0;s0&&(n=this.blockSize-n),this._partialOutput.clear();for(s=0;s0)e.read-=this.blockSize;else for(s=0;s0&&this._partialOutput.getBytes(this._partialBytes),n>0&&!i)return t.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=n,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},r.ofb.prototype.decrypt=r.ofb.prototype.encrypt,r.ctr=function(e){e=e||{},this.name='CTR',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},r.ctr.prototype.start=function(e){if(!('iv'in e))throw new Error('Invalid IV parameter.');this._iv=s(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},r.ctr.prototype.encrypt=function(e,t,i){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var s=0;s0&&(a=this.blockSize-a),this._partialOutput.clear();for(s=0;s0&&(e.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),a>0&&!i)return t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=a,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}n(this._inBlock)},r.ctr.prototype.decrypt=r.ctr.prototype.encrypt,r.gcm=function(e){e=e||{},this.name='GCM',this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0,this._R=3774873600},r.gcm.prototype.start=function(e){if(!('iv'in e))throw new Error('Invalid IV parameter.');var t,r=i.util.createBuffer(e.iv);if(this._cipherLength=0,t='additionalData'in e?i.util.createBuffer(e.additionalData):i.util.createBuffer(),this._tagLength='tagLength'in e?e.tagLength:128,this._tag=null,e.decrypt&&(this._tag=i.util.createBuffer(e.tag).getBytes(),this._tag.length!==this._tagLength/8))throw new Error('Authentication tag does not match tag length.');this._hashBlock=new Array(this._ints),this.tag=null,this._hashSubkey=new Array(this._ints),this.cipher.encrypt([0,0,0,0],this._hashSubkey),this.componentBits=4,this._m=this.generateHashTable(this._hashSubkey,this.componentBits);var s=r.length();if(12===s)this._j0=[r.getInt32(),r.getInt32(),r.getInt32(),1];else{for(this._j0=[0,0,0,0];r.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[r.getInt32(),r.getInt32(),r.getInt32(),r.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(a(8*s)))}this._inBlock=this._j0.slice(0),n(this._inBlock),this._partialBytes=0,t=i.util.createBuffer(t),this._aDataLength=a(8*t.length());var o=t.length()%this.blockSize;for(o&&t.fillWithByte(0,this.blockSize-o),this._s=[0,0,0,0];t.length()>0;)this._s=this.ghash(this._hashSubkey,this._s,[t.getInt32(),t.getInt32(),t.getInt32(),t.getInt32()])},r.gcm.prototype.encrypt=function(e,t,i){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize){for(var s=0;s0&&(a=this.blockSize-a),this._partialOutput.clear();for(s=0;s0&&this._partialOutput.getBytes(this._partialBytes),a>0&&!i)return e.read-=this.blockSize,t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=a,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}this._s=this.ghash(this._hashSubkey,this._s,this._outBlock),n(this._inBlock)},r.gcm.prototype.decrypt=function(e,t,i){var r=e.length();if(r0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),n(this._inBlock),this._hashBlock[0]=e.getInt32(),this._hashBlock[1]=e.getInt32(),this._hashBlock[2]=e.getInt32(),this._hashBlock[3]=e.getInt32(),this._s=this.ghash(this._hashSubkey,this._s,this._hashBlock);for(var s=0;s0;--r)t[r]=e[r]>>>1|(1&e[r-1])<<31;t[0]=e[0]>>>1,i&&(t[0]^=this._R)},r.gcm.prototype.tableMultiply=function(e){for(var t=[0,0,0,0],i=0;i<32;++i){var r=e[i/8|0]>>>4*(7-i%8)&15,s=this._m[i][r];t[0]^=s[0],t[1]^=s[1],t[2]^=s[2],t[3]^=s[3]}return t},r.gcm.prototype.ghash=function(e,t,i){return t[0]^=i[0],t[1]^=i[1],t[2]^=i[2],t[3]^=i[3],this.tableMultiply(t)},r.gcm.prototype.generateHashTable=function(e,t){for(var i=8/t,r=4*i,s=16*i,n=new Array(s),a=0;a>>1,s=new Array(i);s[r]=e.slice(0);for(var n=r>>>1;n>0;)this.pow(s[2*n],s[n]=[]),n>>=1;for(n=2;n>>=2;for(s=0;s>8^255&d^99,s[g]=d,n[d]=g,p=(u=e[d])<<24^d<<16^d<<8^d^u,f=((i=e[g])^(r=e[i])^(h=e[r]))<<24^(g^h)<<16^(g^r^h)<<8^g^i^h;for(var y=0;y<4;++y)o[y][g]=p,c[y][d]=f,p=p<<24|p>>>8,f=f<<24|f>>>8;0===g?g=m=1:(g=i^e[e[e[i^h]]],m^=e[e[m]])}}function d(e,t){for(var i,r=e.slice(0),n=1,o=r.length,l=4*(o+6+1),h=o;h>>16&255]<<24^s[i>>>8&255]<<16^s[255&i]<<8^s[i>>>24]^a[n]<<24,n++):o>6&&h%o==4&&(i=s[i>>>24]<<24^s[i>>>16&255]<<16^s[i>>>8&255]<<8^s[255&i]),r[h]=r[h-o]^i;if(t){for(var d,u=c[0],p=c[1],f=c[2],g=c[3],m=r.slice(0),y=(h=0,(l=r.length)-4);h>>24]]^p[s[d>>>16&255]]^f[s[d>>>8&255]]^g[s[255&d]];r=m}return r}function p(e,t,i,r){var a,l,h,d,u,p,f,g,m,y,E,_,A=e.length/4-1;r?(a=c[0],l=c[1],h=c[2],d=c[3],u=n):(a=o[0],l=o[1],h=o[2],d=o[3],u=s),p=t[0]^e[0],f=t[r?3:1]^e[1],g=t[2]^e[2],m=t[r?1:3]^e[3];for(var v=3,T=1;T>>24]^l[f>>>16&255]^h[g>>>8&255]^d[255&m]^e[++v],E=a[f>>>24]^l[g>>>16&255]^h[m>>>8&255]^d[255&p]^e[++v],_=a[g>>>24]^l[m>>>16&255]^h[p>>>8&255]^d[255&f]^e[++v],m=a[m>>>24]^l[p>>>16&255]^h[f>>>8&255]^d[255&g]^e[++v],p=y,f=E,g=_;i[0]=u[p>>>24]<<24^u[f>>>16&255]<<16^u[g>>>8&255]<<8^u[255&m]^e[++v],i[r?3:1]=u[f>>>24]<<24^u[g>>>16&255]<<16^u[m>>>8&255]<<8^u[255&p]^e[++v],i[2]=u[g>>>24]<<24^u[m>>>16&255]<<16^u[p>>>8&255]<<8^u[255&f]^e[++v],i[r?1:3]=u[m>>>24]<<24^u[p>>>16&255]<<16^u[f>>>8&255]<<8^u[255&g]^e[++v]}function y(e){var t,r='AES-'+((e=e||{}).mode||'CBC').toUpperCase(),s=(t=e.decrypt?i.cipher.createDecipher(r,e.key):i.cipher.createCipher(r,e.key)).start;return t.start=function(e,r){var n=null;r instanceof i.util.ByteBuffer&&(n=r,r={}),(r=r||{}).output=n,r.iv=e,s.call(t,r)},t}}}),E=d({'node_modules/node-forge/lib/oids.js'(e,t){var i=u();i.pki=i.pki||{};var r=t.exports=i.pki.oids=i.oids=i.oids||{};function s(e,t){r[e]=t,r[t]=e}function n(e,t){r[e]=t}s('1.2.840.113549.1.1.1','rsaEncryption'),s('1.2.840.113549.1.1.4','md5WithRSAEncryption'),s('1.2.840.113549.1.1.5','sha1WithRSAEncryption'),s('1.2.840.113549.1.1.7','RSAES-OAEP'),s('1.2.840.113549.1.1.8','mgf1'),s('1.2.840.113549.1.1.9','pSpecified'),s('1.2.840.113549.1.1.10','RSASSA-PSS'),s('1.2.840.113549.1.1.11','sha256WithRSAEncryption'),s('1.2.840.113549.1.1.12','sha384WithRSAEncryption'),s('1.2.840.113549.1.1.13','sha512WithRSAEncryption'),s('1.3.101.112','EdDSA25519'),s('1.2.840.10040.4.3','dsa-with-sha1'),s('1.3.14.3.2.7','desCBC'),s('1.3.14.3.2.26','sha1'),s('1.3.14.3.2.29','sha1WithRSASignature'),s('2.16.840.1.101.3.4.2.1','sha256'),s('2.16.840.1.101.3.4.2.2','sha384'),s('2.16.840.1.101.3.4.2.3','sha512'),s('2.16.840.1.101.3.4.2.4','sha224'),s('2.16.840.1.101.3.4.2.5','sha512-224'),s('2.16.840.1.101.3.4.2.6','sha512-256'),s('1.2.840.113549.2.2','md2'),s('1.2.840.113549.2.5','md5'),s('1.2.840.113549.1.7.1','data'),s('1.2.840.113549.1.7.2','signedData'),s('1.2.840.113549.1.7.3','envelopedData'),s('1.2.840.113549.1.7.4','signedAndEnvelopedData'),s('1.2.840.113549.1.7.5','digestedData'),s('1.2.840.113549.1.7.6','encryptedData'),s('1.2.840.113549.1.9.1','emailAddress'),s('1.2.840.113549.1.9.2','unstructuredName'),s('1.2.840.113549.1.9.3','contentType'),s('1.2.840.113549.1.9.4','messageDigest'),s('1.2.840.113549.1.9.5','signingTime'),s('1.2.840.113549.1.9.6','counterSignature'),s('1.2.840.113549.1.9.7','challengePassword'),s('1.2.840.113549.1.9.8','unstructuredAddress'),s('1.2.840.113549.1.9.14','extensionRequest'),s('1.2.840.113549.1.9.20','friendlyName'),s('1.2.840.113549.1.9.21','localKeyId'),s('1.2.840.113549.1.9.22.1','x509Certificate'),s('1.2.840.113549.1.12.10.1.1','keyBag'),s('1.2.840.113549.1.12.10.1.2','pkcs8ShroudedKeyBag'),s('1.2.840.113549.1.12.10.1.3','certBag'),s('1.2.840.113549.1.12.10.1.4','crlBag'),s('1.2.840.113549.1.12.10.1.5','secretBag'),s('1.2.840.113549.1.12.10.1.6','safeContentsBag'),s('1.2.840.113549.1.5.13','pkcs5PBES2'),s('1.2.840.113549.1.5.12','pkcs5PBKDF2'),s('1.2.840.113549.1.12.1.1','pbeWithSHAAnd128BitRC4'),s('1.2.840.113549.1.12.1.2','pbeWithSHAAnd40BitRC4'),s('1.2.840.113549.1.12.1.3','pbeWithSHAAnd3-KeyTripleDES-CBC'),s('1.2.840.113549.1.12.1.4','pbeWithSHAAnd2-KeyTripleDES-CBC'),s('1.2.840.113549.1.12.1.5','pbeWithSHAAnd128BitRC2-CBC'),s('1.2.840.113549.1.12.1.6','pbewithSHAAnd40BitRC2-CBC'),s('1.2.840.113549.2.7','hmacWithSHA1'),s('1.2.840.113549.2.8','hmacWithSHA224'),s('1.2.840.113549.2.9','hmacWithSHA256'),s('1.2.840.113549.2.10','hmacWithSHA384'),s('1.2.840.113549.2.11','hmacWithSHA512'),s('1.2.840.113549.3.7','des-EDE3-CBC'),s('2.16.840.1.101.3.4.1.2','aes128-CBC'),s('2.16.840.1.101.3.4.1.22','aes192-CBC'),s('2.16.840.1.101.3.4.1.42','aes256-CBC'),s('2.5.4.3','commonName'),s('2.5.4.4','surname'),s('2.5.4.5','serialNumber'),s('2.5.4.6','countryName'),s('2.5.4.7','localityName'),s('2.5.4.8','stateOrProvinceName'),s('2.5.4.9','streetAddress'),s('2.5.4.10','organizationName'),s('2.5.4.11','organizationalUnitName'),s('2.5.4.12','title'),s('2.5.4.13','description'),s('2.5.4.15','businessCategory'),s('2.5.4.17','postalCode'),s('2.5.4.42','givenName'),s('1.3.6.1.4.1.311.60.2.1.2','jurisdictionOfIncorporationStateOrProvinceName'),s('1.3.6.1.4.1.311.60.2.1.3','jurisdictionOfIncorporationCountryName'),s('2.16.840.1.113730.1.1','nsCertType'),s('2.16.840.1.113730.1.13','nsComment'),n('2.5.29.1','authorityKeyIdentifier'),n('2.5.29.2','keyAttributes'),n('2.5.29.3','certificatePolicies'),n('2.5.29.4','keyUsageRestriction'),n('2.5.29.5','policyMapping'),n('2.5.29.6','subtreesConstraint'),n('2.5.29.7','subjectAltName'),n('2.5.29.8','issuerAltName'),n('2.5.29.9','subjectDirectoryAttributes'),n('2.5.29.10','basicConstraints'),n('2.5.29.11','nameConstraints'),n('2.5.29.12','policyConstraints'),n('2.5.29.13','basicConstraints'),s('2.5.29.14','subjectKeyIdentifier'),s('2.5.29.15','keyUsage'),n('2.5.29.16','privateKeyUsagePeriod'),s('2.5.29.17','subjectAltName'),s('2.5.29.18','issuerAltName'),s('2.5.29.19','basicConstraints'),n('2.5.29.20','cRLNumber'),n('2.5.29.21','cRLReason'),n('2.5.29.22','expirationDate'),n('2.5.29.23','instructionCode'),n('2.5.29.24','invalidityDate'),n('2.5.29.25','cRLDistributionPoints'),n('2.5.29.26','issuingDistributionPoint'),n('2.5.29.27','deltaCRLIndicator'),n('2.5.29.28','issuingDistributionPoint'),n('2.5.29.29','certificateIssuer'),n('2.5.29.30','nameConstraints'),s('2.5.29.31','cRLDistributionPoints'),s('2.5.29.32','certificatePolicies'),n('2.5.29.33','policyMappings'),n('2.5.29.34','policyConstraints'),s('2.5.29.35','authorityKeyIdentifier'),n('2.5.29.36','policyConstraints'),s('2.5.29.37','extKeyUsage'),n('2.5.29.46','freshestCRL'),n('2.5.29.54','inhibitAnyPolicy'),s('1.3.6.1.4.1.11129.2.4.2','timestampList'),s('1.3.6.1.5.5.7.1.1','authorityInfoAccess'),s('1.3.6.1.5.5.7.3.1','serverAuth'),s('1.3.6.1.5.5.7.3.2','clientAuth'),s('1.3.6.1.5.5.7.3.3','codeSigning'),s('1.3.6.1.5.5.7.3.4','emailProtection'),s('1.3.6.1.5.5.7.3.8','timeStamping')}}),_=d({'node_modules/node-forge/lib/asn1.js'(e,t){var i=u();f(),E();var r=t.exports=i.asn1=i.asn1||{};function s(e,t,i){if(i>t){var r=new Error('Too few bytes to parse DER.');throw r.available=e.length(),r.remaining=t,r.requested=i,r}}r.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},r.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30},r.create=function(e,t,s,n,a){if(i.util.isArray(n)){for(var o=[],c=0;ct){if(a.strict){var f=new Error('Too few bytes to read ASN.1 value.');throw f.available=e.length(),f.remaining=t,f.requested=p,f}p=t}var g=!(32&~c);if(g)if(d=[],void 0===p)for(;;){if(s(e,t,2),e.bytes(2)===String.fromCharCode(0,0)){e.getBytes(2),t-=2;break}o=e.length(),d.push(n(e,t,i+1,a)),t-=o-e.length()}else for(;p>0;)o=e.length(),d.push(n(e,p,i+1,a)),t-=o-e.length(),p-=o-e.length();if(void 0===d&&l===r.Class.UNIVERSAL&&h===r.Type.BITSTRING&&(u=e.bytes(p)),void 0===d&&a.decodeBitStrings&&l===r.Class.UNIVERSAL&&h===r.Type.BITSTRING&&p>1){var m=e.read,y=t,E=0;if(h===r.Type.BITSTRING&&(s(e,t,1),E=e.getByte(),t--),0===E)try{o=e.length();var _=n(e,t,i+1,{strict:!0,decodeBitStrings:!0}),A=o-e.length();t-=A,h==r.Type.BITSTRING&&A++;var v=_.tagClass;A!==p||v!==r.Class.UNIVERSAL&&v!==r.Class.CONTEXT_SPECIFIC||(d=[_])}catch(e){}void 0===d&&(e.read=m,t=y)}if(void 0===d){if(void 0===p){if(a.strict)throw new Error('Non-constructed ASN.1 object of indefinite length.');p=t}if(h===r.Type.BMPSTRING)for(d='';p>0;p-=2)s(e,t,2),d+=String.fromCharCode(e.getInt16()),t-=2;else d=e.getBytes(p),t-=p}var T=void 0===u?null:{bitStringContents:u};return r.create(l,h,g,d,T)}r.fromDer=function(e,t){void 0===t&&(t={strict:!0,parseAllBytes:!0,decodeBitStrings:!0}),'boolean'==typeof t&&(t={strict:t,parseAllBytes:!0,decodeBitStrings:!0}),'strict'in t||(t.strict=!0),'parseAllBytes'in t||(t.parseAllBytes=!0),'decodeBitStrings'in t||(t.decodeBitStrings=!0),'string'==typeof e&&(e=i.util.createBuffer(e));var r=e.length(),s=n(e,e.length(),0,t);if(t.parseAllBytes&&0!==e.length()){var a=new Error('Unparsed DER bytes remain after ASN.1 parsing.');throw a.byteCount=r,a.remaining=e.length(),a}return s},r.toDer=function(e){var t=i.util.createBuffer(),s=e.tagClass|e.type,n=i.util.createBuffer(),a=!1;if('bitStringContents'in e&&(a=!0,e.original&&(a=r.equals(e,e.original))),a)n.putBytes(e.bitStringContents);else if(e.composed){e.constructed?s|=32:n.putByte(0);for(var o=0;o1)||(0!==e.value.charCodeAt(0)||128&e.value.charCodeAt(1))&&(255!==e.value.charCodeAt(0)||128&~e.value.charCodeAt(1))?n.putBytes(e.value):n.putBytes(e.value.substr(1));if(t.putByte(s),n.length()<=127)t.putByte(127&n.length());else{var c=n.length(),l='';do{l+=String.fromCharCode(255&c),c>>>=8}while(c>0);t.putByte(128|l.length);for(o=l.length-1;o>=0;--o)t.putByte(l.charCodeAt(o))}return t.putBuffer(n),t},r.oidToDer=function(e){var t,r,s,n,a=e.split('.'),o=i.util.createBuffer();o.putByte(40*parseInt(a[0],10)+parseInt(a[1],10));for(var c=2;c>>=7,t||(n|=128),r.push(n),t=!1}while(s>0);for(var l=r.length-1;l>=0;--l)o.putByte(r[l])}return o},r.derToOid=function(e){var t;'string'==typeof e&&(e=i.util.createBuffer(e));var r=e.getByte();t=Math.floor(r/40)+'.'+r%40;for(var s=0;e.length()>0;)s<<=7,128&(r=e.getByte())?s+=127&r:(t+='.'+(s+r),s=0);return t},r.utcTimeToDate=function(e){var t=new Date,i=parseInt(e.substr(0,2),10);i=i>=50?1900+i:2e3+i;var r=parseInt(e.substr(2,2),10)-1,s=parseInt(e.substr(4,2),10),n=parseInt(e.substr(6,2),10),a=parseInt(e.substr(8,2),10),o=0;if(e.length>11){var c=e.charAt(10),l=10;'+'!==c&&'-'!==c&&(o=parseInt(e.substr(10,2),10),l+=2)}if(t.setUTCFullYear(i,r,s),t.setUTCHours(n,a,o,0),l&&('+'===(c=e.charAt(l))||'-'===c)){var h=60*parseInt(e.substr(l+1,2),10)+parseInt(e.substr(l+4,2),10);h*=6e4,'+'===c?t.setTime(+t-h):t.setTime(+t+h)}return t},r.generalizedTimeToDate=function(e){var t=new Date,i=parseInt(e.substr(0,4),10),r=parseInt(e.substr(4,2),10)-1,s=parseInt(e.substr(6,2),10),n=parseInt(e.substr(8,2),10),a=parseInt(e.substr(10,2),10),o=parseInt(e.substr(12,2),10),c=0,l=0,h=!1;'Z'===e.charAt(e.length-1)&&(h=!0);var d=e.length-5,u=e.charAt(d);'+'!==u&&'-'!==u||(l=60*parseInt(e.substr(d+1,2),10)+parseInt(e.substr(d+4,2),10),l*=6e4,'+'===u&&(l*=-1),h=!0);return'.'===e.charAt(14)&&(c=1e3*parseFloat(e.substr(14),10)),h?(t.setUTCFullYear(i,r,s),t.setUTCHours(n,a,o,c),t.setTime(+t+l)):(t.setFullYear(i,r,s),t.setHours(n,a,o,c)),t},r.dateToUtcTime=function(e){if('string'==typeof e)return e;var t='',i=[];i.push((''+e.getUTCFullYear()).substr(2)),i.push(''+(e.getUTCMonth()+1)),i.push(''+e.getUTCDate()),i.push(''+e.getUTCHours()),i.push(''+e.getUTCMinutes()),i.push(''+e.getUTCSeconds());for(var r=0;r=-128&&e<128)return t.putSignedInt(e,8);if(e>=-32768&&e<32768)return t.putSignedInt(e,16);if(e>=-8388608&&e<8388608)return t.putSignedInt(e,24);if(e>=-2147483648&&e<2147483648)return t.putSignedInt(e,32);var r=new Error('Integer too large; max is 32-bits.');throw r.integer=e,r},r.derToInteger=function(e){'string'==typeof e&&(e=i.util.createBuffer(e));var t=8*e.length();if(t>32)throw new Error('Integer too large; max is 32-bits.');return e.getSignedInt(t)},r.validate=function(e,t,s,n){var a=!1;if(e.tagClass!==t.tagClass&&void 0!==t.tagClass||e.type!==t.type&&void 0!==t.type)n&&(e.tagClass!==t.tagClass&&n.push('['+t.name+'] Expected tag class "'+t.tagClass+'", got "'+e.tagClass+'"'),e.type!==t.type&&n.push('['+t.name+'] Expected type "'+t.type+'", got "'+e.type+'"'));else if(e.constructed===t.constructed||void 0===t.constructed){if(a=!0,t.value&&i.util.isArray(t.value))for(var o=0,c=0;a&&c0&&(n+='\n');for(var o='',c=0;c1?n+='0x'+i.util.bytesToHex(e.value.slice(1)):n+='(none)',e.value.length>0){var u=e.value.charCodeAt(0);1==u?n+=' (1 unused bit shown)':u>1&&(n+=' ('+u+' unused bits shown)')}}else if(e.type===r.Type.OCTETSTRING)a.test(e.value)||(n+='('+e.value+') '),n+='0x'+i.util.bytesToHex(e.value);else if(e.type===r.Type.UTF8)try{n+=i.util.decodeUtf8(e.value)}catch(t){if('URI malformed'!==t.message)throw t;n+='0x'+i.util.bytesToHex(e.value)+' (malformed UTF8)'}else e.type===r.Type.PRINTABLESTRING||e.type===r.Type.IA5String?n+=e.value:a.test(e.value)?n+='0x'+i.util.bytesToHex(e.value):0===e.value.length?n+='[null]':n+=e.value}return n}}}),A=d({'node_modules/node-forge/lib/md.js'(e,t){var i=u();t.exports=i.md=i.md||{},i.md.algorithms=i.md.algorithms||{}}}),v=d({'node_modules/node-forge/lib/hmac.js'(e,t){var i=u();A(),f(),(t.exports=i.hmac=i.hmac||{}).create=function(){var e=null,t=null,r=null,s=null,n={start:function(n,a){if(null!==n)if('string'==typeof n){if(!((n=n.toLowerCase())in i.md.algorithms))throw new Error('Unknown hash algorithm "'+n+'"');t=i.md.algorithms[n].create()}else t=n;if(null===a)a=e;else{if('string'==typeof a)a=i.util.createBuffer(a);else if(i.util.isArray(a)){var o=a;a=i.util.createBuffer();for(var c=0;ct.blockLength&&(t.start(),t.update(a.bytes()),a=t.digest()),r=i.util.createBuffer(),s=i.util.createBuffer(),l=a.length();for(c=0;c>>0,a>>>0];for(var o=h.fullMessageLength.length-1;o>=0;--o)h.fullMessageLength[o]+=a[1],a[1]=a[0]+(h.fullMessageLength[o]/4294967296>>>0),h.fullMessageLength[o]=h.fullMessageLength[o]>>>0,a[0]=a[1]/4294967296>>>0;return t.putBytes(s),l(e,r,t),(t.read>2048||0===t.length())&&t.compact(),h},h.digest=function(){var n=i.util.createBuffer();n.putBytes(t.bytes());var a=h.fullMessageLength[h.fullMessageLength.length-1]+h.messageLengthSize&h.blockLength-1;n.putBytes(s.substr(0,h.blockLength-a));for(var o,c=0,d=h.fullMessageLength.length-1;d>=0;--d)c=(o=8*h.fullMessageLength[d]+c)/4294967296>>>0,n.putInt32Le(o>>>0);var u={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3};l(u,r,n);var p=i.util.createBuffer();return p.putInt32Le(u.h0),p.putInt32Le(u.h1),p.putInt32Le(u.h2),p.putInt32Le(u.h3),p},h};var s=null,n=null,a=null,o=null,c=!1;function l(e,t,i){for(var r,s,c,l,h,d,u,p=i.length();p>=64;){for(s=e.h0,c=e.h1,l=e.h2,h=e.h3,u=0;u<16;++u)t[u]=i.getInt32Le(),r=s+(h^c&(l^h))+o[u]+t[u],s=h,h=l,l=c,c+=r<<(d=a[u])|r>>>32-d;for(;u<32;++u)r=s+(l^h&(c^l))+o[u]+t[n[u]],s=h,h=l,l=c,c+=r<<(d=a[u])|r>>>32-d;for(;u<48;++u)r=s+(c^l^h)+o[u]+t[n[u]],s=h,h=l,l=c,c+=r<<(d=a[u])|r>>>32-d;for(;u<64;++u)r=s+(l^(c|~h))+o[u]+t[n[u]],s=h,h=l,l=c,c+=r<<(d=a[u])|r>>>32-d;e.h0=e.h0+s|0,e.h1=e.h1+c|0,e.h2=e.h2+l|0,e.h3=e.h3+h|0,p-=64}}}}),C=d({'node_modules/node-forge/lib/pem.js'(e,t){var i=u();f();var r=t.exports=i.pem=i.pem||{};function s(e){for(var t=e.name+': ',i=[],r=function(e,t){return' '+t},s=0;s65&&-1!==a){var o=t[a];','===o?(++a,t=t.substr(0,a)+'\r\n '+t.substr(a)):t=t.substr(0,a)+'\r\n'+o+t.substr(a+1),n=s-a-1,a=-1,++s}else' '!==t[s]&&'\t'!==t[s]&&','!==t[s]||(a=s);return t}function n(e){return e.replace(/^\s+/,'')}r.encode=function(e,t){t=t||{};var r,n='-----BEGIN '+e.type+'-----\r\n';if(e.procType&&(n+=s(r={name:'Proc-Type',values:[String(e.procType.version),e.procType.type]})),e.contentDomain&&(n+=s(r={name:'Content-Domain',values:[e.contentDomain]})),e.dekInfo&&(r={name:'DEK-Info',values:[e.dekInfo.algorithm]},e.dekInfo.parameters&&r.values.push(e.dekInfo.parameters),n+=s(r)),e.headers)for(var a=0;a8?3:1,y=[],E=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],_=0,A=0;A>>4^T))<<4,v^=t=65535&((T^=t)>>>-16^v),v^=(t=858993459&(v>>>2^(T^=t<<-16)))<<2,v^=t=65535&((T^=t)>>>-16^v),v^=(t=1431655765&(v>>>1^(T^=t<<-16)))<<1,v^=t=16711935&((T^=t)>>>8^v),t=(v^=(t=1431655765&(v>>>1^(T^=t<<8)))<<1)<<8|(T^=t)>>>20&240,v=T<<24|T<<8&16711680|T>>>8&65280|T>>>24&240,T=t;for(var C=0;C>>26,T=T<<2|T>>>26):(v=v<<1|v>>>27,T=T<<1|T>>>27),T&=-15;var I=i[(v&=-15)>>>28]|r[v>>>24&15]|s[v>>>20&15]|n[v>>>16&15]|a[v>>>12&15]|o[v>>>8&15]|c[v>>>4&15],S=l[T>>>28]|h[T>>>24&15]|d[T>>>20&15]|u[T>>>16&15]|p[T>>>12&15]|f[T>>>8&15]|g[T>>>4&15];t=65535&(S>>>16^I),y[_++]=I^t,y[_++]=S^t<<16}}return y}(t),this._init=!0}},r('DES-ECB',i.cipher.modes.ecb),r('DES-CBC',i.cipher.modes.cbc),r('DES-CFB',i.cipher.modes.cfb),r('DES-OFB',i.cipher.modes.ofb),r('DES-CTR',i.cipher.modes.ctr),r('3DES-ECB',i.cipher.modes.ecb),r('3DES-CBC',i.cipher.modes.cbc),r('3DES-CFB',i.cipher.modes.cfb),r('3DES-OFB',i.cipher.modes.ofb),r('3DES-CTR',i.cipher.modes.ctr);var s=[16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756],n=[-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344],a=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584],o=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],c=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],l=[536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312],h=[2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],d=[268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696];function p(e,t,i,r){var u,p,f=32===e.length?3:9;u=3===f?r?[30,-2,-2]:[0,32,2]:r?[94,62,-2,32,64,2,30,-2,-2]:[0,32,2,62,30,-2,64,96,2];var g=t[0],m=t[1];g^=(p=252645135&(g>>>4^m))<<4,g^=(p=65535&(g>>>16^(m^=p)))<<16,g^=p=858993459&((m^=p)>>>2^g),g^=p=16711935&((m^=p<<2)>>>8^g),g=(g^=(p=1431655765&(g>>>1^(m^=p<<8)))<<1)<<1|g>>>31,m=(m^=p)<<1|m>>>31;for(var y=0;y>>4|m<<28)^e[A+1];p=g,g=m,m=p^(n[v>>>24&63]|o[v>>>16&63]|l[v>>>8&63]|d[63&v]|s[T>>>24&63]|a[T>>>16&63]|c[T>>>8&63]|h[63&T])}p=g,g=m,m=p}m=m>>>1|m<<31,m^=p=1431655765&((g=g>>>1|g<<31)>>>1^m),m^=(p=16711935&(m>>>8^(g^=p<<1)))<<8,m^=(p=858993459&(m>>>2^(g^=p)))<<2,m^=p=65535&((g^=p)>>>16^m),m^=p=252645135&((g^=p<<16)>>>4^m),g^=p<<4,i[0]=g,i[1]=m}function y(e){var t,r='DES-'+((e=e||{}).mode||'CBC').toUpperCase(),s=(t=e.decrypt?i.cipher.createDecipher(r,e.key):i.cipher.createCipher(r,e.key)).start;return t.start=function(e,r){var n=null;r instanceof i.util.ByteBuffer&&(n=r,r={}),(r=r||{}).output=n,r.iv=e,s.call(t,r)},t}}}),S=d({'node_modules/node-forge/lib/pbkdf2.js'(e,t){var i=u();v(),A(),f();var r,s=i.pkcs5=i.pkcs5||{};i.util.isNodejs&&!i.options.usePureJavaScript&&(r=h('crypto')),t.exports=i.pbkdf2=s.pbkdf2=function(e,t,s,n,a,o){if('function'==typeof a&&(o=a,a=null),i.util.isNodejs&&!i.options.usePureJavaScript&&r.pbkdf2&&(null===a||'object'!=typeof a)&&(r.pbkdf2Sync.length>4||!a||'sha1'===a))return'string'!=typeof a&&(a='sha1'),e=Buffer.from(e,'binary'),t=Buffer.from(t,'binary'),o?4===r.pbkdf2Sync.length?r.pbkdf2(e,t,s,n,(function(e,t){if(e)return o(e);o(null,t.toString('binary'))})):r.pbkdf2(e,t,s,n,a,(function(e,t){if(e)return o(e);o(null,t.toString('binary'))})):4===r.pbkdf2Sync.length?r.pbkdf2Sync(e,t,s,n).toString('binary'):r.pbkdf2Sync(e,t,s,n,a).toString('binary');if(null==a&&(a='sha1'),'string'==typeof a){if(!(a in i.md.algorithms))throw new Error('Unknown hash algorithm: '+a);a=i.md[a].create()}var c=a.digestLength;if(n>4294967295*c){var l=new Error('Derived key is too long.');if(o)return o(l);throw l}var h=Math.ceil(n/c),d=n-(h-1)*c,u=i.hmac.create();u.start(a,e);var p,f,g,m='';if(!o){for(var y=1;y<=h;++y){u.start(null,null),u.update(t),u.update(i.util.int32ToBytes(y)),p=g=u.digest().getBytes();for(var E=2;E<=s;++E)u.start(null,null),u.update(g),f=u.digest().getBytes(),p=i.util.xorBytes(p,f,c),g=f;m+=yh)return o(null,m);u.start(null,null),u.update(t),u.update(i.util.int32ToBytes(y)),p=g=u.digest().getBytes(),E=2,A()}function A(){if(E<=s)return u.start(null,null),u.update(g),f=u.digest().getBytes(),p=i.util.xorBytes(p,f,c),g=f,++E,i.util.setImmediate(A);m+=y>>0,a>>>0];for(var l=c.fullMessageLength.length-1;l>=0;--l)c.fullMessageLength[l]+=a[1],a[1]=a[0]+(c.fullMessageLength[l]/4294967296>>>0),c.fullMessageLength[l]=c.fullMessageLength[l]>>>0,a[0]=a[1]/4294967296>>>0;return t.putBytes(s),o(e,r,t),(t.read>2048||0===t.length())&&t.compact(),c},c.digest=function(){var n=i.util.createBuffer();n.putBytes(t.bytes());var a,l=c.fullMessageLength[c.fullMessageLength.length-1]+c.messageLengthSize&c.blockLength-1;n.putBytes(s.substr(0,c.blockLength-l));for(var h=8*c.fullMessageLength[0],d=0;d>>0,n.putInt32(h>>>0),h=a>>>0;n.putInt32(h);var u={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4,h5:e.h5,h6:e.h6,h7:e.h7};o(u,r,n);var p=i.util.createBuffer();return p.putInt32(u.h0),p.putInt32(u.h1),p.putInt32(u.h2),p.putInt32(u.h3),p.putInt32(u.h4),p.putInt32(u.h5),p.putInt32(u.h6),p.putInt32(u.h7),p},c};var s=null,n=!1,a=null;function o(e,t,i){for(var r,s,n,o,c,l,h,d,u,p,f,g,m,y=i.length();y>=64;){for(c=0;c<16;++c)t[c]=i.getInt32();for(;c<64;++c)r=((r=t[c-2])>>>17|r<<15)^(r>>>19|r<<13)^r>>>10,s=((s=t[c-15])>>>7|s<<25)^(s>>>18|s<<14)^s>>>3,t[c]=r+t[c-7]+s+t[c-16]|0;for(l=e.h0,h=e.h1,d=e.h2,u=e.h3,p=e.h4,f=e.h5,g=e.h6,m=e.h7,c=0;c<64;++c)n=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),o=l&h|d&(l^h),r=m+((p>>>6|p<<26)^(p>>>11|p<<21)^(p>>>25|p<<7))+(g^p&(f^g))+a[c]+t[c],m=g,g=f,f=p,p=u+r>>>0,u=d,d=h,h=l,l=r+(s=n+o)>>>0;e.h0=e.h0+l|0,e.h1=e.h1+h|0,e.h2=e.h2+d|0,e.h3=e.h3+u|0,e.h4=e.h4+p|0,e.h5=e.h5+f|0,e.h6=e.h6+g|0,e.h7=e.h7+m|0,y-=64}}}}),N=d({'node_modules/node-forge/lib/prng.js'(e,t){var i=u();f();var r=null;!i.util.isNodejs||i.options.usePureJavaScript||process.versions['node-webkit']||(r=h('crypto')),(t.exports=i.prng=i.prng||{}).create=function(e){for(var t={plugin:e,key:null,seed:null,time:null,reseeds:0,generated:0,keyBytes:''},s=e.md,n=new Array(32),a=0;a<32;++a)n[a]=s.create();function o(){if(t.pools[0].messageLength>=32)return c();var e=32-t.pools[0].messageLength<<5;t.collect(t.seedFileSync(e)),c()}function c(){t.reseeds=4294967295===t.reseeds?0:t.reseeds+1;var e=t.plugin.md.create();e.update(t.keyBytes);for(var i=1,r=0;r<32;++r)t.reseeds%i==0&&(e.update(t.pools[r].digest().getBytes()),t.pools[r].start()),i<<=1;t.keyBytes=e.digest().getBytes(),e.start(),e.update(t.keyBytes);var s=e.digest().getBytes();t.key=t.plugin.formatKey(t.keyBytes),t.seed=t.plugin.formatSeed(s),t.generated=0}function l(e){var t=null,r=i.util.globalScope,s=r.crypto||r.msCrypto;s&&s.getRandomValues&&(t=function(e){return s.getRandomValues(e)});var n=i.util.createBuffer();if(t)for(;n.length()>16)))<<16,u=4294967295&(h=(2147483647&(h+=l>>15))+(h>>31));for(c=0;c<3;++c)d=u>>>(c<<3),d^=Math.floor(256*Math.random()),n.putByte(255&d)}return n.getBytes(e)}return t.pools=n,t.pool=0,t.generate=function(e,r){if(!r)return t.generateSync(e);var s=t.plugin.cipher,n=t.plugin.increment,a=t.plugin.formatKey,o=t.plugin.formatSeed,l=i.util.createBuffer();t.key=null,function h(d){if(d)return r(d);if(l.length()>=e)return r(null,l.getBytes(e));t.generated>1048575&&(t.key=null);if(null===t.key)return i.util.nextTick((function(){!function(e){if(t.pools[0].messageLength>=32)return c(),e();var i=32-t.pools[0].messageLength<<5;t.seedFile(i,(function(i,r){if(i)return e(i);t.collect(r),c(),e()}))}(h)}));var u=s(t.key,t.seed);t.generated+=u.length,l.putBytes(u),t.key=a(s(t.key,n(t.seed))),t.seed=o(s(t.key,t.seed)),i.util.setImmediate(h)}()},t.generateSync=function(e){var r=t.plugin.cipher,s=t.plugin.increment,n=t.plugin.formatKey,a=t.plugin.formatSeed;t.key=null;for(var c=i.util.createBuffer();c.length()1048575&&(t.key=null),null===t.key&&o();var l=r(t.key,t.seed);t.generated+=l.length,c.putBytes(l),t.key=n(r(t.key,s(t.seed))),t.seed=a(r(t.key,t.seed))}return c.getBytes(e)},r?(t.seedFile=function(e,t){r.randomBytes(e,(function(e,i){if(e)return t(e);t(null,i.toString())}))},t.seedFileSync=function(e){return r.randomBytes(e).toString()}):(t.seedFile=function(e,t){try{t(null,l(e))}catch(e){t(e)}},t.seedFileSync=l),t.collect=function(e){for(var i=e.length,r=0;r>s&255);t.collect(r)},t.registerWorker=function(e){if(e===self)t.seedFile=function(e,t){self.addEventListener('message',(function e(i){var r=i.data;r.forge&&r.forge.prng&&(self.removeEventListener('message',e),t(r.forge.prng.err,r.forge.prng.bytes))})),self.postMessage({forge:{prng:{needed:e}}})};else{e.addEventListener('message',(function(i){var r=i.data;r.forge&&r.forge.prng&&t.seedFile(r.forge.prng.needed,(function(t,i){e.postMessage({forge:{prng:{err:t,bytes:i}}})}))}))}},t}}}),L=d({'node_modules/node-forge/lib/random.js'(e,t){var i=u();y(),O(),N(),f(),i.random&&i.random.getBytes?t.exports=i.random:function(e){var r={},s=new Array(4),n=i.util.createBuffer();function a(){var e=i.prng.create(r);return e.getBytes=function(t,i){return e.generate(t,i)},e.getBytesSync=function(t){return e.generate(t)},e}r.formatKey=function(e){var t=i.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),i.aes._expandKey(e,!1)},r.formatSeed=function(e){var t=i.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),e},r.cipher=function(e,t){return i.aes._updateBlock(e,t,s,!1),n.putInt32(s[0]),n.putInt32(s[1]),n.putInt32(s[2]),n.putInt32(s[3]),n.getBytes()},r.increment=function(e){return++e[3],e},r.md=i.md.sha256;var o=a(),c=null,l=i.util.globalScope,h=l.crypto||l.msCrypto;if(h&&h.getRandomValues&&(c=function(e){return h.getRandomValues(e)}),i.options.usePureJavaScript||!i.util.isNodejs&&!c){if('undefined'==typeof window||window.document,o.collectInt(+new Date,32),'undefined'!=typeof navigator){var d='';for(var u in navigator)try{'string'==typeof navigator[u]&&(d+=navigator[u])}catch(e){}o.collect(d),d=null}e&&(e().mousemove((function(e){o.collectInt(e.clientX,16),o.collectInt(e.clientY,16)})),e().keypress((function(e){o.collectInt(e.charCode,8)})))}if(i.random)for(var u in o)i.random[u]=o[u];else i.random=o;i.random.createInstance=a,t.exports=i.random}('undefined'!=typeof jQuery?jQuery:null)}}),P=d({'node_modules/node-forge/lib/rc2.js'(e,t){var i=u();f();var r=[217,120,249,196,25,221,181,237,40,233,253,121,74,160,216,157,198,126,55,131,43,118,83,142,98,76,100,136,68,139,251,162,23,154,89,245,135,179,79,19,97,69,109,141,9,129,125,50,189,143,64,235,134,183,123,11,240,149,33,34,92,107,78,130,84,214,101,147,206,96,178,28,115,86,192,20,167,140,241,220,18,117,202,31,59,190,228,209,66,61,212,48,163,60,182,38,111,191,14,218,70,105,7,87,39,242,29,155,188,148,67,3,248,17,199,246,144,239,62,231,6,195,213,47,200,102,30,215,8,232,234,222,128,82,238,247,132,170,114,172,53,77,106,42,150,26,210,113,90,21,73,116,75,159,208,94,4,24,164,236,194,224,65,110,15,81,203,204,36,145,175,80,161,244,112,57,153,124,58,133,35,184,180,122,252,2,54,91,37,85,151,49,45,93,250,152,227,138,146,174,5,223,41,16,103,108,186,201,211,0,230,207,225,158,168,44,99,22,1,63,88,226,137,169,13,56,52,27,171,51,255,176,187,72,12,95,185,177,205,46,197,243,219,71,229,165,156,119,10,166,32,104,254,127,193,173],s=[1,2,3,5],n=function(e,t){return e<>16-t},a=function(e,t){return(65535&e)>>t|e<<16-t&65535};t.exports=i.rc2=i.rc2||{},i.rc2.expandKey=function(e,t){'string'==typeof e&&(e=i.util.createBuffer(e)),t=t||128;var s,n=e,a=e.length(),o=t,c=Math.ceil(o/8),l=255>>(7&o);for(s=a;s<128;s++)n.putByte(r[n.at(s-1)+n.at(s-a)&255]);for(n.setAt(128-c,r[n.at(128-c)&l]),s=127-c;s>=0;s--)n.setAt(s,r[n.at(s+1)^n.at(s+c)]);return n};var o=function(e,t,r){var o,c,l,h,d=!1,u=null,p=null,f=null,g=[];for(e=i.rc2.expandKey(e,t),l=0;l<64;l++)g.push(e.getInt16Le());r?(o=function(e){for(l=0;l<4;l++)e[l]+=g[h]+(e[(l+3)%4]&e[(l+2)%4])+(~e[(l+3)%4]&e[(l+1)%4]),e[l]=n(e[l],s[l]),h++},c=function(e){for(l=0;l<4;l++)e[l]+=g[63&e[(l+3)%4]]}):(o=function(e){for(l=3;l>=0;l--)e[l]=a(e[l],s[l]),e[l]-=g[h]+(e[(l+3)%4]&e[(l+2)%4])+(~e[(l+3)%4]&e[(l+1)%4]),h--},c=function(e){for(l=3;l>=0;l--)e[l]-=g[63&e[(l+3)%4]]});var m=function(e){var t=[];for(l=0;l<4;l++){var i=u.getInt16Le();null!==f&&(r?i^=f.getInt16Le():f.putInt16Le(i)),t.push(65535&i)}h=r?0:63;for(var s=0;s=8;)m([[5,o],[1,c],[6,o],[1,c],[5,o]])},finish:function(e){var t=!0;if(r)if(e)t=e(8,u,!r);else{var i=8===u.length()?8:8-u.length();u.fillWithByte(i,i)}if(t&&(d=!0,y.update()),!r&&(t=0===u.length()))if(e)t=e(8,p,!r);else{var s=p.length(),n=p.at(s-1);n>s?t=!1:p.truncate(n)}return t}}};i.rc2.startEncrypting=function(e,t,r){var s=i.rc2.createEncryptionCipher(e,128);return s.start(t,r),s},i.rc2.createEncryptionCipher=function(e,t){return o(e,t,!0)},i.rc2.startDecrypting=function(e,t,r){var s=i.rc2.createDecryptionCipher(e,128);return s.start(t,r),s},i.rc2.createDecryptionCipher=function(e,t){return o(e,t,!1)}}}),w=d({'node_modules/node-forge/lib/jsbn.js'(e,t){var i,r=u();t.exports=r.jsbn=r.jsbn||{};function s(e,t,i){this.data=[],null!=e&&('number'==typeof e?this.fromNumber(e,t,i):null==t&&'string'!=typeof e?this.fromString(e,256):this.fromString(e,t))}function n(){return new s(null)}function a(e,t,i,r,s,n){for(var a=16383&t,o=t>>14;--n>=0;){var c=16383&this.data[e],l=this.data[e++]>>14,h=o*c+l*a;s=((c=a*c+((16383&h)<<14)+i.data[r]+s)>>28)+(h>>14)+o*l,i.data[r++]=268435455&c}return s}r.jsbn.BigInteger=s,'undefined'==typeof navigator?(s.prototype.am=a,i=28):'Microsoft Internet Explorer'==navigator.appName?(s.prototype.am=function(e,t,i,r,s,n){for(var a=32767&t,o=t>>15;--n>=0;){var c=32767&this.data[e],l=this.data[e++]>>15,h=o*c+l*a;s=((c=a*c+((32767&h)<<15)+i.data[r]+(1073741823&s))>>>30)+(h>>>15)+o*l+(s>>>30),i.data[r++]=1073741823&c}return s},i=30):'Netscape'!=navigator.appName?(s.prototype.am=function(e,t,i,r,s,n){for(;--n>=0;){var a=t*this.data[e++]+i.data[r]+s;s=Math.floor(a/67108864),i.data[r++]=67108863&a}return s},i=26):(s.prototype.am=a,i=28),s.prototype.DB=i,s.prototype.DM=(1<>>16)&&(e=t,i+=16),0!=(t=e>>8)&&(e=t,i+=8),0!=(t=e>>4)&&(e=t,i+=4),0!=(t=e>>2)&&(e=t,i+=2),0!=(t=e>>1)&&(e=t,i+=1),i}function g(e){this.m=e}function m(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,t+=16),255&e||(e>>=8,t+=8),15&e||(e>>=4,t+=4),3&e||(e>>=2,t+=2),1&e||++t,t}function T(e){for(var t=0;0!=e;)e&=e-1,++t;return t}function C(){}function I(e){return e}function S(e){this.r2=n(),this.q3=n(),s.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}g.prototype.convert=function(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e},g.prototype.revert=function(e){return e},g.prototype.reduce=function(e){e.divRemTo(this.m,null,e)},g.prototype.mulTo=function(e,t,i){e.multiplyTo(t,i),this.reduce(i)},g.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},m.prototype.convert=function(e){var t=n();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(s.ZERO)>0&&this.m.subTo(t,t),t},m.prototype.revert=function(e){var t=n();return e.copyTo(t),this.reduce(t),t},m.prototype.reduce=function(e){for(;e.t<=this.mt2;)e.data[e.t++]=0;for(var t=0;t>15)*this.mpl&this.um)<<15)&e.DM;for(i=t+this.m.t,e.data[i]+=this.m.am(0,r,e,t,0,this.m.t);e.data[i]>=e.DV;)e.data[i]-=e.DV,e.data[++i]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},m.prototype.mulTo=function(e,t,i){e.multiplyTo(t,i),this.reduce(i)},m.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},s.prototype.copyTo=function(e){for(var t=this.t-1;t>=0;--t)e.data[t]=this.data[t];e.t=this.t,e.s=this.s},s.prototype.fromInt=function(e){this.t=1,this.s=e<0?-1:0,e>0?this.data[0]=e:e<-1?this.data[0]=e+this.DV:this.t=0},s.prototype.fromString=function(e,t){var i;if(16==t)i=4;else if(8==t)i=3;else if(256==t)i=8;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return void this.fromRadix(e,t);i=2}this.t=0,this.s=0;for(var r=e.length,n=!1,a=0;--r>=0;){var o=8==i?255&e[r]:d(e,r);o<0?'-'==e.charAt(r)&&(n=!0):(n=!1,0==a?this.data[this.t++]=o:a+i>this.DB?(this.data[this.t-1]|=(o&(1<>this.DB-a):this.data[this.t-1]|=o<=this.DB&&(a-=this.DB))}8==i&&128&e[0]&&(this.s=-1,a>0&&(this.data[this.t-1]|=(1<0&&this.data[this.t-1]==e;)--this.t},s.prototype.dlShiftTo=function(e,t){var i;for(i=this.t-1;i>=0;--i)t.data[i+e]=this.data[i];for(i=e-1;i>=0;--i)t.data[i]=0;t.t=this.t+e,t.s=this.s},s.prototype.drShiftTo=function(e,t){for(var i=e;i=0;--i)t.data[i+a+1]=this.data[i]>>s|o,o=(this.data[i]&n)<=0;--i)t.data[i]=0;t.data[a]=o,t.t=this.t+a+1,t.s=this.s,t.clamp()},s.prototype.rShiftTo=function(e,t){t.s=this.s;var i=Math.floor(e/this.DB);if(i>=this.t)t.t=0;else{var r=e%this.DB,s=this.DB-r,n=(1<>r;for(var a=i+1;a>r;r>0&&(t.data[this.t-i-1]|=(this.s&n)<>=this.DB;if(e.t>=this.DB;r+=this.s}else{for(r+=this.s;i>=this.DB;r-=e.s}t.s=r<0?-1:0,r<-1?t.data[i++]=this.DV+r:r>0&&(t.data[i++]=r),t.t=i,t.clamp()},s.prototype.multiplyTo=function(e,t){var i=this.abs(),r=e.abs(),n=i.t;for(t.t=n+r.t;--n>=0;)t.data[n]=0;for(n=0;n=0;)e.data[i]=0;for(i=0;i=t.DV&&(e.data[i+t.t]-=t.DV,e.data[i+t.t+1]=1)}e.t>0&&(e.data[e.t-1]+=t.am(i,t.data[i],e,2*i,0,1)),e.s=0,e.clamp()},s.prototype.divRemTo=function(e,t,i){var r=e.abs();if(!(r.t<=0)){var a=this.abs();if(a.t0?(r.lShiftTo(h,o),a.lShiftTo(h,i)):(r.copyTo(o),a.copyTo(i));var d=o.t,u=o.data[d-1];if(0!=u){var p=u*(1<1?o.data[d-2]>>this.F2:0),g=this.FV/p,m=(1<=0&&(i.data[i.t++]=1,i.subTo(A,i)),s.ONE.dlShiftTo(d,A),A.subTo(o,o);o.t=0;){var v=i.data[--E]==u?this.DM:Math.floor(i.data[E]*g+(i.data[E-1]+y)*m);if((i.data[E]+=o.am(0,v,i,_,0,d))0&&i.rShiftTo(h,i),c<0&&s.ZERO.subTo(i,i)}}},s.prototype.invDigit=function(){if(this.t<1)return 0;var e=this.data[0];if(!(1&e))return 0;var t=3&e;return(t=(t=(t=(t=t*(2-(15&e)*t)&15)*(2-(255&e)*t)&255)*(2-((65535&e)*t&65535))&65535)*(2-e*t%this.DV)%this.DV)>0?this.DV-t:-t},s.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},s.prototype.exp=function(e,t){if(e>4294967295||e<1)return s.ONE;var i=n(),r=n(),a=t.convert(this),o=f(e)-1;for(a.copyTo(i);--o>=0;)if(t.sqrTo(i,r),(e&1<0)t.mulTo(r,a,i);else{var c=i;i=r,r=c}return t.revert(i)},s.prototype.toString=function(e){if(this.s<0)return'-'+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)return this.toRadix(e);t=2}var i,r=(1<0)for(o>o)>0&&(s=!0,n=h(i));a>=0;)o>(o+=this.DB-t)):(i=this.data[a]>>(o-=t)&r,o<=0&&(o+=this.DB,--a)),i>0&&(s=!0),s&&(n+=h(i));return s?n:'0'},s.prototype.negate=function(){var e=n();return s.ZERO.subTo(this,e),e},s.prototype.abs=function(){return this.s<0?this.negate():this},s.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var i=this.t;if(0!=(t=i-e.t))return this.s<0?-t:t;for(;--i>=0;)if(0!=(t=this.data[i]-e.data[i]))return t;return 0},s.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+f(this.data[this.t-1]^this.s&this.DM)},s.prototype.mod=function(e){var t=n();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(s.ZERO)>0&&e.subTo(t,t),t},s.prototype.modPowInt=function(e,t){var i;return i=e<256||t.isEven()?new g(t):new m(t),this.exp(e,i)},s.ZERO=p(0),s.ONE=p(1),C.prototype.convert=I,C.prototype.revert=I,C.prototype.mulTo=function(e,t,i){e.multiplyTo(t,i)},C.prototype.sqrTo=function(e,t){e.squareTo(t)},S.prototype.convert=function(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=n();return e.copyTo(t),this.reduce(t),t},S.prototype.revert=function(e){return e},S.prototype.reduce=function(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)},S.prototype.mulTo=function(e,t,i){e.multiplyTo(t,i),this.reduce(i)},S.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)};var O=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509],N=(1<<26)/O[O.length-1];s.prototype.chunkSize=function(e){return Math.floor(Math.LN2*this.DB/Math.log(e))},s.prototype.toRadix=function(e){if(null==e&&(e=10),0==this.signum()||e<2||e>36)return'0';var t=this.chunkSize(e),i=Math.pow(e,t),r=p(i),s=n(),a=n(),o='';for(this.divRemTo(r,s,a);s.signum()>0;)o=(i+a.intValue()).toString(e).substr(1)+o,s.divRemTo(r,s,a);return a.intValue().toString(e)+o},s.prototype.fromRadix=function(e,t){this.fromInt(0),null==t&&(t=10);for(var i=this.chunkSize(t),r=Math.pow(t,i),n=!1,a=0,o=0,c=0;c=i&&(this.dMultiply(r),this.dAddOffset(o,0),a=0,o=0))}a>0&&(this.dMultiply(Math.pow(t,a)),this.dAddOffset(o,0)),n&&s.ZERO.subTo(this,this)},s.prototype.fromNumber=function(e,t,i){if('number'==typeof t)if(e<2)this.fromInt(1);else for(this.fromNumber(e,i),this.testBit(e-1)||this.bitwiseTo(s.ONE.shiftLeft(e-1),E,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(s.ONE.shiftLeft(e-1),this);else{var r=new Array,n=7&e;r.length=1+(e>>3),t.nextBytes(r),n>0?r[0]&=(1<>=this.DB;if(e.t>=this.DB;r+=this.s}else{for(r+=this.s;i>=this.DB;r+=e.s}t.s=r<0?-1:0,r>0?t.data[i++]=r:r<-1&&(t.data[i++]=this.DV+r),t.t=i,t.clamp()},s.prototype.dMultiply=function(e){this.data[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()},s.prototype.dAddOffset=function(e,t){if(0!=e){for(;this.t<=t;)this.data[this.t++]=0;for(this.data[t]+=e;this.data[t]>=this.DV;)this.data[t]-=this.DV,++t>=this.t&&(this.data[this.t++]=0),++this.data[t]}},s.prototype.multiplyLowerTo=function(e,t,i){var r,s=Math.min(this.t+e.t,t);for(i.s=0,i.t=s;s>0;)i.data[--s]=0;for(r=i.t-this.t;s=0;)i.data[r]=0;for(r=Math.max(t-this.t,0);r0)if(0==t)i=this.data[0]%e;else for(var r=this.t-1;r>=0;--r)i=(t*i+this.data[r])%e;return i},s.prototype.millerRabin=function(e){var t=this.subtract(s.ONE),i=t.getLowestSetBit();if(i<=0)return!1;for(var r,n=t.shiftRight(i),a={nextBytes:function(e){for(var t=0;t=0);var c=r.modPow(n,this);if(0!=c.compareTo(s.ONE)&&0!=c.compareTo(t)){for(var l=1;l++>24},s.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},s.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},s.prototype.toByteArray=function(){var e=this.t,t=new Array;t[0]=this.s;var i,r=this.DB-e*this.DB%8,s=0;if(e-- >0)for(r>r)!=(this.s&this.DM)>>r&&(t[s++]=i|this.s<=0;)r<8?(i=(this.data[e]&(1<>(r+=this.DB-8)):(i=this.data[e]>>(r-=8)&255,r<=0&&(r+=this.DB,--e)),128&i&&(i|=-256),0==s&&(128&this.s)!=(128&i)&&++s,(s>0||i!=this.s)&&(t[s++]=i);return t},s.prototype.equals=function(e){return 0==this.compareTo(e)},s.prototype.min=function(e){return this.compareTo(e)<0?this:e},s.prototype.max=function(e){return this.compareTo(e)>0?this:e},s.prototype.and=function(e){var t=n();return this.bitwiseTo(e,y,t),t},s.prototype.or=function(e){var t=n();return this.bitwiseTo(e,E,t),t},s.prototype.xor=function(e){var t=n();return this.bitwiseTo(e,_,t),t},s.prototype.andNot=function(e){var t=n();return this.bitwiseTo(e,A,t),t},s.prototype.not=function(){for(var e=n(),t=0;t=this.t?0!=this.s:!!(this.data[t]&1<1){var d=n();for(r.sqrTo(o[1],d);c<=h;)o[c]=n(),r.mulTo(d,o[c-2],o[c]),c+=2}var u,y,E=e.t-1,_=!0,A=n();for(s=f(e.data[E])-1;E>=0;){for(s>=l?u=e.data[E]>>s-l&h:(u=(e.data[E]&(1<0&&(u|=e.data[E-1]>>this.DB+s-l)),c=i;!(1&u);)u>>=1,--c;if((s-=c)<0&&(s+=this.DB,--E),_)o[u].copyTo(a),_=!1;else{for(;c>1;)r.sqrTo(a,A),r.sqrTo(A,a),c-=2;c>0?r.sqrTo(a,A):(y=a,a=A,A=y),r.mulTo(A,o[u],a)}for(;E>=0&&!(e.data[E]&1<=0?(i.subTo(r,i),t&&n.subTo(o,n),a.subTo(c,a)):(r.subTo(i,r),t&&o.subTo(n,o),c.subTo(a,c))}return 0!=r.compareTo(s.ONE)?s.ZERO:c.compareTo(e)>=0?c.subtract(e):c.signum()<0?(c.addTo(e,c),c.signum()<0?c.add(e):c):c},s.prototype.pow=function(e){return this.exp(e,new C)},s.prototype.gcd=function(e){var t=this.s<0?this.negate():this.clone(),i=e.s<0?e.negate():e.clone();if(t.compareTo(i)<0){var r=t;t=i,i=r}var s=t.getLowestSetBit(),n=i.getLowestSetBit();if(n<0)return t;for(s0&&(t.rShiftTo(n,t),i.rShiftTo(n,i));t.signum()>0;)(s=t.getLowestSetBit())>0&&t.rShiftTo(s,t),(s=i.getLowestSetBit())>0&&i.rShiftTo(s,i),t.compareTo(i)>=0?(t.subTo(i,t),t.rShiftTo(1,t)):(i.subTo(t,i),i.rShiftTo(1,i));return n>0&&i.lShiftTo(n,i),i},s.prototype.isProbablePrime=function(e){var t,i=this.abs();if(1==i.t&&i.data[0]<=O[O.length-1]){for(t=0;t>>0,c>>>0];for(var l=o.fullMessageLength.length-1;l>=0;--l)o.fullMessageLength[l]+=c[1],c[1]=c[0]+(o.fullMessageLength[l]/4294967296>>>0),o.fullMessageLength[l]=o.fullMessageLength[l]>>>0,c[0]=c[1]/4294967296>>>0;return t.putBytes(s),a(e,r,t),(t.read>2048||0===t.length())&&t.compact(),o},o.digest=function(){var n=i.util.createBuffer();n.putBytes(t.bytes());var c,l=o.fullMessageLength[o.fullMessageLength.length-1]+o.messageLengthSize&o.blockLength-1;n.putBytes(s.substr(0,o.blockLength-l));for(var h=8*o.fullMessageLength[0],d=0;d>>0,n.putInt32(h>>>0),h=c>>>0;n.putInt32(h);var u={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4};a(u,r,n);var p=i.util.createBuffer();return p.putInt32(u.h0),p.putInt32(u.h1),p.putInt32(u.h2),p.putInt32(u.h3),p.putInt32(u.h4),p},o};var s=null,n=!1;function a(e,t,i){for(var r,s,n,a,o,c,l,h=i.length();h>=64;){for(s=e.h0,n=e.h1,a=e.h2,o=e.h3,c=e.h4,l=0;l<16;++l)r=i.getInt32(),t[l]=r,r=(s<<5|s>>>27)+(o^n&(a^o))+c+1518500249+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<20;++l)r=(r=t[l-3]^t[l-8]^t[l-14]^t[l-16])<<1|r>>>31,t[l]=r,r=(s<<5|s>>>27)+(o^n&(a^o))+c+1518500249+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<32;++l)r=(r=t[l-3]^t[l-8]^t[l-14]^t[l-16])<<1|r>>>31,t[l]=r,r=(s<<5|s>>>27)+(n^a^o)+c+1859775393+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<40;++l)r=(r=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|r>>>30,t[l]=r,r=(s<<5|s>>>27)+(n^a^o)+c+1859775393+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<60;++l)r=(r=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|r>>>30,t[l]=r,r=(s<<5|s>>>27)+(n&a|o&(n^a))+c+2400959708+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;for(;l<80;++l)r=(r=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|r>>>30,t[l]=r,r=(s<<5|s>>>27)+(n^a^o)+c+3395469782+r,c=o,o=a,a=(n<<30|n>>>2)>>>0,n=s,s=r;e.h0=e.h0+s|0,e.h1=e.h1+n|0,e.h2=e.h2+a|0,e.h3=e.h3+o|0,e.h4=e.h4+c|0,h-=64}}}}),R=d({'node_modules/node-forge/lib/pkcs1.js'(e,t){var i=u();f(),L(),b();var r=t.exports=i.pkcs1=i.pkcs1||{};function s(e,t,r){r||(r=i.md.sha1.create());for(var s='',n=Math.ceil(t/r.digestLength),a=0;a>24&255,a>>16&255,a>>8&255,255&a);r.start(),r.update(e+o),s+=r.digest().getBytes()}return s.substring(0,t)}r.encode_rsa_oaep=function(e,t,r){var n,a,o,c;'string'==typeof r?(n=r,a=arguments[3]||void 0,o=arguments[4]||void 0):r&&(n=r.label||void 0,a=r.seed||void 0,o=r.md||void 0,r.mgf1&&r.mgf1.md&&(c=r.mgf1.md)),o?o.start():o=i.md.sha1.create(),c||(c=o);var l=Math.ceil(e.n.bitLength()/8),h=l-2*o.digestLength-2;if(t.length>h)throw(m=new Error('RSAES-OAEP input message length is too long.')).length=t.length,m.maxLength=h,m;n||(n=''),o.update(n,'raw');for(var d=o.digest(),u='',p=h-t.length,f=0;fe&&(a=l(e,t));var p=a.toString(16);s.target.postMessage({hex:p,workLoad:h}),a.dAddOffset(d,0)}}}p()}(e,t,s,n);return o(e,t,s,n)}(e,c,n.options,s);throw new Error('Invalid prime generation algorithm: '+n.name)}}function o(e,t,i,r){var s=l(e,t),n=function(e){return e<=100?27:e<=150?18:e<=200?15:e<=250?12:e<=300?9:e<=350?8:e<=400?7:e<=500?6:e<=600?5:e<=800?4:e<=1250?3:2}(s.bitLength());'millerRabinTests'in i&&(n=i.millerRabinTests);var a=10;'maxBlockTime'in i&&(a=i.maxBlockTime),c(s,e,t,0,n,a,r)}function c(e,t,r,n,a,o,h){var d=+new Date;do{if(e.bitLength()>t&&(e=l(t,r)),e.isProbablePrime(a))return h(null,e);e.dAddOffset(s[n++%8],0)}while(o<0||+new Date-d=0||!n.gcd(t.n).equals(i.ONE));for(var a=(e=e.multiply(n.modPow(t.e,t.n)).mod(t.n)).mod(t.p).modPow(t.dP,t.p),o=e.mod(t.q).modPow(t.dQ,t.q);a.compareTo(o)<0;)a=a.add(t.p);var c=a.subtract(o).multiply(t.qInv).mod(t.p).multiply(t.q).add(o);return c=c.multiply(n.modInverse(t.n)).mod(t.n)};function v(e,t,i){var s=r.util.createBuffer(),n=Math.ceil(t.n.bitLength()/8);if(e.length>n-11){var a=new Error('Message is too long for PKCS#1 v1.5 padding.');throw a.length=e.length,a.max=n-11,a}s.putByte(0),s.putByte(i);var o,c=n-3-e.length;if(0===i||1===i){o=0===i?0:255;for(var l=0;l0;){var h=0,d=r.random.getBytes(c);for(l=0;l1;){if(255!==a.getByte()){--a.read;break}++l}else if(2===c)for(l=0;a.length()>1;){if(0===a.getByte()){--a.read;break}++l}if(0!==a.getByte()||l!==n-3-a.length())throw new Error('Encryption block is invalid.');return a.getBytes()}function C(e){var t=e.toString(16);t[0]>='8'&&(t='00'+t);var i=r.util.hexToBytes(t);return!(i.length>1)||(0!==i.charCodeAt(0)||128&i.charCodeAt(1))&&(255!==i.charCodeAt(0)||128&~i.charCodeAt(1))?i:i.substr(1)}function I(e){return e<=100?27:e<=150?18:e<=200?15:e<=250?12:e<=300?9:e<=350?8:e<=400?7:e<=500?6:e<=600?5:e<=800?4:e<=1250?3:2}function S(e){return r.util.isNodejs&&'function'==typeof s[e]}function O(e){return void 0!==a.globalScope&&'object'==typeof a.globalScope.crypto&&'object'==typeof a.globalScope.crypto.subtle&&'function'==typeof a.globalScope.crypto.subtle[e]}function N(e){return void 0!==a.globalScope&&'object'==typeof a.globalScope.msCrypto&&'object'==typeof a.globalScope.msCrypto.subtle&&'function'==typeof a.globalScope.msCrypto.subtle[e]}function P(e){for(var t=r.util.hexToBytes(e.toString(16)),i=new Uint8Array(t.length),s=0;s0;)h.putByte(0),--d;return h.putBytes(r.util.hexToBytes(l)),h.getBytes()},o.rsa.decrypt=function(e,t,s,n){var a=Math.ceil(t.n.bitLength()/8);if(e.length!==a){var o=new Error('Encrypted message length is invalid.');throw o.length=e.length,o.expected=a,o}var c=new i(r.util.createBuffer(e).toHex(),16);if(c.compareTo(t.n)>=0)throw new Error('Encrypted message is invalid.');for(var l=A(c,t,s).toString(16),h=r.util.createBuffer(),d=a-Math.ceil(l.length/2);d>0;)h.putByte(0),--d;return h.putBytes(r.util.hexToBytes(l)),!1!==n?T(h.getBytes(),t,s):h.getBytes()},o.rsa.createKeyPairGenerationState=function(e,t,s){'string'==typeof e&&(e=parseInt(e,10)),e=e||2048;var n,a=(s=s||{}).prng||r.random,o={nextBytes:function(e){for(var t=a.getBytesSync(e.length),i=0;i>1,pBits:e-(e>>1),pqState:0,num:null,keys:null}).e.fromInt(n.eInt),n},o.rsa.stepKeyPairGenerationState=function(e,t){'algorithm'in e||(e.algorithm='PRIMEINC');var r=new i(null);r.fromInt(30);for(var s,n=0,a=function(e,t){return e|t},l=+new Date,h=0;null===e.keys&&(t<=0||hd?e.pqState=0:e.num.isProbablePrime(I(e.num.bitLength()))?++e.pqState:e.num.dAddOffset(c[n++%8],0):2===e.pqState?e.pqState=0===e.num.subtract(i.ONE).gcd(e.e).compareTo(i.ONE)?3:0:3===e.pqState&&(e.pqState=0,null===e.p?e.p=e.num:e.q=e.num,null!==e.p&&null!==e.q&&++e.state,e.num=null)}else if(1===e.state)e.p.compareTo(e.q)<0&&(e.num=e.p,e.p=e.q,e.q=e.num),++e.state;else if(2===e.state)e.p1=e.p.subtract(i.ONE),e.q1=e.q.subtract(i.ONE),e.phi=e.p1.multiply(e.q1),++e.state;else if(3===e.state)0===e.phi.gcd(e.e).compareTo(i.ONE)?++e.state:(e.p=null,e.q=null,e.state=0);else if(4===e.state)e.n=e.p.multiply(e.q),e.n.bitLength()===e.bits?++e.state:(e.q=null,e.state=0);else if(5===e.state){var p=e.e.modInverse(e.phi);e.keys={privateKey:o.rsa.setPrivateKey(e.n,e.e,p,e.p,e.q,p.mod(e.p1),p.mod(e.q1),e.q.modInverse(e.p)),publicKey:o.rsa.setPublicKey(e.n,e.e)}}h+=(s=+new Date)-l,l=s}return null!==e.keys},o.rsa.generateKeyPair=function(e,t,c,l){if(1===arguments.length?'object'==typeof e?(c=e,e=void 0):'function'==typeof e&&(l=e,e=void 0):2===arguments.length?'number'==typeof e?'function'==typeof t?(l=t,t=void 0):'number'!=typeof t&&(c=t,t=void 0):(c=e,l=t,e=void 0,t=void 0):3===arguments.length&&('number'==typeof t?'function'==typeof c&&(l=c,c=void 0):(l=c,c=t,t=void 0)),c=c||{},void 0===e&&(e=c.bits||2048),void 0===t&&(t=c.e||65537),!r.options.usePureJavaScript&&!c.prng&&e>=256&&e<=16384&&(65537===t||3===t))if(l){if(S('generateKeyPair'))return s.generateKeyPair('rsa',{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:'spki',format:'pem'},privateKeyEncoding:{type:'pkcs8',format:'pem'}},(function(e,t,i){if(e)return l(e);l(null,{privateKey:o.privateKeyFromPem(i),publicKey:o.publicKeyFromPem(t)})}));if(O('generateKey')&&O('exportKey'))return a.globalScope.crypto.subtle.generateKey({name:'RSASSA-PKCS1-v1_5',modulusLength:e,publicExponent:P(t),hash:{name:'SHA-256'}},!0,['sign','verify']).then((function(e){return a.globalScope.crypto.subtle.exportKey('pkcs8',e.privateKey)})).then(void 0,(function(e){l(e)})).then((function(e){if(e){var t=o.privateKeyFromAsn1(n.fromDer(r.util.createBuffer(e)));l(null,{privateKey:t,publicKey:o.setRsaPublicKey(t.n,t.e)})}}));if(N('generateKey')&&N('exportKey')){var h=a.globalScope.msCrypto.subtle.generateKey({name:'RSASSA-PKCS1-v1_5',modulusLength:e,publicExponent:P(t),hash:{name:'SHA-256'}},!0,['sign','verify']);return h.oncomplete=function(e){var t=e.target.result,i=a.globalScope.msCrypto.subtle.exportKey('pkcs8',t.privateKey);i.oncomplete=function(e){var t=e.target.result,i=o.privateKeyFromAsn1(n.fromDer(r.util.createBuffer(t)));l(null,{privateKey:i,publicKey:o.setRsaPublicKey(i.n,i.e)})},i.onerror=function(e){l(e)}},void(h.onerror=function(e){l(e)})}}else if(S('generateKeyPairSync')){var d=s.generateKeyPairSync('rsa',{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:'spki',format:'pem'},privateKeyEncoding:{type:'pkcs8',format:'pem'}});return{privateKey:o.privateKeyFromPem(d.privateKey),publicKey:o.publicKeyFromPem(d.publicKey)}}var u=o.rsa.createKeyPairGenerationState(e,t,c);if(!l)return o.rsa.stepKeyPairGenerationState(u,0),u.keys;!function(e,t,s){'function'==typeof t&&(s=t,t={});t=t||{};var n={algorithm:{name:t.algorithm||'PRIMEINC',options:{workers:t.workers||2,workLoad:t.workLoad||100,workerScript:t.workerScript}}};'prng'in t&&(n.prng=t.prng);function a(){c(e.pBits,(function(t,i){return t?s(t):(e.p=i,null!==e.q?l(t,e.q):void c(e.qBits,l))}))}function c(e,t){r.prime.generateProbablePrime(e,n,t)}function l(t,r){if(t)return s(t);if(e.q=r,e.p.compareTo(e.q)<0){var n=e.p;e.p=e.q,e.q=n}if(0!==e.p.subtract(i.ONE).gcd(e.e).compareTo(i.ONE))return e.p=null,void a();if(0!==e.q.subtract(i.ONE).gcd(e.e).compareTo(i.ONE))return e.q=null,void c(e.qBits,l);if(e.p1=e.p.subtract(i.ONE),e.q1=e.q.subtract(i.ONE),e.phi=e.p1.multiply(e.q1),0!==e.phi.gcd(e.e).compareTo(i.ONE))return e.p=e.q=null,void a();if(e.n=e.p.multiply(e.q),e.n.bitLength()!==e.bits)return e.q=null,void c(e.qBits,l);var h=e.e.modInverse(e.phi);e.keys={privateKey:o.rsa.setPrivateKey(e.n,e.e,h,e.p,e.q,h.mod(e.p1),h.mod(e.q1),e.q.modInverse(e.p)),publicKey:o.rsa.setPublicKey(e.n,e.e)},s(null,e.keys)}a()}(u,c,l)},o.setRsaPublicKey=o.rsa.setPublicKey=function(e,t){var i={n:e,e:t,encrypt:function(e,t,s){if('string'==typeof t?t=t.toUpperCase():void 0===t&&(t='RSAES-PKCS1-V1_5'),'RSAES-PKCS1-V1_5'===t)t={encode:function(e,t,i){return v(e,t,2).getBytes()}};else if('RSA-OAEP'===t||'RSAES-OAEP'===t)t={encode:function(e,t){return r.pkcs1.encode_rsa_oaep(t,e,s)}};else if(-1!==['RAW','NONE','NULL',null].indexOf(t))t={encode:function(e){return e}};else if('string'==typeof t)throw new Error('Unsupported encryption scheme: "'+t+'".');var n=t.encode(e,i,!0);return o.rsa.encrypt(n,i,!0)},verify:function(e,t,s,a){'string'==typeof s?s=s.toUpperCase():void 0===s&&(s='RSASSA-PKCS1-V1_5'),void 0===a&&(a={_parseAllDigestBytes:!0}),'_parseAllDigestBytes'in a||(a._parseAllDigestBytes=!0),'RSASSA-PKCS1-V1_5'===s?s={verify:function(e,t){t=T(t,i,!0);var s=n.fromDer(t,{parseAllBytes:a._parseAllDigestBytes}),o={},c=[];if(!n.validate(s,m,o,c))throw(l=new Error('ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value.')).errors=c,l;var l,h=n.derToOid(o.algorithmIdentifier);if(h!==r.oids.md2&&h!==r.oids.md5&&h!==r.oids.sha1&&h!==r.oids.sha224&&h!==r.oids.sha256&&h!==r.oids.sha384&&h!==r.oids.sha512&&h!==r.oids['sha512-224']&&h!==r.oids['sha512-256'])throw(l=new Error('Unknown RSASSA-PKCS1-v1_5 DigestAlgorithm identifier.')).oid=h,l;if((h===r.oids.md2||h===r.oids.md5)&&!('parameters'in o))throw new Error('ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value. Missing algorithm identifer NULL parameters.');return e===o.digest}}:'NONE'!==s&&'NULL'!==s&&null!==s||(s={verify:function(e,t){return e===(t=T(t,i,!0))}});var c=o.rsa.decrypt(t,i,!0,!1);return s.verify(e,c,i.n.bitLength())}};return i},o.setRsaPrivateKey=o.rsa.setPrivateKey=function(e,t,i,s,n,a,c,l){var h={n:e,e:t,d:i,p:s,q:n,dP:a,dQ:c,qInv:l,decrypt:function(e,t,i){'string'==typeof t?t=t.toUpperCase():void 0===t&&(t='RSAES-PKCS1-V1_5');var s=o.rsa.decrypt(e,h,!1,!1);if('RSAES-PKCS1-V1_5'===t)t={decode:T};else if('RSA-OAEP'===t||'RSAES-OAEP'===t)t={decode:function(e,t){return r.pkcs1.decode_rsa_oaep(t,e,i)}};else{if(-1===['RAW','NONE','NULL',null].indexOf(t))throw new Error('Unsupported encryption scheme: "'+t+'".');t={decode:function(e){return e}}}return t.decode(s,h,!1)},sign:function(e,t){var i=!1;'string'==typeof t&&(t=t.toUpperCase()),void 0===t||'RSASSA-PKCS1-V1_5'===t?(t={encode:y},i=1):'NONE'!==t&&'NULL'!==t&&null!==t||(t={encode:function(){return e}},i=1);var r=t.encode(e,h.n.bitLength());return o.rsa.encrypt(r,h,i)}};return h},o.wrapRsaPrivateKey=function(e){return n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,n.integerToDer(0).getBytes()),n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.OID,!1,n.oidToDer(o.oids.rsaEncryption).getBytes()),n.create(n.Class.UNIVERSAL,n.Type.NULL,!1,'')]),n.create(n.Class.UNIVERSAL,n.Type.OCTETSTRING,!1,n.toDer(e).getBytes())])},o.privateKeyFromAsn1=function(e){var t,s,a,c,h,u,p,f,g={},m=[];if(n.validate(e,l,g,m)&&(e=n.fromDer(r.util.createBuffer(g.privateKey))),g={},m=[],!n.validate(e,d,g,m)){var y=new Error('Cannot read private key. ASN.1 object does not contain an RSAPrivateKey.');throw y.errors=m,y}return t=r.util.createBuffer(g.privateKeyModulus).toHex(),s=r.util.createBuffer(g.privateKeyPublicExponent).toHex(),a=r.util.createBuffer(g.privateKeyPrivateExponent).toHex(),c=r.util.createBuffer(g.privateKeyPrime1).toHex(),h=r.util.createBuffer(g.privateKeyPrime2).toHex(),u=r.util.createBuffer(g.privateKeyExponent1).toHex(),p=r.util.createBuffer(g.privateKeyExponent2).toHex(),f=r.util.createBuffer(g.privateKeyCoefficient).toHex(),o.setRsaPrivateKey(new i(t,16),new i(s,16),new i(a,16),new i(c,16),new i(h,16),new i(u,16),new i(p,16),new i(f,16))},o.privateKeyToAsn1=o.privateKeyToRSAPrivateKey=function(e){return n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,n.integerToDer(0).getBytes()),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.n)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.e)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.d)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.p)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.q)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.dP)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.dQ)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.qInv))])},o.publicKeyFromAsn1=function(e){var t={},s=[];if(n.validate(e,g,t,s)){var a,c=n.derToOid(t.publicKeyOid);if(c!==o.oids.rsaEncryption)throw(a=new Error('Cannot read public key. Unknown OID.')).oid=c,a;e=t.rsaPublicKey}if(s=[],!n.validate(e,p,t,s))throw(a=new Error('Cannot read public key. ASN.1 object does not contain an RSAPublicKey.')).errors=s,a;var l=r.util.createBuffer(t.publicKeyModulus).toHex(),h=r.util.createBuffer(t.publicKeyExponent).toHex();return o.setRsaPublicKey(new i(l,16),new i(h,16))},o.publicKeyToAsn1=o.publicKeyToSubjectPublicKeyInfo=function(e){return n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.OID,!1,n.oidToDer(o.oids.rsaEncryption).getBytes()),n.create(n.Class.UNIVERSAL,n.Type.NULL,!1,'')]),n.create(n.Class.UNIVERSAL,n.Type.BITSTRING,!1,[o.publicKeyToRSAPublicKey(e)])])},o.publicKeyToRSAPublicKey=function(e){return n.create(n.Class.UNIVERSAL,n.Type.SEQUENCE,!0,[n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.n)),n.create(n.Class.UNIVERSAL,n.Type.INTEGER,!1,C(e.e))])}}}),D=d({'node_modules/node-forge/lib/pbe.js'(e,t){var i,r=u();y(),_(),I(),A(),E(),S(),C(),L(),P(),U(),f(),void 0===i&&(i=r.jsbn.BigInteger);var s=r.asn1,n=r.pki=r.pki||{};t.exports=n.pbe=r.pbe=r.pbe||{};var a=n.oids,o={name:'EncryptedPrivateKeyInfo',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'EncryptedPrivateKeyInfo.encryptionAlgorithm',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'AlgorithmIdentifier.algorithm',tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:'encryptionOid'},{name:'AlgorithmIdentifier.parameters',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,captureAsn1:'encryptionParams'}]},{name:'EncryptedPrivateKeyInfo.encryptedData',tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:'encryptedData'}]},c={name:'PBES2Algorithms',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'PBES2Algorithms.keyDerivationFunc',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'PBES2Algorithms.keyDerivationFunc.oid',tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:'kdfOid'},{name:'PBES2Algorithms.params',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'PBES2Algorithms.params.salt',tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:'kdfSalt'},{name:'PBES2Algorithms.params.iterationCount',tagClass:s.Class.UNIVERSAL,type:s.Type.INTEGER,constructed:!1,capture:'kdfIterationCount'},{name:'PBES2Algorithms.params.keyLength',tagClass:s.Class.UNIVERSAL,type:s.Type.INTEGER,constructed:!1,optional:!0,capture:'keyLength'},{name:'PBES2Algorithms.params.prf',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,optional:!0,value:[{name:'PBES2Algorithms.params.prf.algorithm',tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:'prfOid'}]}]}]},{name:'PBES2Algorithms.encryptionScheme',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'PBES2Algorithms.encryptionScheme.oid',tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:'encOid'},{name:'PBES2Algorithms.encryptionScheme.iv',tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:'encIv'}]}]},l={name:'pkcs-12PbeParams',tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:'pkcs-12PbeParams.salt',tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:'salt'},{name:'pkcs-12PbeParams.iterations',tagClass:s.Class.UNIVERSAL,type:s.Type.INTEGER,constructed:!1,capture:'iterations'}]};function h(e,t){return e.start().update(t).digest().getBytes()}function d(e){var t;if(e){if(!(t=n.oids[s.derToOid(e)])){var i=new Error('Unsupported PRF OID.');throw i.oid=e,i.supported=['hmacWithSHA1','hmacWithSHA224','hmacWithSHA256','hmacWithSHA384','hmacWithSHA512'],i}}else t='hmacWithSHA1';return p(t)}function p(e){var t=r.md;switch(e){case'hmacWithSHA224':t=r.md.sha512;case'hmacWithSHA1':case'hmacWithSHA256':case'hmacWithSHA384':case'hmacWithSHA512':e=e.substr(8).toLowerCase();break;default:var i=new Error('Unsupported PRF algorithm.');throw i.algorithm=e,i.supported=['hmacWithSHA1','hmacWithSHA224','hmacWithSHA256','hmacWithSHA384','hmacWithSHA512'],i}if(!t||!(e in t))throw new Error('Unknown hash algorithm: '+e);return t[e].create()}n.encryptPrivateKeyInfo=function(e,t,i){(i=i||{}).saltSize=i.saltSize||8,i.count=i.count||2048,i.algorithm=i.algorithm||'aes128',i.prfAlgorithm=i.prfAlgorithm||'sha1';var o,c,l,h=r.random.getBytesSync(i.saltSize),d=i.count,u=s.integerToDer(d);if(0===i.algorithm.indexOf('aes')||'des'===i.algorithm){var f,g,m;switch(i.algorithm){case'aes128':o=16,f=16,g=a['aes128-CBC'],m=r.aes.createEncryptionCipher;break;case'aes192':o=24,f=16,g=a['aes192-CBC'],m=r.aes.createEncryptionCipher;break;case'aes256':o=32,f=16,g=a['aes256-CBC'],m=r.aes.createEncryptionCipher;break;case'des':o=8,f=8,g=a.desCBC,m=r.des.createEncryptionCipher;break;default:throw(T=new Error('Cannot encrypt private key. Unknown encryption algorithm.')).algorithm=i.algorithm,T}var y='hmacWith'+i.prfAlgorithm.toUpperCase(),E=p(y),_=r.pkcs5.pbkdf2(t,h,d,o,E),A=r.random.getBytesSync(f);(C=m(_)).start(A),C.update(s.toDer(e)),C.finish(),l=C.output.getBytes();var v=function(e,t,i,a){var o=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,e),s.create(s.Class.UNIVERSAL,s.Type.INTEGER,!1,t.getBytes())]);'hmacWithSHA1'!==a&&o.value.push(s.create(s.Class.UNIVERSAL,s.Type.INTEGER,!1,r.util.hexToBytes(i.toString(16))),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(n.oids[a]).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.NULL,!1,'')]));return o}(h,u,o,y);c=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(a.pkcs5PBES2).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(a.pkcs5PBKDF2).getBytes()),v]),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(g).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,A)])])])}else{var T;if('3des'!==i.algorithm)throw(T=new Error('Cannot encrypt private key. Unknown encryption algorithm.')).algorithm=i.algorithm,T;o=24;var C,I=new r.util.ByteBuffer(h);_=n.pbe.generatePkcs12Key(t,I,1,d,o),A=n.pbe.generatePkcs12Key(t,I,2,d,o);(C=r.des.createEncryptionCipher(_)).start(A),C.update(s.toDer(e)),C.finish(),l=C.output.getBytes(),c=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(a['pbeWithSHAAnd3-KeyTripleDES-CBC']).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,h),s.create(s.Class.UNIVERSAL,s.Type.INTEGER,!1,u.getBytes())])])}return s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[c,s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,l)])},n.decryptPrivateKeyInfo=function(e,t){var i=null,a={},c=[];if(!s.validate(e,o,a,c)){var l=new Error('Cannot read encrypted private key. ASN.1 object is not a supported EncryptedPrivateKeyInfo.');throw l.errors=c,l}var h=s.derToOid(a.encryptionOid),d=n.pbe.getCipher(h,a.encryptionParams,t),u=r.util.createBuffer(a.encryptedData);return d.update(u),d.finish()&&(i=s.fromDer(d.output)),i},n.encryptedPrivateKeyToPem=function(e,t){var i={type:'ENCRYPTED PRIVATE KEY',body:s.toDer(e).getBytes()};return r.pem.encode(i,{maxline:t})},n.encryptedPrivateKeyFromPem=function(e){var t=r.pem.decode(e)[0];if('ENCRYPTED PRIVATE KEY'!==t.type){var i=new Error('Could not convert encrypted private key from PEM; PEM header type is "ENCRYPTED PRIVATE KEY".');throw i.headerType=t.type,i}if(t.procType&&'ENCRYPTED'===t.procType.type)throw new Error('Could not convert encrypted private key from PEM; PEM is encrypted.');return s.fromDer(t.body)},n.encryptRsaPrivateKey=function(e,t,i){if(!(i=i||{}).legacy){var a=n.wrapRsaPrivateKey(n.privateKeyToAsn1(e));return a=n.encryptPrivateKeyInfo(a,t,i),n.encryptedPrivateKeyToPem(a)}var o,c,l,h;switch(i.algorithm){case'aes128':o='AES-128-CBC',l=16,c=r.random.getBytesSync(16),h=r.aes.createEncryptionCipher;break;case'aes192':o='AES-192-CBC',l=24,c=r.random.getBytesSync(16),h=r.aes.createEncryptionCipher;break;case'aes256':o='AES-256-CBC',l=32,c=r.random.getBytesSync(16),h=r.aes.createEncryptionCipher;break;case'3des':o='DES-EDE3-CBC',l=24,c=r.random.getBytesSync(8),h=r.des.createEncryptionCipher;break;case'des':o='DES-CBC',l=8,c=r.random.getBytesSync(8),h=r.des.createEncryptionCipher;break;default:var d=new Error('Could not encrypt RSA private key; unsupported encryption algorithm "'+i.algorithm+'".');throw d.algorithm=i.algorithm,d}var u=h(r.pbe.opensslDeriveBytes(t,c.substr(0,8),l));u.start(c),u.update(s.toDer(n.privateKeyToAsn1(e))),u.finish();var p={type:'RSA PRIVATE KEY',procType:{version:'4',type:'ENCRYPTED'},dekInfo:{algorithm:o,parameters:r.util.bytesToHex(c).toUpperCase()},body:u.output.getBytes()};return r.pem.encode(p)},n.decryptRsaPrivateKey=function(e,t){var i=null,a=r.pem.decode(e)[0];if('ENCRYPTED PRIVATE KEY'!==a.type&&'PRIVATE KEY'!==a.type&&'RSA PRIVATE KEY'!==a.type)throw(l=new Error('Could not convert private key from PEM; PEM header type is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".')).headerType=l,l;if(a.procType&&'ENCRYPTED'===a.procType.type){var o,c;switch(a.dekInfo.algorithm){case'DES-CBC':o=8,c=r.des.createDecryptionCipher;break;case'DES-EDE3-CBC':o=24,c=r.des.createDecryptionCipher;break;case'AES-128-CBC':o=16,c=r.aes.createDecryptionCipher;break;case'AES-192-CBC':o=24,c=r.aes.createDecryptionCipher;break;case'AES-256-CBC':o=32,c=r.aes.createDecryptionCipher;break;case'RC2-40-CBC':o=5,c=function(e){return r.rc2.createDecryptionCipher(e,40)};break;case'RC2-64-CBC':o=8,c=function(e){return r.rc2.createDecryptionCipher(e,64)};break;case'RC2-128-CBC':o=16,c=function(e){return r.rc2.createDecryptionCipher(e,128)};break;default:var l;throw(l=new Error('Could not decrypt private key; unsupported encryption algorithm "'+a.dekInfo.algorithm+'".')).algorithm=a.dekInfo.algorithm,l}var h=r.util.hexToBytes(a.dekInfo.parameters),d=c(r.pbe.opensslDeriveBytes(t,h.substr(0,8),o));if(d.start(h),d.update(r.util.createBuffer(a.body)),!d.finish())return i;i=d.output.getBytes()}else i=a.body;return null!==(i='ENCRYPTED PRIVATE KEY'===a.type?n.decryptPrivateKeyInfo(s.fromDer(i),t):s.fromDer(i))&&(i=n.privateKeyFromAsn1(i)),i},n.pbe.generatePkcs12Key=function(e,t,i,s,n,a){var o,c;if(null==a){if(!('sha1'in r.md))throw new Error('"sha1" hash algorithm unavailable.');a=r.md.sha1.create()}var l=a.digestLength,h=a.blockLength,d=new r.util.ByteBuffer,u=new r.util.ByteBuffer;if(null!=e){for(c=0;c=0;c--)P>>=8,P+=S.at(c)+L.at(c),L.setAt(c,255&P);N.putBuffer(L)}A=N,d.putBuffer(C)}return d.truncate(d.length()-n),d},n.pbe.getCipher=function(e,t,i){switch(e){case n.oids.pkcs5PBES2:return n.pbe.getCipherForPBES2(e,t,i);case n.oids['pbeWithSHAAnd3-KeyTripleDES-CBC']:case n.oids['pbewithSHAAnd40BitRC2-CBC']:return n.pbe.getCipherForPKCS12PBE(e,t,i);default:var r=new Error('Cannot read encrypted PBE data block. Unsupported OID.');throw r.oid=e,r.supportedOids=['pkcs5PBES2','pbeWithSHAAnd3-KeyTripleDES-CBC','pbewithSHAAnd40BitRC2-CBC'],r}},n.pbe.getCipherForPBES2=function(e,t,i){var a,o={},l=[];if(!s.validate(t,c,o,l))throw(a=new Error('Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.')).errors=l,a;if((e=s.derToOid(o.kdfOid))!==n.oids.pkcs5PBKDF2)throw(a=new Error('Cannot read encrypted private key. Unsupported key derivation function OID.')).oid=e,a.supportedOids=['pkcs5PBKDF2'],a;if((e=s.derToOid(o.encOid))!==n.oids['aes128-CBC']&&e!==n.oids['aes192-CBC']&&e!==n.oids['aes256-CBC']&&e!==n.oids['des-EDE3-CBC']&&e!==n.oids.desCBC)throw(a=new Error('Cannot read encrypted private key. Unsupported encryption scheme OID.')).oid=e,a.supportedOids=['aes128-CBC','aes192-CBC','aes256-CBC','des-EDE3-CBC','desCBC'],a;var h,u,p=o.kdfSalt,f=r.util.createBuffer(o.kdfIterationCount);switch(f=f.getInt(f.length()<<3),n.oids[e]){case'aes128-CBC':h=16,u=r.aes.createDecryptionCipher;break;case'aes192-CBC':h=24,u=r.aes.createDecryptionCipher;break;case'aes256-CBC':h=32,u=r.aes.createDecryptionCipher;break;case'des-EDE3-CBC':h=24,u=r.des.createDecryptionCipher;break;case'desCBC':h=8,u=r.des.createDecryptionCipher}var g=d(o.prfOid),m=r.pkcs5.pbkdf2(i,p,f,h,g),y=o.encIv,E=u(m);return E.start(y),E},n.pbe.getCipherForPKCS12PBE=function(e,t,i){var a={},o=[];if(!s.validate(t,l,a,o))throw(g=new Error('Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.')).errors=o,g;var c,h,u,p=r.util.createBuffer(a.salt),f=r.util.createBuffer(a.iterations);switch(f=f.getInt(f.length()<<3),e){case n.oids['pbeWithSHAAnd3-KeyTripleDES-CBC']:c=24,h=8,u=r.des.startDecrypting;break;case n.oids['pbewithSHAAnd40BitRC2-CBC']:c=5,h=8,u=function(e,t){var i=r.rc2.createDecryptionCipher(e,40);return i.start(t,null),i};break;default:var g;throw(g=new Error('Cannot read PKCS #12 PBE data block. Unsupported OID.')).oid=e,g}var m=d(a.prfOid),y=n.pbe.generatePkcs12Key(i,p,1,f,c,m);return m.start(),u(y,n.pbe.generatePkcs12Key(i,p,2,f,h,m))},n.pbe.opensslDeriveBytes=function(e,t,i,s){if(null==s){if(!('md5'in r.md))throw new Error('"md5" hash algorithm unavailable.');s=r.md.md5.create()}null===t&&(t='');for(var n=[h(s,e+t)],a=16,o=1;a>8*u-d&255;return(A=String.fromCharCode(A.charCodeAt(0)&~v)+A.substr(1))+g+String.fromCharCode(188)},verify:function(e,a,o){var c,l=o-1,h=Math.ceil(l/8);if(a=a.substr(-h),h>8*h-l&255;if(u.charCodeAt(0)&f)throw new Error('Bits beyond keysize not zero as expected.');var g=s.generate(p,d),m='';for(c=0;c128)throw new Error('Invalid "nsComment" content.');e.value=r.create(r.Class.UNIVERSAL,r.Type.IA5STRING,!1,e.comment)}else if('subjectKeyIdentifier'===e.name&&t.cert){var p=t.cert.generateSubjectKeyIdentifier();e.subjectKeyIdentifier=p.toHex(),e.value=r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,p.getBytes())}else if('authorityKeyIdentifier'===e.name&&t.cert){e.value=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[]);h=e.value.value;if(e.keyIdentifier){var f=!0===e.keyIdentifier?t.cert.generateSubjectKeyIdentifier().getBytes():e.keyIdentifier;h.push(r.create(r.Class.CONTEXT_SPECIFIC,0,!1,f))}if(e.authorityCertIssuer){var g=[r.create(r.Class.CONTEXT_SPECIFIC,4,!0,[T(!0===e.authorityCertIssuer?t.cert.issuer:e.authorityCertIssuer)])];h.push(r.create(r.Class.CONTEXT_SPECIFIC,1,!0,g))}if(e.serialNumber){var m=i.util.hexToBytes(!0===e.serialNumber?t.cert.serialNumber:e.serialNumber);h.push(r.create(r.Class.CONTEXT_SPECIFIC,2,!1,m))}}else if('cRLDistributionPoints'===e.name){e.value=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[]);h=e.value.value;var y,E=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[]),_=r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[]);for(u=0;u2)throw new Error('Cannot read notBefore/notAfter validity times; more than two times were provided in the certificate.');if(d.length<2)throw new Error('Cannot read notBefore/notAfter validity times; they were not provided as either UTCTime or GeneralizedTime.');if(l.validity.notBefore=d[0],l.validity.notAfter=d[1],l.tbsCertificate=n.tbsCertificate,t){l.md=m({signatureOid:l.signatureOid,type:'certificate'});var u=r.toDer(l.tbsCertificate);l.md.update(u.getBytes())}var f=i.md.sha1.create(),y=r.toDer(n.certIssuer);f.update(y.getBytes()),l.issuer.getField=function(e){return p(l.issuer,e)},l.issuer.addField=function(e){S([e]),l.issuer.attributes.push(e)},l.issuer.attributes=s.RDNAttributesAsArray(n.certIssuer),n.certIssuerUniqueId&&(l.issuer.uniqueId=n.certIssuerUniqueId),l.issuer.hash=f.digest().toHex();var E=i.md.sha1.create(),_=r.toDer(n.certSubject);return E.update(_.getBytes()),l.subject.getField=function(e){return p(l.subject,e)},l.subject.addField=function(e){S([e]),l.subject.attributes.push(e)},l.subject.attributes=s.RDNAttributesAsArray(n.certSubject),n.certSubjectUniqueId&&(l.subject.uniqueId=n.certSubjectUniqueId),l.subject.hash=E.digest().toHex(),n.certExtensions?l.extensions=s.certificateExtensionsFromAsn1(n.certExtensions):l.extensions=[],l.publicKey=s.publicKeyFromAsn1(n.subjectPublicKeyInfo),l},s.certificateExtensionsFromAsn1=function(e){for(var t=[],i=0;i1&&(s=c.value.charCodeAt(1),a=c.value.length>2?c.value.charCodeAt(2):0),t.digitalSignature=!(128&~s),t.nonRepudiation=!(64&~s),t.keyEncipherment=!(32&~s),t.dataEncipherment=!(16&~s),t.keyAgreement=!(8&~s),t.keyCertSign=!(4&~s),t.cRLSign=!(2&~s),t.encipherOnly=!(1&~s),t.decipherOnly=!(128&~a)}else if('basicConstraints'===t.name){(c=r.fromDer(t.value)).value.length>0&&c.value[0].type===r.Type.BOOLEAN?t.cA=0!==c.value[0].value.charCodeAt(0):t.cA=!1;var o=null;c.value.length>0&&c.value[0].type===r.Type.INTEGER?o=c.value[0].value:c.value.length>1&&(o=c.value[1].value),null!==o&&(t.pathLenConstraint=r.derToInteger(o))}else if('extKeyUsage'===t.name)for(var c=r.fromDer(t.value),l=0;l1&&(s=c.value.charCodeAt(1)),t.client=!(128&~s),t.server=!(64&~s),t.email=!(32&~s),t.objsign=!(16&~s),t.reserved=!(8&~s),t.sslCA=!(4&~s),t.emailCA=!(2&~s),t.objCA=!(1&~s)}else if('subjectAltName'===t.name||'issuerAltName'===t.name){var d;t.altNames=[];c=r.fromDer(t.value);for(var u=0;u=P&&e0&&a.value.push(s.certificateExtensionsToAsn1(e.extensions)),a},s.getCertificationRequestInfo=function(e){return r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.INTEGER,!1,r.integerToDer(e.version).getBytes()),T(e.subject),s.publicKeyToAsn1(e.publicKey),L(e)])},s.distinguishedNameToAsn1=function(e){return T(e)},s.certificateToAsn1=function(e){var t=e.tbsCertificate||s.getTBSCertificate(e);return r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[t,r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(e.signatureOid).getBytes()),N(e.signatureOid,e.signatureParameters)]),r.create(r.Class.UNIVERSAL,r.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},s.certificateExtensionsToAsn1=function(e){var t=r.create(r.Class.CONTEXT_SPECIFIC,3,!0,[]),i=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[]);t.value.push(i);for(var n=0;nh.validity.notAfter)&&(c={message:'Certificate is not valid yet or has expired.',error:s.certificateError.certificate_expired,notBefore:h.validity.notBefore,notAfter:h.validity.notAfter,now:a}),null===c){if(null===(d=t[0]||e.getIssuer(h))&&h.isIssuer(h)&&(u=!0,d=h),d){var p=d;i.util.isArray(p)||(p=[p]);for(var f=!1;!f&&p.length>0;){d=p.shift();try{f=d.verify(h)}catch(e){}}f||(c={message:'Certificate signature is invalid.',error:s.certificateError.bad_certificate})}null!==c||d&&!u||e.hasCertificate(h)||(c={message:'Certificate is not trusted.',error:s.certificateError.unknown_ca})}if(null===c&&d&&!h.isIssuer(d)&&(c={message:'Certificate issuer is invalid.',error:s.certificateError.bad_certificate}),null===c)for(var g={keyUsage:!0,basicConstraints:!0},m=0;null===c&&mE.pathLenConstraint&&(c={message:'Certificate basicConstraints pathLenConstraint violated.',error:s.certificateError.bad_certificate})}var A=null===c||c.error,v=r.verify?r.verify(A,l,n):A;if(!0!==v)throw!0===A&&(c={message:'The application rejected the certificate.',error:s.certificateError.bad_certificate}),(v||0===v)&&('object'!=typeof v||i.util.isArray(v)?'string'==typeof v&&(c.error=v):(v.message&&(c.message=v.message),v.error&&(c.error=v.error))),c;c=null,o=!1,++l}while(t.length>0);return!0}}}),V=d({'node_modules/node-forge/lib/pkcs12.js'(e,t){var i=u();_(),v(),E(),k(),D(),L(),U(),b(),f(),H();var r=i.asn1,s=i.pki,n=t.exports=i.pkcs12=i.pkcs12||{},a={name:'ContentInfo',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'ContentInfo.contentType',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'contentType'},{name:'ContentInfo.content',tagClass:r.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:'content'}]},o={name:'PFX',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'PFX.version',tagClass:r.Class.UNIVERSAL,type:r.Type.INTEGER,constructed:!1,capture:'version'},a,{name:'PFX.macData',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:'mac',value:[{name:'PFX.macData.mac',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'PFX.macData.mac.digestAlgorithm',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'PFX.macData.mac.digestAlgorithm.algorithm',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'macAlgorithm'},{name:'PFX.macData.mac.digestAlgorithm.parameters',tagClass:r.Class.UNIVERSAL,captureAsn1:'macAlgorithmParameters'}]},{name:'PFX.macData.mac.digest',tagClass:r.Class.UNIVERSAL,type:r.Type.OCTETSTRING,constructed:!1,capture:'macDigest'}]},{name:'PFX.macData.macSalt',tagClass:r.Class.UNIVERSAL,type:r.Type.OCTETSTRING,constructed:!1,capture:'macSalt'},{name:'PFX.macData.iterations',tagClass:r.Class.UNIVERSAL,type:r.Type.INTEGER,constructed:!1,optional:!0,capture:'macIterations'}]}]},c={name:'SafeBag',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'SafeBag.bagId',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'bagId'},{name:'SafeBag.bagValue',tagClass:r.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:'bagValue'},{name:'SafeBag.bagAttributes',tagClass:r.Class.UNIVERSAL,type:r.Type.SET,constructed:!0,optional:!0,capture:'bagAttributes'}]},l={name:'Attribute',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'Attribute.attrId',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'oid'},{name:'Attribute.attrValues',tagClass:r.Class.UNIVERSAL,type:r.Type.SET,constructed:!0,capture:'values'}]},h={name:'CertBag',tagClass:r.Class.UNIVERSAL,type:r.Type.SEQUENCE,constructed:!0,value:[{name:'CertBag.certId',tagClass:r.Class.UNIVERSAL,type:r.Type.OID,constructed:!1,capture:'certId'},{name:'CertBag.certValue',tagClass:r.Class.CONTEXT_SPECIFIC,constructed:!0,value:[{name:'CertBag.certValue[0]',tagClass:r.Class.UNIVERSAL,type:r.Class.OCTETSTRING,constructed:!1,capture:'cert'}]}]};function d(e,t,i,r){for(var s=[],n=0;n=0&&s.push(o):s.push(o))}return s}function p(e){if(e.composed||e.constructed){for(var t=i.util.createBuffer(),r=0;r0&&(c=r.create(r.Class.UNIVERSAL,r.Type.SET,!0,d));var u=[],p=[];null!==t&&(p=i.util.isArray(t)?t:[t]);for(var f=[],g=0;g0){var _=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,f),A=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.data).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,r.toDer(_).getBytes())])]);u.push(A)}var v=null;if(null!==e){var T=s.wrapRsaPrivateKey(s.privateKeyToAsn1(e));v=null===a?r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.keyBag).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[T]),c]):r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.pkcs8ShroudedKeyBag).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[s.encryptPrivateKeyInfo(T,a,o)]),c]);var C=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[v]),I=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.data).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,r.toDer(C).getBytes())])]);u.push(I)}var S,O=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,u);if(o.useMac){var N=i.md.sha1.create(),L=new i.util.ByteBuffer(i.random.getBytes(o.saltSize)),P=o.count,w=(e=n.generateKey(a,L,3,P,20),i.hmac.create());w.start(N,e),w.update(r.toDer(O).getBytes());var b=w.getMac();S=r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.sha1).getBytes()),r.create(r.Class.UNIVERSAL,r.Type.NULL,!1,'')]),r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,b.getBytes())]),r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,L.getBytes()),r.create(r.Class.UNIVERSAL,r.Type.INTEGER,!1,r.integerToDer(P).getBytes())])}return r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.INTEGER,!1,r.integerToDer(3).getBytes()),r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(s.oids.data).getBytes()),r.create(r.Class.CONTEXT_SPECIFIC,0,!0,[r.create(r.Class.UNIVERSAL,r.Type.OCTETSTRING,!1,r.toDer(O).getBytes())])]),S])},n.generateKey=i.pbe.generatePkcs12Key}}),G=d({'node_modules/node-forge/lib/pki.js'(e,t){var i=u();_(),E(),D(),C(),S(),V(),F(),U(),f(),H();var r=i.asn1,s=t.exports=i.pki=i.pki||{};s.pemToDer=function(e){var t=i.pem.decode(e)[0];if(t.procType&&'ENCRYPTED'===t.procType.type)throw new Error('Could not convert PEM to DER; PEM is encrypted.');return i.util.createBuffer(t.body)},s.privateKeyFromPem=function(e){var t=i.pem.decode(e)[0];if('PRIVATE KEY'!==t.type&&'RSA PRIVATE KEY'!==t.type){var n=new Error('Could not convert private key from PEM; PEM header type is not "PRIVATE KEY" or "RSA PRIVATE KEY".');throw n.headerType=t.type,n}if(t.procType&&'ENCRYPTED'===t.procType.type)throw new Error('Could not convert private key from PEM; PEM is encrypted.');var a=r.fromDer(t.body);return s.privateKeyFromAsn1(a)},s.privateKeyToPem=function(e,t){var n={type:'RSA PRIVATE KEY',body:r.toDer(s.privateKeyToAsn1(e)).getBytes()};return i.pem.encode(n,{maxline:t})},s.privateKeyInfoToPem=function(e,t){var s={type:'PRIVATE KEY',body:r.toDer(e).getBytes()};return i.pem.encode(s,{maxline:t})}}}),W=d({'node_modules/node-forge/lib/tls.js'(e,t){var i=u();_(),v(),T(),C(),G(),L(),b(),f();var r=function(e,t,r,s){var n=i.util.createBuffer(),a=e.length>>1,o=a+(1&e.length),c=e.substr(0,o),l=e.substr(a,o),h=i.util.createBuffer(),d=i.hmac.create();r=t+r;var u=Math.ceil(s/16),p=Math.ceil(s/20);d.start('MD5',c);var f=i.util.createBuffer();h.putBytes(r);for(var g=0;g0&&(c.queue(e,c.createAlert(e,{level:c.Alert.Level.warning,description:c.Alert.Description.no_renegotiation})),c.flush(e)),e.process()},c.parseHelloMessage=function(e,t,r){var s=null,n=e.entity===c.ConnectionEnd.client;if(r<38)e.error(e,{message:n?'Invalid ServerHello message. Message too short.':'Invalid ClientHello message. Message too short.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}});else{var o=t.fragment,l=o.length();if(s={version:{major:o.getByte(),minor:o.getByte()},random:i.util.createBuffer(o.getBytes(32)),session_id:a(o,1),extensions:[]},n?(s.cipher_suite=o.getBytes(2),s.compression_method=o.getByte()):(s.cipher_suites=a(o,2),s.compression_methods=a(o,1)),(l=r-(l-o.length()))>0){for(var h=a(o,2);h.length()>0;)s.extensions.push({type:[h.getByte(),h.getByte()],data:a(h,2)});if(!n)for(var d=0;d0;){if(0!==p.getByte())break;e.session.extensions.server_name.serverNameList.push(a(p,2).getBytes())}}}if(e.session.version&&(s.version.major!==e.session.version.major||s.version.minor!==e.session.version.minor))return e.error(e,{message:'TLS version change is disallowed during renegotiation.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.protocol_version}});if(n)e.session.cipherSuite=c.getCipherSuite(s.cipher_suite);else for(var f=i.util.createBuffer(s.cipher_suites.bytes());f.length()>0&&(e.session.cipherSuite=c.getCipherSuite(f.getBytes(2)),null===e.session.cipherSuite););if(null===e.session.cipherSuite)return e.error(e,{message:'No cipher suites in common.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.handshake_failure},cipherSuite:i.util.bytesToHex(s.cipher_suite)});e.session.compressionMethod=n?s.compression_method:c.CompressionMethod.none}return s},c.createSecurityParameters=function(e,t){var i=e.entity===c.ConnectionEnd.client,r=t.random.bytes(),s=i?e.session.sp.client_random:r,n=i?r:c.createRandom().getBytes();e.session.sp={entity:e.entity,prf_algorithm:c.PRFAlgorithm.tls_prf_sha256,bulk_cipher_algorithm:null,cipher_type:null,enc_key_length:null,block_length:null,fixed_iv_length:null,record_iv_length:null,mac_algorithm:null,mac_length:null,mac_key_length:null,compression_algorithm:e.session.compressionMethod,pre_master_secret:null,master_secret:null,client_random:s,server_random:n}},c.handleServerHello=function(e,t,i){var r=c.parseHelloMessage(e,t,i);if(!e.fail){if(!(r.version.minor<=e.version.minor))return e.error(e,{message:'Incompatible TLS version.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.protocol_version}});e.version.minor=r.version.minor,e.session.version=e.version;var s=r.session_id.bytes();s.length>0&&s===e.session.id?(e.expect=g,e.session.resuming=!0,e.session.sp.server_random=r.random.bytes()):(e.expect=l,e.session.resuming=!1,c.createSecurityParameters(e,r)),e.session.id=s,e.process()}},c.handleClientHello=function(e,t,r){var s=c.parseHelloMessage(e,t,r);if(!e.fail){var n=s.session_id.bytes(),a=null;if(e.sessionCache&&(null===(a=e.sessionCache.getSession(n))?n='':(a.version.major!==s.version.major||a.version.minor>s.version.minor)&&(a=null,n='')),0===n.length&&(n=i.random.getBytes(32)),e.session.id=n,e.session.clientHelloVersion=s.version,e.session.sp={},a)e.version=e.session.version=a.version,e.session.sp=a.sp;else{for(var o,l=1;l0;)s=a(l.certificate_list,3),n=i.asn1.fromDer(s),s=i.pki.certificateFromAsn1(n,!0),d.push(s)}catch(t){return e.error(e,{message:'Could not parse certificate list.',cause:t,send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.bad_certificate}})}var u=e.entity===c.ConnectionEnd.client;!u&&!0!==e.verifyClient||0!==d.length?0===d.length?e.expect=u?h:I:(u?e.session.serverCertificate=d[0]:e.session.clientCertificate=d[0],c.verifyCertificateChain(e,d)&&(e.expect=u?h:I)):e.error(e,{message:u?'No server certificate provided.':'No client certificate provided.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}}),e.process()},c.handleServerKeyExchange=function(e,t,i){if(i>0)return e.error(e,{message:'Invalid key parameters. Only RSA is supported.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.unsupported_certificate}});e.expect=d,e.process()},c.handleClientKeyExchange=function(e,t,r){if(r<48)return e.error(e,{message:'Invalid key parameters. Only RSA is supported.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.unsupported_certificate}});var s=t.fragment,n={enc_pre_master_secret:a(s,2).getBytes()},o=null;if(e.getPrivateKey)try{o=e.getPrivateKey(e,e.session.serverCertificate),o=i.pki.privateKeyFromPem(o)}catch(t){e.error(e,{message:'Could not get private key.',cause:t,send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.internal_error}})}if(null===o)return e.error(e,{message:'No private key set.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.internal_error}});try{var l=e.session.sp;l.pre_master_secret=o.decrypt(n.enc_pre_master_secret);var h=e.session.clientHelloVersion;if(h.major!==l.pre_master_secret.charCodeAt(0)||h.minor!==l.pre_master_secret.charCodeAt(1))throw new Error('TLS version rollback attack detected.')}catch(e){l.pre_master_secret=i.random.getBytes(48)}e.expect=O,null!==e.session.clientCertificate&&(e.expect=S),e.process()},c.handleCertificateRequest=function(e,t,i){if(i<3)return e.error(e,{message:'Invalid CertificateRequest. Message too short.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}});var r=t.fragment,s={certificate_types:a(r,1),certificate_authorities:a(r,2)};e.session.certificateRequest=s,e.expect=p,e.process()},c.handleCertificateVerify=function(e,t,r){if(r<2)return e.error(e,{message:'Invalid CertificateVerify. Message too short.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}});var s=t.fragment;s.read-=4;var n=s.bytes();s.read+=4;var o={signature:a(s,2).getBytes()},l=i.util.createBuffer();l.putBuffer(e.session.md5.digest()),l.putBuffer(e.session.sha1.digest()),l=l.getBytes();try{if(!e.session.clientCertificate.publicKey.verify(l,o.signature,'NONE'))throw new Error('CertificateVerify signature does not match.');e.session.md5.update(n),e.session.sha1.update(n)}catch(t){return e.error(e,{message:'Bad signature in CertificateVerify.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.handshake_failure}})}e.expect=O,e.process()},c.handleServerHelloDone=function(e,t,r){if(r>0)return e.error(e,{message:'Invalid ServerHelloDone message. Invalid length.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.record_overflow}});if(null===e.serverCertificate){var s={message:'No server certificate provided. Not enough security.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.insufficient_security}},n=e.verify(e,s.alert.description,0,[]);if(!0!==n)return(n||0===n)&&('object'!=typeof n||i.util.isArray(n)?'number'==typeof n&&(s.alert.description=n):(n.message&&(s.message=n.message),n.alert&&(s.alert.description=n.alert))),e.error(e,s)}null!==e.session.certificateRequest&&(t=c.createRecord(e,{type:c.ContentType.handshake,data:c.createCertificate(e)}),c.queue(e,t)),t=c.createRecord(e,{type:c.ContentType.handshake,data:c.createClientKeyExchange(e)}),c.queue(e,t),e.expect=E;var a=function(e,t){null!==e.session.certificateRequest&&null!==e.session.clientCertificate&&c.queue(e,c.createRecord(e,{type:c.ContentType.handshake,data:c.createCertificateVerify(e,t)})),c.queue(e,c.createRecord(e,{type:c.ContentType.change_cipher_spec,data:c.createChangeCipherSpec()})),e.state.pending=c.createConnectionState(e),e.state.current.write=e.state.pending.write,c.queue(e,c.createRecord(e,{type:c.ContentType.handshake,data:c.createFinished(e)})),e.expect=g,c.flush(e),e.process()};if(null===e.session.certificateRequest||null===e.session.clientCertificate)return a(e,null);c.getClientSignature(e,a)},c.handleChangeCipherSpec=function(e,t){if(1!==t.fragment.getByte())return e.error(e,{message:'Invalid ChangeCipherSpec message received.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.illegal_parameter}});var i=e.entity===c.ConnectionEnd.client;(e.session.resuming&&i||!e.session.resuming&&!i)&&(e.state.pending=c.createConnectionState(e)),e.state.current.read=e.state.pending.read,(!e.session.resuming&&i||e.session.resuming&&!i)&&(e.state.pending=null),e.expect=i?m:N,e.process()},c.handleFinished=function(e,t,s){var n=t.fragment;n.read-=4;var a=n.bytes();n.read+=4;var o=t.fragment.getBytes();(n=i.util.createBuffer()).putBuffer(e.session.md5.digest()),n.putBuffer(e.session.sha1.digest());var l=e.entity===c.ConnectionEnd.client,h=l?'server finished':'client finished',d=e.session.sp;if((n=r(d.master_secret,h,n.getBytes(),12)).getBytes()!==o)return e.error(e,{message:'Invalid verify_data in Finished message.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.decrypt_error}});e.session.md5.update(a),e.session.sha1.update(a),(e.session.resuming&&l||!e.session.resuming&&!l)&&(c.queue(e,c.createRecord(e,{type:c.ContentType.change_cipher_spec,data:c.createChangeCipherSpec()})),e.state.current.write=e.state.pending.write,e.state.pending=null,c.queue(e,c.createRecord(e,{type:c.ContentType.handshake,data:c.createFinished(e)}))),e.expect=l?y:P,e.handshaking=!1,++e.handshakes,e.peerCertificate=l?e.session.serverCertificate:e.session.clientCertificate,c.flush(e),e.isConnected=!0,e.connected(e),e.process()},c.handleAlert=function(e,t){var i,r=t.fragment,s={level:r.getByte(),description:r.getByte()};switch(s.description){case c.Alert.Description.close_notify:i='Connection closed.';break;case c.Alert.Description.unexpected_message:i='Unexpected message.';break;case c.Alert.Description.bad_record_mac:i='Bad record MAC.';break;case c.Alert.Description.decryption_failed:i='Decryption failed.';break;case c.Alert.Description.record_overflow:i='Record overflow.';break;case c.Alert.Description.decompression_failure:i='Decompression failed.';break;case c.Alert.Description.handshake_failure:i='Handshake failure.';break;case c.Alert.Description.bad_certificate:i='Bad certificate.';break;case c.Alert.Description.unsupported_certificate:i='Unsupported certificate.';break;case c.Alert.Description.certificate_revoked:i='Certificate revoked.';break;case c.Alert.Description.certificate_expired:i='Certificate expired.';break;case c.Alert.Description.certificate_unknown:i='Certificate unknown.';break;case c.Alert.Description.illegal_parameter:i='Illegal parameter.';break;case c.Alert.Description.unknown_ca:i='Unknown certificate authority.';break;case c.Alert.Description.access_denied:i='Access denied.';break;case c.Alert.Description.decode_error:i='Decode error.';break;case c.Alert.Description.decrypt_error:i='Decrypt error.';break;case c.Alert.Description.export_restriction:i='Export restriction.';break;case c.Alert.Description.protocol_version:i='Unsupported protocol version.';break;case c.Alert.Description.insufficient_security:i='Insufficient security.';break;case c.Alert.Description.internal_error:i='Internal error.';break;case c.Alert.Description.user_canceled:i='User canceled.';break;case c.Alert.Description.no_renegotiation:i='Renegotiation not supported.';break;default:i='Unknown error.'}if(s.description===c.Alert.Description.close_notify)return e.close();e.error(e,{message:i,send:!1,origin:e.entity===c.ConnectionEnd.client?'server':'client',alert:s}),e.process()},c.handleHandshake=function(e,t){var r=t.fragment,s=r.getByte(),n=r.getInt24();if(n>r.length())return e.fragmented=t,t.fragment=i.util.createBuffer(),r.read-=4,e.process();e.fragmented=null,r.read-=4;var a=r.bytes(n+4);r.read+=4,s in j[e.entity][e.expect]?(e.entity!==c.ConnectionEnd.server||e.open||e.fail||(e.handshaking=!0,e.session={version:null,extensions:{server_name:{serverNameList:[]}},cipherSuite:null,compressionMethod:null,serverCertificate:null,clientCertificate:null,md5:i.md.md5.create(),sha1:i.md.sha1.create()}),s!==c.HandshakeType.hello_request&&s!==c.HandshakeType.certificate_verify&&s!==c.HandshakeType.finished&&(e.session.md5.update(a),e.session.sha1.update(a)),j[e.entity][e.expect][s](e,t,n)):c.handleUnexpected(e,t)},c.handleApplicationData=function(e,t){e.data.putBuffer(t.fragment),e.dataReady(e),e.process()},c.handleHeartbeat=function(e,t){var r=t.fragment,s=r.getByte(),n=r.getInt16(),a=r.getBytes(n);if(s===c.HeartbeatMessageType.heartbeat_request){if(e.handshaking||n>a.length)return e.process();c.queue(e,c.createRecord(e,{type:c.ContentType.heartbeat,data:c.createHeartbeat(c.HeartbeatMessageType.heartbeat_response,a)})),c.flush(e)}else if(s===c.HeartbeatMessageType.heartbeat_response){if(a!==e.expectedHeartbeatPayload)return e.process();e.heartbeatReceived&&e.heartbeatReceived(e,i.util.createBuffer(a))}e.process()};var l=1,h=2,d=3,p=4,g=5,m=6,y=7,E=8,A=1,I=2,S=3,O=4,N=5,P=6,w=c.handleUnexpected,R=c.handleChangeCipherSpec,B=c.handleAlert,U=c.handleHandshake,D=c.handleApplicationData,k=c.handleHeartbeat,M=[];M[c.ConnectionEnd.client]=[[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[R,B,w,w,k],[w,B,U,w,k],[w,B,U,D,k],[w,B,U,w,k]],M[c.ConnectionEnd.server]=[[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[w,B,U,w,k],[R,B,w,w,k],[w,B,U,w,k],[w,B,U,D,k],[w,B,U,w,k]];var x=c.handleHelloRequest,F=c.handleServerHello,H=c.handleCertificate,V=c.handleServerKeyExchange,W=c.handleCertificateRequest,K=c.handleServerHelloDone,z=c.handleFinished,j=[];j[c.ConnectionEnd.client]=[[w,w,F,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,H,V,W,K,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,V,W,K,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,W,K,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,K,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,z],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[x,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w]];var Y=c.handleClientHello,q=c.handleClientKeyExchange,Q=c.handleCertificateVerify;j[c.ConnectionEnd.server]=[[w,Y,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,H,w,w,w,w,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,q,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,Q,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,z],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w],[w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w,w]],c.generateKeys=function(e,t){var i=r,s=t.client_random+t.server_random;e.session.resuming||(t.master_secret=i(t.pre_master_secret,'master secret',s,48).bytes(),t.pre_master_secret=null),s=t.server_random+t.client_random;var n=2*t.mac_key_length+2*t.enc_key_length,a=e.version.major===c.Versions.TLS_1_0.major&&e.version.minor===c.Versions.TLS_1_0.minor;a&&(n+=2*t.fixed_iv_length);var o=i(t.master_secret,'key expansion',s,n),l={client_write_MAC_key:o.getBytes(t.mac_key_length),server_write_MAC_key:o.getBytes(t.mac_key_length),client_write_key:o.getBytes(t.enc_key_length),server_write_key:o.getBytes(t.enc_key_length)};return a&&(l.client_write_IV=o.getBytes(t.fixed_iv_length),l.server_write_IV=o.getBytes(t.fixed_iv_length)),l},c.createConnectionState=function(e){var t=e.entity===c.ConnectionEnd.client,i=function(){var e={sequenceNumber:[0,0],macKey:null,macLength:0,macFunction:null,cipherState:null,cipherFunction:function(e){return!0},compressionState:null,compressFunction:function(e){return!0},updateSequenceNumber:function(){4294967295===e.sequenceNumber[1]?(e.sequenceNumber[1]=0,++e.sequenceNumber[0]):++e.sequenceNumber[1]}};return e},r={read:i(),write:i()};if(r.read.update=function(e,t){return r.read.cipherFunction(t,r.read)?r.read.compressFunction(e,t,r.read)||e.error(e,{message:'Could not decompress record.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.decompression_failure}}):e.error(e,{message:'Could not decrypt record or bad MAC.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.bad_record_mac}}),!e.fail},r.write.update=function(e,t){return r.write.compressFunction(e,t,r.write)?r.write.cipherFunction(t,r.write)||e.error(e,{message:'Could not encrypt record.',send:!1,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.internal_error}}):e.error(e,{message:'Could not compress record.',send:!1,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.internal_error}}),!e.fail},e.session){var a=e.session.sp;switch(e.session.cipherSuite.initSecurityParameters(a),a.keys=c.generateKeys(e,a),r.read.macKey=t?a.keys.server_write_MAC_key:a.keys.client_write_MAC_key,r.write.macKey=t?a.keys.client_write_MAC_key:a.keys.server_write_MAC_key,e.session.cipherSuite.initConnectionState(r,e,a),a.compression_algorithm){case c.CompressionMethod.none:break;case c.CompressionMethod.deflate:r.read.compressFunction=n,r.write.compressFunction=s;break;default:throw new Error('Unsupported compression algorithm.')}}return r},c.createRandom=function(){var e=new Date,t=+e+6e4*e.getTimezoneOffset(),r=i.util.createBuffer();return r.putInt32(t),r.putBytes(i.random.getBytes(28)),r},c.createRecord=function(e,t){return t.data?{type:t.type,version:{major:e.version.major,minor:e.version.minor},length:t.data.length(),fragment:t.data}:null},c.createAlert=function(e,t){var r=i.util.createBuffer();return r.putByte(t.level),r.putByte(t.description),c.createRecord(e,{type:c.ContentType.alert,data:r})},c.createClientHello=function(e){e.session.clientHelloVersion={major:e.version.major,minor:e.version.minor};for(var t=i.util.createBuffer(),r=0;r0&&(f+=2);var g=e.session.id,m=g.length+1+2+4+28+2+n+1+l+f,y=i.util.createBuffer();return y.putByte(c.HandshakeType.client_hello),y.putInt24(m),y.putByte(e.version.major),y.putByte(e.version.minor),y.putBytes(e.session.sp.client_random),o(y,1,i.util.createBuffer(g)),o(y,2,t),o(y,1,a),f>0&&o(y,2,h),y},c.createServerHello=function(e){var t=e.session.id,r=t.length+1+2+4+28+2+1,s=i.util.createBuffer();return s.putByte(c.HandshakeType.server_hello),s.putInt24(r),s.putByte(e.version.major),s.putByte(e.version.minor),s.putBytes(e.session.sp.server_random),o(s,1,i.util.createBuffer(t)),s.putByte(e.session.cipherSuite.id[0]),s.putByte(e.session.cipherSuite.id[1]),s.putByte(e.session.compressionMethod),s},c.createCertificate=function(e){var t,r=e.entity===c.ConnectionEnd.client,s=null;e.getCertificate&&(t=r?e.session.certificateRequest:e.session.extensions.server_name.serverNameList,s=e.getCertificate(e,t));var n=i.util.createBuffer();if(null!==s)try{i.util.isArray(s)||(s=[s]);for(var a=null,l=0;lc.MaxFragment;)s.push(c.createRecord(e,{type:t.type,data:i.util.createBuffer(n.slice(0,c.MaxFragment))})),n=n.slice(c.MaxFragment);n.length>0&&s.push(c.createRecord(e,{type:t.type,data:i.util.createBuffer(n)}))}for(var a=0;a0&&(s=r.order[0]),null!==s&&s in r.cache)for(var n in t=r.cache[s],delete r.cache[s],r.order)if(r.order[n]===s){r.order.splice(n,1);break}return t},r.setSession=function(e,t){if(r.order.length===r.capacity){var s=r.order.shift();delete r.cache[s]}s=i.util.bytesToHex(e);r.order.push(s),r.cache[s]=t}}return r},c.createConnection=function(e){var t=null;t=e.caStore?i.util.isArray(e.caStore)?i.pki.createCaStore(e.caStore):e.caStore:i.pki.createCaStore();var r=e.cipherSuites||null;if(null===r)for(var s in r=[],c.CipherSuites)r.push(c.CipherSuites[s]);var n=e.server?c.ConnectionEnd.server:c.ConnectionEnd.client,a=e.sessionCache?c.createSessionCache(e.sessionCache):null,o={version:{major:c.Version.major,minor:c.Version.minor},entity:n,sessionId:e.sessionId,caStore:t,sessionCache:a,cipherSuites:r,connected:e.connected,virtualHost:e.virtualHost||null,verifyClient:e.verifyClient||!1,verify:e.verify||function(e,t,i,r){return t},verifyOptions:e.verifyOptions||{},getCertificate:e.getCertificate||null,getPrivateKey:e.getPrivateKey||null,getSignature:e.getSignature||null,input:i.util.createBuffer(),tlsData:i.util.createBuffer(),data:i.util.createBuffer(),tlsDataReady:e.tlsDataReady,dataReady:e.dataReady,heartbeatReceived:e.heartbeatReceived,closed:e.closed,error:function(t,i){i.origin=i.origin||(t.entity===c.ConnectionEnd.client?'client':'server'),i.send&&(c.queue(t,c.createAlert(t,i.alert)),c.flush(t));var r=!1!==i.fatal;r&&(t.fail=!0),e.error(t,i),r&&t.close(!1)},deflate:e.deflate||null,inflate:e.inflate||null,reset:function(e){o.version={major:c.Version.major,minor:c.Version.minor},o.record=null,o.session=null,o.peerCertificate=null,o.state={pending:null,current:null},o.expect=(o.entity,c.ConnectionEnd.client,0),o.fragmented=null,o.records=[],o.open=!1,o.handshakes=0,o.handshaking=!1,o.isConnected=!1,o.fail=!(e||void 0===e),o.input.clear(),o.tlsData.clear(),o.data.clear(),o.state.current=c.createConnectionState(o)}};o.reset();return o.handshake=function(e){if(o.entity!==c.ConnectionEnd.client)o.error(o,{message:'Cannot initiate handshake as a server.',fatal:!1});else if(o.handshaking)o.error(o,{message:'Handshake already in progress.',fatal:!1});else{o.fail&&!o.open&&0===o.handshakes&&(o.fail=!1),o.handshaking=!0;var t=null;(e=e||'').length>0&&(o.sessionCache&&(t=o.sessionCache.getSession(e)),null===t&&(e='')),0===e.length&&o.sessionCache&&null!==(t=o.sessionCache.getSession())&&(e=t.id),o.session={id:e,version:null,cipherSuite:null,compressionMethod:null,serverCertificate:null,certificateRequest:null,clientCertificate:null,sp:{},md5:i.md.md5.create(),sha1:i.md.sha1.create()},t&&(o.version=t.version,o.session.sp=t.sp),o.session.sp.client_random=c.createRandom().getBytes(),o.open=!0,c.queue(o,c.createRecord(o,{type:c.ContentType.handshake,data:c.createClientHello(o)})),c.flush(o)}},o.process=function(e){var t,r,s,n,a=0;return e&&o.input.putBytes(e),o.fail||(null!==o.record&&o.record.ready&&o.record.fragment.isEmpty()&&(o.record=null),null===o.record&&(a=function(e){var t=0,r=e.input,s=r.length();if(s<5)t=5-s;else{e.record={type:r.getByte(),version:{major:r.getByte(),minor:r.getByte()},length:r.getInt16(),fragment:i.util.createBuffer(),ready:!1};var n=e.record.version.major===e.version.major;n&&e.session&&e.session.version&&(n=e.record.version.minor===e.version.minor),n||e.error(e,{message:'Incompatible TLS version.',send:!0,alert:{level:c.Alert.Level.fatal,description:c.Alert.Description.protocol_version}})}return t}(o)),o.fail||null===o.record||o.record.ready||(a=function(e){var t=0,i=e.input,r=i.length();return r=r.Versions.TLS_1_1.minor&&c.output.putBytes(s),c.update(e.fragment),c.finish(a)&&(e.fragment=c.output,e.length=e.fragment.length(),n=!0),n}function a(e,t,i){if(!i){var r=e-t.length()%e;t.fillWithByte(r-1,r)}return!0}function o(e,t,i){var r=!0;if(i){for(var s=t.length(),n=t.last(),a=s-1-n;a=c?(e.fragment=a.output.getBytes(h-c),l=a.output.getBytes(c)):e.fragment=a.output.getBytes(),e.fragment=i.util.createBuffer(e.fragment),e.length=e.fragment.length();var d=t.macFunction(t.macKey,t.sequenceNumber,e);return t.updateSequenceNumber(),n=function(e,t,r){var s=i.hmac.create();return s.start('SHA1',e),s.update(t),t=s.digest().getBytes(),s.start(null,null),s.update(r),r=s.digest().getBytes(),t===r}(t.macKey,l,d)&&n,n}r.CipherSuites.TLS_RSA_WITH_AES_128_CBC_SHA={id:[0,47],name:'TLS_RSA_WITH_AES_128_CBC_SHA',initSecurityParameters:function(e){e.bulk_cipher_algorithm=r.BulkCipherAlgorithm.aes,e.cipher_type=r.CipherType.block,e.enc_key_length=16,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=r.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:s},r.CipherSuites.TLS_RSA_WITH_AES_256_CBC_SHA={id:[0,53],name:'TLS_RSA_WITH_AES_256_CBC_SHA',initSecurityParameters:function(e){e.bulk_cipher_algorithm=r.BulkCipherAlgorithm.aes,e.cipher_type=r.CipherType.block,e.enc_key_length=32,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=r.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:s}}}),z=d({'node_modules/node-forge/lib/sha512.js'(e,t){var i=u();A(),f();var r=t.exports=i.sha512=i.sha512||{};i.md.sha512=i.md.algorithms.sha512=r;var s=i.sha384=i.sha512.sha384=i.sha512.sha384||{};s.create=function(){return r.create('SHA-384')},i.md.sha384=i.md.algorithms.sha384=s,i.sha512.sha256=i.sha512.sha256||{create:function(){return r.create('SHA-512/256')}},i.md['sha512/256']=i.md.algorithms['sha512/256']=i.sha512.sha256,i.sha512.sha224=i.sha512.sha224||{create:function(){return r.create('SHA-512/224')}},i.md['sha512/224']=i.md.algorithms['sha512/224']=i.sha512.sha224,r.create=function(e){if(a||(n=String.fromCharCode(128),n+=i.util.fillString(String.fromCharCode(0),128),o=[[1116352408,3609767458],[1899447441,602891725],[3049323471,3964484399],[3921009573,2173295548],[961987163,4081628472],[1508970993,3053834265],[2453635748,2937671579],[2870763221,3664609560],[3624381080,2734883394],[310598401,1164996542],[607225278,1323610764],[1426881987,3590304994],[1925078388,4068182383],[2162078206,991336113],[2614888103,633803317],[3248222580,3479774868],[3835390401,2666613458],[4022224774,944711139],[264347078,2341262773],[604807628,2007800933],[770255983,1495990901],[1249150122,1856431235],[1555081692,3175218132],[1996064986,2198950837],[2554220882,3999719339],[2821834349,766784016],[2952996808,2566594879],[3210313671,3203337956],[3336571891,1034457026],[3584528711,2466948901],[113926993,3758326383],[338241895,168717936],[666307205,1188179964],[773529912,1546045734],[1294757372,1522805485],[1396182291,2643833823],[1695183700,2343527390],[1986661051,1014477480],[2177026350,1206759142],[2456956037,344077627],[2730485921,1290863460],[2820302411,3158454273],[3259730800,3505952657],[3345764771,106217008],[3516065817,3606008344],[3600352804,1432725776],[4094571909,1467031594],[275423344,851169720],[430227734,3100823752],[506948616,1363258195],[659060556,3750685593],[883997877,3785050280],[958139571,3318307427],[1322822218,3812723403],[1537002063,2003034995],[1747873779,3602036899],[1955562222,1575990012],[2024104815,1125592928],[2227730452,2716904306],[2361852424,442776044],[2428436474,593698344],[2756734187,3733110249],[3204031479,2999351573],[3329325298,3815920427],[3391569614,3928383900],[3515267271,566280711],[3940187606,3454069534],[4118630271,4000239992],[116418474,1914138554],[174292421,2731055270],[289380356,3203993006],[460393269,320620315],[685471733,587496836],[852142971,1086792851],[1017036298,365543100],[1126000580,2618297676],[1288033470,3409855158],[1501505948,4234509866],[1607167915,987167468],[1816402316,1246189591]],(c={})['SHA-512']=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]],c['SHA-384']=[[3418070365,3238371032],[1654270250,914150663],[2438529370,812702999],[355462360,4144912697],[1731405415,4290775857],[2394180231,1750603025],[3675008525,1694076839],[1203062813,3204075428]],c['SHA-512/256']=[[573645204,4230739756],[2673172387,3360449730],[596883563,1867755857],[2520282905,1497426621],[2519219938,2827943907],[3193839141,1401305490],[721525244,746961066],[246885852,2177182882]],c['SHA-512/224']=[[2352822216,424955298],[1944164710,2312950998],[502970286,855612546],[1738396948,1479516111],[258812777,2077511080],[2011393907,79989058],[1067287976,1780299464],[286451373,2446758561]],a=!0),void 0===e&&(e='SHA-512'),!(e in c))throw new Error('Invalid SHA-512 algorithm: '+e);for(var t=c[e],r=null,s=i.util.createBuffer(),h=new Array(80),d=0;d<80;++d)h[d]=new Array(2);var u=64;switch(e){case'SHA-384':u=48;break;case'SHA-512/256':u=32;break;case'SHA-512/224':u=28}var p={algorithm:e.replace('-','').toLowerCase(),blockLength:128,digestLength:u,messageLength:0,fullMessageLength:null,messageLengthSize:16,start:function(){p.messageLength=0,p.fullMessageLength=p.messageLength128=[];for(var e=p.messageLengthSize/4,n=0;n>>0,n>>>0];for(var a=p.fullMessageLength.length-1;a>=0;--a)p.fullMessageLength[a]+=n[1],n[1]=n[0]+(p.fullMessageLength[a]/4294967296>>>0),p.fullMessageLength[a]=p.fullMessageLength[a]>>>0,n[0]=n[1]/4294967296>>>0;return s.putBytes(e),l(r,h,s),(s.read>2048||0===s.length())&&s.compact(),p},p.digest=function(){var t=i.util.createBuffer();t.putBytes(s.bytes());var a,o=p.fullMessageLength[p.fullMessageLength.length-1]+p.messageLengthSize&p.blockLength-1;t.putBytes(n.substr(0,p.blockLength-o));for(var c=8*p.fullMessageLength[0],d=0;d>>0,t.putInt32(c>>>0),c=a>>>0;t.putInt32(c);var u=new Array(r.length);for(d=0;d=128;){for(w=0;w<16;++w)t[w][0]=i.getInt32()>>>0,t[w][1]=i.getInt32()>>>0;for(;w<80;++w)r=(((b=(B=t[w-2])[0])>>>19|(R=B[1])<<13)^(R>>>29|b<<3)^b>>>6)>>>0,s=((b<<13|R>>>19)^(R<<3|b>>>29)^(b<<26|R>>>6))>>>0,n=(((b=(D=t[w-15])[0])>>>1|(R=D[1])<<31)^(b>>>8|R<<24)^b>>>7)>>>0,a=((b<<31|R>>>1)^(b<<24|R>>>8)^(b<<25|R>>>7))>>>0,U=t[w-7],k=t[w-16],R=s+U[1]+a+k[1],t[w][0]=r+U[0]+n+k[0]+(R/4294967296>>>0)>>>0,t[w][1]=R>>>0;for(f=e[0][0],g=e[0][1],m=e[1][0],y=e[1][1],E=e[2][0],_=e[2][1],A=e[3][0],v=e[3][1],T=e[4][0],C=e[4][1],I=e[5][0],S=e[5][1],O=e[6][0],N=e[6][1],L=e[7][0],P=e[7][1],w=0;w<80;++w)h=((T>>>14|C<<18)^(T>>>18|C<<14)^(C>>>9|T<<23))>>>0,d=(O^T&(I^O))>>>0,c=((f>>>28|g<<4)^(g>>>2|f<<30)^(g>>>7|f<<25))>>>0,l=((f<<4|g>>>28)^(g<<30|f>>>2)^(g<<25|f>>>7))>>>0,u=(f&m|E&(f^m))>>>0,p=(g&y|_&(g^y))>>>0,R=P+(((T<<18|C>>>14)^(T<<14|C>>>18)^(C<<23|T>>>9))>>>0)+((N^C&(S^N))>>>0)+o[w][1]+t[w][1],r=L+h+d+o[w][0]+t[w][0]+(R/4294967296>>>0)>>>0,s=R>>>0,n=c+u+((R=l+p)/4294967296>>>0)>>>0,a=R>>>0,L=O,P=N,O=I,N=S,I=T,S=C,T=A+r+((R=v+s)/4294967296>>>0)>>>0,C=R>>>0,A=E,v=_,E=m,_=y,m=f,y=g,f=r+n+((R=s+a)/4294967296>>>0)>>>0,g=R>>>0;R=e[0][1]+g,e[0][0]=e[0][0]+f+(R/4294967296>>>0)>>>0,e[0][1]=R>>>0,R=e[1][1]+y,e[1][0]=e[1][0]+m+(R/4294967296>>>0)>>>0,e[1][1]=R>>>0,R=e[2][1]+_,e[2][0]=e[2][0]+E+(R/4294967296>>>0)>>>0,e[2][1]=R>>>0,R=e[3][1]+v,e[3][0]=e[3][0]+A+(R/4294967296>>>0)>>>0,e[3][1]=R>>>0,R=e[4][1]+C,e[4][0]=e[4][0]+T+(R/4294967296>>>0)>>>0,e[4][1]=R>>>0,R=e[5][1]+S,e[5][0]=e[5][0]+I+(R/4294967296>>>0)>>>0,e[5][1]=R>>>0,R=e[6][1]+N,e[6][0]=e[6][0]+O+(R/4294967296>>>0)>>>0,e[6][1]=R>>>0,R=e[7][1]+P,e[7][0]=e[7][0]+L+(R/4294967296>>>0)>>>0,e[7][1]=R>>>0,M-=128}}}}),j=d({'node_modules/node-forge/lib/asn1-validator.js'(e){var t=u();_();var i=t.asn1;e.privateKeyValidator={name:'PrivateKeyInfo',tagClass:i.Class.UNIVERSAL,type:i.Type.SEQUENCE,constructed:!0,value:[{name:'PrivateKeyInfo.version',tagClass:i.Class.UNIVERSAL,type:i.Type.INTEGER,constructed:!1,capture:'privateKeyVersion'},{name:'PrivateKeyInfo.privateKeyAlgorithm',tagClass:i.Class.UNIVERSAL,type:i.Type.SEQUENCE,constructed:!0,value:[{name:'AlgorithmIdentifier.algorithm',tagClass:i.Class.UNIVERSAL,type:i.Type.OID,constructed:!1,capture:'privateKeyOid'}]},{name:'PrivateKeyInfo',tagClass:i.Class.UNIVERSAL,type:i.Type.OCTETSTRING,constructed:!1,capture:'privateKey'}]},e.publicKeyValidator={name:'SubjectPublicKeyInfo',tagClass:i.Class.UNIVERSAL,type:i.Type.SEQUENCE,constructed:!0,captureAsn1:'subjectPublicKeyInfo',value:[{name:'SubjectPublicKeyInfo.AlgorithmIdentifier',tagClass:i.Class.UNIVERSAL,type:i.Type.SEQUENCE,constructed:!0,value:[{name:'AlgorithmIdentifier.algorithm',tagClass:i.Class.UNIVERSAL,type:i.Type.OID,constructed:!1,capture:'publicKeyOid'}]},{tagClass:i.Class.UNIVERSAL,type:i.Type.BITSTRING,constructed:!1,composed:!0,captureBitStringValue:'ed25519PublicKey'}]}}}),Y=d({'node_modules/node-forge/lib/ed25519.js'(e,t){var i=u();w(),L(),z(),f();var r,s=j(),n=s.publicKeyValidator,a=s.privateKeyValidator;void 0===r&&(r=i.jsbn.BigInteger);var o=i.util.ByteBuffer,c='undefined'==typeof Buffer?Uint8Array:Buffer;i.pki=i.pki||{},t.exports=i.pki.ed25519=i.ed25519=i.ed25519||{};var l=i.ed25519;function h(e){var t=e.message;if(t instanceof Uint8Array||t instanceof c)return t;var i=e.encoding;if(void 0===t){if(!e.md)throw new TypeError('"options.message" or "options.md" not specified.');t=e.md.digest().getBytes(),i='binary'}if('string'==typeof t&&!i)throw new TypeError('"options.encoding" must be "binary" or "utf8".');if('string'==typeof t){if('undefined'!=typeof Buffer)return Buffer.from(t,i);t=new o(t,i)}else if(!(t instanceof o))throw new TypeError('"options.message" must be a node.js Buffer, a Uint8Array, a forge ByteBuffer, or a string with "options.encoding" specifying its encoding.');for(var r=new c(t.length()),s=0;s=0;--i)V(r,r),1!==i&&G(r,r,t);for(i=0;i<16;++i)e[i]=r[i]}(i,i),G(i,i,s),G(i,i,n),G(i,i,n),G(e[0],i,n),V(r,e[0]),G(r,r,n),P(r,s)&&G(e[0],e[0],A);if(V(r,e[0]),G(r,r,n),P(r,s))return-1;R(e[0])===t[31]>>7&&H(e[0],d,e[0]);return G(e[3],e[0],e[1]),0}(o,r))return-1;for(s=0;s=0};var d=x(),p=x([1]),g=x([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),m=x([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),y=x([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),E=x([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),_=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]),A=x([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function v(e,t){var r=i.md.sha512.create(),s=new o(e);r.update(s.getBytes(t),'binary');var n=r.digest().getBytes();if('undefined'!=typeof Buffer)return Buffer.from(n,'binary');for(var a=new c(l.constants.HASH_BYTE_LENGTH),h=0;h<64;++h)a[h]=n.charCodeAt(h);return a}function T(e,t){var i,r,s,n;for(r=63;r>=32;--r){for(i=0,s=r-32,n=r-12;s>8,t[s]-=256*i;t[s]+=i,t[r]=0}for(i=0,s=0;s<32;++s)t[s]+=i-(t[31]>>4)*_[s],i=t[s]>>8,t[s]&=255;for(s=0;s<32;++s)t[s]-=i*_[s];for(r=0;r<32;++r)t[r+1]+=t[r]>>8,e[r]=255&t[r]}function C(e){for(var t=new Float64Array(64),i=0;i<64;++i)t[i]=e[i],e[i]=0;T(e,t)}function I(e,t){var i=x(),r=x(),s=x(),n=x(),a=x(),o=x(),c=x(),l=x(),h=x();H(i,e[1],e[0]),H(h,t[1],t[0]),G(i,i,h),F(r,e[0],e[1]),F(h,t[0],t[1]),G(r,r,h),G(s,e[3],t[3]),G(s,s,m),G(n,e[2],t[2]),F(n,n,n),H(a,r,i),H(o,n,s),F(c,n,s),F(l,r,i),G(e[0],a,o),G(e[1],l,c),G(e[2],c,o),G(e[3],a,l)}function S(e,t,i){for(var r=0;r<4;++r)M(e[r],t[r],i)}function O(e,t){var i=x(),r=x(),s=x();!function(e,t){var i,r=x();for(i=0;i<16;++i)r[i]=t[i];for(i=253;i>=0;--i)V(r,r),2!==i&&4!==i&&G(r,r,t);for(i=0;i<16;++i)e[i]=r[i]}(s,t[2]),G(i,t[0],s),G(r,t[1],s),N(e,r),e[31]^=R(i)<<7}function N(e,t){var i,r,s,n=x(),a=x();for(i=0;i<16;++i)a[i]=t[i];for(k(a),k(a),k(a),r=0;r<2;++r){for(n[0]=a[0]-65517,i=1;i<15;++i)n[i]=a[i]-65535-(n[i-1]>>16&1),n[i-1]&=65535;n[15]=a[15]-32767-(n[14]>>16&1),s=n[15]>>16&1,n[14]&=65535,M(a,n,1-s)}for(i=0;i<16;i++)e[2*i]=255&a[i],e[2*i+1]=a[i]>>8}function P(e,t){var i=new c(32),r=new c(32);return N(i,e),N(r,t),b(i,0,r,0)}function b(e,t,i,r){return function(e,t,i,r,s){var n,a=0;for(n=0;n>>8)-1}(e,t,i,r,32)}function R(e){var t=new c(32);return N(t,e),1&t[0]}function B(e,t,i){var r,s;for(D(e[0],d),D(e[1],p),D(e[2],p),D(e[3],d),s=255;s>=0;--s)S(e,t,r=i[s/8|0]>>(7&s)&1),I(t,e),I(e,e),S(e,t,r)}function U(e,t){var i=[x(),x(),x(),x()];D(i[0],y),D(i[1],E),D(i[2],p),G(i[3],y,E),B(e,i,t)}function D(e,t){var i;for(i=0;i<16;i++)e[i]=0|t[i]}function k(e){var t,i,r=1;for(t=0;t<16;++t)i=e[t]+r+65535,r=Math.floor(i/65536),e[t]=i-65536*r;e[0]+=r-1+37*(r-1)}function M(e,t,i){for(var r,s=~(i-1),n=0;n<16;++n)r=s&(e[n]^t[n]),e[n]^=r,t[n]^=r}function x(e){var t,i=new Float64Array(16);if(e)for(t=0;t0&&(a=i.util.fillString(String.fromCharCode(0),c)+a),{encapsulation:t.encrypt(a,'NONE'),key:e.generate(a,n)}},decrypt:function(t,i,r){var s=t.decrypt(i,'NONE');return e.generate(s,r)}};return n},i.kem.kdf1=function(e,t){s(this,e,0,t||e.digestLength)},i.kem.kdf2=function(e,t){s(this,e,1,t||e.digestLength)}}}),Q=d({'node_modules/node-forge/lib/log.js'(e,t){var i=u();f(),t.exports=i.log=i.log||{},i.log.levels=['none','error','warning','info','debug','verbose','max'];var r,s,n,a,o,c,l,h={},d=[],p=null;for(i.log.LEVEL_LOCKED=2,i.log.NO_LEVEL_CHECK=4,i.log.INTERPOLATE=8,n=0;n0){for(var s=r.create(r.Class.CONTEXT_SPECIFIC,1,!0,[]),n=0;n=s&&a0&&a.value[0].value.push(r.create(r.Class.CONTEXT_SPECIFIC,0,!0,t)),n.length>0&&a.value[0].value.push(r.create(r.Class.CONTEXT_SPECIFIC,1,!0,n)),a.value[0].value.push(r.create(r.Class.UNIVERSAL,r.Type.SET,!0,e.signerInfos)),r.create(r.Class.UNIVERSAL,r.Type.SEQUENCE,!0,[r.create(r.Class.UNIVERSAL,r.Type.OID,!1,r.oidToDer(e.type).getBytes()),a])},addSigner:function(t){var r=t.issuer,s=t.serialNumber;if(t.certificate){var n=t.certificate;'string'==typeof n&&(n=i.pki.certificateFromPem(n)),r=n.issuer.attributes,s=n.serialNumber}var a=t.key;if(!a)throw new Error('Could not add PKCS#7 signer; no private key specified.');'string'==typeof a&&(a=i.pki.privateKeyFromPem(a));var o=t.digestAlgorithm||i.pki.oids.sha1;switch(o){case i.pki.oids.sha1:case i.pki.oids.sha256:case i.pki.oids.sha384:case i.pki.oids.sha512:case i.pki.oids.md5:break;default:throw new Error('Could not add PKCS#7 signer; unknown message digest algorithm: '+o)}var c=t.authenticatedAttributes||[];if(c.length>0){for(var l=!1,h=!1,d=0;d='8'&&(r='00'+r);var s=i.util.hexToBytes(r);e.putInt32(s.length),e.putBytes(s)}function n(e,t){e.putInt32(t.length),e.putString(t)}function a(){for(var e=i.md.sha1.create(),t=arguments.length,r=0;r{for(var i in t)n(e,i,{get:t[i],enumerable:!0})})(ee,{jingles:()=>i,maps:()=>e,serverMaps:()=>r,songs:()=>t});var te,ie,re,se,ne,ae,oe=(te={'src/lostcity/server/PreloadedDirs.ts'(){e=['l29_75','l30_75','l31_75','l32_70','l32_71','l32_72','l32_73','l32_74','l32_75','l33_70','l33_71','l33_72','l33_73','l33_74','l33_75','l33_76','l34_70','l34_71','l34_72','l34_73','l34_74','l34_75','l34_76','l35_20','l35_75','l35_76','l36_146','l36_147','l36_148','l36_149','l36_150','l36_153','l36_154','l36_52','l36_53','l36_54','l36_72','l36_73','l36_74','l36_75','l36_76','l37_146','l37_147','l37_148','l37_149','l37_150','l37_151','l37_152','l37_153','l37_154','l37_48','l37_49','l37_50','l37_51','l37_52','l37_53','l37_54','l37_55','l37_72','l37_73','l37_74','l37_75','l38_146','l38_147','l38_148','l38_149','l38_150','l38_151','l38_152','l38_153','l38_154','l38_155','l38_45','l38_46','l38_47','l38_48','l38_49','l38_50','l38_51','l38_52','l38_53','l38_54','l38_55','l38_72','l38_73','l38_74','l39_147','l39_148','l39_149','l39_150','l39_151','l39_152','l39_153','l39_154','l39_155','l39_45','l39_46','l39_47','l39_48','l39_49','l39_50','l39_51','l39_52','l39_53','l39_54','l39_55','l39_72','l39_73','l39_74','l39_75','l39_76','l40_147','l40_148','l40_149','l40_150','l40_151','l40_152','l40_153','l40_154','l40_45','l40_46','l40_47','l40_48','l40_49','l40_50','l40_51','l40_52','l40_53','l40_54','l40_55','l40_72','l40_73','l40_74','l40_75','l40_76','l41_146','l41_149','l41_151','l41_152','l41_153','l41_154','l41_45','l41_46','l41_47','l41_48','l41_49','l41_50','l41_51','l41_52','l41_53','l41_54','l41_55','l41_56','l41_72','l41_73','l41_74','l41_75','l42_144','l42_145','l42_146','l42_151','l42_152','l42_153','l42_49','l42_50','l42_51','l42_52','l42_53','l42_54','l42_55','l42_56','l42_72','l42_73','l42_74','l42_75','l43_144','l43_145','l43_146','l43_153','l43_154','l43_45','l43_46','l43_47','l43_48','l43_49','l43_50','l43_51','l43_52','l43_53','l43_54','l43_55','l43_56','l43_72','l43_73','l43_74','l43_75','l44_144','l44_145','l44_146','l44_148','l44_149','l44_150','l44_151','l44_152','l44_153','l44_154','l44_155','l44_45','l44_46','l44_47','l44_48','l44_49','l44_50','l44_51','l44_52','l44_53','l44_54','l44_55','l44_72','l44_73','l44_74','l44_75','l45_145','l45_146','l45_148','l45_150','l45_151','l45_152','l45_153','l45_154','l45_155','l45_45','l45_46','l45_47','l45_48','l45_49','l45_50','l45_51','l45_52','l45_53','l45_54','l45_55','l45_56','l45_57','l45_58','l45_59','l45_60','l45_61','l45_62','l45_73','l45_74','l45_75','l45_76','l46_149','l46_150','l46_152','l46_153','l46_154','l46_161','l46_45','l46_46','l46_47','l46_48','l46_49','l46_50','l46_51','l46_52','l46_53','l46_54','l46_55','l46_56','l46_57','l46_58','l46_59','l46_60','l46_61','l46_62','l46_75','l47_148','l47_149','l47_150','l47_152','l47_153','l47_160','l47_161','l47_47','l47_48','l47_49','l47_50','l47_51','l47_52','l47_53','l47_54','l47_55','l47_56','l47_57','l47_58','l47_59','l47_60','l47_61','l47_62','l47_75','l48_148','l48_149','l48_152','l48_153','l48_154','l48_155','l48_156','l48_47','l48_48','l48_49','l48_50','l48_51','l48_52','l48_53','l48_54','l48_55','l48_56','l48_57','l48_58','l48_59','l48_60','l48_61','l48_62','l49_148','l49_149','l49_153','l49_154','l49_155','l49_156','l49_46','l49_47','l49_48','l49_49','l49_50','l49_51','l49_52','l49_53','l49_54','l49_55','l49_56','l49_57','l49_58','l49_59','l49_60','l49_61','l49_62','l50_149','l50_150','l50_152','l50_153','l50_154','l50_46','l50_47','l50_48','l50_49','l50_50','l50_51','l50_52','l50_53','l50_54','l50_55','l50_56','l50_57','l50_58','l50_59','l50_60','l50_61','l50_62','l51_147','l51_154','l51_46','l51_47','l51_48','l51_49','l51_50','l51_51','l51_52','l51_53','l51_54','l51_55','l51_56','l51_57','l51_58','l51_59','l51_60','l51_61','l51_62','l52_152','l52_153','l52_154','l52_46','l52_47','l52_48','l52_49','l52_50','l52_51','l52_52','l52_53','l52_54','l52_55','l52_56','l52_57','l52_58','l52_59','l52_60','l52_61','l52_62','l53_49','l53_50','l53_51','l53_52','l53_53','m29_75','m30_75','m31_75','m32_70','m32_71','m32_72','m32_73','m32_74','m32_75','m33_70','m33_71','m33_72','m33_73','m33_74','m33_75','m33_76','m34_70','m34_71','m34_72','m34_73','m34_74','m34_75','m34_76','m35_20','m35_75','m35_76','m36_146','m36_147','m36_148','m36_149','m36_150','m36_153','m36_154','m36_52','m36_53','m36_54','m36_72','m36_73','m36_74','m36_75','m36_76','m37_146','m37_147','m37_148','m37_149','m37_150','m37_151','m37_152','m37_153','m37_154','m37_48','m37_49','m37_50','m37_51','m37_52','m37_53','m37_54','m37_55','m37_72','m37_73','m37_74','m37_75','m38_146','m38_147','m38_148','m38_149','m38_150','m38_151','m38_152','m38_153','m38_154','m38_155','m38_45','m38_46','m38_47','m38_48','m38_49','m38_50','m38_51','m38_52','m38_53','m38_54','m38_55','m38_72','m38_73','m38_74','m39_147','m39_148','m39_149','m39_150','m39_151','m39_152','m39_153','m39_154','m39_155','m39_45','m39_46','m39_47','m39_48','m39_49','m39_50','m39_51','m39_52','m39_53','m39_54','m39_55','m39_72','m39_73','m39_74','m39_75','m39_76','m40_147','m40_148','m40_149','m40_150','m40_151','m40_152','m40_153','m40_154','m40_45','m40_46','m40_47','m40_48','m40_49','m40_50','m40_51','m40_52','m40_53','m40_54','m40_55','m40_72','m40_73','m40_74','m40_75','m40_76','m41_146','m41_149','m41_151','m41_152','m41_153','m41_154','m41_45','m41_46','m41_47','m41_48','m41_49','m41_50','m41_51','m41_52','m41_53','m41_54','m41_55','m41_56','m41_72','m41_73','m41_74','m41_75','m42_144','m42_145','m42_146','m42_151','m42_152','m42_153','m42_49','m42_50','m42_51','m42_52','m42_53','m42_54','m42_55','m42_56','m42_72','m42_73','m42_74','m42_75','m43_144','m43_145','m43_146','m43_153','m43_154','m43_45','m43_46','m43_47','m43_48','m43_49','m43_50','m43_51','m43_52','m43_53','m43_54','m43_55','m43_56','m43_72','m43_73','m43_74','m43_75','m44_144','m44_145','m44_146','m44_148','m44_149','m44_150','m44_151','m44_152','m44_153','m44_154','m44_155','m44_45','m44_46','m44_47','m44_48','m44_49','m44_50','m44_51','m44_52','m44_53','m44_54','m44_55','m44_72','m44_73','m44_74','m44_75','m45_145','m45_146','m45_148','m45_150','m45_151','m45_152','m45_153','m45_154','m45_155','m45_45','m45_46','m45_47','m45_48','m45_49','m45_50','m45_51','m45_52','m45_53','m45_54','m45_55','m45_56','m45_57','m45_58','m45_59','m45_60','m45_61','m45_62','m45_73','m45_74','m45_75','m45_76','m46_149','m46_150','m46_152','m46_153','m46_154','m46_161','m46_45','m46_46','m46_47','m46_48','m46_49','m46_50','m46_51','m46_52','m46_53','m46_54','m46_55','m46_56','m46_57','m46_58','m46_59','m46_60','m46_61','m46_62','m46_75','m47_148','m47_149','m47_150','m47_152','m47_153','m47_160','m47_161','m47_47','m47_48','m47_49','m47_50','m47_51','m47_52','m47_53','m47_54','m47_55','m47_56','m47_57','m47_58','m47_59','m47_60','m47_61','m47_62','m47_75','m48_148','m48_149','m48_152','m48_153','m48_154','m48_155','m48_156','m48_47','m48_48','m48_49','m48_50','m48_51','m48_52','m48_53','m48_54','m48_55','m48_56','m48_57','m48_58','m48_59','m48_60','m48_61','m48_62','m49_148','m49_149','m49_153','m49_154','m49_155','m49_156','m49_46','m49_47','m49_48','m49_49','m49_50','m49_51','m49_52','m49_53','m49_54','m49_55','m49_56','m49_57','m49_58','m49_59','m49_60','m49_61','m49_62','m50_149','m50_150','m50_152','m50_153','m50_154','m50_46','m50_47','m50_48','m50_49','m50_50','m50_51','m50_52','m50_53','m50_54','m50_55','m50_56','m50_57','m50_58','m50_59','m50_60','m50_61','m50_62','m51_147','m51_154','m51_46','m51_47','m51_48','m51_49','m51_50','m51_51','m51_52','m51_53','m51_54','m51_55','m51_56','m51_57','m51_58','m51_59','m51_60','m51_61','m51_62','m52_152','m52_153','m52_154','m52_46','m52_47','m52_48','m52_49','m52_50','m52_51','m52_52','m52_53','m52_54','m52_55','m52_56','m52_57','m52_58','m52_59','m52_60','m52_61','m52_62','m53_49','m53_50','m53_51','m53_52','m53_53'],t=['adventure.mid','al_kharid.mid','alone.mid','ambience_2.mid','ambience_3.mid','ambience_4.mid','ambient_jungle.mid','arabian.mid','arabian2.mid','arabian3.mid','arabique.mid','army_of_darkness.mid','arrival.mid','attack1.mid','attack2.mid','attack3.mid','attack4.mid','attack5.mid','attack6.mid','attention.mid','autumn_voyage.mid','background2.mid','ballad_of_enchantment.mid','baroque.mid','beyond.mid','big_chords.mid','book_of_spells.mid','camelot.mid','cave_background1.mid','cavern.mid','cellar_song1.mid','chain_of_command.mid','chompy_hunt.mid','close_quarters.mid','crystal_cave.mid','crystal_sword.mid','cursed.mid','dangerous.mid','dark2.mid','deep_wildy.mid','desert_voyage.mid','doorways.mid','dream1.mid','duel_arena.mid','dunjun.mid','egypt.mid','emotion.mid','emperor.mid','escape.mid','expanse.mid','expecting.mid','expedition.mid','fade_test.mid','faerie.mid','fanfare.mid','fanfare2.mid','fanfare3.mid','fishing.mid','flute_salad.mid','forbidden.mid','forever.mid','game_intro_1.mid','gaol.mid','garden.mid','gnome.mid','gnome_king.mid','gnome_theme.mid','gnome_village.mid','gnome_village2.mid','gnomeball.mid','greatness.mid','grumpy.mid','harmony.mid','harmony2.mid','heart_and_mind.mid','high_seas.mid','horizon.mid','iban.mid','ice_melody.mid','in_the_manor.mid','inspiration.mid','intrepid.mid','jolly-r.mid','jungle_island.mid','jungly1.mid','jungly2.mid','jungly3.mid','knightly.mid','landlubber.mid','lasting.mid','legion.mid','lightness.mid','lightwalk.mid','lonesome.mid','long_ago.mid','long_way_home.mid','lullaby.mid','mage_arena.mid','magic_dance.mid','magical_journey.mid','march2.mid','medieval.mid','mellow.mid','miles_away.mid','miracle_dance.mid','monarch_waltz.mid','moody.mid','neverland.mid','newbie_melody.mid','nightfall.mid','nomad.mid','null.mid','organ_music_1.mid','organ_music_2.mid','oriental.mid','overture.mid','parade.mid','quest.mid','regal2.mid','reggae.mid','reggae2.mid','riverside.mid','royale.mid','rune_essence.mid','sad_meadow.mid','scape_cave.mid','scape_main.mid','scape_sad1.mid','scape_soft.mid','scape_wild1.mid','sea_shanty.mid','sea_shanty2.mid','serenade.mid','serene.mid','shine.mid','shining.mid','silence.mid','soundscape.mid','spirit.mid','splendour.mid','spooky2.mid','spooky_jungle.mid','starlight.mid','start.mid','still_night.mid','talking_forest.mid','the_desert.mid','the_shadow.mid','the_tower.mid','theme.mid','tomorrow.mid','trawler.mid','trawler_minor.mid','tree_spirits.mid','tribal.mid','tribal2.mid','tribal_background.mid','trinity.mid','troubled.mid','undercurrent.mid','underground.mid','understanding.mid','unknown_land.mid','upass1.mid','upcoming.mid','venture.mid','venture2.mid','vision.mid','voodoo_cult.mid','voyage.mid','wander.mid','waterfall.mid','wilderness2.mid','wilderness3.mid','wilderness4.mid','witching.mid','wolf_mountain.mid','wonder.mid','wonderous.mid','workshop.mid','yesteryear.mid','zealot.mid'],i=['advance agility.mid','advance attack.mid','advance attack2.mid','advance cooking.mid','advance cooking2.mid','advance crafting.mid','advance crafting2.mid','advance defense.mid','advance defense2.mid','advance firemarking.mid','advance firemarking2.mid','advance fishing.mid','advance fishing2.mid','advance fletching.mid','advance fletching2.mid','advance herblaw.mid','advance herblaw2.mid','advance hitpoints.mid','advance hitpoints2.mid','advance magic.mid','advance magic2.mid','advance mining.mid','advance mining2.mid','advance prayer.mid','advance prayer2.mid','advance ranged.mid','advance ranged2.mid','advance runecraft.mid','advance runecraft2.mid','advance smithing.mid','advance smithing2.mid','advance strength.mid','advance strength2.mid','advance thieving.mid','advance thieving2.mid','advance woodcutting.mid','advance woodcutting2.mid','death.mid','death2.mid','dice lose.mid','dice win.mid','duel start.mid','duel win2.mid','quest complete 1.mid','quest complete 2.mid','quest complete 3.mid','sailing journey.mid','treasure hunt win.mid'],r=['m29_75','m30_75','m31_75','m32_70','m32_71','m32_72','m32_73','m32_74','m32_75','m33_70','m33_71','m33_72','m33_73','m33_74','m33_75','m33_76','m34_70','m34_71','m34_72','m34_73','m34_74','m34_75','m34_76','m35_20','m35_75','m35_76','m36_146','m36_147','m36_148','m36_149','m36_150','m36_153','m36_154','m36_52','m36_53','m36_54','m36_72','m36_73','m36_74','m36_75','m36_76','m37_146','m37_147','m37_148','m37_149','m37_150','m37_151','m37_152','m37_153','m37_154','m37_48','m37_49','m37_50','m37_51','m37_52','m37_53','m37_54','m37_55','m37_72','m37_73','m37_74','m37_75','m38_146','m38_147','m38_148','m38_149','m38_150','m38_151','m38_152','m38_153','m38_154','m38_155','m38_45','m38_46','m38_47','m38_48','m38_49','m38_50','m38_51','m38_52','m38_53','m38_54','m38_55','m38_72','m38_73','m38_74','m39_147','m39_148','m39_149','m39_150','m39_151','m39_152','m39_153','m39_154','m39_155','m39_45','m39_46','m39_47','m39_48','m39_49','m39_50','m39_51','m39_52','m39_53','m39_54','m39_55','m39_72','m39_73','m39_74','m39_75','m39_76','m40_147','m40_148','m40_149','m40_150','m40_151','m40_152','m40_153','m40_154','m40_45','m40_46','m40_47','m40_48','m40_49','m40_50','m40_51','m40_52','m40_53','m40_54','m40_55','m40_72','m40_73','m40_74','m40_75','m40_76','m41_146','m41_149','m41_151','m41_152','m41_153','m41_154','m41_45','m41_46','m41_47','m41_48','m41_49','m41_50','m41_51','m41_52','m41_53','m41_54','m41_55','m41_56','m41_72','m41_73','m41_74','m41_75','m42_144','m42_145','m42_146','m42_151','m42_152','m42_153','m42_49','m42_50','m42_51','m42_52','m42_53','m42_54','m42_55','m42_56','m42_72','m42_73','m42_74','m42_75','m43_144','m43_145','m43_146','m43_153','m43_154','m43_45','m43_46','m43_47','m43_48','m43_49','m43_50','m43_51','m43_52','m43_53','m43_54','m43_55','m43_56','m43_72','m43_73','m43_74','m43_75','m44_144','m44_145','m44_146','m44_148','m44_149','m44_150','m44_151','m44_152','m44_153','m44_154','m44_155','m44_45','m44_46','m44_47','m44_48','m44_49','m44_50','m44_51','m44_52','m44_53','m44_54','m44_55','m44_72','m44_73','m44_74','m44_75','m45_145','m45_146','m45_148','m45_150','m45_151','m45_152','m45_153','m45_154','m45_155','m45_45','m45_46','m45_47','m45_48','m45_49','m45_50','m45_51','m45_52','m45_53','m45_54','m45_55','m45_56','m45_57','m45_58','m45_59','m45_60','m45_61','m45_62','m45_73','m45_74','m45_75','m45_76','m46_149','m46_150','m46_152','m46_153','m46_154','m46_161','m46_45','m46_46','m46_47','m46_48','m46_49','m46_50','m46_51','m46_52','m46_53','m46_54','m46_55','m46_56','m46_57','m46_58','m46_59','m46_60','m46_61','m46_62','m46_75','m47_148','m47_149','m47_150','m47_152','m47_153','m47_160','m47_161','m47_47','m47_48','m47_49','m47_50','m47_51','m47_52','m47_53','m47_54','m47_55','m47_56','m47_57','m47_58','m47_59','m47_60','m47_61','m47_62','m47_75','m48_148','m48_149','m48_152','m48_153','m48_154','m48_155','m48_156','m48_47','m48_48','m48_49','m48_50','m48_51','m48_52','m48_53','m48_54','m48_55','m48_56','m48_57','m48_58','m48_59','m48_60','m48_61','m48_62','m49_148','m49_149','m49_153','m49_154','m49_155','m49_156','m49_46','m49_47','m49_48','m49_49','m49_50','m49_51','m49_52','m49_53','m49_54','m49_55','m49_56','m49_57','m49_58','m49_59','m49_60','m49_61','m49_62','m50_149','m50_150','m50_152','m50_153','m50_154','m50_46','m50_47','m50_48','m50_49','m50_50','m50_51','m50_52','m50_53','m50_54','m50_55','m50_56','m50_57','m50_58','m50_59','m50_60','m50_61','m50_62','m51_147','m51_154','m51_46','m51_47','m51_48','m51_49','m51_50','m51_51','m51_52','m51_53','m51_54','m51_55','m51_56','m51_57','m51_58','m51_59','m51_60','m51_61','m51_62','m52_152','m52_153','m52_154','m52_46','m52_47','m52_48','m52_49','m52_50','m52_51','m52_52','m52_53','m52_54','m52_55','m52_56','m52_57','m52_58','m52_59','m52_60','m52_61','m52_62','m53_49','m53_50','m53_51','m53_52','m53_53']}},function(){return te&&(ie=(0,te[o(te)[0]])(te=0)),ie}),ce=!0;'undefined'!=typeof process&&(({FORCE_COLOR:re,NODE_DISABLE_COLORS:se,NO_COLOR:ne,TERM:ae}=process.env||{}),ce=process.stdout&&process.stdout.isTTY);var le={enabled:!se&&null==ne&&'dumb'!==ae&&(null!=re&&'0'!==re||ce),reset:de(0,0),bold:de(1,22),dim:de(2,22),italic:de(3,23),underline:de(4,24),inverse:de(7,27),hidden:de(8,28),strikethrough:de(9,29),black:de(30,39),red:de(31,39),green:de(32,39),yellow:de(33,39),blue:de(34,39),magenta:de(35,39),cyan:de(36,39),white:de(37,39),gray:de(90,39),grey:de(90,39),bgBlack:de(40,49),bgRed:de(41,49),bgGreen:de(42,49),bgYellow:de(43,49),bgBlue:de(44,49),bgMagenta:de(45,49),bgCyan:de(46,49),bgWhite:de(47,49)};function he(e,t){let i,r=0,s='',n='';for(;r=65&&r<=90?t+=BigInt(r+1-65):r>=97&&r<=122?t+=BigInt(r+1-97):r>=48&&r<=57&&(t+=BigInt(r+27-48))}return t}var fe=['_','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'];function ge(e){if(e<0n||e>=6582952005840035281n)return'invalid_name';if(e%37n===0n)return'invalid_name';let t=0;const i=Array(12);for(;0n!==e;){const r=e;e/=37n,i[11-t++]=fe[Number(r-37n*e)]}return i.slice(12-t).join('')}function me(e){return t=function(e){return ge(pe(e))}(e).replaceAll('_',' '),t.replace(/\w\S*/g,(e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()));var t}var ye,Ee,_e,Ae,ve=(ye=J(),Ee=1,_e=null!=ye?s(c(ye)):{},((e,t,i,r)=>{if(t&&'object'==typeof t||'function'==typeof t)for(let s of o(t))l.call(e,s)||s===i||n(e,s,{get:()=>t[s],enumerable:!(r=a(t,s))||r.enumerable});return e})(!Ee&&ye&&ye.__esModule?_e:n(_e,'default',{value:ye,enumerable:!0}),ye)),Te=class{key;next;prev;constructor(){this.key=0n,this.next=this,this.prev=this}unlink(){this.prev&&this.next&&(this.prev.next=this.next,this.next.prev=this.prev,this.next=null,this.prev=null)}},Ce=class{sentinel;cursor=null;constructor(){const e=new Te;e.next=e,e.prev=e,this.sentinel=e}addTail(e){e.prev&&e.unlink(),e.prev=this.sentinel.prev,e.next=this.sentinel,e.prev&&(e.prev.next=e),e.next.prev=e}addHead(e){e.prev&&e.unlink(),e.prev=this.sentinel,e.next=this.sentinel.next,e.prev.next=e,e.next&&(e.next.prev=e)}removeHead(){const e=this.sentinel.next;return e===this.sentinel?null:(e?.unlink(),e)}head(){const e=this.sentinel.next;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.next||null,e)}tail(){const e=this.sentinel.prev;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.prev||null,e)}next(){const e=this.cursor;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.next||null,e)}prev(){const e=this.cursor;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.prev||null,e)}clear(){for(;;){const e=this.sentinel.next;if(e===this.sentinel)return;e?.unlink()}}},Ie=class extends Te{nextHashable;prevHashable;constructor(){super(),this.nextHashable=this,this.prevHashable=this}uncache(){this.prevHashable&&this.nextHashable&&(this.prevHashable.nextHashable=this.nextHashable,this.nextHashable.prevHashable=this.prevHashable,this.nextHashable=null,this.prevHashable=null)}},Se=ve.default.jsbn.BigInteger,Oe=class e extends Ie{static crctable=new Int32Array(256);static bitmask=new Uint32Array(33);static crc32b=3988292384;static{for(let e=0;e<32;e++)this.bitmask[e]=(1<>>=1:t=t>>>1^this.crc32b;this.crctable[e]=t}}static getcrc(e,t,i){let r=4294967295;for(let s=t;s>>8^this.crctable[255&(r^e[s])];return~r}static checkcrc(t,i,r,s=0){return e.getcrc(t,i,r)==s}static alloc(t){let i=null;return 0===t&&this.cacheMinCount>0?(i=this.cacheMin.removeHead(),this.cacheMinCount--):1===t&&this.cacheMidCount>0?(i=this.cacheMid.removeHead(),this.cacheMidCount--):2===t&&this.cacheMaxCount>0?(i=this.cacheMax.removeHead(),this.cacheMaxCount--):3===t&&this.cacheBigCount>0?(i=this.cacheBig.removeHead(),this.cacheBigCount--):4===t&&this.cacheHugeCount>0?(i=this.cacheHuge.removeHead(),this.cacheHugeCount--):5===t&&this.cacheUnimaginableCount>0&&(i=this.cacheUnimaginable.removeHead(),this.cacheUnimaginableCount--),null!==i?(i.pos=0,i.bitPos=0,i):new e(0===t?new Uint8Array(100):1===t?new Uint8Array(5e3):2===t?new Uint8Array(3e4):3===t?new Uint8Array(1e5):4===t?new Uint8Array(5e5):5===t?new Uint8Array(2e6):new Uint8Array(t))}static load(t,i=!1){const r=new e(new Uint8Array(fs.readFileSync(t)));return i&&(r.pos=r.data.length),r}static async loadAsync(t,i=!1){const r=new e(new Uint8Array(await(await fetch(t)).arrayBuffer()));return i&&(r.pos=r.data.length),r}static cacheMinCount=0;static cacheMidCount=0;static cacheMaxCount=0;static cacheBigCount=0;static cacheHugeCount=0;static cacheUnimaginableCount=0;static cacheMin=new Ce;static cacheMid=new Ce;static cacheMax=new Ce;static cacheBig=new Ce;static cacheHuge=new Ce;static cacheUnimaginable=new Ce;data;#e;pos;bitPos;constructor(e){super(),this.data=e,this.#e=new DataView(this.data.buffer),this.pos=0,this.bitPos=0}get available(){return this.data.length-this.pos}get length(){return this.data.length}release(){this.pos=0,this.bitPos=0,100===this.data.length&&e.cacheMinCount<1e3?(e.cacheMin.addTail(this),e.cacheMinCount++):5e3===this.data.length&&e.cacheMidCount<250?(e.cacheMid.addTail(this),e.cacheMidCount++):3e4===this.data.length&&e.cacheMaxCount<50?(e.cacheMax.addTail(this),e.cacheMaxCount++):1e5===this.data.length&&e.cacheBigCount<10?(e.cacheBig.addTail(this),e.cacheBigCount++):5e5===this.data.length&&e.cacheHugeCount<5?(e.cacheHuge.addTail(this),e.cacheHugeCount++):2e6===this.data.length&&e.cacheUnimaginableCount<2&&(e.cacheUnimaginable.addTail(this),e.cacheUnimaginableCount++)}save(e,t=this.pos,i=0){if('undefined'==typeof self){const r=path.dirname(e);fs.existsSync(r)||fs.mkdirSync(r,{recursive:!0}),fs.writeFileSync(e,this.data.subarray(i,i+t))}else{const r=new Blob([this.data.subarray(i,i+t)],{type:'application/octet-stream'}),s=URL.createObjectURL(r);self.postMessage({type:'save',value:s,path:e})}}p1(e){this.#e.setUint8(this.pos++,e)}p2(e){this.#e.setUint16(this.pos,e),this.pos+=2}ip2(e){this.#e.setUint16(this.pos,e,!0),this.pos+=2}p3(e){this.#e.setUint8(this.pos++,e>>16),this.#e.setUint16(this.pos,e),this.pos+=2}p4(e){this.#e.setInt32(this.pos,e),this.pos+=4}ip4(e){this.#e.setInt32(this.pos,e,!0),this.pos+=4}p8(e){this.#e.setBigInt64(this.pos,e),this.pos+=8}pbool(e){this.p1(e?1:0)}pjstr(e,t=10){const i=e.length;for(let t=0;t=64)this.p1(e+64);else{if(!(e<16384&&e>=-16384))throw new Error('Error psmarts out of range: '+e);this.p2(e+49152)}}psmart(e){if(e>=0&&e<128)this.p1(e);else{if(!(e>=0&&e<32768))throw new Error('Error psmart out of range: '+e);this.p2(e+32768)}}g1(){return this.#e.getUint8(this.pos++)}g1b(){return this.#e.getInt8(this.pos++)}g2(){return this.pos+=2,this.#e.getUint16(this.pos-2)}g2s(){return this.pos+=2,this.#e.getInt16(this.pos-2)}ig2(){return this.pos+=2,this.#e.getUint16(this.pos-2,!0)}g3(){const e=this.#e.getUint8(this.pos++)<<16|this.#e.getUint16(this.pos);return this.pos+=2,e}g4(){return this.pos+=4,this.#e.getInt32(this.pos-4)}ig4(){return this.pos+=4,this.#e.getInt32(this.pos-4,!0)}g8(){return this.pos+=8,this.#e.getBigInt64(this.pos-8)}gbool(){return 1===this.g1()}gjstr(e=10){const t=this.data.length;let i,r='';for(;(i=this.#e.getUint8(this.pos++))!==e&&this.pos>>3}gBit(t){let i=this.bitPos>>>3,r=8-(7&this.bitPos),s=0;for(this.bitPos+=t;t>r;r=8)s+=(this.#e.getUint8(i++)&e.bitmask[r])<>>r-t&e.bitmask[t],s}pBit(e,t){const i=this.bitPos;this.bitPos+=e;let r=i>>>3,s=8-(7&i);const n=this.#e;for(;e>s;s=8){const i=(1<>>e-s&i),e-=s}const a=s-e,o=(1<0;){const t=e.g1();if(0===t)break;this.decode(t,e)}}},Le=class e extends Ne{static configNames=new Map;static configs=[];static load(e){if(!fs2.existsSync(`${e}/server/category.dat`))return void console.log('Warning: No category.dat found.');const t=Oe.load(`${e}/server/category.dat`);this.parse(t)}static async loadAsync(e){if(!(await fetch(`${e}/server/category.dat`)).ok)return void console.log('Warning: No category.dat found.');const t=await Oe.loadAsync(`${e}/server/category.dat`);this.parse(t)}static parse(t){e.configNames=new Map,e.configs=[];const i=t.g2();for(let r=0;re.tableId===t))}tableId=0;types=[];columnValues=[];decode(e,t){if(3===e){const e=t.g1();this.types=new Array(e),this.columnValues=new Array(e);for(let e=t.g1();255!=e;e=t.g1()){const i=new Array(t.g1());for(let e=0;e{i=e,r=t}));['_BZ2_bzBuffToBuffDecompress','_BZ2_bzBuffToBuffCompress','_malloc','_free','_memory','___indirect_function_table','onRuntimeInitialized'].forEach((e=>{Object.getOwnPropertyDescriptor(n,e)||Object.defineProperty(n,e,{get:()=>z('You are getting '+e+' 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:()=>z('You are setting '+e+' 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'==typeof window,o='function'==typeof importScripts,c='object'==typeof process&&'object'==typeof process.versions&&'string'==typeof process.versions.node,l=!a&&!c&&!o;if(s.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)');if(c){const{createRequire:e}=await import('module');var h=e(import.meta.url)}var d,u,p,f=Object.assign({},s),g=(e,t)=>{throw t},m='';if(c){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 y=process.versions.node,E=y.split('.').slice(0,3);if((E=1e4*E[0]+100*E[1]+1*E[2].split('-')[0])<16e4)throw new Error('This emscripten-generated code requires node v16.0.0 (detected v'+y+')');var _=h('fs'),A=h('path');m=h('url').fileURLToPath(new URL('./',import.meta.url)),d=(e,t)=>(e=Q(e)?new URL(e):A.normalize(e),_.readFileSync(e,t?void 0:'utf8')),p=e=>{var t=d(e,!0);return t.buffer||(t=new Uint8Array(t)),U(t.buffer),t},u=(e,t,i,r=!0)=>{e=Q(e)?new URL(e):A.normalize(e),_.readFile(e,r?void 0:'utf8',((e,s)=>{e?i(e):t(r?s.buffer:s)}))},!s.thisProgram&&process.argv.length>1&&process.argv[1].replace(/\\/g,'/'),process.argv.slice(2),g=(e,t)=>{throw process.exitCode=e,t}}else if(l){if('object'==typeof process&&'function'==typeof h||'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?)')}else{if(!a&&!o)throw new Error('environment detection error');if(o?m=self.location.href:'undefined'!=typeof document&&document.currentScript&&(m=document.currentScript.src),Ae&&(m=Ae),m=m.startsWith('blob:')?'':m.substr(0,m.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?)');d=e=>{var t=new XMLHttpRequest;return t.open('GET',e,!1),t.send(null),t.responseText},o&&(p=e=>{var t=new XMLHttpRequest;return t.open('GET',e,!1),t.responseType='arraybuffer',t.send(null),new Uint8Array(t.response)}),u=(e,t,i)=>{var r=new XMLHttpRequest;r.open('GET',e,!0),r.responseType='arraybuffer',r.onload=()=>{200==r.status||0==r.status&&r.response?t(r.response):i()},r.onerror=i,r.send(null)}}var v,T,C,I=s.print||console.log.bind(console),S=s.printErr||console.error.bind(console);Object.assign(s,f),f=null,v='fetchSettings',Object.getOwnPropertyDescriptor(s,v)&&z(`\`Module.${v}\` was supplied but \`${v}\` not included in INCOMING_MODULE_JS_API`),s.arguments&&s.arguments,ee('arguments','arguments_'),s.thisProgram&&s.thisProgram,ee('thisProgram','thisProgram'),s.quit&&(g=s.quit),ee('quit','quit_'),U(void 0===s.memoryInitializerPrefixURL,'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead'),U(void 0===s.pthreadMainPrefixURL,'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead'),U(void 0===s.cdInitializerPrefixURL,'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead'),U(void 0===s.filePackagePrefixURL,'Module.filePackagePrefixURL option was removed, use Module.locateFile instead'),U(void 0===s.read,'Module.read option was removed (modify read_ in JS)'),U(void 0===s.readAsync,'Module.readAsync option was removed (modify readAsync in JS)'),U(void 0===s.readBinary,'Module.readBinary option was removed (modify readBinary in JS)'),U(void 0===s.setWindowTitle,'Module.setWindowTitle option was removed (modify emscripten_set_window_title in JS)'),U(void 0===s.TOTAL_MEMORY,'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY'),ee('asm','wasmExports'),ee('read','read_'),ee('readAsync','readAsync'),ee('readBinary','readBinary'),ee('setWindowTitle','setWindowTitle'),U(!l,'shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.'),s.wasmBinary&&(T=s.wasmBinary),ee('wasmBinary','wasmBinary'),'object'!=typeof WebAssembly&&S('no native wasm support detected');var O,N,L,P,w,b,R,B=!1;function U(e,t){e||z('Assertion failed'+(t?': '+t:''))}function D(){var e=C.buffer;s.HEAP8=O=new Int8Array(e),s.HEAP16=L=new Int16Array(e),s.HEAPU8=N=new Uint8Array(e),s.HEAPU16=new Uint16Array(e),s.HEAP32=P=new Int32Array(e),s.HEAPU32=w=new Uint32Array(e),s.HEAPF32=b=new Float32Array(e),s.HEAPF64=R=new Float64Array(e)}function k(){if(!B){var e=Ce();0==e&&(e+=4);var t=w[e>>2],i=w[e+4>>2];34821223==t&&2310721022==i||z(`Stack overflow! Stack cookie has been overwritten at ${ce(e)}, expected hex dwords 0x89BACDFE and 0x2135467, but received ${ce(i)} ${ce(t)}`),1668509029!=w[0]&&z('Runtime error: The application has corrupted its heap memory area (address zero)!')}}U(!s.STACK_SIZE,'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time'),U('undefined'!=typeof Int32Array&&'undefined'!=typeof Float64Array&&null!=Int32Array.prototype.subarray&&null!=Int32Array.prototype.set,'JS engine does not provide full typed array support'),U(!s.wasmMemory,'Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally'),U(!s.INITIAL_MEMORY,'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically'),function(){var e=new Int16Array(1),t=new Int8Array(e.buffer);if(e[0]=25459,115!==t[0]||99!==t[1])throw'Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)'}();var M=[],x=[],F=[],H=!1;U(Math.imul,'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'),U(Math.fround,'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'),U(Math.clz32,'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'),U(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 V=0,G=null,W=null,K={};function z(e){s.onAbort?.(e),S(e='Aborted('+e+')'),B=!0;var t=new WebAssembly.RuntimeError(e);throw r(t),t}var j={error(){z('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(){j.error()},createDataFile(){j.error()},createPreloadedFile(){j.error()},createLazyFile(){j.error()},open(){j.error()},mkdev(){j.error()},registerDevice(){j.error()},analyzePath(){j.error()},ErrnoError(){j.error()}};s.FS_createDataFile=j.createDataFile,s.FS_createPreloadedFile=j.createPreloadedFile;var Y,q=e=>e.startsWith("data:application/octet-stream;base64,"),Q=e=>e.startsWith('file://');function $(e,t){return(...i)=>{U(H,`native function \`${e}\` called before runtime initialization`);var r=_e[e];return U(r,`exported native function \`${e}\` not found`),U(i.length<=t,`native function \`${e}\` called with ${i.length} args but expects ${t}`),r(...i)}}function Z(){if(s.locateFile){var e='bzip2.wasm';return q(e)?e:(t=e,s.locateFile?s.locateFile(t,m):m+t)}var t;return new URL('bzip2.wasm',import.meta.url).href}function X(e){if(e==Y&&T)return new Uint8Array(T);if(p)return p(e);throw'both async and sync fetching of the wasm failed'}function J(e,t,i){return function(e){if(!T&&(a||o)){if('function'==typeof fetch&&!Q(e))return fetch(e,{credentials:'same-origin'}).then((t=>{if(!t.ok)throw`failed to load wasm binary file at '${e}'`;return t.arrayBuffer()})).catch((()=>X(e)));if(u)return new Promise(((t,i)=>{u(e,(e=>t(new Uint8Array(e))),i)}))}return Promise.resolve().then((()=>X(e)))}(e).then((e=>WebAssembly.instantiate(e,t))).then(i,(e=>{S(`failed to asynchronously prepare wasm: ${e}`),Q(Y)&&S(`warning: Loading from a file URI (${Y}) 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`),z(e)}))}function ee(e,t,i=!0){Object.getOwnPropertyDescriptor(s,e)||Object.defineProperty(s,e,{configurable:!0,get(){z(`\`Module.${e}\` has been replaced by \`${t}\``+(i?' (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 te(e){return'FS_createPath'===e||'FS_createDataFile'===e||'FS_createPreloadedFile'===e||'FS_unlink'===e||'addRunDependency'===e||'FS_createLazyFile'===e||'FS_createDevice'===e||'removeRunDependency'===e}function ie(e,t){'undefined'!=typeof globalThis&&Object.defineProperty(globalThis,e,{configurable:!0,get(){le(`\`${e}\` is not longer defined by emscripten. ${t}`)}})}function re(e){Object.getOwnPropertyDescriptor(s,e)||Object.defineProperty(s,e,{configurable:!0,get(){var t=`'${e}' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`;te(e)&&(t+='. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you'),z(t)}})}function se(e){this.name='ExitStatus',this.message=`Program terminated with exit(${e})`,this.status=e}ie('buffer','Please use HEAP8.buffer or wasmMemory.buffer'),ie('asm','Please use wasmExports instead');var ne,ae=e=>{for(;e.length>0;)e.shift()(s)},oe=s.noExitRuntime||!0,ce=e=>(U('number'==typeof e),'0x'+(e>>>=0).toString(16).padStart(8,'0')),le=e=>{le.shown||={},le.shown[e]||(le.shown[e]=1,c&&(e='warning: '+e),S(e))},he=e=>{var t=C.buffer,i=(e-t.byteLength+65535)/65536;try{return C.grow(i),D(),1}catch(i){S(`growMemory: Attempted to grow heap from ${t.byteLength} bytes to ${e} bytes, but got error: ${i}`)}},de=()=>oe||!1,ue=(e,t)=>{if(function(){var e=I,t=S,i=!1;I=S=e=>{i=!0};try{ye()}catch(e){}I=e,S=t,i&&(le('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the Emscripten FAQ), or make sure to emit a newline when you printf etc.'),le('(this may also be due to not including full filesystem support - try building with -sFORCE_FILESYSTEM)'))}(),de()&&!t){var i=`program exited (with status: ${e}), but keepRuntimeAlive() is set (counter=0) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;r(i),S(i)}var n;n=e,de()||(s.onExit?.(n),B=!0),g(n,new se(n))},pe='undefined'!=typeof TextDecoder?new TextDecoder('utf8'):void 0,fe=(e,t,i)=>{for(var r=t+i,s=t;e[s]&&!(s>=r);)++s;if(s-t>16&&e.buffer&&pe)return pe.decode(e.subarray(t,s));for(var n='';t>10,56320|1023&l)}}else n+=String.fromCharCode((31&a)<<6|o)}else n+=String.fromCharCode(a)}return n},ge=[null,[],[]],me=(e,t)=>{var i=ge[e];U(i),0===t||10===t?((1===e?I:S)(fe(i,0)),i.length=0):i.push(t)},ye=()=>{ve(0),ge[1].length&&me(1,10),ge[2].length&&me(2,10)},Ee={_emscripten_memcpy_js:(e,t,i)=>N.copyWithin(e,t,t+i),emscripten_resize_heap:e=>{var t=N.length;U((e>>>=0)>t);var i=2147483648;if(e>i)return S(`Cannot enlarge memory, requested ${e} bytes, but the limit is 2147483648 bytes!`),!1;for(var r,s,n=1;n<=4;n*=2){var a=t*(1+.2/n);a=Math.min(a,e+100663296);var o=Math.min(i,(r=Math.max(e,a))+((s=65536)-r%s)%s);if(he(o))return!0}return S(`Failed to grow the heap from ${t} bytes to ${o} bytes, not enough memory!`),!1},exit:ue,fd_close:e=>{z('fd_close called without SYSCALLS_REQUIRE_FILESYSTEM')},fd_seek:function(e,t,i,r,s){var n,a;return a=i,U((n=t)==n>>>0||n==(0|n)),U(a===(0|a)),70},fd_write:(e,t,i,r)=>{for(var s=0,n=0;n>2],o=w[t+4>>2];t+=8;for(var c=0;c>2]=s,0}},_e=function(){var e,t={env:Ee,wasi_snapshot_preview1:Ee};function i(e,t){var i;return _e=e.exports,U(C=_e.memory,'memory not found in wasm exports'),D(),i=_e.__wasm_call_ctors,x.unshift(i),function(e){if(V--,s.monitorRunDependencies?.(V),e?(U(K[e]),delete K[e]):S('warning: run dependency removed without ID'),0==V&&(null!==G&&(clearInterval(G),G=null),W)){var t=W;W=null,t()}}('wasm-instantiate'),_e}e='wasm-instantiate',V++,s.monitorRunDependencies?.(V),e?(U(!K[e]),K[e]=1,null===G&&'undefined'!=typeof setInterval&&(G=setInterval((()=>{if(B)return clearInterval(G),void(G=null);var e=!1;for(var t in K)e||(e=!0,S('still waiting on run dependencies:')),S(`dependency: ${t}`);e&&S('(end of list)')}),1e4))):S('warning: run dependency added without ID');var n,a,o,l,h=s;if(s.instantiateWasm)try{return s.instantiateWasm(t,i)}catch(e){S(`Module.instantiateWasm callback failed with error: ${e}`),r(e)}return Y||(Y=Z()),(n=T,a=Y,o=t,l=function(e){U(s===h,'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?'),h=null,i(e.instance)},n||'function'!=typeof WebAssembly.instantiateStreaming||q(a)||Q(a)||c||'function'!=typeof fetch?J(a,o,l):fetch(a,{credentials:'same-origin'}).then((e=>WebAssembly.instantiateStreaming(e,o).then(l,(function(e){return S(`wasm streaming compile failed: ${e}`),S('falling back to ArrayBuffer instantiation'),J(a,o,l)}))))).catch(r),{}}(),ve=($('__wasm_call_ctors',0),s._malloc=$('malloc',1),s._free=$('free',1),$('fflush',1)),Te=(s._BZ2_bzBuffToBuffCompress=$('BZ2_bzBuffToBuffCompress',7),s._BZ2_bzBuffToBuffDecompress=$('BZ2_bzBuffToBuffDecompress',6),()=>(Te=_e.emscripten_stack_init)()),Ce=()=>(Ce=_e.emscripten_stack_get_end)();function Ie(){var e;Te(),U(!(3&(e=Ce()))),0==e&&(e+=4),w[e>>2]=34821223,w[e+4>>2]=2310721022,w[0]=1668509029}function Se(){function e(){ne||(ne=!0,s.calledRun=!0,B||(U(!H),H=!0,k(),ae(x),i(s),s.onRuntimeInitialized&&s.onRuntimeInitialized(),U(!s._main,'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]'),function(){if(k(),s.postRun)for('function'==typeof s.postRun&&(s.postRun=[s.postRun]);s.postRun.length;)e=s.postRun.shift(),F.unshift(e);var e;ae(F)}()))}V>0||(Ie(),function(){if(s.preRun)for('function'==typeof s.preRun&&(s.preRun=[s.preRun]);s.preRun.length;)e=s.preRun.shift(),M.unshift(e);var e;ae(M)}(),V>0||(s.setStatus?(s.setStatus('Running...'),setTimeout((function(){setTimeout((function(){s.setStatus('')}),1),e()}),1)):e(),k()))}if(s.dynCall_jiji=$('dynCall_jiji',5),s.setValue=function(e,t,i="i8"){switch(i.endsWith('*')&&(i='*'),i){case'i1':case'i8':O[e]=t;break;case'i16':L[e>>1]=t;break;case'i32':P[e>>2]=t;break;case'i64':z('to do setValue(i64) use WASM_BIGINT');case'float':b[e>>2]=t;break;case'double':R[e>>3]=t;break;case'*':w[e>>2]=t;break;default:z(`invalid type for setValue: ${i}`)}},s.getValue=function(e,t="i8"){switch(t.endsWith('*')&&(t='*'),t){case'i1':case'i8':return O[e];case'i16':return L[e>>1];case'i32':return P[e>>2];case'i64':z('to do getValue(i64) use WASM_BIGINT');case'float':return b[e>>2];case'double':return R[e>>3];case'*':return w[e>>2];default:z(`invalid type for getValue: ${t}`)}},['writeI53ToI64','writeI53ToI64Clamped','writeI53ToI64Signaling','writeI53ToU64Clamped','writeI53ToU64Signaling','readI53FromI64','readI53FromU64','convertI32PairToI53','convertU32PairToI53','stackAlloc','getTempRet0','setTempRet0','zeroMemory','isLeapYear','ydayFromDate','arraySum','addDays','inetPton4','inetNtop4','inetPton6','inetNtop6','readSockaddr','writeSockaddr','initRandomFill','randomFill','emscriptenLog','readEmAsmArgs','jstoi_q','getExecutableName','listenOnce','autoResumeAudioContext','dynCallLegacy','getDynCaller','dynCall','handleException','runtimeKeepalivePush','runtimeKeepalivePop','callUserCallback','maybeExit','asmjsMangle','asyncLoad','alignMemory','mmapAlloc','HandleAllocator','getNativeTypeSize','STACK_SIZE','STACK_ALIGN','POINTER_SIZE','ASSERTIONS','getCFunc','ccall','cwrap','uleb128Encode','sigToWasmTypes','generateFuncType','convertJsFunctionToWasm','getEmptyTableSlot','updateTableMap','getFunctionAddress','addFunction','removeFunction','reallyNegative','unSign','strLen','reSign','formatString','stringToUTF8Array','stringToUTF8','lengthBytesUTF8','intArrayFromString','intArrayToString','AsciiToString','stringToAscii','UTF16ToString','stringToUTF16','lengthBytesUTF16','UTF32ToString','stringToUTF32','lengthBytesUTF32','stringToNewUTF8','stringToUTF8OnStack','writeArrayToMemory','registerKeyEventCallback','maybeCStringToJsString','findEventTarget','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','jsStackTrace','getCallstack','convertPCtoSourceLocation','getEnvStrings','checkWasiClock','wasiRightsToMuslOFlags','wasiOFlagsToMuslOFlags','createDyncallWrapper','safeSetTimeout','setImmediateWrapped','clearImmediateWrapped','polyfillSetImmediate','getPromise','makePromise','idsToPromises','makePromiseCallback','ExceptionInfo','findMatchingCatch','Browser_asyncPrepareDataCounter','setMainLoop','getSocketFromFD','getSocketAddress','FS_createPreloadedFile','FS_modeStringToFlags','FS_getMode','FS_stdin_getChar','FS_createDataFile','FS_unlink','FS_mkdirTree','_setNetworkCallback','heapObjectForWebGLType','toTypedArrayIndex','webgl_enable_ANGLE_instanced_arrays','webgl_enable_OES_vertex_array_object','webgl_enable_WEBGL_draw_buffers','webgl_enable_WEBGL_multi_draw','emscriptenWebGLGet','computeUnpackAlignedImageSize','colorChannelsInGlTextureFormat','emscriptenWebGLGetTexPixelData','emscriptenWebGLGetUniform','webglGetUniformLocation','webglPrepareUniformLocationsBeforeFirstUse','webglGetLeftBracePos','emscriptenWebGLGetVertexAttrib','__glGetActiveAttribOrUniform','writeGLArray','registerWebGlEventCallback','runAndAbortIfError','ALLOC_NORMAL','ALLOC_STACK','allocate','writeStringToMemory','writeAsciiToMemory','setErrNo','demangle','stackTrace'].forEach((function(e){'undefined'==typeof globalThis||Object.getOwnPropertyDescriptor(globalThis,e)||Object.defineProperty(globalThis,e,{configurable:!0,get(){var t=`\`${e}\` 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`,i=e;i.startsWith('_')||(i='$'+e),t+=` (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='${i}')`,te(e)&&(t+='. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you'),le(t)}}),re(e)})),['run','addOnPreRun','addOnInit','addOnPreMain','addOnExit','addOnPostRun','addRunDependency','removeRunDependency','FS_createFolder','FS_createPath','FS_createLazyFile','FS_createLink','FS_createDevice','FS_readFile','out','err','callMain','abort','wasmMemory','wasmExports','writeStackCookie','checkStackCookie','convertI32PairToI53Checked','stackSave','stackRestore','ptrToString','exitJS','getHeapMax','growMemory','ENV','MONTH_DAYS_REGULAR','MONTH_DAYS_LEAP','MONTH_DAYS_REGULAR_CUMULATIVE','MONTH_DAYS_LEAP_CUMULATIVE','ERRNO_CODES','ERRNO_MESSAGES','DNS','Protocols','Sockets','timers','warnOnce','readEmAsmArgsArray','jstoi_s','keepRuntimeAlive','wasmTable','noExitRuntime','freeTableIndexes','functionsInTableMap','PATH','PATH_FS','UTF8Decoder','UTF8ArrayToString','UTF8ToString','UTF16Decoder','JSEvents','specialHTMLTargets','findCanvasEventTarget','currentFullscreenStrategy','restoreOldWindowedStyle','UNWIND_CACHE','ExitStatus','flush_NO_FILESYSTEM','promiseMap','uncaughtExceptionCount','exceptionLast','exceptionCaught','Browser','getPreloadedImageData__data','wget','SYSCALLS','preloadPlugins','FS_stdin_getChar_buffer','FS','MEMFS','TTY','PIPEFS','SOCKFS','tempFixedLengthArray','miniTempWebGLFloatBuffers','miniTempWebGLIntBuffers','GL','AL','GLUT','EGL','GLEW','IDBStore','SDL','SDL_gfx','allocateUTF8','allocateUTF8OnStack'].forEach(re),W=function e(){ne||Se(),ne||(W=e)},s.preInit)for('function'==typeof s.preInit&&(s.preInit=[s.preInit]);s.preInit.length>0;)s.preInit.pop()();Se(),t=n;for(const t of Object.keys(s))t in e||Object.defineProperty(e,t,{configurable:!0,get(){z(`Access to module property ('${t}') is no longer possible via the module constructor argument; Instead, use the result of the module constructor.`)}});return t}),Ue=Be,De={'-2':'BZ_PARAM_ERROR: incorrect parameters','-3':"BZ_MEM_ERROR: couldn't allocate enough memory",'-4':'BZ_DATA_ERROR: data integrity error when decompressing','-5':'BZ_DATA_ERROR_MAGIC: compressed data has incorrect header','-7':'BZ_UNEXPECTED_EOF: compressed data ends too early','-8':'BZ_OUTBUFF_FULL: destination buffer is full'},ke=new class{constructor(){this.wasmModule=void 0}async init(){if(!this.wasmModule){if('undefined'!=typeof process){const{dirname:e}=await import('path'),{createRequire:t}=await import('module');globalThis.__dirname=e(import.meta.url),globalThis.require=t(import.meta.url)}this.wasmModule=await Ue()}}ensureInitialized(){if(!this.wasmModule)throw new Error(`${this.constructor.name} not initalized. call .init()`)}handleError(e,t,i){if(0===e)return;this.wasmModule._free(t),this.wasmModule._free(i);const r=De[e];if(r)throw new Error(r);throw new Error(`error code: ${e}`)}createWASMBuffers(e,t){const{_malloc:i,setValue:r,HEAPU8:s}=this.wasmModule,n=i(e.length);s.set(e,n);const a=i(t),o=i(t);return r(o,t,'i32'),{sourcePtr:n,destPtr:a,destLengthPtr:o}}createBuffer(e,t){const{_free:i,getValue:r,HEAPU8:s}=this.wasmModule,n=r(t,'i32'),a=new Uint8Array(n);return a.set(s.subarray(e,e+n)),i(e),i(t),a}decompress(e,t,i=!1,r=!1){if(r&&(t=e[0]<<24|e[1]<<16|e[2]<<8|e[3],e[0]='B'.charCodeAt(0),e[1]='Z'.charCodeAt(0),e[2]='h'.charCodeAt(0),e[3]='1'.charCodeAt(0),i=!1),i){const t=new Uint8Array(e.length+4);t[0]='B'.charCodeAt(0),t[1]='Z'.charCodeAt(0),t[2]='h'.charCodeAt(0),t[3]='1'.charCodeAt(0),t.set(e,4),e=t}this.ensureInitialized();const{sourcePtr:s,destPtr:n,destLengthPtr:a}=this.createWASMBuffers(e,t),o=this.wasmModule._BZ2_bzBuffToBuffDecompress(n,a,s,e.length,0,0);return this.wasmModule._free(s),this.handleError(o,n,a),this.createBuffer(n,a)}compress(e,t=!1,i=!1,r=1,s=0){if(this.ensureInitialized(),s||(s=e.length+1024),s<128&&(s=128),r<=0||r>9)throw new RangeError('blockSize should be between 1-9');const{sourcePtr:n,destPtr:a,destLengthPtr:o}=this.createWASMBuffers(e,s),c=this.wasmModule._BZ2_bzBuffToBuffCompress(a,o,n,e.length,r,0,30);this.wasmModule._free(n),this.handleError(c,a,o);const l=this.createBuffer(a,o);return t&&(l[0]=e.length>>24&255,l[1]=e.length>>16&255,l[2]=e.length>>8&255,l[3]=255&e.length),i?l.subarray(4):l}};await ke.init();var Me=ke;function xe(e){let t=0;e=e.toUpperCase();for(let i=0;ie===this.fileHash[t]));-1!==r&&(this.fileName[t]=He[r]),this.fileUnpackedSize[t]=e.g3(),this.filePackedSize[t]=e.g3(),this.filePos[t]=i,i+=this.filePackedSize[t]}}get(e){if(e<0||e>=this.fileCount)return null;if(null===this.data)throw new Error('Jagfile data is not loaded');const t=this.data.subarray(this.filePos[e],this.filePos[e]+this.filePackedSize[e]);return this.unpacked?new Oe(t):new Oe(Me.decompress(t,this.fileUnpackedSize[e],!0))}read(e){const t=xe(e);for(let e=0;ee===t.hash));if(t.write){if(-1===i&&(i=this.fileCount++,this.fileHash[i]=t.hash,this.fileName[i]=t.name),!t.data)throw new Error('Cannot write without data');this.fileUnpackedSize[i]=t.data.length,this.filePackedSize[i]=t.data.length,this.filePos[i]=-1,this.fileWrite[i]=t.data}if(t.delete&&-1!==i&&(this.fileHash.splice(i,1),this.fileName.splice(i,1),this.fileUnpackedSize.splice(i,1),this.filePackedSize.splice(i,1),this.filePos.splice(i,1),this.fileCount--),t.rename&&-1!==i){if(!t.newHash)throw new Error('Cannot rename without newHash');if(!t.newName)throw new Error('Cannot rename without newName');this.fileHash[i]=t.newHash,this.fileName[i]=t.newName}this.fileQueue.splice(e,1),e--}let r=1===this.fileCount;t&&r&&(r=!1),i.p2(this.fileCount);for(let e=0;e/?\\| ";for(let i=0;i<256;i++){let r=t.indexOf(String.fromCharCode(i));-1==r&&(r=74),e.CHAR_LOOKUP[i]=r}}static load(t){const i=Fe.load(`${t}/client/title`);e.instances[0]=new e(i,'p11'),e.instances[1]=new e(i,'p12'),e.instances[2]=new e(i,'b12'),e.instances[3]=new e(i,'q8')}static async loadAsync(t){const i=await Fe.loadAsync(`${t}/client/title`);e.instances[0]=new e(i,'p11'),e.instances[1]=new e(i,'p12'),e.instances[2]=new e(i,'b12'),e.instances[3]=new e(i,'q8')}static get(t){return e.instances[t]}static get count(){return this.instances.length}charMask=new Array(94);charMaskWidth=new Uint8Array(94);charMaskHeight=new Uint8Array(94);charOffsetX=new Uint8Array(94);charOffsetY=new Uint8Array(94);charAdvance=new Uint8Array(95);drawWidth=new Uint8Array(256);height=0;constructor(t,i){const r=t.read(`${i}.dat`),s=t.read('index.dat');if(!r||!s)return;s.pos=r.g2()+4;const n=s.g1();n>0&&(s.pos+=3*(n-1));for(let e=0;e<94;e++){this.charOffsetX[e]=s.g1(),this.charOffsetY[e]=s.g1();const t=this.charMaskWidth[e]=s.g2(),i=this.charMaskHeight[e]=s.g2(),n=s.g1(),a=t*i;if(this.charMask[e]=new Uint8Array(a),0==n)for(let t=0;tthis.height&&(this.height=i),this.charOffsetX[e]=1,this.charAdvance[e]=t+2;let o=0;for(let r=Math.floor(i/7);r0;){if(this.stringWidth(e)<=t&&-1===e.indexOf('|')){i.push(e);break}let r=e.length;for(let i=0;it)break;r=i}else if('|'===e[i]){r=i;break}i.push(e.substring(0,r)),e=e.substring(r+1)}return i}},We=(e=>(e[e.OFF=0]='OFF',e[e.OUTSIDE_WILDERNESS=1]='OUTSIDE_WILDERNESS',e))(We||{}),Ke=We,ze=(e=>(e[e.OFF=0]='OFF',e[e.PLAYER=1]='PLAYER',e[e.NPC=2]='NPC',e[e.OBJ=3]='OBJ',e[e.SCENERY=4]='SCENERY',e))(ze||{}),je=ze,Ye=(e=>(e[e.KEEPHUNTING=0]='KEEPHUNTING',e[e.PAUSEHUNT=1]='PAUSEHUNT',e))(Ye||{}),qe=Ye,Qe=(e=>(e[e.OFF=0]='OFF',e[e.LINEOFSIGHT=1]='LINEOFSIGHT',e[e.LINEOFWALK=2]='LINEOFWALK',e))(Qe||{}),$e=Qe,Ze=(e=>(e[e.NULL=-1]='NULL',e[e.NONE=0]='NONE',e[e.WANDER=1]='WANDER',e[e.PATROL=2]='PATROL',e[e.PLAYERESCAPE=3]='PLAYERESCAPE',e[e.PLAYERFOLLOW=4]='PLAYERFOLLOW',e[e.PLAYERFACE=5]='PLAYERFACE',e[e.PLAYERFACECLOSE=6]='PLAYERFACECLOSE',e[e.OPPLAYER1=7]='OPPLAYER1',e[e.OPPLAYER2=8]='OPPLAYER2',e[e.OPPLAYER3=9]='OPPLAYER3',e[e.OPPLAYER4=10]='OPPLAYER4',e[e.OPPLAYER5=11]='OPPLAYER5',e[e.APPLAYER1=12]='APPLAYER1',e[e.APPLAYER2=13]='APPLAYER2',e[e.APPLAYER3=14]='APPLAYER3',e[e.APPLAYER4=15]='APPLAYER4',e[e.APPLAYER5=16]='APPLAYER5',e[e.OPLOC1=17]='OPLOC1',e[e.OPLOC2=18]='OPLOC2',e[e.OPLOC3=19]='OPLOC3',e[e.OPLOC4=20]='OPLOC4',e[e.OPLOC5=21]='OPLOC5',e[e.APLOC1=22]='APLOC1',e[e.APLOC2=23]='APLOC2',e[e.APLOC3=24]='APLOC3',e[e.APLOC4=25]='APLOC4',e[e.APLOC5=26]='APLOC5',e[e.OPOBJ1=27]='OPOBJ1',e[e.OPOBJ2=28]='OPOBJ2',e[e.OPOBJ3=29]='OPOBJ3',e[e.OPOBJ4=30]='OPOBJ4',e[e.OPOBJ5=31]='OPOBJ5',e[e.APOBJ1=32]='APOBJ1',e[e.APOBJ2=33]='APOBJ2',e[e.APOBJ3=34]='APOBJ3',e[e.APOBJ4=35]='APOBJ4',e[e.APOBJ5=36]='APOBJ5',e[e.OPNPC1=37]='OPNPC1',e[e.OPNPC2=38]='OPNPC2',e[e.OPNPC3=39]='OPNPC3',e[e.OPNPC4=40]='OPNPC4',e[e.OPNPC5=41]='OPNPC5',e[e.APNPC1=42]='APNPC1',e[e.APNPC2=43]='APNPC2',e[e.APNPC3=44]='APNPC3',e[e.APNPC4=45]='APNPC4',e[e.APNPC5=46]='APNPC5',e[e.QUEUE1=47]='QUEUE1',e[e.QUEUE2=48]='QUEUE2',e[e.QUEUE3=49]='QUEUE3',e[e.QUEUE4=50]='QUEUE4',e[e.QUEUE5=51]='QUEUE5',e[e.QUEUE6=52]='QUEUE6',e[e.QUEUE7=53]='QUEUE7',e[e.QUEUE8=54]='QUEUE8',e[e.QUEUE9=55]='QUEUE9',e[e.QUEUE10=56]='QUEUE10',e[e.QUEUE11=57]='QUEUE11',e[e.QUEUE12=58]='QUEUE12',e[e.QUEUE13=59]='QUEUE13',e[e.QUEUE14=60]='QUEUE14',e[e.QUEUE15=61]='QUEUE15',e[e.QUEUE16=62]='QUEUE16',e[e.QUEUE17=63]='QUEUE17',e[e.QUEUE18=64]='QUEUE18',e[e.QUEUE19=65]='QUEUE19',e[e.QUEUE20=66]='QUEUE20',e))(Ze||{}),Xe=Ze,Je=class e extends Ne{static configNames=new Map;static configs=[];static load(e){if(!fs6.existsSync(`${e}/server/hunt.dat`))return void console.log('Warning: No hunt.dat found.');const t=Oe.load(`${e}/server/hunt.dat`);this.parse(t)}static async loadAsync(e){if(!(await fetch(`${e}/server/hunt.dat`)).ok)return void console.log('Warning: No hunt.dat found.');const t=await Oe.loadAsync(`${e}/server/hunt.dat`);this.parse(t)}static parse(t){e.configNames=new Map,e.configs=[];const i=t.g2();for(let r=0;r=40&&e<50)this.recol_s[e-40]=t.g2();else if(e>=50&&e<60)this.recol_d[e-50]=t.g2();else if(e>=60&&e<70)this.heads[e-60]=t.g2();else{if(250!==e)throw new Error(`Unrecognized idk config code: ${e}`);this.debugname=t.gjstr()}}},tt=class e{static TYPE_LAYER=0;static TYPE_UNUSED=1;static TYPE_INVENTORY=2;static TYPE_RECT=3;static TYPE_TEXT=4;static TYPE_SPRITE=5;static TYPE_MODEL=6;static TYPE_INVENTORY_TEXT=7;static NO_BUTTON=0;static BUTTON=1;static TARGET_BUTTON=2;static CLOSE_BUTTON=3;static TOGGLE_BUTTON=4;static SELECT_BUTTON=5;static PAUSE_BUTTON=6;static componentNames=new Map;static components=[];static load(e){if(!fs8.existsSync(`${e}/server/interface.dat`))return void console.log('Warning: No interface.dat found.');const t=Oe.load(`${e}/server/interface.dat`);this.parse(t)}static async loadAsync(e){if(!(await fetch(`${e}/server/interface.dat`)).ok)return void console.log('Warning: No interface.dat found.');const t=await Oe.loadAsync(`${e}/server/interface.dat`);this.parse(t)}static parse(t){this.componentNames=new Map,this.components=[],t.g2();let i=-1;for(;t.available>0;){let r=t.g2();65535===r&&(i=t.g2(),r=t.g2());const s=new e;s.id=r,s.rootLayer=i,s.comName=t.gjstr(),s.overlay=t.gbool(),s.type=t.g1(),s.buttonType=t.g1(),s.clientCode=t.g2(),s.width=t.g2(),s.height=t.g2(),s.overLayer=t.g1(),0==s.overLayer?s.overLayer=-1:s.overLayer=(s.overLayer-1<<8)+t.g1();const n=t.g1();if(n>0){s.scriptComparator=new Uint8Array(n).fill(0),s.scriptOperand=new Uint16Array(n).fill(0);for(let e=0;e0){s.scripts=new Array(a).fill(null);for(let e=0;e0&&10===r.shapes[0]?1:0,r.op&&r.op.length>0&&(r.active=1)),e.configs[i]=r,r.debugname&&e.configNames.set(r.debugname,i)}}static get(t){return e.configs[t]}static getId(t){return e.configNames.get(t)??-1}static getByName(e){const t=this.getId(e);return void 0===t||-1===t?null:this.get(t)}static get count(){return this.configs.length}models=null;shapes=null;name=null;desc=null;recol_s=null;recol_d=null;width=1;length=1;blockwalk=!0;blockrange=!0;active=0;hillskew=!1;sharelight=!1;occlude=!1;anim=-1;hasalpha=!1;wallwidth=16;ambient=0;contrast=0;op=null;mapfunction=-1;mapscene=-1;mirror=!1;shadow=!0;resizex=128;resizey=128;resizez=128;forceapproach=0;xoff=0;yoff=0;zoff=0;forcedecor=!1;category=-1;params=new Map;decode(e,t){if(1===e){const e=t.g1();this.models=new Uint16Array(e),this.shapes=new Uint8Array(e);for(let i=0;i=30&&e<35)this.op||(this.op=new Array(5).fill(null)),this.op[e-30]=t.gjstr(),'hidden'===this.op[e-30]&&(this.op[e-30]=null);else if(40===e){const e=t.g1();this.recol_s=new Uint16Array(e),this.recol_d=new Uint16Array(e);for(let i=0;i=1&&e<5)this.len[e-1]=t.g2();else{if(250!==e)throw new Error(`Unrecognized mesanim config code: ${e}`);this.debugname=t.gjstr()}}},ct=(e=>(e[e.NONE=0]='NONE',e[e.NPC=1]='NPC',e[e.ALL=2]='ALL',e))(ct||{}),lt=ct,ht=(e=>(e[e.NORMAL=0]='NORMAL',e[e.BLOCKED=1]='BLOCKED',e[e.BLOCKED_NORMAL=2]='BLOCKED_NORMAL',e[e.INDOORS=3]='INDOORS',e[e.OUTDOORS=4]='OUTDOORS',e[e.NOMOVE=5]='NOMOVE',e[e.PASSTHRU=6]='PASSTHRU',e))(ht||{}),dt=ht,ut=(e=>(e[e.ATTACK=0]='ATTACK',e[e.DEFENCE=1]='DEFENCE',e[e.STRENGTH=2]='STRENGTH',e[e.HITPOINTS=3]='HITPOINTS',e[e.RANGED=4]='RANGED',e[e.MAGIC=5]='MAGIC',e))(ut||{}),pt=ut,ft=class e extends Ne{static configNames=new Map;static configs=[];static load(e){if(!fs12.existsSync(`${e}/server/npc.dat`))return void console.log('Warning: No npc.dat found.');const t=Oe.load(`${e}/server/npc.dat`),i=Fe.load(`${e}/client/config`);this.parse(t,i)}static async loadAsync(e){if(!(await fetch(`${e}/server/npc.dat`)).ok)return void console.log('Warning: No npc.dat found.');const t=await Oe.loadAsync(`${e}/server/npc.dat`),i=await Fe.loadAsync(`${e}/client/config`);this.parse(t,i)}static parse(t,i){e.configNames=new Map,e.configs=[];const r=t.g2(),s=i.read('npc.dat');s.pos=2;for(let i=0;i=30&&e<40)this.op||(this.op=new Array(5).fill(null)),this.op[e-30]=t.gjstr(),'hidden'===this.op[e-30]&&(this.op[e-30]=null);else if(40===e){const e=t.g1();this.recol_s=new Uint16Array(e),this.recol_d=new Uint16Array(e);for(let i=0;i{gt.get(t)?.autodisable&&i.params.delete(t)})))}}static get(t){return e.configs[t]}static getId(t){return e.configNames.get(t)??-1}static getByName(e){const t=this.getId(e);return-1===t?null:this.get(t)}static get count(){return this.configs.length}static getWearPosId(e){switch(e){case'hat':return 0;case'back':return 1;case'front':return 2;case'righthand':return 3;case'torso':return 4;case'lefthand':return 5;case'arms':return 6;case'legs':return 7;case'head':return 8;case'hands':return 9;case'feet':return 10;case'jaw':return 11;case'ring':return 12;case'quiver':return 13;default:return-1}}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;op=null;iop=null;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;wearpos=-1;wearpos2=-1;wearpos3=-1;weight=0;category=-1;dummyitem=0;tradeable=!1;respawnrate=100;params=new Map;decode(e,t){if(1===e)this.model=t.g2();else if(2===e)this.name=t.gjstr();else if(3===e)this.desc=t.gjstr();else if(4===e)this.zoom2d=t.g2();else if(5===e)this.xan2d=t.g2();else if(6===e)this.yan2d=t.g2();else if(7===e)this.xof2d=t.g2s();else if(8===e)this.yof2d=t.g2s();else if(9===e)this.code9=!0;else if(10===e)this.code10=t.g2();else if(11===e)this.stackable=!0;else if(12===e)this.cost=t.g4();else if(13===e)this.wearpos=t.g1();else if(14===e)this.wearpos2=t.g1();else if(16===e)this.members=!0;else if(23===e)this.manwear=t.g2(),this.manwearOffsetY=t.g1b();else if(24===e)this.manwear2=t.g2();else if(25===e)this.womanwear=t.g2(),this.womanwearOffsetY=t.g1b();else if(26===e)this.womanwear2=t.g2();else if(27===e)this.wearpos3=t.g1();else if(e>=30&&e<35)this.op||(this.op=new Array(5).fill(null)),this.op[e-30]=t.gjstr();else if(e>=35&&e<40)this.iop||(this.iop=new Array(5).fill(null)),this.iop[e-35]=t.gjstr();else if(40===e){const e=t.g1();this.recol_s=new Uint16Array(e),this.recol_d=new Uint16Array(e);for(let i=0;i=100&&e<110)this.countobj&&this.countco||(this.countobj=new Uint16Array(10),this.countco=new Uint16Array(10)),this.countobj[e-100]=t.g2(),this.countco[e-100]=t.g2();else if(200===e)this.tradeable=!0;else if(201===e)this.respawnrate=t.g2();else if(249===e)this.params=nt(t);else{if(250!==e)throw new Error(`Unrecognized obj config code: ${e}`);this.debugname=t.gjstr()}}toCertificate(){const t=e.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 i=e.get(this.certlink);this.name=i.name,this.members=i.members,this.cost=i.cost,this.tradeable=i.tradeable;let r='a';const s=(i.name||'').toLowerCase().charAt(0);'a'!==s&&'e'!==s&&'i'!==s&&'o'!==s&&'u'!==s||(r='an'),this.desc=`Swap this note at any bank for ${r} ${i.name}.`,this.stackable=!0}},Ct=class e{static instances=[];static load(e){if(!fs15.existsSync(`${e}/server/frame_del.dat`))return void console.log('Warning: No frame_del.dat found.');const t=Oe.load(`${e}/server/frame_del.dat`);this.parse(t)}static async loadAsync(e){if(!(await fetch(`${e}/server/frame_del.dat`)).ok)return void console.log('Warning: No frame_del.dat found.');const t=await Oe.loadAsync(`${e}/server/frame_del.dat`);this.parse(t)}static parse(t){e.instances=[];for(let i=0;i=0&&s6)return 0;let t=0;for(let i=0;i=0;i++)if(Bt.isNumerical(e[i]))return i;return-1}indexOfNonNumber(e,t){for(let i=e;i=0;i++)if(!Bt.isNumerical(t[i]))return i;return t.length}},wt=class{wordEncFragments;bads=[];badCombinations=[];constructor(e){this.wordEncFragments=e}filter(e){for(let t=0;t<2;t++)for(let t=this.bads.length-1;t>=0;t--)this.filterBadCombinations(this.badCombinations[t],e,this.bads[t])}filterBadCombinations(e,t,i){if(!(i.length>t.length))for(let r=0;r<=t.length-i.length;r++){let s=r;const{currentIndex:n,badIndex:a,hasSymbol:o,hasNumber:c,hasDigit:l}=this.processBadCharacters(t,i,s);s=n;let h=t[s],d=s+1=i.length)||c&&l)continue;let u,p=!0;if(o){let e=!1,i=!1;if((r-1<0||Bt.isSymbol(t[r-1])&&"'"!=t[r-1])&&(e=!0),(s>=t.length||Bt.isSymbol(t[s])&&"'"!=t[s])&&(i=!0),!e||!i){let i=!1;for(u=r-2,e&&(u=r);!i&&u=0&&(!Bt.isSymbol(t[u])||"'"==t[u])){const e=[];let r;for(r=0;r<3&&u+r=0&&(!Bt.isSymbol(t[u-1])||"'"==t[u-1])&&(s=!1),s&&!this.wordEncFragments.isBadFragment(e)&&(i=!0)}u++}i||(p=!1)}}else{h=' ',r-1>=0&&(h=t[r-1]),d=' ',s=e.length||o&&c);){const l=e[r],h=r+10)1===d&&Bt.isNumerical(l)&&(o=!0),2===d&&(Bt.isNumerical(l)||Bt.isNumerical(h))&&(o=!0),r+=d,s++;else{if(0===s)break;let e;if((e=this.getEmulatedBadCharLen(h,String.fromCharCode(t[s-1]),l))>0)r+=e;else{if(s>=t.length||!Bt.isNotLowercaseAlpha(l))break;if(Bt.isSymbol(l)&&"'"!==l&&(a=!0),Bt.isNumerical(l)&&(c=!0),r++,n++,(100*n/(r-i)|0)>90)break}}}return{currentIndex:r,badIndex:s,hasSymbol:a,hasNumber:o,hasDigit:c}}getEmulatedBadCharLen(e,t,i){if(t==i)return 1;if(t>='a'&&t<='m'){if('a'==t)return'4'!=i&&'@'!=i&&'^'!=i?'/'==i&&'\\'==e?2:0:1;if('b'==t)return'6'!=i&&'8'!=i?'1'==i&&'3'==e?2:0:1;if('c'==t)return'('!=i&&'<'!=i&&'{'!=i&&'['!=i?0:1;if('d'==t)return'['==i&&')'==e?2:0;if('e'==t)return'3'!=i&&'€'!=i?0:1;if('f'==t)return'p'==i&&'h'==e?2:'£'==i?1:0;if('g'==t)return'9'!=i&&'6'!=i?0:1;if('h'==t)return'#'==i?1:0;if('i'==t)return'y'!=i&&'l'!=i&&'j'!=i&&'1'!=i&&'!'!=i&&':'!=i&&';'!=i&&'|'!=i?0:1;if('j'==t)return 0;if('k'==t)return 0;if('l'==t)return'1'!=i&&'|'!=i&&'i'!=i?0:1;if('m'==t)return 0}if(t>='n'&&t<='z'){if('n'==t)return 0;if('o'==t)return'0'!=i&&'*'!=i?'('==i&&')'==e||'['==i&&']'==e||'{'==i&&'}'==e||'<'==i&&'>'==e?2:0:1;if('p'==t)return 0;if('q'==t)return 0;if('r'==t)return 0;if('s'==t)return'5'!=i&&'z'!=i&&'$'!=i&&'2'!=i?0:1;if('t'==t)return'7'!=i&&'+'!=i?0:1;if('u'==t)return'v'==i?1:'\\'==i&&'/'==e||'\\'==i&&'|'==e||'|'==i&&'/'==e?2:0;if('v'==t)return'\\'==i&&'/'==e||'\\'==i&&'|'==e||'|'==i&&'/'==e?2:0;if('w'==t)return'v'==i&&'v'==e?2:0;if('x'==t)return')'==i&&'('==e||'}'==i&&'{'==e||']'==i&&'['==e||'>'==i&&'<'==e?2:0;if('y'==t)return 0;if('z'==t)return 0}return t>='0'&&t<='9'?'0'==t?'o'==i||'O'==i?1:'('==i&&')'==e||'{'==i&&'}'==e||'['==i&&']'==e?2:0:'1'==t&&'l'==i?1:0:','==t?'.'==i?1:0:'.'==t?','==i?1:0:'!'==t&&'i'==i?1:0}comboMatches(e,t,i){let r=0,s=t.length-1;for(;r<=s;){const n=(r+s)/2|0;if(t[n][0]===e&&t[n][1]===i)return!0;e=0;r--)this.filterDomain(i,t,this.domains[r],e)}getEmulatedDomainCharLen(e,t,i){return t==i||'o'==t&&'0'==i?1:'o'==t&&'('==i&&')'==e?2:'c'!=t||'('!=i&&'<'!=i&&'['!=i?'e'==t&&'€'==i||'s'==t&&'$'==i||'l'==t&&'i'==i?1:0:1}filterDomain(e,t,i,r){const s=i.length,n=r.length;for(let a=0;a<=n-s;a++){const{matched:s,currentIndex:n}=this.findMatchingDomain(a,i,r);if(!s)continue;const o=Bt.prefixSymbolStatus(a,r,3,t,['@']),c=Bt.suffixSymbolStatus(n-1,r,3,e,['.',',']);(o>2||c>2)&&Bt.maskChars(a,n,r)}}findMatchingDomain(e,t,i){const r=t.length;let s=e,n=0;for(;s0)s+=c,n++;else{if(0===n)break;const i=this.getEmulatedDomainCharLen(o,String.fromCharCode(t[n-1]),a);if(i>0)s+=i,1===n&&e++;else{if(n>=r||!Bt.isSymbol(a))break;s++}}}return{matched:n>=r,currentIndex:s}}},Rt=class{wordEncBadWords;wordEncDomains;tlds=[];tldTypes=[];constructor(e,t){this.wordEncBadWords=e,this.wordEncDomains=t}filter(e){const t=[...e],i=[...e];this.wordEncBadWords.filterBadCombinations(null,t,Bt.PERIOD),this.wordEncBadWords.filterBadCombinations(null,i,Bt.SLASH);for(let r=0;ri.length))for(let n=0;n<=i.length-r.length;n++){const{currentIndex:a,tldIndex:o}=this.processTlds(i,r,n);if(o0&&h>0&&(c=!0),2==t&&(l>2&&h>0||l>0&&h>2)&&(c=!0),3==t&&l>0&&h>2&&(c=!0),!c)continue;let d,u=n,p=a-1,f=!1;if(l>2){if(4==l)for(f=!1,d=n-1;d>=0;d--)if(f){if('*'!=s[d])break;u=d}else'*'==s[d]&&(u=d,f=!0);for(f=!1,d=u-1;d>=0;d--)if(f){if(Bt.isSymbol(i[d]))break;u=d}else Bt.isSymbol(i[d])||(f=!0,u=d)}if(h>2){if(4==h)for(f=!1,d=p+1;d0)i+=a,r++;else{if(0===r)break;let e;if((e=this.wordEncDomains.getEmulatedDomainCharLen(n,String.fromCharCode(t[r-1]),s))>0)i+=e;else{if(!Bt.isSymbol(s))break;i++}}}return{currentIndex:i,tldIndex:r}}},Bt=class e{static PERIOD=new Uint16Array(['d','o','t'].join('').split('').map((e=>e.charCodeAt(0))));static AMPERSAT=new Uint16Array(['(','a',')'].join('').split('').map((e=>e.charCodeAt(0))));static SLASH=new Uint16Array(['s','l','a','s','h'].join('').split('').map((e=>e.charCodeAt(0))));static wordEncFragments=new Pt;static wordEncBadWords=new wt(this.wordEncFragments);static wordEncDomains=new bt(this.wordEncBadWords);static wordEncTlds=new Rt(this.wordEncBadWords,this.wordEncDomains);static whitelist=['cook',"cook's",'cooks','seeks','sheet'];static async load(e){if(!fs21.existsSync(`${e}/client/wordenc`))return void console.log('Warning: No wordenc found.');const t=Fe.load(`${e}/client/wordenc`);this.readAll(t)}static async loadAsync(e){if(!(await fetch(`${e}/client/wordenc`)).ok)return void console.log('Warning: No wordenc found.');const t=await Fe.loadAsync(`${e}/client/wordenc`);this.readAll(t)}static readAll(e){const t=e.read('fragmentsenc.txt');if(!t)return void console.log('Warning: No fragmentsenc found.');const i=e.read('badenc.txt');if(!i)return void console.log('Warning: No badenc found.');const r=e.read('domainenc.txt');if(!r)return void console.log('Warning: No domainenc found.');const s=e.read('tldlist.txt');s?(this.decodeBadEnc(i),this.decodeDomainEnc(r),this.decodeFragmentsEnc(t),this.decodeTldList(s)):console.log('Warning: No tldlist found.')}static filter(e){const t=[...e];this.format(t);const i=t.join('').trim(),r=i.toLowerCase(),s=[...r];this.wordEncTlds.filter(s),this.wordEncBadWords.filter(s),this.wordEncDomains.filter(s),this.wordEncFragments.filter(s);for(let e=0;e='0'&&e<='9'}static isLowercaseAlpha(e){return e>='a'&&e<='z'}static isUppercaseAlpha(e){return e>='A'&&e<='Z'}static isNumericalChars(e){for(let t=0;t=0&&e.isSymbol(t[s]);s--)'*'===t[s]&&r++;return r}static maskedCountForwards(e,t){let i=0;for(let r=t+1;r=r?4:this.isSymbol(s?e[i-1]:e[i+1])?1:0}static prefixSymbolStatus(t,i,r,s,n){if(0===t)return 2;for(let r=t-1;r>=0&&e.isSymbol(i[r]);r--)if(n.includes(i[r]))return 3;return e.maskedCharsStatus(i,s,t,r,!0)}static suffixSymbolStatus(t,i,r,s,n){if(t+1===i.length)return 2;for(let r=t+1;re.g1()))}static decodeBadEnc(e){const t=e.g4();for(let i=0;ie.g1()));const t=new Array(e.g1()).fill([]).map((()=>[e.g1b(),e.g1b()]));t.length>0&&(this.wordEncBadWords.badCombinations[i]=t)}}static decodeDomainEnc(e){const t=e.g4();for(let i=0;ie.g1()))}static decodeFragmentsEnc(e){const t=e.g4();for(let i=0;i=' '&&e<=''||' '==e||'\n'==e||'\t'==e||'£'==e||'€'==e}static replaceUppercases(e,t){for(let i=0;i=40&&e<50)this.recol_s[e-40]=t.g2();else if(e>=50&&e<60)this.recol_d[e-50]=t.g2();else{if(250!==e)throw new Error(`Unrecognized spotanim config code: ${e}`);this.debugname=t.gjstr()}}},Dt=(e=>(e[e.ActivePlayer=0]='ActivePlayer',e[e.ActivePlayer2=1]='ActivePlayer2',e[e.ProtectedActivePlayer=2]='ProtectedActivePlayer',e[e.ProtectedActivePlayer2=3]='ProtectedActivePlayer2',e[e.ActiveNpc=4]='ActiveNpc',e[e.ActiveNpc2=5]='ActiveNpc2',e[e.ActiveLoc=6]='ActiveLoc',e[e.ActiveLoc2=7]='ActiveLoc2',e[e.ActiveObj=8]='ActiveObj',e[e.ActiveObj2=9]='ActiveObj2',e[e._LAST=10]='_LAST',e))(Dt||{}),kt=[4,5],Mt=[6,7],xt=[8,9],Ft=[0,1],Ht=[2,3];function Vt(e,t){return function(i){'number'==typeof e?i.pointerCheck(e):i.pointerCheck(e[i.intOperand]),t(i)}}var Gt=Dt,Wt=(e=>(e[e.PUSH_CONSTANT_INT=0]='PUSH_CONSTANT_INT',e[e.PUSH_VARP=1]='PUSH_VARP',e[e.POP_VARP=2]='POP_VARP',e[e.PUSH_CONSTANT_STRING=3]='PUSH_CONSTANT_STRING',e[e.PUSH_VARN=4]='PUSH_VARN',e[e.POP_VARN=5]='POP_VARN',e[e.BRANCH=6]='BRANCH',e[e.BRANCH_NOT=7]='BRANCH_NOT',e[e.BRANCH_EQUALS=8]='BRANCH_EQUALS',e[e.BRANCH_LESS_THAN=9]='BRANCH_LESS_THAN',e[e.BRANCH_GREATER_THAN=10]='BRANCH_GREATER_THAN',e[e.PUSH_VARS=11]='PUSH_VARS',e[e.POP_VARS=12]='POP_VARS',e[e.RETURN=21]='RETURN',e[e.GOSUB=22]='GOSUB',e[e.JUMP=23]='JUMP',e[e.SWITCH=24]='SWITCH',e[e.BRANCH_LESS_THAN_OR_EQUALS=31]='BRANCH_LESS_THAN_OR_EQUALS',e[e.BRANCH_GREATER_THAN_OR_EQUALS=32]='BRANCH_GREATER_THAN_OR_EQUALS',e[e.PUSH_INT_LOCAL=33]='PUSH_INT_LOCAL',e[e.POP_INT_LOCAL=34]='POP_INT_LOCAL',e[e.PUSH_STRING_LOCAL=35]='PUSH_STRING_LOCAL',e[e.POP_STRING_LOCAL=36]='POP_STRING_LOCAL',e[e.JOIN_STRING=37]='JOIN_STRING',e[e.POP_INT_DISCARD=38]='POP_INT_DISCARD',e[e.POP_STRING_DISCARD=39]='POP_STRING_DISCARD',e[e.GOSUB_WITH_PARAMS=40]='GOSUB_WITH_PARAMS',e[e.JUMP_WITH_PARAMS=41]='JUMP_WITH_PARAMS',e[e.DEFINE_ARRAY=44]='DEFINE_ARRAY',e[e.PUSH_ARRAY_INT=45]='PUSH_ARRAY_INT',e[e.POP_ARRAY_INT=46]='POP_ARRAY_INT',e[e.COORDX=1e3]='COORDX',e[e.COORDY=1001]='COORDY',e[e.COORDZ=1002]='COORDZ',e[e.DISTANCE=1003]='DISTANCE',e[e.HUNTALL=1004]='HUNTALL',e[e.HUNTNEXT=1005]='HUNTNEXT',e[e.INZONE=1006]='INZONE',e[e.LINEOFSIGHT=1007]='LINEOFSIGHT',e[e.LINEOFWALK=1008]='LINEOFWALK',e[e.MAP_BLOCKED=1009]='MAP_BLOCKED',e[e.MAP_INDOORS=1010]='MAP_INDOORS',e[e.MAP_CLOCK=1011]='MAP_CLOCK',e[e.MAP_LOCADDUNSAFE=1012]='MAP_LOCADDUNSAFE',e[e.MAP_MEMBERS=1013]='MAP_MEMBERS',e[e.MAP_PLAYERCOUNT=1014]='MAP_PLAYERCOUNT',e[e.MOVECOORD=1015]='MOVECOORD',e[e.PLAYERCOUNT=1016]='PLAYERCOUNT',e[e.PROJANIM_MAP=1017]='PROJANIM_MAP',e[e.PROJANIM_NPC=1018]='PROJANIM_NPC',e[e.PROJANIM_PL=1019]='PROJANIM_PL',e[e.SEQLENGTH=1020]='SEQLENGTH',e[e.SPLIT_GET=1021]='SPLIT_GET',e[e.SPLIT_GETANIM=1022]='SPLIT_GETANIM',e[e.SPLIT_INIT=1023]='SPLIT_INIT',e[e.SPLIT_LINECOUNT=1024]='SPLIT_LINECOUNT',e[e.SPLIT_PAGECOUNT=1025]='SPLIT_PAGECOUNT',e[e.SPOTANIM_MAP=1026]='SPOTANIM_MAP',e[e.STAT_RANDOM=1027]='STAT_RANDOM',e[e.STRUCT_PARAM=1028]='STRUCT_PARAM',e[e.WORLD_DELAY=1029]='WORLD_DELAY',e[e.NPCCOUNT=1030]='NPCCOUNT',e[e.ZONECOUNT=1031]='ZONECOUNT',e[e.LOCCOUNT=1032]='LOCCOUNT',e[e.OBJCOUNT=1033]='OBJCOUNT',e[e.ALLOWDESIGN=2e3]='ALLOWDESIGN',e[e.ANIM=2001]='ANIM',e[e.BAS_READYANIM=2002]='BAS_READYANIM',e[e.BAS_RUNNING=2003]='BAS_RUNNING',e[e.BAS_TURNONSPOT=2004]='BAS_TURNONSPOT',e[e.BAS_WALK_B=2005]='BAS_WALK_B',e[e.BAS_WALK_F=2006]='BAS_WALK_F',e[e.BAS_WALK_L=2007]='BAS_WALK_L',e[e.BAS_WALK_R=2008]='BAS_WALK_R',e[e.BUFFER_FULL=2009]='BUFFER_FULL',e[e.BUILDAPPEARANCE=2010]='BUILDAPPEARANCE',e[e.BUSY=2011]='BUSY',e[e.CAM_LOOKAT=2012]='CAM_LOOKAT',e[e.CAM_MOVETO=2013]='CAM_MOVETO',e[e.CAM_RESET=2014]='CAM_RESET',e[e.CAM_SHAKE=2015]='CAM_SHAKE',e[e.CLEARQUEUE=2016]='CLEARQUEUE',e[e.CLEARSOFTTIMER=2017]='CLEARSOFTTIMER',e[e.CLEARTIMER=2018]='CLEARTIMER',e[e.COORD=2019]='COORD',e[e.DAMAGE=2020]='DAMAGE',e[e.DISPLAYNAME=2021]='DISPLAYNAME',e[e.FACESQUARE=2022]='FACESQUARE',e[e.FINDUID=2023]='FINDUID',e[e.GENDER=2024]='GENDER',e[e.GETQUEUE=2025]='GETQUEUE',e[e.GIVEXP=2026]='GIVEXP',e[e.HEADICONS_GET=2027]='HEADICONS_GET',e[e.HEADICONS_SET=2028]='HEADICONS_SET',e[e.HEALENERGY=2029]='HEALENERGY',e[e.HINT_COORD=2030]='HINT_COORD',e[e.HINT_NPC=2031]='HINT_NPC',e[e.HINT_PLAYER=2032]='HINT_PLAYER',e[e.HINT_STOP=2033]='HINT_STOP',e[e.IF_CLOSE=2034]='IF_CLOSE',e[e.IF_CLOSESTICKY=2035]='IF_CLOSESTICKY',e[e.IF_MULTIZONE=2036]='IF_MULTIZONE',e[e.IF_OPENCHAT=2037]='IF_OPENCHAT',e[e.IF_OPENCHATSTICKY=2038]='IF_OPENCHATSTICKY',e[e.IF_OPENMAINMODAL=2039]='IF_OPENMAINMODAL',e[e.IF_OPENMAINMODALSIDEOVERLAY=2040]='IF_OPENMAINMODALSIDEOVERLAY',e[e.IF_OPENSIDEOVERLAY=2041]='IF_OPENSIDEOVERLAY',e[e.IF_SETANIM=2042]='IF_SETANIM',e[e.IF_SETCOLOUR=2043]='IF_SETCOLOUR',e[e.IF_SETHIDE=2044]='IF_SETHIDE',e[e.IF_SETMODEL=2045]='IF_SETMODEL',e[e.IF_SETRECOL=2046]='IF_SETRECOL',e[e.IF_SETNPCHEAD=2047]='IF_SETNPCHEAD',e[e.IF_SETOBJECT=2048]='IF_SETOBJECT',e[e.IF_SETPLAYERHEAD=2049]='IF_SETPLAYERHEAD',e[e.IF_SETPOSITION=2050]='IF_SETPOSITION',e[e.IF_SETRESUMEBUTTONS=2051]='IF_SETRESUMEBUTTONS',e[e.IF_SETTAB=2052]='IF_SETTAB',e[e.IF_SETTABACTIVE=2053]='IF_SETTABACTIVE',e[e.IF_SETTABFLASH=2054]='IF_SETTABFLASH',e[e.IF_SETTEXT=2055]='IF_SETTEXT',e[e.LAST_LOGIN_INFO=2056]='LAST_LOGIN_INFO',e[e.LAST_COM=2057]='LAST_COM',e[e.LAST_INT=2058]='LAST_INT',e[e.LAST_ITEM=2059]='LAST_ITEM',e[e.LAST_SLOT=2060]='LAST_SLOT',e[e.LAST_TARGETSLOT=2061]='LAST_TARGETSLOT',e[e.LAST_USEITEM=2062]='LAST_USEITEM',e[e.LAST_USESLOT=2063]='LAST_USESLOT',e[e.LONGQUEUE=2064]='LONGQUEUE',e[e.MES=2065]='MES',e[e.MIDI_JINGLE=2066]='MIDI_JINGLE',e[e.MIDI_SONG=2067]='MIDI_SONG',e[e.NAME=2068]='NAME',e[e.P_APRANGE=2069]='P_APRANGE',e[e.P_ARRIVEDELAY=2070]='P_ARRIVEDELAY',e[e.P_COUNTDIALOG=2071]='P_COUNTDIALOG',e[e.P_DELAY=2072]='P_DELAY',e[e.P_EXACTMOVE=2073]='P_EXACTMOVE',e[e.P_FINDUID=2074]='P_FINDUID',e[e.P_LOCMERGE=2075]='P_LOCMERGE',e[e.P_LOGOUT=2076]='P_LOGOUT',e[e.P_OPHELD=2077]='P_OPHELD',e[e.P_OPLOC=2078]='P_OPLOC',e[e.P_OPNPC=2079]='P_OPNPC',e[e.P_OPNPCT=2080]='P_OPNPCT',e[e.P_OPOBJ=2081]='P_OPOBJ',e[e.P_OPPLAYER=2082]='P_OPPLAYER',e[e.P_OPPLAYERT=2083]='P_OPPLAYERT',e[e.P_PAUSEBUTTON=2084]='P_PAUSEBUTTON',e[e.P_STOPACTION=2085]='P_STOPACTION',e[e.P_TELEJUMP=2086]='P_TELEJUMP',e[e.P_TELEPORT=2087]='P_TELEPORT',e[e.P_WALK=2088]='P_WALK',e[e.PLAYER_FINDALLZONE=2089]='PLAYER_FINDALLZONE',e[e.PLAYER_FINDNEXT=2090]='PLAYER_FINDNEXT',e[e.QUEUE=2091]='QUEUE',e[e.SAY=2092]='SAY',e[e.WALKTRIGGER=2093]='WALKTRIGGER',e[e.SETTIMER=2094]='SETTIMER',e[e.SOFTTIMER=2095]='SOFTTIMER',e[e.SOUND_SYNTH=2096]='SOUND_SYNTH',e[e.SPOTANIM_PL=2097]='SPOTANIM_PL',e[e.STAFFMODLEVEL=2098]='STAFFMODLEVEL',e[e.STAT=2099]='STAT',e[e.STAT_ADD=2100]='STAT_ADD',e[e.STAT_BASE=2101]='STAT_BASE',e[e.STAT_HEAL=2102]='STAT_HEAL',e[e.STAT_SUB=2103]='STAT_SUB',e[e.STRONGQUEUE=2104]='STRONGQUEUE',e[e.UID=2105]='UID',e[e.WEAKQUEUE=2106]='WEAKQUEUE',e[e.IF_OPENMAINOVERLAY=2107]='IF_OPENMAINOVERLAY',e[e.AFK_EVENT=2108]='AFK_EVENT',e[e.LOWMEMORY=2109]='LOWMEMORY',e[e.SETIDKIT=2110]='SETIDKIT',e[e.P_CLEARPENDINGACTION=2111]='P_CLEARPENDINGACTION',e[e.GETWALKTRIGGER=2112]='GETWALKTRIGGER',e[e.BUSY2=2113]='BUSY2',e[e.FINDHERO=2114]='FINDHERO',e[e.BOTH_HEROPOINTS=2115]='BOTH_HEROPOINTS',e[e.SETGENDER=2116]='SETGENDER',e[e.SETSKINCOLOUR=2117]='SETSKINCOLOUR',e[e.P_ANIMPROTECT=2118]='P_ANIMPROTECT',e[e.RUNENERGY=2119]='RUNENERGY',e[e.WEIGHT=2120]='WEIGHT',e[e.LAST_COORD=2121]='LAST_COORD',e[e.NPC_ADD=2500]='NPC_ADD',e[e.NPC_ANIM=2501]='NPC_ANIM',e[e.NPC_BASESTAT=2502]='NPC_BASESTAT',e[e.NPC_CATEGORY=2503]='NPC_CATEGORY',e[e.NPC_CHANGETYPE=2504]='NPC_CHANGETYPE',e[e.NPC_COORD=2505]='NPC_COORD',e[e.NPC_DAMAGE=2506]='NPC_DAMAGE',e[e.NPC_DEL=2507]='NPC_DEL',e[e.NPC_DELAY=2508]='NPC_DELAY',e[e.NPC_FACESQUARE=2509]='NPC_FACESQUARE',e[e.NPC_FIND=2510]='NPC_FIND',e[e.NPC_FINDALLANY=2511]='NPC_FINDALLANY',e[e.NPC_FINDEXACT=2512]='NPC_FINDEXACT',e[e.NPC_FINDHERO=2513]='NPC_FINDHERO',e[e.NPC_FINDALLZONE=2514]='NPC_FINDALLZONE',e[e.NPC_FINDNEXT=2515]='NPC_FINDNEXT',e[e.NPC_FINDUID=2516]='NPC_FINDUID',e[e.NPC_GETMODE=2517]='NPC_GETMODE',e[e.NPC_HEROPOINTS=2518]='NPC_HEROPOINTS',e[e.NPC_NAME=2519]='NPC_NAME',e[e.NPC_PARAM=2520]='NPC_PARAM',e[e.NPC_QUEUE=2521]='NPC_QUEUE',e[e.NPC_RANGE=2522]='NPC_RANGE',e[e.NPC_SAY=2523]='NPC_SAY',e[e.NPC_HUNTALL=2524]='NPC_HUNTALL',e[e.NPC_HUNTNEXT=2525]='NPC_HUNTNEXT',e[e.NPC_SETHUNT=2526]='NPC_SETHUNT',e[e.NPC_SETHUNTMODE=2527]='NPC_SETHUNTMODE',e[e.NPC_SETMODE=2528]='NPC_SETMODE',e[e.NPC_WALKTRIGGER=2529]='NPC_WALKTRIGGER',e[e.NPC_SETTIMER=2530]='NPC_SETTIMER',e[e.NPC_STAT=2531]='NPC_STAT',e[e.NPC_STATADD=2532]='NPC_STATADD',e[e.NPC_STATHEAL=2533]='NPC_STATHEAL',e[e.NPC_STATSUB=2534]='NPC_STATSUB',e[e.NPC_TELE=2535]='NPC_TELE',e[e.NPC_TYPE=2536]='NPC_TYPE',e[e.NPC_UID=2537]='NPC_UID',e[e.SPOTANIM_NPC=2538]='SPOTANIM_NPC',e[e.NPC_WALK=2539]='NPC_WALK',e[e.NPC_ATTACKRANGE=2540]='NPC_ATTACKRANGE',e[e.LOC_ADD=3e3]='LOC_ADD',e[e.LOC_ANGLE=3001]='LOC_ANGLE',e[e.LOC_ANIM=3002]='LOC_ANIM',e[e.LOC_CATEGORY=3003]='LOC_CATEGORY',e[e.LOC_CHANGE=3004]='LOC_CHANGE',e[e.LOC_COORD=3005]='LOC_COORD',e[e.LOC_DEL=3006]='LOC_DEL',e[e.LOC_FIND=3007]='LOC_FIND',e[e.LOC_FINDALLZONE=3008]='LOC_FINDALLZONE',e[e.LOC_FINDNEXT=3009]='LOC_FINDNEXT',e[e.LOC_NAME=3010]='LOC_NAME',e[e.LOC_PARAM=3011]='LOC_PARAM',e[e.LOC_SHAPE=3012]='LOC_SHAPE',e[e.LOC_TYPE=3013]='LOC_TYPE',e[e.OBJ_ADD=3500]='OBJ_ADD',e[e.OBJ_ADDALL=3501]='OBJ_ADDALL',e[e.OBJ_COORD=3502]='OBJ_COORD',e[e.OBJ_COUNT=3503]='OBJ_COUNT',e[e.OBJ_DEL=3504]='OBJ_DEL',e[e.OBJ_NAME=3505]='OBJ_NAME',e[e.OBJ_PARAM=3506]='OBJ_PARAM',e[e.OBJ_TAKEITEM=3507]='OBJ_TAKEITEM',e[e.OBJ_TYPE=3508]='OBJ_TYPE',e[e.NC_CATEGORY=4e3]='NC_CATEGORY',e[e.NC_DEBUGNAME=4001]='NC_DEBUGNAME',e[e.NC_DESC=4002]='NC_DESC',e[e.NC_NAME=4003]='NC_NAME',e[e.NC_OP=4004]='NC_OP',e[e.NC_PARAM=4005]='NC_PARAM',e[e.LC_CATEGORY=4100]='LC_CATEGORY',e[e.LC_DEBUGNAME=4101]='LC_DEBUGNAME',e[e.LC_DESC=4102]='LC_DESC',e[e.LC_NAME=4103]='LC_NAME',e[e.LC_OP=4104]='LC_OP',e[e.LC_PARAM=4105]='LC_PARAM',e[e.LC_WIDTH=4106]='LC_WIDTH',e[e.LC_LENGTH=4107]='LC_LENGTH',e[e.OC_CATEGORY=4200]='OC_CATEGORY',e[e.OC_CERT=4201]='OC_CERT',e[e.OC_COST=4202]='OC_COST',e[e.OC_DEBUGNAME=4203]='OC_DEBUGNAME',e[e.OC_DESC=4204]='OC_DESC',e[e.OC_IOP=4205]='OC_IOP',e[e.OC_MEMBERS=4206]='OC_MEMBERS',e[e.OC_NAME=4207]='OC_NAME',e[e.OC_OP=4208]='OC_OP',e[e.OC_PARAM=4209]='OC_PARAM',e[e.OC_STACKABLE=4210]='OC_STACKABLE',e[e.OC_TRADEABLE=4211]='OC_TRADEABLE',e[e.OC_UNCERT=4212]='OC_UNCERT',e[e.OC_WEARPOS2=4213]='OC_WEARPOS2',e[e.OC_WEARPOS3=4214]='OC_WEARPOS3',e[e.OC_WEARPOS=4215]='OC_WEARPOS',e[e.OC_WEIGHT=4216]='OC_WEIGHT',e[e.INV_ALLSTOCK=4300]='INV_ALLSTOCK',e[e.INV_SIZE=4301]='INV_SIZE',e[e.INV_STOCKBASE=4302]='INV_STOCKBASE',e[e.INV_ADD=4303]='INV_ADD',e[e.INV_CHANGESLOT=4304]='INV_CHANGESLOT',e[e.INV_CLEAR=4305]='INV_CLEAR',e[e.INV_DEL=4306]='INV_DEL',e[e.INV_DELSLOT=4307]='INV_DELSLOT',e[e.INV_DROPITEM=4308]='INV_DROPITEM',e[e.INV_DROPSLOT=4309]='INV_DROPSLOT',e[e.INV_FREESPACE=4310]='INV_FREESPACE',e[e.INV_GETNUM=4311]='INV_GETNUM',e[e.INV_GETOBJ=4312]='INV_GETOBJ',e[e.INV_ITEMSPACE=4313]='INV_ITEMSPACE',e[e.INV_ITEMSPACE2=4314]='INV_ITEMSPACE2',e[e.INV_MOVEFROMSLOT=4315]='INV_MOVEFROMSLOT',e[e.INV_MOVETOSLOT=4316]='INV_MOVETOSLOT',e[e.BOTH_MOVEINV=4317]='BOTH_MOVEINV',e[e.INV_MOVEITEM=4318]='INV_MOVEITEM',e[e.INV_MOVEITEM_CERT=4319]='INV_MOVEITEM_CERT',e[e.INV_MOVEITEM_UNCERT=4320]='INV_MOVEITEM_UNCERT',e[e.INV_SETSLOT=4321]='INV_SETSLOT',e[e.INV_TOTAL=4322]='INV_TOTAL',e[e.INV_TOTALCAT=4323]='INV_TOTALCAT',e[e.INV_TRANSMIT=4324]='INV_TRANSMIT',e[e.INVOTHER_TRANSMIT=4325]='INVOTHER_TRANSMIT',e[e.INV_STOPTRANSMIT=4326]='INV_STOPTRANSMIT',e[e.BOTH_DROPSLOT=4327]='BOTH_DROPSLOT',e[e.INV_DROPALL=4328]='INV_DROPALL',e[e.INV_TOTALPARAM=4329]='INV_TOTALPARAM',e[e.INV_TOTALPARAM_STACK=4330]='INV_TOTALPARAM_STACK',e[e.ENUM=4400]='ENUM',e[e.ENUM_GETOUTPUTCOUNT=4401]='ENUM_GETOUTPUTCOUNT',e[e.APPEND_NUM=4500]='APPEND_NUM',e[e.APPEND=4501]='APPEND',e[e.APPEND_SIGNNUM=4502]='APPEND_SIGNNUM',e[e.LOWERCASE=4503]='LOWERCASE',e[e.TEXT_GENDER=4504]='TEXT_GENDER',e[e.TOSTRING=4505]='TOSTRING',e[e.COMPARE=4506]='COMPARE',e[e.TEXT_SWITCH=4507]='TEXT_SWITCH',e[e.APPEND_CHAR=4508]='APPEND_CHAR',e[e.STRING_LENGTH=4509]='STRING_LENGTH',e[e.SUBSTRING=4510]='SUBSTRING',e[e.STRING_INDEXOF_CHAR=4511]='STRING_INDEXOF_CHAR',e[e.STRING_INDEXOF_STRING=4512]='STRING_INDEXOF_STRING',e[e.ADD=4600]='ADD',e[e.SUB=4601]='SUB',e[e.MULTIPLY=4602]='MULTIPLY',e[e.DIVIDE=4603]='DIVIDE',e[e.RANDOM=4604]='RANDOM',e[e.RANDOMINC=4605]='RANDOMINC',e[e.INTERPOLATE=4606]='INTERPOLATE',e[e.ADDPERCENT=4607]='ADDPERCENT',e[e.SETBIT=4608]='SETBIT',e[e.CLEARBIT=4609]='CLEARBIT',e[e.TESTBIT=4610]='TESTBIT',e[e.MODULO=4611]='MODULO',e[e.POW=4612]='POW',e[e.INVPOW=4613]='INVPOW',e[e.AND=4614]='AND',e[e.OR=4615]='OR',e[e.MIN=4616]='MIN',e[e.MAX=4617]='MAX',e[e.SCALE=4618]='SCALE',e[e.BITCOUNT=4619]='BITCOUNT',e[e.TOGGLEBIT=4620]='TOGGLEBIT',e[e.SETBIT_RANGE=4621]='SETBIT_RANGE',e[e.CLEARBIT_RANGE=4622]='CLEARBIT_RANGE',e[e.GETBIT_RANGE=4623]='GETBIT_RANGE',e[e.SETBIT_RANGE_TOINT=4624]='SETBIT_RANGE_TOINT',e[e.SIN_DEG=4625]='SIN_DEG',e[e.COS_DEG=4626]='COS_DEG',e[e.ATAN2_DEG=4627]='ATAN2_DEG',e[e.ABS=4628]='ABS',e[e.DB_FIND_WITH_COUNT=7500]='DB_FIND_WITH_COUNT',e[e.DB_FINDNEXT=7501]='DB_FINDNEXT',e[e.DB_GETFIELD=7502]='DB_GETFIELD',e[e.DB_GETFIELDCOUNT=7503]='DB_GETFIELDCOUNT',e[e.DB_LISTALL_WITH_COUNT=7504]='DB_LISTALL_WITH_COUNT',e[e.DB_GETROWTABLE=7505]='DB_GETROWTABLE',e[e.DB_FINDBYINDEX=7506]='DB_FINDBYINDEX',e[e.DB_FIND_REFINE_WITH_COUNT=7507]='DB_FIND_REFINE_WITH_COUNT',e[e.DB_FIND=7508]='DB_FIND',e[e.DB_FIND_REFINE=7509]='DB_FIND_REFINE',e[e.DB_LISTALL=7510]='DB_LISTALL',e[e.ERROR=1e4]='ERROR',e[e.MAP_PRODUCTION=10001]='MAP_PRODUCTION',e[e.MAP_LASTCLOCK=10002]='MAP_LASTCLOCK',e[e.MAP_LASTWORLD=10003]='MAP_LASTWORLD',e[e.MAP_LASTCLIENTIN=10004]='MAP_LASTCLIENTIN',e[e.MAP_LASTNPC=10005]='MAP_LASTNPC',e[e.MAP_LASTPLAYER=10006]='MAP_LASTPLAYER',e[e.MAP_LASTLOGOUT=10007]='MAP_LASTLOGOUT',e[e.MAP_LASTLOGIN=10008]='MAP_LASTLOGIN',e[e.MAP_LASTZONE=10009]='MAP_LASTZONE',e[e.MAP_LASTCLIENTOUT=10010]='MAP_LASTCLIENTOUT',e[e.MAP_LASTCLEANUP=10011]='MAP_LASTCLEANUP',e[e.MAP_LASTBANDWIDTHIN=10012]='MAP_LASTBANDWIDTHIN',e[e.MAP_LASTBANDWIDTHOUT=10013]='MAP_LASTBANDWIDTHOUT',e))(Wt||{}),Kt=Wt,zt=class e{info={scriptName:'',sourceFilePath:'',lookupKey:-1,parameterTypes:[],pcs:[],lines:[]};id;intLocalCount=0;stringLocalCount=0;intArgCount=0;stringArgCount=0;switchTables=[];opcodes=[];intOperands=[];stringOperands=[];static isLargeOperand(e){if(e>100)return!1;switch(e){case Kt.RETURN:case Kt.POP_INT_DISCARD:case Kt.POP_STRING_DISCARD:case Kt.GOSUB:case Kt.JUMP:return!1}return!0}static decode(t,i){const r=i.data.length;if(r<16)throw new Error('Invalid script file (minimum length)');i.pos=r-2;const s=r-i.g2()-12-2;if(s<0||s>=r)throw new Error('Invalid script file (bad trailer pos)');i.pos=s;const n=new e(t);i.g4();n.intLocalCount=i.g2(),n.stringLocalCount=i.g2(),n.intArgCount=i.g2(),n.stringArgCount=i.g2();const a=i.g1();for(let e=0;ei.pos;){const t=i.g2();t===Kt.PUSH_CONSTANT_STRING?n.stringOperands[l]=i.gjstr(0):e.isLargeOperand(t)?n.intOperands[l]=i.g4():n.intOperands[l]=i.g1(),n.opcodes[l++]=t}return n}constructor(e){this.id=e}get name(){return this.info.scriptName}get fileName(){return path2.basename(this.info.sourceFilePath)}lineNumber(e){for(let t=0;te)return this.info.lines[t-1];return this.info.lines[this.info.lines.length-1]}},jt=class e{static COMPILER_VERSION=18;static scripts=[];static scriptLookup=new Map;static scriptNames=new Map;static load(e){const t=Oe.load(`${e}/server/script.dat`),i=Oe.load(`${e}/server/script.idx`);return this.parse(t,i)}static async loadAsync(e){const t=await Oe.loadAsync(`${e}/server/script.dat`),i=await Oe.loadAsync(`${e}/server/script.idx`);return this.parse(t,i)}static parse(t,i){t.data.length&&i.data.length||(console.log('\nFatal: No script.dat or script.idx found. Please run the server:build script.'),process.exit(1));const r=t.g2();i.pos+=2;t.g4()!==e.COMPILER_VERSION&&(console.error('\nFatal: Scripts were compiled with an older RuneScript compiler. Please update it, try `npm run build` and then restart the server.'),process.exit(1));const s=new Array(r),n=new Map,a=new Map;let o=0;for(let e=0;e=0;i--)t[i]=this.popInt();return t}pushInt(e){this.intStack[this.isp++]=qt(e)}popString(){return this.stringStack[--this.ssp]??''}popStrings(e){const t=Array(e);for(let i=e-1;i>=0;i--)t[i]=this.popString();return t}pushString(e){this.stringStack[this.ssp++]=e}reset(){this.pc=-1,this.frames=[],this.fp=0,this.intStack=[],this.isp=0,this.stringStack=[],this.ssp=0,this.intLocals=[],this.stringLocals=[],this.pointers=0}},Zt=class{requested=0;completed=0;items=[];constructor(e,t=0,i=[]){this.requested=e,this.completed=t,this.items=i}getLeftOver(){return this.requested-this.completed}hasSucceeded(){return this.completed==this.requested}hasFailed(){return!this.hasSucceeded()}revert(e){for(let t=0;tt&&t.id==e))}hasAt(e,t){const i=this.items[e];return i&&i.id==t}get nextFreeSlot(){return this.items.indexOf(null,0)}get freeSlotCount(){return this.items.filter((e=>null==e)).length}get occupiedSlotCount(){return this.items.filter((e=>null!=e)).length}get isFull(){return this.occupiedSlotCount==this.capacity}get isEmpty(){return 0==this.occupiedSlotCount}get hasAny(){return this.items.some((e=>null!=e))}get hasSpace(){return-1!=this.nextFreeSlot}get itemsFiltered(){return this.items.filter((e=>null!=e))}getItemCount(t){let i=0;for(let e=0;et&&t.id==e))}removeAll(){this.items.fill(null,0,this.capacity),this.update=!0}add(t,i=1,r=-1,s=!0,n=!1,a=!1){const o=Tt.get(t),c=!0===it.get(this.type).stockobj?.includes(t),l=!n&&this.stackType!=e.NEVER_STACK&&(o.stackable||this.stackType==e.ALWAYS_STACK);let h=0;if(l&&(h=this.getItemCount(t)),h==e.STACK_LIMIT)return new Zt(i,0,[]);const d=this.freeSlotCount;if(0==d&&(!l||l&&0==h&&!c))return new Zt(i,0,[]);if(s){if(l&&h>e.STACK_LIMIT-i)return new Zt(i,0,[]);if(!l&&i>d)return new Zt(i,0,[])}else{if(l&&h==e.STACK_LIMIT)return new Zt(i,0,[]);if(!l&&0==d)return new Zt(i,0,[])}let u=0;const p=[];if(l){let s=this.getItemIndex(t);if(-1==s&&(s=-1==r?this.nextFreeSlot:this.items.indexOf(null,r),-1==s))return new Zt(i,u,[]);const n=this.get(s)?.count??0,o=Math.min(e.STACK_LIMIT,n+i),c={id:t,count:o};a||this.set(s,c),p.push({slot:s,item:c}),u=o-n}else{for(let e=Math.max(0,r);e=i)break}}return new Zt(i,u,p)}remove(e,t=1,i=-1,r=!1){const s=this.getItemCount(e),n=!0===it.get(this.type).stockobj?.includes(e);if(r&&s=t)break}if(null!=c&&a=t)break}return a>0&&(this.update=!0),new Zt(t,a,o)}delete(e){this.items[e]=null,this.update=!0}swap(e,t){const i=this.items[e];this.set(e,this.items[t]),this.set(t,i)}shift(){this.items.sort(((e,t)=>null===e||null===t?+(null===e)-+(null===t):+(e>t)||-(e=0&&e=0)&&(c={id:o.certlink,count:a});const l=e.add(c.id,c.count,r,!1);if(0==l.completed)return null;const h=this.remove(t.id,l.completed,i,!1);return 0==h.completed?null:h}};async function Jt(e,t={}){const i={env:Object.assign(Object.create(globalThis),t.env||{},{abort(e,t,i,r){e=o(e>>>0),t=o(t>>>0),i>>>=0,r>>>=0,(()=>{throw Error(`${e} in ${t}:${i}:${r}`)})()},seed:()=>Date.now()*Math.random()})},{exports:r}=await WebAssembly.instantiate(e,i),s=r.memory||t.env.memory,n=Object.setPrototypeOf({findPath(e,t,i,s,n,a,o,l,d,u,p,f,g,m){return p=p?1:0,r.__setArgumentsLength(arguments.length),c(h,2,r.findPath(e,t,i,s,n,a,o,l,d,u,p,f,g,m)>>>0)},findNaivePath(e,t,i,s,n,a,o,l,d,u,p){return r.__setArgumentsLength(arguments.length),c(h,2,r.findNaivePath(e,t,i,s,n,a,o,l,d,u,p)>>>0)},changeFloor(e,t,i,s){s=s?1:0,r.changeFloor(e,t,i,s)},changeLoc(e,t,i,s,n,a,o,c){a=a?1:0,o=o?1:0,c=c?1:0,r.changeLoc(e,t,i,s,n,a,o,c)},changeNpc(e,t,i,s,n){n=n?1:0,r.changeNpc(e,t,i,s,n)},changePlayer(e,t,i,s,n){n=n?1:0,r.changePlayer(e,t,i,s,n)},changeRoof(e,t,i,s){s=s?1:0,r.changeRoof(e,t,i,s)},changeWall(e,t,i,s,n,a,o,c){a=a?1:0,o=o?1:0,c=c?1:0,r.changeWall(e,t,i,s,n,a,o,c)},allocateIfAbsent:(e,t,i)=>c(h,2,r.allocateIfAbsent(e,t,i)>>>0),isZoneAllocated:(e,t,i)=>0!=r.isZoneAllocated(e,t,i),isFlagged:(e,t,i,s)=>0!=r.isFlagged(e,t,i,s),canTravel(e,t,i,s,n,a,o,c){return r.__setArgumentsLength(arguments.length),0!=r.canTravel(e,t,i,s,n,a,o,c)},hasLineOfSight(e,t,i,s,n,a,o,c,l,h){return r.__setArgumentsLength(arguments.length),0!=r.hasLineOfSight(e,t,i,s,n,a,o,c,l,h)},hasLineOfWalk(e,t,i,s,n,a,o,c,l,h){return r.__setArgumentsLength(arguments.length),0!=r.hasLineOfWalk(e,t,i,s,n,a,o,c,l,h)},lineOfSight(e,t,i,s,n,a,o,l,d,u){return r.__setArgumentsLength(arguments.length),c(h,2,r.lineOfSight(e,t,i,s,n,a,o,l,d,u)>>>0)},lineOfWalk(e,t,i,s,n,a,o,l,d,u){return r.__setArgumentsLength(arguments.length),c(h,2,r.lineOfWalk(e,t,i,s,n,a,o,l,d,u)>>>0)},reached(e,t,i,s,n,a,o,c,l,h,d){return r.__setArgumentsLength(arguments.length),0!=r.reached(e,t,i,s,n,a,o,c,l,h,d)},__collides:(e,t,i,s,n,a,o,c)=>0!=r.__collides(e,t,i,s,n,a,o,c),__reachRectangle1:(e,t,i,s,n,a,o,c)=>0!=r.__reachRectangle1(e,t,i,s,n,a,o,c),__reachRectangleN:(e,t,i,s,n,a,o,c,l,h)=>0!=r.__reachRectangleN(e,t,i,s,n,a,o,c,l,h),__reachRectangle:(e,t,i,s,n,a,o,c,l,h)=>0!=r.__reachRectangle(e,t,i,s,n,a,o,c,l,h),__reachExclusiveRectangle:(e,t,i,s,n,a,o,c,l,h)=>0!=r.__reachExclusiveRectangle(e,t,i,s,n,a,o,c,l,h),CollisionFlag:(a={},a[a.NULL=r['CollisionFlag.NULL'].valueOf()]='NULL',a[a.OPEN=r['CollisionFlag.OPEN'].valueOf()]='OPEN',a[a.WALL_NORTH_WEST=r['CollisionFlag.WALL_NORTH_WEST'].valueOf()]='WALL_NORTH_WEST',a[a.WALL_NORTH=r['CollisionFlag.WALL_NORTH'].valueOf()]='WALL_NORTH',a[a.WALL_NORTH_EAST=r['CollisionFlag.WALL_NORTH_EAST'].valueOf()]='WALL_NORTH_EAST',a[a.WALL_EAST=r['CollisionFlag.WALL_EAST'].valueOf()]='WALL_EAST',a[a.WALL_SOUTH_EAST=r['CollisionFlag.WALL_SOUTH_EAST'].valueOf()]='WALL_SOUTH_EAST',a[a.WALL_SOUTH=r['CollisionFlag.WALL_SOUTH'].valueOf()]='WALL_SOUTH',a[a.WALL_SOUTH_WEST=r['CollisionFlag.WALL_SOUTH_WEST'].valueOf()]='WALL_SOUTH_WEST',a[a.WALL_WEST=r['CollisionFlag.WALL_WEST'].valueOf()]='WALL_WEST',a[a.LOC=r['CollisionFlag.LOC'].valueOf()]='LOC',a[a.WALL_NORTH_WEST_PROJ_BLOCKER=r['CollisionFlag.WALL_NORTH_WEST_PROJ_BLOCKER'].valueOf()]='WALL_NORTH_WEST_PROJ_BLOCKER',a[a.WALL_NORTH_PROJ_BLOCKER=r['CollisionFlag.WALL_NORTH_PROJ_BLOCKER'].valueOf()]='WALL_NORTH_PROJ_BLOCKER',a[a.WALL_NORTH_EAST_PROJ_BLOCKER=r['CollisionFlag.WALL_NORTH_EAST_PROJ_BLOCKER'].valueOf()]='WALL_NORTH_EAST_PROJ_BLOCKER',a[a.WALL_EAST_PROJ_BLOCKER=r['CollisionFlag.WALL_EAST_PROJ_BLOCKER'].valueOf()]='WALL_EAST_PROJ_BLOCKER',a[a.WALL_SOUTH_EAST_PROJ_BLOCKER=r['CollisionFlag.WALL_SOUTH_EAST_PROJ_BLOCKER'].valueOf()]='WALL_SOUTH_EAST_PROJ_BLOCKER',a[a.WALL_SOUTH_PROJ_BLOCKER=r['CollisionFlag.WALL_SOUTH_PROJ_BLOCKER'].valueOf()]='WALL_SOUTH_PROJ_BLOCKER',a[a.WALL_SOUTH_WEST_PROJ_BLOCKER=r['CollisionFlag.WALL_SOUTH_WEST_PROJ_BLOCKER'].valueOf()]='WALL_SOUTH_WEST_PROJ_BLOCKER',a[a.WALL_WEST_PROJ_BLOCKER=r['CollisionFlag.WALL_WEST_PROJ_BLOCKER'].valueOf()]='WALL_WEST_PROJ_BLOCKER',a[a.LOC_PROJ_BLOCKER=r['CollisionFlag.LOC_PROJ_BLOCKER'].valueOf()]='LOC_PROJ_BLOCKER',a[a.FLOOR_DECORATION=r['CollisionFlag.FLOOR_DECORATION'].valueOf()]='FLOOR_DECORATION',a[a.NPC=r['CollisionFlag.NPC'].valueOf()]='NPC',a[a.PLAYER=r['CollisionFlag.PLAYER'].valueOf()]='PLAYER',a[a.FLOOR=r['CollisionFlag.FLOOR'].valueOf()]='FLOOR',a[a.WALL_NORTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.WALL_NORTH_WEST_ROUTE_BLOCKER'].valueOf()]='WALL_NORTH_WEST_ROUTE_BLOCKER',a[a.WALL_NORTH_ROUTE_BLOCKER=r['CollisionFlag.WALL_NORTH_ROUTE_BLOCKER'].valueOf()]='WALL_NORTH_ROUTE_BLOCKER',a[a.WALL_NORTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.WALL_NORTH_EAST_ROUTE_BLOCKER'].valueOf()]='WALL_NORTH_EAST_ROUTE_BLOCKER',a[a.WALL_EAST_ROUTE_BLOCKER=r['CollisionFlag.WALL_EAST_ROUTE_BLOCKER'].valueOf()]='WALL_EAST_ROUTE_BLOCKER',a[a.WALL_SOUTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.WALL_SOUTH_EAST_ROUTE_BLOCKER'].valueOf()]='WALL_SOUTH_EAST_ROUTE_BLOCKER',a[a.WALL_SOUTH_ROUTE_BLOCKER=r['CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER'].valueOf()]='WALL_SOUTH_ROUTE_BLOCKER',a[a.WALL_SOUTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.WALL_SOUTH_WEST_ROUTE_BLOCKER'].valueOf()]='WALL_SOUTH_WEST_ROUTE_BLOCKER',a[a.WALL_WEST_ROUTE_BLOCKER=r['CollisionFlag.WALL_WEST_ROUTE_BLOCKER'].valueOf()]='WALL_WEST_ROUTE_BLOCKER',a[a.LOC_ROUTE_BLOCKER=r['CollisionFlag.LOC_ROUTE_BLOCKER'].valueOf()]='LOC_ROUTE_BLOCKER',a[a.ROOF=r['CollisionFlag.ROOF'].valueOf()]='ROOF',a[a.FLOOR_BLOCKED=r['CollisionFlag.FLOOR_BLOCKED'].valueOf()]='FLOOR_BLOCKED',a[a.WALK_BLOCKED=r['CollisionFlag.WALK_BLOCKED'].valueOf()]='WALK_BLOCKED',a[a.BLOCK_WEST=r['CollisionFlag.BLOCK_WEST'].valueOf()]='BLOCK_WEST',a[a.BLOCK_EAST=r['CollisionFlag.BLOCK_EAST'].valueOf()]='BLOCK_EAST',a[a.BLOCK_SOUTH=r['CollisionFlag.BLOCK_SOUTH'].valueOf()]='BLOCK_SOUTH',a[a.BLOCK_NORTH=r['CollisionFlag.BLOCK_NORTH'].valueOf()]='BLOCK_NORTH',a[a.BLOCK_SOUTH_WEST=r['CollisionFlag.BLOCK_SOUTH_WEST'].valueOf()]='BLOCK_SOUTH_WEST',a[a.BLOCK_SOUTH_EAST=r['CollisionFlag.BLOCK_SOUTH_EAST'].valueOf()]='BLOCK_SOUTH_EAST',a[a.BLOCK_NORTH_WEST=r['CollisionFlag.BLOCK_NORTH_WEST'].valueOf()]='BLOCK_NORTH_WEST',a[a.BLOCK_NORTH_EAST=r['CollisionFlag.BLOCK_NORTH_EAST'].valueOf()]='BLOCK_NORTH_EAST',a[a.BLOCK_NORTH_AND_SOUTH_EAST=r['CollisionFlag.BLOCK_NORTH_AND_SOUTH_EAST'].valueOf()]='BLOCK_NORTH_AND_SOUTH_EAST',a[a.BLOCK_NORTH_AND_SOUTH_WEST=r['CollisionFlag.BLOCK_NORTH_AND_SOUTH_WEST'].valueOf()]='BLOCK_NORTH_AND_SOUTH_WEST',a[a.BLOCK_NORTH_EAST_AND_WEST=r['CollisionFlag.BLOCK_NORTH_EAST_AND_WEST'].valueOf()]='BLOCK_NORTH_EAST_AND_WEST',a[a.BLOCK_SOUTH_EAST_AND_WEST=r['CollisionFlag.BLOCK_SOUTH_EAST_AND_WEST'].valueOf()]='BLOCK_SOUTH_EAST_AND_WEST',a[a.BLOCK_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_WEST_ROUTE_BLOCKER',a[a.BLOCK_EAST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_EAST_ROUTE_BLOCKER'].valueOf()]='BLOCK_EAST_ROUTE_BLOCKER',a[a.BLOCK_SOUTH_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_SOUTH_ROUTE_BLOCKER'].valueOf()]='BLOCK_SOUTH_ROUTE_BLOCKER',a[a.BLOCK_NORTH_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_ROUTE_BLOCKER',a[a.BLOCK_SOUTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_SOUTH_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_SOUTH_WEST_ROUTE_BLOCKER',a[a.BLOCK_SOUTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_SOUTH_EAST_ROUTE_BLOCKER'].valueOf()]='BLOCK_SOUTH_EAST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_WEST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_EAST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_EAST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_AND_SOUTH_EAST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_AND_SOUTH_EAST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_AND_SOUTH_EAST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_AND_SOUTH_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_AND_SOUTH_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_AND_SOUTH_WEST_ROUTE_BLOCKER',a[a.BLOCK_NORTH_EAST_AND_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_NORTH_EAST_AND_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_NORTH_EAST_AND_WEST_ROUTE_BLOCKER',a[a.BLOCK_SOUTH_EAST_AND_WEST_ROUTE_BLOCKER=r['CollisionFlag.BLOCK_SOUTH_EAST_AND_WEST_ROUTE_BLOCKER'].valueOf()]='BLOCK_SOUTH_EAST_AND_WEST_ROUTE_BLOCKER',a),LocShape:(e=>(e[e.WALL_STRAIGHT=r['LocShape.WALL_STRAIGHT'].valueOf()]='WALL_STRAIGHT',e[e.WALL_DIAGONAL_CORNER=r['LocShape.WALL_DIAGONAL_CORNER'].valueOf()]='WALL_DIAGONAL_CORNER',e[e.WALL_L=r['LocShape.WALL_L'].valueOf()]='WALL_L',e[e.WALL_SQUARE_CORNER=r['LocShape.WALL_SQUARE_CORNER'].valueOf()]='WALL_SQUARE_CORNER',e[e.WALLDECOR_STRAIGHT_NOOFFSET=r['LocShape.WALLDECOR_STRAIGHT_NOOFFSET'].valueOf()]='WALLDECOR_STRAIGHT_NOOFFSET',e[e.WALLDECOR_STRAIGHT_OFFSET=r['LocShape.WALLDECOR_STRAIGHT_OFFSET'].valueOf()]='WALLDECOR_STRAIGHT_OFFSET',e[e.WALLDECOR_DIAGONAL_OFFSET=r['LocShape.WALLDECOR_DIAGONAL_OFFSET'].valueOf()]='WALLDECOR_DIAGONAL_OFFSET',e[e.WALLDECOR_DIAGONAL_NOOFFSET=r['LocShape.WALLDECOR_DIAGONAL_NOOFFSET'].valueOf()]='WALLDECOR_DIAGONAL_NOOFFSET',e[e.WALLDECOR_DIAGONAL_BOTH=r['LocShape.WALLDECOR_DIAGONAL_BOTH'].valueOf()]='WALLDECOR_DIAGONAL_BOTH',e[e.WALL_DIAGONAL=r['LocShape.WALL_DIAGONAL'].valueOf()]='WALL_DIAGONAL',e[e.CENTREPIECE_STRAIGHT=r['LocShape.CENTREPIECE_STRAIGHT'].valueOf()]='CENTREPIECE_STRAIGHT',e[e.CENTREPIECE_DIAGONAL=r['LocShape.CENTREPIECE_DIAGONAL'].valueOf()]='CENTREPIECE_DIAGONAL',e[e.ROOF_STRAIGHT=r['LocShape.ROOF_STRAIGHT'].valueOf()]='ROOF_STRAIGHT',e[e.ROOF_DIAGONAL_WITH_ROOFEDGE=r['LocShape.ROOF_DIAGONAL_WITH_ROOFEDGE'].valueOf()]='ROOF_DIAGONAL_WITH_ROOFEDGE',e[e.ROOF_DIAGONAL=r['LocShape.ROOF_DIAGONAL'].valueOf()]='ROOF_DIAGONAL',e[e.ROOF_L_CONCAVE=r['LocShape.ROOF_L_CONCAVE'].valueOf()]='ROOF_L_CONCAVE',e[e.ROOF_L_CONVEX=r['LocShape.ROOF_L_CONVEX'].valueOf()]='ROOF_L_CONVEX',e[e.ROOF_FLAT=r['LocShape.ROOF_FLAT'].valueOf()]='ROOF_FLAT',e[e.ROOFEDGE_STRAIGHT=r['LocShape.ROOFEDGE_STRAIGHT'].valueOf()]='ROOFEDGE_STRAIGHT',e[e.ROOFEDGE_DIAGONAL_CORNER=r['LocShape.ROOFEDGE_DIAGONAL_CORNER'].valueOf()]='ROOFEDGE_DIAGONAL_CORNER',e[e.ROOFEDGE_L=r['LocShape.ROOFEDGE_L'].valueOf()]='ROOFEDGE_L',e[e.ROOFEDGE_SQUARE_CORNER=r['LocShape.ROOFEDGE_SQUARE_CORNER'].valueOf()]='ROOFEDGE_SQUARE_CORNER',e[e.GROUND_DECOR=r['LocShape.GROUND_DECOR'].valueOf()]='GROUND_DECOR',e))({}),LocAngle:(e=>(e[e.WEST=r['LocAngle.WEST'].valueOf()]='WEST',e[e.NORTH=r['LocAngle.NORTH'].valueOf()]='NORTH',e[e.EAST=r['LocAngle.EAST'].valueOf()]='EAST',e[e.SOUTH=r['LocAngle.SOUTH'].valueOf()]='SOUTH',e))({}),CollisionType:(e=>(e[e.NORMAL=r['CollisionType.NORMAL'].valueOf()]='NORMAL',e[e.BLOCKED=r['CollisionType.BLOCKED'].valueOf()]='BLOCKED',e[e.INDOORS=r['CollisionType.INDOORS'].valueOf()]='INDOORS',e[e.OUTDOORS=r['CollisionType.OUTDOORS'].valueOf()]='OUTDOORS',e[e.LINE_OF_SIGHT=r['CollisionType.LINE_OF_SIGHT'].valueOf()]='LINE_OF_SIGHT',e))({}),LocLayer:(e=>(e[e.WALL=r['LocLayer.WALL'].valueOf()]='WALL',e[e.WALL_DECOR=r['LocLayer.WALL_DECOR'].valueOf()]='WALL_DECOR',e[e.GROUND=r['LocLayer.GROUND'].valueOf()]='GROUND',e[e.GROUND_DECOR=r['LocLayer.GROUND_DECOR'].valueOf()]='GROUND_DECOR',e))({}),BlockAccessFlag:(e=>(e[e.BLOCK_NORTH=r['BlockAccessFlag.BLOCK_NORTH'].valueOf()]='BLOCK_NORTH',e[e.BLOCK_EAST=r['BlockAccessFlag.BLOCK_EAST'].valueOf()]='BLOCK_EAST',e[e.BLOCK_SOUTH=r['BlockAccessFlag.BLOCK_SOUTH'].valueOf()]='BLOCK_SOUTH',e[e.BLOCK_WEST=r['BlockAccessFlag.BLOCK_WEST'].valueOf()]='BLOCK_WEST',e))({})},r);var a;function o(e){if(!e)return null;const t=e+new Uint32Array(s.buffer)[e-4>>>2]>>>1,i=new Uint16Array(s.buffer);let r=e>>>1,n='';for(;t-r>1024;)n+=String.fromCharCode(...i.subarray(r,r+=1024));return n+String.fromCharCode(...i.subarray(r,t))}function c(e,t,i){if(!i)return null;const r=function(e){try{return l.getUint32(e,!0)}catch{return l=new DataView(s.buffer),l.getUint32(e,!0)}}(i-4)>>>t,n=new Array(r);for(let s=0;s>>0));return n}let l=new DataView(s.buffer);function h(e){try{return l.getInt32(e,!0)}catch{return l=new DataView(s.buffer),l.getInt32(e,!0)}}return n}var{memory:ei,findPath:ti,findNaivePath:ii,changeFloor:ri,changeLoc:si,changeNpc:ni,changePlayer:ai,changeRoof:oi,changeWall:ci,allocateIfAbsent:li,deallocateIfPresent:hi,isZoneAllocated:di,isFlagged:ui,canTravel:pi,hasLineOfSight:fi,hasLineOfWalk:gi,lineOfSight:mi,lineOfWalk:yi,reached:Ei,locShapeLayer:_i,__get:Ai,__set:vi,__add:Ti,__remove:Ci,__rotate:Ii,__rotateFlags:Si,__collides:Oi,__reachRectangle1:Ni,__reachRectangleN:Li,__alteredRotation:Pi,__reachRectangle:wi,__reachExclusiveRectangle:bi,CollisionFlag:Ri,LocShape:Bi,LocAngle:Ui,CollisionType:Di,LocLayer:ki,BlockAccessFlag:Mi}=await(async e=>Jt(await(async()=>{try{return await globalThis.WebAssembly.compileStreaming(globalThis.fetch(e))}catch{return globalThis.WebAssembly.compile(await(await import('node:fs/promises')).readFile(e))}})(),{}))(new URL('rsmod-pathfinder.wasm',import.meta.url)),xi=0,Fi=1,Hi=2,Vi=3,Gi=4,Wi=5,Ki=6,zi=7,ji={zone:e=>e>>3,zoneCenter:e=>ji.zone(e)-6,zoneOrigin:e=>ji.zoneCenter(e)<<3,mapsquare:e=>e>>6,local:(e,t)=>e-(ji.zoneCenter(t)<<3),face:(e,t,i,r)=>e!=i?e>i?t>r?Wi:tr?zi:tr?Ki:te+ji.deltaX(t),moveZ:(e,t)=>e+ji.deltaZ(t),distanceTo(e,t){const i=ji.closest(e,t),r=ji.closest(t,e);return Math.max(Math.abs(i.x-r.x),Math.abs(i.z-r.z))},closest(e,t){const i=e.x+e.width-1,r=e.z+e.length-1;return{x:t.x<=e.x?e.x:t.x>=i?i:t.x,z:t.z<=e.z?e.z:t.z>=r?r:t.z}},distanceToSW(e,t){const i=Math.abs(e.x-t.x),r=Math.abs(e.z-t.z);return Math.max(i,r)},isWithinDistanceSW:(e,t,i)=>!(Math.abs(e.x-t.x)>i||Math.abs(e.z-t.z)>i),deltaX(e){switch(e){case zi:case Hi:case Gi:return 1;case Wi:case xi:case Vi:return-1}return 0},deltaZ(e){switch(e){case xi:case Hi:case Fi:return 1;case Wi:case zi:case Ki:return-1}return 0},unpackCoord:e=>({level:e>>28&3,x:e>>14&16383,z:16383&e}),packCoord:(e,t,i)=>16383&i|(16383&t)<<14|(3&e)<<28,packZoneCoord:(e,t)=>(7&e)<<4|7&t,intersects:(e,t,i,r,s,n,a,o)=>!(s>=e+i||s+a<=e||n>=t+r||n+o<=t),formatString:(e,t,i,r="_")=>e+r+(t>>6)+r+(i>>6)+r+(63&t)+r+(63&i)},Yi=(e=>(e[e.BLOCK=0]='BLOCK',e[e.DAMAGE=1]='DAMAGE',e[e.POISON=2]='POISON',e))(Yi||{}),qi=Yi,Qi=(e=>(e[e.ATTACK=0]='ATTACK',e[e.DEFENCE=1]='DEFENCE',e[e.STRENGTH=2]='STRENGTH',e[e.HITPOINTS=3]='HITPOINTS',e[e.RANGED=4]='RANGED',e[e.PRAYER=5]='PRAYER',e[e.MAGIC=6]='MAGIC',e[e.COOKING=7]='COOKING',e[e.WOODCUTTING=8]='WOODCUTTING',e[e.FLETCHING=9]='FLETCHING',e[e.FISHING=10]='FISHING',e[e.FIREMAKING=11]='FIREMAKING',e[e.CRAFTING=12]='CRAFTING',e[e.SMITHING=13]='SMITHING',e[e.MINING=14]='MINING',e[e.HERBLORE=15]='HERBLORE',e[e.AGILITY=16]='AGILITY',e[e.THIEVING=17]='THIEVING',e[e.STAT18=18]='STAT18',e[e.STAT19=19]='STAT19',e[e.RUNECRAFT=20]='RUNECRAFT',e))(Qi||{}),$i=Qi,Zi=class{type;count;name;constructor(e,t,i){this.type=e,this.count=t,this.name=i}validate(e){if(this.count(e))return this.type(e);throw new Error(`An input for a ${this.name} type was not valid to use. Input was ${e}.`)}},Xi=class{min;max;name;constructor(e,t,i){this.min=e,this.max=t,this.name=i}validate(e){if(e>=this.min&&e<=this.max)return e;throw new Error(`An input for a ${this.name} was out of range. Range should be: ${this.min} to ${this.max}. Input was ${e}.`)}},Ji=new class{validate(e){if(-1!==e)return e;throw Error('An input number was null(-1).')}},er=new class{validate(e){if(e.length>0)return e;throw Error('An input string was null(-1).')}},tr=new Zi(at.get,(e=>e>=0&&e=this.min&&e<=this.max)return ji.unpackCoord(e);throw new Error(`An input for a ${this.name} was out of range. Range should be: ${this.min} to ${this.max}. Input was ${e}.`)}}(0,2147483647,'Coord'),ar=new Zi(gt.get,(e=>e>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&ee>=0&&e=50)throw new Error('stack overflow');e.frames[e.fp++]={script:e.script,pc:e.pc,intLocals:e.intLocals,stringLocals:e.stringLocals};const i=jt.get(t);if(!i)throw new Error(`unable to find proc ${i}`);kr(e,i)}function Dr(e,t){const i=jt.get(t);if(!i)throw new Error(`unable to find label ${t}`);e.debugFrames[e.debugFp++]={script:e.script,pc:e.pc},kr(e,i),e.fp=0,e.frames=[]}function kr(e,t){e.script=t,e.pc=-1,e.intLocals=e.popInts(t.intArgCount),e.stringLocals=e.popStrings(t.stringArgCount)}var Mr,xr={[Kt.PUSH_CONSTANT_INT]:e=>{e.pushInt(e.intOperand)},[Kt.PUSH_CONSTANT_STRING]:e=>{e.pushString(e.stringOperand)},[Kt.PUSH_VARP]:e=>{const t=e.intOperand>>16&1;if(t&&!e._activePlayer2)throw new Error('No secondary active_player.');if(!t&&!e._activePlayer)throw new Error('No active_player.');const i=Br(65535&e.intOperand,Cr);i.type===Pe.STRING?e.pushString(t?e._activePlayer2.getVar(i.id):e._activePlayer.getVar(i.id)):e.pushInt(t?e._activePlayer2.getVar(i.id):e._activePlayer.getVar(i.id))},[Kt.POP_VARP]:e=>{const t=e.intOperand>>16&1;if(t&&!e._activePlayer2)throw new Error('No secondary active_player.');if(!t&&!e._activePlayer)throw new Error('No active_player.');const i=Br(65535&e.intOperand,Cr);if(!e.pointerGet(Ht[t])&&i.protect)throw new Error(`%${i.debugname} requires protected access`);if(i.type===Pe.STRING){const r=e.popString();t?e._activePlayer2.setVar(i.id,r):e._activePlayer.setVar(i.id,r)}else{const r=e.popInt();t?e._activePlayer2.setVar(i.id,r):e._activePlayer.setVar(i.id,r)}},[Kt.PUSH_VARN]:e=>{const t=e.intOperand>>16&1;if(t&&!e._activeNpc2)throw new Error('No secondary active_npc.');if(!t&&!e._activeNpc)throw new Error('No active_npc.');const i=Br(65535&e.intOperand,Ir);i.type===Pe.STRING?e.pushString(t?e._activeNpc2.getVar(i.id):e._activeNpc.getVar(i.id)):e.pushInt(t?e._activeNpc2.getVar(i.id):e._activeNpc.getVar(i.id))},[Kt.POP_VARN]:e=>{const t=e.intOperand>>16&1;if(t&&!e._activeNpc2)throw new Error('No secondary active_npc.');if(!t&&!e._activeNpc)throw new Error('No active_npc.');const i=Br(65535&e.intOperand,Ir);if(i.type===Pe.STRING){const r=e.popInt();t?e._activeNpc2.setVar(i.id,r):e._activeNpc.setVar(i.id,r)}else{const r=e.popInt();t?e._activeNpc2.setVar(i.id,r):e._activeNpc.setVar(i.id,r)}},[Kt.PUSH_INT_LOCAL]:e=>{e.pushInt(e.intLocals[e.intOperand])},[Kt.POP_INT_LOCAL]:e=>{e.intLocals[e.intOperand]=e.popInt()},[Kt.PUSH_STRING_LOCAL]:e=>{e.pushString(e.stringLocals[e.intOperand])},[Kt.POP_STRING_LOCAL]:e=>{e.stringLocals[e.intOperand]=e.popString()},[Kt.BRANCH]:e=>{e.pc+=e.intOperand},[Kt.BRANCH_NOT]:e=>{const t=e.popInt();e.popInt()!==t&&(e.pc+=e.intOperand)},[Kt.BRANCH_EQUALS]:e=>{const t=e.popInt();e.popInt()===t&&(e.pc+=e.intOperand)},[Kt.BRANCH_LESS_THAN]:e=>{const t=e.popInt();e.popInt(){const t=e.popInt();e.popInt()>t&&(e.pc+=e.intOperand)},[Kt.BRANCH_LESS_THAN_OR_EQUALS]:e=>{const t=e.popInt();e.popInt()<=t&&(e.pc+=e.intOperand)},[Kt.BRANCH_GREATER_THAN_OR_EQUALS]:e=>{const t=e.popInt();e.popInt()>=t&&(e.pc+=e.intOperand)},[Kt.POP_INT_DISCARD]:e=>{e.isp--},[Kt.POP_STRING_DISCARD]:e=>{e.ssp--},[Kt.RETURN]:e=>{if(0===e.fp)return void(e.execution=$t.FINISHED);const t=e.frames[--e.fp];e.pc=t.pc,e.script=t.script,e.intLocals=t.intLocals,e.stringLocals=t.stringLocals},[Kt.JOIN_STRING]:e=>{const t=e.intOperand,i=[];for(let r=0;r{Ur(e,e.popInt())},[Kt.GOSUB_WITH_PARAMS]:e=>{Ur(e,e.intOperand)},[Kt.JUMP]:e=>{Dr(e,e.popInt())},[Kt.JUMP_WITH_PARAMS]:e=>{Dr(e,e.intOperand)},[Kt.DEFINE_ARRAY]:e=>{throw new Error('unimplemented')},[Kt.PUSH_ARRAY_INT]:e=>{throw new Error('unimplemented')},[Kt.POP_ARRAY_INT]:e=>{throw new Error('unimplemented')},[Kt.SWITCH]:e=>{const t=e.popInt(),i=e.script.switchTables[e.intOperand];if(void 0===i)return;const r=i[t];r&&(e.pc+=r)},[Kt.PUSH_VARS]:e=>{const t=Br(65535&e.intOperand,Sr);t.type===Pe.STRING?e.pushString(Zl.varsString[t.id]??''):e.pushInt(Zl.vars[t.id])},[Kt.POP_VARS]:e=>{const t=Br(65535&e.intOperand,Sr);t.type===Pe.STRING?Zl.varsString[t.id]=e.popString():Zl.vars[t.id]=e.popInt()}},Fr=xr,Hr={[Kt.DB_FIND_WITH_COUNT]:e=>{throw new Error('unimplemented')},[Kt.DB_FINDNEXT]:e=>{if(!e.dbTable)throw new Error('No table selected');e.dbRow+1>=e.dbRowQuery.length?e.pushInt(-1):(e.dbRow++,e.pushInt(Br(e.dbRowQuery[e.dbRow],Pr).id))},[Kt.DB_GETFIELD]:e=>{const[t,i,r]=e.popInts(3),s=i>>12&65535,n=i>>4&127,a=Br(t,Pr),o=Br(s,wr);let c;c=a.tableId!==s?o.getDefault(n):a.getValue(n,r);const l=o.types[n];for(let t=0;t{const[t,i]=e.popInts(2),r=i>>12&65535,s=i>>4&127,n=Br(t,Pr),a=Br(r,wr);n.tableId===r?e.pushInt(n.columnValues[s].length/a.types[s].length):e.pushInt(0)},[Kt.DB_LISTALL_WITH_COUNT]:e=>{throw new Error('unimplemented')},[Kt.DB_GETROWTABLE]:e=>{e.pushInt(Br(e.popInt(),Pr).tableId)},[Kt.DB_FINDBYINDEX]:e=>{throw new Error('unimplemented')},[Kt.DB_FIND_REFINE_WITH_COUNT]:e=>{throw new Error('unimplemented')},[Kt.DB_FIND]:e=>{const t=2==e.popInt()?e.popString():e.popInt(),i=e.popInt(),r=i>>12&65535,s=i>>4&127;e.dbTable=Br(r,wr),e.dbRow=-1,e.dbRowQuery=[];const n=be.getInTable(r);for(let i=0;i{const t=2==e.popInt()?e.popString():e.popInt(),i=e.popInt(),r=i>>12&65535,s=i>>4&127,n=[],a=be.getInTable(r);for(let e=0;e{throw new Error('unimplemented')}},Vr=(e=>(e[e.CYCLE=0]='CYCLE',e[e.WORLD=1]='WORLD',e[e.CLIENT_IN=2]='CLIENT_IN',e[e.NPC=3]='NPC',e[e.PLAYER=4]='PLAYER',e[e.LOGOUT=5]='LOGOUT',e[e.LOGIN=6]='LOGIN',e[e.ZONE=7]='ZONE',e[e.CLIENT_OUT=8]='CLIENT_OUT',e[e.CLEANUP=9]='CLEANUP',e[e.BANDWIDTH_IN=10]='BANDWIDTH_IN',e[e.BANDWIDTH_OUT=11]='BANDWIDTH_OUT',e))(Vr||{}),Gr=Vr,Wr={[Kt.ERROR]:e=>{throw new Error(e.popString())},[Kt.MAP_PRODUCTION]:e=>{e.pushInt(vt.NODE_PRODUCTION?1:0)},[Kt.MAP_LASTCLOCK]:e=>{e.pushInt(Zl.lastCycleStats[Gr.CYCLE])},[Kt.MAP_LASTWORLD]:e=>{e.pushInt(Zl.lastCycleStats[Gr.WORLD])},[Kt.MAP_LASTCLIENTIN]:e=>{e.pushInt(Zl.lastCycleStats[Gr.CLIENT_IN])},[Kt.MAP_LASTNPC]:e=>{e.pushInt(Zl.lastCycleStats[Gr.NPC])},[Kt.MAP_LASTPLAYER]:e=>{e.pushInt(Zl.lastCycleStats[Gr.PLAYER])},[Kt.MAP_LASTLOGOUT]:e=>{e.pushInt(Zl.lastCycleStats[Gr.LOGOUT])},[Kt.MAP_LASTLOGIN]:e=>{e.pushInt(Zl.lastCycleStats[Gr.LOGIN])},[Kt.MAP_LASTZONE]:e=>{e.pushInt(Zl.lastCycleStats[Gr.ZONE])},[Kt.MAP_LASTCLIENTOUT]:e=>{e.pushInt(Zl.lastCycleStats[Gr.CLIENT_OUT])},[Kt.MAP_LASTCLEANUP]:e=>{e.pushInt(Zl.lastCycleStats[Gr.CLEANUP])},[Kt.MAP_LASTBANDWIDTHIN]:e=>{e.pushInt(Zl.lastCycleStats[Gr.BANDWIDTH_IN])},[Kt.MAP_LASTBANDWIDTHOUT]:e=>{e.pushInt(Zl.lastCycleStats[Gr.BANDWIDTH_OUT])}},Kr={[Kt.ENUM]:e=>{const[t,i,r,s]=e.popInts(4),n=Br(r,gr);if(n.inputtype!==t||n.outputtype!==i)throw new Error(`Type validation error: ${n.debugname} key: ${s}. Expected input: ${t} got: ${n.inputtype}. Expected output: ${i} got: ${n.outputtype}`);const a=n.values.get(s);'string'==typeof a?e.pushString(a??n.defaultString):e.pushInt(a??n.defaultInt)},[Kt.ENUM_GETOUTPUTCOUNT]:e=>{e.pushInt(Br(e.popInt(),gr).values.size)}},zr=Kr,jr=(e=>(e[e.FOREVER=0]='FOREVER',e[e.RESPAWN=1]='RESPAWN',e[e.DESPAWN=2]='DESPAWN',e))(jr||{}),Yr=jr,qr=class{level;x;z;width;length;lifecycle;lifecycleTick=-1;lastLifecycleTick=-1;constructor(e,t,i,r,s,n){this.level=e,this.x=t,this.z=i,this.width=r,this.length=s,this.lifecycle=n}updateLifeCycle(e){return this.lifecycleTick===e&&this.lifecycle!==Yr.FOREVER}checkLifeCycle(e){return this.lifecycle===Yr.FOREVER||(this.lifecycle===Yr.RESPAWN?this.lifecycleTicke)}setLifeCycle(e){this.lifecycleTick=e,this.lastLifecycleTick=Zl.currentTick}},Qr=class extends qr{resetEntity(e){}},$r=class extends Qr{type;count;receiverId=-1;reveal=-1;constructor(e,t,i,r,s,n){super(e,t,i,1,1,r),this.type=s,this.count=n}},Zr={[Kt.INV_ALLSTOCK]:e=>{const t=Br(e.popInt(),Er);e.pushInt(t.allstock?1:0)},[Kt.INV_SIZE]:e=>{const t=Br(e.popInt(),Er);e.pushInt(t.size)},[Kt.INV_STOCKBASE]:e=>{const[t,i]=e.popInts(2),r=Br(t,Er),s=Br(i,mr);if(!r.stockobj||!r.stockcount)return void e.pushInt(-1);const n=r.stockobj.indexOf(s.id);e.pushInt(n>=0?r.stockcount[n]:-1)},[Kt.INV_ADD]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3),s=Br(t,Er),n=Br(i,mr);if(Br(r,yr),!e.pointerGet(Ht[e.intOperand])&&s.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${s.debugname}`);if(!s.dummyinv&&0!==n.dummyitem)throw new Error(`dummyitem in non-dummyinv: ${n.debugname} -> ${s.debugname}`);const a=e.activePlayer,o=r-a.invAdd(s.id,n.id,r,!1);if(o>0)if(n.stackable&&1!==o)Zl.addObj(new $r(a.level,a.x,a.z,Yr.DESPAWN,n.id,o),a.pid,200);else for(let e=0;e{const[t,i,r,s]=e.popInts(4);throw new Error('unimplemented')})),[Kt.INV_CLEAR]:Vt(Ft,(e=>{const t=Br(e.popInt(),Er);if(!e.pointerGet(Ht[e.intOperand])&&t.protect&&t.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${t.debugname}`);e.activePlayer.invClear(t.id)})),[Kt.INV_DEL]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3),s=Br(t,Er),n=Br(i,mr);if(Br(r,yr),!e.pointerGet(Ht[e.intOperand])&&s.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${s.debugname}`);e.activePlayer.invDel(s.id,n.id,r)})),[Kt.INV_DELSLOT]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);if(!e.pointerGet(Ht[e.intOperand])&&r.protect&&r.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${r.debugname}`);e.activePlayer.invGetSlot(r.id,i)&&e.activePlayer.invDelSlot(r.id,i)})),[Kt.INV_DROPITEM]:Vt(Ft,(e=>{const[t,i,r,s,n]=e.popInts(5),a=Br(t,Er),o=Br(i,nr),c=Br(r,mr);if(Br(s,yr),Br(n,sr),!e.pointerGet(Ht[e.intOperand])&&a.protect&&a.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);const l=e.activePlayer,h=l.invDel(a.id,c.id,s);if(0==h)return;l.playerLog('Dropped item from',a.debugname,c.debugname);const d=new $r(o.level,o.x,o.z,Yr.DESPAWN,c.id,h);Zl.addObj(d,l.pid,n),e.activeObj=d,e.pointerAdd(xt[e.intOperand])})),[Kt.INV_DROPSLOT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er);Br(s,sr);const a=Br(i,nr);if(!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);const o=e.activePlayer.invGetSlot(n.id,r);if(!o)throw new Error('$slot is empty');const c=e.activePlayer,l=c.invDel(n.id,o.id,o.count,r);if(0===l)return;const h=Tt.get(o.id);if(c.playerLog('Dropped item from',n.debugname,h.debugname),h.stackable&&1!==l){const t=new $r(a.level,a.x,a.z,Yr.DESPAWN,o.id,l);Zl.addObj(t,c.pid,s),e.activeObj=t,e.pointerAdd(xt[e.intOperand])}else for(let t=0;t{const t=Br(e.popInt(),Er);e.pushInt(e.activePlayer.invFreeSpace(t.id))})),[Kt.INV_GETNUM]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);e.pushInt(e.activePlayer.invGetSlot(r.id,i)?.count??0)})),[Kt.INV_GETOBJ]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);e.pushInt(e.activePlayer.invGetSlot(r.id,i)?.id??-1)})),[Kt.INV_ITEMSPACE]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,mr);if(Br(r,yr),s<0||s>n.size)throw new Error(`$count is out of range: ${r}`);e.pushInt(0===e.activePlayer.invItemSpace(n.id,a.id,r,s)?1:0)})),[Kt.INV_ITEMSPACE2]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,mr);Br(r,yr),e.pushInt(e.activePlayer.invItemSpace(n.id,a.id,r,s))})),[Kt.INV_MOVEFROMSLOT]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3),s=Br(t,Er),n=Br(i,Er);if(!e.pointerGet(Ht[e.intOperand])&&s.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${s.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&n.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);const a=e.activePlayer,{overflow:o,fromObj:c}=a.invMoveFromSlot(s.id,n.id,r);if(o>0){if(Tt.get(c).stackable&&1!==o)Zl.addObj(new $r(a.level,a.x,a.z,Yr.DESPAWN,c,o),a.pid,200);else for(let e=0;e{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,Er);if(!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&a.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);e.activePlayer.invMoveToSlot(n.id,a.id,r,s)})),[Kt.BOTH_MOVEINV]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er),s=Br(i,Er),n=1==e.intOperand,a=n?e._activePlayer2:e._activePlayer,o=n?e._activePlayer:e._activePlayer2;if(!a||!o)throw new Error('player is null');if(!e.pointerGet(Ht[n?1:0])&&r.protect&&r.scope!==it.SCOPE_SHARED)throw new Error(`$from_inv requires protected access: ${r.debugname}`);if(!e.pointerGet(Ht[n?0:1])&&s.protect&&r.scope!==it.SCOPE_SHARED)throw new Error(`$to_inv requires protected access: ${s.debugname}`);const c=a.getInventory(t),l=o.getInventory(i);if(!c||!l)throw new Error('inv is null');for(let e=0;e{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,Er),o=Br(r,mr);if(Br(s,yr),!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&a.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);const c=e.activePlayer,l=c.invDel(n.id,o.id,s);if(0==l)return;const h=s-c.invAdd(a.id,o.id,l,!1);if(h>0)if(o.stackable&&1!==h)Zl.addObj(new $r(c.level,c.x,c.z,Yr.DESPAWN,o.id,h),c.pid,200);else for(let e=0;e{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,Er),o=Br(r,mr);if(Br(s,yr),!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&a.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);const c=e.activePlayer,l=c.invDel(n.id,o.id,s);if(0==l)return;let h=o.id;-1===o.certtemplate&&o.certlink>=0&&(h=o.certlink);const d=s-c.invAdd(a.id,h,l,!1);d>0&&Zl.addObj(new $r(c.level,c.x,c.z,Yr.DESPAWN,h,d),c.pid,200)})),[Kt.INV_MOVEITEM_UNCERT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(i,Er),o=Br(r,mr);if(Br(s,yr),!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!e.pointerGet(Ht[e.intOperand])&&a.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${a.debugname}`);const c=e.activePlayer,l=c.invDel(n.id,o.id,s);0!=l&&(o.certtemplate>=0&&o.certlink>=0?c.invAdd(a.id,o.certlink,l):c.invAdd(a.id,o.id,l))})),[Kt.INV_SETSLOT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er),a=Br(r,mr);if(Br(s,yr),!e.pointerGet(Ht[e.intOperand])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${n.debugname}`);if(!n.dummyinv&&0!==a.dummyitem)throw new Error(`dummyitem in non-dummyinv: ${a.debugname} -> ${n.debugname}`);e.activePlayer.invSet(n.id,a.id,s,i)})),[Kt.INV_TOTAL]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);-1!==i?e.pushInt(e.activePlayer.invTotal(r.id,i)):e.pushInt(0)})),[Kt.INV_TOTALCAT]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er),s=Br(i,_r);e.pushInt(e.activePlayer.invTotalCat(r.id,s.id))})),[Kt.INV_TRANSMIT]:Vt(Ft,(e=>{const[t,i]=e.popInts(2),r=Br(t,Er);Br(i,Ji),e.activePlayer.invListenOnCom(r.id,i,e.activePlayer.uid)})),[Kt.INVOTHER_TRANSMIT]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,Ji);const s=Br(i,Er);Br(r,Ji),e.activePlayer.invListenOnCom(s.id,r,t)})),[Kt.INV_STOPTRANSMIT]:Vt(Ft,(e=>{const t=Br(e.popInt(),Ji);e.activePlayer.invStopListenOnCom(t)})),[Kt.BOTH_DROPSLOT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,Er);Br(s,sr);const a=Br(i,nr),o=1==e.intOperand,c=o?e._activePlayer2:e._activePlayer,l=o?e._activePlayer:e._activePlayer2;if(!c||!l)throw new Error('player is null');if(!e.pointerGet(Ht[o?1:0])&&n.protect&&n.scope!==it.SCOPE_SHARED)throw new Error(`inv requires protected access: ${n.debugname}`);const h=c.invGetSlot(n.id,r);if(!h)throw new Error('$slot is empty');const d=c.invDel(n.id,h.id,h.count,r);if(0===d)return;const u=Tt.get(h.id);c.playerLog('Dropped item from',n.debugname,u.debugname),u.tradeable&&Zl.addObj(new $r(a.level,a.x,a.z,Yr.DESPAWN,h.id,d),l.pid,s)})),[Kt.INV_DROPALL]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3),s=Br(t,Er);Br(r,sr);const n=Br(i,nr);if(!e.pointerGet(Ht[e.intOperand])&&s.protect&&s.scope!==it.SCOPE_SHARED)throw new Error(`$inv requires protected access: ${s.debugname}`);const a=e.activePlayer.getInventory(s.id);if(a)for(let e=0;e{const[t,i]=e.popInts(2);e.pushInt(e.activePlayer.invTotalParam(t,i))})),[Kt.INV_TOTALPARAM_STACK]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);e.pushInt(e.activePlayer.invTotalParamStack(t,i))}))},Xr=(e=>(e[e.ZONE=0]='ZONE',e[e.DISTANCE=1]='DISTANCE',e))(Xr||{}),Jr=Xr,es=class{iterator;tick;constructor(e){this.iterator=this.generator(),this.tick=e}[Symbol.iterator](){return this.iterator}next(){return this.iterator.next()}},ts=class extends es{x;z;level;minX;maxX;minZ;maxZ;distance;checkVis;checkType;checkCategory;type;constructor(e,t,i,r,s,n,a,o,c){super(e);const l=ji.zone(i),h=ji.zone(r),d=1+s/8|0;this.x=i,this.z=r,this.level=t,this.maxX=l+d,this.minX=l-d,this.maxZ=h+d,this.minZ=h-d,this.distance=s,this.checkVis=n,this.checkType=a,this.checkCategory=o,this.type=c}*generator(){for(let e=this.maxX;e>=this.minX;e--){const t=e<<3;for(let e=this.maxZ;e>=this.minZ;e--){const i=e<<3;if(this.type===je.PLAYER)for(const e of Zl.getZone(t,i,this.level).getAllPlayersSafe()){if(Zl.currentTick>this.tick)throw new Error('[HuntIterator] tried to use an old iterator. Create a new iterator instead.');ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e)}else if(this.type===je.NPC)for(const e of Zl.getZone(t,i,this.level).getAllNpcsSafe()){if(Zl.currentTick>this.tick)throw new Error('[HuntIterator] tried to use an old iterator. Create a new iterator instead.');if(-1!==this.checkType&&e.type!==this.checkType)continue;const t=ft.get(e.type);-1!==this.checkCategory&&t.category!==this.checkCategory||t.op&&t.op[1]&&(ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e))}else if(this.type===je.OBJ)for(const e of Zl.getZone(t,i,this.level).getAllObjsSafe()){if(Zl.currentTick>this.tick)throw new Error('[HuntIterator] tried to use an old iterator. Create a new iterator instead.');if(-1!==this.checkType&&e.type!==this.checkType)continue;const t=Tt.get(e.type);-1!==this.checkCategory&&t.category!==this.checkCategory||(ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e))}else if(this.type===je.SCENERY)for(const e of Zl.getZone(t,i,this.level).getAllLocsSafe()){if(Zl.currentTick>this.tick)throw new Error('[HuntIterator] tried to use an old iterator. Create a new iterator instead.');if(-1!==this.checkType&&e.type!==this.checkType)continue;const t=at.get(e.type);-1!==this.checkCategory&&t.category!==this.checkCategory||(ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e))}}}}},is=class extends es{level;x;z;minX;maxX;minZ;maxZ;distance;checkVis;type;constructor(e,t,i,r,s,n,a){super(e);const o=ji.zone(i),c=ji.zone(r),l=1+s/8|0;this.x=i,this.z=r,this.level=t,this.maxX=o+l,this.minX=o-l,this.maxZ=c+l,this.minZ=c-l,this.distance=s,this.checkVis=n,this.type=a}*generator(){if(this.type===Jr.ZONE)for(const e of Zl.getZone(this.x,this.z,this.level).getAllNpcsSafe()){if(Zl.currentTick>this.tick)throw new Error('[NpcIterator] tried to use an old iterator. Create a new iterator instead.');yield e}else if(this.type===Jr.DISTANCE)for(let e=this.maxX;e>=this.minX;e--){const t=e<<3;for(let e=this.maxZ;e>=this.minZ;e--){const i=e<<3;for(const e of Zl.getZone(t,i,this.level).getAllNpcsSafe()){if(Zl.currentTick>this.tick)throw new Error('[NpcIterator] tried to use an old iterator. Create a new iterator instead.');ji.distanceToSW({x:this.x,z:this.z},e)>this.distance||(this.checkVis!==$e.LINEOFSIGHT||fi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(this.checkVis!==$e.LINEOFWALK||gi(this.level,this.x,this.z,e.x,e.z,1,1,1,1))&&(yield e)}}}}},rs=class extends es{level;x;z;constructor(e,t,i,r){super(e),this.level=t,this.x=i,this.z=r}*generator(){for(const e of Zl.getZone(this.x,this.z,this.level).getAllLocsSafe()){if(Zl.currentTick>this.tick)throw new Error('[LocIterator] tried to use an old iterator. Create a new iterator instead.');yield e}}},ss=class extends Qr{info;constructor(e,t,i,r,s,n,a,o,c){super(e,t,i,r,s,n),this.info=16383&a|(31&o)<<14|(3&c)<<19}get type(){return 16383&this.info}get shape(){return this.info>>14&31}get angle(){return this.info>>19&3}},ns={[Kt.LOC_ADD]:e=>{const[t,i,r,s,n]=e.popInts(5),a=Br(t,nr),o=Br(i,tr),c=Br(r,ir),l=Br(s,rr);Br(n,sr);const h=new ss(a.level,a.x,a.z,o.width,o.length,Yr.DESPAWN,o.id,l,c),d=Zl.getZone(a.x,a.z,a.level).getLocsUnsafe(ji.packZoneCoord(a.x,a.z));for(const e of d)if(e!==h&&e.angle===c&&e.shape===l){Zl.removeLoc(e,n);break}Zl.addLoc(h,n),e.activeLoc=h,e.pointerAdd(Mt[e.intOperand])},[Kt.LOC_ANGLE]:Vt(Mt,(e=>{e.pushInt(Br(e.activeLoc.angle,ir))})),[Kt.LOC_ANIM]:Vt(Mt,(e=>{const t=Br(e.popInt(),Tr);Zl.animLoc(e.activeLoc,t.id)})),[Kt.LOC_CATEGORY]:Vt(Mt,(e=>{e.pushInt(Br(e.activeLoc.type,tr).category)})),[Kt.LOC_CHANGE]:Vt(Mt,(e=>{const[t,i]=e.popInts(2),r=Br(t,tr);Br(i,sr),Zl.removeLoc(e.activeLoc,i);const{level:s,x:n,z:a,angle:o,shape:c}=e.activeLoc,l=new ss(s,n,a,r.width,r.length,Yr.DESPAWN,r.id,c,o),h=Zl.getZone(n,a,s).getLocsUnsafe(ji.packZoneCoord(n,a));for(const e of h)if(e!==l&&e.angle===o&&e.shape===c){Zl.removeLoc(e,i);break}Zl.addLoc(l,i),e.activeLoc=l,e.pointerAdd(Mt[e.intOperand])})),[Kt.LOC_COORD]:Vt(Mt,(e=>{const t=e.activeLoc;e.pushInt(ji.packCoord(t.level,t.x,t.z))})),[Kt.LOC_DEL]:Vt(Mt,(e=>{const t=Br(e.popInt(),sr),{level:i,x:r,z:s,angle:n,shape:a}=e.activeLoc,o=Zl.getZone(r,s,i).getLocsUnsafe(ji.packZoneCoord(r,s));for(const i of o)if(i!==e.activeLoc&&i.angle===n&&i.shape===a){Zl.removeLoc(i,t);break}Zl.removeLoc(e.activeLoc,t)})),[Kt.LOC_FIND]:e=>{const[t,i]=e.popInts(2),r=Br(i,tr),s=Br(t,nr),n=Zl.getLoc(s.x,s.z,s.level,r.id);n?(e.activeLoc=n,e.pointerAdd(Mt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.LOC_FINDALLZONE]:e=>{const t=Br(e.popInt(),nr);e.locIterator=new rs(Zl.currentTick,t.level,t.x,t.z),e._activeLoc&&(e._activeLoc2=e._activeLoc,e.pointerAdd(Gt.ActiveLoc2))},[Kt.LOC_FINDNEXT]:e=>{const t=e.locIterator?.next();t&&!t.done?(e.activeLoc=t.value,e.pointerAdd(Mt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.LOC_PARAM]:Vt(Mt,(e=>{const t=Br(e.popInt(),ar),i=Br(e.activeLoc.type,tr);t.isString()?e.pushString(rt(t.id,i,t.defaultString)):e.pushInt(st(t.id,i,t.defaultInt))})),[Kt.LOC_TYPE]:Vt(Mt,(e=>{e.pushInt(Br(e.activeLoc.type,tr).id)})),[Kt.LOC_NAME]:Vt(Mt,(e=>{e.pushString(Br(e.activeLoc.type,tr).name??'null')})),[Kt.LOC_SHAPE]:Vt(Mt,(e=>{e.pushInt(Br(e.activeLoc.shape,rr))}))},as={[Kt.LC_NAME]:e=>{const t=Br(e.popInt(),tr);e.pushString(t.name??t.debugname??'null')},[Kt.LC_PARAM]:e=>{const[t,i]=e.popInts(2),r=Br(t,tr),s=Br(i,ar);s.isString()?e.pushString(rt(s.id,r,s.defaultString)):e.pushInt(st(s.id,r,s.defaultInt))},[Kt.LC_CATEGORY]:e=>{e.pushInt(Br(e.popInt(),tr).category)},[Kt.LC_DESC]:e=>{e.pushString(Br(e.popInt(),tr).desc??'null')},[Kt.LC_DEBUGNAME]:e=>{e.pushString(Br(e.popInt(),tr).debugname??'null')},[Kt.LC_WIDTH]:e=>{e.pushInt(Br(e.popInt(),tr).width)},[Kt.LC_LENGTH]:e=>{e.pushInt(Br(e.popInt(),tr).length)}},os=(e=>(e[e.PROC=0]='PROC',e[e.LABEL=1]='LABEL',e[e.DEBUGPROC=2]='DEBUGPROC',e[e.APNPC1=3]='APNPC1',e[e.APNPC2=4]='APNPC2',e[e.APNPC3=5]='APNPC3',e[e.APNPC4=6]='APNPC4',e[e.APNPC5=7]='APNPC5',e[e.APNPCU=8]='APNPCU',e[e.APNPCT=9]='APNPCT',e[e.OPNPC1=10]='OPNPC1',e[e.OPNPC2=11]='OPNPC2',e[e.OPNPC3=12]='OPNPC3',e[e.OPNPC4=13]='OPNPC4',e[e.OPNPC5=14]='OPNPC5',e[e.OPNPCU=15]='OPNPCU',e[e.OPNPCT=16]='OPNPCT',e[e.AI_APNPC1=17]='AI_APNPC1',e[e.AI_APNPC2=18]='AI_APNPC2',e[e.AI_APNPC3=19]='AI_APNPC3',e[e.AI_APNPC4=20]='AI_APNPC4',e[e.AI_APNPC5=21]='AI_APNPC5',e[e.AI_OPNPC1=24]='AI_OPNPC1',e[e.AI_OPNPC2=25]='AI_OPNPC2',e[e.AI_OPNPC3=26]='AI_OPNPC3',e[e.AI_OPNPC4=27]='AI_OPNPC4',e[e.AI_OPNPC5=28]='AI_OPNPC5',e[e.APOBJ1=31]='APOBJ1',e[e.APOBJ2=32]='APOBJ2',e[e.APOBJ3=33]='APOBJ3',e[e.APOBJ4=34]='APOBJ4',e[e.APOBJ5=35]='APOBJ5',e[e.APOBJU=36]='APOBJU',e[e.APOBJT=37]='APOBJT',e[e.OPOBJ1=38]='OPOBJ1',e[e.OPOBJ2=39]='OPOBJ2',e[e.OPOBJ3=40]='OPOBJ3',e[e.OPOBJ4=41]='OPOBJ4',e[e.OPOBJ5=42]='OPOBJ5',e[e.OPOBJU=43]='OPOBJU',e[e.OPOBJT=44]='OPOBJT',e[e.AI_APOBJ1=45]='AI_APOBJ1',e[e.AI_APOBJ2=46]='AI_APOBJ2',e[e.AI_APOBJ3=47]='AI_APOBJ3',e[e.AI_APOBJ4=48]='AI_APOBJ4',e[e.AI_APOBJ5=49]='AI_APOBJ5',e[e.AI_OPOBJ1=52]='AI_OPOBJ1',e[e.AI_OPOBJ2=53]='AI_OPOBJ2',e[e.AI_OPOBJ3=54]='AI_OPOBJ3',e[e.AI_OPOBJ4=55]='AI_OPOBJ4',e[e.AI_OPOBJ5=56]='AI_OPOBJ5',e[e.APLOC1=59]='APLOC1',e[e.APLOC2=60]='APLOC2',e[e.APLOC3=61]='APLOC3',e[e.APLOC4=62]='APLOC4',e[e.APLOC5=63]='APLOC5',e[e.APLOCU=64]='APLOCU',e[e.APLOCT=65]='APLOCT',e[e.OPLOC1=66]='OPLOC1',e[e.OPLOC2=67]='OPLOC2',e[e.OPLOC3=68]='OPLOC3',e[e.OPLOC4=69]='OPLOC4',e[e.OPLOC5=70]='OPLOC5',e[e.OPLOCU=71]='OPLOCU',e[e.OPLOCT=72]='OPLOCT',e[e.AI_APLOC1=73]='AI_APLOC1',e[e.AI_APLOC2=74]='AI_APLOC2',e[e.AI_APLOC3=75]='AI_APLOC3',e[e.AI_APLOC4=76]='AI_APLOC4',e[e.AI_APLOC5=77]='AI_APLOC5',e[e.AI_OPLOC1=80]='AI_OPLOC1',e[e.AI_OPLOC2=81]='AI_OPLOC2',e[e.AI_OPLOC3=82]='AI_OPLOC3',e[e.AI_OPLOC4=83]='AI_OPLOC4',e[e.AI_OPLOC5=84]='AI_OPLOC5',e[e.APPLAYER1=87]='APPLAYER1',e[e.APPLAYER2=88]='APPLAYER2',e[e.APPLAYER3=89]='APPLAYER3',e[e.APPLAYER4=90]='APPLAYER4',e[e.APPLAYER5=91]='APPLAYER5',e[e.APPLAYERU=92]='APPLAYERU',e[e.APPLAYERT=93]='APPLAYERT',e[e.OPPLAYER1=94]='OPPLAYER1',e[e.OPPLAYER2=95]='OPPLAYER2',e[e.OPPLAYER3=96]='OPPLAYER3',e[e.OPPLAYER4=97]='OPPLAYER4',e[e.OPPLAYER5=98]='OPPLAYER5',e[e.OPPLAYERU=99]='OPPLAYERU',e[e.OPPLAYERT=100]='OPPLAYERT',e[e.AI_APPLAYER1=101]='AI_APPLAYER1',e[e.AI_APPLAYER2=102]='AI_APPLAYER2',e[e.AI_APPLAYER3=103]='AI_APPLAYER3',e[e.AI_APPLAYER4=104]='AI_APPLAYER4',e[e.AI_APPLAYER5=105]='AI_APPLAYER5',e[e.AI_OPPLAYER1=108]='AI_OPPLAYER1',e[e.AI_OPPLAYER2=109]='AI_OPPLAYER2',e[e.AI_OPPLAYER3=110]='AI_OPPLAYER3',e[e.AI_OPPLAYER4=111]='AI_OPPLAYER4',e[e.AI_OPPLAYER5=112]='AI_OPPLAYER5',e[e.QUEUE=116]='QUEUE',e[e.AI_QUEUE1=117]='AI_QUEUE1',e[e.AI_QUEUE2=118]='AI_QUEUE2',e[e.AI_QUEUE3=119]='AI_QUEUE3',e[e.AI_QUEUE4=120]='AI_QUEUE4',e[e.AI_QUEUE5=121]='AI_QUEUE5',e[e.AI_QUEUE6=122]='AI_QUEUE6',e[e.AI_QUEUE7=123]='AI_QUEUE7',e[e.AI_QUEUE8=124]='AI_QUEUE8',e[e.AI_QUEUE9=125]='AI_QUEUE9',e[e.AI_QUEUE10=126]='AI_QUEUE10',e[e.AI_QUEUE11=127]='AI_QUEUE11',e[e.AI_QUEUE12=128]='AI_QUEUE12',e[e.AI_QUEUE13=129]='AI_QUEUE13',e[e.AI_QUEUE14=130]='AI_QUEUE14',e[e.AI_QUEUE15=131]='AI_QUEUE15',e[e.AI_QUEUE16=132]='AI_QUEUE16',e[e.AI_QUEUE17=133]='AI_QUEUE17',e[e.AI_QUEUE18=134]='AI_QUEUE18',e[e.AI_QUEUE19=135]='AI_QUEUE19',e[e.AI_QUEUE20=136]='AI_QUEUE20',e[e.SOFTTIMER=137]='SOFTTIMER',e[e.TIMER=138]='TIMER',e[e.AI_TIMER=139]='AI_TIMER',e[e.OPHELD1=140]='OPHELD1',e[e.OPHELD2=141]='OPHELD2',e[e.OPHELD3=142]='OPHELD3',e[e.OPHELD4=143]='OPHELD4',e[e.OPHELD5=144]='OPHELD5',e[e.OPHELDU=145]='OPHELDU',e[e.OPHELDT=146]='OPHELDT',e[e.IF_BUTTON=147]='IF_BUTTON',e[e.INV_BUTTON1=148]='INV_BUTTON1',e[e.INV_BUTTON2=149]='INV_BUTTON2',e[e.INV_BUTTON3=150]='INV_BUTTON3',e[e.INV_BUTTON4=151]='INV_BUTTON4',e[e.INV_BUTTON5=152]='INV_BUTTON5',e[e.INV_BUTTOND=153]='INV_BUTTOND',e[e.IF_CLOSE=154]='IF_CLOSE',e[e.LOGIN=155]='LOGIN',e[e.LOGOUT=156]='LOGOUT',e[e.TUTORIAL_CLICKSIDE=157]='TUTORIAL_CLICKSIDE',e[e.MOVE=158]='MOVE',e[e.WALKTRIGGER=159]='WALKTRIGGER',e[e.AI_WALKTRIGGER=160]='AI_WALKTRIGGER',e[e.LEVELUP=161]='LEVELUP',e))(os||{});(Mr=os||(os={})).toString=function(e){return Mr[e].toLowerCase()};var cs=os,ls=(e=>(e[e.SCRIPT=0]='SCRIPT',e[e.ENGINE=1]='ENGINE',e))(ls||{}),hs=ls,ds={[Kt.NPC_FINDUID]:e=>{const t=e.popInt(),i=65535&t,r=t>>16&65535,s=Zl.getNpc(i);s&&s.type===r?(e.activeNpc=s,e.pointerAdd(kt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.NPC_ADD]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr),n=Br(i,or);Br(r,sr);const a=new kl(s.level,s.x,s.z,n.size,n.size,Yr.DESPAWN,Zl.getNextNid(),n.id,n.moverestrict,n.blockwalk);Zl.addNpc(a,r),e.activeNpc=a,e.pointerAdd(kt[e.intOperand])},[Kt.NPC_ANIM]:Vt(kt,(e=>{const t=Br(e.popInt(),Ji),i=e.popInt();e.activeNpc.playAnimation(i,t)})),[Kt.NPC_BASESTAT]:Vt(kt,(e=>{const t=Br(e.popInt(),cr);e.pushInt(e.activeNpc.baseLevels[t])})),[Kt.NPC_CATEGORY]:Vt(kt,(e=>{e.pushInt(Br(e.activeNpc.type,or).category)})),[Kt.NPC_COORD]:Vt(kt,(e=>{const t=e.activeNpc;e.pushInt(ji.packCoord(t.level,t.x,t.z))})),[Kt.NPC_DEL]:Vt(kt,(e=>{Zl.removeNpc(e.activeNpc,Br(e.activeNpc.type,or).respawnrate)})),[Kt.NPC_DELAY]:Vt(kt,(e=>{e.activeNpc.delay=Zl.currentTick+Br(e.popInt(),Ji)+1,e.execution=$t.NPC_SUSPENDED})),[Kt.NPC_FACESQUARE]:Vt(kt,(e=>{const t=Br(e.popInt(),nr);e.activeNpc.faceSquare(t.x,t.z)})),[Kt.NPC_FINDEXACT]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,or);e.npcIterator=new is(Zl.currentTick,r.level,r.x,r.z,0,0,Jr.ZONE);for(const t of e.npcIterator)if(t.type===s.id&&t.x===r.x&&t.level===r.level&&t.z===r.z)return e.activeNpc=t,e.pointerAdd(kt[e.intOperand]),void e.pushInt(1);e.pushInt(0)},[Kt.NPC_FINDHERO]:Vt(kt,(e=>{const t=e.activeNpc.findHero();if(-1===t)return void e.pushInt(0);const i=Zl.getPlayerByUid(t);i?(e.activePlayer=i,e.pointerAdd(Gt.ActivePlayer),e.pushInt(1)):e.pushInt(0)})),[Kt.NPC_PARAM]:Vt(kt,(e=>{const t=Br(e.popInt(),ar),i=Br(e.activeNpc.type,or);t.isString()?e.pushString(rt(t.id,i,t.defaultString)):e.pushInt(st(t.id,i,t.defaultInt))})),[Kt.NPC_QUEUE]:Vt(kt,(e=>{const t=Br(e.popInt(),Ji),i=e.popInt(),r=Br(e.popInt(),hr),s=Br(e.activeNpc.type,or),n=jt.getByTrigger(cs.AI_QUEUE1+r-1,s.id,s.category);n&&e.activeNpc.enqueueScript(n,t,i)})),[Kt.NPC_RANGE]:Vt(kt,(e=>{const t=Br(e.popInt(),nr),i=e.activeNpc;t.level!==i.level?e.pushInt(-1):e.pushInt(ji.distanceTo(i,{x:t.x,z:t.z,width:1,length:1}))})),[Kt.NPC_SAY]:Vt(kt,(e=>{e.activeNpc.say(e.popString())})),[Kt.NPC_SETHUNT]:Vt(kt,(e=>{e.activeNpc.huntrange=Br(e.popInt(),Ji)})),[Kt.NPC_SETHUNTMODE]:Vt(kt,(e=>{e.activeNpc.huntMode=Br(e.popInt(),dr).id})),[Kt.NPC_SETMODE]:Vt(kt,(e=>{const t=Br(e.popInt(),ur);if(e.activeNpc.clearWaypoints(),t===Xe.NULL||t===Xe.NONE||t===Xe.WANDER||t===Xe.PATROL)return e.activeNpc.clearInteraction(),void(e.activeNpc.targetOp=t);let i;e.activeNpc.targetOp=t,i=t>=Xe.OPNPC1?e._activeNpc2:t>=Xe.OPOBJ1?e._activeObj:t>=Xe.OPLOC1?e._activeLoc:e._activePlayer,i?i instanceof kl||i instanceof $r||i instanceof ss?e.activeNpc.setInteraction(hs.SCRIPT,i,t,{type:i.type,com:-1}):e.activeNpc.setInteraction(hs.SCRIPT,i,t):e.activeNpc.noMode()})),[Kt.NPC_STAT]:Vt(kt,(e=>{const t=Br(e.popInt(),cr);e.pushInt(e.activeNpc.levels[t])})),[Kt.NPC_STATHEAL]:Vt(kt,(e=>{const[t,i,r]=e.popInts(3);Br(t,cr),Br(i,Ji),Br(r,Ji);const s=e.activeNpc,n=s.baseLevels[t],a=s.levels[t],o=a+(i+a*r/100);s.levels[t]=Math.min(o,n),0===t&&s.levels[t]===s.baseLevels[t]&&s.resetHeroPoints()})),[Kt.NPC_TYPE]:Vt(kt,(e=>{e.pushInt(Br(e.activeNpc.type,or).id)})),[Kt.NPC_DAMAGE]:Vt(kt,(e=>{const t=Br(e.popInt(),Ji),i=Br(e.popInt(),pr);e.activeNpc.applyDamage(t,i)})),[Kt.NPC_NAME]:Vt(kt,(e=>{e.pushString(Br(e.activeNpc.type,or).name??'null')})),[Kt.NPC_UID]:Vt(kt,(e=>{e.pushInt(e.activeNpc.uid)})),[Kt.NPC_SETTIMER]:Vt(kt,(e=>{e.activeNpc.setTimer(Br(e.popInt(),Ji))})),[Kt.SPOTANIM_NPC]:Vt(kt,(e=>{const t=Br(e.popInt(),Ji),i=Br(e.popInt(),Ji),r=Br(e.popInt(),fr);e.activeNpc.spotanim(r.id,i,t)})),[Kt.NPC_FIND]:e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,nr),a=Br(i,or);Br(r,Ji);const o=Br(s,vr);let c,l=r;const h=new is(Zl.currentTick,n.level,n.x,n.z,r,o,Jr.DISTANCE);for(const e of h)if(e&&e.type===a.id){const t=ji.distanceToSW(n,e);t<=l&&(c=e,l=t)}c?(e.activeNpc=c,e.pointerAdd(kt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.NPC_FINDALLANY]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr);Br(i,Ji);const n=Br(r,vr);e.npcIterator=new is(Zl.currentTick,s.level,s.x,s.z,i,n,Jr.DISTANCE),e._activeNpc&&(e._activeNpc2=e._activeNpc,e.pointerAdd(Gt.ActiveNpc2))},[Kt.NPC_FINDALLZONE]:e=>{const t=Br(e.popInt(),nr);e.npcIterator=new is(Zl.currentTick,t.level,t.x,t.z,0,0,Jr.ZONE),e._activeNpc&&(e._activeNpc2=e._activeNpc,e.pointerAdd(Gt.ActiveNpc2))},[Kt.NPC_FINDNEXT]:e=>{const t=e.npcIterator?.next();t&&!t.done?(e.activeNpc=t.value,e.pointerAdd(kt[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.NPC_TELE]:Vt(kt,(e=>{const t=Br(e.popInt(),nr);e.activeNpc.teleport(t.x,t.z,t.level)})),[Kt.NPC_WALK]:Vt(kt,(e=>{const t=Br(e.popInt(),nr);e.activeNpc.queueWaypoint(t.x,t.z)})),[Kt.NPC_CHANGETYPE]:Vt(kt,(e=>{e.activeNpc.changeType(Br(e.popInt(),or).id)})),[Kt.NPC_GETMODE]:Vt(kt,(e=>{e.pushInt(e.activeNpc.targetOp)})),[Kt.NPC_HEROPOINTS]:Vt([Gt.ActivePlayer,...kt],(e=>{e.activeNpc.addHero(e.activePlayer.uid,Br(e.popInt(),Ji))})),[Kt.NPC_WALKTRIGGER]:Vt(kt,(e=>{const[t,i]=e.popInts(2);Br(t,hr),e.activeNpc.walktrigger=t-1,e.activeNpc.walktriggerArg=i})),[Kt.NPC_STATADD]:Vt(kt,(e=>{const[t,i,r]=e.popInts(3);Br(t,cr),Br(i,Ji),Br(r,Ji);const s=e.activeNpc,n=s.levels[t],a=n+(i+n*r/100);s.levels[t]=Math.min(a,255),0===t&&s.levels[t]>=s.baseLevels[t]&&s.resetHeroPoints()})),[Kt.NPC_STATSUB]:Vt(kt,(e=>{const[t,i,r]=e.popInts(3);Br(t,cr),Br(i,Ji),Br(r,Ji);const s=e.activeNpc,n=s.levels[t],a=n-(i+n*r/100);s.levels[t]=Math.max(a,0)})),[Kt.NPC_ATTACKRANGE]:Vt(kt,(e=>{e.pushInt(Br(e.activeNpc.type,or).attackrange)}))},us=ds,ps={[Kt.NC_NAME]:e=>{const t=Br(e.popInt(),or);e.pushString(t.name??t.debugname??'null')},[Kt.NC_PARAM]:e=>{const[t,i]=e.popInts(2),r=Br(t,or),s=Br(i,ar);s.isString()?e.pushString(rt(i,r,s.defaultString)):e.pushInt(st(i,r,s.defaultInt))},[Kt.NC_CATEGORY]:e=>{e.pushInt(Br(e.popInt(),or).category)},[Kt.NC_DESC]:e=>{e.pushString(Br(e.popInt(),or).desc??'null')},[Kt.NC_DEBUGNAME]:e=>{e.pushString(Br(e.popInt(),or).debugname??'null')},[Kt.NC_OP]:e=>{const[t,i]=e.popInts(2),r=Br(t,or);Br(i,Ji),r.op?e.pushString(r.op[i-1]??''):e.pushString('')}},gs=class{static _sin=new Int32Array(16384);static _cos=new Int32Array(16384);static{const e=.0003834951969714103;for(let t=0;t<16384;t++)this._sin[t]=16384*Math.sin(t*e)|0,this._cos[t]=16384*Math.cos(t*e)|0}static radians(e){return(16383&e)/16384*6.283185307179586}static atan2(e,t){return 16383&Math.round(2607.5945876176133*Math.atan2(e,t))}static sin(e){return this._sin[16383&e]}static cos(e){return this._cos[16383&e]}},ms={[Kt.ADD]:e=>{const t=e.popInt(),i=e.popInt();e.pushInt(i+t)},[Kt.SUB]:e=>{const t=e.popInt(),i=e.popInt();e.pushInt(i-t)},[Kt.MULTIPLY]:e=>{const t=e.popInt(),i=e.popInt();e.pushInt(i*t)},[Kt.DIVIDE]:e=>{const t=e.popInt(),i=e.popInt();e.pushInt(i/t)},[Kt.RANDOM]:e=>{const t=e.popInt();e.pushInt(Math.random()*t)},[Kt.RANDOMINC]:e=>{const t=e.popInt();e.pushInt(Math.random()*(t+1))},[Kt.INTERPOLATE]:e=>{const[t,i,r,s,n]=e.popInts(5),a=Math.floor((i-t)/(s-r))*(n-r)+t;e.pushInt(a)},[Kt.ADDPERCENT]:e=>{const[t,i]=e.popInts(2);e.pushInt(t*i/100+t|0)},[Kt.SETBIT]:e=>{const[t,i]=e.popInts(2);e.pushInt(t|1<{const[t,i]=e.popInts(2);e.pushInt(t&~(1<{const[t,i]=e.popInts(2);e.pushInt(t&1<{const[t,i]=e.popInts(2);e.pushInt(t%i)},[Kt.POW]:e=>{const[t,i]=e.popInts(2);e.pushInt(Math.pow(t,i))},[Kt.INVPOW]:e=>{const[t,i]=e.popInts(2);if(0===t||0===i)e.pushInt(0);else switch(i){case 1:return void e.pushInt(t);case 2:return void e.pushInt(Math.sqrt(t));case 3:return void e.pushInt(Math.cbrt(t));case 4:return void e.pushInt(Math.sqrt(Math.sqrt(t)));default:return void e.pushInt(Math.pow(t,1/i))}},[Kt.AND]:e=>{const[t,i]=e.popInts(2);e.pushInt(t&i)},[Kt.OR]:e=>{const[t,i]=e.popInts(2);e.pushInt(t|i)},[Kt.MIN]:e=>{const[t,i]=e.popInts(2);e.pushInt(Math.min(t,i))},[Kt.MAX]:e=>{const[t,i]=e.popInts(2);e.pushInt(Math.max(t,i))},[Kt.SCALE]:e=>{const[t,i,r]=e.popInts(3);e.pushInt(t*r/i)},[Kt.BITCOUNT]:e=>{var t;e.pushInt((t=e.popInt(),16843009*((t=(858993459&(t-=t>>1&1431655765))+(t>>2&858993459))+(t>>4)&252645135)>>24))},[Kt.TOGGLEBIT]:e=>{const[t,i]=e.popInts(2);e.pushInt(t^1<{const[t,i,r]=e.popInts(3);e.pushInt(function(e,t,i){return e|Yt[i-t+1]<{const[t,i,r]=e.popInts(3);e.pushInt(Qt(t,i,r))},[Kt.GETBIT_RANGE]:e=>{const[t,i,r]=e.popInts(3),s=31-r;e.pushInt(t<>>i+s)},[Kt.SETBIT_RANGE_TOINT]:e=>{const[t,i,r,s]=e.popInts(4),n=Qt(t,r,s),a=Yt[s-r+1];let o=i;i>a&&(o=a),e.pushInt(n|o<{e.pushInt(gs.sin(e.popInt()))},[Kt.COS_DEG]:e=>{e.pushInt(gs.cos(e.popInt()))},[Kt.ATAN2_DEG]:e=>{e.pushInt(gs.atan2(e.popInt(),e.popInt()))},[Kt.ABS]:e=>{e.pushInt(Math.abs(e.popInt()))}},ys=ms,Es={[Kt.OBJ_ADD]:e=>{const[t,i,r,s]=e.popInts(4);if(-1===i||-1===r)return;const n=Br(i,mr);Br(s,sr);const a=Br(t,nr);if(Br(r,yr),0!==n.dummyitem)throw new Error(`attempted to add dummy item: ${n.debugname}`);if(!n.members||vt.NODE_MEMBERS)if(n.stackable&&1!==r){const t=new $r(a.level,a.x,a.z,Yr.DESPAWN,i,r);Zl.addObj(t,e.activePlayer.pid,s),e.activeObj=t,e.pointerAdd(xt[e.intOperand])}else for(let t=0;t{const[t,i,r,s]=e.popInts(4);if(-1===i||-1===r)return;const n=Br(i,mr);Br(s,sr);const a=Br(t,nr);if(Br(r,yr),0!==n.dummyitem)throw new Error(`attempted to add dummy item: ${n.debugname}`);if(!n.members||vt.NODE_MEMBERS)if(n.stackable&&1!==r){const t=new $r(a.level,a.x,a.z,Yr.DESPAWN,i,r);Zl.addObj(t,-1,s),e.activeObj=t,e.pointerAdd(xt[e.intOperand])}else for(let t=0;t{const t=Br(e.popInt(),ar),i=Br(e.activeObj.type,mr);t.isString()?e.pushString(rt(t.id,i,t.defaultString)):e.pushInt(st(t.id,i,t.defaultInt))},[Kt.OBJ_NAME]:e=>{const t=Br(e.activeObj.type,mr);e.pushString(t.name??t.debugname??'null')},[Kt.OBJ_DEL]:e=>{const t=Tt.get(e.activeObj.type).respawnrate;e.pointerGet(Ft[e.intOperand]),Zl.removeObj(e.activeObj,t)},[Kt.OBJ_COUNT]:e=>{e.pushInt(Br(e.activeObj.count,yr))},[Kt.OBJ_TYPE]:e=>{e.pushInt(Br(e.activeObj.type,mr).id)},[Kt.OBJ_TAKEITEM]:e=>{const t=Br(e.popInt(),Er),i=e.activeObj,r=Tt.get(i.type),s=Zl.getZone(i.x,i.z,i.level);for(const n of s.getObjsSafe(ji.packZoneCoord(i.x,i.z)))if(n.type===i.type&&n.count===i.count&&(-1===n.receiverId||n.receiverId===e.activePlayer.pid)){if(e.activePlayer.playerLog('Picked up item',r.debugname),e.activePlayer.invAdd(t.id,i.type,i.count),i.lifecycle===Yr.RESPAWN){Zl.removeObj(i,r.respawnrate);break}if(i.lifecycle===Yr.DESPAWN){Zl.removeObj(i,0);break}}},[Kt.OBJ_COORD]:e=>{const t=e.activeObj;e.pushInt(ji.packCoord(t.level,t.x,t.z))}},_s={[Kt.OC_NAME]:e=>{const t=Br(e.popInt(),mr);e.pushString(t.name??t.debugname??'null')},[Kt.OC_PARAM]:e=>{const[t,i]=e.popInts(2),r=Br(t,mr),s=Br(i,ar);s.isString()?e.pushString(rt(s.id,r,s.defaultString)):e.pushInt(st(s.id,r,s.defaultInt))},[Kt.OC_CATEGORY]:e=>{e.pushInt(Br(e.popInt(),mr).category)},[Kt.OC_DESC]:e=>{e.pushString(Br(e.popInt(),mr).desc??'null')},[Kt.OC_MEMBERS]:e=>{e.pushInt(Br(e.popInt(),mr).members?1:0)},[Kt.OC_WEIGHT]:e=>{e.pushInt(Br(e.popInt(),mr).weight)},[Kt.OC_WEARPOS]:e=>{e.pushInt(Br(e.popInt(),mr).wearpos)},[Kt.OC_WEARPOS2]:e=>{e.pushInt(Br(e.popInt(),mr).wearpos2)},[Kt.OC_WEARPOS3]:e=>{e.pushInt(Br(e.popInt(),mr).wearpos3)},[Kt.OC_COST]:e=>{e.pushInt(Br(e.popInt(),mr).cost)},[Kt.OC_TRADEABLE]:e=>{e.pushInt(Br(e.popInt(),mr).tradeable?1:0)},[Kt.OC_DEBUGNAME]:e=>{e.pushString(Br(e.popInt(),mr).debugname??'null')},[Kt.OC_CERT]:e=>{const t=Br(e.popInt(),mr);-1==t.certtemplate&&t.certlink>=0?e.pushInt(t.certlink):e.pushInt(t.id)},[Kt.OC_UNCERT]:e=>{const t=Br(e.popInt(),mr);t.certtemplate>=0&&t.certlink>=0?e.pushInt(t.certlink):e.pushInt(t.id)},[Kt.OC_STACKABLE]:e=>{e.pushInt(Br(e.popInt(),mr).stackable?1:0)}},As=class extends Te{type;script;args;delay;lastInt=0;constructor(e,t,i,r){super(),this.type=e,this.script=t,this.args=i,this.delay=r}},vs=class extends Te{script;delay;constructor(e,t){super(),this.script=e,this.delay=t}},Ts=class e{constructor(t,i){this.id=t,this.length=i,e.all.push(this),e.byId[t]=this}static all=[];static byId=[];static IF_OPENCHATMODAL=new e(14,2);static IF_OPENMAINSIDEMODAL=new e(28,4);static IF_CLOSE=new e(129,0);static IF_OPENSIDEOVERLAY=new e(167,3);static IF_OPENMAINMODAL=new e(168,2);static IF_OPENSIDEMODAL=new e(195,2);static IF_SETCOLOUR=new e(2,4);static IF_SETHIDE=new e(26,3);static IF_SETOBJECT=new e(46,6);static IF_SHOWSIDE=new e(84,1);static IF_SETMODEL=new e(87,4);static IF_SETRECOL=new e(103,6);static IF_SETANIM=new e(146,4);static IF_SETPLAYERHEAD=new e(197,2);static IF_SETTEXT=new e(201,-2);static IF_SETNPCHEAD=new e(204,4);static IF_SETPOSITION=new e(209,6);static TUTORIAL_FLASHSIDE=new e(126,1);static TUTORIAL_OPENCHAT=new e(185,2);static UPDATE_INV_STOP_TRANSMIT=new e(15,2);static UPDATE_INV_FULL=new e(98,-2);static UPDATE_INV_PARTIAL=new e(213,-2);static CAM_LOOKAT=new e(74,6);static CAM_SHAKE=new e(13,4);static CAM_MOVETO=new e(3,6);static CAM_RESET=new e(239,0);static NPC_INFO=new e(1,-2);static PLAYER_INFO=new e(184,-2);static FINISH_TRACKING=new e(133,0);static ENABLE_TRACKING=new e(226,0);static MESSAGE_GAME=new e(4,-1);static UPDATE_IGNORELIST=new e(21,-2);static CHAT_FILTER_SETTINGS=new e(32,3);static MESSAGE_PRIVATE=new e(41,-1);static UPDATE_FRIENDLIST=new e(152,9);static UNSET_MAP_FLAG=new e(19,0);static UPDATE_RUNWEIGHT=new e(22,2);static HINT_ARROW=new e(25,6);static UPDATE_REBOOT_TIMER=new e(43,2);static UPDATE_STAT=new e(44,6);static UPDATE_RUNENERGY=new e(68,1);static RESET_ANIMS=new e(136,0);static UPDATE_UID192=new e(139,2);static LAST_LOGIN_INFO=new e(140,9);static LOGOUT=new e(142,0);static P_COUNTDIALOG=new e(243,0);static SET_MULTIWAY=new e(254,1);static DATA_LOC_DONE=new e(20,2);static DATA_LAND_DONE=new e(80,2);static DATA_LAND=new e(132,-2);static DATA_LOC=new e(220,-2);static REBUILD_NORMAL=new e(237,-2);static VARP_SMALL=new e(150,3);static VARP_LARGE=new e(175,6);static RESET_CLIENT_VARCACHE=new e(193,0);static SYNTH_SOUND=new e(12,5);static MIDI_SONG=new e(54,-1);static MIDI_JINGLE=new e(212,-2);static UPDATE_ZONE_PARTIAL_FOLLOWS=new e(7,2);static UPDATE_ZONE_FULL_FOLLOWS=new e(135,2);static UPDATE_ZONE_PARTIAL_ENCLOSED=new e(162,-2)},Cs=(e=>(e[e.STATIONARY=0]='STATIONARY',e[e.CRAWL=1]='CRAWL',e[e.WALK=2]='WALK',e[e.RUN=3]='RUN',e[e.INSTANT=4]='INSTANT',e))(Cs||{}),Is=Cs,Ss=(e=>(e[e.SMART=0]='SMART',e[e.NAIVE=1]='NAIVE',e[e.FLY=2]='FLY',e))(Ss||{}),Os=Ss,Ns=class e extends qr{moveRestrict;blockWalk;moveStrategy;coordmask;entitymask;moveSpeed=Is.INSTANT;walkDir=-1;runDir=-1;waypointIndex=-1;waypoints=new Int32Array(25);lastX=-1;lastZ=-1;lastLevel=-1;tele=!1;jump=!1;lastStepX=-1;lastStepZ=-1;stepsTaken=0;lastInt=-1;lastCrawl=!1;walktrigger=-1;walktriggerArg=0;interacted=!1;repathed=!1;target=null;targetOp=-1;targetSubject={type:-1,com:-1};targetX=-1;targetZ=-1;apRange=10;apRangeCalled=!1;alreadyFacedEntity=!1;mask=0;exactStartX=-1;exactStartZ=-1;exactEndX=-1;exactEndZ=-1;exactMoveStart=-1;exactMoveEnd=-1;exactMoveDirection=-1;faceX=-1;faceZ=-1;orientationX=-1;orientationZ=-1;faceEntity=-1;damageTaken=-1;damageType=-1;animId=-1;animDelay=-1;chat=null;graphicId=-1;graphicHeight=-1;graphicDelay=-1;constructor(e,t,i,r,s,n,a,o,c,l,h){super(e,t,i,r,s,n),this.moveRestrict=a,this.blockWalk=o,this.moveStrategy=c,this.coordmask=l,this.entitymask=h,this.lastStepX=t-1,this.lastStepZ=i}processMovement(){return!(!this.hasWaypoints()||this.moveSpeed===Is.STATIONARY||this.moveSpeed===Is.INSTANT)&&(this.moveSpeed===Is.CRAWL?(this.lastCrawl=!this.lastCrawl,this.lastCrawl&&-1===this.walkDir&&(this.walkDir=this.validateAndAdvanceStep()),!0):(-1===this.walkDir&&(this.walkDir=this.validateAndAdvanceStep(),this.moveSpeed===Is.RUN&&-1!==this.walkDir&&-1===this.runDir&&(this.runDir=this.validateAndAdvanceStep())),!0))}refreshZonePresence(e,t,i){if(this.x!=e||this.z!==t||this.level!==i){switch(this.blockWalk){case lt.NPC:Zl.gameMap.changeNpcCollision(this.width,e,t,i,!1),Zl.gameMap.changeNpcCollision(this.width,this.x,this.z,this.level,!0);break;case lt.ALL:Zl.gameMap.changeNpcCollision(this.width,e,t,i,!1),Zl.gameMap.changeNpcCollision(this.width,this.x,this.z,this.level,!0),Zl.gameMap.changePlayerCollision(this.width,e,t,i,!1),Zl.gameMap.changePlayerCollision(this.width,this.x,this.z,this.level,!0)}this.lastStepX=e,this.lastStepZ=t}ji.zone(e)===ji.zone(this.x)&&ji.zone(t)===ji.zone(this.z)&&i==this.level||(Zl.getZone(e,t,i).leave(this),Zl.getZone(this.x,this.z,this.level).enter(this))}validateAndAdvanceStep(){const e=this.takeStep();if(null===e)return-1;if(-1===e)return this.waypointIndex--,-1!=this.waypointIndex?this.validateAndAdvanceStep():-1;const t=this.x,i=this.z;return this.x=ji.moveX(this.x,e),this.z=ji.moveZ(this.z,e),this.orientationX=2*ji.moveX(this.x,e)+1,this.orientationZ=2*ji.moveZ(this.z,e)+1,this.stepsTaken++,this.refreshZonePresence(t,i,this.level),e}queueWaypoint(e,t){this.waypoints[0]=ji.packCoord(0,e,t),this.waypointIndex=0}queueWaypoints(e){let t=-1;for(let i=e.length-1,r=0;i>=0&&r2&&(this.jump=!0)}convertMovementDir(){let e=this.walkDir,t=this.runDir,i=this.moveSpeed===Is.INSTANT;const r=ji.distanceTo(this,{x:this.lastX,z:this.lastZ,width:this.width,length:this.length});if(i&&!this.jump&&r<=2){if(2===r){const i=(this.x+this.lastX)/2|0,r=(this.z+this.lastZ)/2|0;e=ji.face(this.lastX,this.lastZ,i,r),t=ji.face(i,r,this.x,this.z)}else e=ji.face(this.lastX,this.lastZ,this.x,this.z),t=-1;i=!1}this.walkDir=e,this.runDir=t,this.tele=i}hasWaypoints(){return-1!==this.waypointIndex}isLastOrNoWaypoint(){return this.waypointIndex<=0}inOperableDistance(t){if(t.level!==this.level)return!1;if(t instanceof e)return Ei(this.level,this.x,this.z,t.x,t.z,t.width,t.length,this.width,-1,-2);if(t instanceof ss){const e=at.get(t.type).forceapproach;return Ei(this.level,this.x,this.z,t.x,t.z,t.width,t.length,this.width,t.angle,t.shape,e)}const i=Ei(this.level,this.x,this.z,t.x,t.z,t.width,t.length,this.width,0,-2);return ui(t.x,t.z,t.level,Ri.WALK_BLOCKED)?i:!(this.hasWaypoints()||!i)||Ei(this.level,this.x,this.z,t.x,t.z,t.width,t.length,this.width,0,-1)}inApproachDistance(t,i){return i.level===this.level&&(!(i instanceof e&&ji.intersects(this.x,this.z,this.width,this.length,i.x,i.z,i.width,i.length))&&(ji.distanceTo(this,i)<=t&&fi(this.level,this.x,this.z,i.x,i.z,this.width,this.length,i.width,i.length,Ri.PLAYER)))}pathToMoveClick(e,t){if(this.moveStrategy===Os.SMART)if(t){const{x:t,z:i}=ji.unpackCoord(e[0]);this.queueWaypoints(ti(this.level,this.x,this.z,t,i))}else this.queueWaypoints(e);else{const{x:t,z:i}=ji.unpackCoord(e[e.length-1]);this.queueWaypoint(t,i)}}pathToPathingTarget(){this.target&&this.target instanceof e&&this.isLastOrNoWaypoint()&&(this.targetOp!==cs.APPLAYER3&&this.targetOp!==cs.OPPLAYER3?this.pathToTarget():this.queueWaypoint(this.target.lastStepX,this.target.lastStepZ))}pathToTarget(){if(!this.target)return;this.targetX=this.target.x,this.targetZ=this.target.z;const t=2*this.target.x+this.target.width,i=2*this.target.z+this.target.length;if(this.orientationX=t,this.orientationZ=i,this.moveStrategy===Os.SMART)if(this.target instanceof e)this.queueWaypoints(ti(this.level,this.x,this.z,this.target.x,this.target.z,this.width,this.target.width,this.target.length,0,-2));else if(this.target instanceof ss){const e=at.get(this.target.type).forceapproach;this.queueWaypoints(ti(this.level,this.x,this.z,this.target.x,this.target.z,this.width,this.target.width,this.target.length,this.target.angle,this.target.shape,!0,e))}else this.queueWaypoints(ti(this.level,this.x,this.z,this.target.x,this.target.z));else if(this.moveStrategy===Os.NAIVE){const t=this.getCollisionStrategy();if(null===t)return;const i=this.blockWalkFlag();if(i===Ri.NULL)return;this.target instanceof e?this.queueWaypoints(ii(this.level,this.x,this.z,this.target.x,this.target.z,this.width,this.length,this.target.width,this.target.length,i,t)):this.queueWaypoint(this.target.x,this.target.z)}else{if(null===this.getCollisionStrategy())return;if(this.blockWalkFlag()===Ri.NULL)return;this.queueWaypoint(this.target.x,this.target.z)}}setInteraction(e,t,i,r){this.target=t,this.targetOp=i,this.targetSubject=r??{type:-1,com:-1},this.targetX=t.x,this.targetZ=t.z,this.apRange=10,this.apRangeCalled=!1;const s=2*t.x+t.width,n=2*t.z+t.length;if(this.orientationX=s,this.orientationZ=n,t instanceof Do){const e=t.pid+32768;this.faceEntity!==e&&(this.faceEntity=e,this.mask|=this.entitymask)}else if(t instanceof kl){const e=t.nid;this.faceEntity!==e&&(this.faceEntity=e,this.mask|=this.entitymask)}else this.faceX===s&&this.faceZ===n||(this.faceX=s,this.faceZ=n,this.mask|=this.coordmask);e===hs.SCRIPT&&this.pathToTarget()}clearInteraction(){this.target=null,this.targetOp=-1,this.targetSubject={type:-1,com:-1},this.targetX=-1,this.targetZ=-1,this.apRange=10,this.apRangeCalled=!1,this.alreadyFacedEntity=!0}getCollisionStrategy(){return this.moveRestrict===dt.NORMAL?Di.NORMAL:this.moveRestrict===dt.BLOCKED?Di.BLOCKED:this.moveRestrict===dt.BLOCKED_NORMAL?Di.LINE_OF_SIGHT:this.moveRestrict===dt.INDOORS?Di.INDOORS:this.moveRestrict===dt.OUTDOORS?Di.OUTDOORS:this.moveRestrict===dt.NOMOVE?null:this.moveRestrict===dt.PASSTHRU?Di.NORMAL:null}resetPathingEntity(){this.moveSpeed=this.defaultMoveSpeed(),this.walkDir=-1,this.runDir=-1,this.jump=!1,this.tele=!1,this.lastX=this.x,this.lastZ=this.z,this.lastLevel=this.level,this.stepsTaken=0,this.interacted=!1,this.apRangeCalled=!1,this.mask=0,this.exactStartX=-1,this.exactStartZ=-1,this.exactEndX=-1,this.exactEndZ=-1,this.exactMoveStart=-1,this.exactMoveEnd=-1,this.exactMoveDirection=-1,this.animId=-1,this.animDelay=-1,this.animId=-1,this.animDelay=-1,this.chat=null,this.damageTaken=-1,this.damageType=-1,this.graphicId=-1,this.graphicHeight=-1,this.graphicDelay=-1,this.alreadyFacedEntity&&!this.target&&-1!==this.faceEntity&&(this.mask|=this.entitymask,this.faceEntity=-1,this.alreadyFacedEntity=!1)}takeStep(){if(-1===this.waypointIndex)return null;const e=this.x,t=this.z,{x:i,z:r}=ji.unpackCoord(this.waypoints[this.waypointIndex]),s=ji.face(e,t,i,r),n=ji.deltaX(s),a=ji.deltaZ(s);if(0==n&&0==a)return-1;const o=this.getCollisionStrategy();if(null===o)return-1;const c=this.blockWalkFlag();return c===Ri.NULL?-1:this.moveStrategy===Os.FLY||pi(this.level,this.x,this.z,n,a,this.width,c,o)?s:0!=n&&pi(this.level,this.x,this.z,n,0,this.width,c,o)?ji.face(e,t,i,t):0!=a&&pi(this.level,this.x,this.z,0,a,this.width,c,o)?ji.face(e,t,e,r):null}},Ls=class{sentinel;cursor=null;constructor(){const e=new Ie;e.nextHashable=e,e.prevHashable=e,this.sentinel=e}push(e){e.prevHashable&&e.uncache(),e.prevHashable=this.sentinel.prevHashable,e.nextHashable=this.sentinel,e.prevHashable&&(e.prevHashable.nextHashable=e),e.nextHashable.prevHashable=e}pop(){const e=this.sentinel.nextHashable;return e===this.sentinel?null:(e?.uncache(),e)}head(){const e=this.sentinel.nextHashable;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.nextHashable||null,e)}next(){const e=this.cursor;return e===this.sentinel?(this.cursor=null,null):(this.cursor=e?.nextHashable||null,e)}clear(){for(;;){const e=this.sentinel.next;if(e==this.sentinel)return;e&&e.unlink()}}},Ps=new Map,ws=new Map;var bs=class extends Ie{},Rs=class e{static LOW=new e;static HIGH=new e},Bs=class extends bs{priority=Rs.LOW},Us=class extends bs{constructor(e){super(),this.uid=e}priority=Rs.HIGH},Ds=class extends bs{priority=Rs.HIGH},ks=class extends bs{priority=Rs.HIGH},Ms=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},xs=class extends bs{constructor(e){super(),this.component=e}priority=Rs.HIGH},Fs=class extends bs{constructor(e,t){super(),this.varp=e,this.value=t}priority=Rs.HIGH},Hs=class extends bs{constructor(e,t){super(),this.varp=e,this.value=t}priority=Rs.HIGH},Vs=class extends bs{constructor(e,t,i){super(),this.name=e,this.crc=t,this.length=i}priority=Rs.LOW},Gs=class extends bs{constructor(e,t){super(),this.delay=e,this.data=t}priority=Rs.LOW},Ws=class extends bs{constructor(e,t){super(),this.component=e,this.tab=t}priority=Rs.LOW},Ks=class extends bs{priority=Rs.HIGH},zs=class extends bs{constructor(e,t,i,r,s,n){super(),this.type=e,this.nid=t,this.pid=i,this.x=r,this.z=s,this.y=n}priority=Rs.LOW},js=class extends bs{constructor(e,t,i,r){super(),this.lastLoginIp=e,this.daysSinceLogin=t,this.daysSinceRecoveryChange=i,this.unreadMessageCount=r}priority=Rs.LOW},Ys=class extends bs{constructor(e){super(),this.msg=e}priority=Rs.HIGH},qs=class{type;receiverId;message;constructor(e,t,i){this.type=e,this.receiverId=t,this.message=i}},Qs=(e=>(e[e.ENCLOSED=0]='ENCLOSED',e[e.FOLLOWS=1]='FOLLOWS',e))(Qs||{}),$s=Qs,Zs=class extends bs{constructor(e,t,i,r,s){super(),this.zoneX=e,this.zoneZ=t,this.originX=i,this.originZ=r,this.data=s}priority=Rs.HIGH},Xs=class extends bs{constructor(e,t,i,r){super(),this.zoneX=e,this.zoneZ=t,this.originX=i,this.originZ=r}priority=Rs.HIGH},Js=class extends bs{constructor(e,t,i,r){super(),this.zoneX=e,this.zoneZ=t,this.originX=i,this.originZ=r}priority=Rs.HIGH},en=class extends bs{constructor(e){super(),this.coord=e}priority=Rs.HIGH},tn=class extends en{constructor(e,t,i){super(e),this.coord=e,this.obj=t,this.count=i}},rn=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.loc=t,this.shape=i,this.angle=r}},sn=class extends en{constructor(e,t,i){super(e),this.coord=e,this.shape=t,this.angle=i}},nn=class extends en{constructor(e,t,i,r,s,n,a,o,c,l,h,d){super(ji.packZoneCoord(e,t)),this.srcX=e,this.srcZ=t,this.dstX=i,this.dstZ=r,this.target=s,this.spotanim=n,this.srcHeight=a,this.dstHeight=o,this.startDelay=c,this.endDelay=l,this.peak=h,this.arc=d}},an=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.spotanim=t,this.height=i,this.delay=r}},on=class extends en{constructor(e,t){super(e),this.coord=e,this.obj=t}},cn=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.obj=t,this.oldCount=i,this.newCount=r}},ln=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.obj=t,this.count=i,this.receiverId=r}},hn=class extends en{constructor(e,t,i,r){super(e),this.coord=e,this.shape=t,this.angle=i,this.seq=r}},dn=class extends en{constructor(e,t,i,r,s,n,a,o,c,l,h,d){super(ji.packZoneCoord(e,t)),this.srcX=e,this.srcZ=t,this.shape=i,this.angle=r,this.locId=s,this.startCycle=n,this.endCycle=a,this.pid=o,this.east=c,this.south=l,this.west=h,this.north=d}},un=class{test(e){return this.prot.length}},pn=class extends un{prot=Ts.IF_OPENCHATMODAL;encode(e,t){e.p2(t.component)}},fn=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},gn=class extends bs{constructor(e,t,i,r,s,n,a,o,c,l,h,d,u,p,f){super(),this.buildArea=e,this.level=t,this.x=i,this.z=r,this.originX=s,this.originZ=n,this.uid=a,this.mask=o,this.tele=c,this.jump=l,this.walkDir=h,this.runDir=d,this.deltaX=u,this.deltaZ=p,this.changedLevel=f}priority=Rs.HIGH;accumulator=0},mn=class e extends un{static BITS_NEW=23;static BITS_IDLE=1;static BITS_RUN=10;static BITS_WALK=7;static BITS_EXTENDED=3;static BYTES_LIMIT=4997;prot=Ts.PLAYER_INFO;encode(e,t){const i=t.buildArea;t.changedLevel||t.deltaX>i.viewDistance||t.deltaZ>i.viewDistance?(i.players.clear(),i.lastResize=0,i.viewDistance=wo.PREFERRED_VIEW_DISTANCE):i.resize(),this.writeLocalPlayer(e,t),this.writePlayers(e,t),this.writeNewPlayers(e,t);const r=i.extendedInfo;if(r.size>0)for(const i of r){const r=Zl.getPlayerByUid(i.id);r?this.writeExtendedInfo(r,t,e,i.id===t.uid,i.added):e.p1(0)}i.clearExtended()}test(t){return e.BYTES_LIMIT}willFit(t,i,r,s){return(i.bitPos+r+7>>>3)+(t.accumulator+s)<=e.BYTES_LIMIT}writeLocalPlayer(e,t){const{buildArea:i,uid:r,level:s,x:n,z:a,tele:o,jump:c,walkDir:l,runDir:h}=t,d=Zl.getPlayerByUid(r);if(!d)return;const u=this.calculateExtendedInfo(d,t,!0,!1),p=u>0;e.bits(),e.pBit(1,o||-1!==h||-1!==l||p?1:0),o?(e.pBit(2,3),e.pBit(2,s),e.pBit(7,ji.local(n,d.originX)),e.pBit(7,ji.local(a,d.originZ)),e.pBit(1,c?1:0),e.pBit(1,p?1:0)):-1!==h?(e.pBit(2,2),e.pBit(3,l),e.pBit(3,h),e.pBit(1,p?1:0)):-1!==l?(e.pBit(2,1),e.pBit(3,l),e.pBit(1,p?1:0)):p&&e.pBit(2,0),p&&(i.extendedInfo.add({id:r,added:!1}),t.accumulator+=u)}writePlayers(t,i){const r=i.buildArea;t.pBit(8,r.players.size);for(const s of r.players){const n=Zl.getPlayerByUid(s);if(!n||n.tele||n.level!==i.level||!ji.isWithinDistanceSW(i,n,r.viewDistance)||!n.checkLifeCycle(Zl.currentTick)){t.pBit(1,1),t.pBit(2,3),r.players.delete(s);continue}const a=this.calculateExtendedInfo(n,i,!1,!1);let o=a>0;const{walkDir:c,runDir:l}=n;let h=e.BITS_IDLE;-1!==l?h=e.BITS_RUN:-1!==c?h=e.BITS_WALK:o&&(h=e.BITS_EXTENDED),this.willFit(i,t,h,a)||(o=!1),t.pBit(1,-1!==l||-1!==c||o?1:0),-1!==l?(t.pBit(2,2),t.pBit(3,c),t.pBit(3,l),t.pBit(1,o?1:0)):-1!==c?(t.pBit(2,1),t.pBit(3,c),t.pBit(1,o?1:0)):o&&t.pBit(2,0),o&&(r.extendedInfo.add({id:s,added:!1}),i.accumulator+=a)}}writeNewPlayers(t,i){const r=i.buildArea;for(const s of r.getNearbyPlayers(i.uid,i.x,i.z,i.originX,i.originZ)){const n=this.calculateExtendedInfo(s,i,!1,!0),a=n>0;if(!this.willFit(i,t,e.BITS_NEW+11,n))break;t.pBit(11,s.pid),t.pBit(5,s.x-i.x),t.pBit(5,s.z-i.z),t.pBit(1,s.jump?1:0),t.pBit(1,a?1:0),a&&(r.extendedInfo.add({id:s.uid,added:!0}),i.accumulator+=n),r.players.add(s.uid)}r.extendedInfo.size>0&&t.pBit(11,2047),t.bytes()}writeExtendedInfo(e,t,i,r=!1,s=!1){let n=e.mask;s&&(-1===e.orientationX&&-1===e.faceX||(n|=Do.FACE_COORD),-1!==e.faceEntity&&(n|=Do.FACE_ENTITY)),r&&n&Do.CHAT&&(n&=~Do.CHAT),t.buildArea.hasAppearance(e.uid,e.lastAppearance)||!e.appearance?n&=~Do.APPEARANCE:n|=Do.APPEARANCE,n>255&&(n|=Do.BIG_UPDATE),i.p1(255&n),n&Do.BIG_UPDATE&&i.p1(n>>8),n&Do.APPEARANCE&&(i.p1(e.appearance.length),i.pdata(e.appearance,0,e.appearance.length),t.buildArea.saveAppearance(e.uid,e.lastAppearance)),n&Do.ANIM&&(i.p2(e.animId),i.p1(e.animDelay)),n&Do.FACE_ENTITY&&(-1!==e.faceEntity&&(e.alreadyFacedEntity=!0),i.p2(e.faceEntity)),n&Do.SAY&&i.pjstr(e.chat??''),n&Do.DAMAGE&&(i.p1(e.damageTaken),i.p1(e.damageType),i.p1(e.levels[$i.HITPOINTS]),i.p1(e.baseLevels[$i.HITPOINTS])),n&Do.FACE_COORD&&(s&&-1!==e.orientationX?(i.p2(e.orientationX),i.p2(e.orientationZ)):(i.p2(e.faceX),i.p2(e.faceZ))),n&Do.CHAT&&(i.p1(e.messageColor),i.p1(e.messageEffect),i.p1(e.messageType),i.p1(e.message.length),i.pdata(e.message,0,e.message.length)),n&Do.SPOTANIM&&(i.p2(e.graphicId),i.p2(e.graphicHeight),i.p2(e.graphicDelay)),n&Do.EXACT_MOVE&&(i.p1(e.exactStartX-ji.zoneOrigin(t.originX)),i.p1(e.exactStartZ-ji.zoneOrigin(t.originZ)),i.p1(e.exactEndX-ji.zoneOrigin(t.originX)),i.p1(e.exactEndZ-ji.zoneOrigin(t.originZ)),i.p2(e.exactMoveStart),i.p2(e.exactMoveEnd),i.p1(e.exactMoveDirection))}calculateExtendedInfo(e,t,i=!1,r=!1){let s=0,n=e.mask;return r&&(-1===e.orientationX&&-1===e.faceX||(n|=Do.FACE_COORD),-1!==e.faceEntity&&(n|=Do.FACE_ENTITY)),i&&n&Do.CHAT&&(n&=~Do.CHAT),t.buildArea.hasAppearance(e.uid,e.lastAppearance)||!e.appearance?n&=~Do.APPEARANCE:n|=Do.APPEARANCE,n>255&&(n|=Do.BIG_UPDATE),0===n?0:(s+=1,n&Do.BIG_UPDATE&&(s+=1),n&Do.APPEARANCE&&(s+=1+e.appearance.length),n&Do.ANIM&&(s+=3),n&Do.FACE_ENTITY&&(s+=2),n&Do.SAY&&(s+=1+e.chat.length),n&Do.DAMAGE&&(s+=4),n&Do.FACE_COORD&&(s+=4),n&Do.CHAT&&(s+=4+e.message.length),n&Do.SPOTANIM&&(s+=6),n&Do.EXACT_MOVE&&(s+=9),s)}},yn=class extends bs{constructor(e,t){super(),this.zoneX=e,this.zoneZ=t}priority=Rs.HIGH;get mapsquares(){const e=this.zoneX-6,t=this.zoneX+6,i=this.zoneZ-6,r=this.zoneZ+6,s=new Set;for(let n=e;n<=t;n++){const e=ji.mapsquare(n<<3);for(let t=i;t<=r;t++){const i=ji.mapsquare(t<<3);s.add(e<<8|i)}}return s}},En=class extends un{prot=Ts.REBUILD_NORMAL;encode(e,t){e.p2(t.zoneX),e.p2(t.zoneZ);for(const i of t.mapsquares){const t=i>>8,r=255&i;e.p1(t),e.p1(r),e.p4(ws.get(`m${t}_${r}`)??0),e.p4(ws.get(`l${t}_${r}`)??0)}}test(e){return 4+10*e.mapsquares.size}},_n=class extends bs{constructor(e,t,i,r,s){super(),this.x=e,this.z=t,this.offset=i,this.length=r,this.data=s}priority=Rs.HIGH},An=class extends un{prot=Ts.DATA_LAND;encode(e,t){e.p1(t.x),e.p1(t.z),e.p2(t.offset),e.p2(t.length),e.pdata(t.data,0,t.data.length)}test(e){return 6+e.data.length}},vn=class extends bs{constructor(e,t){super(),this.x=e,this.z=t}priority=Rs.HIGH},Tn=class extends un{prot=Ts.DATA_LAND_DONE;encode(e,t){e.p1(t.x),e.p1(t.z)}},Cn=class extends bs{constructor(e,t,i,r,s){super(),this.x=e,this.z=t,this.offset=i,this.length=r,this.data=s}priority=Rs.HIGH},In=class extends un{prot=Ts.DATA_LOC;encode(e,t){e.p1(t.x),e.p1(t.z),e.p2(t.offset),e.p2(t.length),e.pdata(t.data,0,t.data.length)}test(e){return 6+e.data.length}},Sn=class extends bs{constructor(e,t){super(),this.x=e,this.z=t}priority=Rs.HIGH},On=class extends un{prot=Ts.DATA_LOC_DONE;encode(e,t){e.p1(t.x),e.p1(t.z)}},Nn=class extends bs{constructor(e,t,i,r,s){super(),this.x=e,this.z=t,this.height=i,this.speed=r,this.multiplier=s}priority=Rs.LOW},Ln=class extends un{prot=Ts.CAM_LOOKAT;encode(e,t){e.p1(t.x),e.p1(t.z),e.p2(t.height),e.p1(t.speed),e.p1(t.multiplier)}},Pn=class extends bs{constructor(e,t,i,r,s){super(),this.x=e,this.z=t,this.height=i,this.speed=r,this.multiplier=s}priority=Rs.LOW},wn=class extends un{prot=Ts.CAM_MOVETO;encode(e,t){e.p1(t.x),e.p1(t.z),e.p2(t.height),e.p1(t.speed),e.p1(t.multiplier)}},bn=class extends bs{priority=Rs.LOW},Rn=class extends un{prot=Ts.CAM_RESET;encode(e,t){}},Bn=class extends bs{constructor(e,t,i,r){super(),this.type=e,this.jitter=t,this.amplitude=i,this.frequency=r}priority=Rs.LOW},Un=class extends un{prot=Ts.CAM_SHAKE;encode(e,t){e.p1(t.type),e.p1(t.jitter),e.p1(t.amplitude),e.p1(t.frequency)}},Dn=class extends bs{constructor(e,t,i){super(),this.publicChat=e,this.privateChat=t,this.tradeDuel=i}priority=Rs.HIGH},kn=class extends un{prot=Ts.CHAT_FILTER_SETTINGS;encode(e,t){e.p1(t.publicChat),e.p1(t.privateChat),e.p1(t.tradeDuel)}},Mn=class extends bs{priority=Rs.LOW},xn=class extends un{prot=Ts.ENABLE_TRACKING;encode(e,t){}},Fn=class extends bs{priority=Rs.LOW},Hn=class extends un{prot=Ts.FINISH_TRACKING;encode(e,t){}},Vn=class extends un{prot=Ts.HINT_ARROW;encode(e,t){const{type:i,nid:r,pid:s,x:n,z:a,y:o}=t;1===i?(e.p1(i),e.p2(r),e.p2(0),e.p1(0)):i>=2&&i<=6?(e.p1(i),e.p2(n),e.p2(a),e.p1(o)):10===i?(e.p1(i),e.p2(s),e.p2(0),e.p1(0)):-1===i&&(e.p1(-1),e.p2(0),e.p2(0),e.p1(0))}},Gn=class extends un{prot=Ts.IF_CLOSE;encode(e,t){}},Wn=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},Kn=class extends un{prot=Ts.IF_OPENMAINMODAL;encode(e,t){e.p2(t.component)}},zn=class extends bs{constructor(e,t){super(),this.main=e,this.side=t}priority=Rs.LOW},jn=class extends un{prot=Ts.IF_OPENMAINSIDEMODAL;encode(e,t){e.p2(t.main),e.p2(t.side)}},Yn=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},qn=class extends un{prot=Ts.IF_OPENSIDEMODAL;encode(e,t){e.p2(t.component)}},Qn=class extends un{prot=Ts.IF_OPENSIDEOVERLAY;encode(e,t){e.p2(t.component),e.p1(t.tab)}},$n=class extends bs{constructor(e,t){super(),this.component=e,this.seq=t}priority=Rs.LOW},Zn=class extends un{prot=Ts.IF_SETANIM;encode(e,t){e.p2(t.component),e.p2(t.seq)}},Xn=class extends bs{constructor(e,t){super(),this.component=e,this.colour=t}priority=Rs.LOW},Jn=class extends un{prot=Ts.IF_SETCOLOUR;encode(e,t){e.p2(t.component),e.p2(t.colour)}},ea=class extends bs{constructor(e,t){super(),this.component=e,this.hidden=t}priority=Rs.LOW},ta=class extends un{prot=Ts.IF_SETHIDE;encode(e,t){e.p2(t.component),e.pbool(t.hidden)}},ia=class extends bs{constructor(e,t){super(),this.component=e,this.model=t}priority=Rs.LOW},ra=class extends un{prot=Ts.IF_SETMODEL;encode(e,t){e.p2(t.component),e.p2(t.model)}},sa=class extends bs{constructor(e,t){super(),this.component=e,this.npc=t}priority=Rs.LOW},na=class extends un{prot=Ts.IF_SETNPCHEAD;encode(e,t){e.p2(t.component),e.p2(t.npc)}},aa=class extends bs{constructor(e,t,i){super(),this.component=e,this.obj=t,this.scale=i}priority=Rs.LOW},oa=class extends un{prot=Ts.IF_SETOBJECT;encode(e,t){e.p2(t.component),e.p2(t.obj),e.p2(t.scale)}},ca=class extends bs{constructor(e){super(),this.component=e}priority=Rs.LOW},la=class extends un{prot=Ts.IF_SETPLAYERHEAD;encode(e,t){e.p2(t.component)}},ha=class extends bs{constructor(e,t,i){super(),this.component=e,this.x=t,this.y=i}priority=Rs.LOW},da=class extends un{prot=Ts.IF_SETPOSITION;encode(e,t){e.p2(t.component),e.p2(t.x),e.p2(t.y)}},ua=class extends bs{constructor(e,t,i){super(),this.component=e,this.src=t,this.dst=i}priority=Rs.LOW},pa=class extends un{prot=Ts.IF_SETRECOL;encode(e,t){e.p2(t.component),e.p2(t.src),e.p2(t.dst)}},fa=class extends bs{constructor(e,t){super(),this.component=e,this.text=t}priority=Rs.LOW},ga=class extends un{prot=Ts.IF_SETTEXT;encode(e,t){e.p2(t.component),e.pjstr(t.text)}test(e){return 3+e.text.length}},ma=class extends bs{constructor(e){super(),this.tab=e}priority=Rs.LOW},ya=class extends un{prot=Ts.IF_SHOWSIDE;encode(e,t){e.p1(t.tab)}},Ea=class extends un{prot=Ts.LAST_LOGIN_INFO;encode(e,t){e.p4(t.lastLoginIp),e.p2(t.daysSinceLogin),e.p1(t.daysSinceRecoveryChange),e.p2(t.unreadMessageCount)}},_a=class e extends Ts{static LOC_MERGE=new e(23,14);static LOC_ANIM=new e(42,4);static OBJ_DEL=new e(49,3);static OBJ_REVEAL=new e(50,7);static LOC_ADD_CHANGE=new e(59,4);static MAP_PROJANIM=new e(69,15);static LOC_DEL=new e(76,2);static OBJ_COUNT=new e(151,7);static MAP_ANIM=new e(191,6);static OBJ_ADD=new e(223,5)},Aa=class extends un{enclose(e){const t=new Oe(new Uint8Array(1+this.prot.length));return t.p1(this.prot.id),this.encode(t,e),t.data}},va=class extends Aa{prot=_a.LOC_ADD_CHANGE;encode(e,t){e.p1(t.coord),e.p1(t.shape<<2|3&t.angle),e.p2(t.loc)}},Ta=class extends Aa{prot=_a.LOC_ANIM;encode(e,t){e.p1(t.coord),e.p1(t.shape<<2|3&t.angle),e.p2(t.seq)}},Ca=class extends Aa{prot=_a.LOC_DEL;encode(e,t){e.p1(t.coord),e.p1(t.shape<<2|3&t.angle)}},Ia=class extends Aa{prot=_a.LOC_MERGE;encode(e,t){e.p1(t.coord),e.p1(t.shape<<2|3&t.angle),e.p2(t.locId),e.p2(t.startCycle),e.p2(t.endCycle),e.p2(t.pid),e.p1(t.east-t.srcX),e.p1(t.south-t.srcZ),e.p1(t.west-t.srcX),e.p1(t.north-t.srcZ)}},Sa=class extends bs{priority=Rs.HIGH},Oa=class extends un{prot=Ts.LOGOUT;encode(e,t){}},Na=class extends Aa{prot=_a.MAP_ANIM;encode(e,t){e.p1(t.coord),e.p2(t.spotanim),e.p1(t.height),e.p2(t.delay)}},La=class extends Aa{prot=_a.MAP_PROJANIM;encode(e,t){e.p1(t.coord),e.p1(t.dstX-t.srcX),e.p1(t.dstZ-t.srcZ),e.p2(t.target),e.p2(t.spotanim),e.p1(t.srcHeight),e.p1(t.dstHeight),e.p2(t.startDelay),e.p2(t.endDelay),e.p1(t.peak),e.p1(t.arc)}},Pa=class extends un{prot=Ts.MESSAGE_GAME;encode(e,t){e.pjstr(t.msg)}test(e){return 1+e.msg.length}},wa=class{static CHAR_LOOKUP=[" ","e","t","a","o","i","h","n","s","r","d","l","u","m","w","c","y","f","g","p","b","v","k","x","j","q","z","0","1","2","3","4","5","6","7","8","9"," ","!","?",".",",",":",";","(",")","-","&","*","\\","'","@","#","+","=","£","$","%",'"',"[","]"];static unpack(e,t){const i=[];let r,s=0,n=-1;for(let a=0;a>4&15,-1!==n?(i[s++]=this.CHAR_LOOKUP[(n<<4)+r-195],n=-1):r<13?i[s++]=this.CHAR_LOOKUP[r]:n=r,r=15&t,-1!=n?(i[s++]=this.CHAR_LOOKUP[(n<<4)+r-195],n=-1):r<13?i[s++]=this.CHAR_LOOKUP[r]:n=r}return this.toSentenceCase(i.slice(0,s).join(''))}static pack(e,t){t.length>80&&(t=t.substring(0,80)),t=t.toLowerCase();let i=-1;for(let r=0;r12&&(n+=195),-1==i?n<13?i=n:e.p1(n):n<13?(e.p1((i<<4)+n),i=-1):(e.p1((i<<4)+(n>>4)),i=15&n)}-1!=i&&e.p1(i<<4)}static toSentenceCase(e){const t=[...e.toLowerCase()];let i=!0;for(let e=0;e='a'&&r<='z'&&(t[e]=r.toUpperCase(),i=!1),'.'!==r&&'!'!==r||(i=!0)}return t.join('')}},ba=class extends un{prot=Ts.MESSAGE_PRIVATE;encode(e,t){e.p8(t.from),e.p4(t.messageId),e.p1(t.staffModLevel),wa.pack(e,Bt.filter(t.msg))}test(e){return 14+e.msg.length}},Ra=class extends bs{constructor(e,t,i,r){super(),this.from=e,this.messageId=t,this.staffModLevel=i,this.msg=r}priority=Rs.HIGH},Ba=class extends un{prot=Ts.MIDI_JINGLE;encode(e,t){e.p2(t.delay),e.p4(t.data.length),e.pdata(t.data,0,t.data.length)}test(e){return 6+e.data.length}},Ua=class extends un{prot=Ts.MIDI_SONG;encode(e,t){e.pjstr(t.name),e.p4(t.crc),e.p4(t.length)}test(e){return 1+e.name.length+4+4}},Da=class extends Aa{prot=_a.OBJ_ADD;encode(e,t){e.p1(t.coord),e.p2(t.obj),e.p2(Math.min(t.count,65535))}},ka=class extends Aa{prot=_a.OBJ_COUNT;encode(e,t){e.p1(t.coord),e.p2(t.obj),e.p2(Math.min(t.oldCount,65535)),e.p2(Math.min(t.newCount,65535))}},Ma=class extends Aa{prot=_a.OBJ_DEL;encode(e,t){e.p1(t.coord),e.p2(t.obj)}},xa=class extends Aa{prot=_a.OBJ_REVEAL;encode(e,t){e.p1(t.coord),e.p2(t.obj),e.p2(Math.min(t.count,65535)),e.p2(t.receiverId)}},Fa=class extends bs{priority=Rs.LOW},Ha=class extends un{prot=Ts.P_COUNTDIALOG;encode(e,t){}},Va=class extends un{prot=Ts.RESET_ANIMS;encode(e,t){}},Ga=class extends un{prot=Ts.RESET_CLIENT_VARCACHE;encode(e,t){}},Wa=class extends bs{constructor(e){super(),this.hidden=e}priority=Rs.LOW},Ka=class extends un{prot=Ts.SET_MULTIWAY;encode(e,t){e.pbool(t.hidden)}},za=class extends bs{constructor(e,t,i){super(),this.synth=e,this.loops=t,this.delay=i}priority=Rs.LOW},ja=class extends un{prot=Ts.SYNTH_SOUND;encode(e,t){e.p2(t.synth),e.p1(t.loops),e.p2(t.delay)}},Ya=class extends bs{constructor(e){super(),this.tab=e}priority=Rs.LOW},qa=class extends un{prot=Ts.TUTORIAL_FLASHSIDE;encode(e,t){e.p1(t.tab)}},Qa=class extends un{prot=Ts.TUTORIAL_OPENCHAT;encode(e,t){e.p2(t.component)}},$a=class extends un{prot=Ts.UNSET_MAP_FLAG;encode(e,t){}},Za=class extends bs{constructor(e,t){super(),this.name=e,this.nodeId=t}priority=Rs.LOW},Xa=class extends un{prot=Ts.UPDATE_FRIENDLIST;encode(e,t){e.p8(t.name),e.p1(t.nodeId)}},Ja=class extends bs{constructor(e){super(),this.names=e}priority=Rs.LOW},eo=class extends un{prot=Ts.UPDATE_IGNORELIST;encode(e,t){for(const i of t.names)e.p8(i)}test(e){return 8*e.names.length}},to=class extends bs{constructor(e,t){super(),this.component=e,this.inv=t}priority=Rs.HIGH},io=class extends un{prot=Ts.UPDATE_INV_FULL;encode(e,t){const{component:i,inv:r}=t,s=tt.get(i),n=Math.min(r.capacity,s.width*s.height);e.p2(i),e.p1(n);for(let t=0;t=255?(e.p1(255),e.p4(i.count)):e.p1(i.count)):(e.p2(0),e.p1(0))}}test(e){const{component:t,inv:i}=e,r=tt.get(t),s=Math.min(i.capacity,r.width*r.height);let n=0;n+=3;for(let e=0;e=255?n+=5:n+=1):n+=3}return n}},ro=class extends bs{constructor(e,t,...i){super(),this.component=e,this.inv=t,this.slots=i}priority=Rs.HIGH;slots},so=class extends un{prot=Ts.UPDATE_INV_PARTIAL;encode(e,t){const{component:i,inv:r}=t;e.p2(i);for(const i of t.slots){const t=r.get(i);e.p1(i),t?(e.p2(t.id+1),t.count>=255?(e.p1(255),e.p4(t.count)):e.p1(t.count)):(e.p2(0),e.p1(0))}}test(e){const{inv:t}=e;let i=0;i+=2;for(const r of e.slots){const e=t.get(r);i+=1,e?(i+=2,e.count>=255?i+=5:i+=1):i+=3}return i}},no=class extends un{prot=Ts.UPDATE_INV_STOP_TRANSMIT;encode(e,t){e.p2(t.component)}},ao=class extends bs{constructor(e){super(),this.energy=e}priority=Rs.LOW},oo=class extends un{prot=Ts.UPDATE_RUNENERGY;encode(e,t){e.p1(t.energy/100|0)}},co=class extends bs{constructor(e){super(),this.kg=e}priority=Rs.LOW},lo=class extends un{prot=Ts.UPDATE_RUNWEIGHT;encode(e,t){e.p2(t.kg)}},ho=class extends bs{constructor(e,t,i){super(),this.stat=e,this.exp=t,this.level=i}priority=Rs.LOW},uo=class extends un{prot=Ts.UPDATE_STAT;encode(e,t){e.p1(t.stat),e.p4(t.exp/10|0),e.p1(t.level)}},po=class extends un{prot=Ts.UPDATE_UID192;encode(e,t){e.p2(t.uid)}},fo=class extends un{prot=Ts.UPDATE_ZONE_FULL_FOLLOWS;encode(e,t){e.p1((t.zoneX<<3)-ji.zoneOrigin(t.originX)),e.p1((t.zoneZ<<3)-ji.zoneOrigin(t.originZ))}},go=class extends un{prot=Ts.UPDATE_ZONE_PARTIAL_FOLLOWS;encode(e,t){e.p1((t.zoneX<<3)-ji.zoneOrigin(t.originX)),e.p1((t.zoneZ<<3)-ji.zoneOrigin(t.originZ))}},mo=class extends un{prot=Ts.UPDATE_ZONE_PARTIAL_ENCLOSED;encode(e,t){e.p1((t.zoneX<<3)-ji.zoneOrigin(t.originX)),e.p1((t.zoneZ<<3)-ji.zoneOrigin(t.originZ)),e.pdata(t.data,0,t.data.length)}test(e){return 2+e.data.length}},yo=class extends un{prot=Ts.VARP_LARGE;encode(e,t){e.p2(t.varp),e.p4(t.value)}},Eo=class extends un{prot=Ts.VARP_SMALL;encode(e,t){e.p2(t.varp),e.p1(t.value)}},_o=class extends bs{constructor(e,t,i,r,s,n,a,o,c){super(),this.buildArea=e,this.level=t,this.x=i,this.z=r,this.originX=s,this.originZ=n,this.deltaX=a,this.deltaZ=o,this.changedLevel=c}priority=Rs.HIGH;accumulator=0},Ao=class e extends un{static BITS_NEW=35;static BITS_IDLE=1;static BITS_RUN=10;static BITS_WALK=7;static BITS_EXTENDED=3;static BYTES_LIMIT=4997;prot=Ts.NPC_INFO;encode(e,t){const i=t.buildArea;(t.changedLevel||t.deltaX>i.viewDistance||t.deltaZ>i.viewDistance)&&i.npcs.clear(),this.writeNpcs(e,t),this.writeNewNpcs(e,t);const r=i.extendedInfo;if(r.size>0)for(const t of r){const i=Zl.getNpc(t.id);i?this.writeExtendedInfo(i,e,t.added):e.p1(0)}i.clearExtended()}test(t){return e.BYTES_LIMIT}willFit(t,i,r,s){return(i.bitPos+r+7>>>3)+(t.accumulator+s)<=e.BYTES_LIMIT}writeNpcs(t,i){const r=i.buildArea;t.bits(),t.pBit(8,r.npcs.size);for(const s of r.npcs){const n=Zl.getNpc(s);if(!n||n.tele||n.level!==i.level||!ji.isWithinDistanceSW(i,n,15)||!n.checkLifeCycle(Zl.currentTick)){t.pBit(1,1),t.pBit(2,3),r.npcs.delete(s);continue}const a=this.calculateExtendedInfo(n,!1);let o=a>0;const{walkDir:c,runDir:l}=n;let h=e.BITS_IDLE;-1!==l?h=e.BITS_RUN:-1!==c?h=e.BITS_WALK:o&&(h=e.BITS_EXTENDED),this.willFit(i,t,h,a)||(o=!1),t.pBit(1,-1!==l||-1!==c||o?1:0),-1!==l?(t.pBit(2,2),t.pBit(3,c),t.pBit(3,l),t.pBit(1,o?1:0)):-1!==c?(t.pBit(2,1),t.pBit(3,c),t.pBit(1,o?1:0)):o&&t.pBit(2,0),o&&(r.extendedInfo.add({id:s,added:!1}),i.accumulator+=a)}}writeNewNpcs(t,i){const r=i.buildArea;for(const s of r.getNearbyNpcs(i.x,i.z,i.originX,i.originZ)){const n=this.calculateExtendedInfo(s,!0),a=n>0;if(!this.willFit(i,t,e.BITS_NEW+13,n))break;t.pBit(13,s.nid),t.pBit(11,s.type),t.pBit(5,s.x-i.x),t.pBit(5,s.z-i.z),t.pBit(1,a?1:0),a&&(r.extendedInfo.add({id:s.nid,added:!0}),i.accumulator+=n),r.npcs.add(s.nid)}r.extendedInfo.size>0&&t.pBit(13,8191),t.bytes()}writeExtendedInfo(e,t,i){let r=e.mask;i&&(-1===e.orientationX&&-1===e.faceX||(r|=kl.FACE_COORD),-1!==e.faceEntity&&(r|=kl.FACE_ENTITY)),t.p1(r),r&kl.ANIM&&(t.p2(e.animId),t.p1(e.animDelay)),r&kl.FACE_ENTITY&&(-1!==e.faceEntity&&(e.alreadyFacedEntity=!0),t.p2(e.faceEntity)),r&kl.SAY&&t.pjstr(e.chat??''),r&kl.DAMAGE&&(t.p1(e.damageTaken),t.p1(e.damageType),t.p1(e.levels[pt.HITPOINTS]),t.p1(e.baseLevels[pt.HITPOINTS])),r&kl.CHANGE_TYPE&&t.p2(e.type),r&kl.SPOTANIM&&(t.p2(e.graphicId),t.p2(e.graphicHeight),t.p2(e.graphicDelay)),r&kl.FACE_COORD&&(i&&-1!=e.orientationX?(t.p2(e.orientationX),t.p2(e.orientationZ)):(t.p2(e.faceX),t.p2(e.faceZ)))}calculateExtendedInfo(e,t){let i=0,r=e.mask;return t&&(-1===e.orientationX&&-1===e.faceX||(r|=kl.FACE_COORD),-1!==e.faceEntity&&(r|=kl.FACE_ENTITY)),0===r?0:(i+=1,r&kl.ANIM&&(i+=3),r&kl.FACE_ENTITY&&(i+=2),r&kl.SAY&&(i+=1+e.chat.length),r&kl.DAMAGE&&(i+=4),r&kl.CHANGE_TYPE&&(i+=2),r&kl.SPOTANIM&&(i+=6),r&kl.FACE_COORD&&(i+=4),i)}},vo=class extends bs{constructor(e){super(),this.ticks=e}priority=Rs.LOW},To=class extends un{prot=Ts.UPDATE_REBOOT_TIMER;encode(e,t){e.p2(t.ticks)}},Co=new class{encoders=new Map;bind(e,t){if(this.encoders.has(e))throw new Error(`[ServerProtRepository] Already defines a ${e.name}.`);this.encoders.set(e,t)}constructor(){this.bind(Nn,new Ln),this.bind(Pn,new wn),this.bind(bn,new Rn),this.bind(Bn,new Un),this.bind(Dn,new kn),this.bind(_n,new An),this.bind(vn,new Tn),this.bind(Cn,new In),this.bind(Sn,new On),this.bind(Mn,new xn),this.bind(Fn,new Hn),this.bind(zs,new Vn),this.bind(Bs,new Gn),this.bind(fn,new pn),this.bind(Wn,new Kn),this.bind(zn,new jn),this.bind(Yn,new qn),this.bind(Ws,new Qn),this.bind($n,new Zn),this.bind(Xn,new Jn),this.bind(ea,new ta),this.bind(ia,new ra),this.bind(sa,new na),this.bind(aa,new oa),this.bind(ca,new la),this.bind(ha,new da),this.bind(ua,new pa),this.bind(fa,new ga),this.bind(ma,new ya),this.bind(js,new Ea),this.bind(rn,new va),this.bind(hn,new Ta),this.bind(sn,new Ca),this.bind(dn,new Ia),this.bind(Sa,new Oa),this.bind(an,new Na),this.bind(nn,new La),this.bind(Ys,new Pa),this.bind(Ra,new ba),this.bind(Gs,new Ba),this.bind(Vs,new Ua),this.bind(_o,new Ao),this.bind(tn,new Da),this.bind(cn,new ka),this.bind(on,new Ma),this.bind(ln,new xa),this.bind(Fa,new Ha),this.bind(gn,new mn),this.bind(yn,new En),this.bind(Ds,new Va),this.bind(ks,new Ga),this.bind(Wa,new Ka),this.bind(za,new ja),this.bind(Ya,new qa),this.bind(Ms,new Qa),this.bind(Ks,new $a),this.bind(Za,new Xa),this.bind(Ja,new eo),this.bind(to,new io),this.bind(ro,new so),this.bind(xs,new no),this.bind(ao,new oo),this.bind(co,new lo),this.bind(vo,new To),this.bind(ho,new uo),this.bind(Us,new po),this.bind(Xs,new fo),this.bind(Zs,new mo),this.bind(Js,new go),this.bind(Hs,new yo),this.bind(Fs,new Eo)}getEncoder(e){return this.encoders.get(e.constructor)}getZoneEncoder(e){return this.encoders.get(e.constructor)}},Io=class extends Array{capacity;onFilled;constructor(e,t){super(),this.capacity=e,this.onFilled=t}*stack(e){const t=this[e];if(void 0!==t)for(let e=0;e=0;e--)yield i[e];else for(let e=0;er&&(r=t,i=e)}return i}nextBottomAll(){let e,t=Number.POSITIVE_INFINITY;for(let i=0;ir&&(r=s,i=e)}return i}nextBottomAll(){let e,t=Number.POSITIVE_INFINITY;for(let i=0;i>3,this.z=i.z>>3,this.level=i.level,this.events=new Set,this.players=new Set,this.npcs=new Set,this.locs=new So(e.LOCS,(e=>Zl.removeLoc(e,100))),this.objs=new Oo(e.OBJS,(e=>Zl.removeObj(e,100))),this.entityEvents=new Map}enter(e){e instanceof Do?(this.players.add(e.uid),Zl.getZoneGrid(this.level).flag(this.x,this.z)):e instanceof kl&&this.npcs.add(e.nid)}leave(e){e instanceof Do?(this.players.delete(e.uid),0===this.players.size&&Zl.getZoneGrid(this.level).unflag(this.x,this.z)):e instanceof kl&&this.npcs.delete(e.nid)}tick(e){let t;do{t=!1;for(const i of this.getAllObjsUnsafe())i.updateLifeCycle(e)&&i.lastLifecycleTick!==e&&(i.lifecycle===Yr.DESPAWN?-1!==i.receiverId?Zl.revealObj(i):(Zl.removeObj(i,0),t=!0):i.lifecycle===Yr.RESPAWN&&(Zl.addObj(i,-1,0),t=!0));for(const i of this.getAllLocsUnsafe())i.updateLifeCycle(e)&&i.lastLifecycleTick!==e&&(i.lifecycle===Yr.DESPAWN?(Zl.removeLoc(i,0),t=!0):i.lifecycle===Yr.RESPAWN&&(Zl.addLoc(i,0),t=!0))}while(t)}computeShared(){this.shared=null;let e=0;const t=[];for(const i of this.events.values()){if(i.type!==$s.ENCLOSED)continue;const r=Co.getZoneEncoder(i.message);if(void 0===r)continue;const s=r.enclose(i.message);t.push(s),e+=s.length}if(0===t.length||0===e)return;const i=new Uint8Array(e);let r=0;for(const e of t)i.set(e,r),r+=e.length;this.shared=i}writeFullFollows(e){e.write(new Xs(this.x,this.z,e.originX,e.originZ));for(const t of this.getAllObjsUnsafe(!0))-1!==t.receiverId&&t.receiverId!==e.pid||(e.write(new Js(this.x,this.z,e.originX,e.originZ)),(t.lifecycle===Yr.DESPAWN&&t.checkLifeCycle(Zl.currentTick)||t.lifecycle===Yr.RESPAWN&&t.checkLifeCycle(Zl.currentTick))&&e.write(new tn(ji.packZoneCoord(t.x,t.z),t.type,t.count)));for(const t of this.getAllLocsUnsafe(!0))t.lifecycle===Yr.DESPAWN&&t.checkLifeCycle(Zl.currentTick)?e.write(new rn(ji.packZoneCoord(t.x,t.z),t.type,t.shape,t.angle)):t.lifecycle!==Yr.RESPAWN||t.checkLifeCycle(Zl.currentTick)||e.write(new sn(ji.packZoneCoord(t.x,t.z),t.shape,t.angle))}writePartialEncloses(e){this.shared&&e.write(new Zs(this.x,this.z,e.originX,e.originZ,this.shared))}writePartialFollows(e){if(0!==this.events.size){e.write(new Js(this.x,this.z,e.originX,e.originZ));for(const t of this.events)t.type===$s.FOLLOWS&&(-1!==t.receiverId&&t.receiverId!==e.pid||e.write(t.message))}}reset(){this.events.clear(),this.entityEvents.clear()}addStaticLoc(e){const t=ji.packZoneCoord(e.x,e.z);this.locs.addLast(t,e,!0),this.totalLocs++,this.locs.sortStack(t,!0)}addStaticObj(e){const t=ji.packZoneCoord(e.x,e.z);this.objs.addLast(t,e,!0),this.totalObjs++,this.objs.sortStack(t,!0)}appendEvent(e,t){this.events.add(t);const i=this.entityEvents.get(e);void 0!==i?this.entityEvents.set(e,i.concat(t)):this.entityEvents.set(e,[t])}addLoc(e){const t=ji.packZoneCoord(e.x,e.z);e.lifecycle===Yr.DESPAWN&&(this.locs.addLast(t,e),this.totalLocs++),this.locs.sortStack(t),this.appendEvent(e,new qs($s.ENCLOSED,-1,new rn(t,e.type,e.shape,e.angle)))}removeLoc(e){const t=ji.packZoneCoord(e.x,e.z);e.lifecycle===Yr.DESPAWN&&(this.locs.remove(t,e),this.totalLocs--),this.locs.sortStack(t);const i=this.entityEvents.get(e);if(void 0!==i){for(let e=0;e>this.INT_BITS);grid;constructor(t=e.DEFAULT_GRID_SIZE){this.grid=new Int32Array(t)}index(t,i){return t<>>e.INT_BITS}flag(t,i){this.grid[this.index(t,i)]|=1<<(i&e.INT_BITS_FLAG)}unflag(t,i){this.grid[this.index(t,i)]&=~(1<<(i&e.INT_BITS_FLAG))}isFlagged(t,i,r){const s=Math.max(0,t-r),n=Math.min(e.GRID_SIZE-1,t+r),a=Math.max(0,i-r),o=Math.min(e.GRID_SIZE-1,i+r),c=e.INT_BITS_FLAG,l=a&~c,h=o>>>e.INT_BITS<o&&(s=r&(1<>>a-t),0!==n)return!0}return!1}},Po=class e{static zoneIndex(e,t,i){return e>>3&2047|(t>>3&2047)<<11|(3&i)<<22}static unpackIndex(e){return{x:(2047&e)<<3,z:(e>>11&2047)<<3,level:e>>22}}zones;grids;constructor(){this.zones=new Map,this.grids=new Map}zone(t,i,r){const s=e.zoneIndex(t,i,r);let n=this.zones.get(s);return void 0===n&&(n=new No(s),this.zones.set(s,n)),n}zoneByIndex(e){let t=this.zones.get(e);return void 0===t&&(t=new No(e),this.zones.set(e,t)),t}grid(e){let t=this.grids.get(e);return void 0===t&&(t=new Lo,this.grids.set(e,t)),t}zoneCount(){return this.zones.size}locCount(){let e=0;for(const t of this.zones.values())e+=t.totalLocs;return e}objCount(){let e=0;for(const t of this.zones.values())e+=t.totalObjs;return e}},wo=class e{static INTERVAL=10;static PREFERRED_PLAYERS=250;static PREFERRED_NPCS=255;static PREFERRED_VIEW_DISTANCE=15;npcs;players;loadedZones;activeZones;extendedInfo;appearances;forceViewDistance=!1;viewDistance=e.PREFERRED_VIEW_DISTANCE;lastResize=0;constructor(){this.npcs=new Set,this.players=new Set,this.loadedZones=new Set,this.activeZones=new Set,this.extendedInfo=new Set,this.appearances=new Map}resize(){if(!this.forceViewDistance)return this.players.size>=e.PREFERRED_PLAYERS?(this.viewDistance>1&&this.viewDistance--,void(this.lastResize=0)):void(++this.lastResize>=e.INTERVAL&&(this.viewDistance=e.PREFERRED_PLAYERS)break e;this.players.has(o.uid)||o.uid!==t&&(yield o)}}*getNearbyNpcs(t,i,r,s){e:for(const n of this.proximitySort(t,i,this.activeZones))for(const a of this.getNearby(Zl.getZoneIndex(n).getAllNpcsSafe(),t,i,r,s,15)){if(this.npcs.size>=e.PREFERRED_NPCS)break e;this.npcs.has(a.nid)||(yield a)}}*getNearby(e,t,i,r,s,n){const a=r-48,o=r+48,c=s+48,l=s-48;for(const r of e)r.x<=a||r.x>=o||r.z>=c||r.z<=l||ji.isWithinDistanceSW({x:t,z:i},r,n)&&(yield r)}proximitySort(e,t,i){return Array.from(i.values()).map((i=>this.zoneToDistance(i,e,t))).sort(((e,t)=>e.distance-t.distance)).map((({zoneIndex:e})=>e))}zoneToDistance(e,t,i){const r=Po.unpackIndex(e);return{zoneIndex:e,distance:Math.abs(r.x-t)+Math.abs(r.z-i)}}},bo=new Int32Array(99),Ro=0;for(let e=0;e<99;e++){const t=e+1;Ro+=Math.floor(t+300*Math.pow(2,t/7)),bo[e]=10*Math.floor(Ro/4)}function Bo(e){for(let t=98;t>=0;t--)if(e>=bo[t])return Math.min(t+2,99);return 1}function Uo(e){return bo[e-2]}var Do=class e extends Ns{static APPEARANCE=1;static ANIM=2;static FACE_ENTITY=4;static SAY=8;static DAMAGE=16;static FACE_COORD=32;static CHAT=64;static BIG_UPDATE=128;static SPOTANIM=256;static EXACT_MOVE=512;static SKILLS=['attack','defence','strength','hitpoints','ranged','prayer','magic','cooking','woodcutting','fletching','fishing','firemaking','crafting','smithing','mining','herblore','agility','thieving','stat18','stat19','runecraft'];static DESIGN_BODY_COLORS=[[6798,107,10283,16,4797,7744,5799,4634,33697,22433,2983,54193],[8741,12,64030,43162,7735,8404,1701,38430,24094,10153,56621,4783,1341,16578,35003,25239],[25238,8742,12,64030,43162,7735,8404,1701,38430,24094,10153,56621,4783,1341,16578,35003],[4626,11146,6439,12,4758,10270],[4550,4537,5681,5673,5790,6806,8076,4574]];save(){const e=Oe.alloc(1);e.p2(8196),e.p2(3),e.p2(this.x),e.p2(this.z),e.p1(this.level);for(let t=0;t<7;t++)e.p1(this.body[t]);for(let t=0;t<5;t++)e.p1(this.colors[t]);e.p1(this.gender),e.p2(this.runenergy),e.p4(this.playtime);for(let t=0;t<21;t++)e.p4(this.stats[t]),e.p1(this.levels[t]);e.p2(this.vars.length);for(let t=0;t=255?(e.p1(255),e.p4(i.count)):e.p1(i.count)):e.p2(0)}t++}}e.data[i]=t,e.p1(this.afkZones.length);for(let t=0;tt&&t.uid===e));if(-1!==i)return void(this.heroPoints[i].points+=t);const r=this.heroPoints.findIndex((e=>e&&-1===e.uid));-1===r||(this.heroPoints[r]={uid:e,points:t})}findHero(){return this.heroPoints.sort(((e,t)=>t.points-e.points)),this.heroPoints[0]?.uid??-1}resetEntity(e){e&&(this.faceX=-1,this.faceZ=-1,this.orientationX=-1,this.orientationZ=-1),super.resetPathingEntity(),this.repathed=!1,this.protect=!1,this.messageColor=null,this.messageEffect=null,this.messageType=null,this.message=null}onLogin(){this.playerLog('Logging in'),this.write(new Bs),this.write(new Us(this.pid)),this.unsetMapFlag(),this.write(new Ds),this.resetHeroPoints(),this.write(new ks);for(let e=0;e1){const e=Math.floor(this.runweight/1e3),t=67+67*Math.min(Math.max(e,0),64)/64|0;this.runenergy=Math.max(this.runenergy-t,0)}}recoverEnergy(e){if(!this.delayed()&&(!e||this.moveSpeed!==Is.RUN)&&this.runenergy<1e4){const e=8+(this.baseLevels[$i.AGILITY]/9|0);this.runenergy=Math.min(this.runenergy+e,1e4)}}blockWalkFlag(){return Ri.PLAYER}defaultMoveSpeed(){return this.getVar(Nt.PLAYER_RUN)?Is.RUN:Is.WALK}closeSticky(){if(-1!==this.modalSticky){const e=jt.getByTrigger(cs.IF_CLOSE,this.modalSticky);e&&this.enqueueScript(e,1),this.modalSticky=-1,this.write(new Ms(-1))}}closeModal(){if(this.receivedFirstClose){if(this.weakQueue.clear(),this.delayed()||(this.protect=!1),0!==this.modalState){if(-1!==this.modalTop){const e=jt.getByTrigger(cs.IF_CLOSE,this.modalTop);e&&this.enqueueScript(e,1),this.modalTop=-1}if(-1!==this.modalBottom){const e=jt.getByTrigger(cs.IF_CLOSE,this.modalBottom);e&&this.enqueueScript(e,1),this.modalBottom=-1}if(-1!==this.modalSidebar){const e=jt.getByTrigger(cs.IF_CLOSE,this.modalSidebar);e&&this.enqueueScript(e,1),this.modalSidebar=-1}this.modalState=0,this.refreshModalClose=!0}}else this.receivedFirstClose=!0}delayed(){return this.delay>Zl.currentTick}containsModalInterface(){return!(1&~this.modalState&&2&~this.modalState&&16&~this.modalState)}busy(){return this.delayed()||this.containsModalInterface()}canAccess(){return!this.protect&&!this.busy()}enqueueScript(e,t=0,i=0,r=[]){const s=new As(t,e,r,i);1===t?(s.delay=0,this.engineQueue.addTail(s)):2===t?this.weakQueue.addTail(s):this.queue.addTail(s)}processQueues(){let e=!1;for(let t=this.queue.head();null!==t;t=this.queue.next())if(3===t.type){e=!0;break}e&&this.closeModal(),this.processQueue(),this.processWeakQueue()}processQueue(){for(let e=this.queue.head();null!==e;e=this.queue.next()){3===e.type&&this.closeModal();const t=e.delay--;if(this.canAccess()&&t<=0){const t=Dl.init(e.script,this,null,e.args);this.executeScript(t,!0),e.unlink()}}}processWeakQueue(){for(let e=this.weakQueue.head();null!==e;e=this.weakQueue.next()){const t=e.delay--;if(this.canAccess()&&t<=0){const t=Dl.init(e.script,this,null,e.args);this.executeScript(t,!0),e.unlink()}}}setTimer(e,t,i=[],r){const s=t.id,n={type:e,script:t,args:i,interval:r,clock:r};this.timers.set(s,n)}clearTimer(e){this.timers.delete(e)}processTimers(e){for(const t of this.timers.values())if(e===t.type&&--t.clock<=0&&(1===t.type||this.canAccess())){t.clock=t.interval;const e=Dl.init(t.script,this,null,t.args);this.runScript(e,0===t.type)}}stopAction(){this.clearPendingAction(),this.unsetMapFlag()}clearPendingAction(){this.clearInteraction(),this.closeModal()}hasInteraction(){return null!==this.target}getOpTrigger(){if(!this.target)return null;let e=-1,t=-1;if(this.target instanceof kl||this.target instanceof ss||this.target instanceof $r){const i=this.target instanceof kl?ft.get(this.target.type):this.target instanceof ss?at.get(this.target.type):Tt.get(this.target.type);e=i.id,t=i.category}return-1!==this.targetSubject.type&&(e=this.targetSubject.type),-1!==this.targetSubject.com&&(e=this.targetSubject.com),jt.getByTrigger(this.targetOp+7,e,t)??null}getApTrigger(){if(!this.target)return null;let e=-1,t=-1;if(this.target instanceof kl||this.target instanceof ss||this.target instanceof $r){const i=this.target instanceof kl?ft.get(this.target.type):this.target instanceof ss?at.get(this.target.type):Tt.get(this.target.type);e=i.id,t=i.category}return-1!==this.targetSubject.type&&(e=this.targetSubject.type),-1!==this.targetSubject.com&&(e=this.targetSubject.com),jt.getByTrigger(this.targetOp,e,t)??null}processInteraction(){if(null===this.target||!this.canAccess())return void this.updateMovement();if(this.target.level!==this.level)return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof kl&&(void 0===Zl.getNpc(this.target.nid)||this.target.delayed()))return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof kl&&-1!==this.targetSubject.type&&null===Zl.getNpcByUid(this.targetSubject.type<<16|this.target.nid))return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof $r&&null===Zl.getObj(this.target.x,this.target.z,this.level,this.target.type,this.pid))return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof ss&&null===Zl.getLoc(this.target.x,this.target.z,this.level,this.target.type))return this.clearInteraction(),void this.unsetMapFlag();if(this.target instanceof e&&null===Zl.getPlayerByUid(this.target.uid))return this.clearInteraction(),void this.unsetMapFlag();if(this.targetOp===cs.APPLAYER3||this.targetOp===cs.OPPLAYER3){return void(this.updateMovement(!1)&&(this.alreadyFacedEntity=!1,this.lastMovement=Zl.currentTick+1))}const t=this.getOpTrigger(),i=this.getApTrigger();if(t&&this.target instanceof Ns&&this.inOperableDistance(this.target)){const e=this.target;this.target=null,this.executeScript(Dl.init(t,this,e),!0),null===this.target&&this.unsetMapFlag(),this.interacted=!0,this.clearWaypoints()}else if(i&&this.inApproachDistance(this.apRange,this.target)){const e=this.target;this.target=null,this.executeScript(Dl.init(i,this,e),!0),this.apRangeCalled?this.target=e:(this.clearWaypoints(),this.interacted=!0),null===this.target&&this.unsetMapFlag()}else if(this.target instanceof Ns&&this.inOperableDistance(this.target)){if(vt.NODE_DEBUG&&!t&&!i){let e='_';this.target instanceof kl?e=-1!==this.targetSubject.com&&this.targetOp===cs.APNPCT||this.targetOp===cs.OPNPCT?tt.get(this.targetSubject.com)?.comName??this.targetSubject.toString():ft.get(this.target.type)?.debugname??this.target.type.toString():this.target instanceof ss?e=at.get(this.target.type)?.debugname??this.target.type.toString():this.target instanceof $r?e=Tt.get(this.target.type)?.debugname??this.target.type.toString():-1!==this.targetSubject.com&&this.targetOp===cs.APNPCT||this.targetOp===cs.APPLAYERT||this.targetOp===cs.APLOCT||this.targetOp===cs.APOBJT?e=tt.get(this.targetSubject.com)?.comName??this.targetSubject.toString():-1!==this.targetSubject.type&&(e=Tt.get(this.targetSubject.type)?.debugname??this.targetSubject.toString()),this.messageGame(`No trigger for [${cs[this.targetOp+7].toLowerCase()},${e}]`)}this.target=null,this.messageGame('Nothing interesting happens.'),this.interacted=!0,this.clearWaypoints()}const r=this.updateMovement();if(r&&(this.alreadyFacedEntity=!1,this.lastMovement=Zl.currentTick+1),this.target&&(!this.interacted||this.apRangeCalled))if(this.interacted=!1,t&&(this.target instanceof Ns||!r)&&this.inOperableDistance(this.target)){const e=this.target;this.target=null,this.executeScript(Dl.init(t,this,e),!0),null===this.target&&this.unsetMapFlag(),this.interacted=!0,this.clearWaypoints()}else if(i&&this.inApproachDistance(this.apRange,this.target)){this.apRangeCalled=!1;const e=this.target;this.target=null,this.executeScript(Dl.init(i,this,e),!0),this.apRangeCalled?this.target=e:(this.clearWaypoints(),this.interacted=!0),null===this.target&&this.unsetMapFlag()}else if((this.target instanceof Ns||!r)&&this.inOperableDistance(this.target)){if(!vt.NODE_PRODUCTION&&!t&&!i){let e='_';this.target instanceof kl?e=ft.get(this.target.type)?.debugname??this.target.type.toString():this.target instanceof ss?e=at.get(this.target.type)?.debugname??this.target.type.toString():this.target instanceof $r?e=Tt.get(this.target.type)?.debugname??this.target.type.toString():-1!==this.targetSubject.com&&this.targetOp===cs.APNPCT||this.targetOp===cs.APPLAYERT||this.targetOp===cs.APLOCT||this.targetOp===cs.APOBJT?e=tt.get(this.targetSubject.com)?.comName??this.targetSubject.toString():-1!==this.targetSubject.type&&(e=Tt.get(this.targetSubject.type)?.debugname??this.targetSubject.toString()),this.messageGame(`No trigger for [${cs[this.targetOp+7].toLowerCase()},${e}]`)}this.target=null,this.messageGame('Nothing interesting happens.'),this.interacted=!0,this.clearWaypoints()}if(!this.interactWalkTrigger&&-1!==this.walktrigger&&!this.protect&&!this.delayed()){const e=jt.get(this.walktrigger);if(this.walktrigger=-1,e){const t=Dl.init(e,this);this.interactWalkTrigger=!0,this.unsetMapFlag(),this.runScript(t,!0)}}this.interacted||this.hasWaypoints()||r||(this.messageGame("I can't reach that!"),this.clearInteraction()),this.interacted&&!this.apRangeCalled&&null===this.target&&this.clearInteraction()}getAppearanceInSlot(e){let t=-1;return 8===e?t=this.body[0]:11===e?t=this.body[1]:4===e?t=this.body[2]:6===e?t=this.body[3]:9===e?t=this.body[4]:7===e?t=this.body[5]:10===e&&(t=this.body[6]),-1===t?0:256+t}getCombatLevel(){const e=.25*(this.baseLevels[$i.DEFENCE]+this.baseLevels[$i.HITPOINTS]+Math.floor(this.baseLevels[$i.PRAYER]/2)),t=.325*(this.baseLevels[$i.ATTACK]+this.baseLevels[$i.STRENGTH]),i=.325*(Math.floor(this.baseLevels[$i.RANGED]/2)+this.baseLevels[$i.RANGED]),r=.325*(Math.floor(this.baseLevels[$i.MAGIC]/2)+this.baseLevels[$i.MAGIC]);return Math.floor(e+Math.max(t,i,r))}generateAppearance(t){const i=Oe.alloc(0);i.p1(this.gender),i.p1(this.headicons);const r=[];let s=this.getInventory(t);s||(s=new Xt(it.WORN,0));for(let e=0;ei.type===e&&i.com===t)))return;it.get(e).scope===it.SCOPE_SHARED&&(i=-1),this.invListeners.push({type:e,com:t,source:i,firstSeen:!0})}invStopListenOnCom(e){const t=this.invListeners.findIndex((t=>t.com===e));-1!==t&&(this.invListeners.splice(t,1),this.write(new xs(e)))}invGetSlot(e,t){const i=this.getInventory(e);if(!i)throw new Error('invGetSlot: Invalid inventory type: '+e);if(!i.validSlot(t))throw new Error('invGetSlot: Invalid slot: '+t);return i.get(t)}invClear(e){const t=this.getInventory(e);if(!t)throw new Error('invClear: Invalid inventory type: '+e);t.removeAll()}invAdd(e,t,i,r=!0){const s=this.getInventory(e);if(!s)throw new Error('invAdd: Invalid inventory type: '+e);return s.add(t,i,-1,r).completed}invSet(e,t,i,r){const s=this.getInventory(e);if(!s)throw new Error('invSet: Invalid inventory type: '+e);if(!s.validSlot(r))throw new Error('invSet: Invalid slot: '+r);s.set(r,{id:t,count:i})}invDel(e,t,i,r=-1){const s=this.getInventory(e);if(!s)throw new Error('invDel: Invalid inventory type: '+e);if(r<-1||r>=this.invSize(e))throw new Error('invDel: Invalid beginSlot: '+r);return s.remove(t,i,r).completed}invDelSlot(e,t){const i=this.getInventory(e);if(!i)throw new Error('invDelSlot: Invalid inventory type: '+e);if(!i.validSlot(t))throw new Error('invDelSlot: Invalid slot: '+t);i.delete(t)}invSize(e){const t=this.getInventory(e);if(!t)throw new Error('invSize: Invalid inventory type: '+e);return t.capacity}invTotal(e,t){const i=this.getInventory(e);if(!i)throw new Error('invTotal: Invalid inventory type: '+e);return i.getItemCount(t)}invFreeSpace(e){const t=this.getInventory(e);if(!t)throw new Error('invFreeSpace: Invalid inventory type: '+e);return t.freeSlotCount}invItemSpace(e,t,i,r){const s=this.getInventory(e);if(!s)throw new Error('invItemSpace: Invalid inventory type: '+e);const n=Tt.get(t);let a=t;if(n.certtemplate>=0&&n.certlink>=0&&(a=n.certlink),n.stackable||a!=t||s.stackType==Xt.ALWAYS_STACK){const r=!0===it.get(e).stockobj?.includes(t);return 0!=this.invTotal(e,t)||0!=this.invFreeSpace(e)||r?Math.max(0,i-(Xt.STACK_LIMIT-this.invTotal(e,t))):i}return Math.max(0,i-(this.invFreeSpace(e)-(this.invSize(e)-r)))}invMoveToSlot(e,t,i,r){const s=this.getInventory(e);if(!s)throw new Error('invMoveToSlot: Invalid inventory type: '+e);if(!s.validSlot(i))throw new Error('invMoveToSlot: Invalid from slot: '+i);const n=this.getInventory(t);if(!n)throw new Error('invMoveToSlot: Invalid inventory type: '+t);if(!n.validSlot(r))throw new Error('invMoveToSlot: Invalid to slot: '+r);const a=this.invGetSlot(e,i);if(!a)throw new Error(`invMoveToSlot: Invalid from obj was null. This means the obj does not exist at this slot: ${i}`);const o=this.invGetSlot(t,r);this.invSet(t,a.id,a.count,r),o?this.invSet(e,o.id,o.count,i):this.invDelSlot(e,i)}invMoveFromSlot(e,t,i){const r=this.getInventory(e);if(!r)throw new Error('invMoveFromSlot: Invalid inventory type: '+e);if(!this.getInventory(t))throw new Error('invMoveFromSlot: Invalid inventory type: '+t);if(!r.validSlot(i))throw new Error('invMoveFromSlot: Invalid from slot: '+i);const s=this.invGetSlot(e,i);if(!s)throw new Error(`invMoveFromSlot: Invalid from obj was null. This means the obj does not exist at this slot: ${i}`);return this.invDelSlot(e,i),{overflow:s.count-this.invAdd(t,s.id,s.count,!1),fromObj:s.id}}invTotalCat(e,t){const i=this.getInventory(e);if(!i)throw new Error('invTotalCat: Invalid inventory type: '+e);return i.itemsFiltered.filter((e=>Tt.get(e.id).category==t)).reduce(((e,t)=>e+t.count),0)}_invTotalParam(e,t,i){const r=this.getInventory(e);if(!r)throw new Error('invTotalParam: Invalid inventory type: '+e);const s=gt.get(t);let n=0;for(let e=0;e=Tt.count)continue;const a=Tt.get(t.id),o=st(s.id,a,s.defaultInt);n+=i?t.count*o:o}return n}invTotalParam(e,t){return this._invTotalParam(e,t,!1)}invTotalParamStack(e,t){return this._invTotalParam(e,t,!0)}getVar(e){const t=Nt.get(e);return t.type===Pe.STRING?this.varsString[t.id]:this.vars[t.id]}setVar(e,t){const i=Nt.get(e);i.type===Pe.STRING&&'string'==typeof t?this.varsString[i.id]=t:'number'==typeof t&&(this.vars[i.id]=t,i.transmit&&this.writeVarp(e,t))}writeVarp(e,t){t>=-128&&t<=127?this.write(new Fs(e,t)):this.write(new Hs(e,t))}addXp(e,t){if(t<0)throw new Error(`Invalid xp parameter for addXp call: Stat was: ${e}, Exp was: ${t}`);if(0==t)return;const i=Number(vt.NODE_XPRATE)||1;this.stats[e]+=t*i,this.stats[e]>2e9&&(this.stats[e]=2e9);const r=this.baseLevels[e];if(this.levels[e]===this.baseLevels[e]&&(this.levels[e]=Bo(this.stats[e])),this.baseLevels[e]=Bo(this.stats[e]),this.baseLevels[e]>r){this.levels[e]=It.count||this.animProtect||(-1==t||-1==this.animId||It.get(t).priority>It.get(this.animId).priority||0===It.get(this.animId).priority)&&(this.animId=t,this.animDelay=i,this.mask|=e.ANIM)}spotanim(t,i,r){this.graphicId=t,this.graphicHeight=i,this.graphicDelay=r,this.mask|=e.SPOTANIM}applyDamage(t,i){this.damageTaken=t,this.damageType=i;const r=this.levels[$i.HITPOINTS];r-t<=0?(this.levels[$i.HITPOINTS]=0,this.damageTaken=r):this.levels[$i.HITPOINTS]=r-t,this.mask|=e.DAMAGE}say(t){this.chat=t,this.mask|=e.SAY}faceSquare(t,i){this.faceX=2*t+1,this.faceZ=2*i+1,this.orientationX=this.faceX,this.orientationZ=this.faceZ,this.mask|=e.FACE_COORD}playSong(e){if(!(e=e.toLowerCase().replaceAll(' ','_')))return;const t=Ps.get(e+'.mid'),i=ws.get(e+'.mid');if(t&&i){const r=t.length;this.write(new Vs(e,i,r))}}playJingle(e,t){if(!(t=t.toLowerCase().replaceAll('_',' ')))return;const i=Ps.get(t+'.mid');i&&this.write(new Gs(e,i))}openMainModal(e){4&this.modalState&&(this.write(new Bs),this.modalState&=-5,this.modalSidebar=-1),this.modalState|=1,this.modalTop=e,this.refreshModal=!0}openChat(e){this.modalState|=2,this.modalBottom=e,this.refreshModal=!0}openSideOverlay(e){this.modalState|=4,this.modalSidebar=e,this.refreshModal=!0}openChatSticky(e){this.write(new Ms(e)),this.modalState|=8,this.modalSticky=e}openMainModalSideOverlay(e,t){this.modalState|=1,this.modalTop=e,this.modalState|=4,this.modalSidebar=t,this.refreshModal=!0}exactMove(t,i,r,s,n,a,o){this.exactStartX=t,this.exactStartZ=i,this.exactEndX=r,this.exactEndZ=s,this.exactMoveStart=n,this.exactMoveEnd=a,this.exactMoveDirection=o,this.mask|=e.EXACT_MOVE,this.x=r,this.z=s,this.lastStepX=this.x-1,this.lastStepZ=this.z}setTab(e,t){this.overlaySide[t]=e,this.write(new Ws(e,t))}isComponentVisible(e){return this.modalTop===e.rootLayer||this.modalBottom===e.rootLayer||this.modalSidebar===e.rootLayer||-1!==this.overlaySide.findIndex((t=>t===e.rootLayer))||this.modalSticky===e.rootLayer}updateAfkZones(){if(this.lastAfkZone=Math.min(1e3,this.lastAfkZone+1),this.withinAfkZone())return;const e=ji.packCoord(0,this.x-10,this.z-10);this.moveSpeed===Is.INSTANT&&this.jump?this.afkZones[1]=e:this.afkZones[1]=this.afkZones[0],this.afkZones[0]=e,this.lastAfkZone=0}zonesAfk(){return 1e3===this.lastAfkZone}withinAfkZone(){for(let e=0;e=2944&&this.x<3392&&this.z>=3520&&this.z<6400||this.x>=2944&&this.x<3392&&this.z>=9920&&this.z<12800}runScript(e,t=!1,i=!1){if(!i&&t&&(this.protect||this.delayed()))return-1;t&&(e.pointerAdd(Gt.ProtectedActivePlayer),this.protect=!0);const r=Dl.execute(e);return t&&(this.protect=!1),e.pointerGet(Gt.ProtectedActivePlayer)&&e._activePlayer&&(e.pointerRemove(Gt.ProtectedActivePlayer),e._activePlayer.protect=!1),e.pointerGet(Gt.ProtectedActivePlayer2)&&e._activePlayer2&&(e.pointerRemove(Gt.ProtectedActivePlayer2),e._activePlayer2.protect=!1),r}executeScript(e,t=!1,i=!1){const r=this.runScript(e,t,i);-1!==r&&(r!==$t.FINISHED&&r!==$t.ABORTED?r===$t.WORLD_SUSPENDED?Zl.enqueueScript(e,e.popInt()):r===$t.NPC_SUSPENDED?e.activeNpc.activeScript=e:(e.activePlayer.activeScript=e,e.activePlayer.protect=t):e===this.activeScript&&(this.activeScript=null,1&this.modalState||this.closeModal()))}wrappedMessageGame(e){const t=Ge.get(1).split(e,456);for(const e of t)this.messageGame(e)}write(e){e.priority===Rs.HIGH?this.highPriorityOut.push(e):this.lowPriorityOut.push(e)}unsetMapFlag(){this.clearWaypoints(),this.write(new Ks)}hintNpc(e){this.write(new zs(1,e,0,0,0,0))}hintTile(e,t,i,r){this.write(new zs(e,0,0,t,i,r))}hintPlayer(e){this.write(new zs(10,0,e,0,0,0))}stopHint(){this.write(new zs(-1,0,0,0,0,0))}lastLoginInfo(e,t,i,r){this.write(new js(e,t,i,r)),this.modalState|=16}logout(){}terminate(){}messageGame(e){this.write(new Ys(e))}},ko=class e{constructor(t,i,r){this.index=t,this.id=i,this.length=r,e.all[t]=this,e.byId[i]=this}static all=[];static byId=[];static REBUILD_GETMAPS=new e(4,150,-1);static NO_TIMEOUT=new e(6,108,0);static IDLE_TIMER=new e(30,70,0);static EVENT_TRACKING=new e(34,81,-2);static EVENT_CAMERA_POSITION=new e(35,189,6);static ANTICHEAT_OPLOGIC1=new e(60,7,4);static ANTICHEAT_OPLOGIC2=new e(61,88,4);static ANTICHEAT_OPLOGIC3=new e(62,30,3);static ANTICHEAT_OPLOGIC4=new e(63,176,2);static ANTICHEAT_OPLOGIC5=new e(64,220,0);static ANTICHEAT_OPLOGIC6=new e(65,66,4);static ANTICHEAT_OPLOGIC7=new e(66,17,4);static ANTICHEAT_OPLOGIC8=new e(67,2,2);static ANTICHEAT_OPLOGIC9=new e(68,238,1);static ANTICHEAT_CYCLELOGIC1=new e(70,233,1);static ANTICHEAT_CYCLELOGIC2=new e(71,146,-1);static ANTICHEAT_CYCLELOGIC3=new e(74,215,3);static ANTICHEAT_CYCLELOGIC4=new e(72,236,4);static ANTICHEAT_CYCLELOGIC5=new e(75,85,0);static ANTICHEAT_CYCLELOGIC6=new e(73,219,-1);static OPOBJ1=new e(80,140,6);static OPOBJ2=new e(81,40,6);static OPOBJ3=new e(82,200,6);static OPOBJ4=new e(83,178,6);static OPOBJ5=new e(84,247,6);static OPOBJT=new e(88,138,8);static OPOBJU=new e(89,239,12);static OPNPC1=new e(100,194,2);static OPNPC2=new e(101,8,2);static OPNPC3=new e(102,27,2);static OPNPC4=new e(103,113,2);static OPNPC5=new e(104,100,2);static OPNPCT=new e(108,134,4);static OPNPCU=new e(109,202,8);static OPLOC1=new e(120,245,6);static OPLOC2=new e(121,172,6);static OPLOC3=new e(122,96,6);static OPLOC4=new e(123,97,6);static OPLOC5=new e(124,116,6);static OPLOCT=new e(128,9,8);static OPLOCU=new e(129,75,12);static OPPLAYER1=new e(140,164,2);static OPPLAYER2=new e(141,53,2);static OPPLAYER3=new e(142,185,2);static OPPLAYER4=new e(143,206,2);static OPPLAYERT=new e(148,177,4);static OPPLAYERU=new e(149,248,8);static OPHELD1=new e(160,195,6);static OPHELD2=new e(161,71,6);static OPHELD3=new e(162,133,6);static OPHELD4=new e(163,157,6);static OPHELD5=new e(164,211,6);static OPHELDT=new e(168,48,8);static OPHELDU=new e(169,130,12);static INV_BUTTON1=new e(190,31,6);static INV_BUTTON2=new e(191,59,6);static INV_BUTTON3=new e(192,212,6);static INV_BUTTON4=new e(193,38,6);static INV_BUTTON5=new e(194,6,6);static IF_BUTTON=new e(200,155,2);static RESUME_PAUSEBUTTON=new e(201,235,2);static CLOSE_MODAL=new e(202,231,0);static RESUME_P_COUNTDIALOG=new e(203,237,4);static TUTORIAL_CLICKSIDE=new e(204,175,1);static MOVE_OPCLICK=new e(242,93,-1);static BUG_REPORT=new e(243,190,10);static MOVE_MINIMAPCLICK=new e(244,165,-1);static INV_BUTTOND=new e(245,159,6);static IGNORELIST_DEL=new e(246,171,8);static IGNORELIST_ADD=new e(247,79,8);static IF_PLAYERDESIGN=new e(248,52,13);static CHAT_SETMODE=new e(249,244,3);static MESSAGE_PRIVATE=new e(250,148,-1);static FRIENDLIST_DEL=new e(251,11,8);static FRIENDLIST_ADD=new e(252,118,8);static CLIENT_CHEAT=new e(253,4,-1);static MESSAGE_PUBLIC=new e(254,158,-1);static MOVE_GAMECLICK=new e(255,181,-1)},Mo=class{},xo=class{},Fo=class e{constructor(e,t){this.id=e,this.limit=t}static CLIENT_EVENT=new e(0,20);static USER_EVENT=new e(1,5)},Ho=class extends xo{constructor(e){super(),this.input=e}category=Fo.USER_EVENT},Vo=class extends Mo{prot=ko.CLIENT_CHEAT;decode(e){const t=e.gjstr();return new Ho(t)}},Go=class extends xo{category=Fo.USER_EVENT},Wo=class extends Mo{prot=ko.CLOSE_MODAL;decode(){return new Go}},Ko=class extends xo{category=Fo.CLIENT_EVENT},zo=class extends Mo{prot=ko.IDLE_TIMER;decode(){return new Ko}},jo=class extends xo{constructor(e){super(),this.component=e}category=Fo.USER_EVENT},Yo=class extends Mo{prot=ko.IF_BUTTON;decode(e){const t=e.g2();return new jo(t)}},qo=class extends xo{constructor(e,t,i){super(),this.gender=e,this.idkit=t,this.color=i}category=Fo.USER_EVENT},Qo=class extends Mo{prot=ko.IF_PLAYERDESIGN;decode(e){const t=e.g1(),i=[];for(let t=0;t<7;t++)i[t]=e.g1(),255===i[t]&&(i[t]=-1);const r=[];for(let t=0;t<5;t++)r[t]=e.g1();return new qo(t,i,r)}},$o=class extends xo{constructor(e,t,i,r){super(),this.op=e,this.obj=t,this.slot=i,this.component=r}category=Fo.USER_EVENT},Zo=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new $o(this.op,t,i,r)}},Xo=class extends xo{constructor(e,t,i){super(),this.component=e,this.slot=t,this.targetSlot=i}category=Fo.USER_EVENT},Jo=class extends Mo{prot=ko.INV_BUTTOND;decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new Xo(t,i,r)}},ec=class extends xo{constructor(e,t){super(),this.username=e,this.input=t}category=Fo.USER_EVENT},tc=class extends Mo{prot=ko.MESSAGE_PRIVATE;decode(e){const t=e.g8(),i=wa.unpack(e,e.length-8);return new ec(t,i)}},ic=class extends xo{constructor(e,t,i){super(),this.input=e,this.color=t,this.effect=i}category=Fo.USER_EVENT},rc=class extends Mo{prot=ko.MESSAGE_PUBLIC;decode(e){const t=e.g1(),i=e.g1(),r=wa.unpack(e,e.length-2);return new ic(r,t,i)}},sc=class extends xo{constructor(e,t,i,r){super(),this.op=e,this.obj=t,this.slot=i,this.component=r}category=Fo.USER_EVENT},nc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new sc(this.op,t,i,r)}},ac=class extends xo{constructor(e,t,i,r){super(),this.obj=e,this.slot=t,this.component=i,this.spellComponent=r}category=Fo.USER_EVENT},oc=class extends Mo{prot=ko.OPHELDT;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new ac(t,i,r,s)}},cc=class extends xo{constructor(e,t,i,r,s,n){super(),this.obj=e,this.slot=t,this.component=i,this.useObj=r,this.useSlot=s,this.useComponent=n}category=Fo.USER_EVENT},lc=class extends Mo{prot=ko.OPHELDU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2(),n=e.g2(),a=e.g2();return new cc(t,i,r,s,n,a)}},hc=class extends xo{constructor(e,t,i,r){super(),this.op=e,this.x=t,this.z=i,this.loc=r}category=Fo.USER_EVENT},dc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new hc(this.op,t,i,r)}},uc=class extends xo{constructor(e,t,i,r){super(),this.x=e,this.z=t,this.loc=i,this.spellComponent=r}category=Fo.USER_EVENT},pc=class extends Mo{prot=ko.OPLOCT;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new uc(t,i,r,s)}},fc=class extends xo{constructor(e,t,i,r,s,n){super(),this.x=e,this.z=t,this.loc=i,this.useObj=r,this.useSlot=s,this.useComponent=n}category=Fo.USER_EVENT},gc=class extends Mo{prot=ko.OPLOCU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2(),n=e.g2(),a=e.g2();return new fc(t,i,r,s,n,a)}},mc=class extends xo{constructor(e,t){super(),this.op=e,this.nid=t}category=Fo.USER_EVENT},yc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2();return new mc(this.op,t)}},Ec=class extends xo{constructor(e,t){super(),this.nid=e,this.spellComponent=t}category=Fo.USER_EVENT},_c=class extends Mo{prot=ko.OPNPCT;decode(e){const t=e.g2(),i=e.g2();return new Ec(t,i)}},Ac=class extends xo{constructor(e,t,i,r){super(),this.nid=e,this.useObj=t,this.useSlot=i,this.useComponent=r}category=Fo.USER_EVENT},vc=class extends Mo{prot=ko.OPNPCU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new Ac(t,i,r,s)}},Tc=class extends xo{constructor(e,t,i,r){super(),this.op=e,this.x=t,this.z=i,this.obj=r}category=Fo.USER_EVENT},Cc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2(),i=e.g2(),r=e.g2();return new Tc(this.op,t,i,r)}},Ic=class extends xo{constructor(e,t,i,r){super(),this.x=e,this.z=t,this.obj=i,this.spellComponent=r}category=Fo.USER_EVENT},Sc=class extends Mo{prot=ko.OPOBJT;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new Ic(t,i,r,s)}},Oc=class extends xo{constructor(e,t,i,r,s,n){super(),this.x=e,this.z=t,this.obj=i,this.useObj=r,this.useSlot=s,this.useComponent=n}category=Fo.USER_EVENT},Nc=class extends Mo{prot=ko.OPOBJU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2(),n=e.g2(),a=e.g2();return new Oc(t,i,r,s,n,a)}},Lc=class extends xo{constructor(e,t){super(),this.op=e,this.pid=t}category=Fo.USER_EVENT},Pc=class extends Mo{constructor(e,t){super(),this.prot=e,this.op=t}decode(e){const t=e.g2();return new Lc(this.op,t)}},wc=class extends xo{constructor(e,t){super(),this.pid=e,this.spellComponent=t}category=Fo.USER_EVENT},bc=class extends Mo{prot=ko.OPPLAYERT;decode(e){const t=e.g2(),i=e.g2();return new wc(t,i)}},Rc=class extends xo{constructor(e,t,i,r){super(),this.pid=e,this.useObj=t,this.useSlot=i,this.useComponent=r}category=Fo.USER_EVENT},Bc=class extends Mo{prot=ko.OPPLAYERU;decode(e){const t=e.g2(),i=e.g2(),r=e.g2(),s=e.g2();return new Rc(t,i,r,s)}},Uc=class extends xo{constructor(e){super(),this.maps=e}category=Fo.USER_EVENT},Dc=class extends Mo{prot=ko.REBUILD_GETMAPS;decode(e){const t=[],i=e.length/3;for(let r=0;re.com===n));if(!o)return!1;const c=t.getInventoryFromListener(o);if(!c||!c.validSlot(s)||!c.hasAt(s,r))return!1;if(t.delayed())return!1;let l;t.lastItem=r,t.lastSlot=s,l=1===i?cs.INV_BUTTON1:2===i?cs.INV_BUTTON2:3===i?cs.INV_BUTTON3:4===i?cs.INV_BUTTON4:cs.INV_BUTTON5;const h=jt.getByTrigger(l,n,-1);if(h){const e=tt.get(a.rootLayer);t.executeScript(Dl.init(h,t),0==e.overlay)}else vt.NODE_DEBUG&&t.messageGame(`No trigger for [${cs.toString(l)},${a.comName}]`);return!0}},Kc=class e{static TCP=0;static WEBSOCKET=1;socket=null;type=-1;state=-1;remoteAddress;totalBytesRead=0;totalBytesWritten=0;uniqueId='undefined'==typeof self?randomUUID():'https:'===self.location.protocol?self.crypto.randomUUID():'0';encryptor=null;decryptor=null;in=new Uint8Array(5e3);inOffset=0;inCount=new Uint8Array(256);out=new Oe(new Uint8Array(5e3));player=null;constructor(t,i,r=e.TCP,s=-1){this.socket=t,this.remoteAddress=i,this.type=r,this.state=s}isTCP(){return this.type===e.TCP}isWebSocket(){return this.type===e.WEBSOCKET}send(e){if('undefined'==typeof self){if(!this.socket)return;this.totalBytesWritten+=e.length,this.isTCP()?this.socket.write(e):this.isWebSocket()&&this.socket.send(e)}else this.totalBytesWritten+=e.length,self.postMessage(e)}close(){if('undefined'==typeof self){if(!this.socket)return;setTimeout((()=>{this.isTCP()?this.socket.end():this.isWebSocket()&&this.socket.close()}),100)}else setTimeout((()=>{self.close()}),100)}terminate(){if('undefined'==typeof self){if(!this.socket)return;this.isTCP()?this.socket.destroy():this.isWebSocket()&&this.socket.terminate()}else self.close()}reset(){this.inOffset=0,this.inCount.fill(0)}writeImmediate(e){this.send(e)}flush(){const e=this.out;0!==e.pos&&(this.send(e.data.subarray(0,e.pos)),e.pos=0)}},zc=class extends Kc{constructor(){super(null,'')}isTCP(){return this.type===Kc.TCP}isWebSocket(){return this.type===Kc.WEBSOCKET}send(e){this.socket}close(){this.socket}terminate(){this.socket}reset(){this.inOffset=0,this.inCount.fill(0)}},jc=class e{static loadFromFile(t){const i=ge(pe(t));let r;return r=fs24.existsSync(`data/players/${i}.sav`)?Oe.load(`data/players/${i}.sav`):new Oe(new Uint8Array),e.load(t,r,null)}static load(e,t,i){const r=pe(e),s=ge(r),n=i?new Il(s,r,i):new Do(s,r);if(vt.NODE_PRODUCTION?void 0!==vt.NODE_STAFF.find((e=>e===s))&&(n.staffModLevel=3):n.staffModLevel=3,t.data.length<2){for(let e=0;e<21;e++)n.stats[e]=0,n.baseLevels[e]=1,n.levels[e]=1;return n.stats[$i.HITPOINTS]=Uo(10),n.baseLevels[$i.HITPOINTS]=10,n.levels[$i.HITPOINTS]=10,n}if(8196!==t.g2())throw new Error('Invalid player save');const a=t.g2();if(a>3)throw new Error('Unsupported player save format');t.pos=t.data.length-4;if(t.g4()!=Oe.getcrc(t.data,0,t.data.length-4))throw new Error('Player save corrupted');t.pos=4,n.x=t.g2(),n.z=t.g2(),n.level=t.g1();for(let e=0;e<7;e++)n.body[e]=t.g1(),255===n.body[e]&&(n.body[e]=-1);for(let e=0;e<5;e++)n.colors[e]=t.g1();n.gender=t.g1(),n.runenergy=t.g2(),n.playtime=a>=2?t.g4():t.g2();for(let e=0;e<21;e++)n.stats[e]=t.g4(),n.baseLevels[e]=Bo(n.stats[e]),n.levels[e]=t.g1();const o=t.g2();for(let e=0;e=3){const e=t.g1();for(let i=0;i80)return!1;const{input:i}=e,r=i.toLowerCase().split(' '),s=r.shift();if(void 0===s||s.length<=0)return!1;if(t.playerLog('Cheat ran',i),t.staffModLevel>=3)if('reload'!==s||'undefined'!=typeof self||vt.NODE_PRODUCTION)if('rebuild'!==s||vt.NODE_PRODUCTION){if('serverdrop'===s)t.terminate();else if('bench'===s){const e=Date.now();for(let e=0;e<1e5;e++)ti(t.level,t.x,t.z,t.x,t.z+10);const i=Date.now();console.log(`took = ${i-e} ms`)}else if('bots'===s){t.messageGame('Adding bots');for(let e=0;e<1999;e++){const t=jc.load(`bot${e}`,new Oe(new Uint8Array),new zc);Zl.addPlayer(t)}}else if('lightbots'===s){t.messageGame('Adding lightweight bots');for(let e=0;e<1999;e++){const t=jc.load(`bot${e}`,new Oe(new Uint8Array),null);Zl.addPlayer(t)}}else if('teleall'===s){t.messageGame('Teleporting all players');for(const e of Zl.players){e.closeModal();do{const t=Math.floor(64*Math.random())+3200,i=Math.floor(64*Math.random())+3200;e.teleJump(t+Math.floor(64*Math.random())-32,i+Math.floor(64*Math.random())-32,0)}while(ui(e.x,e.z,e.level,Ri.WALK_BLOCKED))}}else if('moveall'===s){t.messageGame('Moving all players'),console.time('moveall');for(const e of Zl.players)e.closeModal(),e.queueWaypoints(ti(e.level,e.x,e.z,32+(e.x>>>6<<6),32+(e.z>>>6<<6)));console.timeEnd('moveall')}else if('speed'===s){if(r.length<1)return t.messageGame('Usage: ::speed '),!1;const e=yt(r.shift(),20);if(e<20)return t.messageGame('::speed input was too low.'),!1;t.messageGame(`World speed was changed to ${e}ms`),Zl.tickRate=e}else if('fly'===s)t.moveStrategy===Os.FLY?t.moveStrategy=Os.SMART:t.moveStrategy=Os.FLY,t.messageGame(`Fly is on? ${t.moveStrategy===Os.FLY}`);else if('naive'===s)t.moveStrategy===Os.NAIVE?t.moveStrategy=Os.SMART:t.moveStrategy=Os.NAIVE,t.messageGame(`Naive is on? ${t.moveStrategy===Os.NAIVE}`);else if('teleto'===s){if(r.length<1)return!1;const e=Zl.getPlayerByUsername(r[0]);if(!e)return t.messageGame(`${r[0]} is not logged in.`),!1;t.teleJump(e.x,e.z,e.level)}else if('teleother'===s){if(r.length<1)return!1;const e=Zl.getPlayerByUsername(r[0]);if(!e)return t.messageGame(`${r[0]} is not logged in.`),!1;e.teleJump(t.x,t.z,t.level)}else if('setvarother'===s){if(r.length<3)return!1;const e=Zl.getPlayerByUsername(r[0]);if(!e)return t.messageGame(`${r[0]} is not logged in.`),!1;const i=Nt.getId(r[1]),s=Math.max(-2147483648,Math.min(yt(r[2],0),2147483647));if(-1===i)return!1;e.setVar(i,s),t.messageGame('set '+r[1]+': to '+s+' on '+e.username)}else if('shutdown'===s){if(r.length<1)return!1;Zl.rebootTimer(yt(r[0],50))}}else Zl.devThread.postMessage({type:'pack'});else{Zl.reload();const e=jt.load('data/pack');t.messageGame(`Reloaded ${e} scripts.`)}if(vt.NODE_ALLOW_CHEATS||t.staffModLevel>=2)if('tele'===s){if(r.length<1)return!1;if('up'===r[0])t.teleJump(t.x,t.z,t.level+1),t.messageGame('::tele '+ji.formatString(t.level,t.x,t.z,','));else if('down'===r[0])t.teleJump(t.x,t.z,t.level-1),t.messageGame('::tele '+ji.formatString(t.level,t.x,t.z,','));else if(-1===r[0].indexOf(','))t.teleJump(yt(r[0],3200),yt(r[1],3200),yt(r[2],t.level));else{const e=r[0].split(',');if(5!==e.length)return!1;const i=yt(e[0],0),s=yt(e[1],50),n=yt(e[2],50),a=yt(e[3],0),o=yt(e[4],0);if(i<0||i>3||s<0||s>255||n<0||n>255||a<0||a>63||o<0||o>63)return!1;t.teleJump((s<<6)+a,(n<<6)+o,i)}}else if('setvar'===s){if(r.length<2)return!1;const e=Nt.getId(r[0]),i=Math.max(-2147483648,Math.min(yt(r[1],0),2147483647));if(-1===e)return!1;t.setVar(e,i),t.messageGame('set '+r[0]+': to '+i)}else if('random'===s)t.afkEventReady=!0;else if('minme'===s)for(let e=0;e '),!1;const e=Do.SKILLS.indexOf(r[0]);if(-1===e)return t.messageGame(`Unknown stat ${r[0]}`),!1;const i=10*parseInt(r[1]);t.stats[e]=i}else if('setstat'===s){if(r.length<2)return!1;const e=Do.SKILLS.indexOf(r[0]);if(-1===e)return!1;t.setLevel(e,parseInt(r[1]))}else if('advancestat'===s){if(r.length<1)return!1;const e=Do.SKILLS.indexOf(r[0]),i=Math.min(99,Math.max(1,yt(r[1],1)));if(-1===e)return!1;t.setLevel(e,t.baseLevels[e]+i)}else if('getvar'===s){if(r.length<1)return!1;const e=Nt.getId(r[0]);if(-1===e)return!1;const i=t.getVar(e);t.messageGame('get '+r[0]+': '+i)}else if('give'===s){if(r.length<1)return!1;const e=Tt.getId(r[0]),i=Math.max(1,Math.min(yt(r[1],1),2147483647));if(-1===e)return!1;t.invAdd(it.INV,e,i,!1)}if((vt.NODE_ALLOW_CHEATS||t.staffModLevel>=1)&&'getcoord'===s&&t.messageGame(ji.formatString(t.level,t.x,t.z,'_')),vt.NODE_ALLOW_CHEATS||t.staffModLevel>=2){const e=jt.getByName(`[debugproc,${s}]`);if(!e)return!1;const n=new Array(e.info.parameterTypes.length).fill(-1);for(let t=0;t1)return!1;let n=!0;for(let e=0;e<7;e++){let t=e;if(1===i&&(t+=7),8==t&&-1===r[e])continue;const s=et.get(r[e]);if(!s||s.disable||s.type!=t){n=!1;break}}if(!n)return!1;for(let e=0;e<5;e++)if(s[e]>=Do.DESIGN_BODY_COLORS[e].length){n=!1;break}return!!n&&(t.gender=i,t.body=r,t.colors=s,t.generateAppearance(it.WORN),!0)}},Xc=class extends Gc{handle(e,t){const{component:i,slot:r,targetSlot:s}=e,n=tt.get(i);if(void 0===n||!t.isComponentVisible(n))return!1;const a=t.invListeners.find((e=>e.com===i));if(!a)return!1;const o=t.getInventoryFromListener(a);if(!(o&&o.validSlot(r)&&o.get(r)&&o.validSlot(s)))return!1;if(t.delayed())return t.write(new ro(i,o,r,s)),!1;t.lastSlot=r,t.lastTargetSlot=s;const c=jt.getByTrigger(cs.INV_BUTTOND,i);if(c){const e=tt.get(n.rootLayer);t.executeScript(Dl.init(c,t),0==e.overlay)}else vt.NODE_DEBUG&&t.messageGame(`No trigger for [inv_buttond,${n.comName}]`);return!0}},Jc=class extends Gc{handle(e,t){return!0}},el=class extends Gc{handle(e,t){const{color:i,effect:r,input:s}=e;if(i<0||i>11||r<0||r>2||s.length>100)return!1;t.messageColor=i,t.messageEffect=r,t.messageType=0;const n=Oe.alloc(0);return wa.pack(n,Bt.filter(s)),t.message=new Uint8Array(n.pos),n.pos=0,n.gdata(t.message,0,t.message.length),n.release(),t.mask|=Do.CHAT,!0}},tl=class extends Gc{handle(e,t){const{obj:i,slot:r,component:s}=e,n=tt.get(s);if(void 0===n||!t.isComponentVisible(n))return!1;const a=Tt.get(i);if(5!==e.op&&(a.iop&&!a.iop[e.op-1]||!a.iop))return!1;const o=t.invListeners.find((e=>e.com===s));if(!o)return!1;const c=t.getInventoryFromListener(o);if(!c||!c.validSlot(r)||!c.hasAt(r,i))return!1;if(t.delayed())return!1;let l;t.lastItem=i,t.lastSlot=r,t.clearInteraction(),t.closeModal(),l=1===e.op?cs.OPHELD1:2===e.op?cs.OPHELD2:3===e.op?cs.OPHELD3:4===e.op?cs.OPHELD4:cs.OPHELD5;const h=jt.getByTrigger(l,a.id,a.category);return h?t.executeScript(Dl.init(h,t),!0):vt.NODE_DEBUG&&t.messageGame(`No trigger for [${cs.toString(l)},${a.debugname}]`),!0}},il=class extends Gc{handle(e,t){const{obj:i,slot:r,component:s,spellComponent:n}=e,a=tt.get(s);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=tt.get(s);if(void 0===o||!t.isComponentVisible(o))return t.unsetMapFlag(),!1;const c=t.invListeners.find((e=>e.com===s));if(!c)return t.unsetMapFlag(),!1;const l=t.getInventoryFromListener(c);if(!l||!l.validSlot(r)||!l.hasAt(r,i))return t.unsetMapFlag(),!1;if(t.delayed())return t.unsetMapFlag(),!1;t.lastItem=i,t.lastSlot=r,t.clearInteraction(),t.closeModal();const h=jt.getByTrigger(cs.OPHELDT,n,-1);return h?t.executeScript(Dl.init(h,t),!0):(vt.NODE_DEBUG&&t.messageGame(`No trigger for [opheldt,${o.comName}]`),t.messageGame('Nothing interesting happens.')),!0}},rl=class extends Gc{handle(e,t){const{obj:i,slot:r,component:s,useObj:n,useSlot:a,useComponent:o}=e,c=tt.get(s);if(void 0===c||!t.isComponentVisible(c))return t.unsetMapFlag(),!1;const l=tt.get(s);if(void 0===l||!t.isComponentVisible(l))return t.unsetMapFlag(),!1;{const e=t.invListeners.find((e=>e.com===s));if(!e)return t.unsetMapFlag(),!1;const n=t.getInventoryFromListener(e);if(!n||!n.validSlot(r)||!n.hasAt(r,i))return t.unsetMapFlag(),!1}{const e=t.invListeners.find((e=>e.com===o));if(!e)return t.unsetMapFlag(),!1;const i=t.getInventoryFromListener(e);if(!i||!i.validSlot(a)||!i.hasAt(a,n))return t.unsetMapFlag(),!1}if(t.delayed())return t.unsetMapFlag(),!1;t.lastItem=i,t.lastSlot=r,t.lastUseItem=n,t.lastUseSlot=a;const h=Tt.get(t.lastItem),d=Tt.get(t.lastUseItem);if((h.members||d.members)&&!vt.NODE_MEMBERS)return t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1;let u=jt.getByTriggerSpecific(cs.OPHELDU,h.id,-1);u||(u=jt.getByTriggerSpecific(cs.OPHELDU,d.id,-1),[t.lastItem,t.lastUseItem]=[t.lastUseItem,t.lastItem],[t.lastSlot,t.lastUseSlot]=[t.lastUseSlot,t.lastSlot]);const p=-1!==h.category?Le.get(h.category):null;!u&&p&&(u=jt.getByTriggerSpecific(cs.OPHELDU,-1,p.id));const f=-1!==d.category?Le.get(d.category):null;return!u&&f&&(u=jt.getByTriggerSpecific(cs.OPHELDU,-1,f.id),[t.lastItem,t.lastUseItem]=[t.lastUseItem,t.lastItem],[t.lastSlot,t.lastUseSlot]=[t.lastUseSlot,t.lastSlot]),t.clearInteraction(),t.closeModal(),u?t.executeScript(Dl.init(u,t),!0):(vt.NODE_DEBUG&&t.messageGame(`No trigger for [opheldu,${h.debugname}]`),t.messageGame('Nothing interesting happens.')),!0}},sl=class extends Gc{handle(e,t){const{x:i,z:r,loc:s}=e;if(t.delayed())return t.unsetMapFlag(),!1;const n=t.originX-52,a=t.originX+52,o=t.originZ+52,c=t.originZ-52;if(ia||ro)return!1;const l=Zl.getLoc(i,r,t.level,s);if(!l)return t.unsetMapFlag(),!1;const h=at.get(l.type);if(!h.op||!h.op[e.op-1])return t.unsetMapFlag(),!1;let d;return d=1===e.op?cs.APLOC1:2===e.op?cs.APLOC2:3===e.op?cs.APLOC3:4===e.op?cs.APLOC4:cs.APLOC5,t.clearPendingAction(),t.setInteraction(hs.ENGINE,l,d),t.opcalled=!0,!0}},nl=class extends Gc{handle(e,t){const{x:i,z:r,loc:s,spellComponent:n}=e;if(t.delayed())return t.unsetMapFlag(),!1;const a=tt.get(n);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=t.originX-52,c=t.originX+52,l=t.originZ+52,h=t.originZ-52;if(ic||rl)return t.unsetMapFlag(),!1;const d=Zl.getLoc(i,r,t.level,s);return d?(t.clearPendingAction(),t.setInteraction(hs.ENGINE,d,cs.APLOCT,{type:d.type,com:n}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},al=class extends Gc{handle(e,t){const{x:i,z:r,loc:s,useObj:n,useSlot:a,useComponent:o}=e;if(t.delayed())return t.unsetMapFlag(),!1;const c=tt.get(o);if(void 0===c||!t.isComponentVisible(c))return t.unsetMapFlag(),!1;const l=t.originX-52,h=t.originX+52,d=t.originZ+52,u=t.originZ-52;if(ih||rd)return t.unsetMapFlag(),!1;const p=t.invListeners.find((e=>e.com===o));if(!p)return t.unsetMapFlag(),!1;const f=t.getInventoryFromListener(p);if(!f||!f.validSlot(a)||!f.hasAt(a,n))return t.unsetMapFlag(),!1;const g=Zl.getLoc(i,r,t.level,s);return g?Tt.get(n).members&&!vt.NODE_MEMBERS?(t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1):(t.lastUseItem=n,t.lastUseSlot=a,t.clearPendingAction(),t.setInteraction(hs.ENGINE,g,cs.APLOCU),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},ol=class extends Gc{handle(e,t){const{nid:i}=e;if(t.delayed())return t.unsetMapFlag(),!1;const r=Zl.getNpc(i);if(!r||r.delayed())return t.unsetMapFlag(),!1;if(!t.buildArea.npcs.has(r.nid))return t.unsetMapFlag(),!1;const s=ft.get(r.type);if(!s.op||!s.op[e.op-1])return t.unsetMapFlag(),!1;let n;return n=1===e.op?cs.APNPC1:2===e.op?cs.APNPC2:3===e.op?cs.APNPC3:4===e.op?cs.APNPC4:cs.APNPC5,t.clearPendingAction(),t.setInteraction(hs.ENGINE,r,n,{type:r.type,com:-1}),t.opcalled=!0,!0}},cl=class extends Gc{handle(e,t){const{nid:i,spellComponent:r}=e;if(t.delayed())return t.unsetMapFlag(),!1;const s=tt.get(r);if(void 0===s||!t.isComponentVisible(s))return t.unsetMapFlag(),!1;const n=Zl.getNpc(i);return!n||n.delayed()?(t.unsetMapFlag(),!1):t.buildArea.npcs.has(n.nid)?(t.clearPendingAction(),t.setInteraction(hs.ENGINE,n,cs.APNPCT,{type:n.type,com:r}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},ll=class extends Gc{handle(e,t){const{nid:i,useObj:r,useSlot:s,useComponent:n}=e;if(t.delayed())return t.unsetMapFlag(),!1;const a=tt.get(n);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=t.invListeners.find((e=>e.com===n));if(!o)return t.unsetMapFlag(),!1;const c=t.getInventoryFromListener(o);if(!c||!c.validSlot(s)||!c.hasAt(s,r))return t.unsetMapFlag(),!1;const l=Zl.getNpc(i);return!l||l.delayed()?(t.unsetMapFlag(),!1):t.buildArea.npcs.has(l.nid)?Tt.get(r).members&&!vt.NODE_MEMBERS?(t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1):(t.lastUseItem=r,t.lastUseSlot=s,t.clearPendingAction(),t.setInteraction(hs.ENGINE,l,cs.APNPCU,{type:l.type,com:-1}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},hl=class extends Gc{handle(e,t){const{x:i,z:r,obj:s}=e;if(t.delayed())return t.unsetMapFlag(),!1;const n=t.originX-52,a=t.originX+52,o=t.originZ+52,c=t.originZ-52;if(ia||ro)return t.unsetMapFlag(),!1;const l=Zl.getObj(i,r,t.level,s,t.pid);if(!l)return t.unsetMapFlag(),!1;const h=Tt.get(l.type);if(1===e.op&&(h.op&&!h.op[0]||!h.op)||4===e.op&&(h.op&&!h.op[3]||!h.op))return t.unsetMapFlag(),!1;let d;return d=1===e.op?cs.APOBJ1:2===e.op?cs.APOBJ2:3===e.op?cs.APOBJ3:4===e.op?cs.APOBJ4:cs.APOBJ5,t.clearPendingAction(),t.setInteraction(hs.ENGINE,l,d),t.opcalled=!0,!0}},dl=class extends Gc{handle(e,t){const{x:i,z:r,obj:s,spellComponent:n}=e;if(t.delayed())return t.unsetMapFlag(),!1;const a=tt.get(n);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=t.originX-52,c=t.originX+52,l=t.originZ+52,h=t.originZ-52;if(ic||rl)return t.unsetMapFlag(),!1;const d=Zl.getObj(i,r,t.level,s,t.pid);return d?(t.clearPendingAction(),t.setInteraction(hs.ENGINE,d,cs.APOBJT,{type:d.type,com:n}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},ul=class extends Gc{handle(e,t){const{x:i,z:r,obj:s,useObj:n,useSlot:a,useComponent:o}=e;if(t.delayed())return t.unsetMapFlag(),!1;const c=tt.get(o);if(void 0===c||!t.isComponentVisible(c))return t.unsetMapFlag(),!1;const l=t.originX-52,h=t.originX+52,d=t.originZ+52,u=t.originZ-52;if(ih||rd)return t.unsetMapFlag(),!1;const p=t.invListeners.find((e=>e.com===o));if(!p)return t.unsetMapFlag(),!1;const f=t.getInventoryFromListener(p);if(!f||!f.validSlot(a)||!f.hasAt(a,n))return t.unsetMapFlag(),!1;const g=Zl.getObj(i,r,t.level,s,t.pid);return g?Tt.get(n).members&&!vt.NODE_MEMBERS?(t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1):(t.lastUseItem=n,t.lastUseSlot=a,t.clearPendingAction(),t.setInteraction(hs.ENGINE,g,cs.APOBJU),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},pl=class extends Gc{handle(e,t){const{pid:i}=e;if(t.delayed())return t.unsetMapFlag(),!1;const r=Zl.getPlayer(i);if(!r)return t.unsetMapFlag(),!1;if(!t.buildArea.players.has(r.uid))return t.unsetMapFlag(),!1;let s;return s=1===e.op?cs.APPLAYER1:2===e.op?cs.APPLAYER2:3===e.op?cs.APPLAYER3:cs.APPLAYER4,t.clearPendingAction(),t.setInteraction(hs.ENGINE,r,s),t.opcalled=!0,!0}},fl=class extends Gc{handle(e,t){const{pid:i,spellComponent:r}=e;if(t.delayed())return t.unsetMapFlag(),!1;const s=tt.get(r);if(void 0===s||!t.isComponentVisible(s))return t.unsetMapFlag(),!1;const n=Zl.getPlayer(i);return n&&t.buildArea.players.has(n.uid)?(t.clearPendingAction(),t.setInteraction(hs.ENGINE,n,cs.APPLAYERT,{type:-1,com:r}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},gl=class extends Gc{handle(e,t){const{pid:i,useObj:r,useSlot:s,useComponent:n}=e;if(t.delayed())return t.unsetMapFlag(),!1;const a=tt.get(n);if(void 0===a||!t.isComponentVisible(a))return t.unsetMapFlag(),!1;const o=t.invListeners.find((e=>e.com===n));if(!o)return t.unsetMapFlag(),!1;const c=t.getInventoryFromListener(o);if(!c||!c.validSlot(s)||!c.hasAt(s,r))return t.unsetMapFlag(),!1;const l=Zl.getPlayer(i);return l&&t.buildArea.players.has(l.uid)?Tt.get(r).members&&!vt.NODE_MEMBERS?(t.messageGame("To use this item please login to a members' server."),t.unsetMapFlag(),!1):(t.lastUseSlot=s,t.clearPendingAction(),t.setInteraction(hs.ENGINE,l,cs.APPLAYERU,{type:r,com:-1}),t.opcalled=!0,!0):(t.unsetMapFlag(),!1)}},ml=class extends Gc{handle(e,t){const{maps:i}=e;for(let e=0;e13)return!1;const r=jt.getByTriggerSpecific(cs.TUTORIAL_CLICKSIDE,-1,-1);return r&&t.executeScript(Dl.init(r,t),!0),!0}},Al=class extends xo{constructor(e,t,i){super(),this.path=e,this.ctrlHeld=t,this.opClick=i}category=Fo.USER_EVENT},vl=class extends Mo{constructor(e){super(),this.prot=e}decode(e){const t=e.g1(),i=e.g2(),r=e.g2(),s=this.prot===ko.MOVE_MINIMAPCLICK?14:0,n=e.available-s>>1,a=[{x:i,z:r}];for(let t=1;t<=n&&t<25;t++)a.push({x:i+e.g1b(),z:r+e.g1b()});return new Al(a,t,this.prot===ko.MOVE_OPCLICK)}},Tl=class extends Gc{handle(e,t){const i=e.path[0];if(t.delayed()||e.ctrlHeld<0||e.ctrlHeld>1||ji.distanceToSW(t,{x:i.x,z:i.z})>104)return t.unsetMapFlag(),t.userPath=[],!1;if(vt.NODE_CLIENT_ROUTEFINDER){t.userPath=[];for(let i=0;ie;){const t=ko.byId[this.client.in[e++]];let i=t.length;-1==i?i=this.client.in[e++]:-2==i&&(i=this.client.in[e++]<<8|this.client.in[e++]);const r=new Oe(this.client.in.slice(e,e+i));e+=i;const s=Cl.getDecoder(t);if(s){const e=s.decode(r),i=Cl.getHandler(t);i&&i.handle(e,this)}}this.client?.reset()}encodeOut(){if(this.client){(this.modalTop!==this.lastModalTop||this.modalBottom!==this.lastModalBottom||this.modalSidebar!==this.lastModalSidebar||this.refreshModalClose)&&(this.refreshModalClose&&this.write(new Bs),this.refreshModalClose=!1,this.lastModalTop=this.modalTop,this.lastModalBottom=this.modalBottom,this.lastModalSidebar=this.modalSidebar),this.refreshModal&&(1&~this.modalState||4&~this.modalState?1&~this.modalState?2&~this.modalState?4&~this.modalState||this.write(new Yn(this.modalSidebar)):this.write(new fn(this.modalBottom)):this.write(new Wn(this.modalTop)):this.write(new zn(this.modalTop,this.modalSidebar)),this.refreshModal=!1);for(let e=this.highPriorityOut.head();e;e=this.highPriorityOut.next())this.writeInner(e),e.uncache();for(let e=this.lowPriorityOut.head();e;e=this.lowPriorityOut.next())this.writeInner(e),e.uncache();this.client.flush()}}writeInner(e){const t=this.client;if(!t)return;const i=Co.getEncoder(e);if(!i)return void console.error('No encoder for message',e);const r=i.prot,s=t.out,n=1+(-1===r.length?1:-2===r.length?2:0)+i.test(e);s.pos+n>=s.length&&t.flush();const a=s.pos;s.p1(r.id),-1===r.length?s.pos+=1:-2===r.length&&(s.pos+=2);const o=s.pos;i.encode(s,e),-1===r.length?s.psize1(s.pos-o):-2===r.length&&s.psize2(s.pos-o),t.encryptor&&(s.data[a]=s.data[a]+t.encryptor.nextInt()&255),Zl.cycleStats[Gr.BANDWIDTH_OUT]+=s.pos-a}logout(){this.writeInner(new Sa),this.client?.flush()}terminate(){this.client?.terminate(),this.client=null}playerLog(e,...t){'undefined'==typeof self&&(t.length>0?fs25.appendFileSync(`data/players/${this.username}.log`,`[${(new Date).toISOString().split('T')[0]} ${this.client?.remoteAddress}]: ${e} ${t.join(' ')}\n`):fs25.appendFileSync(`data/players/${this.username}.log`,`[${(new Date).toISOString().split('T')[0]} ${this.client?.remoteAddress}]: ${e}\n`))}updateMap(){const e=this.buildArea.loadedZones,t=this.buildArea.activeZones,i=ji.zone(this.originX)-4<<3,r=ji.zone(this.originX)+5<<3,s=ji.zone(this.originZ)+5<<3,n=ji.zone(this.originZ)-4<<3;(this.xr-1||this.z>s-1)&&(this.write(new yn(ji.zone(this.x),ji.zone(this.z))),this.originX=this.x,this.originZ=this.z,e.clear());for(let e=this.cameraPackets.head();null!==e;e=this.cameraPackets.next()){const t=e.camX-ji.zoneOrigin(this.originX),i=e.camZ-ji.zoneOrigin(this.originZ);e.type===Ts.CAM_MOVETO?this.write(new Pn(t,i,e.height,e.rotationSpeed,e.rotationMultiplier)):e.type===Ts.CAM_LOOKAT&&this.write(new Nn(t,i,e.height,e.rotationSpeed,e.rotationMultiplier)),e.unlink()}this.moveSpeed===Is.INSTANT&&this.jump&&e.clear(),t.clear();const a=ji.zone(this.x),o=ji.zone(this.z),c=ji.zone(this.originX)-6,l=ji.zone(this.originX)+6,h=ji.zone(this.originZ)+6,d=ji.zone(this.originZ)-6;for(let e=a-3;e<=a+3;e++)for(let i=o-3;i<=o+3;i++)el||i>h||i243?t>>=4:i>217?t>>=3:i>192?t>>=2:i>179&&(t>>=1),((255&e)>>2<<10)+(t>>5<<7)+(i>>1)}static rgb15to24(e){return((e>>10&31)<<3<<16)+((e>>5&31)<<3<<8)+((31&e)<<3)}static rgb15toHsl16(t){const i=(t>>10&31)/31,r=(t>>5&31)/31,s=(31&t)/31;return e.rgbToHsl(i,r,s)}static rgb24to15(e){return((e>>16&255)>>3<<10)+((e>>8&255)>>3<<5)+((255&e)>>3)}static rgb24toHsl16(t){const i=(t>>16&255)/256,r=(t>>8&255)/256,s=(255&t)/256;return e.rgbToHsl(i,r,s)}static rgbToHsl(t,i,r){let s=t;in&&(n=i),r>n&&(n=r);let a=0,o=0;const c=(s+n)/2;s!==n&&(c<.5?o=(n-s)/(n+s):c>=.5&&(o=(n-s)/(2-n-s)),t===n?a=(i-r)/(n-s):i===n?a=(r-t)/(n-s)+2:r===n&&(a=(t-i)/(n-s)+4)),a/=6;const l=256*a|0;let h=256*o|0,d=256*c|0;return h<0?h=0:h>255&&(h=255),d<0?d=0:d>255&&(d=255),e.hsl24to16(l,h,d)}static RGB15_HSL16=new Int32Array(32768);static{for(let t=0;t<32768;t++)e.RGB15_HSL16[t]=e.rgb15toHsl16(t)}static reverseHsl(t){const i=[];for(let r=0;r<32768;r++)e.RGB15_HSL16[r]===t&&i.push(r);return i}},Ll={[Kt.FINDUID]:e=>{const t=e.popInt(),i=Zl.getPlayerByUid(t);i?(e.activePlayer=i,e.pointerAdd(Ft[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.P_FINDUID]:e=>{const t=e.popInt()>>>0,i=Zl.getPlayerByUid(t);e.pointerGet(Ht[e.intOperand])&&e.activePlayer.uid===t?e.pushInt(1):i&&i.canAccess()?(e.activePlayer=i,e.pointerAdd(Ft[e.intOperand]),e.pointerAdd(Ht[e.intOperand]),e.pushInt(1)):e.pushInt(0)},[Kt.STRONGQUEUE]:Vt(Ft,(e=>{const t=Pl(e),i=Br(e.popInt(),Ji),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find queue script: ${r}`);e.activePlayer.enqueueScript(s,3,i,t)})),[Kt.WEAKQUEUE]:Vt(Ft,(e=>{const t=Pl(e),i=Br(e.popInt(),Ji),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find queue script: ${r}`);e.activePlayer.enqueueScript(s,2,i,t)})),[Kt.QUEUE]:Vt(Ft,(e=>{const t=Pl(e),i=Br(e.popInt(),Ji),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find queue script: ${r}`);e.activePlayer.enqueueScript(s,0,i,t)})),[Kt.ANIM]:Vt(Ft,(e=>{const t=e.popInt(),i=e.popInt();e.activePlayer.playAnimation(i,t)})),[Kt.BUFFER_FULL]:Vt(Ft,(e=>{throw new Error('unimplemented')})),[Kt.BUILDAPPEARANCE]:Vt(Ft,(e=>{e.activePlayer.generateAppearance(Br(e.popInt(),Er).id)})),[Kt.CAM_LOOKAT]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,nr);e.activePlayer.cameraPackets.addTail(new Ol(Ts.CAM_LOOKAT,n.x,n.z,i,r,s))})),[Kt.CAM_MOVETO]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,nr);e.activePlayer.cameraPackets.addTail(new Ol(Ts.CAM_MOVETO,n.x,n.z,i,r,s))})),[Kt.CAM_SHAKE]:Vt(Ft,(e=>{const[t,i,r,s]=e.popInts(4);e.activePlayer.write(new Bn(t,i,r,s))})),[Kt.CAM_RESET]:Vt(Ft,(e=>{e.activePlayer.write(new bn)})),[Kt.COORD]:Vt(Ft,(e=>{const t=e.activePlayer;e.pushInt(ji.packCoord(t.level,t.x,t.z))})),[Kt.DISPLAYNAME]:Vt(Ft,(e=>{e.pushString(e.activePlayer.displayName)})),[Kt.FACESQUARE]:Vt(Ft,(e=>{const t=Br(e.popInt(),nr);e.activePlayer.faceSquare(t.x,t.z)})),[Kt.IF_CLOSE]:Vt(Ft,(e=>{e.activePlayer.closeModal()})),[Kt.LAST_COM]:e=>{e.pushInt(e.activePlayer.lastCom)},[Kt.LAST_INT]:e=>{e.pushInt(e.lastInt)},[Kt.LAST_ITEM]:e=>{if(![cs.OPHELD1,cs.OPHELD2,cs.OPHELD3,cs.OPHELD4,cs.OPHELD5,cs.OPHELDU,cs.OPHELDT,cs.INV_BUTTON1,cs.INV_BUTTON2,cs.INV_BUTTON3,cs.INV_BUTTON4,cs.INV_BUTTON5].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastItem)},[Kt.LAST_SLOT]:e=>{if(![cs.OPHELD1,cs.OPHELD2,cs.OPHELD3,cs.OPHELD4,cs.OPHELD5,cs.OPHELDU,cs.OPHELDT,cs.INV_BUTTON1,cs.INV_BUTTON2,cs.INV_BUTTON3,cs.INV_BUTTON4,cs.INV_BUTTON5,cs.INV_BUTTOND].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastSlot)},[Kt.LAST_USEITEM]:e=>{if(![cs.OPHELDU,cs.APOBJU,cs.APLOCU,cs.APNPCU,cs.APPLAYERU,cs.OPOBJU,cs.OPLOCU,cs.OPNPCU,cs.OPPLAYERU].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastUseItem)},[Kt.LAST_USESLOT]:e=>{if(![cs.OPHELDU,cs.APOBJU,cs.APLOCU,cs.APNPCU,cs.APPLAYERU,cs.OPOBJU,cs.OPLOCU,cs.OPNPCU,cs.OPPLAYERU].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastUseSlot)},[Kt.MES]:Vt(Ft,(e=>{const t=e.popString();e.activePlayer.messageGame(t)})),[Kt.NAME]:Vt(Ft,(e=>{e.pushString(e.activePlayer.username)})),[Kt.P_APRANGE]:Vt(Ht,(e=>{e.activePlayer.apRange=Br(e.popInt(),Ji),e.activePlayer.apRangeCalled=!0})),[Kt.P_ARRIVEDELAY]:Vt(Ht,(e=>{e.activePlayer.lastMovement{e.activePlayer.write(new Fa),e.execution=$t.COUNTDIALOG})),[Kt.P_DELAY]:Vt(Ht,(e=>{e.activePlayer.delay=Zl.currentTick+Br(e.popInt(),Ji)+1,e.execution=$t.SUSPENDED})),[Kt.P_OPHELD]:Vt(Ht,(e=>{throw new Error('unimplemented')})),[Kt.P_OPLOC]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji)-1;if(t<0||t>=5)throw new Error(`Invalid oploc: ${t+1}`);e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,e.activeLoc,cs.APLOC1+t)})),[Kt.P_OPNPC]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji)-1;if(t<0||t>=5)throw new Error(`Invalid opnpc: ${t+1}`);e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,e.activeNpc,cs.APNPC1+t,{type:e.activeNpc.type,com:-1})})),[Kt.P_OPNPCT]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji);e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,e.activeNpc,cs.APNPCT,{type:e.activeNpc.type,com:t})})),[Kt.P_PAUSEBUTTON]:Vt(Ht,(e=>{e.execution=$t.PAUSEBUTTON})),[Kt.P_STOPACTION]:Vt(Ht,(e=>{e.activePlayer.stopAction()})),[Kt.P_CLEARPENDINGACTION]:Vt(Ht,(e=>{e.activePlayer.clearPendingAction()})),[Kt.P_TELEJUMP]:Vt(Ht,(e=>{const t=Br(e.popInt(),nr);e.activePlayer.teleJump(t.x,t.z,t.level)})),[Kt.P_TELEPORT]:Vt(Ht,(e=>{const t=Br(e.popInt(),nr);e.activePlayer.teleport(t.x,t.z,t.level)})),[Kt.P_WALK]:Vt(Ht,(e=>{const t=Br(e.popInt(),nr),i=e.activePlayer;i.queueWaypoints(ti(i.level,i.x,i.z,t.x,t.z,i.width,i.width,i.length)),i.updateMovement(!1)})),[Kt.SAY]:Vt(Ft,(e=>{e.activePlayer.say(e.popString())})),[Kt.SOUND_SYNTH]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);e.activePlayer.write(new za(t,i,r))})),[Kt.STAFFMODLEVEL]:Vt(Ft,(e=>{e.pushInt(e.activePlayer.staffModLevel)})),[Kt.STAT]:Vt(Ft,(e=>{const t=Br(e.popInt(),lr);e.pushInt(e.activePlayer.levels[t])})),[Kt.STAT_BASE]:Vt(Ft,(e=>{const t=Br(e.popInt(),lr);e.pushInt(e.activePlayer.baseLevels[t])})),[Kt.STAT_ADD]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,lr),Br(i,Ji),Br(r,Ji);const s=e.activePlayer,n=s.levels[t],a=n+(i+n*r/100);s.levels[t]=Math.min(a,255),3===t&&s.levels[3]>=s.baseLevels[3]&&s.resetHeroPoints()})),[Kt.STAT_SUB]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,lr),Br(i,Ji),Br(r,Ji);const s=e.activePlayer,n=s.levels[t],a=n-(i+n*r/100);s.levels[t]=Math.max(a,0)})),[Kt.SPOTANIM_PL]:Vt(Ft,(e=>{const t=Br(e.popInt(),Ji),i=e.popInt(),r=Br(e.popInt(),fr);e.activePlayer.spotanim(r.id,i,t)})),[Kt.STAT_HEAL]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,lr),Br(i,Ji),Br(r,Ji);const s=e.activePlayer,n=s.baseLevels[t],a=s.levels[t],o=a+(i+a*r/100);s.levels[t]=Math.max(Math.min(o,n),a),3===t&&s.levels[3]>=s.baseLevels[3]&&s.resetHeroPoints()})),[Kt.UID]:Vt(Ft,(e=>{e.pushInt(e.activePlayer.uid)})),[Kt.P_LOGOUT]:Vt(Ht,(e=>{e.activePlayer.logoutRequested=!0})),[Kt.IF_SETCOLOUR]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.write(new Xn(t,Nl.rgb24to15(i)))})),[Kt.IF_OPENCHAT]:Vt(Ft,(e=>{e.activePlayer.openChat(Br(e.popInt(),Ji))})),[Kt.IF_OPENMAINMODALSIDEOVERLAY]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.openMainModalSideOverlay(t,i)})),[Kt.IF_SETHIDE]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.write(new ea(t,1===i))})),[Kt.IF_SETOBJECT]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,Ji),Br(i,mr),Br(r,Ji),e.activePlayer.write(new aa(t,i,r))})),[Kt.IF_SETTABACTIVE]:Vt(Ft,(e=>{e.activePlayer.write(new ma(Br(e.popInt(),Ji)))})),[Kt.IF_SETMODEL]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.write(new ia(t,i))})),[Kt.IF_SETRECOL]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,Ji),e.activePlayer.write(new ua(t,i,r))})),[Kt.IF_SETTABFLASH]:Vt(Ft,(e=>{e.activePlayer.write(new Ya(Br(e.popInt(),Ji)))})),[Kt.IF_SETANIM]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),-1!==i&&e.activePlayer.write(new $n(t,i))})),[Kt.IF_SETTAB]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(i,Ji),e.activePlayer.setTab(t,i)})),[Kt.IF_OPENMAINMODAL]:Vt(Ft,(e=>{e.activePlayer.openMainModal(Br(e.popInt(),Ji))})),[Kt.IF_OPENCHATSTICKY]:Vt(Ft,(e=>{e.activePlayer.openChatSticky(Br(e.popInt(),Ji))})),[Kt.IF_OPENSIDEOVERLAY]:Vt(Ft,(e=>{e.activePlayer.openSideOverlay(Br(e.popInt(),Ji))})),[Kt.IF_SETPLAYERHEAD]:Vt(Ft,(e=>{e.activePlayer.write(new ca(Br(e.popInt(),Ji)))})),[Kt.IF_SETTEXT]:Vt(Ft,(e=>{const t=e.popString(),i=Br(e.popInt(),Ji);e.activePlayer.write(new fa(i,t))})),[Kt.IF_SETNPCHEAD]:Vt(Ft,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,or),e.activePlayer.write(new sa(t,i))})),[Kt.IF_SETPOSITION]:Vt(Ft,(e=>{const[t,i,r]=e.popInts(3);Br(t,Ji),e.activePlayer.write(new ha(t,i,r))})),[Kt.IF_MULTIZONE]:Vt(Ft,(e=>{e.activePlayer.write(new Wa(1===Br(e.popInt(),Ji)))})),[Kt.GIVEXP]:Vt(Ht,(e=>{const[t,i]=e.popInts(2);Br(t,Ji),Br(i,Ji),e.activePlayer.addXp(t,i)})),[Kt.DAMAGE]:e=>{const t=Br(e.popInt(),Ji),i=Br(e.popInt(),pr),r=Br(e.popInt(),Ji),s=Zl.getPlayerByUid(r);s&&s.applyDamage(t,i)},[Kt.IF_SETRESUMEBUTTONS]:Vt(Ft,(e=>{const[t,i,r,s,n]=e.popInts(5);e.activePlayer.resumeButtons=[t,i,r,s,n]})),[Kt.TEXT_GENDER]:Vt(Ft,(e=>{const[t,i]=e.popStrings(2);0==e.activePlayer.gender?e.pushString(t):e.pushString(i)})),[Kt.MIDI_SONG]:e=>{e.activePlayer.playSong(Br(e.popString(),er))},[Kt.MIDI_JINGLE]:e=>{const t=Br(e.popInt(),Ji),i=Br(e.popString(),er);e.activePlayer.playJingle(t,i)},[Kt.SOFTTIMER]:Vt(Ft,(e=>{const t=Pl(e),i=e.popInt(),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find timer script: ${r}`);e.activePlayer.setTimer(1,s,t,i)})),[Kt.CLEARSOFTTIMER]:Vt(Ft,(e=>{e.activePlayer.clearTimer(e.popInt())})),[Kt.SETTIMER]:Vt(Ft,(e=>{const t=Pl(e),i=e.popInt(),r=e.popInt(),s=jt.get(r);if(!s)throw new Error(`Unable to find timer script: ${r}`);e.activePlayer.setTimer(0,s,t,i)})),[Kt.CLEARTIMER]:Vt(Ft,(e=>{e.activePlayer.clearTimer(e.popInt())})),[Kt.HINT_COORD]:e=>{const[t,i,r]=e.popInts(3),s=Br(i,nr);e.activePlayer.hintTile(t,s.x,s.z,r)},[Kt.HINT_STOP]:e=>{e.activePlayer.stopHint()},[Kt.IF_CLOSESTICKY]:e=>{e.activePlayer.closeSticky()},[Kt.P_EXACTMOVE]:Vt(Ht,(e=>{const[t,i,r,s,n]=e.popInts(5),a=Br(t,nr),o=Br(i,nr);e.activePlayer.unsetMapFlag(),e.activePlayer.exactMove(a.x,a.z,o.x,o.z,r,s,n)})),[Kt.BUSY]:e=>{e.pushInt(e.activePlayer.busy()?1:0)},[Kt.BUSY2]:e=>{e.pushInt(e.activePlayer.hasInteraction()||e.activePlayer.hasWaypoints()?1:0)},[Kt.GETQUEUE]:e=>{const t=e.popInt();let i=0;for(let r=e.activePlayer.queue.head();null!==r;r=e.activePlayer.queue.next())r.script.id===t&&i++;for(let r=e.activePlayer.weakQueue.head();null!==r;r=e.activePlayer.weakQueue.next())r.script.id===t&&i++;e.pushInt(i)},[Kt.P_LOCMERGE]:Vt(Ht,(e=>{const[t,i,r,s]=e.popInts(4),n=Br(r,nr),a=Br(s,nr);Zl.mergeLoc(e.activeLoc,e.activePlayer,t,i,n.z,n.x,a.z,a.x)})),[Kt.LAST_LOGIN_INFO]:e=>{const t=e.activePlayer;if(!Sl(t)||null===t.client)return;const i=t.client.remoteAddress;if(null==i)return;const r=new Uint32Array(new Uint8Array(i.split('.').map((e=>parseInt(e)))).reverse().buffer)[0];t.lastLoginInfo(r,0,201,0)},[Kt.BAS_READYANIM]:e=>{e.activePlayer.basReadyAnim=Br(e.popInt(),Tr).id},[Kt.BAS_TURNONSPOT]:e=>{e.activePlayer.basTurnOnSpot=Br(e.popInt(),Tr).id},[Kt.BAS_WALK_F]:e=>{e.activePlayer.basWalkForward=Br(e.popInt(),Tr).id},[Kt.BAS_WALK_B]:e=>{e.activePlayer.basWalkBackward=Br(e.popInt(),Tr).id},[Kt.BAS_WALK_L]:e=>{e.activePlayer.basWalkLeft=Br(e.popInt(),Tr).id},[Kt.BAS_WALK_R]:e=>{e.activePlayer.basWalkRight=Br(e.popInt(),Tr).id},[Kt.BAS_RUNNING]:e=>{const t=e.popInt();e.activePlayer.basRunning=-1!==t?Br(t,Tr).id:-1},[Kt.GENDER]:e=>{e.pushInt(e.activePlayer.gender)},[Kt.HINT_NPC]:e=>{e.activePlayer.hintNpc(Br(e.popInt(),Ji))},[Kt.HINT_PLAYER]:e=>{const t=Br(e.popInt(),Ji),i=Zl.getPlayerByUid(t);i&&e.activePlayer.hintPlayer(i.pid)},[Kt.HEADICONS_GET]:e=>{e.pushInt(e.activePlayer.headicons)},[Kt.HEADICONS_SET]:e=>{e.activePlayer.headicons=Br(e.popInt(),Ji)},[Kt.P_OPOBJ]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji)-1;if(t<0||t>=5)throw new Error(`Invalid opobj: ${t+1}`);e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,e.activeObj,cs.APOBJ1+t)})),[Kt.P_OPPLAYER]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji)-1;if(t<0||t>=5)throw new Error(`Invalid opplayer: ${t+1}`);const i=e._activePlayer2;i&&(e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,i,cs.APPLAYER1+t))})),[Kt.ALLOWDESIGN]:e=>{e.activePlayer.allowDesign=1===Br(e.popInt(),Ji)},[Kt.LAST_TARGETSLOT]:e=>{if(![cs.INV_BUTTOND].includes(e.trigger))throw new Error('is not safe to use in this trigger');e.pushInt(e.activePlayer.lastTargetSlot)},[Kt.WALKTRIGGER]:e=>{e.activePlayer.walktrigger=e.popInt()},[Kt.GETWALKTRIGGER]:e=>{e.pushInt(e.activePlayer.walktrigger)},[Kt.CLEARQUEUE]:e=>{const t=e.popInt();for(let i=e.activePlayer.queue.head();null!==i;i=e.activePlayer.queue.next())i.script.id===t&&i.unlink();for(let i=e.activePlayer.weakQueue.head();null!==i;i=e.activePlayer.weakQueue.next())i.script.id===t&&i.unlink()},[Kt.HEALENERGY]:e=>{const t=Br(e.popInt(),Ji),i=e.activePlayer;i.runenergy=Math.min(Math.max(i.runenergy+t,0),1e4)},[Kt.AFK_EVENT]:e=>{e.pushInt(e.activePlayer.afkEventReady?1:0),e.activePlayer.afkEventReady=!1},[Kt.LOWMEMORY]:e=>{e.pushInt(e.activePlayer.lowMemory?1:0)},[Kt.SETIDKIT]:e=>{const[t,i]=e.popInts(2),r=Br(t,Ar);let s=r.type;1===e.activePlayer.gender&&(s-=7),e.activePlayer.body[s]=r.id;let n=r.type;1===e.activePlayer.gender&&(n-=7);let a=-1;0===n||1===n?a=0:2===n||3===n?a=1:4===n||(5===n?a=2:6===n&&(a=3)),-1!==a&&(e.activePlayer.colors[a]=i)},[Kt.SETGENDER]:e=>{const t=Br(e.popInt(),br);for(let i=0;i<7;i++){e.activePlayer.body[i]=-1;for(let r=0;r{const t=Br(e.popInt(),Rr);e.activePlayer.colors[4]=t},[Kt.P_OPPLAYERT]:Vt(Ht,(e=>{const t=Br(e.popInt(),Ji),i=e._activePlayer2;i&&(e.activePlayer.stopAction(),e.activePlayer.setInteraction(hs.SCRIPT,i,cs.APPLAYERT,{type:-1,com:t}))})),[Kt.FINDHERO]:Vt(Ft,(e=>{const t=e.activePlayer.findHero();if(-1===t)return void e.pushInt(0);const i=Zl.getPlayerByUid(t);i?(e._activePlayer2=i,e.pointerAdd(Gt.ActivePlayer2),e.pushInt(1)):e.pushInt(0)})),[Kt.BOTH_HEROPOINTS]:Vt(Ft,(e=>{const t=Br(e.popInt(),Ji),i=1===e.intOperand,r=i?e._activePlayer2:e._activePlayer,s=i?e._activePlayer:e._activePlayer2;if(!r||!s)throw new Error('player is null');s.addHero(r.uid,t)})),[Kt.P_ANIMPROTECT]:Vt(Ht,(e=>{e.activePlayer.animProtect=Br(e.popInt(),Ji)})),[Kt.RUNENERGY]:Vt(Ft,(e=>{const t=e.activePlayer;e.pushInt(t.runenergy)})),[Kt.WEIGHT]:Vt(Ht,(e=>{e.pushInt(e.activePlayer.runweight)})),[Kt.LAST_COORD]:Vt(Ft,(e=>{e.pushInt(ji.packCoord(e.activePlayer.level,e.activePlayer.lastX,e.activePlayer.lastZ))}))};function Pl(e){const t=e.popString(),i=[];for(let r=t.length-1;r>=0;r--){const s=t.charAt(r);i[r]='s'===s?e.popString():e.popInt()}return i}var wl=Ll,bl={[Kt.MAP_CLOCK]:e=>{e.pushInt(Zl.currentTick)},[Kt.MAP_MEMBERS]:e=>{e.pushInt(vt.NODE_MEMBERS?1:0)},[Kt.MAP_PLAYERCOUNT]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,nr);let n=0;for(let e=Math.floor(r.x/8);e<=Math.ceil(s.x/8);e++)for(let t=Math.floor(r.z/8);t<=Math.ceil(s.z/8);t++)for(const i of Zl.getZone(e<<3,t<<3,r.level).getAllPlayersSafe())i.x>=r.x&&i.x<=s.x&&i.z>=r.z&&i.z<=s.z&&n++;e.pushInt(n)},[Kt.HUNTALL]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr);Br(i,Ji);const n=Br(r,vr);e.huntIterator=new ts(Zl.currentTick,s.level,s.x,s.z,i,n,-1,-1,je.PLAYER)},[Kt.HUNTNEXT]:e=>{const t=e.huntIterator?.next();if(t&&!t.done){if(!(t.value instanceof Do))throw new Error('[ServerOps] huntnext command must result instance of Player.');e.activePlayer=t.value,e.pointerAdd(Ft[e.intOperand]),e.pushInt(1)}else e.pushInt(0)},[Kt.NPC_HUNTALL]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr);Br(i,Ji);const n=Br(r,vr);e.huntIterator=new ts(Zl.currentTick,s.level,s.x,s.z,i,n,-1,-1,je.NPC)},[Kt.NPC_HUNTNEXT]:e=>{const t=e.huntIterator?.next();if(t&&!t.done){if(!(t.value instanceof kl))throw new Error('[ServerOps] npc_huntnext command must result instance of Npc.');e.activeNpc=t.value,e.pointerAdd(kt[e.intOperand]),e.pushInt(1)}else e.pushInt(0)},[Kt.INZONE]:e=>{const[t,i,r]=e.popInts(3),s=Br(t,nr),n=Br(i,nr),a=Br(r,nr);a.xn.x||a.leveln.level||a.zn.z?e.pushInt(0):e.pushInt(1)},[Kt.LINEOFWALK]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,nr);r.level===s.level?e.pushInt(gi(r.level,r.x,r.z,s.x,s.z,1,1,1,1)?1:0):e.pushInt(0)},[Kt.STAT_RANDOM]:e=>{const[t,i,r]=e.popInts(3),s=Math.floor(i*(99-t)/98)+Math.floor(r*(t-1)/98)+1,n=Math.floor(256*Math.random());e.pushInt(s>n?1:0)},[Kt.SPOTANIM_MAP]:e=>{const[t,i,r,s]=e.popInts(4),n=Br(i,nr),a=Br(t,fr);Zl.animMap(n.level,n.x,n.z,a.id,r,s)},[Kt.DISTANCE]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,nr);e.pushInt(ji.distanceToSW(r,s))},[Kt.MOVECOORD]:e=>{const[t,i,r,s]=e.popInts(4),n=Br(t,nr);e.pushInt(ji.packCoord(n.level+r,n.x+i,n.z+s))},[Kt.SEQLENGTH]:e=>{e.pushInt(Br(e.popInt(),Tr).duration)},[Kt.SPLIT_INIT]:e=>{const[t,i,r]=e.popInts(3);let s=e.popString();const n=Br(r,Or);if(s.startsWith('')){const t=s.substring(3,s.indexOf('>'));e.splitMesanim=ot.getId(t),s=s.substring(s.indexOf('>')+1)}else e.splitMesanim=-1;e.splitPages=[];const a=n.split(s,t);for(;a.length>0;)e.splitPages.push(a.splice(0,i))},[Kt.SPLIT_GET]:e=>{const[t,i]=e.popInts(2);e.pushString(e.splitPages[t][i])},[Kt.SPLIT_PAGECOUNT]:e=>{e.pushInt(e.splitPages.length)},[Kt.SPLIT_LINECOUNT]:e=>{const t=e.popInt();e.pushInt(e.splitPages[t].length)},[Kt.SPLIT_GETANIM]:e=>{const t=e.popInt();-1!==e.splitMesanim?e.pushInt(Br(e.splitMesanim,Nr).len[e.splitPages[t].length-1]):e.pushInt(-1)},[Kt.STRUCT_PARAM]:e=>{const[t,i]=e.popInts(2),r=Br(i,ar),s=Br(t,Lr);r.isString()?e.pushString(rt(r.id,s,r.defaultString)):e.pushInt(st(r.id,s,r.defaultInt))},[Kt.COORDX]:e=>{e.pushInt(Br(e.popInt(),nr).x)},[Kt.COORDY]:e=>{e.pushInt(Br(e.popInt(),nr).level)},[Kt.COORDZ]:e=>{e.pushInt(Br(e.popInt(),nr).z)},[Kt.PLAYERCOUNT]:e=>{e.pushInt(Zl.getTotalPlayers())},[Kt.MAP_BLOCKED]:e=>{const t=Br(e.popInt(),nr);e.pushInt(ui(t.x,t.z,t.level,Ri.WALK_BLOCKED)?1:0)},[Kt.MAP_INDOORS]:e=>{const t=Br(e.popInt(),nr);e.pushInt(ui(t.x,t.z,t.level,Ri.ROOF)?1:0)},[Kt.LINEOFSIGHT]:e=>{const[t,i]=e.popInts(2),r=Br(t,nr),s=Br(i,nr);r.level===s.level?e.pushInt(fi(r.level,r.x,r.z,s.x,s.z,1,1,1,1)?1:0):e.pushInt(0)},[Kt.WORLD_DELAY]:e=>{e.execution=$t.WORLD_SUSPENDED},[Kt.PROJANIM_PL]:e=>{const[t,i,r,s,n,a,o,c,l]=e.popInts(9),h=Br(t,nr),d=Br(r,fr),u=Zl.getPlayerByUid(i);if(!u)throw new Error(`attempted to use invalid player uid: ${i}`);Zl.mapProjAnim(h.level,h.x,h.z,u.x,u.z,-u.pid-1,d.id,s+100,n+100,a,o,c,l)},[Kt.PROJANIM_NPC]:e=>{const[t,i,r,s,n,a,o,c,l]=e.popInts(9),h=Br(t,nr),d=Br(r,fr),u=65535&i,p=Zl.getNpc(u);if(!p)throw new Error(`attempted to use invalid npc uid: ${i}`);Zl.mapProjAnim(h.level,h.x,h.z,p.x,p.z,p.nid+1,d.id,s+100,n+100,a,o,c,l)},[Kt.PROJANIM_MAP]:e=>{const[t,i,r,s,n,a,o,c,l]=e.popInts(9),h=Br(r,fr),d=Br(t,nr),u=Br(i,nr);Zl.mapProjAnim(d.level,d.x,d.z,u.x,u.z,0,h.id,s+100,n,a,o,c,l)},[Kt.MAP_LOCADDUNSAFE]:e=>{const t=Br(e.popInt(),nr);for(const i of Zl.getZone(t.x,t.z,t.level).getAllLocsUnsafe()){if(1!==Br(i.type,tr).active)continue;const r=_i(i.shape);if(i.checkLifeCycle(Zl.currentTick)||r!==ki.WALL)if(r===ki.WALL){if(i.x===t.x&&i.z===t.z)return void e.pushInt(1)}else if(r===ki.GROUND){const r=i.angle===Ui.NORTH||i.angle===Ui.SOUTH?i.length:i.width,s=i.angle===Ui.NORTH||i.angle===Ui.SOUTH?i.width:i.length;for(let n=0;n{e.pushInt(Zl.getTotalNpcs())},[Kt.ZONECOUNT]:e=>{e.pushInt(Zl.getTotalZones())},[Kt.LOCCOUNT]:e=>{e.pushInt(Zl.getTotalLocs())},[Kt.OBJCOUNT]:e=>{e.pushInt(Zl.getTotalObjs())}},Rl=bl,Bl={[Kt.APPEND_NUM]:e=>{const t=e.popString(),i=e.popInt();e.pushString(t+i)},[Kt.APPEND]:e=>{const[t,i]=e.popStrings(2);e.pushString(t+i)},[Kt.APPEND_SIGNNUM]:e=>{const t=e.popString(),i=e.popInt();i>=0?e.pushString(`${t}+${i}`):e.pushString(t+i)},[Kt.LOWERCASE]:e=>{e.pushString(e.popString().toLowerCase())},[Kt.TOSTRING]:e=>{e.pushString(e.popInt().toString())},[Kt.COMPARE]:e=>{const[t,i]=e.popStrings(2);e.pushInt(function(e,t){const i=e.length,r=t.length,s=Math.min(i,r);let n=0;for(;n{const t=e.popInt(),[i,r]=e.popStrings(2);e.pushString(1===t?i:r)},[Kt.APPEND_CHAR]:e=>{const t=e.popString(),i=e.popInt();e.pushString(t+String.fromCharCode(i))},[Kt.STRING_LENGTH]:e=>{e.pushInt(e.popString().length)},[Kt.SUBSTRING]:e=>{const t=e.popString(),[i,r]=e.popInts(2);e.pushString(t.substring(i,r))},[Kt.STRING_INDEXOF_CHAR]:e=>{const t=e.popString(),i=String.fromCharCode(e.popInt());e.pushInt(t.indexOf(i))},[Kt.STRING_INDEXOF_STRING]:e=>{const t=e.popString(),i=e.popString();e.pushInt(t.indexOf(i))}};var Ul=Bl,Dl=class e{static HANDLERS={...Fr,...Rl,...wl,...us,...ns,...Es,...ps,...as,..._s,...Zr,...zr,...Ul,...ys,...Hr,...Wr};static init(e,t=null,i=null,r=[]){const s=new $t(e,r);return s.self=t,t instanceof Do?(s._activePlayer=t,s.pointerAdd(Gt.ActivePlayer)):t instanceof kl?(s._activeNpc=t,s.pointerAdd(Gt.ActiveNpc)):t instanceof ss?(s._activeLoc=t,s.pointerAdd(Gt.ActiveLoc)):t instanceof $r&&(s._activeObj=t,s.pointerAdd(Gt.ActiveObj)),i instanceof Do?t instanceof Do?(s._activePlayer2=i,s.pointerAdd(Gt.ActivePlayer2)):(s._activePlayer=i,s.pointerAdd(Gt.ActivePlayer)):i instanceof kl?t instanceof kl?(s._activeNpc2=i,s.pointerAdd(Gt.ActiveNpc2)):(s._activeNpc=i,s.pointerAdd(Gt.ActiveNpc)):i instanceof ss?t instanceof ss?(s._activeLoc2=i,s.pointerAdd(Gt.ActiveLoc2)):(s._activeLoc=i,s.pointerAdd(Gt.ActiveLoc)):i instanceof $r&&(t instanceof $r?(s._activeObj2=i,s.pointerAdd(Gt.ActiveObj2)):(s._activeObj=i,s.pointerAdd(Gt.ActiveObj))),s}static execute(t,i=!1,r=!1){if(!t||!t.script||!t.script.info)return $t.ABORTED;try{i&&t.reset(),t.execution!==$t.RUNNING&&t.executionHistory.push(t.execution),t.execution=$t.RUNNING;const s=1e3*performance.now();for(;t.execution===$t.RUNNING;){if(t.pc>=t.script.opcodes.length||t.pc<-1)throw new Error('Invalid program counter: '+t.pc+', max expected: '+t.script.opcodes.length);if(!r&&t.opcount>5e5)throw new Error('Too many instructions');t.opcount++,e.executeInner(t,t.script.opcodes[++t.pc])}const n=1e3*performance.now()-s|0;if(vt.NODE_DEBUG_PROFILE&&n>1e3){const e=`Warning [cpu time]: Script: ${t.script.info.scriptName}, time: ${n}us, opcount: ${t.opcount}`;t.self instanceof Do?t.self.wrappedMessageGame(e):console.warn(e)}}catch(e){if(t.pc>=0&&t.pc>16&1:i<=Kt.POP_ARRAY_INT&&(r=0),e.message=Kt[i].toLowerCase()+' '+e.message,r&&(e.message='.'+e.message)}if(t.self instanceof Do){t.self.wrappedMessageGame(`script error: ${e.message}`),t.self.wrappedMessageGame(`file: ${path3.basename(t.script.info.sourceFilePath)}`),t.self.wrappedMessageGame(''),t.self.wrappedMessageGame('stack backtrace:'),t.self.wrappedMessageGame(` 1: ${t.script.name} - ${t.script.fileName}:${t.script.lineNumber(t.pc)}`);let i=1;for(let e=t.fp;e>0;e--){const r=t.frames[e];r&&(i++,t.self.wrappedMessageGame(` ${i}: ${r.script.name} - ${r.script.fileName}:${r.script.lineNumber(r.pc)}`))}for(let e=t.debugFp;e>=0;e--){const r=t.debugFrames[e];r&&(i++,t.self.wrappedMessageGame(` ${i}: ${r.script.name} - ${r.script.fileName}:${r.script.lineNumber(r.pc)}`))}}console.error(`script error: ${e.message}`),console.error(`file: ${path3.basename(t.script.info.sourceFilePath)}`),console.error(''),console.error('stack backtrace:'),console.error(` 1: ${t.script.name} - ${t.script.fileName}:${t.script.lineNumber(t.pc)}`);let i=1;for(let e=t.fp;e>0;e--){const r=t.frames[e];r&&(i++,console.error(` ${i}: ${r.script.name} - ${r.script.fileName}:${r.script.lineNumber(r.pc)}`))}for(let e=t.debugFp;e>=0;e--){const r=t.debugFrames[e];r&&(i++,console.error(` ${i}: ${r.script.name} - ${r.script.fileName}:${r.script.lineNumber(r.pc)}`))}t.execution=$t.ABORTED}return t.execution}static executeInner(t,i){const r=e.HANDLERS[i];if(!r)throw new Error(`Unknown opcode ${i}`);r(t)}},kl=class e extends Ns{static ANIM=2;static FACE_ENTITY=4;static SAY=8;static DAMAGE=16;static CHANGE_TYPE=32;static SPOTANIM=64;static FACE_COORD=128;nid;type;uid;origType;startX;startZ;levels=new Uint8Array(6);baseLevels=new Uint8Array(6);vars;varsString;activeScript=null;delay=0;queue=new Ce;timerInterval=0;timerClock=0;huntMode=-1;nextHuntTick=-1;huntrange=5;nextPatrolTick=-1;nextPatrolPoint=0;delayedPatrol=!1;heroPoints=new Array(16);constructor(t,i,r,s,n,a,o,c,l,h){super(t,i,r,s,n,a,l,h,Os.NAIVE,e.FACE_COORD,e.FACE_ENTITY),this.nid=o,this.type=c,this.uid=c<<16|o,this.startX=this.x,this.startZ=this.z,this.origType=c;const d=ft.get(c);for(let e=0;et&&t.uid===e));if(-1!==i)return void(this.heroPoints[i].points+=t);const r=this.heroPoints.findIndex((e=>e&&-1===e.uid));-1===r||(this.heroPoints[r]={uid:e,points:t})}findHero(){return this.heroPoints.sort(((e,t)=>t.points-e.points)),this.heroPoints[0]?.uid??-1}getVar(e){const t=Ot.get(e);return t.type===Pe.STRING?this.varsString[t.id]:this.vars[t.id]}setVar(e,t){const i=Ot.get(e);i.type===Pe.STRING&&'string'==typeof t?this.varsString[i.id]=t:'number'==typeof t&&(this.vars[i.id]=t)}resetEntity(e){if(e){this.type=this.origType,this.uid=this.type<<16|this.nid,this.faceX=-1,this.faceZ=-1,this.orientationX=-1,this.orientationZ=-1;for(let e=0;et.maxrange&&e>t.maxrange)return!1}if(this.targetOp>=Xe.OPPLAYER1&&this.targetOp<=Xe.OPPLAYER5){const e=Math.abs(this.target.x-this.startX),i=Math.abs(this.target.z-this.startZ);if(Math.max(e,i)>t.maxrange+1)return this.defaultMode(),!1;if(e===t.maxrange+1&&i===t.maxrange+1)return this.defaultMode(),!1}else if(this.targetOp>=Xe.APPLAYER1&&this.targetOp<=Xe.APPLAYER5&&ji.distanceToSW(this.target,{x:this.startX,z:this.startZ})>t.maxrange+t.attackrange)return this.defaultMode(),!1}if(e&&this.target instanceof Ns&&!this.interacted&&-1===this.walktrigger&&this.pathToPathingTarget(),-1!==this.walktrigger){const e=ft.get(this.type),t=jt.getByTrigger(cs.AI_QUEUE1+this.walktrigger,e.id,e.category);if(this.walktrigger=-1,t){const e=Dl.init(t,this,null,[this.walktriggerArg]);Dl.execute(e)}}return this.moveSpeed!==Is.INSTANT&&(this.moveSpeed=this.defaultMoveSpeed()),super.processMovement()}blockWalkFlag(){return this.moveRestrict===dt.NORMAL?Ri.NPC:this.moveRestrict===dt.BLOCKED?Ri.OPEN:this.moveRestrict===dt.BLOCKED_NORMAL||this.moveRestrict===dt.INDOORS||this.moveRestrict===dt.OUTDOORS?Ri.NPC:this.moveRestrict===dt.NOMOVE?Ri.NULL:this.moveRestrict===dt.PASSTHRU?Ri.OPEN:Ri.NULL}defaultMoveSpeed(){return Is.WALK}delayed(){return this.delay>Zl.currentTick}setTimer(e){this.timerInterval=e,this.timerClock=0}executeScript(e){if(!e)return;const t=Dl.execute(e);t!==$t.FINISHED&&t!==$t.ABORTED?t===$t.WORLD_SUSPENDED?Zl.enqueueScript(e,e.popInt()):t===$t.NPC_SUSPENDED?e.activeNpc.activeScript=e:e.activePlayer.activeScript=e:e===this.activeScript&&(this.activeScript=null),e.pointerGet(Gt.ProtectedActivePlayer)&&e._activePlayer&&(e._activePlayer.protect=!1,e.pointerRemove(Gt.ProtectedActivePlayer)),e.pointerGet(Gt.ProtectedActivePlayer2)&&e._activePlayer2&&(e._activePlayer2.protect=!1,e.pointerRemove(Gt.ProtectedActivePlayer2))}processTimers(){if(0!==this.timerInterval&&++this.timerClock>=this.timerInterval){this.timerClock=0;const e=ft.get(this.type),t=jt.getByTrigger(cs.AI_TIMER,e.id,e.category);t&&this.executeScript(Dl.init(t,this))}}processQueue(){for(let e=this.queue.head();null!==e;e=this.queue.next())if(this.delayed()||e.delay--,!this.delayed()&&e.delay<=0){const t=Dl.init(e.script,this,null,e.args);t.lastInt=e.lastInt,this.executeScript(t),e.unlink()}}enqueueScript(e,t=0,i=0){const r=new As(0,e,[],t);r.lastInt=i,this.queue.addTail(r)}randomWalk(e){const t=Math.round(Math.random()*(2*e)-e),i=Math.round(Math.random()*(2*e)-e),r=this.startX+t,s=this.startZ+i;r===this.x&&s===this.z||this.queueWaypoint(r,s)}processNpcModes(){this.targetOp===Xe.NULL?this.defaultMode():this.targetOp===Xe.NONE?this.noMode():this.targetOp===Xe.WANDER?this.wanderMode():this.targetOp===Xe.PATROL?this.patrolMode():this.targetOp===Xe.PLAYERESCAPE?this.playerEscapeMode():this.targetOp===Xe.PLAYERFOLLOW?this.playerFollowMode():this.targetOp===Xe.PLAYERFACE?this.playerFaceMode():this.targetOp===Xe.PLAYERFACECLOSE?this.playerFaceCloseMode():this.aiMode()}noMode(){this.clearInteraction(),this.updateMovement(!1),this.targetOp=Xe.NONE}defaultMode(){this.clearInteraction(),this.updateMovement(!1);const e=ft.get(this.type);this.targetOp=e.defaultmode}wanderMode(){const e=ft.get(this.type);e.moverestrict!==dt.NOMOVE&&Math.random()<.125&&this.randomWalk(e.wanderrange),this.updateMovement(!1)}patrolMode(){const e=ft.get(this.type),t=e.patrolCoord,i=e.patrolDelay[this.nextPatrolPoint];let r=ji.unpackCoord(t[this.nextPatrolPoint]);this.updateMovement(!1),this.hasWaypoints()||this.target||this.queueWaypoint(r.x,r.z),(this.x!==r.x||this.z!==r.z)&&Zl.currentTick>=this.nextPatrolTick&&this.teleport(r.x,r.z,r.level),this.x!==r.x||this.z!==r.z||this.delayedPatrol||(this.nextPatrolTick=Zl.currentTick+i,this.delayedPatrol=!0),this.nextPatrolTick>Zl.currentTick||(this.nextPatrolPoint=(this.nextPatrolPoint+1)%t.length,this.nextPatrolTick=Zl.currentTick+30,this.delayedPatrol=!1,r=ji.unpackCoord(t[this.nextPatrolPoint]),this.queueWaypoint(r.x,r.z))}playerEscapeMode(){if(!this.target)return void this.defaultMode();if(!(this.target instanceof Do))throw new Error('[Npc] Target must be a Player for playerescape mode.');if(null===Zl.getPlayerByUid(this.target.uid))return void this.defaultMode();if(ji.distanceToSW(this,this.target)>25)return void this.defaultMode();let e,t;this.target.x>=this.x&&this.target.z>=this.z?(e=Wi,t=Ri.WALL_SOUTH|Ri.WALL_WEST):this.target.x>=this.x&&this.target.z=this.z?(e=zi,t=Ri.WALL_SOUTH|Ri.WALL_EAST):(e=Hi,t=Ri.WALL_NORTH|Ri.WALL_EAST);const i=ji.moveX(this.x,e),r=ji.moveZ(this.z,e);if(ui(i,r,this.level,t))return void this.defaultMode();const s={x:i,z:r,level:this.level};if(ji.distanceToSW(s,{x:this.startX,z:this.startZ})e.maxrange?this.defaultMode():this.updateMovement(!1)}playerFaceCloseMode(){if(this.target){if(!(this.target instanceof Do))throw new Error('[Npc] Target must be a Player for playerfaceclose mode.');null!=Zl.getPlayerByUid(this.target.uid)&&this.level===this.target.level?ji.distanceTo(this,this.target)>1?this.defaultMode():this.updateMovement(!1):this.defaultMode()}else this.defaultMode()}aiMode(){if(this.delayed()||!this.target)return void this.defaultMode();if(this.target.level!==this.level)return void this.defaultMode();if(this.target instanceof e&&(void 0===Zl.getNpc(this.target.nid)||this.target.delayed()))return void this.defaultMode();if(this.target instanceof e&&-1!==this.targetSubject.type&&null===Zl.getNpcByUid(this.targetSubject.type<<16|this.target.nid))return void this.defaultMode();if(this.target instanceof $r&&null===Zl.getObj(this.target.x,this.target.z,this.level,this.target.type,-1))return void this.defaultMode();if(this.target instanceof ss&&null===Zl.getLoc(this.target.x,this.target.z,this.level,this.target.type))return void this.defaultMode();if(this.target instanceof Do&&null===Zl.getPlayerByUid(this.target.uid))return void this.defaultMode();const t=ft.get(this.type),i=this.targetOp>=Xe.APNPC1&&this.targetOp<=Xe.APNPC5||this.targetOp>=Xe.APPLAYER1&&this.targetOp<=Xe.APPLAYER5||this.targetOp>=Xe.APLOC1&&this.targetOp<=Xe.APLOC5||this.targetOp>=Xe.APOBJ1&&this.targetOp<=Xe.APOBJ5,r=!i,s=this.getTrigger();s&&r&&this.inOperableDistance(this.target)&&this.target instanceof Ns||s&&i&&this.inApproachDistance(t.attackrange,this.target)?(this.executeScript(Dl.init(s,this,this.target)),this.interacted=!0,this.clearWaypoints()):this.inOperableDistance(this.target)&&this.target instanceof Ns&&(this.target=null,this.interacted=!0,this.clearWaypoints());const n=this.updateMovement();n&&(this.alreadyFacedEntity=!1),this.target&&!this.interacted&&(this.interacted=!1,s&&r&&this.inOperableDistance(this.target)&&(this.target instanceof Ns||!n)||s&&i&&this.inApproachDistance(t.attackrange,this.target)?(this.executeScript(Dl.init(s,this,this.target)),this.interacted=!0,this.clearWaypoints()):this.inOperableDistance(this.target)&&(this.target instanceof Ns||!n)&&(this.target=null,this.interacted=!0,this.clearWaypoints()))}getTrigger(){const e=this.getTriggerForMode(this.targetOp);return e?jt.getByTrigger(e,this.type,-1)??null:null}getTriggerForMode(e){return e===Xe.OPPLAYER1?cs.AI_OPPLAYER1:e===Xe.OPPLAYER2?cs.AI_OPPLAYER2:e===Xe.OPPLAYER3?cs.AI_OPPLAYER3:e===Xe.OPPLAYER4?cs.AI_OPPLAYER4:e===Xe.OPPLAYER5?cs.AI_OPPLAYER5:e===Xe.APPLAYER1?cs.AI_APPLAYER1:e===Xe.APPLAYER2?cs.AI_APPLAYER2:e===Xe.APPLAYER3?cs.AI_APPLAYER3:e===Xe.APPLAYER4?cs.AI_APPLAYER4:e===Xe.APPLAYER5?cs.AI_APPLAYER5:e===Xe.OPLOC1?cs.AI_OPLOC1:e===Xe.OPLOC2?cs.AI_OPLOC2:e===Xe.OPLOC3?cs.AI_OPLOC3:e===Xe.OPLOC4?cs.AI_OPLOC4:e===Xe.OPLOC5?cs.AI_OPLOC5:e===Xe.APLOC1?cs.AI_APLOC1:e===Xe.APLOC2?cs.AI_APLOC2:e===Xe.APLOC3?cs.AI_APLOC3:e===Xe.APLOC4?cs.AI_APLOC4:e===Xe.APLOC5?cs.AI_APLOC5:e===Xe.OPOBJ1?cs.AI_OPOBJ1:e===Xe.OPOBJ2?cs.AI_OPOBJ2:e===Xe.OPOBJ3?cs.AI_OPOBJ3:e===Xe.OPOBJ4?cs.AI_OPOBJ4:e===Xe.OPOBJ5?cs.AI_OPOBJ5:e===Xe.APOBJ1?cs.AI_APOBJ1:e===Xe.APOBJ2?cs.AI_APOBJ2:e===Xe.APOBJ3?cs.AI_APOBJ3:e===Xe.APOBJ4?cs.AI_APOBJ4:e===Xe.APOBJ5?cs.AI_APOBJ5:e===Xe.OPNPC1?cs.AI_OPNPC1:e===Xe.OPNPC2?cs.AI_OPNPC2:e===Xe.OPNPC3?cs.AI_OPNPC3:e===Xe.OPNPC4?cs.AI_OPNPC4:e===Xe.OPNPC5?cs.AI_OPNPC5:e===Xe.APNPC1?cs.AI_APNPC1:e===Xe.APNPC2?cs.AI_APNPC2:e===Xe.APNPC3?cs.AI_APNPC3:e===Xe.APNPC4?cs.AI_APNPC4:e===Xe.APNPC5?cs.AI_APNPC5:e===Xe.QUEUE1?cs.AI_QUEUE1:e===Xe.QUEUE2?cs.AI_QUEUE2:e===Xe.QUEUE3?cs.AI_QUEUE3:e===Xe.QUEUE4?cs.AI_QUEUE4:e===Xe.QUEUE5?cs.AI_QUEUE5:e===Xe.QUEUE6?cs.AI_QUEUE6:e===Xe.QUEUE7?cs.AI_QUEUE7:e===Xe.QUEUE8?cs.AI_QUEUE8:e===Xe.QUEUE9?cs.AI_QUEUE9:e===Xe.QUEUE10?cs.AI_QUEUE10:e===Xe.QUEUE11?cs.AI_QUEUE11:e===Xe.QUEUE12?cs.AI_QUEUE12:e===Xe.QUEUE13?cs.AI_QUEUE13:e===Xe.QUEUE14?cs.AI_QUEUE14:e===Xe.QUEUE15?cs.AI_QUEUE15:e===Xe.QUEUE16?cs.AI_QUEUE16:e===Xe.QUEUE17?cs.AI_QUEUE17:e===Xe.QUEUE18?cs.AI_QUEUE18:e===Xe.QUEUE19?cs.AI_QUEUE19:e===Xe.QUEUE20?cs.AI_QUEUE20:null}huntAll(){if(this.nextHuntTick>Zl.currentTick)return;const e=Je.get(this.huntMode);if(e.type===je.OFF)return;if(e.nobodyNear===qe.PAUSEHUNT&&!Zl.getZoneGrid(this.level).isFlagged(ji.zone(this.x),ji.zone(this.z),5))return;if(!e.findKeepHunting&&null!==this.target)return;let t;if(t=e.type===je.PLAYER?this.huntPlayers(e):e.type===je.NPC?this.huntNpcs(e):e.type===je.OBJ?this.huntObjs(e):this.huntLocs(e),t.length>0){const i=t[Math.floor(Math.random()*t.length)];this.setInteraction(hs.SCRIPT,i,e.findNewMode)}this.nextHuntTick=Zl.currentTick+e.rate}huntPlayers(e){const t=ft.get(this.type),i=[],r=new ts(Zl.currentTick,this.level,this.x,this.z,this.huntrange,e.checkVis,-1,-1,je.PLAYER),s=e.findNewMode>=Xe.OPPLAYER1&&e.findNewMode<=Xe.OPPLAYER5;for(const n of r){if(!(n instanceof Do))throw new Error('[Npc] huntAll must be of type Player here.');if(s){const e=Math.abs(n.x-this.startX),i=Math.abs(n.z-this.startZ);if(Math.max(e,i)>t.maxrange+1)continue;if(e===t.maxrange+1&&i===t.maxrange+1)continue}else if(ji.distanceToSW(n,{x:this.startX,z:this.startZ})>t.maxrange+t.attackrange)continue;if((!e.checkAfk||!n.zonesAfk())&&((e.checkNotTooStrong!==Ke.OUTSIDE_WILDERNESS||n.isInWilderness()||!(n.combatLevel>2*t.vislevel))&&!(-1!==e.checkNotCombat&&n.getVar(e.checkNotCombat)+8>Zl.currentTick||-1!==e.checkNotCombatSelf&&this.getVar(e.checkNotCombatSelf)>=Zl.currentTick))){if(-1!==e.checkInv){let t=0;if(-1!==e.checkObj?t=n.invTotal(e.checkInv,e.checkObj):-1!==e.checkObjParam&&(t=n.invTotalParam(e.checkInv,e.checkObjParam)),te.checkInvMaxQuantity)continue}e.checkNotBusy&&n.busy()||i.push(n)}}return i}huntNpcs(e){return Array.from(new ts(Zl.currentTick,this.level,this.x,this.z,this.huntrange,e.checkVis,e.checkNpc,e.checkCategory,je.NPC))}huntObjs(e){return Array.from(new ts(Zl.currentTick,this.level,this.x,this.z,this.huntrange,e.checkVis,e.checkObj,e.checkCategory,je.OBJ))}huntLocs(e){return Array.from(new ts(Zl.currentTick,this.level,this.x,this.z,this.huntrange,e.checkVis,e.checkLoc,e.checkCategory,je.SCENERY))}playAnimation(t,i){t>=It.count||(-1==t||-1==this.animId||It.get(t).priority>It.get(this.animId).priority||0===It.get(this.animId).priority)&&(this.animId=t,this.animDelay=i,this.mask|=e.ANIM)}spotanim(t,i,r){this.graphicId=t,this.graphicHeight=i,this.graphicDelay=r,this.mask|=e.SPOTANIM}applyDamage(t,i){this.damageTaken=t,this.damageType=i;const r=this.levels[pt.HITPOINTS];r-t<=0?(this.levels[pt.HITPOINTS]=0,this.damageTaken=r):this.levels[pt.HITPOINTS]=r-t,this.mask|=e.DAMAGE}say(t){t&&(this.chat=t,this.mask|=e.SAY)}faceSquare(t,i){this.faceX=2*t+1,this.faceZ=2*i+1,this.orientationX=this.faceX,this.orientationZ=this.faceZ,this.mask|=e.FACE_COORD}changeType(t){this.type=t,this.mask|=e.CHANGE_TYPE,this.uid=t<<16|this.nid;const i=ft.get(t);this.setTimer(i.timer)}},Ml=class e{static OPEN=0;static BLOCKED=1;static BRIDGE=2;static ROOF=4;static WALL=8;static LOWMEMORY=16;static Y=4;static X=64;static Z=64;static MAPSQUARE=e.X*e.Y*e.Z;init(t){console.time('Loading game map');const i='data/pack/server/maps/',r=fs26.readdirSync(i).filter((e=>'m'===e[0]));for(let s=0;s(oe(),ee))),s=r.map((async r=>{console.log('init ',r);const[s,n]=r.substring(1).split('_').map(Number),a=s<<6,o=n<<6,[c,l,h,d]=await Promise.all([Oe.loadAsync(`${i}n${s}_${n}`),await Oe.loadAsync(`${i}o${s}_${n}`),await Oe.loadAsync(`${i}m${s}_${n}`),await Oe.loadAsync(`${i}l${s}_${n}`)]);this.decodeNpcs(c,a,o),this.decodeObjs(l,a,o,t);const u=new Int8Array(e.MAPSQUARE);this.decodeLands(u,h,a,o),this.decodeLocs(u,d,a,o,t)}));await Promise.all(s),console.timeEnd('Loading game map')}changeLandCollision(e,t,i,r){ri(e,t,i,r)}changeLocCollision(e,t,i,r,s,n,a,o,c,l){const h=_i(e);h===ki.WALL?ci(a,o,c,t,e,i,!1,l):h===ki.GROUND?t===Ui.NORTH||t===Ui.SOUTH?si(a,o,c,r,s,i,!1,l):si(a,o,c,s,r,i,!1,l):h===ki.GROUND_DECOR&&1===n&&ri(a,o,c,l)}changeNpcCollision(e,t,i,r,s){ni(t,i,r,e,s)}changePlayerCollision(e,t,i,r,s){ai(t,i,r,e,s)}changeRoofCollision(e,t,i,r){oi(e,t,i,r)}decodeNpcs(e,t,i){for(;e.available>0;){const{x:r,z:s,level:n}=this.unpackCoord(e.g2()),a=t+r,o=i+s,c=e.g1();for(let t=0;t0;){const{x:s,z:n,level:a}=this.unpackCoord(e.g2()),o=t+s,c=i+n,l=e.g1();for(let t=0;t>2,E=3&u,_=o+r,A=h+s;n.zone(_,A,p).addStaticLoc(new ss(p,_,A,g,m,Yr.RESPAWN,a,y,E)),f.blockwalk&&this.changeLocCollision(y,E,f.blockrange,m,g,f.active,_,A,p,!0)}o=i.gsmart()}}packCoord(e,t,i){return 63&t|(63&e)<<6|(3&i)<<12}unpackCoord(e){return{x:e>>6&63,z:63&e,level:e>>12&3}}},xl=class{count=0;rsl=new Int32Array(256);mem=new Int32Array(256);a=0;b=0;c=0;constructor(e=[0,0,0,0]){for(let t=0;t>>2,s+=t,i+=r,i^=r<<8,n+=i,r+=s,r^=s>>>16,a+=r,s+=n,s^=n<<10,o+=s,n+=a,n^=a>>>4,e+=n,a+=o,a^=o<<8,t+=a,o+=e,o^=e>>>9,i+=o,e+=t;for(let c=0;c<256;c+=8)e+=this.rsl[c],t+=this.rsl[c+1],i+=this.rsl[c+2],r+=this.rsl[c+3],s+=this.rsl[c+4],n+=this.rsl[c+5],a+=this.rsl[c+6],o+=this.rsl[c+7],e^=t<<11,r+=e,t+=i,t^=i>>>2,s+=t,i+=r,i^=r<<8,n+=i,r+=s,r^=s>>>16,a+=r,s+=n,s^=n<<10,o+=s,n+=a,n^=a>>>4,e+=n,a+=o,a^=o<<8,t+=a,o+=e,o^=e>>>9,i+=o,e+=t,this.mem[c]=e,this.mem[c+1]=t,this.mem[c+2]=i,this.mem[c+3]=r,this.mem[c+4]=s,this.mem[c+5]=n,this.mem[c+6]=a,this.mem[c+7]=o;for(let c=0;c<256;c+=8)e+=this.mem[c],t+=this.mem[c+1],i+=this.mem[c+2],r+=this.mem[c+3],s+=this.mem[c+4],n+=this.mem[c+5],a+=this.mem[c+6],o+=this.mem[c+7],e^=t<<11,r+=e,t+=i,t^=i>>>2,s+=t,i+=r,i^=r<<8,n+=i,r+=s,r^=s>>>16,a+=r,s+=n,s^=n<<10,o+=s,n+=a,n^=a>>>4,e+=n,a+=o,a^=o<<8,t+=a,o+=e,o^=e>>>9,i+=o,e+=t,this.mem[c]=e,this.mem[c+1]=t,this.mem[c+2]=i,this.mem[c+3]=r,this.mem[c+4]=s,this.mem[c+5]=n,this.mem[c+6]=a,this.mem[c+7]=o;this.isaac(),this.count=256}isaac(){this.c++,this.b+=this.c;for(let e=0;e<256;e++){const t=this.mem[e];switch(3&e){case 0:this.a^=this.a<<13;break;case 1:this.a^=this.a>>>6;break;case 2:this.a^=this.a<<2;break;case 3:this.a^=this.a>>>16}let i;this.a+=this.mem[e+128&255],this.mem[e]=i=this.mem[t>>>2&255]+this.a+this.b,this.rsl[e]=this.b=this.mem[i>>>8>>>2&255]+t}}nextInt(){return 0==this.count--&&(this.isaac(),this.count=255),this.rsl[this.count]}};function Fl(e){return'undefined'==typeof self?new NodeWorker(e):new Worker(e,{type:'module'})}var Hl=class{static SUCCESSFUL=Uint8Array.from([2]);static INVALID_USER_OR_PASS=Uint8Array.from([3]);static ACCOUNT_DISABLED=Uint8Array.from([4]);static LOGGED_IN=Uint8Array.from([5]);static SERVER_UPDATED=Uint8Array.from([6]);static WORLD_FULL=Uint8Array.from([7]);static LOGIN_SERVER_OFFLINE=Uint8Array.from([8]);static LOGIN_LIMIT_EXCEEDED=Uint8Array.from([9]);static UNABLE_TO_CONNECT=Uint8Array.from([10]);static LOGIN_REJECTED=Uint8Array.from([11]);static NEED_MEMBERS_ACCOUNT=Uint8Array.from([12]);static COULD_NOT_COMPLETE=Uint8Array.from([13]);static SERVER_UPDATING=Uint8Array.from([14]);static RECONNECTING=Uint8Array.from([15]);static LOGIN_ATTEMPTS_EXCEEDED=Uint8Array.from([16]);static STANDING_IN_MEMBERS=Uint8Array.from([17]);static STAFF_MOD_LEVEL=Uint8Array.from([18])},Vl=new Oe(new Uint8Array(36)),Gl=[],Wl=0;function Kl(e){if(!fs28.existsSync(e))return;const t=Oe.load(e),i=Oe.getcrc(t.data,0,t.data.length);Gl.push(i),Vl.p4(i)}function zl(){Gl=[],Vl.pos=0,Vl.p4(0),Kl('data/pack/client/title'),Kl('data/pack/client/config'),Kl('data/pack/client/interface'),Kl('data/pack/client/media'),Kl('data/pack/client/models'),Kl('data/pack/client/textures'),Kl('data/pack/client/wordenc'),Kl('data/pack/client/sounds'),Wl=Oe.getcrc(Vl.data,0,Vl.data.length)}async function jl(e){if(!(await fetch(e)).ok)return;const t=await Oe.loadAsync(e),i=Oe.getcrc(t.data,0,t.data.length);Gl.push(i),Vl.p4(i)}'undefined'==typeof self?fs28.existsSync('data/pack/client/')&&zl():(await fetch('data/pack/client/crc')).ok&&await async function(){Gl=[],Vl.pos=0,Vl.p4(0),await jl('data/pack/client/title'),await jl('data/pack/client/config'),await jl('data/pack/client/interface'),await jl('data/pack/client/media'),await jl('data/pack/client/models'),await jl('data/pack/client/textures'),await jl('data/pack/client/wordenc'),await jl('data/pack/client/sounds'),Wl=Oe.getcrc(Vl.data,0,Vl.data.length)}();var Yl=new class{loginThread=Fl('undefined'==typeof self?'./src/lostcity/server/LoginThread.ts':'LoginThread.js');loginRequests=new Map;logoutRequests=new Set;constructor(){const e=e=>{try{this.onMessage(e)}catch(e){console.error('Login Thread:',e)}};'undefined'==typeof self?this.loginThread instanceof NodeWorker2&&this.loginThread.on('message',e):this.loginThread instanceof Worker&&(this.loginThread.onmessage=e)}async readIn(e,t){const i=t.g1();if(16===i){const r=t.g1();if(t.available=2e3)return r.writeImmediate(Hl.WORLD_FULL),void r.close();if(Zl.shutdownTick>-1&&Zl.currentTick-Zl.shutdownTick>0)return r.writeImmediate(Hl.SERVER_UPDATING),void r.close();if(!vt.LOGIN_KEY)for(const e of Zl.players)if(e.username===a)return r.writeImmediate(Hl.LOGGED_IN),void r.close();r.decryptor=new xl(n);for(let e=0;e<4;e++)n[e]+=50;r.encryptor=new xl(n);const c=jc.load(a,new Oe(o),r);c.lowMemory=!!(1&s),c.webClient=r.isWebSocket(),Zl.addPlayer(c);break}case'logoutreply':{const{username:t}=e,i=Zl.getPlayerByUsername(t);i&&(Zl.getZone(i.x,i.z,i.level).leave(i),Zl.players.remove(i.pid),i.pid=-1,i.terminate(),this.logoutRequests.delete(i.username37));break}default:throw new Error('Unknown message type: '+e.type)}else switch(e.data.type){case'loginreply':{const{status:t,socket:i}=e.data,r=this.loginRequests.get(i);if(!r)return;if(this.loginRequests.delete(i),2!==t[0])return r.writeImmediate(t),void r.close();const{info:s,seed:n,username:a,save:o}=e.data;if(Zl.getTotalPlayers()>=2e3)return r.writeImmediate(Hl.WORLD_FULL),void r.close();if(Zl.shutdownTick>-1&&Zl.currentTick-Zl.shutdownTick>0)return r.writeImmediate(Hl.SERVER_UPDATING),void r.close();if(!vt.LOGIN_KEY)for(const e of Zl.players)if(e.username===a)return r.writeImmediate(Hl.LOGGED_IN),void r.close();r.decryptor=new xl(n);for(let e=0;e<4;e++)n[e]+=50;r.encryptor=new xl(n);const c=jc.load(a,new Oe(o),r);c.lowMemory=!!(1&s),c.webClient=!0,Zl.addPlayer(c);break}case'logoutreply':{const{username:t}=e.data,i=Zl.getPlayerByUsername(t);i&&(Zl.getZone(i.x,i.z,i.level).leave(i),Zl.players.remove(i.pid),i.pid=-1,i.terminate(),this.logoutRequests.delete(i.username37));break}default:throw new Error('Unknown message type: '+e.data.type)}}},ql=class extends Array{free;indexPadding;ids;lastUsedIndex=0;constructor(e,t){super(e),this.ids=new Int32Array(e).fill(-1),this.free=new Set(Array.from({length:e},((e,t)=>t))),this.indexPadding=t}next(e=!1,t=this.lastUsedIndex+1){const i=this.ids.length;for(let e=t;e(oe(),ee))),r=async(e,t)=>{console.log(t);let i=new Uint8Array(await(await fetch(`data/pack/client/${e}/${t}`)).arrayBuffer());const r=Oe.getcrc(i,0,i.length);'jingles'===e&&(i=i.subarray(4)),Ps.set(t,i),ws.set(t,r)},s=[...t.map((e=>r('maps',e))),...i.map((e=>r('songs',e))),...e.map((e=>r('jingles',e)))];await Promise.all(s),console.timeEnd('Preloaded client data')}()}broadcastMes(e){for(const t of this.players)t.messageGame(e)}async start(e=!1,t=!0){console.log('Starting world...'),'undefined'==typeof self?(Ge.load('data/pack'),Bt.load('data/pack'),this.reload(),e||this.gameMap.init(this.zoneMap)):(await Ge.loadAsync('data/pack'),await Bt.loadAsync('data/pack'),await this.reloadAsync(),e||await this.gameMap.initAsync(this.zoneMap)),Yl.loginThread.postMessage({type:'reset'}),'undefined'!=typeof self||vt.NODE_PRODUCTION||(this.startDevWatcher(),vt.BUILD_STARTUP&&(shouldBuildFileAny('data/pack/client','data/pack/client/lastbuild.pack')||shouldBuildFileAny('data/pack/server','data/pack/server/lastbuild.pack'))&&this.devThread.postMessage({type:'pack'})),80===vt.WEB_PORT?console.log(ue.green().bold('World ready')+ue.white().bold(': http://localhost')):console.log(ue.green().bold('World ready')+ue.white().bold(': http://localhost:'+vt.WEB_PORT)),t&&await this.cycle()}startDevWatcher(){this.devThread=Fl('./src/lostcity/server/DevThread.ts'),this.devThread.on('message',(e=>{'done'===e.type&&(this.devRebuilding=!1,this.reload())})),this.devThread.on('exit',(()=>{this.devRebuilding=!1,this.stopDevWatcher(),-1===this.shutdownTick&&(this.broadcastMes('Error while rebuilding - see console for more info.'),this.startDevWatcher())})),this.devWatcher=new Watcher('./data/src',{recursive:!0}),this.devWatcher.on('add',(e=>{if(e.endsWith('.pack'))return;const t=fs29.statSync(e);this.devMTime.set(e,t.mtimeMs)})),this.devWatcher.on('change',(e=>{if(e.endsWith('.pack'))return;const t=fs29.statSync(e),i=this.devMTime.get(e);i&&i>=t.mtimeMs||(this.devMTime.set(e,t.mtimeMs),this.devRebuilding||(console.log('dev:',path4.basename(e),'was edited'),this.devRebuilding=!0,this.broadcastMes('Rebuilding, please wait...'),this.devThread||(this.devThread=Fl('./src/lostcity/server/DevThread.ts')),this.devThread.postMessage({type:'pack'})))}))}stopDevWatcher(){this.devWatcher&&this.devWatcher.close(),this.devThread&&(this.devThread.terminate(),this.devThread=null)}rebootTimer(e){this.shutdownTick=this.currentTick+e,this.stopDevWatcher();for(const e of this.players)e.write(new vo(this.shutdownTick-this.currentTick))}async cycle(t=!0){const i=Date.now();this.processWorld(),await this.processClientsIn(),this.processNpcs(),await this.processPlayers(),await this.processLogouts(),await this.processLogins(),this.processZones(),this.processMovementDirections(),await this.processClientsOut(),this.processCleanup();const r=this.currentTick;r%e.LOGIN_PINGRATE==0&&this.heartbeat(),this.shutdownTick>-1&&r>=this.shutdownTick&&await this.processShutdown(),r%e.PLAYER_SAVERATE==0&&r>0&&this.savePlayers(),this.currentTick++,this.cycleStats[Gr.CYCLE]=Date.now()-i,this.lastCycleStats[Gr.CYCLE]=this.cycleStats[Gr.CYCLE],this.lastCycleStats[Gr.WORLD]=this.cycleStats[Gr.WORLD],this.lastCycleStats[Gr.CLIENT_IN]=this.cycleStats[Gr.CLIENT_IN],this.lastCycleStats[Gr.NPC]=this.cycleStats[Gr.NPC],this.lastCycleStats[Gr.PLAYER]=this.cycleStats[Gr.PLAYER],this.lastCycleStats[Gr.LOGOUT]=this.cycleStats[Gr.LOGOUT],this.lastCycleStats[Gr.LOGIN]=this.cycleStats[Gr.LOGIN],this.lastCycleStats[Gr.ZONE]=this.cycleStats[Gr.ZONE],this.lastCycleStats[Gr.CLIENT_OUT]=this.cycleStats[Gr.CLIENT_OUT],this.lastCycleStats[Gr.CLEANUP]=this.cycleStats[Gr.CLEANUP],this.lastCycleStats[Gr.BANDWIDTH_IN]=this.cycleStats[Gr.BANDWIDTH_IN],this.lastCycleStats[Gr.BANDWIDTH_OUT]=this.cycleStats[Gr.BANDWIDTH_OUT],t&&setTimeout(this.cycle.bind(this),this.tickRate-this.cycleStats[Gr.CYCLE]),vt.NODE_DEBUG_PROFILE&&(console.log(`tick ${this.currentTick} took ${this.cycleStats[Gr.CYCLE]}ms: ${this.getTotalPlayers()} players`),console.log(`${this.cycleStats[Gr.WORLD]} ms world | ${this.cycleStats[Gr.CLIENT_IN]} ms client in | ${this.cycleStats[Gr.NPC]} ms npcs | ${this.cycleStats[Gr.PLAYER]} ms players | ${this.cycleStats[Gr.LOGOUT]} ms logout | ${this.cycleStats[Gr.LOGIN]} ms login | ${this.cycleStats[Gr.ZONE]} ms zones | ${this.cycleStats[Gr.CLIENT_OUT]} ms client out | ${this.cycleStats[Gr.CLEANUP]} ms cleanup`),console.log('----'))}processWorld(){const t=Date.now(),i=this.currentTick;for(let e=this.queue.head();e;e=this.queue.next()){if(e.delay-- >0)continue;const t=e.script;try{const i=Dl.execute(t);e.unlink(),i===$t.SUSPENDED?t.activePlayer.activeScript=t:i===$t.NPC_SUSPENDED?t.activeNpc.activeScript=t:i===$t.WORLD_SUSPENDED&&this.enqueueScript(t,t.popInt())}catch(e){console.error(e)}}if(i%e.AFK_EVENTRATE==0)for(const e of this.players)e.afkEventReady=Math.random()<(e.zonesAfk()?.1666:.0833);for(const e of this.npcs)e.updateLifeCycle(i)&&(e.lifecycle===Yr.RESPAWN?this.addNpc(e,-1):e.lifecycle===Yr.DESPAWN&&this.removeNpc(e,-1));for(const e of this.npcs)e.checkLifeCycle(i)&&!e.delayed()&&-1!==e.huntMode&&e.huntAll();this.cycleStats[Gr.WORLD]=Date.now()-t}async processClientsIn(){const e=Date.now();this.cycleStats[Gr.BANDWIDTH_IN]=0;for(const e of this.players)if(Sl(e))try{e.decodeIn()}catch(t){console.error(t),await this.removePlayer(e)}for(const e of this.players)if(Sl(e)){if(e.userPath.length>0||e.opcalled){if(e.delayed()){e.unsetMapFlag();continue}if((!e.target||e.target instanceof ss||e.target instanceof $r)&&-1!==e.faceEntity&&(e.faceEntity=-1,e.mask|=Do.FACE_ENTITY),e.opcalled&&(0===e.userPath.length||!vt.NODE_CLIENT_ROUTEFINDER)){e.pathToTarget();continue}e.pathToMoveClick(e.userPath,!vt.NODE_CLIENT_ROUTEFINDER)}e.target instanceof Do&&(e.targetOp===cs.APPLAYER3||e.targetOp===cs.OPPLAYER3)&&(ji.distanceToSW(e,e.target)<=25?e.pathToPathingTarget():e.clearWaypoints())}this.cycleStats[Gr.CLIENT_IN]=Date.now()-e}processNpcs(){const e=Date.now();for(const e of this.npcs)if(e.checkLifeCycle(this.currentTick))try{if(e.delayed())continue;if(e.activeScript&&e.executeScript(e.activeScript),!e.checkLifeCycle(this.currentTick))continue;e.processTimers(),e.processQueue(),e.processNpcModes(),e.validateDistanceWalked()}catch(t){console.error(t),this.removeNpc(e,-1)}this.cycleStats[Gr.NPC]=Date.now()-e}async processPlayers(){const t=Date.now();for(const t of this.players)try{t.playtime++,t.activeScript&&!t.delayed()&&t.activeScript.execution===$t.SUSPENDED&&t.executeScript(t.activeScript,!0),t.processQueues(),t.processTimers(0),t.processTimers(1),t.processEngineQueue(),t.processInteraction(),t.mask&Do.EXACT_MOVE||t.validateDistanceWalked(),this.shutdownTick=e.TIMEOUT_IDLE_TICKS&&(t.logoutRequested=!0),t.logoutRequested&&t.closeModal()}catch(e){console.error(e),await this.removePlayer(t)}this.cycleStats[Gr.PLAYER]=Date.now()-t}async processLogouts(){const t=Date.now();for(const t of this.players)if(vt.NODE_SOCKET_TIMEOUT&&this.currentTick-t.lastResponse>=e.TIMEOUT_LOGOUT_TICKS&&(t.queue.clear(),t.weakQueue.clear(),t.engineQueue.clear(),t.clearInteraction(),t.closeModal(),t.unsetMapFlag(),t.logoutRequested=!0,t.setVar(Nt.LASTCOMBAT,0)),t.logoutRequested)if(null===t.queue.head()){const e=jt.getByTriggerSpecific(cs.LOGOUT,-1,-1);if(!e){console.error('LOGOUT TRIGGER IS BROKEN!');continue}const i=Dl.init(e,t);i.pointerAdd(Gt.ProtectedActivePlayer),Dl.execute(i);0===i.popInt()&&(t.logoutRequested=!1),t.logoutRequested&&await this.removePlayer(t)}else t.messageGame('[DEBUG]: Waiting for queue to empty before logging out.');this.cycleStats[Gr.LOGOUT]=Date.now()-t}async processLogins(){const e=Date.now();e:for(const e of this.newPlayers){for(const t of this.players)if(e.username===t.username){Sl(e)&&e.client&&(e.client.send(Hl.LOGGED_IN),e.client.close());continue e}let t;try{t=this.getNextPid(Sl(e)?e.client:null)}catch(t){Sl(e)&&(e.client?.send(Hl.WORLD_FULL),e.client?.close());continue}this.players.set(t,e),e.pid=t,e.uid=(Number(0x1fffffn&e.username37)<<11|e.pid)>>>0,e.tele=!0,this.getZone(e.x,e.z,e.level).enter(e),e.onLogin(),this.shutdownTick>-1&&e.write(new vo(this.shutdownTick-this.currentTick)),Sl(e)&&e.client&&(e.client.state=1,e.staffModLevel>=2?e.client.send(Hl.STAFF_MOD_LEVEL):e.client.send(Hl.SUCCESSFUL))}this.newPlayers.clear(),this.cycleStats[Gr.LOGIN]=Date.now()-e}processZones(){const e=Date.now(),t=this.currentTick,i=this.zonesTracking.get(t);if(void 0!==i)for(const e of i)e.tick(t);this.computeSharedEvents(),this.cycleStats[Gr.ZONE]=Date.now()-e}processMovementDirections(){for(const e of this.players)e.convertMovementDir();for(const e of this.npcs)e.convertMovementDir()}async processClientsOut(){const e=Date.now();this.cycleStats[Gr.BANDWIDTH_OUT]=0;for(const e of this.players)if(Sl(e))try{e.updateMap(),e.updatePlayers(),e.updateNpcs(),e.updateZones(),e.updateInvs(),e.updateStats(),e.updateAfkZones(),e.encodeOut()}catch(t){console.error(t),await this.removePlayer(e)}else e.highPriorityOut.clear(),e.lowPriorityOut.clear();this.cycleStats[Gr.CLIENT_OUT]=Date.now()-e}processCleanup(){const t=Date.now(),i=this.currentTick,r=this.zonesTracking.get(i);if(void 0!==r)for(const e of r)e.reset();this.zonesTracking.delete(i);for(const e of this.players){e.resetEntity(!1);for(const t of e.invs.values())t&&(t.update=!1)}for(const e of this.npcs)e.checkLifeCycle(i)&&e.resetEntity(!1);for(const t of this.invs){t.update=!1;const r=it.get(t.type);if(r.restock&&r.stockcount&&r.stockrate)for(let s=0;sr.stockcount[s]&&i%r.stockrate[s]==0||r.allstock&&!r.stockcount[s]&&i%e.INV_STOCKRATE==0)&&(t.remove(n?.id,1,s,!0),t.update=!0))}}this.cycleStats[Gr.CLEANUP]=Date.now()-t}heartbeat(){const e=[];for(const t of this.players)e.push(t.username37);Yl.loginThread.postMessage({type:'heartbeat',players:e})}async processShutdown(){const t=this.currentTick-this.shutdownTick;if(this.getTotalPlayers()){for(const e of this.players)e.logoutRequested=!0,Sl(e)&&(e.logout(),e.client&&t>2&&e.client.close());if(this.npcs.reset(),t>2){if(console.log('Super fast shutdown initiated...'),this.tickRate>e.SHUTDOWN_TICKRATE&&(this.tickRate=e.SHUTDOWN_TICKRATE),t>e.SHUTDOWN_TICKS){for(const e of this.players)await this.removePlayer(e);this.tickRate=e.NORMAL_TICKRATE}vt.NODE_PRODUCTION||process.exit(0)}}else process.exit(0)}savePlayers(){if('undefined'==typeof self)for(const e of this.players)e.save().release()}enqueueScript(e,t=0){this.queue.addTail(new vs(e,t+1))}getInventory(e){if(-1===e)return null;for(const t of this.invs)if(t.type===e)return t;const t=Xt.fromType(e);return this.invs.add(t),t}getZone(e,t,i){return this.zoneMap.zone(e,t,i)}getZoneIndex(e){return this.zoneMap.zoneByIndex(e)}getZoneGrid(e){return this.zoneMap.grid(e)}computeSharedEvents(){const e=new Set;for(const t of this.players)if(Sl(t))for(const i of t.buildArea.loadedZones)e.add(i);for(const t of e)this.getZoneIndex(t).computeShared()}addNpc(e,t){this.npcs.set(e.nid,e),e.x=e.startX,e.z=e.startZ;switch(this.getZone(e.x,e.z,e.level).enter(e),e.blockWalk){case lt.NPC:this.gameMap.changeNpcCollision(e.width,e.x,e.z,e.level,!0);break;case lt.ALL:this.gameMap.changeNpcCollision(e.width,e.x,e.z,e.level,!0),this.gameMap.changePlayerCollision(e.width,e.x,e.z,e.level,!0)}e.resetEntity(!0),e.playAnimation(-1,0),e.setLifeCycle(this.currentTick+t)}removeNpc(e,t){switch(this.getZone(e.x,e.z,e.level).leave(e),e.blockWalk){case lt.NPC:this.gameMap.changeNpcCollision(e.width,e.x,e.z,e.level,!1);break;case lt.ALL:this.gameMap.changeNpcCollision(e.width,e.x,e.z,e.level,!1),this.gameMap.changePlayerCollision(e.width,e.x,e.z,e.level,!1)}e.lifecycle===Yr.DESPAWN?this.npcs.remove(e.nid):e.lifecycle===Yr.RESPAWN&&e.setLifeCycle(this.currentTick+t)}getLoc(e,t,i,r){return this.getZone(e,t,i).getLoc(e,t,r)}getObj(e,t,i,r,s){return this.getZone(e,t,i).getObj(e,t,r,s)}trackZone(e,t){let i;const r=this.zonesTracking.get(e);i=r||new Set,i.add(t),this.zonesTracking.set(e,i)}addLoc(e,t){const i=at.get(e.type);i.blockwalk&&this.gameMap.changeLocCollision(e.shape,e.angle,i.blockrange,i.length,i.width,i.active,e.x,e.z,e.level,!0);const r=this.getZone(e.x,e.z,e.level);r.addLoc(e),e.setLifeCycle(this.currentTick+t),this.trackZone(this.currentTick+t,r),this.trackZone(this.currentTick,r)}mergeLoc(e,t,i,r,s,n,a,o){const c=this.getZone(e.x,e.z,e.level);c.mergeLoc(e,t,i,r,s,n,a,o),this.trackZone(this.currentTick,c)}animLoc(e,t){const i=this.getZone(e.x,e.z,e.level);i.animLoc(e,t),this.trackZone(this.currentTick,i)}removeLoc(e,t){const i=at.get(e.type);i.blockwalk&&this.gameMap.changeLocCollision(e.shape,e.angle,i.blockrange,i.length,i.width,i.active,e.x,e.z,e.level,!1);const r=this.getZone(e.x,e.z,e.level);r.removeLoc(e),e.setLifeCycle(this.currentTick+t),this.trackZone(this.currentTick+t,r),this.trackZone(this.currentTick,r)}addObj(e,t,i){const r=Tt.get(e.type),s=this.getObj(e.x,e.z,e.level,e.type,t);if(s&&s.lifecycle===Yr.DESPAWN&&e.lifecycle===Yr.DESPAWN){const i=e.count+s.count;if(r.stackable&&i<=Xt.STACK_LIMIT)return void this.changeObj(s,t,i)}const n=this.getZone(e.x,e.z,e.level);n.addObj(e,t),-1!==t&&r.tradeable?(e.setLifeCycle(this.currentTick+100),this.trackZone(this.currentTick+100,n),this.trackZone(this.currentTick,n),e.receiverId=t,e.reveal=i):(e.setLifeCycle(this.currentTick+i),this.trackZone(this.currentTick+i,n),this.trackZone(this.currentTick,n))}revealObj(e){const t=e.reveal,i=this.getZone(e.x,e.z,e.level);i.revealObj(e,e.receiverId),e.setLifeCycle(this.currentTick+t),this.trackZone(this.currentTick+t,i),this.trackZone(this.currentTick,i)}changeObj(e,t,i){const r=this.getZone(e.x,e.z,e.level);r.changeObj(e,t,e.count,i),this.trackZone(this.currentTick,r)}removeObj(e,t){const i=this.getZone(e.x,e.z,e.level);i.removeObj(e),e.setLifeCycle(this.currentTick+t),this.trackZone(this.currentTick+t,i),this.trackZone(this.currentTick,i)}animMap(e,t,i,r,s,n){const a=this.getZone(t,i,e);a.animMap(t,i,r,s,n),this.trackZone(this.currentTick,a)}mapProjAnim(e,t,i,r,s,n,a,o,c,l,h,d,u){const p=this.getZone(t,i,e);p.mapProjAnim(t,i,r,s,n,a,o,c,l,h,d,u),this.trackZone(this.currentTick,p)}async readIn(e,t){for(;t.available>0;){const i=t.pos;let r=t.g1();if(e.decryptor&&(r=r-e.decryptor.nextInt()&255,t.data[i]=r),void 0===ko.byId[r])return e.state=-1,void e.close();let s=ko.byId[r].length;if(-1===s?s=t.g1():-2===s&&(s=t.g2()),t.available5)continue;const n=new Uint8Array(t.pos-i),a=t.pos;t.pos=i,t.gdata(n,0,n.length),t.pos=a,e.in.set(n,e.inOffset),e.inOffset+=t.pos-i}}addPlayer(e){this.newPlayers.add(e)}async removePlayer(e){-1!==e.pid&&(e.playerLog('Logging out'),Sl(e)&&(e.logout(),e.client.close(),e.client=null),Yl.logout(e))}getPlayer(e){return this.players.get(e)}getPlayerByUid(e){const t=2047&e,i=e>>11&2097151,r=this.getPlayer(t);return r?Number(0x1fffffn&r.username37)!==i?null:r:null}getPlayerByUsername(e){const t=pe(e);for(const e of this.players)if(e.username37===t)return e;for(const e of this.newPlayers)if(e.username37===t)return e}getTotalPlayers(){return this.players.count}getTotalNpcs(){return this.npcs.count}getTotalZones(){return this.zoneMap.zoneCount()}getTotalLocs(){return this.zoneMap.locCount()}getTotalObjs(){return this.zoneMap.objCount()}getNpc(e){return this.npcs.get(e)}getNpcByUid(e){const t=65535&e,i=e>>16&65535,r=this.getNpc(t);return r&&r.type===i?r:null}getNextNid(){return this.npcs.next()}getNextPid(e=null){if(e){const t=e.remoteAddress.split('.'),i=parseInt(t[3])%20*100;return this.players.next(!0,i)}return this.players.next()}};await Zl.start(),(new class{socket=new Kc(null,'127.0.0.1');constructor(){}start(){const e=new Oe(new Uint8Array(8));e.p4(Math.floor(4294967295*Math.random())),e.p4(Math.floor(4294967295*Math.random())),this.socket.send(e.data),self.onmessage=async e=>{const t=new Oe(new Uint8Array(e.data));e.data.type;try{1===this.socket.state?await Zl.readIn(this.socket,t):await Yl.readIn(this.socket,t)}catch(e){this.socket.close()}}}}).start(); \ No newline at end of file