Ejemplo n.º 1
0
    def __init__(self, user_message):
        """Create a new user message hook.

        :param int/str user_message:
            The user message index or name to hook.
        :raise TypeError:
            Raised if ``user_message`` is not and int or str.
        :raise ValueError:
            Raised if the user message does not exist.
        """
        if isinstance(user_message, int):
            index = user_message
        elif isinstance(user_message, str):
            index = get_message_index(user_message)
        else:
            raise TypeError(
                'Invalid type for "user_message". int or str required.')

        self.message_index = index
        self.message_name = get_message_name(index)
        self.callback = None

        # Verify that it's a valid index
        if self.message_name is None:
            raise ValueError(f'Invalid user message: {user_message}')
Ejemplo n.º 2
0
    def __init__(self, user_message):
        """Create a new user message hook.

        :param int/str user_message:
            The user message index or name to hook.
        :raise TypeError:
            Raised if ``user_message`` is not and int or str.
        :raise ValueError:
            Raised if the user message does not exist.
        """
        if isinstance(user_message, int):
            index = user_message
        elif isinstance(user_message, str):
            index = get_message_index(user_message)
        else:
            raise TypeError(
                'Invalid type for "user_message". int or str required.')

        self.message_index = index
        self.message_name = get_message_name(index)
        self.callback = None

        # Verify that it's a valid index
        if self.message_name is None:
            raise ValueError(f'Invalid user message: {user_message}')
Ejemplo n.º 3
0
    def send(self, userid):
        msg_index = get_message_index(self.name)
        if msg_index == -1:
            import es
            dbgmsg(0, 'Invalid UserMessage type: {}'.format(self.name))
            return

        try:
            index = index_from_userid(atoi(userid))
        except ValueError:
            return

        # We need to save the RecipientFilter instance here. Otherwise it would
        # get garbage collected before it is send.
        recipients = RecipientFilter(index)
        user_message = UserMessage(recipients, self.name)
        buffer = user_message.buffer

        for type_name, value in self:
            self._write(buffer, type_name, value)

        user_message.send()
Ejemplo n.º 4
0
    def send(self, userid):
        msg_index = get_message_index(self.name)
        if msg_index == -1:
            import es
            dbgmsg(0, 'Invalid UserMessage type: {}'.format(self.name))
            return

        try:
            index = index_from_userid(atoi(userid))
        except ValueError:
            return

        # We need to save the RecipientFilter instance here. Otherwise it would
        # get garbage collected before it is send.
        recipients = RecipientFilter(index)
        user_message = UserMessage(recipients, self.name)
        buffer = user_message.buffer

        for type_name, value in self:
            self._write(buffer, type_name, value)

        user_message.send()
Ejemplo n.º 5
0
from filters.recipients import RecipientFilter
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:
Ejemplo n.º 6
0
    @staticmethod
    def write_bitbuffer(buffer, data):
        buffer.write_string(data.name)
        buffer.write_byte(data.show)
        buffer.write_byte(len(data.subkeys))
        for key, value in data.subkeys.items():
            buffer.write_string(key)
            buffer.write_string(value)


# =============================================================================
# >> FUNCTIONS
# =============================================================================
#: A dictionary that contains all implemented user messages.
implemented_usermessages = {
    get_message_index('SayText2'): SayText2Impl,
    get_message_index('VGUIMenu'): VGUIMenuImpl,
}

def get_user_message_impl(msg_index):
    """Return the user message implementation for the given message index.

    :param int msg_index:
        The index of the user message.
    :raise NotImplementedError:
        Raised if the given user message is not implemented.
    :rtype: UserMessageImpl
    """
    try:
        return implemented_usermessages[msg_index]
    except KeyError:
Ejemplo n.º 7
0
    @staticmethod
    def write_bitbuffer(buffer, data):
        buffer.write_string(data.name)
        buffer.write_byte(data.show)
        buffer.write_byte(len(data.subkeys))
        for key, value in data.subkeys.items():
            buffer.write_string(key)
            buffer.write_string(value)


# =============================================================================
# >> FUNCTIONS
# =============================================================================
#: A dictionary that contains all implemented user messages.
implemented_usermessages = {
    get_message_index('SayText2'): SayText2Impl,
    get_message_index('ShowMenu'): ShowMenuImpl,
    get_message_index('VGUIMenu'): VGUIMenuImpl
}


def get_user_message_impl(msg_index):
    """Return the user message implementation for the given message index.

    :param int msg_index:
        The index of the user message.
    :raise NotImplementedError:
        Raised if the given user message is not implemented.
    :rtype: UserMessageImpl
    """
    try:
Ejemplo n.º 8
0
from memory import Convention, DataType, get_object_pointer, make_object
from memory.hooks import PreHook
from _messages import ProtobufMessage
from messages import get_message_index
from players.entity import Player

from .info import info
from .paths import ADPURGE_DATA_PATH
from .tlds import tlds

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 = {}