patch.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/env bash
  2. # Templates for next patch
  3. echo " === !! UNTESTED PATCH. CHECK FOR BANS USING A TRASH ACCOUNT !! ==="
  4. echo " === AND REPORT RESULTS TO THE MAIN REPOSITORY. THANK YOU ==="
  5. echo "If you would like to test this patch, modify this script and remove the line below this one."
  6. exit 1
  7. #echo " === !! This patch is very new but almost identical to 1.5.1!! ==="
  8. #echo " === If you are worried, use a secondary account for a few days ==="
  9. #read -p "Continue? [Enter] " _dumpster_
  10. DIR=$(dirname "${BASH_SOURCE[0]}")
  11. FILE="UnityPlayer.dll"
  12. CEXE="GenshinImpact_Data/upload_crash.exe"
  13. sum=($(md5sum $FILE))
  14. if [ "${sum}" != "6a0b94f5d9fbd2724215e40ec07e2c75" ]; then
  15. # The patch might corrupt invalid/outdated files if this check is skippd.
  16. echo "Wrong file version or patch is already applied"
  17. echo "md5sum: ${sum}" && exit 1
  18. fi
  19. # =========== DO NOT REMOVE START ===========
  20. if [[ -e "$DIR/$FILE" ]]; then
  21. # There is a good reason for this check. Do not pollute the game directory.
  22. echo "Please move all patch files outside the game directory prior executing."
  23. echo " -> See README.md for proper installation instructions" && exit 1
  24. fi
  25. # =========== DO NOT REMOVE END ===========
  26. if ! command -v xdelta3 &>/dev/null; then
  27. echo "xdelta3 application is required"
  28. echo " -> Debian/Ubuntu: apt install xdelta3"
  29. echo " -> Fedora: dnf install xdelta"
  30. echo " -> Arch/Arch-based: pacman -S xdelta3"
  31. exit 1
  32. fi
  33. # ===========================================================
  34. echo "[WARNING] Hereby you are violating the game's Terms of Service!"
  35. echo " Do you accept the risk and possible consequences?"
  36. read -p "Accept? [y/n] " choice
  37. if [[ ! "$choice" == [JjSsYy]* ]]; then
  38. exit 1
  39. fi
  40. echo
  41. echo "--- Setting up blocked servers"
  42. # START OF SUDO DANGER ZONE
  43. etc_hosts="$(cat /etc/hosts)"
  44. # See dev_tools/network.md (up-to-date as of 1.6.0)
  45. servers=$(cat <<EOF
  46. # Genshin logging servers (do not remove!)
  47. 0.0.0.0 log-upload-os.mihoyo.com
  48. 0.0.0.0 overseauspider.yuanshen.com
  49. EOF
  50. )
  51. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  52. echo "[MANDATORY] Adding following logging servers to /etc/hosts"
  53. echo " If you really really want to skip this (Ctrl+C),"
  54. echo " PLEASE add the entries manually. Otherwise they will receive"
  55. echo " logs about The Wine project, hence UNCOVERING THIS PATCH!"
  56. echo "$servers" | sudo -k tee -a /etc/hosts
  57. if [ $? -ne 0 ]; then
  58. echo "$servers"
  59. read -p "Please append these lines to your /etc/hosts file now. Enter to continue."
  60. fi
  61. else
  62. echo "--- Logging servers are already blocked. Skip."
  63. fi
  64. servers=$(cat <<EOF
  65. # Optional Unity proxy/cdn servers
  66. 0.0.0.0 prd-lender.cdp.internal.unity3d.com
  67. 0.0.0.0 thind-prd-knob.data.ie.unity3d.com
  68. 0.0.0.0 thind-gke-usc.prd.data.corp.unity3d.com
  69. 0.0.0.0 cdp.cloud.unity3d.com
  70. 0.0.0.0 remote-config-proxy-prd.uca.cloud.unity3d.com
  71. EOF
  72. )
  73. if [[ ! "$etc_hosts" == *"$servers"* ]]; then
  74. echo ""
  75. echo "[Optional] Adding common Unity proxy/cdn servers to /etc/hosts"
  76. echo " Normally this does not cause any issues. If issues arise in other games,"
  77. echo " consider commenting a few lines to check what makes the difference."
  78. read -p "Add 5 servers? [y/n] " choice
  79. if [[ "$choice" == [JjSsYy]* ]]; then
  80. echo "-- Adding proxy/cdn servers"
  81. echo "$servers" | sudo tee -a /etc/hosts
  82. if [ $? -ne 0 ]; then
  83. read -p "--- FAILED to add the servers. Enter to continue."
  84. fi
  85. fi
  86. else
  87. echo "--- Unity proxy/cdn servers are already blocked. Skip."
  88. fi
  89. etc_hosts=""
  90. # END OF SUDO DANGER ZONE
  91. echo ""
  92. # No crashes shall be reported!
  93. echo "--- Renaming the crash reporter"
  94. if [[ -e "$CEXE" ]]; then
  95. # Replace existing backups
  96. mv -f "$CEXE" "$CEXE.bak"
  97. fi
  98. # Registry entry to add on startup
  99. cp -f "$DIR/patch_files/mhyprot2_running.reg" .
  100. # Add launcher & force update to ensure the checks are performed
  101. echo "--- Adding launcher script"
  102. cp -f "$DIR/patch_files/launcher.bat" .
  103. # Do the patch now, replace existing backups (hash confirmed)
  104. echo "--- Patching UnityPlayer"
  105. xdelta_fail() {
  106. mv -vf "$FILE.bak" "$FILE"
  107. exit 1
  108. }
  109. mv -f "$FILE" "$FILE.bak"
  110. # Perform patch or restore .bak on failure
  111. xdelta3 -d -s "$FILE.bak" "$DIR/patch_files/unityplayer_patch.vcdiff" "$FILE" || xdelta_fail
  112. # Done!
  113. echo "==> Patch applied! Enjoy the game."
  114. echo
  115. echo "[NOTICE] Please refrain from sharing this project in public so"
  116. echo " that there can be Linux patches in the future. Thank you."
  117. exit 0