Mounting multiple games
This code extends the Orange Box's AdditionalContentId system to support mounting of multiple Game Cache Files via the gameinfo.txt. It can be used with the Ep1 codebase too.
If the content you want to mount is required in order to play your mod properly, you may want to hard-code the ID instead of relying it to be in the gameinfo.txt. Remember when doing this that the int you pass to filesystem->MountSteamContent()
must be negative!
AdditionalContentId { 220,380 }
gameinfo.txt scheme.The code
This code needs to be added to both the client and the server.
- Client
- Search cdll_client_init.cpp for
MountAdditionalContent()
and replace it. If it didn't already exist, add the code aboveCHLClient::Init
, then call it from that function right beforeif ( CommandLine()->FindParm( "-textmode" ) )
. - Server
- Search gameinterface.cpp for
MountAdditionalContent()
and replace it. If it didn't already exist, add the code aboveCServerGameDLL::DLLInit
and call before thegpGlobals = pGlobals;
line in that func.
static void MountAdditionalContent()
{
KeyValues *pMainFile = new KeyValues( "gameinfo.txt" );
#ifndef _WINDOWS
// case sensitivity
pMainFile->LoadFromFile( filesystem, "GameInfo.txt", "MOD" );
if (!pMainFile)
#endif
pMainFile->LoadFromFile( filesystem, "gameinfo.txt", "MOD" );
if (pMainFile)
{
KeyValues* pFileSystemInfo = pMainFile->FindKey( "FileSystem" );
if (pFileSystemInfo)
for ( KeyValues *pKey = pFileSystemInfo->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey() )
{
if ( strcmp(pKey->GetName(),"AdditionalContentId") == 0 )
{
int appid = abs(pKey->GetInt());
if (appid)
if( filesystem->MountSteamContent(-appid) != FILESYSTEM_MOUNT_OK )
Warning("Unable to mount extra content with appId: %i\n", appid);
}
}
}
pMainFile->deleteThis();
}
Implementing in gameinfo.txt
Now you can mount content by adding something like this after the ToolsAppId:
AdditionalContentId 220 //HL2 AdditionalContentId 240 //CS Source AdditionalContentId 280 //HL Source AdditionalContentId 320 //HL2 Deatmatch AdditionalContentId 340 //HL2 Lost Coast AdditionalContentId 360 //HL Deathmatch: Source AdditionalContentId 380 //Ep1 AdditionalContentId 400 //Portal AdditionalContentId 420 //Ep2 AdditionalContentId 440 //TF2
Don't forget to add the relevant SearchPaths too.
Bugs
Really big numbers will crash the game with an Error-Dialog by Valve. You could check if the value is within a certain range to stop this from happening, but I think the user will get by himself that this value cannot be mounted.