install.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 "PROVEN UNSAFE. MONITOR #7 ON THE MAIN REPOSITORY."
  8. if [ "$(realpath "${script_dir}")" == "$(realpath .)" ]; then
  9. error "Do not put the patch installer into the game directory!"
  10. fi
  11. if ! command -v xdelta3 2>&1 >> /dev/null; then
  12. error "xdelta3 is required for patching the game files, but was not found!"
  13. fi
  14. patch_data=""
  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. --patch-data)
  23. shift
  24. patch_data="$1"
  25. ;;
  26. --root-cmd)
  27. shift
  28. root_cmd="$1"
  29. ;;
  30. --yes-to-all)
  31. yes_to_all="1"
  32. ;;
  33. --no-root)
  34. no_root="1"
  35. ;;
  36. *)
  37. error "Invalid commandline argmument: $1"
  38. ;;
  39. esac
  40. shift
  41. done
  42. if [ "x${patch_data}" == "x" ]; then
  43. error "Patch data directory not specified!"
  44. fi
  45. # Logging servers
  46. logging_servers_os=$(cat <<EOF
  47. # Honkai Star Rail logging servers (oversea)
  48. 0.0.0.0 log-upload-os.hoyoverse.com
  49. 0.0.0.0 sg-public-data-api.hoyoverse.com
  50. EOF
  51. )
  52. # Region detection
  53. game_region=""
  54. logging_servers=""
  55. starrailbase_checksum=($(md5sum StarRailBase.dll))
  56. unityplayer_checksum=($(md5sum UnityPlayer.dll))
  57. case "${starrailbase_checksum}-${unityplayer_checksum}" in
  58. "8aa3790aafa3dd176678392f3f93f435-f17b9b7f9b8c9cbd211bdff7771a80c2")
  59. game_region="os"
  60. logging_servers="${logging_servers_os}"
  61. ;;
  62. *)
  63. error "Wrong game version or game is already patched. Run uninstall.sh to remove the patch."
  64. ;;
  65. esac
  66. info "Detected region: ${game_region}"
  67. warn "VERSION WITH EXPERIMENTAL MITIGATIONS. MIGHT NOT WORK."
  68. if ! [ "${yes_to_all}" ]; then
  69. echo
  70. 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!"
  71. read -p "Do you wish to proceed? [y/N] " response
  72. if [[ ! "$response" == [Yy]* ]]; then
  73. exit 1
  74. fi
  75. fi
  76. echo
  77. info "Installing the patch"
  78. mkdir -p "${patch_data}"
  79. echo
  80. if ! [ "${no_root}" ]; then
  81. if [[ ! `cat /etc/hosts` == *"$logging_servers"* ]]; then
  82. info "Blocking logging servers. This will require superuser privileges (canceling will skip this step)"
  83. echo "$logging_servers" | $root_cmd tee -a /etc/hosts 2>&1 >> /dev/null
  84. if test $? -ne 0; then
  85. warn "Could not block logging servers. Please add the following lines to your /etc/hosts manually:"
  86. echo "$logging_servers"
  87. fi
  88. else
  89. info "Logging servers are already blocked"
  90. fi
  91. else
  92. info "Skipped blocking logging servers because of --no-root"
  93. fi
  94. echo
  95. info "Copying additional files"
  96. for additional_file in ${additional_files[@]}
  97. do
  98. info "Copying ${additional_file}"
  99. cp -r "${script_dir}/${game_region}/files/${additional_file}" "${patch_data}"
  100. if test $? -ne 0; then
  101. error "Failed to copy ${additional_file}!"
  102. fi
  103. done
  104. info "Creating the game launch script"
  105. cat "${script_dir}/${game_region}/files/launch1.bat" > ./launch.bat
  106. winepath -w "${patch_data}/TVMBootstrap.dll" | sed 's|\\|\\\\|g' | tr -d "\n" >> ./launch.bat
  107. cat "${script_dir}/${game_region}/files/launch2.bat" >> ./launch.bat
  108. echo
  109. info "Patching game files"
  110. for game_file in ${game_files[@]}
  111. do
  112. if test -f "${game_file}"; then
  113. info "Patching ${game_file}"
  114. mv "${game_file}" "${game_file}.bak"
  115. xdelta3 -d -s "${game_file}.bak" "${script_dir}/${game_region}/diffs/${game_file}.vcdiff" "${game_file}"
  116. if test $? -ne 0; then
  117. error "Failed to patch ${game_file}!"
  118. fi
  119. else
  120. error "${game_file} not found!"
  121. fi
  122. done
  123. echo
  124. info "Done"
  125. echo
  126. echo "!!! PLEASE DON'T SHARE THIS PROJECT IN PUBLIC !!!"
  127. echo