Screen Drawing API

กก


To draw your own stuff to the game screen, you need to implement the "OnDraw" function in your modules implementation file, usually the same file where "OnGameJoin", "OnGameLeave", "OnGamePacketBeforeReceived", etc are implemented.

The function is defined as the following:

VOID EXPORT OnDraw(CGameDC* pDC, LPCRECT lpScreenRect);

Parameters

pDC

Pointer to a game device context CGameDC structure which contains drawing methods for drawing texts, lines, frames, and solid rectangles.

lpScreenRect

Pointer to a RECT structure which contains current game client screen boundaries.

Remarks

You will be strictly using the given CGameDC pointer to draw your own stuff on the game screen. 

Please note that this function is automatically called by D2Hackit whenever the game screen need to be repainted, you shall never call this function in your own code. The pDC pointer is only valid within the scope of this function, you cannot make a copy of pDC and use it otherwhere, attempt on doing so will raise an error.

Code Sample

///////////////////////////////////////////////////////////////////
// MyBot.cpp
//-----------------------------------------------------------------
// Using the "OnDraw" function to draw something on the game screen
///////////////////////////////////////////////////////////////////

VOID
EXPORT OnDraw(CGameDC* pDC, LPCRECT lpScreenRect)
{
    // First we draw a red bold-line cross over the entire screen
   
pDC->SetPenColor(0x62); // 0x62 = Red
    pDC->SetPenWidth(5); // Make the line 5 pixels wide
    pDC->MoveTo(lpScreenRect->left, lpScreenRect->top);
    pDC->LineTo(lpScreenRect->right, lpScreenRect->bottom);

    // Then we draw a transparent white rectangle outlines by a
    // yellow frame.
   
pDC->SetPenColor(0xA8); // 0xA8 = yellow
    pDC->SetPenWidth(1); // Frame width is 1
    pDC->SetBrushColor(0x20); // 0x20 = white
    pDC->SetBrushTransparency(1); // Nice-looking translucent.
    RECT rect = { 200, 100, 400, 250};
    pDC->Rectangle(&rect);    

    // And how about a green triangle, you said?
   
pDC->SetPenColor(0x84); // 0x84 = Green
    pDC->MoveTo(300, 120);
    pDC->LineTo(220, 230);
    pDC->LineTo(380, 230);
    pDC->LineTo(300, 120);

    // Finally we draw some text at center of the rectangle, using
    // a thin font.
   
pDC->SetFont(D2FONT_THIN);
    pDC->DrawText("yc4OMG yc2r0x0rs?", &rect, DT_CENTER | DT_VCENTER);
}


Color Chart

Lines, frames and rectangles are drawn with 256 colors, as shown below:

0123456789ABCDEF
0                
1                
2                
3                
4                
5                
6                
7                
8                
9                
A                
B                
C                
D                
F                

Each color is a hexadecimal BYTE value combined by the vertical index and the horizontal index, for example:

Note, this color chart does not apply to text colors, to draw colorful texts, either by calling SetTextColor or by inserting text color descriptors (yc1, yc2, etc) into the string.


CGameDC Members


BOOL TextOut(LPCSTR lpszText, long x, long y);

Return Value

The function returns non-zero if succeeds, zero otherwise.

Parameters

lpszText

Pointer to a null-terminated character string which contains the characters to be drawn.

x, y

Specify the screen coordinates, relative to game client area, at which the text is to be drawn.

Remarks

The function writes a character string at the specified location, using the current font, background mode, brush, and text color.


BOOL DrawText(LPCSTR lpszText, LPCRECT lpRect, UINT nAlign);

Return Value

The function returns non-zero if succeeds, zero otherwise.

Parameters

lpszText

Pointer to a null-terminated character string which contains the characters to be drawn.

lpRect

Specify the boundaries, relative to game client area, within which the text is to be drawn.

nAlign

Specifies text aligning types, relative to lpRect. Value of this parameter can be a combination of the following flags:

Value Description
DT_LEFT Left align
DT_CENTER Horizontal center align
DT_RIGHT Right align
DT_TOP Top align
DT_VCENTER Vertical center align
DT_BOTTOM Bottom align

Remarks

Similar to TextOut except for that this function lets you specify text alignments.


POINT MoveTo(long x, long y);

Return Value

The function returns the previous position.

Parameters

x, y

Specify the screen coordinates, relative to game client area, to which the position where be changed.

Remarks

Moves the current position to the point specified by x and y.


BOOL LineTo(long x, long y);

Return Value

The function returns non-zero if succeeds, zero otherwise.

Parameters

x, y

Specify the screen coordinates, relative to game client area, which will be the endpoint of the line.

Remarks

Draws a line from the current position up to, but not including, the point specified by x and y. The current position is set to x,y. The line is drawn by using the current pen color and width.


BOOL FrameRect(LPCRECT lpRect);

Return Value

The function returns non-zero if succeeds, zero otherwise.

Parameters

lpRect

Specify the boundaries, relative to game client area, of the frame to be drawn.

Remarks

Draws a border around the specified rectangle, using the current pen color and width.


BOOL Rectangle(LPCRECT lpRect);

Return Value

The function returns non-zero if succeeds, zero otherwise.

Parameters

lpRect

Specify the boundaries, relative to game client area, of the rectangle to be drawn.

Remarks

Draws a rectangle to the game screen. The rectangle is outlined by using the current pen and filled by using the current brush.


BOOL FillRect(LPCRECT lpRect);

Return Value

The function returns non-zero if succeeds, zero otherwise.

Parameters

lpRect

Specify the boundaries, relative to game client area, of the rectangle to be filled.

Remarks

Fills a rectangle by using the current brush. This function includes the left and top borders, but excludes the right and bottom borders of the rectangle.


BYTE SetFont(BYTE iFont);
BYTE GetFont();

Return Value

The function returns the previously selected font.

Parameters

iFont

Specify the new font value. Please check "Game Fonts" for a complete list of available game font values.

Remarks

Sets and gets the font value of the game device context.


BYTE SetTextColor(BYTE iColor);
BYTE GetTextColor();

Return Value

The function returns the previously selected text color.

Parameters

iColor

Specify the new text color.

Remarks

Sets and gets the text color value of the game device context. Text colors are different from pen or brush colors and there are only about 14 available text colors. You have two ways to specify text colors, either by calling SettextColor or by inserting text color descriptors (yc1, yc2, etc) into the string.


SIZE GetTextExtent(LPCSTR lpszText);

Return Value

The function returns the actual drawing size of the specified string.

Parameters

lpszText

Pointer to a null-terminated character string which contains the text to be calculated.

Remarks

Calculates the width and height of a line of text using the current font to determine the dimensions.


BYTE SetPenColor(BYTE iColor);
BYTE GetPenColor();

Return Value

The function returns the previously selected pen color.

Parameters

iColor

Specify the new color value. Please check "Color Chart" for a complete table of color values.

Remarks

Sets and gets the pen color of the game device context.


int SetPenWidth(int nWidth);
int GetPenWidth();

Return Value

The function returns the previously selected pen width.

Parameters

nWidth

Specify the new width.

Remarks

Sets and gets the pen width of the game device context.


BYTE SetBrushColor(BYTE iColor);
BYTE GetBrushColor();

Return Value

The function returns the previously selected brush color.

Parameters

iColor

Specify the new color value. Please check "Color Chart" for a complete table of color values.

Remarks

Sets and gets the brush color of the game device context.


BYTE SetBrushTransparency(BYTE iTransparency);
BYTE GetBrushTransparency();

Return Value

The function returns the previously selected brush transparency.

Parameters

iTransparency

Specify the new transparency value. The smaller iTransparency is, the more transparent the brush fills. If iTransparency is 0xff, the brush fills opaque.

Remarks

Sets and gets the brush transparency of the game device context.


int SetBkMode(int nBkMode);
int GetBkMode();

Return Value

The function returns the previously selected text background filling mode.

Parameters

nBkMode

Specify the new text background filling mode value. Valid background filling mode values are:

Value Description
OPAQUE Background is filled with the current background color before the text is drawn.
TRANSPARENT Background remains untouched.

Remarks

Sets and gets the text background filling mode of the game device context.

New Diablo 2 Event

http://newd2event.net