get_gacha_url.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. # DESCRIPTION
  3. # Extracts the gacha URL from the Chromium Embedded Framework cache.
  4. # The file paths are detected automatically based on the game process ID
  5. # and executable path.
  6. #
  7. # NOTES
  8. # This script currently returns the last URL in the cache file, which
  9. # usually works but is not entirely reliable.
  10. #
  11. # EXIT STATUS
  12. # 0 on success
  13. set -e
  14. GIPATH="."
  15. function get_path_from_pid() {
  16. # tee eats the status value
  17. _pid=$(pgrep -f -- "GenshinImpact.exe" | tee | head -1)
  18. if [ -z "$_pid" ]; then
  19. _pid=$(pgrep -f -- "YuanShen.exe" | tee | head -1)
  20. fi
  21. [ -z "$_pid" ] && echo "Game process not found" && exit 1
  22. GIPATH=$(pwdx "$_pid")
  23. GIPATH=${GIPATH#*\ } # remove leading "pid: "
  24. }
  25. get_path_from_pid
  26. # Get the most recently modified "data_2" file: ISO timestamp + absolute path
  27. CACHEFILE=$(find "$GIPATH" -type f -wholename '*/Cache_Data/data_2' -printf "%T+ %p\n" | sort | tail -n 1)
  28. CACHEFILE=${CACHEFILE#*\ } # remove leading timestamp
  29. echo "Found cache file: $CACHEFILE"
  30. echo "===== Matching links:"
  31. strings "$CACHEFILE" | grep -o "https://.*/e20190909gacha-v3/.*" | tail -n1