@@ -3,9 +3,13 @@ extends EditorExportPlugin
3
3
const REQUIRE_EXPLICIT_ADDITION := false
4
4
const METHOD_PREFIX := "GodotModLoader"
5
5
6
+ var hashmap := {}
7
+
6
8
func _get_name () -> String :
7
9
return "Godot Mod Loader Export Plugin"
8
10
11
+ func _export_begin (features : PackedStringArray , is_debug : bool , path : String , flags : int ) -> void :
12
+ hashmap .clear ()
9
13
10
14
func _export_file (path : String , type : String , features : PackedStringArray ) -> void :
11
15
if path .begins_with ("res://addons" ) or path .begins_with ("res://mods-unpacked" ):
@@ -46,14 +50,28 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
46
50
var is_static := true if method .flags == METHOD_FLAG_STATIC + METHOD_FLAG_NORMAL else false
47
51
var method_arg_string_with_defaults_and_types := get_function_parameters (method .name , source_code , is_static )
48
52
var method_arg_string_names_only := get_function_arg_name_string (method .args )
53
+
54
+ var hash_before = ModLoaderMod .get_hook_hash (path , method .name , true )
55
+ var hash_after = ModLoaderMod .get_hook_hash (path , method .name , false )
56
+ var hash_before_data = [path , method .name ,true ]
57
+ var hash_after_data = [path , method .name ,false ]
58
+ if hashmap .has (hash_before ):
59
+ push_error ("MODDING EXPORT ERROR: hash collision between %s and %s ." % [hashmap [hash_before ], hash_before_data ])
60
+ if hashmap .has (hash_after ):
61
+ push_error ("MODDING EXPORT ERROR: hash collision between %s and %s ." % [hashmap [hash_after ], hash_after_data ])
62
+ hashmap [hash_before ] = hash_before_data
63
+ hashmap [hash_after ] = hash_after_data
64
+
49
65
var mod_loader_hook_string := get_mod_loader_hook (
50
66
method .name ,
51
67
method_arg_string_names_only ,
52
68
method_arg_string_with_defaults_and_types ,
53
69
type_string ,
54
70
method .return .usage ,
55
71
is_static ,
56
- path
72
+ path ,
73
+ hash_before ,
74
+ hash_after ,
57
75
)
58
76
59
77
# Store the method name
@@ -171,6 +189,8 @@ static func get_mod_loader_hook(
171
189
return_prop_usage : int ,
172
190
is_static : bool ,
173
191
script_path : String ,
192
+ hash_before :int ,
193
+ hash_after :int ,
174
194
method_prefix := METHOD_PREFIX ) -> String :
175
195
var type_string := " -> %s " % method_type if not method_type .is_empty () else ""
176
196
var static_string := "static " if is_static else ""
@@ -181,9 +201,9 @@ static func get_mod_loader_hook(
181
201
182
202
return """
183
203
{%STATIC%}func {%METHOD_NAME%}({%METHOD_PARAMS%}){%RETURN_TYPE_STRING%}:
184
- ModLoaderMod.call_from_callable_stack ({%SELF%}, [{%METHOD_ARGS%}], "{%SCRIPT_PATH%}", "{%METHOD_NAME%}", true )
204
+ ModLoaderMod.call_hooks ({%SELF%}, [{%METHOD_ARGS%}], {%HOOK_ID_BEFORE%} )
185
205
{%METHOD_RETURN_VAR%}{%METHOD_PREFIX%}_{%METHOD_NAME%}({%METHOD_ARGS%})
186
- ModLoaderMod.call_from_callable_stack ({%SELF%}, [{%METHOD_ARGS%}], "{%SCRIPT_PATH%}", "{%METHOD_NAME%}", false )
206
+ ModLoaderMod.call_hooks ({%SELF%}, [{%METHOD_ARGS%}], {%HOOK_ID_AFTER%} )
187
207
{%METHOD_RETURN%}
188
208
""" .format ({
189
209
"%METHOD_PREFIX%" : method_prefix ,
@@ -196,6 +216,8 @@ static func get_mod_loader_hook(
196
216
"%METHOD_RETURN%" : method_return ,
197
217
"%STATIC%" : static_string ,
198
218
"%SELF%" : self_string ,
219
+ "%HOOK_ID_BEFORE%" : hash_before ,
220
+ "%HOOK_ID_AFTER%" : hash_after ,
199
221
})
200
222
201
223
static func get_previous_line_to (text : String , index : int ) -> String :
0 commit comments