Modding Civ I - Load Saved Game without exiting!

darkpanda

Dark Prince
Joined
Oct 28, 2007
Messages
823
I don't know for you, but if there's something that has never failed to annoy me when I was playing CIV as a kid (and still now actually), it's how tedious it is to re-load a savegame when you are already playing a CIV game: first you must exit CIV, then restart CIV, then go through the video/audio options again, credits, main menu and finally you can load your savegame...

Some will argue that a "true" CIV player should only rarely be in that situation, and that only randomness-cheaters would make an extensive use of this technique... Well, I won't really object to that :) But since it truly annoys me, and that now I have designed a small hack to make it possible to re-load a saved game from within CIV without exiting, I thought I would share it here!

Hereunder are the offsets and bytes for all known versions:

Rich (BB code):
Civ EN 474.01 & EN 475.01
        offset: 0x743C
original bytes: B8 01 00 BA 00 00 52 50 CD 3F 0C 00 00
  hacked bytes: B8 FF FF BA 00 00 52 50 CD 3F 0B 00 00

Civ FR 474.05
        offset: 0x758A
original bytes: B8 01 00 BA 00 00 52 50 CD 3F 0C 00 00
  hacked bytes: B8 FF FF BA 00 00 52 50 CD 3F 0B 00 00

Civ EN 474.05
        offset: 0x74A6
original bytes: B8 01 00 BA 00 00 52 50 CD 3F 0C 00 00
  hacked bytes: B8 FF FF BA 00 00 52 50 CD 3F 0B 00 00

Civ EN 47403 & EN 47404
        offset: 0x6E9A
original bytes: B8 01 00 99 52 50 CD 3F 0C 00 00
  hacked bytes: B8 FF FF 99 52 50 CD 3F 0B 00 00

What this hack does is to basically rewire the F10 shortcut key to the "Load Saved Game" routine...

The full world map can still be shown by selecting the "World Map" item from the World menu, in case you ever use it.

Note: I noticed a side effect when playing a game where End OF Turn is blinking and loading a save game where it's not: the loaded saved game would automatically skip to next turn... Re-re-loading the saved game does work properly though.
 
Last edited:
Sweet. This will shave literally hours off of luck manipulation trials over the course of a game.
 
Hey Whelkman. But is it the same?

For the purists out there (people who might use luck manipulation by re-loading, but still want to play a game conceivably possible to be generated by the game engine), they would like to know if there are any "state" variables which would be cleared by restarting the game but may not be cleared by "reloading within game".

I'm thinking of some kind of state for the AI.. or, more particularly, maybe some kind of state for the random number generator.

This brings me to another question that has been lurking in my mind to ask you darkpanda, though not 100% sure I want to know the answer, but will ask it anyway. How does Civ 1 generate random numbers? Speaking in analogy of C/C++ functions, is it just the equivalent of successive rand() calls after an initial srand( current_time ) at the beginning of the program? Or is it more complicated than that such as re-seeding periodically or using additional inputs of "randomness" such as current millisecond or user input sequence, etc?

Dancing with Civ's randomness generator is almost an art form to me. For example, I try to time my attacks according to where the unit is in his "blink" cycle. Or, I wait a few seconds before initiating an attack. Or, if I have five chariots outside an enemy city but the first one to attack loses, I hold the rest until the next turn for fear of being on a "losing streak." It is probably all superstition on my part.. I'm not sure if I want to know how Civ 1 generates randomness or not, but we'd might as well open pandora's box. How is it, darkpanda?
 
Regarding clearing variables, using the same game swap trick (i.e. exiting the game then moving 0-3 to 4-8 then reloading from there) does not seem to offer the standard variability. That is, when using this trick, the pool of potential outcomes seems significantly smaller.
 
Hey Whelkman. But is it the same?

For the purists out there (people who might use luck manipulation by re-loading, but still want to play a game conceivably possible to be generated by the game engine), they would like to know if there are any "state" variables which would be cleared by restarting the game but may not be cleared by "reloading within game".

I'm thinking of some kind of state for the AI.. or, more particularly, maybe some kind of state for the random number generator.

One thing is for sure, this "in-game reload" is definitely not clean, as I have already experienced some side-effect (turn skipping, graphics corruption)... But it's hard to tell whether actual game data doesn't get re-initialized when it should.

This brings me to another question that has been lurking in my mind to ask you darkpanda, though not 100% sure I want to know the answer, but will ask it anyway. How does Civ 1 generate random numbers? Speaking in analogy of C/C++ functions, is it just the equivalent of successive rand() calls after an initial srand( current_time ) at the beginning of the program? Or is it more complicated than that such as re-seeding periodically or using additional inputs of "randomness" such as current millisecond or user input sequence, etc?

Dancing with Civ's randomness generator is almost an art form to me. For example, I try to time my attacks according to where the unit is in his "blink" cycle. Or, I wait a few seconds before initiating an attack. Or, if I have five chariots outside an enemy city but the first one to attack loses, I hold the rest until the next turn for fear of being on a "losing streak." It is probably all superstition on my part.. I'm not sure if I want to know how Civ 1 generates randomness or not, but we'd might as well open pandora's box. How is it, darkpanda?


I didn't thouroughly investigate the management of randomness in CIV, but I just checked again, since you asked...

A couple of things:
  • CIV uses a very classic "seed"-based random algorithm, from which further random values are computed
  • the "random" routine takes a single integer N as argument, and returns a random value from 0 to N-1 included
  • the random function does rely on 2 global variables for computing random values:
    • the first variable is initialized based on the system timestamp on CIV start (part of the opening credits routine); this is the initial "seed", which happens to be precisely the "Terrain Master Word" or "Random Seed" specifying the pattern of special resources and huts, and stored in SVE files
    • the second variable is initialized to 0
  • each call to the random routine will update both random variables, introducing "chained pseudo-randomness", which is a very classic way of simulating randomness in computer algorithms
  • in addition, there are calls that, indeed, re-seed the randomness generator; typically, when displaying a City View, the random seed is re-initialized to the total sum of the city name's ASCII character codes (can you believe it! I just found this out 5 minutes ago...) while the 2nd variable is reset to 0; this ensures that a given city has always the same "random" - yet identical - streets and buildings layout

To be honest, I routinely have irrational behaviours when playing CIV (and other games) such a pressing the attack key harder and shouting encouragements in hopes that my bombers will DESTROY THIS F%#!ING PHALANX!!! :) But of course, even without looking at the cold, clinical assembly, you can guess it is totally useless.

That said, now that I've discovered this City View thing, I'm curious whether finding the perfect City name and displaying it before triggering an attack could actually force the odds in any way...... That would be CIV-cheating at its best, without even hacking it! The city population and buildings should remain unchanged though, most likely.

I'll have to investigate this further...
 
Absolutely fascinating as always darkpanda. And a little bit disheartening that your cheers of encouragement to your bombers are actually useless... :( ;)

That's a pretty funny trick of re-seeding the generator so that every city has a "random" but consistent layout. That's very subtle.
 
Regarding clearing variables, using the same game swap trick (i.e. exiting the game then moving 0-3 to 4-8 then reloading from there) does not seem to offer the standard variability. That is, when using this trick, the pool of potential outcomes seems significantly smaller.

Wanted to say I found your post interesting too, Whelkman. I have never myself played a 'twayf' game as you describe (and lately I have been playing my games straight-through). But back in the days I used to re-load trying to get a certain result from a given hut for example, I was also intrigued by the seeming "range of possible outcomes." So what you say is interesting.
 
Top Bottom