patch.sh 5.7 KB

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