jgoemat Master Cheater Reputation: 22
Joined: 25 Sep 2011 Posts: 252
|
Posted: Mon Dec 12, 2022 2:08 pm Post subject: Creating memory records with LUA in table entry |
|
|
Just wanted to share some code I wrote so I can find it again with google. This is for the game Raft and exists as a AA script that is really LUA. When enabled, it removed any children of the table entry and uses mono functions to find a static address where the list of quest items is stored, then it creates a memory record for the count of each of the quest items as a child.
Code: |
[enable]
{$lua}
if syntaxcheck then return end
-- delete any existing children
-- https://www.cheatengine.org/forum/viewtopic.php?t=613236&sid=6cbc3f31792dc6aab3c32eb7668b12f0
-- https://wiki.cheatengine.org/index.php?title=Lua:Class:MemoryRecord
while (memrec.Count > 0) do
memoryrecord_delete(memrec.Child[memrec.Count - 1])
end
local klass = mono_findClass('', 'QuestItemManager')
local base = mono_class_getStaticFieldAddress(nil, klass)
local queryItems = readQword(base + 0x18) -- static field offset
local count = readInteger(queryItems + 0x18) -- offset of Array.Count
local getQuestItem = function(index)
local addr = readQword(queryItems + 0x20 + (0x08 * index))
-- print("Item at index "..tostring(index).." is at "..string.format("%X", addr)) -- good!
local countAddress = addr + 0x18 -- offset of QuestItem.itemCount
local soQuestItem = readQword(addr + 0x10) -- offset of QuestItem.SOQuestItem
local displayTerm = readQword(soQuestItem + 0x20) -- offset of SOQuestItem.displayTerm
if displayTerm == nil or displayTerm < 100 then return nil end
local length = readInteger(displayTerm + 0x10) -- offset of String.Length
-- 0x14 is offset of String.Value
local text = readString(displayTerm + 0x14, length * 2, true) -- read wide unicode string max length 255
-- print(string.format("%X", countAddress)..": "..text)
return { Address = countAddress, Description = text }
end
if (count > 1000) then return "UH OH" end
-- create new children
local al = getAddressList()
for i = 0,count-1 do
local qi = getQuestItem(i)
if qi ~= nil then
local mr = al.createMemoryRecord()
mr.Description = qi.Description
mr.Address = string.format("%X", qi.Address)
mr.Type = vtDword
mr.Parent = memrec
end
end
{$asm}
[disable]
{$lua}
if syntaxcheck then return end
-- delete any existing children
-- https://www.cheatengine.org/forum/viewtopic.php?t=613236&sid=6cbc3f31792dc6aab3c32eb7668b12f0
-- https://wiki.cheatengine.org/index.php?title=Lua:Class:MemoryRecord
while (memrec.Count > 0) do
memoryrecord_delete(memrec.Child[memrec.Count - 1])
end
{$asm}
|
|
|