patch_revert.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env bash
  2. ANCHOR=""
  3. DATADIR=$(find . -maxdepth 1 -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. VULKAN1="$DATADIR/Plugins/vulkan-1.dll"
  19. XLUA="$DATADIR/Plugins/xlua.dll"
  20. GGM="$DATADIR/globalgamemanagers"
  21. # macOS has a different version of stat
  22. if [ $(uname) = "Darwin" ]; then
  23. STATFLAGS="-f %a"
  24. else
  25. STATFLAGS="-c %Y"
  26. fi
  27. # Reference timestamp to avoid restoring old/invalid backups
  28. ref_timestamp=($(stat $STATFLAGS "$ANCHOR"))
  29. restore_file() {
  30. # $1 -> File name
  31. # $2 -> Human readable description
  32. # $3 -> Overwrite existing file?
  33. if [ ! -e "$1.bak" ]; then
  34. echo "--- Nothing to restore for '$1' (no .bak file)"
  35. return 0
  36. fi
  37. if [ -e "$1" -a "$3" != "overwrite" ]; then
  38. echo "--- $2 is already restored"
  39. return 0
  40. fi
  41. # Do not restore backups from old game versions
  42. difftime=$(( $ref_timestamp - $(stat $STATFLAGS "$1.bak") ))
  43. # Strip negative sign is equal to abs()
  44. if [ ${difftime#-} -gt 3600 ]; then
  45. echo "--- Backup '$1.bak' is older than the current game version. Ignoring."
  46. return 1
  47. fi
  48. # Restore from backup
  49. mv -f "$1.bak" "$1"
  50. echo "--- Restored: $2"
  51. return 0
  52. }
  53. restore_file "$FILE" "Main patch" overwrite
  54. restore_file "$VULKAN1" "Workaround for Wine bug 45277"
  55. restore_file "$CEXE1" "Crash reporter 1"
  56. restore_file "$CEXE2" "Crash reporter 2"
  57. restore_file "mhypbase.dll" "'Blackbox' DLL"
  58. restore_file "$XLUA" "Anti-logincrash patch" overwrite
  59. restore_file "$GGM" "macOS rendering issue patch" overwrite
  60. echo
  61. echo "--> Removing all newly added files"
  62. # The error messages for inexistent files are intended
  63. rm "launcher.bat"
  64. rm "mhyprot2_running.reg"
  65. # dxvk files
  66. rm *.dxvk-cache
  67. rm *_d3d9.log
  68. rm *_d3d11.log
  69. rm *_dxgi.log
  70. echo "==> Patch reverted."
  71. exit 0