-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallable_call.lua
More file actions
89 lines (86 loc) · 3.29 KB
/
Copy pathCallable_call.lua
File metadata and controls
89 lines (86 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
HookSystem.clean_hook()
Callable_call = {}
local pre_callbacks = {}
local post_callbacks = {}
function Callable_call.add_pre_callback(callback_name, name, fn)
if pre_callbacks[callback_name] == nil then
pre_callbacks[callback_name] = {}
end
pre_callbacks[callback_name][name] = fn
end
function Callable_call.add_post_callback(callback_name, name, fn)
if post_callbacks[callback_name] == nil then
post_callbacks[callback_name] = {}
end
post_callbacks[callback_name][name] = fn
end
function Callable_call.remove_pre_callback(callback_name, name)
if pre_callbacks[callback_name] and pre_callbacks[callback_name][name] then
pre_callbacks[callback_name][name] = nil
if Utils.table_get_length(pre_callbacks[callback_name]) == 0 then
pre_callbacks[callback_name] = nil
end
end
end
function Callable_call.remove_post_callback(callback_name, name)
if post_callbacks[callback_name] and post_callbacks[callback_name][name] then
post_callbacks[callback_name][name] = nil
if Utils.table_get_length(post_callbacks[callback_name]) == 0 then
post_callbacks[callback_name] = nil
end
end
end
function Callable_call.add_capture_instance(callback_name, name, deal_func, check_func, pre_ext_func, post_ext_func)
check_func = check_func or function(...)
return true
end
Callable_call.add_pre_callback(callback_name, name, function(self, other, result, args)
if check_func(self, other, result, args) then
Utils.hook_instance_create({gm.constants.oActorTargetEnemy, gm.constants.oActorTargetPlayer})
end
if pre_ext_func then
pre_ext_func(self, other, result, args)
end
end)
Callable_call.add_post_callback(callback_name, name, function(self, other, result, args)
if check_func(self, other, result, args) then
local list = Utils.get_tracked_instances()
for i = 1, #list do
deal_func(list[i])
end
Utils.unhook_instance_create()
end
if post_ext_func then
post_ext_func(self, other, result, args)
end
end)
end
function Callable_call.remove_capture_instance(callback_name, name)
Callable_call.remove_pre_callback(callback_name, name)
Callable_call.remove_post_callback(callback_name, name)
end
HookSystem.pre_script_hook(gm.constants.callable_call, function(self, other, result, args)
local script = args[1].value
local callable_value = script.callable_value
if script and lua_type(callable_value) ~= "number" then
local pre_callbacks = pre_callbacks[callable_value.script_name]
if pre_callbacks then
for _, fn in pairs(pre_callbacks) do
fn(self, other, result, args)
end
end
end
end)
HookSystem.post_script_hook(gm.constants.callable_call, function(self, other, result, args)
local script = args[1].value
local callable_value = script.callable_value
if script and lua_type(callable_value) ~= "number" then
local post_callbacks = post_callbacks[callable_value.script_name]
if post_callbacks then
for _, fn in pairs(post_callbacks) do
fn(self, other, result, args)
end
end
end
end)
return Callable_call