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 


Creating memory records with LUA in table entry

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

Joined: 25 Sep 2011
Posts: 252

PostPosted: Mon Dec 12, 2022 2:08 pm    Post subject: Creating memory records with LUA in table entry Reply with quote

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}
Back to top
View user's profile Send private message
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