For way too long editing esf was slow and painful process. I remember spending something like two hours just to remove all settlement fortifications.
Then came esf2xml, and it became a 15 minute text editor search and replace job, after a bit of practice.
Now comes the next logical step in esf editing - fully automatic transformations.
XML is just so damn easy to convert with scripts, why even bother with text editors?
And thanks to husserlTW's gui for esf editing soon you won't even need any command line.
How they work
Esf transformation scripts work on xml form, so what you need to do is:
- convert esf to xml
- run all scripts you want one after another
- convert xml to esf back
Scripts modify directory full of unpacked xmls in place.
Available scripts
Available scripts so far (a lot more coming soon):
Faction editing - most commands accept either faction name or "*" to apply to all factions:
- make one faction playable (doesn't fix fog of war bug itself, may crash if you try to play emergent or rebel factions etc. - the usual caveats apply)
- make all vanilla non-emergent campaign minor factions playable
- make one/all faction major
- make faction minor
- change faction's religion
- change faction's capital region (by name obviously, script handles name to id mapping automatically)
- change one/all faction's starting treasury
- give faction one technology (research points is db-dependent, but doesn't seem to matter, so it's just set to status=0, research_points=1000.0), or multiple technologies specified by pattern like military_*
- give faction all possible technologies (awesome fun for starting as tiny faction)
Reporting:
- List all factions
- List id by faction
- List ids and cai ids by region
- List starting (startpos.esf) or current (for save games) treasury by faction
- Draw regions from regions.esf
Others:
- remove all settlement fortifications from whole map - the very thing which made me start esf<->xml converter
- change turns per year
- remove current resistance to foreign occupation (doesn't prevent it in for future conquests)
- reset diplomacy for all factions
Almost all "level 1" modifications from husserlTW's list have a script ready, except starting date (how is it supposed to work again?) and victory conditions (these have very easy to use xmls in victory_conditions/*, and no obvious scripting interface).
Plus a few things more complicated than that.
New scripts, and requests for more scripts eagerly solicited.
You're not limited to just startpos.esf - any esf can be edited - including savegames!
I'm sure people who try to open campaign map will find some uses for these scripts as well.
Usage example
$ ./esf2xml '/media/c/Program Files (x86)/Steam/steamapps/common/empire total war/data/campaigns/main/startpos.esf' vanilla_startpos
$ ./scripts/remove_all_fortifications vanilla_startpos
$ ./xml2esf vanilla_startpos startpos_without_fortifications.esf
And this used to take a few hours, imagine that!
How to write your own scripts
But wait, there's more!
Unlike esfxml code which is pretty hardcore, esf transformation scripts are ridiculously simple.
Here's one for making chosen faction major (ignoring some boiletplate):
class MakeFactionMajor < EsfScript
def run!(faction_to_change)
update_faction(faction_to_change) do |faction|
faction.xpath("yes|no")[2].name = 'yes'
true
end
end
end
If you know even a tiny bit of Ruby or Python, or anything vaguely similar,
and have even heard of xml and xpath, it will be no problem whatsoever
to write a script like that yourself.
Not everything can be achieved so easily - but a lot of thing can.
About the only non-trivial aspect of it is that you need to return true if you modified dom tree, or false otherwise, to avoid unnecessary xml re-saving.
Also node.name means xml tag name (<foo>); node['foo'] means attribute (foo='bar'); and node.content means inner text (<foo>x</foo>)
I'll write tutorial for writing such scripts if there's demand for it.
Requirements
Scripts require just what esfxml needs - Ruby or JRuby and nokogiri gem (jgem install nokogiri --pre). It runs on pretty much any operating system.
If you modify xml_split.rb too much, scripts might not be able to find relevant xml files to change. It's better to use it with default xml_split.rb
All scripts are available together with esfxml from etwng repository.
Good modding!





Reply With Quote









