@@ -33,6 +33,7 @@ var regex_keyword_await := RegEx.create_from_string("\\bawait\\b")
3333
3434
3535var hashmap := {}
36+ var script_paths_hooked := {}
3637
3738
3839func process_begin () -> void :
@@ -65,10 +66,27 @@ func process_script(path: String, enable_hook_check := false) -> String:
6566 is_func_moddable .bind (source_code , getters_setters )
6667 )
6768
69+ var methods_hooked := {}
70+
6871 for method in moddable_methods :
6972 if method .name in method_store :
7073 continue
7174
75+ var prefix := "%s%s _" % [METHOD_PREFIX , class_prefix ]
76+
77+ # Check if the method name starts with the prefix added by `edit_vanilla_method()`.
78+ # This indicates that the method was previously processed, possibly by the export plugin.
79+ # If so, store the method name (excluding the prefix) in `methods_hooked`.
80+ if method .name .begins_with (prefix ):
81+ var method_name_vanilla : String = method .name .trim_prefix (prefix )
82+ methods_hooked [method_name_vanilla ] = true
83+ continue
84+
85+ # This ensures we avoid creating a hook for the 'imposter' method, which
86+ # is generated by `build_mod_hook_string()` and has the vanilla method name.
87+ if methods_hooked .has (method .name ):
88+ continue
89+
7290 var type_string := get_return_type_string (method .return )
7391 var is_static := true if method .flags == METHOD_FLAG_STATIC + METHOD_FLAG_NORMAL else false
7492
@@ -132,6 +150,8 @@ func process_script(path: String, enable_hook_check := false) -> String:
132150 )
133151 source_code_additions += "\n %s " % mod_loader_hook_string
134152
153+ script_paths_hooked [path ] = true
154+
135155 # If we have some additions to the code, append them at the end
136156 if source_code_additions != "" :
137157 source_code = "%s \n %s \n %s " % [source_code , MOD_LOADER_HOOKS_START_STRING , source_code_additions ]
0 commit comments