Skip to content

Commit 751d460

Browse files
authored
Workaround for Script.get_script_method_list() (#594)
I discovered through the process of modding Buckshot Roulette (Godot 4.1.1) that `Script.get_script_method_list()` was not returning arguments for any of the functions in specific scripts (e.g. `MenuManager.gd`). This left `method.args` completely empty for every function parsed with `mod_hook_preprocessor.gd`. The current usage of this was easily replaceable with `method_arg_string_with_defaults_and_types`, which was just declared on the previous line. This is a quick fix to get the mod loader working for Buckshot, and will likely need a little tweaking to fit in with the existing style.
2 parents e75c045 + a37e79a commit 751d460

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

‎addons/mod_loader/internal/mod_hook_preprocessor.gd‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ func process_script(path: String, enable_hook_check := false, method_mask: Array
136136
var is_async := is_func_async(func_body.get_string())
137137
var can_return := can_return(source_code, method.name, closing_paren_index, func_body_start_index)
138138
var method_arg_string_with_defaults_and_types := get_function_parameters(method.name, source_code, is_static)
139-
var method_arg_string_names_only := get_function_arg_name_string(method.args)
140-
139+
# Workaround for Script.get_script_method_list() not working as intended for some scripts in Godot 4.1
140+
var method_args_with_hints_and_defaults = Array(method_arg_string_with_defaults_and_types.split(", "))
141+
var method_arg_string_names_only := get_function_arg_name_string(method_args_with_hints_and_defaults)
142+
141143
var hook_id := _ModLoaderHooks.get_hook_hash(path, method.name)
142144
var hook_id_data := [path, method.name, true]
143145
if hashmap.has(hook_id):
@@ -255,15 +257,12 @@ func is_func_async(func_body_text: String) -> bool:
255257
return false
256258

257259

258-
static func get_function_arg_name_string(args: Array) -> String:
259-
var arg_string := ""
260-
for x in args.size():
261-
if x == args.size() -1:
262-
arg_string += args[x].name
263-
else:
264-
arg_string += "%s, " % args[x].name
265-
266-
return arg_string
260+
static func get_function_arg_name_string(method_args_with_hints_and_defaults: Array) -> String:
261+
var method_arg_string = ""
262+
for method_arg_with_hint_and_default in method_args_with_hints_and_defaults:
263+
var method_arg_with_hint = Array(method_arg_with_hint_and_default.split("=")).front() # remove defaults
264+
method_arg_string += Array(method_arg_with_hint.split(":")).front() + ", " # remove hints
265+
return method_arg_string.trim_suffix(", ")
267266

268267

269268
static func get_function_parameters(method_name: String, text: String, is_static: bool, offset := 0) -> String:

0 commit comments

Comments
 (0)