Code that works in tf2 fails in tf2c mod.

Please post any questions about developing your plugin here. Please use the search function before posting!
hubertolszewski
Junior Member
Posts: 2
Joined: Fri Oct 02, 2020 10:29 am

Code that works in tf2 fails in tf2c mod.

Postby hubertolszewski » Fri Oct 02, 2020 10:39 am

I know sourcemod has a unofficial gamedata release to make it work with tf2classic but I prefer source.python
I'm trying to hook things such as entity creation and player run_command but they don't work at all. Nothing is output in console no matter what.

Example of code that works in tf2 but not tf2c (mod)

Code: Select all

from listeners import OnPlayerRunCommand

def IsPlayerBot(Obj):
    if Obj.is_bot == True:
        return True
    elif Obj.playerinfo.is_fake_client():
        return True
    else:
        return False

# This will never run #
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
    print("hook")
    if (IsPlayerBot(player)):
        user_cmd.forward_move = 0
        user_cmd.side_move = 0
    pass


Strangely though on_tick and on_player_say work fine. Right now I can work with that but its very limiting.
Does someone more experienced know what is happening and why it doesn't work?
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Code that works in tf2 fails in tf2c mod.

Postby VinciT » Sat Oct 03, 2020 4:21 am

The offsets for the PlayerRunCommand virtual function are different between TF2 and TF2C, which is why the listener never fires. The same can be said about the gEntList/CGlobalEntityList - which I assume is responsible for entity creation (TF2 vs TF2C).

I don't know how hard or time consuming it would be to add native TF2C support to SP. Hopefully someone else can shed some light on that. In the meantime, you'll have to use these TF2C offsets/signatures and manually hook into functions you'd like to use.
ImageImageImageImageImage
hubertolszewski
Junior Member
Posts: 2
Joined: Fri Oct 02, 2020 10:29 am

Re: Code that works in tf2 fails in tf2c mod.

Postby hubertolszewski » Tue Oct 06, 2020 3:42 am

Ah I see. Appreciate the response can someone here give a simple example of calling a function via signature?
I've used the forum search and I can only find examples of hooking functions with the signature but not calling them.
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Code that works in tf2 fails in tf2c mod.

Postby VinciT » Thu Oct 08, 2020 2:23 pm

There's a tutorial for calling virtual functions on the wiki.
And here's a quick example of calling a function hooked with a signature (made for HL2DM):

Syntax: Select all

# ../util_fadeall/util_fadeall.py

# Source.Python
from colors import Color
from commands.client import ClientCommand
from core import PLATFORM
from memory import Convention, DataType, find_binary


server_binary = find_binary('server')


if PLATFORM == 'windows':
identifier_screen = b'\x55\x8B\xEC\xD9\x45\x10\x8D\x45\xF4'
else:
identifier_screen = '_Z18UTIL_ScreenFadeAllRK9color32_sffi'


UTIL_ScreenFadeAll = server_binary[identifier_screen].make_function(
Convention.CDECL,
(DataType.POINTER, DataType.FLOAT, DataType.FLOAT, DataType.INT),
DataType.VOID
)


@ClientCommand('flash_everyone')
def flash_everyone(command, index):
"""Emulates a global flashbang."""
# More info about the function: https://git.io/JJXoe
# Arguments: color, fade time, fade hold, flags
UTIL_ScreenFadeAll(Color(255, 255, 255, 255), 5, 1, 1)

I've also included some data for TF2 Classic in the attachment below. Simply extract it inside your server's root folder (../sdk2013server/tf2classic/) and you should be good to go. This should fix your issues with entity creation and the OnPlayerRunCommand listener.

tf2classic_data.zip
(5.18 KiB) Downloaded 237 times
ImageImageImageImageImage

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 29 guests