anchor.diff:  )
   
   REM # restore the current directory
  -POPD+POPD
  +EXIT /B
  +
  +
  +:reg
  +REM ====================================================================================================================
  +REM # a function to read a registry key and account for 32 / 64-bit differences
  +REM # %1 = registry key | %2 = value name | returns %REG%, containing the value
  +
  +REM # SUPER IMPORTANT NOTE:
  +REM # 1. if you are on a 64-bit machine, things get real screwy with the registry --
  +REM #    a 64-bit process launching this batch script will access the registry as 64-bit,
  +REM #    meaning that 32-bit keys will not be where you expect them to be!
  +REM # 2. a 32-bit process launching this batch script will access ONLY the 32-bit registry;
  +REM #    a secret route (a "sysnative" junction) will allow us to launch the 64-bit version of REG
  +REM #    from a 32-bit process, granting a 64-bit view of the registry
  +
  +REM # check the native registry, for a native key:
  +REM # -- i.e. 32-bit system, accessing 32-bit software keys or
  +REM #         64-bit system, accessing 64-bit software keys
  +FOR /F "tokens=2*" %%A IN (
  +	'REG QUERY "%~1" /V "%~2" 2^>^&1 ^| FIND "REG_"'
  +) DO (
  +	SET "REG=%%B"
  +	GOTO:EOF
  +)
  +REM # check 32-bits keys on a 64-bit system & process:
  +REM # (note: this batch script could be running as a 32-bit or 64-bit process, so we need to forcefully invoke
  +REM          a 32-bit REG process. on 64-bit Windows, "SYSTEM32" is actually the 64-bit software and is rewritten to
  +REM          to "WINDOWS\SYSWOW64" where the 32-bit "SYSTEM32" is -- what a confusing mess)
  +FOR /F "tokens=2*" %%A IN (
  +	'%WINDIR%\SYSWOW64\REG QUERY "%~1" /V "%~2" 2^>^&1 ^| FIND "REG_"'
  +) DO (
  +	SET "REG=%%B"
  +	GOTO:EOF
  +)
  +REM # check 64-bits keys on a 32-bit system or a 32-bit process on a 64-bit system:
  +REM # thanks goes to https://ovidiupl.wordpress.com/2008/07/11/useful-wow64-file-system-trick/
  +REM # for the solution to this mess!
  +FOR /F "tokens=2*" %%A IN (
  +	'%WINDIR%\SYSNATIVE\REG QUERY "%~1" /V "%~2" 2^>^&1 ^| FIND "REG_"'
  +) DO (
  +	SET "REG=%%B"
  +	GOTO:EOF
  +)
  +REM # key not found
  +SET "REG="
  +GOTO:EOF
positive.code: 	IF EXIST "%REG%\base\wads\NERVE.WAD" SET "PWAD_PATH=%REG%\base\wads\NERVE.WAD" & GOTO :iwad
  )
  REM # if the WAD was not found, we cannot continue, the user does not have NERVE.WAD
  IF "%PWAD_PATH%" == "" (
  	ECHO:
  	ECHO   ERROR: "NERVE.WAD" missing:
  	ECHO:
  	ECHO   You must purchase "DOOM 3: BFG Edition" from Steam to get NERVE.WAD.
  	ECHO   doom.bat automatically finds it, if installed. If you have NERVE.WAD
  	ECHO   elsewhere, copy it to the "%IWADS%" folder and try again.
  	ECHO:
  	POPD
  	PAUSE
  	EXIT /B 1
  )
  REM # PWAD found, skip ahead
  GOTO :iwad
  
  :pwad_master
  REM --------------------------------------------------------------------------------------------------------------------
  REM # are we looking for "Master Levels for DOOM II"?
  IF /I NOT "%PWAD:~0,7%" == "MASTER\" GOTO :pwad_missing
  
  REM # extract the WAD name from that
  SET "WAD=%PWAD:~8%"
  
  REM # is Steam : Master Levels for DOOM II installed?
  CALL :reg "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 9160" "InstallLocation"
  IF NOT "%REG%" == "" (
  	REM # check if the WAD can be found there
  	IF EXIST "%REG%\master\wads\%WAD%" SET "PWAD_PATH=%REG%\master\wads\%WAD%"
  )
  REM # is GOG : DOOM II + Final DOOM (including Master Levels) installed?
  CALL :reg "HKLM\SOFTWARE\GOG.com\Games\1435848814" "Path"
  IF NOT "%REG%" == "" (
  	REM # check if the WAD can be found there
  	IF EXIST "%REG%\master\wads\%WAD%" SET "PWAD_PATH=%REG%\master\wads\%WAD%"
  )
  
  REM # if the WAD was not found, we cannot continue, the user does not have Master Levels
  IF "%PWAD_PATH%" == "" (
  	ECHO:
  	ECHO   ERROR: "%WAD%" missing:
  	ECHO:
  	ECHO   You must purchase either "DOOM Classic Complete" from Steam or
  	ECHO   "DOOM II + Final DOOM" from GOG to get "Master Levels for DOOM II";
  	ECHO   doom.bat automatically finds it, if installed. If you have the Master Levels
  	ECHO   WADs elsewhere, copy them to the "%IWADS%\MASTER" folder and try again.
  	ECHO:
  	POPD
  	PAUSE
  	EXIT /B 1
  )
  REM # PWAD found, skip ahead
  GOTO :iwad
  
  :pwad_missing
  REM --------------------------------------------------------------------------------------------------------------------
  
negative.code: 	:deh
  	REM ------------------------------------------------------------------------------------------------------------
  	REM # load a DeHackEd extension:
  	SET DEH=%DEH% "%FIX_PATH%\%FILE%"
  	CALL :prev_dir "%FILE%"
  	SET ANY_DEH=1
  