Skip to content

Instantly share code, notes, and snippets.

@reneklacan
Last active October 28, 2024 02:03
Show Gist options
  • Save reneklacan/7825b82723bf0534cbd2eae014e121ca to your computer and use it in GitHub Desktop.
Save reneklacan/7825b82723bf0534cbd2eae014e121ca to your computer and use it in GitHub Desktop.
Script to fix AOE4 desync issues
#!/bin/bash
set -ex
STEAM_DIR=/home/$USER/.steam/steam/steamapps
AOE4_DIR=$STEAM_DIR/compatdata/1466860
AOE4_WIN_DIR=$AOE4_DIR/pfx/drive_c/windows
AOE4_WIN_SYS32_DIR=$AOE4_WIN_DIR/system32
AOE4_WIN_SYS64_DIR=$AOE4_WIN_DIR/syswow64
function check_deps() {
which wget || (echo "wget is required (on Ubuntu you can install it with 'sudo apt-get install wget')" && exit 1)
which cabextract || (echo "cabextract is required (on Ubuntu you can install it with 'sudo apt-get install cabextract')" && exit 1)
}
function cleanup() {
local arch=$1
rm -f vc_redist.$arch.exe
rm -rf 0 a{0..11} u{0..31}
}
function backup() {
local timestamp=$(date +%s)
mv ucrtbase.dll ucrtbase.dll.bak-$timestamp
mv concrt140.dll concrt140.dll.bak-$timestamp
mv msvcp140.dll msvcp140.dll.bak-$timestamp
mv vcamp140.dll vcamp140.dll.bak-$timestamp
mv vccorlib140.dll vccorlib140.dll.bak-$timestamp
mv vcomp140.dll vcomp140.dll.bak-$timestamp
mv vcruntime140.dll vcruntime140.dll.bak-$timestamp
}
function download_and_replace() {
local arch=$1
wget https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.$arch.exe
cabextract vc_redist.$arch.exe
cabextract a10
}
function replace_dlls() {
local dir=$1
local arch=$2
cd $dir
backup
cleanup $arch
download_and_replace $arch
cleanup $arch
}
check_deps
replace_dlls $AOE4_WIN_SYS32_DIR x64
replace_dlls $AOE4_WIN_SYS64_DIR x86
@oooovaloide
Copy link

Hello!

Thank you very much for your reply.

Do you mean that I should delete the last three lines?

If I should not delete them, what should I modify in the script?

Thank you in advance.

@jm-chase
Copy link

I hate to be "that guy" but can someone explain how to do this like I'm a five year old. I'm a knuckle dragging idiot when it comes to stuff like this and I just want to play aoe 4 on my steam deck without de-syncing online. Any help would be great, thanks.

@mfilipe
Copy link

mfilipe commented Oct 31, 2022

@jm-chase I don't have a Steam Deck but the commands are below:

  1. install aoe4
  2. download aoe4-mp-fix.sh
  3. chmod +x aoe4-mp-fix.sh
  4. ./aoe4-mp-fix.sh

@Ma5onic
Copy link

Ma5onic commented Oct 31, 2022

@jm-chase

I hate to be "that guy" but can someone explain how to do this like I'm a five year old. I'm a knuckle dragging idiot when it comes to stuff like this and I just want to play aoe 4 on my steam deck without de-syncing online. Any help would be great, thanks.

The code does the following, explained in English:

  1. Check if you have wget and cabextract installed
  2. Download the necessary files (vc_redist.x64.exe and vc_redist.x86.exe)
  3. Extract these files and extract the files inside them
  4. Copy the extracted files to the correct directories

Note: The steam deck is based on arch linux and does not use apt or apt-get to manage packages/applications; it uses pacman instead.
By default, you can't use pacman on the steam deck because you are restricted from writing to specific directories.

Detailed Explanation

This script is composed of functions, which are defined and named based on their purpose. Namely, check_deps, cleanup, backup, download_and_replace & replace_dlls. Once a function is defined, it can then be used in another function or used/called on it's own... not before

set -ex causes the script to exit if an error is detected (of a command exits with status code 1 instead of 0)

Variables

Lines 5-9 are variables created from your existing environment/system variables, which indicate the path for your steam installation, game directory, and wine/proton prefix for your emulated windows C: drive. (capitalised words with a $ before them are variables that already exist/were previously defined):
1. STEAM_DIR is the directory where steam is installed. I'm using Ubuntu so I'm using a default directory.
2. AOE4_DIR is the directory where the game files are stored.
3. AOE4_WIN_DIR is the directory where the game files are stored in Wine. This is the directory where we will be replacing the DLLs.
4. AOE4_WIN_SYS32_DIR is the directory where the 64-bit DLLs are stored.
5. AOE4_WIN_SYS64_DIR is the directory where the 32-bit DLLs are stored.

Functions

  • check_deps is the function that checks if the required dependencies are installed.
    • wget (to get stuff from the web) and cabextract (to extract all files from cabinet or executable cabinet) & returns the full path of where they are located (thanks to which command).
    • If either doesn't work, it will print some text to the user saying which is missing and the ubuntu/debian command to install it & exit with a value of 1 which means that it failed, telling set -ex to exit the script.
  • cleanup is the function that removes the downloaded files and extracted files.
    • The function takes one argument, the architecture of the system (x86 or x64).
    • The function deletes the vc_redist.$arch.exe file and the a0, a1, ..., a11, u0, u1, ..., u31 directories.
  • backup is the function that backs up the old DLLs
    • The function sets a local variable called timestamp to the current date and time as an integer in seconds since the epoch.
    • The function then moves the DLL files to a backup copy with the timestamp appended to the filename.
  • download_and_replace is the function that downloads the required DLLs, extracts them and replaces the old DLLs
    • downloads the exe file from Microsoft website
    • extracts the exe file
    • extracts the cab file that was inside the exe file
  • replace_dlls is the function that calls backup, cleanup and download_and_replace
    • The function replace_dlls gets two parameters: the directory where the DLLs are located and the architecture (32 or 64)
    • The function backup is a function that is defined in the script that is called. It's used to backup the original DLLs
    • The function cleanup is a function that is defined in the script that is called. It's used to remove the DLLs that are downloaded
    • The function download_and_replace is a function that is defined in the script that is called. It's used to download the DLLs and replace the original DLLs

Up till this point, none of the functions have actually been called/executed, they have only been defined.
Lines 55 to 57 are the lines that determine the order that the functions will be executed.

  • check_deps is called
  • replace_dlls is called for both 64-bit and 32-bit DLLs and uses the previously defined functions to: backup, cleanup,download_and_replace & cleanup again.

Link to exe files
64-bit:
https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe

32-bit:
https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe

@jm-chase
Copy link

Thank you @Ma5onic and @mfilipe for helping a smooth brain like me, its very kind. I will work through the above instructions and hopefully learn something along the way. Thanks!

@kaidelorenzo
Copy link

kaidelorenzo commented Nov 5, 2022

Thank you for writing this script and sharing it. I do have one question about it. On the last two lines, do you intentionally swap the archs and the dirs used? Didn’t make sense to me, so I wanted to change it. Figured I’d check first.

replace_dlls $AOE4_WIN_SYS32_DIR x64 replace_dlls $AOE4_WIN_SYS64_DIR x86

Sys32 is actually for 64bit and sys64 is for 32bit. It's super confusing but you can look it up online and read more about it.

Copy link

ghost commented Nov 8, 2022

https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.$arch.exe, this link that you are using with wget is empty, can you just name the file?

@broaken13
Copy link

@Farzam003 Ma5onic posted them above at the end of his detailed explanation

@FoxMulder24
Copy link

Hey guys! I'm pulling my hair out over here. Total beginner for Linux, deck, and scripts. I've read all the comments, they've been super helpful. In my early attempts, I think I screwed something up and now the game crashes when the multiplayer game is just about to begin. So yeah, I made it worse.

Any help would be appreciated. A few questions I have:

How can I restore things back to normal so it doesn't crash immediately?

What Proton version should I be running it on?

Do I need to change anything about the "STEAM_DIR=" path?

Thanks in advance, and thanks for making the workaround.

@ArikRahman
Copy link

One of the few games not working on Garuda Linux

@Yohomie99
Copy link

Yohomie99 commented Feb 22, 2023

As I'm reading this, I became involved with trying to fix this issue for a friend who has a Steam Deck so I can play multiplayer with him so I want ask for some answers on the following questions:

  1. Does this method and script still work in the latest update?

  2. Is there anything else I should do further from those 4 steps before booting the game?

  3. Does the script run by itself with those applications installed and those redist files downloaded when booting the game because you didn't mention running the script in those steps?

My friend was following the steps on the github page with the script but it was too confusing, gave him a headache and didn't get it to work. Even I was trying to help over a discord call but those script steps were confusing as well and hoping your steps are more clearer and simplest explanation. I'm not an expert on Steamdeck navigation because I haven't really fiddled around with it in my hands but I am experienced with using a PC and navigating on that.

Please help! Thanks!

@broaken13
Copy link

@Yohomie99 I'm not playing this on my steam deck, so I don't know if there happens to be any thing different but, my intuition says it should be the same.

  1. I ran this script back in season 2, and have not needed to run it again since. I was able to play some games a couple days ago.
  2. Not that I'm aware of
  3. I'm not sure what you mean here. Scripts don't execute themselves. It sounds like you guys are trying to execute these lines one by one by yourselves? You want to download this file, or copy and paste it into a file, and then execute the entire script at once.

@broaken13
Copy link

@FoxMulder24 sorry to see that you haven't had a response. Hopefully you were able to get it to work. You can always do a 'reset' by uninstalling and reinstalling the game from steam.

@FoxMulder24
Copy link

@broaken13 I appreciate the reply! I did end up finally stumbling my way into getting it to work. I learned a ton about Linux and was reminded of the old Edisom quote: "I have not failed. I've just found 10,000 ways that [the AoE4 multiplayer fix] won't work." Oddly specific, but accurate!

@Yohomie99 , I can confirm at least that once I got everything right, the script ran and I never had to run it again.

@Yohomie99
Copy link

Yohomie99 commented Feb 22, 2023

@Yohomie99 I'm not playing this on my steam deck, so I don't know if there happens to be any thing different but, my intuition says it should be the same.

  1. I ran this script back in season 2, and have not needed to run it again since. I was able to play some games a couple days ago.
  2. Not that I'm aware of
  3. I'm not sure what you mean here. Scripts don't execute themselves. It sounds like you guys are trying to execute these lines one by one by yourselves? You want to download this file, or copy and paste it into a file, and then execute the entire script at once.

Yes so this script "aoe4-mp-fix-sh", what do I do with it when I've downloaded that because those 4 steps didn't mention it?

But the previous comment mentioned downloading the script in Step 2 but I didn't understand what step 3 and 4 means:

@jm-chase I don't have a Steam Deck but the commands are below:

  1. install aoe4
  2. download aoe4-mp-fix.sh
  3. chmod +x aoe4-mp-fix.sh
  4. ./aoe4-mp-fix.sh

@Yohomie99
Copy link

This is why I wondered if there are steps or I just simply download the script itself and then follow @Ma5onic 4 steps.

@FoxMulder24
Copy link

@Yohomie99 I posted a how to thread over on Reddit, trying to break it down into easier steps. It is not perfect, but give it a look and see if it answers any of your questions. https://www.reddit.com/r/SteamDeck/comments/yw1u2m/help_wanted_desperately_aoe_4_multiplayer/izu52o4?utm_medium=android_app&utm_source=share&context=3

@Yohomie99
Copy link

@Yohomie99 I posted a how to thread over on Reddit, trying to break it down into easier steps. It is not perfect, but give it a look and see if it answers any of your questions. https://www.reddit.com/r/SteamDeck/comments/yw1u2m/help_wanted_desperately_aoe_4_multiplayer/izu52o4?utm_medium=android_app&utm_source=share&context=3

Thank you! I'll give it a good read and see how we go when we follow those steps.

@broaken13
Copy link

@Yohomie99 Those are commands to enter in a terminal (I believe the steam deck uses one called konsole). You'll need to navigate the terminal to the folder where the script is and run them. So, assuming the script is downloaded to the Downloads folder, you'll open a terminal and type:

  1. cd Downloads or wherever the script is to navigate it's folder (cd means change directory)
  2. chmod +x aoe4-mp-fix.sh This will allow you to execute the script
  3. ./aoe4-mp-fix.sh This executes the script

However, I'm looking at this now with my steam deck, and this looks like it might be quite a bit more of a headache than I initially thought. Looks like it might be necessary to enable developer mode in order to download the dependencies and run the script.

@kaidelorenzo
Copy link

You don't technically need dev mode to run this on the steamdeck. You can compile cabextract from source in a flatpak runtime. That's why I did just FYI.

@GolDNenex
Copy link

GolDNenex commented Feb 23, 2023

Distrobox is great on the steam deck.

In the script edit:

$USER

in this line on the top:

STEAM_DIR=/home/$USER/.steam/steam/steamapps

You should have something like that:

STEAM_DIR=/home/goldnenex/.steam/steam/steamapps

install Distrobox and run the script from it.

@ballerguitarer
Copy link

ballerguitarer commented Aug 16, 2023

Linux noob here (literally, day #3 of Kubuntu here). I ran the code with the set -ex to set -x tweak, and now AOE doesn't even open. Tried uninstalling and reinstalling, but no change, and now none of my games open. Anyone else run into this issue and solve it?

@BloodyIron
Copy link

FYI this script does not account for the following scenarios:

  1. If your games are stored on another drive, as in outside your home folder. I myself have two additional storage drives mounted elsewhere, since well, games are big and need to put them different places.
  2. Once adapted to other locations, this script is also intolerant for spaces in parent folders where a Steam Library could be housed at. Like "/mnt/ssd-1tb/Steam Library" kind of deal.

I'm not sure what the best solution to #1 is, however for #2, double quotes are needed to surround the variables in the early parts declaring paths and sub-paths, and then also for the cd $dir step, should be cd "$dir", and the replace_dlls step needs double quotes around both 32 and 64 bit dirs.

The double quotes may be needed for arch too, but I could be wrong there.

I had to manually adapt the script for my situation and hopefully this helps someone else in the future.

@BloodyIron
Copy link

Either way though, thanks for this script! \o/

@lc-nyovchev
Copy link

For the people who have steam installed by snap, change:

STEAM_DIR=/home/$USER/.steam/steam/steamapps

to:

STEAM_DIR=/home/$USER/snap/steam/common/.local/share/Steam/steamapps

@Principle
Copy link

After this script with GE Proton still had the sync issue, it let me get an hour into the match before that tho. I was able to play through shorter matches no problem.

@CrackerJackMack
Copy link

I've modified this to be a generic version of this to work with most other games by passing the APP ID. Also collected some additional examples for users so they don't have to edit the file directly (they still can though)

https://gist.github.com/CrackerJackMack/374f49b4ad98e14c0a7e8bbcac668d63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment