Skip to content

Commit

Permalink
mangohud bin: add an array of items to disable LD_PRELOAD, added cs2.…
Browse files Browse the repository at this point in the history
…sh to DISABLE_LD_PRELOAD
  • Loading branch information
gort818 committed Oct 20, 2023
1 parent 84daa06 commit 672d648
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions bin/mangohud.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/bin/sh

if [ "$#" -eq 0 ]; then
programname=`basename "$0"`
echo "ERROR: No program supplied"
echo
echo "Usage: $programname <program>"
exit 1
programname=$(basename "$0")
echo "ERROR: No program supplied"
echo
echo "Usage: $programname <program>"
exit 1
fi

# Names of executables that we do not want LD_PRELOAD set for
DISABLE_LD_PRELOAD=("cs2.sh")

# Combine all command line arguments into a single string
command_line="$0 $@"
disable_preload=false

MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_opengl.so"

if [ "$1" = "--dlsym" ]; then
Expand All @@ -18,20 +25,31 @@ elif [ "$MANGOHUD_DLSYM" = "1" ]; then
fi

if [ "$1" = "--version" ]; then
echo @version@
exit 0
echo @version@
exit 0
fi

# Make sure we don't append mangohud lib multiple times
# otherwise this could cause issues with steam runtime
case ":${LD_PRELOAD-}:" in
(*:$MANGOHUD_LIB_NAME:*)
;;
(*)
# Preload using the plain filenames of the libs, the dynamic linker will
# figure out whether the 32 or 64 bit version should be used
LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}${MANGOHUD_LIB_NAME}"
esac
# Check if any of the names in DISABLE_LD_PRELOAD are in the command line
for name in "${DISABLE_LD_PRELOAD[@]}"; do
if echo "$command_line" | grep -q "$name"; then
disable_preload=true
break
fi
done

if [ "$disable_preload" = true ]; then
exec env MANGOHUD=1 "$@"
else
# Make sure we don't append mangohud lib multiple times
# otherwise, this could cause issues with the steam runtime
case ":${LD_PRELOAD-}:" in
(*:$MANGOHUD_LIB_NAME:*)
;;
(*)
# Preload using the plain filenames of the libs, the dynamic linker will
# figure out whether the 32 or 64 bit version should be used
LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}${MANGOHUD_LIB_NAME}"
esac

exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" "$@"
exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" "$@"
fi

0 comments on commit 672d648

Please sign in to comment.