Skip to content

Fix SetEntityHealth to support 'any' entities#1846

Merged
psychonic merged 1 commit intoalliedmodders:masterfrom
Kenzzer:master
Dec 20, 2022
Merged

Fix SetEntityHealth to support 'any' entities#1846
psychonic merged 1 commit intoalliedmodders:masterfrom
Kenzzer:master

Conversation

@Kenzzer
Copy link
Member

@Kenzzer Kenzzer commented Oct 22, 2022

This PR closes #1770

What changed ?

Instead of assuming the prop name given in core gamedata is a networked property. We will instead assume it's the datamap equivalent, and is on the same offset, plus visible on every single entity as it is a CBaseEntity datamap, unlike the netprop which is only visible if the deriving class decided to have it networked.
To maintain the behaviour the old native had (mainly firing a network update, since it used Prop_Send) we notify the game the entity changed in order to fire a network update. And if the entity isn't networked we do nothing.

Benefits

This will allow for a wider range of entity support. Granted plugins could just do SetEntProp(entity, Prop_Data, "m_iHealth", amount). But Sourcemod aims at being strongly backwards compatible, therefore it is safe to say this native isn't going to be removed anytime soon. So since we already keep track of the property name in the core gamedata might as well just make a native that works on any source games (not that I'm aware of any that changed this property name but still).

Copy link
Member

@psychonic psychonic left a comment

Choose a reason for hiding this comment

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

I went back and forth on this in my head a bit, but I think it's fine enough. I am slightly concerned that there could also be reverse cases where the necessary var only exists as a sendprop and not at all in the datadesc. That is probably rarer yet, but we are trading breakage type either way.

Let's toss it in master and see if anyone complains.

@psychonic psychonic merged commit f8349e8 into alliedmodders:master Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants