Savegame formats?

Okay, now, I'm highly puzzled by this. I've been trying to edit the save game files, and I started a new game, starting with Autosave[0].save (Maybe I should save another save file to edit? - Gonna go do that, BRB.)

Note that I am playing with the default name, the "Terra Confederation". These are the opening few lines of the save file:

Code
  1. TXT
  2. PlayerSetup
  3. type 0
  4. numSlots 11
  5. slot
  6. status 1
  7. networkPlayerID 0
  8. name "Terra Confederation"
  9. actualRace "PlayerTech"
  10. raceIfNotRandom "PlayerTech"
  11. isRaceRandom FALSE
  12. isReadyToStart FALSE
  13. colorIndex 9
  14. themeIndex 41
  15. teamIndex 0
  16. aiDifficulty 1


Since everything else has a status 4 or 3, I'm going to assume that Status 1 means "Player".

Now, the first thing I want to find and do is change my credits, metal and crystal to 50,000 each. So I did another search on the Terra Confederation:

Code
  1. name "Terra Confederation"
  2. victoryStatus 0
  3. <snip a="" bunch="" of="" stuff="" related="" to="" alliances="">
  4. numShareVisionPlayerIndices 0
  5. credits 1015.52 Bits=1149100309
  6. metal 301.25 Bits=1133944832
  7. crystal 150.00 Bits=1125515264
  8. shipSlots
  9. maxSlots 85.00 Bits=1118437376
  10. usedByFrigatesSlots 13.00 Bits=1095761920
  11. usedByCapitalShipsSlots 40.00 Bits=1109393408


It's pretty clear-cut what the "Credits", "Metal" and "Crystal" entries are for. But what I don't understand are the Bits= numbers after them.

Bits=1149100309
Bits=1133944832
Bits=1125515264

I've tried editing the numbers in front of the Bits= and leaving Bits= alone, but when I re-open the save file, or when I load the game, I have the original number of credits. This I do not understand.

Here is what I have done, in changing the Credits/Metal/Crystal line:
Code
  1. credits 50000.52 Bits=1149100309
  2. metal 50000.25 Bits=1133944832
  3. crystal 50000.00 Bits=1125515264


In theory, that ought to mean the game should load up with 50,000 credits/metal/crystal for me. I'm just worried about the "bits" though.

Eh, I'm just going to save it now, and then re-open the file, to see if something bizzare is happening and my changes aren't actually being saved....

Nope. When I opened the file again, it was still at 50,000. So now to try in Sins.

And nada. When I open up the save file in Sins of a Solar Empire, the numbers go back to the originals. I'm starting to think the "Bits" entry is the only one that matters.

What's going on? How can I successfully edit this sucker?
10,410 views 9 replies
Reply #1 Top
Maybe the "bits" value is some kind of sumcheck? So that people can't go editing willy-nilly?
Reply #2 Top
Eureka!

The bits value IS the value you're looking for. The number is apparently just a foolyou measure.

Fortunately, I had an old savegame and I plucked a valid value out of the "maxrecorded" section. This is a good number, it'll work when inserted:

40937.51 Bits=1193273731
Reply #3 Top
hmmm, you should play around with the bitvalues and see if you can find the algorithm... just don't tell anyone or the devs will eat you...
Reply #4 Top
Here's what Blair said: "The bits part is the value that the game cares about and the left side number is just the human readable form to aid with modding and debugging. To convert between the two you can cast the bits as an integer pointer to achieve the human readable (base 10) form."
Reply #5 Top
Can you please explain how to do that translation? I understand those words individually, but together they tell me to do something I don't know how to do.
Reply #6 Top
lol, this is where you use the google
Reply #7 Top

The reason we do it this way is because the C runtime library isn't deterministic. In order to get around this, we write out the exact representation of the number in bit form.

Look here you go if you want to do the float conversion manually: http://en.wikipedia.org/wiki/IEEE_754. But I'm sure there are freeware or online converters.

 

Reply #8 Top
1. Go to http://babbage.cs.qc.edu/IEEE-754/Decimal.html.
2. Type in the number you want in the "Decimal Floating-Point" field and hit the "Rounded" button.
3. Look down for the field called "Hexadecimal" under the section "Single-precision (32 bits)". Copy the value (8-characters) to the clipboard.
4. Open Windows Calculator (calc.exe), via Start->Accessories->Calculator.
5. Select View->Scientific.
6. Select View->Hexadecimal (or click the "Hex" radio button).
7. Paste the 8 characters you copied in step 3.
8. Select View->Decimal (or click the "Dec" radio button). There's your "Bits" value!


For an example, let's take Shadow's value of 40937.51.

In 3., the hexadecimal value is "471FE983". After step 8, the decimal value is "1193273731", exactly the correct "Bits" value.

Blair, to make this sort of operation easier in the future, how about changing the saved game exporter and parser to print the Bits value in hex? That would save the need for conversion via calc.exe.
Reply #9 Top

Can't think of why not off the top of my head. I'll look into it, good idea.