MCPcopy Create free account
hub / github.com/StrongPC123/Far-Cry-1-Source-Full / GetRandomFileProbe

Method GetRandomFileProbe

CrySystem/DataProbe.cpp:399–448  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

397
398//////////////////////////////////////////////////////////////////////////
399bool CDataProbe::GetRandomFileProbe( SDataProbeContext &ctx,bool bAtEnd )
400{
401 // Try to open file and hash it.
402 FILE *file = fopen( ctx.sFilename.c_str(),"rb" );
403 if (file)
404 {
405 fseek( file,0,SEEK_END );
406 int64 nFileSize = ftell(file);
407
408 // Choose any random size.
409 int64 nOffset = 0;
410 int64 nSize = GetRandom( MAX_PROBE_SIZE ) + 100;
411 if (bAtEnd)
412 {
413 // Prefare probe near the file end.
414 nSize = min( nSize,nFileSize-1 );
415 // Choose offset.
416 nOffset = nFileSize - nSize - GetRandom( 1000 );
417 }
418 else
419 {
420 nOffset = GetRandom( nFileSize - nSize );
421
422 if (nFileSize < MAX_PROBE_SIZE)
423 {
424 // Choose small random offset from both sides.
425 int nOffset1 = 0;
426 int nOffset2 = 0;
427 do {
428 nOffset1 = GetRandom( 1000 );
429 nOffset2 = GetRandom( 1000 );
430 } while (nOffset1+nOffset2 >= nFileSize+1);
431 nOffset = nOffset1;
432 nSize = nFileSize - nOffset2 - nOffset1;
433 }
434 }
435
436 if (nOffset < 0)
437 nOffset = 0;
438 if (nSize < 0)
439 nSize = nFileSize;
440
441 ctx.nSize = nSize;
442 ctx.nOffset = nOffset;
443
444 fclose(file);
445 return true;
446 }
447 return false;
448}
449
450//////////////////////////////////////////////////////////////////////////
451void CDataProbe::RandSeed( uint32 seed )

Callers 2

ServerCreateFileProbeMethod · 0.80
AddProtectedFileMethod · 0.80

Calls 3

GetRandomFunction · 0.85
minFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected