AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   CollisionHook (https://forums.alliedmods.net/showthread.php?t=197815)

VoiDeD 10-07-2012 20:18

CollisionHook
 
HEY READ THIS (MARCH 2024)
The notice below still holds. I don't personally use this extension, but contributions on GitHub are welcome.


HEY READ THIS (DEC 2014)
I know you probably really want to use this extension, but here's the fine print: it's now completely unsupported by myself. If you need gamedata updates you're on your own. This extension should be a last resort when you have exhausted all other options for managing collisions: m_nSolidType, m_CollisionGroup, etc

This extension provides a straightforward and easy way to hook and modify collision rules between entities.

You might say "but sdkhooks provides this functionality already!", and you would be partly right. However, I wasn't happy with how sdkhooks ShouldCollide works, and here's why:

If you're familiar with sdkhooks, this code won't be new:
PHP Code:

// somewhere in your code
SDKHooksomeEntitySDKHook_ShouldCollideShouldCollide );

public 
bool:ShouldCollideentitycollisiongroupcontentsmaskbool:result )
{
    
// modify collision rules


As you can see, the hook doesn't provide much information about exactly which entities are colliding; only the collision group and contents mask of the other entity are given to the plugin developer.


To solve this limitation, I wrote CollisionHook.

CollisionHook provides 2 forwards to plugins, both of which can modify the collision rules of certain types of collisions.

PHP Code:

forward Action:CH_ShouldCollideent1ent2, &bool:result ); 

CH_ShouldCollide is called when vphysics is determining whether two vphysics objects (and their associated entities) should collide. Examples of these kinds of collisions include projectiles colliding with the world entity.

PHP Code:

forward Action:CH_PassFilterent1ent2, &bool:result ); 

CH_PassFilter is called when the game is performing a ray/hull trace and is making use of an entity filter. Examples of these kinds of collisions include player-player collisions.

To modify the behavior of the collision check, simply set result to true if you wish for the entities to collide; otherwise false, and return Plugin_Handled or Plugin_Stop in the forward. If you want the game to use default collision rules, simply return Plugin_Continue in the forward.


The benefits of both of these forwards is that you can strictly control which entities can collide, instead of just a specific type of entity.

Installation
  1. Grab the latest release from here.
  2. Drag & Drop.

Source
The source code is available here.


Limitations / Known Issues / Notes
  • Some collisions are not handled by this extension, those include collisions that are checked with traces that don't use an entity filter. Many of these can be handled by sdkhooks' Touch hook.
  • Modifying collisions that are also performed on the client will lead to prediction errors. This is no different from other server-only methods of overriding collisions.
  • This extension should work for any OB-based mod (TF2 CS:S, DoD:S), but it's only been tested on TF2.

Thanks
  • AzuiSleet, for suggesting PassServerEntityFilter for trace based collisions.
  • psychonic, for providing the linux build, makefile, and generally being the most helpful person on the planet.

GoD-Tony 10-08-2012 05:04

Re: CollisionHook
 
This is a neat idea! I tried something like this myself a while ago and ran into a few issues with a PassServerEntityFilter detour.

Using this code for example:
PHP Code:

public Action:CH_PassFilterent1ent2, &bool:result )
{
    
// No client-client collisions
    
if (<= ent1 <= MaxClients && <= ent2 <= MaxClients)
    {
        
result false;
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;


This is all on CS:S, and the code above seems to crash when shooting a player.

Normally it would prevent trace weapons from hitting any player target, because the player firing is passed as pPass. So in order to differentiate player collision traces from the rest, I detoured CTraceFilterSimple::ShouldHitEntity instead which provided collisionGroup and contentsMask.

Mine ended up looking like this:
(unreleased because I thought it was an ugly workaround)
Code:

DETOUR_DECL_MEMBER2(ShouldHitEntity, bool, IHandleEntity *, pHandleEntity, int, contentsMask)
{
        IHandleEntity *m_pPassEnt = *(IHandleEntity **)((intptr_t)this + g_iPassEntOffs);
        int m_collisionGroup = *(int *)((intptr_t)this + g_iCollisionOffs);

        cell_t result = DETOUR_MEMBER_CALL(ShouldHitEntity)(pHandleEntity, contentsMask);

        if (!pHandleEntity || !m_pPassEnt || pHandleEntity == m_pPassEnt)
                return (result != 0);

        cell_t touchEnt = gamehelpers->EntityToBCompatRef((CBaseEntity *)pHandleEntity);
        cell_t passEnt = gamehelpers->EntityToBCompatRef((CBaseEntity *)m_pPassEnt);

        g_pOnShouldCollide->PushCell(touchEnt);
        g_pOnShouldCollide->PushCell(passEnt);
        g_pOnShouldCollide->PushCell(m_collisionGroup);
        g_pOnShouldCollide->PushCell(contentsMask);
        g_pOnShouldCollide->PushCellByRef(&result);
        g_pOnShouldCollide->Execute(NULL);

        return (result != 0);
}

Then in the plugin if you only wanted to work with player collisions, you could check if contentsMask == MASK_PLAYERSOLID.

VoiDeD 10-08-2012 13:12

Re: CollisionHook
 
Quote:

Originally Posted by GoD-Tony (Post 1814680)
Using this code for example:
PHP Code:

public Action:CH_PassFilterent1ent2, &bool:result )
{
    
// No client-client collisions
    
if (<= ent1 <= MaxClients && <= ent2 <= MaxClients)
    {
        
result false;
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;


This is all on CS:S, and the code above seems to crash when shooting a player.

Interesting, in TF2 that code works as expected. The original purpose of the extension was to support a plugin I'm working on that controls precise player-player collision.

I haven't tested CS:S so I'm not sure why that would crash, but I'll check it out and see if anything can be salvaged.

Quote:

Originally Posted by GoD-Tony (Post 1814680)
Normally it would prevent trace weapons from hitting any player target, because the player firing is passed as pPass. So in order to differentiate player collision traces from the rest, I detoured CTraceFilterSimple::ShouldHitEntity instead which provided collisionGroup and contentsMask.

Mine ended up looking like this:
(unreleased because I thought it was an ugly workaround)
Code:

DETOUR_DECL_MEMBER2(ShouldHitEntity, bool, IHandleEntity *, pHandleEntity, int, contentsMask)
{
        IHandleEntity *m_pPassEnt = *(IHandleEntity **)((intptr_t)this + g_iPassEntOffs);
        int m_collisionGroup = *(int *)((intptr_t)this + g_iCollisionOffs);

        cell_t result = DETOUR_MEMBER_CALL(ShouldHitEntity)(pHandleEntity, contentsMask);

        if (!pHandleEntity || !m_pPassEnt || pHandleEntity == m_pPassEnt)
                return (result != 0);

        cell_t touchEnt = gamehelpers->EntityToBCompatRef((CBaseEntity *)pHandleEntity);
        cell_t passEnt = gamehelpers->EntityToBCompatRef((CBaseEntity *)m_pPassEnt);

        g_pOnShouldCollide->PushCell(touchEnt);
        g_pOnShouldCollide->PushCell(passEnt);
        g_pOnShouldCollide->PushCell(m_collisionGroup);
        g_pOnShouldCollide->PushCell(contentsMask);
        g_pOnShouldCollide->PushCellByRef(&result);
        g_pOnShouldCollide->Execute(NULL);

        return (result != 0);
}

Then in the plugin if you only wanted to work with player collisions, you could check if contentsMask == MASK_PLAYERSOLID.

That's a pretty good idea! I may rework the extension hook that function instead, as the extra info during collision checking would definitely be useful. Hooking that function also has the added benefit of handling any checks done in StandardFilterRules as well.

Also I'd make the assumption that most mods won't be touching CTraceFilterSimple, so the offsets to the members would likely be safe to get at.

GoD-Tony 10-10-2012 03:55

Re: CollisionHook
 
Quote:

Originally Posted by VoiDeD (Post 1814901)
Also I'd make the assumption that most mods won't be touching CTraceFilterSimple, so the offsets to the members would likely be safe to get at.

Yea that's true. I can't remember the exact reason for doing that but it probably wasn't important.

I haven't had a chance to play around with the vphysics stuff yet but it looks pretty cool too!

VoiDeD 11-20-2012 20:25

Re: CollisionHook
 
psychonic has been kind enough to update the extension for the linux changes that broke things a while back. You can get it here.

shavit 11-21-2012 10:20

Re: CollisionHook
 
Wanted to make a new plugin.
No success :(
PHP Code:

L 11/21/2012 17:18:23SourceMod error session started
L 11
/21/2012 17:18:23Info (map "bhop_arcane_v1") (file "errors_20121121.log")
L 11/21/2012 17:18:23: [CLHOOKCould not locate PassServerEntityFilter Disabling detour
L 11
/21/2012 17:18:23: [SMUnable to load extension "collisionhook.ext"Unable to hook PassServerEntityFilter!
L 11/21/2012 17:18:23: [SMUnable to load plugin "noblock.smx"Required extension "CollisionHook" file("collisionhook.ext"not running 

CS:S Windows 7 server.
SM 1.4.7 & MM:S 1.9.0.

VoiDeD 11-21-2012 13:08

Re: CollisionHook
 
Quote:

Originally Posted by shavit (Post 1841340)
Wanted to make a new plugin.
No success :(
PHP Code:

L 11/21/2012 17:18:23SourceMod error session started
L 11
/21/2012 17:18:23Info (map "bhop_arcane_v1") (file "errors_20121121.log")
L 11/21/2012 17:18:23: [CLHOOKCould not locate PassServerEntityFilter Disabling detour
L 11
/21/2012 17:18:23: [SMUnable to load extension "collisionhook.ext"Unable to hook PassServerEntityFilter!
L 11/21/2012 17:18:23: [SMUnable to load plugin "noblock.smx"Required extension "CollisionHook" file("collisionhook.ext"not running 

CS:S Windows 7 server.
SM 1.4.7 & MM:S 1.9.0.

Whoops! I made a small error in the gamedata file. If you edit it and change "tf" to "#default", it'll work for CS:S.

That being said, I haven't yet investigated the CS:S crashes mentioned in the previous posts. As this extension was originally designed for TF2, your mileage may vary.

shavit 11-23-2012 06:00

Re: CollisionHook
 
Quote:

Originally Posted by VoiDeD (Post 1841419)
Whoops! I made a small error in the gamedata file. If you edit it and change "tf" to "#default", it'll work for CS:S.

That being said, I haven't yet investigated the CS:S crashes mentioned in the previous posts. As this extension was originally designed for TF2, your mileage may vary.

PHP Code:

"Games"
{
    
"#default"
    
{
        
"Signatures"
        
{
            
"PassServerEntityFilter"
            
{
                
"library"    "server"
                
                "windows"    "\x55\x8b\xec\x57\x8b\x7d\x0c\x85\xff\x75\x2a\xb0\x01\x5f\x5d\xc3\x56\x8b\x75"
                "linux"        "@_Z22PassServerEntityFilterPK13IHandleEntityS1_"
            
}
        }
    }


Crashes my server.
I'll try to find the correct signature.

Trotim 03-05-2013 09:54

Re: CollisionHook
 
Does this still work? Or is there a better way to do this by now?

Peace-Maker 03-06-2013 18:26

Re: CollisionHook
 
It works perfectly fine! There is no other way to do what this does.

shavit 03-13-2013 10:42

Re: CollisionHook
 
Quote:

Originally Posted by Peace-Maker (Post 1908002)
It works perfectly fine! There is no other way to do what this does.

In CS:S?

VoiDeD 03-13-2013 18:50

Re: CollisionHook
 
Quote:

Originally Posted by shavit (Post 1911937)
In CS:S?

Should be working fine in CS:S when compiled from tip.

Despirator 03-14-2013 00:26

Re: CollisionHook
 
but still crashing

VoiDeD 03-14-2013 13:29

Re: CollisionHook
 
Are you compiling from source?

Mirandor 03-14-2013 13:51

Re: CollisionHook
 
Works on cs:s but get random crashs...

Code:

#include <sourcemod>
#include <collisionhook>


#define VERSION "1.0"

#pragma semicolon 1

public Plugin:myinfo =
{
    name = "NoCollide using CollisionHook (with Team Filter)",
    author = "",
    description = "Players dont collide with team-mates.",
    version = VERSION,
    url = ""
};

public OnPluginStart()
{
    CreateConVar( "sm_nocollideteam_version", VERSION, "Version of NoCollide Team Filter", FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY );
}

public Action:CH_PassFilter( ent1, ent2, &bool:result)
{
    if ( IsValidClient( ent1 ) && IsValidClient( ent2 ) )
        {
        if( GetClientTeam( ent1 ) != GetClientTeam( ent2 ) )
        {
            result = true;
            return Plugin_Handled;
        }
        result = false;
        return Plugin_Handled;
    }
    return Plugin_Continue;
}

stock bool:IsValidClient( client )
{
    if ( 0 < client <= MaxClients && IsClientInGame(client) )
        return true;
   
    return false;
}

SM 1.5dev MM1.10.0dev - linux

minimoney1 03-14-2013 18:56

Re: CollisionHook
 
Quote:

Originally Posted by Mirandor (Post 1912617)
Works on cs:s but get random crashs...

Code:

#include <sourcemod>
#include <collisionhook>


#define VERSION "1.0"

#pragma semicolon 1

public Plugin:myinfo =
{
    name = "NoCollide using CollisionHook (with Team Filter)",
    author = "",
    description = "Players dont collide with team-mates.",
    version = VERSION,
    url = ""
};

public OnPluginStart()
{
    CreateConVar( "sm_nocollideteam_version", VERSION, "Version of NoCollide Team Filter", FCVAR_PLUGIN | FCVAR_REPLICATED | FCVAR_NOTIFY );
}

public Action:CH_PassFilter( ent1, ent2, &bool:result)
{
    if ( IsValidClient( ent1 ) && IsValidClient( ent2 ) )
        {
        if( GetClientTeam( ent1 ) != GetClientTeam( ent2 ) )
        {
            result = true;
            return Plugin_Handled;
        }
        result = false;
        return Plugin_Handled;
    }
    return Plugin_Continue;
}

stock bool:IsValidClient( client )
{
    if ( 0 < client <= MaxClients && IsClientInGame(client) )
        return true;
   
    return false;
}

SM 1.5dev MM1.10.0dev - linux

Quote:

Are you compiling from source?

VoiDeD 03-15-2013 00:54

Re: CollisionHook
 
As is probably evident by now, you need to build from source if you want a working version in CS:S. The latest version on the downloads page (0.1) has a crash issue.

I'd build it myself and upload it, but I've been swamped with class work.

Mirandor 03-15-2013 03:35

Re: CollisionHook
 
I use the version available on the download page ; i'll try to compile from source...

Despirator 03-15-2013 03:48

Re: CollisionHook
 
Quote:

Originally Posted by VoiDeD (Post 1912910)
As is probably evident by now, you need to build from source if you want a working version in CS:S. The latest version on the downloads page (0.1) has a crash issue.

I'd build it myself and upload it, but I've been swamped with class work.

oh, didn't know that sorry... getting source to test

Mirandor 03-15-2013 06:08

Re: CollisionHook
 
Quote:

Originally Posted by Despirator (Post 1912953)
oh, didn't know that sorry... getting source to test

Unfortunatly i won't be able to compile it at this time ; if you make it for linux, may you share it please?

Despirator 03-15-2013 09:58

Re: CollisionHook
 
Quote:

Originally Posted by Mirandor (Post 1912991)
Unfortunatly i won't be able to compile it at this time ; if you make it for linux, may you share it please?

no, for windows. But failed to compile beacuse it couldn't find IExtensionSys.h... though i have right environment variables

VoiDeD 03-15-2013 21:46

Re: CollisionHook
 
I've uploaded built versions of 0.2. You can grab it off the downloads page.

Thanks to KyleS for the linux build.

Mirandor 03-16-2013 07:51

Re: CollisionHook
 
Working and doesn't seem to crash anymore...

Good job!

shavit 03-16-2013 12:55

Re: CollisionHook
 
Good job at fixing crashing!

Noblock isn't smooth like I thought it going to be.

Despirator 03-16-2013 16:29

Re: CollisionHook
 
Quote:

Originally Posted by shavit (Post 1913861)
Good job at fixing crashing!

Noblock isn't smooth like I thought it going to be.

hook m_iCollisionGroup with sendproxy and set the value to 2 in the callback

shavit 03-16-2013 17:08

Re: CollisionHook
 
Quote:

Originally Posted by Despirator (Post 1914009)
hook m_iCollisionGroup with sendproxy and set the value to 2 in the callback

Wouldn't be the best because I need it for Trikz partner system and in Trikz, players can toggle noblock on themselves by changing m_iCollisionGroup to 2/5.

Newbie1992 01-12-2014 14:01

Re: CollisionHook
 
Does this work fine without crash?

I need a function like that to prevent a stuck problem on my saxton hale server.

Thanks!

VoiDeD 01-12-2014 19:42

Re: CollisionHook
 
Quote:

Originally Posted by Newbie1992 (Post 2085034)
Does this work fine without crash?

I need a function like that to prevent a stuck problem on my saxton hale server.

Thanks!

I don't really support this extension anymore. It was created for a niche purpose that I personally don't use anymore, and the problem of correctly hooking collisions isn't perfectly (and can't easily be) addressed by this extension.

In your case, you can likely solve your problem in a more ideal way: collision groups, solid type, etc.

Marcos 05-17-2014 04:44

Re: CollisionHook
 
It's broken.
Code:

L 05/17/2014 - 16:40:07: [CLHOOK] Sigscan for PassServerEntityFilter failed - Disabling detour to prevent crashes

shavit 06-27-2014 13:52

Re: CollisionHook
 
Code:

L 06/27/2014 - 20:52:03: SourceMod error session started
L 06/27/2014 - 20:52:03: Info (map "trikz_advanced") (file "errors_20140627.log")
L 06/27/2014 - 20:52:03: [CLHOOK] Sigscan for PassServerEntityFilter failed - Disabling detour to prevent crashes
L 06/27/2014 - 20:52:03: [SM] Unable to load extension "collisionhook.ext": Unable to hook PassServerEntityFilter!

help plox

Neuro Toxin 07-04-2014 23:47

Re: CollisionHook
 
Hey,

I get the following error on CS:GO.

[SM] Extension collisionhook.ext.dll failed to load: The specified procedure could not be found.

Is this an outdated gamedata file issue?

TheLaser 10-09-2014 17:42

Re: CollisionHook
 
Wow what a bummer ,

This was a useful ext.. yet this doesnt surprise me anymore , seems like support for many useful plugins is on the down swing these days and you can wait weeks to years to get a reply and there are many good coders out there who could but just dont want to take the time :cry:

Really sad

skResolver 10-10-2014 17:24

Re: CollisionHook
 
Thank you! I hope it's working!

TheLaser 10-11-2014 07:16

Re: CollisionHook
 
skResolver,

Well you can hope but no its not working anymore unless some one fixed it and didnt release it to anyone it no longer works ... I was using this for a good noblock someone made .

TheLaser 10-21-2014 08:28

Re: CollisionHook
 
Does anyone have this working with new signatures ?
I even tried to PM VoiDeD with no answer so I take it this is a dead extension .
I really need a working noblock for our servers and not one of them work , tested them all and no deal :down:

Neuro Toxin 10-21-2014 18:31

Re: CollisionHook
 
https://forums.alliedmods.net/showthread.php?p=462813

I ended up using this. Works as expected for csgo

TheLaser 10-21-2014 19:30

Re: CollisionHook
 
Thank you Neuro Toxin for trying to help but this one does cause the mayhem bug in HL2dm..
and once it does you have to restart the server to get rid of it .
Only Voided's hook ext will do it correctly . also sendproxy works but you cant team it and the bots will run into you attacking while inside you making it hard to kill them .

Neuro Toxin 10-22-2014 04:27

Re: CollisionHook
 
:(

TheLaser 10-26-2014 08:44

Re: CollisionHook
 
Well since not enough users have a need for this I dont think we will ever see this ext updated ...
I was hoping someone who had experience in either recompile or signatures would have been nice enough to fix it but nothing :cry:

TheLaser 11-04-2014 17:18

Re: CollisionHook
 
Still Hoping ,

All things are possible .
Maybe one day some one will be kind enough to repair this and some other great plugins that have been killed off or damaged thanks to Valve :crab:


All times are GMT -4. The time now is 20:41.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.