Skip to content

Commit

Permalink
Vanilla mode (workaround for MajsoulPlus#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtakingiteasy committed Jul 2, 2021
1 parent 10d1629 commit 57fd306
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions i18n/en-US/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"serverToPlay": "Server to play (0 is China server, 1 is Japan server, 2 is America server)",
"proxyUrl": "Proxy server address (leave it empty if you don't want to use it)",
"userAgent": "Useragent",
"vanillaMode": "Vanilla mode (no extensions)",
"userLibPath": "'User Library' Path",
"localVersion": "Version",
"isManagerHide": "Re-open the launcher when the game quit",
Expand Down
1 change: 1 addition & 0 deletions i18n/ja-JP/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"serverToPlay": "ゲームサーバー(0は中国サーバー、1は日本サーバー、2は米国サーバー)",
"proxyUrl": "プロキシサーバーアドレス(プロキシを使用しない場合は空白のままにします)",
"userAgent": "ユーザーエージェント",
"vanillaMode": "バニラモード(エクステンションなし)",
"userLibPath": "ユーザライブラリディレクトリ",
"localVersion": "バージョン",
"isManagerHide": "ゲーム終了後、管理画面に戻る",
Expand Down
1 change: 1 addition & 0 deletions i18n/ko/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"serverToPlay": "\ud50c\ub808\uc774\ud560 \uc11c\ubc84 (0 : \uc911\uad6d \uc11c\ubc84, 1 : \uc77c\ubcf8 \uc11c\ubc84, 2 : \ubbf8\uad6d \uc11c\ubc84)",
"proxyUrl": "\ud504\ub85d\uc2dc \uc11c\ubc84 \uc8fc\uc18c (\uc0ac\uc6a9\ud558\uc9c0 \uc54a\uc73c\ub824\uba74 \ube48\uce78\uc73c\ub85c \ub458 \uac83)",
"userAgent": "\uc0ac\uc6a9\uc790\u0020\uc5d0\uc774\uc804\ud2b8",
"vanillaMode": "Vanilla mode (no extensions)",
"userLibPath": "'\uc0ac\uc6a9\uc790 \ub77c\uc774\ube0c\ub7ec\ub9ac' \uacbd\ub85c",
"localVersion": "\ubc84\uc804",
"isManagerHide": "\uac8c\uc784 \uc885\ub8cc \ud6c4 \ub7f0\ucc98 \uc7ac\uc2e4\ud589",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"serverToPlay": "游戏服务器(0为国服,1为日服,2为美服)",
"proxyUrl": "代理服务器地址(留空为不使用代理)",
"userAgent": "用户代理",
"vanillaMode": "Vanilla mode (no extensions)",
"userLibPath": "用户库目录",
"localVersion": "版本",
"isManagerHide": "退出游戏后回到管理器界面",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-TW/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"serverToPlay": "\u904a\u6232\u4f3a\u670d\u5668\uff080\u70ba\u570b\u4f3a\uff0c1\u70ba\u65e5\u4f3a\uff0c2\u70ba\u7f8e\u4f3a\uff09",
"proxyUrl": "\u4ee3\u7406\u4f3a\u670d\u5668\u5730\u5740\uff08\u7559\u7a7a\u70ba\u4e0d\u4f7f\u7528\u4ee3\u7406\uff09",
"userAgent": "\u7528\u6236\u4ee3\u7406",
"vanillaMode": "Vanilla mode (no extensions)",
"userLibPath": "\u8cc7\u6599\u593e\u76ee\u9304",
"localVersion": "\u7248\u672c",
"isManagerHide": "\u9000\u51fa\u904a\u6232\u5f8c\uff0c\u8fd4\u56de\u6a94\u6848\u7e3d\u7ba1",
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const defaultChromiumConfig: MajsoulPlus.UserChromiumConfig = {

const defaultUserDataConfig: MajsoulPlus.UserDataConfig = {
useHttpServer: false,
serverToPlay: 0
serverToPlay: 0,
vanillaMode: false
}

const defaultConfig: MajsoulPlus.UserConfig = {
Expand Down
27 changes: 20 additions & 7 deletions src/extension/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,26 @@ export default class MajsoulPlusExtensionManager extends BaseManager {
}
}

const processRegion = (data) => UserConfigs.userData.serverToPlay === 0
? Buffer.from(
data
.toString('utf-8')
.replace(/\.\.\/region\/region\.txt/g, 'region.txt')
)
: data;

router.get('/:version/code.js', async (ctx, next) => {
if (UserConfigs.userData.vanillaMode) {
const code = (
await getRemoteOrCachedFile(ctx.request.originalUrl, false, data =>
processRegion(data)
)
).data.toString('utf-8')
ctx.res.setHeader('Content-Type', 'application/javascript')
ctx.body = code;
return;
}

if (this.codejs !== '') {
ctx.res.statusCode = 200
ctx.body = this.codejs
Expand Down Expand Up @@ -265,13 +284,7 @@ function addScript(url) {
const url = ctx.request.originalUrl.replace(/^\/majsoul_plus/, '')
const code = (
await getRemoteOrCachedFile(url, false, data =>
UserConfigs.userData.serverToPlay === 0
? Buffer.from(
data
.toString('utf-8')
.replace(/\.\.\/region\/region\.txt/g, 'region.txt')
)
: data
processRegion(data)
)
).data.toString('utf-8')
ctx.res.setHeader('Content-Type', 'application/javascript')
Expand Down
1 change: 1 addition & 0 deletions src/majsoul_plus.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ declare namespace MajsoulPlus {
export interface UserDataConfig {
useHttpServer: boolean
serverToPlay: number
vanillaMode: boolean
}

export interface UserConfig {
Expand Down

0 comments on commit 57fd306

Please sign in to comment.