--[[
    INTERNAL PATH HELPER

    UE4SS runs main.lua from the Scripts folder, but the files intended for
    ordinary users live one folder higher. This module finds both locations so
    the other scripts do not repeat path-handling code.
]]

local Paths = {}

local source = debug.getinfo(1, "S").source or ""

if source:sub(1, 1) == "@" then
    source = source:sub(2)
end

-- Windows accepts forward slashes, and using one separator keeps the code
-- predictable on development machines running another operating system.
source = source:gsub("\\", "/")

local scriptsDirectory = source:match("(.*/)[^/]*$") or "./"
local modRoot = scriptsDirectory:match("^(.*)/Scripts/$")
    or scriptsDirectory:match("^(.*)/scripts/$")
    or scriptsDirectory

if modRoot:sub(-1) ~= "/" then
    modRoot = modRoot .. "/"
end

function Paths.Script(fileName)
    return scriptsDirectory .. fileName
end

function Paths.Root(fileName)
    return modRoot .. fileName
end

return Paths
