• Civilization 7 has been announced. For more info please check the forum here .

I need very basic instructions to modify Fail Gold in DLL for mod

MassRiflemen

Dr. Draftingstein
Joined
Oct 19, 2022
Messages
111
Hi there. There are a lot of old guides between 2006 and 2014 that discuss modding the DLL and provide links (many of which don't work anymore) for the tools such as "SDK" and "Microsoft Visual 2010", etc.

I just want very basic instructions for 2024. Talk to me like an idiot. Pretend I know nothing.

1. What files do we download in 2024 (with working links) to mod the dll.

2. How do use these downloaded files in unison to open the CvGameCoreDLL (when I double click the dll file with the old links, nothing happens).

3. Once it is open, where do I go to change Fail Gold.

4. Is it possible to add hammers and food to trade route income. If so, where do I go in the DLL.

5. How do I compile the DLL.

6. Once compiled, I assume I place the file in the mod's folder, correct?
 
when I double click the dll file with the old links, nothing happens
The DLL doesn't contain human-readable code, you'll need to edit the .cpp and .h source files in the CvGameCoreDLL folder and then use the Visual C++ compiler to create a new DLL file from the modified source code. In the case of fail gold, CvCity.cpp is the file to edit, specifically the function CvCity::doCheckProduction. Although fail gold can actually also be disabled or dialed down through XML: MAXED_BUILDING_GOLD_PERCENT in GlobalDefines.xml. There's also iTradeModifier in Civ4YieldInfos.xml (XML\Terrain folder of the base game), which gets stored (cached) by CvPlayer in CvPlayer::init and then gets loaded from CvPlayer by CvCity::calculateTradeYield. Looks like this system could be used to e.g. convert half of the "trade profit" normally paid out as commerce into hammers (production) instead. Probably not going to work well due to rounding losses; but, through a DLL change (i.e. to CvCity.cpp), you could let calculateTradeYield determine the amount of production and food in any way you choose.

Leoreth's thread is still current, and my suggestion would be to ask for any needed clarifications in that thread. I wouldn't call it foolproof, but, at least for my part, I don't want to write something new that I'd then have to keep updated. I'm also not sure that modders agree what IDE (e.g. Visual Studio) and libraries should be used. Imo, for beginners, VS2010 (second link in Leo's thread) is still the best way to go - though I haven't tried using it under Win11 or on a very large display. I think the installer asks whether to install for C++ or C#; the correct choice will be C++. The third link is for the Windows SDK and MSVC toolkit; should also be fine. That'll be version 7.0A of the Win SDK, apparently. Perhaps version 6.0 is more proper, but, at least so long as VS2010 is used, it shouldn't make a difference. Generally, those files, especially the compiler itself (included in the MSVC toolkit) need to be old enough to be fully compatible with the tools that Firaxis used for compiling the EXE (Civ4BeyondSword.exe). Any DLL we compile needs to interact with the old EXE (which we can't recompile because we lack the source code). Step 3 – obtaining the DLL source code, makefile and project files (.vcxproj and .sln) and editing the paths in the makefile – should work as described. That's the difficult part. To compile, the sln file should be opened with Visual Studio. VS can (and probably should) also be used for editing the source code, but any text editor could be used too. For editing in VS, the desired file can be opened via the Solution Explorer window.

If you want to use another DLL mod, e.g. BULL, as the basis of your own mod, then you'll need to obtain the C++ sources (CvGameCoreDLL folder) of that mod, or at least those .h and .cpp files that the mod has modified. Though it might still be a good idea to recompile just the original source code to get started.

Edit, @6: Yes, the recompiled CvGameCoreDLL.dll should go into the Assets folder of your mod. That's why merging two DLL mods is never quite easy; the source files needs to be me merged so that a single DLL file results.
 
Last edited:
The DLL doesn't contain human-readable code, you'll need to edit the .cpp and .h source files in the CvGameCoreDLL folder and then use the Visual C++ compiler to create a new DLL file from the modified source code. In the case of fail gold, CvCity.cpp is the file to edit, specifically the function CvCity::doCheckProduction. Although fail gold can actually also be disabled or dialed down through XML: MAXED_BUILDING_GOLD_PERCENT in GlobalDefines.xml. There's also iTradeModifier in Civ4YieldInfos.xml (XML\Terrain folder of the base game), which gets stored (cached) by CvPlayer in CvPlayer::init and then gets loaded from CvPlayer by CvCity::calculateTradeYield. Looks like this system could be used to e.g. convert half of the "trade profit" normally paid out as commerce into hammers (production) instead. Probably not going to work well due to rounding losses; but, through a DLL change (i.e. to CvCity.cpp), you could let calculateTradeYield determine the amount of production and food in any way you choose.

Leoreth's thread is still current, and my suggestion would be to ask for any needed clarifications in that thread. I wouldn't call it foolproof, but, at least for my part, I don't want to write something new that I'd then have to keep updated. I'm also not sure that modders agree what IDE (e.g. Visual Studio) and libraries should be used. Imo, for beginners, VS2010 (second link in Leo's thread) is still the best way to go - though I haven't tried using it under Win11 or on a very large display. I think the installer asks whether to install for C++ or C#; the correct choice will be C++. The third link is for the Windows SDK and MSVC toolkit; should also be fine. That'll be version 7.0A of the Win SDK, apparently. Perhaps version 6.0 is more proper, but, at least so long as VS2010 is used, it shouldn't make a difference. Generally, those files, especially the compiler itself (included in the MSVC toolkit) need to be old enough to be fully compatible with the tools that Firaxis used for compiling the EXE (Civ4BeyondSword.exe). Any DLL we compile needs to interact with the old EXE (which we can't recompile because we lack the source code). Step 3 – obtaining the DLL source code, makefile and project files (.vcxproj and .sln) and editing the paths in the makefile – should work as described. That's the difficult part. To compile, the sln file should be opened with Visual Studio. VS can (and probably should) also be used for editing the source code, but any text editor could be used too. For editing in VS, the desired file can be opened via the Solution Explorer window.

If you want to use another DLL mod, e.g. BULL, as the basis of your own mod, then you'll need to obtain the C++ sources (CvGameCoreDLL folder) of that mod, or at least those .h and .cpp files that the mod has modified. Though it might still be a good idea to recompile just the original source code to get started.
Thank you. There were so many antiquated threads, this one works.

Also thank you for the code locations on trade routes and fail gold.

I've completely removed the research slider from my mod (meaning its a specialist economy only mod) and I needed these features.
 
Thank you. There were so many antiquated threads, this one works.
That's one of the issues with the forum. Once in a while people posted something, which is outdated by now and in some cases wasn't even correct when it was posted. This is particularly true with technically hard to understand tasks where compiling the dll is the worst affected part. I consider all statements about this outdated and wrong except Leoreth's thread. That is with the exception of statements regarding the mods Caveman2Cosmos and We The People as those two mods modifies how to compile, hence mod specific knowledge is needed for those.

One of the reasons most compiling guides are outdated is that back in 2015 (9 years after dll modding started), I altered the makefile to use all CPU cores rather than just a single one as more is obviously faster. This outdated all compile guides predating 2015, which is most of them.

There has also been some confusion regarding how to compile something, which is compatible with the exe as it is compiled with a 2003 compiler and not compatible with modern compilers, at least not without a whole lot of work.

Forum posts about modding tasks other than compiling specifically seems to be way more accurate.
 
Top Bottom