@echo off
setlocal

echo Please enter DELTARUNE's install path:
set /p gamePath=Path: 

if not exist "%gamePath%" (
    echo [ERROR] Path "%gamePath%" does not exist.
    pause
    exit /b 1
)

echo Patching Chapter 1...
xdelta.exe -d -f -s "%gamePath%\chapter1_windows\lang\lang_en.json" FemaleKrisPart1.xdelta "%gamePath%\chapter1_windows\lang\lang_en_patched.json"
if errorlevel 1 (
    echo Failed to patch FemaleKrisPart1.xdelta
) else (
    del "%gamePath%\chapter1_windows\lang\lang_en.json"
    ren "%gamePath%\chapter1_windows\lang\lang_en_patched.json" "lang_en.json"
)

echo Patching Chapter 2...
xdelta.exe -d -f -s "%gamePath%\chapter2_windows\data.win" FemaleKrisPart2.xdelta "%gamePath%\chapter2_windows\data_patched.win"
if errorlevel 1 (
    echo Failed to patch FemaleKrisPart2.xdelta
) else (
    del "%gamePath%\chapter2_windows\data.win"
    ren "%gamePath%\chapter2_windows\data_patched.win" "data.win"
)

echo Patching Chapter 3...
xdelta.exe -d -f -s "%gamePath%\chapter3_windows\data.win" FemaleKrisPart3.xdelta "%gamePath%\chapter3_windows\data_patched.win"
if errorlevel 1 (
    echo Failed to patch FemaleKrisPart3.xdelta
) else (
    del "%gamePath%\chapter3_windows\data.win"
    ren "%gamePath%\chapter3_windows\data_patched.win" "data.win"
)

echo Patching Chapter 4...
xdelta.exe -d -f -s "%gamePath%\chapter4_windows\data.win" FemaleKrisPart4.xdelta "%gamePath%\chapter4_windows\data_patched.win"
if errorlevel 1 (
    echo Failed to patch FemaleKrisPart4.xdelta
) else (
    del "%gamePath%\chapter4_windows\data.win"
    ren "%gamePath%\chapter4_windows\data_patched.win" "data.win"
)

echo Patching Chapter 5...
xdelta.exe -d -f -s "%gamePath%\chapter5_windows\data.win" FemaleKrisPart5.xdelta "%gamePath%\chapter5_windows\data_patched.win"
if errorlevel 1 (
    echo Failed to patch FemaleKrisPart5.xdelta
) else (
    del "%gamePath%\chapter5_windows\data.win"
    ren "%gamePath%\chapter5_windows\data_patched.win" "data.win"
)

echo Patches successfully applied!
pause