Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #wallhack_test.py
  2. import memory
  3.  
  4. from colors import Color
  5. from events import Event
  6.  
  7. from entities import CheckTransmitInfo
  8. from entities.entity import Entity
  9. from entities.hooks import EntityPreHook, EntityCondition
  10. from entities.constants import EntityEffects, RenderMode
  11. from entities.helpers import index_from_pointer
  12.  
  13. from players.entity import Player
  14. from players.helpers import index_from_userid, userid_from_edict, userid_from_index
  15.  
  16. from commands import CommandReturn
  17. from commands.client import ClientCommand
  18.  
  19. from listeners import OnLevelEnd
  20. from listeners.tick import Delay
  21.  
  22. from filters.players import PlayerIter
  23.  
  24.  
  25. # sv_force_transmit_players
  26. # has to be set to 1 in order for the wallhack to work correctly
  27. # if set to 0, player glows that are too far will appear at map's origin
  28. # NOTE: enabling this makes actual wallhacks more effective
  29.  
  30.  
  31. # =============================================================================
  32. # >> GLOBALS
  33. # =============================================================================
  34. glow_color = {
  35.     2:Color(249, 208, 44),      # terrorist glow color
  36.     3:Color(44, 178, 249)       # counter-terrorist glow color
  37.     }
  38.  
  39. wallhack = []
  40. wallhack_props = []
  41.  
  42. player_models = {}
  43.  
  44. # =============================================================================
  45. # >> COMMANDS
  46. # =============================================================================
  47.  
  48. # toggle_wallhack           - toggles wallhack on the player that used the command
  49. # toggle_wallhack <userid>  - toggles wallhack on the specified userid
  50. @ClientCommand('toggle_wallhack')
  51. def _toggle_wallhack(command, index):
  52.     if len(command) > 1:
  53.         try:
  54.             userid = int(command[1])
  55.             _index = index_from_userid(userid)
  56.         except:
  57.             print('toggle_wallhack: invalid userid > {0}'.format(command.arg_string))
  58.             return CommandReturn.BLOCK
  59.     else:
  60.         userid = userid_from_index(index)
  61.  
  62.     toggle_wallhack(userid)
  63.     return CommandReturn.BLOCK
  64.  
  65.  
  66. # everytime a player toggles the wallhack off, the player model props have to
  67. # be recreated, otherwise the player model props and glows will appear at the
  68. # map origin(0, 0, 0) for the player that toggled the wallhack off
  69. def toggle_wallhack(userid):
  70.     # toggle on
  71.     if userid not in wallhack:
  72.         # is no one using wallhack?
  73.         if len(wallhack) == 0:
  74.             # create player model props and glows for every alive player
  75.             for player in PlayerIter('alive'):
  76.                 create_player_glow(player.userid, glow_color[player.team])
  77.  
  78.         wallhack.append(userid)
  79.  
  80.     # toggle off
  81.     else:
  82.         wallhack.remove(userid)
  83.         remove_all_models()
  84.  
  85.         # is there at least 1 player using wallhack?
  86.         if len(wallhack) > 0:
  87.             # create player model props and glows for every alive player
  88.             for player in PlayerIter('alive'):
  89.                 create_player_glow(player.userid, glow_color[player.team])
  90.  
  91.  
  92. def remove_all_models():
  93.     for userid in player_models:
  94.         player_models[userid].remove()
  95.  
  96.     player_models.clear()
  97.     wallhack_props.clear()
  98.  
  99. # =============================================================================
  100. # >> EVENTS
  101. # =============================================================================
  102. @Event('player_spawn')
  103. def player_spawned(event):
  104.     userid = event['userid']
  105.  
  106.     # is there at least 1 player using wallhack?
  107.     if len(wallhack) > 0:
  108.         # if there is, check if the player spawned after round_start
  109.         Delay(0.1, late_spawn_check, (userid, event['teamnum']))
  110.  
  111. def late_spawn_check(userid, team):
  112.     if userid not in player_models:
  113.         create_player_glow(userid, glow_color[team])
  114.  
  115.  
  116. @Event('player_disconnect')
  117. def player_left(event):
  118.     userid = event['userid']
  119.  
  120.     # does this player have a player model prop?
  121.     if userid in player_models:
  122.         # if yes, get the model prop reference
  123.         skin = player_models[userid]
  124.  
  125.         # remove the model prop index from the list
  126.         wallhack_props.remove(skin.index)
  127.         # remove the model prop entity
  128.         skin.remove()
  129.  
  130.         # remove the model prop reference from the dictionary
  131.         del player_models[userid]
  132.  
  133.     # is this player using wallhack?
  134.     if userid in wallhack:
  135.         wallhack.remove(userid)
  136.  
  137.  
  138. @Event('round_start')
  139. def round_started(event):
  140.     wallhack_props.clear()
  141.     player_models.clear()
  142.  
  143.     # is there at least 1 player using wallhack?
  144.     if len(wallhack) > 0:
  145.         # if there is, create player model props and glows for every alive player
  146.         for player in PlayerIter('alive'):
  147.             create_player_glow(player.userid, glow_color[player.team])
  148.  
  149.  
  150. @OnLevelEnd
  151. def map_changed():
  152.     wallhack.clear()
  153.  
  154. # =============================================================================
  155. # >> SET TRANSMIT
  156. # =============================================================================
  157. @EntityPreHook(EntityCondition.equals_entity_classname('prop_dynamic_override'), 'set_transmit')
  158. def set_transmit(args):
  159.     info = memory.make_object(CheckTransmitInfo, args[1])
  160.     userid = userid_from_edict(info.client)
  161.     entity_index = index_from_pointer(args[0])
  162.  
  163.     # is the player not using wallhack?
  164.     # does the entity index belong to any of the player model props?
  165.     if userid not in wallhack and entity_index in wallhack_props:
  166.         # hide the entity
  167.         return False
  168.  
  169.  
  170. # =============================================================================
  171. # >> PLAYER MODEL PROP & GLOW
  172. # =============================================================================
  173. def get_player_model(userid):
  174.     if userid not in player_models:
  175.         player_models[userid] = create_player_model_prop(userid)
  176.  
  177.     return player_models[userid]
  178.  
  179.  
  180. def create_player_model_prop(userid):
  181.     player = Player(index_from_userid(userid))
  182.  
  183.     skin = Entity.create('prop_dynamic_override')
  184.     skin.model = player.model
  185.    
  186.     # spawn with collisions disabled
  187.     skin.spawn_flags = 256
  188.    
  189.     skin.set_property_uchar('m_CollisionGroup', 11)
  190.     skin.spawn()
  191.  
  192.  
  193.     # BONEMERGE         merge child(player model prop) and parent(player) bones with the same name
  194.     # more info:        https://developer.valvesoftware.com/wiki/EF_BONEMERGE
  195.  
  196.     # NOSHADOW          disable shadows from this model
  197.     # NORECEIVESHADOW   disable receiving of shadows on this model
  198.  
  199.     # PARENT_ANIMATES   make sure the model is always properly aligned with the parent(player)
  200.     # more info:        https://developer.valvesoftware.com/wiki/EF_PARENT_ANIMATES
  201.     skin.effects = EntityEffects.BONEMERGE | EntityEffects.NOSHADOW | EntityEffects.NORECEIVESHADOW | EntityEffects.PARENT_ANIMATES
  202.  
  203.     # parent player model prop to the player
  204.     skin.set_parent(player, -1)
  205.     skin.set_parent_attachment('primary')
  206.  
  207.     # make the player model prop invisible
  208.     skin.render_color = Color(255, 255, 255, 0)
  209.     skin.render_mode = RenderMode.TRANS_ALPHA
  210.  
  211.     # save the player model prop reference in a dictionary(userid:model prop reference)
  212.     if player.userid not in player_models:
  213.         player_models[player.userid] = skin
  214.  
  215.     # add the player model prop index to a list
  216.     if skin.index not in wallhack_props:
  217.         wallhack_props.append(skin.index)
  218.  
  219.     return skin
  220.  
  221.  
  222. def create_player_glow(userid, color):
  223.     player_model = get_player_model(userid)
  224.  
  225.     # turn the glow on
  226.     player_model.set_property_bool('m_bShouldGlow', True)
  227.  
  228.     # set the glow color
  229.     # gotta use long color codes for this one
  230.     # http://www.pbdr.com/pbtips/ps/rgblong.htm
  231.     player_model.set_property_int('m_clrGlow', rgb_to_long(color[0], color[1], color[2]))
  232.  
  233.     # set the distance from which you can see the glow
  234.     # NOTE: without this, the glow won't show
  235.     player_model.set_property_float('m_flGlowMaxDist', 1000000.0)
  236.  
  237.  
  238. # =============================================================================
  239. # >> UTIL
  240. # =============================================================================
  241. def rgb_to_long(r, g, b):
  242.     return b * 65536 + g * 256 + r