install.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/env bash
  2. # HSR patch by mkrsym1
  3. # https://notabug.org/mkrsym1/astra
  4. # mirror: https://codeberg.org/an-anime-team/astra
  5. script_dir=`dirname "$0"`
  6. source "${script_dir}"/common
  7. error "PATCH IS UNSAFE. PLEASE MONITOR THE MAIN REPOSITORY"
  8. exit 1
  9. if [ "$(realpath "${script_dir}")" == "$(realpath .)" ]; then
  10. error "Do not put the patch installer into the game directory!"
  11. fi
  12. if ! command -v xdelta3 2>&1 >> /dev/null; then
  13. error "xdelta3 is required for patching the game files, but was not found!"
  14. fi
  15. root_cmd="pkexec"
  16. yes_to_all=""
  17. no_root=""
  18. # Parse commandline arguments
  19. while [ "x$1" != "x" ];
  20. do
  21. case $1 in
  22. --root-cmd)
  23. shift
  24. root_cmd="$1"
  25. ;;
  26. --yes-to-all)
  27. yes_to_all="1"
  28. ;;
  29. --no-root)
  30. no_root="1"
  31. ;;
  32. *)
  33. error "Invalid commandline argmument: $1"
  34. ;;
  35. esac
  36. shift
  37. done
  38. # Logging servers
  39. logging_servers_os=$(cat <<EOF
  40. # Honkai Star Rail logging servers (oversea)
  41. 0.0.0.0 log-upload-os.hoyoverse.com
  42. 0.0.0.0 sg-public-data-api.hoyoverse.com
  43. EOF
  44. )
  45. logging_servers_cn=$(cat <<EOF
  46. # Honkai Star Rail logging servers (China)
  47. 0.0.0.0 log-upload.mihoyo.com
  48. 0.0.0.0 public-data-api.mihoyo.com
  49. EOF
  50. )
  51. # Region detection
  52. game_region=""
  53. logging_servers=""
  54. starrailbase_checksum=($(md5sum StarRailBase.dll))
  55. unityplayer_checksum=($(md5sum UnityPlayer.dll))
  56. case "${starrailbase_checksum}-${unityplayer_checksum}" in
  57. "8aa3790aafa3dd176678392f3f93f435-f17b9b7f9b8c9cbd211bdff7771a80c2")
  58. game_region="os"
  59. logging_servers="${logging_servers_os}"
  60. ;;
  61. "66c42871ce82456967d004ccb2d7cf77-0c866c44bb3752031a8c12ffe935b26f")
  62. game_region="cn"
  63. logging_servers="${logging_servers_cn}"
  64. ;;
  65. *)
  66. error "Wrong game version or game is already patched. Run uninstall.sh to remove the patch."
  67. ;;
  68. esac
  69. info "Detected region: ${game_region}"
  70. if ! [ "${yes_to_all}" ]; then
  71. echo
  72. 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!"
  73. read -p "Do you wish to proceed? [y/N] " response
  74. if [[ ! "$response" == [Yy]* ]]; then
  75. exit 1
  76. fi
  77. fi
  78. echo
  79. info "Installing the patch"
  80. echo
  81. if ! [ "${no_root}" ]; then
  82. if [[ ! `cat /etc/hosts` == *"$logging_servers"* ]]; then
  83. info "Blocking logging servers. This will require superuser privileges (canceling will skip this step)"
  84. echo "$logging_servers" | $root_cmd tee -a /etc/hosts 2>&1 >> /dev/null
  85. if test $? -ne 0; then
  86. warn "Could not block logging servers. Please add the following lines to your /etc/hosts manually:"
  87. echo "$logging_servers"
  88. fi
  89. else
  90. info "Logging servers are already blocked"
  91. fi
  92. else
  93. info "Skipped blocking logging servers because of --no-root"
  94. fi
  95. echo
  96. for rename_file in ${rename_files[@]}
  97. do
  98. if test -f "${rename_file}"; then
  99. info "Renaming ${rename_file}"
  100. mv "${rename_file}" "${rename_file}.bak"
  101. if test $? -ne 0; then
  102. error "Failed to rename ${rename_file}!"
  103. fi
  104. else
  105. warn "${rename_file} does not exist, ignoring"
  106. fi
  107. done
  108. echo
  109. info "Copying additional files"
  110. for additional_file in ${additional_files[@]}
  111. do
  112. info "Copying ${additional_file}"
  113. cp -r "${script_dir}/${game_region}/files/${additional_file}" .
  114. if test $? -ne 0; then
  115. error "Failed to copy ${additional_file}!"
  116. fi
  117. done
  118. echo
  119. info "Patching game files"
  120. for game_file in ${game_files[@]}
  121. do
  122. if test -f "${game_file}"; then
  123. info "Patching ${game_file}"
  124. mv "${game_file}" "${game_file}.bak"
  125. xdelta3 -d -s "${game_file}.bak" "${script_dir}/${game_region}/diffs/${game_file}.vcdiff" "${game_file}"
  126. if test $? -ne 0; then
  127. error "Failed to patch ${game_file}!"
  128. fi
  129. else
  130. error "${game_file} not found!"
  131. fi
  132. done
  133. echo
  134. info "Done"
  135. echo
  136. echo "!!! PLEASE DON'T SHARE THIS PROJECT IN PUBLIC !!!"
  137. echo