Hex Editing Tasks

Prof. Garfield

Deity
Supporter
Joined
Mar 6, 2004
Messages
4,387
Location
Ontario
I recently received a question about the city plunder calculation, in particular, why the entire treasury is plundered on the first turn. The explanation is here, but the most natural solution to that bug is to hex edit the relevant variable so that each tribe has the correct number of citizens on the first turn, instead of the default 0.

So, I decided to write a hex editing script to automate this fix (which I'll add to the CTRL+SHIFT+F4 scripts in the template). Since I'm currently familiar with the code required to hex edit, I figured I'd ask if people would like to suggest other hex editing tasks that could use a script.
 
From my experience in MGE, and I don’t recall if this was true in TOT, but global warming could effectively be written over—depending on the scenario, this would either stop the world from bugging out (if terrain forms change to something weird) or allow “pollution” to be used in a different way.
 
From my experience in MGE, and I don’t recall if this was true in TOT, but global warming could effectively be written over—depending on the scenario, this would either stop the world from bugging out (if terrain forms change to something weird) or allow “pollution” to be used in a different way.
Thanks for responding, this is the sort of suggestion I'm looking for. However, in this particular instance, the Lua commands civ.game.globalWarming and civ.game.globalWarmingCycle can be used to make the change without actually hex editing.

If anyone else knows of tasks that are done with hex editing, and are unsure if they can now be done with a Lua command, please suggest them anyway. I only came to scenario design because of Lua, so there are a lot of other scenario design tricks I either don't know or aren't at the front of my mind. If an edit can be achieved in-game using Lua, I'll respond with the relevant command, so this thread can act as a reference.
 
I'm not sure what might be done by hex-editing vs. Lua, or what the difference really is, but there are a couple of things that I know have been done by hex-editing previously: moving cities next to each other and setting alliances for the barbarians. Both of these can be done by Lua now, I think.

I have a couple of ideas;

1) allow more options for the calendar. Allow multiples of days and weeks to be configured, eg. May - Week I, II, III, IV, or October 29, 30, November 1, 2, 3... and so on, and

2) Make the happiness of fundamentalism configurable. For example, instead of all citizens being content, make only 2 or 3 content. Right now Fundamentalism is too strong once you've got the key technologies.

Another idea: can you change the effect of wonders? IMO, there are too many happiness wonders and not enough economic and agricultural ones. Wonders that allow a player to increase either the food, shield or trade output of a specific terrain might be useful. Or increase the advantage of a particular type of improvement. Or perhaps another diplomatic wonder, say allowing the player to reset the alliances of another civ once only. Or to change the type of government of one other civ for a fixed number of turns.
 
1.Is it possible by hexediting to enable the atttack animations for defending animated units during the combat ?

2. Is it possible by hexediting to give the different units different sounds during their movement ?
 
I'm not sure what might be done by hex-editing vs. Lua, or what the difference really is, but there are a couple of things that I know have been done by hex-editing previously: moving cities next to each other and setting alliances for the barbarians. Both of these can be done by Lua now, I think.
Hex editing is when you take a saved game, and change something about it. For example, if you know the place in the saved game where a tribe's treasury is stored, you can change the number to change the tribe's treasury. Since the treasury can be changed via the cheat menu, you wouldn't normally hex edit to change a tribe's treasury. Lua provides a way to change most of the data in the game, so if I'm writing a Lua script anyway, it is easier to change that field in the active game.

I don't expect there to be many examples of tasks requiring hex editing, because hex editing is only necessary if TNO didn't realise that scenario designers would want to change a piece of data. The citizen count is a pretty niche application, since it is only relevant on the first turn of a scenario, and only if cities are captured on that turn. I'm just wondering if anyone can think of any others.

Since I said I would make note of the Lua method of doing things:

Moving a city:

relocate
city:relocate(tile) -> boolean

Relocates the city to the location given by `tile`. Returns `true` if successful, `false` otherwise (if a city is already present for example).

Setting Barbarian Alliances:
diplomacy.setAlliance (if using the template) or

treaties (get/set)
tribe.treaties[otherTribe] -> integer

Returns the tribe's treaties with `otherTribe`.

1) allow more options for the calendar. Allow multiples of days and weeks to be configured, eg. May - Week I, II, III, IV, or October 29, 30, November 1, 2, 3... and so on,
This can be done using the file onGetFormattedData.lua if using the Template, or with the civ.scen.onGetFormattedDate function if not.

If anyone wants a custom calendar, please do not hesitate to ask me.

2) Make the happiness of fundamentalism configurable. For example, instead of all citizens being content, make only 2 or 3 content. Right now Fundamentalism is too strong once you've got the key technologies.
Unfortunately, the city happiness calculation is one of the mechanics that we can't control with Lua. We can change the first citizen unhappy size on a city by city basis, but that doesn't help with fundamentalism. Lua does enable a lot of other dastardly drawbacks, such as not being able to build certain improvements, or even direct production penalties.

Another idea: can you change the effect of wonders?
You can condition code on whether a tribe has a particular wonder, and you can change when a wonder expires, if you want to remove its original effect.

IMO, there are too many happiness wonders and not enough economic and agricultural ones. Wonders that allow a player to increase either the food, shield or trade output of a specific terrain might be useful.
The Custom Cosmic module has settings for customised terrain production, so this could be done easily.
Or increase the advantage of a particular type of improvement.
The improvement advantages are hard coded, but that wouldn't stop you from giving them some extra benefit, such as marketplaces giving a city trade arrows in addition to the tax/luxury production.
Or perhaps another diplomatic wonder, say allowing the player to reset the alliances of another civ once only. Or to change the type of government of one other civ for a fixed number of turns.
These could be done.
1.Is it possible by hexediting to enable the atttack animations for defending animated units during the combat ?

2. Is it possible by hexediting to give the different units different sounds during their movement ?
These aren't achievable with hex editing or Lua. Well, 2 might be achievable if you're OK with a scenario event repeatedly changing sound files on the player's computer.
 
These aren't achievable with hex editing or Lua. Well, 2 might be achievable if you're OK with a scenario event repeatedly changing sound files on the player's computer.
Thank you very much for your answers. I suggested the solution to 2 some years ago, but it was considered as to be too dangerous.
 
Thank you very much for your answers. I suggested the solution to 2 some years ago, but it was considered as to be too dangerous.
Yes, I was (and am) a bit wary of having code that overwrites files on the player's computer be part of ordinary scenario code. I also don't know if constantly re-writing files would use up SSD write cycles and harm the user's computer.*

However, I did decide to do a proof of concept, which does work for me:
Code:
local movementSounds = {
    ["default"] = "Movepiece_reg.wav",
    [gen.original.uSettlers.id] = "Movepiece_alt.wav",
    [gen.original.uFreight.id] = "Diesel.wav",
}
local currentMoveSound = nil
local soundFolder = gen.getScenarioDirectory().."\\Sound"



discreteEvents.onActivateUnit(function(unit,source,repeatMove)
    local moveSound = movementSounds[unit.type.id] or movementSounds["default"]
    if moveSound ~= currentMoveSound then
        local soundFile, err = io.open(soundFolder.."\\"..moveSound,"rb")
        if err then
            error("Error opening sound file '"..moveSound.."': "..err)
            return
        end
        local fileContent = soundFile:read("*a")
        soundFile:close()
        io.open(soundFolder.."\\Movpiece.wav","wb"):write(fileContent):close()
        currentMoveSound = moveSound
    end
end)

* I don't think it would be too damaging. If you change the move unit sound every second, you get almost 300 hours of gameplay for 1 million overwrites of movpiece.wav . If you're writing 100kB sound files, that uses up 100GB of writes. With some modern games, downloading (and later deleting) a couple games could easily exceed that amount of "wear" for less than 300 hours of play, and no one would think twice about SSD wear. A quick search suggests that SSDs have about 300TB write cycles. Using 100 of them would take a billion writes, or 1 per second for about 32 years.
 
Back
Top Bottom