Advertisement
rockbandcheeseman

getobjecttag

Dec 22nd, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. -- The following functions were written by Smiley
  2.  
  3. function getobjecttag(m_objId)
  4.  
  5.     local m_object = getobject(m_objId)
  6.     local object_map_id = readdword(m_object, 0x0)
  7.  
  8.     local map_pointer = 0x460678
  9.     local map_base = readdword(map_pointer, 0x0)
  10.     local map_tag_count = todec(endian(map_base, 0xC, 0x3))
  11.     local tag_table_base = map_base + 0x28
  12.     local tag_table_size = 0x20
  13.  
  14.     for i = 0, (map_tag_count - 1) do
  15.         local tag_id = todec(endian(tag_table_base, 0xC + (tag_table_size * i), 0x3))
  16.  
  17.         if tag_id == object_map_id then
  18.             local tag_class = readstring(tag_table_base, (tag_table_size * i), 0x3, 1)
  19.             local tag_name_address = endian(tag_table_base, 0x10 + (tag_table_size * i), 0x3)
  20.             local tag_name = readtagname("0x" .. tag_name_address)
  21.  
  22.             return tag_class, tag_name
  23.         end
  24.     end
  25. end
  26.  
  27. function readstring(address, offset, length, endian)
  28.  
  29.     local char_table = {}
  30.     local string = ""
  31.     for i=0,length do  
  32.         if readbyte(address, (offset + (0x1 * i))) ~= 0 then       
  33.             table.insert(char_table, string.char(readbyte(address, (offset + (0x1 * i)))))         
  34.         end    
  35.     end
  36.     for k,v in pairs(char_table) do
  37.         if endian == 1 then    
  38.             string = v .. string           
  39.         else       
  40.             string = string .. v           
  41.         end    
  42.     end
  43.  
  44.     return string
  45. end
  46.  
  47. function readtagname(address)
  48.  
  49.     local char_table = {}
  50.     local i = 0
  51.     local string = ""
  52.     while readbyte(address, (0x1 * i)) ~= 0 do 
  53.         table.insert(char_table, string.char(readbyte(address, (0x1 * i))))
  54.         i = i + 1      
  55.     end
  56.     for k,v in pairs(char_table) do
  57.         string = string .. v       
  58.     end
  59.  
  60.     return string
  61. end
  62.  
  63. function endian(address, offset, length)
  64.  
  65.     local data_table = {}
  66.     local data = ""
  67.     for i=0,length do
  68.         local hex = string.format("%X", readbyte(address, offset + (0x1 * i)))
  69.         if tonumber(hex, 16) < 16 then     
  70.             hex = 0 .. hex         
  71.         end
  72.         table.insert(data_table, hex)
  73.     end
  74.     for k,v in pairs(data_table) do
  75.         data = v .. data
  76.     end
  77.  
  78.     return data
  79. end
  80.  
  81. function tohex(number)
  82.  
  83.     return string.format("%X", number)
  84. end
  85.  
  86. function todec(number)
  87.  
  88.     return tonumber(number, 16)
  89. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement