"Requests" to research in civ.exe...

hannurabi

Warlord
Joined
Aug 29, 2005
Messages
173
I'm not really requesting anyone (read DarkPanda) to seek these things, but if you ever come across these databits during your research, would you please let me know?;) You don't need to make and test any changes, I'm only interested to find the location of the correct bytes inside civ.exe.

-Building abilities. I know they are hard coded but it would be interesting for example to change Bank to produce 200% of luxury or factory 25% of production. These changes could probably be just one byte.

- Government abilities. For example make democracy to produce 3 unhappy people per unit not in home city. Or change military police number under communism to 10.

-Formula that defines how much food is needed for city to grow. This would allow some really interesting terrain stats modifications.

-Tech cost formula. I have already requested this. Even small changes could be interesting.

-If it's possible to make some other type of unit than nuclear disappear after an attack, it would be interesting. (I'm thinking catapults could be "use only once" units...)

-Difficulty level attributes. I would like to customize a difficulty level to be very difficult but still fun to play.

-etc... Actually if you find anything that you think could be interesting would you please share it?

I have a mod in mind, that I would like to create.

edit:
- Caravan income formula, both initial and trade routes
 
Additional thoughts here:

I think I mentioned before how nearly all "effects" of buildings or government type in the game are actually "passive". By that, I mean that the code for implementing/computing the effect is spread around everywhere in the code, with small parts nested in many smaller routines.

A good example of this is the sub-routine to compute the resource yield for a map square: this computation is completely contained in one single routine (which starts at 0x1394F in CIV 474.01).

In this routine, you have many hard-coded checks, such as:
- if a City has Colossus, add 1 trade point (at 0x13A3A, FF 46 FE - inc [bp+var_2])
- if a Civ's government is Anarchy or Despostism, remove 1 point (starts at 0x13AB6):
Code:
[COLOR="Green"]83 BF 1C EE 01[/COLOR] - [COLOR="Blue"]cmp     word ptr GovernmentType[bx], 1[/COLOR]
         [COLOR="Green"]7F 03[/COLOR] -[COLOR="Blue"] jg      short seg007_6A61[/COLOR] [I]; Jump if gov ID is more than 1, i.e. skip the decrease[/I]
      [COLOR="Green"]FF 4E FE[/COLOR] - [COLOR="Blue"]dec     [bp+var_prod]  [/COLOR] [I]; Decrement by 1[/I]
               - seg007_6A61:

So when you want to modify the effect of Colossus or a Government type, beyond minor tweaking, it very quickly becomes very tricky. Here, the simplest that can be done is skips the checks for Colossus or Government, or replace increase with decrease (or vice-versa). If you want more, you need to get the hacking tool box out :)

Of course, there may be some isolated places that have much more value in being tweaked, such as the impact of difficulty levels on unit/building prices, or tech formula, as you stated, but in my opinion it still makes it hard to really have extended control on the overall behaviour of the modifications.

Nonetheless, I will post what I find here.
 
Thank you. I might not need to change these particular effects you showed, but that is good example of things I'm interested.

Hmmm, it should be possible to apply the colossus bonus to other wonder instead, am I correct? One could create superwonder that has many effects.

---

Wait, did you say that you found the subroutine that defines how much food/production/trade is generated from square? If that is the case I need to investigate it, since it allows very interesting customization of governments.

For example (if I'm not totally mistaken), one could give Communism production bonus instead of production limit for anarchy and despotism.

Spoiler :
I have mod idea for Ancient Mediterranean/Roman Empire. There I will have the Communism Government replaced by the Empire/Imperium government. The changed goverment effects could be something like this:
  • Anarchy : -1 Food, -1 trade, normal production
  • Despotism : -1 Food, -1 trade, normal production
  • Monarchy : no changes
  • Republic : no changes
  • Democracy : no extra trade,(no corruption is good enough) at least 3 unhappy per military unit not in home city (strictly peace time goverment)
  • Imperium : + 1 Production , Military police is very big, at least 10;)
 
Just wondering whether it would be possible to replace the government check by technology check. Instead of checking if government is anarchy or despotism, you could check if for example currency is researched? That would allow some modding possibilities.

edit:
Pushing even further, if it's possible to give SETI program's effect to for example tech philosophy or writing, that would be very cool.
 
Hmmm, it should be possible to apply the colossus bonus to other wonder instead, am I correct? One could create superwonder that has many effects.

Yes, it is possible to change to another Wonder, but then it would still apply only to that city. If you want the change to be more global, then... more change is needed :)

---

Wait, did you say that you found the subroutine that defines how much food/production/trade is generated from square? If that is the case I need to investigate it, since it allows very interesting customization of governments.

For example (if I'm not totally mistaken), one could give Communism production bonus instead of production limit for anarchy and despotism.

Yes I did find that sub-routine: it takes a position (x,y) as argument, as well as a "resource id", depending on whether you're asking for how much food, shields or trade the square at (x,y) is producing. I might create a separate thread to document it (but these days I am starting to look for better solutions to document such things, in a consistent and user-friendly way).

And indeed, as always, if you know what you want to code, I guess anything is possible, although never easy.

Just wondering whether it would be possible to replace the government check by technology check. Instead of checking if government is anarchy or despotism, you could check if for example currency is researched? That would allow some modding possibilities.

I am not sure: government check is very simple, just checking a value in an array (e.g. GovernmentType[civID] == DESPOTISM), but checking for technology may be more complex... I know there is a dedicated sub-routine to check that a player has a tech already, but sub-routine call takes a lot more bytes than simple array value comparison, so there may not be enough room to replace. Alternatively, the technologies for all Civs are stored as bit flags in large arrays, so something like "test TechFlag4[civID], CHIVALRY" may do the trick too, provided it doesn't take more bytes either... Deserves investigation.


Pushing even further, if it's possible to give SETI program's effect to for example tech philosophy or writing, that would be very cool.

That one may be more easy to hack: checking that a Civ is currently benefiting from a Wonder's effect is done through a dedicated sub-routine (e.g. CheckIfCivHasWonderEffect(civID, wonderID)) which checks whether the Civ has the Wonder, and that the Wonder is not obsolete. Since checking that a Civ knows a Tech is also a sub-routine call, I believe it is really piece of cake of switch the calls.

What's your version of Civ again? I found the place for SETI program checking in 474.01, but it's useless to share if it's not the one you have:

 

Attachments

  • seti.PNG
    seti.PNG
    33.4 KB · Views: 853
Nice. Version 474.01 will do fine, if it's the one you use for researching.

I'm interested to change at least SETI program's and Isaac Newton College's effects for certain techs. Writing for SETI, and some other tech renamed as Aristotele's methology for Isaac's.
 
for example to change Bank to produce 200% of luxury

From the snippet below, we see that the effect of Bank is to calculate luxury = luxury + (luxury/2) and tax income = tax income + (tax income/2).

That is to say, a Bank produces 150% of luxury and 150% of tax income:


Hereunder is the exact assembly:

Code:
[color=green]   A1 60 70[/color]  |  [color=blue]mov     ax, cityLuxuryProd_dseg_7060[/color]
[color=green]         99[/color]  |  [color=blue]cwd[/color]
[color=green]      2B C2[/color]  |  [color=blue]sub     ax, dx[/color]
[color=green]      D1 F8[/color]  |  [color=blue]sar     ax, 1[/color]
[color=green]01 06 60 70[/color]  |  [color=blue]add     cityLuxuryProd_dseg_7060, ax ; Add[/color]
[color=green]   A1 9A F0[/color]  |  [color=blue]mov     ax, countCityTaxCollected_dseg_F09A[/color]
[color=green]         99[/color]  |  [color=blue]cwd[/color]
[color=green]      2B C2[/color]  |  [color=blue]sub     ax, dx[/color]
[color=green]      D1 F8[/color]  |  [color=blue]sar     ax, 1[/color]
[color=green]01 06 9A F0[/color]  |  [color=blue]add     countCityTaxCollected_dseg_F09A, ax[/color]

In order to set Bank's luxury effect to 200%, the simplest way here is to skip the "divide by 2" instructions, so the calculation becomes "luxury = luxury + luxury".

So here are the suggested replacement bytes:

Code:
[color=green]   A1 60 70[/color]  |  [color=blue]mov     ax, cityLuxuryProd_dseg_7060[/color]
[color=red]         90[/color]  |  [color=red]nop[/color]
[color=red]         90[/color]  |  [color=red]nop[/color]
[color=red]         90[/color]  |  [color=red]nop[/color]
[color=red]         90[/color]  |  [color=red]nop[/color]
[color=red]         90[/color]  |  [color=red]nop[/color]
[color=green]01 06 60 70[/color]  |  [color=blue]add     cityLuxuryProd_dseg_7060, ax ; Add[/color]
[color=green]   A1 9A F0[/color]  |  [color=blue]mov     ax, countCityTaxCollected_dseg_F09A[/color]
[color=green]         99[/color]  |  [color=blue]cwd[/color]
[color=green]      2B C2[/color]  |  [color=blue]sub     ax, dx[/color]
[color=green]      D1 F8[/color]  |  [color=blue]sar     ax, 1[/color]
[color=green]01 06 9A F0[/color]  |  [color=blue]add     countCityTaxCollected_dseg_F09A, ax[/color]

In other words, here is how to patch CIV.EXE v474.01 in order to have Bank produce 200% luxury (untested):

Code:
offset = [b]0xFA57[/b]
original bytes = [color=green]A1 60 70 99 2B C2 D1 F8 01 06 60 70 A1 9A F0 99 2B C2 D1 F8 01 06 9A F0[/color]
 patched bytes = [color=green]A1 60 70[/color] [color=red]90 90 90 90 90[/color] [color=green]01 06 60 70 A1 9A F0 99 2B C2 D1 F8 01 06 9A F0[/color]

Note: the original bytes sequence can be found twice in CIV.EXE, the other occurence just a few bytes before, encoding the Marketplace behaviour, identical to that of the Bank (but cumulative).
 

Attachments

  • civ_bank.PNG
    civ_bank.PNG
    51.4 KB · Views: 852
That's awesome. Just note that I only used the 200% luxury as example of what kind of changes I'd find interesting. Nevertheless it is very interesting. I probably can play with the formula little bit myself too.
 
That's awesome. Just note that I only used the 200% luxury as example of what kind of changes I'd find interesting. Nevertheless it is very interesting. I probably can play with the formula little bit myself too.

I know, but I wanted to give a concrete example to achieve such a change. As you see from the previous post, there is some margin (between 5 and 10 bytes) to implement different formulas, but it's not always the case, and what you can do really depends on how it is implemented.

Let's see with your second proposal:

hannurabi said:
[...] factory 25% of production [...]

For production bonuses, I have prepared a full picture of how it is managed in CIV.EXE, that you can see below:

Spoiler :

In plain English, the rule implemented above says:
  • Factory gives a 50% production bonus, calculated from base production
  • Mfg. Plant gives a 100% production bonus, calculated from base production (obsoletes Factory)
  • Power plant, Hydro plant, Nuclear plant or Hoover Dam effect give a 50% production bonus (exclusive from one another), calculated from base production, but only if the city already has a Factory or a Mfg. Plant
  • The bonus from Factory/Mfg. Plant and from any type of power Plant are cumulative

We also see that "50% bonus" is actually achieved with the formula "prod = prod + (prod*2)/4".

So to change Factory bonus to 25%, we need to change the formula to "prod = prod + (prod*1)/4".

In terms of assembly, that means we need to replace as follows:
Code:
[B]original code:[/B]
seg007:1367    [COLOR="Green"]C7 86 0C FF 02 00[/COLOR] | [COLOR="Blue"]mov [bp+[/COLOR][COLOR="Green"]var_prodMultiplier1[/COLOR][COLOR="Blue"]], [/COLOR][COLOR="DarkOrange"]2[/COLOR]

[B]changed code:[/B]
seg007:1367    [COLOR="Green"]C7 86 0C FF [/COLOR][COLOR="Red"][B]01 00[/B][/COLOR] | [COLOR="Blue"]mov [bp+[/COLOR][COLOR="Green"]var_prodMultiplier1[/COLOR][COLOR="Blue"]], [/COLOR][COLOR="red"][B]1[/B][/COLOR]

Or more conventionally, to patch CIV.EXE v474.01 as follows (untested):
Code:
offset: [B]0xE3B8[/B]
original bytes: [COLOR="Green"]F7 87 6C 70 00 40 75 03 E9 06 00 C7 86 0C FF 02 00[/COLOR]
 patched bytes: [COLOR="Green"]F7 87 6C 70 00 40 75 03 E9 06 00 C7 86 0C FF[/COLOR] [COLOR="Red"][B]01 00[/B][/COLOR]
 

Attachments

  • civ_factory_effect.png
    civ_factory_effect.png
    146.5 KB · Views: 827
Nice. Version 474.01 will do fine, if it's the one you use for researching.

I'm interested to change at least SETI program's and Isaac Newton College's effects for certain techs. Writing for SETI, and some other tech renamed as Aristotele's methology for Isaac's.

For the Newton College effect, there are 2 occurrences in CIV.EXE:
  1. to increase the effect of a city's Library
  2. to increase the effect of a city's University

In those two occurrences, a call is made to the "checkIfCivHasWonderEffect" routine, passing the civ's ID and the wonder's ID (0xC = 12 for Newton College), at the following locations (in CIV.EXE v474.01):

Code:
 <seg>:<off> | CIV.EXE offset | Bytes
seg007:2A38  |    [B] 0xFA94[/B]     | [COLOR="Green"]B8 0C 00 50 FF 36 CA 64 9A CB 6A 07 0D[/COLOR]
seg007:2A7C  |     [B]0xFAD8[/B]     | [COLOR="Green"]B8 0C 00 50 FF 36 CA 64 9A CB 6A 07 0D[/COLOR]

Let's look at the bytes, and corresponding assembly, in details:


We see here that the only things to change are:
  • the sub-routine address, to call "checkIfCivHasTech" rather than "checkIfWonderAvailableForCiv"
  • the ID argument, to use the desired Tech ID (Writing = 0x16) rather than the Wonder ID

In v474.01, the address of "checkIfCivHasTech" is AD5:2293, in order to replace the logic "Does city owner have Newton College?" with "Does city owner know Writing?", here is the formal patch (untested):

Code:
offsets: [b]0xFA94, 0xFAD8[/b] (2 locations)

original bytes: [color=green]B8 0C 00 50 FF 36 CA 64 9A CB 6A 07 0D[/color]
 patched bytes: [color=green]B8 [/color][color=red]16[/color][color=green] 00 50 FF 36 CA 64 9A [/color][color=red]93 22 D5 0A[/color]

It should be just the same for other versions of CIV.EXE, provided you can find out the addresses of "cityOwner", "checkIfCivHasTech" and "checkIfWonderAvailableForCiv"... If I find the time, I will try to locate them too.
 

Attachments

  • Snap18.png
    Snap18.png
    9.3 KB · Views: 783
Completing the previous post, here is the patch to replace CIV's logic "Does city owner have SETI Program?" with "Does city owner know Writing?", in CIV.EXE v474.01 (untested):

Code:
offset: [B]0x13275[/B]
original bytes: [COLOR="Green"]B8 14 00 50 FF 36 CA 64 9A CB 6A 07 0D[/COLOR]
 patched bytes: [COLOR="Green"]B8[/color][color=red] 16[/color][color=green] 00 50 FF 36 CA 64 9A[/color][color=red] 93 22 D5 0A[/COLOR]

[I]The occurence below is for computing the number of turns per tech in the TRADE screen (F5)[/I]
offset: [B]0x3EEE2[/B]
original bytes: [COLOR="Green"]B8 14 00 50 FF 36 [B]10 E7[/B] 9A CB 6A 07 0D[/COLOR]
 patched bytes: [COLOR="Green"]B8[/color][color=red] 16[/color][color=green] 00 50 FF 36 [B]10 E7[/B] 9A[/color][color=red] 93 22 D5 0A[/COLOR]



And by the way, I am posting hereunder a cheat sheet for CivDOS reference values, which can be very helpful when tweaking with Wonder IDs, Tech IDs, buildings, etc.:

 

Attachments

  • reference_values2.png
    reference_values2.png
    98.8 KB · Views: 898
This is great!

Hmmm... it appears that my version where I have done the hex editing is 475.01, also unpacked for easier hex editing... But I guess I will be able to find the correct addresses.
 
It should be just the same for other versions of CIV.EXE, provided you can find out the addresses of "cityOwner", "checkIfCivHasTech" and "checkIfWonderAvailableForCiv"... If I find the time, I will try to locate them too.

So I did take the time and I found the location of those 3 items in other versions of CIV.EXE:


With this, the hack can be implemented for all versions of CIV, provided you can find the correct offset...
I leave to the reader the exercise of finding the offsets to patch in CIV.EXE ;) (note: for the FR version, it may not be possible, it's the only version using a near call instead of far call)
 

Attachments

  • Snap19.png
    Snap19.png
    8.7 KB · Views: 766
I tested the "SETI program to writing" patch for unpacked 475.01. Game does freeze between turns after pressing enter.

The 25% production for factory works correctly (of course as it is such a simple patch).
 
I confirm it was just a typo in the patch, and I fixed it in the posts above.
Also, I added a second location to patch in CIV.EXE, so that the TRADE screen (F5) takes the SETI Program into effect to calculate the number of turns per research.

Just to verify, I used an old savegame where I had discovered Writing but didn't have the SETI program built, and it worked like a charm, reducing the 5 turns per tech before patch to 3 turns per tech after patch (ignore the year mismatch, nothing dramatically changed in 1 turn):

BEFORE:
AFTER:

I already wrote the the XML patch that does this, and will be bundled with next version of JCivED.
 

Attachments

  • civ_885.png
    civ_885.png
    4.2 KB · Views: 734
  • civ_882.png
    civ_882.png
    4.2 KB · Views: 764
A few things I'd like to request...
First, for the great library effect - check if civilization has university researched. This would allow all civs to gain technologies once they research university. Also, change the great library wonder to give the civ technologies that two civs have in common. Currently technology is only given when a civ researches a technology that another civ possesses, perhaps the check can be changed to see if two civs have technologies researched... After removing the expiration of the wonder, sometimes the wonder is built much more down the line when civilizations already have more than half of the technologies, which isn't fair to the builder of the wonder.

Lastly, much more complicated and may be more down the line... Have jCivED allow you to select a wonder, and then select a technology that a civ researches that would take its place.
 
A few things I'd like to request...
First, for the great library effect - check if civilization has university researched. This would allow all civs to gain technologies once they research university.

Let me get this straight: you want to replace the effect the Great Library, with having the advance University, so basically "Civ has Great Library" becomes "Civ knows University", correct?

Also, change the great library wonder to give the civ technologies that two civs have in common. Currently technology is only given when a civ researches a technology that another civ possesses, perhaps the check can be changed to see if two civs have technologies researched...

I don't quite get your point here: do you mean that currently the check is only if exactly 2 other Civs know the Advance, but if 3 Civs know it, then the Great Library doesn't work?
Or do you want the Great Library owner to get all advances already discovered by 2 Civs upon completing its construction? (which is much harder to implement, obviously)

After removing the expiration of the wonder, sometimes the wonder is built much more down the line when civilizations already have more than half of the technologies, which isn't fair to the builder of the wonder.

Ok, so it seems to confirm my second interpretation above: if you build the Great Library when many Civs already have a lot of techs in common, sadly the Great Library does not give you those techs... Correct? I think this can be very hard to change... In particular, what would be the trigger to give the Library's owner a new tech: give all techs at once on Library completion, plus each new Tech discovered a second time? Or randomly give 1 doubly-discovered tech on each turn? Or on each tech discovery by any Civ?

Lastly, much more complicated and may be more down the line... Have jCivED allow you to select a wonder, and then select a technology that a civ researches that would take its place.

This one would be really interesting :) I think its achievable, but requires some significant work, to identify all places where Wonder effect is implemented...
 
Top Bottom