From 9adb023f7cea4f3892bea7c7e66017d9b6d3a496 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Sun, 24 Apr 2022 00:32:17 -0700 Subject: [PATCH] specify port when connecitng --- languages/en.json | 1 + proxy/proxy.py | 9 +++++++++ resources/index.html | 1 + resources/js/index.js | 5 +++-- resources/js/translation.js | 2 ++ resources/style/index.css | 4 ++++ scripts/killswitch.cmd | 2 +- scripts/private_server_launch.cmd | 13 +++++++------ 8 files changed, 28 insertions(+), 9 deletions(-) diff --git a/languages/en.json b/languages/en.json index cbf092b..195be63 100644 --- a/languages/en.json +++ b/languages/en.json @@ -11,6 +11,7 @@ "folderNotSet": "Not set", "ipPlaceholder": "IP Address", + "portPlaceholder": "Port (optional)", "noFavorites": "No favorites set", "settingsTitle": "Settings", diff --git a/proxy/proxy.py b/proxy/proxy.py index 581b3cb..c2a0b70 100644 --- a/proxy/proxy.py +++ b/proxy/proxy.py @@ -34,9 +34,17 @@ class MlgmXyysd_Anime_Game_Proxy: help = "IP address to replace", ) + loader.add_option( + name = "port", + typespec = int, + default = 80, + help = "Port to replace", + ) + def request(self, flow: http.HTTPFlow) -> None: # This can also be replaced with another IP address. REMOTE_HOST = ctx.options.ip + REMOTE_PORT = ctx.options.port LIST_DOMAINS = [ "api-os-takumi.mihoyo.com", @@ -75,6 +83,7 @@ class MlgmXyysd_Anime_Game_Proxy: if flow.request.host in LIST_DOMAINS: flow.request.host = REMOTE_HOST + flow.request.port = REMOTE_PORT addons = [ MlgmXyysd_Anime_Game_Proxy() diff --git a/resources/index.html b/resources/index.html index 57cc2a6..123f9ac 100644 --- a/resources/index.html +++ b/resources/index.html @@ -103,6 +103,7 @@
+
diff --git a/resources/js/index.js b/resources/js/index.js index 6b68a7e..ceafa16 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -370,17 +370,18 @@ async function launchOfficial() { */ async function launchPrivate() { const ip = document.getElementById('ip').value || 'localhost' + const port = document.getElementById('port').value || '443' const config = await getCfg() - console.log('connecting to ' + ip) + console.log('connecting to ' + ip + ':' + port) // Set the last connect config.lastConnect = ip Neutralino.storage.setData('config', JSON.stringify(config)) // Pass IP and game folder to the private server launcher - Neutralino.os.execCommand(`${NL_CWD}/scripts/private_server_launch.cmd ${ip} "${config.gamefolder}/${await getGameExecName()}" "${NL_CWD}" ${config.enableKillswitch}`).catch(e => console.log(e)) + Neutralino.os.execCommand(`${NL_CWD}/scripts/private_server_launch.cmd ${ip} ${port} "${config.gamefolder}/${await getGameExecName()}" "${NL_CWD}" ${config.enableKillswitch}`).catch(e => console.log(e)) } async function launchLocalServer() { diff --git a/resources/js/translation.js b/resources/js/translation.js index 712053d..f9f6c8f 100644 --- a/resources/js/translation.js +++ b/resources/js/translation.js @@ -13,6 +13,7 @@ async function doTranslation() { } const localization = await filesystem.readFile(`${NL_CWD}/languages/${config.language}.json`) + const engLocale = await filesystem.readFile(`${NL_CWD}/languages/en.json`) localeObj = JSON.parse(localization) const set = (id, localeString) => document.getElementById(id).innerHTML = localeString || 'UNKNOWN' @@ -37,6 +38,7 @@ async function doTranslation() { // Private options document.querySelector('#ip').placeholder = localeObj.ipPlaceholder + document.querySelector('#port').placeholder = localeObj.portPlaceholder // Settings set('fullSettingsTitle', localeObj.settingsTitle) diff --git a/resources/style/index.css b/resources/style/index.css index 8f8c57d..7a33d47 100644 --- a/resources/style/index.css +++ b/resources/style/index.css @@ -351,6 +351,10 @@ body { display: block; } +#port { + width: 12%; +} + #secondPanel input { margin-bottom: 4px; height: 20px; diff --git a/scripts/killswitch.cmd b/scripts/killswitch.cmd index af9e60e..4c78b4f 100644 --- a/scripts/killswitch.cmd +++ b/scripts/killswitch.cmd @@ -87,6 +87,6 @@ if "%PROXY_IP%" EQU "localhost" ( :: Reconnect to the WiFi netsh wlan connect name="%WIFI%" - :: taskkill /f /fi "WINDOWTITLE eq Administrator: PS Killswitch" + taskkill /f /fi "WINDOWTITLE eq Administrator: PS Killswitch" exit \ No newline at end of file diff --git a/scripts/private_server_launch.cmd b/scripts/private_server_launch.cmd index a8a77cf..4993393 100644 --- a/scripts/private_server_launch.cmd +++ b/scripts/private_server_launch.cmd @@ -3,7 +3,7 @@ :: Ensure admin >nul 2>&1 reg query "HKU\S-1-5-19" || ( set params = %*:"="""% - cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %1 "%2" ""%cd%"" %4", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B ) + cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %1 %2 "%3" ""%cd%"" %5", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B ) ) :: Use to force task kill @@ -12,11 +12,12 @@ title PS Launcher Script echo Starting Proxy Server set IP=%1 -set GAME_PATH=%2 +set PORT=%2 +set GAME_PATH=%3 set GAME_PATH=%GAME_PATH:"=% -set ORIGIN=%3 +set ORIGIN=%4 set ORIGIN=%ORIGIN:"=% -set ENABLE_KILLSWITCH=%4 +set ENABLE_KILLSWITCH=%5 set PROXY=true @rem Store original proxy settings @@ -28,7 +29,7 @@ reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v Pr reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "127.0.0.1:8080" /f >nul 2>nul :: Start proxy server -start "Proxy Server" %ORIGIN%/ext/mitmdump.exe -s "%ORIGIN%/proxy/proxy.py" --ssl-insecure --set ip=%IP% +start "Proxy Server" %ORIGIN%/ext/mitmdump.exe -s "%ORIGIN%/proxy/proxy.py" --ssl-insecure --set ip=%IP% --set port=%PORT% echo Opening %GAME_PATH% @@ -72,6 +73,6 @@ echo Done! See you next time! timeout /t 2 /nobreak >nul -:: taskkill /f /fi "WINDOWTITLE eq Administrator: PS Launcher Script" +taskkill /f /fi "WINDOWTITLE eq Administrator: PS Launcher Script" exit /b \ No newline at end of file