Raised This Month: $4 Target: $400
 1% 

[L4D2] Collision Hook


Post New Thread Reply   
 
Thread Tools Display Modes
cravenge
Veteran Member
Join Date: Nov 2015
Location: Middle of Nowhere
Old 10-16-2021 , 17:19   Re: [L4D2] Collision Hook
Reply With Quote #21

Quote:
Originally Posted by vikingo12 View Post
still crashes
Cuz the source code also needs to be changed. Adding the game data alone doesn't do anything.
__________________
cravenge is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Middle of Nowhere
Old 11-07-2021 , 14:17   Re: [L4D2] Collision Hook
Reply With Quote #22

I just did some more research and I happened to find something quite interesting.

Originally, from the SDK:
PHP Code:
bool PassServerEntityFilter( const IHandleEntity *pTouch, const IHandleEntity *pPass 
{
    if ( !
pPass )
        return 
true;

    if ( 
pTouch == pPass )
        return 
false;

    const 
CBaseEntity *pEntTouch EntityFromEntityHandlepTouch );
    const 
CBaseEntity *pEntPass EntityFromEntityHandlepPass );
    if ( !
pEntTouch || !pEntPass )
        return 
true;

    
// don't clip against own missiles
    
if ( pEntTouch->GetOwnerEntity() == pEntPass )
        return 
false;
    
    
// don't clip against owner
    
if ( pEntPass->GetOwnerEntity() == pEntTouch )
        return 
false;    


    return 
true;

By simply looking at this, it would seem that returning true will allow the entity from passing through the other. Otherwise, block it from happening.

Translating this into a plugin will result to:
PHP Code:
public MRESReturn PassServerEntityFilter(DHookReturn hReturnDHookParam hParams)
{
    
int pTouch hParams.Get(1);
    
int pPass hParams.Get(2);
    
    if (!
pPass)
    {
        
hReturn.Value false;
        return 
MRES_Supercede;
    }
    
    if (
pTouch != pPass)
    {
        
// From what I've gathered from Ghidra's decompiler, it would seem that either one of these
        // entity handle pointers can be null when passed as a parameter onto an SDKCall since the
        // result will always be true but only on Linux. Windows, however, does not allow this and
        // will most likely result in a crash.
        
if (IsStaticProp(pTouch) || IsStaticProp(pPass))
        {
            
// This should be false but let's just hope it will prevent entities from phasing through
            // walls and falling into an endless void then crashing the server after some time :p
            
hReturn.Value true;
            return 
MRES_Supercede;
        }
        
        
int pEntTouch GetBaseEntity(pTouch);
        
int pEntPass GetBaseEntity(pPass);
        
        if (
pEntTouch != -&& pEntPass != -1)
        {
            
// Windows: 0x20c -> 524
            // Linux: 0x220 -> 544
            // Both offsets point to "m_hOwnerEntity" property
            
if (GetEntPropEnt(pEntTouchProp_Data"m_hOwnerEntity") == pEntPass || GetEntPropEnt(pEntPassProp_Data"m_hOwnerEntity") == pEntTouch)
            {
                
hReturn.Value true;
                return 
MRES_Supercede;
            }
            
            
// ...
        
}
        else
        {
            
hReturn.Value false;
        }
    }
    else
    {
        
hReturn.Value true;
    }
    return 
MRES_Supercede;

After detouring the function, the logic is somehow inverted for some unknown reason. At least that's what I concluded from how I've seen plugins change the result through the forward.

It really was quite a head scratcher while analyzing this thoroughly. Of course, you can correct me if I made any mistakes. That would help me understand it better and ease the headache I got from this alone.
__________________

Last edited by cravenge; 11-07-2021 at 14:33.
cravenge is offline
BHaType
Great Tester of Whatever
Join Date: Jun 2018
Old 11-08-2021 , 21:24   Re: [L4D2] Collision Hook
Reply With Quote #23

Quote:
Originally Posted by cravenge View Post
I just did some more research and I happened to find something quite interesting.
Thanks for the info. I actually didn't much explore this function I just use it how it was intended in original SDK. If your detour doesn't have random crashes then its a good reason to unapprove my plugin since current way of detouring is kinda hackish.
__________________
cry
BHaType is offline
Send a message via AIM to BHaType
cravenge
Veteran Member
Join Date: Nov 2015
Location: Middle of Nowhere
Old 11-09-2021 , 03:26   Re: [L4D2] Collision Hook
Reply With Quote #24

Quote:
Originally Posted by BHaType View Post
Thanks for the info. I actually didn't much explore this function I just use it how it was intended in original SDK. If your detour doesn't have random crashes then its a good reason to unapprove my plugin since current way of detouring is kinda hackish.
Your current method is the only one able to detour the function without instantly crashing thw server so far. I was just confused about the logic of the return value being inverted for who-knows-what reason.
__________________
cravenge is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:44.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode