本文整理汇总了Python中memory.make_object函数的典型用法代码示例。如果您正苦于以下问题:Python make_object函数的具体用法?Python make_object怎么用?Python make_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pre_send_user_message
def _pre_send_user_message(args):
message_index = args[2]
user_message_hooks = HookUserMessage.hooks[message_index]
protobuf_user_message_hooks = HookProtobufUserMessage.hooks[message_index]
# No need to do anything behind this if no listener is registered
if not user_message_hooks and not protobuf_user_message_hooks:
return
# Replace original recipients filter
tmp_recipients = make_object(BaseRecipientFilter, args[1])
_recipients.update(*tuple(tmp_recipients), clear=True)
args[1] = _recipients
buffer = make_object(ProtobufMessage, args[3])
protobuf_user_message_hooks.notify(_recipients, buffer)
# No need to do anything behind this if no listener is registered
if not user_message_hooks:
return
try:
impl = get_user_message_impl(message_index)
except NotImplementedError:
return
data = impl.read(buffer)
user_message_hooks.notify(_recipients, data)
# Update buffer if data has been changed
if data.has_been_changed():
buffer.clear()
impl.write(buffer, data)
示例2: pre_bump_weapon
def pre_bump_weapon(self, stack_data):
"""Switch the player's team if they are a CT picking up the bomb."""
if make_object(Entity, stack_data[1]).classname != 'weapon_c4':
return
self.bump_player = make_object(Entity, stack_data[0])
if self.bump_player.team == 3:
self.bump_player.team_index = 2
else:
self.bump_player = None
示例3: _callback
def _callback(stack_data, *args):
"""Called when the hooked method is called."""
# Get the temp entity instance...
temp_entity = make_object(TempEntity, stack_data[0])
# Are we looking for that temp entity?
if temp_entity.name == self.name:
# Call the registered callback...
return callback(temp_entity, make_object(
RecipientFilter, stack_data[1]))
示例4: on_take_damage
def on_take_damage(args):
info = make_object(TakeDamageInfo, args[1])
if info.type & DamageTypes.HEADSHOT:
info.damage *= HEADSHOT_DMG_MULTIPLIER
else:
victim = make_object(Player, args[0])
if victim.hitgroup in (HitGroup.CHEST, HitGroup.STOMACH):
info.damage *= CHEST_DMG_MULTIPLIER
else:
info.damage *= BASE_DMG_MULTIPLIER
示例5: on_take_damage
def on_take_damage(args):
protected_player = protected_player_manager[index_from_pointer(args[0])]
if protected_player.dead:
return
info = make_object(TakeDamageInfo, args[1])
return protected_player._hurt(info)
示例6: _pre_on_take_damage
def _pre_on_take_damage(args):
"""
Hooked to a function that is fired any time an
entity takes damage.
"""
player_index = index_from_pointer(args[0])
info = make_object(TakeDamageInfo, args[1])
defender = Player(player_index)
attacker = None if not info.attacker else Player(info.attacker)
eargs = {
'attacker': attacker,
'defender': defender,
'info': info,
'weapon': Weapon(
index_from_inthandle(attacker.active_weapon)
).class_name if attacker and attacker.active_weapon != -1 else ''
}
if not player_index == info.attacker:
defender.hero.execute_skills('player_pre_defend', **eargs)
'''
Added exception to check whether world caused damage.
'''
if attacker:
attacker.hero.execute_skills('player_pre_attack', **eargs)
示例7: _pre_damage_call_events
def _pre_damage_call_events(stack_data):
take_damage_info = make_object(TakeDamageInfo, stack_data[1])
if not take_damage_info.attacker:
return
entity = Entity(take_damage_info.attacker)
attacker = players[entity.index] if entity.is_player() else None
victim = players[index_from_pointer(stack_data[0])]
event_args = {
'attacker': attacker,
'victim': victim,
'take_damage_info': take_damage_info,
}
if attacker:
if victim.team == attacker.team:
attacker.hero.call_events('player_pre_teammate_attack', player=attacker,
**event_args)
victim.hero.call_events('player_pre_teammate_victim', player=victim, **event_args)
return
attacker.hero.call_events('player_pre_attack', player=attacker, **event_args)
victim.hero.call_events('player_pre_victim', player=victim, **event_args)
if victim.health <= take_damage_info.damage:
attacker.hero.call_events('player_pre_death', player=victim, **event_args)
示例8: base_client
def base_client(self):
"""Return the player's base client instance.
:rtype: BaseClient
"""
from players import BaseClient
return make_object(BaseClient, get_object_pointer(self.client) - 4)
示例9: __iter__
def __iter__(self):
"""Iterate over all WeaponInfo instances."""
# Loop through all indexes...
for index in range(_weapon_scripts._length):
# Yield the WeaponInfo instance at the current slot...
yield make_object(WeaponInfo, _weapon_scripts._find(index))
示例10: convert
def convert(self, name, ptr):
"""Convert the pointer.
Tries to convert a pointer in the following order:
Attempts to convert the pointer...
1. to a custom type
2. to a exposed type
3. to a function typedef
4. by using a converter
"""
cls = self.get_class(name)
if cls is not None:
# Use the class to convert the pointer
return make_object(cls, ptr)
# No class was found. Maybe we have luck with a function typedef
converter = self.function_typedefs.get(name, None)
# Is there no function typedef?
if converter is None:
converter = self.converters.get(name, None)
# Is there no converter?
if converter is None:
raise NameError(
'No class, function typedef or ' +
'converter found for "{0}".'.format(name))
# Yay, we found a converter or function typedef!
return converter(ptr)
示例11: _pre_detonate
def _pre_detonate(args):
entity = make_object(Entity, args[0])
if entity.index not in _filtered_indexes:
return None
dissolve(entity)
return True
示例12: _pre_on_take_damage
def _pre_on_take_damage(args):
info = make_object(TakeDamageInfo, args[1])
entity = Entity(info.attacker) if info.attacker else None
if entity is not None and entity.is_player():
attacker = wcgo.player.Player(entity.index)
else:
attacker = None
victim = wcgo.player.Player(index_from_pointer(args[0]))
eargs = {
'attacker': attacker,
'victim': victim,
'info': info,
}
# Adds the weapon argument dependent on scenario
if attacker is not None and attacker.active_weapon != -1:
eargs['weapon'] = Weapon(index_from_inthandle(attacker.active_weapon))
else:
eargs['weapon'] = None
if attacker is None or attacker.userid == victim.userid:
victim.hero.execute_skills('player_pre_self_injury', player=victim, **eargs)
return
if not (attacker.steamid == 'BOT' and attacker.hero is None):
attacker.hero.execute_skills('player_pre_attack', player=attacker, **eargs)
if not (victim.steamid == 'BOT' and victim.hero is None):
victim.hero.execute_skills('player_pre_victim', player=victim, **eargs)
示例13: give_level_weapon
def give_level_weapon(self):
"""Give the player the weapon of their current level."""
if self.has_level_weapon():
return self.get_weapon(self.level_weapon_classname)
return make_object(
Weapon,
self.give_named_item(self.level_weapon_classname)
)
示例14: _pre_take_damage
def _pre_take_damage(stack_data):
"""Store the information for later use."""
take_damage_info = make_object(TakeDamageInfo, stack_data[1])
attacker = Entity(take_damage_info.attacker)
if attacker.classname != 'player':
return
victim = make_object(Player, stack_data[0])
if victim.health > take_damage_info.damage:
return
KILLER_DICTIONARY[victim.userid] = {
'attacker': userid_from_index(attacker.index),
'end': Vector(*take_damage_info.position),
'projectile': attacker.index != take_damage_info.inflictor,
'color': _team_colors[victim.team],
}
示例15: _get_property
def _get_property(self, prop_name, prop_type):
"""Return the value of the given property name.
:param str prop_name:
The name of the property.
:param SendPropType prop_type:
The type of the property.
"""
# Is the given property not valid?
if prop_name not in self.template.properties:
# Raise an exception...
raise NameError(
'"{}" is not a valid property for temp entity "{}".'.format(
prop_name, self.name))
# Get the property data...
prop, offset, type_name = self.template.properties[prop_name]
# Are the prop types matching?
if prop.type != prop_type:
# Raise an exception...
raise TypeError('"{}" is not of type "{}".'.format(
prop_name, prop_type))
# Is the property an array?
if prop_type == SendPropType.ARRAY:
# Return an array instance...
return Array(manager, False, type_name, get_object_pointer(
self) + offset, prop.length)
# Is the given type not supported?
if prop_type not in _supported_property_types:
# Raise an exception...
raise TypeError('"{}" is not supported.'.format(prop_type))
# Is the type native?
if Type.is_native(type_name):
# Return the value...
return getattr(
get_object_pointer(self), 'get_' + type_name)(offset)
# Otherwise
else:
# Make the object and return it...
return make_object(
manager.get_class(type_name),
get_object_pointer(self) + offset)
# Raise an exception...
raise ValueError('Unable to get the value of "{}".'.format(prop_name))