@echo off
@color 0C
title H266MOD Batch Launcher
pushd .
cd /d "%~dp0"

set h266dir=%cd%
set h266dir=%h266dir:"=%
set h266dir=%h266dir:\=/%

set choice=
set dcf=1
set dcconfvar=0
set vacaf=1
set vacaconfvar=0
set nwf=1
set nwconfvar=0
set hrp=
set hrpu=
set grp=
set con=
set def=
set ahrp=
goto top

:top
echo.
type "%~dp0\V.H266"
echo.
echo.
pause
echo.
:: if not exist eduke32.exe goto noeduke32
:: if not exist duke3d.grp goto nogrp
:: if not exist H266MOD.zip goto nohzip
:: if not exist H266MOD.grp goto nohgrp
goto dctest

:dctest
if exist hdukedc.grp set dcf=1
if exist dukedc.grp set dcconfvar=1
if exist dukedc.zip set dcconfvar=1
if '%dcf%'=='0' goto dcconf
goto nwtest

:dcconf
if '%dcconfvar%'=='0' goto nwtest
echo You do have DukeDC, but you haven't run its respective
echo installaion batch file yet. Even if all you want to do is
echo get rid of this warning, please run "HDukeDC.bat". It is
echo in the .rar file named "H266MOD_ADDONS.rar", which is
echo available from the same place you got "H266MOD_DATA.rar".
echo.
pause
echo.
goto nwtest

:nwtest
if exist hnwinter.grp set nwf=1
if exist nwinter.grp set nwconfvar=1
if exist nwinter.zip set nwconfvar=1
if '%nwf%'=='0' goto nwconf
goto vacatest

:nwconf
if '%nwconfvar%'=='0' goto vacatest
echo You do have Nuclear Winter, but you haven't run its respective
echo installaion batch file yet. Even if all you want to do is
echo get rid of this warning, please run "HNWinter.bat". It is
echo in the .rar file named "H266MOD_ADDONS.rar", which is
echo available from the same place you got "H266MOD_DATA.rar".
echo.
pause
echo.
goto vacatest

:vacatest
if exist hvacation.grp set vacaf=1
if exist vacation.grp set vacaconfvar=1
if exist vacation.prg set vacaconfvar=1
if exist vacation.zip set vacaconfvar=1
if '%vacaf%'=='0' goto vacaconf
goto choicepart

:vacaconf
if '%vacaconfvar%'=='0' goto choicepart
echo You do have Duke Caribbean, but you haven't run its respective
echo installaion batch file yet. Even if all you want to do is
echo get rid of this warning, please run "HVacation.bat". It is
echo in the .rar file named "H266MOD_ADDONS.rar", which is
echo available from the same place you got "H266MOD_DATA.rar".
echo.
pause
echo.
goto choicepart

:choicepart
if '%dcf%'=='0' goto forward
goto back

:back
echo What mode of H266MOD do you want to play?
echo.
echo # - Title     - Description
echo.
echo 1 - H266MOD   - H266MOD + (V)anilla Duke Nukem 3D
if '%dcf%'=='1' echo 2 - HDukeDC   - H266MOD + Duke It Out In (D).C.
if '%nwf%'=='1' echo 3 - HNWinter  - H266MOD + Duke: (N)uclear Winter
if '%vacaf%'=='1' echo 4 - HVacation - H266MOD + Duke (C)aribbean (Vacation): Life's a Beach
echo 5 - (E)xit
echo.
echo Please type the number of the your choice and press ENTER.
echo.
set choice=
set /p choice=What is your choice? 
echo.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='V' set choice=1
if '%choice%'=='v' set choice=1
if '%choice%'=='1' goto check
if '%choice%'=='D' set choice=2
if '%choice%'=='d' set choice=2
if '%choice%'=='2' goto dccheck
if '%choice%'=='N' set choice=3
if '%choice%'=='n' set choice=3
if '%choice%'=='3' goto nwcheck
if '%choice%'=='C' set choice=4
if '%choice%'=='c' set choice=4
if '%choice%'=='4' goto vacacheck
if '%choice%'=='E' set choice=5
if '%choice%'=='e' set choice=5
if '%choice%'=='5' goto end
set choice=1
goto check

:choiceerror
cls
echo.
echo "%choice%" is not valid. Please try again.
echo.
pause
cls
goto choicepart

:dccheck
if '%dcf%'=='0' goto choiceerror
goto check

:nwcheck
if '%nwf%'=='0' goto choiceerror
goto check

:vacacheck
if '%vacaf%'=='0' goto choiceerror
goto check

:forward
if '%vacaf%'=='1' goto back
if '%nwf%'=='1' goto back
goto check

:check

set hrp=duke3d_hrp.zip
if exist duke3d_xtr.zip set hrp=duke3d_xtr.zip

set hrpu=hrp_update.zip
if exist xtr_update.zip set hrpu=xtr_update.zip

:recheck
if not exist eduke32.exe goto execheck
:execheck_done

echo.
echo Launching EDuke32 . . .
:: echo.
:: echo Please leave this window open for the entire duration of your game.

if '%dcf%'=='0' goto vanillacheck

:contcheck

if '%choice%'=='1' goto vanilla
if '%choice%'=='2' set grp=DukeDC.grp
if '%choice%'=='2' set con=HDukeDC.con
if '%choice%'=='2' set def=H266DC.def
if '%choice%'=='2' set ahrp=dukedc_hrp.zip
if '%choice%'=='3' set grp=NWinter.grp
if '%choice%'=='3' set con=HNWinter.con
if '%choice%'=='3' set def=H266NW.def
if '%choice%'=='3' set ahrp=nwinter_hrp.zip
if '%choice%'=='4' set grp=Vacation.grp
if '%choice%'=='4' set con=HVacation.con
if '%choice%'=='4' set def=H266Vaca.def
if '%choice%'=='4' set ahrp=vacation_hrp.zip

start EDuke32.exe -h%def% -x%con% %* -j"%h266dir%" -j"%h266dir%/h266mod" -g%grp% -g%hrp% -g%hrpu% -g%ahrp% -gH266MOD.zip -gH266MOD.grp
goto end

:vanillacheck
if '%nwf%'=='1' goto contcheck
if '%vacaf%'=='1' goto contcheck
goto vanilla

:vanilla
start EDuke32.exe -hH266D3D.def -xHEDuke.con %* -j"%h266dir%" -j"%h266dir%/h266mod" -g%hrp% -g%hrpu% -gH266MOD.zip -gH266MOD.grp
goto end

:noeduke32
cls
echo.
echo Error: You don't have EDuke32.exe in your directory.
echo Aborting Launch.
echo.
pause
goto end

:execheck
if exist eduke32.bat goto execheck_done
if exist eduke32.exe goto recheck
set prevdir=%cd%
if not "%cd%"=="%cd:~0,3%" cd ..
if not "%cd%"=="%prevdir%" goto execheck
echo Warning: You don't have EDuke32 in your directory.
chdir /d "%~dp0"
goto execheck_done

:nohzip
cls
echo.
echo Error: You don't have H266MOD.zip in your directory.
echo Aborting Launch.
echo.
pause
goto end

:nohgrp
cls
echo.
echo Error: You don't have H266MOD.grp in your directory.
echo Aborting Launch.
echo.
pause
goto end

:nogrp
cls
echo.
echo Error: You don't have Duke3D.grp in your directory.
echo Aborting Launch.
echo.
pause
goto end

:end
set choice=0
set dcf=0
set dcconfvar=0
set vacaf=0
set vacaconfvar=0
set nwf=0
set nwconfvar=0
set hrp=
set hrpu=
set grp=
set con=
set def=
set ahrp=
echo.
:: echo Press any key to exit . . .
:: pause > NUL
@color 07
title "%ComSpec%"
popd
