Page 1 of 1
[TF2] Hooking Server Log
Posted: Fri Jun 26, 2020 6:29 am
by Zeus
Basically I need the SP equivalent of this:
https://sm.alliedmods.net/new-api/loggi ... ameLogHookThis allows me to take the log output from the server console (via the log cvar) and pipe it into a file which I will later need to upload somewhere when the match ends.
Example log line:
Code: Select all
L 06/26/2020 - 06:11:13: "Moon<2><[U:1:80225322]><Blue>" triggered "shot_fired" (weapon "scattergun")
Capturing all server output would prob have a notable performance penalty and is unnecessary if I can just hook the game log.
Anyway I have no idea ahow to do this; I was unable to find anything on the wiki / source code for it
Re: [TF2] Hooking Server Log
Posted: Fri Jun 26, 2020 9:04 am
by Ayuto
If you want to to hook the complete server output, you can use the OnServerOutput listener:
http://wiki.sourcepython.com/developing ... rveroutputIf you want to get the server output at a specific time (e. g. when executing a command), you can use context manager server_output:
http://wiki.sourcepython.com/developing ... ver_outputIf you want to hook the LogPrint function (that's what SM does), you can use this little snippet:
Syntax: Select all
from memory import get_virtual_function
from memory.hooks import PreHook
from engines.server import engine_server
@PreHook(get_virtual_function(engine_server, 'LogPrint'))
def pre_log_print(args):
print(args)
# Just to test the hook
from commands.typed import TypedServerCommand
@TypedServerCommand('logsp')
def on_logsp(info, message):
engine_server.log_print(message)
Output:
Code: Select all
sp plugin load test1
[SP] Loading plugin 'test1'...
Hooking function: type=PRE, addr=2076087872, conv=THISCALL, args=(_memory.DataType.POINTER, _memory.DataType.STRING), rtype=VOID, callback=<function pre_log_print at 0x1ACB5A08>
(<_memory.Pointer object at 0x1ACAFB60>, "- sp.core.command\t-\tMESSAGE\n\t[SP] Successfully loaded plugin 'test1'.\n")
[SP] Successfully loaded plugin 'test1'.
logsp "Hello, world!"
(<_memory.Pointer object at 0x1ACAFB60>, 'Hello, world!')
Re: [TF2] Hooking Server Log
Posted: Fri Jun 26, 2020 7:09 pm
by Zeus
Ayuto wrote:If you want to to hook the complete server output, you can use the OnServerOutput listener:
http://wiki.sourcepython.com/developing ... rveroutputIf you want to get the server output at a specific time (e. g. when executing a command), you can use context manager server_output:
http://wiki.sourcepython.com/developing ... ver_outputIf you want to hook the LogPrint function (that's what SM does), you can use this little snippet:
Syntax: Select all
from memory import get_virtual_function
from memory.hooks import PreHook
from engines.server import engine_server
@PreHook(get_virtual_function(engine_server, 'LogPrint'))
def pre_log_print(args):
print(args)
# Just to test the hook
from commands.typed import TypedServerCommand
@TypedServerCommand('logsp')
def on_logsp(info, message):
engine_server.log_print(message)
Output:
Code: Select all
sp plugin load test1
[SP] Loading plugin 'test1'...
Hooking function: type=PRE, addr=2076087872, conv=THISCALL, args=(_memory.DataType.POINTER, _memory.DataType.STRING), rtype=VOID, callback=<function pre_log_print at 0x1ACB5A08>
(<_memory.Pointer object at 0x1ACAFB60>, "- sp.core.command\t-\tMESSAGE\n\t[SP] Successfully loaded plugin 'test1'.\n")
[SP] Successfully loaded plugin 'test1'.
logsp "Hello, world!"
(<_memory.Pointer object at 0x1ACAFB60>, 'Hello, world!')
Awesome, ill give this a shot!
Is there a place I can find all of these available virtual functions to hook? Might be useful to put that up as a reference on the wiki
Re: [TF2] Hooking Server Log
Posted: Fri Jun 26, 2020 9:36 pm
by L'In20Cible
Zeus wrote:Is there a place I can find all of these available virtual functions to hook? Might be useful to put that up as a reference on the wiki
You can find them all by searching for
FUNCTION_INFO on the repo.
Re: [TF2] Hooking Server Log
Posted: Fri Jun 26, 2020 10:05 pm
by Ayuto
Or simply type "sp dump class_info class_info".
Re: [TF2] Hooking Server Log
Posted: Sat Jun 27, 2020 5:18 am
by Zeus
This works! Thanks for all the help guys!