patch.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. block_analytics=1
  26. # original hashes
  27. if [ "${sum}" == "3210693b2514fe14e64d96e943c08bf4" ]; then
  28. reltype="os"
  29. echo "--- Applying for: International version"
  30. fi
  31. if [ "${sum}" == "792ca6deda412a36e88284fb23eb7049" ]; then
  32. if [ -e "$DATADIR/Plugins/PCGameSDK.dll" ]; then
  33. reltype="bb"
  34. echo "--- Applying for: bilibili CN version"
  35. else
  36. reltype="cn"
  37. echo "--- Applying for: miHoYo CN version"
  38. fi
  39. fi
  40. if [ -z "$reltype" ]; then
  41. # The patch might corrupt invalid/outdated files if this check is skippd.
  42. echo "[ERROR] Wrong file version or the patch is already applied"
  43. echo " -> md5sum: ${sum}" && exit 1
  44. fi
  45. # =========== DO NOT REMOVE START ===========
  46. if [[ -e "$DIR/$FILE" ]]; then
  47. # There is a good reason for this check. Do not pollute the game directory.
  48. echo "[ERROR] Invalid patch download directory. Please move all"
  49. echo " patch files outside the game directory prior executing."
  50. echo " -> See README.md for proper installation instructions" && exit 1
  51. fi
  52. # =========== DO NOT REMOVE END ===========
  53. if ! command -v xdelta3 &>/dev/null; then
  54. echo "[ERROR] xdelta3 application is required"
  55. echo " -> Debian/Ubuntu: apt install xdelta3"
  56. echo " -> Fedora: dnf install xdelta"
  57. echo " -> Arch/Arch-based: pacman -S xdelta3"
  58. echo " -> macOS: \"port install xdelta\" or \"brew install xdelta\""
  59. exit 1
  60. fi
  61. # ===========================================================
  62. echo ""
  63. echo "[WARNING] Hereby you are violating the game's Terms of Service!"
  64. echo " Do you accept the risk and possible consequences?"
  65. echo " Use Ctrl+C to abort this script if you are not sure."
  66. read -p "Accept? [y/N] " choice
  67. if [[ ! "$choice" == [JjSsYy]* ]]; then
  68. exit 1
  69. fi
  70. echo
  71. echo "--- Setting up blocked servers"
  72. # START OF SUDO DANGER ZONE
  73. etc_hosts="$(cat /etc/hosts)"
  74. # See dev_tools/network.md (up-to-date as of 3.1.0)
  75. # Note: overseauspider is no longer used (2.8.0). Kept to complement the CN version.
  76. if [[ "$reltype" == "os" ]]; then
  77. servers=$(cat <<EOF
  78. # Genshin logging servers (do not remove!)
  79. 0.0.0.0 sg-public-data-api.hoyoverse.com
  80. 0.0.0.0 log-upload-os.hoyoverse.com
  81. 0.0.0.0 overseauspider.yuanshen.com
  82. EOF
  83. )
  84. else
  85. servers=$(cat <<EOF
  86. # Genshin logging servers (do not remove!)
  87. 0.0.0.0 public-data-api.mihoyo.com
  88. 0.0.0.0 log-upload.mihoyo.com
  89. 0.0.0.0 uspider.yuanshen.com
  90. EOF
  91. )
  92. fi
  93. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  94. echo "[Optional] Block analytics domains via /etc/hosts"
  95. echo " The game collects uniquely identifiable information about your system."
  96. echo " For details, refer to the official privacy page or the file"
  97. echo " '../static/analytics_data.txt' contained in this repository."
  98. echo "$servers"
  99. read -r -p "Would you like to block the analytics servers above? [Y/n]: " choice
  100. if [[ ! "$choice" == [Nn0]* ]]; then
  101. echo "-- Adding analytics servers"
  102. echo "$servers" | sudo tee -a /etc/hosts
  103. if [ $? -ne 0 ]; then
  104. read -p "--- Failed. Please edit /etc/hosts manually. Enter to continue."
  105. fi
  106. else
  107. block_analytics=0
  108. fi
  109. else
  110. echo "--- Analytics servers are already blocked. Skip."
  111. fi
  112. etc_hosts=""
  113. # END OF SUDO DANGER ZONE
  114. echo ""
  115. # No crashes shall be reported!
  116. echo "--- Renaming the crash reporter(s)"
  117. if [ -e "$CEXE1" ]; then
  118. # Replace existing backups
  119. mv -f "$CEXE1" "$CEXE1.bak"
  120. fi
  121. if [ -e "$CEXE2" ]; then
  122. mv -f "$CEXE2" "$CEXE2.bak"
  123. fi
  124. if [ -e "$VULKAN1" ]; then
  125. echo "--- Workaround for Wine bug 45277"
  126. mv -f "$VULKAN1" "$VULKAN1.bak"
  127. fi
  128. # Registry entry to add on startup
  129. cp -f "$DIR/patch_files/mhyprot2_running.reg" .
  130. echo "--- Adding launcher script"
  131. cp -f "$DIR/patch_files/launcher.bat" .
  132. if [ "$block_analytics" -eq 0 ]; then
  133. # Remove the lines related to domain checking
  134. sed -i "/REM DOMAIN_CHECK_BEGIN/,/REM DOMAIN_CHECK_END/d" "launcher.bat"
  135. fi
  136. if [[ "$reltype" != "os" ]]; then
  137. # Same thing but different
  138. sed -i "s/GenshinImpact/YuanShen/g" "launcher.bat"
  139. sed -i "s/sg-public-data-api.hoyoverse/public-data-api.mihoyo/g" "launcher.bat"
  140. sed -i "s/log-upload-os.hoyoverse/log-upload.mihoyo/g" "launcher.bat"
  141. sed -i "s/overseauspider/uspider/g" "launcher.bat"
  142. fi
  143. # Do the patch now, replace existing backups (hash confirmed)
  144. echo "--- Patching UnityPlayer"
  145. xdelta_fail() {
  146. mv -vf "$FILE.bak" "$FILE"
  147. exit 1
  148. }
  149. mv -f "$FILE" "$FILE.bak"
  150. # Perform patch or restore .bak on failure
  151. xdelta3 -d -s "$FILE.bak" "$DIR/patch_files/unityplayer_patch_${reltype}.vcdiff" "$FILE" || xdelta_fail
  152. # Done!
  153. echo "==> Patch applied! Enjoy the game."
  154. echo
  155. echo "[NOTICE] Please refrain from sharing this project in public so"
  156. echo " that there can be Linux patches in the future. Thank you."
  157. exit 0