[Drawing Text To Screen a.k.a How to make a Stat Hack]
(best viewed at 1024x768)
[PREFACE]
This is more of a programming tutorial then anything else, it will teach you how to draw text
on another process' window.This is a common method used in creating Stat hacks, which display
how many resources each player has, and how many units, or max population, ..etc. There are
other methods of creating a stat hack, but they involve tracking down the games own draw text
function and that may be hard to find.
-------------------
[Windows API Calls]
-------------------
The FindWindow function retrieves a handle to the top-level window whose class name and window
name match the specified strings. This function does not search child windows. This function
does not perform a case-sensitive search.
HWND FindWindow( LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
The GetDC function retrieves a handle to a display device context (DC) for the client area of
a specified window or for the entire screen. You can use the returned handle in subsequent GDI
functions to draw in the DC.
HDC GetDC(
HWND hWnd // handle to window
);
The SetBkMode function sets the background mix mode of the specified device context. The
background mix mode is used with text, hatched brushes, and with non-solid pen styles.
int SetBkMode(
HDC hdc,
int iBkMode
);
Parameters:
OPAQUE :Background is filled with the current background color before the text,
hatched brush, or pen is drawn.
TRANSPARENT :Background remains untouched.
The SetTextColor function sets the text color for the specified device context to the
specified color.
COLORREF SetTextColor(
HDC hdc, // handle to DC
COLORREF crColor // text color
);
The TextOut function writes a character string at the specified location, using the currently
selected font, background color, and text color.
BOOL TextOut(
HDC hdc, // handle to DC
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // character string
int cbString // number of characters
);
--------------
[The Function]
--------------
I've saved you the time in trying to do research and what not and gave you my DrawMyText function.
Put it in a timer, and have the timer be very fast so that it can paint every frame. My function
prints RED text with a black drop shadow. You can change this by changing the RGB values in the
SetTextColor().
void DrawMyText(char *windowcaption, float x, float y, char *mybuffer, int howmany)
{
gamewindowhandle = FindWindow(NULL, windowcaption); //get the game hwnd
HDC hdc = GetDC(gamewindowhandle);
SetBkColor(hdc,RGB(255,255,255)); //WHITE BACKGROUND
SetBkMode(hdc, TRANSPARENT); //MAKES BACKGROUND TRANSPARENT
//SO ALL YOU SEE IS THE TEXT
//MAKE SHADOW FOR TEXT (BLACK) and offset it by 1 pixel
SetTextColor(hdc,RGB(0,0,0));
TextOut(hdc,x+1,y+1, mybuffer,howmany);
//MAKE SECOND SHADOW FOR TEXT (BLACK) and offset it by 2 pixels
TextOut(hdc,x+2,y+2, mybuffer,howmany);
//PRINTS MY TEXT OVER THE BLACK TEXT IN RED, GIVES IT A DROP SHADOW APPEARANCE.
SetTextColor(hdc,RGB(255,0,0));
TextOut(hdc,x,y, mybuffer,howmany);
UpdateWindow(gamewindowhandle);
ReleaseDC(gamewindowhandle,hdc);
}
-------
[Usage]
-------
char buff[255];
DrawMyText("Crimsonland",155,35,"Time: ",6);
or
DrawMyText("Crimsonland",155,35,buff,3);
First parameter is the games' name.
Second is the the position in X where you want to draw the text.
Third is the Y position where you want to draw the text.
Fourth is the buffer containing text, this could either be a string in between two " or it can be
a variable of type char.
Fifth is the length of the string/buffer.
[CONCLUSION]
I know I didn't really explain anything, all you need to know is that you need a DC to be able to
paint on a window. And you use TextOut to write text to a DC.
The only problem with this is that every frame that the game updates, it will overwrite your text
and then you paint it again, so you will get a flickering effect. There is no way to prevent this
except to find the games own draw text routine. Alternatively, you could inject code to store the
value for gold in an address of your choice ( [0313370] for me ), and then if the game has any kind
of text display (such as a score display board like in Age of Kings/Mythology) you can find and
locate the code and change it to PUSH the value inside of [0313370] rather then the address
of the score. Thus the game will display the value of gold in the place where the score used to be.
^chaos^
<~~greets~~>
[sheep], MiCRal, Archmage, MrNOP, Visual Perfection, MiraMax, cppdude.
#gamehacking on efnet
Drawing Text To Screen - ^chaos^
Started by Omega, Jan 23 2012 02:53 PM
No replies to this topic
#1
Posted 23 January 2012 - 02:53 PM
Omega - The perfection everything comes to speak.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users










