1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Stronghold 2 AI fix

Discussion in 'Games' started by Daerandin, Jul 17, 2022.

  1. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,084
    Likes Received:
    228
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    I've been playing a lot of Stronghold games, mostly the first one, and Stronghold 2 and Stronghold Legends. I really like all the life going on in the castle in Stronghold 2, and how you have complete control over your estates. However, Stronghold 2 does not have the option to play cooperatively against AI in multiplayer.

    So I fixed it. I created a tool that enables AI in multiplayer games, so it can now be played cooperatively. For now there is no makefile, so you need to compile it manually, but the readme contains an example for that.

    https://gitlab.com/Daerandin/sh2_mp_ai_enabler

    I intend to set up a proper download page for this at some point, where people can download Windows binaries, as I realize most people on Windows will not want to compile stuff themselves.

    And yes, this can be compiled both on Windows and Linux.

    It was extremely interesting to make this. I knew very little about how process memory actually works just a few days ago. Well, I thought I knew, but making this forced me to learn a LOT.

    For now you need to manually input the game PID, but I might make it automatically find the PID so you just launch my program, and then launch Stronghold 2.
  2. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,084
    Likes Received:
    228
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    I now have a dedicated download page for precompiled Windows binaries. This might not be very interesting for us Linux users, but might be useful if you know someone on Windows who plays Stronghold 2.

    https://www.questforgaming.com/stronghold2/

    It's super easy to compile on Linux, and I'll work on getting a makefile at some point, for even easier compilation.

    Seems like a lot of people appreciated this over at the Stronghold 2 Steam forums, so I'm happy I was able to help out with a requested feature.
  3. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,084
    Likes Received:
    228
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    Recently updated this so it will now find the game PID automatically. The Linux version is easier to compile now, with the added makefile. You just need to go into the 'src' directory and type 'make'.

    I also created an AUR package for Arch Linux: https://aur.archlinux.org/packages/sh2_mp_ai_enabler

    I have had thoughts about other methods for how this tool is working, but as it is now, it does not require any elevated privileges. There was another tool for earlier game versions that required elevated privileges, and I kind of prefer being able to run this as a regular user.
  4. Gizmo

    Gizmo Chief Site Administrator Staff Member

    Joined:
    Dec 6, 2012
    Messages:
    2,112
    Likes Received:
    133
    Trophy Points:
    63
    Location:
    Webb City, Missouri
    Home page:
    Thanks for sharing, Daerandin. This looks rather cool!
    Daerandin likes this.
  5. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,084
    Likes Received:
    228
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    My tool has been updated a while back. The previous versions were working by constantly overwriting a single byte in memory while the game is running. This byte controls if you can see the button that lets you add AI opponents.

    The new updated version works a little differently. Instead of overwriting this single byte constantly, I managed to identify the specific instruction that was setting this byte to '0' when hosting a multiplayer game. The instruction is exactly 7 bytes long, so my program now overwrites these 7 bytes with 7 NOP codes (0x90). This means my tool does not need to keep running to enforce the changes, it runs once and then exits. The changes will remain in game memory. As with previous versions of my tool, game files are not modified.

Share This Page