Advertisement
npSim

tagclass()

May 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. --[[
  2. @param class [Class type] in pd2. e.g WeaponTweakData PlayerManager
  3. @param class_name [String type] label to be used as identification in output. e.g "Class 1" "WeapTweak"
  4. @param serialize_vararg [Boolean type] that enables verbose output of arguments used when a method is called.
  5. @param bypass [Boolean type] that bypasses Lua metatable classes for use with anonymous classes. e.g Used with class = _G
  6. ]]
  7. function tagclass(class, class_name, serialize_vararg, bypass)
  8.     class_name = class_name or tostring(class)
  9.     log("Tagged " .. tostring(class) .. " as " .. tostring(class_name))
  10.     if bypass then
  11.         class = getmetatable(class)
  12.     end
  13.     if type(class) == "table" or bypass then
  14.         for func_name,_ in pairs(class) do
  15.             if type(class[func_name]) == "function" then
  16.                 -- Hooks:PreHook(class, tostring(func_name), tostring(Application:time()), function(...)
  17.                 local old_func = class[func_name]
  18.                 class[func_name] = function(...)
  19.                     local args = table.pack(...)
  20.                     local num_args = args.n
  21.                     local serial = ""
  22.                     if serialize_vararg then
  23.                         -- log("\t"..tostring(num_args-1).." total args!!!")
  24.                         for i=2, num_args, 1 do
  25.                             -- log("\t"..tostring(args[i]))
  26.                             if (i == num_args) then
  27.                                 if type(args[i]) == "string" then
  28.                                     serial = serial .. " \"" .. tostring(args[i]) .. "\""
  29.                                 else
  30.                                     serial = serial .. " " .. tostring(args[i])
  31.                                 end
  32.                             else
  33.                                 if type(args[i]) == "string" then
  34.                                     serial = serial .. " \"" .. tostring(args[i]) .. "\" ,"
  35.                                 else
  36.                                     serial = serial .. " " .. tostring(args[i]) .. " ,"
  37.                                 end
  38.                             end
  39.                         end
  40.                         -- outTree(args)
  41.                     else
  42.                         serial = " "
  43.                     end
  44.                     log("function " .. tostring(class_name) .. " : " .. tostring(func_name) .. " (" .. tostring(serial) .. " )")
  45.                     return old_func(...)
  46.                 end
  47.             end
  48.         end
  49.     else
  50.         log("CLASS is not a TABLE! Use BYPASS!")
  51.     end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement