@@ -36,7 +36,7 @@ func process_begin() -> void:
36
36
hashmap .clear ()
37
37
38
38
39
- func process_script (path : String ) -> String :
39
+ func process_script (path : String , enable_hook_check : = false ) -> String :
40
40
var start_time := Time .get_ticks_msec ()
41
41
ModLoaderLog .debug ("Start processing script at path: %s " % path , LOG_NAME )
42
42
var current_script := load (path ) as GDScript
@@ -67,8 +67,8 @@ func process_script(path: String) -> String:
67
67
68
68
var hash_before := _ModLoaderHooks .get_hook_hash (path , method .name , true )
69
69
var hash_after := _ModLoaderHooks .get_hook_hash (path , method .name , false )
70
- var hash_before_data := [path , method .name ,true ]
71
- var hash_after_data := [path , method .name ,false ]
70
+ var hash_before_data := [path , method .name , true ]
71
+ var hash_after_data := [path , method .name , false ]
72
72
if hashmap .has (hash_before ):
73
73
push_error (HASH_COLLISION_ERROR % [hashmap [hash_before ], hash_before_data ])
74
74
if hashmap .has (hash_after ):
@@ -87,6 +87,7 @@ func process_script(path: String) -> String:
87
87
hash_before ,
88
88
hash_after ,
89
89
METHOD_PREFIX + class_prefix ,
90
+ enable_hook_check
90
91
)
91
92
92
93
# Store the method name
@@ -261,24 +262,24 @@ static func get_mod_loader_hook(
261
262
return_prop_usage : int ,
262
263
is_static : bool ,
263
264
script_path : String ,
264
- hash_before :int ,
265
- hash_after :int ,
266
- method_prefix := METHOD_PREFIX
265
+ hash_before : int ,
266
+ hash_after : int ,
267
+ method_prefix := METHOD_PREFIX ,
268
+ enable_hook_check := false ,
267
269
) -> String :
268
270
var type_string := " -> %s " % method_type if not method_type .is_empty () else ""
269
271
var static_string := "static " if is_static else ""
270
272
# Cannot use "self" inside a static function.
271
273
var self_string := "null" if is_static else "self"
272
274
var return_var := "var %s = " % "return_var" if not method_type .is_empty () or return_prop_usage == 131072 else ""
273
275
var method_return := "return %s " % "return_var" if not method_type .is_empty () or return_prop_usage == 131072 else ""
276
+ var hook_check := 'if ModLoaderStore.get("any_mod_hooked") and ModLoaderStore.any_mod_hooked:\n\t\t ' if enable_hook_check else ""
274
277
275
278
return """
276
279
{STATIC} func {METHOD_NAME} ({METHOD_PARAMS} ){RETURN_TYPE_STRING} :
277
- if ModLoaderStore.get("any_mod_hooked") and ModLoaderStore.any_mod_hooked:
278
- _ModLoaderHooks.call_hooks({SELF} , [{METHOD_ARGS} ], {HOOK_ID_BEFORE} )
280
+ {HOOKS_CHECK} _ModLoaderHooks.call_hooks({SELF} , [{METHOD_ARGS} ], {HOOK_ID_BEFORE} )
279
281
{METHOD_RETURN_VAR}{METHOD_PREFIX} _{METHOD_NAME} ({METHOD_ARGS} )
280
- if ModLoaderStore.get("any_mod_hooked") and ModLoaderStore.any_mod_hooked:
281
- _ModLoaderHooks.call_hooks({SELF} , [{METHOD_ARGS} ], {HOOK_ID_AFTER} )
282
+ {HOOK_CHECK} _ModLoaderHooks.call_hooks({SELF} , [{METHOD_ARGS} ], {HOOK_ID_AFTER} )
282
283
{METHOD_RETURN} """ .format ({
283
284
"METHOD_PREFIX" : method_prefix ,
284
285
"METHOD_NAME" : method_name ,
@@ -290,8 +291,9 @@ static func get_mod_loader_hook(
290
291
"METHOD_RETURN" : method_return ,
291
292
"STATIC" : static_string ,
292
293
"SELF" : self_string ,
293
- "HOOK_ID_BEFORE" : hash_before ,
294
- "HOOK_ID_AFTER" : hash_after ,
294
+ "HOOK_ID_BEFORE" : hash_before ,
295
+ "HOOK_ID_AFTER" : hash_after ,
296
+ "HOOK_CHECK" : hook_check ,
295
297
})
296
298
297
299
0 commit comments