Ejemplo n.º 1
0
/*
=================
SV_LoadGame_f
=================
*/
void    SV_LoadGame_f( void ) {
	char filename[MAX_QPATH], mapname[MAX_QPATH];
	byte *buffer;
	int size;

	Q_strncpyz( filename, Cmd_Argv( 1 ), sizeof( filename ) );
	if ( !filename[0] ) {
		Com_Printf( "You must specify a savegame to load\n" );
		return;
	}
	if ( Q_strncmp( filename, "save/", 5 ) && Q_strncmp( filename, "save\\", 5 ) ) {
		Q_strncpyz( filename, va( "save/%s", filename ), sizeof( filename ) );
	}
	if ( !strstr( filename, ".svg" ) ) {
		Q_strcat( filename, sizeof( filename ), ".svg" );
	}

	size = FS_ReadFile( filename, NULL );
	if ( size < 0 ) {
		Com_Printf( "Can't find savegame %s\n", filename );
		return;
	}

	buffer = Hunk_AllocateTempMemory( size );
	FS_ReadFile( filename, (void **)&buffer );

	// read the mapname, if it is the same as the current map, then do a fast load
	Com_sprintf( mapname, sizeof( mapname ), buffer + sizeof( int ) );

	if ( com_sv_running->integer && ( com_frameTime != sv.serverId ) ) {
		// check mapname
		if ( !Q_stricmp( mapname, sv_mapname->string ) ) {    // same

			if ( Q_stricmp( filename, "save/current.svg" ) != 0 ) {
				// copy it to the current savegame file
				FS_WriteFile( "save/current.svg", buffer, size );
			}

			Hunk_FreeTempMemory( buffer );

			Cvar_Set( "savegame_loading", "2" );  // 2 means it's a restart, so stop rendering until we are loaded
			SV_MapRestart_f();  // savegame will be loaded after restart

			return;
		}
	}

	Hunk_FreeTempMemory( buffer );

	// otherwise, do a slow load
	if ( Cvar_VariableIntegerValue( "sv_cheats" ) ) {
		Cbuf_ExecuteText( EXEC_APPEND, va( "spdevmap %s", filename ) );
	} else {    // no cheats
		Cbuf_ExecuteText( EXEC_APPEND, va( "spmap %s", filename ) );
	}
}
Ejemplo n.º 2
0
/*
=================
SV_LoadGame_f
=================
*/
void SV_LoadGame_f(void) {
	char            filename[MAX_QPATH], mapname[MAX_QPATH], savedir[MAX_QPATH], *cl_profileStr = Cvar_VariableString("cl_profile");
	byte           *buffer;
	int             size;

	// dont allow command if another loadgame is pending
	if(Cvar_VariableIntegerValue("savegame_loading")) {
		return;
	}
	if(sv_reloading->integer) {
		// (SA) disabling
//  if(sv_reloading->integer && sv_reloading->integer != RELOAD_FAILED )    // game is in 'reload' mode, don't allow starting new maps yet.
		return;
	}

	Q_strncpyz(filename, Cmd_Argv(1), sizeof(filename));
	if(!filename[0]) {
		Com_Printf("You must specify a savegame to load\n");
		return;
	}

	if(com_gameInfo.usesProfiles && cl_profileStr[0]) {
		Com_sprintf(savedir, sizeof(savedir), "profiles/%s/save/", cl_profileStr);
	} else {
		Q_strncpyz(savedir, "save/", sizeof(savedir));
	}

	/*if ( Q_strncmp( filename, "save/", 5 ) && Q_strncmp( filename, "save\\", 5 ) ) {
	   Q_strncpyz( filename, va("save/%s", filename), sizeof( filename ) );
	   } */

	// go through a va to avoid vsnprintf call with same source and target
	Q_strncpyz(filename, va("%s%s", savedir, filename), sizeof(filename));

	// enforce .sav extension
	if(!strstr(filename, ".") || Q_strncmp(strstr(filename, ".") + 1, "sav", 3)) {
		Q_strcat(filename, sizeof(filename), ".sav");
	}
	// use '/' instead of '\\' for directories
	while(strstr(filename, "\\")) {
		*(char *)strstr(filename, "\\") = '/';
	}

	size = FS_ReadFile(filename, NULL);
	if(size < 0) {
		Com_Printf("Can't find savegame %s\n", filename);
		return;
	}

	//buffer = Hunk_AllocateTempMemory(size);
	FS_ReadFile(filename, (void **)&buffer);

	// read the mapname, if it is the same as the current map, then do a fast load
	Q_strncpyz(mapname, (const char *)(buffer + sizeof(int)), sizeof(mapname));

	if(com_sv_running->integer && (com_frameTime != sv.serverId)) {
		// check mapname
		if(!Q_stricmp(mapname, sv_mapname->string)) { // same

			if(Q_stricmp(filename, va("%scurrent.sav", savedir)) != 0) {
				// copy it to the current savegame file
				FS_WriteFile(va("%scurrent.sav", savedir), buffer, size);
			}

			Hunk_FreeTempMemory(buffer);

			Cvar_Set("savegame_loading", "2");	// 2 means it's a restart, so stop rendering until we are loaded
			// set the filename
			Cvar_Set("savegame_filename", filename);
			// quick-restart the server
			SV_MapRestart_f();	// savegame will be loaded after restart

			return;
		}
	}

	Hunk_FreeTempMemory(buffer);

	// otherwise, do a slow load
	if(Cvar_VariableIntegerValue("sv_cheats")) {
		Cbuf_ExecuteText(EXEC_APPEND, va("spdevmap %s", filename));
	} else { // no cheats
		Cbuf_ExecuteText(EXEC_APPEND, va("spmap %s", filename));
	}
}