azerothcore / mod-eluna

Eluna Lua Engine © for WoW Emulators
https://elunaluaengine.github.io/
GNU General Public License v3.0
101 stars 130 forks source link

ReadGUID() Wrong value was read #194

Open zwisus opened 2 months ago

zwisus commented 2 months ago

\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)