Skip to content

fix: 🐛 log spam on tool scripts #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion addons/mod_loader/internal/hooks.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@tool
class_name _ModLoaderHooks
extends Object

Expand All @@ -7,10 +8,13 @@ extends Object

const LOG_NAME := "ModLoader:Hooks"

static var any_mod_hooked := false


## Internal ModLoader method. [br]
## To add hooks from a mod use [method ModLoaderMod.add_hook].
static func add_hook(mod_callable: Callable, script_path: String, method_name: String) -> void:
ModLoaderStore.any_mod_hooked = true
any_mod_hooked = true
var hash := get_hook_hash(script_path, method_name)
if not ModLoaderStore.modding_hooks.has(hash):
ModLoaderStore.modding_hooks[hash] = []
Expand Down
4 changes: 2 additions & 2 deletions addons/mod_loader/internal/mod_hook_preprocessor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func process_script_verbose(path: String, enable_hook_check := false, method_mas


## [param path]: File path to the script to be processed.[br]
## [param enable_hook_check]: Adds a check that ModLoaderStore.any_mod_hooked is [code]true[/code] to the processed method, reducing hash checks.[br]
## [param enable_hook_check]: Adds a check that _ModLoaderHooks.any_mod_hooked is [code]true[/code] to the processed method, reducing hash checks.[br]
## [param method_mask]: If provided, only methods in this [Array] will be processed.[br]
func process_script(path: String, enable_hook_check := false, method_mask: Array[String] = []) -> String:
var current_script := load(path) as GDScript
Expand Down Expand Up @@ -396,7 +396,7 @@ static func build_mod_hook_string(
var static_string := "static " if is_static else ""
var await_string := "await " if is_async else ""
var async_string := "_async" if is_async else ""
var hook_check := "if ModLoaderStore.any_mod_hooked:\n\t\t" if enable_hook_check else ""
var hook_check := "if _ModLoaderHooks.any_mod_hooked:\n\t\t" if enable_hook_check else ""
var hook_check_else := get_hook_check_else_string(
return_string, await_string, method_prefix, method_name, method_arg_string_names_only
) if enable_hook_check else ""
Expand Down
2 changes: 1 addition & 1 deletion addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func _init() -> void:
func _ready():
# Hooks must be generated after all autoloads are available.
# Variables initialized with an autoload property cause errors otherwise.
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
if OS.has_feature("editor"):
_ModLoaderModHookPacker.start()
ModLoaderLog.hint("No mod hooks .zip will be created when running from the editor.", LOG_NAME)
Expand Down
2 changes: 0 additions & 2 deletions addons/mod_loader/mod_loader_store.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const MOD_LOADER_DEV_TOOL_URL := "https://github.com/GodotModding/godot-mod-tool
# =============================================================================


var any_mod_hooked := false

# Stores arrays of hook callables that will be applied to a function,
# associated by a hash of the function name and script path
# Example:
Expand Down
66 changes: 33 additions & 33 deletions test/test_mod_hook_preprocessor/test_script_C_processed.gd
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func vanilla_2078531418_definitely_a_coroutine7(args := []):


func _ready():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
_ModLoaderHooks.call_hooks(vanilla_2078531418__ready, [], 2330625102)
else:
vanilla_2078531418__ready()
Expand All @@ -231,225 +231,225 @@ func _ready():
func method(one, #Somecomment
two, three: int, #Morecomments
four):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_method, [one, two, three, four], 2863650651)
else:
return vanilla_2078531418_method(one, two, three, four)


func super_something():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_super_something, [], 561212438)
else:
return vanilla_2078531418_super_something()


func super_something_else():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_super_something_else, [], 683196062)
else:
return vanilla_2078531418_super_something_else()


func sup_func_two():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_sup_func_two, [], 1626900374)
else:
return vanilla_2078531418_sup_func_two()


func sup_func():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_sup_func, [], 1698024413)
else:
return vanilla_2078531418_sup_func()


func other_test_func():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_other_test_func, [], 124073286)
else:
return vanilla_2078531418_other_test_func()


func hello_hello():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
_ModLoaderHooks.call_hooks(vanilla_2078531418_hello_hello, [], 2008108737)
else:
vanilla_2078531418_hello_hello()


func hellohello(hello: String):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
_ModLoaderHooks.call_hooks(vanilla_2078531418_hellohello, [hello], 1633231170)
else:
vanilla_2078531418_hellohello(hello)


func hello_hello_2(testing: String) -> String:
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_hello_hello_2, [testing], 692064114)
else:
return vanilla_2078531418_hello_hello_2(testing)


func hello():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
_ModLoaderHooks.call_hooks(vanilla_2078531418_hello, [], 1772795918)
else:
vanilla_2078531418_hello()


func hello_again():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
_ModLoaderHooks.call_hooks(vanilla_2078531418_hello_again, [], 1999867085)
else:
vanilla_2078531418_hello_again()


func more_comment_testing():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
_ModLoaderHooks.call_hooks(vanilla_2078531418_more_comment_testing, [], 502348540)
else:
vanilla_2078531418_more_comment_testing()


static func static_super():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_static_super, [], 1720709936)
else:
return vanilla_2078531418_static_super()


func this_is_so_cursed():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_this_is_so_cursed, [], 1705479347)
else:
return vanilla_2078531418_this_is_so_cursed()


func this_too():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_this_too, [], 1507098083)
else:
return vanilla_2078531418_this_too()


func please_stop():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_please_stop, [], 2851245561)
else:
return vanilla_2078531418_please_stop()


func why_would_you(put: int, \
backslashes: ="\\", in_here: ="?!\n"):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_why_would_you, [put, backslashes, in_here], 1414126584)
else:
return vanilla_2078531418_why_would_you(put, backslashes, in_here)


func param_super(one: int, two: String) -> int:
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_param_super, [one, two], 2371788505)
else:
return vanilla_2078531418_param_super(one, two)


func other_param_super(one: int, two: String) -> int:
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_other_param_super, [one, two], 2009491482)
else:
return vanilla_2078531418_other_param_super(one, two)


func get_something():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_get_something, [], 3887992391)
else:
return vanilla_2078531418_get_something()


func set_something():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_set_something, [], 2687664211)
else:
return vanilla_2078531418_set_something()


func set_exclude_me():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_set_exclude_me, [], 1755202272)
else:
return vanilla_2078531418_set_exclude_me()


func get_exclude_me():
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_get_exclude_me, [], 2711326548)
else:
return vanilla_2078531418_get_exclude_me()


func definitely_a_coroutine(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return await _ModLoaderHooks.call_hooks_async(vanilla_2078531418_definitely_a_coroutine, [args], 1072984126)
else:
return await vanilla_2078531418_definitely_a_coroutine(args)


func definitely_a_coroutine2(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return await _ModLoaderHooks.call_hooks_async(vanilla_2078531418_definitely_a_coroutine2, [args], 1048737840)
else:
return await vanilla_2078531418_definitely_a_coroutine2(args)


func definitely_a_coroutine3(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return await _ModLoaderHooks.call_hooks_async(vanilla_2078531418_definitely_a_coroutine3, [args], 1048737841)
else:
return await vanilla_2078531418_definitely_a_coroutine3(args)


func definitely_a_coroutine4(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return await _ModLoaderHooks.call_hooks_async(vanilla_2078531418_definitely_a_coroutine4, [args], 1048737842)
else:
return await vanilla_2078531418_definitely_a_coroutine4(args)


func absolutely_not_a_coroutine(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_absolutely_not_a_coroutine, [args], 2502244037)
else:
return vanilla_2078531418_absolutely_not_a_coroutine(args)


func definitely_a_coroutine5(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return await _ModLoaderHooks.call_hooks_async(vanilla_2078531418_definitely_a_coroutine5, [args], 1048737843)
else:
return await vanilla_2078531418_definitely_a_coroutine5(args)


func definitely_a_coroutine6(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return await _ModLoaderHooks.call_hooks_async(vanilla_2078531418_definitely_a_coroutine6, [args], 1048737844)
else:
return await vanilla_2078531418_definitely_a_coroutine6(args)


func absolutely_not_a_coroutine2(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return _ModLoaderHooks.call_hooks(vanilla_2078531418_absolutely_not_a_coroutine2, [args], 969674647)
else:
return vanilla_2078531418_absolutely_not_a_coroutine2(args)


func definitely_a_coroutine7(args: =[]):
if ModLoaderStore.any_mod_hooked:
if _ModLoaderHooks.any_mod_hooked:
return await _ModLoaderHooks.call_hooks_async(vanilla_2078531418_definitely_a_coroutine7, [args], 1048737845)
else:
return await vanilla_2078531418_definitely_a_coroutine7(args)