Advertisement
DrawingJhon

Wrap re-coded

Oct 30th, 2020 (edited)
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.39 KB | None | 0 0
  1. do
  2.  
  3. --local wrappercache = setmetatable({}, {__mode = "k"})
  4. local reals = setmetatable({}, {__mode = "k"})
  5. local proxies = setmetatable({}, {__mode = "v"})
  6. local customProperties = {}
  7.  
  8. local function isInstance(obj)
  9.     return pcall(game.IsA, obj, "Instance")
  10. end
  11. local function setMeta(obj, meta)
  12.     meta.__call = function(self, ...)
  13.         return unpack(wrap{obj(unpack(unwrap{...}))});
  14.     end
  15.     meta.__tostring = function()
  16.         return tostring(obj);
  17.     end
  18.     meta.__concat = function(v1, v2)
  19.         return wrap(unwrap(v1) .. unwrap(v2));
  20.     end
  21.     meta.__add = function(v1, v2)
  22.         return wrap(unwrap(v1) + unwrap(v2));
  23.     end
  24.     meta.__sub = function(v1, v2)
  25.         return wrap(unwrap(v1) - unwrap(v2));
  26.     end
  27.     meta.__mul = function(v1, v2)
  28.         return wrap(unwrap(v1) * unwrap(v2));
  29.     end
  30.     meta.__div = function(v1, v2)
  31.         return wrap(unwrap(v1) / unwrap(v2));
  32.     end
  33.     meta.__mod = function(v1, v2)
  34.         return wrap(unwrap(v1) % unwrap(v2));
  35.     end
  36.     meta.__pow = function(v1, v2)
  37.         return wrap(unwrap(v1) ^ unwrap(v2));
  38.     end
  39.     meta.__unm = function()
  40.         return wrap(-obj)
  41.     end
  42.     meta.__eq = function(v1, v2)
  43.         return wrap(unwrap(v1) == unwrap(v2));
  44.     end
  45.     meta.__lt = function(v1, v2)
  46.         return wrap(unwrap(v1) < unwrap(v2));
  47.     end
  48.     meta.__le = function(v1, v2)
  49.         return wrap(unwrap(v1) <= unwrap(v2));
  50.     end
  51.     meta.__len = function()
  52.         return wrap(#obj);
  53.     end
  54. end
  55.  
  56. wrap = function(real)
  57.     local REAL = reals[real]
  58.     if REAL then
  59.         return REAL
  60.     end
  61.     local PROXY = proxies[real]
  62.     if PROXY then
  63.         return PROXY
  64.     end
  65.     if type(real) == "userdata" then
  66.         local fake = newproxy(true)
  67.         local meta = getmetatable(fake)
  68.        
  69.         meta.__index = function(s,k)
  70.             local class, index = isInstance(real) and real.ClassName or "", k
  71.             local customValue = (customProperties["onread:"..class..":"..index] or customProperties["onread:Instance:"..index]);
  72.             local onIndex = customProperties["onindex:"..class..":"..index] or customProperties["onindex:Instance:"..index]
  73.             if customValue then
  74.                 return wrap(customValue)
  75.             elseif onIndex then
  76.                 return wrap(onIndex(real, index))
  77.             end
  78.             return wrap(real[k])
  79.         end
  80.         meta.__newindex = function(s,k,v)
  81.             local class, index = real.ClassName, k
  82.             local onEdit = (customProperties["onedit:"..class..":"..index] or customProperties["onedit:Instance:"..index]);
  83.             if (onEdit) then
  84.                 onEdit(real, wrap(v))
  85.             else
  86.                 real[wrap(index)] = unwrap(v)
  87.             end
  88.         end
  89.         meta.__tostring = function(s)
  90.             return tostring(real)
  91.         end
  92.         reals[fake], proxies[real] = real, fake
  93.         return fake
  94.     elseif type(real) == "function" then
  95.         local fake = function(...)
  96.             local args = unwrap{...}
  97.             local results = wrap{real(unpack(args))}
  98.             return unpack(results)
  99.         end
  100.         reals[fake], proxies[real] = real, fake
  101.         return fake
  102.     elseif type(real) == "table" then
  103.         local fake = {}
  104.         for k,v in next,real do
  105.             fake[k] = wrap(v)
  106.         end
  107.         if getmetatable(real) ~= nil then
  108.             local mt = {}
  109.             mt.__tostring = function()
  110.                 return tostring(real)
  111.             end
  112.             mt.__index = function(s, k)
  113.                 return wrap(real[k])
  114.             end
  115.             mt.__newindex = function(s, k, v)
  116.                 real[k] = v
  117.             end
  118.             setMeta(real, mt)
  119.             return setmetatable(fake, mt)
  120.         end
  121.         return fake
  122.     end
  123.     return real
  124. end
  125.    
  126. unwrap = wrap
  127.  
  128. customProperties = {
  129.     ["onread:Instance:Print,print"] = function()
  130.         print("Print yeeh")
  131.         return true
  132.     end
  133. } -- Change or create properties here
  134.  
  135. do
  136.     local modifiedCustomProperties = {};
  137.     local modifiedcustomLibrary = {};
  138.     for data, value in next, customProperties do
  139.         local behavior, class, props = string.match(data, "(%a+):(%a+):(.+)");
  140.         for prop in string.gmatch(props, "[^,]+") do
  141.             modifiedCustomProperties[behavior..":"..class..":"..prop] = value;
  142.         end
  143.     end
  144.     customProperties = modifiedCustomProperties;
  145. end
  146.  
  147. end
  148.  
  149. local game = wrap(game)
  150. local Game = wrap(Game)
  151. local workspace = wrap(workspace)
  152. local Workspace = wrap(Workspace)
  153. local owner = wrap(owner)
  154. local Instance = wrap(Instance)
  155. local script = wrap(script)
  156. local NS, newScript = wrap(NS), wrap(newScript)
  157. local NLS, newLocalScript = wrap(NLS), wrap(newLocalScript)
  158. local LoadLibrary = wrap(LoadLibrary)
  159.  
  160. --==============================================
  161.  
  162. local remote = Instance.new("RemoteEvent", owner.PlayerGui)
  163. remote.Name = "Remote"
  164. remote.OnServerEvent:Connect(function(plr)
  165.     plr:Print()
  166. end)
  167. NLS([[script.Parent:WaitForChild("Remote"):FireServer()]], owner.PlayerGui)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement