patch_revert.sh 1.9 KB

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