Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #wallhack_test.py
- import memory
- from colors import Color
- from events import Event
- from entities import CheckTransmitInfo
- from entities.entity import Entity
- from entities.hooks import EntityPreHook, EntityCondition
- from entities.constants import EntityEffects, RenderMode
- from entities.helpers import index_from_pointer
- from players.entity import Player
- from players.helpers import index_from_userid, userid_from_edict, userid_from_index
- from commands import CommandReturn
- from commands.client import ClientCommand
- from listeners import OnLevelEnd
- from listeners.tick import Delay
- from filters.players import PlayerIter
- # sv_force_transmit_players
- # has to be set to 1 in order for the wallhack to work correctly
- # if set to 0, player glows that are too far will appear at map's origin
- # NOTE: enabling this makes actual wallhacks more effective
- # =============================================================================
- # >> GLOBALS
- # =============================================================================
- glow_color = {
- 2:Color(249, 208, 44), # terrorist glow color
- 3:Color(44, 178, 249) # counter-terrorist glow color
- }
- wallhack = []
- wallhack_props = []
- player_models = {}
- # =============================================================================
- # >> COMMANDS
- # =============================================================================
- # toggle_wallhack - toggles wallhack on the player that used the command
- # toggle_wallhack <userid> - toggles wallhack on the specified userid
- @ClientCommand('toggle_wallhack')
- def _toggle_wallhack(command, index):
- if len(command) > 1:
- try:
- userid = int(command[1])
- _index = index_from_userid(userid)
- except:
- print('toggle_wallhack: invalid userid > {0}'.format(command.arg_string))
- return CommandReturn.BLOCK
- else:
- userid = userid_from_index(index)
- toggle_wallhack(userid)
- return CommandReturn.BLOCK
- # everytime a player toggles the wallhack off, the player model props have to
- # be recreated, otherwise the player model props and glows will appear at the
- # map origin(0, 0, 0) for the player that toggled the wallhack off
- def toggle_wallhack(userid):
- # toggle on
- if userid not in wallhack:
- # is no one using wallhack?
- if len(wallhack) == 0:
- # create player model props and glows for every alive player
- for player in PlayerIter('alive'):
- create_player_glow(player.userid, glow_color[player.team])
- wallhack.append(userid)
- # toggle off
- else:
- wallhack.remove(userid)
- remove_all_models()
- # is there at least 1 player using wallhack?
- if len(wallhack) > 0:
- # create player model props and glows for every alive player
- for player in PlayerIter('alive'):
- create_player_glow(player.userid, glow_color[player.team])
- def remove_all_models():
- for userid in player_models:
- player_models[userid].remove()
- player_models.clear()
- wallhack_props.clear()
- # =============================================================================
- # >> EVENTS
- # =============================================================================
- @Event('player_spawn')
- def player_spawned(event):
- userid = event['userid']
- # is there at least 1 player using wallhack?
- if len(wallhack) > 0:
- # if there is, check if the player spawned after round_start
- Delay(0.1, late_spawn_check, (userid, event['teamnum']))
- def late_spawn_check(userid, team):
- if userid not in player_models:
- create_player_glow(userid, glow_color[team])
- @Event('player_disconnect')
- def player_left(event):
- userid = event['userid']
- # does this player have a player model prop?
- if userid in player_models:
- # if yes, get the model prop reference
- skin = player_models[userid]
- # remove the model prop index from the list
- wallhack_props.remove(skin.index)
- # remove the model prop entity
- skin.remove()
- # remove the model prop reference from the dictionary
- del player_models[userid]
- # is this player using wallhack?
- if userid in wallhack:
- wallhack.remove(userid)
- @Event('round_start')
- def round_started(event):
- wallhack_props.clear()
- player_models.clear()
- # is there at least 1 player using wallhack?
- if len(wallhack) > 0:
- # if there is, create player model props and glows for every alive player
- for player in PlayerIter('alive'):
- create_player_glow(player.userid, glow_color[player.team])
- @OnLevelEnd
- def map_changed():
- wallhack.clear()
- # =============================================================================
- # >> SET TRANSMIT
- # =============================================================================
- @EntityPreHook(EntityCondition.equals_entity_classname('prop_dynamic_override'), 'set_transmit')
- def set_transmit(args):
- info = memory.make_object(CheckTransmitInfo, args[1])
- userid = userid_from_edict(info.client)
- entity_index = index_from_pointer(args[0])
- # is the player not using wallhack?
- # does the entity index belong to any of the player model props?
- if userid not in wallhack and entity_index in wallhack_props:
- # hide the entity
- return False
- # =============================================================================
- # >> PLAYER MODEL PROP & GLOW
- # =============================================================================
- def get_player_model(userid):
- if userid not in player_models:
- player_models[userid] = create_player_model_prop(userid)
- return player_models[userid]
- def create_player_model_prop(userid):
- player = Player(index_from_userid(userid))
- skin = Entity.create('prop_dynamic_override')
- skin.model = player.model
- # spawn with collisions disabled
- skin.spawn_flags = 256
- skin.set_property_uchar('m_CollisionGroup', 11)
- skin.spawn()
- # BONEMERGE merge child(player model prop) and parent(player) bones with the same name
- # more info: https://developer.valvesoftware.com/wiki/EF_BONEMERGE
- # NOSHADOW disable shadows from this model
- # NORECEIVESHADOW disable receiving of shadows on this model
- # PARENT_ANIMATES make sure the model is always properly aligned with the parent(player)
- # more info: https://developer.valvesoftware.com/wiki/EF_PARENT_ANIMATES
- skin.effects = EntityEffects.BONEMERGE | EntityEffects.NOSHADOW | EntityEffects.NORECEIVESHADOW | EntityEffects.PARENT_ANIMATES
- # parent player model prop to the player
- skin.set_parent(player, -1)
- skin.set_parent_attachment('primary')
- # make the player model prop invisible
- skin.render_color = Color(255, 255, 255, 0)
- skin.render_mode = RenderMode.TRANS_ALPHA
- # save the player model prop reference in a dictionary(userid:model prop reference)
- if player.userid not in player_models:
- player_models[player.userid] = skin
- # add the player model prop index to a list
- if skin.index not in wallhack_props:
- wallhack_props.append(skin.index)
- return skin
- def create_player_glow(userid, color):
- player_model = get_player_model(userid)
- # turn the glow on
- player_model.set_property_bool('m_bShouldGlow', True)
- # set the glow color
- # gotta use long color codes for this one
- # http://www.pbdr.com/pbtips/ps/rgblong.htm
- player_model.set_property_int('m_clrGlow', rgb_to_long(color[0], color[1], color[2]))
- # set the distance from which you can see the glow
- # NOTE: without this, the glow won't show
- player_model.set_property_float('m_flGlowMaxDist', 1000000.0)
- # =============================================================================
- # >> UTIL
- # =============================================================================
- def rgb_to_long(r, g, b):
- return b * 65536 + g * 256 + r
Add Comment
Please, Sign In to add comment