[SDK] XML Load

Chinese American

Hamtastic Knight
Joined
Aug 23, 2001
Messages
432
Location
Chinatown, USA
CAUTION:
This mod is obsolete. It has been integrated into native Firaxis code with the BTS expansion. Also, World of Civilization is creating an improved version over Firaxis'.
There are also other versions by Impaler under the name Modular XML, but these are essentially the same as Firaxis'.

XML Load : SDK mod component
v 1.2
Download link:
http://forums.civfanatics.com/downloads.php?do=file&id=2681&act=down

--[[ === Synopsis

For casual or experienced modders who just want to add new units and buildings without copying the huge original files. Use this mod as a launcher to hold your compilation of favorite mod components, or incorporate the SDK code component into your mods.

Will replace old and load new units, buildings, improvements, builds, techs, traits, leaderheads, civilizations.

--[[ === Details

This mod component lets you use partial xml files instead of huge original files. It'll read in extra files without mandatory original Firaxis files inside the mod's folder. A partial file contains only the entries of the things not found in the vanilla game. An example is XMLLoad_Looter_CIV4UnitInfos.xml which I put in this mod. Be sure to include the headers and footers, like this segment example:
HTML:
<Civ4UnitInfos xmlns="x-schema:CIV4UnitSchema.xml">
	<UnitInfos>
	.
	.
	.
	</UnitInfos>
</Civ4UnitInfos>

What it does is read in files that match *_CIV4UnitInfos.xml and add those entries into the game. So in this folder, Mods\XMLLoad\Assets\XML\Units\, could contain XMLLoad_CIV4UnitInfos.xml and nothing else. You don't need the original files. Whereas before, you would have to add your new units into the huge CIV4UnitInfos.xml and put that inside your mod folder.

If you don't want to use the vanilla units, then you would make your own CIV4UnitInfos.xml and put that into your mod folder. This works just like before.

If you want to borrow another mod's units, copy or make the partial file or composite file into the units folder and rename it if necessary, such as HisMod_CIV4UnitInfos.xml. So your units folder may have two files, MyMod_CIV4UnitInfos.xml and HisMod_CIV4UnitInfos.xml, and both will be added to the game. Or you could just use his file and not even make your own.

Be aware that duplicate entries will replace older entries already in the game. If a new version of Workers are found, then this one will be used in the game. This is useful to replace Workers so that they can build new improvements.

Unfortunately, new and replacement buildings may cause a serious bug where some buildings will get a huge amount of happiness. The best remedy is to put replacements in *_CIV4BuildingInfos.xml files and new buildings in *_Infos.xml or *_BuildingInfos.xml files.

--[[ === Files that can be read

This section lists the patterns of file names that can be understood by this mod (so far). The asterisk * represents any set of legal characters that you can normally put in file names. Everything else after the asterisk must be exact. The path to the file is also important. Put only correct entries into the appropriate file. Thus, art defines for units go in xml\art\*_CIV4ArtDefines_Unit.xml.

The List:
Spoiler :
UNITS:
<< ARTS >>
xml\art\*_CIV4ArtDefines_Unit.xml
xml\units\*_UnitArts.xml (do not include schema)
xml\units\*_Arts.xml (do not include schema)
<< UNIT CLASSES >>
xml\units\*_CIV4UnitClassInfos.xml
xml\units\*_UnitClasses.xml
xml\units\*_Classes.xml
<< UNITS >>
xml\units\*_CIV4UnitInfos.xml
xml\units\*_UnitInfos.xml
xml\units\*_Infos.xml
xml\units\*_Units.xml

BUILDINGS:
<< ARTS >>
xml\art\*_CIV4ArtDefines_Building.xml
xml\buildings\*_BuildingArts.xml (do not include schema)
xml\buildings\*_Arts.xml (do not include schema)
<< BUILDING CLASSES >>
xml\buildings\*_CIV4BuildingClassInfos.xml
xml\buildings\*_BuildingClasses.xml
xml\buildings\*_Classes.xml
<< BUILDINGS >>
xml\buildings\*_CIV4BuildingInfos.xml (replacements should go here; don't put new buildings here)
xml\buildings\*_BuildingInfos.xml
xml\buildings\*_Infos.xml
xml\buildings\*_Buildings.xml

TECHNOLOGIES:
xml\technologies\*_CIV4TechInfos.xml
xml\technologies\*_TechInfos.xml
xml\technologies\*_Infos.xml
xml\technologies\*_Techs.xml

IMPROVEMENTS:
<< ARTS >>
xml\art\*_CIV4ArtDefines_Improvement.xml
xml\terrain\*_ImprovementArts.xml (do not include schema)
<< IMPROVEMENTS >>
xml\terrain\*_CIV4ImprovementInfos.xml
xml\terrain\*_ImprovementInfos.xml
xml\terrain\*_Improvements.xml

BUILDS:
xml\units\*_CIV4BuildInfos.xml
xml\units\*_BuildInfos.xml
xml\units\*_Builds.xml

TRAITS:
xml\civilizations\*_CIV4TraitInfos.xml
xml\civilizations\*_TraitInfos.xml
xml\civilizations\*_Traits.xml

LEADERHEADS:
<< ARTS >>
xml\art\*_CIV4ArtDefines_Leaderhead.xml
xml\civilizations\*_LeaderheadArts.xml (do not include schema)
<< LEADERS >>
xml\civilizations\*_CIV4LeaderheadInfos.xml
xml\civilizations\*_LeaderheadInfos.xml
xml\civilizations\*_Leaderheads.xml

CIVILIZATIONS:
<< ARTS >>
xml\art\*_CIV4ArtDefines_Civilization.xml
xml\civilizations\*_CivilizationArts.xml (do not include schema)
<< CIVS >>
xml\civilizations\*_CIV4CivilizationInfos.xml
xml\civilizations\*_CivilizationInfos.xml
xml\civilizations\*_Civilizations.xml


--[[ === SDK files for modders

The changes I made are found in the files under SDK folder and are marked by // CA edit.
For example:
Code:
// CA edit -- added function AddGlobalArtDefineInfo
	template <class T>
	DllExport void AddGlobalArtDefineInfo(T **ppArtDefneInfos, char* szXMLFileName, char* szTagName, int& iNumVals);
// CA edit end

--[[ === Version History

Spoiler :
1.0
Reads partial xml files for *_CIV4ArtDefines_Unit.xml, *_CIV4UnitClassInfos.xml, *_CIV4UnitInfos.xml.

1.1
Will replace old types with new ones.
Reads partial xml files for *_CIV4ArtDefines_Building.xml, *_CIV4BuildingClassInfos.xml, *_CIV4BuildingInfos.xml.

1.2
Workaround for bug where buildings get obscene happiness from new buildings.
Added reading techs, improvements, builds, traits, leaderheads, civilizations.
Reads partial xml files for *_Arts.xml, *_Classes.xml, and *_Infos.xml in xml\units\ and xml\buildings\.
Reads partial xml files for *_UnitArts.xml, *_UnitClasses.xml, *_UnitInfos.xml, and
*_Units.xml in xml\units\.
Reads partial xml files for *_BuildingArts.xml, *_BuildingClasses.xml, *_BuildingInfos.xml, and *_Buildings.xml in xml\buildings\.
Reads partial xml files for *_CIV4TechInfos.xml, *_TechInfos.xml, *_Techs.xml, and *_Infos.xml in xml\technologies.
Reads partial xm files for *_CIV4ImprovementInfos.xml, *_ImprovementInfos.xml and *_Improvements.xml in xml\terrain, and xml\art\*_CIV4ArtDefines_Improvement.xml and xml\terrain\*_ImprovementArts.xml.
Reads partial xml files for *_CIV4BuildInfos.xml, *_BuildInfos.xml and *_Builds.xml in xml\units.
Reads partial xml files for *_CIV4CivilizationInfos.xml, *_CivilizationInfos.xml and *_Civilizations.xml in xml\civilizations\, and xml\art\*_CIV4ArtDefines_Civilization.xml and xml\civilizations\*_CivilizationArts.xml.
Reads partial xml files for *_CIV4LeaderheadInfos.xml, *_LeaderheadInfos.xml and *_Leaderheads.xml in xml\civilizations\, and xml\art\*_CIV4ArtDefines_Leaderhead.xml and xml\civilizations\*_LeaderheadArts.xml.
 
This sounds good. I'd always wondered why Civ4 mods didn't have partial XML files, since the only other modding scene I've encountered which extensively uses XML files (Freelancer) has partials.
 
I had though of trying something like this, but had deseded Mod-Switcher was a better means solution, sadly ModSwitcher never caught on like it should have (its realy a wonderfull program after the initial learning/setup curve the ease of combining mods is incredible)

I would recomend that you make it read off of a "Custom" folder inside the Unit/Building directories, that will help keep new/old content from getting cluttered, also you can do away with the strict file names and just grab every XML file in the folder, that would make things a bit more idiot proof. So for example the path for the new units would be /XML/units/Custom/*.xml

This concept could be taken even further, rather then spread the units/Buildings information over several file directories it should theorticaly be possible to combine them all into one folder, though strict naming would be required to keep things strait. It would also require a means of getting the folder names on a vector. Art files could reside their as well creating a single drag-and-drop folder to fully add/remove a Custom unit/Building from the game. If the idea proves popular I might try implementing this as an extention of your code.

Also I resently tried doing something similar with GlobalDefines, intending for a folder of new Defines that would be read much like the text folder (grabs everything) but was having a problem with how the LoadGlobalDefines function takes its file name argument. Perhaps you would like to take a look at it over in the WL CCCP thread. Not suprisingly I think I'll add this to CCCP if anyone plans to use it.
 
Great Job Chinese American :goodjob:
 
Thanks for everyone's comments.

I tried to read *Civ4UnitInfos.xml , without underscore, and it would read the original file even if it's not in the mods folder. If you do have a Civ4unitInfos.xml, then there would be conflicting versions. So I just added an underscore.

If you want to put everything in a subfolder, then this would not be problem. However I don't think that's necessary. Perhaps just check the file name against Civ4UnitInfos.xml so we know it's reading a partial file. In the long run, subfolders could work.

I think some kind of naming convention is helpful to keep everything easy to manage for both modders and users. Probably just shorten the names, say *_Infos, *_Classes, *_Arts, etc.

Inside function SetGlobalDefines, they list specifically "xml\\GlobalDefines.xml" and "xml\\GlobalDefinesAlt.xml". If you want to read other files, make a files array like I do and the run them through a loop. That's also how they read all the GameTexts. In fact, I should add this to this mod.
 
I've spent half a day trying to figure out how to get folders enumerated and low and behond I find that the enumeratefiles function CAN search recusivly. This means it will be possible to use your mod to add content in more organized folders.

I'm currently working to create a more elegant version that uses a LoadEnumeratedCivXMLFiles function to replace the large blocks of code.

I was wondering if extra files were loaded imediatly after the defaults like so

bLoaded = LoadCivXml(m_pFXml, "Units/CIV4UnitClassInfos.xml");
if (!bLoaded)
{...Error Message}
bLoaded = LoadEnumeratedCivXmlFiles(m_pFXml, "xml\\units\\*_CIV4UnitClassInfos.xml");
if(!bLoaded)
{...Error Message}
if (bLoaded && Validate())
{
SetGlobalUnitClassInfo(&GC.getUnitClassInfo(), "Civ4UnitClassInfos/UnitClassInfos/UnitClassInfo", &GC.getNumUnitClassInfos(), &pszDefaultUnits);
}


wouldn't it be possible to skip the AddGlobalClassInfo function as the normal SetGlobalClassInfo would catch everything?
 
enumerated files will not be treated as a single file. SetGlobalClassInfo will make a new array for each file, so the last one will be the only data for the game. That's why you need AddGlobalClassInfo to expand the array and keep the older data. however, it should be safe to use AddGlobalClassInfo without calling SetGlobalClassInfo first.

enumerateFile creates a vector of file names. this works easily for text because the game will accept new text data. for other things, it wouldn't do any good unless you expand their arrays.

also, some things might not use the general SetGlobalClassInfo, like buildings and techs.
 
Hi!

What should "do not include schema" tell me?
I have some xml files with new tags included. So I changed the schemas and the SDK code to read them. How can I use this with your modification?

Matze
 
I've incorporated a modified version version of your XML loading in my CCCP compilation Dll. The main change involved the naming conventions. I've changed most files to load with the following kind of string pattern.

"xml\\*_CIV4UnitInfos.xml

In all cases the ending is the root element of the XML file pre-pended with an underscore. This should help people keep things strait. By dropping the folders that would normaly come under XML the moder can combine all the files for a particular piece of new content under a single folder which can be located basicaly Anyware under the xml directory. The downside is a copy of the apropriate schema must be included their as well so this solution is less efficient in file size for a ready to play download but is more modular and easier to use.

I have a proof of concept downloadable folder that adds the Mark V tank, in principle any unit or new game element should be able to be packaged up like this in a single folder. Buildings though require Lsystem references so any new buildings will have to modify that file as well. Hopefully some kind of solution can be found for that someday.

The modified code is in the CCCP Warlords CoreDll 2.00.05 same 2 files as CA modified, 99% of the code is his, I just modified a few file paterns and moved some functions around for neatness. The movment of LeaderHead loading is for a seperate mod of mine and wont cause any ill effects.
 
MatzeHH said:
Hi!

What should "do not include schema" tell me?
I have some xml files with new tags included. So I changed the schemas and the SDK code to read them. How can I use this with your modification?

Matze

normally art defines headers look like this
<Civ4ArtDefines xmlns="x-schema:CIV4ArtDefinesSchema.xml">

for those files that say dont put schema, their headers should look like this
<Civ4ArtDefines>
 
Well, I found out how to deal with schemas by myself in the meantime. Works great!

Your code also works with Warlords, just a little fine tuning was needed.

Matze
 
Will Bonusses, Interface and Wondermovies (art defines) be included in this in the near future?
Because at the actual state it's senseless to make new wonders modular, because we'll have to add the art defines for the videos into the original files.
 
Also theirs the LCityPlot problem, buildings have to be referenced thier inorder to actualy apear. I think we wil have to modify this so the Leaf size can be placed on the Building Schema.
 
I think Fall from Heaven also has modifications to the same file and thus its not "safe" to just ram all the changes in, to be reasonaly shure its going to work you need to examine every diff and carfully look for any imcompatabilities. Also If I remember correct FFH has unique new files it loads for things like magic spells, if youd didnt have a copy of one of these it might cause a problem, but I'm realy just speculationg. Kael could probably have a better idea of how robust/fragile the loading in FFH is and if he examines this code could recomend a means of combining it.
 
I think there might be an issue with this and Warlords...

I get the following errors when trying to compile:

CvXMLLoadUtilitySet.cpp
CvXMLLoadUtilitySet.cpp(2720) : error C2039: 'setFreeBuilding' : is not a member of 'CvBuildingInfo'
c:\Users\Sarke\Desktop\CIV4SDK\CVGameCoreDLL\CvInfos.h(1508) : see declaration of 'CvBuildingInfo'
CvXMLLoadUtilitySet.cpp(2785) : error C2039: 'setFreeBuilding' : is not a member of 'CvBuildingInfo'
c:\Users\Sarke\Desktop\CIV4SDK\CVGameCoreDLL\CvInfos.h(1508) : see declaration of 'CvBuildingInfo'
CvXMLLoadUtilitySet.cpp(2793) : error C2039: 'setFreeBuilding' : is not a member of 'CvBuildingInfo'
c:\Users\Sarke\Desktop\CIV4SDK\CVGameCoreDLL\CvInfos.h(1508) : see declaration of 'CvBuildingInfo'

Just to check something, I used your already compiled version and it crashed to desktop. Any ideas?
 
Back
Top Bottom