View previous topic :: View next topic |
Author |
Message |
gir489 Grandmaster Cheater Reputation: 14
Joined: 03 Jan 2012 Posts: 835 Location: Maryland, United States
|
Posted: Tue Apr 18, 2023 1:31 pm Post subject: Undocumented function abort() |
|
|
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 |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Tue Apr 18, 2023 2:02 pm Post subject: |
|
|
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Tue Apr 18, 2023 2:51 pm Post subject: |
|
|
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 |
|
|
gir489 Grandmaster Cheater Reputation: 14
Joined: 03 Jan 2012 Posts: 835 Location: Maryland, United States
|
Posted: Tue Apr 18, 2023 3:08 pm Post subject: |
|
|
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 |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Tue Apr 18, 2023 3:22 pm Post subject: |
|
|
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 |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
Posted: Tue Apr 18, 2023 3:41 pm Post subject: |
|
|
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.
_________________
Last edited by AylinCE on Tue Apr 18, 2023 4:28 pm; edited 1 time in total |
|
Back to top |
|
|
gir489 Grandmaster Cheater Reputation: 14
Joined: 03 Jan 2012 Posts: 835 Location: Maryland, United States
|
Posted: Tue Apr 18, 2023 4:24 pm Post subject: |
|
|
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 |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Tue Apr 18, 2023 4:59 pm Post subject: |
|
|
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 |
|
|
gir489 Grandmaster Cheater Reputation: 14
Joined: 03 Jan 2012 Posts: 835 Location: Maryland, United States
|
Posted: Tue Apr 18, 2023 8:16 pm Post subject: |
|
|
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. |
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 |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
Posted: Wed Apr 19, 2023 12:56 am Post subject: |
|
|
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.
Description: |
|
Filesize: |
26.4 KB |
Viewed: |
2090 Time(s) |
|
Description: |
|
Filesize: |
25.55 KB |
Viewed: |
2090 Time(s) |
|
_________________
|
|
Back to top |
|
|
gir489 Grandmaster Cheater Reputation: 14
Joined: 03 Jan 2012 Posts: 835 Location: Maryland, United States
|
Posted: Wed Apr 19, 2023 12:57 pm Post subject: |
|
|
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 |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Wed Apr 19, 2023 1:52 pm Post subject: |
|
|
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 |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
Posted: Wed Apr 19, 2023 2:00 pm Post subject: Re: Undocumented function abort() |
|
|
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.
_________________
|
|
Back to top |
|
|
|