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 


Make object always have same coordinates as mouse

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
mindfreak516
Newbie cheater
Reputation: 0

Joined: 13 Nov 2011
Posts: 24

PostPosted: Mon Dec 10, 2012 5:05 pm    Post subject: Make object always have same coordinates as mouse Reply with quote

i need little help with this script..
it should copy mouse coordinates to the coordinates of a ball thus making the ball always follow the mouse pointer..
i wrote a script that saves mouse coordinates and then copies them into coordinates of a ball.. the problem is that the ball is not acting as i want it.. upon activating the script, ball just flies out of the screen with lightning speed..
btw, the game is called Peggle Deluxe.. you can download free trial version (i also have that version) from popcap website
it's a very small and simple game, but it's good for my purpose of making this cheat/hack..

so please, if anyone could help me, here is the script i wrote:

Code:

//newmem1 = BallY
//newmem2 = BallX
//newmem6 = MouseY
//newmem11 = MouseX

[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
alloc(newmem11,2048) //2kb should be enough
label(returnhere11)
label(originalcode11)
label(exit11)

alloc(_mX,4)
alloc(_mY,4)
registersymbol(_mX)
registersymbol(_mY)

newmem11: //this is allocated memory, you have read,write,execute access
//place your code here

mov [_mX],eax //save mouseX

originalcode11:
mov [ebx+6C],eax
fadd dword ptr [ebp-0C]

exit11:
jmp returnhere11

"popcapgame1.exe"+4120F:
jmp newmem11
nop
returnhere11:

alloc(newmem6,2048) //2kb should be enough
label(returnhere6)
label(originalcode6)
label(exit6)

newmem6: //this is allocated memory, you have read,write,execute access
//place your code here

mov [_mY],ecx //save mouseY

originalcode6:
mov [ebx+70],ecx
pop edi
pop esi

exit6:
jmp returnhere6

"popcapgame1.exe"+4121B:
jmp newmem6
returnhere6:

alloc(newmem2,2048) //2kb should be enough
label(returnhere2)
label(originalcode2)
label(exit2)

newmem2: //this is allocated memory, you have read,write,execute access
//place your code here

//code that i wrote to copy mouse position to ball coordinate
push eax
mov eax,[_mX]
mov [edi+000000EC],eax
pop eax

originalcode2:
//fstp dword ptr [edi+000000EC] -> original code
fstp dword ptr [edi+0000012C] //changed code so it stores value in unused bytes

exit2:
jmp returnhere2

"popcapgame1.exe"+7F492:
jmp newmem2
nop
returnhere2:

alloc(newmem,2048) //2kb should be enough
label(returnhere)
label(originalcode)
label(exit)

newmem: //this is allocated memory, you have read,write,execute access
//place your code here

//code that i wrote to copy mouse position to ball coordinate
push eax
mov eax,[_mY]
mov [edi+000000F0],eax
pop eax

originalcode:
//fstp dword ptr [edi+000000F0] -> original code
fstp dword ptr [edi+00000120] //changed code so it stores value in unused bytes

exit:
jmp returnhere

"popcapgame1.exe"+7F4A4:
jmp newmem
nop
returnhere:


 
 
[DISABLE]
//code from here till the end of the code will be used to disable the cheat
dealloc(newmem11)
"popcapgame1.exe"+4120F:
mov [ebx+6C],eax
fadd dword ptr [ebp-0C]
//Alt: db 89 43 6C D8 45 F4
dealloc(newmem6)
"popcapgame1.exe"+4121B:
mov [ebx+70],ecx
pop edi
pop esi
//Alt: db 89 4B 70 5F 5E
dealloc(newmem2)
"popcapgame1.exe"+7F492:
fstp dword ptr [edi+000000EC]
//Alt: db D9 9F EC 00 00 00
dealloc(newmem)
"popcapgame1.exe"+7F4A4:
fstp dword ptr [edi+000000F0]
//Alt: db D9 9F F0 00 00 00
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Mon Dec 10, 2012 6:18 pm    Post subject: Reply with quote

---
_________________
I'm rusty and getting older, help me re-learn lua.


Last edited by daspamer on Mon Dec 10, 2012 7:13 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Mon Dec 10, 2012 7:05 pm    Post subject: Reply with quote

The core of your problem is that you mix up between float and integer representation. I assume that when you scanned for the mouse coordinates you found that those were "4 byte" variables, which means 4 byte INTEGERs and the ball coordinates were floats (which also take 4 bytes in memory each).

Anyway 1 as an integer corresponds in memory to 01 00 00 00.
1.0 as a float corresponds in memory to 00 00 80 3F.
Even worse: if your mouse cursor is at x=-320 (c0 FE FF FF) or any negative value, that corresponds to NaN (Not a Number) in float representation, that's probably why your ball goes ballistic.

Anyway to load an integer and convert it to float use the fild (Float Integer LOad) instruction.

Here is a patched script. Despite a lot of cleanup/renaming it's still YOUR script, with just a little fild fixup.

A remark though, try to avoid using multiple allocs because each time you ask for bytes that way windows allocates 4096 bytes (or the smallest 4096 multiple that contains the desired amount of bytes), even if you just asked for 4 bytes.

Code:
[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
alloc(code,2048) //2kb should be enough

//code locations
label(SaveMouseX)
label(SaveMouseX_return)
label(SaveMouseY)
label(SaveMouseY_return)
label(WriteBallX)
label(WroteBallX)
label(WriteBallY)
label(WroteBallY)
//variable declaration
label(_mX)
label(_mY)
/*registersymbol(_mX) //uncomment if you need them elsewhere
registersymbol(_mY)*/

//hooks
"popcapgame1.exe"+4120F:
  jmp SaveMouseX
  nop
SaveMouseX_return:

"popcapgame1.exe"+4121B:
  jmp SaveMouseY
SaveMouseY_return:

"popcapgame1.exe"+7F4A4:
  jmp WriteBallY
  nop
WroteBallY:

"popcapgame1.exe"+7F492:
  jmp WriteBallX
  nop
WroteBallX:

//code cave
code: //this is allocated memory, you have read,write,execute access
//place your code here
SaveMouseX:
  mov [_mX],eax //save mouseX
  //original code
  mov [ebx+6C],eax
  fadd dword ptr [ebp-0C]
jmp SaveMouseX_return

SaveMouseY:
  mov [_mY],ecx //save mouseY
  //original code
  mov [ebx+70],ecx
  pop edi
  pop esi
jmp SaveMouseY_return


//code that i wrote to copy mouse position to ball coordinate
WriteBallX:
  fstp st(0) //send the current value in st0 to oblivion
  fild dword [_mX] //load an integer (_mX), convert it to a float, and store it in st0
  fstp dword ptr[edi+000000EC]
jmp WroteBallX

WriteBallY:
  fstp st(0) //send the current value in st0 to oblivion
  fild dword [_mY]
  fstp dword ptr [edi+000000F0]
jmp WroteBallY

//variable storage
_mX:
dd 0

_mY:
dd 0






[DISABLE]
//code from here till the end of the code will be used to disable the cheat
dealloc(code)

"popcapgame1.exe"+4120F:
  mov [ebx+6C],eax
  fadd dword ptr [ebp-0C]
  //Alt: db 89 43 6C D8 45 F4

"popcapgame1.exe"+4121B:
  mov [ebx+70],ecx
  pop edi
  pop esi
  //Alt: db 89 4B 70 5F 5E

"popcapgame1.exe"+7F492:
  fstp dword ptr [edi+000000EC]
  //Alt: db D9 9F EC 00 00 00

"popcapgame1.exe"+7F4A4:
  fstp dword ptr [edi+000000F0]
  //Alt: db D9 9F F0 00 00 00
I'd have loved to test it, but didn't want to create an account for their game manager
Back to top
View user's profile Send private message
mindfreak516
Newbie cheater
Reputation: 0

Joined: 13 Nov 2011
Posts: 24

PostPosted: Tue Dec 11, 2012 5:02 am    Post subject: Reply with quote

they are both float, the mouse and the ball..
tested your script and it does the same thing..

EDIT:
fixed it..
it turns out that the mouse coordinates were top left of game's window, but ball coordinates were from top left corner of play field..
so i just needed to subtract 400 from mouse coordinates and now it works


Last edited by mindfreak516 on Tue Dec 11, 2012 5:38 am; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Tue Dec 11, 2012 5:19 am    Post subject: Reply with quote

Have you checked that the mouse coordinate system is the same as the ball?

It might very well be that for the ball the center of the screen is 0,0, the left side is 0,-1 and the right side is 0,1, while the mouse cursor is just between 0,0 and the width/height of the windows

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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