在 VS2008 下编译
This page either contains information that is only partially or incorrectly translated, or there isn't a translation yet.
If this page cannot be translated for some reason, or is left untranslated for an extended period of time after this notice is posted, the page should be requested to be deleted.
Also, please make sure the article tries to comply with the alternate languages guide.
In this tutorial you will learn how to get the Source SDK to compile under Visual Studio 2008 and/or Visual C++ Express 2008. There are several things you're going to have to do to get it working. Before you begin, 创建一个mod .
安装 Visual Studio 2008
If you do not have Visual Studio 2008, you can download Visual Express 2008 for free from Microsoft. This download comes with SP1 so you do not need the information below in that case.
升级到 Service Pack 1
If you installed VS2008 before August 2008 it will probably need updating to SP1. The service pack will presumably be offered through Windows Update eventually, but for now you'll need to manually download it:
- Visual Studio update
- Visual C++ Express update (choose vcsetup.exe)
Service Pack 1 improves error reporting and fixes issues with Intellisense database corruption (" cannot update program database" / "Cannot open program database file"), alongside other improvements not directly relevant to the Source SDK.
打开解决方案
- Launch your copy of Microsoft Visual Studio.
- Select File->Open Solution from the menu and open the Game_Episodic-2008.sln solution located in your mod's
src
directory, select the one that matches your version of Microsoft Visual Studio. Note the "HL2" portion of the file name will correspond to the selection you made in the mod creation step. If you selected mod from scratch, "Scratch" will appear there instead.
升级工程文件
This is only the case if the 2008 solution/projects are not available.
Visual Studio will prompt you to upgrade the project files. If you've been working on your mod in a previous version of the VS you'll probably want to have it make a backup of the project file, though this is a good time to do a backup of the entire source tree yourself anyway. Otherwise you can just do the conversion in-place.
whatever_2005.sln
to whatever_2008.sln
.修复编译BUG
#ifdef DEBUG
'ed code. It's up to you: debug builds are slower and larger than release builds.Right-click > Properties on the Server and Client projects (multi-select both of them). Making sure that you are working on the Debug configuration (top left of properties dialogue- you may need to first select the Configuration Properties item in the list on the left) change Configuration Properties > Linker > Input > Ignore Specific Library to libc;libcd;libcmtd
(an extra 'd' on the end).
A function also needs commenting out from public\tier0\memoverride.cpp
:
void __cdecl _invalid_parameter_noinfo(void)
{
Assert(0);
}
Get rid of the whole thing. Remember to launch your mod with -allowdebug
!
修复丢失的符号
If you see missing symbols such as: ConVar_Register you'll need to add tier3.lib to the Link Libraries folder.
禁用 /Wp64
You'll receive warnings about the Wp64
option. You can ignore them if you like, but it's a simple matter to sort them out too: right-click > Properties on both the Server and Client projects, then change Configuration Properties > C/C++ > General > Detect 64-bit Portability Issues to No
.
安装 DirectX SDK (为了 shaders)
To create new shaders you will need the MS DirectX SDK (March 2009). Once installed, follow the instructions below to incorporate it with your project.
- Go to Tools - Options: Projects and Solutions - VC++ Directories
- Select "Include files" and add "...\Microsoft DirectX SDK (November 2008)\Include"
- Select "Library files" and add "...\Microsoft DirectX SDK (November 2008)\Lib\x86"
- In the Solution Explorer, right click the client project and select Properties. Navigate to the Linker -> Input pane.
- Select the 'Additional Properties' row and click the '...' on the right hand side of the row
- Add
user32.lib
to the list that appears. Separate it from any other entries with a new line. - Repeat for the server.
丢失 vc80.pdb
You may encounter these warnings after trying to compile one of the other tool/library projects included in the SDK. You see it because your code has been compiled with VS2008 (VC9), whereas the SDK's .libs were compiled with VS2005 (VC8).
The warnings prevent the compilation of PDB files. The easiest way to fix them is to build the library which is generating them yourself!
修复 grenade_tripmine.cpp
If you've started from hl2mp code and get error C2039: 'OnTakeDamage_Alive' : is not a member of 'CBaseGrenade', go to line 31 in game/shared/basegrenade_shared.h
:
//Tony; Compromise! in episodic single player, inherit CBaseCombatCharacter for the barnacle interaction, otherwise this will never get called.
class CBaseGrenade :
#if defined( HL2_EPISODIC )
public CBaseCombatCharacter
#else
public CBaseAnimating
#endif
#if defined( GAME_DLL )
, public CDefaultPlayerPickupVPhysics
#endif
{ //Tony; the ugliest class definition ever, but it saves characters, or something. Should I be shot for this?
DECLARE_CLASS( CBaseGrenade, CBaseAnimating );
Replace this with:
//Tony; Compromise! in episodic single player, inherit CBaseCombatCharacter for the barnacle interaction, otherwise this will never get called.
#if defined( HL2_EPISODIC ) || defined ( HL2MP )
#define GRENADEBASECLASS CBaseCombatCharacter
#else
#define GRENADEBASECLASS CBaseAnimating
#endif
class CBaseGrenade : public GRENADEBASECLASS
#if defined( GAME_DLL )
, public CDefaultPlayerPickupVPhysics
#endif
{ //Tony; the ugliest class definition ever, but it saves characters, or something. Should I be shot for this?
DECLARE_CLASS( CBaseGrenade, GRENADEBASECLASS );
Don't forget to add HL2_EPISODIC to your preprocessor definitions!
修复编译器崩溃
The 2008 compiler crashes on line 341 of client/c_vguiscreen.cpp
:
dist = c_x / tan( M_PI * scaled_fov / 360.0 );
Replace it with:
float dist_denom = tan( M_PI * scaled_fov / 360.0f ); dist = c_x / dist_denom;
This can also be fixed using the following :
dist = c_x / (float)tan(M_PI * scaled_fov / 360.0f);