123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #!/usr/bin/env bash
- # HSR patch by mkrsym1
- # https://notabug.org/mkrsym1/astra
- # mirror: https://codeberg.org/an-anime-team/astra
- script_dir=`dirname "$0"`
- source "${script_dir}"/common
- error "PATCH IS UNSAFE. PLEASE MONITOR THE MAIN REPOSITORY"
- exit 1
- if [ "$(realpath "${script_dir}")" == "$(realpath .)" ]; then
- error "Do not put the patch installer into the game directory!"
- fi
- if ! command -v xdelta3 2>&1 >> /dev/null; then
- error "xdelta3 is required for patching the game files, but was not found!"
- fi
- root_cmd="pkexec"
- yes_to_all=""
- no_root=""
- # Parse commandline arguments
- while [ "x$1" != "x" ];
- do
- case $1 in
- --root-cmd)
- shift
- root_cmd="$1"
- ;;
- --yes-to-all)
- yes_to_all="1"
- ;;
- --no-root)
- no_root="1"
- ;;
- *)
- error "Invalid commandline argmument: $1"
- ;;
- esac
- shift
- done
- # Logging servers
- logging_servers_os=$(cat <<EOF
- # Honkai Star Rail logging servers (oversea)
- 0.0.0.0 log-upload-os.hoyoverse.com
- 0.0.0.0 sg-public-data-api.hoyoverse.com
- EOF
- )
- logging_servers_cn=$(cat <<EOF
- # Honkai Star Rail logging servers (China)
- 0.0.0.0 log-upload.mihoyo.com
- 0.0.0.0 public-data-api.mihoyo.com
- EOF
- )
- # Region detection
- game_region=""
- logging_servers=""
- starrailbase_checksum=($(md5sum StarRailBase.dll))
- unityplayer_checksum=($(md5sum UnityPlayer.dll))
- case "${starrailbase_checksum}-${unityplayer_checksum}" in
- "8aa3790aafa3dd176678392f3f93f435-f17b9b7f9b8c9cbd211bdff7771a80c2")
- game_region="os"
- logging_servers="${logging_servers_os}"
- ;;
- "66c42871ce82456967d004ccb2d7cf77-0c866c44bb3752031a8c12ffe935b26f")
- game_region="cn"
- logging_servers="${logging_servers_cn}"
- ;;
- *)
- error "Wrong game version or game is already patched. Run uninstall.sh to remove the patch."
- ;;
- esac
- info "Detected region: ${game_region}"
- if ! [ "${yes_to_all}" ]; then
- echo
- echo "Modifying the game is a violation of it's Terms of Service! Make sure that you understand all of the risks and possible consequences before proceeding!"
- read -p "Do you wish to proceed? [y/N] " response
- if [[ ! "$response" == [Yy]* ]]; then
- exit 1
- fi
- fi
- echo
- info "Installing the patch"
- echo
- if ! [ "${no_root}" ]; then
- if [[ ! `cat /etc/hosts` == *"$logging_servers"* ]]; then
- info "Blocking logging servers. This will require superuser privileges (canceling will skip this step)"
- echo "$logging_servers" | $root_cmd tee -a /etc/hosts 2>&1 >> /dev/null
- if test $? -ne 0; then
- warn "Could not block logging servers. Please add the following lines to your /etc/hosts manually:"
- echo "$logging_servers"
- fi
- else
- info "Logging servers are already blocked"
- fi
- else
- info "Skipped blocking logging servers because of --no-root"
- fi
- echo
- for rename_file in ${rename_files[@]}
- do
- if test -f "${rename_file}"; then
- info "Renaming ${rename_file}"
- mv "${rename_file}" "${rename_file}.bak"
- if test $? -ne 0; then
- error "Failed to rename ${rename_file}!"
- fi
- else
- warn "${rename_file} does not exist, ignoring"
- fi
- done
- echo
- info "Copying additional files"
- for additional_file in ${additional_files[@]}
- do
- info "Copying ${additional_file}"
- cp -r "${script_dir}/${game_region}/files/${additional_file}" .
- if test $? -ne 0; then
- error "Failed to copy ${additional_file}!"
- fi
- done
- echo
- info "Patching game files"
- for game_file in ${game_files[@]}
- do
- if test -f "${game_file}"; then
- info "Patching ${game_file}"
-
- mv "${game_file}" "${game_file}.bak"
- xdelta3 -d -s "${game_file}.bak" "${script_dir}/${game_region}/diffs/${game_file}.vcdiff" "${game_file}"
- if test $? -ne 0; then
- error "Failed to patch ${game_file}!"
- fi
- else
- error "${game_file} not found!"
- fi
- done
- echo
- info "Done"
- echo
- echo "!!! PLEASE DON'T SHARE THIS PROJECT IN PUBLIC !!!"
- echo
|