diff --git a/docs/apidoc/meta.md b/docs/apidoc/meta.md index f226829..346d030 100644 --- a/docs/apidoc/meta.md +++ b/docs/apidoc/meta.md @@ -10,4 +10,8 @@ Methods: - Sets the description of the mod. Character limit of 160. - `ModAPI.meta.icon(iconURL: String)` - Sets the icon of the mod. - - It can be extremely low res, it will not appear blurry. \ No newline at end of file + - It can be extremely low res, it will not appear blurry. +- `ModAPI.meta.version(versionCode: String)` + - Sets the version of the mod. Appended after the title. +- `ModAPI.meta.config(configFn: Function)` + - Once the client is fully loaded, creates a button in the mod manager GUI that runs the specified function when pressed. \ No newline at end of file diff --git a/injector.js b/injector.js index f705d87..0852b16 100644 --- a/injector.js +++ b/injector.js @@ -1,4 +1,4 @@ -globalThis.ModAPIVersion = "v2.7.2"; +globalThis.ModAPIVersion = "v2.7.3"; globalThis.doEaglerforge = true; document.querySelector("title").innerText = `EaglerForge Injector ${ModAPIVersion}`; document.querySelector("h1").innerText = `EaglerForge Injector ${ModAPIVersion}`; diff --git a/modgui.js b/modgui.js index a0c0d7a..6b58b16 100644 --- a/modgui.js +++ b/modgui.js @@ -248,15 +248,28 @@ globalThis.modapi_guikit = "(" + (() => { spacer.classList.add("nothing"); var controls = document.createElement("td"); - var button = document.createElement("button"); - button.innerText = "Delete"; - button.style.height = "3rem"; - button.addEventListener("click", async () => { + var deleteBtn = document.createElement("button"); + deleteBtn.innerText = "Delete"; + deleteBtn.style.height = "3rem"; + deleteBtn.addEventListener("click", async () => { await removeMod(i); window.modapi_displayModGui(); }); - button.classList.add("button"); - controls.appendChild(button); + deleteBtn.classList.add("button"); + controls.appendChild(deleteBtn); + + if (typeof ModAPI.meta._configMap[hash] === "function") { + var configBtn = document.createElement("button"); + configBtn.innerText = "Config"; + configBtn.style.height = "3rem"; + configBtn.style.marginLeft = "1rem"; + configBtn.addEventListener("click", async () => { + ModAPI.meta._configMap[hash](); + }); + configBtn.classList.add("button"); + controls.appendChild(configBtn); + } + tr.appendChild(mod); tr.appendChild(spacer); tr.appendChild(controls); diff --git a/postinit.js b/postinit.js index 0ae13ec..f75e2df 100644 --- a/postinit.js +++ b/postinit.js @@ -22,6 +22,7 @@ globalThis.modapi_postinit = "(" + (() => { ModAPI.meta = {}; ModAPI.meta._titleMap = {}; ModAPI.meta._descriptionMap = {}; + ModAPI.meta._configMap = {}; ModAPI.meta._developerMap = {}; ModAPI.meta._iconMap = {}; ModAPI.meta._versionMap = {}; @@ -78,6 +79,9 @@ globalThis.modapi_postinit = "(" + (() => { " - Made the mod gui open before the client starts"); function limitSize(x, n) { + if (!x) { + return ""; + } if (x.length > n) { return x.substring(0, n) + "…"; } else { @@ -161,6 +165,18 @@ globalThis.modapi_postinit = "(" + (() => { } ModAPI.meta._descriptionMap[document.currentScript.getAttribute("data-hash")] = limitSize(desc, 160); } + ModAPI.meta.config = function (conf) { + if (typeof conf !== "function") { + return console.log("[ModAPIMeta] Config value was not a function"); + } + if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") { + return console.log("[ModAPIMeta] Cannot set meta for non-mod script."); + } + if (!document.currentScript.hasAttribute("data-hash")) { + return console.log("[ModAPIMeta] Script does not have a hashcode."); + } + ModAPI.meta._configMap[document.currentScript.getAttribute("data-hash")] = conf; + } ModAPI.meta.version = function (ver) { if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") { return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");