hlsdk

hlsdk

May 11th, 2010
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.37 KB | None | 0 0
  1. bool IsShotCritical ( C_BaseCombatWeapon* pBaseWeapon )
  2. {
  3.     if (!pBaseWeapon)
  4.         return false;
  5.     DWORD result = false;
  6.     DWORD FuncOffset = 0x568;
  7.     DWORD weaponOffset = 0x1700;
  8.     DWORD weaponSeed = 0;
  9.     __asm
  10.     {
  11.         pushad;
  12.         mov ecx, pBaseWeapon;
  13.         mov eax, [ecx+0x1700];
  14.         push eax;
  15.         mov eax, [ecx];
  16.         mov eax, [eax+0x568];
  17.         call eax;
  18.         mov result, eax;
  19.         pop eax;
  20.         mov ecx, pBaseWeapon;
  21.         mov [ecx+0x1700], eax;
  22.         popad;
  23.     }
  24.     return (bool)(result&1);
  25. }
  26.  
  27. //=========== Copyright © 1990-2010, HL-SDK, All rights reserved. ===========//
  28. //
  29. // Purpose: Additional information can be found in header file.
  30. //
  31. //===========================================================================//
  32.  
  33. #include "Critbot.h"
  34.  
  35. #include <in_buttons.h>
  36.  
  37. #include <Release/Memory.h>
  38. #include <Release/Entity.h>
  39. #include <Release/Weapon.h>
  40. #include <Release/Interfaces.h>
  41. #include <Release/TF2.h>
  42.  
  43. #include <Release/SigManager.h>
  44.  
  45. enum { CRIT_NONE, CRIT_ALL, CRIT_MELEE, CRIT_SPECIALIZED };
  46.  
  47. CCritbot::CCritbot()
  48. {
  49.     m_pGlobalSeed = (int*)g_pSigManager->Find("pGlobalSeed");
  50.     m_iFramesWaited = 0;
  51.     m_iCritMult = 0;
  52. }
  53.  
  54. CCritbot::~CCritbot()
  55. {
  56. }
  57.  
  58. void ms_crits_enable_callback( IConVar *var, const char *pOldValue, float flOldValue );
  59. static ConVar ms_crits_enable( "ms_crits_enable", "0", FCVAR_NONE, "Crithack enabled? 0 = no, 1 = all weapons, 2 = melee only", ms_crits_enable_callback );
  60. void ms_crits_enable_callback( IConVar *var, const char *pOldValue, float flOldValue )
  61. {
  62.     switch (ms_crits_enable.GetInt())
  63.     {
  64.         case CRIT_NONE:
  65.             Msg("[MS] Crits turned OFF\n");
  66.             break;
  67.         case CRIT_ALL:
  68.             Msg("[MS] Crits turned ON for ALL WEAPONS\n");
  69.             break;
  70.         case CRIT_MELEE:
  71.             Msg("[MS] Crits turned ON for MELEE WEAPONS\n");
  72.             break;
  73.         case CRIT_SPECIALIZED:
  74.             Msg("[MS] Crits turned ON in SPECIALIZED FRAME WAITING MODE\n");
  75.             break;
  76.     }
  77. }
  78.  
  79. bool CCritbot::Run(CUserCmd* pCmd)
  80. {
  81.     C_BaseCombatWeapon* pWeapon = Zeus::Weapons::GetFromPlayer((C_BasePlayer*)Zeus::Entity::Me());
  82.    
  83.     if (!pWeapon)
  84.         return false;
  85.  
  86.     m_iCritMult = *reinterpret_cast<GenDT_TFPlayer*>(Zeus::Entity::Me())->Shared()->iCritMult();
  87.  
  88.     //if (!(pCmd->buttons & IN_ATTACK)) //We're not attempting to fire
  89.     //{
  90.     //  m_iFramesWaited = 0; //Reset frame counter
  91.     //  return false;        //Nothing to do.
  92.     //}
  93.  
  94.     int GlobalSeed_backup = *m_pGlobalSeed;
  95.     *m_pGlobalSeed = pCmd->random_seed;
  96.  
  97.     bool bCrit = Zeus::Weapons::IsShotCritical(pWeapon);
  98.        
  99.     *m_pGlobalSeed = GlobalSeed_backup;
  100.  
  101.     switch (ms_crits_enable.GetInt())
  102.     {
  103.         case CRIT_NONE: //no crits
  104.             break;
  105.         case CRIT_ALL:
  106.             if (!bCrit)
  107.                 pCmd->buttons &= ~0x00000001;
  108.             break;
  109.         case CRIT_MELEE: //melee only
  110.             if (Zeus::Weapons::IsMelee(Zeus::Weapons::GetID(pWeapon)))
  111.             {
  112.                 if (!bCrit)
  113.                     pCmd->buttons &= ~0x00000001;
  114.             }
  115.             break;
  116.         case CRIT_SPECIALIZED: //Special frame-waiting method
  117.             {
  118.                 if (!bCrit)
  119.                 {
  120.                     m_iFramesWaited++;
  121.                     if (m_iCritMult < 40)
  122.                     {
  123.                         if (m_iFramesWaited < 5) //If our critmult is low and we haven't waited 10 frames yet, hold back
  124.                             pCmd->buttons &= ~IN_ATTACK;
  125.                     }
  126.                     else
  127.                     {
  128.                         if (m_iFramesWaited < 30) //Critmult is pretty high, we can wait longer
  129.                             pCmd->buttons &= ~IN_ATTACK;
  130.                     }
  131.                 }
  132.                 else
  133.                 {
  134.                     m_iFramesWaited = 0; //We are critting, reset counter.
  135.                 }
  136.             }
  137.             break;
  138.         default:
  139.             break;
  140.     }
  141.     return false;
  142. }
Add Comment
Please, Sign In to add comment