12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/usr/bin/env bash
- ANCHOR=""
- DATADIR=$(find -maxdepth 1 -type d -name "*_Data")
- if [ -e "GenshinImpact.exe" ]; then
- ANCHOR="GenshinImpact.exe"
- fi
- if [ -e "YuanShen.exe" ]; then
- ANCHOR="YuanShen.exe"
- fi
- if [ -z "$ANCHOR" ]; then
- echo "==> Game executable not found. Wrong directory?"
- exit 1
- fi
- # Restore files that have a backup
- FILE="UnityPlayer.dll"
- CEXE1="$DATADIR/upload_crash.exe"
- CEXE2="$DATADIR/Plugins/crashreport.exe"
- VULKAN1="$DATADIR/Plugins/vulkan-1.dll"
- XLUA="$DATADIR/Plugins/xlua.dll"
- GGM="$DATADIR/globalgamemanagers"
- # macOS has a different version of stat
- if [ $(uname) = "Darwin" ]; then
- STATFLAGS="-f %a"
- else
- STATFLAGS="-c %Y"
- fi
- # Reference timestamp to avoid restoring old/invalid backups
- ref_timestamp=($(stat $STATFLAGS "$ANCHOR"))
- restore_file() {
- # $1 -> File name
- # $2 -> Human readable description
- # $3 -> Overwrite existing file?
- if [ ! -e "$1.bak" ]; then
- echo "--- Nothing to restore for '$1' (no .bak file)"
- return 0
- fi
- if [ -e "$1" -a "$3" != "overwrite" ]; then
- echo "--- $2 is already restored"
- return 0
- fi
- # Do not restore backups from old game versions
- difftime=$(( $ref_timestamp - $(stat $STATFLAGS "$1.bak") ))
- # Strip negative sign is equal to abs()
- if [ ${difftime#-} -gt 3600 ]; then
- echo "--- Backup '$1.bak' is older than the current game version. Ignoring."
- return 1
- fi
- # Restore from backup
- mv -f "$1.bak" "$1"
- echo "--- Restored: $2"
- return 0
- }
- restore_file "$FILE" "Main patch" overwrite
- restore_file "$VULKAN1" "Workaround for Wine bug 45277"
- restore_file "$CEXE1" "Crash reporter 1"
- restore_file "$CEXE2" "Crash reporter 2"
- restore_file "mhypbase.dll" "'Blackbox' DLL"
- restore_file "$XLUA" "Anti-logincrash patch" overwrite
- restore_file "$GGM" "macOS rendering issue patch" overwrite
- echo
- echo "--> Removing all newly added files"
- # The error messages for inexistent files are intended
- rm "launcher.bat"
- rm "mhyprot2_running.reg"
- # dxvk files
- rm *.dxvk-cache
- rm *_d3d9.log
- rm *_d3d11.log
- rm *_dxgi.log
- echo "==> Patch reverted."
- exit 0
|