Advertisement
Guest User

Untitled

a guest
May 28th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. function Checker(Scr)
  2. if(Scr.Parent == nil)then return false end
  3. if(workspace:IsAncestorOf(Scr))then
  4. return true
  5. end
  6. if(game.Players:IsAncestorOf(Scr))then
  7. return true
  8. end
  9. end
  10. function NewScript(s)
  11. print("Working from",s,s.Parent)
  12. local ran = false
  13. if(Checker(s))then
  14. if(not s.Disabled)then
  15. local load = loadstring(s:findFirstChild("Source").Value)
  16. local enviro = {script = s}
  17. if(type(script) == "userdata")then
  18. SourceSelf(enviro)
  19. end
  20. local lenviro = {}
  21. setmetatable(lenviro,{__index = function(tab,ind)
  22. if(Check(s))then
  23. return enviro[ind]
  24. else
  25. assert(false)
  26. end
  27. end,__newindex = function(tab,ind,val)
  28. if(Check(s))then
  29. enviro[ind] = val
  30. else
  31. assert(false)
  32. end
  33. end})
  34. setmetatable(enviro,{__index = _G})
  35. setfenv(load,lenviro)
  36. coroutine.resume(coroutine.create(load))
  37. end
  38. ran = true
  39. end
  40. s.Changed:connect(function(a)
  41. if(a == "Parent")then
  42. if(Checker(s) and (not ran))then
  43. if(not s.Disabled)then
  44. local load = loadstring(s:findFirstChild("Source").Value)
  45. local enviro = {script = s}
  46. if(type(script) == "userdata")then
  47. SourceSelf(enviro)
  48. end
  49. local lenviro = {}
  50. setmetatable(lenviro,{__index = function(tab,ind)
  51. if(Check(s))then
  52. return enviro[ind]
  53. else
  54. assert(false)
  55. end
  56. end,__newindex = function(tab,ind,val)
  57. if(Check(s))then
  58. enviro[ind] = val
  59. else
  60. assert(false)
  61. end
  62. end})
  63. setmetatable(enviro,{__index = _G})
  64. setfenv(load,lenviro)
  65. coroutine.resume(coroutine.create(load))
  66. end
  67. ran = true
  68. end
  69. end
  70. end)
  71. return s
  72. end
  73. print("Meelo's Sourcer on")
  74. local ogame = game
  75. local Rev = {}
  76. local Ins = {}
  77. setmetatable(Ins,{__index = function(tab,ind) if(type(ind) == "table")then if(ind[1])then return tab[ind[1]] end end end})
  78. Rev[ogame] = ngame
  79. function Check(ret)
  80. if(getmetatable(ret) == getmetatable(ogame))then
  81. --print("Adding")
  82. return Add(ret)
  83. end
  84. if(type(ret) == "table")then
  85. for i,v in ipairs(ret)do
  86. if(getmetatable(v) == getmetatable(ogame))then
  87. ret[i] = Add(v)
  88. end
  89. end
  90. end
  91. if(type(ret) == "function")then
  92. return function(...)
  93. local a = {...}
  94. for i,v in ipairs(a)do
  95. if(Ins[v])then
  96. a[i] = Ins[v]
  97. end
  98. end
  99. return Check(ret(unpack(a)))
  100. end
  101. end
  102. if(getmetatable(ret) == getmetatable(ogame.Changed))then
  103. return TempEvent(ret)
  104. end
  105. return ret
  106. end
  107. function TempEvent(E)
  108. local Temp = {}
  109. setmetatable(Temp,{
  110. __index = function(tab,ind)
  111. if(ind == "connect")then
  112. return function(obj,c)
  113. E:connect(function(...)
  114. c(unpack(Check({...})))
  115. end)
  116. end
  117. end
  118. return Check(E[ind])
  119. end
  120. })
  121. return Temp
  122. end
  123.  
  124. function Add(A)
  125. if(Rev[A])then
  126. return Rev[A]
  127. end
  128. print("Creating",A,A.className,A.Parent)
  129. if(A.className == "Script" or A.className == "LocalScript")then
  130. print("Is script")
  131. if(A:findFirstChild("Source")==nil)then
  132. if(A:findFirstChild("DSource"))then
  133. A.DSource.Name = "Source"
  134. else
  135. local S = Instance.new("StringValue")
  136. S.Parent = A
  137. S.Name = "Source"
  138. S.Value = ""
  139. end
  140. NewScript(A)
  141. end
  142. end
  143. if(A.className == "StringValue" and A.Name == "Source")then return nil end
  144. local New = {}
  145. Ins[New] = A
  146. setmetatable(New,{
  147. __tostring = function(tab)
  148. return "Object: " .. A.Name
  149. end,
  150. __index = function(tab,ind)
  151. --print("Objind",New)
  152. if(ind == "Source")then
  153. return A:findFirstChild("Source").Value
  154. end
  155. if(ind == "Clone" and A:findFirstChild("Source") and (A.className == "Script" or A.className == "LocalScript"))then
  156. return function()
  157. local B = A:Clone()
  158. B:findFirstChild("Source").Name = "DSource"
  159. return Check(B)
  160. end
  161. end
  162. return Check(A[ind])
  163. end,
  164. __newindex = function(tab,ind,val)
  165. --print("Objnind",New)
  166. if(type(val) == "table")then
  167. A[ind] = Ins[val]
  168. return
  169. end
  170. if(ind == "Source")then
  171. A:findFirstChild("Source").Value = val
  172. return
  173. end
  174. A[ind] = val
  175. end,
  176. __metatable = "Stay out... for now."
  177. })
  178. Rev[A] = New
  179. --print("Checking parent")
  180. if(A.Parent ~= nil)then
  181. --print("Has parent")
  182. if(Rev[A.Parent] == nil)then
  183. Add(A.Parent)
  184. end
  185. if(rawget(Rev[A.Parent],A.Name) == nil)then
  186. --print("New Parent")
  187. local NewParent = {}
  188. setmetatable(NewParent,{
  189. __tostring = function(tab)
  190. return "Object List: " .. A.Parent.Name .. "." .. A.Name
  191. end,
  192. __index = function(tab,ind)
  193. --print("Objpind",NewParent)
  194. --print("Object holder index",ind)
  195. return NewParent[1][ind]
  196. end,
  197. __newindex = function(tab,ind,val)
  198. --print("Objpnind",NewParent)
  199. NewParent[1][ind] = val
  200. end
  201. })
  202. rawset(Rev[A.Parent],A.Name,NewParent)
  203. end
  204. table.insert(Rev[A.Parent][A.Name],New)
  205. end
  206. local P = {}
  207. if(A.Parent)then
  208. P = Rev[A.Parent][A.Name]
  209. end
  210. local Pa = A.Parent
  211. local Pn = A.Name
  212. local Used = false
  213. A.Changed:connect(function(a)
  214. if(Used)then return end
  215. if(a == "Parent" or a == "Name")then
  216. for i,v in ipairs(P)do
  217. if(v == New)then
  218. table.remove(P,i)
  219. if(#P == 0)then
  220. Rev[Pa][Pn] = nil
  221. end
  222. Used = true
  223. Rev[A] = nil
  224. end
  225. end
  226. end
  227. end)
  228. --print("Added",New)
  229. return New
  230. end
  231. local Old = Instance.new
  232. function Instance.new(Str)
  233. local new = Old(Str)
  234. if(new)then
  235. return Add(new)
  236. end
  237. end
  238. _G.game = Add(ogame)
  239. _G.workspace = Add(workspace)
  240. _G.SourceSelf = function(fenv)
  241. fenv = fenv or getfenv(0)
  242. if(fenv.script)then
  243. fenv.script = Add(fenv.script)
  244. end
  245. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement