patch.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.0.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. domains+=("sdk-log-upload-os.hoyoverse.com")
  65. else
  66. # Possibly outdated as of 4.6.0
  67. domains+=("log-upload.mihoyo.com")
  68. domains+=("uspider.yuanshen.com")
  69. domains+=("ys-log-upload.mihoyo.com")
  70. domains+=("sdk-log-upload.mihoyo.com")
  71. fi
  72. servers="# Genshin logging servers (do not remove!)"
  73. for i in "${domains[@]}"; do
  74. servers=$(echo -e "${servers}\n0.0.0.0 $i")
  75. done
  76. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  77. echo "[Optional] Block analytics domains via /etc/hosts"
  78. echo " The game collects uniquely identifiable information about your system."
  79. echo " For details, refer to the official privacy page or the file"
  80. echo " '../static/analytics_data.md' contained in this repository."
  81. echo "$servers"
  82. read -r -p "Would you like to block the analytics servers above? [Y/n]: " choice
  83. if [[ ! "$choice" == [Nn0]* ]]; then
  84. echo "-- Adding analytics servers"
  85. echo "$servers" | sudo tee -a /etc/hosts
  86. if [ $? -ne 0 ]; then
  87. read -p "--- Failed. Please edit /etc/hosts manually. Enter to continue."
  88. fi
  89. else
  90. block_analytics=0
  91. fi
  92. else
  93. echo "--- Analytics servers are already blocked. Skip."
  94. fi
  95. # "Fix" to allow start-up 1 week *before* the next update. See issue #471
  96. bb_domain="dispatchcnglobal.yuanshen.com"
  97. servers=$(cat <<EOF
  98. # Workaround for BiliBili startup issue
  99. 0.0.0.0 ${bb_domain}
  100. EOF
  101. )
  102. if [[ $reltype == "bb" ]] && [[ ! "$etc_hosts" == *"$servers"* ]]; then
  103. echo "[Info] Detected BiliBili variant. It is likely that the game will no longer start"
  104. echo " 1 week before the next update. Would you like to block the following domain"
  105. echo " with /etc/hosts as a workaround? If not, cancel this step using Ctrl+C."
  106. echo "$servers"
  107. echo "$servers" | sudo tee -a /etc/hosts
  108. if [ $? -eq 0 ]; then
  109. domains+=($bb_domain)
  110. else
  111. echo "--- Cancelled. Domain not added."
  112. fi
  113. fi
  114. etc_hosts=""
  115. # END OF SUDO DANGER ZONE
  116. # ===========================================================
  117. echo "--- Adding launcher script"
  118. cp -f "$DIR/patch_files/launcher.bat" .
  119. if [ "$block_analytics" -eq 0 ]; then
  120. # Remove the lines related to domain checking
  121. sed -i "/REM DOMAIN_CHECK_BEGIN/,/REM DOMAIN_CHECK_END/d" "launcher.bat"
  122. fi
  123. if [[ "$reltype" != "os" ]]; then
  124. # Same thing but different
  125. sed -i "s/GenshinImpact/YuanShen/g" "launcher.bat"
  126. fi
  127. n=0
  128. placeholder="UNKNOWN_DOMAIN"
  129. while true; do
  130. [ "$n" -eq "${#domains[@]}" ] && break
  131. grep --quiet "$placeholder" -- "launcher.bat"
  132. if [ $? -eq 1 ]; then
  133. # TODO: There are currently only 5 placeholders
  134. echo "[ERROR] Domain blocking code template is too short."
  135. break
  136. fi
  137. sed -i "1,// s/${placeholder}/${domains[${n}]}/" "launcher.bat"
  138. n=$((n + 1))
  139. done
  140. sed -i "/REM SCRIPT_SANITY_BEGIN/,/REM SCRIPT_SANITY_END/d" "launcher.bat"
  141. # Done!
  142. echo "==> Patch applied! Enjoy the game."
  143. echo
  144. echo "[NOTICE] Please refrain from sharing this project in public. Thank you."
  145. exit 0