Getting DLL modding set up

Jaegerguy

Chieftain
Joined
Jul 12, 2020
Messages
28
Hi, I wanted to try my hand at modding the source code DLLs, and I was suggested to document the steps in the process much like whoward69 did in 2019 (https://forums.civfanatics.com/threads/building-a-dll-based-mod-in-2019.645887/). Another useful thread is this one by DaveMcW: https://forums.civfanatics.com/threads/how-to-compile-the-dll.479374/. You can also check https://modiki.civfanatics.com/index.php/Basic_DLL_tasks.

Additionally, as I'm mostly a Linux user these days, I'll also describe the steps in getting a custom DLL working on Linux. Do note that I've only done this on Ubuntu 24.04.2 LTS, so I can't say much on the process on other distros. Also, another important matter to note is that you'll still probably need a Windows PC, or a Windows running in a virtual machine (VM) to build the source code. Also, ModBuddy installed on Windows makes building the final mod pack easy. I used a VM running Win11.

To start things off, boot your Windows PC or VM and download the .iso file containing Visual studio 2008 express with SP1 from the link that user bc1 had already provided in whoward's thread (https://download.microsoft.com/down...59B738298/VS2008ExpressWithSP1ENUX1504728.iso). I haven't tested the other versions of Visual Studio provided in the same message, so I can't say if/how they work. Next, open the .iso file in file explorer, at least on my VM I got it open just by double clicking it. After that, multiple folders can be found, and I again have to confess I only tested one of them (VCExpress). Find setup.exe in the folder, and run it. This should get you Visual C++ 2008 Express Edition installed on Windows.

Next, run the Visual C++ 2008 you installed. The default installation location and the executable you want to run was "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\VCExpress.exe" for me. Make a bookmark or shortcut to avoid having to find the folder again.

Next, find your installation folder of the Civilization V SDK (mine is "C:\Program Files (x86)\Steam\steamapps\common\Sid Meier's Civilization V SDK" ). In the SDK folder you can find folder called CvGameCoreSource. Inside there are multiple Visual Studio solution files. Open CvGameCoreDLL.vs2008.sln in Visual C++ 2008 Express Edition.
1758656925705.png


Next, you can find three DLLs in the solution explorer found on the left side of the window. I've only edited the expansion2 files, but if you specifically want to build a mod for the base game or G&K, pick the DLL for that version. Inside the DLL there are multiple folders containing for example header files and the source code files. Study the code and make the changes you want to. I don't know much about C++ coding, so I can't make anything very complicated (at least for now :P). If you want to verify that the build works, make some small change that you can see easily in game. I just added the highlighted line into the DoGold() method in CvTreasure.cpp, should be easy enough to see in game if it works.
1758658115338.png


When you've made the changes you want to, you need to build the DLL. Before that, you will need to make one small change to /CvGameCoreSource/CvGameCoreDLL_Expansion2/CvGameCoreDLL.rc. The .rc file can be seen in the solution explorer of Visual C++, but at least in my setup I cannot open it directly from there. Fortunately you can just open it in a text editor. Replace the first occurrence of text "afxres.h" with "windows.h", which is in the include statement on line 10. Save the file.

As described in the replies of the second thread I linked at the start, you will need to provide a unique GUID for the DLL in the file CvDllVersion.h. (see next image)
1758659633034.png

Unfortunately, I didn't find the Visual Studio Create GUID tool installed at all. I tried searching tools online, but I only found dead download links. There are browser based GUID generation tools online, but I didn't find one that directly outputs the type of hexadecimal monster as seen here. I also didn't want to spend any time researching GUID/UUID formatting, so I just changed one character in the GUID, just remember it has to be hexadecimal so don't be like me at first and change an "f" to "g" (valid characters consist of digits from 0 to 9 and letters from a to f). I don't know if this is a proper practice, but it worked in the end.

Last thing before the build, also described by DaveMcW in their thread (steps 8, 9 and 10): right click the desired CvGameCoreDLL (so, for BNW, CvGameCoreDLL_Expansion2). Select properties -> linker and change Output File into $(OutDir)\CvGameCore_Expansion2.dll

Then you can start the build! Again assuming that you want to work on one version/expansion DLL, you can save time by only building the select DLL you desire. For Expansion2, select Build from the top menu and the option "Build CvGameCoreDLL_Expansion2". The process should take some time, but if it finishes without problems, you can find the built DLL in directory CvGameCoreSource/BuildOutput/VS2008_ModWin32. It should have the name you described in the linker part earlier.
1758661245133.png

Next, open ModBuddy, set up a new mod solution and add the file CvGameCore_Expansion2.dll from the build output into the mod. In its properties, set Import into VFS to True. This is all you need. Then build the mod. This should be enough for Windows Civ5, and you can just toggle the mod on from the mod menu when you start the game.

However, for Linux, it seems that DLL mods have issues related to whether you are using the game via Proton or via the Aspyr port of the game. It seems DLL mods don't work with the latter one, at least I just got a crash to desktop while trying to load the mod. Fortunately they seem to work on Proton. So, just open Steam, right click Civ5 in Library and select Properties -> Compatibility. Tick the box that says Force the use of a specific Steam Play compatibility tool and select a Proton based one. I used Proton 10.0-2 (beta)
1758661774081.png

Then, once Steam has finished changing the compatibility tool, find the folder for mods on your OS, which for me was /home/<username here>/.steam/steam/steamapps/compatdata/8930/pfx/drive_c/users/steamuser/Documents/My Games/Sid Meier's Civilization 5/MODS (also see ). Get the .civ5mod file for the mod you built with ModBuddy on Windows, and put it into the MODS folder. It is just a 7zip package so you can extract it easily to the MODS folder, at least on Ubuntu. Then launch the game, apply the mod and check if it works as intended!

So to conclude, hopefully this can be helpful to others as well, even if much of the information can already found in the earlier threads or sites I've linked here. Happy modding!
 
Back
Top Bottom