local HttpService = game:GetService("HttpService")
local _request = request or (http and http.request) or http_request

pcall(restorefunction, decompile)
local native = getgenv().decompile

getgenv().decompile = newcclosure(function(path: Script)
    assert(API_KEY, "No API_KEY provided.")
    local ok, bytecode = pcall(getscriptbytecode, path)
    if not ok then return "-- Genesis failed to get script's bytecode." end
    
    local res = _request({
        Url = "https://soteria.rip/api/genesis",
        Method = "POST",
        Headers = {
            ["x-api-key"] = API_KEY,
        },
        Body = HttpService:JSONEncode({
            bytecode = crypt.base64encode(bytecode),
            args = GEN_OPT or {},
        })
    })

    local ok, data = pcall(function()
        return HttpService:JSONDecode(res.Body)
    end)

    if not res.Success then
        local code = native(path)
        code = "-- Failed to decompile with Genesis, using executor native as fallback.\n-- Error: "..(data.error or "Unknown").."\n\n".. code
        return code
    end


    return crypt.base64decode(data.code)
end)