Plugin Overloading - Bug Report?

Fou-lu

New member
Messages
145
Points
0
Github
Pedro
I apologize if this is posted in the wrong location.

When programming a plugin that uses overloading, I realized that the way it is in the Hercules tutorial doesn't work.

image.png

When reproducing what the tutorial asks for, placing it inside the "server_ready" function, overloading does not work. I needed to put it in the "plugin_init" function for it to work.

image.png

 
You are right, looks like "server_ready" is not part of the HPM events, so it is never called. I think the docs actually meant "server_online" (which means the server is ready / online).

I generally prefer using plugin_init, as you said, since server_online runs after several processing already happened (e.g. config loading). So the tutorial should probably use "plugin_init" instead.

Nice finding!

Do you want to PR a fix to the docs? :) If not, I can edit it later

 
Last edited by a moderator:
better not do direct overloading without reason. Because it may break other plugins if you not do correct overloading.

better use hpm overload things

 
better not do direct overloading without reason. Because it may break other plugins if you not do correct overloading.

better use hpm overload things
by "hpm overload things" you mean hookPre/hookPost?

As far as I remember, overloading, as in "I want to completely skip hercules original function" (maybe it should actually be called override?) were always made with a direct assignment to the interface (like in the original post here), while hookPre/hookPost would be used if you want to keep the original code running, but wants to do something else before/after it.

Example: https://github.com/HerculesWS/Hercules/blob/stable/src/plugins/db2sql.c#L1180

I am not aware of another method for overloading/overriding.

I do agree that you should only do it if you have a reason to, but is there a better way to overload/override than a direct assignment?

 
Do you want to PR a fix to the docs? :) If not, I can edit it later


Perfect. I have now submitted the change on GitHub.

better not do direct overloading without reason. Because it may break other plugins if you not do correct overloading.

better use hpm overload things
I share the same doubt as KirieZ. As far as I know and have learned about HPM Plugins, the only method to overwrite/replace a function is through this way.

I know about HookPre and HookPost, however, in some situations where you want to remove a piece of code within the function, these solutions don't work, forcing you to resort to overloading.

Of course, whenever possible, I will adhere to HookPre and HookPost, and I can identify well when this is necessary.

 
hpm overloading i mean hookPre/hookPost

Direct overloading i mean for example

clif->special_popup = my_special_popup


direct overloading may break other plugins.

 
Back
Top