Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # >> IMPORTS
- # =============================================================================
- # Python
- from __future__ import with_statement
- import os
- import pprint
- from path import path
- # EventScripts
- import es
- import binutils
- from binutils import Convention
- # =============================================================================
- # >> GLOBAL VARIABLES
- # =============================================================================
- server = binutils.find_binary('cstrike/bin/server')
- if os.name == 'nt':
- GetWeaponInfo_ptr = server.find_signature('\x55\x8B\xEC\x8B\x4D\x08\x85\xC9\x75\x2A\x33\xC0\x5D\xC3')
- else:
- GetWeaponInfo_ptr = server['_Z13GetWeaponInfo10CSWeaponID']
- GetWeaponInfo = GetWeaponInfo_ptr.make_function(Convention.CDECL, 'i)p')
- # Size of a category of SoundData is 80
- offsets = {
- 'vtable': ('ptr', 0),
- 'bParsedScript': ('bool', 4),
- 'bLoadedHudElements': ('bool', 5),
- 'szClassName': ('string', 6), # size = 80
- 'printname': ('string', 86), # size = 80
- 'viewmodel': ('string', 166), # size = 80
- 'playermodel': ('string', 246), # size = 80
- 'anim_prefix': ('string', 326), # size = 16
- # Unknown at 342 or 2 bytes byte padding?
- 'bucket': ('int', 344), # What's right? This one or...
- 'IsSecondary': ('bool', 344), # ... this one?
- 'bucket_position': ('int', 348),
- 'clip_size': ('int', 352),
- 'clip2_size': ('int', 356),
- 'default_clip': ('int', 360),
- 'default_clip2': ('int', 364),
- 'weight': ('int', 368),
- 'rumble': ('int', 372),
- 'autoswitchto': ('bool', 376),
- 'autoswitchfrom': ('bool', 377),
- 'item_flags': ('int', 380),
- 'primary_ammo': ('string', 384), # size = 32
- 'secondary_ammo': ('string', 416), # size = 32
- # SoundData start
- # Each category has a size of 80
- 'empty': ('string', 448),
- 'single_shot': ('string', 528),
- 'SoundData2': ('string', 608),
- 'SoundData3': ('string', 688),
- 'SoundData4': ('string', 768),
- 'SoundData5': ('string', 848),
- 'reload': ('string', 928),
- 'SoundData7': ('string', 1008),
- 'SoundData8': ('string', 1088),
- 'SoundData9': ('string', 1168),
- 'SoundData10': ('string', 1248),
- 'special1': ('string', 1328),
- 'special2': ('string', 1408),
- 'special3': ('string', 1488),
- 'SoundData13': ('string', 1568),
- 'SoundData14': ('string', 1648),
- # SoundData end
- 'iAmmoType1': ('int', 1728),
- 'iAmmoType2': ('int', 1732),
- 'MeleeWeapon': ('bool', 1736),
- 'BuiltRightHanded': ('bool', 1737),
- 'AllowFlipping': ('bool', 1738),
- 'showusagehint': ('bool', 1780),
- 'MaxPlayerSpeed': ('float', 1784),
- 'WeaponType': ('int', 1788),
- 'FullAuto': ('bool', 1792),
- 'Team': ('int', 1796),
- 'BotAudibleRange': ('float', 1800),
- 'WeaponArmorRatio': ('float', 1804),
- 'CrosshairMinDistance': ('int', 1808),
- 'CrosshairDeltaDistance': ('int', 1812),
- 'CanEquipWithShield': ('bool', 1816),
- 'WrongTeamMsg': ('string', 1817), # size = 32
- 'PlayerAnimationExtension': ('string', 1849), # size = 16
- 'shieldviewmodel': ('string', 1865), # size = 64
- 'AddonModel': ('string', 1929), # size = 80
- 'DroppedModel': ('string', 2009), # size = 80
- 'SilencerModel': ('string', 2089), # size = 80
- # Unknown at 2169 or 3 byte padding?
- 'MuzzleFlashStyle': ('int', 2172),
- 'MuzzleFlashScale': ('float', 2176),
- 'Penetration': ('int', 2180),
- 'Damage': ('int', 2184),
- 'Range': ('float', 2188),
- 'RangeModifier': ('float', 2192),
- 'Bullets': ('int', 2196),
- 'CycleTime': ('float', 2200),
- 'AccuracyQuadratic': ('int', 2204),
- 'AccuracyDivisor': ('float', 2208),
- 'AccuracyOffset': ('float', 2212),
- 'MaxInaccuracy': ('float', 2216),
- 'Spread': ('float', 2220),
- 'SpreadAlt': ('float', 2224),
- 'InaccuracyCrouch': ('float', 2228),
- 'InaccuracyCrouchAlt': ('float', 2232),
- 'InaccuracyStand': ('float', 2236),
- 'InaccuracyStandAlt': ('float', 2240),
- 'InaccuracyJump': ('float', 2244),
- 'InaccuracyJumpAlt': ('float', 2248),
- 'InaccuracyLand': ('float', 2252),
- 'InaccuracyLandAlt': ('float', 2256),
- 'InaccuracyLadder': ('float', 2260),
- 'InaccuracyLadderAlt': ('float', 2264),
- 'InaccuracyFire': ('float', 2268),
- 'InaccuracyFireAlt': ('float', 2272),
- 'InaccuracyMove': ('float', 2276),
- 'InaccuracyMoveAlt': ('float', 2280),
- 'RecoveryTimeStand': ('float', 2284),
- 'RecoveryTimeCrouch': ('float', 2288),
- 'InaccuracyReload': ('float', 2292),
- 'InaccuracyAltSwitch': ('float', 2296),
- 'TimeToIdle': ('float', 2300),
- 'IdleInterval': ('float', 2304),
- 'WeaponPrice': ('int', 2308),
- }
- class CSWeaponInfo(binutils.Pointer):
- def __getattr__(self, attr):
- typename, offset = offsets.get(attr, (None, None))
- if offset is None:
- raise AttributeError('CSWeaponInfo has no attribute "%s".'% attr)
- method = getattr(self, 'get_' + typename)
- if typename == 'string':
- return method(offset, False)
- return method(offset)
- def __setattr__(self, attr, value):
- typename, offset = offsets.get(attr, (None, None))
- if offset is None:
- raise AttributeError('CSWeaponInfo has no attribute "%s".'% attr)
- method = getattr(self, 'set_' + typename)
- if typename == 'string':
- method(value, 1024, offset, False)
- else:
- method(value, offset)
- """
- es.set('eventscripts_noisy', 1)
- def weapon_fire(ev):
- userid = ev['userid']
- es.setplayerprop(userid, 'CCSPlayer.cslocaldata.m_iShotsFired', 0)
- es.setplayerprop(userid, 'CCSPlayer.baseclass.localdata.m_Local.m_vecPunchAngle', '0.000000,0.000000,0.000000')
- """
- def print_weapon_ids():
- for x in xrange(60):
- info = CSWeaponInfo(GetWeaponInfo(x))
- if not info:
- continue
- name = info.szClassName
- if name:
- print (x, name)
- def get_weapon_info(index):
- return CSWeaponInfo(GetWeaponInfo(index)) or None
- def weapon_infos():
- for x in xrange(1, 29):
- yield get_weapon_info(x)
- info = CSWeaponInfo(GetWeaponInfo(21))
- for attr in sorted(offsets):
- print (attr + ':').ljust(30), getattr(info, attr)
- print 'A total of %s properties.'% len(offsets)
- #print_weapon_ids()
- """
- for info in weapon_infos():
- for attr in offsets:
- if 'accuracy' in attr.lower() or 'spread' in attr.lower():
- setattr(info, attr, 0)
- info.WeaponPrice = 1
- info.clip_size = 100
- info.RecoveryTimeCrouch = 0
- info.RecoveryTimeStand = 0
- info.RangeModifier = 0
- info.MuzzleFlashScale = 1
- info.viewmodel = 'models/weapons/v_snip_awp.mdl'"""
- """
- x = '''# =============================================================================
- # >> %s
- # =============================================================================
- '''
- with path(__file__).parent.joinpath('weapon_config.txt').open('w') as f:
- for info in weapon_infos():
- f.write(x%info.szClassName)
- for attr in sorted(offsets):
- f.write((attr + ':').ljust(30) + str(getattr(info, attr)) + '\n')
- f.write('\n\n')"""
Advertisement
Add Comment
Please, Sign In to add comment