patch_revert.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. # Reference timestamp to avoid restoring old/invalid backups
  12. ref_timestamp=($(stat -c %Y "$ANCHOR"))
  13. restore_file() {
  14. # $1 -> File name
  15. # $2 -> Human readable description
  16. if [[ ! -e "$1.bak" ]]; then
  17. echo "--- Nothing to restore for '$1' (no .bak file)"
  18. return 0
  19. fi
  20. # Do not restore backups from old game versions
  21. difftime=$(( $ref_timestamp - $(stat -c %Y "$1.bak") ))
  22. # Strip negative sign is equal to abs()
  23. if [[ ${difftime#-} -gt 3600 ]]; then
  24. echo "==> ERROR: Backup '$1.bak' is older than the current game version. Ignoring."
  25. return 1
  26. fi
  27. # Restore from backup
  28. mv -f "$1.bak" "$1"
  29. echo "--- Restored: $2"
  30. return 0
  31. }
  32. restore_file "$FILE" "$FILE"
  33. restore_file "$XLUA" "$XLUA"
  34. if [[ -e "$CEXE" ]]; then
  35. echo "--- Crash reporter already exists"
  36. else
  37. restore_file "$FILE" "Crash reporter"
  38. fi
  39. echo "--- Removing all newly added files"
  40. # The error messages for inexistent files are intended
  41. rm "launcher.bat"
  42. rm "mhyprot2_running.reg"
  43. # xlua patch
  44. rm "no message"
  45. # dxvk files
  46. rm *.dxvk-cache
  47. rm *_d3d9.log
  48. rm *_d3d11.log
  49. rm *_dxgi.log
  50. echo "==> Patch reverted."
  51. exit 0