Mounting multiple games: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(simplified code, avoiding weird errors in console but changing the gameinfo.txt format required)
(Some extra clarification?)
 
(5 intermediate revisions by 3 users not shown)
Line 3: Line 3:
This code extends the Orange Box's [[AdditionalContentId]] system to support '''mounting of multiple [[GCF|Game Cache Files]] via the [[gameinfo.txt]]'''. It can be used with the Ep1 codebase too.
This code extends the Orange Box's [[AdditionalContentId]] system to support '''mounting of multiple [[GCF|Game Cache Files]] via the [[gameinfo.txt]]'''. It can be used with the Ep1 codebase too.


{{warning|Your mod will run regardless of whether or not the user owns the game that you mount content for. If the game isn't owned the content will not be mounted, and error signs will appear everywhere instead!}}
{{warning|Your mod will run regardless of whether or not the user owns the game that you mount content for. If the game isn't owned the content will not be mounted, and error signs and missing textures will appear everywhere instead!}}


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 <code>filesystem->MountSteamContent()</code> must be negative!
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 <code>filesystem->MountSteamContent()</code> must be negative!
Line 9: Line 9:
{{note|1=The code below is version 2, and has ditched [http://developer.valvesoftware.com/w/index.php?title=Mounting_multiple_games&oldid=131419 the previous subkey approach]. It is not compatible with the <code>AdditionalContentId { 220,380 }</code> gameinfo.txt scheme.}}
{{note|1=The code below is version 2, and has ditched [http://developer.valvesoftware.com/w/index.php?title=Mounting_multiple_games&oldid=131419 the previous subkey approach]. It is not compatible with the <code>AdditionalContentId { 220,380 }</code> gameinfo.txt scheme.}}


== Client ==
== The code ==
This code needs to be added to both the client and the server.


'''Search cdll_client_init.cpp for the <code>MountAdditionalContent()</code> function''', and replace it with the code below.
; Client
 
: Search ''cdll_client_int.cpp'' for <code>MountAdditionalContent()</code> and replace it. If it didn't already exist, add the code above <code>CHLClient::Init</code>, then call it from that function right before <code>if ( CommandLine()->FindParm( "-textmode" ) )</code>.
If you don't already <code>MountAdditionalContent()</code> have, just add this function above <code>CHLClient::Init</code>, then call it right before <code>if ( CommandLine()->FindParm( "-textmode" ) )</code>.
; Server
 
: Search ''gameinterface.cpp'' for <code>MountAdditionalContent()</code> and replace it. If it didn't already exist, add the code above <code>CServerGameDLL::DLLInit</code> and call before the <code>gpGlobals = pGlobals;</code> line in that func.
<source lang="cpp">
static void MountAdditionalContent()
{
KeyValues *pMainFile, *pFileSystemInfo;
pMainFile = new KeyValues( "gameinfo.txt" );
if ( pMainFile->LoadFromFile( filesystem, VarArgs("%s/gameinfo.txt", engine->GetGameDirectory()), "MOD" ) )
{
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();
}
</source>
 
== Server ==
 
'''Search gameinterface.cpp for the <code>MountAdditionalContent()</code> function.''' Replace it with this code.
 
If you don't have it, just add it right above <code>CServerGameDLL::DLLInit</code> and call before the <code>gpGlobals = pGlobals;</code> line in that func.


<source lang="cpp">
<source lang="cpp">
static void MountAdditionalContent()
static void MountAdditionalContent()
{
{
KeyValues *pMainFile, *pFileSystemInfo;
KeyValues *pMainFile = new KeyValues( "gameinfo.txt" );
 
#ifndef _WINDOWS
char gamePath[MAX_PATH];
// case sensitivity
engine->GetGameDir( gamePath, MAX_PATH );
pMainFile->LoadFromFile( filesystem, "GameInfo.txt", "MOD" );
Q_StripTrailingSlash( gamePath );
pMainFile = new KeyValues( "gameinfo.txt" );
#ifdef _LINUX
//On linux because of case sensitivity we need to check for both.
pMainFile->LoadFromFile( filesystem, UTIL_VarArgs("%s/GameInfo.txt", gamePath), "MOD" );
if (!pMainFile)
if (!pMainFile)
#endif
#endif
pMainFile->LoadFromFile( filesystem, UTIL_VarArgs("%s/gameinfo.txt", gamePath), "MOD" );
pMainFile->LoadFromFile( filesystem, "gameinfo.txt", "MOD" );
if (pMainFile)
if (pMainFile)
{
{
pFileSystemInfo = pMainFile->FindKey( "FileSystem" );
KeyValues* pFileSystemInfo = pMainFile->FindKey( "FileSystem" );
if (pFileSystemInfo)
if (pFileSystemInfo)
for ( KeyValues *pKey = pFileSystemInfo->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey() )
for ( KeyValues *pKey = pFileSystemInfo->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey() )
Line 83: Line 48:


== Implementing in gameinfo.txt ==
== Implementing in gameinfo.txt ==
Now you can mount content by adding something like this after the ToolsAppId:
Now you can mount content by adding something like this after the ToolsAppId:


Line 96: Line 60:
  AdditionalContentId 420 //Ep2
  AdditionalContentId 420 //Ep2
  AdditionalContentId 440 //TF2
  AdditionalContentId 440 //TF2
AdditionalContentId 500 // L4D - has content incompatibilities!
AdditionalContentId 550 // L4D2 - as above!


Don't forget to add the relevant [[Gameinfo.txt#SearchPaths|SearchPaths]] too.
Don't forget to add the relevant [[Gameinfo.txt#SearchPaths|SearchPaths]] too.
{{note|With the {{l4dbranch|2}} Valve has switched from the [[GCF]] file system to the [[VPK]] format. GCF engine branches cannot mount VPK content, nor the other way around.}}


== Bugs ==
== 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.
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.



Latest revision as of 01:25, 10 March 2025

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.

Warning.pngWarning:Your mod will run regardless of whether or not the user owns the game that you mount content for. If the game isn't owned the content will not be mounted, and error signs and missing textures will appear everywhere instead!

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!

Note.pngNote:The code below is version 2, and has ditched the previous subkey approach. It is not compatible with the 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_int.cpp for MountAdditionalContent() and replace it. If it didn't already exist, add the code above CHLClient::Init, then call it from that function right before if ( CommandLine()->FindParm( "-textmode" ) ).
Server
Search gameinterface.cpp for MountAdditionalContent() and replace it. If it didn't already exist, add the code above CServerGameDLL::DLLInit and call before the gpGlobals = 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.

Note.pngNote:With the Left 4 Dead engine branch Left 4 Dead engine branch Valve has switched from the GCF file system to the VPK format. GCF engine branches cannot mount VPK content, nor the other way around.

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.

Confirm:filesystem->MountSteamContent returns FILESYSTEM_MOUNT_OK, even if the content is not available. There's nothing you can do about it, apart from poking some guy from Valvesoftware.

See also