patch.sh 6.0 KB

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