Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- WebSocket mock
- WebSocket = WebSocket or {}
- WebSocket.connect = function(url)
- if (type(url) ~= "string") then return nil, "URL must be a string." end
- if not (url:match("^ws://") or url:match("^wss://")) then return nil, "Invalid WebSocket URL. Must start with 'ws://' or 'wss://'." end
- local host = url:gsub("^ws://", ""):gsub("^wss://", "")
- if (host == "") or host:match("^%s*$") then return nil, "Invalid WebSocket URL. No host specified." end
- return {
- Send = function(data) end,
- Close = function() end,
- OnMessage = {},
- OnClose = {}
- }
- end
- -- Metatable functions
- local rawMetatables = {}
- local originalSetMetatable = setmetatable
- function setmetatable(obj, mt)
- local result = originalSetMetatable(obj, mt)
- rawMetatables[result] = mt
- return result
- end
- function getrawmetatable(obj)
- return rawMetatables[obj]
- end
- function setrawmetatable(obj, mt)
- local current = getrawmetatable(obj)
- for k, v in pairs(mt) do
- current[k] = v
- end
- return obj
- end
- -- Hidden property system
- local hiddenProps = {}
- function sethiddenproperty(obj, key, value)
- if not obj or type(key) ~= "string" then
- error("Failed to set hidden property '" .. tostring(key) .. "' on object: " .. tostring(obj))
- end
- hiddenProps[obj] = hiddenProps[obj] or {}
- hiddenProps[obj][key] = value
- return true
- end
- function gethiddenproperty(obj, key)
- if not obj or type(key) ~= "string" then
- error("Failed to get hidden property '" .. tostring(key) .. "' from object: " .. tostring(obj))
- end
- local val = (hiddenProps[obj] and hiddenProps[obj][key]) or nil
- return val or ((key == "size_xml") and 5), true
- end
- -- Metamethod hooking
- function hookmetamethod(obj, method, func)
- assert(type(obj) == "table" or type(obj) == "userdata", "Expected table/userdata, got " .. type(obj))
- assert(type(method) == "string", "Expected string for method")
- assert(type(func) == "function", "Expected function for replacement")
- local mt = getrawmetatable(obj)
- local original = mt[method]
- mt[method] = func
- return original
- end
- -- Callback mocking
- function getcallbackvalue(obj, key)
- return obj[key]
- end
- -- Simulated debug functions
- debug = debug or {}
- debug.getproto = function(func, index, asTable)
- local dummy = function() return true end
- if asTable then
- return { dummy }
- else
- return dummy
- end
- end
- debug.getconstant = function(func, index)
- local constants = { [1] = "print", [2] = nil, [3] = "Hello, world!" }
- return constants[index]
- end
- debug.getupvalues = function(func)
- local captured
- setfenv(func, { print = function(val) captured = val end })
- func()
- return { captured }
- end
- debug.getupvalue = function(func, index)
- local captured
- setfenv(func, { print = function(val) captured = val end })
- func()
- return captured
- end
- -- Table functions
- table.clone = function(t)
- local copy = {}
- for k, v in pairs(t) do
- copy[k] = v
- end
- return copy
- end
- table.freeze = function(tbl, deep) end
- function setreadonly() end
- function isreadonly(t)
- assert(type(t) == "table", "Expected table")
- return true
- end
- -- Additional Functions
- function getnamecallmethod()
- return debug.getinfo(2, "n").name or "__namecall"
- end
- function hookfunction(original, replacement)
- assert(type(original) == "function", "Expected function for original")
- assert(type(replacement) == "function", "Expected function for replacement")
- -- In real environments, hooking logic would go here.
- return original
- end
- debug.setupvalue = function(func, index, value)
- local i = 1
- while true do
- local name = debug.getupvalue(func, i)
- if not name then break end
- if i == index then
- debug.setupvalue(func, i, value)
- return name
- end
- i = i + 1
- end
- return nil
- end
- debug.setstack = function(level, value)
- error("Setting the call stack is not supported in standard Lua", 2)
- end
- debug.setconstant = function(func, index, value)
- error("Setting constants is not supported in standard Lua", 2)
- end
- -- End of Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement