mirror of
https://github.com/Grasscutters/GrassClipper.git
synced 2024-11-22 15:37:48 +00:00
Kill switch
This commit is contained in:
parent
f205f5f767
commit
0e8a4b61cc
64
scripts/killswitch.cmd
Normal file
64
scripts/killswitch.cmd
Normal file
@ -0,0 +1,64 @@
|
||||
@echo off
|
||||
|
||||
set GAME_EXE_NAME=%1
|
||||
set GAME_EXE_NAME=%GAME_EXE_NAME:"=%
|
||||
set PROXY_IP=%2
|
||||
set PROXY_IP=%PROXY_IP:"=%
|
||||
|
||||
echo Starting killswitch...
|
||||
|
||||
if "%PROXY_IP%" EQU "localhost" (
|
||||
:: Needed
|
||||
set PROXY_IP=127.0.0.1
|
||||
)
|
||||
|
||||
:loop
|
||||
:: Check if the game is even running
|
||||
@REM QPROCESS "%GAME_EXE_NAME%">NUL
|
||||
@REM IF %ERRORLEVEL% NEQ 0 (
|
||||
@REM exit /b
|
||||
@REM )
|
||||
|
||||
:: Check if the proxy server process is running
|
||||
:: https://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script
|
||||
qprocess "mitmdump.exe">NUL
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
goto killgame
|
||||
)
|
||||
|
||||
:: Ensure system proxy is on and set to the proxy IP
|
||||
for /F "usebackq tokens=3*" %%A in (`reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable`) do (
|
||||
set PROXY_ENABLED=%%A %%B
|
||||
)
|
||||
:: echo %PROXY_ENABLED%
|
||||
|
||||
:: Get the proxy IP
|
||||
:: https://stackoverflow.com/questions/445167/how-can-i-get-the-value-of-a-registry-key-from-within-a-batch-script
|
||||
for /F "usebackq tokens=3*" %%A in (`reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer`) do (
|
||||
set CUR_PROXY_IP=%%A %%B
|
||||
)
|
||||
:: echo %CUR_PROXY_IP%
|
||||
|
||||
:: Ensure proxy is enabled, space is there on purpose
|
||||
IF "%PROXY_ENABLED%" NEQ "0x1 " (
|
||||
goto killgame
|
||||
)
|
||||
|
||||
:: echo Proxy is enabled!
|
||||
|
||||
:: echo Current Windows proxy is %CUR_PROXY_IP% while the proxy IP is %PROXY_IP%:8080
|
||||
|
||||
:: There is a space after %PROXY_IP on purpose, Windows is weird
|
||||
if "%CUR_PROXY_IP%" NEQ "%PROXY_IP%:8080 " (
|
||||
goto killgame
|
||||
)
|
||||
|
||||
timeout /t 2 /NOBREAK >nul
|
||||
|
||||
goto loop
|
||||
|
||||
:killgame
|
||||
echo Proxy server not running properly, killing %GAME_EXE_NAME%
|
||||
netsh interface set interface "Ethernet" disabled
|
||||
taskkill /f /im "%GAME_EXE_NAME%"
|
||||
exit
|
@ -1,10 +1,18 @@
|
||||
@echo off
|
||||
|
||||
:: 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%"" ", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )
|
||||
)
|
||||
|
||||
echo Starting Proxy Server
|
||||
|
||||
SET ip=%1
|
||||
SET gamePath=%2
|
||||
SET gamePath=%gamePath:"=%
|
||||
SET ORIGIN=%3
|
||||
SET ORIGIN=%ORIGIN:"=%
|
||||
|
||||
set PROXY=true
|
||||
@rem Store original proxy settings
|
||||
@ -16,13 +24,20 @@ 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" ./ext/mitmdump.exe -s "./proxy/proxy.py" --ssl-insecure --set ip=%ip%
|
||||
start "Proxy Server" ./ext/mitmdump.exe -s "%ORIGIN%/proxy/proxy.py" --ssl-insecure --set ip=%ip%
|
||||
|
||||
echo Opening %gamePath%
|
||||
|
||||
:: Allow the proxy server to create the certificates
|
||||
ping 127.0.0.1 -n 5 > nul
|
||||
|
||||
For %%A in ("%gamePath%") do (
|
||||
Set GAME_EXE=%%~nxA
|
||||
)
|
||||
|
||||
:: Start killswitch
|
||||
start /b %ORIGIN%\scripts\killswitch.cmd "%GAME_EXE%" %ip%"
|
||||
|
||||
:: Launch game
|
||||
"%gamePath%"
|
||||
|
||||
@ -38,4 +53,6 @@ if "%PROXY%" == "" (
|
||||
|
||||
:: Kill proxy server
|
||||
taskkill /f /im mitmdump.exe
|
||||
|
||||
exit /b
|
||||
)
|
Loading…
Reference in New Issue
Block a user