Stronghold Legends Steam Edition hacking

Discussion in 'Hacking' started by Daerandin, Dec 4, 2023.

  1. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,143
    Likes Received:
    248
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    I have the Steam Edition of this game, and I have managed to get all in-game awards and Steam achievements in the normal way. However, this was an extremely boring process as some had annoying requirements such as spending total 10 days in-game. So that got me interested in figuring out how to circumvent the requirements.

    I started by looking at the files associated to your in-game profile. There are two files, config.dat and stats.dat, both are binary data. Both are zlib compressed, and once you uncompress them you can inspect them with a hex editor. Both files consist of 32-bit values, all in little-endian byte ordering. With the help of my 100% complete in-game profile, and a new profile, I managed to figure out pretty all the useful data values in those files. In short, config.dat has data for which maps you have unlocked/completed in the campaigns/trails. The stats.dat file consists a lot of useless statistics, as well as which in-game awards you have unlocked.

    Steam Achievements are given when you earn an in-game award in this game. So I can unlock all in-game awards by editing the stats.dat file, but this will not yield Steam Achievements. But I managed to figure that out too. I ran the game, and used the edb debugger to attach to the game process. Once I managed to identify the specific memory address for awards, I could put a breakpoint on such an address when the game modified it. With this I managed to identify all parts of the game code that give you awards after a match.

    This part was quite interesting, the game first checks if your profile already has an award. If not, then it moves on to perform one or more checks to see if you qualify for the award. For a while I was considering modifying the actual checks, but that would require way too much work. The easier solution was just to remove the conditional jump that happens if you don't qualify. Since I already have all achievements I couldn't test myself, but I made a small program to test one specific achievement, and it worked both two others who tested it.

    If anyone is interested in the full details of my investigation, just let me know.

    In any case, I am going to create programs (for both windows and Linux) to let you unlock all campaign/trails maps and fill the in-game awards-cabinet. I will additionally create a separate program to modify game code while it is running so that you can qualify for awards, which will also result in getting Steam achievements.
  2. booman

    booman Grand High Exalted Mystic Emperor of Linux Gaming Staff Member

    Joined:
    Dec 17, 2012
    Messages:
    8,312
    Likes Received:
    619
    Trophy Points:
    113
    Location:
    Linux, Virginia
    Home page:
    Wow, hacking a Steam game as a workaround for achievements!
    Not surprised you would find the tools and provide a solution!

    I honestly think achievements are just a marketing tool to get more sales. They never really provide any kind of reward, and are typically just silly accomplishments. The only ones I like to see are the progress and percentages. Like 30% of gamers made it to the final boss...

    Thanks for making the files available! Are you going to host them on your website or here on GamersOnLinux?
    Daerandin likes this.
  3. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,143
    Likes Received:
    248
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    I still need to actually create the programs. And before I can do that, I need to fully go through the debug data to map all of the address offsets. At least I have verified that they all have a constant offset from the base game modules in memory.

    The full source code will be put on my gitlab account. I will only create precompiled files for Windows, which I will put on my website. But compilation on Linux will be easy as I will include a Makefile for simple compilation.
    booman likes this.
  4. booman

    booman Grand High Exalted Mystic Emperor of Linux Gaming Staff Member

    Joined:
    Dec 17, 2012
    Messages:
    8,312
    Likes Received:
    619
    Trophy Points:
    113
    Location:
    Linux, Virginia
    Home page:
    Awesome! I don't know how you do it!!!???
    A lot of patience for sure.

    Like when you helped me:
    • Create a python script for GOL guides
    • Create a compressed GZDoom installer for Hedon
    • Helped me install Arch Linux
    Daerandin likes this.
  5. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,143
    Likes Received:
    248
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    Yeah it just requires patience, and a hunch for what you are looking for. If I didn't have a hunch to work from then I would be way too lost to figure anything out. For this particular project I've had to learn a lot of assembly. I wouldn't call myself proficient enough to write programs in assembly, and I honestly don't want to try either, but I am able to understand smaller segments of assembly within the larger game code. This, along with the edb debugger, helped me to find the code I was looking for and modify it for the results I wanted. The modification I am doing is very simple. In x86 and x86_64 assembly, there is a specific opcode with the value 0x90, which does nothing. You can overwrite existing code with this nopcode to nullify certain parts of the code. As long as you do this correctly so it does not disturb the code flow, and only changes the tiny parts you are looking to change, then you get your results. The difficult part is identifying what to overwrite. If you get it wrong, you will usually just crash the program.
    booman likes this.
  6. booman

    booman Grand High Exalted Mystic Emperor of Linux Gaming Staff Member

    Joined:
    Dec 17, 2012
    Messages:
    8,312
    Likes Received:
    619
    Trophy Points:
    113
    Location:
    Linux, Virginia
    Home page:
    I've always wondered something about Steam games. If you modify a game file like you are talking about, does Steam auto-update the file to the original state? Ya know, like when it does a check or game update?

    I've messed with a few game configuration files to set something not available in-game.
    I'm always trying to find the save games as well. I sometimes have to back those up manually if cloud sync is not available in Steam. Obviously its not for GOG games and Heroic Launcher.

    I've never played with a Hex editor. I know some executables require a Hex editor for you to eliminate the need for a CD/DVD ROM in the drive. Hence all of the No CD Cracks available.
    Daerandin likes this.
  7. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,143
    Likes Received:
    248
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    The config.dat and stats.dat are files for your profile. So they will not be changed by Steam in any way. The only modifications I do to them are the same that the game does when you unlock stuff.

    The other program I will make, which will let you actually get Steam achievements, does not alter any game files. It changes the game code in memory while it is running. I could obtain the same effect by modifying the the game executable (the .exe file), but Steam would replace the file with the original if you verify game cache. The game code is exactly the same in the executable file as it is in memory while running. Some executable files are compressed in some way, which obfuscates the code, but Stronghold Legends (and Stronghold 2) are not, so I could find the exact same byte sequences in the executable and modify them there.

    If you ever want to dive into this kind of stuff just let me know and I can give you a hand. But I am no expert.
  8. booman

    booman Grand High Exalted Mystic Emperor of Linux Gaming Staff Member

    Joined:
    Dec 17, 2012
    Messages:
    8,312
    Likes Received:
    619
    Trophy Points:
    113
    Location:
    Linux, Virginia
    Home page:
    Thanks but until there is a need, I'll pass. Working in IT is complicated enough and testing/playing games in Linux is complicated enough.

    If I pick up anything else that is complicated, I'll explode!

    It is nice hearing about your adventures in coding, hacking and experimenting..
  9. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,143
    Likes Received:
    248
    Trophy Points:
    63
    Location:
    Northern Norway
    Home page:
    I finished making the awards+Steam Achievement unlocker for Stronghold Legends. Source code is on my gitlab:

    https://gitlab.com/Daerandin/shl_award_qualify

    The code will also compile and run on Windows, and I am planning to create a download page for a precompiled Windows binary. As for Linux, just download, go into the 'src' directory and run the 'make' command. You really just need gcc installed.

    This has been tested to work on both Linux and Windows.
  10. booman

    booman Grand High Exalted Mystic Emperor of Linux Gaming Staff Member

    Joined:
    Dec 17, 2012
    Messages:
    8,312
    Likes Received:
    619
    Trophy Points:
    113
    Location:
    Linux, Virginia
    Home page:
    Awesome Daerandin!
    Thanks for providing this to the gaming community!

Share This Page