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] My SetValue function

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
talkerzero
Grandmaster Cheater
Reputation: 1

Joined: 24 Jul 2008
Posts: 560
Location: California

PostPosted: Sun Sep 20, 2009 11:07 am    Post subject: [C] My SetValue function Reply with quote

Code:
#include <windows.h>

#define GOOD_RETURN 696969

__checkReturn inline ULONG_PTR SetValue(__in LPVOID lpvDest, __in ULONG_PTR ulValue)
{
   if(*(ULONG_PTR*)lpvDest != ulValue)
   {
      (*(ULONG_PTR*)lpvDest > ulValue) ? --(*(ULONG_PTR*)lpvDest) : ++(*(ULONG_PTR*)lpvDest);
      return SetValue(lpvDest, ulValue);
   }
   return GOOD_RETURN;
}


Example:
Code:
// instead of using:
ulValue = 69;

// use:
if(SetValue(&ulValue, 69) != GOOD_RETURN)
   return EXIT_FAILURE;


Full example:
Code:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>

#define GOOD_RETURN 696969

__checkReturn inline ULONG_PTR SetValue(__in LPVOID lpvDest, __in ULONG_PTR ulValue)
{
   if(*(ULONG_PTR*)lpvDest != ulValue)
   {
      (*(ULONG_PTR*)lpvDest > ulValue) ? --(*(ULONG_PTR*)lpvDest) : ++(*(ULONG_PTR*)lpvDest);
      return SetValue(lpvDest, ulValue);
   }
   return GOOD_RETURN;
}

int __cdecl _tmain(__in int argc, __in_ecount_z_opt(argc) _TCHAR* __targv[], __in_z_opt _TCHAR* __tenviron[])
{
   UNREFERENCED_PARAMETER(argc);
   UNREFERENCED_PARAMETER(__targv);
   UNREFERENCED_PARAMETER(__tenviron);

   ULONG_PTR ulValue = 0;
   
   if(SetValue(&ulValue, 69) != GOOD_RETURN)
      return EXIT_FAILURE;

   printf("%d", ulValue);
   _gettchar();
   return EXIT_SUCCESS;
}


We should totally all use this function and slow down our programs. (lolololol)
Back to top
View user's profile Send private message Visit poster's website
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Tue Sep 22, 2009 6:24 pm    Post subject: Reply with quote

I don't get why people use C on a C++ environment :S

Code:

int Lol = 0;
memset((void*)Lol, 69, 4);


Think that will work.
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: Tue Sep 22, 2009 7:27 pm    Post subject: Reply with quote

void:] wrote:
I don't get why people use C on a C++ environment :S

Code:

int Lol = 0;
memset((void*)Lol, 69, 4);


Think that will work.


lol. Do you understand how pointers work at all?

Try referencing the variable Rolling Eyes
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Sep 22, 2009 8:31 pm    Post subject: Reply with quote

void:] wrote:
I don't get why people use C on a C++ environment :S

Code:

int Lol = 0;
memset((void*)Lol, 69, 4);


Think that will work.


this is trying to access memory at 0x00000000

i am sure you meant
Code:
memset(&Lol, 69, 4);
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Tue Sep 22, 2009 8:36 pm    Post subject: Reply with quote

slovach wrote:
void:] wrote:
I don't get why people use C on a C++ environment :S

Code:

int Lol = 0;
memset((void*)Lol, 69, 4);


Think that will work.


this is trying to access memory at 0x00000000

i am sure you meant
Code:
memset(&Lol, 69, 4);
Yeah, my bad.
Back to top
View user's profile Send private message
igoticecream
Grandmaster Cheater Supreme
Reputation: 0

Joined: 23 Apr 2006
Posts: 1807
Location: 0x00400000

PostPosted: Tue Sep 22, 2009 9:48 pm    Post subject: Reply with quote

Just to know, why _cdecl over _stdcall?

i know _cdecl stack is to be release by the caller and _stdcall by the callee, but i don't see the diference
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Sep 22, 2009 11:02 pm    Post subject: Reply with quote

igoticecream wrote:
Just to know, why _cdecl over _stdcall?

i know _cdecl stack is to be release by the caller and _stdcall by the callee, but i don't see the diference


http://en.wikipedia.org/wiki/X86_calling_conventions

main() must be cdecl
WinMain() must be stdcall
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Tue Sep 22, 2009 11:20 pm    Post subject: Reply with quote

igoticecream wrote:
Just to know, why _cdecl over _stdcall?

i know _cdecl stack is to be release by the caller and _stdcall by the callee, but i don't see the diference


STDCALL is needed for functions in a DLL, as the compiler has no idea how much stack space is needed. CDECL opens up opportunities for optimization.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Sep 23, 2009 1:08 am    Post subject: Reply with quote

void:] wrote:
I don't get why people use C on a C++ environment :S
Because C is still faster.
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