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 


Pompt user and handle results
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
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Wed May 18, 2022 10:10 pm    Post subject: Pompt user and handle results Reply with quote

I have a value in memory that doesn't have any other consistent bytes near it to form an aob (checked a perimeter of 25000 bytes on either side).

My thought was to create a script that will cycle through each of the results of my 'close enough' aob, change the value, then prompt "Did it change on screen?" If yes, then stop looking and make that address my address. If not, continue.

But, from what I've read, LUA doesn't have any such yes/no prompts, so not sure how this would be possible.

Hooking instructions are not an option here (android emulator).

I'm open to any ideas. Smile
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Wed May 18, 2022 11:08 pm    Post subject: Reply with quote

if messageDialog('did it change?', mbYes,mbNo)==mrYes then
showMessage('clicked yes')
end

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Thu May 19, 2022 12:32 pm    Post subject: Reply with quote

I tried testing like this, but only has No as an option

[ENABLE]
{$lua}
if messageDialog('did it change?', mbYes,mbNo)==mrYes then
showMessage('clicked yes')
end
{$asm}

[DISABLE]
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 30

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Thu May 19, 2022 1:03 pm    Post subject: Reply with quote

0=Warning
1=Info
2=Information
3=Confirmation
4=Normal Dialog Message


Code:
[ENABLE]
{$lua}
if messageDialog('did it change?', 2, mbYes, mbNo)==mrYes then
showMessage('clicked yes')
else
showMessage('clicked no')
end
{$asm}

[DISABLE]

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Thu May 19, 2022 1:10 pm    Post subject: Reply with quote

That did the trick. Thank you both!

Now to accomplish what I'm trying to do...

Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

for i = 0,20,20

do
function aob_register(sym, pat)
  instr = AOBScan(pat, "+r+w")
  addy = instr[i]
  instr.destroy()
  addy = tonumber(addy, 16)
  unregisterSymbol(sym)
  registerSymbol(sym, addy)
end

aob_register("block","e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00 00 00 ?? ?? ?? ?? ?? ?? ?? 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00 00 00 ?? ?? 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 ?? 00 00 00")

writeInteger("block","3686")

      if messageDialog('did it change?',mtWarning, mbYes,mbNo)==mbYes then
      --return
      end

end

{$asm}
[DISABLE]

unregistersymbol(block)


It works each time I click the checkbox, but doesn't loop on it's own after I made a selection (yes or no). Is it clear where I'm going wrong? If possible, I'd also like to grab the number of results so I can use it in my For loop. thx

Edit1: Figured out the loop issue - my increment was wrong. Should be 1,not 20

Edit2: I can't figure out how to escape the loop once it detects Yes. Other than that, it's working.

Here's my current script:

Code:

[ENABLE]
{$lua}
if syntaxcheck then return end

for i = 0,99,1

do
function aob_register(sym, pat)
  instr = AOBScan(pat, "+r+w")
  addy = instr[i]
  instr.destroy()
  addy = tonumber(addy, 16)
  unregisterSymbol(sym)
  registerSymbol(sym, addy)
end

aob_register("block","e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00")

writeInteger("block","3868")

      if messageDialog('did it change?',mtWarning, mbYes,mbNo)==mbYes then
      break return end

end

{$asm}
[DISABLE]

unregistersymbol(block)
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 30

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Thu May 19, 2022 2:52 pm    Post subject: Reply with quote

You used "block" without defining it anywhere. Isn't this a problem?

I think it would be better to add the code change test at the end of the loop.

Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

for i = 0,99,1 do

function aob_register(sym, pat)
  instr = AOBScan(pat, "+r+w")
  addy = instr[i]
  instr.destroy()
  addy = tonumber(addy, 16)
  unregisterSymbol(sym)
  registerSymbol(sym, addy)
end

aob_register("block","e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00")

writeInteger("block","3868")
  if i==98 then -- or 99
      if messageDialog('did it change?',mtWarning, mbYes,mbNo)==mbYes then
      break return end
  end

end

{$asm}
[DISABLE]

unregistersymbol(block)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Thu May 19, 2022 3:03 pm    Post subject: Reply with quote

Well, my code does what I need, I just can't end it by selecting Yes
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Thu May 19, 2022 3:14 pm    Post subject: This post has 1 review(s) Reply with quote

My try:
Code:


function SelectAOB(OnTest, OnRestore, OnFinalize)
  OnFinalize = OnFinalize or OnTest
  assert(OnTest and OnFinalize, 'OnTest must be provided')
  return function (...)--- AOBScan parameters
    local md, found, addy = inMainThread() and messageDialog or function(...)
        return synchronize(messageDialog,...)
      end
--    print(inMainThread() and 'main' or 'sub')
    local fms, aobs = string.format, AOBScan(...)
    if not aobs then return nil,'SelectAOB: no aob results'else
      local total = aobs.Count
      for i=1,total do
        addy = tonumber(aobs[i-1],16)
        local tested, errmsg = OnTest(addy)
        if tested then -- notify test success, ask user if effect valid
          if md(fms('aob (%d/%d) found at %X, is any effect valid?', i,total,addy),mtConfirmation, mbNo, mbYes)==mrYes then
            if OnRestore then OnRestore(addy) end -- undo effect done by OnTest, if any
            found = true
            break
          end
        elseif errmsg then -- notify test failed, eg. some error?
          md(fms('aob (%d/%d) found at %X, but some thing wrong: %s', i,total, addy, tostring(errmsg)),mtError )
        --elseif tested == nil then
          -- do nothing?
        end
        if tested and OnRestore then OnRestore(addy) end -- undo effect done by OnTest, if any
      end
      aobs.Destroy()
      if found then
        OnFinalize(addy) -- OnFInalize may be just OnTest
        return addy
      else
        return nil,fms('no effect on %d aob found',total)
      end
    end
  end
end

-- test
-- attach some process for testing
autoAssemble[[
globalalloc(SelAOB,$1000)
SelAOB:
db 11 22 33 44 11 11 11 11 55 99 ff ff 55 99 ff ff
db 11 22 33 44 22 22 22 22 55 99 ff ff 55 99 ff ff
db 11 22 33 44 33 33 33 33 55 99 ff ff 55 99 ff ff
db 11 22 33 44 44 44 44 44 55 99 ff ff 55 99 ff ff
db 11 22 33 44 55 55 55 55 55 99 ff ff 55 99 ff ff
]]
local TEST_ERR_ADDY = getAddressSafe'SelAOB+20'

local function TestFuncs()
  local original = {}
  return function(Addy)-- OnTest example
    if Addy == TEST_ERR_ADDY then return nil,'-oops-forced-error-'end
    local addy = Addy + 0x6
    local ori = readSmallInteger(addy)
    if not ori then return nil,string.format('%X is not readable',Addy)else
      getMemoryViewForm().HexadecimalView.Address = Addy-0x60 -- not neccessary
      original[Addy] = {addy,ori}
      writeSmallInteger(addy, 0xff)
      return true -- must return this if OnTest ok
    end
  end, function(Addy) -- OnRestore Example
    local addy, ori = original[Addy]
    addy, ori = addy and addy[1], addy and addy[2]
    if addy and ori then writeSmallInteger(addy, ori)end
  end
end

local queryAOB = SelectAOB(TestFuncs())

print(queryAOB'11 22 33 44 ?? ?? ?? ?? 55 99 ff ff 55 99 ff ff')

It has to adapt to your code.

_________________
- Retarded.
Back to top
View user's profile Send private message
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Fri May 20, 2022 11:36 am    Post subject: Reply with quote

I appreciate this, but I don't understand most of what's going on there, so any modifications to it would be time consuming. I think I can get by with how to exit my above script with a Yes answer.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 30

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Fri May 20, 2022 1:11 pm    Post subject: Reply with quote

You are asking the code change test in a 99 loop. Is this true?

In other words, the test message will be displayed 99 times and the user will not be able to reach this speed!

If this is true, it's very tragic.

I guess it's better to get the test message outside of the "for" loop.
Or using a test message driven timer!

Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

for i = 0,99,1 do

function aob_register(sym, pat)
  instr = AOBScan(pat, "+r+w")
  addy = instr[i]
  instr.destroy()
  addy = tonumber(addy, 16)
  unregisterSymbol(sym)
  registerSymbol(sym, addy)
end

aob_register("block","e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00")

writeInteger("block","3868")
      if messageDialog('did it change?',mtWarning, mbYes,mbNo)==mbYes then
       i=98 end
  end

end

{$asm}
[DISABLE]

unregistersymbol(block)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Sun May 22, 2022 11:14 pm    Post subject: Reply with quote

AylinCE wrote:
You are asking the code change test in a 99 loop. Is this true?

In other words, the test message will be displayed 99 times and the user will not be able to reach this speed!

If this is true, it's very tragic.

I guess it's better to get the test message outside of the "for" loop.
Or using a test message driven timer!

Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

for i = 0,99,1 do

function aob_register(sym, pat)
  instr = AOBScan(pat, "+r+w")
  addy = instr[i]
  instr.destroy()
  addy = tonumber(addy, 16)
  unregisterSymbol(sym)
  registerSymbol(sym, addy)
end

aob_register("block","e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00")

writeInteger("block","3868")
      if messageDialog('did it change?',mtWarning, mbYes,mbNo)==mbYes then
       i=98 end
  end

end

{$asm}
[DISABLE]

unregistersymbol(block)


Well, ideally - it'd loop the same number of times as there are results (1:1). I just wasn't sure how to make that happen.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 30

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon May 23, 2022 8:41 am    Post subject: Reply with quote

I haven't tested the code. You may need to fix some tests.
Restricted to 9 tests (9x10 adresd change) instead of 99 separate tests.

What does it do;
1) The timer works on the first interaction.
2) If "check" is 0, it will scan aob and store the results in the table.
3) With the instructions you give, 10 addresses change and the interaction message is activated.
4) If the result is "Yes", the loop ends.
5) If the result is "No", it takes the addresses from the table and changes 10 addresses each cycle.


Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

local aobTbl = {}
local check = 0
local findChnge = 0
if checkTimer then checkTimer.Destroy() checkTimer=nil end
checkTimer=createTimer(MainForm) checkTimer.Interval=1000
checkTimer.Enabled=false

function aob_register(sym)
checkTimer.Enabled=false
aa = tonumber(findChnge) + 10
 if aa < #aobTbl then
  for i = 1, 10 do
   addy = aobTbl[findChnge]
  --instr.destroy()
   addy = tonumber(addy, 16)
   unregisterSymbol(sym)
   registerSymbol(sym, addy)
   writeInteger("block","3868")
   findChnge=tonumber(findChnge) + i
   if i==10 then
    local answer= messageDialog('did it change?',mtWarning, mbYes,mbNo)
    if answer == mrYes then
     checkTimer.Enabled=false
     else --If "mrNo" the loop will repeat to change 10 more addresses.
     checkTimer.Enabled=true
    end
   end
  end
  else --The addresses listed in the table are sold out!
  showMessage("Ops! Something went wrong!\nCode not found!")
 end
end

function resTbl(aob)
checkTimer.Enabled=false
  instr = AOBScan(aob, "+r+w")
 if(instr ~= nil then
  for i=0,stringlist_getCount(instr) -1 do
   aobTbl[i+1] = instr[i]
  end
  check = 1
  aob_register("block")
 end
end
--aob_register("block","e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00")

checkTimer.OnTimer=function()
 if check==0 then
  resTbl("e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00")
  else
  aob_register("block")
 end
end
checkTimer.Enabled=true

{$asm}
[DISABLE]

unregistersymbol(block)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Mon May 23, 2022 8:56 am    Post subject: Reply with quote

Awesome! Just tried it and indicated missing ")" here:
if(instr ~= nil

So, I added it, then got this error:

Error:[string "local syntaxcheck,memrec=...
..."]:18: bad argument #1 to 'tonumber' (string expected, got nil)
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 30

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon May 23, 2022 12:10 pm    Post subject: Reply with quote

These have changed;

Code:
   addy = aobTbl[findChnge]
  --instr.destroy()
   addy = tonumber(addy, 16)




Code:
   addy1 = tostring(aobTbl[tonumber(findChnge)])
  --instr.destroy()
   addy = tonumber(addy1, 16)



Possible cause of error;
Code:
   findChnge=tonumber(findChnge) + i



Code:
   findChnge=tonumber(findChnge) + 1


Fix;
Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

local aobTbl = {}
local check = 0
local findChnge = 0
if checkTimer then checkTimer.Destroy() checkTimer=nil end
checkTimer=createTimer(MainForm) checkTimer.Interval=1000
checkTimer.Enabled=false

function aob_register(sym)
checkTimer.Enabled=false
aa = tonumber(findChnge) + 10
 if aa < #aobTbl then
  for i = 1, 10 do
   addy1 = tostring(aobTbl[tonumber(findChnge)])
  --instr.destroy()
   addy = tonumber(addy1, 16)
   unregisterSymbol(sym)
   registerSymbol(sym, addy)
   writeInteger("block","3868")
   findChnge=tonumber(findChnge) + 1
   if i==10 then
    local answer= messageDialog('did it change?',mtWarning, mbYes,mbNo)
    if answer == mrYes then
     checkTimer.Enabled=false
     else --If "mrNo" the loop will repeat to change 10 more addresses.
     checkTimer.Enabled=true
    end
   end
  end
  else --The addresses listed in the table are sold out!
  showMessage("Ops! Something went wrong!\nCode not found!")
 end
end

function resTbl(aob)
checkTimer.Enabled=false
  instr = AOBScan(aob, "+r+w")
 if instr ~= nil then
  for i=0,stringlist_getCount(instr) -1 do
   aobTbl[i+1] = instr[i]
  end
  check = 1
  aob_register("block")
 end
end
--aob_register("block","e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00")

checkTimer.OnTimer=function()
 if check==0 then
  resTbl("e0 0e 00 00 ?? 00 ?? 00 ?? ?? ?? ?? ?? 00")
  else
  aob_register("block")
 end
end
checkTimer.Enabled=true

{$asm}
[DISABLE]

unregistersymbol(block)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Mon May 23, 2022 1:57 pm    Post subject: Reply with quote

Dude! Worked exactly as I'd hoped! Thank you!!!!
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