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 


messageDialog() cancel closing of AA script ?

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

Joined: 21 Nov 2013
Posts: 68
Location: Germany

PostPosted: Thu Nov 26, 2020 3:04 pm    Post subject: messageDialog() cancel closing of AA script ? Reply with quote

Hi,

is there a way to prevent the closing of an AA script via LUA messageDialog ?

LUA Script:
Code:

function testMe(params, syntaxcheck)
  local bResult = messageDialog("Some Error, you want close the script?", mtError, mbYes, mbNo)
  --pseudo code
  -- if bResult == mbYes then
  --   close AA script window
  -- else
  --   cancel the closing of AA script window
  -- end
end
registerAutoAssemblerCommand('testMe', testMe)


AA Script:
Code:

[ENABLE]
  testMe()
[DISABLE]


hope you get the idea
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Thu Nov 26, 2020 3:30 pm    Post subject: Reply with quote

find the AA form used for that script and then override the OnCloseQuery property.

Make it return false if you don't want to allow it to be closed

_________________
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
Reaper79
Advanced Cheater
Reputation: 2

Joined: 21 Nov 2013
Posts: 68
Location: Germany

PostPosted: Thu Nov 26, 2020 4:45 pm    Post subject: Reply with quote

Pewww, what a puzzle...

ok, first approach:

LUA Script:
Code:

function testMe(params, syntaxcheck)

  local frm = nil

  for i = 0, getFormCount() - 1 do
    frm = getForm(i)
    if frm.Caption == "Auto Assemble edit: TestMe" then
      break
    end
  end

  if frm ~= nil then
    frm.OnCloseQuery = function()
      return false
    end
  end

end


This works like a charm, you can't close the AA script anymore ^^

But how do i get the "sender" AA script single name without iteration?

Quote:
find the AA form used for that script
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Fri Nov 27, 2020 12:45 am    Post subject: Reply with quote

getForm(0) is the top window and the higher you go the deeper in the z-level you go.

so it's reasonable to assume the first aa window is the one you're interested in. (check ClassName if it is 'TfrmAutoInject')
Assuming that you run that script manually and not from a memoryrecord activate event, as there is no autoassembler window assigned then

_________________
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
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Fri Nov 27, 2020 1:51 am    Post subject: Reply with quote

Get description (from memrec) and pass it as params in your script
Code:
{$LUA}
  return ("define(memrecDesc,%s)"):format(memrec.Description);
{$ASM}
[ENABLE]
  testMe(memrecDesc)
[DISABLE]



And then testMe would look like this
Code:
function testMe(params, syntaxcheck)
  local frm = nil

  for i = 0, getFormCount() - 1 do
    frm = getForm(i)
    if frm.Caption == ("Auto Assemble edit: %s"):format(params) then
      break
    end
  end
  if frm ~= nil then
    frm.OnCloseQuery = function()
      return true
    end
  end

end
registerAutoAssemblerCommand('testMe', testMe)

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
Reaper79
Advanced Cheater
Reputation: 2

Joined: 21 Nov 2013
Posts: 68
Location: Germany

PostPosted: Fri Nov 27, 2020 9:34 am    Post subject: Reply with quote

Great answers. Thank you both.
Back to top
View user's profile Send private message
Reaper79
Advanced Cheater
Reputation: 2

Joined: 21 Nov 2013
Posts: 68
Location: Germany

PostPosted: Fri Nov 27, 2020 5:49 pm    Post subject: Reply with quote

Have to add something:

if a LUA Error occurs or you use print(), the Lua Engine form window is going to pop top.

so if you use
Code:
getForm(0)


is not a good idea ^^

but this is working at the moment:

Code:
local function _getForm()
  local frm = nil

  for i = 0, getFormCount() - 1 do
    frm = getForm(i)
    if frm.ClassName == 'TfrmAutoInject' then
      return frm
    end
  end
  if DEBUG then print('DEBUG: _getForm(): could not get active form!') end
  return nil
end


@DaSpamer
your define(sender) example is good, but i try to avoid as much lua code in the AA script as possible....

Great thing would be, if you click on the OK Button in AA script, and there is a LUA event / listener / callback....
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Fri Nov 27, 2020 6:49 pm    Post subject: Reply with quote

Quote:

Great thing would be, if you click on the OK Button in AA script, and there is a LUA event / listener / callback....


Code:

function forEachAndFutureForm(classname, func)
  local i
  for i=0,getFormCount()-1 do
    local f
    f=getForm(i)
    if f.ClassName==classname then
      func(f)
    end
  end

  registerFormAddNotification(function(f)
    if classname==f.ClassName then
      f.registerCreateCallback(func)
    end
  end)
end

forEachAndFutureForm('TfrmAutoInject',function(f)
  local originalExecute=f.btnExecute.OnClick
  f.btnExecute.OnClick=function(sender)
    --f.Assemblescreen.Lines.Text contains the script
    print("Before execute")
    originalExecute(sender)
    print("After execute")
  end
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


Last edited by Dark Byte on Fri Nov 27, 2020 7:18 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Reaper79
Advanced Cheater
Reputation: 2

Joined: 21 Nov 2013
Posts: 68
Location: Germany

PostPosted: Fri Nov 27, 2020 7:13 pm    Post subject: Reply with quote

Woho, 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 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