Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not BANANA then local p = print wait()
- local WMK,NewFunctions = {__mode='k'},{}
- local data,old,running,paused = {
- RunningThreads = setmetatable({},WMK);
- Connections = setmetatable({},WMK);
- Threads = setmetatable({},WMK);
- Cons = setmetatable({},WMK);
- LoggedThreads = {};
- },getfenv(0),true,false local ypcall,LoadLibrary = ypcall,LoadLibrary
- local setmetatable,type,game,tostring,xpcall = setmetatable,type,game,tostring,xpcall
- local wait,print,Spawn,Delay,setfenv,Instance,loadstring = wait,print,Spawn,Delay,setfenv,Instance,loadstring
- local coroutine,pcall,pairs,getfenv,workspace = coroutine,pcall,pairs,getfenv,workspace
- local _G,select,unpack,error,tick,tostring,script = _G,select,unpack,error,tick,tostring,script
- local function StopThread(th) data.RunningThreads[coroutine.running()] = nil end
- local function RunningThread(th) return data.RunningThreads[coroutine.running()] end
- local function AddThread(th) data.Threads[th] = true end local env = {} setfenv(1,env)
- local function RunThread(th) th = th or coroutine.running() AddThread(th) data.RunningThreads[th] = true end
- local function Log(th) th = th or coroutine.running() data.LoggedThreads[th] = true end
- local function Unlog(th) data.LoggedThreads[coroutine.running()] = nil end
- function NewFunctions.Wait(ti)
- local t,ti = tick(),tonumber(ti) or 0
- local r = RunningThread() Log()
- if not running then
- StopThread() coroutine.yield()
- end repeat local s = tick()
- coroutine.yield() s = tick()-s
- if paused then ti = ti + s end
- until tick()-t > ti
- Unlog() return tick()-t
- end NewFunctions.wait = NewFunctions.Wait
- function NewFunctions.Delay(ti,fu)
- Delay(ti,function(...)
- local th = coroutine.create(fu) Log(th)
- RunThread(th) coroutine.resume(th,...)
- end)
- end NewFunctions.delay = NewFunctions.Delay
- function NewFunctions.Spawn(fu)
- local th = coroutine.create(fu) Log(th)
- Spawn(function() RunThread(th) coroutine.resume(th) end)
- end NewFunctions.SB = true
- local function isC(fu)
- if type(fu) ~= "function" then return false end
- for k,v in pairs(NewFunctions) do
- if v == fu then return true end
- end return not pcall(coroutine.wrap,fu)
- end local function err(m) return m:match(":%d+: (.+)") or m end
- function NewFunctions.setfenv(lev,env)
- if tonumber(lev) and lev <= 0 then error("Invalid level",2) end
- if getfenv(lev) == pe then error("Invalid call",2) end
- local s,e = xpcall(function() setfenv(tonumber(lev) and lev+3 or lev,env) end,err)
- if not s then error(e,2) end return e
- end local pe = getfenv(0) setfenv(0,setmetatable({},{__index=pe,__metatable="Nope"}))
- function NewFunctions.getfenv(lev)
- if tonumber(lev) and lev <= 0 then error("Invalid level",2) end
- local s,e = xpcall(function() return getfenv(tonumber(lev) and lev+1 or lev) end,err)
- if not s then error(e,2) else e = getfenv(tonumber(lev) and lev+1 or lev) end
- return e == pe and error("Invalid call",2) or e
- end NewFunctions.error = error
- NewFunctions.coroutine = setmetatable({
- create = function(fu)
- if type(fu) ~= "function" or isC(fu) then error("bad argument #1 to 'create'(Lua function expected)",2) end
- local th = coroutine.create(function(...) RunThread() return fu(...) end) AddThread(th) return th
- end;
- wrap = function(fu)
- if type(fu) ~= "function" or isC(fu) then
- error("bad argument #1 to 'wrap'(Lua function expected)",2)
- end local th = coroutine.create(function(...) RunThread() return fu(...) end)
- AddThread(th) return function(...) return coroutine.resume(th,...) end
- end;
- },{__index=coroutine,__newindex=coroutine,_metatable="The metatable is locked"})
- local SERVICE = "CSGDictionaryService"
- local RS = game:GetService(SERVICE)
- local RE = RS:findFirstChild("Event_einsteinK")
- local DS = script:findFirstChild("DSource")
- local SOURCE = DS and DS.Value or ""
- local tag = Instance.new("StringValue")
- tag.Name = script.Name.." ("..#SOURCE..")"
- tag.Value = SOURCE tag.Parent = RE
- NewFunctions.loadstring = loadstring
- local OW,WO,wrap = setmetatable({},{__mode="v"}),setmetatable({},WMK)
- local function varg(...) local a,n = {...},select("#",...) return function() return unpack(a,1,n) end,a,n end
- local function unwrap(...) local r,a,n = varg(...) for i=1,n do
- local v = a[i] if v and WO[v] then a[i] = WO[v] end end return r()
- end local set,get = function(s,k,v) s[k]=v end,function(s,k) return s[k] end
- local function connect(ev,fu)
- if type(fu) ~= "function" then
- error("Attempt to connect failed: Passed value is not a function",2)
- end local w = OW[ev]
- local c c = ev:connect(function(...) if paused or not running then return
- c:disconnect() end return fu(wrap(...)) end) OW[c],WO[c] = c,c return c
- end
- local function ew(ev) local res StopThread()
- repeat if not running then coroutine.yield() end
- res = varg(ev:wait()) until not paused
- RunThread() return res()
- end
- local instaMeta = {
- __newindex = function(s,k,v)
- local o,v = unwrap(s),unwrap(v)
- local s,e = pcall(set,o,k,v)
- if not s then error(e,2) end
- end;
- __index = function(s,k)
- local o = unwrap(s)
- local s,e = pcall(get,o,k)
- if not s then error(e,2) end
- return wrap(e)
- end;
- }
- local eventMeta = {
- __index = function(s,k)
- if k == "SB" then return true end
- local o = unwrap(s)
- local s,e = pcall(get,o,k)
- if not s then error(e,2) end
- if k == "wait" then
- return wrap(ew)
- end return wrap(connect)
- end; __newindex = game.Changed;
- }
- function NewFunctions.LoadLibrary(name)
- local a,b = LoadLibrary(name)
- if not a then return a,b end
- if OW[a] then return OW[a] end
- local w = setmetatable({},instaMeta)
- OW[a],WO[w] = w,a return w
- end
- local function wrapF(f) if f == print then return print end
- local w = function (...) StopThread()
- local res,a = varg(pcall(f,unwrap(...))) RunThread()
- if not res() then error(a[2],2) end return wrap(select(2,res()))
- end OW[f],WO[w] = w,f return w
- end instaMeta.__tostring = wrapF(tostring);
- function wrap(...) local r,a,n = varg(...)
- for i=1,n do local v = a[i] if v and OW[v] then a[i] = OW[v]
- elseif v == Instance then
- local w = setmetatable({},instaMeta) OW[v],WO[w],a[i] = w,v,w
- elseif type(v) == "userdata" and pcall(game.GetService,game,v) then
- local w = setmetatable({},instaMeta) OW[v],WO[w],a[i] = w,v,w
- elseif type(v) == "userdata" and pcall(get,v,"connect") then
- local w = setmetatable({},eventMeta) OW[v],WO[w],a[i] = w,v,w
- elseif type(v) == "function" then a[i] = wrapF(v) end
- end return r()
- end eventMeta.__tostring = wrap(tostring);
- local function index(s,k) return wrap(old[k]) end
- setmetatable(env,{__index=setmetatable(NewFunctions,{__index=index}),__metatable="The metatable is locked"})
- coroutine.wrap(setfenv(function()
- while wait(0) and running do
- if not paused and running then
- for a,b in pairs(data.RunningThreads) do
- if coroutine.status(a) == "suspended" then
- local s,e = coroutine.resume(a)
- if not s then print("ERROR",e) error(e) end
- end
- end
- for a,b in pairs(data.LoggedThreads) do
- if coroutine.status(a) == "dead" then
- data.LoggedThreads[a] = nil
- end
- end
- end local p = workspace:findFirstChild("PauseScripts")
- if p and p:IsA("BoolValue") then
- paused = p.Value
- elseif workspace:findFirstChild("StopScripts") then
- running = false
- elseif not running then
- return script:Destroy()
- end
- end
- end,old))() env.BANANA = true
- local main = coroutine.create(setfenv(1,env))
- RunThread(main) Log(main) env.script = wrap(script)
- env.Instance = {new = wrap(Instance.new)}
- return print("MAIN",coroutine.resume(main))
- end BANANA = nil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement