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 


[C++] Read Double Pointer
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Sharel972
Newbie cheater
Reputation: 0

Joined: 02 Nov 2009
Posts: 24
Location: israel

PostPosted: Sun Jan 03, 2010 12:14 pm    Post subject: [C++] Read Double Pointer Reply with quote

here's my pointer reader :
Code:


//Reads a Pointer
__inline ULONG_PTR ReadPointer(ULONG_PTR* ulBase, INT nOffset)
{
   if ( !IsBadReadPtr((VOID*)ulBase, sizeof(ULONG_PTR)) )
        if ( !IsBadReadPtr((VOID*)((*(ULONG_PTR*)ulBase)+nOffset), sizeof(ULONG_PTR)) )
            return *(ULONG_PTR*)((*(ULONG_PTR*)ulBase)+nOffset);
    return 0;
}
// Read Double Pointers
__inline DOUBLE ReadDouble(ULONG_PTR* ulBase, INT nOffset)
{
   if(!IsBadReadPtr((VOID*)ulBase, sizeof(double)))
      if(!IsBadReadPtr((VOID*)((*(ULONG_PTR*)ulBase)+nOffset), sizeof(DOUBLE)))
         return *(DOUBLE*)((*(ULONG_PTR*)ulBase)+nOffset);
   return 0;
}


when i do this :
Code:
      SetDlgItemText(hWnd, IDC_MP, _itoa(ReadDouble((ULONG_PTR*)StatBase, StatMP), buf, 10));

i am get an warrning :
Quote:

warning C4244: 'argument' : conversion from 'DOUBLE' to 'int', possible loss of data

and the reader not works .

Arrow Arrow HELP>.<
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Jan 03, 2010 12:25 pm    Post subject: Reply with quote

_stprintf()
Back to top
View user's profile Send private message
Sharel972
Newbie cheater
Reputation: 0

Joined: 02 Nov 2009
Posts: 24
Location: israel

PostPosted: Sun Jan 03, 2010 12:31 pm    Post subject: Reply with quote

didn't relly understand
what do u mean?
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Jan 03, 2010 12:35 pm    Post subject: Reply with quote

use that function to format your double as a string. at the moment you're trying to convert it as an int when it is a double

_itoa is for integers
Back to top
View user's profile Send private message
Sharel972
Newbie cheater
Reputation: 0

Joined: 02 Nov 2009
Posts: 24
Location: israel

PostPosted: Sun Jan 03, 2010 12:42 pm    Post subject: Reply with quote

it;s not it , i succeed befor to do that but i don't remember how . ...
Back to top
View user's profile Send private message MSN Messenger
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Sun Jan 03, 2010 1:22 pm    Post subject: Reply with quote

Sharel972 wrote:
it;s not it , i succeed befor to do that but i don't remember how . ...


You won't be able to itoa a double..yes it is it.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Jan 03, 2010 2:09 pm    Post subject: Reply with quote

Since you're using C++, you should probably make use of some of its features.

Code:
#include <windows.h>
#include <iostream>

using namespace std;

template <typename T>
bool CrashProgramRandomly(const T *ptr) {
   return ::IsBadReadPtr(ptr, sizeof(T)) ? true : false;
}

template <typename T>
bool Read(const T ** base, unsigned int offset, T & out)
{
   if(!CrashProgramRandomly<const T*>(base)) {
      if(!CrashProgramRandomly<T>((const T *)((char*)(*base) + offset))) {
         out = *(T*)((char*)(*base) + offset);
         return true;
      }
   }
   return false;
}

int someNumber = 1337;
int magicNumber = 42;

int main()
{
   const int *somePtr = &someNumber;
   int anotherNumber;
   if(Read(&somePtr, sizeof(int), anotherNumber)) {
      cout << anotherNumber << endl;
   }
   return 0;
}


(You should probably replace those C style casts with proper C++ casts. I didn't because it would make the example look like a cluster fuck, and I'm lazy.)
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Sun Jan 03, 2010 2:19 pm    Post subject: Reply with quote

Flyte: The program clearly has a dialog as its GUI, and that is his main issue. Can you help him with that instead of unnecessary examples?
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Jan 03, 2010 2:21 pm    Post subject: Reply with quote

smartz993 wrote:
Flyte: The program clearly has a dialog as its GUI, and that is his main issue. Can you help him with that instead of unnecessary examples?

It's his job to impart wisdom. See here : http://forum.cheatengine.org/viewtopic.php?t=479428&postdays=0&postorder=asc&start=0

Despite Flyte having been given tens of thousands of dollars in scholarship money, numerous awards, and even attending a university that essentially pays him to go there, he is still full of shit. He has no interest in helping people, only showing off what little he knows.

OP : here is an example how to convert a hex address for example :
Code:
swprintf_s( szAddress, _countof( szAddress ), _T("%08X"), i );


Same principle applies
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Jan 03, 2010 2:25 pm    Post subject: Reply with quote

smartz993 wrote:
Flyte: The program clearly has a dialog as its GUI, and that is his main issue. Can you help him with that instead of unnecessary examples?


Clearly his issue is not understanding the difference between primitive types.

Slugsnack wrote:
It's his job to impart wisdom. See here : http://forum.cheatengine.org/viewtopic.php?t=479428&postdays=0&postorder=asc&start=0


Code:
<Flyte> !right
<nolyc> http://adrinael.net/youreright.jpg


No one else here seems to be capable of doing it.

Slugsnack wrote:

OP : here is an example how to convert a hex address for example :
Code:
swprintf_s( szAddress, _countof( szAddress ), _T("%08X"), i );



Giving him C code when he is programming in C++... see above.
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Sun Jan 03, 2010 2:28 pm    Post subject: Reply with quote

Flyte wrote:
smartz993 wrote:
Flyte: The program clearly has a dialog as its GUI, and that is his main issue. Can you help him with that instead of unnecessary examples?


Clearly his issue is not understanding the difference between primitive types.

Slugsnack wrote:
It's his job to impart wisdom. See here : http://forum.cheatengine.org/viewtopic.php?t=479428&postdays=0&postorder=asc&start=0


Code:
<Flyte> !right
<nolyc> http://adrinael.net/youreright.jpg


No one else here seems to be capable of doing it.

Slugsnack wrote:

OP : here is an example how to convert a hex address for example :
Code:
swprintf_s( szAddress, _countof( szAddress ), _T("%08X"), i );



Giving him C code when he is programming in C++... see above.


I don't see how you can criticize other replies to his problem, if you yourself have not given a valid response.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Jan 03, 2010 2:32 pm    Post subject: Reply with quote

Flyte wrote:
smartz993 wrote:
Flyte: The program clearly has a dialog as its GUI, and that is his main issue. Can you help him with that instead of unnecessary examples?


Clearly his issue is not understanding the difference between primitive types.

Are you blind.. ? That clearly is his issue
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Jan 03, 2010 2:33 pm    Post subject: Reply with quote

smartz993 wrote:
I don't see how you can criticize other replies to his problem, if you yourself have not given a valid response.


There are many ways to do this. The easiest would be to use boost::lexical_cast.

Slugsnack wrote:
Are you blind.. ? That clearly is his issue


His problem is not related to his GUI at all. Replace SetDlgItemText with any function that wants a 'const char *' and he will end up with the exact same error.

I reiterate: his problem is not understanding the differences between the primitive types.


Last edited by Flyte on Sun Jan 03, 2010 2:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Sun Jan 03, 2010 2:35 pm    Post subject: Reply with quote

Flyte wrote:
smartz993 wrote:
I don't see how you can criticize other replies to his problem, if you yourself have not given a valid response.


There are many ways to do this. The easiest would be to use boost::lexical_cast.


With this, you can just cast a double right to a char*?

I'll have to start reading more about boost APIs.


Code:
boost::lexical_cast<std::string>(doublevalue)


Last edited by smartz993 on Sun Jan 03, 2010 2:38 pm; edited 1 time in total
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Jan 03, 2010 2:37 pm    Post subject: Reply with quote

smartz993 wrote:
With this, you can just cast a double right to a char*?

I'll have to start reading more about boost APIs.


No, you would cast to std::string then use string::c_str(). I would hope something this simple would be obvious.
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
Goto page 1, 2  Next
Page 1 of 2

 
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