[SDK] Using Microsoft Visual C++ 2005 Express Edition

Chazcon

Prince
Joined
Feb 16, 2006
Messages
476
Location
Left Coast
Yes, you CAN use the free Microsoft Visual C++ 2005 Express Edition (albeit not right out of the box) to mod Civilization IV’s CvGameCoreDLL.dll code that is publicly available from Firaxis in the SDK.

Credit goes to DaveMcW, Kael, and Maian for doing all the hard work. I’ve only combined their efforts into one post.

*** I’ve changed this procedure slightly so that it makes sense for both vanilla and Warlords code ***

Let’s do it:


1 - *VANILLA*
Download the SDK from Civilization IV Source Code. This is a file named Civ4_SDK_source.zip. Unzip it and you will see the following directory structure:

(folder you extracted it to)
CvGameCoreDLL_v161
CvGameCoreDLL
Boost-1.32.0
Python24

I suggest that you leave these folders and their files in place and intact so that you always have an original copy of the source files. Copy the folder CvGameCoreDLL and all of it’s contents to another location (commonly called your working folder).

DELETE two files, CvGameCoreDLL.vcproj, and CvGameCoreDLL.vcproj.vspcc.


1 - *WARLORDS*
Install Warlords, and patch 2.08. You will see a folder in your \Warlords directory named CvGameCoreDLL. I suggest that you leave this folder and it’s files in place and intact so that you always have an original copy of the source files. Copy the folder CvGameCoreDLL and all of it’s contents to another location (commonly called your working folder).

DELETE two files, CvGameCoreDLL.vcproj, and CvGameCoreDLL.vcproj.vspcc.


2 - Download and install Microsoft Visual C++ Toolkit 2003.


3 - Download the following three library files and put them in the folder:

C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib

msvcrt.lib
msvcrtd.lib
msvcprt.lib


4 - Download and install the Microsoft Platform SDK.


5 - Download the Makefile and extract it into your CvGameCoreDLL_v161\CvGameCoreDLL folder.


6 - Open the Makefile in WordPad (not Notepad).

At the very top, change the line that begins with TOOLKIT to the path of your Visual C++ Toolkit 2003 directory.

Change the line that begins with PSDK to the path of your Microsoft Platform SDK.

Save and exit.


7 - Download and install Microsoft Visual C++ 2005 Express Edition


8 - Launch Visual C++ 2005 Express Edition

*** DO NOT open the existing project file in Visual C++ 2005 Express Edition ***


9 - Click -File- -New- -Project-. The ‘New Project’ window will open.

In the ‘Project types’ box select –General-.

In the ‘Templates’ box select -Makefile Project-.

In the ‘Name’ box type ‘CvGameCoreDLL’.

In the ‘Location’ box browse to the folder where you copied your CvGameCoreDLL folder to. This folder MUST be the last folder listed in this box. For example, if you copied CvGameCoreDLL to another folder like so:

C:\MyModsFolder\CvGameCoreDLL

The entry in the ‘Location’ box must read:

C:\MyModsFolder

UNCHECK the box that says 'Create Directory for Solution'.


Click -OK-. The ‘Makefile Application Wizard’ will open. Click –Next-. Clear all the boxes. Click –Finish-.


10 - Click -Project- -Add Existing Item…-. The ‘Add Existing Item - CvGameCoreDLL’ window will open.

This folder will contain all of the source code files, the Boost-1.32.0 folder, and the Python24 folder. Select everything (use Ctrl-A) and click -Add-.


11 - Click -Project- -CvgameCoreDLL Properties-. The ‘CvgameCoreDLL Properties Pages’ window will open.

In the left-hand box under ‘Configuration Properties’ select ‘NMake’.

In the upper-right-hand corner click the ‘Configuration Manager’ button. The ‘Configuration Manager’ window will open.

In the upper-left-hand box named &#8216;Active solution configuration&#8217;, click the drop-down button and select &#8216;<Edit&#8230;>&#8217;. The &#8216;Edit Solution Configurations&#8217; window will open.

Select &#8216;Debug&#8217; and click the &#8216;Remove' button. Click 'Yes'.

Select &#8216;Release&#8217; and click the &#8216;Rename&#8217; button. Change the name from &#8216;Release&#8217; to &#8216;Final_Release&#8217;. Click 'Rename'. Click 'Yes'.

Close the &#8216;Edit Solution Configurations&#8217; window.

In the &#8216;Project contexts&#8217; window, in the &#8216;Configurations&#8217; column, click the drop-down button and select &#8216;<Edit&#8230;>&#8217;. The &#8216;Edit Project Configurations&#8217; window will open. Repeat the steps above to remove &#8216;Debug&#8217; and rename &#8216;Release&#8217; to &#8216;Final_Release&#8217;.

Close the &#8216;Configuration Manager&#8217; window. Now you&#8217;re back at the &#8216;CvgameCoreDLL Properties Pages&#8217; window. Make sure in the left-hand box under &#8216;Configuration Properties&#8217; you&#8217;ve selected &#8216;NMake&#8217;.

In the right-hand box under &#8216;General&#8217; it says &#8216;Build Command Line&#8217;. Click the empty box to the right of it and type &#8216;nmake Final_Release&#8217;.

In the next line down, to the right of where it says &#8216;Rebuild All Command Line&#8217;, click in the empty box and then click the button in the box at the right. The &#8216;Rebuild All Command Line&#8217; window will open. Type &#8216;nmake clean Final_Release&#8217;, and then directly below it on a second line, type &#8216;nmake Final_Release&#8217;. Click -OK-.

In the next line down, to the right of where it says &#8216;Clean Command Line&#8217;, type &#8216;nmake clean Final_Release&#8217;.

Click 'Ok' to close the &#8216;CvgameCoreDLL Properties Pages&#8217; window,

*** YOU ARE DONE ***


Now, the first thing to do is to compile the source code. Click -Build- -Build Solution-. This will begin building, or compiling, the source code. It takes about 20 minutes to do a full compile on my machine.

When the build has completed successfully, you will see this in the last few lines of the &#8216;Output&#8217; box:

------------------------------------------------------------------------------------------------------
LINK : warning LNK4089: all references to 'KERNEL32.dll' discarded by /OPT:REF

CvGameCoreDLL - 0 error(s), 1 warning(s)

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
------------------------------------------------------------------------------------------------------


You can ignore the harmless LNK4089 warning. Any other warnings should be addressed (errors in your code after you&#8217;ve been modding).

A successful build will generate the folder &#8216;Final_Release&#8217; which is under your CvGameCoreDLL folder like so:

CvGameCoreDLL_v161
CvGameCoreDLL
Boost-1.32.0
Final_Release
Python24

In the &#8216;Final_Release&#8217; folder you will find your freshly baked CvGameCoreDLL.dll file, which you then copy into your mod&#8217;s Assets folder.


*** MODDING ***

After you go into the source code and modify it, you&#8217;ll need to compile the code, to produce a modified CvGameCoreDLL.dll file. The nice thing is, you&#8217;ll only need to compile the files you have changed, so it&#8217;s much faster to do a build after changing a couple of files. If you&#8217;re like me, you&#8217;ll be building .dll&#8217;s and testing them regularly. If you&#8217;re a REAL programmer, I&#8217;d imagine you&#8217;d have a good grasp of what code works and what doesn&#8217;t just by looking at it. For us novices, the compiler itself will teach you a few things through the errors and warnings it produces when you compile. C++ isn&#8217;t easy at first, but there are a lot of resources available on the web and at your local bookstore. One of my favorite links: cplusplus.com. Getting into detail about C++, modding, and best practices are beyond the scope of this post.

Have fun!
 
Wow... Thanks a lot... and all free. It seems a very nice interface and enough for what I want to do.

Just be carfull with step 9, I think I did it correctly, but it created an extra CvGameCoreDLL folder and after moving it manually I had to rename all reference to headers and code files. Took only a few minutes, but it can confuse later steps.

9 - Click -File- -New- -Project-. The ‘New Project’ window will open.

In the ‘Project types’ box select –General-.

In the ‘Templates’ box select -Makefile Project-.

In the ‘Name’ box type ‘CvGameCoreDLL’.

In the ‘Location’ box browse to the CvGameCoreDLL_v161 folder. This folder MUST be the last folder listed in this box.

Click -OK-. The ‘Makefile Application Wizard’ will open. Click –Next-. Clear all the boxes. Click –Finish-.
 
Thanks rf for the heads up, yes, most folks get hung up on step 9. I rewrote it slightly to include an example. After you do it once you smack your head and say, "Duh!". I had to smack myself many times with a 2X4 before I got it.

I also changed step 1 slightly to cover using either vanilla code or Warlords code.

Remember this is not my original work, many thanks to DaveMcW, Kael, and Maian for chopping the path through the jungle. I only followed their trail.

Enjoy!
 
Just letting you guys know that there is a newer version of Visual C++ out since this guide was written (or Chaz was using a slightly older version)... 99&#37; of things are still in the same place, but some things are slightly different. I did (hopefully - compiling now) get it to work however. The big thing to note is in Step 10 to change from just the C++ files to ALL files and folders so that you can truly select everything.

And Thanks Chaz, and everyone else involved!

PS- What should I be doing with all these other files (the .objs) etc. created by the compile?
 
A new version? Yay!

I just downloaded this recently - I'm using version 8.0.50727 (RTM.050727-4200)

What version is yours?
 
Yes, I should add:

- You can only 'build' using this procedure. Do not 'clean' or 'rebuild'.

I have no idea how to fix this. What would be REALLY nice would be being able to use debugging. Without it, it's like building a chair with an axe. You can do it, but it sure would beeasier with the right tools.

It's a shame that Civ4 wasn't written in VS C++ 2005. But it's not their fault, 2003 was the state of the art at the time Civ4 was being written

The REAL shame is that Microsoft, in their infinite wisdom, changed the compiler and broke backwards compatibility when they released 2005. As much a fan of Microsoft that I am, I think that was an unspeakable crime.
 
OK, a bit more hoop jumping, but I got what I want.

http://unxutils.sourceforge.net/
has a copy of rm.exe available. So I grabbed that, extracted the rm.exe file from it. You could put it anywhere on your execution path, I suppose. For my purposes, I dropped it into the Platform SDK/Bin directory, then modified the makefile

Code:
RM="$(PSDK)/bin/rm.exe" -f

... seems to work. Presumably, if I extracted the file onto my execution path, I wouldn't have to worry about the "$(PSDK)/bin".
 
A new version? Yay!

I just downloaded this recently - I'm using version 8.0.50727 (RTM.050727-4200)

What version is yours?

Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: VC Express

Microsoft Visual C++ 2005 76542-000-0000011-00125
Microsoft Visual C++ 2005


--------------------

Interesting that things would be different. Perhaps it's because i'm using Windows Vista?
 
Here seems to be the biggest issue i'm having thus far. I managed to get it to compile once...but the dll crashes the game... what I had to do was have 2 copies of each file.... 1 in a seperate folder to include, and a second copy in the main dll directory (ala step 9)... When I try to include the set from the main dll it yells at me because of the existing project files in the directory.

Any ideas?

EDIT: I think I managed to get it to compile again....ASSUMING it compiles without erroring out - when I make a change to a file and go to build again, it does not seem to make the changes....And as discussed earlier rebuild/clean build doesnt function.... Should I remove the .obj for the files i'm changing or the dll and then try a build again?

EDIT 2: Ok it did compile... I did check... it does not seem to rebuild the .dll file -- I CRC compared the two and they are identical. How can I get it to remake the DLL when I make a change?

EDIT 3: I deleted the .obj files created for the files I changed and re-built. It did compile the new version correctly. This is a huge pain- is there any way to make it so you dont have to do this?
 
I've done this hundreds of times - I compile after any little change to any file, and it builds a new DLL. I wonder what's up for you , sarke. You never need to do anything with the .obj files, it's the .dll you want.

In other words I follow the above procedure, to set up the new project, do a full compile, then I start modding. As i make changes i do a compile, which only compiles the files that have changed. Then I copy/paste the freshly baked .dll into my mod's Assets folder, and launch the game. It's very trouble free. I save the entire contents of the CvGameCore folder (all my source files, plus the project files) to a seperate folder now and then (at least once a day, sometimes more often) as a backup. Sometimes when modding I've gone too far in one direction and want to start again at a known good point. It's only when I copy a new set of source files (either from one of my saves, or to work on a completely different project) into my CvGameCoreDLL folder that I have to repeat the above 'project set up' feature. I ONLY 'build', never 'clean build' or 'rebuild', as these don't work with this procedure and I haven't felt the need to figure it out. I don't know what a CRC compare is, but I never get a build where it doesn't change the .dll, verified by in-game testing. My usual procedure is to write out my planned mods, in as much detail as possible, then make the changes in the code one little part at a time, build, test in-game, and repeat until I'm happy with it. Baby steps. Occasionally I'll toss out three days' work and start again. Slow, but it works. If you make too many changes and have bugs, it makes it that much more difficult to track them down - especially since we are modding 'blind', without the ability to debug.

Hope this helps in some small way. I'm no master coder by any stretch of the imagination, but I've learned a few things over the years of coding as a hobby.
 
I've done this hundreds of times - I compile after any little change to any file, and it builds a new DLL. I wonder what's up for you , sarke. You never need to do anything with the .obj files, it's the .dll you want.

In other words I follow the above procedure, to set up the new project, do a full compile, then I start modding. As i make changes i do a compile, which only compiles the files that have changed. Then I copy/paste the freshly baked .dll into my mod's Assets folder, and launch the game. It's very trouble free. I save the entire contents of the CvGameCore folder (all my source files, plus the project files) to a seperate folder now and then (at least once a day, sometimes more often) as a backup. Sometimes when modding I've gone too far in one direction and want to start again at a known good point. It's only when I copy a new set of source files (either from one of my saves, or to work on a completely different project) into my CvGameCoreDLL folder that I have to repeat the above 'project set up' feature. I ONLY 'build', never 'clean build' or 'rebuild', as these don't work with this procedure and I haven't felt the need to figure it out. I don't know what a CRC compare is, but I never get a build where it doesn't change the .dll, verified by in-game testing. My usual procedure is to write out my planned mods, in as much detail as possible, then make the changes in the code one little part at a time, build, test in-game, and repeat until I'm happy with it. Baby steps. Occasionally I'll toss out three days' work and start again. Slow, but it works. If you make too many changes and have bugs, it makes it that much more difficult to track them down - especially since we are modding 'blind', without the ability to debug.

Hope this helps in some small way. I'm no master coder by any stretch of the imagination, but I've learned a few things over the years of coding as a hobby.

Thanks for all the help Chaz. I think I rooted out the issue. I was making changes in an outside editor. For whatever reason on my system the compiler didnt realize the files were changed, and so wasnt compiling them. I found if I open the files add in a space somewhere and save it compiles just fine. Thanks again :)

Oh yeah a CRC compare is basicly checking the hex of two files to make sure they match (or dont match in this case) -- very useful to ensure you have a file thats identical to its original (you can give someone the CRC of a file your sending them and they can check to make sure nothing was lost durring transit etc.)
 
Ahh thank YOU for the tip - CRC (Cyclic Redundancy Check) - gotta love Wikipedia. What program do you use for this?

And glad you got it working. Playing in the SDK is as much fun as actually playing the game (I think - been a while since I actually played a game!)
 
Ahh thank YOU for the tip - CRC (Cyclic Redundancy Check) - gotta love Wikipedia. What program do you use for this?

And glad you got it working. Playing in the SDK is as much fun as actually playing the game (I think - been a while since I actually played a game!)

LoL - I actually use MiRC to do it - I built a small script into it that does it :) - a good CRC checker isn't hard to find though - just google it...it's standard practice for most anyone who works with changing files :)
 
Anyone figure out how to do debugging with VC2005? I have actually managed to modify the script to build a debug version of the dll, copied it to the civ4 mods folder, where it picks it up. I had civ4 complaining about not finding certain debug dlls (i.e. mscvrt71d.dll), so I copied them all over to the civ4 root folder. However, it now complains about there not being a manifest. I tried using the /MANIFEST linker option to create one, as Microsoft support site tells me to do, but it seems the link.exe program in toolkit 2003 doesn't support that option. So, I can build a working release version but not a working debug version because of Microsoft's apparent need to break their build tools for 2005. Anyone figure out how to get around this issue?
 
Did you try using Microsoft Visual Studio 8/VC/bin/mt.exe to create a manifest?
 
No. Actually, what I did was change the makefile to use VC 2005's link.exe, instead of the one in the 2003 toolkit. That way I was able to build it with the /MANIFEST option. So after doing that I copied the dll and manifest file over to CustomAssets, but am still getting the same problem. Even tried to move the manifest over to the Civ4 root folder - same problem (note, this is where I copied the dlls to that it complained about earlier, and Civ4 found them there, so it should've also found the manifest there unless something else is wrong).

Jet, have you been able to get debugging to work after building with mt.exe? If so, what is the exact command-line you used for mt.exe?
 
I haven't tried it.
 
Just wanted to say a quick thanks for this tutorial. Everything worked great first time out the door.

Thanks, again. :goodjob:
 
Hi, i followed all your steps, but at the end i got a different error message:

------ Build started: Project: CvGameCoreDLL, Configuration: Final_Release Win32 ------
Performing Makefile project actions
Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
NMAKE : fatal error U1052: file 'Final_Release' not found
Stop.
Project : error PRJ0019: A tool returned an error code from "Performing Makefile project actions"
Build log was saved at "file://c:\Games\Civ 4 Modding Folder\CvGameCoreDLL\Final_Release\BuildLog.htm"
CvGameCoreDLL - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

what does this mean? did i do something wrong?
 
Top Bottom