123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #!/usr/bin/env bash
- # DESCRIPTION
- # This is the main patch script to ensure basic game functionality in Wine.
- #
- # EXIT STATUS
- # 0 : The patch was applied successfully.
- # other : Patch failure. See stdout or stderr output for details.
- # Templates for the next patch testing phase
- #echo " === !! UNTESTED PATCH. CHECK FOR BANS USING A TRASH ACCOUNT !! ==="
- #echo " === REPORT RESULTS TO THE MAIN REPOSITORY. THANK YOU. ==="
- #echo ""
- #echo "If you would like to test this patch, modify this script and remove the line below this one."
- #exit 1
- echo "[NOTE] As of game version 3.7.0, it is assumed that binary patches are no longer"
- echo " needed for upcoming game versions. If you face issues while starting the"
- echo " game or logging in, please consult TROUBLESHOOTING.md for workarounds."
- echo ""
- # MacOS and *BSD do not have md5sum: use md5 instead
- if [[ $(uname) == "Darwin" || $(uname) == *"BSD" ]]; then
- md5sum() {
- md5 -q $@
- }
- fi
- DIR=$(dirname "${BASH_SOURCE[0]}")
- DATADIR=$(find . -maxdepth 1 -type d -name "*_Data")
- FILE="UnityPlayer.dll"
- sum=($(md5sum $FILE))
- reltype="" # os, cn, bb
- block_analytics=1
- # original hashes
- # TODO: Switch back to file hashes on occasion
- if [ -e "GenshinImpact.exe" ]; then
- reltype="os"
- echo "--- Applying for: International version"
- fi
- if [ -e "YuanShen.exe" ]; then
- reltype="bb"
- echo "--- Applying for: bilibili/miHoYo CN version"
- fi
- if [ -z "$reltype" ]; then
- # The patch might corrupt invalid/outdated files if this check is skippd.
- echo "[ERROR] Wrong file version or the patch is already applied"
- echo " -> md5sum: ${sum}" && exit 1
- fi
- # =========== DO NOT REMOVE START ===========
- if [[ -e "$DIR/$FILE" ]]; then
- # There is a good reason for this check. Do not pollute the game directory.
- echo "[ERROR] Invalid patch download directory. Please move all"
- echo " patch files outside the game directory prior executing."
- echo " -> See README.md for proper installation instructions" && exit 1
- fi
- # =========== DO NOT REMOVE END ===========
- echo
- echo "--- Setting up blocked servers"
- # START OF SUDO DANGER ZONE
- etc_hosts="$(cat /etc/hosts)"
- # See dev_tools/network.md (up-to-date as of 5.2.0)
- declare -a domains
- if [[ "$reltype" == "os" ]]; then
- domains+=("overseauspider.yuanshen.com")
- domains+=("osuspider.yuanshen.com")
- domains+=("ys-log-upload-os.hoyoverse.com")
- domains+=("sg-public-data-api.hoyoverse.com")
- # v-- unused as of 2024-10-09
- domains+=("sdk-log-upload-os.hoyoverse.com")
- else
- # Possibly outdated as of 4.6.0
- domains+=("log-upload.mihoyo.com")
- domains+=("uspider.yuanshen.com")
- domains+=("ys-log-upload.mihoyo.com")
- domains+=("sdk-log-upload.mihoyo.com")
- fi
- servers="# Genshin logging servers (do not remove!)"
- for i in "${domains[@]}"; do
- servers=$(echo -e "${servers}\n0.0.0.0 $i")
- done
- if [[ ! "$etc_hosts" == *"$servers"* ]]; then
- echo "[Optional] Block analytics domains via /etc/hosts"
- echo " The game collects uniquely identifiable information about your system."
- echo " For details, refer to the official privacy page or the file"
- echo " '../static/analytics_data.md' contained in this repository."
- echo "$servers"
- read -r -p "Would you like to block the analytics servers above? [Y/n]: " choice
- if [[ ! "$choice" == [Nn0]* ]]; then
- echo "-- Adding analytics servers"
- echo "$servers" | sudo tee -a /etc/hosts
- if [ $? -ne 0 ]; then
- read -p "--- Failed. Please edit /etc/hosts manually. Enter to continue."
- fi
- else
- block_analytics=0
- fi
- else
- echo "--- Analytics servers are already blocked. Skip."
- fi
- etc_hosts=""
- # END OF SUDO DANGER ZONE
- # See issue #471 and #490
- if [[ $reltype == "bb" ]]; then
- echo "[Info] Detected BiliBili variant. If the game suddenly refuses to start, it is"
- echo " recommended to use the 'nmcli' workaround documented in '../TROUBLESHOOTING.md'."
- fi
- # ===========================================================
- echo "--- Adding launcher script"
- cp -f "$DIR/patch_files/launcher.bat" .
- if [ "$block_analytics" -eq 0 ]; then
- # Remove the lines related to domain checking
- sed -i "/REM DOMAIN_CHECK_BEGIN/,/REM DOMAIN_CHECK_END/d" "launcher.bat"
- fi
- if [[ "$reltype" != "os" ]]; then
- # Same thing but different
- sed -i "s/GenshinImpact/YuanShen/g" "launcher.bat"
- fi
- n=0
- placeholder="UNKNOWN_DOMAIN"
- while true; do
- [ "$n" -eq "${#domains[@]}" ] && break
- grep --quiet "$placeholder" -- "launcher.bat"
- if [ $? -eq 1 ]; then
- # TODO: There are currently only 5 placeholders
- echo "[ERROR] Domain blocking code template is too short."
- break
- fi
- sed -i "1,// s/${placeholder}/${domains[${n}]}/" "launcher.bat"
- n=$((n + 1))
- done
- sed -i "/REM SCRIPT_SANITY_BEGIN/,/REM SCRIPT_SANITY_END/d" "launcher.bat"
- # Done!
- echo "==> Patch applied! Enjoy the game."
- echo
- echo "[NOTICE] Please refrain from sharing this project in public. Thank you."
- exit 0
|