0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RPGツクールMVで複数の暗号化画像リソースに強引に対応する

Posted at

わかりやすさ優先で、Sysytem.jsonにキーを追加します

System.json
    "encryptionKey2":"<暗号化キー>",    

読めるようにします

rpg_core.js

Decrypter._encryptionKey = "";
Decrypter._encryptionKey2 = ""; // 追加
Decrypter._ignoreList = [
rpg_core.js

Decrypter.readEncryptionkey = function(){
    this._encryptionKey = $dataSystem.encryptionKey.split(/(.{2})/).filter(Boolean);
    this._encryptionKey2 = $dataSystem.encryptionKey2.split(/(.{2})/).filter(Boolean); // 追加
};

既存の関数をコピペしてデコード関数を追加します

rpg_core.js
Decrypter.decryptArrayBuffer2 = function(arrayBuffer) {
    if (!arrayBuffer) return null;
    var header = new Uint8Array(arrayBuffer, 0, this._headerlength);

    var i;
    var ref = this.SIGNATURE + this.VER + this.REMAIN;
    var refBytes = new Uint8Array(16);
    for (i = 0; i < this._headerlength; i++) {
        refBytes[i] = parseInt("0x" + ref.substr(i * 2, 2), 16);
    }
    for (i = 0; i < this._headerlength; i++) {
        if (header[i] !== refBytes[i]) {
            throw new Error("Header is wrong");
        }
    }

    arrayBuffer = this.cutArrayHeader(arrayBuffer, Decrypter._headerlength);
    var view = new DataView(arrayBuffer);
    this.readEncryptionkey();
    if (arrayBuffer) {
        var byteArray = new Uint8Array(arrayBuffer);
        for (i = 0; i < this._headerlength; i++) {
            byteArray[i] = byteArray[i] ^ parseInt(Decrypter._encryptionKey2[i], 16);
            view.setUint8(i, byteArray[i]);
        }
    }

    return arrayBuffer;
};

読み込み処理を多重化します

rpg_core.js
Decrypter.decryptImg = function(url, bitmap) {
    url = this.extToEncryptExt(url);

    var requestFile = new XMLHttpRequest();
    requestFile.open("GET", url);
    requestFile.responseType = "arraybuffer";
    requestFile.send();

    requestFile.onload = function () {
        if(this.status < Decrypter._xhrOk) {
            var arrayBuffer = Decrypter.decryptArrayBuffer(requestFile.response); //Bitmap
            bitmap._image.src = Decrypter.createBlobUrl(arrayBuffer);
            bitmap._image.onload = Bitmap.prototype._onLoad.bind(bitmap); 
            //Bitmap.prototype._onError.bind(bitmap);
            bitmap._image.onerror = ()=>{

                var requestFile2 = new XMLHttpRequest();
                requestFile2.open("GET", url);
                requestFile2.responseType = "arraybuffer";
                requestFile2.send();
            
                requestFile2.onload = function () {
                    if(this.status < Decrypter._xhrOk) {
                        var arrayBuffer2 = Decrypter.decryptArrayBuffer2(requestFile2.response); //Bitmap
                        bitmap._image.src = Decrypter.createBlobUrl(arrayBuffer2);
                        bitmap._image.onload = Bitmap.prototype._onLoad.bind(bitmap);
                        //bitmap._image.onerror = Bitmap.prototype._onError.bind(bitmap);
                    }
                };
            };
            
            
        }
    };

こうすると、(読み込み失敗時は別のキーを使ってリトライすることによって)複数の暗号化キーによって暗号化された画像に強引に対応されます。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?