Skip to content

Add EntityCollisionRulesChanged & SetEntityOwner natives#1620

Merged
KyleSanderson merged 11 commits intoalliedmodders:masterfrom
Kenzzer:master
Nov 22, 2021
Merged

Add EntityCollisionRulesChanged & SetEntityOwner natives#1620
KyleSanderson merged 11 commits intoalliedmodders:masterfrom
Kenzzer:master

Conversation

@Kenzzer
Copy link
Member

@Kenzzer Kenzzer commented Oct 27, 2021

Introduction

#1507

Alright, in that case I'll open a PR in the next couple of days!

Famous last words... or not!

First I'd like to apologise for not having made this PR earlier.

What changed ?

SetCollisionGroup signature has been removed, this signature was used by sdktools to call CBaseEntity::SetCollisionGroup.

void CBaseEntity::SetCollisionGroup( int collisionGroup )
{
	if ( (int)m_CollisionGroup != collisionGroup )
	{
		m_CollisionGroup = collisionGroup;
		CollisionRulesChanged();
	}
}

The main point, was to call CBaseEntity::CollisionRulesChanged after setting the collision group.

So instead now we go through CBaseEntity::SetEntityOwner, a virtual function which should ideally provide easier maintenance of gamedata (if ever needed) and easier support accross all source games.

void CBaseEntity::SetOwnerEntity( CBaseEntity* pOwner )
{
	if ( m_hOwnerEntity.Get() != pOwner )
	{
		m_hOwnerEntity = pOwner;

		CollisionRulesChanged();
	}
}

Bypassing the if statement is trivial, as m_hOwnerEntity is both a datamap and netprop. With this little hack, we get an easy access to CBaseEntity::CollisionRulesChanged.

The native SetEntityCollisionGroup has been rewritten to mimic what CBaseEntity::SetCollisionGroup does.
Added EntityCollisionRulesChanged as native, since we have an access to it.
And finally added SetEntityOwner as native, because we have to maintain that vtable offset in order to keep the other two natives working.

Final note

As said in introduction, I have not tested anything yet and I'd be very grateful if anyone could test this on csgo, css and l4d.
I also want to mention, that the vtable offsets for CSGO and Left 4 Dead 1 were guessed, there's a chance they're invalid. If someone can provide or confirm them that'd be helpful too!

I'm planning on testing this for CSGO & TF2 this weekend.

@Kenzzer
Copy link
Member Author

Kenzzer commented Oct 27, 2021

@KyleSanderson tagging you (hope you don't mind), since you wanted to review this and I can't seem to be able to request reviews. Sorry for the 3 months delay!

@psychonic psychonic added Needs Testing untested by author Feature Request user requested feature labels Oct 27, 2021
@Wend4r
Copy link
Contributor

Wend4r commented Oct 27, 2021

I have a suggestion to add a GetEntityOwner() native by CBaseEntity::m_hOwnerEntity. Usually get it through netprop, but it would be more convenient to use the functionality of this PR

@KyleSanderson KyleSanderson self-requested a review November 1, 2021 23:02
Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were you able to test over the weekend? I'm really optimistic about this PR as it's going to help a lot of people.

// Returns false if CollisionRulesChanged hack isn't supported for this game
if (!CollisionRulesChanged(pEntity))
{
return pContext->ThrowNativeError("\"SetEntityCollisionGroup\" unsupported entity");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is not supported on this engine." ? Something like that - it shouldn't be the same message if it fails the datamap lookup.

@Kenzzer
Copy link
Member Author

Kenzzer commented Nov 2, 2021

were you able to test over the weekend?

Not yet, unfortunately time flew by without me noticing, I also need to come up with a good test plugin to ensure everything's fine. But I've built the ext for tf2 & csgo (linux) and setup my local server already, hopefully this shouldn't take much longer.

@KyleSanderson
Copy link
Member

were you able to test over the weekend?

Not yet, unfortunately time flew by without me noticing, I also need to come up with a good test plugin to ensure everything's fine. But I've built the ext for tf2 & csgo (linux) and setup my local server already, hopefully this shouldn't take much longer.

Damn. Let us know when this is closer (I think we're close, too).

@Kenzzer
Copy link
Member Author

Kenzzer commented Nov 17, 2021

The requested changes have been done, and the PR has been tested on TF2 both linux & windows.

Here's a test plugin for those interested to test this out on their own
(With the merge of dhooks, this works on stock SM)
collisionrules.txt
collisionrules.sp.txt

Here's the console output
unknown

I believe this time we're ready.

@KyleSanderson KyleSanderson merged commit b38c982 into alliedmodders:master Nov 22, 2021
@einyux
Copy link
Contributor

einyux commented Nov 22, 2021

Like often a little too late, but I think it would have been better to keep the real function name "SetOwnerEntity()" instead of "SetEntityOwner()" :).

@psychonic
Copy link
Member

Like often a little too late, but I think it would have been better to keep the real function name "SetOwnerEntity()" instead of "SetEntityOwner()" :).

SetEntityOwner is more in line with the rest of the SourceMod API. The full original function name is CBaseEntity::SetOwnerEntity, implying that you're operating on an entity to set it's owner entity. SetEntityOwner also implies that you're operating on an entity to set it's owner. The only part lost is that the owner is an entity, but I think that's better left implied rather than SetEntityOwnerEntity.

@einyux
Copy link
Contributor

einyux commented Nov 22, 2021

Indeed, I understand the issue for SetOwnerEntity().

However, I don't really see a problem with SetEntityOwnerEntity(), which is in line with CBaseEntity::SetOwnerEntity, knowing that CXX::SetOwner() exists too.

Here we're loosing the info that we're setting "m_hOwnerEntity" and not "m_hOwner".
Its not indicated in the sdktools_functions.inc either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Request user requested feature Needs Testing untested by author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants