void CEP2GameStats::Event_LoadGame( void ) { BaseClass::Event_LoadGame(); Ep2LevelStats_t *map = m_pCurrentMap; if ( !map ) return; ++map->m_IntCounters[ Ep2LevelStats_t::COUNTER_LOADS ]; StatsLog( " %I64uth load on this map\n", map->m_IntCounters[ Ep2LevelStats_t::COUNTER_LOADS ] ); char const *pchSaveFile = engine->GetMostRecentlyLoadedFileName(); if ( !pchSaveFile || !pchSaveFile[ 0 ] ) return; char name[ 512 ]; Q_snprintf( name, sizeof( name ), "SAVE/%s", pchSaveFile ); Q_DefaultExtension( name, IsX360() ? ".360.sav" : ".sav", sizeof( name ) ); Q_FixSlashes( name ); Q_strlower( name ); Ep2LevelStats_t::SaveGameInfo_t *pSaveGameInfo = &map->m_SaveGameInfo; if ( pSaveGameInfo->m_nCurrentSaveFileTime == 0 || pSaveGameInfo->m_sCurrentSaveFile != name ) { unsigned int uFileTime = filesystem->GetFileTime( name, "GAME" ); // Latch off previous StatsLog( "Relatching save game file due to time or filename change (%s : %u)\n", name, uFileTime ); pSaveGameInfo->Latch( name, uFileTime ); } }
//----------------------------------------------------------------------------- // Purpose: Writes out a new .dem file based on the existing dem file with new camera positions saved into the dem file // Note: The new file is named filename_smooth.dem // Input : *filename - // smoothing - //----------------------------------------------------------------------------- void SaveSmoothingInfo( char const *filename, CSmoothingContext& smoothing ) { // Nothing to do int c = smoothing.smooth.Count(); if ( !c ) return; IBaseFileSystem *fs = g_pFileSystem; FileHandle_t infile, outfile; infile = fs->Open( filename, "rb", "GAME" ); if ( infile == FILESYSTEM_INVALID_HANDLE ) return; int filesize = fs->Size( infile ); char outfilename[ 512 ]; Q_StripExtension( filename, outfilename, sizeof( outfilename ) ); Q_strncat( outfilename, "_smooth", sizeof(outfilename), COPY_ALL_CHARACTERS ); Q_DefaultExtension( outfilename, ".dem", sizeof( outfilename ) ); outfile = fs->Open( outfilename, "wb", "GAME" ); if ( outfile == FILESYSTEM_INVALID_HANDLE ) { fs->Close( infile ); return; } int i; // The basic algorithm is to seek to each sample and "overwrite" it during copy with the new data... int lastwritepos = 0; for ( i = 0; i < c; i++ ) { demosmoothing_t *p = &smoothing.smooth[ i ]; int copyamount = p->file_offset - lastwritepos; COM_CopyFileChunk( outfile, infile, copyamount ); fs->Seek( infile, p->file_offset, FILESYSTEM_SEEK_HEAD ); // wacky hacky overwriting fs->Write( &p->info, sizeof( democmdinfo_t ), outfile ); lastwritepos = fs->Tell( outfile ); fs->Seek( infile, p->file_offset + sizeof( democmdinfo_t ), FILESYSTEM_SEEK_HEAD ); } // Copy the final bit of data, if any... int final = filesize - lastwritepos; COM_CopyFileChunk( outfile, infile, final ); fs->Close( outfile ); fs->Close( infile ); }
bool GetModelNameFromSourceFile( char const *filename, char *modelname, int maxlen ) { modelname[0]=0; int filelength; char *buffer = (char *)COM_LoadFile( filename, &filelength ); if ( !buffer ) { vprint( 0, "Couldn't load %s\n", filename ); return false; } bool valid = false; // Parse tokens char *current = buffer; while ( current ) { current = CC_ParseToken( current ); if ( strlen( com_token ) <= 0 ) break; if ( stricmp( com_token, "$modelname" ) ) continue; current = CC_ParseToken( current ); strcpy( modelname, com_token ); _strlwr( modelname ); Q_FixSlashes( modelname ); Q_DefaultExtension( modelname, ".mdl", maxlen ); valid = true; break; } COM_FreeFile( (unsigned char *)buffer ); if ( !valid ) { vprint( 0, ".qc file %s missing $modelname directive!!!\n", filename ); } return valid; }
//----------------------------------------------------------------------------- // Purpose: Loads up all camera samples from a .dem file into the passed in context. // Input : *filename - // smoothing - //----------------------------------------------------------------------------- void LoadSmoothingInfo( const char *filename, CSmoothingContext& smoothing ) { char name[ MAX_OSPATH ]; Q_strncpy (name, filename, sizeof(name) ); Q_DefaultExtension( name, ".dem", sizeof( name ) ); CToolDemoFile demoFile; if ( !demoFile.Open( filename, true ) ) { Warning( "ERROR: couldn't open %s.\n", name ); return; } demoheader_t * header = demoFile.ReadDemoHeader(); if ( !header ) { demoFile.Close(); return; } Msg( "\n\n" ); Msg( "--------------------------------------------------------------\n" ); Msg( "demofilestamp: '%s'\n", header->demofilestamp ); Msg( "demoprotocol: %i\n", header->demoprotocol ); Msg( "networkprotocol: %i\n", header->networkprotocol ); Msg( "servername: '%s'\n", header->servername ); Msg( "clientname: '%s'\n", header->clientname ); Msg( "mapname: '%s'\n", header->mapname ); Msg( "gamedirectory: '%s'\n", header->gamedirectory ); Msg( "playback_time: %f seconds\n", header->playback_time ); Msg( "playback_ticks: %i ticks\n", header->playback_ticks ); Msg( "playback_frames: %i frames\n", header->playback_frames ); Msg( "signonlength: %s\n", Q_pretifymem( header->signonlength ) ); smoothing.active = true; Q_strncpy( smoothing.filename, name, sizeof(smoothing.filename) ); smoothing.smooth.RemoveAll(); ClearSmoothingInfo( smoothing ); ParseSmoothingInfo( demoFile, smoothing.smooth ); Msg( "--------------------------------------------------------------\n" ); Msg( "smoothing data: %i samples\n", smoothing.smooth.Count() ); if ( verbose ) { int c = smoothing.smooth.Count(); for ( int i = 0; i < c; ++i ) { demosmoothing_t& sample = smoothing.smooth[ i ]; Msg( "Sample %i:\n", i ); Msg( " file pos: %i\n", sample.file_offset ); Msg( " tick: %i\n", sample.frametick ); Msg( " flags: %s\n", DescribeFlags( sample.info.flags ) ); Msg( " Original Data:\n" ); Msg( " origin: %.4f %.4f %.4f\n", sample.info.viewOrigin.x, sample.info.viewOrigin.y, sample.info.viewOrigin.z ); Msg( " viewangles: %.4f %.4f %.4f\n", sample.info.viewAngles.x, sample.info.viewAngles.y, sample.info.viewAngles.z ); Msg( " localviewangles: %.4f %.4f %.4f\n", sample.info.localViewAngles.x, sample.info.localViewAngles.y, sample.info.localViewAngles.z ); Msg( " Resampled Data:\n" ); Msg( " origin: %.4f %.4f %.4f\n", sample.info.viewOrigin2.x, sample.info.viewOrigin2.y, sample.info.viewOrigin2.z ); Msg( " viewangles: %.4f %.4f %.4f\n", sample.info.viewAngles2.x, sample.info.viewAngles2.y, sample.info.viewAngles2.z ); Msg( " localviewangles: %.4f %.4f %.4f\n", sample.info.localViewAngles2.x, sample.info.localViewAngles2.y, sample.info.localViewAngles2.z ); Msg( "\n" ); } } demoFile.Close(); }