Advertisement
XZTablets

Untitled

Aug 2nd, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. --[[
  2. ██▀███ ▓█████ ▓█████▄
  3. ▓██ ▒ ██▒▓█ ▀ ▒██▀ ██▌
  4. ▓██ ░▄█ ▒▒███ ░██ █▌
  5. ▒██▀▀█▄ ▒▓█ ▄ ░▓█▄ ▌
  6. ░██▓ ▒██▒░▒████▒░▒████▓
  7. ░ ▒▓ ░▒▓░░░ ▒░ ░ ▒▒▓ ▒
  8. ░▒ ░ ▒░ ░ ░ ░ ░ ▒ ▒
  9. ░░ ░ ░ ░ ░ ░
  10. ░ ░ ░ ░
  11. ]]
  12.  
  13. -- All credits to red development.
  14. -- Members: KowalskiFX, 0x59, RoboMat
  15. local dumper = {};
  16.  
  17. function dumper:GetTabChar(count)
  18. local c = ''
  19. for i = 1, count do
  20. c = c .. '\t';
  21. end
  22. return c;
  23. end
  24.  
  25. function dumper:CheckGlobal(pGlobal, tab, tString, count)
  26. if (tab == nil) then tab = _G; end;
  27. if (count == nil) then count = 0; end;
  28. if (tString == nil) then tString = ""; end;
  29.  
  30. if (count ~= 2) then
  31. count = count + 1;
  32. local cache = {};
  33. for name, val in pairs(tab) do
  34. if (type(val) == "table") then
  35. cache[name] = val;
  36. end
  37. if (val == pGlobal) then
  38. tString = tString .. name;
  39. return tString;
  40. end
  41. end
  42.  
  43. for name, val in pairs(cache) do
  44. local r = dumper:CheckGlobal(pGlobal, val, tString, count);
  45. if (r ~= false) then
  46. tString = tString .. name .. "." .. r;
  47. return tString
  48. end
  49. end
  50. end
  51.  
  52. --[[
  53. function innerCheck(t)
  54. for name,val in pairs(t) do
  55. if (val == pGlobal) then
  56. return name;
  57. end
  58. if (type(val) == "table") then
  59. if (val ~= tab) then
  60. return innerCheck(val);
  61. end
  62. end
  63. end
  64. end
  65. --]]
  66.  
  67. return false;
  68. end
  69.  
  70. function dumper:conv_to_str(int)
  71. local hexwheel = "0123456789ABCDEF"
  72. local hexstr = ""
  73. int = int + 1
  74. while int > 0 do
  75. local mod = math.fmod(int, 16)
  76. hexstr = string.sub(hexwheel, mod+1, mod+1) .. hexstr
  77. int = math.floor(int/16)
  78. end
  79. if hexstr == "" then return "0x0" end
  80. return "0x" .. hexstr
  81. end
  82.  
  83. function dumper:SerializeName(name)
  84. if (type(name) == "string") then
  85. return "[\"" .. name .. "\"]";
  86. elseif (type(name) == "number") then
  87. return "[" .. name .. "]";
  88. end
  89. end
  90.  
  91. function dumper:SerializeValue(name, value, index)
  92. if (type(value) == "string") then
  93. if (index == name) then
  94. return "\"" .. value .. "\"";
  95. else
  96. return dumper:SerializeName(name) .. " = " .. "\"" .. value .. "\"";
  97. end
  98. elseif (type(value) == "number") then
  99. if value > 10000 then value = dumper:conv_to_str(value) end
  100. if (index == name) then
  101. return tostring(value);
  102. else
  103. return dumper:SerializeName(name) .. " = " .. tostring(value);
  104. end
  105. elseif (type(value) == "boolean") then
  106. if (index == name) then
  107. return tostring(value);
  108. else
  109. return dumper:SerializeName(name) .. " = " .. tostring(value);
  110. end
  111. elseif (type(value) == "table") then
  112. if (index == name) then
  113. return tostring(value);
  114. else
  115. return dumper:SerializeName(name) .. " = " .. tostring(value);
  116. end
  117. elseif (type(value) == "userdata") then
  118. if (index == name) then
  119. if (not dumper:CheckGlobal(value)) then
  120. return "\"" .. tostring(value) .. "\"";
  121. else
  122. return dumper:CheckGlobal(value);
  123. end
  124. else
  125. if (not dumper:CheckGlobal(value)) then
  126. return dumper:SerializeName(name) .. " = " .. "\"" .. tostring(value) .. "\""
  127. else
  128. return dumper:SerializeName(name) .. " = " .. dumper:CheckGlobal(value);
  129. end
  130. end
  131. elseif (type(value) == "function") then
  132. if (index == name) then
  133. if (not dumper:CheckGlobal(value)) then
  134. return "\"" .. tostring(value) .. "\"";
  135. else
  136. return dumper:CheckGlobal(value);
  137. end
  138. else
  139. if (not dumper:CheckGlobal(value)) then
  140. return dumper:SerializeName(name) .. " = " .. "\"" .. tostring(value) .. "\"";
  141. else
  142. return dumper:SerializeName(name) .. " = " .. dumper:CheckGlobal(value);
  143. end
  144. end
  145. end
  146.  
  147. print('unknown_value type: ' .. type(value))
  148. return "unknown_value";
  149. end
  150.  
  151. function dumper:DumpTable(gTab, mode, recursive)
  152. if (gTab == nil) then gTab = {}; end;
  153. if (recursive == nil) then recursive = true; end;
  154. local deserialized = "";
  155. local gTabScanned = false;
  156. local tIndex = -1;
  157.  
  158. if (mode == nil) then mode = 0; end;
  159.  
  160. local function innerDump(tab, key)
  161. if (key == nil) then key = ""; end;
  162. if (tIndex > 20) then
  163. return
  164. end
  165. tIndex = tIndex + 1;
  166. if (key == "lineinfo") then
  167. deserialized = deserialized .. dumper:GetTabChar(tIndex) .. "[\"" .. key .. "\"] = { --[[ blacklisted key ]] }\n";
  168. tIndex = tIndex - 1;
  169. return
  170. end
  171. if (key ~= "") then
  172. deserialized = deserialized .. dumper:GetTabChar(tIndex) .. "[\"" .. key .. "\"] = {\n";
  173. else
  174. deserialized = deserialized .. dumper:GetTabChar(tIndex) .. "{\n";
  175. end
  176. local currIndex = 0;
  177. if (tab == gTab) then
  178. if (gTabScanned) then
  179. deserialized = deserialized .. dumper:GetTabChar(tIndex+1) .. "{...}\n";
  180. else
  181. gTabScanned = true;
  182. end
  183. end
  184.  
  185. for name,val in pairs(tab) do
  186. currIndex = currIndex + 1;
  187. if (type(val) == "table") then
  188. if (recursive == true) then
  189. if (val ~= gTab) then
  190. innerDump(val, name);
  191. else
  192. deserialized = deserialized .. dumper:GetTabChar(tIndex+1) .. "{...}\n";
  193. end
  194. else
  195. deserialized = deserialized .. dumper:GetTabChar(tIndex+1) .. dumper:SerializeValue(name, val, currIndex) .. "\n";
  196. end
  197. else
  198. if (currIndex == #tab) then
  199. if (mode == 1) then
  200. deserialized = deserialized .. dumper:GetTabChar(tIndex+1) .. dumper:SerializeValue(name, val, currIndex) .. "\t\t-- " .. tostring(val) .. "\n";
  201. else
  202. deserialized = deserialized .. dumper:GetTabChar(tIndex+1) .. dumper:SerializeValue(name, val, currIndex) .. "\n";
  203. end
  204. else
  205. if (mode == 1) then
  206. deserialized = deserialized .. dumper:GetTabChar(tIndex+1) .. dumper:SerializeValue(name, val, currIndex) .. ",\t\t-- " .. tostring(val) .. "\n";
  207. else
  208. deserialized = deserialized .. dumper:GetTabChar(tIndex+1) .. dumper:SerializeValue(name, val, currIndex) .. ",\n";
  209. end
  210. end
  211. end
  212. end
  213.  
  214. deserialized = deserialized .. dumper:GetTabChar(tIndex) .. "}\n"
  215. tIndex = tIndex - 1;
  216. end
  217.  
  218. innerDump(gTab);
  219.  
  220. return deserialized;
  221. end
  222.  
  223. return dumper;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement