patch_revert.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. ANCHOR="GenshinImpact.exe"
  3. if [[ ! -e "$ANCHOR" ]]; then
  4. echo "==> GenshinImpact executable not found. Wrong directory?"
  5. exit 1
  6. fi
  7. # Restore files that have a backup
  8. FILE="UnityPlayer.dll"
  9. CEXE="GenshinImpact_Data/upload_crash.exe"
  10. XLUA="GenshinImpact_Data/Plugins/xlua.dll"
  11. # macOS has a different version of stat
  12. if [ $(uname) = "Darwin" ]; then
  13. STATFLAGS="-f %a"
  14. else
  15. STATFLAGS="-c %Y"
  16. fi
  17. # Reference timestamp to avoid restoring old/invalid backups
  18. ref_timestamp=($(stat $STATFLAGS "$ANCHOR"))
  19. restore_file() {
  20. # $1 -> File name
  21. # $2 -> Human readable description
  22. if [[ ! -e "$1.bak" ]]; then
  23. echo "--- Nothing to restore for '$1' (no .bak file)"
  24. return 0
  25. fi
  26. # Do not restore backups from old game versions
  27. difftime=$(( $ref_timestamp - $(stat $STATFLAGS "$1.bak") ))
  28. # Strip negative sign is equal to abs()
  29. if [[ ${difftime#-} -gt 3600 ]]; then
  30. echo "==> ERROR: Backup '$1.bak' is older than the current game version. Ignoring."
  31. return 1
  32. fi
  33. # Restore from backup
  34. mv -f "$1.bak" "$1"
  35. echo "--- Restored: $2"
  36. return 0
  37. }
  38. restore_file "$FILE" "$FILE"
  39. restore_file "$XLUA" "$XLUA"
  40. if [[ -e "$CEXE" ]]; then
  41. echo "--- Crash reporter already exists"
  42. else
  43. restore_file "$CEXE" "Crash reporter"
  44. fi
  45. echo "--- Removing all newly added files"
  46. # The error messages for inexistent files are intended
  47. rm "launcher.bat"
  48. rm "mhyprot2_running.reg"
  49. # xlua patch
  50. rm "no message"
  51. # dxvk files
  52. rm *.dxvk-cache
  53. rm *_d3d9.log
  54. rm *_d3d11.log
  55. rm *_dxgi.log
  56. echo "==> Patch reverted."
  57. exit 0