Jump to content
  • 0

Optimizing script - UTF16


Platonic

Question

Hi.

This is regarding a previous post which got posted by accident in the LUA script section while it had to be in Help.

Managed to kind of get the script working. Now it does load the correct addresses and their corresponding names in to the saved list. The only problem im having is that this process is really slow. Its adding the addresses in the saved list one by one for each loop..which is kind of slow. Is there a way to optimize the script in a way that it does the objective (adding the addresses of the table "baseValue" in to the saved list with their corresponding names) faster? Here is the script. 

function skillsGroup()
  if loopSkills <= 1 then
    gg.clearResults()
    gg.setRanges(gg.REGION_ANONYMOUS | gg.REGION_C_ALLOC | gg.REGION_OTHER)
    gg.searchNumber(1000, gg.TYPE_QWORD) 
    a = gg.getResults(1000)
    resultAmount = gg.getResultsCount()
    skills = {}
    baseValue = {}
    loop = 1
    end
    for i, v in ipairs(a) do
      skills[i] = {address = a[loop].address + 0x18, flags = gg.TYPE_QWORD} -- skillIdOffset: 32bit = 0x8 | 64bit = 0x10
      baseValue[i] = {address = a[loop].address + 0x28, flags = gg.TYPE_DOUBLE} --
    end
    gg.clearResults()
    baseValue = gg.getValues(baseValue) -- the table to which i want to past each complete string
    skills = gg.getValues(skills) -- value on these addresses == pointers to string name
    for i, v in ipairs(skills) do
      v.address = v.value 
    end
    skills = gg.getValues(skills) 

    stringLengthFilter = {}

    for i, v in ipairs(skills) do
      stringLengthFilter[i] = {address = v.address + 0x10, flags = gg.TYPE_BYTE} -- value on those addresses == length of the string to be copied
    end
    stringLength = gg.getValues(stringLengthFilter)
    --[[
    stringLength = {}
    for i, v in ipairs(stringLengthFilter) do
      if v.value > 5 and v.value < 80 then
        stringLength[#stringLength + 1] = v
      end
    end
    ]]
    if loop > 1 then
      tester()
    end
  return skills, resultAmount, stringLength
end
skillsGroup()

function tester()
  resultAddress = {}
  for i = 1, 1 do
    resultAddress[#resultAddress + 1] = {address = stringLength[1].address + 2, flags = gg.TYPE_BYTE, value = stringLength[1].value} -- + 2 == start of the first char of the string
    saint = {} 
    for j = 0, resultAddress[1].value * 2 do
      saint[#saint + 1] = {address = resultAddress[1].address + j, flags = gg.TYPE_BYTE}
    end
    saint = gg.getValues(saint)
    finish = {}
    local str = ''
    for i, v in ipairs(saint) do
      str = str .. string.char(v.value & 0xFF)
    end
    finish = {}
    finish[1] = {address = baseValue[i].address, flags = gg.TYPE_DOUBLE, name = str}
    print(finish)
    gg.addListItems(finish)
  end
  loop = loop + 1
  if loop == resultAmount then
    os.exit()
  end
  skillsGroup()
end
tester()

Some help, guidance would be great. 

unknown-7.png

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

7 hours ago, Lover1500 said:

I optimized some codes to speed up. Take care the loops.

string_name.lua 1.9 kB · 3 downloads

Its way faster now, but i don't get it.

I don't see the part where it shows that baseValue matches its corresponding string name. I printed the indexes and they all match but i don't really understand where that happens. 

Even if the indexes match how are the strings on the right addresses?

Link to comment
Share on other sites

Oke wait. Just noticed when printing the (skills) table its order is different then when loaded in the result list. Address order doesn't seem to be a factor if the table isn't like taken from the result list.

The order in the print matches the order of the skills table before value got replaced with address.

{ -- table(3c78713)
    [1] = { -- table(2ce7d50)
        ['address'] = 0x7f75518b3ef0,
        ['flags'] = 32, -- gg.TYPE_QWORD
        ['value'] = 140142013995224,
    },
    [2] = { -- table(7f9eb49)
        ['address'] = 0x7f74d4c4e0c0,
        ['flags'] = 32, -- gg.TYPE_QWORD
        ['value'] = 140145157636096,
    },
    [3] = { -- table(e8f9c4e)
        ['address'] = 0x7f74d4c4e180,
        ['flags'] = 32, -- gg.TYPE_QWORD
        ['value'] = 140145157636096,
    }

 

unknown-10.png

Which then as well equals the order of the baseValue table(i think)

Link to comment
Share on other sites

1 hour ago, Platonic said:

I don't see the part where it shows that baseValue matches its corresponding string name.

You can notice that

The tables of skills, baseValue, id have the same indexes. same indexes as when you did gg.getResults().

And you can notice that I store all string bytes into a table by assigning them with id.

I loop string bytes, convert them into character, and connect them with defined id. Thats where strings match with table baseValue.

 

1 hour ago, Platonic said:

The order in the print matches the order of the skills table before value got replaced with address.

The values of the skills were pointers in the first place. Pointers may point to different places. Note that result list always show you according to lowest to highest addresses. But it was good that we still have the same index as other table to compare.

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.