Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Checker(Scr)
- if(Scr.Parent == nil)then return false end
- if(workspace:IsAncestorOf(Scr))then
- return true
- end
- if(game.Players:IsAncestorOf(Scr))then
- return true
- end
- end
- function NewScript(s)
- print("Working from",s,s.Parent)
- local ran = false
- if(Checker(s))then
- if(not s.Disabled)then
- local load = loadstring(s:findFirstChild("Source").Value)
- local enviro = {script = s}
- if(type(script) == "userdata")then
- SourceSelf(enviro)
- end
- local lenviro = {}
- setmetatable(lenviro,{__index = function(tab,ind)
- if(Check(s))then
- return enviro[ind]
- else
- assert(false)
- end
- end,__newindex = function(tab,ind,val)
- if(Check(s))then
- enviro[ind] = val
- else
- assert(false)
- end
- end})
- setmetatable(enviro,{__index = _G})
- setfenv(load,lenviro)
- coroutine.resume(coroutine.create(load))
- end
- ran = true
- end
- s.Changed:connect(function(a)
- if(a == "Parent")then
- if(Checker(s) and (not ran))then
- if(not s.Disabled)then
- local load = loadstring(s:findFirstChild("Source").Value)
- local enviro = {script = s}
- if(type(script) == "userdata")then
- SourceSelf(enviro)
- end
- local lenviro = {}
- setmetatable(lenviro,{__index = function(tab,ind)
- if(Check(s))then
- return enviro[ind]
- else
- assert(false)
- end
- end,__newindex = function(tab,ind,val)
- if(Check(s))then
- enviro[ind] = val
- else
- assert(false)
- end
- end})
- setmetatable(enviro,{__index = _G})
- setfenv(load,lenviro)
- coroutine.resume(coroutine.create(load))
- end
- ran = true
- end
- end
- end)
- return s
- end
- print("Meelo's Sourcer on")
- local ogame = game
- local Rev = {}
- local Ins = {}
- setmetatable(Ins,{__index = function(tab,ind) if(type(ind) == "table")then if(ind[1])then return tab[ind[1]] end end end})
- Rev[ogame] = ngame
- function Check(ret)
- if(getmetatable(ret) == getmetatable(ogame))then
- --print("Adding")
- return Add(ret)
- end
- if(type(ret) == "table")then
- for i,v in ipairs(ret)do
- if(getmetatable(v) == getmetatable(ogame))then
- ret[i] = Add(v)
- end
- end
- end
- if(type(ret) == "function")then
- return function(...)
- local a = {...}
- for i,v in ipairs(a)do
- if(Ins[v])then
- a[i] = Ins[v]
- end
- end
- return Check(ret(unpack(a)))
- end
- end
- if(getmetatable(ret) == getmetatable(ogame.Changed))then
- return TempEvent(ret)
- end
- return ret
- end
- function TempEvent(E)
- local Temp = {}
- setmetatable(Temp,{
- __index = function(tab,ind)
- if(ind == "connect")then
- return function(obj,c)
- E:connect(function(...)
- c(unpack(Check({...})))
- end)
- end
- end
- return Check(E[ind])
- end
- })
- return Temp
- end
- function Add(A)
- if(Rev[A])then
- return Rev[A]
- end
- print("Creating",A,A.className,A.Parent)
- if(A.className == "Script" or A.className == "LocalScript")then
- print("Is script")
- if(A:findFirstChild("Source")==nil)then
- if(A:findFirstChild("DSource"))then
- A.DSource.Name = "Source"
- else
- local S = Instance.new("StringValue")
- S.Parent = A
- S.Name = "Source"
- S.Value = ""
- end
- NewScript(A)
- end
- end
- if(A.className == "StringValue" and A.Name == "Source")then return nil end
- local New = {}
- Ins[New] = A
- setmetatable(New,{
- __tostring = function(tab)
- return "Object: " .. A.Name
- end,
- __index = function(tab,ind)
- --print("Objind",New)
- if(ind == "Source")then
- return A:findFirstChild("Source").Value
- end
- if(ind == "Clone" and A:findFirstChild("Source") and (A.className == "Script" or A.className == "LocalScript"))then
- return function()
- local B = A:Clone()
- B:findFirstChild("Source").Name = "DSource"
- return Check(B)
- end
- end
- return Check(A[ind])
- end,
- __newindex = function(tab,ind,val)
- --print("Objnind",New)
- if(type(val) == "table")then
- A[ind] = Ins[val]
- return
- end
- if(ind == "Source")then
- A:findFirstChild("Source").Value = val
- return
- end
- A[ind] = val
- end,
- __metatable = "Stay out... for now."
- })
- Rev[A] = New
- --print("Checking parent")
- if(A.Parent ~= nil)then
- --print("Has parent")
- if(Rev[A.Parent] == nil)then
- Add(A.Parent)
- end
- if(rawget(Rev[A.Parent],A.Name) == nil)then
- --print("New Parent")
- local NewParent = {}
- setmetatable(NewParent,{
- __tostring = function(tab)
- return "Object List: " .. A.Parent.Name .. "." .. A.Name
- end,
- __index = function(tab,ind)
- --print("Objpind",NewParent)
- --print("Object holder index",ind)
- return NewParent[1][ind]
- end,
- __newindex = function(tab,ind,val)
- --print("Objpnind",NewParent)
- NewParent[1][ind] = val
- end
- })
- rawset(Rev[A.Parent],A.Name,NewParent)
- end
- table.insert(Rev[A.Parent][A.Name],New)
- end
- local P = {}
- if(A.Parent)then
- P = Rev[A.Parent][A.Name]
- end
- local Pa = A.Parent
- local Pn = A.Name
- local Used = false
- A.Changed:connect(function(a)
- if(Used)then return end
- if(a == "Parent" or a == "Name")then
- for i,v in ipairs(P)do
- if(v == New)then
- table.remove(P,i)
- if(#P == 0)then
- Rev[Pa][Pn] = nil
- end
- Used = true
- Rev[A] = nil
- end
- end
- end
- end)
- --print("Added",New)
- return New
- end
- local Old = Instance.new
- function Instance.new(Str)
- local new = Old(Str)
- if(new)then
- return Add(new)
- end
- end
- _G.game = Add(ogame)
- _G.workspace = Add(workspace)
- _G.SourceSelf = function(fenv)
- fenv = fenv or getfenv(0)
- if(fenv.script)then
- fenv.script = Add(fenv.script)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement