Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Register selected addresses as their descriptions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
ymiu
Cheater
Reputation: 0

Joined: 16 Dec 2018
Posts: 41

PostPosted: Sun Jan 06, 2019 3:46 pm    Post subject: Register selected addresses as their descriptions Reply with quote

I'd like to be able to select one or more pointer addresses in my table and register symbols for them based on their descriptions. However, I'm getting errors while trying to access the number of records returned by AddressList.getSelectedRecords(). The wiki says it returns a "table", and links to the MemoryRecord object, but I'm not finding any examples of folks using this function in their scripts.

Code:
function register_selected_addresses()
  -- attempts to register symbols for each selected address.
  -- the symbol name will be the description

  if AddressList.SelCount >= 1 then
    local sList = AddressList.getSelectedRecords()
    local desc = 'default'
    local addr = 0x0
    for i = 0, sList.Count - 1 do -- ERROR: this attempts to perform arithmetic on a nil value (field 'Count')
      if sList[i].Type == vtPointer then -- vtPointer=12
        desc = sList[i].Description
        addr = sList[i].CurrentAddress -- get what it points to?
        unregisterSymbol(desc) -- no errors even if not registered
        registerSymbol(desc, addr) -- errors if already registered
      end
    end
  end
end


Any ideas? Thanks!

Edit:

Apparently I don't know what a "table" is in LUA. Unfortunately, after reading the LUA Tables Tutorial, I still don't really know how this works.

Code:
local testList = AddressList.getSelectedRecords()
for key,value in pairs(testList) do print(key, value) end

Yields output: 13 0C02E9C0

It's saying I'm highlighting the 13th record in my table, but there is no obvious relation between that entry and the hex that was returned above.

Edit 2:

Trial and error. That interactive LUA terminal is great. I think I figured this out:

Code:
function register_selected_addresses()
  -- attempts to register symbols for each selected address.
  -- the symbol name will be the description

  if AddressList.SelCount >= 1 then
    local sList = AddressList.getSelectedRecords()
    local desc = 'default'
    local addr = 0x0
    for i,mr in pairs(sList) do
      if sList[i].OffsetCount > 0 then
        desc = sList[i].Description
        addr = sList[i].CurrentAddress -- get what it points to?
        unregisterSymbol(desc) -- no errors even if not registered
        registerSymbol(desc, addr) -- errors if already registered
      end
    end
  end
end
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Wed Jan 09, 2019 7:53 am    Post subject: Reply with quote

Congrats on working it out!

yeah, it'd almost be more helpful if CE/lua printed the classname rather than the address of the userdata eg.
Code:
local testList = AddressList.getSelectedRecords()
for key,value in pairs(testList) do print(key, value, value.ClassName, value.ID, value.index) end
might print something like
Code:
2 022911C0 TMemoryRecord 0 1
4 02291340 TMemoryRecord 1 3
I believe that you'll find the key will always be off by 1 from the index since lua tables start at 1 and CE arrays start at 0 ... though, now that I think about it with pairs there's probably no technical reason it couldn't start at 0 (iirc ipairs always starts at 1 and stops at the first nil/empty index)... oh well, not like the key really matters when you get the memory record directly and can get whatever value you want from it directly

Of course, in lua userdata doesn't have to be something that has a classname property so I can understand the default, but it pretty much always does in CE.

Quote:
addr = sList[i].CurrentAddress -- get what it points to?
pretty much, particularly with pointers the address can change at any time and rather than making you read the pointer-offset chain yourself CE can just give you the final address it's currently showing in the window.
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Wed Jan 09, 2019 7:58 am    Post subject: Reply with quote

Quote:

yeah, it'd almost be more helpful if CE/lua printed the classname rather than the address of the userdata eg.

that's what "return" does

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites