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 


Working with AOB
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Oct 20, 2016 9:38 am    Post subject: Working with AOB Reply with quote

I searched and could not find an appropriate answer so here goes
There is a table address that is a 16 byte AOB and has the "value" of
1C B3 08 80 8C B2 08 80 CC B4 08 80 5C B5 08 80
Now what I'm attempting is access bytes 1 & 2, 5 & 6, 9 & 10, 13 & 14
Code:

local addresslist = getAddressList()
battlepartyaddress = addresslist_getMemoryRecordByDescription(addresslist,"Battle Party")
test = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Battle Party"))
print(test)
battleparty = test
print(battleparty)
print(readBytes(battleparty,2))
maxhp1address = addresslist_getMemoryRecordByDescription(addresslist, "Zidane-Max HP Field")
maxhp1 = memoryrecord_getValue(maxhp1address)
  maxhp2address = addresslist_getMemoryRecordByDescription(addresslist, "Vivi-Max HP Field")
  maxhp2 = memoryrecord_getValue(maxhp2address)
--  if readBytes(battleparty) == 0x8c then
--    firstcharmaxhp = maxhp1
--  elseif readBytes(battleparty) == 0x1c then
--    firstcharmaxhp = maxhp2
--  end

now the print statement for both test and battleparty are both:
1C B3 08 80 8C B2 08 80 CC B4 08 80 5C B5 08 80
the print statement for readBytes(battleparty,2))

Error:Failure determining what 1C B3 08 80 8C B2 08 80 CC B4 08 80 5C B5 08 80 means
Script Error

What are the proper syntax to read/compare the bytes in the array?
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Oct 20, 2016 2:45 pm    Post subject: Reply with quote

Not sure if you realize this, but your AOB contains the bytes you're trying to find...
Code:
1C B3 08 80 8C B2 08 80 CC B4 08 80 5C B5 08 80
 1&2         5&6         9&10       13&14

Anyway...
Code:
local aob = AOBScan("1C B3 08 80 8C B2 08 80 CC B4 08 80 5C B5 08 80")
local addr = tonumber(aob[0],16)
aob.Destroy()
print(readBytes(addr,2))
print(readBytes(addr+4,2))
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Oct 20, 2016 8:05 pm    Post subject: Reply with quote

Zanzer wrote:
Not sure if you realize this, but your AOB contains the bytes you're trying to find...
Code:
1C B3 08 80 8C B2 08 80 CC B4 08 80 5C B5 08 80
 1&2         5&6         9&10       13&14

Anyway...
Code:
local aob = AOBScan("1C B3 08 80 8C B2 08 80 CC B4 08 80 5C B5 08 80")
local addr = tonumber(aob[0],16)
aob.Destroy()
print(readBytes(addr,2))
print(readBytes(addr+4,2))


Yes I realize that the AOB contained the bytes, but the [0] gave me the hint I was needing as I needed a way to get at the addresses.
Code:

aob1 = AOBScan("1C B3 08 80")
  if aob1 ~= nil then
  if string.sub(aob1[0],-2) == "BC" then
    firstcharmaxhp = maxhp2
    print("found the top char")
  elseif string.sub(aob1[0],-2) == "C0" then
    secondcharmaxhp = maxhp2
  elseif string.sub(aob1[0],-2) == "C4" then
    thirdcharmaxhp = maxhp2
  elseif string.sub(aob1[0],-2) == "C8" then
    fourthcharmaxhp = maxhp2
  end
  end

Broke the bytes into the 4 group's information I needed and then found who was in each place. I did run some tests and as with the 16 bytes there was only one AOB Scan result for each of the four pieces.
Thanks
Back to top
View user's profile Send private message Yahoo Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Wed Oct 26, 2016 2:28 pm    Post subject: Reply with quote

OK, so what does .Destroy do to an AOB?

Code:
aob1 = AOBScan("8C B2 08 80")
print(aob1)
aob1.Destroy()
print(aob1)
aob1 = nil
print("Now nil")
print(aob1)


The out put:
0BA58380
0BA58380
Now nil

Not only that but the address should be 78eb7bc. What's up with this? Is there another setting?
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Wed Oct 26, 2016 4:11 pm    Post subject: Reply with quote

It cleans up the AOB object's scan results. Try this:
Code:
local aob1 = AOBScan("8C B2 08 80")
print(aob1[0])
aob1.Destroy()
print(aob1[0])

Printing aob1 gives you the address of the instantiated object created within Lua.
Indexing aob1 gives you the corresponding found address out of aob1.Count results.
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Wed Oct 26, 2016 6:19 pm    Post subject: Reply with quote

I got a error: access violation
maybe that is what is causing my issues, as I keep getting access error violation. But this error is different, it does not cause CE to crash, just keeps popping up the access violations. I got code running that destroys them and then checks if they exist in an if statement.
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Wed Oct 26, 2016 7:30 pm    Post subject: Reply with quote

Yes, I was showing you what happens after you destroy the AOB.
Its memory is cleared up and you can no longer use it (access violation).

What exactly are you trying to do now? What's the issue?
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Wed Oct 26, 2016 8:06 pm    Post subject: Reply with quote

What are you exactly trying to do, couldn't quite understand whats the problem, also send your script so we could tell what causes the access violation, it is no good in the long run if you add more stuff even if it doesn't bother you, yet.

Here's one approach of how I'd filter all address the aobscan returns, compare bytes and based on that assume if we are holding the right address.

Code:
 local target = {[1] = 0x1C,[2] = 0xb3,[5] = 0x8c, [6] = 0xb2,[9] = 0xcc, [10] = 0xb4, [13] = 0x5c, [14] = 0xb5} -- key is offset in the aob.
 local aobs = AOBscan("1C B3 08 80") -- perhaps use this? 1C B3 08 80 8C B2 08 80 CC B4 08 80 5C B5 08 80 just wildcard part of the aob incase it's not consistent.
 if aobs then -- if the object has any results otherwise it returns nil.. we may only then access and destroy it
   for index = 0, aobs.Count -1 do
      local address = object[index];
      local bytes = readBytes(address,16,true) -- returns a table
      print("address =",address,",containing the following bytes:",unpack(bytes));
      local matchesCount,total = 0,0;
      for offset,byte in pairs(target) do
         total = total + 1; -- #target stop counting after the 2nd index, because of 3rd index being nil, so we gotta count ourself.
         if (bytes[offset] == byte) then
            matchesCount = matchesCount + 1; -- we are checking 8 bytes so matchesCount should be 8 if thats the correct address
         end
      end
      if (matchesCount == total) then
         print("our target address is ",adress)
      end
   end
   aobs.destroy()
 end

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Wed Oct 26, 2016 8:08 pm    Post subject: Reply with quote

As I posted earlier getting the addresses so that I may reset cur HP, MP with max values
Code:
if not aobresult1 and counter == 1 then
aob1 = AOBScan("1C B3 08 80")
  if aob1[0] ~= nil then
--  print("Vivi is at " .. "0x" .. aob1[0])
  if string.sub(aob1[0],-2) == "BC" then
    firstcharmaxhp = maxhp2
    --print("found the top char")
  elseif string.sub(aob1[0],-2) == "C0" then
    secondcharmaxhp = maxhp2
  elseif string.sub(aob1[0],-2) == "C4" then
    thirdcharmaxhp = maxhp2
  elseif string.sub(aob1[0],-2) == "C8" then
    fourthcharmaxhp = maxhp2
  end
  end
...

Finding out which character is in which slot. Six other AOB's that I left out, but are essentially equivalent
Code:

if battlebyte.value == 128 then
  if firstcharcurhp ~= firstcharmaxhp then
    firstcharcurhp.value = firstcharmaxhp
  end
  if secondcharcurhp ~= secondcharmaxhp then
    secondcharcurhp.value = secondcharmaxhp
  end
  if thirdcharcurhp ~= thirdcharmaxhp then
    thirdcharcurhp.value = econdcharmaxhp
  end
  if fourthcharcurhp ~= fourthcharmaxhp then
    fourthcharcurhp.value = fourthcharmaxhp
  end
end--if maxhp1address.value == 128 then

At the end of the Major if statement not shown
Code:
aob1.Destroy()
aob2.Destroy()
aob3.Destroy()
aob4.Destroy()
aob5.Destroy()
aob6.Destroy()
aob7.Destroy()
counter = counter + 1


counter is set to 1 in a check box
Anyway after running all these code lines after mouseing over any part of CE I would get the Access violation pop-up
Back to top
View user's profile Send private message Yahoo Messenger
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Wed Oct 26, 2016 9:50 pm    Post subject: Reply with quote

Restart C.E does not solve it?
Something must be broken if you get access violation just by hovering.
Are you updating GUI or something? modifying anything related to C.E main window?

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Oct 27, 2016 5:09 am    Post subject: Reply with quote

The behavior does not exist after restarting CE. It only occurs after the code has run and then stopped. The behavior MAY be in existence while the check box is selected, but it is only selected for a short time (maybe a minute or less), and I haven't observed it while the code is running.

EDIT: I have change the last steps to aob1 = nil etc. and the behavior has not been observed.
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Oct 27, 2016 1:59 pm    Post subject: Reply with quote

Sounds like you have some code which checks if "aob1" is nil before performing the AOBScan().
Then when your function runs a second time, aob1 still exists, but you ran Destroy().
So it doesn't rescan, but then it attempts to index the result aob1[0].
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Oct 27, 2016 2:19 pm    Post subject: Reply with quote

counter being greater than one should negate any further scans as the initial step in each AOBscan is if not aobx and counter == 1 then
Back to top
View user's profile Send private message Yahoo Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Mon Nov 07, 2016 5:18 pm    Post subject: Reply with quote

Continuing on the AOB theme, I ran an AOB for "08 80" and got 4643 hits.
Now what I would like to do is to determine if a following hits is 3 bytes away
Code:
mr = AOBScan("08 80")
for x = 0, mr.count -1 do
if mr[x + 1] == mr[x] +0x03 then
print (mr[x])
end
end

now the if statement is giving error fits
1. attempt to perform calculation on sting
Changed to if string.format("x%",mr[x + 1]) == string.format("%x", mr[x]) +0x03 then
2. Expected number got sting
Changed to if string.format(tonumber(mr[x+1])) == string.format(tonumber(mr[x])) +0x03 then
3. number expected got nil

Suggestions to change the code?
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Nov 07, 2016 5:56 pm    Post subject: Reply with quote

Code:
if tonumber(mr[x + 1], 16) == tonumber(mr[x], 16) + 3 then
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
Goto page 1, 2  Next
Page 1 of 2

 
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