rpgm-asset-decrypter
Version:
RPG Maker MV/MZ asset decrypter, that can be safely used both in browser and Node.js.
2 lines • 2.34 kB
JavaScript
(()=>{"use strict";var e={};e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};e.r(t),e.d(t,{Decrypter:()=>n});function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var n=function(){var e;function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),r(this,"key",void 0),r(this,"keyArray",[]),r(this,"headerLength",16),this.key=e,e&&(this.keyArray=this.splitEncryptionCode())}return e=[{key:"splitEncryptionCode",value:function(){if(!this.key)return[];for(var e=[],t=0;t<this.key.length;t+=2)e.push(this.key.slice(t,t+2));return e}},{key:"processBuffer",value:function(e){for(var t=new Uint8Array(e),r=Math.min(this.headerLength,this.keyArray.length),n=0;n<r;n++)t[n]^=Number.parseInt(this.keyArray[n],16);return e}},{key:"getKey",value:function(){var e;return null!==(e=this.key)&&void 0!==e?e:""}},{key:"setKeyString",value:function(e){this.key=e,this.keyArray=this.splitEncryptionCode()}},{key:"setKeyFromImage",value:function(e){var t=new Uint8Array(e.slice(this.headerLength,2*this.headerLength)),r=[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82];this.key=Array.from({length:this.headerLength},function(e,n){return(r[n]^t[n]).toString(16).padStart(2,"0").slice(-2)}).join(""),this.keyArray=this.splitEncryptionCode()}},{key:"decrypt",value:function(e){return this.key||this.setKeyFromImage(e),this.processBuffer(e.slice(this.headerLength,e.byteLength))}},{key:"encrypt",value:function(e){if(!this.key)throw Error("Encryption key is not set.");var t=this.processBuffer(e),r=new Uint8Array(t.byteLength+this.headerLength);return r.set([82,80,71,77,86,0,0,0,0,3,1,0,0,0,0,0],0),r.set(new Uint8Array(t),this.headerLength),r.buffer}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(t.prototype,e),t}();module.exports=t})();
//# sourceMappingURL=index.cjs.map