Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nix flake #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
result
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ for example, if you cloned the repo to your $HOME directory,

if %steam_location% is not set, the script will default to /home/$USER/.local/share

## Usage

```
Usage: ./run.sh [OPTIONS]...
Small script containing Multiplayer fix for AOE2 Definitive Edition.

Options:
-h, --help print this text and exit
-l, --steam-location <PATH> path to your Steam installation
-f, --force forcefully repatch AOE2DE
```

## Dependencies
- cabextract
- wget
Expand Down
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
description = "Multiplayer fix for AoE 2: DE";

inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-23.11;

outputs = { self, nixpkgs, ... }:
{
defaultPackage.x86_64-linux =
with import nixpkgs { system = "x86_64-linux"; };
stdenv.mkDerivation {
name = "proton_aoe2de_mpfix";
src = self;
installPhase = ''
patch -p1 < nixos.patch
mkdir -p $out/bin
mv run.sh $out/bin/run.sh
'';
};
};
}
13 changes: 13 additions & 0 deletions nixos.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/run.sh b/run.sh
index 7fb44cb..b0f6009 100755
--- a/run.sh
+++ b/run.sh
@@ -1,4 +1,7 @@
-#!/bin/bash
+#!/usr/bin/env nix-shell
+#! nix-shell -i bash
+#! nix-shell -p bash jq cabextract wget
+
set -e # Fail fast

# Check if jq is installed, then fetch the App ID if it is
127 changes: 82 additions & 45 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,55 +1,92 @@
#!/bin/bash
set -e # Fail fast

# Check if jq is installed, then fetch the App ID if it is
if command -v jq &> /dev/null
then
APPID=$(wget -qO- https://api.steampowered.com/ISteamApps/GetAppList/v2/ | jq '.applist.apps[] | select(.name=="Age of Empires II: Definitive Edition")' | jq ".appid")
else
APPID=813780 # The most recent App ID when this was written
fi

# Arguments
USAGE=0
STEAM_LOCATION="/home/$USER/.steam/steam"
FORCE=0
VCREDIST_LOCATION=""

# check if arguments are not empty
if [ ! $# -eq 0 ]; then
# set STEAM_LOCATION to the provided argument
STEAM_LOCATION=$1
fi
usage() {
cat <<- _end_of_usage
Usage: $0 [OPTIONS]...
Small script containing Multiplayer fix for AOE2 Definitive Edition.

libraries=$(grep 'path' $STEAM_LOCATION/steamapps/libraryfolders.vdf | sed -re 's/^(\s)+"path"(\s)+"(.*)"$/\3/g')
Options:
-h, --help print this text and exit
-l, --steam-location <PATH> path to your Steam installation
-f, --force forcefully repatch AOE2DE
_end_of_usage

echo "Found steam library locations:"
for library in $libraries; do
echo " * $library"
done
exit 0
}

for library in $libraries; do
SYSTEM32_LOCATION="$library/steamapps/compatdata/$APPID/pfx/drive_c/windows/system32"
get_args() {
while [ $# -ne 0 ]
do
case "$1" in
"-h"|"--help") USAGE=1;;
"-l"|"--steam-location") STEAM_LOCATION=$2; shift;;
"-f"|"--force") FORCE=1; shift;;
*) echo "Unkown argument $1! See --help." 1>&2;;
esac
shift
done
}

if [ -d "$SYSTEM32_LOCATION" ]; then
echo "Found app in: $SYSTEM32_LOCATION"
break
fi
done;
patch() {
# Check if jq is installed, then fetch the App ID if it is
if command -v jq &> /dev/null
then
APPID=$(wget -qO- https://api.steampowered.com/ISteamApps/GetAppList/v2/ | jq '.applist.apps[] | select(.name=="Age of Empires II: Definitive Edition")' | jq ".appid")
else
APPID=813780 # The most recent App ID when this was written
fi

# Check if the dll already exists and is not a symlink
if [ -f "$SYSTEM32_LOCATION/ucrtbase.dll" ] && [ ! -L "$SYSTEM32_LOCATION/ucrtbase.dll" ]; then
echo "ucrtbase.dll is already installed"
exit 0
fi

rm -f $SYSTEM32_LOCATION/ucrtbase.dll # There might be a simlink to the "default" ucrtbase.dll, it needs to be deleted

TEMP_FOLDER=$(mktemp --directory)
cd $TEMP_FOLDER
echo "Fetching vc_redist.x64.exe"
wget https://download.microsoft.com/download/0/6/4/064F84EA-D1DB-4EAA-9A5C-CC2F0FF6A638/vc_redist.x64.exe
cabextract vc_redist.x64.exe --filter a10
cabextract a10 --filter ucrtbase.dll
cp ucrtbase.dll $SYSTEM32_LOCATION
echo "Copied ucrtbase.dll"
rm -f vc_redist.x64.exe a10 ucrtbase.dll
rmdir $TEMP_FOLDER

exit 0
libraries=$(grep 'path' $STEAM_LOCATION/steamapps/libraryfolders.vdf | sed -re 's/^(\s)+"path"(\s)+"(.*)"$/\3/g')

echo "Found steam library locations:"
for library in $libraries; do
echo " * $library"
done

for library in $libraries; do
SYSTEM32_LOCATION="$library/steamapps/compatdata/$APPID/pfx/drive_c/windows/system32"

if [ -d "$SYSTEM32_LOCATION" ]; then
echo "Found app in: $SYSTEM32_LOCATION"
VCREDIST_LOCATION="$library/steamapps/common/AoE2DE/vc_redist.x64.exe"
break
fi
done;

# Check if the dll already exists and is not a symlink
if [ -f "$SYSTEM32_LOCATION/ucrtbase.dll" ] && [ ! -L "$SYSTEM32_LOCATION/ucrtbase.dll" ]; then
echo "ucrtbase.dll is already installed"
[ $FORCE -eq 0 ] && exit 0
echo "Forcing patch anyway..."
fi

rm -f $SYSTEM32_LOCATION/ucrtbase.dll # There might be a simlink to the "default" ucrtbase.dll, it needs to be deleted

TEMP_FOLDER=$(mktemp --directory)
cd $TEMP_FOLDER

# Download vc_redist only if we don't already have it
if [ -n "$VCREDIST_LOCATION" ] && [ -f "$VCREDIST_LOCATION" ]; then
cp "$VCREDIST_LOCATION" .
else
echo "Fetching vc_redist.x64.exe"
wget https://download.microsoft.com/download/0/6/4/064F84EA-D1DB-4EAA-9A5C-CC2F0FF6A638/vc_redist.x64.exe
fi
cabextract vc_redist.x64.exe --filter a10
cabextract a10 --filter ucrtbase.dll
cp ucrtbase.dll $SYSTEM32_LOCATION
echo "Copied ucrtbase.dll"
rm -f vc_redist.x64.exe a10 ucrtbase.dll
rmdir $TEMP_FOLDER
}

get_args "$@"
[ $USAGE -eq 1 ] && usage
patch