The "server" API Set
This API set encapsulates general game attribues and global operations. I will only list new API's that were added in D2Hackit 2.00. API's those exist since older versions of D2Hackit are assumed well known.
General Functions
Inter-Module Communication
Information Printing Functions
Unit Functions
Misc Functions
Return Value
The function returns current ping value.
Remarks
Retrieve current network ping value. Ping values are used for detecting lag, the higher the ping, the worse the lag.
Return Value
If suceeded, the function returns pointer to a null-terminated string which contains realm name, otherwise it returns zero.
Remarks
Retrieve realm name.
Return Value
If suceeded, the function returns pointer to a null-terminated string which contains game IP, otherwise it returns zero.
Remarks
Retrieve current game server IP.
Return Value
If suceeded, the function returns pointer to a null-terminated string which contains game name, otherwise it returns zero.
Remarks
Retrieve current game name.
Return Value
If suceeded, the function returns pointer to a null-terminated string which contains game password, otherwise it returns zero.
Remarks
Retrieve current game password.
Return Value
The function returens pointer to a null-terminated string which contains module directory.
Remarks
Retrieve directory where D2Hackit resides.
BOOL IsClientLoaded(LPCSTR lpszClientName);
Return Value
The function returns non-zero if the d2h module was loaded, zero otherwise.
Parameters
lpszClientName
Pointer to a null-terminated string which contains name of the module to be examed. Note that module file extension, usually ".d2h", shall not be included in lpszClientName.
Remarks
Determine whether a pariticular module was loaded.
BOOL GameInfof(LPCSTR lpszFormat, ...);
BOOL GameErrorf(LPCSTR lpszFormat, ...);
BOOL GameStringf(LPCSTR lpszFormat, ...);
BOOL GameCommandf(LPCSTR lpszFormat, ...);
Return Value
The functions return non-zero if succeeds, zero otherwise.
Parameters
lpszFormat
Pointer to a null-terminated string which contains the format specifications.
Remarks
These functions will first format a given string, then call GamePrintInfo, GamePrintError, GamePrintString, GameCommandLine and pass in the formatted string. For example, if you want to print an integer value to the screen, you no longer need to declare a string buffer, then format the string using sprintf, then print it, instead, you can simply call server->GameInfof("My value is: %d", nValue); for significant code length reduction.
BOOL GamePrintPacket(BOOL bReceived, const BYTE *aPacket, DWORD aLen);
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
bReceived
Specifies whether the packet is received or sent.
aPacket
Packet data block.
aLen
Specifies the packet length, in bytes.
Remarks
Print packet contents to screen.
Return Value
The function returns non-zero if the game is ready to be operated, zero otherwise.
Remarks
When the player joins a game, the game doesn't become ready immediately, there will be a few seconds of delay until all necessary data are received or loaded by the game client. Your modules should not operate the player until the game is ready.
BOOL WasD2HackitLoadedBeforeJoinGame();
Return Value
The function returns non-zero if the D2Hackit.dll was loaded before joining the game, zero otherwise.
Remarks
Some important data can only be received upon joining a game, so if D2Hackit.dll was not loaded before joining a game, some features may not work properly until the player joins a new game.
BOOL EnumUnits(DWORD dwUnitType, fnEnumUnitProc lpfnEnumUnitProc, LPARAM lParam = 0);
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
dwUnitType
Specifies type of the game units that are to be enumerated. Please check Unit Types for a complete list of game unit types.
lpfnEnumUnitProc
Pointer to a fnEnumUnitProc function which will receive unit data.
lParam
A 32-bit application defined value.
Remarks
Enumerate all existing game units whose unit type equal to dwUnitType.
typedef BOOL (CALLBACK *fnEnumUnitProc)(LPCGAMEUNIT lpUnit, LPARAM lParam)
Return Value
Return zero to abort unit enumeration, return non-zero to continue.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
lParam
A 32-bit application defined value.
Remarks
Process each unit data passed from EnumUnit.
BOOL VerifyUnit(LPCGAMEUNIT lpUnit);
Return Value
The function returns non-zero if the unit data is valid, zero otherwise.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
Remarks
Verify an unit data, if the unit does not exist or is invalid, this function will fail.
BOOL FindUnitByClassID(DWORD dwUnitClassID, DWORD dwUnitType, LPGAMEUNIT lpBuffer);
Return Value
The function returns non-zero if the unit has been found, zero otherwise.
Parameters
dwUnitClassID
Specifies unit class ID. If there are multiple units with same class ID, the first matched unit in the game unit chain will be used.
dwUnitType
Specifies type of the game unit that is to be found. Please check Unit Types for a complete list of game unit types.
lpBuffer
Pointer to a GAMEUNIT struct which will receive the unit's data if the unit is found.
Remarks
Find a game unit whose class ID equals to dwUnitClassID and unit type equals to dwUnitType. Class ID's identify units' base types.
BOOL FindUnitByName(LPCSTR lpszUnitName, DWORD dwUnitType, LPGAMEUNIT lpBuffer);
Return Value
The function returns non-zero if the unit has been found, zero otherwise.
Parameters
lpszUnitName
Pointer to a null-terminated string which contains name of the unit to be found. If there are multiple units with same name, the first matched unit in the game unit chain will be used.
dwUnitType
Specifies type of the game unit that is to be found. Please check Unit Types for a complete list of game unit types.
lpBuffer
Pointer to a GAMEUNIT struct which will receive the unit's data if the unit is found.
Remarks
Find a game unit whose name matches lpszUnitName and unit type equals to dwUnitType. Unit names are case-insensitive.
MAPPOS GetUnitPosition(LPCGAMEUNIT lpUnit);
Return Value
The function returns a MAPPOS struct which contains the unit's map position if the unit is found, otherwise it returns zero.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
Remarks
Retrieves map position of a pariticular game unit.
DWORD GetUnitName(LPCGAMEUNIT lpUnit, LPSTR lpszBuffer, DWORD dwMaxChars);
Return Value
If succeeded, the function returns length of the unit name, otherwise it returns zero.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
lpszBuffer
Pointer to a null-terminated string which will receive the unit's name.
dwMaxChars
Specifies the maximum buffer size, in char's.
Remarks
Retrieves name of a particular game unit.
DWORD GetUnitOwnerID(LPCGAMEUNIT lpUnit);
Return Value
The function returns ID of the unit's owner if succeeds, -1 otherwise.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
Remarks
Retrieves ID of the unit owner, only works for monsters. This can be used to determine whether a mercenary belongs to a player. Global units that do not have any owner will have -1(0xffffffff) as owner ID.
DWORD GetUnitClassID(LPCGAMEUNIT lpUnit);
Return Value
The function returns class ID of the unit if succeeds, zero otherwise.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
Remarks
Retrieve class ID of a particular game unit. Class ID's identify units' base types.
BYTE GetUnitHPPercent(LPCGAMEUNIT lpUnit);
Return Value
The function returns unit's remaining life percent.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
Remarks
Retrieve life percent of a particular game unit, return value ranges from 0 to 100.
DWORD GetUnitStat(LPCGAMEUNIT lpUnit, int nStatID);
Return Value
The function returns unit's stat value specified by nStatID.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
nStatID
ID of the stat to return. Please check Unit Stat Definition for a complete list of unit stat ID's.
Remarks
Retrieve a particular stat value of the unit. This function can be used to retrieve any unit stats such as HP, max HP, mana, max mana, magic find, IAS, fast run, fast cast, resists, absorbs, etc. You may even use this function to retrieve stats of other players, but do not abuse it and ruin the PVP!
BOOL GetUnitAffection(LPCGAMEUNIT lpUnit, int nAffectionID);
Return Value
The function returns non-zero if the unit is affected by the affection specified by nAffectionID, zero otherwise.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
nAffectionID
ID of the affection. Please check Unit Affection Definition for a complete list of unit affection ID's.
Remarks
Check whether the unit is affected by a particular affection. Affections are states that can affect game units, such as poisoned, chilled, all passive skills, auras, etc.
DWORD GetAffectionName(BYTE iAffectionID, LPTSTR lpszBuffer, DWORD dwMaxChars);
Return Value
If succeeded, the function returns length of the affection name, otherwise it returns zero.
Parameters
nAffectionID
ID of the affection. Please check Unit Affection Definition for a complete list of unit affection ID's.
lpszBuffer
Pointer to a null-terminated string which will receive the affection name.
dwMaxChars
Specifies the maximum buffer size, in char's.
Remarks
Convert an affection into its string representation.
BOOL AffectionIsAura(BYTE iAffectionID);
Return Value
The function returns non-zero if the affection is an aura, zero otherwise.
Parameters
nAffectionID
ID of the affection. Please check Unit Affection Definition for a complete list of unit affection ID's.
Remarks
Check whether an affection is an aura.
DWORD IsMercUnit(LPCGAMEUNIT lpUnit);
Return Value
If succeeded, the function returns class ID of the merc, otherwise it returns zero.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
Remarks
Determine whether a game unit is a merc and which merc type it is. Please check Merc Class ID for a complete list of merc types.
int GetMonsterType(LPCGAMEUNIT lpUnit);
Return Value
The function returns monster type of the unit if succeeds, zero otherwise.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
Remarks
Determine monster type of a particular unit, e.g. champion, minor, boss, etc. Please check Monster Types for a complete list of monster types.
BOOL GetBossEnchants(LPCGAMEUNIT lpUnit, LPBOSSENCHANTS lpBuffer);
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
lpUnit
Pointer to a GAMEUNIT struct.
lpBuffer
Pointer to a BOSSENCHANTS struct which will receive boss enchants data.
Remarks
Retrieve boss monster enchants data, such as fire enchanted, multishot, extra strong, stone skin, etc.
DWORD GetDistance(WORD x1, WORD y1, WORD x2, WORD y2);
Return Value
The function returns distance, in yards, between two map positions.
Parameters
x1, y1
Specifies the first map position.
x2, y2
Specifies the second map position.
Remarks
Calculate map position distance, in yards.
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
iVKCode
Virtual key code of the key which is being sent.
Remarks
Simulate a key press event in the game.
DWORD GetSpellName(WORD wSpell, LPSTR lpszBuffer, DWORD dwMaxChars);
Return Value
If succeeded, the function returns length of the spell name, otherwise it returns zero.
Parameters
wSpell
Specifies the spell ID. Please check Spell Definition for a complete list of spell ID's.
lpszBuffer
Pointer to a null-terminated string which will receive the spell name.
dwMaxChars
Specifies the maximum buffer size, in char's.
Remarks
Retrieve name of a spell.
DWORD GetMapName(BYTE iMapID, LPTSTR lpszBuffer, DWORD dwMaxChars);
Return Value
If succeeded, the function returns length of the map name, otherwise it returns zero.
Parameters
iMapID
Specifies the map ID. Please check Map definition for a complete list of map ID's.
lpszBuffer
Pointer to a null-terminated string which will receive the map name.
dwMaxChars
Specifies the maximum buffer size, in char's.
Remarks
Retrieve name of a map.
Return Value
The function returns non-zero if the map is a town, zero otherwise.
Parameters
iMapID
Specifies the map ID. Please check Map definition for a complete list of map ID's.
Remarks
Check whether a map is a town.
Return Value
The function returns a map ID if succeeds, zero otherwise.
Parameters
iAct
Specifies the act, act number is zero-based, so 0 represents act 1, 1 represents act 2, and so on.
Remarks
Retrieve the town map ID of an act.
BYTE GetActFromMap(BYTE iMapID);
Return Value
The function returns act number of the given map.
Parameters
iMapID
Specifies the map ID. Please check Map definition for a complete list of map ID's.
Remarks
Determine which act the particular map belongs to.
BOOL ParseItem(const BYTE* aPacket, DWORD aLen, LPITEM lpItem);
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
aPacket
Packet data block.
aLen
Specifies the packet length, in bytes.
lpItem
Pointer to an ITEM struct which will receive extracted item information.
Remarks
Parses the packet data and extract item information. The first byte of aPacket must be either 0x9c or 0x9d, otherwise the function fails.
SIZE GetItemSize(LPCSTR lpszItemCode);
Return Value
The function returns size of an item.
Parameters
lpszItemCode
Pointer to a null-terminated string which represents the 3-letter item code.
Remarks
Determine size of an item.
DWORD GetD2WindowTitle(LPSTR lpszBuffer, DWORD dwMaxChars);
Return Value
If succeeded, the function returns number of characters copied to the buffer, otherwise it returns zero.
Parameters
lpszBuffer
Pointer to a null-terminated string which will receive the window title.
dwMaxChars
Specifies the maximum buffer size, in char's.
Remarks
Retrieve D2 game window title.
Return Value
The function returns total elapsed time, in milliseconds, since the player joined the game.
Remarks
Retrieve current game length.
Return Value
If succeeded, the function returns difficulty of current game, otherwise it returns zero.
Remarks
Retrieve game difficulty, if succeeded, the return value can be 1(normal), 2(nightmare), or 3(hell).
BOOL EnumPresetUnits(fnEnumPresetUnitProc lpfnEnumPresetUnitProc, LPARAM lParam = 0);
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
lpfnEnumPresetUnitProc
Pointer to a fnEnumPresetUnitProc function which will received preset-unit data.
lParam
A 32-bit application defined value.
Remarks
Enumerate all preset-units in current map.
typedef BOOL (CALLBACK *fnEnumPresetUnitProc)(LPCPRESETUNIT lpPresetUnit, LPARAM lParam);
Return Value
Return zero to abort preset-unit enumeration, return non-zero to continue.
Parameters
lpPresetUnit
Pointer to a PRESETUNIT struct which will receive the preset-unit data.
lParam
A 32-bit application defined value.
Remarks
Process each preset-unit data passed from EnumPresetUnit.
BYTE CalculatePath(WORD x, WORD y, LPPATH lpBuffer, int nAdjust = 5);
Return Value
If succeeded, the function returns number of path node calculated, otherwise it returns zero.
Parameters
x, y
Specifies the destination map position.
lpBuffer
Pointer to a PATH struct which will receive the calculated path data.
nAdjust
Specifies how accurate you wish the path to be calculated. Unless you are having problems on path finding, the default value is recommended in most circumstances.
Remarks
Calculate all required steps from the player's current map position to the destination map position specified by x and y. This function can be extremely handy for finding a path from one position to another, for example, finding the path from Durance of hate level 2 waypoint to the Durance of hate level 3 entrance, whose map position can be obtained by a previous call to EnumPresetUnit.
Please note that path calculated by this function does not take into account obstacle(monsters, chests, closed doorways, etc), so it is recommended to be used for players with the Teleport spell.
Code Sample
/////////////////////////////////////////////////////////////////////
// Calculate a path and teleport there
/////////////////////////////////////////////////////////////////////
// Suppose we have already obtained a PRESETUNIT named "pu" from a previous call to EnumPresetUnitPATH path = { 0 };
if (!server->Calculatepath(pu.x, pu.y, &path)
{
server->GamePrintError("Failed to calculate path!");
}
else
{
for (BYTE i = 0; i < path.iNodeCount; i++)
me->TeleportTo(path.aPathNodes[i].x, path.aPathNodes[i].y, TRUE);
}
// Now wait for the PM_MOVEEND message...
BOOL GetItemCode(DWORD dwItemID, LPSTR lpszBuffer, DWORD dwMaxChars);
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
dwItemID
Specifies the item ID.
lpszBuffer
Pointer to a null-terminated buffer which will receive the item code.
dwMaxChars
Specifies the maximum number of characters that can be copied to lpszBuffer. The value shall be no less than 4.
Remarks
Retrieve the 3-letter item code of the item specified by dwItemID.
BOOL LeftClick(long x,
long y);
BOOL RightClick(long x, long y);
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
x, y
Specifies the client coordinates where the mouse click shall occur.
Remarks
Simulate a mouse-click on the game client area.
DWORD QueryModuleData(LPCSTR lpszModuleName, DWORD dwDataID, LPVOID lpBuffer, DWORD dwMaxLength, LPARAM lParam = 0);
Return Value
If succeeded, the function returns number of bytes that were actually copied to lpBuffer, otherwise it returns zero.
Parameters
lpszModuleName
Specifies name of the target module. Module extension is not included, for example, if you want to query data from the module "pickit.d2h", you must specify "pickit" as the target module name.
dwDataID
Specifies the iddentity of the data to be queried. This value must had been defined in the target module.
lpBuffer
Pointer to a memory block, to where the target module will write the data if the query is successful.
dwMaxLength
Specify maximum data length, in bytes, that can be written to lpBuffer. The return value of this function will never exceed dwMaxLength.
lParam
Specifies additional information to the target module on how the data should be queried. Assuming the caller and the target module have already made agreement on how lParam is defined.
Remarks
Retrieve some particular data or information from the target module specified by lpszModuleName. This function fails if any of the following conditions are true:
- The target module cannot be found (was not loaded by D2Hackit).
- The target module did not export or implement the "OnQueryModuleData" function.
- Meanings of dwDataID or lParam cannot be recognized by the target module.
- The target module does not agree to expose the required data to the caller.
DWORD GetKeyName(BYTE iKeyCode, LPSTR lpszBuffer, DWORD dwMaxChars);
Return Value
If succeeded, the function returns length of the key name, otherwise it returns zero.
Parameters
iKeyCode
Specifies the virtual key code.
lpszBuffer
Pointer to a null-terminated string which will receive the key name.
dwMaxChars
Specifies the maximum buffer size, in char's.
Remarks
Retrieve name of a key whose virtual key code value is specified by iKeyCode.
BOOL GetItemMod(LPCITEM lpItem, DWORD dwModID, LPITEMMOD pMod);
Return Value
The function returns non-zero if succeeds, zero otherwise.
Parameters
lpItem
Pointer to an ITEM struct which contain item information.
dwModID
Specifies the item mod ID.
pMod
Pointer to an ITEMMOD struct which will receive the required item mod data.
Remarks
Retrieve a particular mod data of an item.