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 


[HELP] CE LUA Scripting - ZxPwds ULTIMATE help thread!
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
ZxPwds
Advanced Cheater
Reputation: 0

Joined: 27 Oct 2015
Posts: 59

PostPosted: Thu Oct 29, 2015 3:58 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Maybe that memory isn't writable or something. Try this:
Code:
function CEButton2Click(sender)
  fullAccess(getAddress("Theduel.exe")+0x3087C0,8)
  writeDouble(getAddress("Theduel.exe")+0x3087C0,2000)
end


Well ParkourPenguin I'm very happy with all the help you gave me.
That final snippet you gave me worked like a charm. I would love to be able
to get in touch with you VIA skype if possible if I ever have small questions
if you wouldn't mind ? You can PM me your skype or I will leave it below this
post. I do have another question.

What does: fullAccess(getAddress("Theduel.exe")+0x3087C0,Cool do exactly ?
How come using this works?


Skype: ZxPwds


.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Oct 29, 2015 4:27 pm    Post subject: Reply with quote

As for what was wrong, I'd guess that part of memory ("Theduel.exe"+0x3087C0) was read-only. AKA: your computer won't let you write anything to it. Maybe in the source code that variable was declared as a constant or something, I dunno.

fullAccess(address,size) makes all the memory starting at "address" writable and executable. "size" is just the number of bytes you're doing this for. Since a double takes up 8 bytes of space, 8 is a fine number to put down for the size.

For future reference, writeDouble(address,value) will return true on success. So, if you want to be completely safe, you should have something like this in your code to test for it:
Code:
if not writeDouble(address,value) then
  fullAccess(address,8)
  if not writeDouble(address,value) then
    showMessage(string.format("Could not write to address %X", address))
  end
end

Edit: formatted code so the address shows up as a hex number.

_________________
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
ZxPwds
Advanced Cheater
Reputation: 0

Joined: 27 Oct 2015
Posts: 59

PostPosted: Thu Oct 29, 2015 5:21 pm    Post subject: New Question - Hotkeys + Timers Reply with quote

ParkourPenguin wrote:
As for what was wrong, I'd guess that part of memory ("Theduel.exe"+0x3087C0) was read-only. AKA: your computer won't let you write anything to it. Maybe in the source code that variable was declared as a constant or something, I dunno.

fullAccess(address,size) makes all the memory starting at "address" writable and executable. "size" is just the number of bytes you're doing this for. Since a double takes up 8 bytes of space, 8 is a fine number to put down for the size.

For future reference, writeDouble(address,value) will return true on success. So, if you want to be completely safe, you should have something like this in your code to test for it:
Code:
if not writeDouble(address,value) then
  fullAccess(address,8)
  if not writeDouble(address,value) then
    showMessage(string.format("Could not write to address %X", address))
  end
end

Edit: formatted code so the address shows up as a hex number.



I do not wish to create a new thread for this but I was hopping for you to add me on skype but I do not think you want that.
So I will ask here, It's just Instant Messaging would be a lot quicker ;P. But this is fine also.

I'm also going to need to WriteMemory to "Float" Type values. So what would I put for that ?

___________________________________________________________________________

For Double Type Values:

Code:
if not writeDouble(address,value) then
  fullAccess(address,8)
  if not writeDouble(address,value) then
    showMessage(string.format("Could not write to address %X", address))
  end
end


For Double Type Values:

Code:

function CEButton2Click(sender)
  fullAccess(getAddress("Theduel.exe")+0x3087C0,8)
  writeDouble(getAddress("Theduel.exe")+0x3087C0,2000)
end




If I want to do this to Float Type Values how would I do that? The amount of Bytes in a Double is 8 but what
would I do for a Float Type?
___________________________________________________________________________


See when I was making this trainer in Vb.Net it didn't let me WriteProcessMemory after the Game had an update.
It was just like now when it was not letting me WriteMemory until you found the solution. So I'm guessing I can just
find a way to do the same on Vb.Net.

Quote:
("Theduel.exe"+0x3087C0) was read-only. AKA: your computer won't let you write anything to it. Maybe in the source code that variable was declared as a constant or something, I dunno.

fullAccess(address,size) makes all the memory starting at "address" writable and executable. "size" is just the number of bytes you're doing this for. Since a double takes up 8 bytes of space, 8 is a fine number to put down for the size.



But in vb.net it's just extra code for nothing I want to see where this is taking me. I see a couple of controls I can use
in this trainer like I would use in Vb.Net so I'm going to see how far this will go.

I wanted to now start making hotkeys. I'm assuming using hotkeys your going to need to use timers to listen for key inputs.
If you could maybe help me with that instead of using ControlBox buttons, I find that is really ghetto way of activating hacks.

I guess my question is: How can I make "Hotkeys" using timers?
Using: NUMPAD KEYS


.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Oct 29, 2015 7:59 pm    Post subject: Reply with quote

You can write a float to memory with writeFloat(address,value) the same way you can with a double. Floats take up 4 bytes of space, so if writing to it initially fails, you can use fullAccess(address,4) to let you write to it.

If you want to make ROM (Read Only Memory) writable in vb.net Dark Byte said you can use something called VirtualProtectEx in this post. I found an article on it that looks somewhat informational here.

As for hotkeys, CE makes it even easier than that. All you need to do is use the method createHotkey(function, keys...). "keys" is some integer constant that's declared in defines.lua which should be in your main CE directory (also located online here). "function" is some function that's called when you press the key.

For example, this Lua code should work when you execute it:
Code:
function toggleJumpHack()
  if readDouble(getAddress("mem")) == 800 then
    writeDouble(getAddress("Theduel.exe")+0x3087C0,2000)
  else
    writeDouble(getAddress("Theduel.exe")+0x3087C0,800)
  end
end

if jumpHackHotkey and jumpHackHotkey.destroy then jumpHackHotkey.destroy() end
jumpHackHotkey = nil
jumpHackHotkey = createHotkey(toggleJumpHack, VK_J, VK_LCONTROL)
jumpHackHotkey.DelayBetweenActivate = 1000

When you hold left control and J, it will run toggleJumpHack even if you're not viewing the main CE window. DelayBetweenActivate should be self-explanatory (it's in milliseconds). That's there so you don't deactivate the cheat if you hold the keys down for too long.

_________________
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
ZxPwds
Advanced Cheater
Reputation: 0

Joined: 27 Oct 2015
Posts: 59

PostPosted: Thu Oct 29, 2015 8:21 pm    Post subject: Reply with quote

Dam I feel stupid I just made a new topic about hotkeys. Darn!
Thanks for the reply.

What does "nil" mean ?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Oct 29, 2015 8:32 pm    Post subject: Reply with quote

http://www.lua.org/pil/2.1.html

In this case jumpHackHotkey = nil and the line before it are deleting whatever the variable "jumpHackHotkey" had inside of it before assigning something new to it. This is mostly just to clean up the old stuff if you run this script more than once (which you'll most likely do).

_________________
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
ZxPwds
Advanced Cheater
Reputation: 0

Joined: 27 Oct 2015
Posts: 59

PostPosted: Thu Oct 29, 2015 8:42 pm    Post subject: Reply with quote

Thanks a lot the code worked perfectly.

I also created a CECheckbox1 and I wish to make it so when I do push CTRL+J the
checkbox state will be checked along with changing the color of the labal/caption.

in vb.net i would do this:

**** ON ****
CheckBox1.Checked = True
CheckBox1.Color = Color.Red

**** OFF ****
CheckBox1.Checked = True
CheckBox1.Color = Color.Black





function toggleJumpHack()
if readDouble(getAddress("Theduel.exe")+0x3087C0) == 900 then
fullAccess(getAddress("Theduel.exe")+0x3087C0,Cool
writeDouble(getAddress("Theduel.exe")+0x3087C0,2000)
checkbox_getState(UDF1.CECheckbox1) = 1 // Does not work
// I also want to change the caption color of the checkbox
else
fullAccess(getAddress("Theduel.exe")+0x3087C0,Cool
writeDouble(getAddress("Theduel.exe")+0x3087C0,900)
checkbox_getState(UDF1.CECheckbox1) = 0 // Does not work
// I also want to change the caption color of the checkbox
end
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Oct 29, 2015 8:53 pm    Post subject: Reply with quote

Code:
function toggleJumpHack()
  if readDouble(getAddress("mem")) == 800 then
    writeDouble(getAddress("mem"),2000)
    UDF1.CECheckbox1.Checked = true
  else
    writeDouble(getAddress("mem"),800)
    UDF1.CECheckbox1.Checked = false
  end
end

_________________
I don't know where I'm going, but I'll figure it out when I get there.


Last edited by ParkourPenguin on Thu Oct 29, 2015 9:11 pm; edited 2 times in total
Back to top
View user's profile Send private message
ZxPwds
Advanced Cheater
Reputation: 0

Joined: 27 Oct 2015
Posts: 59

PostPosted: Thu Oct 29, 2015 9:11 pm    Post subject: Reply with quote

Thank you that worked perfectly as well.
Sorry for all my questions but I have 2 additional questions

1: I also want to change the color of the [Caption] when activated.
2: Is it possible to give my address *0x3087C0* a string name so this way
I can easily update the address when the game updates. This will save me time
instead of copy and pasting the new address 5 - 6 times.

WriteDouble(getAddress("Theduel.exe")+0x3087C0,2000)

EXAMPLE:

In VB.NET I would do something like:

Dim JumpString As String = "0062AB6C"

so I can then do this

WriteDouble(getAddress("Theduel.exe")+JumpString,2000)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Oct 29, 2015 9:17 pm    Post subject: Reply with quote

Oh yeah, the color of the font. I dunno what to tell you. Theoretically, you can change it via UDF1.CECheckbox1.Font.setColor(0x00BBGGRR), but for the life of me I can't change the color of the caption of anything besides labels, even when editing the form directly. If it works for you, great, but if it doesn't and you really want the font to change color, you could just have no caption on the checkbox and instead put a label next to it and change the color of that.

As for the address, you can instead just assign the address itself to a global variable and use that like so:
Code:
jumpAddress = getAddress("Theduel.exe")+0x3087C0
...
writeDouble(jumpAddress,2000)

_________________
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
ZxPwds
Advanced Cheater
Reputation: 0

Joined: 27 Oct 2015
Posts: 59

PostPosted: Thu Oct 29, 2015 9:29 pm    Post subject: Reply with quote

Thank you very much I appreciate it.

I guess I can always use a label. So If I wanted to change a label color
i would do this?

UDF1.CELabel1.Font.setColor(0x00BBGGRR)

Also: UDF1.CELabel1.Font.setColor(0x00BBGGRR)

How do I know what color that is? is it hex? color? RGB or what ?

Example #E00B0B is red



.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Oct 29, 2015 9:43 pm    Post subject: Reply with quote

In Lua, the prefix 0x denotes that the following number is in hexadecimal.

It's actually an RGB stored as a 4-byte value. 0x00BBGGRR is just a pseudo hex number I made up. BB is blue, GG is green, and RR is red. So, if you wanted to make it red, you would call setColor(0x000000FF). If you want a light blue aqua color, use setColor(0x00FFFF00). You don't really need those first couple 0s, using setColor(0xBBGGRR) is fine, it's just that the color itself is a 4-byte integer, so when I set it I like to explicitly set it to 4 bytes, not 3.

_________________
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
ZxPwds
Advanced Cheater
Reputation: 0

Joined: 27 Oct 2015
Posts: 59

PostPosted: Thu Oct 29, 2015 9:47 pm    Post subject: Reply with quote

I understand thank you.


And for : jumpAddress = getAddress("Theduel.exe")+0x3087C0
the following code I got:

Code:
----------------------------------------------------------------
----------------------------------------------------------------
jumpAddress = getAddress("Theduel.exe")+0x3087C0

function toggleJumpHack()

  if readDouble(getAddress(jumpAddress)) == 900 then
    fullAccess(getAddress(jumpAddress),8)
    writeDouble(getAddress(jumpAddress),2000)
   UDF1.CECheckBoxJump.Checked = true

  else
    fullAccess(getAddress(jumpAddress),8)
    writeDouble(getAddress(jumpAddress),900)
    UDF1.CECheckBoxJump.Checked = false
  end
end

if jumpHackHotkey and jumpHackHotkey.destroy then
jumpHackHotkey.destroy()
end

jumpHackHotkey = nil
jumpHackHotkey = createHotkey(toggleJumpHack, VK_J, VK_LCONTROL)
jumpHackHotkey.DelayBetweenActivate = 1000

----------------------------------------------------------------
----------------------------------------------------------------


Now the value wont change.


.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Oct 29, 2015 9:56 pm    Post subject: Reply with quote

As in my example, you just use this:
writeDouble(jumpAddress,2000)
...not:
writeDouble(getAddress(jumpAddress),2000)

From the main.lua file:
Quote:
getAddress(string, local OPTIONAL): returns the address of a symbol. Can be a modulename or an export.

AKA getAddress() is only used to dereference a modulename (i.e. Theduel.exe) or a userdefined symbol you registered yourself in CE.

_________________
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
ZxPwds
Advanced Cheater
Reputation: 0

Joined: 27 Oct 2015
Posts: 59

PostPosted: Thu Oct 29, 2015 10:09 pm    Post subject: Reply with quote

What would I put for fullAccess?

I tried the following and it doesn't work

Code:
 fullAccess(jumpAddress)
 fullAccess(jumpAddress),8)
 fullAccess(getAddress(jumpAddress),8)




Also do I need to have

Code:
jumpAddress = getAddress("Theduel.exe")+0x3087C0

inside the function ?
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
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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