-
Notifications
You must be signed in to change notification settings - Fork 1
Mod API
This page describes the Mod-API, which is exposed as a global variable to all mods.
This namespace holds all functions related to logging.
Emits a warning message.
Example (init.lua) |
---|
function ready()
mod_api.logger.warn("Some warning!")
end |
Emits an info message.
Emits an error message, also implicitly includes the mod name of the callee.
Emits an debug message, also implicitly includes the mod name of the callee.
Returns all log-entries of the current session that are of type warning or higher.
Example (init.lua) |
---|
function ready()
local logs = mod_api.logger.logs()
for k, v in pairs(logs) do
local message = v:message()
local level = v:level() -- 3 = warning, 4 = error, critical = 5
end
end |
This namespace contains functions related to loaded mods.
Returns all loaded mods, regardless of whether they're enabled or not.
Returns all enabled mods.
Example (init.lua) |
---|
function ready()
local mods = mod_api.mods.enabled()
for k, v in pairs(mods) do
local name = v:name()
local author = v:author()
local version = v:version()
local requires_restart = v:requires_restart()
local description = v:description()
local detailed_description = v:detailed_description()
local dependencies = v:dependencies()
local enabled = v:enabled()
-- Disable mod
v:enable(false)
-- Enable mod
v:enable(true)
end
end |
This namespace contains functions useful for modding.
Used to hook a function call.
Example |
---|
local Module = {}
function Module:give_number(n)
return n + 10
end
local restore = mod_api.hooks.detour(Module, "give_number", function(original, self, n)
return original(self, n - 10)
end)
print(Module:give_number(0)) -- Returns 0
restore()
print(Module:give_number(0)) -- Returns 10 |
Given a module and a callback, intercepts all require
calls to the given module and invokes the callback with the value returned by the original require.
Game Code | Example (init.lua) |
---|---|
local menu_builder = require("classes.modules.interface.menuBuilder")
-- do something with menu_builder |
local remove_hook = mod_api.hooks.intercept_require("classes.modules.interface.menuBuilder", function(module)
mod_api.hooks.detour(module, "some_func", ...)
end)
function unload()
remove_hook()
end |