local httpservice = cloneref and cloneref(game:GetService("HttpService")) or game:GetService("HttpService")

getgenv().decompile = function(scr)
    assert(scr, "Decompile error: No script provided.")
    assert(getscriptbytecode, "Exploit Error: Your exploit does not support 'getscriptbytecode'.")
    assert(request, "Exploit Error: Your exploit does not support 'request'.")

    local startTime = tick()

    local scriptPath = scr:GetFullName()
    local executorName = (identifyexecutor and identifyexecutor()) or (getexecutorname and getexecutorname()) or "Unknown Executor"

    local function internal_base64(data)
        local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
        return ((data:gsub('.', function(x) 
            local r, byte = '', x:byte()
            for i = 8, 1, -1 do r = r .. (byte % 2^i - byte % 2^(i-1) > 0 and '1' or '0') end
            return r;
        end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
            if (#x < 6) then return '' end
            local c = 0
            for i = 1, 6 do c = c + (x:sub(i, i) == '1' and 2^(6 - i) or 0) end
            return b:sub(c + 1, c + 1)
        end)..({ '', '==', '=' })[#data % 3 + 1])
    end

    local ok, bytecode = pcall(getscriptbytecode, scr)
    if not ok then 
        return "--[[ Error: Failed to read bytecode ]]\n--[[\n" .. tostring(bytecode) .. "\n--]]" 
    end

    local b64 = (syn and syn.crypt and syn.crypt.base64.encode(bytecode)) or (crypt and crypt.base64encode(bytecode)) or internal_base64(bytecode)

    local res = request({
        Url = "https://api.xan888.cloud/decompile",
        Method = "POST",
        Headers = { ["Content-Type"] = "application/json" },
        Body = httpservice:JSONEncode({
            bytecode = b64
        })
    })

    if not res then
        return "--[[ Error: API request failed (No response) ]]"
    end

    local elapsed = math.floor((tick() - startTime) * 1000) / 1000

    local header = string.format(
        "--[[\n  > Script: %s\n  > Executor: %s\n  > Took %ss to decompile\n--]]\n\n",
        scriptPath,
        executorName,
        tostring(elapsed)
    )

    return header .. res.Body
end