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 


Single stepping through LUA script

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
zappo
How do I cheat?
Reputation: 0

Joined: 20 Feb 2015
Posts: 3

PostPosted: Fri Feb 20, 2015 6:41 am    Post subject: Single stepping through LUA script Reply with quote

Hello all, totally new member here and i need a little guidance with CE - a lot actually, but i think it's best to start off small.

I have a small LUA script (not written by me), that I would like to understand what it's doing by stepping into it when the CE breakpoint is triggered. The script uses debugger_onBreakpoint() and tests the contents of EIP and if it matches a given value it does some stuff. I want to step into each line at it does its thing so i can understand what's happening.

Can this be done? I don't see any options in CE that connect it to the script other than loading/running it. I'm also new to CE and even newer to LUA so stepping over code as it's running will help a lot in learning both.
Back to top
View user's profile Send private message
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Fri Feb 20, 2015 7:52 am    Post subject: Reply with quote

Well what do you want to know exactly? The best way to see what a line of code does or will do is to play around with the code and tweak it and run it again seeing what your change has done. After changing a line or a few you can just hit execute script again, and the modified code will run again.

debugger_onBreakpoint() is exactly how it sounds. It is executed each time a breakpoint is hit. When you define that function, any Lua code inside of it will be executed upon every breakpoint, even manually placed breakpoints. So therefore to target a specific one, as your example you could check whether EIP/RIP equals a certain value. You can also check other registers, and modify registers.

You can single step with: debug_continueFromBreakpoint(co_stepinto)-F7 or debug_continueFromBreakpoint(co_stepover)-F8.
and contnue/run [F9] with co_run instead of co_stepinto/co_stepover

If you mean you want to debug the lua code itself, well I guess you could attach a second cheat engine to Cheat Engine, and debug that lol. However I think that would probably just add more confusion, what you want to do instead is add print() lines in order to see what effects your code is having, what's going on within it.

I use the Cheat Engine Help, "Script Engine" page with the various lua functions and options you can use, and also these forums for guidance. These lua functions only work because Dark Byte has implemented them within Cheat Engine. Many things that CE can do he has given Lua the capability of invoking them.

extra, opcode, bytes, address = splitDisassembledString(disassemble(RIP)) (RIP/EIP are interchangable/the same x64/x86 [what I mean is if you use the wrong one it wont matter it'll still be correct as based on whether the application is 64-bit or 32-bit, it knows what you mean])

That will give you the instruction pointer's(EIP/RIP) current instruction disassembled and split into 4 strings. I know that seems weird right, but in lua there can be more than 1 return value Very Happy

So after doing that you could print to see what it did. getNameFromAddress(address) is useful to go from ex. 0x400500 or "0x400500" to Game.exe+500. (or if theres a symbol CE was able to gather, Game.InitializeGame+104 or something like that)

print(getNameFromAddress(address)..": "..opcode.." "..bytes.." "..extra)

.. (two periods) concatenates or combines/attaches strings together [a part of the Lua language itself].

table.concat is another way that I discovered recently (built into Lua also)

print(table.concat(getNameFromAddress(address),": ",opcode," ",bytes," ",extra))
which is the almost the same as the double period way.

Another thing I like is variables don't have to be defined really, you define them as needed whenever you want just by giving something a value.
disassembledString=table.concat(getNameFromAddress(address),": ",opcode," ",bytes," ",extra)
print(disassembledString)

Would've been the same, except you created a 'disassembledString' variable as a string (since you gave it a string, later you could change it's type completely into something else simply by giving it a different value, very cool.)

To go from a string version of an address to one you can use in calculations: getAddress(stringVersionOfAddress)

for example: address="0x45831a" is different than: address=0x45831a

in the first the 'address' variable will contain a string with the address given, and the second will actually contain a numerical data type.

Alright that's pretty much the basics of it, unless you're more specific I'm not sure what else to say.
One final thing, if a function doesn't return anything it won't return 0, but instead 'nil'

so if you did returnValue=SomeFunctionCall(parameter1,parameter2)

then

if returnValue==nil then
--code here
--is executed if returnValue is nil
end


and

if returnValue~=nil
--code here
--is executed if return value is NON nil
end


-- on a line makes the rest of it a comment, so if you come back to your code after a while you can hopefully remember what you were doing Razz lol

EDIT: As per Dark Byte's post, YOU CAN SINGLE STEP THE LUA ACTUALLY! That is pretty nifty, and I wasn't aware of that before. You have to place your code in the Lua engine window though and you can click on the left side (which is the right side to click Wink) where you want the breakpoint and it will stop there before the line is executed and the option to step or continue lights up! I can't figure out how to open the Lua Engine window though without first executing a print("something") in the main Cheat Table Lua Script window! So do that if you can't locate it.

_________________


Last edited by SteveAndrew on Fri Feb 20, 2015 8:53 am; edited 2 times in total
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: Fri Feb 20, 2015 7:53 am    Post subject: Reply with quote

you can set lua breakpoints in the lua engine window. (just click on the left side)
it won't be able to step through callbacks like onbreakpoint though

use print for that

_________________
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 Feb 20, 2015 9:39 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
zappo
How do I cheat?
Reputation: 0

Joined: 20 Feb 2015
Posts: 3

PostPosted: Fri Feb 20, 2015 8:55 am    Post subject: Reply with quote

SteveAndrew wrote:
~~~ lots of interesting info here ~~~


I know i have a LOT to learn about both CE and LUA, but what I wanted to know was (and clearly i didn't articulate it very well) can I single step through a lua script and watch the effect is is having in real-time. I know i can put a ton of print all through the code, but it's not as elegant as like stepping through the CE asm debugger line by line.

Anyway, it turns out DB told me i can by clicking in the margin of the lua engine script window (which i discovered myself by accident).

All that extra info you provided almost made my brain explode ... one day it will make sense, but atm it's mostly jibberish and i'm only just starting out on my journey of discovery.

I now have another question.

The game the cheat is working on is an online game and is very sensitive to any lack of response by the client running on my comp. How do you go about debugging something that keeps kicking you out of the game when it senses a break in the client/server connection?


SteveAndrew wrote:

I can't figure out how to open the Lua Engine window though without first executing a print("something") in the main Cheat Table Lua Script window! So do that if you can't locate it.


Ctrl+Alt+Shift+L from the main CE window brings it up.
Back to top
View user's profile Send private message
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Sat Feb 21, 2015 5:37 pm    Post subject: Reply with quote

Ctrl+Alt+Shift+L, thanks for that I knew about CTRL+ALT+L which brings up the main lua scripting window instead...

As for those basic lua lines of code, I'm new to Lua myself so that's just what I learned recently. I used to not like it but now that there is syntax error recognition which does a pretty good job at telling you where the problem with your code is, I like it now Very Happy

Careful with the online game stuff, we're not really supposed to be doing that. Most things can't be done anyway as the data is stored server sided. Guaranteed. There are little things that can be done though. My suggestion would be to make some type of user input generating bot, that'll act like you, doing something in the game. Just a little something, enough to pretend like you're actually there... Then you'll have time to try and maybe get lucky and find something.

Anyway that's all I can say about that Very Happy So good luck, maybe you'll get lucky.

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