Darkwater

hl2.sh

May 9th, 2013
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.97 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # figure out the absolute path to the script being run a bit
  4. # non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
  5. # specified directory, then uses $PWD to figure out where that
  6. # directory lives - and all this in a subshell, so we don't affect
  7. # $PWD
  8.  
  9. GAMEROOT=$(cd "${0%/*}" && echo $PWD)
  10.  
  11. #determine platform
  12. UNAME=`uname`
  13. if [ "$UNAME" == "Darwin" ]; then
  14.    # prepend our lib path to LD_LIBRARY_PATH
  15.    export DYLD_LIBRARY_PATH="${GAMEROOT}"/bin:$DYLD_LIBRARY_PATH
  16. elif [ "$UNAME" == "Linux" ]; then
  17.    # prepend our lib path to LD_LIBRARY_PATH
  18.    export LD_LIBRARY_PATH="${GAMEROOT}"/bin:$LD_LIBRARY_PATH
  19. fi
  20.  
  21. if [ -z $GAMEEXE ]; then
  22.     if [ "$UNAME" == "Darwin" ]; then
  23.         GAMEEXE=hl2_osx
  24.     elif [ "$UNAME" == "Linux" ]; then
  25.         GAMEEXE=hl2_linux
  26.     fi
  27. fi
  28.  
  29. ulimit -n 2048
  30.  
  31. # enable nVidia threaded optimizations
  32. export __GL_THREADED_OPTIMIZATIONS=1
  33.  
  34. # and launch the game
  35. cd "$GAMEROOT"
  36.  
  37. # Enable path match if we are running with loose files
  38. if [ -f pathmatch.inf ]; then
  39.     export ENABLE_PATHMATCH=1
  40. fi
  41.  
  42. # Do the following for strace:
  43. #   GAME_DEBUGGER="strace -f -o strace.log"
  44. # Do the following for tcmalloc
  45. #   LD_PRELOAD=../src/thirdparty/gperftools-2.0/.libs/libtcmalloc_debug.so:$LD_PRELOAD
  46.  
  47. STATUS=42
  48. while [ $STATUS -eq 42 ]; do
  49.     if [ "${GAME_DEBUGGER}" == "gdb" ] || [ "${GAME_DEBUGGER}" == "cgdb" ]; then
  50.         ARGSFILE=$(mktemp $USER.hl2.gdb.XXXX)
  51.         echo b main > "$ARGSFILE"
  52.  
  53.         # Set the LD_PRELOAD varname in the debugger, and unset the global version. This makes it so that
  54.         #   gameoverlayrenderer.so and the other preload objects aren't loaded in our debugger's process.
  55.         echo set env LD_PRELOAD=$LD_PRELOAD >> "$ARGSFILE"
  56.         echo show env LD_PRELOAD >> "$ARGSFILE"
  57.         unset LD_PRELOAD
  58.  
  59.         echo run $@ >> "$ARGSFILE"
  60.         echo show args >> "$ARGSFILE"
  61.         ${GAME_DEBUGGER} "${GAMEROOT}"/${GAMEEXE} -x "$ARGSFILE"
  62.         rm "$ARGSFILE"
  63.     else
  64.         ${GAME_DEBUGGER} "${GAMEROOT}"/${GAMEEXE} "$@"
  65.     fi
  66.     STATUS=$?
  67. done
  68. exit $STATUS
Add Comment
Please, Sign In to add comment