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 


What is the best way to set a memory location to a double?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Csimbi
I post too much
Reputation: 98

Joined: 14 Jul 2007
Posts: 3375

PostPosted: Sat Jul 02, 2011 6:07 pm    Post subject: What is the best way to set a memory location to a double? Reply with quote

This is what I want to achieve:
Quote:
mov [eax+10], (double)1000

I guess I would load the integer 1000 to XMM0, then I would use this:
Code:
movq [eax+10], xmm0

but how do I save the XMM0, load the int into XMM0 and restore XMM0 efficiently?
Thank you.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sat Jul 02, 2011 10:35 pm    Post subject: Reply with quote

Write a code cave to do all that if you want to 'save' the value before overwriting it. Or just directly write to the address and not overwrite xmm0 at all and remove the original instruction.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Csimbi
I post too much
Reputation: 98

Joined: 14 Jul 2007
Posts: 3375

PostPosted: Sun Jul 03, 2011 4:00 pm    Post subject: Reply with quote

Wiccaan wrote:
Write a code cave to do all that if you want to 'save' the value before overwriting it. Or just directly write to the address and not overwrite xmm0 at all and remove the original instruction.

I think you're missing the point.
There's no such instruction as:
Code:
mov [eax+10], (double)1000

What is the most efficient way of implementing the instruction above (pluy, push and pop XMM0? What do you type in auto-assembler (the actual code)?
Thank you.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sun Jul 03, 2011 7:20 pm    Post subject: Reply with quote

You'll need to look into floating point instructions then.

FIST / FISTP would probably be the ones you need mainly. I'm not at all an expert with the FPU instructions so I can't really help much other then suggesting you check into them.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Freiza
Grandmaster Cheater
Reputation: 22

Joined: 28 Jun 2010
Posts: 662

PostPosted: Mon Jul 04, 2011 2:51 am    Post subject: Reply with quote

i am not sure what is your requirement but I think this is what you want'


CVTTSD2SI r32, xmm/m64
example: CVTTSD2SI eax, xmm0


It will convert and Truncate to int
Back to top
View user's profile Send private message Send e-mail
Geri
Moderator
Reputation: 112

Joined: 05 Feb 2010
Posts: 5627

PostPosted: Mon Jul 04, 2011 10:00 am    Post subject: Reply with quote

This would add 5 (in double) to another double value every time when the code is executed.

Code:
alloc(boostinc,8)

boostinc:
dq (double)5

newmem: //this is allocated memory, you have read,write,execute access
fld qword ptr [esi+00003CF8]
fadd qword ptr [boostinc]
fstp qword ptr [esi+00003CF8]


As for simply using for "mov [blabla],(double)5":

Code:
alloc(boostinc,8)

boostinc:
dq (double)5

newmem: //this is allocated memory, you have read,write,execute access
fld qword ptr [boostinc]
fstp qword ptr [esi+00003CF8]


This code would convert an integer value from an address into double, but again, you need to define the value so it is basically the same solution but you define the number in integer and it is converted by fild.

Code:
fild qword ptr [whatever_integer_value_on_an_address]
fstp qword ptr [esi+00003CF8]


And if you want to push/pop XMM0, well I don't know if there is a legit instruction for that (on 32-bit), but you could just allocate 8 bytes, use movsd to move the values from XMM0 to the allocated address and push the values from the address in 2 pieces (4-4 bytes) as if they were 2 different values. I have never tried it, but in theory, there is nothing wrong with it (except the fact that it is pretty complicated for a seemingly easy task). I don't put values in the stack when I modify a code, so I have never tried. I would just leave it on an allocated address for storage if it is needed. I don't know how many programs are passing double values into 32-bit stack, but if they do, I am sure they split the value in 2 pieces.

_________________
My trainers can be found here: http://www.szemelyesintegracio.hu/cheats

If you are interested in any of my crappy articles/tutorials about CE and game hacking, you can find them here:
http://www.szemelyesintegracio.hu/cheats/41-game-hacking-articles

Don't request cheats or updates.
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 98

Joined: 14 Jul 2007
Posts: 3375

PostPosted: Tue Jul 05, 2011 8:29 am    Post subject: Reply with quote

@Freiza
There is a double in XMM0, that's what I need to 'patch'.
Thanks for the reply though.

@Geri
Just what the doctor ordered!
Thank you!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming 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