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 


Undocumented function abort()

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
gir489
Grandmaster Cheater
Reputation: 14

Joined: 03 Jan 2012
Posts: 835
Location: Maryland, United States

PostPosted: Tue Apr 18, 2023 1:31 pm    Post subject: Undocumented function abort() Reply with quote

I had to add a warning to one of my scripts for RE4, telling the user not to use the script outside of its usecase, because someone reported that it corrupted their game. I spent a few minutes on the Bing and the Wiki looking for a way to make the script not enable when the user clicked No. At first I tried return, but that did nothing, the script would still enable regardless of what was selected. I then tried to look for solutions, someone posted something about getting the address list and finding the script by name and then setting the Activate member to false. I tried that, but it didn't work. I just started trying random function names, and found abort() worked. It would make the script not enable when no was selected.

Here is a snippet of the script. (I remember Cheat Engine purged all cheats posted so I won't post the whole thing, if you want to see it, it's on fearless)

Code:
{ Game   : re4.exe
  Version: ‎Sunday, ‎March ‎19, ‎2023 11:28:19 PM
  Date   : 2023-04-04
  Author : gir489

  One hit kill the lake monster.
}
[ENABLE]
{$lua}
if (messageDialog("This script should only be used during the fight. If used elsewhere, it could corrupt your game. Are you sure you want to enable it now? Disable it after the fight is over.",mtConfirmation, mbYes, mbNo) == mrNo) then
   abort()
end
{$asm}
//Do the things here


All I'm really reporting here, is that abort() is a highly useful undocumented Lua function that can be used for scripts. I think it should be added to the wiki or something.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1054
Location: 0x90

PostPosted: Tue Apr 18, 2023 2:02 pm    Post subject: Reply with quote

It doesn't appear to be a function in 7.5:
Quote:

Error:[string "function smallerthan(a,b)
..."]:3: attempt to call a nil value (global 'abort')
Script Error


I used the following test code:
Code:

1:function smallerthan(a,b)
2:      if a > b then
3:         abort()
4:      else
5:         return a
6:      end
7:end
8:
9:smallerthan(15,10)


This is the result when testing your code:
Quote:

Error:[string "if (messageDialog("This script should only be..."]:2: attempt to call a nil value (global 'abort')
Script Error
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: Tue Apr 18, 2023 2:51 pm    Post subject: Reply with quote

you can also do
Code:

error('not an error')

_________________
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
gir489
Grandmaster Cheater
Reputation: 14

Joined: 03 Jan 2012
Posts: 835
Location: Maryland, United States

PostPosted: Tue Apr 18, 2023 3:08 pm    Post subject: Reply with quote

LeFiXER wrote:
It doesn't appear to be a function in 7.5:
Quote:

Error:[string "function smallerthan(a,b)
..."]:3: attempt to call a nil value (global 'abort')
Script Error


I used the following test code:
Code:

1:function smallerthan(a,b)
2:      if a > b then
3:         abort()
4:      else
5:         return a
6:      end
7:end
8:
9:smallerthan(15,10)


This is the result when testing your code:
Quote:

Error:[string "if (messageDialog("This script should only be..."]:2: attempt to call a nil value (global 'abort')
Script Error

It's only a function when used as a script snippet.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1054
Location: 0x90

PostPosted: Tue Apr 18, 2023 3:22 pm    Post subject: Reply with quote

gir489 wrote:
LeFiXER wrote:
It doesn't appear to be a function in 7.5:
Quote:

Error:[string "function smallerthan(a,b)
..."]:3: attempt to call a nil value (global 'abort')
Script Error


I used the following test code:
Code:

1:function smallerthan(a,b)
2:      if a > b then
3:         abort()
4:      else
5:         return a
6:      end
7:end
8:
9:smallerthan(15,10)


This is the result when testing your code:
Quote:

Error:[string "if (messageDialog("This script should only be..."]:2: attempt to call a nil value (global 'abort')
Script Error

It's only a function when used as a script snippet.


I also tested within a script. I made sure to test both the Lua Engine and an Auto Assembler script before reporting my findings.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Tue Apr 18, 2023 3:41 pm    Post subject: Reply with quote

Code:
{ Game   : re4.exe
  Version: ‎Sunday, ‎March ‎19, ‎2023 11:28:19 PM
  Date   : 2023-04-04
  Author : gir489

  One hit kill the lake monster.
}

[ENABLE]
{$lua}
local answer = messageDialog("This script should only be used during the fight. If used elsewhere, it could corrupt your game. Are you sure you want to enable it now?",mtConfirmation, mbYes, mbNo)
   if answer == mrYes then
    showMessage(" Disable it after the fight is over.")
   else
    error() --If it gives a warning, confirm anyway. It will work.
    return
   end
showMessage("Script activated!")

{$asm}
//Do the things here

[DISABLE]
//Do the things here
{$lua}
showMessage("Script terminated!")


EDIT :
If "NO" is clicked on the warning message, the script will stop, but the active box will still be checked.
I re-edited the code with @DB's advice.

Dark Byte wrote:
error('no') will stop it from activating


Now if "NO" is selected, the script will return leaving an empty box.

_________________
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


Last edited by AylinCE on Tue Apr 18, 2023 4:28 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
gir489
Grandmaster Cheater
Reputation: 14

Joined: 03 Jan 2012
Posts: 835
Location: Maryland, United States

PostPosted: Tue Apr 18, 2023 4:24 pm    Post subject: Reply with quote

LeFiXER wrote:

I also tested within a script. I made sure to test both the Lua Engine and an Auto Assembler script before reporting my findings.


https://youtu.be/8bFoE5jzjWs Video proof of it working.

AylinCE wrote:
Code:
{ Game   : re4.exe
  Version: ‎Sunday, ‎March ‎19, ‎2023 11:28:19 PM
  Date   : 2023-04-04
  Author : gir489

  One hit kill the lake monster.
}

[ENABLE]
{$lua}
local answer = messageDialog("This script should only be used during the fight. If used elsewhere, it could corrupt your game. Are you sure you want to enable it now?",mtConfirmation, mbYes, mbNo)
   if answer == mrYes then
    showMessage(" Disable it after the fight is over.")
   else
    return
   end
showMessage("Script activated!")

{$asm}
//Do the things here

[DISABLE]
//Do the things here
{$lua}
showMessage("Script terminated!")


I already said I tried return and it did nothing, did you not read what I posted? FFS.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Tue Apr 18, 2023 4:35 pm    Post subject: Reply with quote

gir489 wrote:

I already said I tried return and it did nothing, did you not read what I posted? FFS.


Try again now. not "abort()". "error()" is more efficient.

https://forum.cheatengine.org/viewtopic.php?p=5784250#5784250

_________________
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
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1054
Location: 0x90

PostPosted: Tue Apr 18, 2023 4:59 pm    Post subject: Reply with quote

gir489 wrote:
LeFiXER wrote:

I also tested within a script. I made sure to test both the Lua Engine and an Auto Assembler script before reporting my findings.


https://youtu.be/8bFoE5jzjWs Video proof of it working.


I didn't disbelieve you, just saying it wouldn't work for me. Perhaps there are other criteria for that function to work like being attached to a process. When testing Lua code I don't always attach to a process unless I have require access to memory.
Back to top
View user's profile Send private message
gir489
Grandmaster Cheater
Reputation: 14

Joined: 03 Jan 2012
Posts: 835
Location: Maryland, United States

PostPosted: Tue Apr 18, 2023 8:16 pm    Post subject: Reply with quote

LeFiXER wrote:
gir489 wrote:
LeFiXER wrote:

I also tested within a script. I made sure to test both the Lua Engine and an Auto Assembler script before reporting my findings.


https://youtu.be/8bFoE5jzjWs Video proof of it working.


I didn't disbelieve you, just saying it wouldn't work for me. Perhaps there are other criteria for that function to work like being attached to a process. When testing Lua code I don't always attach to a process unless I have require access to memory.

AylinCE wrote:
gir489 wrote:

I already said I tried return and it did nothing, did you not read what I posted? FFS.


Try again now. not "abort()". "error()" is more efficient.

https://forum.cheatengine.org/viewtopic.php?p=5784250#5784250


It seems all calling abort or error does is just call an invalid function, which causes the script running to fault.

Calling error() just displays that "an error occured."

Calling error("message") like Dark Byte suggested causes it to error out with the message.

Calling abort() just errors out with the error that the function is missing.

So it really doesn't matter what you do to cause an error, as long as it's silent about it.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Wed Apr 19, 2023 12:56 am    Post subject: Reply with quote

I think you are wrong!
This is an expression defined by lua. (error())
The other is an undefined and imposed statement. (abord() whatever())

In fact, it's like trying to pollute it, imposing statements that don't exist.
Wrong way for future learners.

One of the examples in the pictures gives a more deterrent warning.

Take Global or Defined expressions as an example and show them as examples.

What may not be a "Problem" for you may be a "Confusion" for new learners.



ek2.png
 Description:
 Filesize:  26.4 KB
 Viewed:  2008 Time(s)

ek2.png



ek1.PNG
 Description:
 Filesize:  25.55 KB
 Viewed:  2008 Time(s)

ek1.PNG



_________________
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
gir489
Grandmaster Cheater
Reputation: 14

Joined: 03 Jan 2012
Posts: 835
Location: Maryland, United States

PostPosted: Wed Apr 19, 2023 12:57 pm    Post subject: Reply with quote

AylinCE wrote:
I think you are wrong!
This is an expression defined by lua. (error())
The other is an undefined and imposed statement. (abord() whatever())

In fact, it's like trying to pollute it, imposing statements that don't exist.
Wrong way for future learners.

One of the examples in the pictures gives a more deterrent warning.

Take Global or Defined expressions as an example and show them as examples.

What may not be a "Problem" for you may be a "Confusion" for new learners.

What? I think you didn't read what I said again. All I said is that all 3 scenarios cause a fault in the script, whatever error it makes is irrelevant, because the end result is the same. Look at your two messages. They both literally say the same thing.

"Lua error in the script at line 10"

It doesn't matter what the fucking error is, just as long as you error the script out, you will get the described behaviour in the OP post.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Wed Apr 19, 2023 1:52 pm    Post subject: Reply with quote

gir489 wrote:
All I'm really reporting here, is that abort() is a highly useful undocumented Lua function that can be used for scripts.
It's not a function. It never was- not in the main Lua script window, not in the Lua Engine window, and not in AA scripts.

The only reason why it works is because it isn't a function. You'd get the same behaviour with this:
Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

local response = messageDialog("Really enable the script?",mtConfirmation, mbYes, mbNo)
if response ~= mrYes then
  qKwUb2xCjXpoRekSjYjr()  -- not a function
end
{$asm}

[DISABLE]

gir489 wrote:
It seems all calling abort or error does is just call an invalid function, which causes the script running to fault.
`error` is actually a function defined by the Lua API:
https://www.lua.org/manual/5.3/manual.html#pdf-error

The reason why `error` is preferred over calling something that's not a function is because you get information about what caused the script to fail.
Code:
error'script aborted by user'


In any case, I think the most appropriate way of doing this is to not treat it as an error in the first place. Memory records have an OnActivate event that can be used to abort activation:
Code:
-- main Lua script window

function memrecConfirmActivate(memrec, before, currentstate)
  if not before then return true end

  local response = messageDialog("Really enable the script?",mtConfirmation, mbYes, mbNo)
  return response == mrYes
end

-- could also use getMemoryRecordByDescription, getMemoryRecordByID
local memrec = AddressList.createMemoryRecord()
memrec.Description = 'AA Confirm Script'
memrec.Type = vtAutoAssembler
memrec.Script = [[
[ENABLE]
[DISABLE]
]]

memrec.OnActivate = memrecConfirmActivate

Of course, simply raising an error in a {$lua} block is usually more convenient.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Wed Apr 19, 2023 2:00 pm    Post subject: Re: Undocumented function abort() Reply with quote

gir489 wrote:
All I'm really reporting here, is that abort() is a highly useful undocumented Lua function that can be used for scripts. I think it should be added to the wiki or something.


I will not prolong the matter.
I didn't find it right to give (or recommend) an undefined function to the user and to glorify that function.
If it does the same job as the defined functions, recommend the defined one.
This is my opinion. Of course I won't insist.

Probably @DB will find a solution to this soon. And this long thread will be closed. Idea

_________________
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
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