patch.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. DATADIR=$(find -type d -name "*_Data")
  21. FILE="UnityPlayer.dll"
  22. CEXE="$DATADIR/upload_crash.exe"
  23. sum=($(md5sum $FILE))
  24. reltype=""
  25. # original hashes
  26. if [ "${sum}" == "63addffbe46d3c588e4ef5ec246365b0" ]; then
  27. reltype="os"
  28. echo "--- Applying for: International (OS) version"
  29. fi
  30. if [ "${sum}" == "67db43b7c2c2a1d09093ea54cd3cf7b8" ]; then
  31. reltype="cn"
  32. echo "--- Applying for: Chinese (CN) version"
  33. fi
  34. if [ -z "$reltype" ]; then
  35. # The patch might corrupt invalid/outdated files if this check is skippd.
  36. echo "[ERROR] Wrong file version or the patch is already applied"
  37. echo " -> md5sum: ${sum}" && exit 1
  38. fi
  39. # =========== DO NOT REMOVE START ===========
  40. if [[ -e "$DIR/$FILE" ]]; then
  41. # There is a good reason for this check. Do not pollute the game directory.
  42. echo "[ERROR] Invalid patch download directory. Please move all"
  43. echo " patch files outside the game directory prior executing."
  44. echo " -> See README.md for proper installation instructions" && exit 1
  45. fi
  46. # =========== DO NOT REMOVE END ===========
  47. if ! command -v xdelta3 &>/dev/null; then
  48. echo "[ERROR] xdelta3 application is required"
  49. echo " -> Debian/Ubuntu: apt install xdelta3"
  50. echo " -> Fedora: dnf install xdelta"
  51. echo " -> Arch/Arch-based: pacman -S xdelta3"
  52. echo " -> macOS: \"port install xdelta\" or \"brew install xdelta\""
  53. exit 1
  54. fi
  55. # ===========================================================
  56. echo ""
  57. echo "[WARNING] Hereby you are violating the game's Terms of Service!"
  58. echo " Do you accept the risk and possible consequences?"
  59. read -p "Accept? [y/n] " choice
  60. if [[ ! "$choice" == [JjSsYy]* ]]; then
  61. exit 1
  62. fi
  63. echo
  64. echo "--- Setting up blocked servers"
  65. # START OF SUDO DANGER ZONE
  66. etc_hosts="$(cat /etc/hosts)"
  67. # See dev_tools/network.md (up-to-date as of 2.4.0)
  68. if [[ "$reltype" == "os" ]]; then
  69. servers=$(cat <<EOF
  70. # Genshin logging servers (do not remove!)
  71. 0.0.0.0 log-upload-os.mihoyo.com
  72. 0.0.0.0 overseauspider.yuanshen.com
  73. EOF
  74. )
  75. else
  76. servers=$(cat <<EOF
  77. # Genshin logging servers (do not remove!)
  78. 0.0.0.0 log-upload.mihoyo.com
  79. 0.0.0.0 uspider.yuanshen.com
  80. EOF
  81. )
  82. fi
  83. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  84. echo "[MANDATORY] Adding following logging servers to /etc/hosts"
  85. echo " If you really really want to skip this (Ctrl+C),"
  86. echo " PLEASE add the entries manually. Otherwise they will receive"
  87. echo " logs about The Wine project, hence UNCOVERING THIS PATCH!"
  88. echo "$servers" | sudo -k tee -a /etc/hosts
  89. if [ $? -ne 0 ]; then
  90. echo "$servers"
  91. read -p "Please append these lines to your /etc/hosts file now. Enter to continue."
  92. fi
  93. else
  94. echo "--- Logging servers are already blocked. Skip."
  95. fi
  96. servers=$(cat <<EOF
  97. # Optional Unity proxy/cdn servers
  98. 0.0.0.0 prd-lender.cdp.internal.unity3d.com
  99. 0.0.0.0 thind-prd-knob.data.ie.unity3d.com
  100. 0.0.0.0 thind-gke-usc.prd.data.corp.unity3d.com
  101. 0.0.0.0 cdp.cloud.unity3d.com
  102. 0.0.0.0 remote-config-proxy-prd.uca.cloud.unity3d.com
  103. EOF
  104. )
  105. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  106. echo ""
  107. echo "[Optional] Adding common Unity proxy/cdn servers to /etc/hosts"
  108. echo " Normally this does not cause any issues. If issues arise in other games,"
  109. echo " consider commenting a few lines to check what makes the difference."
  110. read -p "Add 5 servers? [y/n] " choice
  111. if [[ "$choice" == [JjSsYy]* ]]; then
  112. echo "-- Adding proxy/cdn servers"
  113. echo "$servers" | sudo tee -a /etc/hosts
  114. if [ $? -ne 0 ]; then
  115. read -p "--- FAILED to add the servers. Enter to continue."
  116. fi
  117. fi
  118. else
  119. echo "--- Unity proxy/cdn servers are already blocked. Skip."
  120. fi
  121. etc_hosts=""
  122. # END OF SUDO DANGER ZONE
  123. echo ""
  124. # No crashes shall be reported!
  125. echo "--- Renaming the crash reporter"
  126. if [[ -e "$CEXE" ]]; then
  127. # Replace existing backups
  128. mv -f "$CEXE" "$CEXE.bak"
  129. fi
  130. # Registry entry to add on startup
  131. cp -f "$DIR/patch_files/mhyprot2_running.reg" .
  132. # Add launcher & force update to ensure the checks are performed
  133. echo "--- Adding launcher script"
  134. cp -f "$DIR/patch_files/launcher.bat" .
  135. if [[ "$reltype" == "cn" ]]; then
  136. # Same thing but different
  137. sed -i "s/GenshinImpact/YuanShen/g" "launcher.bat"
  138. sed -i "s/log-upload-os/log-upload/g" "launcher.bat"
  139. sed -i "s/overseauspider/uspider/g" "launcher.bat"
  140. fi
  141. # Do the patch now, replace existing backups (hash confirmed)
  142. echo "--- Patching UnityPlayer"
  143. xdelta_fail() {
  144. mv -vf "$FILE.bak" "$FILE"
  145. exit 1
  146. }
  147. mv -f "$FILE" "$FILE.bak"
  148. # Perform patch or restore .bak on failure
  149. xdelta3 -d -s "$FILE.bak" "$DIR/patch_files/unityplayer_patch_${reltype}.vcdiff" "$FILE" || xdelta_fail
  150. # Done!
  151. echo "==> Patch applied! Enjoy the game."
  152. echo
  153. echo "[NOTICE] Please refrain from sharing this project in public so"
  154. echo " that there can be Linux patches in the future. Thank you."
  155. exit 0