patch_revert.sh 1.8 KB

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