Ayuto

custom_types

Dec 23rd, 2013
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 17.65 KB | None | 0 0
  1. # =============================================================================
  2. # >> IMPORTS
  3. # =============================================================================
  4. # Python
  5. import random
  6. import os
  7.  
  8. # binutils
  9. import binutils
  10.  
  11. from binutils import Convention
  12.  
  13.  
  14. # =============================================================================
  15. # >> CONSTANTS
  16. # =============================================================================
  17. RAND_MAX = 0x7fff
  18.  
  19.  
  20. # =============================================================================
  21. # >> GLOBAL VARIABLES
  22. # =============================================================================
  23. manager = binutils.TypeManager()
  24.  
  25.  
  26. # =============================================================================
  27. # >> QAngle
  28. # =============================================================================
  29. class QAngle(binutils.CustomType):
  30.     __metaclass__ = manager
  31.  
  32.     x = manager.attribute('float', 0)
  33.     y = manager.attribute('float', 4)
  34.     z = manager.attribute('float', 8)
  35.  
  36.     size = 12
  37.  
  38.     def Init(self, x=0, y=0, z=0):
  39.         self.x = x
  40.         self.y = y
  41.         self.z = z
  42.  
  43.     def Random(self, min_val, max_val):
  44.         for x in 'xyz':
  45.             rand = float(random.randint(0, RAND_MAX)) / RAND_MAX
  46.             setattr(self, x, min_val + (rand * (max_val - min_val)))
  47.  
  48.     def __iter__(self):
  49.         return iter((self.x, self.y, self.z))
  50.  
  51.  
  52. # =============================================================================
  53. # >> Vector
  54. # =============================================================================
  55. class Vector(binutils.CustomType):
  56.     __metaclass__ = manager
  57.  
  58.     x = manager.attribute('float', 0)
  59.     y = manager.attribute('float', 4)
  60.     z = manager.attribute('float', 8)
  61.  
  62.     size = 12
  63.  
  64.     def Init(self, x=0, y=0, z=0):
  65.         self.x = x
  66.         self.y = y
  67.         self.z = z
  68.  
  69.     def __iter__(self):
  70.         return iter((self.x, self.y, self.z))
  71.  
  72.  
  73. # =============================================================================
  74. # >> CUserCmd
  75. # =============================================================================
  76. class CUserCmd(binutils.CustomType):
  77.     __metaclass__ = manager
  78.  
  79.     vtable           = manager.attribute('ptr', 0)
  80.     command_number   = manager.attribute('int', 4)
  81.     tick_count       = manager.attribute('int', 8)
  82.     viewangles       = manager.attribute('QAngle', 12, aligned=True)
  83.     forwardmove      = manager.attribute('float', 24)
  84.     sidemove         = manager.attribute('float', 28)
  85.     upmove           = manager.attribute('float', 32)
  86.     buttons          = manager.attribute('int', 36)
  87.     impulse          = manager.attribute('uchar', 40)
  88.     weaponselect     = manager.attribute('int', 44)
  89.     weaponsubtype    = manager.attribute('int', 48)
  90.     random_seed      = manager.attribute('int', 52)
  91.     mousedx          = manager.attribute('short', 56)
  92.     mousedy          = manager.attribute('short', 60)
  93.     hasbeenpredicted = manager.attribute('bool', 64)
  94.  
  95.     size = 68
  96.  
  97.     def Init(self):
  98.         self.Reset()
  99.  
  100.     def Reset(self):
  101.         self.command_number   = 0
  102.         self.tick_count       = 0
  103.         self.forwardmove      = 0
  104.         self.sidemove         = 0
  105.         self.upmove           = 0
  106.         self.buttons          = 0
  107.         self.impulse          = 0
  108.         self.weaponselect     = 0
  109.         self.weaponsubtype    = 0
  110.         self.random_seed      = 0
  111.         self.mousedx          = 0
  112.         self.mousedy          = 0
  113.         self.hasbeenpredicted = False;
  114.  
  115.         self.viewangles.Init()
  116.  
  117.  
  118. # =============================================================================
  119. # >> IHandleEntity
  120. # =============================================================================
  121. class IHandleEntity(binutils.CustomType):
  122.     __metaclass__ = manager
  123.  
  124.     destructor = manager.virtual_function(0, 'p)v')
  125.     SetRefHandle = manager.virtual_function(1, 'pp)v')
  126.     GetRefHandle = manager.virtual_function(2, 'p)p', 'CBaseHandle')
  127.  
  128.  
  129. # =============================================================================
  130. # >> CBaseEntity
  131. # =============================================================================
  132. class CBaseEntity(IHandleEntity):
  133.     __metaclass__ = manager
  134.  
  135.     GetDataDescMap = manager.virtual_function(11, 'p)p', 'datamap_t')
  136.  
  137.     m_iClassname = manager.attribute('string', 92)
  138.  
  139.  
  140. # =============================================================================
  141. # >> CCSPlayer
  142. # =============================================================================
  143. class CCSPlayer(CBaseEntity):
  144.     __metaclass__ = manager
  145.  
  146.     PlayerRunCommand = manager.function(
  147.         'cstrike/bin/server',
  148.         '55 8B EC 83 EC 58 56 89 4D A8',
  149.         'ppp)v'
  150.     )
  151.  
  152.  
  153. # =============================================================================
  154. # >> CBaseHandle
  155. # =============================================================================
  156. class CBaseHandle(CBaseEntity):
  157.     __metaclass__ = manager
  158.  
  159.     m_Index = manager.attribute('ulong', 0)
  160.  
  161.  
  162. # =============================================================================
  163. # >> datamap_t
  164. # =============================================================================
  165. class datamap_t(binutils.CustomType):
  166.     __metaclass__ = manager
  167.  
  168.     dataDesc                = manager.attribute('typedescription_t', 0, is_array=True)
  169.     dataNumFields           = manager.attribute('int', 4)
  170.     dataClassName           = manager.attribute('string', 8)
  171.     baseMap                 = manager.attribute('datamap_t', 12)
  172.     chains_validated        = manager.attribute('bool', 16)
  173.     packed_offsets_computed = manager.attribute('bool', 20)
  174.     packed_size             = manager.attribute('int', 24)
  175.     bValidityChecked        = manager.attribute('bool', 28)
  176.  
  177.     size = 32
  178.  
  179.  
  180. # =============================================================================
  181. # >> typedescription_t
  182. # =============================================================================
  183. class typedescription_t(binutils.CustomType):
  184.     __metaclass__ = manager
  185.  
  186.     fieldType        = manager.attribute('int', 0)
  187.     fieldName        = manager.attribute('string', 4)
  188.     fieldOffset      = manager.attribute('int', 8, 2, True, True)
  189.     fieldSize        = manager.attribute('ushort', 16)
  190.     flags            = manager.attribute('short', 18)
  191.     externalName     = manager.attribute('string', 20)
  192.     pSaveRestoreOps  = manager.attribute('ISaveRestoreOps', 24)
  193.     inputFunc        = manager.attribute('inputfunc_t', 28)
  194.     td               = manager.attribute('datamap_t', 32)
  195.     fieldSizeInBytes = manager.attribute('int', 36)
  196.     override_field   = manager.attribute('typedescription_t', 40)
  197.     override_count   = manager.attribute('int', 44)
  198.     fieldTolerance   = manager.attribute('float', 48)
  199.  
  200.     size = 52 if os.name == 'nt' else 56
  201.  
  202.  
  203. # =============================================================================
  204. # >> inputfunc_t
  205. # =============================================================================
  206. inputfunc_t = manager.create_function_typedef(
  207.     'inputfunc_t', Convention.THISCALL, 'pp)v'
  208. )
  209.  
  210.  
  211. # =============================================================================
  212. # >> ISaveRestoreOps
  213. # =============================================================================
  214. class ISaveRestoreOps(binutils.CustomType):
  215.     __metaclass__ = manager
  216.  
  217.     vtable = manager.attribute('ptr', 0)
  218.  
  219.  
  220. # =============================================================================
  221. # >> IServerTools
  222. # =============================================================================
  223. class IServerTools(binutils.CustomType):
  224.     __metaclass__ = manager
  225.  
  226.     destructor                 = manager.virtual_function(0, 'p)v')
  227.     GetIServerEntity           = manager.virtual_function(1, 'pp)p', 'IServerEntity')
  228.     SnapPlayerToPosition       = manager.virtual_function(2, 'pppp)b')
  229.     GetPlayerPosition          = manager.virtual_function(3, 'pppp)b')
  230.     SetPlayerFOV               = manager.virtual_function(4, 'pip)b')
  231.     GetPlayerFOV               = manager.virtual_function(5, 'pp)i')
  232.     IsInNoClipMode             = manager.virtual_function(6, 'pp)b')
  233.     FirstEntity                = manager.virtual_function(7, 'p)p', 'CBaseEntity')
  234.     NextEntity                 = manager.virtual_function(8, 'pp)p', 'CBaseEntity')
  235.     FindEntityByHammerID       = manager.virtual_function(9, 'pi)p', 'CBaseEntity')
  236.     GetKeyValue                = manager.virtual_function(10, 'ppZpi)b')
  237.     SetKeyValueString          = manager.virtual_function(11, 'ppZZ)b')
  238.     SetKeyValueFloat           = manager.virtual_function(12, 'ppZf)b')
  239.     SetKeyValueVector          = manager.virtual_function(13, 'ppZp)b')
  240.     CreateEntityByName         = manager.virtual_function(14, 'pZ)p', 'CBaseEntity')
  241.     DispatchSpawn              = manager.virtual_function(15, 'pp)v')
  242.     ReloadParticleDefintions   = manager.virtual_function(16, 'pZpi)v')
  243.     AddOriginToPVS             = manager.virtual_function(17, 'pp)v')
  244.     MoveEngineViewTo           = manager.virtual_function(18, 'ppp)v')
  245.     DestroyEntityByHammerId    = manager.virtual_function(19, 'pi)b')
  246.     GetBaseEntityByEntIndex    = manager.virtual_function(20, 'pi)p', 'CBaseEntity')
  247.     RemoveEntity               = manager.virtual_function(21, 'pp)v')
  248.     RemoveEntityImmediate      = manager.virtual_function(22, 'pp)v')
  249.     GetEntityFactoryDictionary = manager.virtual_function(23, 'p)p', 'IEntityFactoryDictionary')
  250.     SetMoveType                = manager.virtual_function(24, 'ppi)v')
  251.     SetMoveType2               = manager.virtual_function(25, 'ppii)v')
  252.     ResetSequence              = manager.virtual_function(26, 'ppi)v')
  253.     ResetSequenceInfo          = manager.virtual_function(27, 'pp)v')
  254.     ClearMultiDamage           = manager.virtual_function(28, 'p)v')
  255.     ApplyMultiDamage           = manager.virtual_function(29, 'p)v')
  256.     AddMultiDamage             = manager.virtual_function(30, 'ppp)v')
  257.     RadiusDamage               = manager.virtual_function(31, 'pppfip)v')
  258.     GetTempEntsSystem          = manager.virtual_function(32, 'p)p', 'ITempEntsSystem')
  259.  
  260.  
  261. # =============================================================================
  262. # >> IEntityFactoryDictionary
  263. # =============================================================================
  264. class IEntityFactoryDictionary(binutils.CustomType):
  265.     __metaclass__ = manager
  266.  
  267.     InstallFactory    = manager.virtual_function(0, 'ppZ)v')
  268.     Create            = manager.virtual_function(1, 'pZ)p', 'IServerNetworkable')
  269.     Destroy           = manager.virtual_function(2, 'pZp)v')
  270.     FindFactory       = manager.virtual_function(3, 'pZ)p', 'IEntityFactory')
  271.     GetCannonicalName = manager.virtual_function(4, 'pZ)Z')
  272.  
  273.  
  274. # =============================================================================
  275. # >> IEntityFactory
  276. # =============================================================================
  277. class IEntityFactory(binutils.CustomType):
  278.     __metaclass__ = manager
  279.  
  280.     Create        = manager.virtual_function(0, 'pZ)p', 'IServerNetworkable')
  281.     Destroy       = manager.virtual_function(1, 'pp)v')
  282.     GetEntitySize = manager.virtual_function(2, 'p)I')
  283.  
  284.  
  285. # =============================================================================
  286. # >> IPredictionSystem
  287. # =============================================================================
  288. class IPredictionSystem(binutils.CustomType):
  289.     __metaclass__ = manager
  290.  
  291.     vtable           = manager.attribute('ptr', 0)
  292.     m_pNextSystem    = manager.attribute('IPredictionSystem', 4)
  293.     m_bSuppressEvent = manager.attribute('bool', 8)
  294.     m_pSuppressHost  = manager.attribute('CBaseEntity', 12)
  295.     m_nStatusPushed  = manager.attribute('int', 16)
  296.  
  297.     destructor = manager.virtual_function(0, 'p)v')
  298.  
  299.  
  300. # =============================================================================
  301. # >> ITempEntsSystem
  302. # =============================================================================
  303. class ITempEntsSystem(IPredictionSystem):
  304.     __metaclass__ = manager
  305.  
  306.     BeamRingPoint = manager.virtual_function(8, 'ppfpffiiiiffifiiiiii)v')
  307.  
  308.  
  309. # =============================================================================
  310. # >> IRecipientFilter
  311. # =============================================================================
  312. class IRecipientFilter(binutils.CustomType):
  313.     __metaclass__ = manager
  314.  
  315.     vtable = manager.attribute('ptr', 0)
  316.  
  317.     destructor        = manager.virtual_function(0, 'p)v')
  318.     IsReliable        = manager.virtual_function(1, 'p)b')
  319.     IsInitMessage     = manager.virtual_function(2, 'p)b')
  320.     GetRecipientCount = manager.virtual_function(3, 'p)i')
  321.     GetRecipientIndex = manager.virtual_function(4, 'pi)i')
  322.  
  323.  
  324. # =============================================================================
  325. # >> CRecipientFilter
  326. # =============================================================================
  327. class CRecipientFilter(IRecipientFilter):
  328.     __metaclass__ = manager
  329.  
  330.     size = 40
  331.  
  332.     constructor = manager.function(
  333.         'cstrike/bin/server',
  334.         '8B C1 33 C9 C7 00 2A 2A 2A 2A 89 48 08',
  335.         'p)v'
  336.     )
  337.  
  338.     AddRecipient = manager.function(
  339.         'cstrike/bin/server',
  340.         '55 8B EC 8B 55 08 85 D2 0F 84 2A 2A 2A 2A 8B 42 18 53 85 C0 74 2A',
  341.         'pp)v'
  342.     )
  343.  
  344.     def AddAllPlayers(self):
  345.         for player in get_player_instances():
  346.             self.AddRecipient(player)
  347.  
  348.  
  349. # =============================================================================
  350. # >> CreateInterfaceFn
  351. # =============================================================================
  352. CreateInterfaceFn = manager.create_function_typedef(
  353.     'CreateInterfaceFn', Convention.CDECL, 'Zi)p'
  354. )
  355.  
  356.  
  357. # =============================================================================
  358. # >> InstantiateInterfaceFn
  359. # =============================================================================
  360. InstantiateInterfaceFn = manager.create_function_typedef(
  361.     'InstantiateInterfaceFn', Convention.CDECL, 'v)p'
  362. )
  363.  
  364.  
  365. # =============================================================================
  366. # >> InterfaceReg
  367. # =============================================================================
  368. class InterfaceReg(binutils.CustomType):
  369.     __metaclass__ = manager
  370.  
  371.     m_CreateFn       = manager.attribute('InstantiateInterfaceFn', 0)
  372.     m_pName          = manager.attribute('string', 4)
  373.     m_pNext          = manager.attribute('InterfaceReg', 8)
  374.     s_pInterfaceRegs = manager.attribute('InterfaceReg', 12)
  375.  
  376.  
  377. # =============================================================================
  378. # >> IServerGameDLL
  379. # =============================================================================
  380. class IServerGameDLL(binutils.CustomType):
  381.     __metaclass__ = manager
  382.  
  383.     GetAllServerClasses = manager.virtual_function(11, 'p)p', 'ServerClass')
  384.     GetGameDescription  = manager.virtual_function(12, 'p)Z')
  385.  
  386.  
  387. # =============================================================================
  388. # >> ServerClass
  389. # =============================================================================
  390. class ServerClass(binutils.CustomType):
  391.     __metaclass__ = manager
  392.  
  393.     m_pNetworkName          = manager.attribute('string', 0)
  394.     m_pTable                = manager.attribute('SendTable', 4)
  395.     m_pNext                 = manager.attribute('ServerClass', 8)
  396.     m_ClassID               = manager.attribute('int', 12)
  397.     m_InstanceBaselineIndex = manager.attribute('int', 16)
  398.  
  399.  
  400. # =============================================================================
  401. # >> SendTable
  402. # =============================================================================
  403. class SendTable(binutils.CustomType):
  404.     __metaclass__ = manager
  405.  
  406.     m_pProps                                  = manager.attribute('SendProp', 0)
  407.     m_nProps                                  = manager.attribute('int', 4)
  408.     m_pNetTableName                           = manager.attribute('string', 8)
  409.     m_pPrecalc                                = manager.attribute('CSendTablePrecalc', 12)
  410.     m_bInitialized                            = manager.attribute('bool', 16)
  411.     m_bHasBeenWritten                         = manager.attribute('bool', 20)
  412.     m_bHasPropsEncodedAgainstCurrentTickCount = manager.attribute('bool', 24)
  413.  
  414.  
  415. # =============================================================================
  416. # >> Util pipe
  417. # =============================================================================
  418. utils = manager.create_pipe(
  419.     EntityByIndex = manager.pipe_function(
  420.         'cstrike/bin/server',
  421.         '55 8B EC 8B 45 08 56 33 F6 85 C0 7E 32 8B 0D 2A 2A 2A 2A 8B 11 50 8B 42 4C',
  422.         'i)p',
  423.         'CBaseEntity'
  424.     ),
  425.     CreateServerInterface = manager.pipe_function(
  426.         'cstrike/bin/server', 'CreateInterface', 'Zi)p'
  427.     )
  428. )
  429.  
  430.  
  431. # =============================================================================
  432. # >> MISC
  433. # =============================================================================
  434. # Interfaces
  435. server_tools = IServerTools(utils.CreateServerInterface('VSERVERTOOLS002', 0))
  436. game_dll     = IServerGameDLL(utils.CreateServerInterface('ServerGameDLL009', 0))
  437.  
  438. def get_entity_instances():
  439.     '''
  440.    Returns a generator for all entity instances.
  441.    '''
  442.  
  443.     entity = server_tools.FirstEntity()
  444.     while entity:
  445.         yield entity
  446.         entity = server_tools.NextEntity(entity)
  447.  
  448. def get_player_instances():
  449.     '''
  450.    Returns a generator for all player instances.
  451.    '''
  452.  
  453.     # Loop through all possible player indexes
  454.     for index in xrange(1, 65):
  455.         player = utils.EntityByIndex(index)
  456.  
  457.         # If the player exists, yield a CCSPlayer instance
  458.         if player:
  459.             yield CCSPlayer(player)
Advertisement
Add Comment
Please, Sign In to add comment