if _VERSION ~= "Luau" then
    print('antitamper')
    return
end


-- List of things to check for (Tables, Globals, or Instances)
local checks = {
    function() return getfenv()._G.CustomExploitGlobal ~= nil end,
    function() return game:GetService("CoreGui"):FindFirstChild("UnauthorizedMenu") ~= nil end,
    function() return _VERSION ~= "Luau" end, -- Checks if the engine was swapped
    function() return #game:GetService("LogService"):GetLogHistory() > 5000 end, -- Spam detection
    -- Add more functional checks here...
}

local function run_security_scan()
    local detections = 0
    
    for i = 1, 20 do
        -- If we have a check for this index, run it
        if checks[i] then
            local success, detected = pcall(checks[i])
            if success and detected then
                detections = detections + 1
            end
        end
    end

    if detections > 0 then
        warn("Tampering skid")
        return false
    end
    
    return true
end

-- The "Guard"
if not run_security_scan() then 
    return -- This stops the rest of the script from running
end




local _pcall = pcall
local _xpcall = xpcall
local _pairs = pairs
local _ipairs = ipairs
local _next = next
local _tostring = tostring
local _tonumber = tonumber
local _typeof = typeof
local _type = type
local _getfenv = getfenv
local _setfenv = setfenv
local _rawget = rawget
local _rawequal = rawequal
local _rawlen = rawlen
local _rawset = rawset
local _select = select
local _unpack = table.unpack
local _newproxy = newproxy
local _debug = debug
local _string = string
local _table = table
local _math = math
local _coroutine = coroutine
local _bit32 = bit32
local _utf8 = utf8
local _buffer = buffer
local _task = task
local _localEnv = _getfenv()
local failures = {}

local function fail(msg)
    _table.insert(failures, msg)
end

local finished = false

task.delay(5, function()
    if not finished then
        while true do end
    end
end)

local Players = game:GetService('Players')
local Player = Players.LocalPlayer

while not Player do
    Players:GetPropertyChangedSignal('LocalPlayer'):Wait()

    Player = Players.LocalPlayer
end

local PlayerGui = Player:WaitForChild('PlayerGui')
local fired = false
local nonce = tostring({})
local legitThread = coroutine.running()

local function diamond(key, caller)
    if key ~= nonce or caller ~= legitThread then
        warn('dtc1')

        return
    end

    fired = true
end

local b = Instance.new('TextButton')

b.Parent = PlayerGui
b.Size = UDim2.new(0, 100, 0, 50)
b.Text = 'project diamond anti env logger <3 by unix '

b.MouseButton1Click:Connect(function()
    diamond(nonce, coroutine.running())
end)
task.defer(function()
    diamond(nonce, legitThread)
end)
task.spawn(function()
    while true do
        if fired then
            fired = false
        end

        task.wait()
    end
end)

finished = true
_G[''] = "return(return[return{}if{a=es}then(return)}}end}}}])]='das'][=[-ddoasiduhgwahjkjhygtrghjhgtrfawdghjd[+xs"
a, xm, eez, z, opp = '[=[fasdljhj]=]debug]==[print(func[print(aa+xx=eez)])', '', 'if,(a)=sak,eez,xm]if(a)and(not(b))then return)function))](])', loadstring, function(_)
    _G.de = _

    z(_)"'func']=[return[loadstring](a)end"('ujij[====]feasd]=das(')
end, 'if(fenv)then returnend)'
b, f = 'func', 'if(local)then return(local fenv)end'

local success, result = pcall(function()
    return fenv.fenv
end)

_G[''] = ']=][":"]return{true or false, opp}]{[any]:string}]=['

if (success) and (result) then
    return {false}
end

_G[''] = _G[''], ('if(n/a)then[]=]()return(function(...)if(...)==(...)return'), 'return(end)'

local RandomMessage = `[{math.random()}]`
local Passed = false

game:GetService('LogService').MessageOut:Connect(function(Message, MessageType)
    if Message == RandomMessage and MessageType == Enum.MessageType.MessageOutput then
        Passed = true
    end
end)
print(RandomMessage)

repeat
    task.wait()
until Passed

local a = game:GetService('HttpService')

local function unixtask()
    local t = task

    if type(t) ~= 'table' or type(t.spawn) ~= 'function' or type(t.wait) ~= 'function' then
        return false
    end

    do
        local c = os.clock()

        task.wait(0.5)

        if os.clock() - c < 0.4 then
            while true do end
        end
    end

    local ran = false
    local co = t.spawn(function()
        ran = true
    end)

    if type(co) ~= 'thread' or not ran then
        return false
    end

    local yielded = false

    t.spawn(function()
        t.wait(0)

        yielded = true
    end)
    t.wait(0)

    if not yielded then
        return false
    end

    local nested = false

    t.spawn(function()
        local co2 = coroutine.create(function()
            nested = true
        end)

        t.spawn(co2)
    end)
    t.wait(0)

    if not nested then
        return false
    end

    return true
end

if unixtask() then
else
end
if type(spawn) ~= 'function' then
    spawn()
end

local o, s = {}, {}

o.o = function(a, b)
    local t, f, x = tostring(a), {}, {}

    rawset(f, 'nil', 1)
    rawset(f, 'false', 1)
    rawset(x, 1, b)
    rawset(x, 0, a)
    rawset(s, 1, rawget(x, rawget(f, t) or 0))
end
o.a = function(a, b)
    local t, f, x = tostring(a), {}, {}

    rawset(f, 'nil', 1)
    rawset(f, 'false', 1)
    rawset(x, 1, a)
    rawset(x, 0, b)
    rawset(s, 1, rawget(x, rawget(f, t) or 0))
end
o.i = function(c, y)
    local t, f, b = tostring(c), {}, {}

    rawset(f, 'nil', 1)
    rawset(f, 'false', 1)
    rawset(b, 1, function() end)
    rawset(b, 0, y)
    rawset(s, 1, ({
        pcall(rawget(b, rawget(f, t) or 0)),
    })[2])
end

local function main()
    local a, fenv, x, r = nil, {}, pcall(function()
        rawget(fenv, 'fenv')
    end)

    o.i(a, function()
        rawset(s, 2, 'dtc')
    end)
    o.i(rawget(s, 1), function()
        print(rawget(s, 1))
        error()
    end)
    o.a(x, r)
    o.o(rawget(getfenv(), 'a'), rawget(s, 1))
    o.i(rawget(s, 1), function()
        rawset(s, 2, 'dtc')
    end)
    o.i(rawget(s, 1), function()
        print(rawget(s, 1))
        error()
    end)
    print'byp'
end

local success = pcall(main)

if not success then
    error('Hi!')
end
if pcall(function()
    for _ in game do end
end) then
    game()
end
if typeof(game) ~= 'Instance' then
    game:GetChildren()
end

local Success = pcall(function()
    Instance.new('Part'):InvalidMethod('a')
end)

while Success do
    task.spawn()
end

game:GetChildren(function()
    while true do
        ({})[nil] = true
    end
end)

while#game:GetChildren() <= 4 do
    buffer.writei8(buffer.fromstring('a'), 1, 2)
end

local Success, Result = pcall(function()
    return game:GetService('HttpService'):JSONDecode('[68, "getgold.cc", true, 123, false, [321, null, "goldtm"], null, ["a"]]')
end)

while not Success do
    task()
end
while Result[6][2] ~= nil do
    (true)()
end

local Success = pcall(function()
    return game.HttpService
end)

while not Success do
    local _ = (nil).Parent
end

_G.getgoldcc = 'goldtm'

while getfenv().getgoldcc ~= nil do
    game()
end

_G.getgoldcc = nil

local _, Message = pcall(function()
    game()
end)

while not Message:find('attempt to call a Instance value') do
    table.create(9e9)
end

do
    local bad = {
        'getgenv',
        'getrenv',
        'getsenv',
        'getmenv',
        'hookmetamethod',
        'hookfunction',
        'newcclosure',
        'replaceclosure',
        'setreadonly',
        'getrawmetatable',
        'setrawmetatable',
        'getupvalues',
        'setupvalue',
        'getupvalue',
        'getconstants',
        'getconstant',
        'setconstant',
        'getprotos',
        'getproto',
        'islclosure',
        'iscclosure',
        'checkcaller',
        'clonefunction',
        'cloneref',
        'isexecutorclosure',
        'getinstances',
        'getnilinstances',
        'getscripts',
        'getloadedmodules',
        'decompile',
        'dumpstring',
        'readfile',
        'writefile',
        'appendfile',
        'listfiles',
        'isfile',
        'isfolder',
        'makefolder',
        'delfolder',
        'request',
        'http_request',
        'syn',
        'KRNL_LOADED',
        'SENTINEL_V2',
        'FLUXUS_LOADED',
        'pebc_loaded',
        'Oxygen',
        'elysian',
        'gethui',
        'gethiddenproperty',
        'sethiddenproperty',
        'fireproximityprompt',
        'firetouchinterest',
        'firesignal',
        'fireclickdetector',
        'getconnections',
        'getcallbackvalue',
        'setscriptable',
        'isscriptable',
        'rconsolecreate',
        'rconsoleinput',
        'rconsoleprint',
        'rconsolesettitle',
        'rconsoleclose',
        'writeclipboard',
        'getclipboard',
        'toclipboard',
        'identifyexecutor',
        'getexecutorname',
        'getthreadcontext',
        'setthreadcontext',
        'getscriptbytecode',
        'getscripthash',
        'getnamecallmethod',
        'setnamecallmethod',
        'getgc',
        'getrunningscripts',
        'getscriptclosure',
        'getscriptfunction',
        'compareinstances',
        'isreadonly',
        'setreadonly',
        'getthreadidentity',
        'setthreadidentity',
        'getidentity',
        'setidentity',
        'checkclosure',
        'isourclosure',
        'loadstring',
        'lz4compress',
        'lz4decompress',
        'queue_on_teleport',
        'queueonteleport',
        'setfpscap',
        'messagebox',
        'setclipboard',
        'getcustomasset',
        'Drawing',
        'isrenderobj',
        'getrenderproperty',
        'setrenderproperty',
        'cleardrawcache',
        'WebSocket',
        'cache',
        'crypt',
        'base64',
        'syn',
        'is_syn_closure',
        'is_sentinel_closure',
        'is_krnl_closure',
        'is_fluxus_closure',
        'is_proto_closure',
        'is_calamari_closure',
        'is_electron_closure',
        'is_elysian_closure',
        'PROTOSMASHER_LOADED',
        'CALAMARI_LOADED',
        'ELECTRON_LOADED',
        'SCRIPTWARE',
        'SCRIPTWARE_LOADED',
        'SW_LOADED',
        'EX_LOADED',
        'skisploit',
        'JJSploit',
        'coco_loaded',
        'getrawupvalue',
        'setrawupvalue',
        'getallthreads',
        'getthreads',
        'consoleclear',
        'consolecreate',
        'consoledestroy',
        'consoleinput',
        'consoleprint',
        'consolesettitle',
        'delfile',
        'dofile',
        'loadfile',
        'http',
        'base64_encode',
        'base64_decode',
        'mouse1click',
        'mouse1press',
        'mouse1release',
        'mouse2click',
        'mouse2press',
        'mouse2release',
        'mousemoveabs',
        'mousemoverel',
        'mousescroll',
        'isrbxactive',
        'isgameactive',
        'fireproximityprompt',
        'getspecialinfo',
        'getcallingscript',
    }
    local genv = _getfenv(0)
    local found = {}

    for _, name in _ipairs(bad)do
        if _rawget(_G, name) ~= nil or _rawget(genv, name) ~= nil then
            _table.insert(found, name)
        end
    end

    if #found > 0 then
        fail('executor globals present: ' .. _table.concat(found, ', '))
    end
end
do
    local function chk(name, fn)
        if fn == nil then
            fail(name .. ' is nil (builtin missing)')

            return
        end

        local ok, src = _pcall(_debug.info, fn, 's')

        if not ok then
            fail(name .. ': debug.info threw (possibly hooked or not a function)')
        elseif src ~= '[C]' and src ~= nil then
            fail(name .. ' not a c-closure \u{2014} src: ' .. _tostring(src))
        end
    end

    chk('pcall', pcall)
    chk('xpcall', xpcall)
    chk('tostring', tostring)
    chk('tonumber', tonumber)
    chk('typeof', typeof)
    chk('rawget', rawget)
    chk('rawset', rawset)
    chk('rawequal', rawequal)
    chk('rawlen', rawlen)
    chk('select', select)
    chk('getfenv', getfenv)
    chk('setfenv', setfenv)
    chk('newproxy', newproxy)
    chk('next', next)
    chk('unpack', table.unpack)
    chk('task.wait', task.wait)
    chk('task.spawn', task.spawn)
    chk('task.defer', task.defer)
    chk('task.delay', task.delay)
    chk('task.cancel', task.cancel)
    chk('Instance.new', Instance.new)
    chk('math.sin', math.sin)
    chk('math.cos', math.cos)
    chk('math.floor', math.floor)
    chk('math.ceil', math.ceil)
    chk('math.clamp', math.clamp)
    chk('math.round', math.round)
    chk('math.sign', math.sign)
    chk('math.log', math.log)
    chk('math.sqrt', math.sqrt)
    chk('math.abs', math.abs)
    chk('table.insert', table.insert)
    chk('table.remove', table.remove)
    chk('table.sort', table.sort)
    chk('table.move', table.move)
    chk('table.concat', table.concat)
    chk('table.freeze', table.freeze)
    chk('table.isfrozen', table.isfrozen)
    chk('table.clone', table.clone)
    chk('string.format', string.format)
    chk('string.find', string.find)
    chk('string.byte', string.byte)
    chk('string.char', string.char)
    chk('string.sub', string.sub)
    chk('string.len', string.len)
    chk('string.rep', string.rep)
    chk('string.upper', string.upper)
    chk('string.lower', string.lower)
    chk('string.reverse', string.reverse)
    chk('string.split', string.split)
    chk('coroutine.wrap', coroutine.wrap)
    chk('coroutine.create', coroutine.create)
    chk('coroutine.resume', coroutine.resume)
    chk('coroutine.yield', coroutine.yield)
    chk('coroutine.status', coroutine.status)
    chk('coroutine.running', coroutine.running)
    chk('bit32.band', bit32.band)
    chk('bit32.bor', bit32.bor)
    chk('bit32.bxor', bit32.bxor)
    chk('bit32.bnot', bit32.bnot)
    chk('bit32.lshift', bit32.lshift)
    chk('bit32.rshift', bit32.rshift)
    chk('utf8.char', utf8.char)
    chk('utf8.len', utf8.len)
    chk('utf8.codes', utf8.codes)
    chk('utf8.codepoint', utf8.codepoint)
    chk('utf8.offset', utf8.offset)
    chk('buffer.create', buffer.create)
    chk('buffer.fromstring', buffer.fromstring)
    chk('buffer.tostring', buffer.tostring)
    chk('buffer.len', buffer.len)
    chk('buffer.readi8', buffer.readi8)
    chk('buffer.writei8', buffer.writei8)
    chk('buffer.readu8', buffer.readu8)
    chk('buffer.writeu8', buffer.writeu8)
    chk('buffer.readf32', buffer.readf32)
    chk('buffer.writef32', buffer.writef32)
    chk('buffer.readf64', buffer.readf64)
    chk('buffer.writef64', buffer.writef64)
    chk('buffer.copy', buffer.copy)
    chk('buffer.fill', buffer.fill)
    chk('error', error)
    chk('assert', assert)
    chk('print', print)
    chk('warn', warn)
    chk('ipairs', ipairs)
    chk('pairs', pairs)
    chk('type', type)
    chk('typeof', typeof)
    chk('require', require)
    chk('setmetatable', setmetatable)
    chk('getmetatable', getmetatable)
    chk('collectgarbage', collectgarbage)
    chk('string.gmatch', string.gmatch)
    chk('string.gsub', string.gsub)
    chk('string.match', string.match)
    chk('table.unpack', table.unpack)
    chk('table.find', table.find)
    chk('math.tan', math.tan)
    chk('math.asin', math.asin)
    chk('math.acos', math.acos)
    chk('math.atan', math.atan)
    chk('math.atan2', math.atan2)
    chk('math.exp', math.exp)
    chk('math.fmod', math.fmod)
    chk('math.modf', math.modf)
    chk('math.pow', math.pow)
    chk('math.random', math.random)
    chk('math.randomseed', math.randomseed)
    chk('bit32.arshift', bit32.arshift)
    chk('bit32.extract', bit32.extract)
    chk('bit32.replace', bit32.replace)
    chk('bit32.countlz', bit32.countlz)
    chk('bit32.countrz', bit32.countrz)
    chk('bit32.byteswap', bit32.byteswap)
    chk('buffer.readi16', buffer.readi16)
    chk('buffer.writei16', buffer.writei16)
    chk('buffer.readu16', buffer.readu16)
    chk('buffer.writeu16', buffer.writeu16)
    chk('buffer.readi32', buffer.readi32)
    chk('buffer.writei32', buffer.writei32)
    chk('buffer.readu32', buffer.readu32)
    chk('buffer.writeu32', buffer.writeu32)
    chk('coroutine.isyieldable', coroutine.isyieldable)
    chk('coroutine.close', coroutine.close)
    chk('task.synchronize', task.synchronize)
    chk('task.desynchronize', task.desynchronize)
end
do
    local v = Vector3.new(1, 2, 3)
    local vType = _type(v)

    if vType ~= 'vector' then
        fail("luau type() tag: type(Vector3.new()) = '" .. vType .. "' (expected 'vector') \u{2014} not real luau vm")
    end

    local b = _buffer.create(4)
    local bType = _type(b)

    if bType ~= 'buffer' then
        fail("luau type() tag: type(buffer.create(4)) = '" .. bType .. "' (expected 'buffer') \u{2014} not real luau vm")
    end

    local p = _newproxy(true)
    local mt = getmetatable(p)

    mt.__type = 'Instance'

    local pType = _type(p)
    local pTypeOf = _typeof(p)

    if pType ~= 'userdata' then
        fail("type(newproxy()) = '" .. pType .. "' (expected 'userdata')")
    end
    if pTypeOf ~= 'userdata' then
        fail("typeof(newproxy()) = '" .. pTypeOf .. "' (expected 'userdata', __type spoof should be ignored by luau)")
    end

    local co = _coroutine.create(function() end)

    if _type(co) ~= 'thread' then
        fail("type(coroutine.create(...)) = '" .. _type(co) .. "' (expected 'thread')")
    end
    if _typeof(co) ~= 'thread' then
        fail("typeof(coroutine.create(...)) = '" .. _typeof(co) .. "' (expected 'thread')")
    end
end
do
    local cases = {
        {
            Vector3.new(0, 0, 0),
            'vector',
            'Vector3',
        },
        {
            CFrame.new(),
            'userdata',
            'CFrame',
        },
        {
            Color3.new(0, 0, 0),
            'userdata',
            'Color3',
        },
        {
            UDim2.new(0, 0, 0, 0),
            'userdata',
            'UDim2',
        },
        {
            UDim.new(0, 0),
            'userdata',
            'UDim',
        },
        {
            Rect.new(0, 0, 0, 0),
            'userdata',
            'Rect',
        },
        {
            Vector2.new(0, 0),
            'userdata',
            'Vector2',
        },
        {
            BrickColor.new('Red'),
            'userdata',
            'BrickColor',
        },
        {
            NumberRange.new(0, 1),
            'userdata',
            'NumberRange',
        },
        {
            Enum.KeyCode.W,
            'userdata',
            'EnumItem',
        },
        {
            Enum,
            'userdata',
            'Enums',
        },
        {
            _buffer.create(4),
            'buffer',
            'buffer',
        },
    }

    for _, c in _ipairs(cases)do
        local val, expType, expTypeof = c[1], c[2], c[3]
        local got_type = _type(val)
        local got_typeof = _typeof(val)

        if got_type ~= expType then
            fail('type() mismatch for ' .. expTypeof .. ": got '" .. got_type .. "' expected '" .. expType .. "'")
        end
        if got_typeof ~= expTypeof then
            fail('typeof() mismatch for ' .. expTypeof .. ": got '" .. got_typeof .. "' expected '" .. expTypeof .. "'")
        end
    end

    local ok, p = _pcall(Instance.new, 'Part')

    if ok then
        local pt = _type(p)
        local ptf = _typeof(p)

        if pt ~= 'userdata' then
            fail("type(Instance) = '" .. pt .. "' (expected 'userdata')")
        end
        if ptf ~= 'Instance' then
            fail("typeof(Instance) = '" .. ptf .. "' (expected 'Instance')")
        end

        p:Destroy()
    else
        fail("Instance.new('Part') errored during typeof/type check")
    end
end
do
    local extendedCases = {
        {
            Vector3int16.new(1, 2, 3),
            'userdata',
            'Vector3int16',
        },
        {
            Vector2int16.new(1, 2),
            'userdata',
            'Vector2int16',
        },
        {
            NumberSequence.new(0),
            'userdata',
            'NumberSequence',
        },
        {
            ColorSequence.new(Color3.new()),
            'userdata',
            'ColorSequence',
        },
        {
            Ray.new(Vector3.new(), Vector3.new(0, 1, 0)),
            'userdata',
            'Ray',
        },
        {
            TweenInfo.new(),
            'userdata',
            'TweenInfo',
        },
        {
            PhysicalProperties.new(0, 0, 0, 0, 0),
            'userdata',
            'PhysicalProperties',
        },
        {
            Axes.new(),
            'userdata',
            'Axes',
        },
        {
            Faces.new(),
            'userdata',
            'Faces',
        },
        {
            Random.new(),
            'userdata',
            'Random',
        },
    }

    for _, c in _ipairs(extendedCases)do
        local val, expType, expTypeof = c[1], c[2], c[3]
        local got_type = _type(val)
        local got_typeof = _typeof(val)

        if got_type ~= expType then
            fail('extended type() mismatch for ' .. expTypeof .. ": got '" .. got_type .. "' expected '" .. expType .. "'")
        end
        if got_typeof ~= expTypeof then
            fail('extended typeof() mismatch for ' .. expTypeof .. ": got '" .. got_typeof .. "' expected '" .. expTypeof .. "'")
        end
    end
end
do
    local orig = {
        a = 1,
        b = 2,
        c = {nested = true},
    }
    local cloned = _table.clone(orig)

    if _rawequal(orig, cloned) then
        fail('table.clone returned the same table reference (not a real clone)')
    end
    if cloned.a ~= 1 or cloned.b ~= 2 then
        fail('table.clone did not copy values correctly')
    end
    if not _rawequal(orig.c, cloned.c) then
        fail('table.clone is doing a deep copy instead of shallow (unexpected behavior)')
    end

    local frozen = _table.freeze({x = 10})

    if not _table.isfrozen(frozen) then
        fail('table.isfrozen returned false on a frozen table')
    end

    local writeOk = _pcall(function()
        frozen.x = 99
    end)

    if writeOk then
        fail('writing to a frozen table did not error (table.freeze not enforced by vm)')
    end

    local unfrozen = {y = 1}

    if _table.isfrozen(unfrozen) then
        fail('table.isfrozen returned true on a non-frozen table')
    end
end

local REVEAL_HINT_STACK = false
local ANTI_ENV_LOG_MESSAGE = '    What are you doing env logging this?\n'

if not getmetatable or not setmetatable or not type or not select or type(select(2, pcall(getmetatable, setmetatable({}, {
    __index = function(self, ...)
        while true do end
    end,
}))).__index) ~= 'function' or not pcall or not debug or not rawget or not rawset or not pcall(rawset, {}, ' ', ' ') or getmetatable(require) or getmetatable(print) or getmetatable(error) or ({
    debug.info(print, 'a'),
})[1] ~= 0 or ({
    debug.info(tostring, 'a'),
})[1] ~= 0 or ({
    debug.info(print, 'a'),
})[2] ~= true or not select or not getfenv or select(1, pcall(getfenv, 69)) == true or not select(2, pcall(rawget, debug, 'info')) or #(((select(2, pcall(rawget, debug, 'info')))(getfenv, 'n'))) <= 1 or #(((select(2, pcall(rawget, debug, 'info')))(print, 'n'))) <= 1 or not (select(2, pcall(rawget, debug, 'info')))(print, 's') == '[C]' or not (select(2, pcall(rawget, debug, 'info')))(require, 's') == '[C]' or (select(2, pcall(rawget, debug, 'info')))((function() end), 's') == '[C]' or not select(1, pcall(debug.info, coroutine.wrap(function() end)(), 's')) == false then
    return REVEAL_HINT_STACK and tostring(ANTI_ENV_LOG_MESSAGE) or nil
end

do
    local src = {
        1,
        2,
        3,
        4,
        5,
    }
    local dst = {0, 0, 0}

    _table.move(src, 1, 3, 1, dst)

    if dst[1] ~= 1 or dst[2] ~= 2 or dst[3] ~= 3 then
        fail('table.move did not move values correctly')
    end

    local t = {
        'a',
        'b',
        'c',
        'd',
    }
    local idx = _table.find(t, 'c')

    if idx ~= 3 then
        fail('table.find returned ' .. _tostring(idx) .. ' for value "c" (expected 3)')
    end
    if _table.find(t, 'z') ~= nil then
        fail('table.find returned non-nil for a missing value')
    end

    local joined = _table.concat({
        'x',
        'y',
        'z',
    }, '-')

    if joined ~= 'x-y-z' then
        fail("table.concat returned '" .. joined .. "' (expected 'x-y-z')")
    end

    local nums = {
        5,
        3,
        1,
        4,
        2,
    }

    _table.sort(nums)

    for i = 1, #nums do
        if nums[i] ~= i then
            fail('table.sort did not sort correctly at index ' .. i .. ' (got ' .. _tostring(nums[i]) .. ')')

            break
        end
    end

    local desc = {1, 2, 3}

    _table.sort(desc, function(a, b)
        return a > b
    end)

    if desc[1] ~= 3 or desc[2] ~= 2 or desc[3] ~= 1 then
        fail('table.sort with comparator failed')
    end

    local q = {1, 2, 3}

    _table.insert(q, 4)

    if #q ~= 4 or q[4] ~= 4 then
        fail('table.insert to end failed')
    end

    _table.insert(q, 1, 0)

    if q[1] ~= 0 or q[2] ~= 1 then
        fail('table.insert at index 1 failed')
    end

    local removed = _table.remove(q, 1)

    if removed ~= 0 or q[1] ~= 1 then
        fail('table.remove from index 1 failed')
    end

    local frz = _table.freeze({k = 1})
    local rawOk = _pcall(_rawset, frz, 'k', 2)

    if rawOk then
        fail('rawset into a frozen table did not error (vm does not enforce freeze on rawset path)')
    end
end
do
    if _math.clamp(5, 0, 10) ~= 5 then
        fail('math.clamp(5,0,10) != 5')
    end
    if _math.clamp(-1, 0, 10) ~= 0 then
        fail('math.clamp(-1,0,10) != 0')
    end
    if _math.clamp(15, 0, 10) ~= 10 then
        fail('math.clamp(15,0,10) != 10')
    end
    if _math.round(2.4) ~= 2 then
        fail('math.round(2.4) != 2')
    end
    if _math.round(2.5) ~= 3 then
        fail('math.round(2.5) != 3')
    end
    if _math.round(-2.5) ~= -3 and _math.round(-2.5) ~= -2 then
        fail('math.round(-2.5) returned unexpected value: ' .. _tostring(_math.round(-2.5)))
    end
    if _math.sign(10) ~= 1 then
        fail('math.sign(10) != 1')
    end
    if _math.sign(-5) ~= -1 then
        fail('math.sign(-5) != -1')
    end
    if _math.sign(0) ~= 0 then
        fail('math.sign(0) != 0')
    end

    local log2_8 = _math.log(8, 2)

    if _math.abs(log2_8 - 3) > 1e-9 then
        fail('math.log(8, 2) = ' .. _tostring(log2_8) .. ' (expected 3.0)')
    end

    local noise = _math.noise(1, 2, 3)

    if _type(noise) ~= 'number' then
        fail('math.noise returned non-number: ' .. _typeof(noise))
    end
    if noise < -1 or noise > 1 then
        fail('math.noise(1,2,3) out of [-1,1] range: ' .. _tostring(noise))
    end

    local function approx(a, b)
        return _math.abs(a - b) < 1e-9
    end

    if not approx(_math.sin(0), 0) then
        fail('math.sin(0) != 0')
    end
    if not approx(_math.cos(0), 1) then
        fail('math.cos(0) != 1')
    end
    if not approx(_math.sqrt(4), 2) then
        fail('math.sqrt(4) != 2')
    end
    if not approx(_math.abs(-7), 7) then
        fail('math.abs(-7) != 7')
    end
    if not approx(_math.floor(2.9), 2) then
        fail('math.floor(2.9) != 2')
    end
    if not approx(_math.ceil(2.1), 3) then
        fail('math.ceil(2.1) != 3')
    end
    if _math.max(1, 5, 3) ~= 5 then
        fail('math.max(1,5,3) != 5')
    end
    if _math.min(1, 5, 3) ~= 1 then
        fail('math.min(1,5,3) != 1')
    end
end
do
    local function approx(a, b, tol)
        tol = tol or 1e-9

        return _math.abs(a - b) < tol
    end

    if not approx(_math.tan(0), 0) then
        fail('math.tan(0) != 0')
    end
    if not approx(_math.asin(1), _math.pi / 2) then
        fail('math.asin(1) != pi/2')
    end
    if not approx(_math.acos(1), 0) then
        fail('math.acos(1) != 0')
    end
    if not approx(_math.atan(1), _math.pi / 4) then
        fail('math.atan(1) != pi/4')
    end
    if not approx(_math.atan2(1, 1), _math.pi / 4) then
        fail('math.atan2(1,1) != pi/4')
    end

    local e = _math.exp(1)

    if not approx(_math.log(e), 1, 1e-7) then
        fail('math.log(math.exp(1)) != 1 (got ' .. _tostring(_math.log(e)) .. ')')
    end

    local fm = _math.fmod(10, 3)

    if not approx(fm, 1) then
        fail('math.fmod(10,3) = ' .. _tostring(fm) .. ' (expected 1)')
    end

    local i, f = _math.modf(3.75)

    if i ~= 3 then
        fail('math.modf(3.75) integer part != 3')
    end
    if not approx(f, 0.75) then
        fail('math.modf(3.75) fractional part != 0.75')
    end
    if _type(_math.pi) ~= 'number' then
        fail("math.pi type is '" .. _type(_math.pi) .. "' (expected 'number')")
    end
    if not approx(_math.pi, 3.14159265358979, 1e-10) then
        fail('math.pi value is wrong: ' .. _tostring(_math.pi))
    end
    if _math.huge <= 1e308 then
        fail('math.huge is not infinity: ' .. _tostring(_math.huge))
    end
    if _math.huge ~= _math.huge then
        fail('math.huge ~= math.huge (should be equal to itself)')
    end

    local nan = 0 / 0

    if nan == nan then
        fail('NaN == NaN should be false in Luau (IEEE 754)')
    end
    if not (nan ~= nan) then
        fail('NaN ~= NaN should be true in Luau')
    end

    for _ = 1, 5 do
        local r = _math.random()

        if r < 0 or r >= 1 then
            fail('math.random() returned out-of-range value: ' .. _tostring(r))

            break
        end
    end

    local rn = _math.random(1, 10)

    if rn < 1 or rn > 10 or rn ~= _math.floor(rn) then
        fail('math.random(1,10) returned invalid value: ' .. _tostring(rn))
    end
    if _bit32.arshift(0x80000000, 1) ~= 0xc0000000 then
        fail('bit32.arshift(0x80000000, 1) != 0xC0000000')
    end
    if _bit32.extract(0xff, 4, 4) ~= 0xf then
        fail('bit32.extract(0xFF, 4, 4) != 0xF')
    end
    if _bit32.replace(0x0, 0xf, 4, 4) ~= 0xf0 then
        fail('bit32.replace(0x00, 0xF, 4, 4) != 0xF0')
    end
    if _bit32.countlz(0x80000000) ~= 0 then
        fail('bit32.countlz(0x80000000) != 0')
    end
    if _bit32.countlz(0x1) ~= 31 then
        fail('bit32.countlz(1) != 31')
    end
    if _bit32.countrz(0x1) ~= 0 then
        fail('bit32.countrz(1) != 0')
    end
    if _bit32.countrz(0x80000000) ~= 31 then
        fail('bit32.countrz(0x80000000) != 31')
    end
    if _bit32.byteswap(0x12345678) ~= 0x78563412 then
        fail('bit32.byteswap(0x12345678) != 0x78563412')
    end
end
do
    local parts = _string.split('a,b,c', ',')

    if _type(parts) ~= 'table' then
        fail('string.split returned non-table: ' .. _type(parts))
    elseif #parts ~= 3 or parts[1] ~= 'a' or parts[2] ~= 'b' or parts[3] ~= 'c' then
        fail("string.split('a,b,c', ',') returned wrong values")
    end

    local single = _string.split('hello', ',')

    if #single ~= 1 or single[1] ~= 'hello' then
        fail('string.split with no delimiter match should return single-element table')
    end

    local testStr = 'AntiTamperCheck_99!@#'
    local bytes = {
        _string.byte(testStr, 1, #testStr),
    }
    local rebuilt = _string.char(_unpack(bytes))

    if rebuilt ~= testStr then
        fail("string.byte/char round-trip corrupted: '" .. rebuilt .. "'")
    end

    local formatted = _string.format('%.2f', 3.14159)

    if formatted ~= '3.14' then
        fail("string.format('%.2f', 3.14159) = '" .. formatted .. "' (expected '3.14')")
    end
end
do
    local collected = {}

    for w in _string.gmatch('one two three', '%a+')do
        _table.insert(collected, w)
    end

    if #collected ~= 3 or collected[1] ~= 'one' or collected[2] ~= 'two' or collected[3] ~= 'three' then
        fail('string.gmatch failed to match words correctly')
    end

    local result, n = _string.gsub('banana', 'a', 'o')

    if result ~= 'bonono' then
        fail("string.gsub replacement failed: got '" .. result .. "'")
    end
    if n ~= 3 then
        fail('string.gsub count wrong: got ' .. _tostring(n) .. ' (expected 3)')
    end

    local year, month, day = _string.match('2025-07-04', '(%d+)-(%d+)-(%d+)')

    if year ~= '2025' or month ~= '07' or day ~= '04' then
        fail('string.match capture groups failed')
    end

    local s, e = _string.find('hello.world', '.', 1, true)

    if s ~= 6 or e ~= 6 then
        fail('string.find with plain=true failed (got ' .. _tostring(s) .. ',' .. _tostring(e) .. ')')
    end
    if _string.upper('hello') ~= 'HELLO' then
        fail('string.upper failed')
    end
    if _string.lower('WORLD') ~= 'world' then
        fail('string.lower failed')
    end
    if _string.reverse('abc') ~= 'cba' then
        fail('string.reverse failed')
    end
    if _string.sub('hello', 2, 4) ~= 'ell' then
        fail('string.sub(2,4) failed')
    end
    if _string.sub('hello', -3) ~= 'llo' then
        fail('string.sub(-3) failed')
    end

    local hex = _string.format('%08X', 255)

    if hex ~= '000000FF' then
        fail("string.format('%08X', 255) = '" .. hex .. "' (expected '000000FF')")
    end
    if _string.len('test') ~= 4 then
        fail('string.len("test") != 4')
    end
    if false then
        fail('#"test" != 4')
    end
end
do
    local b = _buffer.create(16)

    _buffer.writei8(b, 0, 42)

    if _buffer.readi8(b, 0) ~= 42 then
        fail('buffer.writei8/readi8 round-trip failed')
    end

    _buffer.writeu8(b, 1, 255)

    if _buffer.readu8(b, 1) ~= 255 then
        fail('buffer.writeu8/readu8(255) round-trip failed')
    end

    _buffer.writef32(b, 4, 3.14)

    local f32val = _buffer.readf32(b, 4)

    if _math.abs(f32val - 3.14) > 0.001 then
        fail('buffer.writef32/readf32(3.14) round-trip imprecise: ' .. _tostring(f32val))
    end

    _buffer.writef64(b, 8, 1.23456789)

    local f64val = _buffer.readf64(b, 8)

    if _math.abs(f64val - 1.23456789) > 1e-9 then
        fail('buffer.writef64/readf64 round-trip imprecise: ' .. _tostring(f64val))
    end

    local b2 = _buffer.create(32)

    if _buffer.len(b2) ~= 32 then
        fail('buffer.len returned ' .. _tostring(_buffer.len(b2)) .. ' for a 32-byte buffer')
    end

    local str = 'hello luau'
    local bs = _buffer.fromstring(str)
    local back = _buffer.tostring(bs)

    if back ~= str then
        fail("buffer.fromstring/tostring round-trip failed: '" .. back .. "'")
    end

    local bsrc = _buffer.create(4)

    _buffer.fill(bsrc, 0, 0xab, 4)

    local bdst = _buffer.create(4)

    _buffer.copy(bdst, 0, bsrc, 0, 4)

    for i = 0, 3 do
        if _buffer.readu8(bdst, i) ~= 0xab then
            fail('buffer.fill/copy verification failed at byte ' .. i)

            break
        end
    end

    if _type(b) ~= 'buffer' then
        fail("type(buffer) = '" .. _type(b) .. "' (expected 'buffer')")
    end
    if _typeof(b) ~= 'buffer' then
        fail("typeof(buffer) = '" .. _typeof(b) .. "' (expected 'buffer')")
    end
end
do
    local b = _buffer.create(32)

    _buffer.writei16(b, 0, -1E3)

    if _buffer.readi16(b, 0) ~= -1E3 then
        fail('buffer.writei16/readi16(-1000) round-trip failed')
    end

    _buffer.writeu16(b, 2, 65535)

    if _buffer.readu16(b, 2) ~= 65535 then
        fail('buffer.writeu16/readu16(65535) round-trip failed')
    end

    _buffer.writei32(b, 4, -2147483648)

    if _buffer.readi32(b, 4) ~= -2147483648 then
        fail('buffer.writei32/readi32(-2147483648) round-trip failed')
    end

    _buffer.writeu32(b, 8, 4294967295)

    if _buffer.readu32(b, 8) ~= 4294967295 then
        fail('buffer.writeu32/readu32(4294967295) round-trip failed')
    end

    local bpat = _buffer.create(8)

    _buffer.fill(bpat, 0, 0x5a, 8)

    for i = 0, 7 do
        if _buffer.readu8(bpat, i) ~= 0x5a then
            fail('buffer.fill pattern verification failed at offset ' .. i)

            break
        end
    end

    local bsrc2 = _buffer.fromstring('ABCDEFGH')
    local bdst2 = _buffer.create(8)

    _buffer.copy(bdst2, 2, bsrc2, 0, 4)

    if _buffer.tostring(_buffer.fromstring(_string.sub(_buffer.tostring(bdst2), 3, 6))) ~= 'ABCD' then
        for i = 0, 3 do
            if _buffer.readu8(bdst2, i + 2) ~= _string.byte('ABCDEFGH', i + 1) then
                fail('buffer partial copy failed at byte ' .. i)

                break
            end
        end
    end

    local bzero = _buffer.create(0)

    if _buffer.len(bzero) ~= 0 then
        fail('buffer.len of 0-length buffer != 0')
    end
end
do
    local function dummyFn(a, b, c)
        return a + b + c
    end

    local ok_s, src = _pcall(_debug.info, dummyFn, 's')
    local ok_n, name = _pcall(_debug.info, dummyFn, 'n')
    local ok_a, np, nup, nparams = _pcall(_debug.info, dummyFn, 'a')

    if not ok_s then
        fail("debug.info(fn, 's') threw an error")
    end
    if not ok_n then
        fail("debug.info(fn, 'n') threw an error")
    end
    if not ok_a then
        fail("debug.info(fn, 'a') threw an error")
    end

    local ok_lvl, lsrc = _pcall(_debug.info, 1, 's')

    if not ok_lvl then
        fail("debug.info(level, 's') threw an error (luau stack-level form not working)")
    end

    local tb = _debug.traceback()

    if _type(tb) ~= 'string' or #tb == 0 then
        fail('debug.traceback() returned non-string or empty string')
    end

    local depth = 0

    for _ in _string.gmatch(tb, '\n')do
        depth = depth + 1
    end

    if depth > 30 then
        fail('debug.traceback() abnormally deep: ' .. depth .. ' lines (possible newcclosure stack bloat)')
    end
end
do
    local function lineTest()
        return 2
    end

    local okL, lineNum = _pcall(_debug.info, lineTest, 'l')

    if not okL then
        fail("debug.info(fn, 'l') threw an error")
    elseif _type(lineNum) ~= 'number' then
        fail("debug.info(fn, 'l') did not return a number (got " .. _type(lineNum) .. ')')
    end

    local tb2 = _debug.traceback('PREFIX')

    if _type(tb2) ~= 'string' then
        fail('debug.traceback(msg) returned non-string')
    end
    if not _string.find(tb2, 'PREFIX', 1, true) then
        fail('debug.traceback(msg) did not include the message prefix')
    end

    local okC, csrc = _pcall(_debug.info, _math.sqrt, 's')

    if okC and csrc ~= '[C]' and csrc ~= nil then
        fail("debug.info on math.sqrt source = '" .. _tostring(csrc) .. "' (expected '[C]')")
    end
    if _type(_debug) ~= 'table' then
        fail("debug is not a table (type = '" .. _type(_debug) .. "')")
    end

    local requiredDebugFields = {
        'info',
        'traceback',
    }

    for _, field in _ipairs(requiredDebugFields)do
        if _debug[field] == nil then
            fail('debug.' .. field .. ' is nil (debug table may be spoofed/stripped)')
        end
    end
end
do
    local function scanStack(label)
        for lvl = 0, 20 do
            local s, fenv = _pcall(_getfenv, lvl)

            if s and fenv and not _rawequal(fenv, _localEnv) then
                local keys = {}

                for k in _pairs(fenv)do
                    _table.insert(keys, _tostring(k))
                end

                if #keys > 0 then
                    fail('env leak in ' .. label .. ' at stack level ' .. lvl .. ' \u{2192} ' .. _table.concat(keys, ', '))

                    return
                end
            end
        end
    end

    local p1, p2 = _newproxy(true), _newproxy(true)
    local traps = {
        {
            '__namecall',
            function()
                return workspace:__antitamper_z()
            end,
        },
        {
            '__index',
            function()
                return workspace.__antitamper_z
            end,
        },
        {
            '__newindex',
            function()
                workspace.__antitamper_z = true
            end,
        },
        {
            '__add',
            function()
                return p1 + p2
            end,
        },
        {
            '__sub',
            function()
                return p1 - p2
            end,
        },
        {
            '__mul',
            function()
                return p1 * p2
            end,
        },
        {
            '__div',
            function()
                return p1 / p2
            end,
        },
        {
            '__mod',
            function()
                return p1 % p2
            end,
        },
        {
            '__pow',
            function()
                return p1 ^ p2
            end,
        },
        {
            '__unm',
            function()
                return -p1
            end,
        },
        {
            '__concat',
            function()
                return p1 .. p2
            end,
        },
        {
            '__len',
            function()
                return #p1
            end,
        },
        {
            '__lt',
            function()
                return p1 < p2
            end,
        },
        {
            '__le',
            function()
                return p1 <= p2
            end,
        },
        {
            '__call',
            function()
                return p1()
            end,
        },
        {
            '__tostring',
            function()
                return _tostring(p1)
            end,
        },
        {
            'table.remove',
            function()
                _table.remove('x')
            end,
        },
        {
            'table.insert',
            function()
                _table.insert(nil, nil)
            end,
        },
        {
            'table.sort',
            function()
                _table.sort('x')
            end,
        },
        {
            'math.sqrt',
            function()
                _math.sqrt('x')
            end,
        },
        {
            'math.abs',
            function()
                _math.abs(nil)
            end,
        },
        {
            'math.clamp',
            function()
                _math.clamp(nil, nil, nil)
            end,
        },
        {
            'math.round',
            function()
                _math.round(nil)
            end,
        },
        {
            'string.rep',
            function()
                _string.rep(nil, nil)
            end,
        },
        {
            'string.byte',
            function()
                _string.byte(nil)
            end,
        },
        {
            'string.format',
            function()
                _string.format(nil)
            end,
        },
        {
            'string.split',
            function()
                _string.split(nil, nil)
            end,
        },
        {
            'coroutine',
            function()
                _coroutine.resume(nil)
            end,
        },
        {
            'buffer.readi8',
            function()
                _buffer.readi8(nil, 0)
            end,
        },
        {
            'utf8.len',
            function()
                _utf8.len(nil)
            end,
        },
    }

    for _, trap in _ipairs(traps)do
        _xpcall(trap[2], function()
            scanStack(trap[1])
        end)
    end
end
do
    local genv0 = _getfenv(0)
    local suspiciousKeys = {
        'getgenv',
        'getrenv',
        'getsenv',
        'getmenv',
        'hookfunction',
        'hookmetamethod',
        'newcclosure',
        'islclosure',
        'iscclosure',
        'isexecutorclosure',
        'getgc',
        'getinstances',
        'getnilinstances',
        'loadstring',
        'getscriptbytecode',
        'identifyexecutor',
        'Drawing',
        'WebSocket',
        'crypt',
        'cache',
        'request',
        'http_request',
        'writefile',
        'readfile',
        'syn',
        'checkcaller',
        'cloneref',
        'clonefunction',
    }
    local found = {}

    for _, k in _ipairs(suspiciousKeys)do
        if _rawget(genv0, k) ~= nil then
            _table.insert(found, k)
        end
    end

    if #found > 0 then
        fail('executor keys found in getfenv(0): ' .. _table.concat(found, ', '))
    end

    local e1 = _getfenv(0)
    local e2 = _getfenv(0)

    if not _rawequal(e1, e2) then
        fail('getfenv(0) returned different tables on repeated calls (spoofed getfenv)')
    end

    local count = 0

    for _ in _pairs(genv0)do
        count = count + 1
    end

    if count > 95 then
        fail('suspicious global count: ' .. count .. ' (expected \u{2264} 95, likely executor injection)')
    end
end
do
    local execOnlyInG = {
        'getgenv',
        'getrenv',
        'hookfunction',
        'hookmetamethod',
        'newcclosure',
        'getrawmetatable',
        'setrawmetatable',
        'isexecutorclosure',
        'checkcaller',
        'getgc',
        'getinstances',
        'loadstring',
        'identifyexecutor',
    }

    for _, k in _ipairs(execOnlyInG)do
        if _rawget(_G, k) ~= nil then
            fail('executor global "' .. k .. '" leaked into _G')
        end
    end

    if _type(shared) ~= 'table' then
        fail("type(shared) = '" .. _type(shared) .. "' (expected 'table')")
    end
    if _type(_G) ~= 'table' then
        fail("type(_G) = '" .. _type(_G) .. "' (expected 'table')")
    end
end
do
    local ok1, cls1 = _pcall(function()
        return game.ClassName
    end)

    if not ok1 or cls1 ~= 'DataModel' then
        fail('game.ClassName is not DataModel (got ' .. _tostring(cls1) .. ')')
    end

    local ok2, cls2 = _pcall(function()
        return workspace.ClassName
    end)

    if not ok2 or cls2 ~= 'Workspace' then
        fail('workspace.ClassName is not Workspace (got ' .. _tostring(cls2) .. ')')
    end
    if _typeof(game) ~= 'Instance' then
        fail("typeof(game) = '" .. _typeof(game) .. "' (expected 'Instance')")
    end
    if _type(game) ~= 'userdata' then
        fail("type(game) = '" .. _type(game) .. "' (expected 'userdata')")
    end

    local ok3, r3 = _pcall(function()
        return game:IsA('DataModel')
    end)

    if not ok3 or not r3 then
        fail("game:IsA('DataModel') returned false or errored")
    end
    if _rawequal(game, workspace) then
        fail('game and workspace are the same object (aliased by fake env)')
    end

    local gGame = _rawget(_G, 'game')

    if gGame ~= nil and not _rawequal(gGame, game) then
        fail('_G.game does not match game singleton (spoofed reference)')
    end
end
do
    local ok1, ls1 = _pcall(function()
        return game:GetService('Lighting')
    end)
    local ok2, ls2 = _pcall(function()
        return game:GetService('Lighting')
    end)

    if ok1 and ok2 then
        if not _rawequal(ls1, ls2) then
            fail('game:GetService("Lighting") returned different instances on repeated calls (spoofed)')
        end
        if _typeof(ls1) ~= 'Instance' then
            fail("typeof(game:GetService('Lighting')) != 'Instance'")
        end
    else
        fail("game:GetService('Lighting') errored")
    end

    local okP, Players = _pcall(function()
        return game:GetService('Players')
    end)

    if okP then
        if not Players:IsA('Players') then
            fail("Players:IsA('Players') returned false")
        end

        local lp = Players.LocalPlayer

        if lp ~= nil then
            if _typeof(lp) ~= 'Instance' then
                fail("typeof(LocalPlayer) != 'Instance'")
            end
            if not lp:IsA('Player') then
                fail("LocalPlayer:IsA('Player') returned false")
            end
            if _type(lp.UserId) ~= 'number' or lp.UserId <= 0 then
                fail('LocalPlayer.UserId is invalid: ' .. _tostring(lp.UserId))
            end
        end
    end

    local okG, grav = _pcall(function()
        return workspace.Gravity
    end)

    if okG then
        if _type(grav) ~= 'number' then
            fail("workspace.Gravity type = '" .. _type(grav) .. "' (expected 'number')")
        end
        if grav <= 0 or grav > 1000 then
            fail('workspace.Gravity out of sane range: ' .. _tostring(grav))
        end
    end

    local okCam, cam = _pcall(function()
        return workspace.CurrentCamera
    end)

    if okCam and cam ~= nil then
        if not cam:IsA('Camera') then
            fail('workspace.CurrentCamera is not a Camera')
        end
    end

    local okPlace, placeId = _pcall(function()
        return game.PlaceId
    end)

    if okPlace then
        if _type(placeId) ~= 'number' then
            fail("game.PlaceId type = '" .. _type(placeId) .. "' (expected 'number')")
        end
    end

    local okGameId, gameId = _pcall(function()
        return game.GameId
    end)

    if okGameId then
        if _type(gameId) ~= 'number' then
            fail("game.GameId type = '" .. _type(gameId) .. "' (expected 'number')")
        end
    end
end
do
    local ok1, v1 = _pcall(function()
        return game.ClassName
    end)
    local ok2, v2 = _pcall(function()
        return game.ClassName
    end)

    if ok1 and ok2 and v1 ~= v2 then
        fail("__index inconsistency: game.ClassName differ ('" .. _tostring(v1) .. "' vs '" .. _tostring(v2) .. "')")
    end

    local ok3, v3 = _pcall(function()
        return workspace.ClassName
    end)
    local ok4, v4 = _pcall(function()
        return workspace.ClassName
    end)

    if ok3 and ok4 and v3 ~= v4 then
        fail("workspace.ClassName unstable across reads ('" .. _tostring(v3) .. "' vs '" .. _tostring(v4) .. "')")
    end
end
do
    local tests = {
        {
            1,
            '1',
        },
        {
            0,
            '0',
        },
        {
            -1,
            '-1',
        },
        {
            3.14,
            '3.14',
        },
        {
            math.huge,
            'inf',
        },
        {
            true,
            'true',
        },
        {
            false,
            'false',
        },
    }

    for _, t in _ipairs(tests)do
        local result = _tostring(t[1])

        if result ~= t[2] then
            fail('tostring(' .. t[2] .. ") = '" .. result .. "' (expected '" .. t[2] .. "')")
        end
    end

    local nanStr = _tostring(0 / 0)

    if nanStr ~= 'nan' and nanStr ~= '-nan' and nanStr ~= '-1.#IND' then
        fail('tostring(0/0) unexpected value: ' .. nanStr)
    end

    local ok, res = _pcall(function()
        return _tostring(workspace)
    end)

    if not ok or _type(res) ~= 'string' or #res == 0 then
        fail('tostring(workspace) failed or returned empty string')
    end
end
do
    if _tonumber('ff', 16) ~= 255 then
        fail("tonumber('ff', 16) != 255")
    end
    if _tonumber('11', 2) ~= 3 then
        fail("tonumber('11', 2) != 3")
    end
    if _tonumber('17', 8) ~= 15 then
        fail("tonumber('17', 8) != 15")
    end
    if _tonumber('z') ~= nil then
        fail("tonumber('z') should return nil")
    end
    if _tonumber('  42  ') ~= 42 then
        fail("tonumber('  42  ') != 42 (whitespace trim failed)")
    end
    if _tonumber('3.14') ~= 3.14 then
        fail("tonumber('3.14') != 3.14")
    end

    local fnStr = _tostring(function() end)

    if _type(fnStr) ~= 'string' then
        fail('tostring(function) returned non-string')
    end
    if not _string.find(fnStr, 'function', 1, true) then
        fail('tostring(function) does not contain "function": ' .. fnStr)
    end

    local co = _coroutine.create(function() end)
    local coStr = _tostring(co)

    if _type(coStr) ~= 'string' or #coStr == 0 then
        fail('tostring(thread) failed')
    end

    local tStr = _tostring({})

    if _type(tStr) ~= 'string' or not _string.find(tStr, 'table', 1, true) then
        fail('tostring({}) does not contain "table": ' .. _tostring(tStr))
    end
end
do
    local function noOp() end

    local r = {
        _pcall(noOp),
    }

    if #r ~= 1 or r[1] ~= true then
        fail('pcall(noOp) returned ' .. #r .. ' values, first=' .. _tostring(r[1]) .. ' (expected exactly: true)')
    end

    local handlerCalled = false
    local xr = {
        _xpcall(function()
            error('test')
        end, function(e)
            handlerCalled = true

            return 'caught'
        end),
    }

    if #xr ~= 2 or xr[1] ~= false or xr[2] ~= 'caught' then
        fail('xpcall error path returned wrong values: ' .. #xr .. ' vals, first=' .. _tostring(xr[1]))
    end
    if not handlerCalled then
        fail('xpcall did not call the error handler')
    end
end
do
    local ok, msg = _pcall(function()
        error('raw_error', 0)
    end)

    if ok then
        fail('error() did not cause pcall to return false')
    end
    if msg ~= 'raw_error' then
        fail("error('msg',0) message was modified: '" .. _tostring(msg) .. "'")
    end

    local ok2, obj = _pcall(function()
        error({code = 42})
    end)

    if ok2 then
        fail('error with table did not cause pcall to return false')
    end
    if _type(obj) ~= 'table' or obj.code ~= 42 then
        fail('error with table did not preserve the table object')
    end

    local outer_ok, inner_result = _pcall(function()
        local inner_ok, inner_err = _pcall(function()
            error('inner')
        end)

        return inner_ok, inner_err
    end)

    if not outer_ok then
        fail('outer pcall failed (nested pcall broken)')
    end

    local captured = nil

    _xpcall(function()
        error('xpcall_msg', 0)
    end, function(e)
        captured = e
    end)

    if captured ~= 'xpcall_msg' then
        fail("xpcall handler received wrong message: '" .. _tostring(captured) .. "'")
    end

    local aok, aerr = _pcall(function()
        assert(false, 'assert_fail')
    end)

    if aok then
        fail('assert(false) did not error')
    end
    if not _string.find(_tostring(aerr), 'assert_fail', 1, true) then
        fail("assert(false, msg) did not include message in error: '" .. _tostring(aerr) .. "'")
    end

    local aok2 = _pcall(function()
        return assert(42)
    end)

    if not aok2 then
        fail('assert(42) should not error')
    end
end
do
    local t = {}

    _rawset(t, 'key', 'val_abc')

    local got = _rawget(t, 'key')

    if got ~= 'val_abc' then
        fail("rawset/rawget round-trip failed: got '" .. _tostring(got) .. "'")
    end
    if _rawget(t, 'nonexistent_xyz') ~= nil then
        fail('rawget returned non-nil for missing key')
    end
    if _rawlen({1, 2, 3}) ~= 3 then
        fail('rawlen({1,2,3}) != 3')
    end

    local a, b = {}, {}

    if not _rawequal(a, a) then
        fail('rawequal(a, a) returned false')
    end
    if _rawequal(a, b) then
        fail('rawequal(a, b) returned true for different tables')
    end
end
do
    local mt_called = false
    local obj = setmetatable({}, {
        __index = function(t, k)
            mt_called = true

            return 'from_mt'
        end,
    })
    local v = _rawget(obj, 'missing_key')

    if mt_called then
        fail('rawget triggered __index metamethod (should bypass it)')
    end
    if v ~= nil then
        fail('rawget on missing key returned non-nil via bypass: ' .. _tostring(v))
    end

    local ni_called = false
    local obj2 = setmetatable({}, {
        __newindex = function(t, k, v)
            ni_called = true
        end,
    })

    _rawset(obj2, 'testkey', 'testval')

    if ni_called then
        fail('rawset triggered __newindex metamethod (should bypass it)')
    end
    if _rawget(obj2, 'testkey') ~= 'testval' then
        fail('rawset value not accessible via rawget after bypass')
    end

    local len_called = false
    local obj3 = setmetatable({1, 2, 3}, {
        __len = function()
            len_called = true

            return 999
        end,
    })
    local rl = _rawlen(obj3)

    if len_called then
        fail('rawlen triggered __len metamethod (should bypass it)')
    end
    if rl ~= 3 then
        fail('rawlen returned ' .. _tostring(rl) .. ' (expected 3)')
    end
end
do
    local count = _select('#', 10, 20, 30)

    if count ~= 3 then
        fail("select('#', 10, 20, 30) = " .. _tostring(count) .. ' (expected 3)')
    end

    local a, b = _select(2, 'x', 'y', 'z')

    if a ~= 'y' or b ~= 'z' then
        fail("select(2, 'x','y','z') returned wrong values: " .. _tostring(a) .. ', ' .. _tostring(b))
    end

    local last = _select(-1, 'a', 'b', 'c')

    if last ~= 'c' then
        fail("select(-1, 'a','b','c') = '" .. _tostring(last) .. "' (expected 'c')")
    end
end
do
    local z = _select('#')

    if z ~= 0 then
        fail("select('#') with zero args = " .. _tostring(z) .. ' (expected 0)')
    end

    local function packTest(...)
        local t = _table.pack(...)

        return t.n, _unpack(t, 1, t.n)
    end

    local n, v1, v2, v3 = packTest('x', 'y', 'z')

    if n ~= 3 then
        fail('table.pack .n field = ' .. _tostring(n) .. ' (expected 3)')
    end
    if v1 ~= 'x' or v2 ~= 'y' or v3 ~= 'z' then
        fail('table.pack/unpack round-trip failed')
    end

    local arr = {
        10,
        20,
        30,
        40,
        50,
    }
    local r1, r2, r3 = _unpack(arr, 2, 4)

    if r1 ~= 20 or r2 ~= 30 or r3 ~= 40 then
        fail('table.unpack(arr, 2, 4) returned wrong values: ' .. _tostring(r1) .. ',' .. _tostring(r2) .. ',' .. _tostring(r3))
    end
end
do
    local co, isMain = _coroutine.running()

    if co == nil then
        fail('coroutine.running() returned nil')
    end
    if _type(co) ~= 'thread' then
        fail("coroutine.running() type = '" .. _type(co) .. "' (expected 'thread')")
    end

    local co2 = _coroutine.create(function()
        _coroutine.yield('mid')

        return 'done'
    end)

    if _coroutine.status(co2) ~= 'suspended' then
        fail("new coroutine status should be 'suspended'")
    end

    local ok1, v1 = _coroutine.resume(co2)

    if not ok1 or v1 ~= 'mid' then
        fail('coroutine first resume failed or wrong yield value: ' .. _tostring(v1))
    end
    if _coroutine.status(co2) ~= 'suspended' then
        fail("coroutine should be 'suspended' after yield")
    end

    local ok2, v2 = _coroutine.resume(co2)

    if not ok2 or v2 ~= 'done' then
        fail('coroutine second resume failed or wrong return: ' .. _tostring(v2))
    end
    if _coroutine.status(co2) ~= 'dead' then
        fail("finished coroutine should be 'dead', got '" .. _coroutine.status(co2) .. "'")
    end

    local ok3, err3 = _coroutine.resume(co2)

    if ok3 then
        fail('resuming a dead coroutine should return false')
    end
    if _type(err3) ~= 'string' then
        fail('resuming a dead coroutine should return an error string')
    end

    local gen = _coroutine.wrap(function()
        for i = 1, 3 do
            _coroutine.yield(i)
        end
    end)

    for expected = 1, 3 do
        local got = gen()

        if got ~= expected then
            fail('coroutine.wrap yielded ' .. _tostring(got) .. ' (expected ' .. expected .. ')')

            break
        end
    end

    local yieldable = nil
    local coy = _coroutine.create(function()
        yieldable = _coroutine.isyieldable()
    end)

    _coroutine.resume(coy)

    if yieldable ~= true then
        fail('coroutine.isyieldable() inside coroutine returned ' .. _tostring(yieldable) .. ' (expected true)')
    end

    local coc = _coroutine.create(function()
        _coroutine.yield()
    end)

    _coroutine.resume(coc)

    local closeOk = _pcall(_coroutine.close, coc)

    if not closeOk then
        fail('coroutine.close on suspended coroutine threw an error')
    end
    if _coroutine.status(coc) ~= 'dead' then
        fail("coroutine.status after close != 'dead': " .. _coroutine.status(coc))
    end
end
do
    if _bit32.band(0xff, 0xf) ~= 0xf then
        fail('bit32.band(0xFF,0x0F) != 0x0F')
    end
    if _bit32.bor(0xf0, 0xf) ~= 0xff then
        fail('bit32.bor(0xF0,0x0F) != 0xFF')
    end
    if _bit32.bxor(0xff, 0xff) ~= 0 then
        fail('bit32.bxor(0xFF,0xFF) != 0')
    end
    if _bit32.bnot(0) ~= 0xffffffff then
        fail('bit32.bnot(0) != 0xFFFFFFFF')
    end
    if _bit32.lshift(1, 4) ~= 16 then
        fail('bit32.lshift(1,4) != 16')
    end
    if _bit32.rshift(16, 4) ~= 1 then
        fail('bit32.rshift(16,4) != 1')
    end
    if _bit32.band(0xabcd, 0xff) ~= 0xcd then
        fail('bit32.band(0xABCD,0xFF) != 0xCD')
    end
    if _bit32.lshift(0xffffffff, 32) ~= 0 then
        fail('bit32.lshift(0xFFFFFFFF, 32) != 0')
    end
    if _bit32.rshift(0xffffffff, 32) ~= 0 then
        fail('bit32.rshift(0xFFFFFFFF, 32) != 0')
    end

    local val = 0xdeadbeef

    if _bit32.bnot(_bit32.bnot(val)) ~= val then
        fail('bit32.bnot(bnot(x)) != x')
    end
    if _bit32.bxor(val, val) ~= 0 then
        fail('bit32.bxor(x, x) != 0')
    end

    local a, b2 = 0xf0f0, 0xf0f

    if _bit32.band(a, b2) ~= 0 then
        fail('bit32.band(0xF0F0, 0x0F0F) != 0 (non-overlapping bits)')
    end
    if _bit32.bor(a, b2) ~= 0xffff then
        fail('bit32.bor(0xF0F0, 0x0F0F) != 0xFFFF')
    end
end
do
    local utf8str = 'hello'
    local ok, len = _pcall(_utf8.len, utf8str)

    if not ok or len ~= 5 then
        fail("utf8.len('hello') = " .. _tostring(len) .. ' (expected 5)')
    end

    local cp = 0x1f600
    local ok2, encoded = _pcall(_utf8.char, cp)

    if ok2 then
        local ok3, decoded = _pcall(_utf8.codepoint, encoded, 1)

        if ok3 and decoded ~= cp then
            fail('utf8.char/codepoint round-trip failed: got ' .. _tostring(decoded) .. ' expected ' .. cp)
        end
    end

    local visited = {}

    for pos, code in _utf8.codes('abc')do
        _table.insert(visited, code)
    end

    if #visited ~= 3 or visited[1] ~= 97 or visited[2] ~= 98 or visited[3] ~= 99 then
        fail("utf8.codes('abc') visited wrong codepoints")
    end

    local heart = '\u{2764}'
    local okH, lenH = _pcall(_utf8.len, heart)

    if okH and lenH ~= 1 then
        fail('utf8.len of 3-byte heart character != 1 (got ' .. _tostring(lenH) .. ')')
    end

    local okOff, off = _pcall(_utf8.offset, 'abc', 2)

    if okOff and off ~= 2 then
        fail('utf8.offset("abc", 2) != 2 (got ' .. _tostring(off) .. ')')
    end

    local invalid = '\255\254'
    local okInv, lenInv, errPos = _pcall(_utf8.len, invalid)

    if okInv then
        if lenInv ~= nil then
            fail('utf8.len on invalid UTF-8 should return nil, got ' .. _tostring(lenInv))
        end
    end
end
do
    local v1 = Vector3.new(1, 2, 3)
    local v2 = Vector3.new(4, 5, 6)
    local sum = v1 + v2

    if _math.abs(sum.X - 5) > 1e-5 or _math.abs(sum.Y - 7) > 1e-5 or _math.abs(sum.Z - 9) > 1e-5 then
        fail('Vector3 addition corrupted: ' .. _tostring(sum))
    end

    local diff = v2 - v1

    if _math.abs(diff.X - 3) > 1e-5 or _math.abs(diff.Y - 3) > 1e-5 or _math.abs(diff.Z - 3) > 1e-5 then
        fail('Vector3 subtraction corrupted: ' .. _tostring(diff))
    end

    local scaled = v1 * 2

    if _math.abs(scaled.X - 2) > 1e-5 or _math.abs(scaled.Y - 4) > 1e-5 or _math.abs(scaled.Z - 6) > 1e-5 then
        fail('Vector3 scalar multiply corrupted: ' .. _tostring(scaled))
    end

    local mag = v1.Magnitude

    if _math.abs(mag - _math.sqrt(14)) > 1e-5 then
        fail('Vector3.Magnitude corrupted: ' .. _tostring(mag))
    end

    local cf = CFrame.new(1, 2, 3)
    local pos = cf.Position

    if _math.abs(pos.X - 1) > 1e-5 or _math.abs(pos.Y - 2) > 1e-5 or _math.abs(pos.Z - 3) > 1e-5 then
        fail('CFrame.Position corrupted: ' .. _tostring(pos))
    end

    local identity = CFrame.identity
    local cfResult = cf * identity

    if _math.abs(cfResult.X - 1) > 1e-5 or _math.abs(cfResult.Y - 2) > 1e-5 or _math.abs(cfResult.Z - 3) > 1e-5 then
        fail('CFrame * identity corrupted: ' .. _tostring(cfResult))
    end

    local dot = v1:Dot(v2)

    if _math.abs(dot - 32) > 1e-5 then
        fail('Vector3:Dot() = ' .. _tostring(dot) .. ' (expected 32)')
    end

    local cross = v1:Cross(v2)

    if _math.abs(cross.X - (-3)) > 1e-5 or _math.abs(cross.Y - 6) > 1e-5 or _math.abs(cross.Z - (-3)) > 1e-5 then
        fail('Vector3:Cross() corrupted: ' .. _tostring(cross))
    end

    local unit = Vector3.new(3, 0, 0).Unit

    if _math.abs(unit.X - 1) > 1e-5 or _math.abs(unit.Y) > 1e-5 or _math.abs(unit.Z) > 1e-5 then
        fail('Vector3.Unit corrupted: ' .. _tostring(unit))
    end

    local cfInv = cf:Inverse()
    local product = cf * cfInv

    if _math.abs(product.X) > 1e-4 or _math.abs(product.Y) > 1e-4 or _math.abs(product.Z) > 1e-4 then
        fail('CFrame * Inverse not identity: ' .. _tostring(product))
    end

    local rx, ry, rz = CFrame.Angles(_math.pi / 4, 0, 0):ToEulerAnglesXYZ()

    if _type(rx) ~= 'number' or _type(ry) ~= 'number' or _type(rz) ~= 'number' then
        fail('CFrame:ToEulerAnglesXYZ() did not return 3 numbers')
    end
    if _math.abs(rx - _math.pi / 4) > 1e-4 then
        fail('CFrame:ToEulerAnglesXYZ() X angle incorrect: ' .. _tostring(rx))
    end

    local v2a = Vector2.new(3, 4)

    if _math.abs(v2a.Magnitude - 5) > 1e-5 then
        fail('Vector2.Magnitude(3,4) != 5 (got ' .. _tostring(v2a.Magnitude) .. ')')
    end
end
do
    local ok, inst = _pcall(Instance.new, 'Part')

    if not ok then
        fail("Instance.new('Part') threw an error")
    else
        if _typeof(inst) ~= 'Instance' then
            fail("Instance.new('Part') typeof = '" .. _typeof(inst) .. "' (expected 'Instance')")
        end
        if _type(inst) ~= 'userdata' then
            fail("Instance.new('Part') type = '" .. _type(inst) .. "' (expected 'userdata')")
        end

        local ok2, cls = _pcall(function()
            return inst.ClassName
        end)

        if not ok2 or cls ~= 'Part' then
            fail("Part.ClassName = '" .. _tostring(cls) .. "' (expected 'Part')")
        end

        local ok3, r = _pcall(function()
            return inst:IsA('BasePart')
        end)

        if not ok3 or not r then
            fail("Part:IsA('BasePart') returned false or errored")
        end

        inst.Name = 'TestPart_AntiTamper'

        if inst.Name ~= 'TestPart_AntiTamper' then
            fail('Instance.Name assignment did not persist')
        end

        local child = Instance.new('StringValue')

        child.Name = 'ChildValue'
        child.Parent = inst

        local found = inst:FindFirstChild('ChildValue')

        if found == nil then
            fail('Instance:FindFirstChild returned nil for a known child')
        end
        if not _rawequal(found, child) then
            fail('Instance:FindFirstChild returned wrong object')
        end

        local children = inst:GetChildren()

        if _type(children) ~= 'table' then
            fail('Instance:GetChildren() returned non-table: ' .. _type(children))
        end
        if #children ~= 1 then
            fail('Instance:GetChildren() length wrong: ' .. #children .. ' (expected 1)')
        end

        child.Parent = inst

        if not child:IsDescendantOf(inst) then
            fail('child:IsDescendantOf(parent) returned false')
        end

        local clonePart = inst:Clone()

        if clonePart == nil then
            fail('Instance:Clone() returned nil')
        end
        if _rawequal(clonePart, inst) then
            fail('Instance:Clone() returned same reference')
        end
        if clonePart.ClassName ~= 'Part' then
            fail("Clone.ClassName != 'Part'")
        end

        clonePart:Destroy()
        inst:Destroy()
    end
end
do
    if _type(Enum) ~= 'userdata' then
        fail("type(Enum) = '" .. _type(Enum) .. "' (expected 'userdata')")
    end
    if _typeof(Enum) ~= 'Enums' then
        fail("typeof(Enum) = '" .. _typeof(Enum) .. "' (expected 'Enums')")
    end

    local ok, item = _pcall(function()
        return Enum.KeyCode.W
    end)

    if not ok or _typeof(item) ~= 'EnumItem' then
        fail('Enum.KeyCode.W access failed or wrong type: ' .. _tostring(_typeof(item)))
    end
    if ok and item.Name ~= 'W' then
        fail("Enum.KeyCode.W.Name = '" .. _tostring(item.Name) .. "' (expected 'W')")
    end
    if ok and _type(item.Value) ~= 'number' then
        fail("Enum.KeyCode.W.Value type != 'number'")
    end

    local okItems, items = _pcall(function()
        return Enum.KeyCode:GetEnumItems()
    end)

    if okItems then
        if _type(items) ~= 'table' or #items == 0 then
            fail('Enum.KeyCode:GetEnumItems() returned empty or non-table')
        end
        if _typeof(items[1]) ~= 'EnumItem' then
            fail('First item from GetEnumItems() is not EnumItem')
        end
    end

    local okM, mat = _pcall(function()
        return Enum.Material.SmoothPlastic
    end)

    if not okM or _typeof(mat) ~= 'EnumItem' then
        fail('Enum.Material.SmoothPlastic access failed')
    end

    local okN, nid = _pcall(function()
        return Enum.NormalId.Top
    end)

    if not okN or _typeof(nid) ~= 'EnumItem' then
        fail('Enum.NormalId.Top access failed')
    end
end
do
    local okMt, mt = _pcall(getmetatable, game)

    if okMt then
        if _type(mt) ~= 'string' then
            fail('getmetatable(game) should return lock string, got ' .. _type(mt) .. ' (possible getrawmetatable exposure)')
        end
    end

    local okSet = _pcall(setmetatable, game, {})

    if okSet then
        fail('setmetatable(game, {}) should error on a locked Instance')
    end

    local prx = _newproxy(true)
    local prxMt = getmetatable(prx)

    if prxMt ~= nil then
        prxMt.__type = 'FakeInstance'

        local spoofed = _typeof(prx)

        if spoofed == 'FakeInstance' then
            fail('typeof() was fooled by __type on newproxy (executor may have patched typeof)')
        end
    end

    local guardedMt = {
        __metatable = 'GuardedMT',
    }
    local guarded = setmetatable({}, guardedMt)
    local lockStr = getmetatable(guarded)

    if lockStr ~= 'GuardedMT' then
        fail("getmetatable on __metatable-guarded object returned '" .. _tostring(lockStr) .. "' (expected 'GuardedMT')")
    end
end
do
    local RS = game:GetService('RunService')

    if not RS:IsClient() then
        fail('RunService:IsClient() returned false')
    end
    if RS:IsServer() then
        fail('RunService:IsServer() returned true in a client-only context')
    end
    if _type(RS:IsRunning()) ~= 'boolean' then
        fail('RunService:IsRunning() did not return a boolean')
    end
    if _type(RS:IsStudio()) ~= 'boolean' then
        fail('RunService:IsStudio() did not return a boolean')
    end
end
do
    local spawned = false
    local thr = _task.spawn(function()
        spawned = true
    end)

    if not spawned then
        fail('task.spawn did not execute the function in the same frame')
    end
    if _type(thr) ~= 'thread' then
        fail('task.spawn returned non-thread: ' .. _type(thr))
    end

    local deferred = _task.defer(function() end)

    if _type(deferred) ~= 'thread' then
        fail('task.defer returned non-thread: ' .. _type(deferred))
    end

    local cancelOk = _pcall(_task.cancel, deferred)

    if not cancelOk then
        fail('task.cancel on deferred thread threw an error')
    end
end
do
    local okCg, mem = _pcall(collectgarbage, 'count')

    if not okCg then
        fail('collectgarbage("count") threw an error')
    elseif _type(mem) ~= 'number' then
        fail("collectgarbage('count') returned non-number: " .. _type(mem))
    elseif mem < 0 or mem > 2e6 then
        fail("collectgarbage('count') returned suspicious value: " .. _tostring(mem) .. ' KB')
    end
end
do
    local folder = Instance.new('Folder')
    local fired = false
    local conn = folder.ChildAdded:Connect(function(child)
        if child.Name == 'TestChild_AT' then
            fired = true
        end
    end)
    local child = Instance.new('Part')

    child.Name = 'TestChild_AT'
    child.Parent = folder

    if _typeof(conn) ~= 'RBXScriptConnection' then
        fail("RBXScriptConnection typeof = '" .. _typeof(conn) .. "' (expected 'RBXScriptConnection')")
    end
    if _type(conn.Connected) ~= 'boolean' then
        fail('RBXScriptConnection.Connected is not a boolean')
    end
    if not conn.Connected then
        fail('RBXScriptConnection.Connected is false immediately after Connect()')
    end

    conn:Disconnect()

    if conn.Connected then
        fail('RBXScriptConnection.Connected is true after Disconnect()')
    end

    folder:Destroy()
end
do
    local function multiRet()
        return 1, 2, 3
    end

    local results = {
        _pcall(multiRet),
    }

    if results[1] ~= true then
        fail('pcall multi-return: success flag wrong')
    end
    if results[2] ~= 1 or results[3] ~= 2 or results[4] ~= 3 then
        fail('pcall did not pass through multiple return values correctly')
    end

    local function noRet() end

    local zr = {
        _pcall(noRet),
    }

    if #zr ~= 1 or zr[1] ~= true then
        fail('pcall with zero-return function returned unexpected extra values')
    end
end
do
    local a = Instance.new('Folder')
    local b = Instance.new('Folder')

    if _rawequal(a, b) then
        fail('Two Instance.new calls returned the same object')
    end

    a.Name = 'A_AT'
    b.Name = 'B_AT'

    if a.Name == b.Name then
        fail('Setting Name on one instance affected another')
    end

    a:Destroy()
    b:Destroy()

    local t1 = {}
    local t2 = t1

    if not _rawequal(t1, t2) then
        fail('rawequal on aliased table returned false')
    end

    local t3 = {}

    if _rawequal(t1, t3) then
        fail('rawequal on distinct tables returned true')
    end
end
do
    local count = 0

    for _ in _string.gmatch('abc', '')do
        count = count + 1

        if count > 10 then
            break
        end
    end

    if count == 0 then
        fail('string.gmatch with empty pattern returned 0 matches')
    end

    local inner = _string.match('(hello (world))', '%b()')

    if inner == nil then
        fail('string.match %b() balanced pattern returned nil')
    end

    local fr = _string.find('THE END', '%f[%a]%u+')

    if fr == nil then
        fail('string.find frontier pattern %f[%a] returned nil')
    end

    local out = _string.gsub('hello world', '%a+', function(w)
        return _string.upper(w)
    end)

    if out ~= 'HELLO WORLD' then
        fail("string.gsub with function replacer failed: got '" .. out .. "'")
    end

    local t = {
        hello = 'HI',
        world = 'EARTH',
    }
    local out2 = _string.gsub('hello world', '%a+', t)

    if out2 ~= 'HI EARTH' then
        fail("string.gsub with table replacer failed: got '" .. out2 .. "'")
    end
end
do
    local sparse = {
        10,
        20,
        nil,
        40,
    }
    local ipCount = 0

    for i, v in _ipairs(sparse)do
        ipCount = ipCount + 1
    end

    if ipCount ~= 2 then
        fail('ipairs did not stop at first nil gap (got ' .. ipCount .. ' iterations, expected 2)')
    end

    local mixed = {
        a = 1,
        b = 2,
        c = 3,
    }
    local pCount = 0

    for k, v in _pairs(mixed)do
        pCount = pCount + 1
    end

    if pCount ~= 3 then
        fail('pairs visited wrong number of keys: ' .. pCount .. ' (expected 3)')
    end

    local nt = {
        x = 10,
        y = 20,
    }
    local keys = {}
    local k = nil

    while true do
        k = _next(nt, k)

        if k == nil then
            break
        end

        _table.insert(keys, k)
    end

    if #keys ~= 2 then
        fail('next traversal visited ' .. #keys .. ' keys (expected 2)')
    end
end
do
    local i = 1
    local f = 1

    if _type(i) ~= 'number' then
        fail("type(1) != 'number'")
    end
    if _type(f) ~= 'number' then
        fail("type(1.0) != 'number'")
    end
end
do
    local ranTimes = 0
    local conn47 = game:GetService('RunService').Heartbeat:Connect(function()
        ranTimes += 1
    end)
    local t0 = os.clock()

    while ranTimes < 2 and (os.clock() - t0) < 3 do
        _task.wait()
    end

    conn47:Disconnect()

    if ranTimes < 2 then
        fail('RunService.Heartbeat did not fire at least 2 times within 3 seconds (stubbed/fake Heartbeat)')
    end
end
do
    local ok48 = _pcall(function()
        Instance.new('Part'):__antitamper_invalid_method_xyz('a')
    end)

    if ok48 then
        fail('Calling an invalid Instance method did not error (executor may be faking method dispatch)')
    end
end
do
    local ok49, children = _pcall(function()
        return game:GetChildren()
    end)

    if ok49 then
        if _type(children) ~= 'table' then
            fail('game:GetChildren() returned non-table: ' .. _type(children))
        elseif #children <= 4 then
            fail('game:GetChildren() returned only ' .. #children .. ' children (expected > 4, likely fake DataModel)')
        end
    else
        fail('game:GetChildren() errored unexpectedly')
    end
end
do
    local hs = game:GetService('HttpService')
    local ok50, result = _pcall(function()
        return hs:JSONDecode('[68, "antitamper", true, 123, false, [321, null, "goldtm"], null, ["a"]]')
    end)

    if not ok50 then
        fail('HttpService:JSONDecode threw an error on valid JSON')
    else
        if _type(result) ~= 'table' then
            fail('JSONDecode result is not a table: ' .. _type(result))
        else
            if result[1] ~= 68 then
                fail('JSONDecode: result[1] != 68 (got ' .. _tostring(result[1]) .. ')')
            end
            if result[2] ~= 'antitamper' then
                fail('JSONDecode: result[2] != "antitamper"')
            end
            if result[3] ~= true then
                fail('JSONDecode: result[3] != true')
            end
            if result[5] ~= false then
                fail('JSONDecode: result[5] != false')
            end
            if result[6] == nil or result[6][1] ~= 321 then
                fail('JSONDecode: result[6][1] != 321 (nested array broken)')
            end
            if result[6][2] ~= nil then
                fail('JSONDecode: null in nested array should decode as nil, got ' .. _tostring(result[6][2]))
            end
            if result[7] ~= nil then
                fail('JSONDecode: top-level null should decode as nil, got ' .. _tostring(result[7]))
            end
        end
    end
end
do
    local ok51 = _pcall(function()
        for _ in game do end
    end)

    if ok51 then
        fail('game is iterable (real DataModel should not support generic for-in)')
    end
end
do
    if _typeof(game) ~= 'Instance' then
        fail("typeof(game) = '" .. _typeof(game) .. "' (expected 'Instance')")
    end
end
do
    local ok54, msg54 = _pcall(function()
        game()
    end)

    if ok54 then
        fail('game() did not error (real DataModel should not be callable)')
    else
        local s = _tostring(msg54)

        if not _string.find(s, 'attempt to call', 1, true) then
            fail("game() error message unexpected: '" .. s .. "' (expected 'attempt to call')")
        end
    end
end
do
    local t0 = os.clock()
    local delta = _task.wait(0.5)
    local elapsed = os.clock() - t0

    if elapsed < 0.4 then
        fail('task.wait(0.5) returned in ' .. _string.format('%.3f', elapsed) .. 's (too fast, likely stubbed)')
    end
    if _type(delta) ~= 'number' or delta < 0 then
        fail('task.wait return value is not a valid positive number: ' .. _tostring(delta))
    end
end
do
    local okP, ispP, nupsP = _pcall(_debug.info, print, 'a')

    if okP then
        if ispP ~= 0 then
            fail('debug.info(print,"a") isparam != 0 (print is C, should have 0 params reported)')
        end
    end

    local okTs, ispTs = _pcall(_debug.info, tostring, 'a')

    if okTs then
        if ispTs ~= 0 then
            fail('debug.info(tostring,"a") isparam != 0')
        end
    end

    local okPrS, srcPr = _pcall(_debug.info, print, 's')

    if okPrS and srcPr ~= '[C]' then
        fail("debug.info(print,'s') = '" .. _tostring(srcPr) .. "' (expected '[C]')")
    end

    local okReqS, srcReq = _pcall(_debug.info, require, 's')

    if okReqS and srcReq ~= '[C]' then
        fail("debug.info(require,'s') = '" .. _tostring(srcReq) .. "' (expected '[C]')")
    end

    local luaFn = function() end
    local okLua, srcLua = _pcall(_debug.info, luaFn, 's')

    if okLua and srcLua == '[C]' then
        fail("debug.info(luaFn,'s') = '[C]' (a plain Lua function should not report [C])")
    end
end
do
    local ok57 = _pcall(_getfenv, 69)

    if ok57 then
        fail('getfenv(69) did not error (level 69 is out of valid stack range in real Luau)')
    end
end
do
    local ran58 = false
    local thr58 = _task.spawn(function()
        ran58 = true
    end)

    if not ran58 then
        fail('task.spawn did not run function immediately (unix task check)')
    end
    if _type(thr58) ~= 'thread' then
        fail('task.spawn did not return a thread')
    end

    local yielded58 = false

    _task.spawn(function()
        _task.wait(0)

        yielded58 = true
    end)
    _task.wait(0)

    local nested58 = false

    _task.spawn(function()
        local co2 = _coroutine.create(function()
            nested58 = true
        end)

        _task.spawn(co2)
    end)
    _task.wait(0)

    if not nested58 then
        fail('task.spawn(coroutine) did not execute nested coroutine (unix nested spawn check)')
    end

    local okTW, srcTW = _pcall(_debug.info, _task.wait, 's')

    if okTW and srcTW ~= '[C]' and srcTW ~= nil then
        fail("debug.info(task.wait,'s') = '" .. _tostring(srcTW) .. "' (expected '[C]', may be hooked)")
    end
end
do
    if _type(spawn) ~= 'function' then
        fail("type(spawn) = '" .. _type(spawn) .. "' (expected 'function') \u{2014} executor may have removed global spawn")
    end
end
do
    local ok61a, changed = _pcall(function()
        return game.Changed
    end)

    if ok61a then
        if _typeof(changed) ~= 'RBXScriptSignal' then
            fail("typeof(game.Changed) = '" .. _typeof(changed) .. "' (expected 'RBXScriptSignal')")
        end
    end

    local ok61b, hb = _pcall(function()
        return game:GetService('RunService').Heartbeat
    end)

    if ok61b then
        if _typeof(hb) ~= 'RBXScriptSignal' then
            fail("typeof(RunService.Heartbeat) = '" .. _typeof(hb) .. "' (expected 'RBXScriptSignal')")
        end
    end

    local ok61c, plastic = _pcall(function()
        return Enum.Material.Plastic
    end)

    if ok61c then
        if _typeof(plastic) ~= 'EnumItem' then
            fail('Enum.Material.Plastic is not an EnumItem')
        end
        if plastic.Value ~= 256 then
            fail('Enum.Material.Plastic.Value != 256 (got ' .. _tostring(plastic.Value) .. ')')
        end
    end
end
do
    local ok62, name62 = _pcall(function()
        return workspace:GetFullName()
    end)

    if ok62 then
        if name62 ~= 'Workspace' then
            fail("workspace:GetFullName() = '" .. _tostring(name62) .. "' (expected 'Workspace')")
        end
    else
        fail('workspace:GetFullName() errored')
    end
end
do
    local ok63a, t1 = _pcall(function()
        return workspace.DistributedGameTime
    end)

    if ok63a then
        _task.wait(0.1)

        local ok63b, t2 = _pcall(function()
            return workspace.DistributedGameTime
        end)

        if ok63b then
            if (t2 - t1) <= 0 then
                fail('workspace.DistributedGameTime did not advance after task.wait(0.1) (frozen/fake clock)')
            end
        end
    end
end
do
    local hs = game:GetService('HttpService')
    local okG, guid = _pcall(function()
        return hs:GenerateGUID(false)
    end)

    if okG then
        if _type(guid) ~= 'string' then
            fail('GenerateGUID returned non-string: ' .. _type(guid))
        elseif #guid ~= 36 then
            fail('GenerateGUID length != 36 (got ' .. #guid .. ')')
        elseif _string.sub(guid, 9, 9) ~= '-' then
            fail('GenerateGUID format wrong: char 9 is not "-" (got ' .. _string.sub(guid, 9, 9) .. ')')
        end

        local _, guid2 = _pcall(function()
            return hs:GenerateGUID(false)
        end)

        if guid2 == guid then
            fail('GenerateGUID returned the same GUID twice (not random)')
        end
    else
        fail('HttpService:GenerateGUID errored')
    end
end
do
    local ok65, tcs = _pcall(function()
        return game:GetService('TextChatService')
    end)

    if ok65 and tcs then
        local okCh, channel = _pcall(function()
            return tcs.TextChannels:WaitForChild('RBXGeneral', 3)
        end)

        if okCh and channel then
            local Players = game:GetService('Players')
            local player = Players.LocalPlayer

            if player then
                local nonce65 = 'MANGO'
                local fired65 = false
                local conn65

                conn65 = tcs.MessageReceived:Connect(function(message)
                    if message.Text == nonce65 and message.TextSource and message.TextSource.UserId == player.UserId then
                        fired65 = true
                    end
                end)

                _pcall(function()
                    channel:SendAsync(nonce65)
                end)

                local t0 = os.clock()

                while not fired65 and (os.clock() - t0) < 3 do
                    _task.wait()
                end

                conn65:Disconnect()

                if not fired65 then
                    fail('TextChatService MessageReceived did not fire for own message (executor may be blocking chat events)')
                end
            end
        end
    end
end
do
    local pd_triggered = false
    local pd_ok = _pcall(function()
        local c1 = game.ClassName == 'DataModel'
        local c2 = workspace.ClassName == 'Workspace'
        local c3 = _typeof(Enum.Material.Plastic) == 'EnumItem'
        local c4 = Enum.Material.Plastic.Value == 256
        local c5 = _typeof(game.Changed) == 'RBXScriptSignal'
        local c6 = _typeof(workspace.Changed) == 'RBXScriptSignal'
        local rs = game:GetService('RunService')
        local c7 = rs.ClassName == 'RunService'
        local c8 = _typeof(rs.Heartbeat) == 'RBXScriptSignal'
        local c9 = rs:IsClient() ~= rs:IsServer()
        local part = Instance.new('Part')
        local c10 = _typeof(part) == 'Instance' and part.ClassName == 'Part'

        part:Destroy()

        local c11 = workspace:GetFullName() == 'Workspace'
        local cf = CFrame.new(1, 2, 3)
        local c12 = cf.X == 1 and cf.Y == 2 and cf.Z == 3
        local t1 = workspace.DistributedGameTime

        _task.wait(0.1)

        local t2 = workspace.DistributedGameTime
        local c13 = (t2 - t1) > 0
        local hs = game:GetService('HttpService')
        local gok, guid = _pcall(function()
            return hs:GenerateGUID(false)
        end)
        local c14 = gok and #guid == 36 and _string.sub(guid, 9, 9) == '-'
        local checks = {
            c1,
            c2,
            c3,
            c4,
            c5,
            c6,
            c7,
            c8,
            c9,
            c10,
            c11,
            c12,
            c13,
            c14,
        }
        local passed = 0

        for _, v in _ipairs(checks)do
            if v then
                passed += 1
            end
        end

        if passed < #checks then
            pd_triggered = true

            fail('Project Diamond suite: only ' .. passed .. '/14 checks passed')
        end
    end)

    if not pd_ok then
        fail('Project Diamond suite: pcall wrapper errored (environment too broken to test)')
    end
end

if #failures > 0 then
    print('anti-tamper: ' .. #failures .. ' problem(s) found')

    for _, msg in _ipairs(failures)do
        print('  - ' .. msg)
    end

    return
end

print('passed all checks.')