Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- # 16.05.13
- # UTIL_TraceLine(Vector const&, Vector const&, unsigned int, IHandleEntity const*, int, CGameTrace *)
- [UTIL_TraceLine]
- shortname = TraceLine
- sig = 53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 83 EC 6C 56
- symbol = _Z14UTIL_TraceLineRK6VectorS1_jPK13IHandleEntityiP10CGameTrace
- param = ppipip)v
- convention = cdecl
- # 17.05.13
- # CTraceFilterSimple::ShouldHitEntity(IHandleEntity *, int)
- [CTraceFilterSimple::ShouldHitEntity]
- shortname = ShouldHitEntity
- sig = 55 8B EC 8B 45 0C 53 8B 5D 08 57
- symbol = _ZN18CTraceFilterSimple15ShouldHitEntityEP13IHandleEntityi
- param = ppi)b
- convention = thiscall
- '''
- # =============================================================================
- # >> IMPORTS
- # =============================================================================
- # EventScripts
- import es
- import playerlib
- from vecmath import Vector
- # Source-Python-Extensions
- import spe
- from spe import HookAction
- from spe import HookType
- # =============================================================================
- # >> GLOBAL VARIABLES
- # =============================================================================
- SIZE_VECTOR = 12
- SIZE_TRACE_T = 84
- MAX_COORD_RANGE = 16384
- spe.parseINI('signatures.ini')
- # =============================================================================
- # >> GAME EVENTS
- # =============================================================================
- def player_say(ev):
- userid = int(ev['userid'])
- """
- # enumerateEntities()
- player = playerlib.getPlayer(userid)
- startvec = player.getEyeLocation()
- endvec = list(Vector(startvec) + Vector(player.viewvector) * \
- MAX_COORD_RANGE)
- entities = enumerateEntities(startvec, endvec)
- es.msg(map(lambda x: es.entitygetvalue(x, 'classname'), entities))
- """
- # isWallBetween()
- player = playerlib.getPlayer(userid)
- for player2 in playerlib.getPlayerList('#alive'):
- es.msg('Is wall between %s & %s? %s!'% (player.name, player2.name,
- isWallBetween(player.getEyeLocation(), player2.getEyeLocation())))
- # =============================================================================
- # >> CLASSES
- # =============================================================================
- class EnumHelper:
- entities = set()
- @staticmethod
- def startTracing():
- EnumHelper.entities.clear()
- spe.detourFunction('ShouldHitEntity', HookType.Pre,
- preShouldHitEntity)
- @staticmethod
- def stopTracing():
- spe.undetourFunction('ShouldHitEntity', HookType.Pre,
- preShouldHitEntity)
- return EnumHelper.entities
- # =============================================================================
- # >> FUNCTIONS
- # =============================================================================
- def isWallBetween(start, end):
- '''
- Returns True if a wall is between the start and end vector.
- '''
- # Create start and end vector pointers
- pStart = createVector(*start)
- pEnd = createVector(*end)
- # Allocate space for the CGameTrace object
- ptr = spe.alloc(SIZE_TRACE_T)
- # Call UTIL_TraceLine()
- spe.call('TraceLine', pStart, pEnd, 0x1, 0, 0, ptr)
- # Get m_pEnt
- result = bool(spe.getLocVal('i', ptr + 76))
- # Deallocate reserved space
- spe.dealloc(pStart)
- spe.dealloc(pEnd)
- spe.dealloc(ptr)
- return result
- def enumerateEntities(start, end, mask=0x1, collisiongroup=0):
- '''
- Returns all entity indexes between the start and end vector.
- '''
- # Create start and end vector pointers
- pStart = createVector(*start)
- pEnd = createVector(*end)
- # Allocate space for the CGameTrace object
- ptr = spe.alloc(SIZE_TRACE_T)
- # Start the trace
- EnumHelper.startTracing()
- # Call UTIL_TraceLine()
- spe.call('TraceLine', pStart, pEnd, mask, 0, collisiongroup, ptr)
- # Stop the trace
- result = EnumHelper.stopTracing()
- # Deallocate reserved space
- spe.dealloc(pStart)
- spe.dealloc(pEnd)
- spe.dealloc(ptr)
- return result
- def getViewCoords(userid, mask=0x1, collisiongroup=0):
- '''
- Returns the coordinates the given player is currently looking at.
- '''
- player = playerlib.getPlayer(userid)
- startvec = player.getEyeLocation()
- # Create start and end vector pointers
- pStart = createVector(*startvec)
- pEnd = createVector(*list(Vector(startvec) + Vector(player.viewvector) \
- * MAX_COORD_RANGE))
- # Allocate space for the CGameTrace object
- ptr = spe.alloc(SIZE_TRACE_T)
- # Call UTIL_TraceLine()
- spe.call('TraceLine', pStart, pEnd, mask, spe.getPlayer(int(userid)),
- collisiongroup, ptr)
- # Wrap the end vector...
- x = spe.makeObject('Vector', ptr + 12)
- # ... and save the result
- result = x.x, x.y, x.z
- # Deallocate reserved space
- spe.dealloc(pStart)
- spe.dealloc(pEnd)
- spe.dealloc(ptr)
- return result
- def getGroundMaterial(userid, mask=0x1, collisiongroup=0):
- '''
- Returns the name of the material on which the given player is currently
- standing.
- '''
- x, y, z = es.getplayerlocation(userid)
- # Create start and end vector pointers
- pStart = createVector(x, y, z)
- pEnd = createVector(x, y, -MAX_COORD_RANGE)
- # Allocate space for the CGameTrace object
- ptr = spe.alloc(SIZE_TRACE_T)
- # Call UTIL_TraceLine()
- spe.call('TraceLine', pStart, pEnd, mask, 0, collisiongroup, ptr)
- # TODO: Explore IPhysicsSurfaceProps::GetSurfaceData() to get the material
- # of **studio** or **displacement**
- result = spe.getLocVal('s', spe.getLocVal('i', ptr + 60))
- # Deallocate reserved space
- spe.dealloc(pStart)
- spe.dealloc(pEnd)
- spe.dealloc(ptr)
- return result
- def createVector(x, y, z):
- obj = spe.makeObject('Vector', spe.alloc(SIZE_VECTOR))
- obj.x = x
- obj.y = y
- obj.z = z
- return obj.base
- # =============================================================================
- # >> CALLBACKS
- # =============================================================================
- def preShouldHitEntity(args):
- spe.setCallingConvention('thiscall')
- # Call IHandleEntity::GetRefEHandle() and read m_Index of the return
- # value (CBaseHandle)
- spe.setCallingConvention('thiscall')
- handle = spe.getLocVal('i', spe.callFunction(spe.findVirtualFunc(
- args[0], 2), 'p)p', (args[0],)))
- EnumHelper.entities.add(es.getindexfromhandle(handle))
- return (HookAction.Continue, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement