123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #!/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
- # 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"
- CEXE1="$DATADIR/upload_crash.exe"
- CEXE2="$DATADIR/Plugins/crashreport.exe"
- VULKAN1="$DATADIR/Plugins/vulkan-1.dll"
- sum=($(md5sum $FILE))
- reltype="" # os, cn, bb
- block_analytics=1
- # original hashes
- if [ "${sum}" == "a8238a3be126723b7226b16447a6cb81" ]; then
- reltype="os"
- echo "--- Applying for: International version"
- fi
- if [ "${sum}" == "70b9906ba8c9adec0276c84f087d25d2" ]; then
- if [ -e "$DATADIR/Plugins/PCGameSDK.dll" ]; then
- reltype="bb"
- echo "--- Applying for: bilibili CN version"
- else
- reltype="cn"
- echo "--- Applying for: miHoYo CN version"
- fi
- 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 ===========
- if ! command -v xdelta3 &>/dev/null; then
- echo "[ERROR] xdelta3 application is required"
- echo " -> Debian/Ubuntu: apt install xdelta3"
- echo " -> Fedora: dnf install xdelta"
- echo " -> Arch/Arch-based: pacman -S xdelta3"
- echo " -> macOS: \"port install xdelta\" or \"brew install xdelta\""
- exit 1
- fi
- # ===========================================================
- echo ""
- echo "[WARNING] Hereby you are violating the game's Terms of Service!"
- echo " Do you accept the risk and possible consequences?"
- echo " Use Ctrl+C to abort this script if you are not sure."
- read -p "Accept? [y/N] " choice
- if [[ ! "$choice" == [JjSsYy]* ]]; then
- exit 1
- fi
- 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 3.4.0)
- # Note: overseauspider is no longer used (2.8.0). Kept to complement the CN version.
- if [[ "$reltype" == "os" ]]; then
- servers=$(cat <<EOF
- # Genshin logging servers (do not remove!)
- 0.0.0.0 sg-public-data-api.hoyoverse.com
- 0.0.0.0 log-upload-os.hoyoverse.com
- 0.0.0.0 overseauspider.yuanshen.com
- EOF
- )
- else
- servers=$(cat <<EOF
- # Genshin logging servers (do not remove!)
- 0.0.0.0 public-data-api.mihoyo.com
- 0.0.0.0 log-upload.mihoyo.com
- 0.0.0.0 uspider.yuanshen.com
- EOF
- )
- fi
- 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.txt' 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
- echo ""
- # No crashes shall be reported!
- echo "--- Renaming the crash reporter(s)"
- if [ -e "$CEXE1" ]; then
- # Replace existing backups
- mv -f "$CEXE1" "$CEXE1.bak"
- fi
- if [ -e "$CEXE2" ]; then
- mv -f "$CEXE2" "$CEXE2.bak"
- fi
- if [ -e "$VULKAN1" ]; then
- echo "--- Workaround for Wine bug 45277"
- mv -f "$VULKAN1" "$VULKAN1.bak"
- fi
- # Registry entry to add on startup
- cp -f "$DIR/patch_files/mhyprot2_running.reg" .
- 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"
- sed -i "s/sg-public-data-api.hoyoverse/public-data-api.mihoyo/g" "launcher.bat"
- sed -i "s/log-upload-os.hoyoverse/log-upload.mihoyo/g" "launcher.bat"
- fi
- # Do the patch now, replace existing backups (hash confirmed)
- echo "--- Patching UnityPlayer"
- xdelta_fail() {
- mv -vf "$FILE.bak" "$FILE"
- exit 1
- }
- mv -f "$FILE" "$FILE.bak"
- # Perform patch or restore .bak on failure
- xdelta3 -d -s "$FILE.bak" "$DIR/patch_files/unityplayer_patch_${reltype}.vcdiff" "$FILE" || xdelta_fail
- # Done!
- echo "==> Patch applied! Enjoy the game."
- echo
- echo "[NOTICE] Please refrain from sharing this project in public so"
- echo " that there can be Linux patches in the future. Thank you."
- exit 0
|