Modding Civilization I - Data Tables

Gowron

Chieftain
Joined
May 21, 2007
Messages
62
In this topic I'm going to list and explain some data tables which can be found inside of civ.exe. These tables influence the behaviour of the game. They contain data such as in-game names, terrain/unit stats, or the tech tree. Since tables are relatively easy to edit, they are useful for modding Civilization I.

For modding civ.exe you need a hex editor. I use
http://mh-nexus.de/en/hxd/
While this is no doubt a very good editor, you can find many more on the web. Just pick one that you feel comfortable with :)

When testing your changes, do not load a saved game. Savegames use some tables of their own, so most changes would not be visible. Instead, start a new game to test any modifications you do.

Always make sure to have a backup before editing civilization.

The information below applies to CivDOS v475.01. It may also apply to other versions of CivDOS, but I cannot guarantee for that.



1. Unpacking Civ.exe

The file "Civ.exe" is actually a compressed executable. Although it's possible to edit many things in the packed file directly, it's still a good idea to decompress it first, because the tables are messed up in the compressed file. The program that was used for the compression is ExePack v3.65. To decompress civ.exe, you can used the UNP tool which can be downloaded here. The uncompressed .exe is about 10% larger than the compressed one.
Also, after decompression, the executable can be analyzed with a disassembler (of course it must be one that can handle MS-DOS executables).

All offsets listed below apply to the decompressed executable of CivDOS v475.01.

Update: If you get an "Overlay not found" error whe trying to launch the unpacked executable, look here for a solution.


2. City Names

The city names table starts at position 0x28900. It contains 256 entries, each consisting of a 12-byte string (the city name plus one or more blanks) followed by a null character (0x00). The entries are sorted by civs first (with a pool of additional city names like "Mecca" at the end) and then by the order in which they are founded. Note that a string must always be followed by a null character (this applies to all following sections as well).



3. Leader Names (Hall of Fame)

At position 0x29600, right after the city names table, we have the names of historical characters for the "your civilization rating of... exceeds even..." message. This table has 20 entries, each 25 bytes in size. So the maximum length for such a name is 24 bytes.



4. Terrain Stats

This is where things become a bit more interesting. While the first two tables were just made of strings, this one actually contains data which will have an influence on in-game values. The terrain stats table begins at position 0x2CBB2. It contains 24 entries (one entry for each terrain type; special resources are treated as separate terrains). Entries are each 19 bytes in size and are divided as follows:

relative offset: 0x00
terrain name

relative offset: 0x0C
movement cost

relative offset: 0x0D
defense value (will be multiplied by 50%, for example 0x04 means 200% defense)

relative offset: 0x0E
food production

relative offset: 0x0F
resources production

relative offset: 0x10
trade production

relative offset: 0x11
unknown

relative offset: 0x12
terrain ID



5. Terrain Improvement

The next table controls how terrain can be improved by irrigation and/or mining. It starts at position 2CD7A and contains 12 entries (12 bytes per entry). The order of terrain types matches that of the terrain stats table, but this time, special resources are NOT treated as separate terrains. Instead, they share entries with their unbonused "counterparts".
The order is Desert, Plains, Grassland, Forest, Hills, Mountains, Tundra, Arctic, Swamp, Jungle, Ocean, River.
When entering negative numbers, keep in mind that these are 2-byte values, so for example, for -2 you have to enter "FE FF", not just "FE".
Here's what each entry contains:

relative offset: 0x00
effect of irrigation
(if positive: terrain ID of resulting terrain; must be a valid terrain ID)
(if negative: -1 = impossible to irrigate; -2 = +1 food; -3 = +2 food; -4 = +3 food; etc.)

relative offset: 0x02
duration of irrigation (i.e. it will take a settler this many turns to irrigate a square)

relative offset: 0x04
effect of mining
(if positive: terrain ID of resulting terrain; must be a valid terrain ID)
(if negative: -1 = impossible to mine; -2 = +1 shield; -3 = +2 shields; -4 = +3 shields; etc.)

relative offset: 0x06
duration of mining (i.e. it will take a settler this many turns to mine a square)

relative offset: 0x08
ability of the AI to irrigate/mine this terrain type under despotism
(0 = no; 1 = yes)

relative offset: 0x0A
ability of the AI to irrigate/mine this terrain type under monarchy (or higher)
(0 = no; 1 = yes)


The "effect of irrigation" and "effect of mining" values can for example be used to enable settlers to change ocean squares into land squares and vice-versa. After turning a land square into an ocean square, the settlers unit is *not* destroyed and can move to any adjacent land square. To turn ocean squares into land squares, put the settlers on a ship and wake them.



6. Tech Tree

The tech tree, which starts at position 0x2CE0A, consists of 72 entries (22 bytes each). Here the names and prerequisites of the technologies are stored. Each technology has its own ID, but this ID is not stored explicitly. Instead, the technologies are simply sorted by IDs, starting with Alphabet (ID 0). There are four dummy techs (IDs 68, 69, 70, 71). Note that some techs have special effects (such as making existing barracks obsolete). These effects only depend on the ID, i.e. the order of the techs.
For dummy techs and for future technology, "0x7F" is used as both prerequisites.
Contents of an entry:

relative offset: 0x00
name of the technology

relative offset: 0x14
tech ID of first prerequisite
(-1 = no prerequisite)

relative offset: 0x15
tech ID of second prerequisite
(-1 = no prerequisite)


With embasssies you can look at the techs of other civs. When doing so, the techs with the highest IDs are displayed first.


List of tech IDs:

0x00 Alphabet
0x01 Code of Laws
0x02 Currency
0x03 Atomic Theory
0x04 Democracy
0x05 Monarchy
0x06 Astronomy
0x07 MapMaking
0x08 Navigation
0x09 Mathematics
0x0A Medicine
0x0B Physics
0x0C Engineering
0x0D University
0x0E Magnetism
0x0F Electronics
0x10 Masonry
0x11 Bronze Working
0x12 Iron Working
0x13 Bridge Building
0x14 Invention
0x15 Computers
0x16 Writing
0x17 Steam Engine
0x18 Trade
0x19 Ceremonial Burial
0x1A Mysticism
0x1B Nuclear Fission
0x1C Philosophy
0x1D Religion
0x1E Literacy
0x1F Horseback Riding
0x20 Feudalism
0x21 The Wheel
0x22 Gunpowder
0x23 Industrialization
0x24 Chemistry
0x25 Combustion
0x26 Flight
0x27 Advanced Flight
0x28 Space Flight
0x29 Mass Production
0x2A Pottery
0x2B Communism
0x2C The Republic
0x2D Construction
0x2E Rocketry
0x2F The Corporation
0x30 Metallurgy
0x31 RailRoad
0x32 Nuclear Power
0x33 Theory of Gravity
0x34 Steel
0x35 Banking
0x36 Electricity
0x37 Refining
0x38 Explosives
0x39 SuperConductor
0x3A Automobile
0x3B Genetic Engineering
0x3C Plastics
0x3D Recycling
0x3E Chivalry
0x3F Robotics
0x40 Conscription
0x41 Labor Union
0x42 Fusion Power
0x43 1 (dummy tech)
0x44 2 (dummy tech)
0x45 3 (dummy tech)
0x46 4 (dummy tech)
0x47 Future Tech.


Give the dummy techs some valid prerequisites, and you can actually discover them. They won't appear in the Civilopedia without further editing, but that's just a cosmetic issue. On the other hand, I'd advise you to stay away from editing Future Technology. It's needed when there is nothing else to research.



7. AI Tech Values

At position 0x2D43A there's a table (72 entries, 2 bytes per entry) which controls how "valuable" a technology will be in the "opinion" of the AI. Each technology has a base value and a modifier. For "civilized" leaders, the modifier is added to the base value. For "militaristic" leaders, it is subtracted instead. The result determines which technologies the AI will ask for during negotiations, and probably also what the AI decides to research next.
The entries are sorted by tech IDs.
An entry contains:

relative offset: 0x00
base value

relative offset: 0x01
value modifier


Example: "Code of Laws" has a base value of 4 and a value modifier of +1. For a leader who is neither civilized nor militaristic, its value is 4. For a civilized leader, its value is 4+1=5, while for a militaristic leader its value is 4-1=3.



8. Buildings

The building table (position 0x2D4CA, 46 entries, 30 ybtes per entry) starts with a dummy entry and contains all city improvements, including space ship parts and wonders of the world. The effects of buildings are hardcoded and depend on the position of the entry in this table.
Each entry consists of the following data:

relative offset: 0x00
name of the building

relative offset: 0x18
construction cost (will be multiplied by 10 shields)

relative offset: 0x1A
maintenance cost (per turn)

relative offset: 0x1C
tech ID of the prerequite technology
(-1 = no prerequisite, use "FF FF", not just "FF")



9. Wonder Expiration

The table at position 0x2DA2E (21 entries, 2 bytes per entry) controls when wonders of the world become obsolete. The order of the entries is the same as the order of the wonders in the building table.
Each entry contains just one value:

relative offset: 0x00
tech ID of the tech which cancels the effect of the wonder
(use 0x7F to make the effect of a wonder last for the whole game)



10. Unit Stats

The unit table starts at position 0x2DA5A (28 entries, 34 bytes per entry) and allows for quite a few interesting modifications. However, the position of an entry in this table can have important effects, for example which units can be appear as barbarians.
Each entry contains the following data:

relative offset: 0x00
unit name

relative offset: 0x0C
tech ID of the advance which makes this unit obsolete
(use 0x7F for units which do not become obsolete)

relative offset: 0x0E
domain
(0 = land; 1 = air; 2 = ocean)

relative offset: 0x10
movement rate

relative offset: 0x12
fuel (air units only)
(1 = must return to city or carrier each turn; 2 = must return to city or carrier each other turn; etc.)

relative offset: 0x14
attack rating

relative offset: 0x16
defense rating

relative offset: 0x18
cost (will be multiplied by 10 shields)

relative offset: 0x1A
visibility
(0 = one square; 2 = two squares; 3 = two sea squares)

relative offset: 0x1C
number of transport slots

relative offset: 0x1E
AI role
(0 = colonization; 1 = attack; 2 = defense; 3 = sea superiority, 4 = air superiority, 5 = sea transport; 6 = diplomacy/trade)

relative offset: 0x20
tech ID of the prerequite technology
(-1 = no prerequisite, use "FF FF", not just "FF")



11. Civilization Leaders

The leaders table is divided into two parts (position of 1st part: 0x2DE4C, position of 2nd part: 0x2E01C). Each part contains 7 entries (1 entry for each leader, 58 bytes per entry). Negative values for attitudes must be "FF FF" (i.e. 2 bytes).
Each entry contains:

relative offset: 0x00
name of the leader

relative offset: 0x10
civilization name (plural)
(this entry can be empty if the plural is formed by simply adding an "s" at the end)

relative offset: 0x20
civilization name (singular)

relative offset: 0x30
1st attitude
(-1 = friendly, 0 = neutral, 1 = aggressive)

relative offset: 0x32
2nd attitude
(-1 = perfectionist, 0 = neutral, 1 = expansionistic)

relative offset: 0x34
3rd attitude
(-1 = militaristic, 0 = neutral, 1 = civilized)

relative offset: 0x36
music ID (short tune, e.g. when discovering a new technology)

relative offset: 0x38
music ID (long tune, e.g. during negotiations)



12. EARTH starting positions

See
http://forums.civfanatics.com/showthread.php?t=223182

In the decompressed .exe, the table starts at position 0x2FEBC.
 
And I thought that the golden age of CIV was behind us. This is certainly interesting research. Although I never cared for modifying the EXE your work does this open up some interesting avenues. Very nice indeed.

I do wonder if the modifications will influence the way the games civilization function. I wonder if the game uses strategies based on the parameters as given.
 
I tried to decompress version 05 exe but after the decompression the game didn't work.Do I have to somehow compress the exe again?
 
I do wonder if the modifications will influence the way the games civilization function. I wonder if the game uses strategies based on the parameters as given.

The changes will affect the AI behaviour, but only up to a certain extent. Giving a unit like the militia a high attack factor will affect AI diplomacy, as the sum of the attack factors of all of your units will become very high already st the start (AI empires would surrender more easily). The AI tech values would of course affect the AI. But there are certain hardcoded limitations. For example, the AI will never settle on forest, no matter how much food it produces.

And there could be changes which the AI is completely unable to adapt to.

I tried to decompress version 05 exe but after the decompression the game didn't work.Do I have to somehow compress the exe again?
Well, since I don't have version 05, I cannot say for sure what will or will not work for that version. Using version 01, I did not have to re-compress civ.exe. It runs fine while decompressed. I could probably tell you more if I knew the exact difference between versions 01 and 05.

You could try using the gettyp tool to find out if versions 01 and 05 use different compression methods.
You could also try to re-compress the file if you can somehow find a program which can do that. Or you could try modifying the packed .exe, although that would be more difficult than modifying it after decompression.
 
this looks great fun :D

im thinking of changing the values of the wonder expiration techs... most of them to remove lol

playing with the unit values can be VERY usefull. think about it this way. if you multiply all the values of all units by a set value you can make the famous phalanx vs battleship battle more realistic. (i mean the battleship always winning )

adding some arrows to hills also makes sence to me. im gonna get my hands dirty on this.

too bad things can also get unbalanced if we go too far.. would be fun to play emperror make the great library and making it never obsolete

this reminds me of my modifications on colonization. i changed the settings of all the tribes to be "civilised" and that made the game a lot more interesting (specially for the spanish AI )

--EDIT--
im struggling to unpack the file the link you gave doesnt help me much can you give me some fool proff step by step guide on unpacking ? i can use the hex edit tool i have used it before but uncompressing the exe is something tutally new to me.
 
1.Place your Civ.exe file same folder as unp.exe
2.on command line: type unp e civ.exe
You should now have decompressed civ.exe file

I wish you share with us the changes you make for the game.
 
1.Place your Civ.exe file same folder as unp.exe
2.on command line: type unp e civ.exe
You should now have decompressed civ.exe file

I wish you share with us the changes you make for the game.

i type exactly "unp e civ.exe" ? or just civ.exe ? i got a bit confused with that.

im not very confident it will work cus i noticed 2 hours after i posted that previous message that my vercion is .04 instead of 0.1

--EDIT--
tried both and didnt work. i sopose its cus i have a diferent vercion =( too bad i would love to play without the limits of the wonders and some other modifications that i would like to make...
 
I find it weird, but maybe it really works just for 475.01 . I have 474.04 and just decompressing original exe file is enough to make launching game impossible. Error message is "Overlay not found". I just tried it in DOSBox 0.74, in which original game runs perfectly.
 
So, thanks to really great job done by Gowron i succesully tested first changes in data tables :) I am no using UNP (cause i am not able to run decompressed .exe), but it is quite comfortable to change original .exe itself. I could be possible to make editing program with user friendly GUI, but personally i am not thinking of programming that just now :)

Ideas: it would be great to find settlers actions, so that it can make railroad in city. And change effects of roads and railroads :) I i can do it, for sure let you know.

To my last post: problem is not in version 474.01, i checked also 475.01, no changes to me. So problem should be somewhere between HW an ME :))
 
Yes! :clap:

I knew it, I already knew it all! Some 15 or 17 years beferore. With hex editor, right in undecompresed .exe (never thought I need to)

Thanks for a reminder!
(In the corner mountain of unsortable papers there probably are my old notes to the topic, if not burned)
 
Btw, Unit costs is in ROWS, that 10 for human, but for AI it 12 at chieftan and only 6 at emperor.

And, hey, can You do the same for CivWin please ?
 
Sorry for reviving a dead thread but I have been playing a lot of civilization 1 recently and got the urge to "look under the hood". Primarily i want to look at ways to improve the games ai and to make the game harder.

I have the same problem as Adamos. The decompressed .EXE fails to launch with the error message "Overlay not found". I have tried with both version 474.05 and 475.01, and it's the same thing. I have also tried with other unpacking utilities. Same results.

If anyone has an idea on what to do please let me know, as the compressed .EXE is a mess to debug (I believe ExePack is a simple RLE compressor, which means that it's pure luck if code is editable or not)
 
Sorry for reviving a dead thread but I have been playing a lot of civilization 1 recently and got the urge to "look under the hood". Primarily i want to look at ways to improve the games ai and to make the game harder.

I have the same problem as Adamos. The decompressed .EXE fails to launch with the error message "Overlay not found". I have tried with both version 474.05 and 475.01, and it's the same thing. I have also tried with other unpacking utilities. Same results.

If anyone has an idea on what to do please let me know, as the compressed .EXE is a mess to debug (I believe ExePack is a simple RLE compressor, which means that it's pure luck if code is editable or not)

I've just recently stumbled across this error myself, so i can now provide a solution:

1. Unpack Civ.exe, and rename the unpacked file to something else (like CIV1.exe).
2. Put the unpacked file into your Civ 1 directory, but also keep the original "civ.exe" file in that directory, and don't change the name of said original file.
3. You should now be able to run the unpacked file.


For some reason it seems like civ needs to be able to access its own original .exe file even after modding. Maybe it's using self-modifying code, that would also explain why it's so hard to disassemble.
 
I've just recently stumbled across this error myself, so i can now provide a solution:

1. Unpack Civ.exe, and rename the unpacked file to something else (like CIV1.exe).
2. Put the unpacked file into your Civ 1 directory, but also keep the original "civ.exe" file in that directory, and don't change the name of said original file.
3. You should now be able to run the unpacked file.


For some reason it seems like civ needs to be able to access its own original .exe file even after modding. Maybe it's using self-modifying code, that would also explain why it's so hard to disassemble.

I actually tried this and reached the conclusion that it was still unpacking the data from the original civ.exe because changes made in my unpacked .exe would not be reflected in the game. Now I find out it was because the decompiler I used didn't apply the changes I made until I make a "patch".. silly me

Anyway, yes this works, thanks! :)
 
Would you mind sharing what decompiler you do use ?

I use something called IDA Pro. It has some very nifty features like automatic code analysis (what is code what is data) and recognition of standard c libraries. I think it's pretty much what everyone is using.

It's a commercial software but older version can be downloaded for free.
 
Hey guys, any chance of getting a gui version of this? There is so much that can be done, but I haven't learned how to use a hex editor yet. Anyways, I'd be most interested in editing how terrain improvements effect the game.
 
Hey guys, any chance of getting a gui version of this? There is so much that can be done, but I haven't learned how to use a hex editor yet. Anyways, I'd be most interested in editing how terrain improvements effect the game.

I've been thinking of adding this kind of feature to JCivED (CIV.EXE patching), but probably not very soon...
 
Top Bottom