PluginID - #577
Open
IIIaKa wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I propose adding a ulong ModificationID property to BaseEntity(the name can be changed) as a replacement for the skinID.
There are many plugins that modify or completely replace the behavior of different entities(NPCs, turrets, containers, vehicles, etc).
Many plugins used skinID to identify entities created or modified by plugins. Since skinID was not widely used by vanilla entities at the time, it also provided a simple way for other plugins to determine whether an entity was vanilla or controlled/modified by plugin.
However, this approach is becoming increasingly unreliable. With more and more vanilla entities supporting skins, skinID can no longer be safely used as a plugin-specific identifier.
That's why I propose adding a ulong ModificationID property to BaseEntity:
Why is this useful?
Consider a plugin that modifies NPC targeting:
In these conditions, the plugin takes control of all NPCs, including those created by other plugins, such as NPCs used for raids, events, custom events, etc, which can potentially lead to conflicts between plugins.
Without a common identifier, the plugin would need to explicitly check against every other plugin that creates custom NPCs:
This has several problems:
With ModificationID, the same logic becomes much simpler:
This provides a cheap and generic way to ignore all modified entities.
It can also be used to process only entities belonging to a specific plugin:
The main advantage is that this is a simple value comparison entity.ModificationID == 0uL.
There is no need to query other plugins, perform dictionary lookups, or maintain compatibility lists for every plugin that creates custom entities.
The memory overhead is also minimal, a ulong requires only 8 bytes per entity. Even with 100,000 entities, this would require only ~0.76MB of memory, which is a much better trade-off than adding extra CPU overhead.
This can be especially useful in frequently executed hooks where even small amounts of unnecessary work can accumulate.
I also understand that this could be considered a somewhat "hacky" solution, but currently there does not appear to be a generic, lightweight mechanism that allows plugins to identify ownership or modification of an entity without maintaining plugin-specific compatibility logic.
If we reject every solution simply because it could be considered "hacky", we could keep searching for a perfect solution until the game itself is no longer around. This is similar to the issue with conflicts between return types in hooks, where the solution may also require accepting a practical compromise rather than waiting for a perfect, generic solution.
I understand that there is a possibility of plugin IDs overlapping, but I don't think this is as much of a problem as having to add numerous checks such as IS_PLUGIN2_ENTITY.
In the end, plugin authors can coordinate and choose different values if necessary. After all, the ulong range is 0 - 18,446,744,073,709,551,615, so there is an enormous number of possible values.
I am open to suggestions regarding the property name, semantics, or a better implementation approach.