The "screen" API Set

This API set encapsulates game screen hooking(permanent text drawing) and screen attributes access.


DWORD CreateScreenHook();

Return Value

If the function succeeds, the return value is the newly created screen hook ID. If the function fails, the return value is zero.

Remarks

Registers a new screen hook and retrieve the hook ID. The retrieved hook ID shall be kept unaltered for subsequent usage. Your module must call ReleaseScreenHook before unloading to release the hook resource, or the text drawn using this hook will never be removed until D2Hackit is unloaded.


BOOL ReleaseScreenHook(DWORD dwHookID);

Return Value

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

Parameters

dwHookID

The screen hook ID you retrieved from a previous call to CreateScreenHook.

Remarks

Unregisters the screen hook, frees all resource occupied by the hook and removes all text that were drawn to the screen using this hook ID.


BOOL SendToFront(DWORD dwHookID);
BOOL SendToBack(DWORD
dwHookID);

Return Value

The functions return non-zero if succeed, zero otherwise.

Parameters

dwHookID

The screen hook ID you retrieved from a previous call to CreateScreenHook.

Remarks

Multiple text will overlap if drawn at same screen coordinates, these two function are used to change text layers, SendToFront makes the text drawn using dwHookID appear on top of all other text, whereas SendToback makes the text drawn using dwHookID appear on bottom of all other text.


BOOL DrawSingleText(DWORD dwHookID, LPCSTR lpszText, long x, long y, int nFont = 0, BOOL bRightAlign = FALSE);

Return Value

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

Parameters

dwHookID

The screen hook ID you retrieved from a previous call to CreateScreenHook.

lpszText

Pointer to a null-terminated string to be drawn to the screen. 

x

If bRightAlign is zero, this value specifies the left position of the text where it should be drawn. If bRightAlign is non-zero, this value specifies the right position of the text where it should be drawn.

y

Specifies the top position of the text where it should be drawn.

nFont 

Specifies the font value, using which the text will be drawn. Please check game fonts for a complete list of available game font.

Remarks

Draw on line of text to the screen. Text color symbols("yc1", "yc2" etc) can be used in lpszText to display colors. 


BOOL DrawMultipleTexts(DWORD dwHookID, LPCD2DRAWDATA aData, int nDataCount);

Return Value

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

Parameters

dwHookID

The screen hook ID you retrieved from a previous call to CreateScreenHook.

aData

Pointer to an array of D2DRAWDATA structs, each of which contains detailed drawing data information.

nDataCount

Number of D2DRAWDATA structs pointed by aData.

Remarks

Draw multiple lines of text to the screen.

Code Sample

/////////////////////////////////////////////////////////
// Draw 2 lines of text
/////////////////////////////////////////////////////////

g_dwScreenHookID = screen->CreateScreenHook();
assert(g_dwScreenHookID);

D2DRAWDATA aData[2] = { 0 };

// the first line
::strcpy(aData[0].szText, "First line");
aData[0].x = 100;
aData[0].y = 100;
aData[0].nFont = D2FONT_SMALL;

// the second line
::strcpy(aData[1].szText, "Second line");
aData[1].x = 100;
aData[1].y = 200;
aData[1].nFont = D2FONT_THIN;

// Draw them
screen->DrawMultipleTexts(g_dwScreenHookID, aData, 2);


SIZE GetTextSize(LPCSTR lpszText, int nFont);

Return Value

The function returns size of the specified text using specified font.

Parameters

lpszText

Pointer to a null-terminated string whose size is to be calculated. 

nFont

Specifies the font value, using which the text will be calculated. Please check game fonts for a complete list of available game font.

Remarks

Calculate drawing size of a string.


SIZE GetScreenSize(); 

Return Value

The function returns size of the game window client area.

Remarks

Calculate size of the game window client area, the return value will be either {800, 600} or {640, 480}. No other sizes are defined.


MAPPOS ScreenToMapCoords(POINT ptScreenCoords);

Return Value

The function returns a MAPPOS struct which contains the game map position value.

Parameters

ptScreenCoords

Screen coordinates.

Remarks

Translate a screen coordinates into an absolute game map position.


POINT MapToScreenCoords(MAPPOS mapPosition);

Return Value

The function returns the screen coordinates value.

Parameters

mapPosition

A MAPPOS struct contains an absolute game map position.

Remarks

Translate an absolute game map position into a screen coordinates.


POINT GetMousePosition();

Return Value

The function returns current mouse position.

Remarks

Retrieve current mouse position in the game client area.


void SetScrollTitle(LPCSTR lpszTitle);

Parameters

lpszTitle

Pointer to a null-terminated string which contains the scroll title.

Remarks

Specify title of the scroll. Title will be drawn using a different font then other text lines on the scroll.


BOOL AddScrollLine(LPCSTR lpszText);

Return Value

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

Parameters

lpszText

Pointer to a null-terminated string which contains a text line to be drawn on the scroll.

Remarks

Add a text line to the scroll.


BOOL ShowScroll();

Return Value

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

Remarks

Show the scroll UI. The scroll UI is a "scroll of whatever" screen which displays a scroll and the text you specified by previous calls to SetScrollTitle and AddScrollLine. This UI looks pretty cool and can be used for displaying bot instructions, notifications, or credits.


void ClearScroll();

Remarks

Clear all text that were drawn on the scroll UI.