Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.92 KB | None | 0 0
  1. -- Originally written by Autumn
  2. -- Amended by asd & 3dsboy08
  3.  
  4. -- There's no reason to support Protosmasher, as it doesn't support newcclosure()
  5.  
  6. local enabled = {
  7.     -- Set any of these objects to false to stop logging them
  8.     BindableEvent = false,
  9.     BindableFunction = false,
  10.     RemoteEvent = true,
  11.     RemoteFunction = true,
  12. }
  13.  
  14. local ignore = {
  15.     CharacterSoundEvent = true,
  16.     GetSetting = true,
  17.     GetAwaiting = true,
  18.     GetSelection = true,
  19.     SelectionChange = true,
  20.     empty = true,
  21.     Ping = true,
  22.     UpdatePing = true,
  23.    
  24.     --[[ -- I'd personally recommend keeping this commented out, as game scripts can name their remotes these
  25.     GetSetting = true,
  26.     GetSelection = true,
  27.     SelectionChanged = true,
  28.     GetAwaiting = true
  29.     --]]
  30. }
  31.  
  32. local metatable = assert(getrawmetatable, "needs access to function 'getrawmetatable'")(game)
  33. if setreadonly then
  34.     setreadonly(metatable, false)
  35. end
  36.  
  37. local function CountTable(t)
  38.     local count, key = 0
  39.     repeat
  40.         key = next(t, key)
  41.         if key ~= nil then
  42.             count = count + 1
  43.         end
  44.     until key == nil
  45.     return count
  46. end
  47.  
  48. local PrintTable
  49. local function ParseObject(object, spacing, scope, checkedTables)
  50.     local objectType = type(object)
  51.     if objectType == "string" then
  52.         return spacing .. string.format("%q", object)
  53.     elseif objectType == "nil" then
  54.         return spacing .. "nil"
  55.     elseif objectType == "table" then
  56.         if checkedTables[object] then
  57.             return spacing .. tostring(object) .. " [recursive table]"
  58.         else
  59.             checkedTables[object] = true
  60.             return spacing .. PrintTable(object, scope + 1, checkedTables)
  61.         end
  62.     elseif objectType == "userdata" then
  63.         if typeof(object) == "userdata" then
  64.             return spacing .. "userdata"
  65.         else
  66.             return spacing .. tostring(object)
  67.         end
  68.     else -- userdata, function, boolean, thread, number
  69.         return spacing .. tostring(object)
  70.     end
  71. end
  72. function PrintTable(t, scope, checkedTables)
  73.     local mt = getrawmetatable(t)
  74.     local backup = {}
  75.     if mt and mt ~= t then
  76.         for i, v in pairs(mt) do
  77.             rawset(backup, i, v)
  78.             rawset(mt, i, nil)
  79.         end
  80.     end
  81.  
  82.     checkedTables = checkedTables or {}
  83.     scope = scope or 1
  84.     local result = (checkedTables and "{" or "") .. "\n"
  85.     local spacing = string.rep("\t", scope)
  86.     local function parse(index, value)
  87.         result = result .. ParseObject(index, spacing, scope, checkedTables) .. " : " .. ParseObject(value, "", scope, checkedTables) .. "\n"
  88.     end
  89.     if CountTable(t) ~= #t then
  90.         table.foreach(t, parse) -- I'm very aware this is a deprecated function
  91.     else
  92.         for index = 1, select("#", unpack(t)) do
  93.             parse(index, t[index])
  94.         end
  95.     end
  96.  
  97.     if mt and mt ~= t then
  98.         for i, v in pairs(mt) do
  99.             rawset(mt, rawget(backup, i), v)
  100.         end
  101.     end
  102.  
  103.     return result .. string.sub(spacing, 1, #spacing - 1) .. (checkedTables and "}" or "")
  104. end
  105.  
  106. local methods = {
  107.     BindableEvent = "Fire",
  108.     BindableFunction = "Invoke",
  109.     RemoteEvent = "FireServer",
  110.     RemoteFunction = "InvokeServer"
  111. }
  112.  
  113. local __namecall = __namecall or metatable.__namecall
  114. local __index = __index or metatable.__index
  115. if getgenv then
  116.     if removeSpy then
  117.         removeSpy()
  118.     end
  119.     getgenv().__namecall = __namecall
  120.     getgenv().__index = __index
  121.     getgenv().removeSpy = function()
  122.         getgenv().removeSpy = nil
  123.         metatable.__namecall = __namecall
  124.         metatable.__index = __index
  125.     end
  126. end
  127.  
  128. local function RemoteCallback(self, ...)
  129.     if typeof(self) ~= "Instance" then
  130.         return error(select(2, pcall(__index, self))) -- magic
  131.     end
  132.     local arguments = {...}    
  133.     local result = {}
  134.     local callerScript = rawget(getfenv(0), "script")
  135.     callerScript = typeof(callerScript) == "Instance" and callerScript or nil
  136.     print(string.format(
  137.         "%s called!\nFrom Script: %s\nPath: %s\nArguments: %s\nReturn: %s",
  138.         self.ClassName,
  139.         tostring(not callerScript and "Not Found" or callerScript:GetFullName()),
  140.         (not self.Parent and "[NIL]: " or "") .. self:GetFullName(),
  141.         CountTable(arguments) == 0 and "None!" or PrintTable(arguments),
  142.         CountTable(result) == 0 and "None!" or PrintTable(result)
  143.     ))
  144.     return unpack({methods[self.ClassName](self, ...)})
  145. end
  146. RemoteCallback = newcclosure(RemoteCallback)
  147.  
  148. local function IsAuthorized(self, index)
  149.     return (index == "Fire" or index == "Invoke" or index == "FireServer" or index == "InvokeServer") and (enabled[self.ClassName] and not ignore[self.Name])
  150. end
  151.  
  152. metatable.__namecall = function(self, ...)
  153.     local args = {...}
  154.     local method = table.remove(args)
  155.     if IsAuthorized(self, method) then
  156.         return RemoteCallback(self, unpack(args))
  157.     end
  158.     return __namecall(self, ...)
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement