diff --git a/mods/base/base.lua b/mods/base/base.lua deleted file mode 100644 index 24ac2ba..0000000 --- a/mods/base/base.lua +++ /dev/null @@ -1,316 +0,0 @@ - --- Create our console -if false then - console.CreateConsole() -end - --- Vars -if not _G then return end -local _G = _G -local io = io -local print = print -local file = file - -if not declare then - declare = function(var, val) - rawset(_G, var, val or false) - end -end - --- Load Mod Manager -if not LuaModManager then - local lmm_path = "mods/base/req/lua_mod_manager.lua" - dofile( lmm_path ) -end - -local C = LuaModManager.Constants -_lua_reqs = _lua_reqs or {} -_mods_folders = _mods_folders or {} -_mods = _mods or {} -_prehooks = _prehooks or {} -_posthooks = _posthooks or {} -_wildcard_hooks = _wildcard_hooks or {} - --- Load JSON -if not _loaded_json then - dofile( C.mods_directory .. C.lua_base_directory .. C.json_module ) - _loaded_json = true -end - --- Set logs folder -if not _G[ C.logs_path_global ] then - declare( C.logs_path_global, C.mods_directory .. C.logs_directory ) -end - --- Set saves folder -if not _G[ C.save_path_global ] then - declare( C.save_path_global, C.mods_directory .. C.saves_directory ) -end - --- IO Helper -if io then - - io.file_is_readable = function( fname ) - local file = io.open(fname, "r" ) - if file ~= nil then - io.close(file) - return true - end - return false - end - - io.remove_directory_and_files = function( path, do_log ) - if not path then - log("[Error] paramater #1 to io.remove_directory_and_files, string expected, recieved " .. tostring(path)) - return false - end - - if not file.DirectoryExists( path ) then - log("[Error] Directory does not exist: " .. path) - return false - end - - local dirs = file.GetDirectories( path ) - if dirs then - for k, v in pairs( dirs ) do - local child_path = path .. v .. "/" - if do_log then log("Removing directory: " .. child_path) end - io.remove_directory_and_files( child_path, do_log ) - local r = file.RemoveDirectory( child_path ) - if not r then - log("[Error] Could not remove directory: " .. child_path) - return false - end - end - end - - local files = file.GetFiles( path ) - if files then - for k, v in pairs( files ) do - local file_path = path .. v - if do_log then log("Removing files: " .. file_path) end - local r, error_str = os.remove( file_path ) - if not r then - log("[Error] Could not remove file: " .. file_path .. ", " .. error_str) - return false - end - end - end - - if do_log then log("Removing directory: " .. path) end - local r = file.RemoveDirectory( path ) - if not r then - log("[Error] Could not remove directory: " .. path) - return false - end - - return true - - end - -end - --- Override require() -if not _require_orig then - - local _require_orig = require - - call_require_hook = function( hooks_table, path ) - - if hooks_table then - if hooks_table[path] then - for k, v in pairs( hooks_table[path] ) do - declare( C.required_script_global, path ) - declare( C.mod_path_global, v.mod_path ) - dofile( v.script ) - end - end - end - - end - - require = function( path ) - - local path_orig = path - path = path:lower() - - call_require_hook( _prehooks, path ) - local res = _require_orig( path_orig ) - call_require_hook( _posthooks, path ) - for k, v in ipairs( _wildcard_hooks ) do - declare( C.required_script_global, path ) - declare( C.mod_path_global, v.mod_path ) - dofile( v.script ) - end - - return res - - end - -end - --- Load saved mod data -if not _loaded_mod_manager then - - LuaModManager:Load() - _loaded_mod_manager = true - -end - --- Load mod definition files -if not _loaded_mod_folders then - - local print = function(str) - log("[Mods] " .. str) - end - - print("Loading mods for state (" .. tostring(_G) .. ")") - _mods_folders = file.GetDirectories( C.mods_directory ) - - if _mods_folders then - - for k, v in pairs( _mods_folders ) do - - if not C.excluded_mods_directories[v] then - - print("Loading mod: " .. tostring(v) .. "...") - local mod_path = C.mods_directory .. v .. "/" - local mod_def_file = mod_path .. C.mod_definition_file - local is_readable = io.file_is_readable and io.file_is_readable(mod_def_file) or false - if is_readable then - - local file = io.open(mod_def_file) - if file then - - local file_contents = file:read("*all") - local mod_content = nil - local json_success = pcall(function() - mod_content = json.decode(file_contents) - end) - - if json_success and mod_content then - local data = { - path = mod_path, - definition = mod_content, - priority = tonumber(mod_content.priority) or 0, - } - table.insert( _mods, data ) - else - print("An error occured while loading mod.txt from: " .. mod_path) - end - file:close() - - end - - else - print("Could not read or find " .. C.mod_definition_file .. " for modification: " .. v) - end - - end - - end - - end - - _loaded_mod_folders = true - -end - --- Process mod definitions -if _loaded_mod_folders and _mods then - - local add_hooks_table = function( mod, table_key, destination_table ) - - local hooks = mod.definition[table_key] - if hooks then - - for i, hook in pairs( hooks ) do - local hook_id = hook[ C.mod_hook_id_key ] - local script = hook[ C.mod_script_path_key ] - if hook_id and script then - - hook_id = hook_id:lower() - local tbl = { - mod_path = mod.path, - script = mod.path .. script - } - - if hook_id ~= C.mod_hook_wildcard_key then - destination_table[ hook_id ] = destination_table[ hook_id ] or {} - table.insert( destination_table[ hook_id ], tbl ) - else - table.insert( _wildcard_hooks, tbl ) - end - - end - end - - end - - end - - local add_persist_scripts = function( mod ) - - local persists = mod.definition[C.mod_persists_key] - if persists then - for k, v in pairs( persists ) do - LuaModManager:AddPersistScript( v, mod.path ) - end - end - - end - - local add_keybind_scripts = function( mod ) - - local keybinds = mod.definition[C.mod_keybinds_key] - if keybinds then - for k, v in pairs( keybinds ) do - LuaModManager:AddJsonKeybinding( v, mod.path ) - end - end - - end - - local add_updates = function( mod ) - - local updates = mod.definition[C.mod_update_key] - if updates then - for k, update in pairs( updates ) do - LuaModManager:AddUpdateCheck( mod.definition, mod.path, update ) - end - end - - end - - -- Prioritize - table.sort( _mods, function(a, b) - return a.priority > b.priority - end) - - -- Add mod hooks to tables - for k, v in ipairs( _mods ) do - - if LuaModManager:IsModEnabled( v.path ) and LuaModManager:HasRequiredMod(v) then - - -- Load pre- and post- hooks - add_hooks_table( v, C.mod_hooks_key, _posthooks ) - add_hooks_table( v, C.mod_prehooks_key, _prehooks ) - - -- Load persist scripts - add_persist_scripts( v ) - - -- Load keybinds - add_keybind_scripts( v ) - - -- Load updates - add_updates( v ) - - else - log("[Mods] Mod '" .. v.path .. "' is disabled!") - end - - end - - LuaModManager.Mods = _mods - -end diff --git a/mods/base/loc/de.txt b/mods/base/loc/de.txt deleted file mode 100644 index 713b105..0000000 --- a/mods/base/loc/de.txt +++ /dev/null @@ -1,80 +0,0 @@ -{ - "base_options_menu_lua_mods" : "Lua Mods", - "base_options_menu_lua_mods_desc" : "Status pruefen, installierte Lua-Mods aktivieren oder deaktivieren", - "base_options_menu_keybinds" : "Mod Tastenkuerzel", - "base_options_menu_keybinds_desc" : "Tastenkuerzel fur Lua-Mods anpassen", - "base_options_menu_lua_mod_options" : "Mod Optionen", - "base_options_menu_lua_mod_options_desc" : "Lua Mods anpassen", - - "base_mod_info_version" : "Version", - "base_mod_info_author" : "Author", - "base_mod_info_contact" : "Kontakt", - "base_mod_info_path" : "Pfad", - "base_mod_info_keybinds" : "Kuerzel", - "base_mod_info_prehooks" : "Prae-Hooks", - "base_mod_info_hooks" : "Hooks", - "base_mod_info_persist" : "Persistente Skripte", - "base_mod_info_disabled" : "Deaktiviert", - "base_mod_info_to_be_disabled" : "Wird beim Neustart deaktiviert", - "base_mod_info_to_be_enabled" : "Wird beim Neustart aktiviert", - "base_mod_info_disabled_impossible" : "Kann nicht deaktiviert werden", - - "base_mod_info_no_name" : "Mod ohne Name", - "base_mod_info_no_desc" : "Mod ohne Beschreibung", - "base_mod_info_no_author" : "Kein Author angegeben", - "base_mod_info_no_contact" : "Keine Kontaktiformationen", - "base_mod_info_no_keybinds" : "Ohne Kuerzel", - "base_mod_info_no_hooks" : "Keine Hooks", - "base_mod_info_no_prehooks" : "Keine Prae-Hooks", - "base_mod_info_no_persist_scripts" : "Keine persistenten Skripte", - - "base_mod_notifications_none" : "Keine Benachrichtigungen", - "base_mod_notifications_prev" : "<", - "base_mod_notifications_next" : ">", - "base_mod_notifications_count" : "$current/$max", - - "base_mod_updates_all_up_to_date" : "Alle Mods aktuell!", - "base_mod_updates_updates_required" : " $count Aktualisierung(en) benoetigt", - "base_mod_updates_updates_required_row" : " $mod", - "base_mod_updates_click_manager" : "[Update Manager oeffnen]", - - "base_mod_updates_update_all" : "Alle Mods aktualisieren", - "base_mod_automically_check_for_updates" : "$mod_name Aktualisierungen", - "base_mod_automically_check_for_updates_desc" : "Beim Spielstart automatisch nach Aktualisierungen fuer $mod_name suchen", - "base_mod_check_for_updates_now" : "Aktualisiere $mod_name jetzt", - "base_mod_check_for_updates_now_desc" : "Jetzt nach Aktualisierungen fuer $mod_name suchen", - - "base_mod_updates_show_update_available" : "$mod_name Update verfuegbar", - "base_mod_updates_show_update_available_message" : "Es ist eine Aktualisierung fuer $mod_name verfuegbar!\nEs kann direkt heruntergeladen werden, wenn Du den Update Manager links-unten oeffnest!", - - "base_mod_updates_update_mod_now" : "Jetzt $mod_name aktualisieren", - "base_mod_update_update_available" : "Fur $mod_name ist eine Aktualisierung verfuegbar!\nWillst Du $mod_name jetzt aktualisieren?", - "base_mod_updates_open_update_manager" : "Oeffne Update Manager", - "base_mod_updates_open_update_notes" : "Oeffne Patch Notes (Steam Overlay benoetigt)", - "base_mod_updates_update_now" : "Jetzt aktualisieren", - "base_mod_updates_update_later" : "Spater aktualisieren", - - "base_mod_updates_show_multiple_update_available" : "Mehrere Aktualisierungen verfuegbar", - "base_mod_updates_show_multiple_update_available_message" : "Es stehen Aktualisierungen fuer folgende Mods bereit:\n$mods\nDu kannst Sie automatisch aktualiseren, wenn Du den Update Manager oeffnest!", - "base_mod_updates_update_all_now" : "Alle Mods aktualisieren", - - "base_mod_update_no_update_available_title" : "$mod_name Aktuell!", - "base_mod_update_no_update_available" : "Du hast die neueste Version von $mod_name.\nWillst Du $mod_name herunterladen und neu installieren?", - "base_mod_update_no_update_available_no_data" : "$mod_name ist aktuell.", - "base_mod_update_no_update_available_force" : "Erneutes Herunterladen erzwingen", - - "base_mod_download_downloading_mod" : "Lade: $mod_name", - "base_mod_download_download_progress" : "Heruntergeladen $downloaded kb / $total kb", - "base_mod_download_download_progress_extract" : "Entpacke...", - "base_mod_download_download_progress_complete" : "Herunterladen abgeschlossen, bitte Payday2 neustarten!", - "base_mod_download_download_progress_failed" : "Herunterladen fehlgeschlagen, bitte erneut versuchen! :(", - - "base_language_select" : "Sprache", - "base_language_select_desc" : "Waehle die Sprache, in der Texte der BLT angezeigt werden sollen", - "base_language_en" : "Englisch", - "base_language_de" : "Deutsch", - "base_language_fr" : "French", - "base_language_ru" : "Russian", - "base_language_tr" : "Turkish", - -} diff --git a/mods/base/loc/en.txt b/mods/base/loc/en.txt deleted file mode 100644 index 7a7d6e1..0000000 --- a/mods/base/loc/en.txt +++ /dev/null @@ -1,95 +0,0 @@ -{ - "base_options_menu_lua_mods" : "Lua Mods", - "base_options_menu_lua_mods_desc" : "Check status, enable and disable your installed Lua mods", - "base_options_menu_keybinds" : "Mod Keybinds", - "base_options_menu_keybinds_desc" : "Customize keybinds for lua modifications", - "base_options_menu_lua_mod_options" : "Mod Options", - "base_options_menu_lua_mod_options_desc" : "Customize your lua mods", - - "base_mod_info_version" : "Version", - "base_mod_info_author" : "Author", - "base_mod_info_contact" : "Contact", - "base_mod_info_path" : "Path", - "base_mod_info_keybinds" : "Keybinds", - "base_mod_info_prehooks" : "Pre-Hooks", - "base_mod_info_hooks" : "Hooks", - "base_mod_info_persist" : "Persistent Scripts", - "base_mod_info_disabled" : "Disabled", - "base_mod_info_to_be_disabled" : "Will be disabled on restart", - "base_mod_info_to_be_enabled" : "Will be enabled on restart", - "base_mod_info_disabled_impossible" : "Cannot be disabled", - - "base_mod_info_no_name" : "No Mod Name", - "base_mod_info_no_desc" : "No Mod Description", - "base_mod_info_no_author" : "No Author Specified", - "base_mod_info_no_contact" : "No Contact Details", - "base_mod_info_no_keybinds" : "No Keybinds", - "base_mod_info_no_hooks" : "No Hooks", - "base_mod_info_no_prehooks" : "No Pre-Hooks", - "base_mod_info_no_persist_scripts" : "No Persistent Scripts", - - "base_mod_notifications_none" : "No Notifications", - "base_mod_notifications_prev" : "<", - "base_mod_notifications_next" : ">", - "base_mod_notifications_count" : "$current/$max", - - "base_mod_updates_all_up_to_date" : "All mods up to date!", - "base_mod_updates_updates_required" : " $count Update$s Required", - "base_mod_updates_mod_required" : " $count Mod$s Required", - "base_mod_updates_updates_required_row" : " $mod", - "base_mod_updates_click_manager" : "[Click to View Updates Manager]", - - "base_mod_updates_update_all" : "Update All Mods", - "base_mod_automically_check_for_updates" : "$mod_name Updates", - "base_mod_automically_check_for_updates_desc" : "Automatically check the server for updates for the mod $mod_name every time the game is loaded", - "base_mod_check_for_updates_now" : "Update $mod_name Now", - "base_mod_check_for_updates_now_desc" : "Check the server for updates for $mod_name immediately", - - "base_mod_notify_required" : "$mod_name Notification", - "base_mod_notify_required_desc" : "Automatically notify you that $mod_name is required to be installed by certain mods", - "base_mod_download_required_now" : "Download $mod_name Now", - "base_mod_download_required_now_desc" : "Download and Install $mod_name immediately", - - "base_mod_updates_show_update_available" : "$mod_name Update Available", - "base_mod_updates_show_update_available_message" : "An update for $mod_name is available!\nIt can be automatically downloaded for by visiting the Update Manager in the lower-left!", - - "base_mod_updates_update_mod_now" : "Update $mod_name Now", - "base_mod_update_update_available" : "There is an update available for $mod_name!\nDo you want to update $mod_name now?", - "base_mod_updates_open_update_manager" : "Open Update Manager", - "base_mod_updates_open_update_notes" : "View Patch Notes (Steam Overlay Required)", - "base_mod_updates_update_now" : "Update Now", - "base_mod_updates_update_later" : "Update Later", - - "base_mod_updates_show_required_available" : "Download $mod_name Now", - "base_mod_updates_show_required_available_message" : "$req_mod_name require(s) $mod_name to be installed to function!\nDo you want to download $mod_name now?", - "base_mod_updates_show_required_available_optional_message" : "$req_mod_name require(s) $mod_name to be installed for all features to work!\nDo you want to download $mod_name now?", - "base_mod_required_update_mod_now" : "Download Now", - "base_mod_required_update_later" : "Download Later", - "base_mod_updates_show_multiple_require_available" : "Multiple Mods Required", - "base_mod_updates_show_multiple_require_available_message" : "The following mods are required for certain mods to function fully:\n$mods\nYou can update them by visiting the Update Manager in the lower-left!", - - "base_mod_updates_show_multiple_update_available" : "Multiple Updates Available", - "base_mod_updates_show_multiple_update_available_message" : "Updates are available for the following mods:\n$mods\nYou can update them by visiting the Update Manager in the lower-left!", - "base_mod_updates_update_all_now" : "Update All Mods Now", - - "base_mod_update_no_update_available_title" : "$mod_name Up-to-Date!", - "base_mod_update_no_update_available" : "You have the latest version of $mod_name.\nDo you want to redownload and reinstall $mod_name automatically?", - "base_mod_update_no_update_available_no_data" : "You have the latest version of $mod_name.", - "base_mod_update_no_update_available_force" : "Force Redownload", - - "base_mod_download_downloading_mod" : "Downloading $mod_name", - "base_mod_download_download_progress" : "Downloaded $downloaded kb / $total kb", - "base_mod_download_download_progress_extract" : "Extracting archive...", - "base_mod_download_download_progress_complete" : "Download Complete, Please restart your game!", - "base_mod_download_download_progress_failed" : "Download Failed, Please try again! :(", - - "base_language_select" : "Language", - "base_language_select_desc" : "Select the language for the BLT to be displayed in", - "base_language_en" : "English", - "base_language_de" : "German", - "base_language_fr" : "French", - "base_language_ru" : "Russian", - "base_language_tr" : "Turkish", - "base_language_id" : "Indonesian", - -} diff --git a/mods/base/loc/fr.txt b/mods/base/loc/fr.txt deleted file mode 100644 index c0250e1..0000000 --- a/mods/base/loc/fr.txt +++ /dev/null @@ -1,80 +0,0 @@ -{ - "base_options_menu_lua_mods" : "Mods Lua", - "base_options_menu_lua_mods_desc" : "Vérifier l'état, activer et désactiver vos mods installés", - "base_options_menu_keybinds" : "Keybinds des mods", - "base_options_menu_keybinds_desc" : "Personnalisez vos keybinds pour les modifications de lua", - "base_options_menu_lua_mod_options" : "Options des mods", - "base_options_menu_lua_mod_options_desc" : "Paramétrer les mods", - - "base_mod_info_version" : "Version", - "base_mod_info_author" : "Auteur", - "base_mod_info_contact" : "Contact", - "base_mod_info_path" : "Emplacement", - "base_mod_info_keybinds" : "Keybinds", - "base_mod_info_prehooks" : "Pre-Fichier", - "base_mod_info_hooks" : "Fichier", - "base_mod_info_persist" : "Scripts persistants", - "base_mod_info_disabled" : "Désactivé", - "base_mod_info_to_be_disabled" : "Sera désactivée au redémarrage", - "base_mod_info_to_be_enabled" : "Sera activé au redémarrage", - "base_mod_info_disabled_impossible" : "Ne peut pas être désactivé", - - "base_mod_info_no_name" : "Pas de nom", - "base_mod_info_no_desc" : "Pas de description", - "base_mod_info_no_author" : "Pas de Auteur spécifié", - "base_mod_info_no_contact" : "Pas de contact", - "base_mod_info_no_keybinds" : "Pas de Keybinds", - "base_mod_info_no_hooks" : "Pas de fichier", - "base_mod_info_no_prehooks" : "Pas de Pre-Fichier", - "base_mod_info_no_persist_scripts" : "Pas de Scripts persistants", - - "base_mod_notifications_none" : "Pas de Notifications", - "base_mod_notifications_prev" : "<", - "base_mod_notifications_next" : ">", - "base_mod_notifications_count" : "$current/$max", - - "base_mod_updates_all_up_to_date" : "Tout les mods sont à jour!", - "base_mod_updates_updates_required" : " $count mises à jour$s Requis", - "base_mod_updates_updates_required_row" : " $mod", - "base_mod_updates_click_manager" : "[Cliquez ici pour voir le gestionnaire des mises à jour]", - - "base_mod_updates_update_all" : "Mettre à jour tout les mods", - "base_mod_automically_check_for_updates" : "$mod_name Updates", - "base_mod_automically_check_for_updates_desc" : "Vérifier automatiquement si le mod $mod_name est à jour à chaque fois que le jeu est lancé", - "base_mod_check_for_updates_now" : "Mettre à jour $mod_name Maintenant", - "base_mod_check_for_updates_now_desc" : "Voir si il y a une mise à jour pour $mod_name immédiatement", - - "base_mod_updates_show_update_available" : "$mod_name Mise à jour Disponible", - "base_mod_updates_show_update_available_message" : "Une mise à jour pour $mod_name est disponible!\nIl peut être automatiquement téléchargé en visitant le gestionnaire des mises à jour en bas à gauche!", - - "base_mod_updates_update_mod_now" : "Mettre à jour $mod_name Maintenant", - "base_mod_update_update_available" : "Une mise à jour est disponible pour $mod_name!\nVoulez-vous mettre à jour $mod_name maintenant?", - "base_mod_updates_open_update_manager" : "Ouvrir le gestionnaire des mises à jour", - "base_mod_updates_open_update_notes" : "Voir les notes de mises à jour (Overlay Steam Requis)", - "base_mod_updates_update_now" : "Mettre à jour", - "base_mod_updates_update_later" : "Mettre à jour plus tard", - - "base_mod_updates_show_multiple_update_available" : "Plusieurs mises à jour disponibles", - "base_mod_updates_show_multiple_update_available_message" : "Des mises à jour sont disponibles pour les mods suivants:\n$mods\nVous pouvez les mettres à jour en visitant le gestionnaire des mises à jour en bas à gauche!", - "base_mod_updates_update_all_now" : "Mettre à jour tout les mods maintenant", - - "base_mod_update_no_update_available_title" : "$mod_name est à jour!", - "base_mod_update_no_update_available" : "Voulez vous re-télécharger et réinstaller $mod_name immédiatement?", - "base_mod_update_no_update_available_no_data" : "Vous avez la derniere version de $mod_name.", - "base_mod_update_no_update_available_force" : "Forcer le téléchargement", - - "base_mod_download_downloading_mod" : "Téléchargement de $mod_name", - "base_mod_download_download_progress" : "Téléchargement de $downloaded kb / sur $total kb", - "base_mod_download_download_progress_extract" : "Extraction de l'archive...", - "base_mod_download_download_progress_complete" : "Téléchargement fini, veuillez redémarrez votre jeu!", - "base_mod_download_download_progress_failed" : "Téléchargement raté, veuillez essayer à nouveau! :(", - - "base_language_select" : "Langue", - "base_language_select_desc" : "Choisir la langue du BLT", - "base_language_fr" : "Français", - "base_language_en" : "Anglais", - "base_language_de" : "Allemand", - "base_language_ru" : "Russe", - "base_language_tr" : "Turque", - -} diff --git a/mods/base/loc/id.txt b/mods/base/loc/id.txt deleted file mode 100644 index 8cdfd7d..0000000 --- a/mods/base/loc/id.txt +++ /dev/null @@ -1,81 +0,0 @@ -{ - "base_options_menu_lua_mods" : "Lua Mods", - "base_options_menu_lua_mods_desc" : "Cek status, mengaktifkan dan menonaktifkan mods Lua Anda yang terpasang", - "base_options_menu_keybinds" : "Mod Keybinds", - "base_options_menu_keybinds_desc" : "Atur keybinds untuk modifikasi lua", - "base_options_menu_lua_mod_options" : "Opsi Mod", - "base_options_menu_lua_mod_options_desc" : "Atur lua mods Anda", - - "base_mod_info_version" : "Versi", - "base_mod_info_author" : "Pencipta", - "base_mod_info_contact" : "Kontak", - "base_mod_info_path" : "Letak", - "base_mod_info_keybinds" : "Keybinds", - "base_mod_info_prehooks" : "Pre-Hooks", - "base_mod_info_hooks" : "Hooks", - "base_mod_info_persist" : "Skrip Persisten", - "base_mod_info_disabled" : "Dinonaktifkan", - "base_mod_info_to_be_disabled" : "Akan dinonaktifkan setelah dimulai ulang", - "base_mod_info_to_be_enabled" : "Akan diaktifkan setelah dimulai ulang", - "base_mod_info_disabled_impossible" : "Tidak bisa dinonaktifkan", - - "base_mod_info_no_name" : "Tidak ada Nama Mod", - "base_mod_info_no_desc" : "Tidak ada Diskripsi Mod", - "base_mod_info_no_author" : "Pencipta tidak ditetapkan", - "base_mod_info_no_contact" : "tidak ada detail kontak", - "base_mod_info_no_keybinds" : "Tidak ada Keybinds", - "base_mod_info_no_hooks" : "Tidak ada Hooks", - "base_mod_info_no_prehooks" : "Tidak ada Pre-Hooks", - "base_mod_info_no_persist_scripts" : "Tidak ada Skrip Persinten", - - "base_mod_notifications_none" : "Tidak ada pemberitahuan", - "base_mod_notifications_prev" : "<", - "base_mod_notifications_next" : ">", - "base_mod_notifications_count" : "$current/$max", - - "base_mod_updates_all_up_to_date" : "Semua mod ini terbaru!", - "base_mod_updates_updates_required" : " $count Pembaruan Dibutuhkan", - "base_mod_updates_updates_required_row" : " $mod", - "base_mod_updates_click_manager" : "[Tekan Untuk Melihat Pengelola Pembaruan]", - - "base_mod_updates_update_all" : "Perbarui semua Mod", - "base_mod_automically_check_for_updates" : "Perbarui $mod_name", - "base_mod_automically_check_for_updates_desc" : "Secara otomatis memeriksa server untuk memperbarui mod $mod_name setiap permainan ini dimuat", - "base_mod_check_for_updates_now" : "Perbarui $mod_name Sekarang", - "base_mod_check_for_updates_now_desc" : "Cek server untuk perbarui segera $mod_name ini", - - "base_mod_updates_show_update_available" : "Pembaruan $mod_name Tersedia", - "base_mod_updates_show_update_available_message" : "Pembaruan $mod_name Tersedia!\nini dapat secara otomatis diunduh untuk dengan mengunjungi Pengelola Pembaruan pada kiri bawah!", - - "base_mod_updates_update_mod_now" : "Perbarui $mod_name Sekarang", - "base_mod_update_update_available" : "Pembaruan $mod_name tersedia!\nApakah Anda ingin memperbarui $mod_name sekarang?", - "base_mod_updates_open_update_manager" : "Buka Pengelola Pembaruan", - "base_mod_updates_open_update_notes" : "Lihat Catatan Patch (Membutuhkan Steam Overlay)", - "base_mod_updates_update_now" : "Perbarui Sekarang", - "base_mod_updates_update_later" : "Perbarui Nanti", - - "base_mod_updates_show_multiple_update_available" : "Beberapa Pembaruan Tersedia", - "base_mod_updates_show_multiple_update_available_message" : "Pembaruan tersedia untuk Mod Berikut ini:\n$mods\nAnda dapat memperbarui itu dengan mengunjungi Pengelola Pembaruan pada kiri bawah!", - "base_mod_updates_update_all_now" : "Perbarui Semua Mod Sekarang", - - "base_mod_update_no_update_available_title" : "$mod_name Ini Terbaru!", - "base_mod_update_no_update_available" : "Anda mempunyai versi terbaru dari $mod_name.\nApakah Anda ingin mengunduh dan memasang ulang $mod_name ini secara otomatis?", - "base_mod_update_no_update_available_no_data" : "Anda mempunyai versi terbaru dari $mod_name.", - "base_mod_update_no_update_available_force" : "Paksa Unduh", - - "base_mod_download_downloading_mod" : "Mengunduh $mod_name", - "base_mod_download_download_progress" : "Mengunduh $downloaded kb / $total kb", - "base_mod_download_download_progress_extract" : "Mengekstrak Arsip...", - "base_mod_download_download_progress_complete" : "Pengunduhan Selesai, Silahkan mulai ulang permainan Anda!", - "base_mod_download_download_progress_failed" : "Pengunduhan Sagal, Silahkan coba lagi! :(", - - "base_language_select" : "Bahasa", - "base_language_select_desc" : "Pilih bahasa yang akan ditampilkan dalam BLT", - "base_language_en" : "Inggris", - "base_language_de" : "Jerman", - "base_language_fr" : "Perancis", - "base_language_id" : "Indonesia", - "base_language_ru" : "Rusia", - "base_language_tr" : "Turki", - -} diff --git a/mods/base/loc/ru.txt b/mods/base/loc/ru.txt deleted file mode 100644 index f44a215..0000000 --- a/mods/base/loc/ru.txt +++ /dev/null @@ -1,80 +0,0 @@ -{ - "base_options_menu_lua_mods" : "Lua Моды", - "base_options_menu_lua_mods_desc" : "Проверьте статус, включите или отключите ваши Lua моды", - "base_options_menu_keybinds" : "Горячие клавиши модов", - "base_options_menu_keybinds_desc" : "Настройте горячие клавиши для lua модификаций", - "base_options_menu_lua_mod_options" : "Настройки модов", - "base_options_menu_lua_mod_options_desc" : "Настройте ваши lua моды", - - "base_mod_info_version" : "Версия", - "base_mod_info_author" : "Автор", - "base_mod_info_contact" : "Связь", - "base_mod_info_path" : "Путь", - "base_mod_info_keybinds" : "Горячие Клавиши", - "base_mod_info_prehooks" : "Предварительно Изменяемые Файлы", - "base_mod_info_hooks" : "Изменяемые Файлы", - "base_mod_info_persist" : "Постоянные скрипты", - "base_mod_info_disabled" : "Отключен", - "base_mod_info_to_be_disabled" : "Будет отключен после рестарта", - "base_mod_info_to_be_enabled" : "Будет включен после рестарта", - "base_mod_info_disabled_impossible" : "Невозможно отключить", - - "base_mod_info_no_name" : "<Название мода отсутствует>", - "base_mod_info_no_desc" : "<Описание мода отсутствует>", - "base_mod_info_no_author" : "<Автор не указан>", - "base_mod_info_no_contact" : "<Контактные данные отсутствуют>", - "base_mod_info_no_keybinds" : "<Горячие клавиши отсутствуют>", - "base_mod_info_no_hooks" : "<Изменяемые файлы отсутствуют>", - "base_mod_info_no_prehooks" : "<Предварительно изменяемые файлы отсутствуют>", - "base_mod_info_no_persist_scripts" : "<Постоянные скрипты отсутствуют>", - - "base_mod_notifications_none" : "Нет Уведомлений", - "base_mod_notifications_prev" : "<", - "base_mod_notifications_next" : ">", - "base_mod_notifications_count" : "$current/$max", - - "base_mod_updates_all_up_to_date" : "Все моды актуальны!", - "base_mod_updates_updates_required" : " $count Обновлений$s Доступно", - "base_mod_updates_updates_required_row" : " $mod", - "base_mod_updates_click_manager" : "[Нажмите для Просмотра Менеджера Обновлений]", - - "base_mod_updates_update_all" : "Обновить Все Моды", - "base_mod_automically_check_for_updates" : "$mod_name Обновления", - "base_mod_automically_check_for_updates_desc" : "Автоматически проверять сервер на обновления для мода $mod_name при каждом запуске игры", - "base_mod_check_for_updates_now" : "Обновить $mod_name", - "base_mod_check_for_updates_now_desc" : "Немедленно проверить сервер на обновления для $mod_name", - - "base_mod_updates_show_update_available" : "$mod_name Обновление Доступно", - "base_mod_updates_show_update_available_message" : "Обновление для $mod_name доступно!\nМожно настроить автоматическую загрузку, посетив Менджер Обновлений в левом нижнем углу!", - - "base_mod_updates_update_mod_now" : "Обновить $mod_name", - "base_mod_update_update_available" : "Доступно обновление для $mod_name!\nХотите обновить $mod_name прямо сейчас?", - "base_mod_updates_open_update_manager" : "Открыть Менеджер Обновлений", - "base_mod_updates_open_update_notes" : "Посмотреть Изменения", - "base_mod_updates_update_now" : "Обновить Сейчас", - "base_mod_updates_update_later" : "Обновить Позже", - - "base_mod_updates_show_multiple_update_available" : "Доступно Несколько Обновлений", - "base_mod_updates_show_multiple_update_available_message" : "Обновления доступны для следующих модов:\n$mods\nВы можете обновить их, посетив Менеджер Обновлений в левом нижнем углу!", - "base_mod_updates_update_all_now" : "Обновить Все Моды", - - "base_mod_update_no_update_available_title" : "$mod_name Последней Версии!", - "base_mod_update_no_update_available" : "У вас последняя версия $mod_name.\nХотите автоматически перезагрузить и переустановить $mod_name ?", - "base_mod_update_no_update_available_no_data" : "У вас последняя версия $mod_name.", - "base_mod_update_no_update_available_force" : "Перезагрузить Мод", - - "base_mod_download_downloading_mod" : "Скачивание $mod_name", - "base_mod_download_download_progress" : "Скачано $downloaded kb / $total kb", - "base_mod_download_download_progress_extract" : "Распаковка архива...", - "base_mod_download_download_progress_complete" : "Загрузка Завершена, Пожалуйста, Перезагрузите Игру!", - "base_mod_download_download_progress_failed" : "Ошибка Загрузки, Пожалуйста, повтори позже! :(", - - "base_language_select" : "Язык", - "base_language_select_desc" : "Выберите язык для BLT", - "base_language_en" : "English", - "base_language_de" : "German", - "base_language_fr" : "French", - "base_language_ru" : "Русский", - "base_language_tr" : "Turkish", - -} diff --git a/mods/base/loc/tr.txt b/mods/base/loc/tr.txt deleted file mode 100644 index 1780a66..0000000 --- a/mods/base/loc/tr.txt +++ /dev/null @@ -1,79 +0,0 @@ -{ - "base_options_menu_lua_mods" : "Lua Mods", - "base_options_menu_lua_mods_desc" : "Yukledigin Lua modlarinin durumu kontrol et, etkinlestir ve devre disi birak.", - "base_options_menu_keybinds" : "Mod Keybinds", - "base_options_menu_keybinds_desc" : "Lua modlari icin keybindleri ozellestir", - "base_options_menu_lua_mod_options" : "Mod Ayarlari", - "base_options_menu_lua_mod_options_desc" : "Lua modlarini ozellestir", - - "base_mod_info_version" : "Versiyon", - "base_mod_info_author" : "Yaratici", - "base_mod_info_contact" : "Irtibat", - "base_mod_info_path" : "Konum", - "base_mod_info_keybinds" : "Keybinds", - "base_mod_info_prehooks" : "Pre-Hooks", - "base_mod_info_hooks" : "Hooklar", - "base_mod_info_persist" : "Persistent Scripts", - "base_mod_info_disabled" : "Devre Disi Birakilmis", - "base_mod_info_to_be_disabled" : "Yeniden baslatmada devre disi birakilacak", - "base_mod_info_to_be_enabled" : "Yeniden baslatmada etkinlestirilecek", - "base_mod_info_disabled_impossible" : "Devre disi birakilamaz", - - "base_mod_info_no_name" : "Mod Ismi Yok", - "base_mod_info_no_desc" : "Mod Aciklamasi Yok", - "base_mod_info_no_author" : "Yaratici belirtilmemis", - "base_mod_info_no_contact" : "Irtibat detaylari yok", - "base_mod_info_no_keybinds" : "Keybindler yok", - "base_mod_info_no_hooks" : "Hooklar yok", - "base_mod_info_no_prehooks" : "Pre-Hooklar yok", - "base_mod_info_no_persist_scripts" : "Persistent Scriptsleri yok", - - "base_mod_notifications_none" : "Bildiri yok", - "base_mod_notifications_prev" : "<", - "base_mod_notifications_next" : ">", - "base_mod_notifications_count" : "$current/$max", - - "base_mod_updates_all_up_to_date" : "Tum modlar guncel!", - "base_mod_updates_updates_required" : " $count Update$s Gerekli", - "base_mod_updates_updates_required_row" : " $mod", - "base_mod_updates_click_manager" : "[Guncelleme Yoneticisini Goruntulemek Icin Tikla]", - - "base_mod_updates_update_all" : "Tum Modlari Guncelle", - "base_mod_automically_check_for_updates" : "$mod_name Guncellemeleri", - "base_mod_automically_check_for_updates_desc" : "Otomatik olarak sunucu guncellemelerini $mod_name icin her oyun yuklendiginde kontrol et", - "base_mod_check_for_updates_now" : "$mod_name'i Simdi Guncelle", - "base_mod_check_for_updates_now_desc" : "$mod_name icin sunucu guncellemelerini hemen kontrol et", - - "base_mod_updates_show_update_available" : "$mod_name Guncellemesi Mevcut", - "base_mod_updates_show_update_available_message" : "Bir guncelleme $mod_name icin mevcut!\nOtomatik olarak sol alttaki Guncelleme Yoneticisi'ni ziyaret ederek indirilebilir", - - "base_mod_updates_update_mod_now" : "$mod_name'i Simdi Guncelle", - "base_mod_update_update_available" : "Bir guncelleme $mod_name! icin mevcut!\n$mod_name'i simdi guncellemek ister misiniz?", - "base_mod_updates_open_update_manager" : "Guncelleme Yoneticisini Ac", - "base_mod_updates_open_update_notes" : "Yama Notlarini Goster (Steam Penceresi Gerekli)", - "base_mod_updates_update_now" : "Simdi Guncelle", - "base_mod_updates_update_later" : "Sonra Guncelle", - - "base_mod_updates_show_multiple_update_available" : "Birden Cok Guncelleme Mevcut", - "base_mod_updates_show_multiple_update_available_message" : "Guncellemer su modlar icin mevcut:\n$mods\nOnlari sol alttaki Guncelleme Yoneticisi'ni ziyaret ederek guncelleyebilirsin!", - "base_mod_updates_update_all_now" : "Tum Modlari Simdi Guncelle", - - "base_mod_update_no_update_available_title" : "$mod_name Guncel!", - "base_mod_update_no_update_available" : "$mod_name'un son surumune sahipsiniz.\nOtomatik olarak $mod_name'i tekrar indirmek ve yuklemek ister misiniz?", - "base_mod_update_no_update_available_no_data" : "$mod_name'in son surumune sahipsiniz.", - "base_mod_update_no_update_available_force" : "Tekrar Indirmeye Zorla", - - "base_mod_download_downloading_mod" : "$mod_name indiriliyor", - "base_mod_download_download_progress" : "$downloaded kb indirildi/ $total kb", - "base_mod_download_download_progress_extract" : "Arsiv cikariliyor...", - "base_mod_download_download_progress_complete" : "Indirme Tamamlandi, Lutfen oyununu yeniden baslat!", - "base_mod_download_download_progress_failed" : "Indirme basarisiz, Lutfen tekrar dene :(", - - "base_language_select" : "Dil", - "base_language_select_desc" : "BLT'nin goruntulenmesi icin bir dil sec.", - "base_language_en" : "Ingilizce", - "base_language_de" : "Almanca", - "base_language_fr" : "Fransizca", - "base_language_ru" : "Rusca", - "base_language_tr" : "Turkce" -} diff --git a/mods/base/lua/BaseNetworkSession.lua b/mods/base/lua/BaseNetworkSession.lua deleted file mode 100644 index 15bf283..0000000 --- a/mods/base/lua/BaseNetworkSession.lua +++ /dev/null @@ -1,30 +0,0 @@ -CloneClass(BaseNetworkSession) - -Hooks:Register("BaseNetworkSessionOnEnteredLobby") -function BaseNetworkSession.on_entered_lobby(self) - self.orig.on_entered_lobby(self) - local local_peer = managers.network:session():local_peer() - local id = local_peer:id() - Hooks:Call("BaseNetworkSessionOnEnteredLobby", local_peer, id) -end - -Hooks:Register("BaseNetworkSessionOnPeerEnteredLobby") -function BaseNetworkSession.on_peer_entered_lobby(self, peer) - self.orig.on_peer_entered_lobby(self, peer) - local peer_id = peer:id() - Hooks:Call("BaseNetworkSessionOnPeerEnteredLobby", peer, peer_id) -end - -Hooks:Register("BaseNetworkSessionOnPeerRemoved") -function BaseNetworkSession._on_peer_removed(self, peer, peer_id, reason) - self.orig._on_peer_removed(self, peer, peer_id, reason) - Hooks:Call("BaseNetworkSessionOnPeerRemoved", peer, peer_id, reason) -end - -Hooks:Register("BaseNetworkSessionOnLoadComplete") -function BaseNetworkSession.on_load_complete(self, simulation) - self.orig.on_load_complete(self, simulation) - local local_peer = managers.network:session():local_peer() - local id = local_peer:id() - Hooks:Call("BaseNetworkSessionOnLoadComplete", local_peer, id) -end diff --git a/mods/base/lua/ChatManager.lua b/mods/base/lua/ChatManager.lua deleted file mode 100644 index 33719f7..0000000 --- a/mods/base/lua/ChatManager.lua +++ /dev/null @@ -1,14 +0,0 @@ - -CloneClass( ChatManager ) - -Hooks:RegisterHook( "ChatManagerOnSendMessage" ) -function ChatManager.send_message(this, channel_id, sender, message) - Hooks:Call( "ChatManagerOnSendMessage", channel_id, sender, message ) - return this.orig.send_message(this, channel_id, sender, message) -end - -Hooks:RegisterHook( "ChatManagerOnReceiveMessage" ) -function ChatManager._receive_message(this, channel_id, name, message, color, icon) - Hooks:Call( "ChatManagerOnReceiveMessage", channel_id, name, message, color, icon ) - return this.orig._receive_message(this, channel_id, name, message, color, icon) -end diff --git a/mods/base/lua/CoreMenuItemSlider.lua b/mods/base/lua/CoreMenuItemSlider.lua deleted file mode 100644 index 6877a68..0000000 --- a/mods/base/lua/CoreMenuItemSlider.lua +++ /dev/null @@ -1,24 +0,0 @@ - -core:module("CoreMenuItemSlider") -local CloneClass = _G.CloneClass -local tweak_data = _G.tweak_data - -CloneClass( ItemSlider ) - -function ItemSlider.setup_gui(self, node, row_item) - local r = self.orig.setup_gui(self, node, row_item) - row_item.gui_slider_text:set_font_size( tweak_data.menu.stats_font_size ) - return r -end - -function ItemSlider.set_value(self, value) - self._value = math.min(math.max(self._min, value), self._max) - self:dirty() -end - -function ItemSlider.reload(self, row_item, node) - local r = self.orig.reload(self, row_item, node) - local value = self:show_value() and string.format("%.2f", math.round_with_precision(self:value(), 2)) or string.format("%.0f", self:percentage()) .. "%" - row_item.gui_slider_text:set_text(value) - return r -end diff --git a/mods/base/lua/CoreMenuLogic.lua b/mods/base/lua/CoreMenuLogic.lua deleted file mode 100644 index d2aca81..0000000 --- a/mods/base/lua/CoreMenuLogic.lua +++ /dev/null @@ -1,12 +0,0 @@ - -local Hooks = Hooks -local CloneClass = CloneClass -core:module("CoreMenuLogic") - -CloneClass( Logic ) - -Hooks:RegisterHook("LogicOnSelectNode") -function Logic.select_node(self, node_name, queue, ...) - self.orig.select_node(self, node_name, queue, ...) - Hooks:Call( "LogicOnSelectNode", self, node_name, queue, ... ) -end diff --git a/mods/base/lua/CorePatchLua.lua b/mods/base/lua/CorePatchLua.lua deleted file mode 100644 index 61d55c1..0000000 --- a/mods/base/lua/CorePatchLua.lua +++ /dev/null @@ -1,23 +0,0 @@ - -local mt = getmetatable(_G) -if mt == nil then - mt = {} - setmetatable(_G, mt) -end -mt.__declared = {} -function mt.__newindex(t, n, v) - if not mt.__declared[n] then - local info = debug.getinfo(2, "S") - mt.__declared[n] = true - end - rawset(t, n, v) -end - -function mt.__index(t, n) - if not mt.__declared[n] then - local info = debug.getinfo(2, "S") - if info and info.what ~= "main" and info.what ~= "C" then - return nil - end - end -end diff --git a/mods/base/lua/GameSetup.lua b/mods/base/lua/GameSetup.lua deleted file mode 100644 index f842b58..0000000 --- a/mods/base/lua/GameSetup.lua +++ /dev/null @@ -1,8 +0,0 @@ - -CloneClass( GameSetup ) - -Hooks:RegisterHook("GameSetupUpdate") -function GameSetup.update(this, t, dt) - Hooks:Call("GameSetupUpdate", t, dt) - return this.orig.update(this, t, dt) -end diff --git a/mods/base/lua/LocalizationManager.lua b/mods/base/lua/LocalizationManager.lua deleted file mode 100644 index 4f19592..0000000 --- a/mods/base/lua/LocalizationManager.lua +++ /dev/null @@ -1,72 +0,0 @@ - -CloneClass( LocalizationManager ) - -LocalizationManager._custom_localizations = LocalizationManager._custom_localizations or {} - -Hooks:RegisterHook("LocalizationManagerPostInit") -function LocalizationManager.init( self ) - self.orig.init( self ) - Hooks:Call( "LocalizationManagerPostInit", self ) -end - -function LocalizationManager.text( self, str, macros ) - - -- log( "Localizer: " .. tostring(Localizer.__index) ) - -- log( "SystemInfo:language():key(): " ) - -- lang_mods[Idstring("german"):key()] - -- lang_mods[Idstring("french"):key()] - -- lang_mods[Idstring("italian"):key()] - -- lang_mods[Idstring("spanish"):key()] - -- lang_mods[Idstring("english"):key()] - - if self._custom_localizations[str] then - - local return_str = self._custom_localizations[str] - if macros and type(macros) == "table" then - for k, v in pairs( macros ) do - return_str = return_str:gsub( "$" .. k, v ) - end - end - return return_str - - end - return self.orig.text(self, str, macros) - -end - -function LocalizationManager:add_localized_strings( string_table, overwrite ) - - -- Should we overwrite existing localization strings - if overwrite == nil then - overwrite = true - end - - if type(string_table) == "table" then - for k, v in pairs( string_table ) do - if not self._custom_localizations[k] or (self._custom_localizations[k] and overwrite) then - self._custom_localizations[k] = v - end - end - end - -end - -function LocalizationManager:load_localization_file( file_path, overwrite ) - - -- Should we overwrite existing localization strings - if overwrite == nil then - overwrite = true - end - - local file = io.open( file_path, "r" ) - if file then - - local file_contents = file:read("*all") - file:close() - - local contents = json.decode( file_contents ) - self:add_localized_strings( contents, overwrite ) - - end - -end diff --git a/mods/base/lua/MenuComponentManager.lua b/mods/base/lua/MenuComponentManager.lua deleted file mode 100644 index 0db512f..0000000 --- a/mods/base/lua/MenuComponentManager.lua +++ /dev/null @@ -1,41 +0,0 @@ - -CloneClass( MenuComponentManager ) - -Hooks:RegisterHook("MenuComponentManagerInitialize") -function MenuComponentManager.init( self ) - self.orig.init( self ) - Hooks:Call( "MenuComponentManagerInitialize", self ) -end - -Hooks:RegisterHook("MenuComponentManagerUpdate") -function MenuComponentManager.update( self, t, dt ) - self.orig.update( self, t, dt ) - Hooks:Call( "MenuComponentManagerUpdate", self, t, dt ) -end - -Hooks:RegisterHook("MenuComponentManagerPreSetActiveComponents") -function MenuComponentManager.set_active_components( self, components, node ) - Hooks:Call( "MenuComponentManagerPreSetActiveComponents", self, components, node ) - self.orig.set_active_components(self, components, node) -end - -Hooks:RegisterHook("MenuComponentManagerOnMousePressed") -function MenuComponentManager.mouse_pressed( self, o, button, x, y ) - local r = self.orig.mouse_pressed(self, o, button, x, y) - local val = Hooks:ReturnCall("MenuComponentManagerOnMousePressed", self, o, button, x, y) - if val then - r = val - end - return r -end - -Hooks:RegisterHook("MenuComponentManagerOnMouseMoved") -function MenuComponentManager.mouse_moved( self, o, x, y ) - local hover, pointer = self.orig.mouse_moved( self, o, x, y ) - local ohover, opointer = Hooks:ReturnCall("MenuComponentManagerOnMouseMoved", self, o, x, y) - if ohover ~= nil then - hover = ohover - pointer = opointer - end - return hover, pointer -end diff --git a/mods/base/lua/MenuItemCustomizeController.lua b/mods/base/lua/MenuItemCustomizeController.lua deleted file mode 100644 index 120701d..0000000 --- a/mods/base/lua/MenuItemCustomizeController.lua +++ /dev/null @@ -1,67 +0,0 @@ - -CloneClass( MenuItemCustomizeController ) - -function MenuItemCustomizeController.init(self, data_node, parameters) - CoreMenuItem.Item.init(self, data_node, parameters) - self._type = MenuItemCustomizeController.TYPE -end - -function MenuItemCustomizeController.setup_gui(self, node, row_item) - row_item.gui_panel = node.item_panel:panel({ - w = node.item_panel:w() - }) - row_item.controller_name = node._text_item_part(node, row_item, row_item.gui_panel, node._left_align(node)) - row_item.controller_name:set_align("right") - row_item.controller_binding = node._text_item_part(node, row_item, row_item.gui_panel, node._left_align(node), "left") - row_item.controller_binding:set_align("left") - row_item.controller_binding:set_text(string.upper(row_item.item:parameters().binding)) - row_item.controller_binding:set_color(tweak_data.menu.default_changeable_text_color) - self:_layout(node, row_item) - return true -end - -function MenuItemCustomizeController.reload(self, row_item, node) - if row_item ~= nil then - if self:parameters().axis then - row_item.controller_binding:set_text(string.upper(self:parameters().binding)) - else - row_item.controller_binding:set_text(string.upper(self:parameters().binding)) - end - end - return true -end - -function MenuItemCustomizeController.highlight_row_item(self, node, row_item, mouse_over) - if row_item ~= nil then - row_item.controller_binding:set_color(row_item.color) - row_item.controller_binding:set_font(row_item.font and Idstring(row_item.font) or tweak_data.menu.default_font_no_outline_id) - row_item.controller_name:set_color(row_item.color) - row_item.controller_name:set_font(row_item.font and Idstring(row_item.font) or tweak_data.menu.default_font_no_outline_id) - end - return true -end - -function MenuItemCustomizeController.fade_row_item(self, node, row_item) - if row_item ~= nil then - row_item.controller_name:set_color(row_item.color) - row_item.controller_name:set_font(row_item.font and Idstring(row_item.font) or tweak_data.menu.default_font_id) - row_item.controller_binding:set_color(tweak_data.menu.default_changeable_text_color) - row_item.controller_binding:set_font(row_item.font and Idstring(row_item.font) or tweak_data.menu.default_font_id) - end - return true -end - -function MenuItemCustomizeController._layout(self, node, row_item) - local safe_rect = managers.gui_data:scaled_size() - if row_item ~= nil then - row_item.controller_name:set_font_size(tweak_data.menu.customize_controller_size) - local x, y, w, h = row_item.controller_name:text_rect() - row_item.controller_name:set_height(h) - row_item.controller_name:set_right(row_item.gui_panel:w() - node.align_line_padding(node)) - row_item.gui_panel:set_height(h) - row_item.controller_binding:set_font_size(tweak_data.menu.customize_controller_size) - row_item.controller_binding:set_height(h) - row_item.controller_binding:set_left(node._right_align(node)) - end -end - diff --git a/mods/base/lua/MenuManager.lua b/mods/base/lua/MenuManager.lua deleted file mode 100644 index ce47308..0000000 --- a/mods/base/lua/MenuManager.lua +++ /dev/null @@ -1,586 +0,0 @@ - -CloneClass( MenuManager ) -CloneClass( MenuCallbackHandler ) -CloneClass( ModMenuCreator ) -CloneClass( MenuModInfoGui ) - -Hooks:RegisterHook( "MenuManagerInitialize" ) -Hooks:RegisterHook( "MenuManagerPostInitialize" ) -function MenuManager.init( self, ... ) - self.orig.init( self, ... ) - Hooks:Call( "MenuManagerInitialize", self ) - Hooks:Call( "MenuManagerPostInitialize", self ) -end - -Hooks:RegisterHook( "MenuManagerOnOpenMenu" ) -function MenuManager.open_menu( self, menu_name, position ) - self.orig.open_menu( self, menu_name, position ) - Hooks:Call( "MenuManagerOnOpenMenu", self, menu_name, position ) -end - -function MenuManager.open_node( self, node_name, parameter_list ) - self.orig.open_node( self, node_name, parameter_list ) -end - -function MenuManager:show_download_progress( mod_name ) - - local dialog_data = {} - dialog_data.title = managers.localization:text("base_mod_download_downloading_mod", { ["mod_name"] = mod_name }) - dialog_data.mod_name = mod_name or "No Mod Name" - - local ok_button = {} - ok_button.cancel_button = true - ok_button.text = managers.localization:text("dialog_ok") - - dialog_data.focus_button = 1 - dialog_data.button_list = { - ok_button - } - - managers.system_menu:show_download_progress( dialog_data ) - -end - --- Add menus -Hooks:Add( "MenuManagerPostInitialize", "MenuManagerPostInitialize_Base", function( menu_manager ) - - local success, err = pcall(function() - - -- Setup lua mods menu - menu_manager:_base_process_menu( - {"menu_main"}, - "mods_options", - "options", - "MenuManager_Base_SetupModsMenu", - "MenuManager_Base_PopulateModsMenu", - "MenuManager_Base_BuildModsMenu" - ) - - -- Setup mod options/keybinds menu - menu_manager:_base_process_menu( - {"menu_main", "menu_pause"}, - "video", - "options", - "MenuManager_Base_SetupModOptionsMenu", - "MenuManager_Base_PopulateModOptionsMenu", - "MenuManager_Base_BuildModOptionsMenu" - ) - - -- Allow custom menus on the main menu (and lobby) and the pause menu - menu_manager:_base_process_menu( {"menu_main"} ) - menu_manager:_base_process_menu( {"menu_pause"} ) - - end) - if not success then - log("[Error] " .. tostring(err)) - end - -end ) - -function MenuManager._base_process_menu( menu_manager, menu_names, parent_menu_name, parent_menu_button, setup_hook, populate_hook, build_hook ) - - for k, v in pairs( menu_names ) do - - local menu = menu_manager._registered_menus[ v ] - if menu then - - local nodes = menu.logic._data._nodes - local hook_id_setup = setup_hook or "MenuManagerSetupCustomMenus" - local hook_id_populate = populate_hook or "MenuManagerPopulateCustomMenus" - local hook_id_build = build_hook or "MenuManagerBuildCustomMenus" - - MenuHelper:SetupMenu( nodes, parent_menu_name or "video" ) - MenuHelper:SetupMenuButton( nodes, parent_menu_button or "options" ) - - Hooks:RegisterHook( hook_id_setup ) - Hooks:RegisterHook( hook_id_populate ) - Hooks:RegisterHook( hook_id_build ) - - Hooks:Call( hook_id_setup, menu_manager, nodes ) - Hooks:Call( hook_id_populate, menu_manager, nodes ) - Hooks:Call( hook_id_build, menu_manager, nodes ) - - end - - end - -end - --- Add lua mods menu -function ModMenuCreator.modify_node(self, original_node, data) - - ModMenuCreator._mod_menu_modifies = { - [ LuaModManager.Constants._lua_mods_menu_id ] = "create_lua_mods_menu" - } - - local node_name = original_node._parameters.name - if self._mod_menu_modifies then - if self._mod_menu_modifies[node_name] then - - local func = self._mod_menu_modifies[node_name] - local node = original_node - self[func](self, node, data) - - return node - - end - end - - return self.orig.modify_node(self, original_node, data) - -end - -function ModMenuCreator.create_lua_mods_menu(self, node) - - node:clean_items() - - local C = LuaModManager.Constants - local sorted_mods = {} - local mods = {} - local conflicted_content = {} - local modded_content = {} - - local text = function(str) - return managers.localization:text(str) - end - - local add_hooks_list = function( content_table, hooks_table, title ) - local _hooks = {} - local hooks_str = "" - if type(hooks_table) == "table" then - for x, y in pairs( hooks_table ) do - local hook = y[ C.mod_hook_id_key ] - if not _hooks[ hook ] then - hooks_str = hooks_str .. " " .. tostring(hook) .. "\n" - _hooks[ hook ] = true - end - end - end - if not string.is_nil_or_empty(hooks_str) then - table.insert( content_table, text(title) .. ":\n" .. hooks_str ) - end - end - - local add_persist_scripts_list = function( content_table, persist_table, title ) - local str = "" - if type( persist_table ) == "table" then - local pattern = " [{1}] = {2}\n" - for k, v in pairs( persist_table ) do - str = str .. pattern - str = str:gsub("{1}", v[C.mod_persists_global_key]) - str = str:gsub("{2}", v[C.mod_script_path_key]) - end - end - if not string.is_nil_or_empty(str) then - table.insert( content_table, text(title) .. ":\n" .. str ) - end - end - - local add_keybinds_list = function( content_table, keybinds_table, title ) - local str = "" - if type( keybinds_table ) == "table" then - local pattern = " [{1}] {2}" - for id, keybind in pairs( keybinds_table ) do - - local keybind_id = keybind[ C.mod_keybind_id_key ] - local keybind_name = keybind[ C.mod_keybind_name_key ] - local key = LuaModManager:GetPlayerKeybind( keybind_id ) or "Not Set" - - str = str .. pattern - str = str:gsub("{1}", key) - str = str:gsub("{2}", keybind_name) - - end - end - if not string.is_nil_or_empty(str) then - table.insert( content_table, text(title) .. ":\n" .. str ) - end - end - - for k, v in pairs( LuaModManager.Mods ) do - - local mod_disabled = not LuaModManager:WasModEnabledAtLoadTime( v.path ) - local mod_flagged = LuaModManager:IsFlaggedForEnabledChange( v.path ) - local path = v.path - local info = v.definition - local mod_tag = " [{0}]" - local mod_id = info[ C.mod_name_key ] or text("base_mod_info_no_name") - local mod_name = mod_id - local mod_desc = info[ C.mod_desc_key ] or text("base_mod_info_no_desc") - local mod_version = info[ C.mod_version_key ] or nil - local mod_author = info[ C.mod_author_key ] or text("base_mod_info_no_author") - local mod_contact = info[ C.mod_contact_key ] or text("base_mod_info_no_contact") - local mod_hooks = info[ C.mod_hooks_key ] or text("base_mod_info_no_hooks") - local mod_prehooks = info[ C.mod_prehooks_key ] or text("base_mod_info_no_prehooks") - local mod_persist_scripts = info[ C.mod_persists_key ] or text("base_mod_info_no_persist_scripts") - local mod_keybinds = info[ C.mod_keybinds_key ] or text("base_mod_info_no_keybinds") - - local name_iterator = 0 - while mods[mod_id] ~= nil do - name_iterator = name_iterator + 1 - mod_id = string.format("%s_%i", mod_name, name_iterator) - end - - table.insert(sorted_mods, mod_id) - mods[mod_id] = { - content = {}, - conflicted = {}, - title = nil - } - - local title_str = mod_name - if mod_flagged then - title_str = title_str .. mod_tag:gsub( "{0}", mod_disabled and text("base_mod_info_to_be_enabled") or text("base_mod_info_to_be_disabled") ) - else - title_str = title_str .. ( mod_disabled and mod_tag:gsub( "{0}", text("base_mod_info_disabled") ) or "" ) - end - mods[mod_id].title = title_str - - local content = mods[mod_id].content - table.insert( content, mod_desc ) - if mod_version then - table.insert( content, text("base_mod_info_version") .. ": " .. mod_version ) - end - table.insert( content, text("base_mod_info_author") .. ": " .. mod_author ) - table.insert( content, text("base_mod_info_contact") .. ": " .. mod_contact ) - table.insert( content, text("base_mod_info_path") .. ": " .. path ) - add_keybinds_list( content, mod_keybinds, "base_mod_info_keybinds" ) - add_hooks_list( content, mod_prehooks, "base_mod_info_prehooks" ) - add_hooks_list( content, mod_hooks, "base_mod_info_hooks" ) - add_persist_scripts_list( content, mod_persist_scripts, "base_mod_info_persist" ) - - MenuCallbackHandler.base_toggle_lua_mod = function(self, item) - if item and item._parameters.mod_path then - - local path_id = item._parameters.mod_path - local text_id = item._parameters.text_id - LuaModManager:ToggleModState( path_id ) - - local disabled = item:value() == "off" and true or false - local node_title = "" - if C.always_active_mods[path_id] then - item:set_value("on") - node_title = text_id .. mod_tag:gsub( "{0}", text("base_mod_info_disabled_impossible") ) - else - node_title = text_id .. mod_tag:gsub( "{0}", disabled and text("base_mod_info_to_be_disabled") or text("base_mod_info_to_be_enabled") ) - end - node._parameters.mods[text_id].title = node_title - - local gui = MenuCallbackHandler._current_mod_info_gui - if gui then - gui:set_mod_info(item) - end - - end - end - - local params = { - name = mod_id, - text_id = mod_name, - mod_path = path, - localize = false, - enabled = true, - callback = "base_toggle_lua_mod", - hightlight_color = mod_disabled and tweak_data.menu.default_disabled_text_color, - row_item_color = mod_disabled and tweak_data.menu.default_disabled_text_color, - } - local toggle = self:create_toggle(node, params) - toggle:set_value( mod_disabled and "off" or "on" ) - if mod_flagged then - toggle:set_value( mod_disabled and "on" or "off" ) - end - - end - - self:add_back_button(node) - - node:parameters().mods = mods - node:parameters().sorted_mods = sorted_mods - node:parameters().conflicted_content = conflicted_content - node:parameters().modded_content = modded_content - - -end - -function MenuModInfoGui.set_mod_info(self, item) - - -- This is ugly as hell, but at least it gets us an easily usable reference to the mod gui - MenuCallbackHandler._current_mod_info_gui = self - - self.mod_info_panel:clear() - - if alive(self._scroll_bar_panel) then - self.safe_rect_panel:remove(self._scroll_bar_panel) - end - - self._scroll_bar_panel = nil - if self._scroll_up_box then - self._scroll_up_box:close() - self._scroll_up_box = nil - end - - if self._scroll_down_box then - self._scroll_down_box:close() - self._scroll_down_box = nil - end - - if self.safe_rect_panel:child("info_title") then - self.safe_rect_panel:remove(self.safe_rect_panel:child("info_title")) - end - - local params = item:parameters() or {} - if params.back or params.pd2_corner then - return - end - - local mods = self.node:parameters().mods - local modded_content = self.node:parameters().modded_content - local mod_name = params.name - local mod_data = mods and mods[mod_name] - local conflicted_panel = self.mod_info_panel:panel({name = "conflicted", y = 10}) - local modded_panel = self.mod_info_panel:panel({name = "modded"}) - local title = self.safe_rect_panel:text({ - name = "info_title", - text = managers.localization:to_upper_text("menu_mods_info_title", {mod = mod_name}), - font = self.medium_font, - font_size = self.medium_font_size, - layer = 1 - }) - - self.make_fine_text(title) - - if mod_data then - - local text = conflicted_panel:text({ - text = managers.localization:to_upper_text("menu_mods_conflict_title"), - font = self.medium_font, - font_size = self.medium_font_size, - layer = 1, - x = 10, - y = 0, - w = conflicted_panel:w() - 20 - }) - - local _, _, _, h = text:text_rect() - text:set_h(h) - local cy = h - local conflict_text_title = text - conflict_text_title:hide() - - local text = modded_panel:text({ - text = mod_data.title or managers.localization:to_upper_text("menu_mods_modded_title"), - font = self.medium_font, - font_size = self.medium_font_size, - layer = 1, - x = 10, - y = 0, - w = conflicted_panel:w() - 20 - }) - - local _, _, _, h = text:text_rect() - text:set_h(h) - local my = h - local mod_text_title = text - mod_text_title:hide() - local conflicted_mods = {} - - for _, path in ipairs(mod_data.content) do - - if mod_data.conflicted[Idstring(path):key()] then - - for _, conflict_mod in ipairs(mod_data.conflicted[Idstring(path):key()]) do - if conflict_mod ~= mod_name then - conflicted_mods[conflict_mod] = conflicted_mods[conflict_mod] or {} - table.insert(conflicted_mods[conflict_mod], path) - end - end - - conflict_text_title:show() - - else - - text = modded_panel:text({ - text = path, - font = self.small_font, - font_size = self.small_font_size, - layer = 1, - x = 20, - y = my, - w = modded_panel:w() - 30, - wrap = true - }) - _, _, _, h = text:text_rect() - text:set_h(h) - text:set_color(tweak_data.screen_colors.text) - my = my + math.ceil(h) - mod_text_title:show() - - end - - end - - local sorted_conflicts = {} - - for mod, conflicts in pairs(conflicted_mods) do - table.insert(sorted_conflicts, mod) - end - - table.sort(sorted_conflicts) - - for _, mod in ipairs(sorted_conflicts) do - - text = conflicted_panel:text({ - text = utf8.to_upper(mod) .. ":", - font = self.small_font, - font_size = self.small_font_size, - layer = 1, - x = 20, - y = cy, - w = conflicted_panel:w() - 30, - wrap = true - }) - _, _, _, h = text:text_rect() - text:set_h(h) - cy = cy + math.ceil(h) - - for _, path in ipairs(conflicted_mods[mod]) do - - text = conflicted_panel:text({ - text = path, - font = self.small_font, - font_size = self.small_font_size, - layer = 1, - x = 25, - y = cy, - w = conflicted_panel:w() - 35, - wrap = true - }) - _, _, _, h = text:text_rect() - text:set_h(h) - text:set_color(tweak_data.screen_colors.important_1) - cy = cy + math.ceil(h) - - end - - cy = cy + 10 - - end - - conflicted_panel:set_h(cy) - modded_panel:set_y(conflict_text_title:visible() and conflicted_panel:bottom() or 10) - modded_panel:set_h(my) - self.mod_info_panel:set_y(0) - self.mod_info_panel:set_h(modded_panel:bottom() + 10) - - if self.mod_info_panel:h() > self._mod_main_panel:h() then - - self._scroll_up_box = BoxGuiObject:new(self._mod_main_panel, { - sides = { - 0, - 0, - 2, - 0 - } - }) - - self._scroll_down_box = BoxGuiObject:new(self._mod_main_panel, { - sides = { - 0, - 0, - 0, - 2 - } - }) - - self._scroll_up_box:hide() - self._scroll_down_box:show() - self._scroll_bar_panel = self.safe_rect_panel:panel({ - name = "scroll_bar_panel", - w = 20, - h = self._mod_main_panel:h() - }) - - self._scroll_bar_panel:set_world_left(self._mod_main_panel:world_right()) - self._scroll_bar_panel:set_world_top(self._mod_main_panel:world_top()) - - local texture, rect = tweak_data.hud_icons:get_icon_data("scrollbar_arrow") - local scroll_up_indicator_arrow = self._scroll_bar_panel:bitmap({ - name = "scroll_up_indicator_arrow", - texture = texture, - texture_rect = rect, - layer = 2, - color = Color.white, - blend_mode = "add" - }) - - scroll_up_indicator_arrow:set_center_x(self._scroll_bar_panel:w() / 2) - - local texture, rect = tweak_data.hud_icons:get_icon_data("scrollbar_arrow") - local scroll_down_indicator_arrow = self._scroll_bar_panel:bitmap({ - name = "scroll_down_indicator_arrow", - texture = texture, - texture_rect = rect, - layer = 2, - color = Color.white, - rotation = 180, - blend_mode = "add" - }) - - scroll_down_indicator_arrow:set_bottom(self._scroll_bar_panel:h()) - scroll_down_indicator_arrow:set_center_x(self._scroll_bar_panel:w() / 2) - - local bar_h = scroll_down_indicator_arrow:top() - scroll_up_indicator_arrow:bottom() - self._scroll_bar_panel:rect({ - color = Color.black, - alpha = 0.05, - y = scroll_up_indicator_arrow:bottom(), - h = bar_h, - w = 4 - }):set_center_x(self._scroll_bar_panel:w() / 2) - bar_h = scroll_down_indicator_arrow:bottom() - scroll_up_indicator_arrow:top() - - local scroll_bar = self._scroll_bar_panel:panel({ - name = "scroll_bar", - layer = 2, - h = bar_h - }) - - local scroll_bar_box_panel = scroll_bar:panel({ - name = "scroll_bar_box_panel", - w = 4, - halign = "scale", - valign = "scale" - }) - - self._scroll_bar_box_class = BoxGuiObject:new(scroll_bar_box_panel, { - sides = { - 2, - 2, - 0, - 0 - } - }) - - self._scroll_bar_box_class:set_aligns("scale", "scale") - self._scroll_bar_box_class:set_blend_mode("add") - scroll_bar_box_panel:set_w(8) - scroll_bar_box_panel:set_center_x(scroll_bar:w() / 2) - scroll_bar:set_top(scroll_up_indicator_arrow:top()) - scroll_bar:set_center_x(scroll_up_indicator_arrow:center_x()) - self:set_scroll_indicators(0) - - end - - end - -end - --- Create this function if it doesn't exist -function MenuCallbackHandler.can_toggle_chat( self ) - if managers and managers.menu then - local input = managers.menu:active_menu() and managers.menu:active_menu().input - return not input or input.can_toggle_chat and input:can_toggle_chat() - else - return true - end -end diff --git a/mods/base/lua/MenuNodeGUI.lua b/mods/base/lua/MenuNodeGUI.lua deleted file mode 100644 index abb3d64..0000000 --- a/mods/base/lua/MenuNodeGUI.lua +++ /dev/null @@ -1,141 +0,0 @@ - -CloneClass( MenuNodeGui ) - -Hooks:RegisterHook("CustomizeControllerOnKeySet") -function MenuNodeGui._key_press(self, o, key, input_id, item, no_add) - - if managers.system_menu:is_active() then - return - end - - if self._skip_first_activate_key then - self._skip_first_activate_key = false - if input_id == "mouse" then - if key == Idstring("0") then - return - end - elseif input_id == "keyboard" and key == Idstring("enter") then - return - end - end - - local row_item = self:row_item(item) - if key == Idstring("esc") then - if not item._parameters.is_custom_keybind then - self:_end_customize_controller(o, item) - return - end - end - if input_id ~= "mouse" or not Input:mouse():button_name_str(key) then - end - local key_name = "" .. ( key == Idstring("esc") and "" or Input:keyboard():button_name_str(key) ) - if not no_add and input_id == "mouse" then - key_name = "mouse " .. key_name or key_name - end - - local forbidden_btns = { - "esc", - "tab", - "num abnt c1", - "num abnt c2", - "@", - "ax", - "convert", - "kana", - "kanji", - "no convert", - "oem 102", - "stop", - "unlabeled", - "yen", - "mouse 8", - "mouse 9", - "" - } - - if not key_name:is_nil_or_empty() then - for _, btn in ipairs(forbidden_btns) do - if Idstring(btn) == key then - managers.menu:show_key_binding_forbidden({KEY = key_name}) - self:_end_customize_controller(o, item) - return - end - end - end - - local connections = managers.controller:get_settings(managers.controller:get_default_wrapper_type()):get_connection_map() - for _, name in ipairs(MenuCustomizeControllerCreator.CONTROLS) do - - local connection = connections[name] - if connection._btn_connections then - - for name, btn_connection in pairs(connection._btn_connections) do - if btn_connection.name == key_name and item:parameters().binding ~= btn_connection.name then - managers.menu:show_key_binding_collision({ - KEY = key_name, - MAPPED = managers.localization:text(MenuCustomizeControllerCreator.CONTROLS_INFO[name].text_id) - }) - self:_end_customize_controller(o, item) - return - end - end - - else - - for _, b_name in ipairs(connection:get_input_name_list()) do - if tostring(b_name) == key_name and item:parameters().binding ~= b_name then - managers.menu:show_key_binding_collision({ - KEY = key_name, - MAPPED = managers.localization:text(MenuCustomizeControllerCreator.CONTROLS_INFO[name].text_id) - }) - self:_end_customize_controller(o, item) - return - end - end - - end - - end - - if item:parameters().axis then - - connections[item:parameters().axis]._btn_connections[item:parameters().button].name = key_name - managers.controller:set_user_mod(item:parameters().connection_name, { - axis = item:parameters().axis, - button = item:parameters().button, - connection = key_name - }) - item:parameters().binding = key_name - - local conn = connections[item:parameters().axis] - local key_button = conn._input_name_list[1] - Hooks:Call( "CustomizeControllerOnKeySet", item:parameters().connection_name, key_button ) - - else - - if connections[item:parameters().button] == nil then - for k, v in pairs( connections ) do - connections[item:parameters().button] = clone(v) - break - end - connections[item:parameters().button]._name = item:parameters().connection_name - end - connections[item:parameters().button]:set_controller_id(input_id) - connections[item:parameters().button]:set_input_name_list({key_name}) - managers.controller:set_user_mod(item:parameters().connection_name, { - button = item:parameters().button, - connection = key_name, - controller_id = input_id - }) - item:parameters().binding = key_name - - local conn = connections[item:parameters().button] - local key_button = conn._input_name_list[1] - Hooks:Call( "CustomizeControllerOnKeySet", item:parameters().connection_name, key_button ) - - end - - managers.controller:rebind_connections() - self:_end_customize_controller(o, item) - -end diff --git a/mods/base/lua/MenuSetup.lua b/mods/base/lua/MenuSetup.lua deleted file mode 100644 index f6b504a..0000000 --- a/mods/base/lua/MenuSetup.lua +++ /dev/null @@ -1,14 +0,0 @@ - -CloneClass( MenuSetup ) - -Hooks:RegisterHook("MenuUpdate") -function MenuSetup.update(self, t, dt) - self.orig.update(self, t, dt) - Hooks:Call("MenuUpdate", t, dt) -end - -Hooks:RegisterHook("SetupOnQuit") -function MenuSetup.quit(self) - Hooks:Call("SetupOnQuit", self) - return self.orig.quit(self) -end diff --git a/mods/base/lua/NetworkManager.lua b/mods/base/lua/NetworkManager.lua deleted file mode 100644 index f14c457..0000000 --- a/mods/base/lua/NetworkManager.lua +++ /dev/null @@ -1,7 +0,0 @@ -CloneClass(NetworkManager) - -Hooks:Register("NetworkManagerOnPeerAdded") -function NetworkManager.on_peer_added(self, peer, peer_id) - self.orig.on_peer_added(self, peer, peer_id) - Hooks:Call("NetworkManagerOnPeerAdded", peer, peer_id) -end diff --git a/mods/base/lua/SystemMenuManager.lua b/mods/base/lua/SystemMenuManager.lua deleted file mode 100644 index b1f789e..0000000 --- a/mods/base/lua/SystemMenuManager.lua +++ /dev/null @@ -1,11 +0,0 @@ - -core:module("SystemMenuManager") -require("lib/managers/dialogs/SpecializationDialog") - -GenericSystemMenuManager.GENERIC_DOWNLOAD_PROGRESS_CLASS = DownloadProgressDialog -GenericSystemMenuManager.DOWNLOAD_PROGRESS_CLASS = DownloadProgressDialog - -function GenericSystemMenuManager:show_download_progress( data ) - local success = self:_show_class(data, self.GENERIC_DOWNLOAD_PROGRESS_CLASS, self.DOWNLOAD_PROGRESS_CLASS, data.force) - self:_show_result(success, data) -end diff --git a/mods/base/mod.txt b/mods/base/mod.txt deleted file mode 100644 index 1617f74..0000000 --- a/mods/base/mod.txt +++ /dev/null @@ -1,96 +0,0 @@ -{ - "name" : "Payday 2 BLT", - "description" : "The collection of lua files that allow the lua hook to function", - "author" : "James Wilkinson", - "contact" : "jw@jameswilko.com", - "version" : "1.0", - "priority" : 1001, - "updates" : [ - { - "revision" : 11, - "identifier" : "payday2blt" - }, - { - "revision" : "./mods/saves/blt_revision.txt", - "identifier" : "payday2bltdll", - "install_dir" : ".", - "display_name" : "Payday 2 BLT Hook DLL" - } - ], - "pre_hooks" : [ - { "hook_id" : "lib/entry", "script_path" : "req/utils.lua" }, - { "hook_id" : "lib/entry", "script_path" : "req/localization.lua" }, - { "hook_id" : "lib/entry", "script_path" : "req/menus.lua" }, - { "hook_id" : "lib/entry", "script_path" : "req/network.lua" }, - { "hook_id" : "lib/entry", "script_path" : "req/persist_scripts.lua" }, - { "hook_id" : "lib/entry", "script_path" : "req/quick_menu.lua" }, - { "hook_id" : "lib/entry", "script_path" : "req/update_mods.lua" }, - { "hook_id" : "lib/entry", "script_path" : "req/update_mods_menu.lua" }, - { "hook_id" : "lib/entry", "script_path" : "req/notifications.lua" } - ], - "hooks" : [ - { "hook_id" : "core/lib/utils/coreclass", - "script_path" : "req/hooks.lua" - }, - { "hook_id" : "core/lib/utils/coreclass", - "script_path" : "req/delayed_calls.lua" - }, - { "hook_id" : "core/lib/system/corepatchlua", - "script_path" : "lua/CorePatchLua.lua" - }, - { "hook_id" : "lib/managers/localizationmanager", - "script_path" : "lua/LocalizationManager.lua" - }, - { "hook_id" : "lib/managers/menumanager", - "script_path" : "lua/MenuManager.lua" - }, - { "hook_id" : "lib/setups/gamesetup", - "script_path" : "lua/GameSetup.lua" - }, - { "hook_id" : "lib/setups/menusetup", - "script_path" : "lua/MenuSetup.lua" - }, - { "hook_id" : "lib/managers/menu/menunodegui", - "script_path" : "lua/MenuNodeGUI.lua" - }, - { "hook_id" : "lib/managers/menu/items/menuitemcustomizecontroller", - "script_path" : "lua/MenuItemCustomizeController.lua" - }, - { "hook_id" : "core/lib/managers/menu/items/coremenuitemslider", - "script_path" : "lua/CoreMenuItemSlider.lua" - }, - { "hook_id" : "core/lib/managers/menu/coremenulogic", - "script_path" : "lua/CoreMenuLogic.lua" - }, - { "hook_id" : "lib/managers/chatmanager", - "script_path" : "lua/ChatManager.lua" - }, - { "hook_id" : "lib/managers/menumanager", - "script_path" : "req/lua_mods_menu.lua" - }, - { "hook_id" : "lib/managers/menumanager", - "script_path" : "req/mod_keybinds.lua" - }, - { "hook_id" : "lib/managers/menu/menucomponentmanager", - "script_path" : "lua/MenuComponentManager.lua" - }, - { "hook_id" : "lib/managers/menu/playerprofileguiobject", - "script_path" : "req/notifications_gui_object.lua" - }, - { "hook_id" : "lib/managers/dialogs/specializationdialog", - "script_path" : "req/download_progress_dialog.lua" - }, - { "hook_id" : "lib/managers/menu/specializationboxgui", - "script_path" : "req/download_progress_box_gui.lua" - }, - { "hook_id" : "lib/managers/systemmenumanager", - "script_path" : "lua/SystemMenuManager.lua" - }, - { "hook_id" : "lib/network/base/basenetworksession", - "script_path" : "lua/BaseNetworkSession.lua" - }, - { "hook_id" : "lib/network/base/networkmanager", - "script_path" : "lua/NetworkManager.lua" - } - ] -} diff --git a/mods/base/req/delayed_calls.lua b/mods/base/req/delayed_calls.lua deleted file mode 100644 index 688813b..0000000 --- a/mods/base/req/delayed_calls.lua +++ /dev/null @@ -1,62 +0,0 @@ - -DelayedCalls = DelayedCalls or {} -DelayedCalls._calls = DelayedCalls._calls or {} - -Hooks:Add("MenuUpdate", "MenuUpdate_Queue", function( t, dt ) - DelayedCalls:Update(t, dt) -end) - -Hooks:Add("GameSetupUpdate", "GameSetupUpdate_Queue", function( t, dt ) - DelayedCalls:Update(t, dt) -end) - -function DelayedCalls:Update( time, deltaTime ) - - local t = {} - - for k, v in pairs( self._calls ) do - - if v ~= nil then - - v.currentTime = v.currentTime + deltaTime - if v.currentTime > v.timeToWait then - if v.functionCall then - v.functionCall() - end - v = nil - else - table.insert(t, v) - end - - end - - end - - self._calls = t - -end - ---[[ - DelayedCalls:Add( id, time, func ) - Adds a function to be automatically called after a set delay - id, Unique identifier for this delayed call - time, Time in seconds to call the specified function after - func, Function call to call after the time runs out -]] -function DelayedCalls:Add( id, time, func ) - local queuedFunc = { - functionCall = func, - timeToWait = time, - currentTime = 0 - } - self._calls[id] = queuedFunc -end - ---[[ - DelayedCalls:Remove( id ) - Removes a scheduled call before it can be automatically called - id, Unique identifier for the delayed call remove -]] -function DelayedCalls:Remove( id ) - self._calls[id] = nil -end diff --git a/mods/base/req/download_progress_box_gui.lua b/mods/base/req/download_progress_box_gui.lua deleted file mode 100644 index 5722d4c..0000000 --- a/mods/base/req/download_progress_box_gui.lua +++ /dev/null @@ -1,163 +0,0 @@ - -DownloadProgressBoxGui = DownloadProgressBoxGui or class(TextBoxGui) -DownloadProgressBoxGui.TEXT = "" - -function DownloadProgressBoxGui:init(...) - local ws, title, text, content_data, config = ... - config.forced_h = 100 - config.w = 600 - config.is_title_outside = true - DownloadProgressBoxGui.super.init(self, ...) -end - -local make_fine_text = function(text) - local x, y, w, h = text:text_rect() - text:set_size(w, h) - text:set_position(math.round(text:x()), math.round(text:y())) -end - -function DownloadProgressBoxGui:_create_text_box(ws, title, text, content_data, config) - - local panel = DownloadProgressBoxGui.super._create_text_box(self, ws, title, text, content_data, config) - local small_text = { - text = "", - layer = 1, - font = tweak_data.menu.pd2_small_font, - font_size = tweak_data.menu.pd2_small_font_size, - blend_mode = "add" - } - - local medium_text = { - text = "", - layer = 1, - font = tweak_data.menu.pd2_medium_font, - font_size = tweak_data.menu.pd2_medium_font_size, - blend_mode = "add" - } - - local progress_text = self._scroll_panel:text(medium_text) - progress_text:set_position(10, 30) - progress_text:set_text( "000%" ) - make_fine_text(progress_text) - - local progress_bg = self._scroll_panel:rect({ - h = progress_text:h(), - color = Color.black, - alpha = 0.4, - layer = 1 - }) - progress_bg:set_position(progress_text:right() + 4, progress_text:top()) - progress_bg:set_w(self._scroll_panel:w() - progress_bg:left() - 5) - - local progress_bar = self._scroll_panel:rect({ - color = Color.white, - alpha = 1, - layer = 2, - blend_mode = "add" - }) - progress_bar:set_shape(progress_bg:shape()) - progress_bar:set_w(0) - progress_bar:grow(0, -4) - progress_bar:move(2, 0) - progress_bar:set_center_y(progress_bg:center_y()) - - local progress_end = self._scroll_panel:rect({ - color = Color.white, - alpha = 1, - layer = 3, - blend_mode = "add" - }) - progress_end:set_shape(progress_bg:shape()) - progress_end:set_w(2) - progress_end:grow(0, -4) - progress_end:set_center_y(progress_bg:center_y()) - progress_end:set_right(progress_bg:right()) - - local download_amt_text = self._scroll_panel:text(small_text) - download_amt_text:set_text(managers.localization:to_upper_text("base_mod_download_download_progress")) - make_fine_text(download_amt_text) - download_amt_text:set_position(progress_bg:left(), progress_bg:bottom() + 2) - - self._panel:set_y(math.round(self._panel:y())) - self._scroll_panel:set_y(math.round(self._scroll_panel:y())) - self._anim_data = { - progress_bar = progress_bar, - progress_text = progress_text, - download_amt_text = download_amt_text, - - start_progress_width = 0, - progress_width = 0, - end_progress_width = progress_end:right() - progress_bar:left(), - - bytes_downloaded = 0, - bytes_total = 0, - } - - -end - -function DownloadProgressBoxGui:chk_close() - return self._anim_data.download_complete -end - -function DownloadProgressBoxGui._update(o, self) - - local init_done = false - while not init_done do - init_done = not not self._anim_data - coroutine.yield() - end - wait(1) - -- managers.menu_component:post_event("count_1") - - -- Download Progress - while self._anim_data and not self._anim_data.mod_download_complete and not self._anim_data.mod_download_failed do - - coroutine.yield() - - local bytes_down = math.round(self._anim_data.bytes_downloaded / 1024) - local bytes_total = math.round(self._anim_data.bytes_total / 1024) - local bytes_tbl = { - ["downloaded"] = bytes_down, - ["total"] = bytes_total - } - local t = 0 - if self._anim_data.bytes_downloaded > 0 and self._anim_data.bytes_total > 0 then - t = self._anim_data.bytes_downloaded / self._anim_data.bytes_total - end - - self._anim_data.progress_width = math.lerp(self._anim_data.start_progress_width, self._anim_data.end_progress_width, t) - self._anim_data.progress_bar:set_width(self._anim_data.progress_width) - - self._anim_data.progress_text:set_text( string.format("%000.f %%", t * 100) ) - self._anim_data.download_amt_text:set_text( managers.localization:to_upper_text("base_mod_download_download_progress", bytes_tbl) ) - - end - - managers.menu_component:post_event("count_1_finished") - - -- Extract Progress - self._anim_data.download_amt_text:set_text( managers.localization:to_upper_text("base_mod_download_download_progress_extract") ) - make_fine_text( self._anim_data.download_amt_text ) - - while self._anim_data and not self._anim_data.mod_extraction_complete and not self._anim_data.mod_download_failed do - coroutine.yield() - end - - managers.menu_component:post_event("count_1_finished") - - -- Download Complete or Failed - if not self._anim_data.mod_download_failed then - -- Complete - self._anim_data.download_amt_text:set_text( managers.localization:to_upper_text("base_mod_download_download_progress_complete") ) - make_fine_text( self._anim_data.download_amt_text ) - else - -- Failed - self._anim_data.download_amt_text:set_text( managers.localization:to_upper_text("base_mod_download_download_progress_failed") ) - make_fine_text( self._anim_data.download_amt_text ) - end - - self._anim_data.progress_bar:set_width( not self._anim_data.mod_download_failed and self._anim_data.end_progress_width or 0 ) - self._anim_data.download_complete = true - -end diff --git a/mods/base/req/download_progress_dialog.lua b/mods/base/req/download_progress_dialog.lua deleted file mode 100644 index 25af2ea..0000000 --- a/mods/base/req/download_progress_dialog.lua +++ /dev/null @@ -1,102 +0,0 @@ - -local LuaModUpdates = _G.LuaModUpdates -core:module("SystemMenuManager") -require("lib/managers/dialogs/GenericDialog") -DownloadProgressDialog = DownloadProgressDialog or class(GenericDialog) - -function DownloadProgressDialog:init(manager, data, is_title_outside) - - Dialog.init(self, manager, data) - if not self._data.focus_button then - if #self._button_text_list > 0 then - self._data.focus_button = #self._button_text_list - else - self._data.focus_button = 1 - end - end - self._ws = self._data.ws or manager:_get_ws() - local text_config = { - title_font = data.title_font, - title_font_size = data.title_font_size, - font = data.font, - font_size = data.font_size, - w = data.w or 420, - h = data.h or 400, - no_close_legend = true, - no_scroll_legend = true, - use_indicator = data.indicator or data.no_buttons, - is_title_outside = is_title_outside, - use_text_formating = data.use_text_formating, - text_formating_color = data.text_formating_color, - text_formating_color_table = data.text_formating_color_table, - text_blend_mode = data.text_blend_mode - } - self._panel_script = _G.DownloadProgressBoxGui:new(self._ws, self._data.title or "", self._data.text or "", self._data, text_config) - self._panel_script:add_background() - self._panel_script:set_layer(_G.tweak_data.gui.DIALOG_LAYER) - self._panel_script:set_centered() - self._panel_script:set_fade(0) - self._controller = self._data.controller or manager:_get_controller() - self._confirm_func = callback(self, self, "button_pressed_callback") - self._cancel_func = callback(self, self, "dialog_cancel_callback") - self._resolution_changed_callback = callback(self, self, "resolution_changed_callback") - managers.viewport:add_resolution_changed_func(self._resolution_changed_callback) - if data.counter then - self._counter = data.counter - self._counter_time = self._counter[1] - end - self._sound_event = data.sound_event - - LuaModUpdates:RegisterDownloadDialog( self ) - -end - -function DownloadProgressDialog:button_pressed_callback() - self._download_complete = self._panel_script:chk_close() - if self._download_complete then - DownloadProgressDialog.super.button_pressed_callback(self) - end -end - -function DownloadProgressDialog:dialog_cancel_callback() - self._download_complete = self._panel_script:chk_close() - if self._download_complete then - DownloadProgressDialog.super.dialog_cancel_callback(self) - end -end - -function DownloadProgressDialog:fade_in() - DownloadProgressDialog.super.fade_in(self) - self._start_sound_t = self._sound_event and TimerManager:main():time() + 0.2 -end - -function DownloadProgressDialog:update(t, dt) - DownloadProgressDialog.super.update(self, t, dt) - if self._start_sound_t and t > self._start_sound_t then - managers.menu_component:post_event(self._sound_event) - self._start_sound_t = nil - end -end - -function DownloadProgressDialog:fade_out_close() - self._download_complete = self._panel_script:chk_close() - if self._download_complete then - self:fade_out() - end - managers.menu:post_event("prompt_exit") -end - -function DownloadProgressDialog:remove_mouse() - if not self._download_complete then - return - end - if not self._removed_mouse then - self._removed_mouse = true - if managers.controller:get_default_wrapper_type() == "pc" then - managers.mouse_pointer:remove_mouse(self._mouse_id) - else - managers.mouse_pointer:enable() - end - self._mouse_id = nil - end -end diff --git a/mods/base/req/hooks.lua b/mods/base/req/hooks.lua deleted file mode 100644 index 2472777..0000000 --- a/mods/base/req/hooks.lua +++ /dev/null @@ -1,313 +0,0 @@ - -_G.Hooks = Hooks or {} -Hooks._registered_hooks = Hooks._registered_hooks or {} -Hooks._prehooks = Hooks._prehooks or {} -Hooks._posthooks = Hooks._posthooks or {} - ---[[ - Hooks:Register( key ) - Registers a hook so that functions can be added to it, and later called - key, Unique identifier for the hook, so that hooked functions can be added to it -]] -function Hooks:RegisterHook( key ) - self._registered_hooks[key] = self._registered_hooks[key] or {} -end - ---[[ - Hooks:Register( key ) - Functionaly the same as Hooks:RegisterHook -]] -function Hooks:Register( key ) - self:RegisterHook( key ) -end - ---[[ - Hooks:AddHook( key, id, func ) - Adds a function call to a hook, so that it will be called when the hook is - key, The unique identifier of the hook to be called on - id, A unique identifier for this specific function call - func, The function to call with the hook -]] -function Hooks:AddHook( key, id, func ) - self._registered_hooks[key] = self._registered_hooks[key] or {} - -- Update existing hook - for k, v in pairs( self._registered_hooks[key] ) do - if v.id == id then - v.func = func - return - end - end - -- Add new hook, if id doesn't exist - local tbl = { - id = id, - func = func - } - table.insert( self._registered_hooks[key], tbl ) -end - ---[[ - Hooks:Add( key, id, func ) - Functionaly the same as Hooks:AddHook -]] -function Hooks:Add( key, id, func ) - self:AddHook( key, id, func ) -end - ---[[ - Hooks:UnregisterHook( key ) - Removes a hook, so that it will not call any functions - key, The unique identifier of the hook to unregister -]] -function Hooks:UnregisterHook( key ) - self._registered_hooks[key] = nil -end - ---[[ - Hooks:Unregister( key ) - Functionaly the same as Hooks:UnregisterHook -]] -function Hooks:Unregister( key ) - self:UnregisterHook( key ) -end - ---[[ - Hooks:Remove( id ) - Removes a hooked function call with the specified id to prevent it from being called - id, Removes the function call and prevents it from being called -]] -function Hooks:Remove( id ) - - for k, v in pairs(self._registered_hooks) do - if type(v) == "table" then - for x, y in pairs( v ) do - if y.id == id then - y = nil - end - end - end - end - -end - ---[[ - Hooks:Call( key, ... ) - Calls a specified hook, and all of its hooked functions - key, The unique identifier of the hook to call its hooked functions - args, The arguments to pass to the hooked functions -]] -function Hooks:Call( key, ... ) - - if not self._registered_hooks[key] then - return - end - - for k, v in pairs(self._registered_hooks[key]) do - if v then - if type(v.func) == "function" then - v.func( ... ) - end - end - end - -end - ---[[ - Hooks:ReturnCall( key, ... ) - Calls a specified hook, and returns the first non-nil value returned by a hooked function - key, The unique identifier of the hook to call its hooked functions - args, The arguments to pass to the hooked functions - returns, The first non-nil value returned by a hooked function -]] -function Hooks:ReturnCall( key, ... ) - - if not self._registered_hooks[key] then - return - end - - for k, v in pairs(self._registered_hooks[key]) do - if v then - if type(v.func) == "function" then - - -- Holy hell would you look at this shit - local r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, r26, r27, r28, r29, r30, r31, r32 = v.func( ... ) - if r1 ~= nil then - return r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, r26, r27, r28, r29, r30, r31, r32 - end - - end - end - end - -end - ---[[ - Hooks:PreHook( object, func, id, pre_call ) - Automatically hooks a function to be called before the specified function on a specified object - object, The object for the hooked function to be called on - func, The name of the function (as a string) on the object for the hooked call to be ran before - id, The unique identifier for this prehook - pre_call, The function to be called before the func on object -]] -function Hooks:PreHook( object, func, id, pre_call ) - - if not object then - self:_PrePostHookError(func) - return - end - - if object and self._prehooks[object] == nil then - self._prehooks[object] = {} - end - - if object and self._prehooks[object][func] == nil then - - self._prehooks[object][func] = { - original = object[func], - overrides = {} - } - - object[func] = function(...) - - local hooked_func = self._prehooks[object][func] - local r, _r - - for k, v in ipairs(hooked_func.overrides) do - if v.func then - _r = v.func(...) - end - if _r then - r = _r - end - end - - _r = hooked_func.original(...) - if _r then - r = _r - end - - return r - - end - - end - - for k, v in pairs( self._prehooks[object][func].overrides ) do - if v.id == id then - return - end - end - - local func_tbl = { - id = id, - func = pre_call, - } - table.insert( self._prehooks[object][func].overrides, func_tbl ) - -end - ---[[ - Hooks:RemovePreHook( id ) - Removes the prehook with id, and prevents it from being run - id, The unique identifier of the prehook to remove -]] -function Hooks:RemovePreHook( id ) - - for object_i, object in pairs( self._prehooks ) do - for func_i, func in pairs( object ) do - for override_i, override in ipairs( func.overrides ) do - if override and override.id == id then - table.remove( func.overrides, override_i ) - end - end - end - end - -end - ---[[ - Hooks:PostHook( object, func, id, post_call ) - Automatically hooks a function to be called after the specified function on a specified object - object, The object for the hooked function to be called on - func, The name of the function (as a string) on the object for the hooked call to be ran after - id, The unique identifier for this posthook - post_call, The function to be called after the func on object -]] -function Hooks:PostHook( object, func, id, post_call ) - - if not object then - self:_PrePostHookError(func) - return - end - - if object and self._posthooks[object] == nil then - self._posthooks[object] = {} - end - - if object and self._posthooks[object][func] == nil then - - self._posthooks[object][func] = { - original = object[func], - overrides = {} - } - - object[func] = function(...) - - local hooked_func = self._posthooks[object][func] - local r, _r - - _r = hooked_func.original(...) - if _r then - r = _r - end - - for k, v in ipairs(hooked_func.overrides) do - if v.func then - _r = v.func(...) - end - if _r then - r = _r - end - end - - return r - - end - - end - - for k, v in pairs( self._posthooks[object][func].overrides ) do - if v.id == id then - return - end - end - - local func_tbl = { - id = id, - func = post_call, - } - table.insert( self._posthooks[object][func].overrides, func_tbl ) - -end - ---[[ - Hooks:RemovePostHook( id ) - Removes the posthook with id, and prevents it from being run - id, The unique identifier of the posthook to remove -]] -function Hooks:RemovePostHook( id ) - - for object_i, object in pairs( self._posthooks ) do - for func_i, func in pairs( object ) do - for override_i, override in ipairs( func.overrides ) do - if override and override.id == id then - table.remove( func.overrides, override_i ) - end - end - end - end - -end - -function Hooks:_PrePostHookError( func ) - log("[Hooks] Error: Could not hook function '", tostring(func), "'!") -end diff --git a/mods/base/req/json.lua b/mods/base/req/json.lua deleted file mode 100644 index 6c54130..0000000 --- a/mods/base/req/json.lua +++ /dev/null @@ -1,521 +0,0 @@ ------------------------------------------------------------------------------ --- JSON4Lua: JSON encoding / decoding support for the Lua language. --- json Module. --- Author: Craig Mason-Jones --- Homepage: http://json.luaforge.net/ --- Version: 0.9.50 --- This module is released under the MIT License (MIT). --- Please see LICENCE.txt for details. --- --- USAGE: --- This module exposes two functions: --- encode(o) --- Returns the table / string / boolean / number / nil / json.null value as a JSON-encoded string. --- decode(json_string) --- Returns a Lua object populated with the data encoded in the JSON string json_string. --- --- REQUIREMENTS: --- compat-5.1 if using Lua 5.0 --- --- CHANGELOG --- 0.9.50 Radical performance improvement on decode from Eike Decker. Many thanks! --- 0.9.40 Changed licence to MIT License (MIT) --- 0.9.20 Introduction of local Lua functions for private functions (removed _ function prefix). --- Fixed Lua 5.1 compatibility issues. --- Introduced json.null to have null values in associative arrays. --- encode() performance improvement (more than 50%) through table.concat rather than .. --- Introduced decode ability to ignore /**/ comments in the JSON string. --- 0.9.10 Fix to array encoding / decoding to correctly manage nil/null values in arrays. ------------------------------------------------------------------------------ - ------------------------------------------------------------------------------ --- Imports and dependencies ------------------------------------------------------------------------------ -local math = require('math') -local string = require("string") -local table = require("table") -local tostring = tostring - -local base = _G - ------------------------------------------------------------------------------ --- Module declaration ------------------------------------------------------------------------------ -module("json") - --- Public functions - --- Private functions -local decode_scanArray -local decode_scanComment -local decode_scanConstant -local decode_scanNumber -local decode_scanObject -local decode_scanString -local decode_scanWhitespace -local encodeString -local isArray -local isEncodable - ------------------------------------------------------------------------------ --- PUBLIC FUNCTIONS ------------------------------------------------------------------------------ ---- Encodes an arbitrary Lua object / variable. --- @param v The Lua object / variable to be JSON encoded. --- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) -function encode (v) - -- Handle nil values - if v==nil then - return "null" - end - - local vtype = base.type(v) - - -- Handle strings - if vtype=='string' then - return '"' .. encodeString(v) .. '"' -- Need to handle encoding in string - end - - -- Handle booleans - if vtype=='number' or vtype=='boolean' then - return base.tostring(v) - end - - -- Handle tables - if vtype=='table' then - local rval = {} - -- Consider arrays separately - local bArray, maxCount = isArray(v) - if bArray then - for i = 1,maxCount do - table.insert(rval, encode(v[i])) - end - else -- An object, not an array - for i,j in base.pairs(v) do - if isEncodable(i) and isEncodable(j) then - table.insert(rval, '"' .. encodeString(i) .. '":' .. encode(j)) - end - end - end - if bArray then - return '[' .. table.concat(rval,',') ..']' - else - return '{' .. table.concat(rval,',') .. '}' - end - end - - -- Handle null values - if vtype=='function' and v==null then - return 'null' - end - - base.assert(false,'encode attempt to encode unsupported type ' .. vtype .. ':' .. base.tostring(v)) -end - - ---- Decodes a JSON string and returns the decoded value as a Lua data structure / value. --- @param s The string to scan. --- @return Lua objectthat was scanned, as a Lua table / string / number / boolean or nil. -function decode(s) - -- Function is re-defined below after token and other items are created. - -- Just defined here for code neatness. - return null -end - ---- The null function allows one to specify a null value in an associative array (which is otherwise --- discarded if you set the value with 'nil' in Lua. Simply set t = { first=json.null } -function null() - return null -- so json.null() will also return null ;-) -end - ------------------------------------------------------------------------------ --- Internal, PRIVATE functions. ------------------------------------------------------------------------------ - ---- Encodes a string to be JSON-compatible. --- This just involves back-quoting inverted commas, back-quotes and newlines, I think ;-) --- @param s The string to return as a JSON encoded (i.e. backquoted string) --- @return The string appropriately escaped. -local qrep = {["\\"]="\\\\", ['"']='\\"',['\n']='\\n',['\t']='\\t'} -function encodeString(s) - return tostring(s):gsub('["\\\n\t]',qrep) -end - --- Determines whether the given Lua type is an array or a table / dictionary. --- We consider any table an array if it has indexes 1..n for its n items, and no --- other data in the table. --- I think this method is currently a little 'flaky', but can't think of a good way around it yet... --- @param t The table to evaluate as an array --- @return boolean, number True if the table can be represented as an array, false otherwise. If true, --- the second returned value is the maximum --- number of indexed elements in the array. -function isArray(t) - -- Next we count all the elements, ensuring that any non-indexed elements are not-encodable - -- (with the possible exception of 'n') - local maxIndex = 0 - for k,v in base.pairs(t) do - if (base.type(k)=='number' and math.floor(k)==k and 1<=k) then -- k,v is an indexed pair - if (not isEncodable(v)) then return false end -- All array elements must be encodable - maxIndex = math.max(maxIndex,k) - else - if (k=='n') then - if v ~= table.getn(t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') - if isEncodable(v) then return false end - end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs - return true, maxIndex -end - ---- Determines whether the given Lua object / table / variable can be JSON encoded. The only --- types that are JSON encodable are: string, boolean, number, nil, table and json.null. --- In this implementation, all other types are ignored. --- @param o The object to examine. --- @return boolean True if the object should be JSON encoded, false if it should be ignored. -function isEncodable(o) - local t = base.type(o) - return (t=='string' or t=='boolean' or t=='number' or t=='nil' or t=='table') or (t=='function' and o==null) -end - --- Radical performance improvement for decode from Eike Decker! -do - local type = base.type - local error = base.error - local assert = base.assert - local print = base.print - local tonumber = base.tonumber - -- initialize some values to be used in decoding function - - -- initializes a table to contain a byte=>table mapping - -- the table contains tokens (byte values) as keys and maps them on other - -- token tables (mostly, the boolean value 'true' is used to indicate termination - -- of a token sequence) - -- the token table's purpose is, that it allows scanning a sequence of bytes - -- until something interesting has been found (e.g. a token that is not expected) - -- name is a descriptor for the table to be printed in error messages - local function init_token_table (tt) - local struct = {} - local value - function struct:link(other_tt) - value = other_tt - return struct - end - function struct:to(chars) - for i=1,#chars do - tt[chars:byte(i)] = value - end - return struct - end - return function (name) - tt.name = name - return struct - end - end - - -- keep "named" byte values at hands - local - c_esc, - c_e, - c_l, - c_r, - c_u, - c_f, - c_a, - c_s, - c_slash = ("\\elrufas/"):byte(1,9) - - -- token tables - tt_doublequote_string = strDoubleQuot, tt_singlequote_string = strSingleQuot - local - tt_object_key, - tt_object_colon, - tt_object_value, - tt_doublequote_string, - tt_singlequote_string, - tt_array_value, - tt_array_seperator, - tt_numeric, - tt_boolean, - tt_null, - tt_comment_start, - tt_comment_middle, - tt_ignore --< tt_ignore is special - marked tokens will be tt_ignored - = {},{},{},{},{},{},{},{},{},{},{},{},{} - - -- strings to be used in certain token tables - local strchars = "" -- all valid string characters (all except newlines) - local allchars = "" -- all characters that are valid in comments - --local escapechar = {} - for i=0,0xff do - local c = string.char(i) - if c~="\n" and c~="\r" then strchars = strchars .. c end - allchars = allchars .. c - --escapechar[i] = "\\" .. string.char(i) - end - ---[[ - charstounescape = "\"\'\\bfnrt/"; - unescapechars = "\"'\\\b\f\n\r\t\/"; - for i=1,#charstounescape do - escapechar[ charstounescape:byte(i) ] = unescapechars:sub(i,i) - end -]]-- - - -- obj key reader, expects the end of the object or a quoted string as key - init_token_table (tt_object_key) "object (' or \" or } or , expected)" - :link(tt_singlequote_string) :to "'" - :link(tt_doublequote_string) :to '"' - :link(true) :to "}" - :link(tt_object_key) :to "," - :link(tt_comment_start) :to "/" - :link(tt_ignore) :to " \t\r\n" - - - -- after the key, a colon is expected (or comment) - init_token_table (tt_object_colon) "object (: expected)" - :link(tt_object_value) :to ":" - :link(tt_comment_start) :to "/" - :link(tt_ignore) :to" \t\r\n" - - -- as values, anything is possible, numbers, arrays, objects, boolean, null, strings - init_token_table (tt_object_value) "object ({ or [ or ' or \" or number or boolean or null expected)" - :link(tt_object_key) :to "{" - :link(tt_array_seperator) :to "[" - :link(tt_singlequote_string) :to "'" - :link(tt_doublequote_string) :to '"' - :link(tt_numeric) :to "0123456789.-" - :link(tt_boolean) :to "tf" - :link(tt_null) :to "n" - :link(tt_comment_start) :to "/" - :link(tt_ignore) :to " \t\r\n" - - -- token tables for reading strings - init_token_table (tt_doublequote_string) "double quoted string" - :link(tt_ignore) :to (strchars) - :link(c_esc) :to "\\" - :link(true) :to '"' - - init_token_table (tt_singlequote_string) "single quoted string" - :link(tt_ignore) :to (strchars) - :link(c_esc) :to "\\" - :link(true) :to "'" - - -- array reader that expects termination of the array or a comma that indicates the next value - init_token_table (tt_array_value) "array (, or ] expected)" - :link(tt_array_seperator) :to "," - :link(true) :to "]" - :link(tt_comment_start) :to "/" - :link(tt_ignore) :to " \t\r\n" - - -- a value, pretty similar to tt_object_value - init_token_table (tt_array_seperator) "array ({ or [ or ' or \" or number or boolean or null expected)" - :link(tt_object_key) :to "{" - :link(tt_array_seperator) :to "[" - :link(tt_singlequote_string) :to "'" - :link(tt_doublequote_string) :to '"' - :link(tt_comment_start) :to "/" - :link(tt_numeric) :to "0123456789.-" - :link(tt_boolean) :to "tf" - :link(tt_null) :to "n" - :link(tt_ignore) :to " \t\r\n" - - -- valid number tokens - init_token_table (tt_numeric) "number" - :link(tt_ignore) :to "0123456789.-Ee" - - -- once a comment has been started with /, a * is expected - init_token_table (tt_comment_start) "comment start (* expected)" - :link(tt_comment_middle) :to "*" - - -- now everything is allowed, watch out for * though. The next char is then checked manually - init_token_table (tt_comment_middle) "comment end" - :link(tt_ignore) :to (allchars) - :link(true) :to "*" - - function decode (js_string) - local pos = 1 -- position in the string - - -- read the next byte value - local function next_byte () pos = pos + 1 return js_string:byte(pos-1) end - - -- in case of error, report the location using line numbers - local function location () - local n = ("\n"):byte() - local line,lpos = 1,0 - for i=1,pos do - if js_string:byte(i) == n then - line,lpos = line + 1,1 - else - lpos = lpos + 1 - end - end - return "Line "..line.." character "..lpos - end - - -- debug func - --local function status (str) - -- print(str.." ("..s:sub(math.max(1,p-10),p+10)..")") - --end - - -- read the next token, according to the passed token table - local function next_token (tok) - while pos <= #js_string do - local b = js_string:byte(pos) - local t = tok[b] - if not t then - error("Unexpected character at "..location()..": ".. - string.char(b).." ("..b..") when reading "..tok.name.."\nContext: \n".. - js_string:sub(math.max(1,pos-30),pos+30).."\n"..(" "):rep(pos+math.min(-1,30-pos)).."^") - end - pos = pos + 1 - if t~=tt_ignore then return t end - end - error("unexpected termination of JSON while looking for "..tok.name) - end - - -- read a string, double and single quoted ones - local function read_string (tok) - local start = pos - --local returnString = {} - repeat - local t = next_token(tok) - if t == c_esc then - --table.insert(returnString, js_string:sub(start, pos-2)) - --table.insert(returnString, escapechar[ js_string:byte(pos) ]) - pos = pos + 1 - --start = pos - end -- jump over escaped chars, no matter what - until t == true - return (base.loadstring("return " .. js_string:sub(start-1, pos-1) ) ()) - - -- We consider the situation where no escaped chars were encountered separately, - -- and use the fastest possible return in this case. - - --if 0 == #returnString then - -- return js_string:sub(start,pos-2) - --else - -- table.insert(returnString, js_string:sub(start,pos-2)) - -- return table.concat(returnString,""); - --end - --return js_string:sub(start,pos-2) - end - - local function read_num () - local start = pos - while pos <= #js_string do - local b = js_string:byte(pos) - if not tt_numeric[b] then break end - pos = pos + 1 - end - return tonumber(js_string:sub(start-1,pos-1)) - end - - -- read_bool and read_null are both making an assumption that I have not tested: - -- I would expect that the string extraction is more expensive than actually - -- making manual comparision of the byte values - local function read_bool () - pos = pos + 3 - local a,b,c,d = js_string:byte(pos-3,pos) - if a == c_r and b == c_u and c == c_e then return true end - pos = pos + 1 - if a ~= c_a or b ~= c_l or c ~= c_s or d ~= c_e then - error("Invalid boolean: "..js_string:sub(math.max(1,pos-5),pos+5)) - end - return false - end - - -- same as read_bool: only last - local function read_null () - pos = pos + 3 - local u,l1,l2 = js_string:byte(pos-3,pos-1) - if u == c_u and l1 == c_l and l2 == c_l then return nil end - error("Invalid value (expected null):"..js_string:sub(pos-4,pos-1).. - " ("..js_string:byte(pos-1).."="..js_string:sub(pos-1,pos-1).." / "..c_l..")") - end - - local read_object_value,read_object_key,read_array,read_value,read_comment - - -- read a value depending on what token was returned, might require info what was used (in case of comments) - function read_value (t,fromt) - if t == tt_object_key then return read_object_key({}) end - if t == tt_array_seperator then return read_array({}) end - if t == tt_singlequote_string or - t == tt_doublequote_string then return read_string(t) end - if t == tt_numeric then return read_num() end - if t == tt_boolean then return read_bool() end - if t == tt_null then return read_null() end - if t == tt_comment_start then return read_value(read_comment(fromt)) end - error("unexpected termination - "..js_string:sub(math.max(1,pos-10),pos+10)) - end - - -- read comments until something noncomment like surfaces, using the token reader which was - -- used when stumbling over this comment - function read_comment (fromt) - while true do - next_token(tt_comment_start) - while true do - local t = next_token(tt_comment_middle) - if next_byte() == c_slash then - local t = next_token(fromt) - if t~= tt_comment_start then return t end - break - end - end - end - end - - -- read arrays, empty array expected as o arg - function read_array (o,i) - --if not i then status "arr open" end - i = i or 1 - -- loop until ... - while true do - o[i] = read_value(next_token(tt_array_seperator),tt_array_seperator) - local t = next_token(tt_array_value) - if t == tt_comment_start then - t = read_comment(tt_array_value) - end - if t == true then -- ... we found a terminator token - --status "arr close" - return o - end - i = i + 1 - end - end - - -- object value reading - function read_object_value (o) - local t = next_token(tt_object_value) - return read_value(t,tt_object_value) - end - - -- object key reading, might also terminate the object - function read_object_key (o) - while true do - local t = next_token(tt_object_key) - if t == tt_comment_start then - t = read_comment(tt_object_key) - end - if t == true then return o end - if t == tt_object_key then return read_object_key(o) end - local k = read_string(t) - - if next_token(tt_object_colon) == tt_comment_start then - t = read_comment(tt_object_colon) - end - - local v = read_object_value(o) - o[k] = v - end - end - - -- now let's read data from our string and pretend it's an object value - local r = read_object_value() - if pos<=#js_string then - -- not sure about what to do with dangling characters - --error("Dangling characters in JSON code ("..location()..")") - end - - return r - end -end diff --git a/mods/base/req/localization.lua b/mods/base/req/localization.lua deleted file mode 100644 index 217f0f8..0000000 --- a/mods/base/req/localization.lua +++ /dev/null @@ -1,75 +0,0 @@ - -LuaModManager._languages = { - "en", - "de", - "fr", - "ru", - "tr", - "id" -} -LuaModManager.Constants.default_language = "en" -LuaModManager.Constants.language_key = "language" - -function LuaModManager:GetIndexOfDefaultLanguage() - for k, v in pairs(LuaModManager._languages) do - if v == LuaModManager.Constants.default_language then - return k - end - end - return 1 -end - -function LuaModManager:GetLanguageIndex() - local key = LuaModManager.Constants.language_key - return self._enabled_mods[key] or self:GetIndexOfDefaultLanguage() -end - -function LuaModManager:GetLanguageFile() - local lang = LuaModManager._languages[self:GetLanguageIndex()] - lang = lang or LuaModManager._languages[self:GetIndexOfDefaultLanguage()] - return string.format("%sloc/%s.txt", LuaModManager._base_path, lang) -end - -function LuaModManager:SetActiveLanguage( index ) - local key = LuaModManager.Constants.language_key - self._enabled_mods[key] = index -end - -Hooks:Add("LocalizationManagerPostInit", "Base_LocalizationManagerPostInit", function(loc) - -- Load english strings to use as backup - loc:load_localization_file( string.format("%sloc/%s.txt", LuaModManager._base_path, "en") ) - loc:load_localization_file( LuaModManager:GetLanguageFile() ) -end) - -Hooks:Add("MenuManager_Base_BuildModOptionsMenu", "MenuManager_Base_SetupModOptionsMenu_Localization", function( menu_manager ) - - local menu_id = LuaModManager.Constants._lua_mod_options_menu_id - - MenuCallbackHandler.blt_base_select_language = function(this, item) - LuaModManager:SetActiveLanguage( tonumber(item:value()) ) - LuaModManager:Save() - end - - local items = {} - for k, v in ipairs( LuaModManager._languages ) do - items[k] = "base_language_" .. v - end - - MenuHelper:AddMultipleChoice({ - id = "base_language_select", - title = "base_language_select", - desc = "base_language_select_desc", - callback = "blt_base_select_language", - menu_id = menu_id, - items = items, - value = LuaModManager:GetLanguageIndex(), - priority = 1001, - }) - - MenuHelper:AddDivider({ - size = 16, - menu_id = menu_id, - priority = 1000, - }) - -end) diff --git a/mods/base/req/lua_mod_manager.lua b/mods/base/req/lua_mod_manager.lua deleted file mode 100644 index 84d783f..0000000 --- a/mods/base/req/lua_mod_manager.lua +++ /dev/null @@ -1,385 +0,0 @@ - -if not _G["LuaModManager"] then - declare( "LuaModManager", {} ) -end -LuaModManager = LuaModManager or {} -LuaModManager.Constants = LuaModManager.Constants or {} - -local C = LuaModManager.Constants -C.mods_directory = "mods/" -C.lua_base_directory = "base/" -C.logs_directory = "logs/" -C.downloads_directory = "downloads/" -C.saves_directory = "saves/" -C.json_module = "req/json.lua" -C.mod_manager_file = "mod_manager.txt" -C.mod_keybinds_file = "mod_keybinds.txt" -C.mod_updates_file = "mod_updates.txt" -C.mod_required_file = "mod_required.txt" - -C.excluded_mods_directories = { - ["logs"] = true, - ["saves"] = true, - ["downloads"] = true, -} - -C.always_active_mods = { - ["mods/base/"] = true, - ["mods/logs/"] = true, - ["mods/saves/"] = true, -} - -C.required_script_global = "RequiredScript" -C.mod_path_global = "ModPath" -C.logs_path_global = "LogsPath" -C.save_path_global = "SavePath" - -C.mod_definition_file = "mod.txt" -C.mod_name_key = "name" -C.mod_desc_key = "description" -C.mod_version_key = "version" -C.mod_author_key = "author" -C.mod_contact_key = "contact" -C.mod_hooks_key = "hooks" -C.mod_prehooks_key = "pre_hooks" -C.mod_persists_key = "persist_scripts" -C.mod_hook_id_key = "hook_id" -C.mod_script_path_key = "script_path" -C.mod_persists_global_key = "global" -C.mod_persists_path_key = "path" -C.mod_hook_wildcard_key = "*" - -C.mod_keybinds_key = "keybinds" -C.mod_keybind_id_key = "keybind_id" -C.mod_keybind_name_key = "name" -C.mod_keybind_desc_key = "description" -C.mod_keybind_script_key = "script_path" -C.mod_keybind_path_key = "path" -C.mod_keybind_scope_menu_key = "run_in_menu" -C.mod_keybind_scope_game_key = "run_in_game" -C.mod_keybind_callback_key = "callback" -C.mod_keybind_localize_key = "localized" - -C.mod_update_key = "updates" -C.mod_update_revision_key = "revision" -C.mod_update_identifier_key = "identifier" -C.mod_update_install_key = "install_dir" -C.mod_update_install_folder_key = "install_folder" -C.mod_update_name_key = "display_name" - -C.mod_libs_key = "libraries" -C.mod_libs_identifier_key = "identifier" -C.mod_libs_display_name_key = "display_name" -C.mod_libs_optional_key = "optional" - -C.hook_dll_id = "payday2bltdll" -C.hook_dll_name = "IPHLPAPI.dll" -C.hook_dll_temp_name = "IPHLPAPI_temp.dll" - -LuaModManager._persist_scripts = LuaModManager._persist_scripts or {} - -LuaModManager._base_path = C.mods_directory .. C.lua_base_directory -LuaModManager._save_path = C.mods_directory .. C.saves_directory - -LuaModManager._enabled_mods = LuaModManager._enabled_mods or {} -LuaModManager._mod_manager_file_path = LuaModManager._save_path .. C.mod_manager_file - -LuaModManager._keybinds = LuaModManager._keybinds or {} -LuaModManager._player_keybinds = LuaModManager._player_keybinds or {} -LuaModManager._mod_keybinds_file_path = LuaModManager._save_path .. C.mod_keybinds_file - -LuaModManager._updates = LuaModManager._updates or {} -LuaModManager._required = LuaModManager._required or {} -LuaModManager._updates_enabled = LuaModManager._updates_enabled or {} -LuaModManager._mod_updates_file_path = LuaModManager._save_path .. C.mod_updates_file - -LuaModManager._required_enabled = LuaModManager._required_enabled or {} -LuaModManager._mod_required_file_path = LuaModManager._save_path .. C.mod_required_file - -local function clone( o ) - local res = {} - for k, v in pairs( o ) do - res[k] = v - end - setmetatable( res, getmetatable(o) ) - return res -end - -function LuaModManager:GetMod( mod_path ) - - if self.Mods then - for k, v in pairs( self.Mods ) do - if v.path == mod_path then - return v - end - end - end - -end - -function LuaModManager:WasModEnabledAtLoadTime( mod_name ) - -- Use a separate table for checking if mods are enabled, so that we don't end up showing that mods - -- are "enabled" when somebody flags a mod for being enabled and then reloads the mods menu - if not self._enabled_mods_on_load then - self._enabled_mods_on_load = clone( self._enabled_mods ) - end - return (self._enabled_mods_on_load[mod_name] == nil or self._enabled_mods_on_load[mod_name] == true) -end - -function LuaModManager:IsModEnabled( mod_name ) - return (self._enabled_mods[mod_name] == nil or self._enabled_mods[mod_name] == true) -end - -function LuaModManager:SetModEnabledState( mod_name, state ) - self._enabled_mods[mod_name] = state - self:Save() -end - -function LuaModManager:HasModFromIdentifier(identifier) - for k, v in pairs(_mods) do - local updates = v.definition[C.mod_update_key] - if updates then - for i, update in pairs(updates) do - if update[C.mod_update_identifier_key] == identifier then - return true - end - end - end - end - return false -end - -function LuaModManager:HasRequiredMod(mod) - local libs = mod.definition[C.mod_libs_key] - local has_any_required = false - if libs then - for k, lib in pairs(libs) do - if not self:HasModFromIdentifier(lib[C.mod_libs_identifier_key]) then - if not lib[C.mod_libs_optional_key] == "true" then - has_any_required = true - end - self:AddRequireCheck( lib[C.mod_libs_display_name_key], lib[C.mod_libs_identifier_key], mod.definition[C.mod_name_key], (lib[C.mod_libs_optional_key] == "true") ) - end - end - end - - return not has_any_required -end - -function LuaModManager:ToggleModState( mod_name ) - if not C.always_active_mods[mod_name] then - if self._enabled_mods[mod_name] == nil then - self._enabled_mods[mod_name] = false - else - self._enabled_mods[mod_name] = not self._enabled_mods[mod_name] - end - self:Save() - end - return self._enabled_mods[mod_name] -end - -function LuaModManager:EnableMod( mod_name ) - self:SetModEnabledState( mod_name, true ) - self:Save() -end - -function LuaModManager:DisableMod( mod_name ) - self:SetModEnabledState( mod_name, false ) - self:Save() -end - -function LuaModManager:IsFlaggedForEnabledChange( mod_name ) - return self:IsModEnabled( mod_name ) ~= self:WasModEnabledAtLoadTime( mod_name ) -end - -function LuaModManager:PersistScripts() - return self._persist_scripts -end - -function LuaModManager:AddPersistScript( persist, path ) - local tbl = clone( persist ) - tbl[ C.mod_script_path_key ] = path .. tbl[ C.mod_script_path_key ] - tbl[ C.mod_persists_path_key ] = path - declare( persist[C.mod_persists_global_key], false ) - table.insert( self._persist_scripts, tbl ) -end - -function LuaModManager:Keybinds() - return self._keybinds -end - -function LuaModManager:GetNumberOfJsonKeybinds() - local i = 0 - for k, v in pairs( self._keybinds ) do - if v._is_json then - i = i + 1 - end - end - return i -end - -function LuaModManager:PlayerKeybinds() - return self._player_keybinds -end - -function LuaModManager:AddJsonKeybinding( keybind, path ) - - local tbl = clone( keybind ) - tbl._is_json = true - tbl[ C.mod_keybind_path_key ] = path - tbl[ C.mod_keybind_script_key ] = path .. tbl[ C.mod_keybind_script_key ] - - local keybind_id = tbl[ C.mod_keybind_id_key ] - self._keybinds[ keybind_id ] = tbl - -end - -function LuaModManager:AddKeybinding( keybind_id, callback ) - self._keybinds[ keybind_id ] = callback -end - -function LuaModManager:GetPlayerKeybind( keybind_id ) - return self._player_keybinds[ keybind_id ] -end - -function LuaModManager:SetPlayerKeybind( keybind_id, key ) - self._player_keybinds[ keybind_id ] = key - self:Save() -end - -function LuaModManager:UpdateChecks() - return self._updates -end - -function LuaModManager:Required() - return self._required -end - -function LuaModManager:AddUpdateCheck( mod_table, mod_id, update_tbl ) - - local tbl = { - mod = mod_id, - mod_table = mod_table, - revision = update_tbl[ C.mod_update_revision_key ], - identifier = update_tbl[ C.mod_update_identifier_key ], - install_dir = update_tbl[ C.mod_update_install_key ] or nil, - install_folder = update_tbl[ C.mod_update_install_folder_key ] or nil, - display_name = update_tbl[ C.mod_update_name_key ] or nil, - } - - if tbl.identifier == nil then - log("[Error] Could not add automatic update for " .. tostring(mod_id) .. " as it has no identifier key!") - return - end - - if tbl.revision == nil then - log("[Error] Could not add automatic update for " .. tostring(tbl.display_name or mod_id) .. " as it has no revision key!") - return - end - - -- Load revision from file if necessary - if type(tbl.revision) == "string" then - - local path = tbl.revision - if tbl.revision:sub(1, 2) == "./" then - path = tbl.revision:sub( 3, tbl.revision:len() ) - tbl.revision_path = path - else - path = tbl.install_dir .. tbl.install_folder .. "/" .. tbl.revision - end - - local file = io.open( path, "r" ) - if file then - local data = file:read("*all") - data = tonumber(data) - if data then - tbl.revision = data - else - tbl.revision = nil - end - else - tbl.revision = nil - end - - if tbl.revision == nil then - log("[Error] Could not load revision file for " .. tostring(tbl.display_name or mod_id) .. "!") - return - end - - end - - table.insert( self._updates, tbl ) - -end - -function LuaModManager:AddRequireCheck( mod_name, identifier, required_by, optional ) - self._required[identifier] = self._required[identifier] or {} - self._required[identifier].required_by = self._required[identifier].required_by or {} - self._required[identifier].optional = self._required[identifier].optional == nil and optional or not optional and optional or self._required[identifier].optional - self._required[identifier].display_name = mod_name - self._required[identifier].identifier = identifier - - table.insert(self._required[identifier].required_by, required_by) -end - -function LuaModManager:AreModUpdatesEnable( mod_id ) - return (self._updates_enabled[mod_id] == nil or self._updates_enabled[mod_id] == true) -end - -function LuaModManager:SetModUpdatesState( mod_id, state ) - log( ("[Updates] Setting automatic updates for mod '{1}' to: {2}"):gsub("{1}", mod_id):gsub("{2}", tostring(state)) ) - self._updates_enabled[mod_id] = state - self:Save() -end - -function LuaModManager:Save() - self:SaveTableToJson( self._enabled_mods, self._mod_manager_file_path ) - self:SaveTableToJson( self._player_keybinds, self._mod_keybinds_file_path ) - self:SaveTableToJson( self._updates_enabled, self._mod_updates_file_path ) -end - -function LuaModManager:SaveTableToJson( tbl, file_path ) - - local count = 0 - for k, v in pairs( tbl ) do - count = count + 1 - end - - if tbl and count > 0 then - - local file = io.open(file_path, "w+") - if file then - file:write( json.encode( tbl ) ) - file:close() - else - log("[Error] Could not save to file '" .. file_path .. "', data may be lost!") - end - - else - log("[Warning] Attempting to save empty data table '" .. file_path .. "', skipping...") - end - -end - -function LuaModManager:Load() - self._enabled_mods = self:LoadJsonFileToTable( self._mod_manager_file_path ) or self._enabled_mods - self._player_keybinds = self:LoadJsonFileToTable( self._mod_keybinds_file_path ) or self._player_keybinds - self._updates_enabled = self:LoadJsonFileToTable( self._mod_updates_file_path ) or self._updates_enabled -end - -function LuaModManager:LoadJsonFileToTable( file_path ) - - local file = io.open( file_path, "r" ) - if file then - - local file_contents = file:read("*all") - local mod_manager_data = json.decode(file_contents) - file:close() - return mod_manager_data - - else - log("[Warning] Could not load file '" .. file_path .. "', no data loaded...") - end - return nil - -end diff --git a/mods/base/req/lua_mods_menu.lua b/mods/base/req/lua_mods_menu.lua deleted file mode 100644 index 6ee41ac..0000000 --- a/mods/base/req/lua_mods_menu.lua +++ /dev/null @@ -1,33 +0,0 @@ - -LuaModManager.Constants._lua_mods_menu_id = "base_lua_mods_menu" -LuaModManager.Constants._lua_mod_options_menu_id = "lua_mod_options_menu" -local lua_mods_menu_id = LuaModManager.Constants._lua_mods_menu_id -local lua_mod_options_menu_id = LuaModManager.Constants._lua_mod_options_menu_id - --- Lua Mods Menu -Hooks:Add("MenuManager_Base_SetupModsMenu", "Base_SetupModsMenu", function( menu_manager, nodes ) - MenuHelper:NewMenu( lua_mods_menu_id ) -end) - -Hooks:Add("MenuManager_Base_BuildModsMenu", "Base_BuildModsMenu", function( menu_manager, nodes ) - - -- Add mods menu - local mods_menu = MenuHelper:BuildMenu( lua_mods_menu_id ) - mods_menu._parameters.name = lua_mods_menu_id - nodes[lua_mods_menu_id] = mods_menu - MenuHelper:AddMenuItem( nodes.options, lua_mods_menu_id, "base_options_menu_lua_mods", "base_options_menu_lua_mods_desc", "mods", "after" ) - -end) - --- Mod Options Menu -Hooks:Add("MenuManager_Base_SetupModOptionsMenu", "Base_SetupModOptionsMenu", function( menu_manager, nodes ) - MenuHelper:NewMenu( lua_mod_options_menu_id ) -end) - -Hooks:Add("MenuManager_Base_BuildModOptionsMenu", "Base_BuildModOptionsMenu", function( menu_manager, nodes ) - - -- Add mod options menu - nodes[lua_mod_options_menu_id] = MenuHelper:BuildMenu( lua_mod_options_menu_id ) - MenuHelper:AddMenuItem( nodes.options, lua_mod_options_menu_id, "base_options_menu_lua_mod_options", "base_options_menu_lua_mod_options_desc", lua_mods_menu_id, "after" ) - -end) diff --git a/mods/base/req/menus.lua b/mods/base/req/menus.lua deleted file mode 100644 index 0090964..0000000 --- a/mods/base/req/menus.lua +++ /dev/null @@ -1,588 +0,0 @@ - -_G.MenuHelper = _G.MenuHelper or {} -local Menu = _G.MenuHelper - -function Menu:SetupMenu( menu, id ) - if menu[id] == nil then - log("[Error] Could not find '" .. id .. "' in menu!") - return - end - self.menu_to_clone = menu[id] -end - -function Menu:SetupMenuButton( menu, id, button_id ) - if menu[id] == nil then - log("[Error] Could not find '" .. id .. "' in menu!") - return - end - if button_id == nil then - button_id = 1 - end - self.menubutton_to_clone = menu[id]:items()[button_id] -end - -function Menu:NewMenu( menu_id ) - - self.menus = self.menus or {} - - local new_menu = deep_clone( self.menu_to_clone ) - new_menu._items = {} - self.menus[menu_id] = new_menu - - return new_menu - -end - -function Menu:GetMenu( menu_id ) - local menu = self.menus[menu_id] - if menu == nil then - log("[Error] Could not find menu with id '" .. tostring(menu_id) .. "'!") - end - return menu -end - -function Menu:AddBackButton( menu_id ) - local menu = self:GetMenu( menu_id ) - MenuManager:add_back_button( menu ) -end - -function Menu:AddButton( button_data ) - - local data = { - type = "CoreMenuItem.Item", - } - - local params = { - name = button_data.id, - text_id = button_data.title, - help_id = button_data.desc, - callback = button_data.callback, - back_callback = button_data.back_callback, - disabled_color = button_data.disabled_color or Color(0.25, 1, 1, 1), - next_node = button_data.next_node, - localize = button_data.localized, - } - - local menu = self:GetMenu( button_data.menu_id ) - local item = menu:create_item(data, params) - item._priority = button_data.priority - - if button_data.disabled then - item:set_enabled( not button_data.disabled ) - end - - menu._items_list = menu._items_list or {} - table.insert( menu._items_list, item ) - -end - -function Menu:AddDivider( divider_data ) - - local data = { - type = "MenuItemDivider", - size = divider_data.size or 8, - no_text = divider_data.no_text or true, - } - - local params = { - name = divider_data.id, - } - - local menu = self:GetMenu( divider_data.menu_id ) - local item = menu:create_item( data, params ) - item._priority = divider_data.priority or 0 - menu._items_list = menu._items_list or {} - table.insert( menu._items_list, item ) - -end - -function Menu:AddToggle( toggle_data ) - - local data = { - type = "CoreMenuItemToggle.ItemToggle", - { - _meta = "option", - icon = "guis/textures/menu_tickbox", - value = "on", - x = 24, - y = 0, - w = 24, - h = 24, - s_icon = "guis/textures/menu_tickbox", - s_x = 24, - s_y = 24, - s_w = 24, - s_h = 24 - }, - { - _meta = "option", - icon = "guis/textures/menu_tickbox", - value = "off", - x = 0, - y = 0, - w = 24, - h = 24, - s_icon = "guis/textures/menu_tickbox", - s_x = 0, - s_y = 24, - s_w = 24, - s_h = 24 - } - } - - local params = { - name = toggle_data.id, - text_id = toggle_data.title, - help_id = toggle_data.desc, - callback = toggle_data.callback, - disabled_color = toggle_data.disabled_color or Color( 0.25, 1, 1, 1 ), - icon_by_text = toggle_data.icon_by_text or false, - localize = toggle_data.localized, - } - - local menu = self:GetMenu( toggle_data.menu_id ) - local item = menu:create_item( data, params ) - item:set_value( toggle_data.value and "on" or "off" ) - item._priority = toggle_data.priority - - if toggle_data.disabled then - item:set_enabled( not toggle_data.disabled ) - end - - menu._items_list = menu._items_list or {} - table.insert( menu._items_list, item ) - -end - -function Menu:AddSlider( slider_data ) - - local data = { - type = "CoreMenuItemSlider.ItemSlider", - min = slider_data.min or 0, - max = slider_data.max or 10, - step = slider_data.step or 1, - show_value = slider_data.show_value or false - } - - local params = { - name = slider_data.id, - text_id = slider_data.title, - help_id = slider_data.desc, - callback = slider_data.callback, - disabled_color = slider_data.disabled_color or Color( 0.25, 1, 1, 1 ), - localize = slider_data.localized, - } - - local menu = self:GetMenu( slider_data.menu_id ) - local item = menu:create_item(data, params) - item:set_value( math.clamp(slider_data.value, data.min, data.max) or data.min ) - item._priority = slider_data.priority - - if slider_data.disabled then - item:set_enabled( not slider_data.disabled ) - end - - menu._items_list = menu._items_list or {} - table.insert( menu._items_list, item ) - -end - -function Menu:AddMultipleChoice( multi_data ) - - local data = { - type = "MenuItemMultiChoice" - } - for k, v in ipairs( multi_data.items or {} ) do - table.insert( data, { _meta = "option", text_id = v, value = k } ) - end - - local params = { - name = multi_data.id, - text_id = multi_data.title, - help_id = multi_data.desc, - callback = multi_data.callback, - filter = true, - localize = multi_data.localized, - } - - local menu = self:GetMenu( multi_data.menu_id ) - local item = menu:create_item(data, params) - item._priority = multi_data.priority - item:set_value( multi_data.value or 1 ) - - if multi_data.disabled then - item:set_enabled( not multi_data.disabled ) - end - - menu._items_list = menu._items_list or {} - table.insert( menu._items_list, item ) - -end - -function Menu:AddKeybinding( bind_data ) - - local data = { - type = "MenuItemCustomizeController", - } - - local params = { - name = bind_data.id, - text_id = bind_data.title, - help_id = bind_data.desc, - connection_name = bind_data.connection_name, - binding = bind_data.binding, - button = bind_data.button, - callback = bind_data.callback, - localize = bind_data.localized, - localize_help = bind_data.localized, - is_custom_keybind = true, - } - - local menu = self:GetMenu( bind_data.menu_id ) - local item = menu:create_item(data, params) - item._priority = bind_data.priority - - menu._items_list = menu._items_list or {} - table.insert( menu._items_list, item ) - -end - - -function Menu:BuildMenu( menu_id, data ) - - -- Check menu exists - local menu = self.menus[menu_id] - if menu == nil then - log("[Error] Attempting to build menu '" .. menu_id .."' which doesn't exist!") - return - end - - -- Check items exist for this menu - if menu._items_list ~= nil then - - local priority_items = {} - local nonpriority_items = {} - for k, v in pairs( menu._items_list ) do - if v._priority ~= nil then - table.insert( priority_items, v ) - else - table.insert( nonpriority_items, v ) - end - end - - -- Sort table by priority, higher priority first - table.sort( priority_items, function(a, b) - return a._priority > b._priority - end) - - -- Sort non-priority items alphabetically - table.sort( nonpriority_items, function(a, b) - return managers.localization:text(a._parameters.text_id or "") < managers.localization:text(b._parameters.text_id or "") - end) - - -- Add items to menu - for k, item in pairs( priority_items ) do - menu:add_item( item ) - end - for k, item in pairs( nonpriority_items ) do - menu:add_item( item ) - end - - -- Slider dirty callback fix - for k, item in pairs( menu._items ) do - if item._type == "slider" or item._parameters.type == "CoreMenuItemSlider.ItemSlider" then - item.dirty_callback = nil - end - end - - -- Back callback - if data then - - if data.focus_changed_callback then - menu._parameters.focus_changed_callback = { - MenuCallbackHandler[data.focus_changed_callback] - } - end - - if data.back_callback then - - if not menu._parameters.back_callback then - menu._parameters.back_callback = {} - end - - if type(data.back_callback) == "table" then - for k, v in pairs( data.back_callback ) do - - if type(v) == "string" then - data.back_callback = MenuCallbackHandler[v] - end - - table.insert( menu._parameters.back_callback, v ) - - end - else - - if type(data.back_callback) == "string" then - data.back_callback = MenuCallbackHandler[data.back_callback] - end - - table.insert( menu._parameters.back_callback, data.back_callback ) - - end - - end - - if data.area_bg then - menu._parameters.area_bg = data.area_bg - end - - end - - end - - -- Add back button to menu - self:AddBackButton( menu_id ) - - -- Build menu data - menu._parameters.menu_id = menu_id - self.menus[menu_id] = menu - - return self.menus[menu_id] - -end - -function Menu:AddMenuItem( parent_menu, child_menu, name, desc, menu_position, subposition ) - - if parent_menu == nil then - log( string.gsub("[Menus][Warning] Parent menu for child '{1}' is null, ignoring...", "{1}", child_menu) ) - return - end - - -- Get menu position from string - if type( menu_position ) == "string" then - for k, v in pairs( parent_menu._items ) do - if menu_position == v["_parameters"]["name"] then - - if subposition == nil then - subposition = "after" - end - - if subposition == "after" then - menu_position = k + 1 - else - menu_position = k - end - - break - - end - end - end - - -- Put at end of menu, but before the back button - if menu_position == nil or type(menu_position) == "string" then - menu_position = #parent_menu._items - end - - -- Insert in menu - local button = deep_clone( self.menubutton_to_clone ) - button._parameters.name = child_menu - button._parameters.text_id = name - button._parameters.help_id = desc - button._parameters.next_node = child_menu - table.insert( parent_menu._items, menu_position, button ) - -end - -function MenuHelper:LoadFromJsonFile( file_path, parent_class, data_table ) - - local file = io.open( file_path, "r" ) - if file then - - local file_content = file:read("*all") - file:close() - - local content = json.decode( file_content ) - local menu_id = content.menu_id - local parent_menu = content.parent_menu_id - local menu_name = content.title - local menu_desc = content.description - local items = content.items - local focus_changed_callback = content.focus_changed_callback - local back_callback = content.back_callback - local menu_priority = content.priority or nil - local area_bg = content.area_bg - - Hooks:Add("MenuManagerSetupCustomMenus", "Base_SetupCustomMenus_Json_" .. menu_id, function( menu_manager, nodes ) - MenuHelper:NewMenu( menu_id ) - end) - - Hooks:Add("MenuManagerBuildCustomMenus", "Base_BuildCustomMenus_Json_" .. menu_id, function( menu_manager, nodes ) - - local data = { - focus_changed_callback = focus_changed_callback, - back_callback = back_callback, - area_bg = area_bg, - } - nodes[menu_id] = MenuHelper:BuildMenu( menu_id, data ) - - if menu_priority ~= nil then - for k, v in pairs( nodes[parent_menu]._items ) do - if menu_priority > (v._priority or 0) then - menu_priority = k - break - end - end - end - - MenuHelper:AddMenuItem( nodes[parent_menu], menu_id, menu_name, menu_desc, menu_priority ) - - end) - - Hooks:Add("MenuManagerPopulateCustomMenus", "Base_PopulateCustomMenus_Json_" .. menu_id, function( menu_manager, nodes ) - - for k, item in pairs( items ) do - - local type = item.type - local id = item.id - local title = item.title - local desc = item.description - local callback = item.callback - local priority = item.priority or #items - k - local value = item.default_value - local localized = item.localized - if data_table and data_table[item.value] ~= nil then - value = data_table[item.value] - end - - if type == "button" then - MenuHelper:AddButton({ - id = id, - title = title, - desc = desc, - callback = callback, - next_node = item.next_menu or nil, - menu_id = menu_id, - priority = priority, - localized = localized, - }) - end - - if type == "toggle" then - MenuHelper:AddToggle({ - id = id, - title = title, - desc = desc, - callback = callback, - value = value, - menu_id = menu_id, - priority = priority, - localized = localized, - }) - end - - if type == "slider" then - MenuHelper:AddSlider({ - id = id, - title = title, - desc = desc, - callback = callback, - value = value, - min = item.min or 0, - max = item.max or 1, - step = item.step or 0.1, - show_value = true, - menu_id = menu_id, - priority = priority, - localized = localized, - }) - end - - if type == "divider" then - MenuHelper:AddDivider({ - id = "divider_" .. menu_id .. "_" .. tostring(priority), - size = item.size, - menu_id = menu_id, - priority = priority, - }) - end - - if type == "keybind" then - - local key = "" - if item.keybind_id then - key = LuaModManager:GetPlayerKeybind( item.keybind_id ) or "" - end - - MenuHelper:AddKeybinding({ - id = id, - title = title, - desc = desc, - connection_name = item.keybind_id, - button = key, - binding = key, - menu_id = menu_id, - priority = priority, - localized = localized, - }) - - LuaModManager:AddKeybinding( item.keybind_id, parent_class[item.func] ) - - end - - if type == "multiple_choice" then - MenuHelper:AddMultipleChoice({ - id = id, - title = title, - desc = desc, - callback = callback, - items = item.items, - value = value, - menu_id = menu_id, - priority = priority, - localized = localized, - }) - end - - end - - end) - - else - log("[Error] Could not load file: " .. file_path) - end - -end - -function Menu:ResetItemsToDefaultValue( item, items_table, value ) - - if type(items_table) ~= "table" then - local s = tostring(items_table) - items_table = {} - items_table[s] = true - end - - local node_items = item._parameters.gui_node.row_items - for k, v in pairs( node_items ) do - - if items_table[v.item._parameters.name] and v.item.set_value then - - local item_type = v.item._type - - if item_type == "toggle" then - v.item:set_value( value and "on" or "off" ) - else - v.item:set_value( value ) - end - - for x, y in pairs( v.item._parameters.callback ) do - y(v.item) - end - - end - - end - - managers.viewport:resolution_changed() - -end diff --git a/mods/base/req/mod_keybinds.lua b/mods/base/req/mod_keybinds.lua deleted file mode 100644 index d828978..0000000 --- a/mods/base/req/mod_keybinds.lua +++ /dev/null @@ -1,118 +0,0 @@ - -local C = LuaModManager.Constants -LuaModManager.Constants._keybinds_menu_id = "base_keybinds_menu" -local keybinds_menu_id = C._keybinds_menu_id - -local display_keybinds_menu = false -local set_keybind_time = 0 -local keybind_set_delay = 0.5 - --- Keybinds Menu -Hooks:Add("MenuManager_Base_SetupModOptionsMenu", "Base_SetupKeybindsMenu", function( menu_manager, nodes ) - display_keybinds_menu = LuaModManager:GetNumberOfJsonKeybinds() > 0 - if display_keybinds_menu then - MenuHelper:NewMenu( keybinds_menu_id ) - end -end) - -Hooks:Add("MenuManager_Base_PopulateModOptionsMenu", "Base_PopulateKeybindsMenu", function( menu_manager, nodes ) - - if display_keybinds_menu then - - for k, v in pairs( LuaModManager:Keybinds() ) do - - local keybind_id = v[ C.mod_keybind_id_key ] - local keybind_name = v[ C.mod_keybind_name_key ] - local keybind_desc = v[ C.mod_keybind_desc_key ] - local keybind_script = v[ C.mod_keybind_script_key ] - local keybind_localized = v[ C.mod_keybind_localize_key ] - local key = LuaModManager:GetPlayerKeybind( keybind_id ) or "" - - MenuHelper:AddKeybinding({ - id = keybind_id, - title = keybind_name, - desc = keybind_desc, - connection_name = keybind_id, - button = key, - binding = key, - menu_id = keybinds_menu_id, - localized = keybind_localized, - }) - - end - - end - -end) - -Hooks:Add("MenuManager_Base_BuildModOptionsMenu", "Base_BuildKeybindsMenu", function( menu_manager, nodes ) - if display_keybinds_menu then - nodes[keybinds_menu_id] = MenuHelper:BuildMenu( keybinds_menu_id ) - MenuHelper:AddMenuItem( nodes.options, keybinds_menu_id, "base_options_menu_keybinds", "base_options_menu_keybinds_desc", "lua_mod_options_menu", "after" ) - end -end) - -Hooks:Add("CustomizeControllerOnKeySet", "Base_Keybinds_CustomizeControllerOnKeySet", function( keybind, key ) - LuaModManager:SetPlayerKeybind( keybind, key ) - set_keybind_time = Application:time() -end) - -Hooks:Add("MenuUpdate", "Base_Keybinds_MenuUpdate", function(t, dt) - LuaModManager:UpdateBindings("MENU") -end) - -Hooks:Add("GameSetupUpdate", "Base_Keybinds_GameStateUpdate", function(t, dt) - LuaModManager:UpdateBindings("GAME") -end) - -function LuaModManager:UpdateBindings( state ) - - if not self._input_keyboard then - self._input_keyboard = Input:keyboard() - end - if not self._input_mouse then - self._input_mouse = Input:mouse() - end - if managers and managers.hud and managers.hud:chat_focus() then - return - end - - for keybind_id, key in pairs( LuaModManager:PlayerKeybinds() ) do - if not string.is_nil_or_empty( key ) then - - local keybind = LuaModManager:Keybinds()[ keybind_id ] - if keybind then - - local key_pressed = nil - if string.find(key, "mouse ") ~= nil then - key_pressed = self._input_mouse:pressed( key:sub(7) ) - else - key_pressed = self._input_keyboard:pressed( Idstring(key) ) - end - if key_pressed and Application:time() - set_keybind_time >= keybind_set_delay then - self:AttemptRunKeybind( keybind, state ) - end - - end - - end - end - -end - -function LuaModManager:AttemptRunKeybind( keybind, state ) - - local keybind_type = type(keybind) - if keybind_type == "table" then - local should_run = keybind[ state == "MENU" and C.mod_keybind_scope_menu_key or C.mod_keybind_scope_game_key ] - if should_run then - local script = keybind[ C.mod_keybind_script_key ] - dofile( script ) - end - end - - if keybind_type == "function" then - keybind() - end - -end diff --git a/mods/base/req/network.lua b/mods/base/req/network.lua deleted file mode 100644 index f3c9a2d..0000000 --- a/mods/base/req/network.lua +++ /dev/null @@ -1,243 +0,0 @@ - -_G.LuaNetworking = _G.LuaNetworking or {} -local LNetwork = _G.LuaNetworking - -LNetwork.HiddenChannel = 4 -LNetwork.AllPeers = "GNAP" -LNetwork.AllPeersString = "{1}/{2}/{3}" -LNetwork.SinglePeer = "GNSP" -LNetwork.SinglePeerString = "{1}/{2}/{3}/{4}" -LNetwork.ExceptPeer = "GNEP" -LNetwork.ExceptPeerString = "{1}/{2}/{3}/{4}" -LNetwork.Split = "[/]" - -function LNetwork:IsMultiplayer() - if not managers.network then - return false - end - return managers.network:session() -end - -function LNetwork:IsHost() - if not Network then - return false - end - return not Network:is_client() -end - -function LNetwork:IsClient() - if not Network then - return false - end - return Network:is_client() -end - -function LNetwork:LocalPeerID() - if managers.network == nil or managers.network:session() == nil or managers.network:session():local_peer() == nil then - return 0 - end - return managers.network:session():local_peer():id() or 0 -end - -function LNetwork:TableToString(tbl) - local str = "" - for k, v in pairs(tbl) do - if str ~= "" then - str = str .. "," - end - str = str .. ("{0}|{1}"):gsub("{0}", tostring(k)):gsub("{1}", tostring(v)) - end - return str -end - -function LNetwork:StringToTable(str) - local tbl = {} - local tblPairs = string.split( str, "[,]" ) - for k, v in pairs(tblPairs) do - local pairData = string.split( v, "[|]" ) - tbl[ pairData[1] ] = pairData[2] - end - return tbl -end - -function LNetwork:GetNameFromPeerID(id) - - if managers.network and managers.network:session() and managers.network:session():peers() then - - for k, v in pairs( managers.network:session():peers() ) do - if k == id then - return v:name() - end - end - - end - - return "No Name" - -end - -function LNetwork:GetPeers() - return managers.network:session():peers() -end - -function LNetwork:GetNumberOfPeers() - local i = 0 - for k, v in pairs( managers.network:session():peers() ) do - i = i + 1 - end - return i -end - -function LNetwork:SendToPeers(type_prm, data) - local dataString = LNetwork.AllPeersString - dataString = dataString:gsub("{1}", LNetwork.AllPeers) - dataString = dataString:gsub("{2}", type_prm) - dataString = dataString:gsub("{3}", data) - LNetwork:SendStringThroughChat(dataString) -end - -function LNetwork:SendToPeer(peer, type_prm, data) - local dataString = LNetwork.SinglePeerString - dataString = dataString:gsub("{1}", LNetwork.SinglePeer) - dataString = dataString:gsub("{2}", peer) - dataString = dataString:gsub("{3}", type_prm) - dataString = dataString:gsub("{4}", data) - LNetwork:SendStringThroughChat(dataString) -end - -function LNetwork:SendToPeersExcept(peer, type_prm, data) - local dataString = LNetwork.ExceptPeerString - local peerStr = peer - if type(peer) == "table" then - peerStr = "" - for k, v in pairs(peer) do - if peerStr ~= "" then - peerStr = peerStr .. "," - end - peerStr = peerStr .. tostring(v) - end - end - - dataString = dataString:gsub("{1}", LNetwork.ExceptPeer) - dataString = dataString:gsub("{2}", peerStr) - dataString = dataString:gsub("{3}", type_prm) - dataString = dataString:gsub("{4}", data) - LNetwork:SendStringThroughChat(dataString) -end - -function LNetwork:SendStringThroughChat(message) - if ChatManager._receivers == nil then - ChatManager._receivers = {} - end - ChatManager:send_message( LNetwork.HiddenChannel, tostring(LNetwork:LocalPeerID()), message ) -end - -Hooks:Add("ChatManagerOnReceiveMessage", "ChatManagerOnReceiveMessage_Network", function(channel_id, name, message, color, icon) - - local s = "[{1}] {2}: {3}" - s = s:gsub("{1}", channel_id) - s = s:gsub("{2}", name) - s = s:gsub("{3}", message) - log(s) - - local senderID = nil - if LNetwork:IsMultiplayer() then - - if name == managers.network:session():local_peer():name() then - senderID = LNetwork:LocalPeerID() - end - - for k, v in pairs( managers.network:session():peers() ) do - if v:name() == name then - senderID = k - end - end - - end - - if senderID == LNetwork:LocalPeerID() then return end - - if tonumber(channel_id) == LNetwork.HiddenChannel then - LNetwork:ProcessChatString(senderID or name, message, color, icon) - end - -end) - -Hooks:RegisterHook("NetworkReceivedData") -function LNetwork:ProcessChatString(sender, message, color, icon) - - local splitData = string.split( message, LNetwork.Split ) - local msgType = splitData[1] - if msgType == LNetwork.AllPeers then - LNetwork:ProcessAllPeers(sender, message, color, icon) - end - if msgType == LNetwork.SinglePeer then - LNetwork:ProcessSinglePeer(sender, message, color, icon) - end - if msgType == LNetwork.ExceptPeer then - LNetwork:ProcessExceptPeer(sender, message, color, icon) - end - -end - -function LNetwork:ProcessAllPeers(sender, message, color, icon) - local splitData = string.split( message, LNetwork.Split ) - Hooks:Call("NetworkReceivedData", sender, splitData[2], splitData[3]) -end - -function LNetwork:ProcessSinglePeer(sender, message, color, icon) - - local splitData = string.split( message, LNetwork.Split ) - local toPeer = tonumber( splitData[2] ) - - if toPeer == LNetwork:LocalPeerID() then - Hooks:Call("NetworkReceivedData", sender, splitData[3], splitData[4]) - end - -end - -function LNetwork:ProcessExceptPeer(sender, message, color, icon) - - local splitData = string.split( message, LNetwork.Split ) - local exceptedPeers = string.split( splitData[2], "[,]" ) - - local excepted = false - for k, v in pairs(exceptedPeers) do - if tonumber(v) == LNetwork:LocalPeerID() then - excepted = true - end - end - - if not excepted then - Hooks:Call("NetworkReceivedData", sender, splitData[3], splitData[4]) - end - -end - --- Extensions -LNetwork._networked_colour_string = "r:{1}|g:{2}|b:{3}|a:{4}" -function LNetwork:ColourToString(col) - local dataString = LNetwork._networked_colour_string - dataString = dataString:gsub("{1}", math.round_with_precision(col.r, 4)) - dataString = dataString:gsub("{2}", math.round_with_precision(col.g, 4)) - dataString = dataString:gsub("{3}", math.round_with_precision(col.b, 4)) - dataString = dataString:gsub("{4}", math.round_with_precision(col.a, 4)) - return dataString -end - -function LNetwork:StringToColour(str) - - local data = string.split( str, "[|]" ) - if #data < 4 then - return nil - end - - local split_str = "[:]" - local r = tonumber(string.split(data[1], split_str)[2]) - local g = tonumber(string.split(data[2], split_str)[2]) - local b = tonumber(string.split(data[3], split_str)[2]) - local a = tonumber(string.split(data[4], split_str)[2]) - - return Color(a, r, g, b) - -end diff --git a/mods/base/req/notifications.lua b/mods/base/req/notifications.lua deleted file mode 100644 index 8ffd9da..0000000 --- a/mods/base/req/notifications.lua +++ /dev/null @@ -1,264 +0,0 @@ - -NotificationsManager = NotificationsManager or {} -local Notify = NotificationsManager -Notify._notifications = {} -Notify._current_notification = 1 -Notify._NOTIFICATION_TIME = 6.5 -Notify._time_to_next_notification = Notify._NOTIFICATION_TIME - -Hooks:RegisterHook("NotificationManagerOnNotificationsUpdated") - -function Notify:GetNotifications() - return self._notifications -end - -function Notify:GetCurrentNotification() - return self._notifications[ self._current_notification ] -end - -function Notify:GetCurrentNotificationIndex() - return self._current_notification -end - -function Notify:AddNotification( id, title, message, priority, callback ) - - if not id then - log("[Error] Attempting to add notification with no id!") - return false - end - - for k, v in ipairs( self._notifications ) do - if v.id == id then - local error_str = ("[Error] Notification already has a notification with id '{1}'! Can not add duplicate id's!"):gsub("{1}", id) - log( error_str ) - return false - end - end - - local tbl = { - id = id, - title = title or "", - message = message or "", - priority = priority or 0, - callback = callback or nil, - read = false - } - - table.insert( self._notifications, tbl ) - table.sort( self._notifications, function(a, b) - return a.priority > b.priority - end) - - self:_OnUpdated() - return true - -end - -function Notify:UpdateNotification( id, new_title, new_message, new_priority, new_callback ) - - if not id then - log("[Error] Attempting to update notification with no id!") - return false - end - - local updated = false - for k, v in ipairs( self._notifications ) do - - if v.id == id then - - v.title = new_title or v.title - v.message = new_message or v.message - v.priority = new_priority or v.priority - v.callback = new_callback or v.callback - v.read = false - - updated = true - - end - - end - - if not updated then - local error_str = ("[Warning] Could not find notification with id '{1}', it has not been updated!"):gsub("{1}", id) - log( error_str ) - return false - end - - self:_OnUpdated() - return true - -end - -function Notify:RemoveNotification( id ) - - if not id then - log("[Error] Attempting to remove notification with no id!") - return false - end - - local tbl = {} - - for k, v in ipairs( self._notifications ) do - if v.id ~= id then - table.insert( tbl, v ) - end - end - - self._notifications = tbl - self:_OnUpdated() - return true - -end - -function Notify:ClearNotifications() - self._notifications = {} - self:_OnUpdated() -end - -function Notify:NotificationExists( id ) - - for k, v in ipairs( self._notifications ) do - if v.id == id then - return true - end - end - - return false - -end - -function Notify:ShowNextNotification( suppress_sound ) - - self._current_notification = self._current_notification + 1 - if self._current_notification > #self._notifications then - self._current_notification = 1 - end - if not suppress_sound then - managers.menu_component:post_event("highlight") - end - self:_OnUpdated() - self:_ResetTimeToNextNotification() - -end - -function Notify:ShowPreviousNotification( suppress_sound ) - - self._current_notification = self._current_notification - 1 - if self._current_notification < 1 then - self._current_notification = #self._notifications - end - if not suppress_sound then - managers.menu_component:post_event("highlight") - end - self:_OnUpdated() - self:_ResetTimeToNextNotification() - -end - -function Notify:ClickNotification( suppress_sound ) - - local notif = self:GetCurrentNotification() - if notif and notif.callback then - notif.callback() - if not suppress_sound then - managers.menu_component:post_event("menu_enter") - end - end - -end - -function Notify:MarkNotificationAsRead( id ) - - if not id then - log("[Error] Attempting to mark notification with no id!") - return false - end - - for k, v in ipairs( self._notifications ) do - if v.id == id then - v.read = true - return true - end - end - - return false - -end - -function Notify:_OnUpdated() - if not self:GetCurrentNotification().read then - managers.menu_component:post_event("job_appear") - end - Hooks:Call("NotificationManagerOnNotificationsUpdated", self, self._notifications) -end - -function Notify:_ResetTimeToNextNotification() - NotificationsManager._time_to_next_notification = NotificationsManager._NOTIFICATION_TIME -end - --- Auto-scroll notifications -Hooks:Add("MenuUpdate", "Base_Notifications_MenuUpdate", function(t, dt) - - if #NotificationsManager:GetNotifications() > 1 then - - local hovering = false - if managers.menu_component._notifications_gui then - hovering = managers.menu_component._notifications_gui._hovering_on_notification - end - - if not hovering then - - NotificationsManager._time_to_next_notification = NotificationsManager._time_to_next_notification - dt - if NotificationsManager._time_to_next_notification <= 0 then - NotificationsManager:ShowNextNotification( true ) - NotificationsManager:_ResetTimeToNextNotification() - end - - end - - end - -end) - --- Add notifications GUI to main menu -Hooks:Add("MenuComponentManagerInitialize", "Base_Notifications_MenuComponentManagerInitialize", function(menu) - - menu._create_notifications_gui = function( self ) - self:create_notifications_gui() - end - - menu.create_notifications_gui = function( self ) - self:close_notifications_gui() - self._notifications_gui = NotificationsGuiObject:new( self._ws ) - end - - menu.refresh_notifications_gui = function( self ) - if self._notifications_gui then - self:create_notifications_gui() - end - end - - menu.close_notifications_gui = function( self ) - if self._notifications_gui then - self._notifications_gui:close() - self._notifications_gui = nil - end - end - - menu._active_components.lua_mod_notifications = { - create = callback(menu, menu, "create_notifications_gui"), - close = callback(menu, menu, "close_notifications_gui") - } - -end) - -Hooks:Add("MenuComponentManagerPreSetActiveComponents", "Base_Notifications_MenuComponentManagerPreSetActiveComponents", function(menu, components, node) - - if node then - local node_name = node._parameters.name - if node._default_item_name and node_name == "main" then - table.insert( components, "lua_mod_notifications" ) - end - end - -end) diff --git a/mods/base/req/notifications_gui_object.lua b/mods/base/req/notifications_gui_object.lua deleted file mode 100644 index d1fab7d..0000000 --- a/mods/base/req/notifications_gui_object.lua +++ /dev/null @@ -1,477 +0,0 @@ - -NotificationsGuiObject = NotificationsGuiObject or class() -NotificationsGuiObject._edge_padding = 2 - -local HIGHLIGHT_VISIBLE = 0.3 -local HIGHLIGHT_INVISIBLE = 0 -local VISIBILITY_THRESHOLD = 0.001 -local CHANGE_NOTIF_THRESHOLD = 0.15 -local HIGHLIGHT_PADDING = 2 - -function NotificationsGuiObject:init(ws) - - local panel = ws:panel():panel() - managers.menu_component:close_contract_gui() - - local next_level_data = managers.experience:next_level_data() or {} - local font = tweak_data.menu.pd2_small_font - local font_size = tweak_data.menu.pd2_small_font_size - local max_left_len = 0 - local max_right_len = 0 - local extra_w = font_size * 4 - local icon_size = 16 - - local highlight_rect = panel:rect({ - name = "highlight", - color = tweak_data.screen_colors.button_stage_3, - alpha = HIGHLIGHT_INVISIBLE, - blend_mode = "add", - layer = 0, - }) - - local highlight_left_rect = panel:rect({ - name = "highlight_left", - color = tweak_data.screen_colors.button_stage_3, - alpha = HIGHLIGHT_INVISIBLE, - blend_mode = "add", - layer = 0, - }) - - local highlight_right_rect = panel:rect({ - name = "highlight_right", - color = tweak_data.screen_colors.button_stage_3, - alpha = HIGHLIGHT_INVISIBLE, - blend_mode = "add", - layer = 0, - }) - - local update_icon = panel:bitmap({ - texture = "guis/textures/pd2/blackmarket/inv_newdrop", - w = icon_size, - h = icon_size, - x = 10, - y = 10, - color = Color.white:with_alpha(0), - blend_mode = "add", - layer = 2 - }) - extra_w = extra_w - icon_size - - local heat_glow = panel:bitmap({ - texture = "guis/textures/pd2/hot_cold_glow", - layer = 1, - w = 32, - h = 32, - blend_mode = "add", - color = Color.yellow:with_alpha(0), - }) - heat_glow:set_center(10 + icon_size / 2 - 4, 10 + icon_size / 2) - - local focus = ws:panel():bitmap({ - name = "focus", - texture = "guis/textures/crimenet_map_circle", - layer = 10, - color = Color.white:with_alpha(0), - blend_mode = "add", - w = 0, - h = 0, - }) - focus:set_center(10 + icon_size / 2 - 4, 10 + icon_size / 2) - - local notification_title_text = panel:text({ - font = font, - font_size = font_size, - text = managers.localization:text("base_mod_notifications_none"), - y = 10, - color = tweak_data.screen_colors.text - }) - self:_make_fine_text(notification_title_text) - notification_title_text:set_left(math.round(update_icon:right())) - max_left_len = math.max(max_left_len, notification_title_text:w()) - - local total_money_text = panel:text({ - text = self:get_text("hud_offshore_account") .. ": " .. managers.experience:cash_string(managers.money:offshore()), - font_size = font_size, - font = font, - color = tweak_data.screen_colors.text:with_alpha(0) - }) - self:_make_fine_text(total_money_text) - total_money_text:set_left(math.round(update_icon:right())) - total_money_text:set_top(math.round(notification_title_text:bottom())) - total_money_text:set_height(0) - max_left_len = math.max(max_left_len, total_money_text:w()) - - local notification_message_text = panel:text({ - text = "", - font_size = font_size, - font = font, - color = tweak_data.screen_colors.text - }) - self:_make_fine_text(notification_message_text) - notification_message_text:set_left(math.round(update_icon:right())) - notification_message_text:set_top(math.round(total_money_text:bottom())) - max_left_len = math.max(max_left_len, notification_message_text:w()) - - local font_scale = 1 - local mastermind_ponts, num_skills = managers.skilltree:get_tree_progress("mastermind") - mastermind_ponts = string.format("%02d", mastermind_ponts) - local mastermind_text = panel:text({ - text = self:get_text("menu_profession_progress", { - profession = self:get_text("st_menu_mastermind"), - progress = mastermind_ponts, - num_skills = num_skills - }), - font_size = font_size * font_scale, - font = font, - color = tweak_data.screen_colors.text:with_alpha(0), - y = 10 - }) - self:_make_fine_text(mastermind_text) - max_right_len = math.max(max_right_len, mastermind_text:w()) + extra_w - - local prev_notification_text = panel:text({ - font = font, - font_size = font_size, - text = managers.localization:text("base_mod_notifications_prev"), - x = 10, - y = 10, - color = tweak_data.screen_colors.text:with_alpha( 0.3 ) - }) - self:_make_fine_text(prev_notification_text) - - local next_notification_text = panel:text({ - font = font, - font_size = font_size, - text = managers.localization:text("base_mod_notifications_next"), - x = 10, - y = 10, - color = tweak_data.screen_colors.text:with_alpha( 0.3 ) - }) - self:_make_fine_text(next_notification_text) - - local notification_count_text = panel:text({ - font = font, - font_size = font_size * 0.8, - text = managers.localization:text("base_mod_notifications_count", {["current"] = 1, ["max"] = 1}), - x = 10, - y = 10, - color = tweak_data.screen_colors.text:with_alpha( 0.3 ) - }) - self:_make_fine_text(notification_count_text) - - self._panel = panel - self._panel:set_size(update_icon:w() + max_left_len + 15 + max_right_len + 10, math.max(notification_message_text:bottom(), mastermind_text:bottom()) + 8) - self._panel:set_bottom(self._panel:parent():h() - 200) - self._panel_box = BoxGuiObject:new(self._panel, { - sides = { - 1, - 1, - 1, - 1 - } - }) - - mastermind_text:set_right(self._panel:w() - 10) - update_icon:move(-5, 0) - self:_rec_round_object(panel) - - self._highlight_rect = highlight_rect - self._highlight_left_rect = highlight_left_rect - self._highlight_right_rect = highlight_right_rect - self._heat_glow = heat_glow - self._focus = focus - self._update_icon = update_icon - self._notification_title_text = notification_title_text - self._notification_message_text = notification_message_text - self._total_money_text = total_money_text - self._mastermind_text = mastermind_text - self._max_left_len = max_left_len - self._max_right_len = max_right_len - - self._prev_notification_text = prev_notification_text - self._next_notification_text = next_notification_text - self._notification_count_text = notification_count_text - - self._hovering_on_notification = false - - self:LoadNotifications() - -end - -function NotificationsGuiObject:_rec_round_object(object) - local x, y, w, h = object:shape() - object:set_shape(math.round(x), math.round(y), math.round(w), math.round(h)) - if object.children then - for i, d in ipairs(object:children()) do - self:_rec_round_object(d) - end - end -end - -function NotificationsGuiObject:get_text(text, macros) - return utf8.to_upper(managers.localization:text(text, macros)) -end - -function NotificationsGuiObject:_make_fine_text(text) - local x, y, w, h = text:text_rect() - text:set_size(w, h) - text:set_position(math.round(text:x()), math.round(text:y())) -end - -function NotificationsGuiObject:close() - - if self._panel and alive(self._panel) then - - if self._focus and alive(self._focus) then - self._panel:parent():remove( self._focus ) - self._focus = nil - end - - self._panel:parent():remove(self._panel) - self._panel = nil - - end - -end - -function NotificationsGuiObject:LoadNotifications() - - local notifs = NotificationsManager:GetNotifications() - if #notifs < 1 then - - self._notification_title_text:set_text( managers.localization:text("base_mod_notifications_none") ) - self._notification_message_text:set_text( "" ) - self:update() - - else - - local notif = NotificationsManager:GetCurrentNotification() - if self._panel and alive(self._panel) then - - self._notification_title_text:set_text( notif.title ) - self._notification_message_text:set_text( notif.message ) - - self._update_icon:set_color( Color.white:with_alpha(notif.read and 0 or 1) ) - self._heat_glow:set_color( Color.yellow:with_alpha(notif.read and 0 or 0.7) ) - - self:update() - - DelayedCalls:Add("MarkNotificationAsRead", 0.2, function() - NotificationsManager:MarkNotificationAsRead( notif.id ) - end) - - end - - end - -end - -function NotificationsGuiObject:update() - - local update_icon = self._update_icon - local notification_title_text = self._notification_title_text - local notification_message_text = self._notification_message_text - local total_money_text = self._total_money_text - local mastermind_text = self._mastermind_text - - if alive(update_icon) and alive(notification_title_text) and alive(notification_message_text) and alive(total_money_text) and alive(mastermind_text) then - - self:_make_fine_text(notification_title_text) - notification_title_text:set_left(math.round(update_icon:right())) - self._max_left_len = math.max(self._max_left_len, notification_title_text:w()) - - self:_make_fine_text(notification_message_text) - notification_message_text:set_left(math.round(update_icon:right())) - notification_message_text:set_top(math.round(total_money_text:bottom())) - self._max_left_len = math.max(self._max_left_len, notification_message_text:w()) - - self._panel:set_size(self._panel:w(), math.max(notification_message_text:bottom(), mastermind_text:bottom()) + 8) - self._panel:set_bottom(self._panel:parent():h() - 200) - - self._panel_box:close() - self._panel_box = BoxGuiObject:new(self._panel, { - sides = { - 1, - 1, - 1, - 1 - } - }) - - end - - local prev_notification_text = self._prev_notification_text - local next_notification_text = self._next_notification_text - local notification_count_text = self._notification_count_text - - if alive(prev_notification_text) and alive(next_notification_text) and alive(notification_count_text) then - - local padding = self._edge_padding - local alpha = #NotificationsManager:GetNotifications() > 1 and 1 or 0 - - prev_notification_text:set_left( padding ) - prev_notification_text:set_top( self._panel:h() / 2 - prev_notification_text:h() / 2 ) - prev_notification_text:set_alpha( alpha ) - - next_notification_text:set_right( self._panel:w() - padding ) - next_notification_text:set_top( self._panel:h() / 2 - next_notification_text:h() / 2 ) - next_notification_text:set_alpha( alpha ) - - notification_count_text:set_left( padding ) - notification_count_text:set_bottom( self._panel:h() - padding ) - notification_count_text:set_alpha( alpha ) - - local current = NotificationsManager:GetCurrentNotificationIndex() - local num_notifs = #NotificationsManager:GetNotifications() - notification_count_text:set_text( managers.localization:text("base_mod_notifications_count", {["current"] = current, ["max"] = num_notifs}) ) - - end - - local highlight_rect = self._highlight_rect - local highlight_left_rect = self._highlight_left_rect - local highlight_right_rect = self._highlight_right_rect - - if alive(highlight_rect) and alive(highlight_left_rect) and alive(highlight_right_rect) then - - local panel = self._panel - - highlight_rect:set_h( panel:h() - HIGHLIGHT_PADDING * 2 ) - highlight_rect:set_w( panel:w() - HIGHLIGHT_PADDING * 2 ) - highlight_rect:set_top( HIGHLIGHT_PADDING ) - highlight_rect:set_left( HIGHLIGHT_PADDING ) - - highlight_left_rect:set_h( panel:h() - HIGHLIGHT_PADDING * 2 ) - highlight_left_rect:set_w( panel:w() * CHANGE_NOTIF_THRESHOLD - HIGHLIGHT_PADDING * 2 ) - highlight_left_rect:set_top( HIGHLIGHT_PADDING ) - highlight_left_rect:set_left( HIGHLIGHT_PADDING ) - - highlight_right_rect:set_h( panel:h() - HIGHLIGHT_PADDING * 2 ) - highlight_right_rect:set_w( panel:w() * CHANGE_NOTIF_THRESHOLD - HIGHLIGHT_PADDING * 2 ) - highlight_right_rect:set_top( HIGHLIGHT_PADDING ) - highlight_right_rect:set_right( panel:right() - HIGHLIGHT_PADDING ) - - end - -end - -function NotificationsGuiObject:SetHighlightVisibility( highlight, visible ) - - if visible then - if highlight:alpha() < HIGHLIGHT_VISIBLE - VISIBILITY_THRESHOLD then - highlight:set_alpha( HIGHLIGHT_VISIBLE ) - managers.menu_component:post_event("highlight") - end - else - if highlight:alpha() > HIGHLIGHT_INVISIBLE + VISIBILITY_THRESHOLD then - highlight:set_alpha( HIGHLIGHT_INVISIBLE ) - end - end - -end - -Hooks:Add("MenuComponentManagerOnMousePressed", "Base_ModUpdates_MenuComponentManagerOnMousePressed", function( menu, o, button, x, y ) - - if menu._notifications_gui and menu._notifications_gui._panel and menu._notifications_gui._panel:inside(x, y) then - - local x_percent = ( x - menu._notifications_gui._panel:x() ) / menu._notifications_gui._panel:w() - local num_notifs = #NotificationsManager:GetNotifications() - - if num_notifs > 1 then - if x_percent < CHANGE_NOTIF_THRESHOLD then - NotificationsManager:ShowPreviousNotification() - menu._notifications_gui:LoadNotifications() - return true - end - if x_percent > (1 - CHANGE_NOTIF_THRESHOLD) then - NotificationsManager:ShowNextNotification() - menu._notifications_gui:LoadNotifications() - return true - end - end - - NotificationsManager:ClickNotification() - return true - - end - -end) - -Hooks:Add("MenuComponentManagerOnMouseMoved", "Base_ModUpdates_MenuComponentManagerOnMouseMoved", function( menu, o, x, y ) - - if menu._notifications_gui then - - local highlighted = false - local multiple_notifs = #NotificationsManager:GetNotifications() > 1 - - if multiple_notifs then - - -- Next notification highlight - local highlight_right_rect = menu._notifications_gui._highlight_right_rect - if alive( highlight_right_rect ) then - local highlight_visible = highlight_right_rect:inside( x, y ) - highlighted = highlighted or highlight_visible - menu._notifications_gui:SetHighlightVisibility( highlight_right_rect, highlight_visible ) - end - - -- Previous notification highlight - local highlight_left_rect = menu._notifications_gui._highlight_left_rect - if alive( highlight_left_rect ) then - local highlight_visible = highlight_left_rect:inside( x, y ) - highlighted = highlighted or highlight_visible - menu._notifications_gui:SetHighlightVisibility( highlight_left_rect, highlight_visible ) - end - - end - - -- Clickable area highlight - local highlight_rect = menu._notifications_gui._highlight_rect - if alive( highlight_rect ) then - - local current_notif = NotificationsManager:GetCurrentNotification() - local x_percent = ( x - menu._notifications_gui._panel:x() ) / menu._notifications_gui._panel:w() - local highlight_visible = false - if multiple_notifs then - highlight_visible = highlight_rect:inside( x, y ) and x_percent > CHANGE_NOTIF_THRESHOLD and x_percent < (1 - CHANGE_NOTIF_THRESHOLD) - else - highlight_visible = highlight_rect:inside( x, y ) - end - if current_notif and not current_notif.callback then - highlight_visible = false - end - - menu._notifications_gui:SetHighlightVisibility( highlight_rect, highlight_visible ) - highlighted = highlighted or highlight_visible - - end - - menu._notifications_gui._hovering_on_notification = highlighted - if highlighted then - return true, "link" - else - if alive(highlight_rect) and highlight_rect:inside( x, y ) then - return true, "arrow" - end - end - - end - -end) - -Hooks:Add("LogicOnSelectNode", "Base_ModUpdates_LogicOnSelectNode", function() - - local node = managers.menu:active_menu().logic:selected_node() - if node and node._default_item_name and node._default_item_name ~= "crimenet" then - - if managers.menu_component and managers.menu_component._notifications_gui then - managers.menu_component._notifications_gui:close() - end - - end - -end) - -Hooks:Add("NotificationManagerOnNotificationsUpdated", "NotificationManagerOnNotificationsUpdated_NotificationsGUI", function(notify, notifications) - if managers.menu_component and managers.menu_component._notifications_gui then - managers.menu_component._notifications_gui:LoadNotifications() - end -end) diff --git a/mods/base/req/persist_scripts.lua b/mods/base/req/persist_scripts.lua deleted file mode 100644 index 3073421..0000000 --- a/mods/base/req/persist_scripts.lua +++ /dev/null @@ -1,30 +0,0 @@ - -local LMM = LuaModManager -local C = LuaModManager.Constants - -Hooks:Add( "MenuUpdate", "MenuUpdate_Base_UpdatePersistScripts", function(t, dt) - LMM:UpdatePersistScripts() -end ) - -Hooks:Add( "GameSetupUpdate", "GameSetupUpdate_Base_UpdatePersistScripts", function(t, dt) - LMM:UpdatePersistScripts() -end ) - -function LMM:UpdatePersistScripts() - - for k, v in pairs( LMM:PersistScripts() ) do - - local global = v[ C.mod_persists_global_key ] - local script = v[ C.mod_script_path_key ] - local path = v[ C.mod_persists_path_key ] - local exists = _G[global] - - if not exists then - declare( "PersistScriptPath", path ) - dofile( script ) - end - - end - declare( "PersistScriptPath", nil ) - -end diff --git a/mods/base/req/quick_menu.lua b/mods/base/req/quick_menu.lua deleted file mode 100644 index 6f483ab..0000000 --- a/mods/base/req/quick_menu.lua +++ /dev/null @@ -1,97 +0,0 @@ - -QuickMenu = QuickMenu or class() -QuickMenu._menu_id_key = "quick_menu_id_" -QuickMenu._menu_id_index = 0 - -function QuickMenu:new( ... ) - return self:init( ... ) -end - -function QuickMenu:init( title, text, options, show_immediately ) - - QuickMenu._menu_id_index = QuickMenu._menu_id_index + 1 - self.dialog_data = { - id = QuickMenu._menu_id_key .. tostring( QuickMenu._menu_id_index ), - title = title, - text = text, - button_list = {}, - } - self.visible = false - - local add_default = false - if (not options) or (options ~= nil and type(options) ~= "table") or (options ~= nil and type(options) == "table" and #options == 0) then - add_default = true - end - if add_default then - local tbl = { - text = "OK", - is_cancel_button = true, - } - table.insert( options, tbl ) - end - - for k, option in ipairs( options ) do - - option.data = option.data - option.callback = option.callback - - local button = {} - local callback_data = { - data = option.data, - callback = option.callback - } - button.text = option.text - button.callback_func = callback( self, self, "_callback", callback_data ) - button.cancel_button = option.is_cancel_button or false - - if option.is_focused_button then - self.dialog_data.focus_button = #self.dialog_data.button_list + 1 - end - - table.insert( self.dialog_data.button_list, button ) - - end - - if show_immediately then - self:show() - end - - return self - -end - -function QuickMenu:_callback( callback_data ) - - if callback_data.callback then - callback_data.callback( callback_data.data ) - end - - self.visible = false - -end - -function QuickMenu:Show() - - if not self.visible then - self.visible = true - managers.system_menu:show( self.dialog_data ) - end - -end - -function QuickMenu:show() - self:Show() -end - -function QuickMenu:Hide() - - if self.visible then - managers.system_menu:close( self.dialog_data.id ) - self.visible = false - end - -end - -function QuickMenu:hide() - self:Hide() -end diff --git a/mods/base/req/update_mods.lua b/mods/base/req/update_mods.lua deleted file mode 100644 index 4d97d4e..0000000 --- a/mods/base/req/update_mods.lua +++ /dev/null @@ -1,393 +0,0 @@ - -LuaModUpdates = LuaModUpdates or {} -LuaModUpdates._updates_api_path = "http://api.paydaymods.com/updates/retrieve/?" -LuaModUpdates._updates_api_mod = "mod[{1}]={2}" -LuaModUpdates._updates_download_url = "http://download.paydaymods.com/download/latest/{1}" -LuaModUpdates._updates_notes_url = "http://download.paydaymods.com/download/patchnotes/{1}" -LuaModUpdates._notification_id = "lua_mod_updates_notif" -LuaModUpdates.__required_notification_id = "lua_mod_require_notif" - -LuaModUpdates._currently_downloading = {} -LuaModUpdates._current_download_dialog = nil - -Hooks:Add("MenuManagerOnOpenMenu", "Base_ModUpdates_MenuManagerOnOpenMenu", function( menu_manager, menu, position ) - - -- Check for updates after going to the main menu - if menu == "menu_main" then - - LuaModUpdates:ShowUpdatesAvailableNotification({}) - - if not LuaNetworking:IsMultiplayer() then - LuaModUpdates:CheckForUpdates( LuaModUpdates.ShowUpdatesAvailableCallback ) - end - - -- Remove temporary hook dll - LuaModUpdates:RemoveTemporaryDLL() - - local required = LuaModManager:Required() - - local required_count = table.size(required) - - local initial_mod - - for _, mod in pairs(required) do - initial_mod = mod - break - end - - if required_count == 1 then - LuaModUpdates:ShowModRequiredMessage(initial_mod) - elseif required_count > 1 then - LuaModUpdates:ShowMultiRequiredAvailableMessage( required ) - end - - LuaModUpdates:ShowRequiredModsNotification( required ) - - end - -end) - -function LuaModUpdates:RemoveTemporaryDLL() - log("[Updates] Attempting to remove temporary hook dll...") - local hook_result, hook_error = os.remove( LuaModManager.Constants.hook_dll_temp_name ) - if not hook_result then - log("[Warning] Could not remove hook dll: " .. tostring(hook_error)) - end -end - -Hooks:RegisterHook("ModUpdates_CheckedModForUpdates") -function LuaModUpdates:CheckForUpdates( callback ) - - local url_path = LuaModUpdates._updates_api_path - local i = 0 - - for k, v in pairs( LuaModManager:UpdateChecks() ) do - if LuaModManager:AreModUpdatesEnable( v.mod ) then - - if i > 0 then - url_path = url_path .. "&" - end - - url_path = url_path .. LuaModUpdates._updates_api_mod:gsub("{1}", i) - url_path = url_path:gsub("{2}", v.identifier) - i = i + 1 - - end - end - - if i > 0 then - LuaModUpdates:FetchUpdatesFromAPI( url_path, callback ) - end - -end - -function LuaModUpdates:FetchUpdatesFromAPI( path, callback ) - - -- Escape characters for URL - local url = path:gsub(" ", "%%20") - url = url:gsub("!", "%%21") - url = url:gsub("#", "%%23") - url = url:gsub("-", "%%2D") - - -- Get data from API - dohttpreq( url, function( data, id ) - - if data:is_nil_or_empty() then - log("[Error] Could not connect to PaydayMods.com API!") - return - end - - local server_data = json.decode( data ) - if server_data then - - for k, v in pairs( server_data ) do - log(string.format("[Updates] Received update data for '%s', server revision: %i", k, v.revision)) - end - - local mods_needing_updates = {} - local mods_required = {} - for k, v in pairs( LuaModManager:UpdateChecks() ) do - - local mod_data = server_data[v.identifier] - if mod_data then - - local local_version = tonumber( v.revision ) or -1 - local server_version = tonumber( mod_data.revision ) or -1 - - v.server_revision = server_version - v.update_required = local_version < server_version - if local_version < server_version then - table.insert( mods_needing_updates, v ) - end - - else - log( ("[Updates] Received no update data for '{1}'"):gsub("{1}", v.identifier) ) - end - - end - - LuaModUpdates:ShowUpdatesAvailableNotification( mods_needing_updates ) - - if callback then - callback( self, mods_needing_updates ) - end - - - else - log("[Error] Could not decode server updates data!") - end - - end ) - -end - -function LuaModUpdates:ShowUpdatesAvailableCallback( mods, required ) - if #mods == 1 then - LuaModUpdates:ShowUpdateAvailableMessage( mods[1] ) - elseif #mods > 1 then - LuaModUpdates:ShowMultiUpdateAvailableMessage( mods ) - end -end - -function LuaModUpdates.DoUpdateAllModsNow() - LuaModUpdates.OpenUpdateManagerNode() - log("[Updates] Updating all mods now...") -end - -function LuaModUpdates:ShowUpdatesAvailableNotification( mods_to_update ) - - local count = 0 - local message = "" - for k, v in pairs( mods_to_update ) do - local loc_table = { - ["mod"] = v.display_name or v.mod_table[ LuaModManager.Constants.mod_name_key ] - } - message = message .. managers.localization:text("base_mod_updates_updates_required_row", loc_table) .. "\n" - count = count + 1 - end - message = message .. managers.localization:text("base_mod_updates_click_manager") - - local loc_table = { - ["count"] = count, - ["s"] = count > 1 and "s" or "", - } - local title = count < 1 and managers.localization:text("base_mod_updates_all_up_to_date") or managers.localization:text("base_mod_updates_updates_required", loc_table) - local prio = count < 1 and 101 or 1001 - - if NotificationsManager:NotificationExists( LuaModUpdates._notification_id ) then - NotificationsManager:UpdateNotification( LuaModUpdates._notification_id, title, message, prio, LuaModUpdates.NotificationClickCallback ) - else - NotificationsManager:AddNotification( LuaModUpdates._notification_id, title, message, prio, LuaModUpdates.NotificationClickCallback ) - end - -end - -function LuaModUpdates:ShowRequiredModsNotification( mods_required ) - if table.size(mods_required) == 0 then - return - end - - local count = 0 - local message = "" - for k, v in pairs( mods_required ) do - local loc_table = { - ["mod"] = v.display_name - } - message = message .. managers.localization:text("base_mod_updates_updates_required_row", loc_table) .. "\n" - count = count + 1 - end - message = message .. managers.localization:text("base_mod_updates_click_manager") - - local loc_table = { - ["count"] = count, - ["s"] = count > 1 and "s" or "", - } - local title = count < 1 and managers.localization:text("base_mod_updates_all_up_to_date") or managers.localization:text("base_mod_updates_mod_required", loc_table) - local prio = count < 1 and 101 or 1001 - - if NotificationsManager:NotificationExists( LuaModUpdates.__required_notification_id ) then - NotificationsManager:UpdateNotification( LuaModUpdates.__required_notification_id, title, message, prio, LuaModUpdates.NotificationClickCallback ) - else - NotificationsManager:AddNotification( LuaModUpdates.__required_notification_id, title, message, prio, LuaModUpdates.NotificationClickCallback ) - end - -end - -function LuaModUpdates.NotificationClickCallback() - LuaModUpdates.OpenUpdateManagerNode() - return true -end - -function LuaModUpdates.OpenUpdateManagerNode() - - managers.menu:open_node("base_lua_mod_updates_menu") - - if managers.menu_component and managers.menu_component._notifications_gui then - managers.menu_component._notifications_gui:close() - end - -end - -function LuaModUpdates:VerifyModIsDownloadable( mod_id ) - for k, v in pairs( LuaModManager:UpdateChecks() ) do - if mod_id == v.identifier then - return v.server_revision and v.server_revision >= 0 or false - end - end - return false -end - -function LuaModUpdates:DownloadAndStoreMod( mod_id ) - - if not self:VerifyModIsDownloadable( mod_id ) then - log("[Updates][Warning] Attempted to download a mod which is not on the server, halting...") - end - - local url = self._updates_download_url:gsub("{1}", mod_id) - log( ("[Updates] Downloading mod data for {1}"):gsub("{1}", mod_id) ) - - local http_id = dohttpreq( url, LuaModUpdates.ModDownloadFinished, LuaModUpdates.UpdateDownloadDialog ) - log("[Updates] Started http download: " .. tostring(http_id)) - - local mod_name = LuaModUpdates:GetModFriendlyName( mod_id ) - managers.menu:show_download_progress( mod_name ) - - LuaModUpdates._currently_downloading[http_id] = mod_id - -end - -function LuaModUpdates.ModDownloadFinished( data, http_id ) - - local self = LuaModUpdates - local psuccess, perror = pcall(function() - - log("[Updates] Finished http download: " .. tostring(http_id)) - - local mod_id = LuaModUpdates._currently_downloading[http_id] - local mod_table = LuaModUpdates:GetModTable( mod_id ) - local mod_path = mod_table.mod - - log( ("[Updates] Finished downloading mod data for {1}"):gsub("{1}", tostring(mod_id)) ) - LuaModUpdates:SetDownloadDialogKey( "mod_download_complete", true ) - - if data:is_nil_or_empty() then - log("[Updates] Update failed, no data received!") - LuaModUpdates:SetDownloadDialogKey( "mod_download_failed", true ) - return - end - - local C = LuaModManager.Constants - local download_path = C.mods_directory .. C.downloads_directory - local file_path = download_path .. tostring(mod_id) .. ".zip" - log("[Updates] Saving mod to file path: " .. file_path) - - local file = io.open( file_path, "wb+" ) - if file then - - file:write( data ) - file:close() - - local install_dir = mod_table.install_dir or C.mods_directory - if not mod_table.install_dir and not mod_table.required then - io.remove_directory_and_files( mod_path ) - else - - local install_path = mod_table.install_dir - if mod_table.install_folder then - install_path = install_path .. tostring(mod_table.install_folder) .. "/" - io.remove_directory_and_files( install_path ) - end - - -- Special case for hook dll - if mod_id == C.hook_dll_id or mod_id == "testmod" or mod_id == "payday2bltdll_test" then - - local hook_result, hook_error = os.rename( C.hook_dll_name, C.hook_dll_temp_name ) - if not hook_result then - log( "[Error] Could not update hook DLL! " .. tostring(hook_error) ) - return - end - - if mod_table.revision_path and mod_table.server_revision then - - local revision_file, file_err = io.open( mod_table.revision_path, "w+" ) - if revision_file then - revision_file:write( tostring(mod_table.server_revision) ) - revision_file:close() - end - - else - log( "[Error] No revision path or server revision found in mod table, aborting update of DLL" ) - return - end - - end - - end - - unzip( file_path, install_dir ) - LuaModUpdates:SetDownloadDialogKey( "mod_extraction_complete", true ) - - end - - LuaModUpdates._currently_downloading[http_id] = nil - self._current_download_dialog = nil - - end) - if not psuccess then - log("[Error] " .. perror) - end - -end - -function LuaModUpdates.UpdateDownloadDialog( id, bytes, total_bytes ) - LuaModUpdates:SetDownloadDialogKey( "bytes_downloaded", bytes or 0 ) - LuaModUpdates:SetDownloadDialogKey( "bytes_total", total_bytes or 0 ) -end - -function LuaModUpdates:RegisterDownloadDialog( dialog ) - self._current_download_dialog = dialog -end - -function LuaModUpdates:SetDownloadDialogKey( key, data ) - - if self._current_download_dialog then - local dialog = self._current_download_dialog - dialog._panel_script._anim_data[ key ] = data - end - -end - -function LuaModUpdates:GetModFriendlyName( mod_id ) - - for k, v in ipairs( LuaModManager:UpdateChecks() ) do - if v.identifier == mod_id then - local mod_definition = LuaModManager:GetMod( v.mod ).definition - return v.display_name or mod_definition[ LuaModManager.Constants.mod_name_key ] - end - end - - for k, v in pairs( LuaModManager:Required() ) do - if v.identifier == mod_id then - return v.display_name - end - end - - return mod_id - -end - -function LuaModUpdates:GetModTable( mod_id ) - - for k, v in ipairs( LuaModManager:UpdateChecks() ) do - if v.identifier == mod_id then - return v - end - end - - for k, v in pairs( LuaModManager:Required() ) do - if v.identifier == mod_id then - return v - end - end - -end diff --git a/mods/base/req/update_mods_menu.lua b/mods/base/req/update_mods_menu.lua deleted file mode 100644 index d4dd054..0000000 --- a/mods/base/req/update_mods_menu.lua +++ /dev/null @@ -1,365 +0,0 @@ -function LuaModUpdates:ShowMultiRequiredAvailableMessage( req_mods ) - local mods = clone(req_mods) - - for k, v in pairs(mods) do - if not LuaModManager:AreModUpdatesEnable( v.identifier ) then - mods[k] = nil - end - end - - if not (table.size(mods) > 0) then - return - end - - local mod_names = "" - for k, v in pairs( mods ) do - local name = v.display_name - mod_names = mod_names .. " " .. name .. "\n" - end - - local loc_table = { ["mods"] = mod_names } - local menu_title = managers.localization:text("base_mod_updates_show_multiple_require_available", loc_table) - local menu_message = managers.localization:text("base_mod_updates_show_multiple_require_available_message", loc_table) - local menu_options = { - -- [1] = { - -- text = managers.localization:text("base_mod_updates_update_all_now"), - -- callback = LuaModUpdates.DoUpdateAllModsNow, - -- }, - [1] = { - text = managers.localization:text("base_mod_updates_open_update_manager"), - callback = LuaModUpdates.OpenUpdateManagerNode, - }, - [2] = { - text = managers.localization:text("base_mod_required_update_later"), - is_cancel_button = true, - }, - } - QuickMenu:new( menu_title, menu_message, menu_options, true ) - -end - -function LuaModUpdates:ShowMultiUpdateAvailableMessage( mods ) - - local mod_names = "" - for k, v in pairs( mods ) do - local mod_definition = LuaModManager:GetMod( v.mod ).definition - local name = v.display_name or mod_definition[ LuaModManager.Constants.mod_name_key ] - mod_names = mod_names .. " " .. name .. "\n" - end - - local loc_table = { ["mods"] = mod_names } - local menu_title = managers.localization:text("base_mod_updates_show_multiple_update_available", loc_table) - local menu_message = managers.localization:text("base_mod_updates_show_multiple_update_available_message", loc_table) - local menu_options = { - -- [1] = { - -- text = managers.localization:text("base_mod_updates_update_all_now"), - -- callback = LuaModUpdates.DoUpdateAllModsNow, - -- }, - [1] = { - text = managers.localization:text("base_mod_updates_open_update_manager"), - callback = LuaModUpdates.OpenUpdateManagerNode, - }, - [2] = { - text = managers.localization:text("base_mod_updates_update_later"), - is_cancel_button = true, - }, - } - QuickMenu:new( menu_title, menu_message, menu_options, true ) - -end - -function LuaModUpdates:ShowUpdateAvailableMessage( mod_tbl ) - - local loc_table = { ["mod_name"] = self:GetModFriendlyName(mod_tbl.identifier) } - local menu_title = managers.localization:text("base_mod_updates_show_update_available", loc_table) - local menu_message = managers.localization:text("base_mod_updates_show_update_available_message", loc_table) - local menu_options = { - [1] = { - text = managers.localization:text("base_mod_updates_update_mod_now", loc_table), - callback = function() - LuaModUpdates:OpenUpdateManagerNode() - LuaModUpdates.ForceDownloadAndInstallMod(mod_tbl.identifier) - end, - }, - [2] = { - text = managers.localization:text("base_mod_updates_open_update_manager"), - callback = LuaModUpdates.OpenUpdateManagerNode, - }, - [3] = { - text = managers.localization:text("base_mod_updates_open_update_notes"), - callback = LuaModUpdates.ShowModPatchNotes, - data = mod_tbl.identifier - }, - [4] = { - text = managers.localization:text("base_mod_updates_update_later"), - is_cancel_button = true, - }, - } - QuickMenu:new( menu_title, menu_message, menu_options, true ) - -end - -function LuaModUpdates:ShowModRequiredMessage( mod_tbl ) - if LuaModManager:AreModUpdatesEnable( mod_tbl.identifier ) then - local required_by = clone(mod_tbl.required_by) - table.remove(required_by, #required_by) - local loc_table = { ["req_mod_name"] = table.concat(required_by, ", ") .. " & " .. mod_tbl.required_by[#mod_tbl.required_by], ["mod_name"] = mod_tbl.display_name } - local menu_title = managers.localization:text("base_mod_updates_show_required_available", loc_table) - local menu_message = managers.localization:text(mod_tbl.optional and "base_mod_updates_show_required_available_optional_message" or "base_mod_updates_show_required_available_message", loc_table) - local menu_options = { - [1] = { - text = managers.localization:text("base_mod_required_update_mod_now", loc_table), - callback = function() - LuaModUpdates:OpenUpdateManagerNode() - LuaModUpdates.ForceDownloadAndInstallMod(mod_tbl.identifier) - end, - }, - [2] = { - text = managers.localization:text("base_mod_updates_open_update_manager"), - callback = LuaModUpdates.OpenUpdateManagerNode, - }, - [3] = { - text = managers.localization:text("base_mod_required_update_later"), - is_cancel_button = true, - }, - } - QuickMenu:new( menu_title, menu_message, menu_options, true ) - end -end - --- Updates menu -local mod_updates_menu = "base_lua_mod_updates_menu" -Hooks:Add("MenuManagerSetupCustomMenus", "Base_ModUpdatesMenu_SetupCustomMenus", function( menu_manager, nodes ) - MenuHelper:NewMenu( mod_updates_menu ) -end) - -Hooks:Add("MenuManagerPopulateCustomMenus", "Base_ModUpdatesMenu_PopulateCustomMenus", function( menu_manager, nodes ) - - MenuCallbackHandler.mod_updates_update_all = function(self, item) - log("Update all mods") - end - - MenuCallbackHandler.mod_updates_toggle_mod = function(self, item) - if item and item._parameters then - local mod_path = item._parameters.text_id:gsub("toggle_lua_auto_updates_", "") - if mod_path then - LuaModManager:SetModUpdatesState( mod_path, item:value() == "on" and true or false ) - end - end - end - - MenuCallbackHandler.mod_updates_check_mod = function(self, item) - if item and item._parameters then - local mod_path = item._parameters.text_id:gsub("button_check_for_updates_", "") - if mod_path then - LuaModUpdates:CheckForUpdates( function(updater, mods, required) - if not required then - LuaModUpdates:CheckModForUpdateAndShowOptions( mod_path ) - end - end ) - end - end - end - - MenuCallbackHandler.mod_updates_download_mod = function(self, item) - if item and item._parameters then - local mod_path = item._parameters.text_id:gsub("button_check_for_updates_", "") - if mod_path then - LuaModUpdates.ForceDownloadAndInstallMod(mod_path) - LuaModManager:SetModUpdatesState( mod_path, true ) --Reset Notification state for now installed mod - end - end - end - - local priority = ((#LuaModManager:UpdateChecks() * 3) + (table.size(LuaModManager:Required()) * 3)) - local toggle_updates_loc_str = "toggle_lua_auto_updates_{0}" - local check_for_updates_loc_str = "button_check_for_updates_{0}" - - --[[ - MenuHelper:AddButton({ - id = "lua_mods_update_all", - title = "base_mod_updates_update_all", - desc = "base_mod_updates_update_all_desc", - callback = "mod_updates_update_all", - menu_id = mod_updates_menu, - priority = priority + 3, - }) - - MenuHelper:AddDivider({ - id = "lua_mods_update_divider_1", - size = 16, - menu_id = mod_updates_menu, - priority = priority + 1, - }) - ]] - - for k, v in ipairs( LuaModManager:UpdateChecks() ) do - local mod_definition = v.mod and LuaModManager:GetMod( v.mod ).definition or nil - local mod_name = v.display_name or mod_definition and mod_definition[ LuaModManager.Constants.mod_name_key ] - local mod_name_table = { ["mod_name"] = mod_name } - local loc_toggle = toggle_updates_loc_str:gsub("{0}", v.identifier) - local loc_button = check_for_updates_loc_str:gsub("{0}", v.identifier) - LocalizationManager:add_localized_strings({ - [loc_toggle] = managers.localization:text("base_mod_automically_check_for_updates", mod_name_table), - [loc_toggle .. "_desc"] = managers.localization:text("base_mod_automically_check_for_updates_desc", mod_name_table), - [loc_button] = managers.localization:text("base_mod_check_for_updates_now", mod_name_table), - [loc_button .. "_desc"] = managers.localization:text("base_mod_check_for_updates_now_desc", mod_name_table), - }) - - local toggle = MenuHelper:AddToggle({ - id = "toggle_updates_" .. v.identifier, - title = loc_toggle, - desc = loc_toggle .. "_desc", - callback = "mod_updates_toggle_mod", - value = LuaModManager:AreModUpdatesEnable( v.identifier ), - menu_id = mod_updates_menu, - priority = priority, - }) - - MenuHelper:AddButton({ - id = "button_check_for_updates_" .. v.identifier, - title = loc_button, - desc = loc_button .. "_desc", - callback ="mod_updates_check_mod", - menu_id = mod_updates_menu, - priority = priority - 1, - }) - - MenuHelper:AddDivider({ - id = "divider_updates_" .. v.identifier, - size = 8, - menu_id = mod_updates_menu, - priority = priority - 2, - }) - - priority = priority - 3 - - end - - for k, v in pairs( LuaModManager:Required() ) do - local mod_definition = v.mod and LuaModManager:GetMod( v.mod ).definition or nil - local mod_name = v.display_name or mod_definition and mod_definition[ LuaModManager.Constants.mod_name_key ] - local mod_name_table = { ["mod_name"] = mod_name } - local loc_toggle = toggle_updates_loc_str:gsub("{0}", v.identifier) - local loc_button = check_for_updates_loc_str:gsub("{0}", v.identifier) - LocalizationManager:add_localized_strings({ - [loc_toggle] = managers.localization:text("base_mod_notify_required", mod_name_table), - [loc_toggle .. "_desc"] = managers.localization:text("base_mod_notify_required_desc", mod_name_table), - [loc_button] = managers.localization:text("base_mod_download_required_now", mod_name_table), - [loc_button .. "_desc"] = managers.localization:text("base_mod_download_required_now_desc", mod_name_table), - }) - - local toggle = MenuHelper:AddToggle({ - id = "toggle_notification_" .. v.identifier, - title = loc_toggle, - desc = loc_toggle .. "_desc", - callback = "mod_updates_toggle_mod", - value = LuaModManager:AreModUpdatesEnable( v.identifier ), - menu_id = mod_updates_menu, - priority = priority, - }) - - MenuHelper:AddButton({ - id = "button_check_for_updates_" .. v.identifier, - title = loc_button, - desc = loc_button .. "_desc", - callback = "mod_updates_download_mod", - menu_id = mod_updates_menu, - priority = priority - 1, - }) - - MenuHelper:AddDivider({ - id = "divider_updates_" .. v.identifier, - size = 8, - menu_id = mod_updates_menu, - priority = priority - 2, - }) - - priority = priority - 3 - - end - -end) - -Hooks:Add("MenuManagerBuildCustomMenus", "Base_ModUpdatesMenu_BuildCustomMenus", function( menu_manager, nodes ) - nodes[mod_updates_menu] = MenuHelper:BuildMenu( mod_updates_menu ) -end) - --- Info Boxes -function LuaModUpdates:CheckModForUpdateAndShowOptions( mod_id ) - - log("[Updates] Checking for updates for mod: " .. mod_id) - for k, v in pairs( LuaModManager:UpdateChecks() ) do - if v.identifier == mod_id then - - if v.update_required then - self:ShowModRequiresUpdate( mod_id ) - else - self:ShowModUpToDate( mod_id ) - end - - end - end - -end - -function LuaModUpdates:ShowModUpToDate( mod_id ) - - local message_id = self:VerifyModIsDownloadable( mod_id ) and "base_mod_update_no_update_available" or "base_mod_update_no_update_available_no_data" - - local mod_name_tbl = { ["mod_name"] = self:GetModFriendlyName( mod_id ) } - local title = managers.localization:text("base_mod_update_no_update_available_title", mod_name_tbl) - local message = managers.localization:text(message_id, mod_name_tbl) - local options = {} - - if self:VerifyModIsDownloadable( mod_id ) then - local download_btn = { - text = managers.localization:text("base_mod_update_no_update_available_force"), - callback = LuaModUpdates.ForceDownloadAndInstallMod, - data = mod_id - } - table.insert( options, download_btn ) - end - - local cancel_btn = { - text = managers.localization:text("dialog_ok"), - is_cancel_button = true - } - table.insert( options, cancel_btn ) - - QuickMenu:new( title, message, options, true ) - -end - -function LuaModUpdates:ShowModRequiresUpdate( mod_id ) - local mod_name_tbl = { ["mod_name"] = self:GetModFriendlyName( mod_id ) } - local title = managers.localization:text("base_mod_updates_update_mod_now", mod_name_tbl) - local message = managers.localization:text("base_mod_update_update_available", mod_name_tbl) - local options = { - [1] = { - text = managers.localization:text("base_mod_updates_update_now"), - callback = LuaModUpdates.ForceDownloadAndInstallMod, - data = mod_id - }, - [2] = { - text = managers.localization:text("base_mod_updates_open_update_notes"), - callback = LuaModUpdates.ShowModPatchNotes, - data = mod_id - }, - [3] = { - text = managers.localization:text("base_mod_updates_update_later"), - is_cancel_button = true - } - } - QuickMenu:new( title, message, options, true ) -end - -function LuaModUpdates.ForceDownloadAndInstallMod( data ) - LuaModUpdates:DownloadAndStoreMod( data ) -end - -function LuaModUpdates.ShowModPatchNotes( data ) - local url = LuaModUpdates._updates_notes_url:gsub("{1}", data) - Steam:overlay_activate("url", url) - LuaModUpdates:ShowModRequiresUpdate( data ) -end diff --git a/mods/base/req/utils.lua b/mods/base/req/utils.lua deleted file mode 100644 index 0c68e0a..0000000 --- a/mods/base/req/utils.lua +++ /dev/null @@ -1,288 +0,0 @@ - -_G.Utils = _G.Utils or {} - ---[[ - CloneClass( class ) - Copies an existing class into an orig table, so that class functions can be overwritten and called again easily - class, The class table to clone -]] -function _G.CloneClass( class ) - if not class.orig then - class.orig = clone(class) - end -end - ---[[ - PrintTable( tbl ) - Prints the contents of a table to your console - Warning, may cause game slowdown if the table is fairly large, only for debugging purposes - tbl, The table to print to console -]] -function _G.PrintTable( tbl, cmp ) - cmp = cmp or {} - if type(tbl) == "table" then - for k, v in pairs (tbl) do - if type(v) == "table" and not cmp[v] then - cmp[v] = true - log( string.format("[\"%s\"] = table", tostring(k)) ); - PrintTable (v, cmp) - else - log( string.format("\"%s\" = %s", tostring(k), tostring(v)) ) - end - end - else - log(tbl) - end -end - ---[[ - SaveTable( tbl, file ) - Saves the contents of a table to the specified file - tbl, The table to save to a file - file, The path (relative to payday2_win32_release.exe) and file name to save the table to -]] -function _G.SaveTable( tbl, file ) - Utils.DoSaveTable( tbl, {}, file, nil, "" ) -end - -function Utils.DoSaveTable( tbl, cmp, fileName, fileIsOpen, preText ) - - local file = nil - if fileIsOpen == nil then - file = io.open(fileName, "w") - else - file = fileIsOpen - end - - cmp = cmp or {} - if tbl and type(tbl) == "table" then - for k, v in pairs(tbl) do - if type(v) == "table" and not cmp[v] then - cmp[v] = true - file:write( preText .. string.format("[\"%s\"] -> table", tostring (k)) .. "\n" ) - Utils.DoSaveTable(v, cmp, fileName, file, preText .. "\t") - else - file:write( preText .. string.format( "\"%s\" -> %s", tostring(k), tostring(v) ) .. "\n" ) - end - end - else - file:write( preText .. tostring(tbl) .. "\n") - end - - if fileIsOpen == nil then - file:close() - end - -end - -Vector3.StringFormat = "%08f,%08f,%08f" -Vector3.MatchFormat = "([-0-9.]+),([-0-9.]+),([-0-9.]+)" - ---[[ - Vector3.ToString( v ) - Converts a Vector3 to a string, useful in conjunction with Networking - v, The Vector3 to convert to a formatted string - return, A formatted string containing the data of the Vector3 -]] -function Vector3.ToString( v ) - return string.format( Vector3.StringFormat, v.x, v.y, v.z ) -end - ---[[ - string.ToVector3( string ) - Converts a formatted string to a Vector3, useful in conjunction with Networking - string, The string to convert to a Vector3 - return, A Vector3 of the converted string or nil if no conversion could be made -]] -function string.ToVector3( string ) - local x, y, z = string:match( Vector3.MatchFormat ) - if x ~= nil and y ~= nil and z ~= nil then - return Vector3( tonumber(x), tonumber(y), tonumber(z) ) - end - return nil -end - ---[[ - string.is_nil_or_empty( str ) - Returns if a string exists or not - str, The string to check if it exists or is empty - return, Returns false if the string is empty ("") or nil, true otherwise -]] -function string.is_nil_or_empty( str ) - return str == "" or str == nil -end - ---[[ - math.round_with_precision( num, idp ) - Rounds a number to the specified precision (decimal places) - num, The number to round - idp, The number of decimal places to round to (0 default) - return, The input number rounded to the input precision (or floored integer) -]] -function math.round_with_precision( num, idp ) - local mult = 10 ^ (idp or 0) - return math.floor(num * mult + 0.5) / mult -end - ---[[ - IsInGameState() - Returns true if you are in GameState (loadout, ingame, end screens like victory and defeat) and false - if you are not. -]] -function Utils:IsInGameState() - if not game_state_machine then - return false - end - return string.find(game_state_machine:current_state_name(), "game") -end - ---[[ - IsInLoadingState() - Returns true if you are in a loading state, and false if you are not. -]] -function Utils:IsInLoadingState() - if not BaseNetworkHandler then - return false - end - return BaseNetworkHandler._gamestate_filter.waiting_for_players[ game_state_machine:last_queued_state_name() ] -end - ---[[ - IsInHeist() - Returns true if you are currently in game (you're able to use your weapons, spot, call teammates etc) and - false if you are not. Only returns true if currently ingame, does not check for GameState like IsInGameState(). -]] -function Utils:IsInHeist() - if not BaseNetworkHandler then - return false - end - return BaseNetworkHandler._gamestate_filter.any_ingame_playing[ game_state_machine:last_queued_state_name() ] -end - ---[[ - IsInCustody() - Returns true if the local player is in custody, and false if not. -]] -function Utils:IsInCustody() - local player = managers.player:local_player() - local in_custody = false - if managers and managers.trade and not alive( player ) and managers.network:session() and managers.network:session():local_peer() and managers.network:session():local_peer():id() then - in_custody = managers.trade:is_peer_in_custody(managers.network:session():local_peer():id()) - end - return in_custody -end - ---[[ - IsCurrentPrimaryOfCategory(type) - Checks current primary weapon's weapon class. - type, the weapon class to check for. "assault_rifle", "snp", "shotgun"; refer to weapontweakdata -]] -function Utils:IsCurrentPrimaryOfCategory(type) - local primary = managers.blackmarket:equipped_primary() - if primary then - local category = tweak_data.weapon[ primary.weapon_id ].category - return category == string.lower(type) - end - return false -end - ---[[ - IsCurrentSecondaryOfCategory(type) - Checks current secondary weapon's weapon class. - type, the weapon class to check for. "pistol", "shotgun", "smg"; refer to weapontweakdata -]] -function Utils:IsCurrentSecondaryOfCategory(type) - local secondary = managers.blackmarket:equipped_secondary() - if secondary then - local category = tweak_data.weapon[ secondary.weapon_id ].category - return category == string.lower(type) - end - return false -end - ---[[ - IsCurrentWeapon(type) - Checks current equipped weapon's name ID. - type, the weapon's ID. "aug", "glock_18c", "new_m4", "colt_1911"; refer to weaponfactorytweakdata -]] -function Utils:IsCurrentWeapon(type) - local weapon = managers.player:local_player():inventory():equipped_unit():base()._name_id - if weapon then - return weapon == string.lower(type) - end - return false -end - ---[[ - IsCurrentWeaponPrimary() - Checks if current equipped weapon is your primary weapon. -]] -function Utils:IsCurrentWeaponPrimary() - local weapon = managers.player:local_player():inventory():equipped_unit():base():selection_index() - local curstate = managers.player._current_state - if weapon then - return (curstate ~= "mask_off" and weapon == 2) - end -end - ---[[ - IsCurrentWeaponPrimary() - Checks if current equipped weapon is your secondary weapon. -]] -function Utils:IsCurrentWeaponSecondary() - local weapon = managers.player:local_player():inventory():equipped_unit():base():selection_index() - local curstate = managers.player._current_state - if weapon then - return (curstate ~= "mask_off" and weapon == 1) - end -end - ---[[ - Utils:GetPlayerAimPos( player, maximum_range ) - Gets the point in the world, as a Vector3, where the player is aiming at - player, The player to get the aiming position of - maximum_range, The maximum distance to check for a point (default 100000, 1km) - return, A Vector3 containing the location that the player is looking at, or false if the player was not looking at anything - or was looking at something past the maximum_range -]] -function Utils:GetPlayerAimPos( player, maximum_range ) - local ray = self:GetCrosshairRay(player:camera():position(), player:camera():position() + player:camera():forward() * (maximum_range or 100000)) - if not ray then - return false - end - return ray.hit_position -end - ---[[ - Utils:GetCrosshairRay( from, to, slot_mask ) - Gets a ray between two points and checks for a collision with the slot_mask along the ray - from, The starting position of the ray, defaults to the player's head - to, The ending position of the ray, defaults to 1m in from of the player's head - slot_mask, The collision group to check against the ray, defaults to all objects the player can shoot - return, A table containing the ray information -]] -function Utils:GetCrosshairRay( from, to, slot_mask ) - - slot_mask = slot_mask or "bullet_impact_targets" - - local player = managers.player:player_unit() - local from = from or player:camera():position() - local mvecTo = Vector3() - - mvector3.set( mvecTo, player:camera():forward() ) - mvector3.add(to, from) - - local colRay = World:raycast("ray", from, to, "slot_mask", managers.slot:get_mask(slot_mask)) - return colRay - -end - ---[[ - Utils:ToggleItemToBoolean( item ) - Gets the string value of a toggle item and converts it to a boolean value - item, The toggle menu item to get a boolean value from - return, True if the toggle item is on, false otherwise -]] -function Utils:ToggleItemToBoolean( item ) - return item:value() == "on" and true or false -end diff --git a/mods/downloads/downloads.txt b/mods/downloads/downloads.txt deleted file mode 100644 index d6989f5..0000000 --- a/mods/downloads/downloads.txt +++ /dev/null @@ -1,4 +0,0 @@ - -# Downloads -This is the downloads folder for the Payday 2 BLT. -All archives downloaded from the Payday 2 BLT update system will be downloaded here before being extracted and installed. diff --git a/mods/logs/log.txt b/mods/logs/log.txt deleted file mode 100644 index e69de29..0000000 diff --git a/mods/saves/blt_revision.txt b/mods/saves/blt_revision.txt deleted file mode 100644 index 56a6051..0000000 --- a/mods/saves/blt_revision.txt +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/mods/saves/saves.txt b/mods/saves/saves.txt deleted file mode 100644 index b7cdfb2..0000000 --- a/mods/saves/saves.txt +++ /dev/null @@ -1,4 +0,0 @@ - -# Saves -This is a folder for mods to save their users data in. -All data should be saved in this saves directory to ensure that no data is lost during the update process.