@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" MaleKrisPart1.xdelta "%gamePath%\chapter1_windows\lang\lang_en_patched.json"
if errorlevel 1 (
    echo Failed to patch MaleKrisPart1.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" MaleKrisPart2.xdelta "%gamePath%\chapter2_windows\data_patched.win"
if errorlevel 1 (
    echo Failed to patch MaleKrisPart2.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" MaleKrisPart3.xdelta "%gamePath%\chapter3_windows\data_patched.win"
if errorlevel 1 (
    echo Failed to patch MaleKrisPart3.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" MaleKrisPart4.xdelta "%gamePath%\chapter4_windows\data_patched.win"
if errorlevel 1 (
    echo Failed to patch MaleKrisPart4.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" MaleKrisPart5.xdelta "%gamePath%\chapter5_windows\data_patched.win"
if errorlevel 1 (
    echo Failed to patch MaleKrisPart5.xdelta
) else (
    del "%gamePath%\chapter5_windows\data.win"
    ren "%gamePath%\chapter5_windows\data_patched.win" "data.win"
)

echo Patches successfully applied!
pause