[CS:S] Return type not working for shouldcollide

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

[CS:S] Return type not working for shouldcollide

Postby Kami » Thu Jan 28, 2021 7:31 pm

Hey guys,

I'm trying to hook ShouldCollide with this code

Syntax: Select all

from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook
from memory import make_object
from memory import Convention
from memory import DataType

@EntityPreHook(
EntityCondition.is_player,
lambda player: player.make_virtual_function(
16,
Convention.THISCALL,
(DataType.POINTER, DataType.INT, DataType.INT),
DataType.BOOL
)
)
def pre_should_collide(args):
return False


1. The hook itself works as I can read the arguments (entity, collisiongroup and coliisionmask) but returning False does not work.
Edit: It seems to work now, not sure what changed. My other questions still apply :)

2. Is there a way to check for the colliding entity?

3. The "gliding" through is pretty rough, is there any ways to make it smoother? Sourcemod uses sendproxy which SourcePython seems to have too. Maybe you could explain to me how to use that.

Thanks!

Edit: The goal would be to have player specific block. e.g. Player1 only collides with Player3 but not Player4 and Player5.
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [CS:S] Return type not working for shouldcollide

Postby VinciT » Fri Jan 29, 2021 5:14 pm

Kami wrote:2. Is there a way to check for the colliding entity?
If you want to see which entities are colliding, you'll have to switch to PassServerEntityFilter():

Syntax: Select all

# ../player_collision/player_collision.py

# Source.Python
from core import PLATFORM
from memory import Convention, DataType, find_binary
from memory import DataType
from memory.hooks import PreHook
from entities.entity import Entity


server_binary = find_binary('server')


if PLATFORM == 'windows':
identifier = b'\x55\x8B\xEC\x56\x8B\x2A\x2A\x85\x2A\x75\x2A\xB0\x2A\x5E'
else:
identifier = '_Z22PassServerEntityFilterPK13IHandleEntityS1_'


# https://git.io/Jt8oF
PassServerEntityFilter = server_binary[identifier].make_function(
Convention.CDECL,
(DataType.POINTER, DataType.POINTER),
DataType.BOOL
)


@PreHook(PassServerEntityFilter)
def pass_server_entity_filter_pre(stack_data):
entity1 = Entity._obj(stack_data[0])
entity2 = Entity._obj(stack_data[1])
It works the same as ShouldCollide() - return False to prevent the collision.
ImageImageImageImageImage
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Return type not working for shouldcollide

Postby Kami » Fri Jan 29, 2021 9:57 pm

Thank you very much, this is exactly what I was looking for! I've seen this in a SourceMod plugin but I'm not that good with hooks yet so this is a huge help.

I'm still confused how I would use a SendProp (in my case "m_CollisionGroup") and the proxy function or even how to get it.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Return type not working for shouldcollide

Postby L'In20Cible » Fri Jan 29, 2021 10:57 pm

Kami wrote:I'm still confused how I would use a SendProp (in my case "m_CollisionGroup") and the proxy function or even how to get it.

Here's a quick and dirty example:

Syntax: Select all

from entities.entity import Entity
from entities.props import ServerClass
from memory import Convention
from memory import DataType
from memory import NULL
from memory import get_object_pointer
from memory.hooks import PreHook

for prop in ServerClass.find_server_class('CBaseEntity').table:
if prop.name != 'm_CollisionGroup':
continue
proxy_function = get_object_pointer(prop.proxy_function).make_function(
Convention.CDECL,
(DataType.POINTER, DataType.POINTER, DataType.POINTER,
DataType.POINTER, DataType.INT, DataType.INT
),
DataType.VOID
)
break
else:
raise Exception('Failed to find CBaseEntity.m_CollisionGroup.')

@PreHook(proxy_function)
def pre_proxy_function(stack_data):
if stack_data[0] != get_object_pointer(prop):
return

entity = Entity(stack_data[5])
if not entity.is_player():
return

stack_data[3] = NULL
return False

Though you are likely to crash your server unless you disable the parallelization. But it really just revert the issue; now clients will predict they can pass through players and bounce back if the server decides they should be colliding.
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Return type not working for shouldcollide

Postby Kami » Sat Jan 30, 2021 2:11 pm

Thank you for the example! Have to try if it works for my problem.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 20 guests