Advertisement
LuckyScripters

Custom functions

Oct 5th, 2024 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.50 KB | None | 0 0
  1. -- Roblox -- Universal -- Custom functions
  2. -- This is only for exploits
  3. -- Put the script in autoexec folder
  4.  
  5. local LogService = game:GetService("LogService")
  6. local ScriptContext = game:GetService("ScriptContext")
  7.  
  8. local oldIndex = nil
  9. local oldNamecall = nil
  10.  
  11. local protectedInstances = {}
  12.  
  13. local function modifyConstantsFromClosure(closure : (...any) -> any, constantType : string, constantToChange : any, newConstant : any)
  14.     for index, constant in getconstants(closure) do
  15.         if typeof(constant) == constantType and constant == constantToChange then
  16.             setconstant(closure, index, newConstant)
  17.         end
  18.     end
  19. end
  20.  
  21. local function modifyConstantsFromScript(script : LocalScript | ModuleScript, constantType : string, constantToChange : any, newConstant : any)
  22.     local closure = getscriptclosure(script)
  23.     for index, constant in getconstants(closure) do
  24.         if typeof(constant) == constantType and constant == constantToChange then
  25.             setconstant(closure, index, newConstant)
  26.         end
  27.     end
  28. end
  29.  
  30. local function displayConstantsFromClosure(closure : (...any) -> any)
  31.     print("------ Constant Display ------")
  32.     for index, constant in getconstants(closure) do
  33.         if typeof(constant) == "function" then
  34.             print(index, debug.getinfo(constant).name .. " " .. "(function)")
  35.             continue
  36.         end
  37.         print(index, constant)
  38.     end
  39. end
  40.  
  41. local function displayConstantsFromScript(script : LocalScript | ModuleScript)
  42.     print("------ Constant Display ------")
  43.     local closure = getscriptclosure(script)
  44.     for index, constant in getconstants(closure) do
  45.         if typeof(constant) == "function" then
  46.             print(index, debug.getinfo(constant).name .. " " .. "(function)")
  47.             continue
  48.         end
  49.         print(index, constant)
  50.     end
  51. end
  52.  
  53. local function modifyUpValuesFromClosure(closure : (...any) -> any, upValueType : string, upValueToChange : any, newUpValue : any)
  54.     for index, upValue in getupvalues(closure) do
  55.         if typeof(upValue) == upValueType and upValue == upValueToChange then
  56.             setupvalue(closure, index, newUpValue)
  57.         end
  58.     end
  59. end
  60.  
  61. local function modifyUpValuesFromScript(script : LocalScript | ModuleScript,  upValueType : string, upValueToChange : any, newUpValue : any)
  62.     local closure = getscriptclosure(script)
  63.     for index, upValue in getupvalues(closure) do
  64.         if typeof(upValue) == upValueType and upValue == upValueToChange then
  65.             setupvalue(closure, index, newUpValue)
  66.         end
  67.     end
  68. end
  69.  
  70. local function displayUpValuesFromClosure(closure : (...any) -> any)
  71.     print("------ UpValue Display ------")
  72.     for index, upValue in getupvalues(closure) do
  73.         if typeof(upValue) == "function" then
  74.             print(index, debug.getinfo(upValue).name .. " " .. "(function)")
  75.             continue
  76.         end
  77.         print(index, upValue)
  78.     end
  79. end
  80.  
  81. local function displayUpValuesFromScript(script : LocalScript | ModuleScript)
  82.     print("------ UpValue Display ------")
  83.     local closure = getscriptclosure(script)
  84.     for index, upValue in getupvalues(closure) do
  85.         if typeof(upValue) == "function" then
  86.             print(index, debug.getinfo(upValue).name .. " " .. "(function)")
  87.             continue
  88.         end
  89.         print(index, upValue)
  90.     end
  91. end
  92.  
  93. local function secureCall(closure : (...any) -> any, script : Instance, ... : any)
  94.     local resultCall = nil
  95.     local environment = getfenv(1)
  96.     local oldTraceback = nil
  97.     local oldDebugInfo = clonefunction(debug.info)
  98.     local securityContext = getthreadcontext()
  99.     local registeryEnvironment = getrenv()
  100.     oldTraceback = hookfunction(debug.traceback, function(... : any)
  101.         local info = string.sub(getinfo(1).source, 2)
  102.         local traceback = oldTraceback(...)
  103.         if string.find(traceback, info, 0, true) then
  104.             return script:GetFullName() .. ":" .. "0" .. "\n" .. script:GetFullName() .. ":" .. "0"
  105.         end
  106.         return traceback
  107.     end)
  108.     hookfunction(debug.info, function(... : any)
  109.         local arguments = table.pack(...)
  110.         if typeof(arguments[1]) ~= "number" then
  111.             return oldDebugInfo(...)
  112.         end
  113.         if string.find(arguments[2], "s", 0, true) then
  114.             local info = string.sub(getinfo(1).source, 2)
  115.             local functionInfo = oldDebugInfo(closure, arguments[2])
  116.             local result, remplacements = string.gsub(functionInfo, info, script:GetFullName(), math.huge)
  117.             return result
  118.         end
  119.         return oldDebugInfo(...)
  120.     end)
  121.     setthreadcontext(2)
  122.     setfenv(1, setmetatable({script = script}, {
  123.         __index = registeryEnvironment
  124.     }))
  125.     resultCall = closure(...)
  126.     setfenv(1, environment)
  127.     setthreadcontext(securityContext)
  128.     debug.info = oldDebugInfo
  129.     return resultCall
  130. end
  131.  
  132. while not game:IsLoaded() do
  133.     task.wait()
  134. end
  135.  
  136. for index, signal in {LogService.MessageOut, ScriptContext.Error} do
  137.     for index, connection in getconnections(signal) do
  138.         connection:Disable()
  139.     end
  140. end
  141.  
  142. oldIndex = hookmetamethod(game, "__index", newcclosure(function(self : Instance, index : string)
  143.     if checkcaller() then
  144.         return oldIndex(self, index)
  145.     end
  146.     if table.find(protectedInstances, self, 1) then
  147.         return nil
  148.     end
  149.     return oldIndex(self, index)
  150. end))
  151.  
  152. oldNamecall = hookmetamethod(game, "__namecall", newcclosure(function(self : Instance, ... : any)
  153.     if checkcaller() then
  154.         return oldNamecall(self, ...)
  155.     end
  156.     local result = oldNamecall(self, ...)
  157.     local namecallmethod = getnamecallmethod()
  158.     if namecallmethod == "WaitForChild" or namecallmethod == "FindFirstChild" then
  159.         if table.find(protectedInstances, result, 1) then
  160.             result = nil
  161.         end
  162.     elseif namecallmethod == "GetChildren" or namecallmethod == "GetDescendants" then
  163.         if typeof(result) == "table" then
  164.             for index, value in result do
  165.                 if table.find(protectedInstances, value, 1) then
  166.                     table.remove(result, index)
  167.                 end
  168.             end
  169.         end
  170.     else
  171.         return oldNamecall(self, ...)
  172.     end
  173.     return result
  174. end))
  175.  
  176. getgenv().__customEnvironment = {
  177.     ["UpValues"] = {
  178.         Modifier = {
  179.             Script = modifyUpValuesFromScript,
  180.             Closure = modifyUpValuesFromClosure
  181.         },
  182.         Displayer = {
  183.             Script = displayUpValuesFromScript,
  184.             Closure = displayUpValuesFromClosure
  185.         }
  186.     },
  187.     ["Constants"] = {
  188.         Modifier = {
  189.             Script = modifyConstantsFromScript,
  190.             Closure = modifyConstantsFromClosure
  191.         },
  192.         Displayer = {
  193.             Script = displayConstantsFromScript,
  194.             Closure = displayConstantsFromClosure
  195.         }
  196.     },
  197.     ["Instances"] = {
  198.         Protect = function(instance : Instance)
  199.             if not table.find(protectedInstances, instance, 1) then
  200.                 table.insert(protectedInstances, instance)
  201.             end
  202.         end,
  203.         Unprotect = function(instance : Instance)
  204.             if table.find(protectedInstances, instance, 1) then
  205.                 table.remove(protectedInstances, table.find(protectedInstances, instance, 1))
  206.             end
  207.         end
  208.     },
  209.     SecureCall = secureCall
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement