-
-
Notifications
You must be signed in to change notification settings - Fork 192
feat: Implement bypass hook for Invoke method #1027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks for the PR. Unfortunately adding optional parameters to a method is actually a breaking change if a plugin is not recompiled against latest API. Sadly the only way around this to create an entirely new method with the new parameter added. |
…th older framework versions
Testing Results:The server is using CounterStrikeSharp.API.dll built from the current PR, while the test library was compiled with v1.0.338 The Invoke functionality works without errors, confirming that the current implementation approach is viable btw: I simply overloaded all the relevant functions, which does create some code redundancy. If refactoring is needed to reduce duplication, please let me know and I will refactor the implementation |
|
You're absolutely right about the potential issues with default parameters. Initially, I did consider using default parameters, but after your feedback, I switched to method overloading instead: public TResult Invoke(T1 arg1) // Method 1
public TResult Invoke(T1 arg1, bool bypasshook) // Method 2This approach generates two separate methods in the compiled assembly, ensuring full backward compatibility without requiring recompilation of existing code |


Assume we have:
We created a hook for this function:
However, at some point, we may need to invoke
funcwithout any modifications to its parameters (i.e., bypassing the hook):This type of requirement is common, but previously, it could not be achieved using the CSS framework itself.
Without a bypass mechanism, the above
Invokecall would still be intercepted by the hook, potentially modifying the parameters, which contradicts the requirementWe have now implemented a bypass hook feature. By simply passing a
boolparameter, you can easily bypass the hook:btw: This update is fully backward compatible (the default value of
bool bypassis set tofalse). Even plugins built with older versions of CSS usingHook/Invokewill continue to work without issues