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 


Groupscan + add results to current adress list with lua?

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

Joined: 06 Jul 2015
Posts: 65
Location: Poland

PostPosted: Sun Jun 25, 2017 10:49 am    Post subject: Groupscan + add results to current adress list with lua? Reply with quote

Hey.
I have a small question:

Is it possible (with lua script of course) to perform groupscan, and then fill the current adress list with scan results?
The adresses from groupscan result should be automatically named too, like:
- "resultA1"
- "resultA2"
- "resultA3"
- "resultA4"
- "resultA5"
- "resultA6"
- etc... You know what I mean

For example, this groupscan command in my game has always 1 result, which is correct.
Tested on other PC too.

Code:
4:0 w:20 4:12 w:4 4:9 w:4 4:48 4:384 w:120 4:41


So, how the lua script should look like?
I was looking for some scripts on this forum (only found some lua value scans) but could not modify and continue them so they will work as I want. I'm total n00bzor in CE to be honest.

Thank You for any help.

I've found idea with groupscan in lua because in my game (Two Worlds 1 by Reality Pump) some adresses couldn't be tracked with pointers correctly (or I just sucks, dunno) - some adresses need manual correction of pointer offset a little bit every time.
I don't have motivation and skills to learn LUA, AoB, autoassemblys etc. too, so groupscan is the only method for me - especially because where pointerscan fails, groupscan success with 1, correct result even on other PC Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website
squerol
Advanced Cheater
Reputation: 2

Joined: 06 Jul 2015
Posts: 65
Location: Poland

PostPosted: Mon Jun 26, 2017 8:38 am    Post subject: Reply with quote

Or maybe just simple value change of found groupscan result is possible?

Found script for String result value change through lua on CE forum (by DarkByte)

Code:

ms=createMemScan()
ms.firstScan(soExactValue,vtString,0,"3.6","",0, 0xffffffffffffffff, "", fsmNotAligned, "1", false, false, false, false)
ms.waitTillDone()

f=createFoundList(ms);
f.initialize();

resultToWrite=stringToByteTable("40.6"..string.char(0))

for i=0,f.Count-1 do
  writeString(f.Address[i], "40.6")
  writeBytes(("0x"..f.Address[i])+4,0)
end

f.destroy()
ms.destroy()


It works.
But sadly I have no idea how to edit it so it will work with my example groupscan from first post (no scan for string)...

Code:

4:0 w:20 4:12 w:4 4:9 w:4 4:48 4:384 w:120 4:41


For example:
- keep 4:0,
- change 4:12 value to 4:24,
- 4:9 to 4:50,
- 4:48 to 4:0,
- 4:384 to 4:100,
- 4:41 to 4:1,

Thanks.

--------------------------------

EDIT:

Progressed a bit...
The first adress from group scan (4:0 result) is changed by script...
But how to change later adresses from group scan result?
4:12, 4:9, 4:48, 4:384 and 4:41 from groupscan?

Code:

ms=createMemScan()
ms.FirstScan(soExactValue, vtGrouped, rtRounded, "4:0 w:20 4:12 w:4 4:9 w:4 4:48 4:384 w:120 4:41","", 0, 0xffffffffffffffff,"", fsmNotAligned,"1", false, false, false, false)
ms.waitTillDone()

f=createFoundList(ms);
f.initialize();

resultToWrite=DwordToByteTable("55")

for i=0,f.Count-1 do
  writeInteger(f.Address[i], "55")
  writeBytes("0x"..f.Address[i])
end

f.destroy()
ms.destroy()


Thanks

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 42

Joined: 09 Aug 2013
Posts: 1089

PostPosted: Mon Jun 26, 2017 1:15 pm    Post subject: Reply with quote

squerol wrote:
But how to change later adresses from group scan result?
The address you get from f.Address[i] is the address of the first element, so you just figure out what the offsets are from that.

4:0 = 0 (first value)
w:20 = 0 +4 (last offset + last size)
4:12 = 0+4+20 (last offset + last size)
w:4 = 0+4+20+4 (last offset + last size)
4:9 = ... +4
w:4 = ... +4
4:48 = ... +4
4:384 = ... + 4
w:120 = ... + 4
4:41 = ... + 120
note these offsets are in decimal, which is what lua uses by default, but the auto assembler (and most of the rest of CE) uses hex by default for addresses and offsets

So to
Quote:

- keep 4:0,
- change 4:12 value to 4:24,
- 4:9 to 4:50,
- 4:48 to 4:0,
- 4:384 to 4:100,
- 4:41 to 4:1


You'd use something like
Code:

for i=0,f.Count-1 do
  -- f.Address[i] is a string by default, since I don't want to concatenate using ..
  -- which would be interpreted by CE and treat the offsets as hex
  -- first convert it to a number and then use normal addition in lua
  local addr = tonumber(f.Address[i])
  -- keep 4:0 by doing nothing
  -- change 4:12 to 24
  writeInteger(addr+24, 24)
  -- 4:9 to 4:50
  writeInteger(addr+32, 50)
  -- 4:48 to 4:0
  writeInteger(addr+40, 0)
  -- 4:384 to 100
  writeInteger(addr+44, 100)
  -- 4:41 to  1
  writeInteger(addr+164, 1)
  writeBytes("0x"..f.Address[i])
end


You may want to double check my math if you try it and some of it doesn't work as expected lol
Back to top
View user's profile Send private message
squerol
Advanced Cheater
Reputation: 2

Joined: 06 Jul 2015
Posts: 65
Location: Poland

PostPosted: Mon Jun 26, 2017 2:02 pm    Post subject: Reply with quote

FreeER wrote:
squerol wrote:
But how to change later adresses from group scan result?
The address you get from f.Address[i] is the address of the first element, so you just figure out what the offsets are from that.

4:0 = 0 (first value)
w:20 = 0 +4 (last offset + last size)
4:12 = 0+4+20 (last offset + last size)
w:4 = 0+4+20+4 (last offset + last size)
4:9 = ... +4
w:4 = ... +4
4:48 = ... +4
4:384 = ... + 4
w:120 = ... + 4
4:41 = ... + 120
note these offsets are in decimal, which is what lua uses by default, but the auto assembler (and most of the rest of CE) uses hex by default for addresses and offsets

So to
Quote:

- keep 4:0,
- change 4:12 value to 4:24,
- 4:9 to 4:50,
- 4:48 to 4:0,
- 4:384 to 4:100,
- 4:41 to 4:1


You'd use something like
Code:

for i=0,f.Count-1 do
  -- f.Address[i] is a string by default, since I don't want to concatenate using ..
  -- which would be interpreted by CE and treat the offsets as hex
  -- first convert it to a number and then use normal addition in lua
  local addr = tonumber(f.Address[i])
  -- keep 4:0 by doing nothing
  -- change 4:12 to 24
  writeInteger(addr+24, 24)
  -- 4:9 to 4:50
  writeInteger(addr+32, 50)
  -- 4:48 to 4:0
  writeInteger(addr+40, 0)
  -- 4:384 to 100
  writeInteger(addr+44, 100)
  -- 4:41 to  1
  writeInteger(addr+164, 1)
  writeBytes("0x"..f.Address[i])
end


You may want to double check my math if you try it and some of it doesn't work as expected lol


Oh, looks nice, Thank You very much for clear explaination.

About math, checked it, I think the offset of final adress should be 168, right?

Anyway, even after skipping the last adress with unsure offset, or just leaving just one, I'm getting the same error while executing script:

Code:

Error:[string "ms=createMemScan()..."]:10: attempt to perform arithmetic on a nil value (local 'addr')


To be honest, it's just like language from other galactic for me, don't understand it, google don't help too there.

Do You have any idea, @FreeER, what could triggered it?

Full lua:

Code:

ms=createMemScan()
ms.FirstScan(soExactValue, vtGrouped, rtRounded, "4:0 w:20 4:12 w:4 4:9 w:4 4:48 4:384 w:120 4:41","", 0, 0xffffffffffffffff,"", fsmNotAligned,"1", false, false, false, false)
ms.waitTillDone()

f=createFoundList(ms);
f.initialize();

for i=0,f.Count-1 do
  local addr = tonumber(f.Address[i])
  writeInteger(addr+24, 24)
  writeBytes("0x"..f.Address[i])
end

f.destroy()
ms.destroy()


Thanks.

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 42

Joined: 09 Aug 2013
Posts: 1089

PostPosted: Mon Jun 26, 2017 5:23 pm    Post subject: This post has 1 review(s) Reply with quote

yeah, it should be 168 Smile

Code:
attempt to perform arithmetic on a nil value (local 'addr')
means that addr had the value nil (basically undefined or not set) but was used in some kind of math (in this case addition). Since the code tries to set it to tonumber(f.Address[i]) that means that tonumber returned nil instead of a valid number, which means that what it got wasn't a valid number.... ah, I forgot that the string is going to be in hex like "4003BC" and that tonumber assumes it'll be base 10 by default where a letter would mean it's not a valid number.

simple example code
Code:
print(tonumber("A")) -- nil (not a base 10 number)
print(tonumber("A",16)) -- 10, 9+1 in base 16 is 0xA, decimal 10
print(tonumber("G",16)) -- nil, not a valid digit in hex, only 0-F


So it should be as simple as using
Code:
local addr = tonumber(f.Address[i],16)
Smile

Sorry 'bout that... it does tend to be the simple things that you forget Embarassed
Back to top
View user's profile Send private message
squerol
Advanced Cheater
Reputation: 2

Joined: 06 Jul 2015
Posts: 65
Location: Poland

PostPosted: Tue Jun 27, 2017 8:05 am    Post subject: Reply with quote

FreeER wrote:
yeah, it should be 168 Smile

Code:
attempt to perform arithmetic on a nil value (local 'addr')
means that addr had the value nil (basically undefined or not set) but was used in some kind of math (in this case addition). Since the code tries to set it to tonumber(f.Address[i]) that means that tonumber returned nil instead of a valid number, which means that what it got wasn't a valid number.... ah, I forgot that the string is going to be in hex like "4003BC" and that tonumber assumes it'll be base 10 by default where a letter would mean it's not a valid number.

simple example code
Code:
print(tonumber("A")) -- nil (not a base 10 number)
print(tonumber("A",16)) -- 10, 9+1 in base 16 is 0xA, decimal 10
print(tonumber("G",16)) -- nil, not a valid digit in hex, only 0-F


So it should be as simple as using
Code:
local addr = tonumber(f.Address[i],16)
Smile

Sorry 'bout that... it does tend to be the simple things that you forget Embarassed


Wow, Thank You Very Much for deep explaination and script correction, now it works as intended!

Now, with Your lua script I can continue modding "Two Worlds 1" and fix adresses for which I was unable to find correct pointer Embarassed

Fixed, working script now:
Code:

ms=createMemScan()
ms.FirstScan(soExactValue, vtGrouped, rtRounded, "4:0 w:20 4:12 w:4 4:9 w:4 4:48 4:384 w:120 4:41","", 0, 0xffffffffffffffff,"", fsmNotAligned,"1", false, false, false, false)
ms.waitTillDone()

f=createFoundList(ms);
f.initialize();

for i=0,f.Count-1 do
  local addr = tonumber(f.Address[i],16)
  writeInteger(addr+24, 24)
  writeInteger(addr+32, 50)
  writeInteger(addr+40, 0)
  writeInteger(addr+44, 100)
  writeInteger(addr+168, 1)
  writeBytes("0x"..f.Address[i])
end

f.destroy()
ms.destroy()


Thanks once more!

Quote:

Sorry 'bout that... it does tend to be the simple things that you forget Embarassed


Laughing

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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