add_in_steam.sh 3.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/bin/bash
# GPL-3.0 license
# based on https://github.com/sonic2kk/steamtinkerlaunch/blob/master/steamtinkerlaunch

PROGNAME="PortProton"
# PERSONAL_NAME="$(grep PersonaName "$HOME/.local/share/Steam/config/loginusers.vdf" | awk -F'"' '{print $4}')"

SCVDF="shortcuts.vdf"
SCPATH="$STUIDPATH/config/$SCVDF"

11 12 13 14
if [[ ! -f "$SCPATH" ]] ; then
	echo '0073686f727463757473000808' | xxd -r -p > "$SCPATH"
fi

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
NOSTAPPNAME="$name_desktop"
NOSTEXEPATH="\"${STEAM_SCRIPTS}/${name_desktop}.sh\""
NOSTSTDIR="\"${STEAM_SCRIPTS}\""
# icon
NOSTICONPATH="${PORT_WINE_PATH}/data/img/${name_desktop}.png"
# IsHidden
NOSTHIDE=0
# AllowDesktopConfig
NOSTADC=0
# AllowOverlay
NOSTAO=0
# openvr
NOSTVR=0
NOSTSTLLO=0
# LaunchOptions
NOSTLAOP=

if [ -n "${NOSTEXEPATH}" ]; then
	if [ -z "${NOSTAPPNAME}" ]; then
		NOSTAPPNAME="${QEP##*/}"
	fi

	NOSTAIDRHX="$(printf "%03x%03x%02x\n" $((RANDOM%4096)) $((RANDOM%4096)) $((RANDOM%256)))"
	#NOSTAID="$(hex2dec "$NOSTAIDRHX")"
	NOSTAIDHX="\x$(awk '{$1=$1}1' FPAT='.{2}' OFS="\\\x" <<< "$NOSTAIDRHX")"

	if [ -f "$SCPATH" ]; then
		#writelog "INFO" "${FUNCNAME[0]} - The file '$SCPATH' already exists, creating a backup, then removing the 2 closing backslashes at the end"
		cp "$SCPATH" "${SCPATH//.vdf}_${PROGNAME}_backup.vdf" 2>/dev/null
		truncate -s-2 "$SCPATH"
		OLDSET="$(grep -aPo '\x00[0-9]\x00\x02appid' "$SCPATH" | tail -n1 | tr -dc '0-9')"
		NEWSET=$((OLDSET + 1))
		#writelog "INFO" "${FUNCNAME[0]} - Last set in file has ID '$OLDSET', so continuing with '$OLDSET'"
	else
		#writelog "INFO" "${FUNCNAME[0]} - Creating new $SCPATH"
		printf '\x00%s\x00' "shortcuts" > "$SCPATH"
		NEWSET=0
	fi

	#writelog "INFO" "${FUNCNAME[0]} - Adding new set '$NEWSET'"

	{
	printf '\x00%s\x00' "$NEWSET"
	printf '\x02%s\x00%b' "appid" "$NOSTAIDHX"
	printf '\x01%s\x00%s\x00' "appname" "$NOSTAPPNAME"
	printf '\x01%s\x00%s\x00' "Exe" "$NOSTEXEPATH"
	printf '\x01%s\x00%s\x00' "StartDir" "$NOSTSTDIR"

	if [ -n "$NOSTICONPATH" ]; then
		printf '\x01%s\x00%s\x00' "icon" "$NOSTICONPATH"
	else
		printf '\x01%s\x00\x00' "icon"
	fi

	printf '\x01%s\x00\x00' "ShortcutPath"

	if [ -n "$NOSTLAOP" ]; then
		printf '\x01%s\x00%s\x00' "LaunchOptions" "$NOSTLAOP"
	else
		printf '\x01%s\x00\x00' "LaunchOptions"
	fi
	
	if [ "$NOSTHIDE" -eq 1 ]; then
		printf '\x02%s\x00\x01\x00\x00\x00' "IsHidden"
	else
		printf '\x02%s\x00\x00\x00\x00\x00' "IsHidden"
	fi

	if [ "$NOSTADC" -eq 1 ]; then
		printf '\x02%s\x00\x01\x00\x00\x00' "AllowDesktopConfig"
	else
		printf '\x02%s\x00\x00\x00\x00\x00' "AllowDesktopConfig"
	fi

	if [ "$NOSTAO" -eq 1 ]; then
		printf '\x02%s\x00\x01\x00\x00\x00' "AllowOverlay"
	else
		printf '\x02%s\x00\x00\x00\x00\x00' "AllowOverlay"
	fi

	if [ "$NOSTVR" -eq 1 ]; then
		printf '\x02%s\x00\x01\x00\x00\x00' "openvr"
	else
		printf '\x02%s\x00\x00\x00\x00\x00' "openvr"
	fi

	printf '\x02%s\x00\x00\x00\x00\x00' "Devkit"
	printf '\x01%s\x00\x00' "DevkitGameID"
	printf '\x02%s\x00\x00\x00\x00\x00' "LastPlayTime"
	printf '\x00%s\x00' "tags"
	printf '\x08'
	printf '\x08'

	#file end:
	printf '\x08'
	printf '\x08'
	} >> "$SCPATH"
112 113
	
	# echo '00013000504f727450726f746f6e0008080808' | xxd -r -p >> "$SCPATH"
114
fi