 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Jul 24, 2020 1:14 pm Post subject: |
|
|
If lua_pcall fails, it returns a non-zero which can be used to determine the error type. You would generally check the Lua stack top for a string after pcall has failed to obtain the error message like this:
| Code: |
const auto err = lua_pcall(L, 0, LUA_MULTRET, 0);
if (err != 0)
{
const auto msg = luaL_checkstring(L, -1);
if (msg != nullptr)
printf_s(err);
}
|
_________________
- Retired. |
|
| Back to top |
|
 |
whimzala How do I cheat?
Reputation: 0
Joined: 24 Jul 2020 Posts: 2
|
Posted: Sat Jul 25, 2020 12:12 pm Post subject: |
|
|
| atom0s wrote: | If lua_pcall fails, it returns a non-zero which can be used to determine the error type. You would generally check the Lua stack top for a string after pcall has failed to obtain the error message like this:
| Code: |
const auto err = lua_pcall(L, 0, LUA_MULTRET, 0);
if (err != 0)
{
const auto msg = luaL_checkstring(L, -1);
if (msg != nullptr)
printf_s(err);
}
|
|
So I got to this:
| Code: |
mov ecx,[esp+04] // lua state
push 0 // error
push -1 // results
push 0 // args
push ecx // push state
call lua_pcall
add esp,10
// since eax seems to be either 0 or nonzero compare and call checkstring
cmp eax,0
je short exit
mov ecx,[esp+04]
push eax
push ecx
call "lua51.dll"+6300
add esp,0C
|
I've noticed after pcall is called that the EAX would be 0 if the script had no errors, but would return a nonzero if there was an error, so knowing this i'm calling checkstring and pushing eax which should be int narg in checkstring
Everything runs fine, no crashes, but i'm still lost on simply returning the string now? or the error in this case.
That's assuming what I have down is correct, and not complete gibberish..
Btw thanks for helping
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Jul 25, 2020 1:24 pm Post subject: |
|
|
luaL_checkstring is a wrapper around other Lua API:
| Code: |
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
|
| Code: |
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, size_t *l);
|
So you would want to call 'luaL_checklstring' with arg being -1 as the stack top index which should have the error string. The return from that will then be a pointer to the string if there was one on the stack top, otherwise, it'll return 0 (null).
_________________
- Retired. |
|
| Back to top |
|
 |
|
|
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
|
|