From ac23be14762eab482094771f7b3c010a5b74797c Mon Sep 17 00:00:00 2001 From: K <65287118+katzerax@users.noreply.github.com> Date: Thu, 14 Nov 2024 23:59:11 -0800 Subject: [PATCH] SHOULD bring r2modman exclusivity support to the titles. --- Modules/KRecognizer/k_recognizer.gd | 42 +++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/Modules/KRecognizer/k_recognizer.gd b/Modules/KRecognizer/k_recognizer.gd index 18abcd5..ce10824 100644 --- a/Modules/KRecognizer/k_recognizer.gd +++ b/Modules/KRecognizer/k_recognizer.gd @@ -3,23 +3,49 @@ extends Node var prefix = "[KMOD.k_recognizer] " var title_api +func _register_kmod_titles(): + title_api.register_title(76561198233616048, "[color=#ff1a5c]KMod Dev[/color]", false) + title_api.register_title(76561198799078563, "[color=#f6a4f3]Paw tuah[/color]", false) + func _ready(): - if _check_for_title_api(): + if _check_r2_titleapi_location() or _check_for_title_api(): yield(wait_for_title_api(), "completed") if title_api != null: - title_api.register_title(76561198233616048, "[color=#ff1a5c]KMod Dev[/color]", false) - title_api.register_title(76561198799078563, "[color=#f6a4f3]Paw tuah[/color]", false) + _register_kmod_titles() + +func _get_gdweave_dir() -> String: + var game_directory = OS.get_executable_path().get_base_dir() + var folder_override = _get_folder_override() + if folder_override: + var relative_path = game_directory.plus_file(folder_override) + var is_relative = not ":" in relative_path and Directory.new().file_exists(relative_path) + return relative_path if is_relative else folder_override + else: + return game_directory.plus_file("GDWeave") + +func _get_folder_override() -> String: + for argument in OS.get_cmdline_args(): + if argument.begins_with("--gdweave-folder-override="): + return argument.trim_prefix("--gdweave-folder-override=").replace("\\", "/") + return "" + +func _check_r2_titleapi_location() -> bool: + var gdweave_dir = _get_gdweave_dir() + var manifest_path = gdweave_dir.plus_file("mods").plus_file("LoafWF-TitleAPI").plus_file("manifest.json") + return _check_manifest(manifest_path, "r2modman TitleAPI ") func _check_for_title_api() -> bool: - var exe_path = OS.get_executable_path().get_base_dir() - var manifest_path = exe_path.plus_file("GDWeave").plus_file("mods").plus_file("TitleAPI").plus_file("manifest.json") - print(prefix, "Checking for TitleAPI manifest") + var gdweave_dir = _get_gdweave_dir() + var manifest_path = gdweave_dir.plus_file("mods").plus_file("TitleAPI").plus_file("manifest.json") + return _check_manifest(manifest_path, "TitleAPI ") + +func _check_manifest(manifest_path: String, api_name: String) -> bool: var file = File.new() if file.file_exists(manifest_path): - print(prefix, "TitleAPI manifest found!") + print(prefix, api_name, "manifest found!") return true else: - print(prefix, "TitleAPI manifest not found.") + print(prefix, api_name, "manifest not found.") return false func wait_for_title_api() -> GDScriptFunctionState: