patch.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. echo "[NOTE] As of game version 3.7.0, it is assumed that binary patches are no longer"
  15. echo " needed for upcoming game versions. If you face issues while starting the"
  16. echo " game or logging in, please consult TROUBLESHOOTING.md for workarounds."
  17. echo ""
  18. # MacOS and *BSD do not have md5sum: use md5 instead
  19. if [[ $(uname) == "Darwin" || $(uname) == *"BSD" ]]; then
  20. md5sum() {
  21. md5 -q $@
  22. }
  23. fi
  24. DIR=$(dirname "${BASH_SOURCE[0]}")
  25. DATADIR=$(find . -maxdepth 1 -type d -name "*_Data")
  26. FILE="UnityPlayer.dll"
  27. sum=($(md5sum $FILE))
  28. reltype="" # os, cn, bb
  29. block_analytics=1
  30. # original hashes
  31. # TODO: Switch back to file hashes on occasion
  32. if [ -e "GenshinImpact.exe" ]; then
  33. reltype="os"
  34. echo "--- Applying for: International version"
  35. fi
  36. if [ -e "YuanShen.exe" ]; then
  37. reltype="bb"
  38. echo "--- Applying for: bilibili/miHoYo CN version"
  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. echo
  54. echo "--- Setting up blocked servers"
  55. # START OF SUDO DANGER ZONE
  56. etc_hosts="$(cat /etc/hosts)"
  57. # See dev_tools/network.md (up-to-date as of 5.1.0)
  58. declare -a domains
  59. if [[ "$reltype" == "os" ]]; then
  60. domains+=("overseauspider.yuanshen.com")
  61. domains+=("osuspider.yuanshen.com")
  62. domains+=("ys-log-upload-os.hoyoverse.com")
  63. domains+=("sg-public-data-api.hoyoverse.com")
  64. # v-- unused as of 2024-10-09
  65. domains+=("sdk-log-upload-os.hoyoverse.com")
  66. else
  67. # Possibly outdated as of 4.6.0
  68. domains+=("log-upload.mihoyo.com")
  69. domains+=("uspider.yuanshen.com")
  70. domains+=("ys-log-upload.mihoyo.com")
  71. domains+=("sdk-log-upload.mihoyo.com")
  72. fi
  73. servers="# Genshin logging servers (do not remove!)"
  74. for i in "${domains[@]}"; do
  75. servers=$(echo -e "${servers}\n0.0.0.0 $i")
  76. done
  77. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  78. echo "[Optional] Block analytics domains via /etc/hosts"
  79. echo " The game collects uniquely identifiable information about your system."
  80. echo " For details, refer to the official privacy page or the file"
  81. echo " '../static/analytics_data.md' contained in this repository."
  82. echo "$servers"
  83. read -r -p "Would you like to block the analytics servers above? [Y/n]: " choice
  84. if [[ ! "$choice" == [Nn0]* ]]; then
  85. echo "-- Adding analytics servers"
  86. echo "$servers" | sudo tee -a /etc/hosts
  87. if [ $? -ne 0 ]; then
  88. read -p "--- Failed. Please edit /etc/hosts manually. Enter to continue."
  89. fi
  90. else
  91. block_analytics=0
  92. fi
  93. else
  94. echo "--- Analytics servers are already blocked. Skip."
  95. fi
  96. # "Fix" to allow start-up 1 week *before* the next update. See issue #471
  97. bb_domain="dispatchcnglobal.yuanshen.com"
  98. servers=$(cat <<EOF
  99. # Workaround for BiliBili startup issue
  100. 0.0.0.0 ${bb_domain}
  101. EOF
  102. )
  103. if [[ $reltype == "bb" ]] && [[ ! "$etc_hosts" == *"$servers"* ]]; then
  104. echo "[Info] Detected BiliBili variant. It is likely that the game will no longer start"
  105. echo " 1 week before the next update. Would you like to block the following domain"
  106. echo " with /etc/hosts as a workaround? If not, cancel this step using Ctrl+C."
  107. echo "$servers"
  108. echo "$servers" | sudo tee -a /etc/hosts
  109. if [ $? -eq 0 ]; then
  110. domains+=($bb_domain)
  111. else
  112. echo "--- Cancelled. Domain not added."
  113. fi
  114. fi
  115. etc_hosts=""
  116. # END OF SUDO DANGER ZONE
  117. # ===========================================================
  118. echo "--- Adding launcher script"
  119. cp -f "$DIR/patch_files/launcher.bat" .
  120. if [ "$block_analytics" -eq 0 ]; then
  121. # Remove the lines related to domain checking
  122. sed -i "/REM DOMAIN_CHECK_BEGIN/,/REM DOMAIN_CHECK_END/d" "launcher.bat"
  123. fi
  124. if [[ "$reltype" != "os" ]]; then
  125. # Same thing but different
  126. sed -i "s/GenshinImpact/YuanShen/g" "launcher.bat"
  127. fi
  128. n=0
  129. placeholder="UNKNOWN_DOMAIN"
  130. while true; do
  131. [ "$n" -eq "${#domains[@]}" ] && break
  132. grep --quiet "$placeholder" -- "launcher.bat"
  133. if [ $? -eq 1 ]; then
  134. # TODO: There are currently only 5 placeholders
  135. echo "[ERROR] Domain blocking code template is too short."
  136. break
  137. fi
  138. sed -i "1,// s/${placeholder}/${domains[${n}]}/" "launcher.bat"
  139. n=$((n + 1))
  140. done
  141. sed -i "/REM SCRIPT_SANITY_BEGIN/,/REM SCRIPT_SANITY_END/d" "launcher.bat"
  142. # Done!
  143. echo "==> Patch applied! Enjoy the game."
  144. echo
  145. echo "[NOTICE] Please refrain from sharing this project in public. Thank you."
  146. exit 0