Advertisement
ph0ne

rip constant crits

Jun 14th, 2013
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. //=========================================================
  2. bool __stdcall ShouldCalculateNewCritCommands ( void )
  3. {
  4.     if ( cl.curtime >= cl.crit.fNextCrit )
  5.         return true;
  6.  
  7.     if ( cl.crit.wpnIndex != cl.crit.lastWeapon )
  8.         return true;
  9.  
  10.     if ( cl.crit.playerIndex != cl.crit.lastPlayer )
  11.         return true;
  12.  
  13.     return false;
  14. }
  15. //=========================================================
  16. bool __stdcall IsShotCritical ( int iSeed )
  17. {
  18.     int index = (cl.crit.wpnIndex << 8) | cl.crit.playerIndex;
  19.    
  20.     if ( cl.pWeapon->IsMelee() )
  21.         index <<= 8;
  22.    
  23.     tf2hook->RandomSeed ( index ^ iSeed );
  24.  
  25.     return ( tf2hook->RandomInt ( 0, 9999 ) < 100 );
  26. }
  27. //=========================================================
  28. void __stdcall ForceCriticalHit ( CUserCmd* cmd )
  29. {
  30.     int i, cmdNum, iSeed, critCmd, best;
  31.    
  32.     cl.crit.wpnIndex = cl.pWeapon->GetClientNetworkable()->entindex();
  33.     cl.crit.playerIndex = cl.player->GetClientNetworkable()->entindex();
  34.  
  35.     if ( !tf2hook->IsCritBoosted ( cl.player->GetTFPlayerShared() ) && cl.pWeapon->CanFireCriticalShot() )
  36.     {
  37.         if ( ShouldCalculateNewCritCommands() )
  38.         {
  39.             // make sure we use a seed with the lowest spread possible (while critting).
  40.             best = cl.pWeapon->GetBestSpreadSeed();
  41.             for ( i = 0, cmdNum = cmd->commandNumber; i < MAX_CRIT_CMDS; cmdNum++ )
  42.             {
  43.                 iSeed = tf2hook->MD5_PseudoRandom ( cmdNum ) & 0x7FFFFFFF;
  44.                 if ( best != -1 ) {
  45.                     if ( (iSeed & 255) != best  )
  46.                         continue;
  47.                 }
  48.            
  49.                 if ( !IsShotCritical ( iSeed ) )
  50.                     continue;
  51.  
  52.                 // cache dat command_number.
  53.                 cl.crit.cmds[ i++ ] = cmdNum;
  54.             }
  55.  
  56.             // set the time for us to recalculate.
  57.             cl.crit.fNextCrit = cl.curtime + CRIT_INTERVAL;
  58.         }
  59.  
  60.         // force dat seed.
  61.         critCmd = cl.crit.cmds[ (cl.crit.cmdIndex++) % MAX_CRIT_CMDS ];
  62.         cmd->commandNumber = critCmd;
  63.         cmd->randomSeed = tf2hook->MD5_PseudoRandom ( critCmd ) & 0x7FFFFFFF;
  64.     }
  65.    
  66.     cl.crit.lastWeapon = cl.crit.wpnIndex;
  67.     cl.crit.lastPlayer = cl.crit.playerIndex;
  68. }
  69. //=========================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement