patch.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env bash
  2. DIR=$(dirname "${BASH_SOURCE[0]}")
  3. FILE="UnityPlayer.dll"
  4. CEXE="GenshinImpact_Data/upload_crash.exe"
  5. sum=($(md5sum $FILE))
  6. if [ "${sum}" != "2a7b40cbcf1e0de95900b9f822ad33f9" ]; then
  7. # The patch might corrupt invalid/outdated files if this check is skippd.
  8. echo "Wrong file version or patch is already applied"
  9. echo "md5sum: ${sum}" && exit 1
  10. fi
  11. if [[ -e "$DIR/$FILE" ]]; then
  12. # Script may not be placed into the main directory
  13. echo "Please move all patch files outside the game directory prior executing."
  14. echo " -> See README.md for proper installation instructions" && exit 1
  15. fi
  16. if ! command -v xdelta3 &>/dev/null; then
  17. echo "xdelta3 application is required"
  18. echo " -> Debian/Ubuntu: apt install xdelta3"
  19. echo " -> Fedora: dnf install xdelta"
  20. exit 1
  21. fi
  22. # ===========================================================
  23. echo "[WARNING] Hereby you are violating the game's Terms of Service!"
  24. echo " Do you accept the risk and possible consequences?"
  25. read -p "Accept? [y/n] " choice
  26. if [[ ! "$choice" == [JjSsYy]* ]]; then
  27. exit 1
  28. fi
  29. echo "--- Setting up blocked servers"
  30. # START OF SUDO DANGER ZONE
  31. etc_hosts="$(cat /etc/hosts)"
  32. # See 110/network.md (up-to-date as of 1.2.0)
  33. servers=$(cat <<EOF
  34. # Genshin logging servers (do not remove!)
  35. 0.0.0.0 log-upload-os.mihoyo.com
  36. 0.0.0.0 overseauspider.yuanshen.com
  37. EOF
  38. )
  39. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  40. echo "[MANDATORY] Adding following logging servers to /etc/hosts"
  41. echo " If you really really want to skip this (Ctrl+C),"
  42. echo " PLEASE add the entries manually. Otherwise they will receive"
  43. echo " logs about The Wine project, hence UNCOVERING THIS PATCH!"
  44. echo "$servers" | sudo -k tee -a /etc/hosts
  45. if [ $? -ne 0 ]; then
  46. read -p "Please check your /etc/hosts file now. Enter to continue. "
  47. fi
  48. else
  49. echo "-- Logging servers are already blocked. Skip."
  50. fi
  51. servers=$(cat <<EOF
  52. # Optional Unity proxy/cdn servers
  53. 0.0.0.0 prd-lender.cdp.internal.unity3d.com
  54. 0.0.0.0 thind-prd-knob.data.ie.unity3d.com
  55. 0.0.0.0 thind-gke-usc.prd.data.corp.unity3d.com
  56. 0.0.0.0 cdp.cloud.unity3d.com
  57. 0.0.0.0 remote-config-proxy-prd.uca.cloud.unity3d.com
  58. EOF
  59. )
  60. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  61. echo ""
  62. echo "[Optional] Adding common Unity proxy/cdn servers to /etc/hosts"
  63. echo " Normally this does not cause any issues. If issues arise in other games,"
  64. echo " consider commenting a few lines to check what makes the difference."
  65. read -p "Add 5 servers? [y/n] " choice
  66. if [[ "$choice" == [JjSsYy]* ]]; then
  67. echo "-- Adding proxy/cdn servers"
  68. echo "$servers" | sudo tee -a /etc/hosts
  69. if [ $? -ne 0 ]; then
  70. read -p "--- FAILED to add the servers. What happened?!"
  71. fi
  72. fi
  73. else
  74. echo "-- Unity proxy/cdn servers are already blocked. Skip."
  75. fi
  76. etc_hosts=""
  77. # END OF SUDO DANGER ZONE
  78. echo ""
  79. # No crashes shall be reported!
  80. echo "--- Renaming the crash reporter"
  81. if [[ -e "$CEXE" ]]; then
  82. # Replace existing backups
  83. mv -f "$CEXE" "$CEXE.bak"
  84. fi
  85. # Registry entry to add on startup
  86. cp -f "$DIR/patch_files/mhyprot2_running.reg" .
  87. # Add launcher
  88. echo "--- Adding launcher script"
  89. cp -n "$DIR/patch_files/launcher.bat" .
  90. # Do the patch now, replace existing backups (hash confirmed)
  91. echo "--- Patching UnityPlayer"
  92. mv -f "$FILE" "$FILE.bak"
  93. xdelta3 -d -s "$FILE.bak" "$DIR/patch_files/unityplayer_patch.vcdiff" "$FILE"
  94. # Done!
  95. echo "==> Patch applied! Enjoy the game."
  96. exit 0