Update patcher

This commit is contained in:
DazedAnon 2026-05-10 12:18:54 -05:00
parent 4b28d70984
commit aedad64a47
3 changed files with 239 additions and 248 deletions

View file

@ -97,11 +97,11 @@ try {
if (Test-Path -LiteralPath $StateFile) { if (Test-Path -LiteralPath $StateFile) {
$previousSha = (Get-Content -LiteralPath $StateFile -Raw).Trim() $previousSha = (Get-Content -LiteralPath $StateFile -Raw).Trim()
} else { } else {
Write-Host 'Previous SHA hash not found. Assuming first time patching...' Write-Host 'No saved patch version yet (first run); comparing with remote...'
} }
if ($previousSha -eq $latestSha) { if ($previousSha -eq $latestSha) {
$exitCode = 10 Write-Host 'Already up to date (matches latest patch commit).'
return exit 10
} }
Write-Host 'Update found! Patching...' Write-Host 'Update found! Patching...'

View file

@ -1,238 +1,234 @@
@echo off @echo off
setlocal EnableExtensions EnableDelayedExpansion setlocal EnableExtensions EnableDelayedExpansion
REM Check if being run from gameupdate folder (incorrect usage) REM Check if being run from gameupdate folder (incorrect usage)
for %%I in ("%CD%") do set "CURRENT_FOLDER=%%~nxI" for %%I in ("%CD%") do set "CURRENT_FOLDER=%%~nxI"
if /I "%CURRENT_FOLDER%"=="gameupdate" ( if /I "%CURRENT_FOLDER%"=="gameupdate" (
echo. echo.
echo ======================================== echo ========================================
echo ERROR: Do not run patch.bat directly! echo ERROR: Do not run patch.bat directly!
echo ======================================== echo ========================================
echo. echo.
echo You are running this from the gameupdate folder. echo You are running this from the gameupdate folder.
echo This will not work correctly! echo This will not work correctly!
echo. echo.
echo Please go back to the game's root folder and echo Please go back to the game's root folder and
echo run GameUpdate.bat instead. echo run GameUpdate.bat instead.
echo ======================================== echo ========================================
echo. echo.
pause pause
exit /b 1 exit /b 1
) )
REM Determine important paths REM Determine important paths
set "SCRIPT_DIR=%~dp0" set "SCRIPT_DIR=%~dp0"
set "ROOT_DIR=%CD%" set "ROOT_DIR=%CD%"
set "CONFIG_FILE=%SCRIPT_DIR%patch-config.txt" set "CONFIG_FILE=%SCRIPT_DIR%patch-config.txt"
echo Using root directory: "%ROOT_DIR%" echo Using root directory: "%ROOT_DIR%"
echo Using config: "%CONFIG_FILE%" echo Using config: "%CONFIG_FILE%"
echo Checking for pwsh... echo Checking for pwsh...
set "_my_shell=pwsh" set "_my_shell=pwsh"
where /q !_my_shell! where /q !_my_shell!
if !errorlevel! neq 0 ( if !errorlevel! neq 0 (
echo pwsh not found. echo pwsh not found.
if /I "%GAMEUPDATE_PROMPT_PWSH%"=="1" ( if /I "%GAMEUPDATE_PROMPT_PWSH%"=="1" (
echo. echo.
set /p "INSTALL_PWSH=PowerShell 7 is faster. Install now via winget? (Y/N): " set /p "INSTALL_PWSH=PowerShell 7 is faster. Install now via winget? (Y/N): "
if /I "!INSTALL_PWSH!"=="Y" ( if /I "!INSTALL_PWSH!"=="Y" (
echo Installing PowerShell 7 via winget... echo Installing PowerShell 7 via winget...
winget install --id Microsoft.PowerShell --source winget --accept-package-agreements --accept-source-agreements winget install --id Microsoft.PowerShell --source winget --accept-package-agreements --accept-source-agreements
where /q pwsh where /q pwsh
if !errorlevel! equ 0 ( if !errorlevel! equ 0 (
set "_my_shell=pwsh" set "_my_shell=pwsh"
echo PowerShell 7 installed; using pwsh. echo PowerShell 7 installed; using pwsh.
) else ( ) else (
echo Install failed or unavailable; falling back to powershell. echo Install failed or unavailable; falling back to powershell.
set "_my_shell=powershell" set "_my_shell=powershell"
) )
) else ( ) else (
echo Skipping install; falling back to powershell. echo Skipping install; falling back to powershell.
set "_my_shell=powershell" set "_my_shell=powershell"
) )
) else ( ) else (
echo Tip: Set GAMEUPDATE_PROMPT_PWSH=1 to offer PowerShell 7 install. echo Tip: Set GAMEUPDATE_PROMPT_PWSH=1 to offer PowerShell 7 install.
echo Falling back to powershell... echo Falling back to powershell...
set "_my_shell=powershell" set "_my_shell=powershell"
) )
where /q !_my_shell! where /q !_my_shell!
if !errorlevel! neq 0 ( if !errorlevel! neq 0 (
echo ERROR: Neither pwsh nor powershell was found. echo ERROR: Neither pwsh nor powershell was found.
pause pause
exit /b 1 exit /b 1
) )
) else ( ) else (
echo pwsh found. echo pwsh found.
) )
echo Using !_my_shell! for script execution. echo Using !_my_shell! for script execution.
REM Check if patch-config.txt exists in gameupdate folder REM Check if patch-config.txt exists in gameupdate folder
if not exist "%CONFIG_FILE%" ( if not exist "%CONFIG_FILE%" (
echo "Config file (gameupdate\patch-config.txt) not found! Assuming no patching needed." echo "Config file (gameupdate\patch-config.txt) not found! Assuming no patching needed."
pause pause
exit /b exit /b
) )
REM Read configuration from file REM Read configuration from file
for /f "usebackq tokens=1,2 delims==" %%a in ("%CONFIG_FILE%") do ( for /f "usebackq tokens=1,2 delims==" %%a in ("%CONFIG_FILE%") do (
if "%%a"=="username" set "username=%%b" if "%%a"=="username" set "username=%%b"
if "%%a"=="repo" set "repo=%%b" if "%%a"=="repo" set "repo=%%b"
if "%%a"=="branch" set "branch=%%b" if "%%a"=="branch" set "branch=%%b"
) )
REM Validate required config keys early for clearer errors REM Validate required config keys early for clearer errors
if "%username%"=="" ( if "%username%"=="" (
echo ERROR: 'username=' is missing in gameupdate\patch-config.txt echo ERROR: 'username=' is missing in gameupdate\patch-config.txt
pause pause
exit /b 1 exit /b 1
) )
if "%repo%"=="" ( if "%repo%"=="" (
echo ERROR: 'repo=' is missing in gameupdate\patch-config.txt echo ERROR: 'repo=' is missing in gameupdate\patch-config.txt
pause pause
exit /b 1 exit /b 1
) )
if "%branch%"=="" ( if "%branch%"=="" (
echo ERROR: 'branch=' is missing in gameupdate\patch-config.txt echo ERROR: 'branch=' is missing in gameupdate\patch-config.txt
pause pause
exit /b 1 exit /b 1
) )
REM For PowerShell (proper URL encoding; avoids cmd %% pitfalls) REM For PowerShell (proper URL encoding; avoids cmd %% pitfalls)
set "GU_USERNAME=%username%" set "GU_USERNAME=%username%"
set "GU_REPO=%repo%" set "GU_REPO=%repo%"
set "GU_BRANCH=%branch%" set "GU_BRANCH=%branch%"
REM -------------------------------------------------------- REM --------------------------------------------------------
REM PRE-SETUP: Ensure SRPG data and patch structure exists REM PRE-SETUP: Ensure SRPG data and patch structure exists
REM Run Steps 1 and 2 BEFORE pulling repo patch to avoid overwriting updates REM Run Steps 1 and 2 BEFORE pulling repo patch to avoid overwriting updates
REM 1) Unpack once if data folder doesn't exist (and data.dts does) REM 1) Unpack once if data folder doesn't exist (and data.dts does)
REM 2) Create Patch once if patch folder doesn't exist REM 2) Create Patch once if patch folder doesn't exist
REM -------------------------------------------------------- REM --------------------------------------------------------
set "UNPACKER=%ROOT_DIR%\SRPG_Unpacker.exe" set "UNPACKER=%ROOT_DIR%\SRPG_Unpacker.exe"
if exist "%ROOT_DIR%\data.dts" ( if exist "%ROOT_DIR%\data.dts" (
if exist "%UNPACKER%" ( if exist "%UNPACKER%" (
echo [Pre-Setup] Running SRPG_Unpacker preparation steps... echo [Pre-Setup] Running SRPG_Unpacker preparation steps...
REM Step 1: Unpack (once) REM Step 1: Unpack (once)
if not exist "%ROOT_DIR%\data\" ( if not exist "%ROOT_DIR%\data\" (
set "SHOULD_UNPACK=1" set "SHOULD_UNPACK=1"
) else if not exist "%ROOT_DIR%\data\project.dat" ( ) else if not exist "%ROOT_DIR%\data\project.dat" (
set "SHOULD_UNPACK=1" set "SHOULD_UNPACK=1"
) else ( ) else (
set "SHOULD_UNPACK=0" set "SHOULD_UNPACK=0"
) )
if "!SHOULD_UNPACK!"=="1" ( if "!SHOULD_UNPACK!"=="1" (
if exist "%ROOT_DIR%\data.dts" ( if exist "%ROOT_DIR%\data.dts" (
echo [Pre-Setup] Step 1: Unpacking data.dts to data echo [Pre-Setup] Step 1: Unpacking data.dts to data
pushd "%ROOT_DIR%" pushd "%ROOT_DIR%"
"%UNPACKER%" -o "data" "data.dts" "%UNPACKER%" -o "data" "data.dts"
if !errorlevel! neq 0 ( if !errorlevel! neq 0 (
echo [Pre-Setup] ERROR: Unpack failed. Continuing. echo [Pre-Setup] ERROR: Unpack failed. Continuing.
) )
popd popd
) else ( ) else (
echo [Pre-Setup] Step 1: Skipping unpack - no data folder and no data.dts found. echo [Pre-Setup] Step 1: Skipping unpack - no data folder and no data.dts found.
) )
) else ( ) else (
echo [Pre-Setup] Step 1: data folder exists; skipping unpack. echo [Pre-Setup] Step 1: data folder exists; skipping unpack.
) )
REM Step 2: Create Patch (once) REM Step 2: Create Patch (once)
if not exist "%ROOT_DIR%\patch\" ( if not exist "%ROOT_DIR%\patch\" (
if exist "%ROOT_DIR%\data\project.dat" ( if exist "%ROOT_DIR%\data\project.dat" (
echo [Pre-Setup] Step 2: Creating patch from data\project.dat echo [Pre-Setup] Step 2: Creating patch from data\project.dat
pushd "%ROOT_DIR%" pushd "%ROOT_DIR%"
"%UNPACKER%" ".\data\project.dat" -c "%UNPACKER%" ".\data\project.dat" -c
if !errorlevel! neq 0 ( if !errorlevel! neq 0 (
echo [Pre-Setup] ERROR: Create Patch failed. Continuing. echo [Pre-Setup] ERROR: Create Patch failed. Continuing.
) )
popd popd
) else ( ) else (
echo [Pre-Setup] Step 2: Skipping create patch - data\project.dat not found. echo [Pre-Setup] Step 2: Skipping create patch - data\project.dat not found.
) )
) else ( ) else (
echo [Pre-Setup] Step 2: patch folder exists; skipping create. echo [Pre-Setup] Step 2: patch folder exists; skipping create.
) )
) else ( ) else (
echo [Pre-Setup] SRPG_Unpacker.exe not found in root; skipping pre-setup steps. echo [Pre-Setup] SRPG_Unpacker.exe not found in root; skipping pre-setup steps.
) )
) else ( )
echo [Pre-Setup] data.dts not found; skipping pre-setup SRPG steps.
) :download_extract
:download_extract REM Download/extract via patch-download.ps1 (IWR-based); Bypass avoids ExecutionPolicy prompts
if not exist "%SCRIPT_DIR%patch-download.ps1" (
REM Download/extract via patch-download.ps1 (IWR-based); Bypass avoids ExecutionPolicy prompts echo ERROR: patch-download.ps1 not found next to patch.bat in the gameupdate folder.
if not exist "%SCRIPT_DIR%patch-download.ps1" ( pause
echo ERROR: patch-download.ps1 not found next to patch.bat in the gameupdate folder. exit /b 1
pause )
exit /b 1 !_my_shell! -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%patch-download.ps1" -GameRoot "%ROOT_DIR%" -StateFile "%SCRIPT_DIR%previous_patch_sha.txt"
) set "PATCH_DL_EXIT=!errorlevel!"
!_my_shell! -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%patch-download.ps1" -GameRoot "%ROOT_DIR%" -StateFile "%SCRIPT_DIR%previous_patch_sha.txt" if "!PATCH_DL_EXIT!"=="10" (
set "PATCH_DL_EXIT=!errorlevel!" echo Already up to date.
if "!PATCH_DL_EXIT!"=="10" ( endlocal
echo Patch is up to date. pause
endlocal exit /b 0
pause )
exit /b 0 if not "!PATCH_DL_EXIT!"=="0" (
) echo Download or extraction failed!
if not "!PATCH_DL_EXIT!"=="0" ( if exist "%ROOT_DIR%\repo.zip" del "%ROOT_DIR%\repo.zip"
echo Download or extraction failed! if exist "%ROOT_DIR%\_patch_extract_tmp" rmdir /s /q "%ROOT_DIR%\_patch_extract_tmp"
if exist "%ROOT_DIR%\repo.zip" del "%ROOT_DIR%\repo.zip" pause
if exist "%ROOT_DIR%\_patch_extract_tmp" rmdir /s /q "%ROOT_DIR%\_patch_extract_tmp" exit /b 1
pause )
exit /b 1 echo "Applying patch..."
) REM Files merged by Copy-Item above
echo "Applying patch..." REM --------------------------------------------------------
REM Files merged by Copy-Item above REM POST-APPLY: Run Steps 3 and 4 after patch files are merged
REM -------------------------------------------------------- REM 3) Apply Patch to data\project.dat
REM POST-APPLY: Run Steps 3 and 4 after patch files are merged REM 4) Pack data back into data.dts
REM 3) Apply Patch to data\project.dat REM --------------------------------------------------------
REM 4) Pack data back into data.dts set "UNPACKER=%ROOT_DIR%\SRPG_Unpacker.exe"
REM -------------------------------------------------------- if exist "%ROOT_DIR%\data.dts" (
set "UNPACKER=%ROOT_DIR%\SRPG_Unpacker.exe" if exist "%UNPACKER%" (
if exist "%ROOT_DIR%\data.dts" ( echo Running SRPG_Unpacker apply/pack steps...
if exist "%UNPACKER%" (
echo Running SRPG_Unpacker apply/pack steps... REM Step 3: Apply Patch
if exist "%ROOT_DIR%\data\project.dat" (
REM Step 3: Apply Patch echo Step 3: Applying patch to data\project.dat
if exist "%ROOT_DIR%\data\project.dat" ( pushd "%ROOT_DIR%"
echo Step 3: Applying patch to data\project.dat "%UNPACKER%" ".\data\project.dat" -a
pushd "%ROOT_DIR%" if !errorlevel! neq 0 (
"%UNPACKER%" ".\data\project.dat" -a echo ERROR: Apply Patch failed.
if !errorlevel! neq 0 ( )
echo ERROR: Apply Patch failed. popd
) ) else (
popd echo ERROR: data\project.dat not found; cannot apply patch.
) else ( )
echo ERROR: data\project.dat not found; cannot apply patch.
) REM Step 4: Pack
if exist "%ROOT_DIR%\data\" (
REM Step 4: Pack echo Step 4: Packing data to data.dts
if exist "%ROOT_DIR%\data\" ( pushd "%ROOT_DIR%"
echo Step 4: Packing data to data.dts "%UNPACKER%" -o "data.dts" "data"
pushd "%ROOT_DIR%" if !errorlevel! neq 0 (
"%UNPACKER%" -o "data.dts" "data" echo WARNING: Pack failed.
if !errorlevel! neq 0 ( )
echo WARNING: Pack failed. popd
) ) else (
popd echo Step 4: Skipping pack - data folder not found.
) else ( )
echo Step 4: Skipping pack - data folder not found. ) else (
) echo SRPG_Unpacker.exe not found in root; skipping SRPG patch steps.
) else ( )
echo SRPG_Unpacker.exe not found in root; skipping SRPG patch steps. )
) REM Clean up
) else ( echo "Cleaning up..."
echo data.dts not found; skipping SRPG patch steps. del "%ROOT_DIR%\repo.zip"
) if exist "%ROOT_DIR%\_patch_extract_tmp" rmdir /s /q "%ROOT_DIR%\_patch_extract_tmp"
REM Clean up endlocal
echo "Cleaning up..." pause
del "%ROOT_DIR%\repo.zip" exit /b
if exist "%ROOT_DIR%\_patch_extract_tmp" rmdir /s /q "%ROOT_DIR%\_patch_extract_tmp"
endlocal
pause
exit /b

View file

@ -128,8 +128,6 @@ if [ -f "$ROOT_DIR/data.dts" ]; then
else else
echo "[Pre-Setup] SRPG_Unpacker.exe not found in root; skipping pre-setup steps." echo "[Pre-Setup] SRPG_Unpacker.exe not found in root; skipping pre-setup steps."
fi fi
else
echo "[Pre-Setup] data.dts not found; skipping pre-setup SRPG steps."
fi fi
download_extract() { download_extract() {
@ -205,8 +203,6 @@ download_extract() {
else else
echo "SRPG_Unpacker.exe not found in root; skipping SRPG patch steps." echo "SRPG_Unpacker.exe not found in root; skipping SRPG patch steps."
fi fi
else
echo "data.dts not found; skipping SRPG patch steps."
fi fi
echo "$latest_patch_sha" > "$STATE_FILE" echo "$latest_patch_sha" > "$STATE_FILE"
@ -214,8 +210,7 @@ download_extract() {
# Check if previous_patch_sha.txt exists in gameupdate # Check if previous_patch_sha.txt exists in gameupdate
if [ ! -f "$STATE_FILE" ]; then if [ ! -f "$STATE_FILE" ]; then
echo "Previous SHA hash not found!" echo "No saved patch version yet (first run); comparing with remote..."
echo "Assuming first time patching..."
download_extract download_extract
else else
previous_patch_sha=$(tr -d '[:space:]' < "$STATE_FILE") previous_patch_sha=$(tr -d '[:space:]' < "$STATE_FILE")
@ -224,6 +219,6 @@ else
echo "Update found! Patching..." echo "Update found! Patching..."
download_extract download_extract
else else
echo "Patch is up to date." echo "Already up to date (matches latest patch commit)."
fi fi
fi fi