TF2-DMB / CBaseNPC

Provides a friendly interface for plugins to use in order to create custom NPCs on the game Team Fortress 2
37 stars 6 forks source link

Disallow factory clone #55

Closed Kenzzer closed 3 months ago

Kenzzer commented 3 months ago

Reported as bug on Alliedmodders discord by user magnat2645, if a plugin clones the entity factory handle with sourcemod's CloneHandle native and then deletes the original handle. Calling CEntityFactory.GetFactoryOfEntity will end up returning the now deleted and therefore invalid factory handle.

Rather than allowing the cloning of handles for entity factories, as it's still not clear how we want cross-plugin interaction to work, and because it would require a significant rewrite of the internal code base to allow us. I opt to fully restrict handle cloning for entity factories. Instead the constructor for entity factories has been edited like so

-CEntityFactory(const char[] classname, CEntityFactoryPostConstructor postConstructor=INVALID_FUNCTION, CEntityFactoryOnRemoveCallback onRemove=INVALID_FUNCTION)
+CEntityFactory(const char[] classname, CEntityFactoryPostConstructor postConstructor=INVALID_FUNCTION, CEntityFactoryOnRemoveCallback onRemove=INVALID_FUNCTION, Handle plugin = INVALID_HANDLE)

This will allow plugins to allocate entity factories for other plugins.