Files
Redcraft.Dragon.V3/键位覆盖处理程序V1.bat

142 lines
4.9 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
:: ====== 标题显示(调用 powershell 做彩色)======
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"Write-Host '=======键位覆盖处理程序v1.0=======' -ForegroundColor Green; ^
Start-Sleep -Milliseconds 80; ^
"Write-Host '本程序适用于:游戏因为各种如闪退等原因导致键位经常被重置(被覆盖)的情况' -ForegroundColor Cyan; ^
Start-Sleep -Milliseconds 80; ^
Write-Host '!重要!受限于游戏结构,锁定键位将一同锁定如画质选项等其他游戏设置!' -ForegroundColor Red; ^
Start-Sleep -Milliseconds 80; ^
Write-Host '一经锁定将会在每次启动游戏还原至现在的设置,更改前先解锁' -ForegroundColor Yellow"
timeout /t 1 >nul
:: ====== 管理员检测 ======
net session >nul 2>&1
if %errorlevel% neq 0 (
echo 》》检测到正在非管理员模式下运行!如闪退请右键程序以管理员运行。
pause
)
timeout /t 1 >nul
:: ====== 路径检测 ======
set "BASEDIR=%~dp0"
cd /d "%BASEDIR%"
echo 》》当前路径是:%cd%
set "TARGET1=%BASEDIR%.minecraft\versions\RedCraft.Dragon.1.21.1\options.txt"
set "TARGET2=%BASEDIR%options.txt"
if exist "%TARGET1%" (
set "FILE=%TARGET1%"
) else if exist "%TARGET2%" (
set "FILE=%TARGET2%"
) else (
echo 错误:在以下目录中未找到目标设置文件!
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
echo %TARGET1%
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
echo %TARGET2%
(PATHPING 127.0.0.1 -n -q 1 -p 1200)>NUL
echo.
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"Write-Host '》》请将程序放在游戏根目录启动器同目录或者将本程序放在游戏程序目录有options.txt的目录下。' -ForegroundColor Red;
pause
exit
)
timeout /t 1 >nul
:: ====== 检查是否锁定 ======
powershell -NoProfile -Command ^
"$p='%FILE%'; ^
$acl=Get-Acl $p; ^
$locked=$false; ^
foreach($r in $acl.Access){if($r.IdentityReference -match 'Users' -and $r.AccessControlType -eq 'Deny' -and ($r.FileSystemRights -band 'Write')){$locked=$true}}; ^
if($locked){Write-Host '》》当前游戏设置文件状态:[-]锁定' -ForegroundColor Green}else{Write-Host '》》当前游戏设置文件状态:[\]解锁' -ForegroundColor DarkYellow}"
timeout /t 1 >nul
echo ========你要锁定键位,还是解除锁定(修改键位)?=======
:menu
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
echo 1=锁定
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
echo 2=解除
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
set /p choice=请输入选项:
if "%choice%"=="1" goto lock
if "%choice%"=="2" goto unlock
echo 》》请输入有效的按钮
goto menu
:: ====== 检测Java进程 ======
:checkjava
tasklist | findstr /i "java.exe javaw.exe" >nul
if %errorlevel%==0 (
echo 》》检测到游戏可能仍在运行!请确保游戏关闭再继续。
(PATHPING 127.0.0.1 -n -q 1 -p 1200)>NUL
echo 1 重试
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
echo 任意键 跳过
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
set /p jchoice=选择:
)
if "%jchoice%"=="1" goto checkjava
goto :eof
:: ====== 锁定 ======
:lock
call :checkjava
timeout /t 1 >nul
:confirm
echo 是否已经设置好键位?再次提醒红字内容!(Y/n)
set /p yn=
if /i "%yn%"=="n" (
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
echo 请进入游戏主菜单,设置完键位后退出游戏。确保本次游戏没有崩溃!然后重新运行本程序。
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
pause
exit
)
if /i not "%yn%"=="Y" (
echo 》》请输入有效的按钮
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
goto confirm
)
powershell -NoProfile -Command ^
"$p='%FILE%'; ^
$acl=Get-Acl $p; ^
$rules=@(); ^
$rules+=New-Object System.Security.AccessControl.FileSystemAccessRule('Users','Write','Deny'); ^
$rules+=New-Object System.Security.AccessControl.FileSystemAccessRule('Administrators','Write','Deny'); ^
foreach($r in $rules){$acl.AddAccessRule($r)}; ^
try{Set-Acl $p $acl; Write-Host '=======处理完成!进入游戏检查效果=======' -ForegroundColor Green}catch{Write-Host '》》设置失败!请使用管理员权限重试。' -ForegroundColor Red}"
timeout /t 1 >nul
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
pause
exit
:: ====== 解锁 ======
:unlock
call :checkjava
timeout /t 1 >nul
powershell -NoProfile -ExecutionPolicy Bypass -Command "$p='%FILE%'; $acl=Get-Acl $p; $rules=$acl.Access | Where-Object { ($_.IdentityReference -match 'Users' -or $_.IdentityReference -match 'Administrators') -and $_.AccessControlType -eq 'Deny' -and ($_.FileSystemRights -band 'Write') }; foreach($r in $rules){$acl.RemoveAccessRuleSpecific($r)}; try{Set-Acl $p $acl; Write-Host '=======处理完成!进入游戏检查效果=======' -ForegroundColor Green}catch{Write-Host '》》设置失败!请使用管理员权限重试。' -ForegroundColor Red}"
timeout /t 1 >nul
(PATHPING 127.0.0.1 -n -q 1 -p 80)>NUL
pause
exit