Partial fix for issue #390.#399
Conversation
|
Nice one! What do you mean by retrieving the data? |
|
Sorry for not being more clear. The following code should print the contents of a sent menu: from messages.hooks import HookProtobufUserMessage
@HookProtobufUserMessage('ShowMenu')
def show_menu_pre(recipients, buffer):
"""Called when a ShowMenu user message gets sent."""
print(buffer.get_string('menu_string'))It does with SP menus, but not with SM menus. |
Ah yeah. There are two possible causes;
That said, the ideal solution would be to simply have a static constructor (for example, like RecipientFilter.from_abstract that create a new message and make a copy of the fields using Message::CopyFrom -- either that or export those directly though more efficient through a one-call constructor. |
|
Yep, it's the size. As soon as I added a few bytes it started working properly: buffer_size = get_size(buffer) + 16Running this and opening the admin menu from SourceMod: @HookProtobufUserMessage('ShowMenu')
def show_menu_pre(recipients, buffer):
"""Called when a ShowMenu user message gets sent."""
print(buffer.get_int32('bits_valid_slots'))
print(buffer.get_int32('display_time'))
print(buffer.get_string('menu_string'))Prints this:
I'd love to do that, but I'm kinda out of my depth when it comes to stuff like this. 😅 |
|
Untested in a real scenario, but try this: core.dll Here's the basic test I ran: from _messages import ProtobufMessage
from messages import UserMessage
from filters.recipients import RecipientFilter
message = UserMessage(RecipientFilter(), 'ShowMenu')
buffer = message.buffer
buffer.set_string('menu_string', 'blah blah blah')
copy = ProtobufMessage.from_abstract_pointer(buffer)
assert buffer.debug_string == copy.debug_string |
|
Tried this (going by how it's done here) inside message/hooks.py: buffer = ProtobufMessage.from_abstract_pointer(args[3])And I got this: |
|
Hmm, that's weird. Updated the build above, what's the last number you get? |
|
Seems to be 3: |
|
Then that means |
|
It works perfectly! |
This fixes the hooks from not getting called when the UserMessage was created/sent by a third-party plugin (SourceMod), but I'm not sure how to retrieve the actual UserMessage data (e.g. ShowMenu data).