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 


Lua script, please help.
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
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sun Jan 01, 2017 4:22 pm    Post subject: Re: Lua script, please help. Reply with quote

I have not tested
Code:

all_address = {}
function findDoubleValueAndReplace(findValue)
  memscan = createMemScan()
  foundlist = createFoundList(memscan)
  protectionflags = "*W*X-C"

  -- firstScan(scanoption, vartype, roundingtype, input1, input2,
  --           startAddress, stopAddress, protectionflags,
  --           alignmenttype, "alignmentparam",
  --           isHexadecimalInput, isNotABinaryString, isunicodescan, iscasesensitive)

  --    scanOption: soUnknownValue, soExactValue, soValueBetween, soBiggerThan, soSmallerThan
  --    vartype: vtByte, vtWord, vtDword, vtQword, vtSingle, vtDouble, vtString,
  --             vtByteArray, vtGrouped, vtBinary, vtAll
  --    roundingtype: rtRounded, rtTruncated, rtExtremerounded
  --    alignmenttype: fsmNotAligned, fsmAligned, fsmLastDigits
  --    protectionflags: X W C   (+ to indicate that flag MUST be set, - MUST NOT, * whatever)

  memscan.firstScan(soExactValue, vtSingle, rtTruncated, findValue, nil,
               "0","7fffffff",protectionflags,
               fsmAligned,"4",
               false, false, false, false)
  memscan.waitTillDone()
  foundlist.initialize()

  for i=0,foundlist.Count-1 do
   all_address[i+1] = foundlist[i]
  end

  sleep(50)
  foundlist.destroy()
  sleep(50)
  memscan.destroy()

end
findDoubleValueAndReplace(2.309374809)

function change_value()
   for i=1, #all_address do
       writeFloat(all_address[i], readFloat(all_address[i]+0.0625))
    end
end

if hotkey1 then hotkey1.destroy(); hotkey1=nil end
hotkey1 = createHotkey(change_value, VK_C)

_________________
...
Back to top
View user's profile Send private message
fcqgju14156
Newbie cheater
Reputation: 0

Joined: 01 Jan 2017
Posts: 18

PostPosted: Mon Jan 02, 2017 2:01 am    Post subject: Reply with quote

Not working(
Back to top
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Mon Jan 02, 2017 7:23 am    Post subject: Reply with quote

This one is working
Code:
all_address = {}
function findDoubleValueAndReplace(findValue)

  memscan = createMemScan()
  foundlist = createFoundList(memscan)
  protectionflags = "*W*X*C"

  -- firstScan(scanoption, vartype, roundingtype, input1, input2,
  --           startAddress, stopAddress, protectionflags,
  --           alignmenttype, "alignmentparam",
  --           isHexadecimalInput, isNotABinaryString, isunicodescan, iscasesensitive)

  --    scanOption: soUnknownValue, soExactValue, soValueBetween, soBiggerThan, soSmallerThan
  --    vartype: vtByte, vtWord, vtDword, vtQword, vtSingle, vtDouble, vtString,
  --             vtByteArray, vtGrouped, vtBinary, vtAll
  --    roundingtype: rtRounded, rtTruncated, rtExtremerounded
  --    alignmenttype: fsmNotAligned, fsmAligned, fsmLastDigits
  --    protectionflags: X W C   (+ to indicate that flag MUST be set, - MUST NOT, * whatever)

  memscan.firstScan(soExactValue, vtSingle, rtRounded, findValue, nil,
               "0","7fffffff",protectionflags,
               fsmAligned,"4",
               false, false, false, false)
  memscan.waitTillDone()
  foundlist.initialize()

  for i=0, foundlist.Count-1 do
    all_address[i+1] = foundlist.Address[i]
  end

  foundlist.destroy()
  memscan.destroy()

end
findDoubleValueAndReplace(2.309374809)

function change_value()
   for i=1, #all_address do
       writeFloat(all_address[i], readFloat(all_address[i])+0.0625)
    end
end

if hotkey1 then hotkey1.destroy(); hotkey1=nil end
hotkey1 = createHotkey(change_value, VK_C)

_________________
...
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Mon Jan 02, 2017 8:02 am    Post subject: Reply with quote

Maybe also this (not tested)

Code:
function change_value()

--Scan
local scan = createMemScan(true);
scan.setOnlyOneResult(false);
scan.firstScan(soExactValue,vtSingle,rtRounded,"2.309374809",nil,0,0xffffffffffffffff,"+W-C",fsmNotAligned,nil,false,false,false,false);
scan.waitTillDone();

--Fetch result
local FoundList=createFoundList(scan);
FoundList.initialize();


--Overwite
for i=0,FoundList.Count-1 do
  --print(FoundList.Address[i]);
  writeFloat(FoundList.Address[i],2.371874809);
  end

--Cleanup
FoundList.deinitialize();
FoundList.destroy();
FoundList=nil;
scan.destroy();
scan=nil;

end

if hotkey1 then hotkey1.destroy(); hotkey1=nil end
hotkey1 = createHotkey(change_value, VK_C)



--- Note : 
 // 2.309374809 + 0.0625 = 2.371874809
 // also check for "rtRounded", "rtTruncated", etc
 // rtRounded to two decimal places for 2.309374809 = 2.31
 // rtTruncated to two decimal places for 2.309374809 = 2.30
 // check for "+W-C", "*W*X*C", "*W*X-C"     
Back to top
View user's profile Send private message
fcqgju14156
Newbie cheater
Reputation: 0

Joined: 01 Jan 2017
Posts: 18

PostPosted: Mon Jan 02, 2017 11:19 am    Post subject: Filipe_Br Reply with quote

Working, Thank you. What if the address value is changed periodically? This value (2.309374809) after a while changes the address. It is possible to bypass it, that would again not search for value?
Or maybe make the script was looking for all the values from 2.309374809 to 2.967968702 (intervals 0.0625)?
Back to top
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Mon Jan 02, 2017 1:37 pm    Post subject: Re: Filipe_Br Reply with quote

fcqgju14156 wrote:
Working, Thank you. What if the address value is changed periodically? This value (2.309374809) after a while changes the address. It is possible to bypass it, that would again not search for value?
Or maybe make the script was looking for all the values from 2.309374809 to 2.967968702 (intervals 0.0625)?

I did not understand, would it redo the scan with a different value?

_________________
...
Back to top
View user's profile Send private message
fcqgju14156
Newbie cheater
Reputation: 0

Joined: 01 Jan 2017
Posts: 18

PostPosted: Mon Jan 02, 2017 2:00 pm    Post subject: Reply with quote

the script was looking for multiple values.
From 2.309374809 to 2.967968702 (intervals 0.0625).
For example 2.309374809, 2.371874809, 2.434374809, 2.496874809 ..... and so on.
It is necessary that the script was looking for and changed several values at once
Back to top
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Mon Jan 02, 2017 4:10 pm    Post subject: Reply with quote

Try to explain in detail what you want.
Let's see if I get it: You want a script that looks for multiple values, starting from a specific value to another specific value. And that all these values would be increased when the "C" key is pressed.

_________________
...
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Jan 02, 2017 5:39 pm    Post subject: Reply with quote

To search for all values between 2.309374809 and 2.967968702 use:
Code:
scan.firstScan(soExactValue,vtSingle,rtRounded,"2.309374809","2.967968702",0,0xffffffffffffffff,"+W-C",fsmNotAligned,nil,false,false,false,false);


Just so you know, 2.967968702 is not one of the values when adding 0.0625...
So decide if you want to stop at 2.934374809 or 2.996874809.
Code:
local start = 2.309374809
local interval = 0.0625
local finish = 2.934374809
local values = {}
for i = start, finish, interval do
  values[i] = true
end


You can then check if the found value is equal to one of those intervals.
I'm not sure how well this approach will work due to possible rounding differences.
You could do a similar approach and add/subtract 0.0001 to check against a tiny range.
Code:
for i=0,FoundList.Count-1 do
  if values[FoundList.Value[i]] then
    writeFloat(FoundList.Address[i],2.371874809);
  end
end
Back to top
View user's profile Send private message
fcqgju14156
Newbie cheater
Reputation: 0

Joined: 01 Jan 2017
Posts: 18

PostPosted: Tue Jan 03, 2017 5:41 am    Post subject: Reply with quote

Filipe_Br, yes. Perhaps make a script that he found these few float values, and replaces recording instructions on NOP, and returns the source code of the recording instructions. What would all this was done on the button C. (first click on the C - replaced with NOP, the second click on the C - Returns the source code). Make that possible? Thank you.
Back to top
View user's profile Send private message
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Mon Jan 23, 2017 12:17 pm    Post subject: Reply with quote

Filipe_Br wrote:
This one is working
Code:
all_address = {}
function findDoubleValueAndReplace(findValue)

  memscan = createMemScan()
  foundlist = createFoundList(memscan)
  protectionflags = "*W*X*C"

  -- firstScan(scanoption, vartype, roundingtype, input1, input2,
  --           startAddress, stopAddress, protectionflags,
  --           alignmenttype, "alignmentparam",
  --           isHexadecimalInput, isNotABinaryString, isunicodescan, iscasesensitive)

  --    scanOption: soUnknownValue, soExactValue, soValueBetween, soBiggerThan, soSmallerThan
  --    vartype: vtByte, vtWord, vtDword, vtQword, vtSingle, vtDouble, vtString,
  --             vtByteArray, vtGrouped, vtBinary, vtAll
  --    roundingtype: rtRounded, rtTruncated, rtExtremerounded
  --    alignmenttype: fsmNotAligned, fsmAligned, fsmLastDigits
  --    protectionflags: X W C   (+ to indicate that flag MUST be set, - MUST NOT, * whatever)

  memscan.firstScan(soExactValue, vtSingle, rtRounded, findValue, nil,
               "0","7fffffff",protectionflags,
               fsmAligned,"4",
               false, false, false, false)
  memscan.waitTillDone()
  foundlist.initialize()

  for i=0, foundlist.Count-1 do
    all_address[i+1] = foundlist.Address[i]
  end

  foundlist.destroy()
  memscan.destroy()

end
findDoubleValueAndReplace(2.309374809)

function change_value()
   for i=1, #all_address do
       writeFloat(all_address[i], readFloat(all_address[i])+0.0625)
    end
end

if hotkey1 then hotkey1.destroy(); hotkey1=nil end
hotkey1 = createHotkey(change_value, VK_C)


Hi.
I've tried using this code for my own purpose but there are a few things that are not working correctly for me.

First of all, I'm looking for integer values instead of float, that seems to works to some degree. But the real problem is that it replaces values in every address instead of only those addresses where the value matches exactly. The second part of the problem (related to the first part) is that I don't know how to access the current value of stored at the addresses scanned.

Maybe it is easier if I show the code that I have first:

Code:
function findValueAndReplace(findValue, replaceWith)
  memscan = createMemScan()
  foundlist = createFoundList(memscan)
  protectionflags = "*W*X*C"

  memscan.firstScan(soExactValue, vtInteger, rtTruncated, findValue, nil,
               "0","7fffffff",protectionflags, fsmAligned,"4",
               false, false, false, false)
  memscan.waitTillDone()
  foundlist.initialize()


  for i=0, foundlist.Count-1 do
    fullAccess(getAddress(foundlist.Address[i]), 8)
    writeInteger(foundlist.Address[i], replaceWith)
  end

  sleep(50)
  foundlist.destroy()
  sleep(50)
  memscan.destroy()
end

findValueAndReplace(0xDC059C4F, 0xDC059C00)


As I mentioned, this code will overwrite EVERY address scanned with the value set by 'replaceWith', whereas I simply want it to overwrite those addresses that have the value of 'findValue'.
The other issue I mentioned maybe isn't even necessary if this worked as I expected, but if not I would have to check every address for it's value and use an 'if' clause to overwrite only the ones that do match the case. Where am I going wrong?

Thanks for the help!
Back to top
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Mon Jan 23, 2017 2:04 pm    Post subject: Reply with quote

This script will search for "0xDC059C4F" and change the value of all addresses you find by "0xDC059C00". Is not that what you want?
_________________
...
Back to top
View user's profile Send private message
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Mon Jan 23, 2017 3:29 pm    Post subject: Reply with quote

Filipe_Br wrote:
This script will search for "0xDC059C4F" and change the value of all addresses you find by "0xDC059C00". Is not that what you want?

Not sure if I'm having an incorrect interpretation...
Let's say that this is the range for scanning: 0x00000000 - 0x00000004
Let's assume that the value I'm searching is: 0xDC059C4F
Now, let's also say that only one address matches the value above: 0x000000002

My intention is that the address which holds the value that matches is the only one that is written to, but instead what is happening is that all addresses in the range are written to.

Is my expectation for the code wrong or am I using the incorrect approach?
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Mon Jan 23, 2017 7:51 pm    Post subject: Reply with quote

Maybe something like this :

Code:
function findValueAndReplaceSpecific(findValue, replaceWith)
  memscan = createMemScan()
  foundlist = createFoundList(memscan)
  protectionflags = "*W*X*C"

  memscan.firstScan(soExactValue, vtInteger, rtTruncated, findValue, nil,
               "0","7fffffff",protectionflags, fsmAligned,"4",
               false, false, false, false)
  memscan.waitTillDone()
  foundlist.initialize()

  if (foundlist) then
   lngt = foundlist.getCount()
  ----------------------------------- set condition for find and replace specific address
    if (lngt > 5) then
     i = 6
     fullAccess(getAddress(foundlist.Address[i]), 8)  --- find and replace 6th address
     writeInteger(foundlist.Address[i], replaceWith)
    end
  ----------------------------------- Add another set condition according what you want...
     sleep(50)
     foundlist.destroy()
     sleep(50)
    memscan.destroy()
  end
end

findValueAndReplaceSpecific(0xDC059C4F, 0xDC059C00)



If you want to replace more results let's say 2, 3 and 7 extend the script with this lines:
Code:

Code:
if (lngt > 1) then fullAccess(getAddress(foundlist.Address[1]), 8); writeInteger(foundlist.Address[1], replaceWith)); end
if (lngt > 2) then fullAccess(getAddress(foundlist.Address[2]), 8); writeInteger(foundlist.Address[2], replaceWith)); end
if (lngt > 6) then fullAccess(getAddress(foundlist.Address[6]), 8); writeInteger(foundlist.Address[6], replaceWith)); end



Quote:
findValueAndReplace(0xDC059C4F, 0xDC059C00)


Not sure, it must be :

Code:
findValueAndReplace("0xDC059C4F", 0xDC059C00)


or maybe :

Code:
ms=createMemScan()
protectionflags = "+W-C"
memscan_firstScan(ms, soExactValue, vtInteger, rtTruncated, 0xDC059C4F, nil, "0", 0x00000000, 0x00000004, protectionflags, fsmAligned, "4", false, false, false, false)
memscan_waitTillDone(ms)

--get the result of the scans
fl=createFoundList(ms)
foundlist_initialize(fl)
local count=foundlist_getCount(fl)
local values = {}
if (count>0) then
--get the first address
  local saddress=foundlist_getAddress(fl, 0)
  print("Adding "..saddress.." to the list")
--add to the addresslist
  local al=getAddressList()
  local mr=addresslist_createMemoryRecord(al)
  memoryrecord_setDescription(mr,"Result of automated scan")
  memoryrecord_setAddress(mr, saddress)
  memoryrecord_setType(mr, vtDouble)
---
    for i=0,fl.count-1 do
     if values[fl.Value[i]] == 0xDC059C4F then
     writeInteger(fl.Address[i],0xDC059C00); end
   end
else
  print("No addresses found")
end

--cleanup
object_destroy(fl)
object_destroy(ms)
Back to top
View user's profile Send private message
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Tue Jan 24, 2017 4:49 am    Post subject: Reply with quote

@Corroder

Thanks for the code, but unfortunately I don't think I'm getting the idea through, at least it seems so from the code you posted.

If I understand correctly, the condition is the position of the address in the scan list? If that is so, it is assumed that I will know what position in the scan the target address will have, but I do not know that - that is why I'm trying to find the correct address for the specific value. Talking in practical terms, when I use the code you demonstrated, this will write to the address 0x0041A9DC (where the current value is not the one searched for with 'findValue'), instead of writing to the address 0x1AB607F1 which is where the 'findValue' actually is.

Also, wrapping the value in quotes doesn't seem to make a difference.
I may be doing something wrong, but I think the problem is more about the approach here. I have to be able to use the 'findValue' as t6eh condition and not some static position on a scan result to which I can't relate twice.

Cheers.

EDIT: The second snippet seems closer to what I'm trying to achieve, although the firstScan had a misconfiguration just before the address range.
Anyway, for some reason fl.Value[i] only gives one byte as a result, which makes it hard to compare against 4 bytes. How can I extend the result to 4 bytes and, if possible, make the output hex instead of dec?
Also, values[fl.Value[i]] is always empty, not sure why, which makes the if condition not able to evaluate correctly.
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