Skip to content

Instantly share code, notes, and snippets.

@Riesi
Last active May 25, 2023 09:16
Show Gist options
  • Save Riesi/3796020a845873673f649b034dafbfcd to your computer and use it in GitHub Desktop.
Save Riesi/3796020a845873673f649b034dafbfcd to your computer and use it in GitHub Desktop.
Script for making apitracing via hooking of Windows apps easy on Linux!
#!/bin/bash
# "THE BEER-WARE LICENSE" (Revision 42):
# Stefan Riesenberger wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.
echo "Make sure to have wget, 7z and wine installed!"
echo "Environment variables that can be set externally to reduce the manual input:"
echo " TRACEALOT_ARCH=[32,64]"
echo " TRACEALOT_API=[ddraw,d3d8,d3d9,d3d11]"
echo " TRACEALOT_GAME_PATH=<path>"
echo " WINEPREFIX=<Unix_path>"
echo ''
unset CONDITION
if [[ -z "${TRACEALOT_ARCH}" ]]; then
read -p " What architecture is your game.exe?`echo $'\n\t1) 32Bit\n\t2) 64Bit\n\tchoice[1-2?]: '`" CONDITION;
if [ "$CONDITION" = "1" ]; then
ARCH=32
elif [ "$CONDITION" = "2" ]; then
ARCH=64
else
echo 'No architecture selected!'
exit 1
fi
else
ARCH="${TRACEALOT_ARCH}"
fi
if [ "$ARCH" = "32" ]; then
APITRACE="apitrace-latest-win32"
elif [ "$ARCH" = "64" ]; then
APITRACE="apitrace-latest-win64"
else
echo 'No architecture selected!'
exit 1
fi
if [ ! -d "$APITRACE" ]; then
wget https://people.freedesktop.org/~jrfonseca/apitrace/$APITRACE.7z -nc
7z x $APITRACE
fi;
if [[ -z "${TRACEALOT_API}" ]]; then
read -p "What graphics API is your game.exe using?`echo $'\n\t1) d3d11\n\t2) d3d9\n\t3) d3d8\n\t4) ddraw\n\tchoice[1-4?]: '`" CONDITION;
if [ "$CONDITION" = "1" ]; then
API="d3d11"
elif [ "$CONDITION" = "2" ]; then
API="d3d9"
elif [ "$CONDITION" = "3" ]; then
API="d3d8"
elif [ "$CONDITION" = "4" ]; then
API="ddraw"
else
echo 'No API selected!'
exit 1
fi
else
API="${TRACEALOT_API}"
fi
if [[ -z "${WINEPREFIX}" ]]; then
read -p "Wine prefix path: " PREFIX;
if [ ! -d "$PREFIX" ]; then
echo 'Wine prefix doesnt exist!'
exit 1
fi
else
PREFIX="${WINEPREFIX}"
fi
if [[ -z "${TRACEALOT_GAME_PATH}" ]]; then
read -p 'Absolute game.exe path (i.e.: "C://Program Files (x86)/../game.exe" or "/home/user/../game.exe"): ' GAME_PATH;
else
GAME_PATH="${TRACEALOT_GAME_PATH}"
fi
export WINEDEBUG=+loaddll
export WINEPREFIX="$PREFIX"
export WINEDLLOVERRIDES="ddraw=n,b;d3d8=n,b;d3d9=n,b;d3d11=n,b;dxgi=n,b"
wine ./$APITRACE/bin/apitrace.exe trace -a $API $GAME_PATH
echo '\n\n\n-----------------------------------------\n\n'
OUTPUT="Apitrace file should be located in '${WINEPREFIX}/drive_c/users/<your_user>/Desktop/'."
echo $OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment