Modifying Existing XML
Instead of completely replacing a base game XML file in a mod, XML files can be used to alter specific values present in the base game XML files. Changes to GameConstants.xml are a good example of why you would want to do this. GameConstants.xml is a repository of global game settings that runs to several thousand lines of XML. If you only want to change one setting, it's overkill to replace the entire file and you may break other mods that also try to replace the entire file. Instead, you can create a new file with only the required change and add it to the
<AdditionalGameConstantsXMLFiles> <Entry>GameConstantsMod.xml</Entry> </AdditionalGameConstantsXMLFiles>
Inside GameConstantsMod.xml you would place the tag that you want to change and the new value. For example, if you wanted to change the max number of dead bodies left on the battlefield at the highest detail setting you would place this inside your GameConstantsMod.xml file:
<?xml version="1.0"?> <GameConstants> <GameConstantsClass> <CorpseFadeDetailSettingMaxCorpses network="client"> 2500 </CorpseFadeDetailSettingMaxCorpses> </GameConstantsClass> </GameConstants>
The 'network="client"' attribute means that the setting is only read by the client. You should preserve this setting from the original XML file.
Two other attributes to be aware of are the 'append' and 'overwrite' attributes which specify the behavior when modifying existing data collections. 'append' will add your changes to the end of the existing list. 'overwrite' will replace the entire list with your changes.
For example, if you wanted to add an additional quote to the loading screen that would be mixed in with all the others then you would do something like this using the 'append' attribute to preserve the existing quotes:
<?xml version="1.0"?> <GameConstants> <GameConstantsClass> <InspirationalQuotes network="client" append=""> <Entry> <QuoteBodyText>TEXT_BATTLE_LOAD_SCREEN_QUOTES_STEVES_MOD</QuoteBodyText> <QuoteAuthorText>TEXT_BATTLE_LOAD_SCREEN_AUTHOR_STEVE</QuoteAuthorText> <AllowedImages> <Entry>IWM_ART_005219.jpg</Entry> </AllowedImages> </Entry> </InspirationalQuotes> </GameConstantsClass> </GameConstants>
Note that the empty quotes on append="" is intentional and nothing else is needed.
If you wanted to replace all of the existing quotes with just a single new one, instead of using 'append', you would use 'overwrite'.
<?xml version="1.0"?> <GameConstants> <GameConstantsClass> <InspirationalQuotes network="client" overwrite=""> <Entry> <QuoteBodyText>TEXT_BATTLE_LOAD_SCREEN_QUOTES_STEVES_MOD</QuoteBodyText> <QuoteAuthorText>TEXT_BATTLE_LOAD_SCREEN_AUTHOR_STEVE</QuoteAuthorText> <AllowedImages> <Entry>IWM_ART_005219.jpg</Entry> </AllowedImages> </Entry> </InspirationalQuotes> </GameConstantsClass> </GameConstants>
Now your quote will be the only one seen. Unless some other higher priority mod changes InspirationalQuotes again.
XML Syntax for Updates to Existing Object Types
Some game systems use XML definitions that support the "Variant=" attribute which allows newly defined objects to inherit all the data from an existing object definition. The "Modify=" attribute must be used when making changes to existing hierarchical objects. The XML files that support this include the game objects, sound effects events, and music events.
There are examples above of how to modify a single value in
For example, to change just the MaxSpeed of the Unit_VEH_Tank_British_MkI_00 you can either copy the whole Unit_VEH_Tank_British_MkI_00.xml file into the mod and make a one line change, or you can add a new XML file that has just the change you want. The advantage of the second approach is that it won't conflict with any other mod that also changes Unit_VEH_Tank_British_MkI_00 in some other way. To make the targeted change, you would add a new XML file in your mod called something like DATA\XML\Unit_VEH_Tank_British_MkI_00_Mod.xml. Inside that file you would put:
<?xml version="1.0" encoding="utf-8"?> <ObjectTypeList> <ObjectTypeClass Name="Unit_VEH_Tank_British_MkI_00" Modify=""> <WalkLocomotorComponent> <MaxSpeed>200</MaxSpeed> </WalkLocomotorComponent> </ObjectTypeClass> </ObjectTypeList>
Note the Modify="" on the
Then add a reference to the new Unit_VEH_Tank_British_MkI_00_Mod.xml into the DATA\XML\ModConfig.xml like so:
<?xml version="1.0" encoding="utf-8"?> <ModConfigs> <ModConfig> <AdditionalGameObjectXMLFiles> <Entry>Unit_VEH_Tank_British_MkI_00_Mod.xml</Entry> </AdditionalGameObjectXMLFiles> </ModConfig> </ModConfigs>
Now your mod changes just that one value and is compatible with any other mod, as long as it doesn't change the same value on the same unit.
Note that XML variants are resolved before modifications are applied, so modifications made to a base object won't propagate to the variants. You need to use the "Modify=" attribute only on the most derived objects.