# Generate random signed 32bit integer which can be converted into hex, using the first argument (AppName and Exe fields) as seed (in an attempt to reduce the chances of the same AppID being generated twice)
function generateShortcutVDFAppId{
seed="$(echo-n"$1" | md5sum | cut-c1-8)"
echo"-$((16#${seed} % 1000000000 ))"
generateShortcutVDFAppId(){
seed="$(echo-n"$1" | md5sum | cut-c1-8)"
echo"-$((16#${seed} % 1000000000))"
}
function dec2hex{
dec2hex(){
printf'%x\n'"$1"|cut-c 9-# cut removes the 'ffffffff' from the string (represents the sign) and starts from the 9th character
}
# Takes big-endian ("normal") hexidecimal number and converts to little-endian
function bigToLittleEndian{
bigToLittleEndian(){
echo-n "$1"|tac-rs .. |tr-d '\n'
}
# Takes an signed 32bit integer and converts it to a 4byte little-endian hex number
function generateShortcutVDFHexAppId{
bigToLittleEndian "$( dec2hex "$1")"
generateShortcutVDFHexAppId(){
bigToLittleEndian "$(dec2hex "$1")"
}
# Takes an signed 32bit integer and converts it to an unsigned 32bit integer
function generateShortcutGridAppId{
echo$(($1&0xFFFFFFFF ))
generateShortcutGridAppId(){
echo$(($1&0xFFFFFFFF))
}
## ----------
### END MAGIC APPID FUNCTIONS
NOSTAIDVDF="$(generateShortcutVDFAppId "${NOSTAPPNAME}${NOSTEXEPATH}")"# signed integer AppID, stored in the VDF as hexidecimal - ex: -598031679
NOSTAIDVDFHEX="$(generateShortcutVDFHexAppId "$NOSTAIDVDF")"# 4byte little-endian hexidecimal of above 32bit signed integer, which we write out to the binary VDF - ex: c1c25adc
NOSTAIDVDFHEXFMT="\x$(awk'{$1=$1}1'FPAT='.{2}'OFS="\\\x"<<<"$NOSTAIDVDFHEX")"# binary-formatted string hex of the above which we actually write out - ex: \xc1\xc2\x5a\xdc
NOSTAIDGRID="$(generateShortcutGridAppId "$NOSTAIDVDF")"# unsigned 32bit ingeger version of "$NOSTAIDVDF", which is used as the AppID for Steam artwork ("grids"), as well as for our shortcuts
getSteamShortcutsVdfFileHex |grep-oP "(${SHORTCUTVDFFILESTARTHEXPAT}|${SHORTCUTVDFENTRYBEGINHEXPAT})\K.*?(?=${SHORTCUTSVDFENTRYENDHEXPAT})"# Get entire shortcuts.vdf as hex, then grep each entry using the begin and end patterns for each block
}
getSteamShortcutEntryHex(){
SHORTCUTSVDFINPUTHEX="$1"# The hex block representing the shortcut
SHORTCUTSVDFMATCHPATTERN="$2"# The pattern to match against in the block
downloadImageSteamGridDB "grids""${NOSTAIDGRID}.jpg""mimes=image/jpeg""dimensions=460x215,920x430"|| downloadImageSteam "header.jpg""${NOSTAIDGRID}.jpg"||echo"Failed to load header.jpg"
downloadImageSteamGridDB "grids""${NOSTAIDGRID}p.jpg""mimes=image/jpeg""dimensions=600x900,660x930"|| downloadImageSteam "library_600x900_2x.jpg""${NOSTAIDGRID}p.jpg"||echo"Failed to load library_600x900_2x.jpg"
downloadImageSteamGridDB "heroes""${NOSTAIDGRID}_hero.jpg""mimes=image/jpeg"|| downloadImageSteam "library_hero.jpg""${NOSTAIDGRID}_hero.jpg"||echo"Failed to load library_hero.jpg"
downloadImageSteamGridDB "logos""${NOSTAIDGRID}_logo.png""mimes=image/png"|| downloadImageSteam "logo.png""${NOSTAIDGRID}_logo.png"||echo"Failed to load logo.png"
else
echo"Game is not found"
fi
}
addNonSteamGame(){
if[[-n "${SCPATH}"]];then
NOSTAIDGRID=$(getAppId "${NOSTSHPATH}")
if[[-z "${NOSTAIDGRID}"]];then
NOSTAIDVDF="$(generateShortcutVDFAppId "${NOSTAPPNAME}${NOSTEXEPATH}")"# signed integer AppID, stored in the VDF as hexidecimal - ex: -598031679
NOSTAIDVDFHEX="$(generateShortcutVDFHexAppId "$NOSTAIDVDF")"# 4byte little-endian hexidecimal of above 32bit signed integer, which we write out to the binary VDF - ex: c1c25adc
NOSTAIDVDFHEXFMT="\x$(awk'{$1=$1}1'FPAT='.{2}'OFS="\\\x"<<<"$NOSTAIDVDFHEX")"# binary-formatted string hex of the above which we actually write out - ex: \xc1\xc2\x5a\xdc
NOSTAIDGRID="$(generateShortcutGridAppId "$NOSTAIDVDF")"# unsigned 32bit ingeger version of "$NOSTAIDVDF", which is used as the AppID for Steam artwork ("grids"), as well as for our shortcuts
create_new_dir "${STEAM_SCRIPTS}"
echo"#!/usr/bin/env bash">"${NOSTSHPATH}"
echo"export START_FROM_STEAM=1">>"${NOSTSHPATH}"
echo"export LD_PRELOAD=">>"${NOSTSHPATH}"
if check_flatpak;then
echo"flatpak run ru.linux_gaming.PortProton \"${portwine_exe}\" ">>"${NOSTSHPATH}"
SHORTCUTVDFFILESTARTHEXPAT="0073686f7274637574730000300002"# Bytes for beginning of the shortcuts.vdf file
SHORTCUTVDFENTRYBEGINHEXPAT="00080800.*?0002"# Pattern for beginning of shortcut entry in shortcuts.vdf -- Beginning of file has a different pattern, but every other pattern begins like this
SHORTCUTSVDFENTRYENDHEXPAT="000808"# Pattern for how shortcuts.vdf blocks end
SHORTCUTVDFAPPIDHEXPAT="617070696400"# 'appid'
SHORTCUTVDFNAMEHEXPAT="(014170704e616d6500|6170706e616d6500)"# 'AppName' and 'appname'
SHORTCUTVDFENDPAT="0001"# Generic end pattern for each shortcut.vdf column
SHORTCUTVDFEXEHEXPAT="000145786500"# 'Exe' ('exe' is 6578650a if we ever need it)