Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadGUID() Wrong value was read #194

Open
zwisus opened this issue Sep 1, 2024 · 0 comments
Open

ReadGUID() Wrong value was read #194

zwisus opened this issue Sep 1, 2024 · 0 comments

Comments

@zwisus
Copy link

zwisus commented Sep 1, 2024

\modules\mod-eluna\src\LuaEngine\WorldPacketMethods.h

The GUID is incorrect, it was read without going through the buffer.Sometings crash.

int ReadGUID(lua_State* L, WorldPacket* packet)
{
ObjectGuid guid;
(*packet) >> guid;
Eluna::Push(L, guid);
return 1;
}

The following code works correctly:

int ReadGUID(lua_State* L, WorldPacket* packet)
{
uint64 guid;
packet->readPackGUID(guid);
Eluna::Push(L, guid);
return 1;
}

cpp:

void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage* log)
{
WorldPacket data(SMSG_SPELLNONMELEEDAMAGELOG, (16 + 4 + 4 + 4 + 1 + 4 + 4 + 1 + 1 + 4 + 4 + 1)); // we guess size
//IF we are in cheat mode we swap absorb with damage and set damage to 0, this way we can still debug damage but our hp bar will not drop
uint32 damage = log->damage;
uint32 absorb = log->absorb;
if (log->target->GetTypeId() == TYPEID_PLAYER && log->target->ToPlayer()->GetCommandStatus(CHEAT_GOD))
{
absorb = damage;
damage = 0;
}
data << log->target->GetPackGUID();
data << log->attacker->GetPackGUID();
data << uint32(log->spellInfo->Id);
data << uint32(damage); // damage amount
int32 overkill = damage - log->target->GetHealth();
data << uint32(overkill > 0 ? overkill : 0); // overkill
data << uint8 (log->schoolMask); // damage school
data << uint32(absorb); // AbsorbedDamage
data << uint32(log->resist); // resist
data << uint8 (log->physicalLog); // if 1, then client show spell name (example: %s's ranged shot hit %s for %u school or %s suffers %u school damage from %s's spell_name
data << uint8 (log->unused); // unused
data << uint32(log->blocked); // blocked
data << uint32(log->HitInfo);
data << uint32(log->HitInfo);
data << uint8(log->HitInfo & (SPELL_HIT_TYPE_CRIT_DEBUG | SPELL_HIT_TYPE_HIT_DEBUG | SPELL_HIT_TYPE_ATTACK_TABLE_DEBUG));
//if (log->HitInfo & SPELL_HIT_TYPE_CRIT_DEBUG)
//{
// data << float(log->CritRoll);
// data << float(log->CritNeeded);
//}
//if (log->HitInfo & SPELL_HIT_TYPE_HIT_DEBUG)
//{
// data << float(log->HitRoll);
// data << float(log->HitNeeded);
//}
//if (log->HitInfo & SPELL_HIT_TYPE_ATTACK_TABLE_DEBUG)
//{
// data << float(log->MissChance);
// data << float(log->DodgeChance);
// data << float(log->ParryChance);
// data << float(log->BlockChance);
// data << float(log->GlanceChance);
// data << float(log->CrushChance);
//}
SendMessageToSet(&data, true);
}

lua:

local function OnPacketSend(event, packet, player)
if packet:GetOpcode() == 592 then -- Direct damage combat log
local packetSize = packet:GetSize()
print("Packet size: " .. tostring(packetSize))

    local TargetGUID = packet:ReadGUID()
    print("Target GUID Byte " .. tostring(TargetGUID))

    local AttackerGUID = packet:ReadGUID()
    print("Attacker GUID Byte " .. tostring(AttackerGUID))

    -- The following values are generally accurate
    -- Read spell ID (4 bytes)
    local spellId = packet:ReadULong()
    print("Spell ID: " .. spellId)

    -- Read damage value (4 bytes)
    local damage = packet:ReadULong()
    print("Damage: " .. damage)

    -- Read overkill value (4 bytes)
    local overkill = packet:ReadULong()
    print("Overkill: " .. overkill)

    -- Read damage type (1 byte)
    local schoolMask = packet:ReadUByte()
    print("School Mask: " .. schoolMask)

    -- Read absorbed damage value (4 bytes)
    local absorb = packet:ReadULong()
    print("Absorb: " .. absorb)

    -- Read resisted damage value (4 bytes)
    local resist = packet:ReadULong()
    print("Resist: " .. resist)

    -- Read physical log flag (1 byte)
    local physicalLog = packet:ReadUByte()
    print("Physical Log: " .. physicalLog)

    -- Read unused field (1 byte)
    local unused = packet:ReadUByte()
    print("Unused: " .. unused)

    -- Read blocked damage value (4 bytes)
    local blocked = packet:ReadULong()
    print("Blocked: " .. blocked)

    -- Read hit info (4 bytes)
    local hitInfo = packet:ReadULong()
    print("Hit Info: " .. hitInfo)

    -- Read hit info (duplicate) (4 bytes)
    local hitInfo2 = packet:ReadULong()
    print("Hit Info 2: " .. hitInfo2)

    -- Read extended data flag (1 byte)
    local hitInfo3 = packet:ReadUByte()
    print("Hit Info 3: " .. hitInfo3)
end

end
RegisterServerEvent(7, OnPacketSend)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant