Results 1 to 3 of 3

Thread: Perfect ESF<->XML converter - Modifications Tutorial

  1. #1

    Default Perfect ESF<->XML converter - Modifications Tutorial

    ESF<->XML converter - Tutorial

    What is ESF<->XML converter - main thread: http://www.twcenter.net/forums/showthread.php?t=392712

    What is ESF<->XML converter?
    It is .esf files editor created by taw, it converterts files such as startpos from .esf to .xml making it more easy to be edited.

    How to use ESF<->XML converter?
    The easiest way to get it running under Windows is by installing
    JRuby single installer with Java Runtime Environment bundled.
    Here's the link:
    http://jruby.org.s3.amazonaws.com/do...sjre_1_5_3.exe

    For Windows JRuby you need prerelease version of Nokogiri (--pre flag).
    If you have installed other version before, you must also uninstall it first.
    These two commands should do it:

    $ jgem uninstall nokogiri
    $ jgem install nokogiri –pre

    == Usage ==
    $ ./esf2xml foo.esf foo_dir
    $ ./esf2xml --quiet foo.esf foo_dir
    $ ./xml2esf foo_dir foo.esf

    esf2xml automatically prints progressbar unless told not to by --quiet option
    (xml2esf might get this too later)

    To run with specific Ruby version use like:
    $ ruby ./esf2xml foo.esf foo_dir
    $ jruby --server -J-Xmx2048m ./esf2xml foo.esf foo_dir

    You might want to specify higher memory limit like -J-Xmx2048m option,
    default JVM max heap size is ridiculously small 500MB, half of it
    going to JVM overhead.

    Passing --server to jruby speeds it up by about 10%, so do it.


    == Unpacked Directory ==
    Main file in unpacked directory is always esf.xml
    There might be other files as well, xml, bitmap, or anything else.
    By: taw

    Scripts:
    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

    By: taw

    List of ids

    Spoiler for factions ids

    afghanistan: 699851360
    austria: 297040272
    barbary_states: 297051832
    bavaria: 706318120
    britain: 297003280
    chechenya_dagestan: 297017152
    cherokee: 699239152
    colombia: 706336616
    courland: 700383800
    crimean_khanate: 297021776
    denmark: 297014840
    france: 297049520
    genoa: 297037960
    georgia: 297019464
    greece: 297028712
    hannover: 698056392
    hessen: 297007904
    hungary: 706329680
    huron: 297054144
    inuit: 706311184
    ireland: 706331992
    iroquoi: 699366848
    knights_stjohn: 297005592
    louisiana: 698861288
    mamelukes: 297031024
    maratha: 297058768
    mexico: 699494544
    morocco: 706313496
    mughal: 297061080
    mysore: 699872016
    naples_sicily: 700023920
    netherlands: 297056456
    new_spain: 297063392
    norway: 297012528
    ottomans: 297042584
    papal_states: 698130408
    piedmont_savoy: 297035648
    pirates: 706338928
    plains: 698126112
    poland_lithuania: 297047208
    portugal: 706315808
    prussia: 297024088
    pueblo: 699049752
    punjab: 706322744
    quebec: 706334304
    russia: 698383912
    safavids: 297065704
    saxony: 706325056
    scotland: 700388072
    spain: 297010216
    sweden: 297044896
    thirteen_colonies: 699086792
    united_states: 698165400
    venice: 297033336
    westphalia: 297026400
    wurttemberg: 706320432

    Spoiler for regions ids


    Code:
    Region name    |      id      | cai id
    acadia  709101912       3485
    afghanistan     708827832       1578
    ahmadnagar      709659200       2861
    algiers 708913496       1593
    algonquin_territory     709392376       3402
    alsace  705860840       2220
    anatolia        709284008       1704
    arkhangelsk     705856160       2673
    armenia 705858032       1804
    astrakhan       709645160       2174
    austria 709383952       1956
    azerbaijan      708921688       1734
    bahamas 709649840       3245
    baluchistan     709098168       1530
    bashkira        708647608       2516
    bavaria 709391440       2093
    belarus 708831576       2314
    bengal  708825024       2919
    berar   709388632       2873
    bijapur 708649480       2807
    bohemia 708909752       2260
    bosnia  709284944       1992
    bulgaria        709402208       2020
    carnatica       708650416       2732
    carolinas       709289624       3313
    ceylon  709286816       2758
    chechenya-dagestan      705869264       1879
    cherokee_territory      709650776       3289
    corsica 709386760       1816
    courland        709095360       2602
    crimea  708828768       2038
    croatia 709394248       1976
    cuba    708915136       3211
    curacao 709655456       3124
    denmark 708917944       2546
    don_voisko      709100040       2056
    dutch_guyana    705863648       3063
    egypt   705865520       1441
    england 708656032       2186
    estonia_and_livonia     708645736       2643
    finland 708825960       2685
    flanders        709278392       2245
    florida 709397056       3229
    france  709644224       1891
    french_guyana   709277456       3053
    galicia 709287752       2297
    genoa   709656392       1942
    georgia 709399400       1867
    georgia_usa     708919816       3305
    gibraltar       709395184       2726
    great_plains    706953200       3499
    greece  709000800       1683
    guatemala       708652288       3108
    gujarat 709281200       2890
    hannover        709275584       2361
    hindustan       708648544       2973
    hispaniola      709282136       3191
    hungary 709096296       2115
    huron_territory 708657904       3509
    hyderabad       709403144       2825
    iceland 708658840       2716
    ingria  708997056       2659
    ireland 708918880       2347
    iroquois_territory      707709968       3463
    jamaica 708999864       3183
    kaintuck_territory      708997992       3342
    karelia 709387696       2702
    kashmir 709276520       3020
    komi    705857096       2616
    labrador        708908816       3570
    leeward_islands 709389568       3175
    lithuania       708920752       2465
    lower_louisiana 709279328       3273
    maine   709290560       3475
    malabar 709647968       2795
    malta   708654160       1662
    malwa   706955936       2904
    maryland        709400336       3384
    mesopotamia     709097232       1560
    michigan_territory      709652648       3390
    milan   709285880       2068
    moldavia        709653584       2144
    morea   708826896       1668
    morocco 705855224       1464
    muscovy 705864584       2486
    mysore  708906944       2775
    naples  709396120       1782
    netherlands     708907880       2375
    new_andalusia   705868328       3080
    new_england     709100976       3431
    new_france      709405016       3524
    new_grenada     709099104       3030
    new_mexico      709001736       3265
    new_spain       708651352       3145
    new_york        708646672       3414
    newfoundland    709647032       3542
    northwest_territories   705858968       3582
    norway  706956848       2622
    ontario 709648904       3449
    orissa  708998928       2841
    palestine       709401272       1495
    panama  708910688       3096
    pennsylvania    708659776       3370
    persia  709384888       1506
    poland  709385824       2430
    portugal        709398464       1754
    prussia 705861776       2450
    punjab  709002672       3000
    rajpootana      709393312       2953
    rhineland       708829704       2229
    rumelia 708830640       1849
    ruperts_land    705859904       3556
    sardinia        708655096       1772
    savoy   709383016       1930
    saxony  709003608       2275
    scotland        708911624       2531
    serbia  709390504       2007
    silesia 709657328       2287
    sindh   705866456       2939
    spain   708916072       1630
    sweden  709283072       2570
    syria   708656968       1610
    tatariya        709646096       2154
    tejas   705862712       3253
    the_papal_states        709654520       1827
    transylvania    708917008       2132
    trinidad_tobago 709288688       3590
    tripoli 705870200       1482
    tunis   709651712       1543
    ukraine 705867392       2333
    upper_louisiana 709404080       3329
    venice  708912560       2078
    virginia        708653224       3354
    west_pommerania 709280264       2392
    west_prussia    709382080       2412
    windward_islands        709658264       3134
    wurttemberg     708644800       2105


    MODIFICATIONS

    Index



    Make faction playable:
    Spoiler Alert, click show to read: 
    To make a faction playable use taw’s script make one faction playable:

    E.g make Portugal playable:
    jruby scripts/make_faction_playable portugal startpos.xml

    E.g make all minor nations playable (doesn't include emergent neither protectorates):
    jruby scripts/make_more_vanilla_factions_playable startpos.xml


    Change starting treasury:
    Spoiler Alert, click show to read: 
    To change the starting treasury of a faction use taw’s script change one/all faction's starting treasury.

    E.g change Portugal treasury to 11000
    jruby scripts/starting_treasury startpos.xml portugal 11000


    Make minor faction major:
    Spoiler Alert, click show to read: 
    To make a minor nation major use taw’s script make_faction_major.

    E.g make Portugal major
    jruby scripts/make_faction_major startpos.xml portugal

    E.g make all factions major
    jruby scripts/make_all_factions_major startpos.xml


    Make major faction minor:
    Spoiler Alert, click show to read: 
    To make a minor nation major use taw’s script make_faction_major.

    E.g make France minor
    jruby scripts/make_faction_minor startpos.xml france


    Change factions capital:
    Spoiler Alert, click show to read: 
    To change the capital of a faction use taw’s script faction_capital.

    E.g make France Portuguese capital
    jruby scripts/faction_capital startpos.xml portugal France


    Change victory conditions:
    Spoiler Alert, click show to read: 
    To change the victory conditions go inside the startpos.xml -> victory_conditions, and open the faction that you want to change.

    E.g change Portuguese short campaign Vic. Conditions.
    Spoiler Alert, click show to read: 


    Add victory conditions:
    Spoiler Alert, click show to read: 
    Some factions don't have victory conditions, to add them go inside the startpos.xml -> victory_conditions:
    • make a copy of victory_conditions file for any existing faction
    • adjust to new faction - change name, region list, and possibly region count
    • go into "preopen_map_info" open the existing file
    • add <xml_include path="victory_conditions/{name of the faction}.xml"/>

    E.g: Adding vic. conditions to Venice:
    Spoiler Alert, click show to read: 



    Change type of government:
    Spoiler Alert, click show to read: 
    There are 3 types of government:
    • gov_constitutional_monarchy
    • gov_absolute_monarchy
    • gov_republic


    • To change the type of government of faction go into government folder
    • Open the faction that you want to change
    • 4th line contains the type of government, change it to the one that you want
      Spoiler Alert, click show to read: 
    • Change the name of the file for the type of government that you have change it:

      E.g: United States are a republic, if you change it to a constitutional monarchy rename the file to "united_states-gov_constitutional_monarchy"


    Change available technologies:
    Spoiler Alert, click show to read: 
    To give techs to a faction use taw’s scripts give_all_techs and give_tech.

    E.g give Portugal a tech.:
    jruby scripts/give_tech startpos.xml portugal {name of the tech.}

    E.g give Portugal all techs.:
    jruby scripts/give_all_techs startpos.xml Portugal


    Change a faction religion:
    Spoiler Alert, click show to read: 
    To change the religion of a faction use taw’s script faction_religion

    This are the vanilla types of religion:
    • rel_hindu
    • rel_nonconformist
    • rel_sikh
    • rel_animist
    • rel_orthodox
    • rel_buddhist
    • rel_catholic
    • rel_islamic
    • rel_protestant


    E.g change Portuguese religion
    jruby scripts/faction_religion startpos.xml portugal {religion name}


    Change amount of religion followers by region:
    Spoiler Alert, click show to read: 
    To change the amount of religion followers:
    • Go into population folder
    • Open the region that you want to change
    • Go to line No. 106
    • «1.0» means 100% of followers, 0.2 means 20% and so on
      Spoiler Alert, click show to read: 
    • Do the changes that you want to do and exit



    Change turns/year:
    Spoiler Alert, click show to read: 
    To change the number of turns per year use taw’s script turns_per_year

    E.g 8 turns per year
    jruby scripts/turns_per_year startpos.xml 8


    How to active towns/ports:
    Spoiler Alert, click show to read: 
    To active ports and towns go to region_slot folder and open the slot that you want to change

    Without building:
    Go to line 27th
    Change «no» to «yes»

    With building (town)
    Go to line 27th
    Change «no» to «yes»
    Open a slot with a building that you want to have in other slot
    Inside the slot with the building that you want, copy line 28
    Go to the slot that you want to add a building and past in line 28
    Make sure that now your moded slot has 46 wroten lines
    Save and exit

    E.g: Add school to Faro
    Spoiler Alert, click show to read: 


    With building (port)
    Go to line 27th
    Change «no» to «yes»
    Open a slot with a building that you want to have in other slot
    Inside the slot with the building that you want, copy line 28
    Go to the slot that you want to add a building and past in line 28
    Go to line 37 change «0» to «1»
    Line 38 change «no» to «yes»
    Go to the slot with the port that you want to add to the other slot and copy from line 43 to the last one
    Go the the slot that you want to add the port, delete from line 43 to last one
    Past what you've copy from the slot with the port
    Make sure that your moded slot has now 56 wroten lines
    Save and exit



    Thanks to Taw for the tool
    husserlTW for his STARTPOS.ESF analysis and modifications thread

    To continue...
    Last edited by ForteS; March 20, 2011 at 01:00 PM.

    UNDER THE MOST HONORABLE PATRONAGE OF: Legio!
    PATRON OF: Wangrin, ♔Sir Digby Chicken Caesar♔, Geronimo2006 and Narf!

  2. #2
    Artifex
    Patrician

    Join Date
    Oct 2008
    Location
    London, UK
    Posts
    1,332

    Default Re: Perfect ESF<->XML converter - Tutorial

    Huge thanks for your tutorial.

    A few additions and corrections below:
    jruby scripts/give_tech startpos.xml {name of the tech.} portugal
    jruby scripts/faction_religion startpos.xml {religion name} Portugal
    Faction name goes before any other arguments in all scripts:jruby scripts/give_tech startpos.xml portugal military_ordnance_canister_shot

    jruby scripts/faction_religion startpos.xml portugal rel_protestant

    Also many commands accept wildcards "*" for faction names or technology names:

    jruby scripts/give_tech startpos.xml portugal "military_navy_*"
    jruby scripts/give_tech startpos.xml portugal "*"

    jruby scripts/give_tech startpos.xml "*" "military_navy_sextant"

    Or even:

    jruby scripts/give_tech startpos.xml "*" "military_navy_*"

    Victory conditions now look like this, so it's even easier to edit:

    Code:
      <rec type="VICTORY_CONDITIONS_BLOCK">
       <victory_conditions year="1799" region_count="35" prestige_victory="no" campaign_type="1 (long)">
        naples
        portugal
        austria
        flanders
        netherlands
        spain
        curacao
        morocco
        milan
        gibraltar
        tejas
        trinidad_tobago
       </victory_conditions>
      </rec>
    Unfortunately most factions do not have any victory conditions in vanilla's startpos.esf,
    so you need to follow these slightly more complicated instructions to give them victory conditions.
    I might turn this into a script someday.

    E.g make all minor nations playable:
    jruby scripts/make_more_vanilla_factions_playable startpos.xml


    Also this doesn't currently apply to protectorates, if you made new_spain or some other
    such country not a protectorate, you'll need to make it playable manually.

    If you need any more help, just ask.

  3. #3

    Default Re: Perfect ESF<->XML converter - Tutorial

    Quote Originally Posted by taw View Post
    Huge thanks for your tutorial.

    A few additions and corrections below:
    Faction name goes before any other arguments in all scripts:
    jruby scripts/give_tech startpos.xml portugal military_ordnance_canister_shot

    jruby scripts/faction_religion startpos.xml portugal rel_protestant

    Also many commands accept wildcards "*" for faction names or technology names:

    jruby scripts/give_tech startpos.xml portugal "military_navy_*"
    jruby scripts/give_tech startpos.xml portugal "*"

    jruby scripts/give_tech startpos.xml "*" "military_navy_sextant"

    Or even:

    jruby scripts/give_tech startpos.xml "*" "military_navy_*"

    Victory conditions now look like this, so it's even easier to edit:

    Code:
      <rec type="VICTORY_CONDITIONS_BLOCK">
       <victory_conditions year="1799" region_count="35" prestige_victory="no" campaign_type="1 (long)">
        naples
        portugal
        austria
        flanders
        netherlands
        spain
        curacao
        morocco
        milan
        gibraltar
        tejas
        trinidad_tobago
       </victory_conditions>
      </rec>
    Unfortunately most factions do not have any victory conditions in vanilla's startpos.esf,
    so you need to follow these slightly more complicated instructions to give them victory conditions.
    I might turn this into a script someday.

    E.g make all minor nations playable:
    jruby scripts/make_more_vanilla_factions_playable startpos.xml


    Also this doesn't currently apply to protectorates, if you made new_spain or some other
    such country not a protectorate, you'll need to make it playable manually.

    If you need any more help, just ask.
    Thanks for your corrections Taw, I'll correct it now

    UNDER THE MOST HONORABLE PATRONAGE OF: Legio!
    PATRON OF: Wangrin, ♔Sir Digby Chicken Caesar♔, Geronimo2006 and Narf!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •