Skip to content

Conversation

@CookStar
Copy link
Contributor

@CookStar CookStar commented Aug 25, 2021

This makes it possible to use chat format with SayText and send messages to the console without whitespace at the beginning.

#   Commands
from commands import CommandReturn
from commands.say import SayFilter
#   Core
from core import PLATFORM
#   Engines
from engines.gamerules import find_game_rules
#   Memory
from memory import Convention
from memory import DataType
from memory import find_binary
from memory.hooks import HookType
#   Messages
from messages import SayText2
#   Players
from players.entity import Player


server = find_binary("server", srv_check=False)

# CS:GO
if PLATFORM == "linux":
    signature = b"\x55\x89\xE5\x83\xEC\x18\x89\x5D\xF8\x8B\x5D\x10\x89\x75\xFC\x0F\xB6\x45\x0C"
else:
    signature = b"\x55\x8B\xEC\x53\x57\x8B\x7D\x0C\x8B\xD9\x85\xFF\x75\x2A\x5F"

# char const * CCSGameRules::GetChatFormat( bool bTeamOnly, CBasePlayer * pPlayer )
get_chat_format = server[signature].make_function(
    Convention.THISCALL, (
        DataType.POINTER,
        DataType.BOOL,
        DataType.POINTER,
    ),
    DataType.STRING,
)


@SayFilter
def on_say(command, index, team_only):
    player = Player(index)
    chat_format = get_chat_format(find_game_rules(), team_only, player)
    string = command.command_string
    SayText2(chat_format, index=index, chat=True, param1=player.name, param2=string).send() # Old
    SayText2(chat_format, index=index, chat=True, param1=player.name, param2=string, color="").send() # New
    SayText2(string, index=index, chat=True, color=('\u200b'+'\x01')).send() # New
    return CommandReturn.BLOCK

saytextcolor

@jordanbriere jordanbriere merged commit a2babee into Source-Python-Dev-Team:master Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants