How to merge mods

Ninja2

Great Engineer
Joined
Nov 17, 2005
Messages
1,142
Location
Denmarkia
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, I’ll only give advice, as I don’t have time to mod anything but my own stuff! :p 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 don’t 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! :D Going into this, all I knew was a little HTML. And anyone who reads this, probably knows how little help a little HTML is! :D I started out by playing mods such as Wolfshanze and Dale’s 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 I’ll 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 didn’t 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 you’re 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 it’s done, pitfalls to avoid and so on. The last section deals with various recommended tools that I’ve 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 don’t 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 haven’t 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, you’ll have a folder with Beyond the Sword. Inside that, there’s one called Mods. So we’re at C:\...something...\CIV4\Beyond the Sword\Mods. Here you’ll see all the standard mods that ship with BTS, and this is also where you’ll create a folder to hold your own mod components. When you create a folder here and fill it with data, you’ll 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 there’s 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 you’re 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. It’s important to note that you ONLY need to copy the files that you are going to edit. The ones you DON’t edit will get loaded from the default files. Smart!

*CAUTION* If you’re 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 mod’s 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 mod’s 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 doesn’t even feel like you’re 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 you’ll 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 component’s 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, you’ll be looking at adding several components that all change the dll, or you’re even trying to merge two modpacks. And then it is time to do some serious merging! :D

• 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 you’d like to include. Just make sure that they are all compatible – i.e. don’t attempt to include a mod which is made for Warlords when you are modding Beyond the Sword. It might work, but chances are it won’t, especially if it’s 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.
 
Thanks for this Ninja2, i now have all the tools i need to do a merge but don't have a clue on where to start with it. :(

XML stuff is easy i can do that no problem. :D

The trouble starts when i look at any SDK components on the Mod i want to merge into my mod, basically it means i need to create a DLL for the Babylon5 mod. As there isn't one there to begin with i have nothng to merge with if you follow me. :confused:
 
If there isn't a dll to begin with in the mod, then said mod just uses the default CIV4 CvGameCoreDLL.dll file. In that case, your starting point is the code found in ...\Beyond the Sword\CvGameCoreDLL. You should copy the .cpp and .h files from this folder to a new folder, and then proceed from there to add in the desired components.
 
Nice Ninja, next time someone asks about merging stuff, I can direct them here. This is definatly a much needed tutorial. However some of the links are dated, or impractical, such as the link to installing and using the SDK, this is pretty worthless, and the MS 2005 one is out of date, and doesn't explain setting up a debug dll; a debug dll will save a modder hundreds of hours if they build one. These links should just be removed. There is a civ4 modwiki list of usefull programs. This list of programs are what modders should be using now. I've double checked it, and it's all useful and current stuff, please use programs from here to direct people to, it will save anyone that gets use out of your tutorial much time:

Civ4 Modwiki Useful Program's List
 
Nice Ninja, next time someone asks about merging stuff, I can direct them here. This is definatly a much needed tutorial. However some of the links are dated, or impractical, such as the link to installing and using the SDK, this is pretty worthless, and the MS 2005 one is out of date, and doesn't explain setting up a debug dll; a debug dll will save a modder hundreds of hours if they build one. These links should just be removed. There is a civ4 modwiki list of usefull programs. This list of programs are what modders should be using now. I've double checked it, and it's all useful and current stuff, please use programs from here to direct people to, it will save anyone that gets use out of your tutorial much time:

Civ4 Modwiki Useful Program's List

Thanks! That's a great page.

By the way, is there any guide to setting up with visual studio 2008 and doing the debug dll etc.? I'm wanting to do that at the moment... Still using codeblocks at the moment. :)
 
Just use Refar's guide, it's the same thing. Everything you'll ever need in Civ4 modding is in the links to that wiki page.
 
Just use Refar's guide, it's the same thing. Everything you'll ever need in Civ4 modding is in the links to that wiki page.

Thanks, I just found it. Will try his guide out.
 
Thank you for the input, phungus, I have updated the first post with the links and a little more information.
 
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.

Is this even true?

edit: Oh and great work on the guide, I'm just starting to merge but this caught my eye.
 
Nice work on the guide! By the way, I'm trying to merge a mod into another and it keeps loading up to the part 'Init XML' and then it just closes and nothing happens. I've already spent about an hour trying to fix this, but I can't find anything wrong. Do you have any suggestions?
 
I followed the steps in Refar's guide exactly but nmake could not find Final_Release - File. Any hints for me? I have the sdk for Win Vista / Server 2008 (the files from the links in the guide did not work) and Visual C++ 2008 Express. Visual Toolkit is version 2003 - is that what went wrong?
 
I followed the steps in Refar's guide exactly but nmake could not find Final_Release - File. Any hints for me? I have the sdk for Win Vista / Server 2008 (the files from the links in the guide did not work) and Visual C++ 2008 Express. Visual Toolkit is version 2003 - is that what went wrong?

Refar's guide is a bit outdated. Try my tutorial.
 
I'd like to merge the Maria II *Generic Mod* with Neoteric World *Regular Mod*.

Can you point me to the guide for that or tell me how to do that?
 
Hi there, I really enjoyed reading and using this "guide" (not sure what else to call it) to try to merge a couple of custom civilization mods together. Not having any luck so far, but one thing is confusing me greatly. Neither mod has any .cpp or .h files. Here are the file types in the mods: .Bak, .Xml, .Mp3, .ini, .dds, .nif, and .tga.

As I have already stated, this confuses me greatly because I'm not sure if I need to merge anything together or not. Do I need to actually merge any files together or can I just copy and paste everything into a folder?
 
If there are XMLs with the same name, then they need to be merged.
The .ini/.ini.bak most likely don't need merging, since they should contain all the same, besides a name, probably.
The other files are graphic files. As long as they all have a different folder name, then you can just dump these folders into the respective subfolders.
 
There's hardly any xml files that have the same name, 5 at max. It should be easy, but I can't seem to find Visual Studio 2008. The link provided in the first post lead me to the proper website, but they just don't have to 2008 version. I'm not sure how to proceed.

Also, thank you for responding back. I didn't see the other post dates until after I posted. Nothing like reviving dead threads accidentally, right?
 
Not unusual for tutorials ;).
They often cover many things, so most people who read them don't need to ask anything. But if someone stumbles upon something, which hasn't been written down, then there's the need to ask, and that doesn't have to be shortly after the thread has been posted.

Why are you looking for Visual Studio 2008?
You only need it, if there are 2 .dll files, which source codes need to be merged.
For XML files, you can simply open them with a text editor (right click on the file -> open with... -> choose wordpad, notepad, or a text editor of your choice).
 
Oh, well, the way the post was worded, it sounded like I could only merge the files through Visual Studio 2008. But, that brings up another question. The xml files that need merged seem very identical, having only a space of the very bottom of the documents that vary. And in that space, its just nothing on one, and a lot text on the second. Doesn't that mean that I could just copy and paste that chuck of text from the second onto the first?
 
Top Bottom