diff --git a/i18n/en-US/manager.json b/i18n/en-US/manager.json index 777bf30..39c73ed 100644 --- a/i18n/en-US/manager.json +++ b/i18n/en-US/manager.json @@ -21,6 +21,8 @@ "useHttpServer": "User http server(avoid certificate error)", "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": "User-Agent", + "vanillaMode": "Vanilla mode (no extensions)", "userLibPath": "'User Library' Path", "localVersion": "Version", "isManagerHide": "Re-open the launcher when the game quit", diff --git a/i18n/ja-JP/manager.json b/i18n/ja-JP/manager.json index 5dd1336..f6a6543 100644 --- a/i18n/ja-JP/manager.json +++ b/i18n/ja-JP/manager.json @@ -17,6 +17,8 @@ "useHttpServer": "http サービスを使用する(証明書エラーがない)", "serverToPlay": "ゲームサーバー(0は中国サーバー、1は日本サーバー、2は米国サーバー)", "proxyUrl": "プロキシサーバーアドレス(プロキシを使用しない場合は空白のままにします)", + "userAgent": "ユーザーエージェント", + "vanillaMode": "バニラモード(エクステンションなし)", "userLibPath": "ユーザライブラリディレクトリ", "localVersion": "バージョン", "isManagerHide": "ゲーム終了後、管理画面に戻る", diff --git a/i18n/ko/manager.json b/i18n/ko/manager.json index bcc54fa..7f3d6aa 100644 --- a/i18n/ko/manager.json +++ b/i18n/ko/manager.json @@ -21,6 +21,8 @@ "useHttpServer": "\uc0ac\uc6a9\uc790 HTTP \uc11c\ubc84(\uc778\uc99d\uc11c \uc624\ub958 \ud68c\ud53c)", "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", diff --git a/i18n/zh-CN/manager.json b/i18n/zh-CN/manager.json index 112a0a1..c1f13ac 100644 --- a/i18n/zh-CN/manager.json +++ b/i18n/zh-CN/manager.json @@ -17,6 +17,8 @@ "useHttpServer": "使用 http 服务器(不存在证书错误)", "serverToPlay": "游戏服务器(0为国服,1为日服,2为美服)", "proxyUrl": "代理服务器地址(留空为不使用代理)", + "userAgent": "User-Agent", + "vanillaMode": "纯净模式(停用所有扩展)", "userLibPath": "用户库目录", "localVersion": "版本", "isManagerHide": "退出游戏后回到管理器界面", diff --git a/i18n/zh-TW/manager.json b/i18n/zh-TW/manager.json index 3d85419..213a7f8 100644 --- a/i18n/zh-TW/manager.json +++ b/i18n/zh-TW/manager.json @@ -21,6 +21,8 @@ "useHttpServer": "\u4f7f\u7528 http \u670d\u52d9\u5668\uff08\u4e0d\u5b58\u5728\u8b49\u66f8\u932f\u8aa4\uff09", "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": "User-Agent", + "vanillaMode": "\u7d14\u6de8\u6a21\u5f0f\uff08\u505c\u7528\u6240\u6709\u64f4\u5c55\uff09", "userLibPath": "\u8cc7\u6599\u593e\u76ee\u9304", "localVersion": "\u7248\u672c", "isManagerHide": "\u9000\u51fa\u904a\u6232\u5f8c\uff0c\u8fd4\u56de\u6a94\u6848\u7e3d\u7ba1", diff --git a/src/bin/main/mainLoader.ts b/src/bin/main/mainLoader.ts index 2dae4d3..dff4aa3 100644 --- a/src/bin/main/mainLoader.ts +++ b/src/bin/main/mainLoader.ts @@ -105,6 +105,7 @@ function getLocalUrlWithParams(url: string) { function redirectGameWindow(url: string, gameWindow: Electron.WebviewTag) { const localUrl = getLocalUrlWithParams(url) console.log('[Majsoul Plus] Redirect Target:' + localUrl) + gameWindow.loadURL(localUrl) } @@ -139,8 +140,6 @@ mainWindow.addEventListener('dom-ready', () => { } else { scaleWindow(100) } - - mainWindow.useragent = navigator.userAgent }) ipcRenderer.on( @@ -152,6 +151,8 @@ ipcRenderer.on( if (partition) { mainWindow.partition = partition } + + mainWindow.useragent = navigator.userAgent mainWindow.src = url mainWindowBox.style.width = '100vw' mainWindowBox.style.height = '100vh' diff --git a/src/config.ts b/src/config.ts index a5da68d..11caf1f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -13,7 +13,8 @@ const defaultWindowConfig: MajsoulPlus.UserWindowConfig = { renderingMultiple: 100, isKioskModeOn: false, isNoBorder: false, - isManagerHide: false + isManagerHide: false, + userAgent: Global.HttpGetUserAgent } const defaultUpdateConfig: MajsoulPlus.UserUpdateConfig = { @@ -29,7 +30,8 @@ const defaultChromiumConfig: MajsoulPlus.UserChromiumConfig = { const defaultUserDataConfig: MajsoulPlus.UserDataConfig = { useHttpServer: false, - serverToPlay: 0 + serverToPlay: 0, + vanillaMode: false } const defaultConfig: MajsoulPlus.UserConfig = { diff --git a/src/extension/manager.ts b/src/extension/manager.ts index e644d7d..8ea68f0 100644 --- a/src/extension/manager.ts +++ b/src/extension/manager.ts @@ -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 @@ -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') diff --git a/src/index.ts b/src/index.ts index 0e85b36..d5ea2e0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -142,11 +142,13 @@ app.on('ready', () => { // 资源管理器通知启动游戏 ipcMain.on('start-game', () => { - // 加载服务器路由规则 - LoadServer() + if (!UserConfigs.userData.vanillaMode) { + // 加载服务器路由规则 + LoadServer() - // 启动服务器 - ListenServer(Global.ServerPort) + // 启动服务器 + ListenServer(Global.ServerPort) + } if (!process.env.SERVER_ONLY) { GameWindows.newWindow() diff --git a/src/majsoul_plus.d.ts b/src/majsoul_plus.d.ts index d476741..9752d68 100644 --- a/src/majsoul_plus.d.ts +++ b/src/majsoul_plus.d.ts @@ -12,6 +12,7 @@ declare namespace MajsoulPlus { isKioskModeOn: boolean isNoBorder: boolean isManagerHide: boolean + userAgent: string } export interface UserUpdateConfig { @@ -28,6 +29,7 @@ declare namespace MajsoulPlus { export interface UserDataConfig { useHttpServer: boolean serverToPlay: number + vanillaMode: boolean } export interface UserConfig { diff --git a/src/manager/pages/Setting.ts b/src/manager/pages/Setting.ts index e1882af..4064428 100644 --- a/src/manager/pages/Setting.ts +++ b/src/manager/pages/Setting.ts @@ -66,7 +66,7 @@ class Setting { index }), string: () => { - if (item === 'proxyUrl') { + if (item === 'proxyUrl' || item === 'userAgent') { this.renderTextSectionItem({ settingInner, section, diff --git a/src/utils.ts b/src/utils.ts index 07b4612..2ca2917 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,7 +118,7 @@ export async function getRemoteSource( const remoteUrl = getRemoteUrl(url) const resp = await fetch(remoteUrl, { headers: { - 'User-Agent': Global.HttpGetUserAgent + 'User-Agent': UserConfigs.window.userAgent } }) @@ -261,7 +261,7 @@ export async function getRemoteOrCachedFile( export async function fetchAnySite(url: string, encoding: BufferEncoding = 'binary') { const resp = await fetch(url, { headers: { - 'User-Agent': Global.HttpGetUserAgent + 'User-Agent': UserConfigs.window.userAgent } }) return (await resp.buffer()).toString(encoding) diff --git a/src/windows/game.ts b/src/windows/game.ts index d9d932b..434af5b 100644 --- a/src/windows/game.ts +++ b/src/windows/game.ts @@ -21,6 +21,7 @@ import { ListenServer, LoadServer } from '../server' +import { getRemoteUrl } from '../utils'; import { ToolManager } from '../tool/tool' import { AudioPlayer, initPlayer, shutoffPlayer } from './audioPlayer' import { ManagerWindow } from './manager' @@ -103,15 +104,21 @@ export function newGameWindow(id: number) { window.setMenu(getGameWindowMenu(id)) window.webContents.on('dom-ready', () => { - // 加载本地服务器地址 - const http = UserConfigs.userData.useHttpServer - const port = (UserConfigs.userData.useHttpServer - ? (httpServer.address() as AddressInfo) - : (httpsServer.address() as AddressInfo) - ).port - const url = `http${ - UserConfigs.userData.useHttpServer ? '' : 's' - }://localhost:${port}/` + let url, port, http + + if (UserConfigs.userData.vanillaMode) { + url = getRemoteUrl('/') + } else { + // 加载本地服务器地址 + http = UserConfigs.userData.useHttpServer + port = (UserConfigs.userData.useHttpServer + ? (httpServer.address() as AddressInfo) + : (httpsServer.address() as AddressInfo) + ).port + url = `http${ + UserConfigs.userData.useHttpServer ? '' : 's' + }://localhost:${port}/` + } window.webContents.send( 'load-url', @@ -160,8 +167,9 @@ export function newGameWindow(id: number) { window.show() }) + // 设置 GameWindow 的 userAgent - window.webContents.userAgent = Global.HttpGetUserAgent + window.webContents.userAgent = UserConfigs.window.userAgent // 载入本地启动器 window.loadURL('file://' + path.join(__dirname, '../bin/main/index.html'))