patch.sh 4.8 KB

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