Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # >> IMPORTS
- # =============================================================================
- # Python
- import random
- import os
- # binutils
- import binutils
- from binutils import Convention
- # =============================================================================
- # >> CONSTANTS
- # =============================================================================
- RAND_MAX = 0x7fff
- # =============================================================================
- # >> GLOBAL VARIABLES
- # =============================================================================
- manager = binutils.TypeManager()
- # =============================================================================
- # >> QAngle
- # =============================================================================
- class QAngle(binutils.CustomType):
- __metaclass__ = manager
- x = manager.attribute('float', 0)
- y = manager.attribute('float', 4)
- z = manager.attribute('float', 8)
- size = 12
- def Init(self, x=0, y=0, z=0):
- self.x = x
- self.y = y
- self.z = z
- def Random(self, min_val, max_val):
- for x in 'xyz':
- rand = float(random.randint(0, RAND_MAX)) / RAND_MAX
- setattr(self, x, min_val + (rand * (max_val - min_val)))
- def __iter__(self):
- return iter((self.x, self.y, self.z))
- # =============================================================================
- # >> Vector
- # =============================================================================
- class Vector(binutils.CustomType):
- __metaclass__ = manager
- x = manager.attribute('float', 0)
- y = manager.attribute('float', 4)
- z = manager.attribute('float', 8)
- size = 12
- def Init(self, x=0, y=0, z=0):
- self.x = x
- self.y = y
- self.z = z
- def __iter__(self):
- return iter((self.x, self.y, self.z))
- # =============================================================================
- # >> CUserCmd
- # =============================================================================
- class CUserCmd(binutils.CustomType):
- __metaclass__ = manager
- vtable = manager.attribute('ptr', 0)
- command_number = manager.attribute('int', 4)
- tick_count = manager.attribute('int', 8)
- viewangles = manager.attribute('QAngle', 12, aligned=True)
- forwardmove = manager.attribute('float', 24)
- sidemove = manager.attribute('float', 28)
- upmove = manager.attribute('float', 32)
- buttons = manager.attribute('int', 36)
- impulse = manager.attribute('uchar', 40)
- weaponselect = manager.attribute('int', 44)
- weaponsubtype = manager.attribute('int', 48)
- random_seed = manager.attribute('int', 52)
- mousedx = manager.attribute('short', 56)
- mousedy = manager.attribute('short', 60)
- hasbeenpredicted = manager.attribute('bool', 64)
- size = 68
- def Init(self):
- self.Reset()
- def Reset(self):
- self.command_number = 0
- self.tick_count = 0
- self.forwardmove = 0
- self.sidemove = 0
- self.upmove = 0
- self.buttons = 0
- self.impulse = 0
- self.weaponselect = 0
- self.weaponsubtype = 0
- self.random_seed = 0
- self.mousedx = 0
- self.mousedy = 0
- self.hasbeenpredicted = False;
- self.viewangles.Init()
- # =============================================================================
- # >> IHandleEntity
- # =============================================================================
- class IHandleEntity(binutils.CustomType):
- __metaclass__ = manager
- destructor = manager.virtual_function(0, 'p)v')
- SetRefHandle = manager.virtual_function(1, 'pp)v')
- GetRefHandle = manager.virtual_function(2, 'p)p', 'CBaseHandle')
- # =============================================================================
- # >> CBaseEntity
- # =============================================================================
- class CBaseEntity(IHandleEntity):
- __metaclass__ = manager
- GetDataDescMap = manager.virtual_function(11, 'p)p', 'datamap_t')
- m_iClassname = manager.attribute('string', 92)
- # =============================================================================
- # >> CCSPlayer
- # =============================================================================
- class CCSPlayer(CBaseEntity):
- __metaclass__ = manager
- PlayerRunCommand = manager.function(
- 'cstrike/bin/server',
- '55 8B EC 83 EC 58 56 89 4D A8',
- 'ppp)v'
- )
- # =============================================================================
- # >> CBaseHandle
- # =============================================================================
- class CBaseHandle(CBaseEntity):
- __metaclass__ = manager
- m_Index = manager.attribute('ulong', 0)
- # =============================================================================
- # >> datamap_t
- # =============================================================================
- class datamap_t(binutils.CustomType):
- __metaclass__ = manager
- dataDesc = manager.attribute('typedescription_t', 0, is_array=True)
- dataNumFields = manager.attribute('int', 4)
- dataClassName = manager.attribute('string', 8)
- baseMap = manager.attribute('datamap_t', 12)
- chains_validated = manager.attribute('bool', 16)
- packed_offsets_computed = manager.attribute('bool', 20)
- packed_size = manager.attribute('int', 24)
- bValidityChecked = manager.attribute('bool', 28)
- size = 32
- # =============================================================================
- # >> typedescription_t
- # =============================================================================
- class typedescription_t(binutils.CustomType):
- __metaclass__ = manager
- fieldType = manager.attribute('int', 0)
- fieldName = manager.attribute('string', 4)
- fieldOffset = manager.attribute('int', 8, 2, True, True)
- fieldSize = manager.attribute('ushort', 16)
- flags = manager.attribute('short', 18)
- externalName = manager.attribute('string', 20)
- pSaveRestoreOps = manager.attribute('ISaveRestoreOps', 24)
- inputFunc = manager.attribute('inputfunc_t', 28)
- td = manager.attribute('datamap_t', 32)
- fieldSizeInBytes = manager.attribute('int', 36)
- override_field = manager.attribute('typedescription_t', 40)
- override_count = manager.attribute('int', 44)
- fieldTolerance = manager.attribute('float', 48)
- size = 52 if os.name == 'nt' else 56
- # =============================================================================
- # >> inputfunc_t
- # =============================================================================
- inputfunc_t = manager.create_function_typedef(
- 'inputfunc_t', Convention.THISCALL, 'pp)v'
- )
- # =============================================================================
- # >> ISaveRestoreOps
- # =============================================================================
- class ISaveRestoreOps(binutils.CustomType):
- __metaclass__ = manager
- vtable = manager.attribute('ptr', 0)
- # =============================================================================
- # >> IServerTools
- # =============================================================================
- class IServerTools(binutils.CustomType):
- __metaclass__ = manager
- destructor = manager.virtual_function(0, 'p)v')
- GetIServerEntity = manager.virtual_function(1, 'pp)p', 'IServerEntity')
- SnapPlayerToPosition = manager.virtual_function(2, 'pppp)b')
- GetPlayerPosition = manager.virtual_function(3, 'pppp)b')
- SetPlayerFOV = manager.virtual_function(4, 'pip)b')
- GetPlayerFOV = manager.virtual_function(5, 'pp)i')
- IsInNoClipMode = manager.virtual_function(6, 'pp)b')
- FirstEntity = manager.virtual_function(7, 'p)p', 'CBaseEntity')
- NextEntity = manager.virtual_function(8, 'pp)p', 'CBaseEntity')
- FindEntityByHammerID = manager.virtual_function(9, 'pi)p', 'CBaseEntity')
- GetKeyValue = manager.virtual_function(10, 'ppZpi)b')
- SetKeyValueString = manager.virtual_function(11, 'ppZZ)b')
- SetKeyValueFloat = manager.virtual_function(12, 'ppZf)b')
- SetKeyValueVector = manager.virtual_function(13, 'ppZp)b')
- CreateEntityByName = manager.virtual_function(14, 'pZ)p', 'CBaseEntity')
- DispatchSpawn = manager.virtual_function(15, 'pp)v')
- ReloadParticleDefintions = manager.virtual_function(16, 'pZpi)v')
- AddOriginToPVS = manager.virtual_function(17, 'pp)v')
- MoveEngineViewTo = manager.virtual_function(18, 'ppp)v')
- DestroyEntityByHammerId = manager.virtual_function(19, 'pi)b')
- GetBaseEntityByEntIndex = manager.virtual_function(20, 'pi)p', 'CBaseEntity')
- RemoveEntity = manager.virtual_function(21, 'pp)v')
- RemoveEntityImmediate = manager.virtual_function(22, 'pp)v')
- GetEntityFactoryDictionary = manager.virtual_function(23, 'p)p', 'IEntityFactoryDictionary')
- SetMoveType = manager.virtual_function(24, 'ppi)v')
- SetMoveType2 = manager.virtual_function(25, 'ppii)v')
- ResetSequence = manager.virtual_function(26, 'ppi)v')
- ResetSequenceInfo = manager.virtual_function(27, 'pp)v')
- ClearMultiDamage = manager.virtual_function(28, 'p)v')
- ApplyMultiDamage = manager.virtual_function(29, 'p)v')
- AddMultiDamage = manager.virtual_function(30, 'ppp)v')
- RadiusDamage = manager.virtual_function(31, 'pppfip)v')
- GetTempEntsSystem = manager.virtual_function(32, 'p)p', 'ITempEntsSystem')
- # =============================================================================
- # >> IEntityFactoryDictionary
- # =============================================================================
- class IEntityFactoryDictionary(binutils.CustomType):
- __metaclass__ = manager
- InstallFactory = manager.virtual_function(0, 'ppZ)v')
- Create = manager.virtual_function(1, 'pZ)p', 'IServerNetworkable')
- Destroy = manager.virtual_function(2, 'pZp)v')
- FindFactory = manager.virtual_function(3, 'pZ)p', 'IEntityFactory')
- GetCannonicalName = manager.virtual_function(4, 'pZ)Z')
- # =============================================================================
- # >> IEntityFactory
- # =============================================================================
- class IEntityFactory(binutils.CustomType):
- __metaclass__ = manager
- Create = manager.virtual_function(0, 'pZ)p', 'IServerNetworkable')
- Destroy = manager.virtual_function(1, 'pp)v')
- GetEntitySize = manager.virtual_function(2, 'p)I')
- # =============================================================================
- # >> IPredictionSystem
- # =============================================================================
- class IPredictionSystem(binutils.CustomType):
- __metaclass__ = manager
- vtable = manager.attribute('ptr', 0)
- m_pNextSystem = manager.attribute('IPredictionSystem', 4)
- m_bSuppressEvent = manager.attribute('bool', 8)
- m_pSuppressHost = manager.attribute('CBaseEntity', 12)
- m_nStatusPushed = manager.attribute('int', 16)
- destructor = manager.virtual_function(0, 'p)v')
- # =============================================================================
- # >> ITempEntsSystem
- # =============================================================================
- class ITempEntsSystem(IPredictionSystem):
- __metaclass__ = manager
- BeamRingPoint = manager.virtual_function(8, 'ppfpffiiiiffifiiiiii)v')
- # =============================================================================
- # >> IRecipientFilter
- # =============================================================================
- class IRecipientFilter(binutils.CustomType):
- __metaclass__ = manager
- vtable = manager.attribute('ptr', 0)
- destructor = manager.virtual_function(0, 'p)v')
- IsReliable = manager.virtual_function(1, 'p)b')
- IsInitMessage = manager.virtual_function(2, 'p)b')
- GetRecipientCount = manager.virtual_function(3, 'p)i')
- GetRecipientIndex = manager.virtual_function(4, 'pi)i')
- # =============================================================================
- # >> CRecipientFilter
- # =============================================================================
- class CRecipientFilter(IRecipientFilter):
- __metaclass__ = manager
- size = 40
- constructor = manager.function(
- 'cstrike/bin/server',
- '8B C1 33 C9 C7 00 2A 2A 2A 2A 89 48 08',
- 'p)v'
- )
- AddRecipient = manager.function(
- 'cstrike/bin/server',
- '55 8B EC 8B 55 08 85 D2 0F 84 2A 2A 2A 2A 8B 42 18 53 85 C0 74 2A',
- 'pp)v'
- )
- def AddAllPlayers(self):
- for player in get_player_instances():
- self.AddRecipient(player)
- # =============================================================================
- # >> CreateInterfaceFn
- # =============================================================================
- CreateInterfaceFn = manager.create_function_typedef(
- 'CreateInterfaceFn', Convention.CDECL, 'Zi)p'
- )
- # =============================================================================
- # >> InstantiateInterfaceFn
- # =============================================================================
- InstantiateInterfaceFn = manager.create_function_typedef(
- 'InstantiateInterfaceFn', Convention.CDECL, 'v)p'
- )
- # =============================================================================
- # >> InterfaceReg
- # =============================================================================
- class InterfaceReg(binutils.CustomType):
- __metaclass__ = manager
- m_CreateFn = manager.attribute('InstantiateInterfaceFn', 0)
- m_pName = manager.attribute('string', 4)
- m_pNext = manager.attribute('InterfaceReg', 8)
- s_pInterfaceRegs = manager.attribute('InterfaceReg', 12)
- # =============================================================================
- # >> IServerGameDLL
- # =============================================================================
- class IServerGameDLL(binutils.CustomType):
- __metaclass__ = manager
- GetAllServerClasses = manager.virtual_function(11, 'p)p', 'ServerClass')
- GetGameDescription = manager.virtual_function(12, 'p)Z')
- # =============================================================================
- # >> ServerClass
- # =============================================================================
- class ServerClass(binutils.CustomType):
- __metaclass__ = manager
- m_pNetworkName = manager.attribute('string', 0)
- m_pTable = manager.attribute('SendTable', 4)
- m_pNext = manager.attribute('ServerClass', 8)
- m_ClassID = manager.attribute('int', 12)
- m_InstanceBaselineIndex = manager.attribute('int', 16)
- # =============================================================================
- # >> SendTable
- # =============================================================================
- class SendTable(binutils.CustomType):
- __metaclass__ = manager
- m_pProps = manager.attribute('SendProp', 0)
- m_nProps = manager.attribute('int', 4)
- m_pNetTableName = manager.attribute('string', 8)
- m_pPrecalc = manager.attribute('CSendTablePrecalc', 12)
- m_bInitialized = manager.attribute('bool', 16)
- m_bHasBeenWritten = manager.attribute('bool', 20)
- m_bHasPropsEncodedAgainstCurrentTickCount = manager.attribute('bool', 24)
- # =============================================================================
- # >> Util pipe
- # =============================================================================
- utils = manager.create_pipe(
- EntityByIndex = manager.pipe_function(
- 'cstrike/bin/server',
- '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',
- 'i)p',
- 'CBaseEntity'
- ),
- CreateServerInterface = manager.pipe_function(
- 'cstrike/bin/server', 'CreateInterface', 'Zi)p'
- )
- )
- # =============================================================================
- # >> MISC
- # =============================================================================
- # Interfaces
- server_tools = IServerTools(utils.CreateServerInterface('VSERVERTOOLS002', 0))
- game_dll = IServerGameDLL(utils.CreateServerInterface('ServerGameDLL009', 0))
- def get_entity_instances():
- '''
- Returns a generator for all entity instances.
- '''
- entity = server_tools.FirstEntity()
- while entity:
- yield entity
- entity = server_tools.NextEntity(entity)
- def get_player_instances():
- '''
- Returns a generator for all player instances.
- '''
- # Loop through all possible player indexes
- for index in xrange(1, 65):
- player = utils.EntityByIndex(index)
- # If the player exists, yield a CCSPlayer instance
- if player:
- yield CCSPlayer(player)
Advertisement
Add Comment
Please, Sign In to add comment