Jump to content
  • 0

Lua scripting how to distinguish between dword and float value in group search (1 dword 1 float)?


luanoob

Question

funcion file_exists(name)
  local f = io.open(name,"r")
  if f~=nil then
    io.close(f)
    return true
  else
    return false
  end
end

local gg = gg
gg.clearResults()

past_addresses_filename = "/storage/emulated/0/Notes/past-data.txt"
local past_addresses = {}
if file_exists(past_addresses_filename) then
  for line in io.lines(past_addresses_filename) do
    s = line:gsub('%\n','')    
    past_addresses[s] = 1
  end
end 
   
gg.searchNumber('1,000,000,000D;4106~4108::8', gg.TYPE_FLOAT)
local final_table = {}
local table = gg.getResults(500)
for i = 1, #table do  
  if past_addresses[table[i]['address']] ~= nil then goto continue end
  v = table[i]

  if (v.value > 999999999 and v.value < 1000000001) then
    final_table[n] = table[i]
    final_table[n]['value'] = 16
    final_table[n]['freeze'] = true
    past_addresses[v.address] = 1
  end
  if (v.value > 3016 and v.value < 3018) then
    final_table[n] = table[i]
    final_table[n]['value'] = 1000000
    final_table[n]['freeze'] = true
    past_addresses[v.address] = 1
  end
  ::continue::
end
gg.setValues(final_table)
gg.addListItems(final_table)

f = io.open(past_addresses_filename,"w")
for key,value in final_table do
  f:write(tostring(key) .. '\n')
end
io.close(f)

So basically, I have to search for this group: '1,000,000,000D;4106~4108::8' with using the float type in gg.searchNumber(). It's easy to see that: when i%2==1, v.value in range (10^9 -1 ~ 10^9 + 1); when i%2==0, v.value in range(3016, 3018).

However, since the 1st value is a dword, it might get become a completely different number when parsed as a float. 

For example, number 0x000002A7 = 679 (dword) = 9.51481657276550791157212387054E-43 (float).

So in the above code, how do I ensure that 

if (v.value > 999999999 and v.value < 1000000001)

if (v.value > 3016 and v.value < 3018)

are parsing v.value as dword in the 1st one, then as float in the second one? 

In another language, I can do something like, what's the equivalent for Lua?

if (dword.fromBytes(v.value.toByteArray()) > ...)

Thank you

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Processing results of such group search doesn't require checking result's values at all. Since there is exactly one dword result and one float result in each group, it is enough to check type of the result to distinguish between them: 

for i = 1, #table do  
  if past_addresses[table[i]['address']] ~= nil then goto continue end
  v = table[i]

  if v.flags == gg.TYPE_DWORD then
    -- Process dword result
  elseif v.flags == gg.TYPE_FLOAT then
    -- Process float result
  end
  past_addresses[v.address] = 1
  
  ::continue::
end
Link to comment
Share on other sites

49 minutes ago, CmP said:

Processing results of such group search doesn't require checking result's values at all. Since there is exactly one dword result and one float result in each group, it is enough to check type of the result to distinguish between them: 


for i = 1, #table do  
  if past_addresses[table[i]['address']] ~= nil then goto continue end
  v = table[i]

  if v.flags == gg.TYPE_DWORD then
    -- Process dword result
  elseif v.flags == gg.TYPE_FLOAT then
    -- Process float result
  end
  past_addresses[v.address] = 1
  
  ::continue::
end

Thanks! I didn't see the ".flags" attribute.

I have another question, is the "search address" function limited to the chosen program's memory space? I have a problem where frozen addresses in the saved list (tab with the save symbol in game guardian) cannot be found using the address search function. I need to read its value, and change/unfreeze it if necessary.

In short, if I find an address 0x12345678, but some time later that address is freed and is no longer used by/belong to the program, can I still use the "search address" function to read its value it? If not, which lua function should I use to directly read and change that address (such as unfreezing it)?

Edit: never mind I found it, it's setValue and getValue. For anyone reading, note that the ".address" attribute in those functions must be of type number, so use tonumber(x) or tonumber(x,16). Also remember to use both setValues and addListItems()

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.