patch.sh 4.5 KB

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