Tutorial on Mod-Merging
By Ninja2
Intro (and who am I?)
This tutorial is aimed at providing some help for players who like mods, and who want to play more than one mod combined. I have succesfully merged quite a few full mods, components and other tweaks into a single, playable mod, the Merged Mod. I will use my experience from that work in this tutorial, to provide you some guidance as to how to tackle some of the problems that might crop up. You are free to ask questions in this thread about merging, and I will try to help you the best I can. But please, take some time to get into this stuff yourself, I will not do it for you, Ill only give advice, as I dont have time to mod anything but my own stuff! It is a much more rewarding experience, when you yourself manage to put bits and pieces together, and find out that it actually works! I dont want to take that experience away from you.
I should also point out that I am not a programmer by profession. This tutorial is for absolute beginners! Going into this, all I knew was a little HTML. And anyone who reads this, probably knows how little help a little HTML is! I started out by playing mods such as Wolfshanze and Dales Combat Mod, and decided that it would be really awesome if I could have both mods going at the same time. Working with this stuff has actually taught me a lot about programming and data structuring not that Ill ever need it in my own profession, but it has been a fun experience all along, seeing as I could follow the progress, and feel a little like I was playing my own game (even though I didnt actually program much).
Merging mods is really all about identifying differences in data files, and then figuring out which differences you want to keep, which ones you want to merge, and which ones you want to delete. It all comes down to this exercise. Your goal is to build new data files that hold both the changes from the two original files, and then making those changes work in tandem. If two mods do not modify the same file(s), it is as easy as copy-pasting these different files into the proper folders, and youre done!!
This guide is divided into three sections: First is understanding mods, the second section concerns tools for merging, and the third is about planning your work. First of all, it is necessary to study a little bit on the data structure of CIV4, to find out what a mod really is. There are some excellent threads about modding which you should get into reading. If you already feel comfortable about different the types of data in CIV4, XML, Python and source code, you can skip right ahead to the next section! Section two goes more into detail about the practicalities of merging, how its done, pitfalls to avoid and so on. The last section deals with various recommended tools that Ive used myself when merging.
So, here we go!
Understanding mods
What are mods
Mods are modifications, or edits, to the basic game. You can mod anything you want, if you have the right skills. You can mod graphics, stats, interfaces, even the detailed workings of the engine itself. All the various mods and scenarios that ship with Beyond the Sword are basically modifications to the original game. Mods come in many shapes and sizes some are full conversion mods (like Final Frontier) where nothing is like CIV4, and some are only slightly changed versions of the original game, like Blue Marble, for example, which only changes the appearance of the terrain. Most of the stuff that go into mods are made by users, and shared on Civfanatics. You are free to use pretty much anything made by anyone here, as long as you give them the proper credit for their work! There is a lot of useful info for you on most aspects of modding in this forum, and on this wikipage.
Modular mods
Some mods are only modular, which means that they only contain the actual changes to the basic files. This makes them into add-ons, rather than replacements. I will mainly be discussing regular mods, which in principle replace one entire file for another, editted (modded) version. Modular mods dont do this, they simply contain the extra, or modded data, which appends to or replaces the original data when the mod loads. It is somewhat easier to work with modular mods (in theory at least, I havent tried it), since they are easy to switch on or off as you please. When I have come across some stuff in a modular mod that I like, I have just copied the data I want, I pasted it into the appropriate target file, so it always gets loaded but cannot be switched off without editing the data file again.
File structure
Alright, time to look at the data structure of CIV4! On your harddrive, you have CIV4 in a folder. Inside that folder, youll have a folder with Beyond the Sword. Inside that, theres one called Mods. So were at C:\...something...\CIV4\Beyond the Sword\Mods. Here youll see all the standard mods that ship with BTS, and this is also where youll create a folder to hold your own mod components. When you create a folder here and fill it with data, youll be able to load it from the game by selecting Advanced on the Main Menu in the game, and the selecting Load Mod. A list will appear, where your new mod name will be selectable, and this is how you load it up. I should mention that theres another way to mod the game. If you stick your modded files inside \My Documents\My Games\CIV4\Beyond the Sword\Mods instead, your modded files will load with ALL games of CIV4, normal games and other mods. So ONLY do this if youre absolutely certain that you want this particular change to apply for EVERY SINGLE GAME!
You should NEVER overwrite the original files of the game. All mods should start with you creating a new folder, and then copying whatever files you wish to mod into that folder, retaining the original file structure. Its important to note that you ONLY need to copy the files that you are going to edit. The ones you DONt edit will get loaded from the default files. Smart!
*CAUTION* If youre on a Vista system, make SURE that you have administration rights over the folder that holds CIV!!!
Depending on how many things any particular mod changes about the game, there may be more or less files and folders inside said mods directory. All CIV mods contain a folder called Assets. Inside this folder, there will typically be an Art folder, a Python folder and a XML folder. You may also see a file called CvGameCoreDLL.dll. Remember, your goal is to join two mods together, so examining each mods file structure, and see what files they use is an important step.
XML, Python, C++
Mods range in their complexity from very simple to extremely complicated. A mod can be as simple as changing the default combat value for a single unit from its default value, to one that is higher or lower. Mods can also change the game so that it doesnt even feel like youre playing civ anymore. Rules, values, graphics, mechanics, most of anything in civ can be modded. So there is a huge range of possibilities. Part of this range comes from the three levels of modding available to us. You can mod XML files, which are simple text files. You can mod Python files, which are bits of programming that can be made very advanced, or simple. Or, you can do C++ programming, which apart from the actual programming, requires you to set up a process using the SDK, which can compile a working dll file. There are already a couple of great guides on setting up the SDK process:
Refar's guide. Essential reading if you want to set up a compiler for CIV.
EDIT: The below links describe some slightly outdated techniques, although they still contain a lot of useful help and hints.
Installing and using the SDK
Using Microsoft Visual C++ 2005 Express Edition
In order to do any sort of SDK work, you need the source files from the mod you are trying to merge. Usually, the mod author will have provided these files for you, but they are typically found in a separate download location. You'll just have to look or ask around.
Tools for merging
Below are some highly recommended tools for merging, all free. You *could* just do all your editing with the basic Windows Notepad, but your life will be a lot easier if you use a more advanced editor, like Notepad++. There are many useful programs listed on this wikipage, below I've just mentioned the ones that are most relevant for merging.
Winmerge
The MOST vital tool for merging. You should not start to merge anything, without this tool or one that is similar. Winmerge allows you to view two files with identical names side by side in two panes, and then have the program color highlight the sections that are not identical. And finding differences is what merging is all about, remember?! I cannot stress how important this tool really is you can also view two file folders in two panes, and winmerge will show you what files are identical, and which files are different. You can find it at winmerge.org
Editor (Notepad++)
A superb text editor, which will color-code code tags, values, etc for you. You can in fact use your favorite text editor, but this one is just very, very good. You can find it here.
Codeblocks
Codeblocks is a freeware compiling tool. Compiling is the process of converting all the files of code (all files named *.cpp and *.h) into a single file, the CvGameCoreDLL.dll. Again, there are a separate tutorials and guides on setting up Codeblocks (or you can also use Visual Studio Express, which is also free), and you NEED to read these guides to get going!
EDIT: This process is somewhat obsolete, as the guide describing setting this up uses programs that are very difficult to find. Newer versions of CodeBlocks have completely different setups.
Visual Studio 2008 Express
Instead of CodeBlocks, you should use Visual Studio 2008 Express. It does the same thing as CodeBlocks does, it's a compiler. The BIG difference is that VS can make a debug version for you, which is an incredibly powerful way of tracing bugs in a finished dll. So, as you play your CIV game, you can follow the code in a window, and this allows you some insight to see where things go wrong.
7zip
Most of the mod sources youll be downloading will be compressed in some way, so you need a program to decompress. There are a lot of options out there, 7zip is just one of them.
Planning your mod merging
So, now I (think I) have covered the basics. The next step is to plan what mods to merge! You should start out by doing something that is not too big like adding a single component to the default game. Go ahead and choose any component that you find in the Mod Components sub-forum of the Creation & Customization forum. If you can add a component to the basic game sucessfully, you are well on your way! Normally, all components come with installation instructions. They should more or less be step by step instructions, as modders like it when people try out their mods! If you have trouble adding a component, ask a question in the components thread. Once you have figured out how to add a component, go ahead and select another component. It might just be that the two components change two completely separate things about the game, and they might as such be able to coexist without any merging actually done. However, as you increase the number of mods you add, the probability of the mods not clashing will be ever smaller. Eventually, youll be looking at adding several components that all change the dll, or youre even trying to merge two modpacks. And then it is time to do some serious merging!
Your reference: The unmodded game, 3.19
When you set out to mod, always remember that the umodded game, patched to 3.19, is your point of reference. It is the Great Lighthouse, that shows you how to undo stuff back to its original state. So NEVER edit original files, always copy them to a mod folder first!
Unofficial patches
Some of the most innovative and capable modders and programmers (and, I think, some of Firaxis original CIV coders?), have published what is known as Unofficial patches. They may be found here: Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - Project & Mod Development > Civ4 - Unofficial Patches
As of this writing, the most current Unofficial patch is version 1.30, published byjdog5000. If you are planning to merge mods that included SDK work, this is a great starting point. Go ahead and merge the unoffical patch with the original code, and then compile it.
Study your targets (compatibility)
There a a TON of mods on Civfanatics. You might find bits and pieces around the place that youd like to include. Just make sure that they are all compatible i.e. dont attempt to include a mod which is made for Warlords when you are modding Beyond the Sword. It might work, but chances are it wont, especially if its either python or C++ mods. Instead, you could try and contact the author of the component you want to add, and ask for an update.
Finally, I just want to wish you good luck! And ask all the questions in the world you want, there are so many helpful people on this forum, and the knowledge shared between them is immense.
By Ninja2
Intro (and who am I?)
This tutorial is aimed at providing some help for players who like mods, and who want to play more than one mod combined. I have succesfully merged quite a few full mods, components and other tweaks into a single, playable mod, the Merged Mod. I will use my experience from that work in this tutorial, to provide you some guidance as to how to tackle some of the problems that might crop up. You are free to ask questions in this thread about merging, and I will try to help you the best I can. But please, take some time to get into this stuff yourself, I will not do it for you, Ill only give advice, as I dont have time to mod anything but my own stuff! It is a much more rewarding experience, when you yourself manage to put bits and pieces together, and find out that it actually works! I dont want to take that experience away from you.
I should also point out that I am not a programmer by profession. This tutorial is for absolute beginners! Going into this, all I knew was a little HTML. And anyone who reads this, probably knows how little help a little HTML is! I started out by playing mods such as Wolfshanze and Dales Combat Mod, and decided that it would be really awesome if I could have both mods going at the same time. Working with this stuff has actually taught me a lot about programming and data structuring not that Ill ever need it in my own profession, but it has been a fun experience all along, seeing as I could follow the progress, and feel a little like I was playing my own game (even though I didnt actually program much).
Merging mods is really all about identifying differences in data files, and then figuring out which differences you want to keep, which ones you want to merge, and which ones you want to delete. It all comes down to this exercise. Your goal is to build new data files that hold both the changes from the two original files, and then making those changes work in tandem. If two mods do not modify the same file(s), it is as easy as copy-pasting these different files into the proper folders, and youre done!!
This guide is divided into three sections: First is understanding mods, the second section concerns tools for merging, and the third is about planning your work. First of all, it is necessary to study a little bit on the data structure of CIV4, to find out what a mod really is. There are some excellent threads about modding which you should get into reading. If you already feel comfortable about different the types of data in CIV4, XML, Python and source code, you can skip right ahead to the next section! Section two goes more into detail about the practicalities of merging, how its done, pitfalls to avoid and so on. The last section deals with various recommended tools that Ive used myself when merging.
So, here we go!
Understanding mods
What are mods
Mods are modifications, or edits, to the basic game. You can mod anything you want, if you have the right skills. You can mod graphics, stats, interfaces, even the detailed workings of the engine itself. All the various mods and scenarios that ship with Beyond the Sword are basically modifications to the original game. Mods come in many shapes and sizes some are full conversion mods (like Final Frontier) where nothing is like CIV4, and some are only slightly changed versions of the original game, like Blue Marble, for example, which only changes the appearance of the terrain. Most of the stuff that go into mods are made by users, and shared on Civfanatics. You are free to use pretty much anything made by anyone here, as long as you give them the proper credit for their work! There is a lot of useful info for you on most aspects of modding in this forum, and on this wikipage.
Modular mods
Some mods are only modular, which means that they only contain the actual changes to the basic files. This makes them into add-ons, rather than replacements. I will mainly be discussing regular mods, which in principle replace one entire file for another, editted (modded) version. Modular mods dont do this, they simply contain the extra, or modded data, which appends to or replaces the original data when the mod loads. It is somewhat easier to work with modular mods (in theory at least, I havent tried it), since they are easy to switch on or off as you please. When I have come across some stuff in a modular mod that I like, I have just copied the data I want, I pasted it into the appropriate target file, so it always gets loaded but cannot be switched off without editing the data file again.
File structure
Alright, time to look at the data structure of CIV4! On your harddrive, you have CIV4 in a folder. Inside that folder, youll have a folder with Beyond the Sword. Inside that, theres one called Mods. So were at C:\...something...\CIV4\Beyond the Sword\Mods. Here youll see all the standard mods that ship with BTS, and this is also where youll create a folder to hold your own mod components. When you create a folder here and fill it with data, youll be able to load it from the game by selecting Advanced on the Main Menu in the game, and the selecting Load Mod. A list will appear, where your new mod name will be selectable, and this is how you load it up. I should mention that theres another way to mod the game. If you stick your modded files inside \My Documents\My Games\CIV4\Beyond the Sword\Mods instead, your modded files will load with ALL games of CIV4, normal games and other mods. So ONLY do this if youre absolutely certain that you want this particular change to apply for EVERY SINGLE GAME!
You should NEVER overwrite the original files of the game. All mods should start with you creating a new folder, and then copying whatever files you wish to mod into that folder, retaining the original file structure. Its important to note that you ONLY need to copy the files that you are going to edit. The ones you DONt edit will get loaded from the default files. Smart!
*CAUTION* If youre on a Vista system, make SURE that you have administration rights over the folder that holds CIV!!!
Depending on how many things any particular mod changes about the game, there may be more or less files and folders inside said mods directory. All CIV mods contain a folder called Assets. Inside this folder, there will typically be an Art folder, a Python folder and a XML folder. You may also see a file called CvGameCoreDLL.dll. Remember, your goal is to join two mods together, so examining each mods file structure, and see what files they use is an important step.
XML, Python, C++
Mods range in their complexity from very simple to extremely complicated. A mod can be as simple as changing the default combat value for a single unit from its default value, to one that is higher or lower. Mods can also change the game so that it doesnt even feel like youre playing civ anymore. Rules, values, graphics, mechanics, most of anything in civ can be modded. So there is a huge range of possibilities. Part of this range comes from the three levels of modding available to us. You can mod XML files, which are simple text files. You can mod Python files, which are bits of programming that can be made very advanced, or simple. Or, you can do C++ programming, which apart from the actual programming, requires you to set up a process using the SDK, which can compile a working dll file. There are already a couple of great guides on setting up the SDK process:
Refar's guide. Essential reading if you want to set up a compiler for CIV.
EDIT: The below links describe some slightly outdated techniques, although they still contain a lot of useful help and hints.
Installing and using the SDK
Using Microsoft Visual C++ 2005 Express Edition
In order to do any sort of SDK work, you need the source files from the mod you are trying to merge. Usually, the mod author will have provided these files for you, but they are typically found in a separate download location. You'll just have to look or ask around.
Tools for merging
Below are some highly recommended tools for merging, all free. You *could* just do all your editing with the basic Windows Notepad, but your life will be a lot easier if you use a more advanced editor, like Notepad++. There are many useful programs listed on this wikipage, below I've just mentioned the ones that are most relevant for merging.
Winmerge
The MOST vital tool for merging. You should not start to merge anything, without this tool or one that is similar. Winmerge allows you to view two files with identical names side by side in two panes, and then have the program color highlight the sections that are not identical. And finding differences is what merging is all about, remember?! I cannot stress how important this tool really is you can also view two file folders in two panes, and winmerge will show you what files are identical, and which files are different. You can find it at winmerge.org
Editor (Notepad++)
A superb text editor, which will color-code code tags, values, etc for you. You can in fact use your favorite text editor, but this one is just very, very good. You can find it here.
Codeblocks
Codeblocks is a freeware compiling tool. Compiling is the process of converting all the files of code (all files named *.cpp and *.h) into a single file, the CvGameCoreDLL.dll. Again, there are a separate tutorials and guides on setting up Codeblocks (or you can also use Visual Studio Express, which is also free), and you NEED to read these guides to get going!
EDIT: This process is somewhat obsolete, as the guide describing setting this up uses programs that are very difficult to find. Newer versions of CodeBlocks have completely different setups.
Visual Studio 2008 Express
Instead of CodeBlocks, you should use Visual Studio 2008 Express. It does the same thing as CodeBlocks does, it's a compiler. The BIG difference is that VS can make a debug version for you, which is an incredibly powerful way of tracing bugs in a finished dll. So, as you play your CIV game, you can follow the code in a window, and this allows you some insight to see where things go wrong.
7zip
Most of the mod sources youll be downloading will be compressed in some way, so you need a program to decompress. There are a lot of options out there, 7zip is just one of them.
Planning your mod merging
So, now I (think I) have covered the basics. The next step is to plan what mods to merge! You should start out by doing something that is not too big like adding a single component to the default game. Go ahead and choose any component that you find in the Mod Components sub-forum of the Creation & Customization forum. If you can add a component to the basic game sucessfully, you are well on your way! Normally, all components come with installation instructions. They should more or less be step by step instructions, as modders like it when people try out their mods! If you have trouble adding a component, ask a question in the components thread. Once you have figured out how to add a component, go ahead and select another component. It might just be that the two components change two completely separate things about the game, and they might as such be able to coexist without any merging actually done. However, as you increase the number of mods you add, the probability of the mods not clashing will be ever smaller. Eventually, youll be looking at adding several components that all change the dll, or youre even trying to merge two modpacks. And then it is time to do some serious merging!
Your reference: The unmodded game, 3.19
When you set out to mod, always remember that the umodded game, patched to 3.19, is your point of reference. It is the Great Lighthouse, that shows you how to undo stuff back to its original state. So NEVER edit original files, always copy them to a mod folder first!
Unofficial patches
Some of the most innovative and capable modders and programmers (and, I think, some of Firaxis original CIV coders?), have published what is known as Unofficial patches. They may be found here: Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - Project & Mod Development > Civ4 - Unofficial Patches
As of this writing, the most current Unofficial patch is version 1.30, published byjdog5000. If you are planning to merge mods that included SDK work, this is a great starting point. Go ahead and merge the unoffical patch with the original code, and then compile it.
Study your targets (compatibility)
There a a TON of mods on Civfanatics. You might find bits and pieces around the place that youd like to include. Just make sure that they are all compatible i.e. dont attempt to include a mod which is made for Warlords when you are modding Beyond the Sword. It might work, but chances are it wont, especially if its either python or C++ mods. Instead, you could try and contact the author of the component you want to add, and ask for an update.
Finally, I just want to wish you good luck! And ask all the questions in the world you want, there are so many helpful people on this forum, and the knowledge shared between them is immense.