Commit graph

129 commits

Author SHA1 Message Date
FireSiku
0380e9f4a8 Adding small hook creation info log. 2018-06-08 03:01:28 -04:00
FireSiku
4af4cd5f75 Fix a few edge cases and correctly error if the function doesn't exist. 2018-06-08 01:56:26 -04:00
FireSiku
722bc35f60 Rename newhooks. 2018-06-07 23:12:33 -04:00
FireSiku
55ebff741b Removed old hooks.lua 2018-06-07 23:10:42 -04:00
FireSiku
007fabfae4 Some final changes that were discussed on discord.:rawhook has been renamed :hook_origin, making it a much better name.:after has been renamed :hook_safe.:before has been removed. 2018-06-07 23:02:39 -04:00
FireSiku
5287ce2569 Throw an error if it cannot find an object after everything is loaded.
The delayed hooking implementation didn't have a flag to say when to stop trying to delay hooks that do not exist.
2018-06-07 23:00:36 -04:00
FireSiku
fa393c4f78 Prevent creating multiple hooks on the same function using different API 2018-06-07 22:58:18 -04:00
FireSiku
099b9db187 Fix issue where hooks arent delayed properly.
Under certain conditions, get_object_from_string could return that a hook needs to be delayed, but also return nil instead of the string.
2018-06-07 22:37:47 -04:00
FireSiku
f195b10e7d Make sure to restore original functions when reloading vmf. 2018-06-07 22:37:47 -04:00
FireSiku
f6baeb4ccd Send function name instead of hook_type to generic functions.
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.
2018-06-07 19:33:17 -04:00
FireSiku
9d554418f4 Added generic_hook_toggle
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.
2018-06-07 19:32:05 -04:00
FireSiku
7a08f1c32b Refactor API to use generic function for argument checking/handling
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.
2018-06-07 18:10:59 -04:00
FireSiku
78a1f5cbc0 Replace old vmf hook system.
- 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.
2018-06-07 18:09:09 -04:00
FireSiku
be0e9075ef Add mod:enable/disable_all_hooks() 2018-06-07 18:08:29 -04:00
FireSiku
06b23556a3 Implementing new hook 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.
2018-06-07 18:07:24 -04:00
bi
0439a66c45 Possible fix for not unloaded resources inside Guis on reloading 2018-06-07 13:51:59 +03:00
bi
14a6bdfa0f Persistent Tables: refactoring, added ability to set default table 2018-06-07 13:18:24 +03:00
FireSiku
d35060d57a Ignore the hook file since it will be changed soon. 2018-06-07 00:56:00 -04:00
FireSiku
61c0caa083 OptionsView: Fixed all luacheck errors.
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.
2018-06-07 00:22:06 -04:00
FireSiku
99aec819b9 Custom Textures: make UI_RENDERERS a persistant table. 2018-06-07 00:21:39 -04:00
FireSiku
d207c30720 DevConsole: Moved globals inside a persistant table 2018-06-07 00:21:39 -04:00
FireSiku
036544e04a Mutators: Rename external externals to be consistent with style
In most other files in VMF, modules (from mods and from source) and functions are lowercased without an underscore.
2018-06-07 00:21:39 -04:00
FireSiku
a349098062 Network: Get rid of some magic numbers. 2018-06-07 00:21:39 -04:00
FireSiku
a1124e3519 Keybindings: move input_service:get(special_key) calls out of the loop.
The function is called whenever a key is pressed, therefore we only need to check for ctrl, alt and shift once. Each of them was called twice, nested inside two loops.

The same thing can be found in Custom Menus, the same block of three lines and six conditionals. Good target for refactoring.
2018-06-07 00:20:27 -04:00
FireSiku
d9f3dd6c55 Commands: Replace command_entry with command_data 2018-06-07 00:20:18 -04:00
FireSiku
17505f0864 Fix line length errors across the entire project.
Modules include: Commands, UIScaling, Core Functions, Keybindings, Network, Settings, Dump, Custom Menus, Custom Textures, CommandList, ChatActions, VMFOptions

Extra: UIScaling: Fix _internals and remove single-letter vars
2018-06-07 00:18:35 -04:00
FireSiku
38af31d854 Changed the naming style for all internals across the project
Modules included: Commands, Keybindings, Network, Mutators, Settings, Localization, Persistant Tables, Toggling, Custom Textures, CommandList, Chat Actions
2018-06-07 00:11:49 -04:00
bi
d36f0b3d44 Options: automatic concatenation of the option name and a tooltip 2018-06-06 20:11:44 +03:00
bi
7205b4eb13 Chat: small changes in comments 2018-06-06 17:33:33 +03:00
bi
f16130838c Events: refactoring 2018-06-06 17:17:55 +03:00
bi
44724faffe Events: removed warning about not existing on_enabled/on_disabled event 2018-06-06 14:46:18 +03:00
bi
192871e222 Toggling: toggling mod now enables/disables all hooks by default 2018-06-06 14:42:12 +03:00
bi
edf53e44a4 Events: update event is now active only for enabled mods 2018-06-06 14:35:05 +03:00
bi
a634627823 Chat: refactoring, changing the way of sending message 2018-06-06 13:55:03 +03:00
bi
732c367397 Disabled mutators test 2018-05-31 15:53:51 +03:00
bi
f30c158fb3 Logging: fixed not showing mod name and msg type in chat 2018-05-28 22:43:31 +03:00
bi
1ac6a25024 Updated the rest of VMF to use new pcall system 2018-05-28 22:12:37 +03:00
bi
a7e88ef128 Renamed/removed files 2018-05-28 21:24:05 +03:00
bi
accbf12f2d Moved custom gui textures information to mod_data 2018-05-28 20:35:31 +03:00
bi
1fbe207930 Reworked mods initialization process.
Reworked 'new_mod' functionality.
Reworked pcalls (added error callstack).
Got rid of 'mod:initialize', 'mod:initialize_data', 'mod:localization'.
2018-05-28 17:44:38 +03:00
bi
c2dabc69ac VMF Loader: refactoring 2018-05-26 16:19:43 +03:00
bi
79ef3ff00d Small changes that are pending for quite a while 2018-05-26 15:17:49 +03:00
bi
06be8520a7 Keybindings: possible fix for inevitable crash for controller users 2018-05-26 13:45:11 +03:00
bi
5ce828b247 Disabled test mod 2018-05-26 13:19:45 +03:00
bi
93652cc0f0 Options Menu: fixed multiple Mod Options buttons 2018-05-26 13:17:20 +03:00
bi
d0e691fd12 Chat Actions: blocked raycast workaround [2] 2018-05-26 11:57:04 +03:00
bi
77b7643744 Chat Actions: blocked raycast workaround 2018-05-22 12:40:53 +03:00
bi
a54d0528d9 Mutators: moving, removig and renaming stuff 2018-05-22 11:52:57 +03:00
bi
59ca071b0f Mutators: changed method for retrieving cookies 2018-05-22 10:24:56 +03:00
bi
5946b0dac1 Mutators: tabs to spaces 2018-05-21 20:22:02 +03:00