Advertisement
pa1nx9

ROBLOX ADVANCED DECOMPILER – SEPTEMBER 2021

Sep 28th, 2021
3,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. local _decompile = assert(decompile or syn_decompile)
  2. local _getscriptclosure = assert(getscriptclosure)
  3. local _getrenv = assert(getrenv or syn_getrenv)
  4. local _getgenv = assert(getgenv or syn_getgenv)
  5. local _getsenv = assert(getsenv or syn_getsenv)
  6. local _getmenv = assert(getmenv or syn_getmenv)
  7. local _getprotos = assert(getprotos or debug.getprotos)
  8. local _getconstants = assert(getconstants or debug.getconstants)
  9. local _getinfo = debug.info
  10. local stringsplit = string.split
  11. local stringmatch = string.match
  12. local stringfind = string.find
  13. local stringgmatch = string.gmatch
  14. local stringgsub = string.gsub
  15. local tableclear = table.clear
  16. local tableinsert = table.insert
  17. local tableremove = table.remove
  18.  
  19. local IsA = game.IsA
  20.  
  21. local GetFuncs
  22. do
  23. local Funcs = {}
  24. function GetFuncs(Closure, Globals)
  25. local Protos = _getprotos(Closure)
  26. if Protos and #Protos > 0 then
  27. for Index, Proto in ipairs(_getprotos(Closure)) do
  28. local Name, Args, VarArg = _getinfo(Proto, "na")
  29. local Protos = _getprotos(Proto)
  30. if #Name > 0 and not Globals[Name] then -- we dont need globals
  31. tableinsert(Funcs, {Name, Args, VarArg, _getconstants(Proto)})
  32. end
  33. if Protos and #Protos > 0 then
  34. GetFuncs(Proto, Globals)
  35. end
  36. end
  37. end
  38. return Funcs
  39. end
  40. end
  41.  
  42. _getgenv().decompile = (function(Script, ...)
  43. if typeof(Script) == "Instance" then
  44. local isModuleScript = IsA(Script, "ModuleScript")
  45. if isModuleScript or (IsA(Script, "LocalScript") and not Script.Disabled) then
  46. local Success, Globals = pcall(((isModuleScript and require) or _getsenv), Script)
  47. local Closure = _getscriptclosure(Script)
  48. if isModuleScript and Success then
  49. if type(Globals) ~= "table" then
  50. Success, Globals = pcall(_getmenv, Script)
  51. end
  52. end
  53. if Success and Closure then
  54. local Source = _decompile(Script, ...)
  55. if Source then
  56. do -- local function names
  57. local Funcs = GetFuncs(Closure, Globals)
  58. for Match in stringgmatch(Source, "function %w+%.%w+%b()") do
  59. local Name = stringmatch(Match, "%.(%w+)")
  60. for Iteration = 1, #Funcs do
  61. if Funcs[Iteration][1] == Name then
  62. tableremove(Funcs, Iteration)
  63. break
  64. end
  65. end
  66. end
  67. for Proto in stringgmatch(Source, "%s+local function %l%d+%b()") do
  68. local Spaces = stringmatch(Proto, "%s+")
  69. local GeneratedName = stringmatch(Proto, "%l%d+")
  70. local ArgPattern = stringmatch(Proto, "%b()")
  71. local _, Args = stringgsub(ArgPattern, "p%d+", "")
  72. local IsVarArg = stringfind(ArgPattern, "...", 1, true) ~= nil
  73. local ProtoClosure = stringmatch(Source, "local function " .. GeneratedName .. "%b().+" .. Spaces .. "end;") or ""
  74. ProtoClosure = stringgsub(ProtoClosure, "local function %l%d+%b().+end;$", function(Match)
  75. local Split = stringsplit(Match, Spaces .. "end;\n")
  76. local NumSplit = #Split
  77. if NumSplit > 1 then
  78. for Index = 1, NumSplit do
  79. local SplitI = Split[Index]
  80. if stringmatch(SplitI, GeneratedName) then
  81. return SplitI .. Spaces .. "end;"
  82. end
  83. end
  84. end
  85. return Match
  86. end)
  87. for Iteration = 1, #Funcs do
  88. local Func = Funcs[Iteration]
  89. local Name = Func[1]
  90. if Args == Func[2] then
  91. if IsVarArg == Func[3] then
  92. local Constants = Func[4]
  93. local HasConstants = true
  94. for Index = 1, #Constants do
  95. local Constant = Constants[Index]
  96. if type(Constant) == "string" then
  97. if not stringfind(ProtoClosure, Constant, 1, true) then
  98. HasConstants = false
  99. break
  100. end
  101. end
  102. end
  103. if HasConstants then
  104. tableremove(Funcs, Iteration)
  105. Source = stringgsub(Source, GeneratedName, Name)
  106. break
  107. else
  108. continue
  109. end
  110. end
  111. end
  112. end
  113. end
  114. tableclear(Funcs)
  115. end
  116. return Source
  117. end
  118. end
  119. end
  120. end
  121. return _decompile(Script, ...)
  122. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement