patch.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/usr/bin/env bash
  2. # DESCRIPTION
  3. # This is the main patch script to ensure basic game functionality in Wine.
  4. #
  5. # EXIT STATUS
  6. # 0 : The patch was applied successfully.
  7. # other : Patch failure. See stdout or stderr output for details.
  8. # Templates for the next patch testing phase
  9. echo " === !! UNTESTED PATCH. CHECK FOR BANS USING A TRASH ACCOUNT !! ==="
  10. echo " === REPORT RESULTS TO THE MAIN REPOSITORY. THANK YOU. ==="
  11. echo ""
  12. echo "If you would like to test this patch, modify this script and remove the line below this one."
  13. exit 1
  14. # MacOS and *BSD do not have md5sum: use md5 instead
  15. if [[ $(uname) == "Darwin" || $(uname) == *"BSD" ]]; then
  16. md5sum() {
  17. md5 -q $@
  18. }
  19. fi
  20. DIR=$(dirname "${BASH_SOURCE[0]}")
  21. DATADIR=$(find . -maxdepth 1 -type d -name "*_Data")
  22. FILE="UnityPlayer.dll"
  23. CEXE1="$DATADIR/upload_crash.exe"
  24. CEXE2="$DATADIR/Plugins/crashreport.exe"
  25. VULKAN1="$DATADIR/Plugins/vulkan-1.dll"
  26. sum=($(md5sum $FILE))
  27. reltype="" # os, cn, bb
  28. block_analytics=1
  29. # original hashes
  30. if [ "${sum}" == "9373c2057ebe53391466b7bff2977001" ]; then
  31. reltype="os"
  32. echo "--- Applying for: International version"
  33. fi
  34. if [ "${sum}" == "cf7d4ebf1f4216ef58c2a39b630ef2ca" ]; then
  35. if [ -e "$DATADIR/Plugins/PCGameSDK.dll" ]; then
  36. reltype="bb"
  37. echo "--- Applying for: bilibili CN version"
  38. else
  39. reltype="cn"
  40. echo "--- Applying for: miHoYo CN version"
  41. fi
  42. fi
  43. if [ -z "$reltype" ]; then
  44. # The patch might corrupt invalid/outdated files if this check is skippd.
  45. echo "[ERROR] Wrong file version or the patch is already applied"
  46. echo " -> md5sum: ${sum}" && exit 1
  47. fi
  48. # =========== DO NOT REMOVE START ===========
  49. if [[ -e "$DIR/$FILE" ]]; then
  50. # There is a good reason for this check. Do not pollute the game directory.
  51. echo "[ERROR] Invalid patch download directory. Please move all"
  52. echo " patch files outside the game directory prior executing."
  53. echo " -> See README.md for proper installation instructions" && exit 1
  54. fi
  55. # =========== DO NOT REMOVE END ===========
  56. if ! command -v xdelta3 &>/dev/null; then
  57. echo "[ERROR] xdelta3 application is required"
  58. echo " -> Debian/Ubuntu: apt install xdelta3"
  59. echo " -> Fedora: dnf install xdelta"
  60. echo " -> Arch/Arch-based: pacman -S xdelta3"
  61. echo " -> macOS: \"port install xdelta\" or \"brew install xdelta\""
  62. exit 1
  63. fi
  64. # ===========================================================
  65. echo ""
  66. echo "[WARNING] Hereby you are violating the game's Terms of Service!"
  67. echo " Do you accept the risk and possible consequences?"
  68. echo " Use Ctrl+C to abort this script if you are not sure."
  69. read -p "Accept? [y/N] " choice
  70. if [[ ! "$choice" == [JjSsYy]* ]]; then
  71. exit 1
  72. fi
  73. echo
  74. echo "--- Setting up blocked servers"
  75. # START OF SUDO DANGER ZONE
  76. etc_hosts="$(cat /etc/hosts)"
  77. # See dev_tools/network.md (up-to-date as of 3.8.0)
  78. # Note: sg-public-data-api is unused since 3.7.0
  79. if [[ "$reltype" == "os" ]]; then
  80. servers=$(cat <<EOF
  81. # Genshin logging servers (do not remove!)
  82. 0.0.0.0 sg-public-data-api.hoyoverse.com
  83. 0.0.0.0 log-upload-os.hoyoverse.com
  84. 0.0.0.0 overseauspider.yuanshen.com
  85. EOF
  86. )
  87. else
  88. servers=$(cat <<EOF
  89. # Genshin logging servers (do not remove!)
  90. 0.0.0.0 public-data-api.mihoyo.com
  91. 0.0.0.0 log-upload.mihoyo.com
  92. 0.0.0.0 uspider.yuanshen.com
  93. EOF
  94. )
  95. fi
  96. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  97. echo "[Optional] Block analytics domains via /etc/hosts"
  98. echo " The game collects uniquely identifiable information about your system."
  99. echo " For details, refer to the official privacy page or the file"
  100. echo " '../static/analytics_data.txt' contained in this repository."
  101. echo "$servers"
  102. read -r -p "Would you like to block the analytics servers above? [Y/n]: " choice
  103. if [[ ! "$choice" == [Nn0]* ]]; then
  104. echo "-- Adding analytics servers"
  105. echo "$servers" | sudo tee -a /etc/hosts
  106. if [ $? -ne 0 ]; then
  107. read -p "--- Failed. Please edit /etc/hosts manually. Enter to continue."
  108. fi
  109. else
  110. block_analytics=0
  111. fi
  112. else
  113. echo "--- Analytics servers are already blocked. Skip."
  114. fi
  115. etc_hosts=""
  116. # END OF SUDO DANGER ZONE
  117. echo ""
  118. # No crashes shall be reported!
  119. echo "--- Renaming the crash reporter(s)"
  120. if [ -e "$CEXE1" ]; then
  121. # Replace existing backups
  122. mv -f "$CEXE1" "$CEXE1.bak"
  123. fi
  124. if [ -e "$CEXE2" ]; then
  125. mv -f "$CEXE2" "$CEXE2.bak"
  126. fi
  127. if [ -e "$VULKAN1" ]; then
  128. echo "--- Workaround for Wine bug 45277"
  129. mv -f "$VULKAN1" "$VULKAN1.bak"
  130. fi
  131. # Registry entry to add on startup
  132. cp -f "$DIR/patch_files/mhyprot2_running.reg" .
  133. echo "--- Adding launcher script"
  134. cp -f "$DIR/patch_files/launcher.bat" .
  135. if [ "$block_analytics" -eq 0 ]; then
  136. # Remove the lines related to domain checking
  137. sed -i "/REM DOMAIN_CHECK_BEGIN/,/REM DOMAIN_CHECK_END/d" "launcher.bat"
  138. fi
  139. if [[ "$reltype" != "os" ]]; then
  140. # Same thing but different
  141. sed -i "s/GenshinImpact/YuanShen/g" "launcher.bat"
  142. sed -i "s/sg-public-data-api.hoyoverse/public-data-api.mihoyo/g" "launcher.bat"
  143. sed -i "s/log-upload-os.hoyoverse/log-upload.mihoyo/g" "launcher.bat"
  144. sed -i "s/overseauspider.yuanshen/uspider.yuanshen/g" "launcher.bat"
  145. fi
  146. # Do the patch now, replace existing backups (hash confirmed)
  147. echo "--- Patching UnityPlayer"
  148. xdelta_fail() {
  149. mv -vf "$FILE.bak" "$FILE"
  150. exit 1
  151. }
  152. mv -f "$FILE" "$FILE.bak"
  153. # Perform patch or restore .bak on failure
  154. xdelta3 -d -s "$FILE.bak" "$DIR/patch_files/unityplayer_patch_${reltype}.vcdiff" "$FILE" || xdelta_fail
  155. # Temporary workaround for faulty updates on game version 3.7.0
  156. if [ `find "$DATADIR/Plugins/" -iname telemetry.dll 2>/dev/null | wc -l` -gt 1 ]; then
  157. echo "--- Removing duplicated telemetry.dll"
  158. rm -f "$DATADIR/Plugins/Telemetry.dll"
  159. fi
  160. # Done!
  161. echo "==> Patch applied! Enjoy the game."
  162. echo
  163. echo "[NOTICE] Please refrain from sharing this project in public so"
  164. echo " that there can be Linux patches in the future. Thank you."
  165. exit 0