patch.sh 4.0 KB

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