Skip to content

Commit

Permalink
Updated ShowDamage to use use foxed buffer and to use packet 0x64 ins…
Browse files Browse the repository at this point in the history
…tead of 0x45.
  • Loading branch information
nooperation committed Feb 25, 2024
1 parent 126c8a2 commit de4507a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
7 changes: 0 additions & 7 deletions d2es-stuff.sln
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AutoBuy", "D2Hackit\Modules
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "showItemPropertyRanges", "plugins\showItemPropertyRanges\showItemPropertyRanges.vcxproj", "{FFF512D1-F611-4E9A-81E5-074B75B02094}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "showDamage", "D2Hackit\Modules\showDamage\showDamage.vcxproj", "{EA69AB6D-FFC2-4CB7-83C8-FFF3CDAFF036}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "showDamage", "plugins\showDamage\showDamage.vcxproj", "{FFFF12D1-F611-4E9A-81E5-074B75B02094}"
EndProject
Global
Expand Down Expand Up @@ -235,10 +233,6 @@ Global
{FFF512D1-F611-4E9A-81E5-074B75B02094}.Debug|Win32.Build.0 = Debug|Win32
{FFF512D1-F611-4E9A-81E5-074B75B02094}.Release|Win32.ActiveCfg = Release|Win32
{FFF512D1-F611-4E9A-81E5-074B75B02094}.Release|Win32.Build.0 = Release|Win32
{EA69AB6D-FFC2-4CB7-83C8-FFF3CDAFF036}.Debug|Win32.ActiveCfg = Debug|Win32
{EA69AB6D-FFC2-4CB7-83C8-FFF3CDAFF036}.Debug|Win32.Build.0 = Debug|Win32
{EA69AB6D-FFC2-4CB7-83C8-FFF3CDAFF036}.Release|Win32.ActiveCfg = Release|Win32
{EA69AB6D-FFC2-4CB7-83C8-FFF3CDAFF036}.Release|Win32.Build.0 = Release|Win32
{FFFF12D1-F611-4E9A-81E5-074B75B02094}.Debug|Win32.ActiveCfg = Debug|Win32
{FFFF12D1-F611-4E9A-81E5-074B75B02094}.Debug|Win32.Build.0 = Debug|Win32
{FFFF12D1-F611-4E9A-81E5-074B75B02094}.Release|Win32.ActiveCfg = Release|Win32
Expand Down Expand Up @@ -284,7 +278,6 @@ Global
{EA69AB6D-FFF2-4CF7-83C8-5D43CDAFF0E6} = {B633F61A-62D5-4159-BA82-8C17FFE77E9C}
{D92FD3C9-082F-4DFB-B414-3538D1F9DFFF} = {B633F61A-62D5-4159-BA82-8C17FFE77E9C}
{FFF512D1-F611-4E9A-81E5-074B75B02094} = {9637B3AB-2054-440D-8836-84624BE534C5}
{EA69AB6D-FFC2-4CB7-83C8-FFF3CDAFF036} = {B633F61A-62D5-4159-BA82-8C17FFE77E9C}
{FFFF12D1-F611-4E9A-81E5-074B75B02094} = {9637B3AB-2054-440D-8836-84624BE534C5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
37 changes: 22 additions & 15 deletions plugins/showDamage/showDamage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,15 @@ struct PacketHandlerEntry
{
PacketHandlerFunc_t Callback;
uint32_t PacketSize;
uint32_t UnknownFlag;
void* UnknownFunc;
};

struct D2DamagePacket
struct D2DamageReportPacket
{
uint8_t unknownA;
uint8_t unknownB;
uint8_t unknownC;
uint8_t packetId;
uint8_t isPlayerBeingAttacked;
uint32_t unitId;
uint32_t damage;
int64_t damage;
};
#pragma pack(pop)

Expand All @@ -84,7 +83,7 @@ struct DamageInfo
bool isPlayerBeingAttacked;
uint32_t unitId;
uint64_t tickCreated;
std::wstring text;
wchar_t text[32];
};

PLUGIN_INTERFACE Interface;
Expand Down Expand Up @@ -167,18 +166,18 @@ void __cdecl RenderHook()

int32_t textWidth;
int32_t textHeight;
D2Win_10131_GetTextDimensions(damageInfos[i].text.c_str(), &textWidth, &textHeight);
D2Win_10131_GetTextDimensions(damageInfos[i].text, &textWidth, &textHeight);

unitY -= (65 + ticksRemaining >> 3);
unitX -= textWidth / 2;

D2Win_10117_DrawText(damageInfos[i].text.c_str(), unitX, unitY, color, FALSE);
D2Win_10117_DrawText(damageInfos[i].text, unitX, unitY, color, FALSE);
}

D2Win_10127_SetFont(originalFont);
}

void UpdateUnitDamage(uint32_t unitId, int32_t damage, bool isPlayerBeingAttacked)
void UpdateUnitDamage(uint32_t unitId, int64_t damage, bool isPlayerBeingAttacked)
{
for (std::size_t i = 0; i < damageInfos.size(); ++i)
{
Expand All @@ -196,15 +195,17 @@ void UpdateUnitDamage(uint32_t unitId, int32_t damage, bool isPlayerBeingAttacke
wss.imbue(std::locale(""));
wss << (damage >> 8);

damageInfos[i].text = wss.str();
swprintf_s(damageInfos[i].text, L"%s", wss.str().c_str());

// damageInfos[i].text = wss.str();
return;
}
}

uint32_t __fastcall HandleDamagePacket(const char* packet, uint32_t packetLength)
{
auto damage = (D2DamagePacket*)&packet[1];
UpdateUnitDamage(damage->unitId, damage->damage, damage->unknownA == 2);
auto damage = (D2DamageReportPacket*)&packet[0];
UpdateUnitDamage(damage->unitId, damage->damage, damage->isPlayerBeingAttacked);

return 1;
}
Expand All @@ -230,8 +231,14 @@ DWORD __stdcall PluginEntry(DWORD dwReason, LPVOID lpData)
}

PacketHandlerEntry* packetHandlerTable = (PacketHandlerEntry*)((unsigned char*)d2ClientHandle + 0xD6270);
packetHandlerTable[0x45].Callback = HandleDamagePacket;
packetHandlerTable[0x45].PacketSize = 13;
packetHandlerTable[0x64].Callback = HandleDamagePacket;
packetHandlerTable[0x64].PacketSize = sizeof(D2DamageReportPacket);
packetHandlerTable[0x64].UnknownFunc = nullptr;

// This is already setup on via D2CommonESE.dll
//auto d2NetHandle = GetModuleHandle("D2Net.dll");
//volatile int32_t* pServerPacketSizeTable = (volatile int32_t*)((unsigned char*)d2NetHandle + 0x8148);
//pServerPacketSizeTable[0x64] = sizeof(D2DamageReportPacket);

GetUnit = (GetUnit_t)((unsigned char*)d2ClientHandle + 0x869F0);
GetPlayerUnit = (GetPlayerUnit_t)((unsigned char*)d2ClientHandle + 0x883D0);
Expand Down

0 comments on commit de4507a

Please sign in to comment.