Skip to content

Recipes

89pleasure edited this page Jul 16, 2026 · 2 revisions

Recipes

These examples combine the focused API methods into common mod workflows.

Load a boolean and list from an INI

local content = pleasureLib:read_text_file(config_path)
local ini = pleasureLib:parse_ini(content)

local enabled = pleasureLib:parse_bool(ini.ENABLED, true)
local item_names = pleasureLib:split_list(ini.ITEMS or "")

Change one INI value without replacing the file

local ok = pleasureLib:update_ini_value(
    config_path,
    "ShowExtraInfo",
    tostring(config.ShowExtraInfo == true)
)

if not ok then
    pleasureLib:log("Could not update config")
end

Safely inspect an Unreal object

local object = pleasureLib:find_object("/Game/Some/Object.Path")

if pleasureLib:is_valid(object) then
    pleasureLib:log(pleasureLib:full_name(object))
else
    pleasureLib:debug_log("object is not loaded")
end

Run Unreal work later on the game thread

local scheduled = pleasureLib:delay_game_thread(100, function()
    local player = pleasureLib:find_object("/Game/Some/Player.Path")
    if pleasureLib:is_valid(player) then
        -- Interact with the object here.
    end
end)

if not scheduled then
    pleasureLib:log("Could not schedule callback")
end

Use a native post-hook

local function noop() end

pleasureLib:register_hook(
    "/Script/SomeClass:SomeNativeFunction",
    noop,
    function(context)
        pleasureLib:debug_log("native function completed")
    end
)

For native /Script/ functions, passing the callback as the third argument is what makes it a true post-handler.

Capture objects created by an action

Start capture immediately before the player action or code path that creates the object:

local capture = pleasureLib:capture_new_objects({
    filter = function(object)
        return string.find(
            pleasureLib:full_name(object),
            "W_Inventory",
            1,
            true
        ) ~= nil
    end,
    sample_delays_ms = { 50, 150, 300, 600 },
}, function(results)
    pleasureLib:log("captured " .. tostring(#results) .. " object(s)")
    for _, entry in ipairs(results) do
        pleasureLib:log(entry.key)
    end
end)

Keep the returned handle if another event should cancel the observation:

if capture then capture.cancel() end

Register a persistent setting

See the complete example and lifecycle notes on Native Game Settings.

Clone this wiki locally