using System; using System.Buffers.Binary; namespace AcDream.Core.Net.Messages; /// /// Inbound 0x019E PlayerKilled top-level GameMessage. /// Server announcement that a player was killed in combat — used for /// the death-message scroll and chat-log lines like /// "Caith was killed by an Olthoi Soldier." /// /// /// Wire layout (port from holtburger /// references/holtburger/.../messages/combat/types.rs::PlayerKilledData, /// see also opcodes.rs:150): /// /// u32 opcode // 0x019E /// string16L deathMessage /// u32 victimGuid /// u32 killerGuid /// /// /// public static class PlayerKilled { public const uint Opcode = 0x019Eu; public readonly record struct Parsed( string DeathMessage, uint VictimGuid, uint KillerGuid); public static Parsed? TryParse(byte[] body) { if (body is null || body.Length < 4) return null; uint opcode = BinaryPrimitives.ReadUInt32LittleEndian(body); if (opcode != Opcode) return null; try { int pos = 4; string deathMessage = StringReader.ReadString16L(body, ref pos); if (body.Length - pos < 8) return null; uint victimGuid = BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(pos)); pos += 4; uint killerGuid = BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(pos)); return new Parsed(deathMessage, victimGuid, killerGuid); } catch { return null; } } }