patch.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 4.1.0)
  58. if [[ "$reltype" == "os" ]]; then
  59. servers=$(cat <<EOF
  60. # Genshin logging servers (do not remove!)
  61. 0.0.0.0 log-upload-os.hoyoverse.com
  62. 0.0.0.0 overseauspider.yuanshen.com
  63. 0.0.0.0 ys-log-upload-os.hoyoverse.com
  64. EOF
  65. )
  66. else
  67. servers=$(cat <<EOF
  68. # Genshin logging servers (do not remove!)
  69. 0.0.0.0 log-upload.mihoyo.com
  70. 0.0.0.0 uspider.yuanshen.com
  71. 0.0.0.0 ys-log-upload.mihoyo.com
  72. EOF
  73. )
  74. fi
  75. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  76. echo "[Optional] Block analytics domains via /etc/hosts"
  77. echo " The game collects uniquely identifiable information about your system."
  78. echo " For details, refer to the official privacy page or the file"
  79. echo " '../static/analytics_data.md' contained in this repository."
  80. echo "$servers"
  81. read -r -p "Would you like to block the analytics servers above? [Y/n]: " choice
  82. if [[ ! "$choice" == [Nn0]* ]]; then
  83. echo "-- Adding analytics servers"
  84. echo "$servers" | sudo tee -a /etc/hosts
  85. if [ $? -ne 0 ]; then
  86. read -p "--- Failed. Please edit /etc/hosts manually. Enter to continue."
  87. fi
  88. else
  89. block_analytics=0
  90. fi
  91. else
  92. echo "--- Analytics servers are already blocked. Skip."
  93. fi
  94. etc_hosts=""
  95. # END OF SUDO DANGER ZONE
  96. # ===========================================================
  97. echo "--- Adding launcher script"
  98. cp -f "$DIR/patch_files/launcher.bat" .
  99. if [ "$block_analytics" -eq 0 ]; then
  100. # Remove the lines related to domain checking
  101. sed -i "/REM DOMAIN_CHECK_BEGIN/,/REM DOMAIN_CHECK_END/d" "launcher.bat"
  102. fi
  103. if [[ "$reltype" != "os" ]]; then
  104. # Same thing but different
  105. sed -i "s/GenshinImpact/YuanShen/g" "launcher.bat"
  106. sed -i "s/log-upload-os.hoyoverse/log-upload.mihoyo/g" "launcher.bat"
  107. sed -i "s/overseauspider.yuanshen/uspider.yuanshen/g" "launcher.bat"
  108. fi
  109. # Temporary workaround for faulty updates on game version 3.7.0
  110. if [ `find "$DATADIR/Plugins/" -iname telemetry.dll 2>/dev/null | wc -l` -gt 1 ]; then
  111. echo "--- Removing duplicated telemetry.dll"
  112. rm -f "$DATADIR/Plugins/Telemetry.dll"
  113. fi
  114. # Done!
  115. echo "==> Patch applied! Enjoy the game."
  116. echo
  117. echo "[NOTICE] Please refrain from sharing this project in public. Thank you."
  118. exit 0