or SIGN UP for FREE
 
Search for Cheats (BETA)

Developer
Latest VAC Update: 17.08.08
pixelscanner wrapper for [ Source Code ]
Status:
  • Anti-Cheat Proof:
  • Author:
  • Release Date:
  • Downloads:
  • Size:
  • Submitted by
  • none
  • Andrew Thomas
  • 21.02.09
  • 107
  • 7.4 kb
  • CampStaff

Description:
Source code
Unmodified Readme for pixelscanner wrapper
Thanks to :
UHM, learn_more - Checked code for neatness
Roverturbo, Alkatraz - Provided information in topic : [Help]Pixel Scanning


I'm sure you can all write better wrappers. This wrapper includes basic methods such as loading a bitmap file from a resource or from the HDD. Along with scanning the screen in a defined area for a loaded bitmap. Below I have given a description of all the methods, and structs defined in the header file. Below that is an example code which should explain all you need to know on how to use the the wrapper. I hope you find this useful, and find time to improve on it

structs
PHP Code:
struct Img
{
       COLORREF crPixSearch[30][30];
       int iX,iY;
       int iWidth, iHeight;
};
 
 
struct Vector2D {
       int iX,iY;
};
 
struct Rect {
       int iX,iY,iWidth,iHeight;
}; 
struct Img Holds all the information needed to provide searchForImg in order to scan for the bitmap you need. You don't have to worry about manually initilizing this struct, you can simply call loadImage() using the proper params(information on how to use methods are below)

struct Vector2D Yeah, I know there is a better way to hold X,Y positions, you can add that addition yourself This is a struct that is returned on searchForImage. When searchForImage returns a Vector2D struct, it will either be {-1,-1} for Failed To Find Image On Screen or the {X,Y} position of the top-left corner of the image found.

struct Rect This struct is passed to loadImage, and searchForImage. In loadImage, it specifies which pixels to gather. For example, if {5,5,5,5} was passed to loadImage, it loads pixels that are within a rectangle positioned 5 pixels from the top, and 5 pixels from the left. With the width of 5, and height of 5. In searchForImage, it is used to defined where to search on the screen. For example, if Rect{5,5,5,5} was passed to searchForImage, it would search for the bitmap passed in the first param within the rectangle, which has properties stored in it's rect struct.

Methods
PHP Code:
Vector2D searchForImg(Img &Input, Rect &SearchBounds, float delay);
HBITMAP getImage(LPCWSTR path, bool resource); //Consider making method inline
int loadImage(Img &Input, HBITMAP &hBitmapSource,Rect rect, float delay); 









searchForImg :

    Return : (Vector2D)

        {-1,-1} : Error

        {X,Y} location if the image : Sucess

    Params:

    Param 1 : Img Image to search for. This struct should be inited with loadImage

    Param 2 : Rect The pixel scanning should be performed within this rect.

    Param 3 : float Amount(ms) to wait between each pixel scan. Read Setting Delay Accordingly.

getImage : Simplified version of the Win32 LoadImage. CONSIDER MAKING INLINE

    Return : (HBITMAP) 

        0x0 : Error 

        Non-zero : Success

    Params : 

    Param1 : LPCWSTR path\name of bitmap location\resource.

    Param2 : bool FALSE = Load from path TRUE = load as resource.

loadImage : Used to init Img struct.

    Return : (int)

    -1 : Error

    1 : Sucess

    Params : 

    Param1 : Img Img struct to init.

    Param2 : HBITMAP Handle to bitmap file loaded in getImage.

    Param3 : Rect All pixels within this Rect's iWidth, iHeight, iX, and iY members will be loaded into the Img struct passed in param1.

    Param4 : float Amount(ms) to wait between each pixel scan. Read Setting Delay Accordingly.

Example Code


#include "stdafx.h" //You may not need this include. if source doesn't compile, comment out this line.
#include "pixelScanningWrapper.h"
#include <windows.h> //.h suffix may be needed depending on how you setup your platfrom SDK and compiler options.
 
int main(int arc, char *argv[])
{ 
       Rect imageSourceRect = {
              0, //X
              0, //Y
              11, //Width
              12 //Height
       };
 
       Rect SearchBounds = {
              100, //X
              0, //Y
              500,//Height
              500//Width
       };
 
       Img imageToFind;
       HBITMAP hBitmapImage;
 
       memset(&imageToFind ,0, sizeof(imageToFind));
       memset(&hBitmapImage,0, sizeof(hBitmapImage));
 
       hBitmapImage = getImage(L"C:/test.bmp", false);
       if(!hBitmapImage)
              return -1; //ERROR LOADING IMAGE. END PROGRAM
 
       loadImage(imageToFind, hBitmapImage, imageSourceRect, 1); //Set Delay accordingly. Read tutorial to learn how to determine what to set delay to.
 
       system("pause"); //So you can move the console out of the way before scanning.
       Vector2D loc = searchForImg(imageToFind, SearchBounds, 0.1f); 
 
       if(loc.iX <= -1)
               return -1;
       else
               SetCursorPos(loc.iX,loc.iY);
 
       return 0;

}




stdafx.h may be needed if you created your project requesting precompiled headers. The code should explain everything you need to know, if you have problems, feel free to post  DON'T PM ME, Chances are I won't read it. I usually don't read PMs.

Additional notes

    * Setting Delay Accordingly
          o If you're scanning a large area, you may need to set delay to something below 0.1ms to get the performance you need. However, if you're scanning\loading a small set of pixels(<20X20) I suggest you set the sleep to no lower then 1 and no higher then 3. Keep in mind, the lower this value, the more processing power your application uses, but the faster it scans. This can cause a slow performing computer.
    * Scanning Small Areas
          o Make sure, that during the development of your pixel scanner\bot or whatever you may be creating with this, you choose as small of an area you can to scan in order to get fast performance, and less CPU usage. For example, to locate the X on the top right of this window, don't scan the whole screen. Just scan within a rectangle that it may be in.

    * When loading pictures larger then 30X30px
          o Honestly, I don't suggest loading images larger then 30X30(usually it can be avoided), but if you need to, you have to change the Img struct within the header file.

    * Couple of flaws to be fixed over the long weekend
         1. If one row is matched, y searching location will be incremented by one, if the next row isn't matched, it won't go back to rescan the previous row for matches. Please note, it is very rare to encounter this issue if you're using the methods the way they were intended to be used. I will fix this sometime this weekend.
         2. If you find any other flaws, or ways to optimize my code, please post

This is a thanks to UC-Forum for all the help you've given to not just me, but many other members. To be honest, sometimes you guys are so tolorant against some of the questions asked here. Thanks!

Copyright © Cheat-Project 2007-2009