Skip to content

Commit

Permalink
Fix error after update
Browse files Browse the repository at this point in the history
  • Loading branch information
laplamgor committed Aug 23, 2023
1 parent 581204b commit ed91c71
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 121 deletions.
4 changes: 0 additions & 4 deletions index.es
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import i18next from 'views/env-parts/i18next'
const { session } = electron.remote
const path = require('path')


// Only block the main.js when the request has version number query (by original code)
// Do not block the main.js when the request has no version number query (by patcher)
const filter = { urls: ['*://*/kcs2/js/main.js?*'] }



export const

pluginDidLoad = (e) => {
Expand All @@ -26,7 +23,6 @@ export const
});

session.defaultSession.protocol.interceptFileProtocol('k3d', (request, callback) => {

callback({ path: path.join(__dirname, i18next.t('main', { ns: 'poi-plugin-kantai3d' }) + '.js') })
})

Expand Down
122 changes: 93 additions & 29 deletions main.ja-JP.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
var xhr = new XMLHttpRequest();
xhr.open("GET", window.location.protocol + '//' + window.location.hostname + '/kcs2/js/main.js', true);
xhr.onreadystatechange = () =>
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200)
{
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
result = xhr.responseText;


// patch the main.js and then store it into the storage
patchedMainJs = patchMainJs(result);

Expand All @@ -19,28 +15,37 @@ xhr.onreadystatechange = () =>
};
xhr.send();



function patchMainJs(contents) {

contents = contents.toString();
var oldContents = contents;
var oldlength = contents.length;
var version = '3.7';
var error_text = ' - エラーが発生します。 Kantai3D は現在利用できません。 開発者がプラグインを更新するまでお待ちください。';
var setting_text1 = '120 FPS\\n\\nKantai3D V' + version + '\\n\\n追加の深度マップ';
var setting_text2 = '追加の深度マップはAIによって生成され、\\nカスタム手描き深度マップなしでCGに\\nよって使用されます。3D効果の品質は、\\n比較すると粗くなります。\\n\\n変更は、次回母港に戻ったときに有効に\\nなります。';

contents = contents.replace(/(=[^,;=]{0,50}\(this\)\|\|this;return ([^,;=]{0,50}=new PIXI.{0,80},){6}[^,;=]{0,50}=new [^;=]{0,80}\((0x4f|79),(0xa4|164)\),)/g,
`= window.sound_options $1`);
`= window.sound_options $1`);
if (contents.length == oldlength) {
alert('A' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}


contents = contents.replace(/(=new )([^,;=]{0,20})(,[^,;=]{0,70}\((0x5a|90),(0x18e|398)\),)/g,
`$1$2$3
`$1$2$3
window.sound_options._toggle120 = new $2,
window.sound_options._toggle120.position.set(-120, 85),
window.sound_options._toggle3d = new $2,
window.sound_options._toggle3d.position.set(-120, 150),
window.sound_options._toggle3d_ai = new $2,
window.sound_options._toggle3d_ai.position.set(-120, 215),
window.sound_options._toggle3d_text = new PIXI.Text('120 FPS\\n\\nKantai3D V3.6\\n\\n追加の深度マップ', new PIXI.TextStyle({fontFamily: "Georgia", fontSize: 28, fill: '#ffffff'})),
window.sound_options._toggle3d_text = new PIXI.Text('` + setting_text1 + `', new PIXI.TextStyle({fontFamily: "Georgia", fontSize: 28, fill: '#ffffff'})),
window.sound_options._toggle3d_text.position.set(-360, 88),
window.sound_options._toggle3d_ai_text = new PIXI.Text('追加の深度マップはAIによって生成され、\\nカスタム手描き深度マップなしでCGに\\nよって使用されます。3D効果の品質は、\\n比較すると粗くなります。\\n\\n変更は、次回母港に戻ったときに有効に\\nなります。', new PIXI.TextStyle({fontFamily: "Georgia", fontSize: 18, fill: '#ffffff'})),
window.sound_options._toggle3d_ai_text = new PIXI.Text('` + setting_text2 + `', new PIXI.TextStyle({fontFamily: "Georgia", fontSize: 18, fill: '#ffffff'})),
window.sound_options._toggle3d_ai_text.position.set(-360, 290),
window.sound_options._toggle3d_bg = new PIXI.Graphics(),
window.sound_options._toggle3d_bg.beginFill(0x202020, 0.8).lineStyle(2, 0xd1b44b, 0.8).drawRect(7-373-15, 56, 373, 413),
Expand All @@ -50,44 +55,72 @@ function patchMainJs(contents) {
window.sound_options.addChild(window.sound_options._toggle3d_ai),
window.sound_options.addChild(window.sound_options._toggle3d_text),
window.sound_options.addChild(window.sound_options._toggle3d_ai_text),`);

if (contents.length == oldlength) {
alert('B' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}

contents = contents.replace(/(\((0x26|38),(0x18e|398)\),this[^,;=]{0,60}\((0xc6|198),(0x18e|398)\),)/g,
`$1
`$1
this._toggle120.initialize(),
this._toggle3d.initialize(),
this._toggle3d_ai.initialize(),`);
if (contents.length == oldlength) {
alert('C' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}



contents = contents.replace(/(function\(\)\{[^=]{0,90},([^;=]{0,90}\(\),this[^=]{0,90}=null){11})([^,])/g,
`$1
`$1
;
this._toggle120.dispose();
this._toggle120 = null;
this._toggle3d.dispose();
this._toggle3d = null;
this._toggle3d_ai.dispose();
this._toggle3d_ai = null; $3`);
if (contents.length == oldlength) {
alert('D' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}



contents = contents.replace(/(,[^,;=]{0,70}\(\),0(x0)?==this[^,;=]{0,20}&&0(x0)?<[^,;=]{0,2000}:0(x0)?<this[^,;=]{0,20}&&0(x0)?)/g,
`,localStorage.setItem('kantai3d.is120Enabled', this._sound._toggle120.value),
`,localStorage.setItem('kantai3d.is120Enabled', this._sound._toggle120.value),
localStorage.setItem('kantai3d.isDepthEnabled', this._sound._toggle3d.value),
localStorage.setItem('kantai3d.isDepthAiEnabled', this._sound._toggle3d_ai.value),
console.log(localStorage.getItem('kantai3d.is120Enabled')),
createjs.Ticker.setFPS((localStorage.getItem('kantai3d.is120Enabled') != 'false') ? 120 : 60)
$1`);
if (contents.length == oldlength) {
alert('E' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}

contents = contents.replace(/((null==this[^,;=]{0,40}&&\(this[^,;=]{0,40}=[^,;=]{0,70}\),this[^,;=]{0,40}=[^,;=]{0,70},){2})/g,
`$1
`$1
this._toggle120.value = localStorage.getItem('kantai3d.is120Enabled') != 'false',
this._toggle3d.value = localStorage.getItem('kantai3d.isDepthEnabled') != 'false',
this._toggle3d_ai.value = localStorage.getItem('kantai3d.isDepthAiEnabled') != 'false',
console.log(createjs.Ticker.timingMode),
console.log(createjs.Ticker.framerate),`);
if (contents.length == oldlength) {
alert('F' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}







Expand All @@ -97,18 +130,37 @@ function patchMainJs(contents) {



contents = contents.replace(/(return[^,;=]{0,30}\=[^,;=]{0,30}[^,;=]{0,20}\!\=[^,;=]{0,10}\|\|null\!\=\([^,;=]{0,10}\=[^,;=]{0,100}\)&&\([^,;=]{0,10}\=("_"|'_')\+[^,;=]{0,30}\),[^,;=]{0,70}\+\([^,;=]{0,70}\+[^,;=]{0,10}\+("\/"|'\/')\+\([^,;=]{0,20}\+[^,;=]{0,30}\([^,;=]{0,20},[^,;=]{0,20}\)\)\+("_"|'_')\+[^,;=]{0,20}\+[^,;=]{0,20}\+[^,;=]{0,20}\+[^,;=]{0,60}\(0(x0)?,parseInt\([^,;=]{0,20}\)\)\);?)/g,

contents = contents.replace(/(return[^,;=]{0,30}\=[^,;=]{0,30}[^,;=]{0,20}\!\=[^,;=]{0,10}\|\|null\!\=\([^,;=]{0,10}\=[^,;=]{0,100}\)&&\([^,;=]{0,10}\=("_"|'_')\+[^,;=]{0,30}\),[^,;=]{0,70}\+\([^,;=]{0,70}\+[^,;=]{0,10}\+("\/"|'\/')\+\([^,;=]{0,20}\+[^,;=]{0,30}\([^,;=]{0,20},[^,;=]{0,20}\)\)\+("_"|'_')\+[^,;=]{0,20}\+[^,;=]{0,20}\+[^,;=]{0,20}\+[^,;=]{0,60}\(0(x0)?,parseInt\([^,;=]{0,20}\)\)\);?)/g,
"\n return window.displacementPath = (function () {\n$1\n})();\n");
if (contents.length == oldlength) {
alert('G' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}


contents = contents.replace(/(new PIXI[^,;=]{0,20}\([^,;=]{0,70},[^,;=]{0,60},[^,;=]{0,20}\);document)/g,
contents = contents.replace(/(new PIXI[^,;=]{0,20}\([^,;=]{0,70},[^,;=]{0,60},[^,;=]{0,20}\);document)/g,
"\n window.pixiApp = $1");
if (contents.length == oldlength) {
alert('H' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}

contents = contents.replace(/(\=[^,;=]{0,70},[^,;=]{0,20}\=0(x0)?\=\=[^,;=]{0,20}\?0(x0)?\:[^,;=]{0,20},[^,;=]{0,20}\=.{0,500}\((0x1eb,-0x58|491,-88)\);var [^=]{0,99}=)/g,
contents = contents.replace(/(\=[^,;=]{0,200},[^,;=]{0,200}\=0(x0)?\=\=[^,;=]{0,200}\?0(x0)?\:[^:]*\:[^:]*,[^,;=]{0,200}\=.{0,500}\((0x1eb,-0x58|491,-88)\);var [^=]{0,99}=)/g,
"\n = window.charar $1 window.charal = \n");
if (contents.length == oldlength) {
alert('I' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}

contents = contents.replace(/(\=[^,;=]{0,40}\([^,;=]{0,20}\)[^,;=]{0,30}\([^,;=]{0,60}\);this[^,;=]{0,70}\-[^,;=]{0,70}\+[^,;=]{0,20}x[^,;=]{0,20}\+[^,;=]{0,20},\-[^,;=]{0,40}y[^,;=]{0,20},[^,;=]{0,200},[^,;=]{0,10}-(0x58|88)\)[^;]{0,200};?)(})/g,
`\n = window.charah $1
contents = contents.replace(/(\=[^,;=]{0,40}\([^,;=]{0,20}\)[^,;=]{0,30}\([^,;=]{0,60}\);this[^,;=]{0,70}\-[^,;=]{0,70}\+[^,;=]{0,20}x[^,;=]{0,20}\+[^,;=]{0,20},\-[^,;=]{0,40}y[^,;=]{0,20},[^,;=]{0,200},[^,;=]{0,10}-(0x58|88)\)[^;]{0,200};?)(})/g,
`\n = window.charah $1
window.portOffset = -window.charal + window.charah.x;//-l+h.x
window.portOffsetR = window.charar;//r
Expand Down Expand Up @@ -261,11 +313,23 @@ function prepareJiggle(baseMap, depthMap) {
window.My2 = null;
}
$3`);
if (contents.length == oldlength) {
alert('J' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}

contents = contents.replace(/(\=Math[^,;=]{0,40},[^,;=]{0,30}\=(0x)?1\+(0)?\.012[^,;=]{0,10}\*\(.{0,29}\);this[^,;=]{0,90}\([^,;=]{0,90}\),this(\.y|\['y'\])=this[^,;=]{0,20}-1.5\*[^,;=]{0,40}\*1.8;?)/g,
contents = contents.replace(/(\=Math[^,;=]{0,40},[^,;=]{0,30}\=(0x)?1\+(0)?\.012[^,;=]{0,10}\*\(.{0,29}\);this[^,;=]{0,90}\([^,;=]{0,90}\),this(\.y|\['y'\])=this[^,;=]{0,20}-1.5\*[^,;=]{0,40}\*1.8;?)/g,
` = window.charasin $1 ;
window.displacementFilter.uniforms.textureScale = this.scale.x;
`);
if (contents.length == oldlength) {
alert('K' + error_text);
return oldContents;
} else {
oldlength = contents.length;
}


return contents + `;
Expand Down
Loading

0 comments on commit ed91c71

Please sign in to comment.