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++] "Templated" Type Scanner Function

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

Joined: 07 Jan 2008
Posts: 11
Location: /dev/null

PostPosted: Wed Dec 31, 2008 7:17 am    Post subject: [C++] "Templated" Type Scanner Function Reply with quote

Hi everyone. Thanks for reading my post. Just to start off, I'd like to say that though I don't post on this forum, I use it primarily for coding needs and have gained insight from many of the users and their questions. I've learned a lot from you guys and appreciate your hard work and dedication.

Having said that, I'd like to further preface this by saying that I'm one of those many people who think it'd be a great idea to make a C++ version of CE. Yes, I'm "that guy."

My question revolves around the actual search function itself. Its working and I've been testing it on minesweeper using **short** (as opposed to int, long, char, etc.) values to scan for the timer address (0x100579C on XP SP2, if anyone's interested). I would like to be able to search for a generic type and forgo the copy and paste of the entire function changing only a few types.

I've tried messing with the
Code:
template <typename T>
returnType ClassName::memberFunction(T data)
{ ... }

approach, but ran into some difficulty. I've also considered using an approach like
Code:
enum TYPES { SHORT, INT, LONG, FLOAT, etc... }
returnType ClassName::memberFunction(void* data, SHORT)
{ ... }

or something to that effect.

I'm doing this in the interest of not having to change the entire search function for each datatype if I were to update the algorithm I use, in the future. I've taken a look at the following posts and found them helpful (for anyone who stumbles upon this and is interested in such a project) (sorry, can't post actual links yet, apparently):

/viewtopic.php?t=245357
/viewtopic.php?p=2560019
/viewtopic.php?p=18045

I've looked at DB's code itself, but being as I'm really only (moderately) literate in C++, I have a lot of difficulty parsing it in my mind.

If anyone has any suggestions as to what to do, I would greatly appreciate hearing them. Also, if you need to see some of my code (I don't want to post what is unnecessary, so as to prevent spamming), let me know and I'll put it up. If you are just plain confused with what I'm wanting, please let me know and I'll try to clarify. Thank you VERY much for reading this post and even more thanks if you have suggestions.
Cheers!
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Wed Dec 31, 2008 8:27 am    Post subject: Reply with quote

What exactly is the problem you ran into?
I think you will be getting much more help if you elaborate about your problem.
Back to top
View user's profile Send private message MSN Messenger
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Wed Dec 31, 2008 10:44 am    Post subject: Reply with quote

You do not need to write a separate function for each type

Example:

Code:

DWORD ScanFor(PBYTE pBuffer, PBYTE pToFind, SIZE_T nBufferSize, SIZE_T nDataSize)
{
    DWORD i;

    for (i = 0; i < nBufferSize; i += nDataSize)
    {
        if (!memcmp(pBuffer[i], pToFind, nDataSize))
            return i;
    }
}


Simply fill out nDataSize when you call "ScanFor." If you want to scan for a short, just do "sizeof(short)" as the nDataSize.[/code]
Back to top
View user's profile Send private message
shad0wfyr3
Newbie cheater
Reputation: 0

Joined: 07 Jan 2008
Posts: 11
Location: /dev/null

PostPosted: Thu Jan 01, 2009 5:09 am    Post subject: Reply with quote

rapion124, thank you for your response. I took your suggestion and modified my search function to accept a PVOID rather than a specific type. The conversion of type is instead done right before I call the function. Thus I make a temporary buffer with the specific type's data residing in it. This is a much better solution than what I had and I thank you for your advice.

Happy New Year everyone!
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