optimize this code : ::[Bat To Exe Converter]
::
::YAwzoRdxOk+EWAjk
::fBw5plQjdCqDJHeF/1c8FB9bTxe+FWW8CaYF+6jd5uSJo04RUaIafIjeyKKLMvYW1nbxd5skwm5fnIsoAxhNcxelehwIkFoCgG2BMsiPjzbuX1yc5E5wN2pziCPWgzl7Qtx8m80C2C/+20zylqsXn3H8Uck=
::YAwzuBVtJxjWCl3EqQJgSA==
::ZR4luwNxJguZRRnk
::Yhs/ulQjdF+5
::cxAkpRVqdFKZSDk=
::cBs/ulQjdF+5
::ZR41oxFsdFKZSTk=
::eBoioBt6dFKZSDk=
::cRo6pxp7LAbNWATEpSI=
::egkzugNsPRvcWATEpSI=
::dAsiuh18IRvcCxnZtBJQ
::cRYluBh/LU+EWAnk
::YxY4rhs+aU+IeA==
::cxY6rQJ7JhzQF1fEqQJhZks0
::ZQ05rAF9IBncCkqN+0xwdVs0
::ZQ05rAF9IAHYFVzEqQISJw9VQg+NfEy7C7wS76jc7ueCrkISRKIeUaC7
::eg0/rx1wNQPfEVWB+kM9LVsJDCaNKGq0Dbpcz+n25uSA4mocWeczd4DLmpWnD4A=
::fBEirQZwNQPfEVWB+kM9LVsJDCaNKGq0Dbpcz+n25uSA4mocWeczd4DLmpWnD4A=
::cRolqwZ3JBvQF1fEqQIDPRlHXg2AOSuuCfU+5/z64eGI4mocWesxf8/Y0rWALuUfqkrqNa8iw25Pms5s
::dhA7uBVwLU+EWDk=
::YQ03rBFzNR3SWATElA==
::dhAmsQZ3MwfNWATElA==
::ZQ0/vhVqMQ3MEVWAtB9wSA==
::Zg8zqx1/OA3MEVWAtB9wSA==
::dhA7pRFwIByZRRm34UAjOhJWSUSWMyuYCaEd5uP0r82Gr0QTU6I8cI7V1LGCYO8dqnzrYII41H86
::Zh4grVQjdCyDJGyX8VAjFBVVRxGOAE+/Fb4I5/jHzc2qiw1OGrZ/X47W37iBL/BTzEzocIUR8XtXnccDAwsYXzuEIAosrA4=
::YB416Ek+ZW8=
::
::
::978f952a14a936cc963da21a135fa983
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
title Botanko Gaming
color a

rem Check if the script is running with administrative privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting administrative privileges...
    powershell -Command "Start-Process cmd -Argument '/c %~s0' -Verb runAs"
    exit /b
)

title Botanko Gameloop AIO
color 3
rem Check for GameLoop installation path in the registry
FOR /F "usebackq tokens=2*" %%I IN (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Tencent\MobileGamePC\UI" /v 
InstallPath`) DO (
    SET "InstallPath=%%J"
)

rem Check if the installation path was found
cls
IF NOT DEFINED InstallPath (
    echo GameLoop is not installed, Do you want to download GameLoop now?
    echo Press 1 to Download GameLoop, 2 to Exit.
    choice /C 12 /N /M "Select your option:"
    if errorlevel 2 (
        echo Exiting. >nul 2>&1
        exit /b
    ) else if errorlevel 1 (
        echo Reopen Botanko AIO.bat after installing GameLoop
        pause
        start "" "https://www.gameloop.com/"
        if !errorlevel! neq 0 (
            echo Failed to open the browser. Error level: !errorlevel! >nul 2>&1
        ) else (
            echo Reopen Botanko AIO.bat after installing GameLoop.
        )
        exit /b
    )
) ELSE (
    echo GameLoop is installed at: !InstallPath! >nul 2>&1
    goto menu
)

endlocal




:menu
cls
title Botanko Gameloop AIO
rem Reset color to default
color 07
echo Select an option:
echo.
echo 1) Launch BGMI
echo 2) Fixer
echo 3) Restart BGMI Apk
echo 4) BGMI GFX Tool
echo 5) Gameloop Tweaks
echo 6) Safe Exit
echo 7) Install BGMI
echo.
choice /C 1234567 /N /M "Enter your choice (1-7): "

if errorlevel 7 goto install_bgmi
if errorlevel 6 goto safe_exit
if errorlevel 5 goto gameloop_tweaks
if errorlevel 4 goto bgmi_gfx_tool
if errorlevel 3 goto restart_bgmi
if errorlevel 2 goto fixer_menu
if errorlevel 1 goto launch_bgmi
goto menu

:launch_bgmi

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

rem Check if the script is running with administrative privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting administrative privileges...
    powershell -Command "Start-Process cmd -Argument '/c %~s0' -Verb runAs"
    exit /b
)

rem Check for GameLoop installation path in the registry
FOR /F "usebackq tokens=2*" %%I IN (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Tencent\MobileGamePC\UI" /v 
InstallPath`) DO (
    SET "InstallPath=%%J"
)

rem Check if the installation path was found
IF NOT DEFINED InstallPath (
    echo GameLoop is not installed, Do you want to download GameLoop now?
    echo Press 1 to Download GameLoop, 2 to Exit.
    choice /C 12 /N /M "Select your option:"
    if errorlevel 2 (
        echo Exiting. >nul 2>&1
        exit /b
    ) else if errorlevel 1 (
        echo Reopen Botanko AIO.bat after installing GameLoop
        pause
        start "" "https://www.gameloop.com/"
        if !errorlevel! neq 0 (
            echo Failed to open the browser. Error level: !errorlevel! >nul 2>&1
        ) else (
            echo Reopen Botanko AIO.bat after installing GameLoop.
        )
        exit /b
    )
) ELSE (
    echo GameLoop is installed at: !InstallPath! >nul 2>&1
    goto ContinueLaunch
)


:ContinueLaunch
:: Set the registry keys to enable ADB and RootEnabled
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "AdbDisable" /t REG_DWORD /d 0 /f   >nul 2>&1
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "RootEnabled" /t REG_DWORD /d 1 /f  >nul 2>&1
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v VMDeviceModel /t REG_SZ /d "SM-X910" /f


:: Disable Fixer before launching
netsh advfirewall firewall delete rule name="hola" >nul 2>&1


:: Set the working directory to the script's directory
cd /d "%~dp0"

set "TARGET_DIR=%InstallPath%"
set "TARGET_FILE=%TARGET_DIR%\AEngine.dll"
if exist "%TARGET_FILE%" (
    takeown /F "%TARGET_FILE%" /A >nul 2>&1
    icacls "%TARGET_FILE%" /grant administrators:F >nul 2>&1
    del "%TARGET_FILE%" >nul 2>&1
    echo Deleted existing AEngine.dll file: %TARGET_FILE% >nul 2>&1
)
echo Copying new AEngine.dll file >nul 2>&1
copy /Y "resources\AEngine.dll" "%TARGET_DIR%\" >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Failed to copy AEngine.dll to %TARGET_DIR% >nul 2>&1
) else (
    echo Successfully copied AEngine.dll to %TARGET_DIR% >nul 2>&1
)



set "TARGET_DIR=%USERPROFILE%\AppData\Local\Temp"
set "TARGET_FILE=%TARGET_DIR%\AEngine.dll"
if exist "%TARGET_FILE%" (
    takeown /F "%TARGET_FILE%" /A >nul 2>&1
    icacls "%TARGET_FILE%" /grant administrators:F >nul 2>&1
    del "%TARGET_FILE%" >nul 2>&1
    echo Deleted existing AEngine.dll: %TARGET_FILE% >nul 2>&1
)
echo Copying new AEngine.dll file >nul 2>&1
copy /Y "resources\AEngine.dll" "%TARGET_DIR%\" >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Failed to copy AEngine.dll to %TARGET_DIR% >nul 2>&1
) else (
    echo Successfully copied AEngine.dll to %TARGET_DIR% >nul 2>&1


set "TARGET_FILE=%TARGET_DIR%\smk.conf"
if exist "%TARGET_FILE%" (
    takeown /F "%TARGET_FILE%" /A >nul 2>&1
    icacls "%TARGET_FILE%" /grant administrators:F >nul 2>&1
    del "%TARGET_FILE%" >nul 2>&1
    echo Deleted existing smk.conf: %TARGET_FILE% >nul 2>&1
)
echo Copying new smk.conf file >nul 2>&1
copy /Y "resources\smk.conf" "%TARGET_DIR%\" >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Failed to copy smk.conf to %TARGET_DIR% >nul 2>&1
) else (
    echo Successfully copied smk.conf to %TARGET_DIR% >nul 2>&1
)
goto check_gameloop_running_ornot

:loopwalaunch
(
:: Launching Gameloop
START "" "%InstallPath%\AndroidEmulatorEn.exe" -vm 100
echo Starting GameLoop
goto continuing_launch
)

:: Wait before checking the process

:check_gameloop_running_ornot
(
:: Fetch the PID for AndroidEmulatorEn.exe
FOR /F "tokens=2" %%A IN ('tasklist ^| find /I "AndroidEmulatorEn.exe"') DO (
    SET "PidHook=%%A"
)

:: Check if the PidHook was set
IF NOT DEFINED PidHook (
    echo AndroidEmulatorEn.exe is not running yet.
    goto loopwalaunch
)

:: Check if the process with the fetched PID is running
tasklist /FI "PID eq !PidHook!" | find "!PidHook!" >nul
IF ERRORLEVEL 1 (
    echo Process with PID !PidHook! not found.
    goto loopwalaunch
)

:: Process found; perform ADB commands
echo Process with PID !PidHook! is running.
)

:continuing_launch
:: Set the working directory to the script's directory
cd /d "%~dp0"
goto server_launch

:: Start the ADB server
:server_launch
cls
adb kill-server >nul 2>&1
adb start-server >nul 2>&1
echo ADB server started. >nul 2>&1
goto check_adb

echo Waiting for emulator to connect...
timeout /t 2 

:: Check if the emulator is connected
:check_adb
FOR /F "tokens=1,2" %%a IN ('adb devices') DO (
    IF "%%b"=="device" (
        echo Emulator is connected. >nul 2>&1
        GOTO check_bgmi_installed_launch
    )
)

:: If the emulator doesn't connect, go back to the server step
goto server_launch

:check_bgmi_installed_launch
adb shell "[ -d /sdcard/Android/obb/com.pubg.imobile ] && echo exists || echo not_exists" > temp.txt
set /p bgmi_status=<temp.txt
del temp.txt

if "%bgmi_status%"=="exists" (
    echo BGMI is installed. Proceeding...
    GOTO check_bgmi_running
) else (
    cls
    echo BGMI needs to be installed first.
    echo Please go back to the main menu and install BGMI.
    pause
    goto menu
)

:check_bgmi_running
set ACTIVITY=com.pubg.imobile/com.epicgames.ue4.SplashActivity

adb shell dumpsys activity activities | findstr /C:"%ACTIVITY%"
if %errorlevel% equ 0 (
    echo The activity %ACTIVITY% is running.
    adb shell am force-stop com.pubg.imobile
) else (
    echo The activity %ACTIVITY% is not running.
)

:create_directories
REM Create the necessary directory structure
adb shell mkdir -p /data/data/com.pubg.imobile/files/ano_tmp

rem Change to the directory where the script is located
cd /d "%~dp0"

:push_files
REM Push the ano_emu_c2.dat file to the specified location
adb push resources/ano_emu_c2.dat /data/data/com.pubg.imobile/files/ano_tmp/ano_emu_c2.dat >nul 2>&1

:: Disable Fixer before launching
netsh advfirewall firewall delete rule name="hola" >nul 2>&1

REM Start the PUBG Mobile app
adb shell am start -n com.pubg.imobile/com.epicgames.ue4.SplashActivity >nul 2>&1

echo BGMI Started, Subscribe to Botanko Gaming.
timeout /t 5 >nul




goto fixer_menu












:restart_bgmi
:: Check for GameLoop installation path
FOR /F "usebackq tokens=2*" %%I IN (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Tencent\MobileGamePC\UI" /v InstallPath`) DO (
    SET "InstallPath=%%J"
)

:: Check if the installation path was found
IF NOT DEFINED InstallPath (
    echo GameLoop installation path not found.
    exit /b 1
)

:: Check if GameLoop is already running
tasklist | find /I "AndroidEmulatorEn.exe" >nul
IF ERRORLEVEL 1 (
    echo GameLoop needs to be started first.
    goto ContinueLaunch
    echo Starting Gameloop...
) ELSE (
    echo GameLoop is already running. Skipping launch. >nul 2>&1
)


echo Restarting BGMI...
adb kill-server >nul 2>&1
adb start-server >nul 2>&1
:check_bgmi_installed_restart
adb shell "[ -d /sdcard/Android/obb/com.pubg.imobile ] && echo exists || echo not_exists" > temp.txt
set /p bgmi_status=<temp.txt
del temp.txt

if "%bgmi_status%"=="exists" (
    echo BGMI is installed. Proceeding...
    GOTO check_bgmi_running_restart
) else (
    cls
    echo BGMI needs to be installed first.
    echo Please go back to the main menu and install BGMI.
    pause
    goto menu
)

:check_bgmi_running_restart
set ACTIVITY=com.pubg.imobile/com.epicgames.ue4.SplashActivity

adb shell dumpsys activity activities | findstr /C:"%ACTIVITY%"
if %errorlevel% equ 0 (
    echo The activity %ACTIVITY% is running.
    adb shell am force-stop com.pubg.imobile
) else (
    echo The activity %ACTIVITY% is not running.
)

adb push resources/ano_emu_c2.dat /data/data/com.pubg.imobile/files/ano_tmp/ano_emu_c2.dat >nul 2>&1
netsh advfirewall firewall delete rule name="hola" >nul 2>&1
adb shell am start -n com.pubg.imobile/com.epicgames.ue4.SplashActivity >nul 2>&1
goto fixer_menu



















:bgmi_gfx_tool
color a
rem Check if the script is running with administrative privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting administrative privileges...
    powershell -Command "Start-Process cmd -Argument '/c %~s0' -Verb runAs"
    exit /b
)

rem Check for GameLoop installation path in the registry
FOR /F "usebackq tokens=2*" %%I IN (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Tencent\MobileGamePC\UI" /v 
InstallPath`) DO (
    SET "InstallPath=%%J"
)

rem Check if the installation path was found
IF NOT DEFINED InstallPath (
    echo GameLoop is not installed, Do you want to download GameLoop now?
    echo Press 1 to Download GameLoop, 2 to Exit.
    choice /C 12 /N /M "Select your option:"
    if errorlevel 2 (
        echo Exiting. >nul 2>&1
        exit /b
    ) else if errorlevel 1 (
        echo Reopen Botanko AIO.bat after installing GameLoop
        pause
        start "" "https://www.gameloop.com/"
        if !errorlevel! neq 0 (
            echo Failed to open the browser. Error level: !errorlevel! >nul 2>&1
        ) else (
            echo Reopen Botanko AIO.bat after installing GameLoop.
        )
        exit /b
    )
) ELSE (
    echo GameLoop is installed at: !InstallPath! >nul 2>&1
    goto continue
)


:continue
:: Set the registry keys to enable ADB and RootEnabled
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "AdbDisable" /t REG_DWORD /d 0 /f   >nul 2>&1
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "RootEnabled" /t REG_DWORD /d 1 /f  >nul 2>&1
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v VMDeviceModel /t REG_SZ /d "SM-X910" /f

:: Disable Fixer before launching
netsh advfirewall firewall delete rule name="hola" >nul 2>&1


:: Set the working directory to the script's directory
cd /d "%~dp0"


set "TARGET_DIR=%InstallPath%"
set "TARGET_FILE=%TARGET_DIR%\AEngine.dll"
if exist "%TARGET_FILE%" (
    takeown /F "%TARGET_FILE%" /A >nul 2>&1
    icacls "%TARGET_FILE%" /grant administrators:F >nul 2>&1
    del "%TARGET_FILE%" >nul 2>&1
    echo Deleted existing AEngine.dll file: %TARGET_FILE% >nul 2>&1
)
echo Copying new AEngine.dll file >nul 2>&1
copy /Y "resources\AEngine.dll" "%TARGET_DIR%\" >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Failed to copy AEngine.dll to %TARGET_DIR% >nul 2>&1
) else (
    echo Successfully copied AEngine.dll to %TARGET_DIR% >nul 2>&1
)



set "TARGET_DIR=%USERPROFILE%\AppData\Local\Temp"
set "TARGET_FILE=%TARGET_DIR%\AEngine.dll"
if exist "%TARGET_FILE%" (
    takeown /F "%TARGET_FILE%" /A >nul 2>&1
    icacls "%TARGET_FILE%" /grant administrators:F >nul 2>&1
    del "%TARGET_FILE%" >nul 2>&1
    echo Deleted existing AEngine.dll: %TARGET_FILE% >nul 2>&1
)
echo Copying new AEngine.dll file >nul 2>&1
copy /Y "resources\AEngine.dll" "%TARGET_DIR%\" >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Failed to copy AEngine.dll to %TARGET_DIR% >nul 2>&1
) else (
    echo Successfully copied AEngine.dll to %TARGET_DIR% >nul 2>&1
)

set "TARGET_FILE=%TARGET_DIR%\smk.conf"
if exist "%TARGET_FILE%" (
    takeown /F "%TARGET_FILE%" /A >nul 2>&1
    icacls "%TARGET_FILE%" /grant administrators:F >nul 2>&1
    del "%TARGET_FILE%" >nul 2>&1
    echo Deleted existing smk.conf: %TARGET_FILE% >nul 2>&1
)
echo Copying new smk.conf file >nul 2>&1
copy /Y "resources\smk.conf" "%TARGET_DIR%\" >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Failed to copy smk.conf to %TARGET_DIR% >nul 2>&1
) else (
    echo Successfully copied smk.conf to %TARGET_DIR% >nul 2>&1
    goto continue_graphics
)


:loopwa

:: Launching Gameloop
START "" "%InstallPath%\AndroidEmulatorEn.exe" -vm 100
echo Starting GameLoop
:: Wait before checking the process

:continue_graphics
:: Fetch the PID for AndroidEmulatorEn.exe
FOR /F "tokens=2" %%A IN ('tasklist ^| find /I "AndroidEmulatorEn.exe"') DO (
    SET "PidHook=%%A"
)

:: Check if the PidHook was set
IF NOT DEFINED PidHook (
    echo AndroidEmulatorEn.exe is not running yet.
    goto loopwa
)

:: Check if the process with the fetched PID is running
tasklist /FI "PID eq !PidHook!" | find "!PidHook!" >nul
IF ERRORLEVEL 1 (
    echo Process with PID !PidHook! not found.
    goto loopwa
)

:: Process found; perform ADB commands
echo Process with PID !PidHook! is running.
goto server


:: Set the working directory to the script's directory
cd /d "%~dp0"

:: Start the ADB server
:server
cls
adb kill-server >nul 2>&1
adb start-server >nul 2>&1
echo ADB server started. >nul 2>&1
goto check_adb

echo Waiting for emulator to connect...
timeout /t 2 

:: Check if the emulator is connected
:check_adb
FOR /F "tokens=1,2" %%a IN ('adb devices') DO (
    IF "%%b"=="device" (
        echo Emulator is connected. >nul 2>&1
        GOTO check_bgmi_installed
    )
)

:: If the emulator doesn't connect, go back to the server step
goto server

:check_bgmi_installed
adb shell "[ -d /sdcard/Android/obb/com.pubg.imobile ] && echo exists || echo not_exists" > temp.txt
set /p bgmi_status=<temp.txt
del temp.txt

if "%bgmi_status%"=="exists" (
    echo BGMI is installed. Proceeding...
    GOTO check_bgmi_running_gfx
) else (
    echo BGMI needs to be installed first.
    echo Please go back to the main menu and install BGMI.
    pause
    goto menu
)

:check_bgmi_running_gfx
set ACTIVITY=com.pubg.imobile/com.epicgames.ue4.SplashActivity

adb shell dumpsys activity activities | findstr /C:"%ACTIVITY%"
if %errorlevel% equ 0 (
    echo The activity %ACTIVITY% is running.
    adb shell am force-stop com.pubg.imobile
) else (
    echo The activity %ACTIVITY% is not running.
)

cls
echo ===================================
echo Botanko Gaming GameLoop GFX Tool
echo ===================================
echo.
echo Select FPS option:
echo 1) 90 FPS
echo 2) 120 FPS
echo 3) Go back to main menu
choice /C 123 /N /M "Enter your choice (1-3): "

set FPS_CHOICE=%ERRORLEVEL%

if %FPS_CHOICE%==3 goto menu

cls
echo Select graphics option:
echo 1) Smooth
echo 2) Balanced
echo 3) HD
echo 4) HDR
echo 5) Ultra HDR
echo 6) Go back to FPS menu
choice /C 123456 /N /M "Enter your choice (1-6): "

set GRAPHICS_CHOICE=%ERRORLEVEL%

if %GRAPHICS_CHOICE%==6 goto :fps_menu

if %FPS_CHOICE%==1 (
    set "FPS_FOLDER=90fps config"
) else (
    set "FPS_FOLDER=120fps config"
)

if %GRAPHICS_CHOICE%==1 (
    set "GRAPHICS_FOLDER=Smooth"
) else if %GRAPHICS_CHOICE%==2 (
    set "GRAPHICS_FOLDER=Balanced"
) else if %GRAPHICS_CHOICE%==3 (
    set "GRAPHICS_FOLDER=HD"
) else if %GRAPHICS_CHOICE%==4 (
    set "GRAPHICS_FOLDER=HDR"
) else (
    set "GRAPHICS_FOLDER=Ultra HDR"
)

rem Construct full path to Active.sav
set "FULL_PATH=%~dp0resources\Active_Sav_Files\%FPS_FOLDER%\%GRAPHICS_FOLDER%\Active.sav"

rem Check if the file exists
if not exist "%FULL_PATH%" (
    echo Error: The file "%FULL_PATH%" does not exist.
    exit /b 1
)

rem Create the necessary directory structure
cd /d "%~dp0"
adb shell mkdir -p sdcard/Android/Data/com.pubg.imobile/files/UE4Game/ShadowTrackerExtra/ShadowTrackerExtra/Saved/SaveGames

rem Push the Active.sav file to the specified location
cd /d "%~dp0"
adb push "%FULL_PATH%" sdcard/Android/Data/com.pubg.imobile/files/UE4Game/ShadowTrackerExtra/ShadowTrackerExtra/Saved/SaveGames/Active.sav

echo Configuration applied successfully.
pause
goto menu






:gameloop_tweaks
color a
cls
echo Checking for running Gameloop processes...

set "foundTasks=0"

:: Check if GameLoop or related processes are running
for %%P in (
    "AndroidEmulatorEn.exe"
    "tencentdl.exe" 
    "aow_exe.exe" 
    "TP3Helper.exe" 
    "tp3helper.dat"
    "QMEmulatorService.exe" 
    "adb.exe" 
    "TBSWebRenderer.exe" 
    "AppMarket.exe"
    "AndroidEmulator.exe"
    "syzs_dl_svr.exe" 
) do (
    tasklist | find /I "%%~P" >nul
    if !errorlevel! equ 0 (
        echo %%~P is running.
        set /a foundTasks+=1
    )
)

if !foundTasks! gtr 0 (
    echo Gameloop needs to be closed before proceeding.
    echo 1. Close all Gameloop-related tasks and proceed
    echo 2. Go back to the main menu
    choice /C 12 /N /M "Enter your choice (1 or 2): "
    if errorlevel 2 goto menu
    if errorlevel 1 goto CloseGameloop
) else (
    echo No Gameloop processes are running.
    goto Gameloop_graphics_menu
)

:CloseGameloop
cls
echo Closing Gameloop processes...

:: Close the necessary processes
for %%P in (
    "AndroidEmulatorEn.exe"
    "tencentdl.exe"
    "aow_exe.exe"
    "TP3Helper.exe"
    "tp3helper.dat"
    "QMEmulatorService.exe"
    "adb.exe"
    "TBSWebRenderer.exe"
    "AppMarket.exe"
    "AndroidEmulator.exe"
    "syzs_dl_svr.exe"
) do (
    echo Closing %%P...
    taskkill /F /IM %%P >nul 2>&1
    if !errorlevel! equ 0 (
        echo %%P closed successfully.
    ) else (
        echo Failed to close %%P or it was not running. >nul 2>&1
    )
)

:: Stop services
echo Stopping QMEmulatorService...
net stop QMEmulatorService >nul 2>&1
echo Stopping aow_drv...
net stop aow_drv >nul 2>&1

:: Cleanup
echo Cleaning up files...
if exist C:\aow_drv.log del C:\aow_drv.log >nul 2>&1
if exist C:\ProgramData\Tencent rmdir /s /q C:\ProgramData\Tencent >nul 2>&1
if exist C:\Users\%USERNAME%\AppData\Local\Tencent rmdir /s /q C:\Users\%USERNAME%\AppData\Local\Tencent >nul 2>&1
if exist C:\Users\%USERNAME%\AppData\Roaming\Tencent rmdir /s /q C:\Users\%USERNAME%\AppData\Roaming\Tencent >nul 2>&1

echo All Gameloop processes have been closed and cleanup is complete.
goto Gameloop_graphics_menu

:Gameloop_graphics_menu
rem Change to the directory where the script is located
cd /d "%~dp0"
cls
echo.
echo 1) Resolution
echo 2) Graphics Render Quality
echo 3) FPS
echo 4) Keymapping
echo 5) Go back to main menu
choice /C 12345 /N /M "Choose an option (1-5): "

if errorlevel 5 goto menu
if errorlevel 4 goto Gameloop_keymapping_menu
if errorlevel 3 goto Gameloop_FPS_menu
if errorlevel 2 goto Gameloop_graphics_Quality
if errorlevel 1 goto Resolution_Menu


:Resolution_Menu
cls
echo 1) SD 720P
echo 2) HD 1080P
echo 3) UHD 2K
echo 4) Go back to Gamleoop graphics menu
set /p resChoice=Choose a resolution (1-4): 


if "%resChoice%"=="1" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_ContentScale" /t REG_DWORD /d 0 /f
    echo Set to SD 720P
    echo Done!
)
if "%resChoice%"=="2" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_ContentScale" /t REG_DWORD /d 1 /f
    echo Set to HD 1080P
    echo Done!
)
if "%resChoice%"=="3" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_ContentScale" /t REG_DWORD /d 2 /f
    echo Set to UHD 2K
    echo Done!
)

echo Resolution set successfully!
goto Gameloop_graphics_menu

:Gameloop_graphics_Quality
cls
echo 1) SMOOTH
echo 2) BALANCED
echo 3) HD

set /p graphicsChoice=Choose graphics quality (1-3): 

if "%graphicsChoice%"=="1" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_RenderQuality" /t REG_DWORD /d 0 /f
    echo Set to SMOOTH
)
if "%graphicsChoice%"=="2" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_RenderQuality" /t REG_DWORD /d 1 /f
    echo Set to BALANCED
)
if "%graphicsChoice%"=="3" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_RenderQuality" /t REG_DWORD /d 2 /f
    echo Set to HD
)

goto Gameloop_graphics_Menu

:Gameloop_FPS_menu
cls
echo 1) 30 FPS
echo 2) 40 FPS
echo 3) 60 FPS
echo 4) 90 FPS
echo 5) 120 FPS
set /p fpsChoice=Choose FPS (1-5): 

if "%fpsChoice%"=="1" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_FPSLevel" /t REG_DWORD /d 30 /f
    echo Set to 30 FPS
)
if "%fpsChoice%"=="2" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_FPSLevel" /t REG_DWORD /d 40 /f
    echo Set to 40 FPS
)
if "%fpsChoice%"=="3" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_FPSLevel" /t REG_DWORD /d 60 /f
    echo Set to 60 FPS
)
if "%fpsChoice%"=="4" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_FPSLevel" /t REG_DWORD /d 90 /f
    echo Set to 90 FPS
)
if "%fpsChoice%"=="5" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_FPSLevel" /t REG_DWORD /d 120 /f
    echo Set to 120 FPS
)

goto Gameloop_graphics_menu




:Gameloop_keymapping_menu

rem Change to the directory where the script is located
cd /d "%~dp0"
cls
echo 1) Normal
echo 2) Ipad View
echo 3) Go back to main menu
choice /C 123 /N /M "Choose an option (1-3): "

if errorlevel 3 goto menu
if errorlevel 2 goto Gameloop_keymapping_menu_ipad_view
if errorlevel 1 goto Gameloop_keymapping_menu_normal

:Gameloop_keymapping_menu_normal
set "TARGET_DIR=C:\Users\%USERNAME%\AppData\Roaming\AndroidTbox"
set "TARGET_FILE=%TARGET_DIR%\TVM_100.xml"

:: Create the target directory if it doesn't exist
if not exist "%TARGET_DIR%" (
    mkdir "%TARGET_DIR%"
)

:: Delete the target file if it exists
if exist "%TARGET_FILE%" (
    del "%TARGET_FILE%"
    echo Deleted existing file: %TARGET_FILE%
)
cls
:: Display keymapping choice menu
echo Select keymapping:
echo 1) SD 720P
echo 2) HD 1080P
echo 3) UHD 2K
choice /C 123 /N /M "Choose a keymapping (1-3): "

set resChoice=%errorlevel%

if "%resChoice%"=="1" (
    echo Set to SD 720P
    echo Copying 720p keymapping file...
    copy /Y "resources\Keymapping\Normal\720p\TVM_100.xml" "%TARGET_DIR%\"
)
if "%resChoice%"=="2" (
    echo Set to HD 1080P
    echo Copying 1080p keymapping file...
    copy /Y "resources\Keymapping\Normal\1080p\TVM_100.xml" "%TARGET_DIR%\"
)
if "%resChoice%"=="3" (
    echo Set to UHD 2K
    echo Copying 2k keymapping file...
    copy /Y "resources\Keymapping\Normal\2k\TVM_100.xml" "%TARGET_DIR%\"
)

echo Keymapping set successfully!
timeout /t 2 >nul
goto Gameloop_graphics_menu











:Gameloop_keymapping_menu_ipad_view
set "TARGET_DIR=C:\Users\%USERNAME%\AppData\Roaming\AndroidTbox"
set "TARGET_FILE=%TARGET_DIR%\TVM_100.xml"

:: Create the target directory if it doesn't exist
if not exist "%TARGET_DIR%" (
    mkdir "%TARGET_DIR%"
)

:: Delete the target file if it exists
if exist "%TARGET_FILE%" (
    del "%TARGET_FILE%"
    echo Deleted existing file: %TARGET_FILE%
)
cls
echo 1) SD 720P
echo 2) HD 1080P
echo 3) UHD 2K
choice /C 123 /N /M "Choose a keymapping (1-3): "

set resChoice=%errorlevel%

if "%resChoice%"=="1" (
    echo Set to SD 720P
    echo Copying 720p keymapping file...
    copy /Y "resources\Keymapping\iPad_View\720p\TVM_100.xml" "%TARGET_DIR%\" >nul
)
if "%resChoice%"=="2" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_ContentScale" /t REG_DWORD /d 1 /f
    echo Set to HD 1080P
    echo Copying 1080p keymapping file...
    copy /Y "resources\Keymapping\iPad_View\1080p\TVM_100.xml" "%TARGET_DIR%\" >nul
)
if "%resChoice%"=="3" (
    reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "com.tencent.ig_ContentScale" /t REG_DWORD /d 2 /f
    echo Set to UHD 2K
    echo Copying 2k keymapping file...
    copy /Y "resources\Keymapping\iPad_View\2k\TVM_100.xml" "%TARGET_DIR%\" >nul
)

echo Keymapping set successfully!
timeout /t 2 >nul
goto Gameloop_graphics_menu











:safe_exit
@ECHO OFF
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo Requesting administrative privileges...
    PowerShell -Command "Start-Process '%~f0' -Verb runAs"
    exit /b
)
cls
taskkill /F /im AndroidEmulatorEn.exe
taskkill /F /im AndroidEmulatorEn.exe
taskkill /f /im tencentdl.exe
taskkill /f /im aow_exe.exe
taskkill /F /IM TP3Helper.exe
taskkill /F /IM tp3helper.dat
TaskKill /F /IM aow_exe.exe
TaskKill /F /IM QMEmulatorService.exe
TaskKill /F /IM RuntimeBroker.exe
taskkill /F /im adb.exe
taskkill /F /im TBSWebRenderer.exe
taskkill /F /im AppMarket.exe
taskkill /F /im AndroidEmulator.exe
taskkill /F /im syzs_dl_svr.exe
cls
net stop QMEmulatorService
net stop aow_drv
del C:\aow_drv.log
del /s /f /q C:\ProgramData\Tencent
del /s /f /q C:\Users\%USERNAME%\AppData\Local\Tencent
del /s /f /q C:\Users\%USERNAME%\AppData\Roaming\Tencent
goto menu





















:fixer_menu
@echo off
cls
rem Define variables
set "ruleName=hola"
set "foundRule="
set "softwareName=AndroidEmulatorEn"
set "executablePath="
rem Check if the firewall is enabled
netsh advfirewall show allprofiles state | find "State" | find "ON" >nul
if %errorlevel% neq 0 (
    echo Windows Firewall is disabled. Please enable the firewall to use this fixer.
    pause
    goto fixer_menu
)
rem Check if the process is running and get the path
for /f "tokens=1" %%i in ('tasklist /fo csv ^| find /I "AndroidEmulatorEn.exe"') do (
    set "processName=%%~i"
)
rem Get the executable path based on the process name
for /f "tokens=2 delims=," %%i in ('wmic process where "name='AndroidEmulatorEn.exe'" get ExecutablePath /format:csv ^| find /I "AndroidEmulatorEn.exe"') do (
    set "executablePath=%%~i"
)
rem If the path was not found, exit
if "%executablePath%"=="" (
    echo Gameloop is not running. Please ensure it is running.
    pause
    goto menu
)
rem Check if the rule exists
netsh advfirewall firewall show rule name="%ruleName%" >nul 2>&1
if %errorlevel% equ 0 (
    set "foundRule=true"
) else (
    set "foundRule="
)

cls
rem Reset color to default
color 07

rem Display current status at the top
if defined foundRule (
    color 2F
    echo Current Status : Fixer on
) else (
    color 4F
    echo Current Status : Fixer off
)
echo.

echo Select an option:
echo 1. Start Fixer
echo 2. Stop Fixer
echo 3. No match found fix
echo 4. Main menu
choice /C 1234 /N /M "Enter your choice (1-4): "

if errorlevel 4 (
    color 07
    goto menu
)
if errorlevel 3 (
    echo Turning on Fixer for No match found fix...
    netsh advfirewall firewall add rule name="%ruleName%" protocol=TCP remoteport=9031,443,8700,8013,20002,80,8088,8086,9030,20000,10427,9031,10012,10012,17500 dir=out action=block program="%executablePath%"
    timeout /t 2 >nul
    netsh advfirewall firewall delete rule name="%ruleName%" >nul 2>&1
    set "foundRule="
) else if errorlevel 2 (
    netsh advfirewall firewall delete rule name="%ruleName%" >nul 2>&1
    set "foundRule="
) else if errorlevel 1 (
    echo Starting Fixer..
    REM Add firewall rule for the specified software
    netsh advfirewall firewall add rule name="%ruleName%" protocol=TCP remoteport=9031,443,8700,8013,20002,80,8088,8086,9030,20000,10427,9031,10012,10012,17500 dir=out action=block program="%executablePath%"
    set "foundRule=true"
)

rem Stay on the Fixer menu after an action is taken
goto fixer_menu




















:install_bgmi
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

rem Check if the script is running with administrative privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting administrative privileges...
    powershell -Command "Start-Process cmd -Argument '/c %~s0' -Verb runAs"
    exit /b
)

rem Check for GameLoop installation path in the registry
FOR /F "usebackq tokens=2*" %%I IN (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Tencent\MobileGamePC\UI" /v InstallPath`) DO (
    SET "InstallPath=%%J"
)

rem Check if the installation path was found
IF NOT DEFINED InstallPath (
    echo GameLoop is not installed, Do you want to download GameLoop now?
    echo Press 1 to Download GameLoop, 2 to Exit.
    choice /C 12 /N /M "Select your option:"
    if errorlevel 2 (
        echo Exiting. >nul 2>&1
        exit /b
    ) else if errorlevel 1 (
        echo Reopen Botanko AIO.bat after installing GameLoop
        pause
        start "" "https://www.gameloop.com/"
        if !errorlevel! neq 0 (
            echo Failed to open the browser. Error level: !errorlevel! >nul 2>&1
        ) else (
            echo Reopen Botanko AIO.bat after installing GameLoop.
        )
        exit /b
    )
) ELSE (
    echo GameLoop is installed at: !InstallPath! >nul 2>&1
    goto ContinueLaunch_install
)

:ContinueLaunch_install
:: Set the registry keys to enable ADB and RootEnabled
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "AdbDisable" /t REG_DWORD /d 0 /f   >nul 2>&1
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v "RootEnabled" /t REG_DWORD /d 1 /f  >nul 2>&1
reg add "HKEY_CURRENT_USER\Software\Tencent\MobileGamePC" /v VMDeviceModel /t REG_SZ /d "SM-X910" /f

:: Disable Fixer before launching
netsh advfirewall firewall delete rule name="hola" >nul 2>&1

goto check_gameloop_running_ornot_install

:loopwalaunch_install
(
    :: Launching Gameloop
    START "" "%InstallPath%\AndroidEmulatorEn.exe" -vm 100
    echo Starting GameLoop
    goto continuing_launch_install
)

:: Wait before checking the process

:check_gameloop_running_ornot_install
(
    :: Fetch the PID for AndroidEmulatorEn.exe
    FOR /F "tokens=2" %%A IN ('tasklist ^| find /I "AndroidEmulatorEn.exe"') DO (
        SET "PidHook=%%A"
    )

    :: Check if the PidHook was set
    IF NOT DEFINED PidHook (
        echo AndroidEmulatorEn.exe is not running yet.
        goto loopwalaunch_install
    )

    :: Check if the process with the fetched PID is running
    tasklist /FI "PID eq !PidHook!" | find "!PidHook!" >nul
    IF ERRORLEVEL 1 (
        echo Process with PID !PidHook! not found.
        goto loopwalaunch_install
    )

    :: Process found; perform ADB commands
    echo Process with PID !PidHook! is running.
    goto continuing_launch_install
)


:continuing_launch_install
:: Set the working directory to the script's directory
cd /d "%~dp0"

goto server_launch_install

:: Start the ADB server
:server_launch_install
cls
adb kill-server >nul 2>&1
adb start-server >nul 2>&1
echo ADB server started. >nul 2>&1
goto check_adb

echo Waiting for emulator to connect...
timeout /t 2 

:: Check if the emulator is connected
:check_adb
FOR /F "tokens=1,2" %%a IN ('adb devices') DO (
    IF "%%b"=="device" (
        echo Emulator is connected. >nul 2>&1
        GOTO check_bgmi_installed_install
    )
)
:: If the emulator doesn't connect, go back to the server step
goto server_launch_install

:check_bgmi_installed_install
(
    adb shell "[ -d /sdcard/Android/obb/com.pubg.imobile ] && echo exists || echo not_exists" > temp.txt
    set /p bgmi_status=<temp.txt
    del temp.txt

    if "%bgmi_status%"=="exists" (
        echo BGMI is already installed, do you want to reinstall it?
        choice /C YN /N /M "Do you want to reinstall BGMI? (Y/N): "
        if "%errorlevel%"=="1" (
            GOTO hojabhai
        ) else (
            echo Reinstallation cancelled.
            pause
            goto menu
        )
    )
)

:hojabhai
title BGMI 3.4 Installer
color 3

:: Change to the directory where the batch file is located
cd /d "%~dp0"

echo Starting installation of BGMI
title Installing BGMI in Gameloop ................ STEP 1 of 2

if not exist "resources\BGMI_Apk\package1.apx" (
    echo Error: package1.apx not found in resources\BGMI_Apk folder.
    pause
    exit /b
)
adb install -r "resources\BGMI_Apk\package1.apx" >NUL

title Installing BGMI in Gameloop ................ STEP 1 of 2
adb shell mkdir /sdcard/Android/obb >nul 2>&1
adb shell mkdir /sdcard/Android/obb/com.pubg.imobile >nul 2>&1

title Installing BGMI in Gameloop ................ STEP 2 of 2
adb shell mkdir -p /sdcard/Android/data/com.pubg.imobile/files/UE4Game/ShadowTrackerExtra/ShadowTrackerExtra/Saved/Paks >NUL

if not exist "resources\BGMI_Apk\package2.apx" (
    echo Error: package2.apx not found in resources\BGMI_Apk folder.
    pause
    exit /b
)
adb push "resources\BGMI_Apk\package2.apx" /sdcard/Android/obb/com.pubg.imobile/main.19120.com.pubg.imobile.obb >NUL
adb push resources/ano_emu_c2.dat /data/data/com.pubg.imobile/files/ano_tmp/ano_emu_c2.dat >nul 2>&1
title Successfully Installed Battlegrounds Mobile India!
echo Thank you for using our BGMI installer. Now you can play BGMI in Gameloop!
pause
goto menu