Ayuto

CSWeaponInfo offsets

Dec 23rd, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.30 KB | None | 0 0
  1. # =============================================================================
  2. # >> IMPORTS
  3. # =============================================================================
  4. # Python
  5. from __future__ import with_statement
  6.  
  7. import os
  8. import pprint
  9.  
  10. from path import path
  11.  
  12. # EventScripts
  13. import es
  14. import binutils
  15.  
  16. from binutils import Convention
  17.  
  18.  
  19. # =============================================================================
  20. # >> GLOBAL VARIABLES
  21. # =============================================================================
  22. server = binutils.find_binary('cstrike/bin/server')
  23.  
  24. if os.name == 'nt':
  25.     GetWeaponInfo_ptr = server.find_signature('\x55\x8B\xEC\x8B\x4D\x08\x85\xC9\x75\x2A\x33\xC0\x5D\xC3')
  26. else:
  27.     GetWeaponInfo_ptr = server['_Z13GetWeaponInfo10CSWeaponID']
  28.  
  29. GetWeaponInfo = GetWeaponInfo_ptr.make_function(Convention.CDECL, 'i)p')
  30.  
  31. # Size of a category of SoundData is 80
  32. offsets = {
  33.     'vtable': ('ptr', 0),
  34.     'bParsedScript': ('bool', 4),
  35.     'bLoadedHudElements': ('bool', 5),
  36.     'szClassName': ('string', 6), # size = 80
  37.     'printname': ('string', 86), # size = 80
  38.     'viewmodel': ('string', 166), # size = 80
  39.     'playermodel': ('string', 246), # size = 80
  40.     'anim_prefix': ('string', 326), # size = 16
  41.     # Unknown at 342 or 2 bytes byte padding?
  42.     'bucket': ('int', 344), # What's right? This one or...
  43.     'IsSecondary': ('bool', 344), # ... this one?
  44.     'bucket_position': ('int', 348),
  45.     'clip_size': ('int', 352),
  46.     'clip2_size': ('int', 356),
  47.     'default_clip': ('int', 360),
  48.     'default_clip2': ('int', 364),
  49.     'weight': ('int', 368),
  50.     'rumble': ('int', 372),
  51.     'autoswitchto': ('bool', 376),
  52.     'autoswitchfrom': ('bool', 377),
  53.     'item_flags': ('int', 380),
  54.     'primary_ammo': ('string', 384), # size = 32
  55.     'secondary_ammo': ('string', 416), # size = 32
  56.     # SoundData start
  57.     # Each category has a size of 80
  58.     'empty': ('string', 448),
  59.     'single_shot': ('string', 528),
  60.     'SoundData2': ('string', 608),
  61.     'SoundData3': ('string', 688),
  62.     'SoundData4': ('string', 768),
  63.     'SoundData5': ('string', 848),
  64.     'reload': ('string', 928),
  65.     'SoundData7': ('string', 1008),
  66.     'SoundData8': ('string', 1088),
  67.     'SoundData9': ('string', 1168),
  68.     'SoundData10': ('string', 1248),
  69.     'special1': ('string', 1328),
  70.     'special2': ('string', 1408),
  71.     'special3': ('string', 1488),
  72.     'SoundData13': ('string', 1568),
  73.     'SoundData14': ('string', 1648),
  74.     # SoundData end
  75.     'iAmmoType1': ('int', 1728),
  76.     'iAmmoType2': ('int', 1732),
  77.     'MeleeWeapon': ('bool', 1736),
  78.     'BuiltRightHanded': ('bool', 1737),
  79.     'AllowFlipping': ('bool', 1738),
  80.     'showusagehint': ('bool', 1780),
  81.     'MaxPlayerSpeed': ('float', 1784),
  82.     'WeaponType': ('int', 1788),
  83.     'FullAuto': ('bool', 1792),
  84.     'Team': ('int', 1796),
  85.     'BotAudibleRange': ('float', 1800),
  86.     'WeaponArmorRatio': ('float', 1804),
  87.     'CrosshairMinDistance': ('int', 1808),
  88.     'CrosshairDeltaDistance': ('int', 1812),
  89.     'CanEquipWithShield': ('bool', 1816),
  90.     'WrongTeamMsg': ('string', 1817), # size = 32
  91.     'PlayerAnimationExtension': ('string', 1849), # size = 16
  92.     'shieldviewmodel': ('string', 1865), # size = 64
  93.     'AddonModel': ('string', 1929), # size = 80
  94.     'DroppedModel': ('string', 2009), # size = 80
  95.     'SilencerModel': ('string', 2089), # size = 80
  96.     # Unknown at 2169 or 3 byte padding?
  97.     'MuzzleFlashStyle': ('int', 2172),
  98.     'MuzzleFlashScale': ('float', 2176),
  99.     'Penetration': ('int', 2180),
  100.     'Damage': ('int', 2184),
  101.     'Range': ('float', 2188),
  102.     'RangeModifier': ('float', 2192),
  103.     'Bullets': ('int', 2196),
  104.     'CycleTime': ('float', 2200),
  105.     'AccuracyQuadratic': ('int', 2204),
  106.     'AccuracyDivisor': ('float', 2208),
  107.     'AccuracyOffset': ('float', 2212),
  108.     'MaxInaccuracy': ('float', 2216),
  109.     'Spread': ('float', 2220),
  110.     'SpreadAlt': ('float', 2224),
  111.     'InaccuracyCrouch': ('float', 2228),
  112.     'InaccuracyCrouchAlt': ('float', 2232),
  113.     'InaccuracyStand': ('float', 2236),
  114.     'InaccuracyStandAlt': ('float', 2240),
  115.     'InaccuracyJump': ('float', 2244),
  116.     'InaccuracyJumpAlt': ('float', 2248),
  117.     'InaccuracyLand': ('float', 2252),
  118.     'InaccuracyLandAlt': ('float', 2256),
  119.     'InaccuracyLadder': ('float', 2260),
  120.     'InaccuracyLadderAlt': ('float', 2264),
  121.     'InaccuracyFire': ('float', 2268),
  122.     'InaccuracyFireAlt': ('float', 2272),
  123.     'InaccuracyMove': ('float', 2276),
  124.     'InaccuracyMoveAlt': ('float', 2280),
  125.     'RecoveryTimeStand': ('float', 2284),
  126.     'RecoveryTimeCrouch': ('float', 2288),
  127.     'InaccuracyReload': ('float', 2292),
  128.     'InaccuracyAltSwitch': ('float', 2296),
  129.     'TimeToIdle': ('float', 2300),
  130.     'IdleInterval': ('float', 2304),
  131.     'WeaponPrice': ('int', 2308),
  132. }
  133.  
  134.  
  135. class CSWeaponInfo(binutils.Pointer):
  136.     def __getattr__(self, attr):
  137.         typename, offset = offsets.get(attr, (None, None))
  138.         if offset is None:
  139.             raise AttributeError('CSWeaponInfo has no attribute "%s".'% attr)
  140.  
  141.         method = getattr(self, 'get_' + typename)
  142.         if typename == 'string':
  143.             return method(offset, False)
  144.  
  145.         return method(offset)
  146.  
  147.     def __setattr__(self, attr, value):
  148.         typename, offset = offsets.get(attr, (None, None))
  149.         if offset is None:
  150.             raise AttributeError('CSWeaponInfo has no attribute "%s".'% attr)
  151.  
  152.         method = getattr(self, 'set_' + typename)
  153.         if typename == 'string':
  154.             method(value, 1024, offset, False)
  155.         else:
  156.             method(value, offset)
  157.  
  158.            
  159. """
  160. es.set('eventscripts_noisy', 1)
  161. def weapon_fire(ev):
  162.    userid = ev['userid']
  163.    es.setplayerprop(userid, 'CCSPlayer.cslocaldata.m_iShotsFired', 0)
  164.    es.setplayerprop(userid, 'CCSPlayer.baseclass.localdata.m_Local.m_vecPunchAngle', '0.000000,0.000000,0.000000')
  165. """
  166.  
  167. def print_weapon_ids():
  168.     for x in xrange(60):
  169.         info = CSWeaponInfo(GetWeaponInfo(x))
  170.         if not info:
  171.             continue
  172.  
  173.         name = info.szClassName
  174.         if name:
  175.             print (x, name)
  176.  
  177. def get_weapon_info(index):
  178.    return CSWeaponInfo(GetWeaponInfo(index)) or None
  179.  
  180. def weapon_infos():
  181.     for x in xrange(1, 29):
  182.         yield get_weapon_info(x)
  183.        
  184.        
  185. info = CSWeaponInfo(GetWeaponInfo(21))
  186. for attr in sorted(offsets):
  187.     print (attr + ':').ljust(30), getattr(info, attr)
  188.  
  189. print 'A total of %s properties.'% len(offsets)
  190. #print_weapon_ids()
  191.  
  192. """
  193. for info in weapon_infos():
  194.    for attr in offsets:
  195.        if 'accuracy' in attr.lower() or 'spread' in attr.lower():
  196.            setattr(info, attr, 0)
  197.        
  198.    info.WeaponPrice = 1
  199.    info.clip_size = 100
  200.    info.RecoveryTimeCrouch = 0
  201.    info.RecoveryTimeStand = 0
  202.    info.RangeModifier = 0
  203.    info.MuzzleFlashScale = 1
  204.    info.viewmodel = 'models/weapons/v_snip_awp.mdl'"""
  205.    
  206.    
  207.  
  208. """
  209. x = '''# =============================================================================
  210. # >> %s
  211. # =============================================================================
  212. '''
  213.  
  214. with path(__file__).parent.joinpath('weapon_config.txt').open('w') as f:
  215.    for info in weapon_infos():
  216.        f.write(x%info.szClassName)
  217.        for attr in sorted(offsets):
  218.            f.write((attr + ':').ljust(30) + str(getattr(info, attr)) + '\n')
  219.            
  220.        f.write('\n\n')"""
Advertisement
Add Comment
Please, Sign In to add comment