public static DataChangeEvent Serdes(DataChangeEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (s.IsWriting() && e == null) { throw new ArgumentNullException(nameof(e)); } ChangeProperty property = s.EnumU8(nameof(ChangeProperty), e?.ChangeProperty ?? ChangeProperty.Unk0); return(property switch { ChangeProperty.Unk0 => ChangeUnk0Event.Serdes((ChangeUnk0Event)e, s), ChangeProperty.Health => ChangeHealthEvent.Serdes((ChangeHealthEvent)e, mapping, s), ChangeProperty.Mana => ChangeManaEvent.Serdes((ChangeManaEvent)e, mapping, s), ChangeProperty.Status => ChangeStatusEvent.Serdes((ChangeStatusEvent)e, mapping, s), ChangeProperty.Language => ChangeLanguageEvent.Serdes((ChangeLanguageEvent)e, mapping, s), ChangeProperty.Experience => ChangeExperienceEvent.Serdes((ChangeExperienceEvent)e, mapping, s), ChangeProperty.UnkB => ChangeUnkBEvent.Serdes((ChangeUnkBEvent)e, s), ChangeProperty.UnkC => ChangeUnkCEvent.Serdes((ChangeUnkCEvent)e, s), ChangeProperty.Item => ChangeItemEvent.Serdes((ChangeItemEvent)e, mapping, s), ChangeProperty.Gold => ChangeGoldEvent.Serdes((ChangeGoldEvent)e, mapping, s), ChangeProperty.Food => ChangeFoodEvent.Serdes((ChangeFoodEvent)e, mapping, s), _ => throw new FormatException($"Unexpected data change type \"{property}\"") });
public static ChangeFoodEvent Serdes(ChangeFoodEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new ChangeFoodEvent(); e.Operation = s.EnumU8(nameof(Operation), e.Operation); e.Unk3 = s.UInt8(nameof(Unk3), e.Unk3); int zeroed = s.UInt8(null, 0); e.PartyMemberId = PartyMemberId.SerdesU8(nameof(PartyMemberId), e.PartyMemberId, mapping, s); zeroed += s.UInt16(null, 0); e.Amount = s.UInt16(nameof(Amount), e.Amount); s.Assert(zeroed == 0, "ChangeFoodEvent: Expected bytes 4, 6 & 7 to be 0"); return(e); }