Guide:DDSopt/Batch Files/2 Pre-Optimization

From Step Mods | Change The Game

REM Batch file to perform several tasks to prepare vanilla textures
REM for optimization using DDSopt as per steps in the DDSopt guide (https://stepmodifications.org/wiki/Guide:DDSopt#tab=DDSopt_Optimization).
REM It is only useful when being used with other steps described in this guide.
REM Like all batch files that change or add files, it needs to be run with Administrative Privilege.
REM If this batch file is edited, this MUST BE DONE with an editor that does not add additional characters (e.g., line feed, carriage return)
REM these characters are often invisible but can cause the batch file to malfunction
REM DO NOT USE a default Windows text editor to edit this file
REM Editors like Notepad++ (which was used to create this file), TextPad, UltraEdit are fine

REM It expects that there is a Working directory containing the "Vanilla Extracted" directory
REM This directory should not be in any User Access Controlled (UAC) directory such as Program Files or Program Files (x86).
REM It expects that the BSA contents have already been extracted into folders in the  "Vanilla Extracted" directory
REM It expects a folder in "Vanilla Extracted" labeled "STD"
REM If the HRDLC are being optimized, the extracted BSA contents should be in "HRDLC1", "HRDLC2", "HRDLC3" in "Vanilla Extracted"
REM If there are any optional DLC being used their BSAs should have also been extracted into "Vanilla Extracted"
REM with folder names of "Dawnguard", "Hearthfires", and "Dragonborn" (based on the DLC being used).
REM
REM The batch file first copies .png files in the STD folder in "Vanilla Extracted" to the STD folder in "Vanilla Optimized"
REM The .png files in the DLC BSAs REMain there so they don't need to be copied
REM
REM To prepare the vanilla textures this batch file copies vanilla texture files (files ending in .dds) from folders 
REM in "Vanilla Extracted" to "Vanilla Textures" while excluding normal map textures (file names ending in _n.dds and _msn.dds)
REM from the HRDLC
REM Any large compressed normal maps (2Kx2K) in the Skyrim - Textures.bsa and the addon DLC BSA are copied to "Vanilla Normal Maps"
REM The rest of the compressed normal map textures in Skyrim - Textures.bsa and the addon DLC BSA are all low to medium resolution
REM Since their resolutions are not very high, these are optimized with the rest of the textures without changing resolution
REM
REM The batch file copies uncompressed normal map textures from the HRDLC in "Vanilla Extracted"
REM to the corresponding folders in the "Vanilla Uncompressed Normal Maps" directory.
REM
REM Finally, the batch file copies the rest of the normal map textures from the HRDLC in "Vanilla Extracted"
REM and any large normal maps in the other directories to the corresponding folders (as mentiond above) in the "Vanilla Normal Maps" directory.
REM
REM While the batch file runs there will be a command window that echoes the commands
REM This allows monitoring the progress of the batch processing if desired, although it is not required.

REM the initial 2 lines should ensure that the system provides the correct working directory name in %cd%
REM This is needed for a small percentage of systems, probably because of interaction with Windows UAC on those systems

REM tests added 8/18/2013 to make sure the batch files are in the right folder and the folder structures are correct

@setlocal enableextensions
@cd /d "%~dp0"
 
echo off
echo.
echo The system says the Working Directory is   %cd%
echo This directory should include the "Vanilla Extracted" directory
echo If any of the above is incorrect terminate the processing and fix the problem
echo.


IF NOT EXIST "%cd%\Vanilla Extracted" echo The Vanilla Extracted directory is not in the working directory; fix this before proceeding
echo.
pause

echo on
 
IF NOT EXIST "%cd%\Vanilla Textures\NUL"  MD "Vanilla Textures"
IF NOT EXIST "%cd%\Vanilla Normal Maps\NUL"  MD "Vanilla Normal Maps"
IF NOT EXIST "%cd%\Vanilla Optimized\NUL"  MD "Vanilla Optimized"
IF NOT EXIST "%cd%\Vanilla Uncompressed Normal Maps\NUL"  MD "Vanilla Uncompressed Normal Maps"
cd "Vanilla Optimized"
IF NOT EXIST \STD\NUL  MD STD
cd ..

cd "Vanilla Textures"
IF EXIST "..\Vanilla Extracted\HRDLC1" IF NOT EXIST \HRDLC1\NUL  MD HRDLC1
IF EXIST "..\Vanilla Extracted\HRDLC2" IF NOT EXIST \HRDLC2\NUL  MD HRDLC2
IF EXIST "..\Vanilla Extracted\HRDLC3" IF NOT EXIST \HRDLC3\NUL  MD HRDLC3
cd ..

cd "Vanilla Uncompressed Normal Maps"
IF EXIST "..\Vanilla Extracted\HRDLC1" IF NOT EXIST \HRDLC1\NUL  MD HRDLC1
IF EXIST "..\Vanilla Extracted\HRDLC2" IF NOT EXIST \HRDLC2\textures\terrain\NUL  MD HRDLC2\textures\terrain\
IF EXIST "..\Vanilla Extracted\HRDLC3" IF NOT EXIST \HRDLC3\NUL  MD HRDLC3
cd .. 

REM copy the PNG files from Skyrim - textures to the Vanilla Optimized directory
IF EXIST "%cd%\Vanilla Extracted\STD" robocopy "%cd%\Vanilla Extracted\STD" "%cd%\Vanilla Optimized\STD" *.png /s /nfl /ndl /njh /njs /ns /nc /np >>log.txt
 
REM Copy texture files (from folders other than the HRDLC) to "Vanilla Textures ", excluding any normal map textures
robocopy "%cd%\Vanilla Extracted" "%cd%\Vanilla Textures" *.dds /s  /xd HRDLC1 HRDLC2 HRDLC3 /xf  *_n.dds /nfl /ndl /njh /njs /ns /nc /np >>log.txt
REM Copy small and medium size normal map textures (from folders other than the HRDLC) to "Vanilla Textures"
REM ignore file seruinsmarble01_n.dds that needs to be optimized manually with DDSopt using the associated tga file
robocopy "%cd%\Vanilla Extracted" "%cd%\Vanilla Textures" *_n.dds /s /max:2999999 /xf *seruinsmarble01_n.dds /xd HRDLC1 HRDLC2 HRDLC3 /nfl /ndl /njh /njs /ns /nc /np >>log.txt
REM Copy any large normal map textures (from folders other than the HRDLC) to "Vanilla Normal Maps"
robocopy "%cd%\Vanilla Extracted" "%cd%\Vanilla Normal Maps" *_n.dds /s /min:3000000 /xd HRDLC1 HRDLC2 HRDLC3 /nfl /ndl /njh /njs /ns /nc /np >>log.txt

REM Now copy texture files from the HRDLC to "Vanilla Textures" excluding any normal map textures
IF EXIST "%cd%\Vanilla Extracted\HRDLC1" robocopy "%cd%\Vanilla Extracted\HRDLC1" "%cd%\Vanilla Textures\HRDLC1" *.dds /s /xf *_n.dds *_msn.dds /nfl /ndl /njh /njs /ns /nc /np >>log.txt
IF EXIST "%cd%\Vanilla Extracted\HRDLC2"  robocopy "%cd%\Vanilla Extracted\HRDLC2" "%cd%\Vanilla Textures\HRDLC2" *.dds /s /xf *_n.dds *_msn.dds /nfl /ndl /njh /njs /ns /nc /np >>log.txt
IF EXIST "%cd%\Vanilla Extracted\HRDLC3" robocopy "%cd%\Vanilla Extracted\HRDLC3" "%cd%\Vanilla Textures\HRDLC3" *.dds /s /xf *_n.dds *_msn.dds /nfl /ndl /njh /njs /ns /nc /np >>log.txt

REM Now copy uncompressed HRDLC MSN and terrain TSN texture files to "Vanilla Uncompressed Normal Maps"

IF EXIST "%cd%\Vanilla Extracted\HRDLC1" robocopy "%cd%\Vanilla Extracted\HRDLC1" "%cd%\Vanilla Uncompressed Normal Maps\HRDLC1" *_msn.dds /s /nfl /ndl /njh /njs /ns /nc /np >>log.txt
IF EXIST "%cd%\Vanilla Extracted\HRDLC3" robocopy "%cd%\Vanilla Extracted\HRDLC3" "%cd%\Vanilla Uncompressed Normal Maps\HRDLC3" *_msn.dds /s /nfl /ndl /njh /njs /ns /nc /np >>log.txt
IF EXIST "%cd%\Vanilla Extracted\HRDLC2"  robocopy "%cd%\Vanilla Extracted\HRDLC2\textures\terrain" "%cd%\Vanilla Uncompressed Normal Maps\HRDLC2\textures\terrain" *_n.dds /s /nfl /ndl /njh /njs /ns /nc /np >>log.txt

REM Now copy the rest of the HRDLC normal maps (the compressed normal maps) to "Vanilla Normal Maps"

IF EXIST "%cd%\Vanilla Extracted\HRDLC1" robocopy "%cd%\Vanilla Extracted\HRDLC1" "%cd%\Vanilla Normal Maps\HRDLC1" *_n.dds /s /nfl /ndl /njh /njs /ns /nc /np >>log.txt
IF EXIST "%cd%\Vanilla Extracted\HRDLC2"  robocopy "%cd%\Vanilla Extracted\HRDLC2" "%cd%\Vanilla Normal Maps\HRDLC2" *_n.dds /s /xd *terrain  /nfl /ndl /njh /njs /ns /nc /np >>log.txt
IF EXIST "%cd%\Vanilla Extracted\HRDLC3" robocopy "%cd%\Vanilla Extracted\HRDLC3" "%cd%\Vanilla Normal Maps\HRDLC3" *_n.dds /s /nfl /ndl /njh /njs /ns /nc /np >>log.txt

REM When the batch file processing terminates, check the log file (log.txt). It should not show any errors.


echo off
echo.
echo When the batch file processing terminates, check the log file (log.txt).
echo The log file should not show any errors and should have 14 blank lines
echo.
pause

echo on