Advertisement
xzlui

[BATCH] Patch files by editing an offset's hex values

May 24th, 2025
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.18 KB | None | 0 0
  1. REM A script I made to patch LOTRC for certain mods.
  2.  
  3. @echo off
  4. color 0a
  5. setlocal
  6.  
  7. ::Define your input for patching
  8. set "EXE_FILE=Conquest.exe"
  9. set "OFFSET=0x49F238"
  10. set "NEW_HEX=C7 05 00 E2 A3 00 00 00 00 10" ::C7 05 00 E2 A3 00 00 00 A0 0A
  11.  
  12. ::Create backup of file being patched
  13. set "TIMESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%"
  14. set "TIMESTAMP=%TIMESTAMP: =0%"  :: Replace space with 0 for time formatting
  15. set "BACKUP_FILE=%EXE_FILE%.backup.%TIMESTAMP%"
  16.  
  17. ::Catch error
  18. echo Creating backup: %BACKUP_FILE%
  19. copy /Y "%EXE_FILE%" "%BACKUP_FILE%" > nul
  20. if errorlevel 1 (
  21.     echo Failed to create backup. Aborting patch.
  22.     exit /b 1
  23. )
  24.  
  25. ::Find offset and replace hex values
  26. powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  27.   "$Path='%EXE_FILE%';" ^
  28.   "$Offset=%OFFSET%;" ^
  29.   "$Bytes='%NEW_HEX%'.Split(' ') | ForEach-Object { [Convert]::ToByte($_,16) };" ^
  30.   "$fs=[System.IO.File]::Open($Path, 'Open', 'ReadWrite');" ^
  31.   "$fs.Seek($Offset, 'Begin') > $null;" ^
  32.   "$fs.Write($Bytes, 0, $Bytes.Length);" ^
  33.   "$fs.Close();"
  34.  
  35. echo.
  36. echo Patch has been applied successfully! You may now close this window or press any key.
  37. pause > nul
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement