This makes it much easier to give the function name in the error/warning messages and we can easily get the hook type based on function name.
Also, swap around enable_hook and similar function to hook_enable format to keep backward-compatibility with existing mods.
Instead of having a single enable/disable_hook call that requires modders to know hook type IDs, make separate APIs for all types.
This also makes it much easier in the future to improve the system or handle new use case scenarios easily.
A lot of the code ended up being duplicated between the four api calls,
on top of that some type handling checks had to be made in both create_hook and get_orig_function.
This lead to a very messy state of things, so combine all of the handling into a single function,
then we can proceed with the rest of the code expecting one thing.
Having a single entry point made it very easy to add support for delaying hook cleanly.
Also add support for "Obj.Method" notation for backward-compatibility with old hooks.
I initially tried to use string.split provided by fatshark's code, but it creates a table, and requires a lot of supporting code that is all avoided by using a simple string.sub call.
- Comment out the old hooks.lua
- Remove the HookMixin table in favor of using VMFMod.
- Update UIRenderer hook to adjust for changes in the new system.
Changes includes:
- No longer relies on any globals.
- No longer uses loadstrings, or recreate the hook chain frivolously.
- Adding :before() and :after() which will call the func before and after the function call.
- Added :rawhook() that imitate the old 'back' functionality, by replacing the original function at the "end" of the chain.
- Refactoring to only fetch original function once.
- Refactor to use a single internal _registry table.
- registry.hooks[hook_type] are now using metatable to automatically generate tables.
- Rawhooks now have their own specialized hooks, that will call the original if disabled.
- Make sure rawhooks are limited to one per function.
- No longer has the ability to overwrite hooks. We remove a table lookup from every hook call and make the code more straightforward.
- The functionality of overwriting a hook is not used in any mods. Any code that would require this can simply be written in a better way without bogging down the whole system for everyone.
The ascii is causing weird issues with line length so it has been disabled.
The file also contains really high amount of duplicated code causing Luacheck to throw a million redefined / shadowed variables warnings, so I muted those too for the time being.