Example #1
0
        def fset(ptr, value):
            """Set the property value and notify if networked."""
            # Does the property have True/False values?
            if true_value is not None:

                # Get the proper value to set
                value = true_value if value else false_value

            # Is the property a native type?
            if native_type:

                # Set the property
                getattr(ptr, 'set_' + type_name)(value, offset)

            # Is the property not a native type?
            else:

                # Get the class to set the property as
                cls = self.get_class(type_name)

                # Set the property
                get_object_pointer(value).copy(
                    ptr + offset, cls._size)

            # Is the property networked?
            if networked:

                # Notify the change of state
                edict_from_pointer(ptr).state_changed()
Example #2
0
        def fset(ptr, value):
            """Set the property value and notify if networked."""
            # Is the property a native type?
            if native_type:

                # Does the value need cast to a string?
                if type_name == 'char':
                    value = chr(value)

                # Set the property
                getattr(ptr, 'set_' + type_name)(value, offset)

            # Is the property not a native type?
            else:

                # Get the class to set the property as
                cls = self.get_class(type_name)

                # Set the property
                get_object_pointer(value).copy(ptr + offset, cls._size)

            # Is the property networked?
            if networked:

                # Notify the change of state
                edict_from_pointer(ptr).state_changed()
Example #3
0
        def fset(ptr, value):
            """Set the property value and notify if networked."""
            # Is the property a native type?
            if native_type:

                # Does the value need cast to a string?
                if type_name == 'char':
                    value = chr(value)

                # Set the property
                getattr(ptr, 'set_' + type_name)(value, offset)

            # Is the property not a native type?
            else:

                # Get the class to set the property as
                cls = self.get_class(type_name)

                # Set the property
                get_object_pointer(value).copy(
                    ptr + offset, cls._size)

            # Is the property networked?
            if networked:

                # Notify the change of state
                edict_from_pointer(ptr).state_changed()
    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))
Example #5
0
    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))
Example #6
0
        def fset(ptr, value):
            """Set the instance attribute value."""
            # Handle custom type
            if not native_type:
                cls = self.get_class(type_name)
                if cls is None:
                    raise NameError('Unknown class "{0}".'.format(type_name))

                get_object_pointer(value).copy(ptr + offset, cls._size)

            # Handle native type
            else:
                getattr(ptr, 'set_' + type_name)(value, offset)
Example #7
0
        def fset(ptr, value):
            """Set the instance attribute value."""
            # Handle custom type
            if not native_type:
                cls = self.get_class(type_name)
                if cls is None:
                    raise NameError('Unknown class "{0}".'.format(type_name))

                get_object_pointer(value).copy(
                    ptr + offset,
                    cls._size
                )

            # Handle native type
            else:
                getattr(ptr, 'set_' + type_name)(value, offset)
Example #8
0
    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)
    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)
Example #10
0
 def _pre_user_message_begin(args):
     try:
         # Replace original recipients filter
         tmp_recipients = make_object(BaseRecipientFilter, args[1])
         _recipients.update(*tuple(tmp_recipients), clear=True)
     except RuntimeError:
         # Patch for issue #314
         tmp_recipients = RecipientFilter()
         (args[1] + 4).copy(
             get_object_pointer(tmp_recipients) + 4,
             get_size(RecipientFilter) - 4)
         _recipients.update(*tuple(tmp_recipients), clear=True)
     args[1] = _recipients
Example #11
0
    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

        try:
            # Replace original recipients filter
            tmp_recipients = make_object(BaseRecipientFilter, args[1])
            _recipients.update(*tuple(tmp_recipients), clear=True)
        except RuntimeError:
            # Patch for issue #314
            tmp_recipients = RecipientFilter()
            (args[1] + 4).copy(
                get_object_pointer(tmp_recipients) + 4,
                get_size(RecipientFilter) - 4)
            _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)
Example #12
0
def _pre_player_run_command(args):
    if (not on_player_run_command_listener_manager
            and not on_button_state_changed_listener_manager):
        return

    player = make_object(Player, args[0])

    # https://github.com/Source-Python-Dev-Team/Source.Python/issues/149
    use_rtti_fix = SOURCE_ENGINE_BRANCH == 'tf2' and player.is_fake_client()
    if use_rtti_fix:
        user_cmd = UserCmd()
        user_cmd_ptr = get_object_pointer(user_cmd)
        args[1].copy(user_cmd_ptr, USER_CMD_SIZE)
    else:
        user_cmd = make_object(UserCmd, args[1])

    if on_player_run_command_listener_manager:
        on_player_run_command_listener_manager.notify(player, user_cmd)

    if on_button_state_changed_listener_manager:
        _handle_button_state_changed(player, player.buttons, user_cmd.buttons)

    if use_rtti_fix:
        user_cmd_ptr.copy(args[1], USER_CMD_SIZE)
def _pre_player_run_command(args):
    if (not on_player_run_command_listener_manager
            and not on_button_state_changed_listener_manager):
        return

    player = make_object(Player, args[0])

    # https://github.com/Source-Python-Dev-Team/Source.Python/issues/149
    use_rtti_fix = SOURCE_ENGINE_BRANCH == 'tf2' and player.is_fake_client()
    if use_rtti_fix:
        user_cmd = UserCmd()
        user_cmd_ptr = get_object_pointer(user_cmd)
        args[1].copy(user_cmd_ptr, USER_CMD_SIZE)
    else:
        user_cmd = make_object(UserCmd, args[1])

    if on_player_run_command_listener_manager:
        on_player_run_command_listener_manager.notify(player, user_cmd)

    if on_button_state_changed_listener_manager:
        _handle_button_state_changed(player, player.buttons, user_cmd.buttons)

    if use_rtti_fix:
        user_cmd_ptr.copy(args[1], USER_CMD_SIZE)
Example #14
0
 def base_client(self):
     """Return the player's :class:`players.BaseClient` object."""
     return memory.make_object(BaseClient,
                               memory.get_object_pointer(self.client) - 4)
Example #15
0
    def pointer(self):
        """Return the entity's pointer."""
        if self._pointer is None:
            self._pointer = memory.get_object_pointer(self)

        return self._pointer
Example #16
0
    def _set_property(self, prop_name, prop_type, value):
        """Set the given property to the given value.

        :param str prop_name: The name of the property.
        :param SendPropType prop_type: The type of the property.
        :param value object: To value to set to the given 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:

            # Is the given value not an Array instance?
            if not isinstance(value, Array):

                # Raise an exception...
                raise TypeError('Given value is not an Array instance.')

            # Is the length not matching?
            if value._length != prop.length:

                # Raise an exception...
                raise ValueError('Given array is not of length "{}".'.format(
                    prop.length))

            # Copy the values...
            value.copy(get_object_pointer(self), self._get_type_size(
                type_name) * prop.length)

            # No need to go further...
            return

        # Otherwise, is the type native?
        elif Type.is_native(type_name):

            # Set the value of the property...
            getattr(get_object_pointer(self), 'set_{}'.format(type_name))(
                value, offset)

            # No need to go further...
            return

        # Otherwise...
        else:

            # Get the class...
            cls = manager.get_class(type_name)

            # Is the given value valid?
            if not isinstance(value, cls):

                # Raise an exception...
                raise TypeError('"{}" is not a valid "{}" value.'.format(
                    value, type_name))

            # Set the value of the property...
            get_object_pointer(value).copy(
                get_object_pointer(self) + offset, get_size(cls))

            # No need to go further...
            return

        # Raise an exception...
        raise NameError('Unable to set "{}" for the temp entity "{}".'.format(
            prop_name, self.name))
Example #17
0
    def __setattr__(self, name, value):
        """Set the value of the given alias.

        :param str name: The alias name.
        :param object value: The value to set.
        """
        # Get the name of the prop...
        prop_name = self.template.aliases.get(name, None)

        # Was the given name a valid alias?
        if prop_name is not None:

            # Is the name a section?
            if isinstance(prop_name, Section):

                # Is the alias a decal?
                if prop_name['type'] == Decal.__name__:

                    # Is the given value an invalid decal instance?
                    if not isinstance(value, Decal):

                        # Raise an exception...
                        raise ValueError(
                            '"{}" is not a valid Decal instance.'.format(
                                value))

                    # Set the model index...
                    setattr(self, prop_name['name'], value.index)

                # Is the alias an entity?
                elif prop_name['type'] == Entity.__name__:

                    # Is the given value an invalid entity instance?
                    if not isinstance(value, Entity):

                        # Raise an exception...
                        raise ValueError(
                            '"{}" is not a valid Entity instance.'.format(
                                value))

                    # Set the alias value...
                    setattr(self, prop_name['name'], value.index)

                # Otherwise, is the alias a player?
                elif prop_name['type'] == Player.__name__:

                    # Set the player instance...
                    setattr(self, prop_name['name'], value.index)

                # Otherwise, is the alias a model?
                elif prop_name['type'] == Model.__name__:

                    # Is the given value an invalid model instance?
                    if not isinstance(value, Model):

                        # Raise an exception...
                        raise ValueError(
                            '"{}" is not a valid Model instance.'.format(
                                value))

                    # Set the model index...
                    setattr(self, prop_name['name'], value.index)

                # Otherwise, is the alias a color?
                elif prop_name['type'] == Color.__name__:

                    # Is the given value an invalid color instance?
                    if not isinstance(value, Color):

                        # Raise an exception...
                        raise ValueError(
                            '"{}" is not a valid Color instance.'.format(
                                value))

                    # Loop through all aliases...
                    for index, alias in enumerate(prop_name['name']):

                        # Set the current alias...
                        setattr(self, alias, value[index])

                # Otherwise...
                else:

                    # Get the data of the property...
                    prop, offset, type_name = self.template.properties[
                        prop_name['name']]

                    # Get the class of the type...
                    cls = manager.get_class(prop_name['type'])

                    # Is the given value not valid?
                    if not isinstance(value, cls):

                        # Raise an exception...
                        raise TypeError(
                            'The given value is not of type "{}".'.format(
                                type_name))

                    # Set the value of the property...
                    get_object_pointer(value).copy(
                        get_object_pointer(self) + offset,
                        self.template._get_type_size(prop_name['type']))

                # No need to go further...
                return

            # Get the data of the property...
            prop, offset, type_name = self.template.properties[prop_name]

            # Set the value of the property...
            self._set_property(prop_name, prop.type, value)

            # No need to go further...
            return

        # Set the value of the given attribute...
        super().__setattr__(name, value)
Example #18
0
    def __getattr__(self, name):
        """Return the value of the given alias.

        :param str name: The alias name.
        :rtype: object
        """
        # Get the name of the prop...
        prop_name = self.template.aliases.get(name, None)

        # Was the given name a valid alias?
        if prop_name is not None:

            # Is the name a section?
            if isinstance(prop_name, Section):

                # Is the alias a decal?
                if prop_name['type'] == Decal.__name__:

                    # Return the decal instance...
                    return Decal(string_tables[Decal._precache_table][
                        getattr(self, prop_name['name'])])

                # Otherwise, is the alias an entity?
                elif prop_name['type'] == Entity.__name__:

                    # Return the entity instance...
                    return Entity(getattr(self, prop_name['name']))

                # Otherwise, is the alias a player?
                elif prop_name['type'] == Player.__name__:

                    # Return the player instance...
                    return Player(getattr(self, prop_name['name']))

                # Otherwise, is the alias a model?
                elif prop_name['type'] == Model.__name__:

                    # Get the name of the model...
                    model_name = string_tables[Model._precache_table][
                        getattr(self, prop_name['name'])]

                    # Was the model not precached?
                    if not model_name:

                        # Return an error model...
                        return Model('models/error.mdl')

                    # Return the model instance...
                    return Model(model_name)

                # Otherwise, is the alias a color?
                elif prop_name['type'] == Color.__name__:

                    # Get a tuple to store the RGBA values...
                    values = tuple()

                    # Loop through all aliases...
                    for alias in prop_name['name']:

                        # Add the current value to the tuple...
                        values += (getattr(self, alias),)

                    # Return the color instance...
                    return Color(*values)

                # Otherwise...
                else:

                    # Get the data of the property...
                    prop, offset, type_name = self.template.properties[
                        prop_name['name']]

                    # Return the value of the property...
                    return make_object(
                        manager.get_class(prop_name['type']),
                        get_object_pointer(self) + offset)

            # Get the data of the property...
            prop, offset, type_name = self.template.properties[prop_name]

            # Return the value of the property...
            return self._get_property(prop_name, prop.type)

        # Return the value of the given attribute...
        return super().__getattribute__(name)
Example #19
0
from players import Client

# Connect Filter
from .. import get_connection_rejection_text
from ..paths import CF_DATA_PATH

# =============================================================================
# >> CONSTANTS
# =============================================================================
MAX_REJECTION_TEXT_LENGTH = 64

# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
manager = TypeManager()
server_ptr = get_object_pointer(server)

CustomServer = manager.create_type_from_file(
    'CBaseServer', CF_DATA_PATH / 'memory' / GAME_NAME / 'CBaseServer.ini')

custom_server = make_object(CustomServer, server_ptr)


# =============================================================================
# >> HOOKS
# =============================================================================
@PostHook(custom_server.check_challenge_type)
def post_check_challenge_type(args, ret_val):
    client = make_object(Client, args[1] + 4)

    rejection_text = get_connection_rejection_text(client)
Example #20
0
 def pointer(self):
     """Return the entity's :class:`memory.Pointer`."""
     if self._pointer is None:
         pointer = get_object_pointer(self)
         object.__setattr__(self, '_pointer', pointer)
     return self._pointer
Example #21
0
    def __getattr__(self, name):
        """Return the value of the given alias.

        :param str name: The alias name.
        :rtype: object
        """
        # Get the name of the prop...
        prop_name = self.template.aliases.get(name, None)

        # Was the given name a valid alias?
        if prop_name is not None:

            # Is the name a section?
            if isinstance(prop_name, Section):

                # Is the alias a decal?
                if prop_name['type'] == Decal.__name__:

                    # Return the decal instance...
                    return Decal(string_tables[Decal._precache_table][getattr(
                        self, prop_name['name'])])

                # Otherwise, is the alias an entity?
                elif prop_name['type'] == Entity.__name__:

                    # Return the entity instance...
                    return Entity(getattr(self, prop_name['name']))

                # Otherwise, is the alias a player?
                elif prop_name['type'] == Player.__name__:

                    # Return the player instance...
                    return Player(getattr(self, prop_name['name']))

                # Otherwise, is the alias a model?
                elif prop_name['type'] == Model.__name__:

                    # Get the name of the model...
                    model_name = string_tables[Model._precache_table][getattr(
                        self, prop_name['name'])]

                    # Was the model not precached?
                    if not model_name:

                        # Return an error model...
                        return Model('models/error.mdl')

                    # Return the model instance...
                    return Model(model_name)

                # Otherwise, is the alias a color?
                elif prop_name['type'] == Color.__name__:

                    # Get a tuple to store the RGBA values...
                    values = tuple()

                    # Loop through all aliases...
                    for alias in prop_name['name']:

                        # Add the current value to the tuple...
                        values += (getattr(self, alias), )

                    # Return the color instance...
                    return Color(*values)

                # Otherwise...
                else:

                    # Get the data of the property...
                    prop, offset, type_name = self.template.properties[
                        prop_name['name']]

                    # Return the value of the property...
                    return make_object(manager.get_class(prop_name['type']),
                                       get_object_pointer(self) + offset)

            # Get the data of the property...
            prop, offset, type_name = self.template.properties[prop_name]

            # Return the value of the property...
            return self._get_property(prop_name, prop.type)

        # Return the value of the given attribute...
        return super().__getattribute__(name)
Example #22
0
from memory import get_object_pointer, make_object
from memory.hooks import PreHook
from memory.manager import TypeManager
from _messages import ProtobufMessage
from messages import get_message_index

# DeadChat
from ..core.paths import DEADCHAT_DATA_PATH
from ..deadchat import is_hltv_message


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
say_text2_index = get_message_index('SayText2')
engine_server_ptr = get_object_pointer(engine_server)

type_manager = TypeManager()
engine_server_type = type_manager.create_type_from_file(
    'CVEngineServer', DEADCHAT_DATA_PATH / "protobuf" / "CVEngineServer.ini")

engine_server = make_object(engine_server_type, engine_server_ptr)


# =============================================================================
# >> HOOKS
# =============================================================================
@PreHook(engine_server.send_user_message)
def pre_send_user_message(args):
    if args[2] != say_text2_index:
        return
Example #23
0
    def __setattr__(self, name, value):
        """Set the value of the given alias.

        :param str name: The alias name.
        :param object value: The value to set.
        """
        # Get the name of the prop...
        prop_name = self.template.aliases.get(name, None)

        # Was the given name a valid alias?
        if prop_name is not None:

            # Is the name a section?
            if isinstance(prop_name, Section):

                # Is the alias a decal?
                if prop_name['type'] == Decal.__name__:

                    # Is the given value an invalid decal instance?
                    if not isinstance(value, Decal):

                        # Raise an exception...
                        raise ValueError(
                            '"{}" is not a valid Decal instance.'.format(
                                value))

                    # Set the model index...
                    setattr(self, prop_name['name'], value.index)

                # Is the alias an entity?
                elif prop_name['type'] == Entity.__name__:

                    # Is the given value an invalid entity instance?
                    if not isinstance(value, Entity):

                        # Raise an exception...
                        raise ValueError(
                            '"{}" is not a valid Entity instance.'.format(
                                value))

                    # Set the alias value...
                    setattr(self, prop_name['name'], value.index)

                # Otherwise, is the alias a player?
                elif prop_name['type'] == Player.__name__:

                    # Set the player instance...
                    setattr(self, prop_name['name'], value.index)

                # Otherwise, is the alias a model?
                elif prop_name['type'] == Model.__name__:

                    # Is the given value an invalid model instance?
                    if not isinstance(value, Model):

                        # Raise an exception...
                        raise ValueError(
                            '"{}" is not a valid Model instance.'.format(
                                value))

                    # Set the model index...
                    setattr(self, prop_name['name'], value.index)

                # Otherwise, is the alias a color?
                elif prop_name['type'] == Color.__name__:

                    # Is the given value an invalid color instance?
                    if not isinstance(value, Color):

                        # Raise an exception...
                        raise ValueError(
                            '"{}" is not a valid Color instance.'.format(
                                value))

                    # Loop through all aliases...
                    for index, alias in enumerate(prop_name['name']):

                        # Set the current alias...
                        setattr(self, alias, value[index])

                # Otherwise...
                else:

                    # Get the data of the property...
                    prop, offset, type_name = self.template.properties[
                        prop_name['name']]

                    # Get the class of the type...
                    cls = manager.get_class(prop_name['type'])

                    # Is the given value not valid?
                    if not isinstance(value, cls):

                        # Raise an exception...
                        raise TypeError(
                            'The given value is not of type "{}".'.format(
                                type_name))

                    # Set the value of the property...
                    get_object_pointer(value).copy(
                        get_object_pointer(self) + offset,
                        self.template._get_type_size(prop_name['type']))

                # No need to go further...
                return

            # Get the data of the property...
            prop, offset, type_name = self.template.properties[prop_name]

            # Set the value of the property...
            self._set_property(prop_name, prop.type, value)

            # No need to go further...
            return

        # Set the value of the given attribute...
        super().__setattr__(name, value)
Example #24
0
    def _set_property(self, prop_name, prop_type, value):
        """Set the given property to the given value.

        :param str prop_name: The name of the property.
        :param SendPropType prop_type: The type of the property.
        :param value object: To value to set to the given 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:

            # Is the given value not an Array instance?
            if not isinstance(value, Array):

                # Raise an exception...
                raise TypeError('Given value is not an Array instance.')

            # Is the length not matching?
            if value._length != prop.length:

                # Raise an exception...
                raise ValueError('Given array is not of length "{}".'.format(
                    prop.length))

            # Copy the values...
            value.copy(get_object_pointer(self),
                       self._get_type_size(type_name) * prop.length)

            # No need to go further...
            return

        # Otherwise, is the type native?
        elif Type.is_native(type_name):

            # Set the value of the property...
            getattr(get_object_pointer(self),
                    'set_{}'.format(type_name))(value, offset)

            # No need to go further...
            return

        # Otherwise...
        else:

            # Get the class...
            cls = manager.get_class(type_name)

            # Is the given value valid?
            if not isinstance(value, cls):

                # Raise an exception...
                raise TypeError('"{}" is not a valid "{}" value.'.format(
                    value, type_name))

            # Set the value of the property...
            get_object_pointer(value).copy(
                get_object_pointer(self) + offset, get_size(cls))

            # No need to go further...
            return

        # Raise an exception...
        raise NameError('Unable to set "{}" for the temp entity "{}".'.format(
            prop_name, self.name))
Example #25
0
 def base_client(self):
     """Return the player's :class:`players.BaseClient` object."""
     from players import BaseClient
     return make_object(BaseClient, get_object_pointer(self.client) - 4)
Example #26
0
CENSORED_NAME = "Advertiser #{userid:04}"
REPLACE_DOMAIN_RES_PATH = ADPURGE_DATA_PATH / "replace-domain.res"
REPLACE_IP_RES_PATH = ADPURGE_DATA_PATH / "replace-ip.res"
DOMAIN_AD_REGEX = re.compile(r"\w+\.({tlds})".format(tlds='|'.join(tlds)))
IP_AD_REGEX = re.compile(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
TEXTMSG_INDEX = get_message_index('TextMsg')
SAYTEXT2_INDEX = get_message_index('SayText2')

if PLATFORM == "windows":
    SEND_USER_MESSAGE_INDEX = 45
else:
    SEND_USER_MESSAGE_INDEX = 45

send_user_message = get_object_pointer(engine_server).make_virtual_function(
    SEND_USER_MESSAGE_INDEX, Convention.THISCALL,
    [DataType.POINTER, DataType.POINTER, DataType.INT, DataType.POINTER],
    DataType.VOID)


def get_replacements(path):
    replacements = {}
    with open(path, 'rb') as f:
        for mapping in f.read().decode('utf-8').split('\n'):
            replace_what, replace_to = mapping.split(':')
            replacements[replace_what] = replace_to

    return replacements


replace_domains = get_replacements(REPLACE_DOMAIN_RES_PATH)
replace_ips = get_replacements(REPLACE_IP_RES_PATH)
Example #27
0
 def base_client(self):
     """Return the player's :class:`players.BaseClient` object."""
     return memory.make_object(BaseClient, memory.get_object_pointer(self.client) - 4)