How to fix the 0 relations bug

Age of History II386 views9 favorites3 min readby SammerUpdated Jun 10, 2024View on Steam ↗

Introduction

Hello person reading this.
Today I've taken the time to read the source code as well as the serialized save data in order to find the fix.
You're welcome. Enjoy

(btw this guide won't fix you being stuck with 0 relations in real life)

Why it's bugged

The game, at some point, for some horrible reason that I don't want to track down, sets a civ's relation with another civ to NaN. Well Sam, what's NaN you ask? It means "Not A Number". It's very bad and not normal!! This value, which is technically a number, has special properties compared to normal numbers. For example: what's 10 + NaN? Well, it's NaN. So anything that touches NaN becomes NaN. This is why the 0 relations bug quickly spreads to other civs as the NaN spreads like cancer all over your save file.

How to fix it

Okay, clearly the game is bugged as tarnation, but don't panic! Here's the fix.

Step 1:
Find the folder where your save data is. Okay, boring, but you do need to find the save data if you want to fix it...

Step 2:
Backup that save data, in case something bad happens. If you somehow ruin your save file I'm not responsible!!
Step 3:
See those files that end with "_2X"? There's _2X, _2X1, _2X2, and so on. The number of files depends on how many civs there are in your game. For all of those files that end with underscore 2 X something, I want you to open the file in any hex editor (You already have one, right? right? ...what do you mean I'm a nerd) and do a global replace: replace all occurrences of "7F C0 00 00" (that's NaN) with "41 20 00 00" (that's +10). Or, if you know how this stuff works, you can replace the NaNs with any number you want, really.

Because we're only overwriting NaNs, it will only replace the bugged relations: the relations that aren't bugged won't change.

Remember to do this in all the files that end in _2X!!!

Step 4:
...there isn't one. You're already done, big guy. You got rid of the cancer and now you can get back to gaming.

How to fix it, the easy way

Well, manually replacing bytes in a bunch of files is a lot of work, isn't it?
I think so too.
So I made an app that automatically does all the work for you.
You can leave it open while playing, and if you see bugged relations, you save your game, you click the big "Fix 0 relations bug" button on my app, and you reload your game and you're done!

You can download it here:
https://github.com/SamTheBlow/aoh2-tools

It's open source, so you can read the code yourself if you don't trust it, and you can contribute your own code too.

How to fix it PERMANENTLY?

Okay, so we just fixed our save file, but uhhh won't the bug come back eventually?
Yeah, it will.
We can't just change the source code itself. Only Łukasz can.

So this final part is for you Łukasz. Here's how you can fix this bug for everyone permanently with just two lines of code.

In the Civilization class, in both the getRelation and setRelation functions, add these two lines of code:
if (((Float)this.civGameData.lRelation.get(i)).floatValue().isNaN()) { this.civGameData.lRelation.set(i, Float.valueOf(0.0F)); }

Okayyy that's three lines if you count the closing bracket... But HEY this fix is so easy to add, there's no excuse!! Just do it right now!!!

This guide was created by its original author on the Steam Community. Are you the author and want it removed? Request removal.