public static ActionEvent Serdes(ActionEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } var actionType = s.EnumU8(nameof(ActionType), e?.ActionType ?? 0); e ??= new ActionEvent(); var assetType = actionType switch { ActionType.AskAboutItem or ActionType.UseItem or ActionType.EquipItem or ActionType.UnequipItem or ActionType.PickupItem => AssetType.Item, ActionType.Word => AssetType.Word, ActionType.DialogueLine => AssetType.Unknown, _ => AssetType.Unknown }; e.ActionType = actionType; e.Unk2 = s.UInt8(nameof(Unk2), e.Unk2); e.Block = s.UInt8(nameof(Block), e.Block); e.Unk4 = s.UInt8(nameof(Unk4), e.Unk4); e.Unk5 = s.UInt8(nameof(Unk5), e.Unk5); e.Argument = AssetId.SerdesU16(nameof(Argument), e.Argument, assetType, mapping, s); e.Unk8 = s.UInt16(nameof(Unk8), e.Unk8); ApiUtil.Assert(e.Unk2 == 1 || ((int)e.ActionType == 14 && e.Unk2 == 2)); ApiUtil.Assert(e.Unk4 == 0); ApiUtil.Assert(e.Unk5 == 0); ApiUtil.Assert(e.Unk8 == 0); return(e); } byte Unk4 { get; set; } byte Unk5 { get; set; } ushort Unk8 { get; set; }
public static MapNpc Serdes(int _, MapNpc existing, MapType mapType, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } var npc = existing ?? new MapNpc(); byte id = (byte)npc.Id.ToDisk(mapping); id = s.UInt8(nameof(Id), id); // npc.Sound = (SampleId?)Tweak.Serdes(nameof(Sound), (byte?)npc.Sound, s.UInt8); npc.Sound = s.UInt8(nameof(Sound), npc.Sound); ushort?eventNumber = MaxToNullConverter.Serdes(nameof(npc.Node), npc.Node?.Id, s.UInt16); if (eventNumber != null && npc.Node == null) { npc.Node = new DummyEventNode(eventNumber.Value); } switch (mapType) { case MapType.ThreeD: npc.SpriteOrGroup = AssetId.SerdesU16(nameof(SpriteOrGroup), npc.SpriteOrGroup, AssetType.ObjectGroup, mapping, s); break; case MapType.TwoD: npc.SpriteOrGroup = SpriteId.SerdesU16(nameof(SpriteOrGroup), npc.SpriteOrGroup, AssetType.BigNpcGraphics, mapping, s); break; case MapType.TwoDOutdoors: npc.SpriteOrGroup = SpriteId.SerdesU16(nameof(SpriteOrGroup), npc.SpriteOrGroup, AssetType.SmallNpcGraphics, mapping, s); break; default: throw new ArgumentOutOfRangeException(nameof(mapType), mapType, null); } npc.Flags = s.EnumU8(nameof(Flags), npc.Flags); npc.Movement = s.EnumU8(nameof(Movement), npc.Movement); npc.Unk8 = s.UInt8(nameof(Unk8), npc.Unk8); npc.Unk9 = s.UInt8(nameof(Unk9), npc.Unk9); var assetType = (npc.Flags & NpcFlags.IsMonster) != 0 ? AssetType.MonsterGroup : AssetType.Npc; npc.Id = AssetId.FromDisk(assetType, id, mapping); return(npc); }
public static QueryEvent Serdes(QueryEvent e, AssetMapping mapping, ISerializer s, TextId textSourceId) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new QueryEvent(textSourceId); e.QueryType = s.EnumU8(nameof(QueryType), e.QueryType); e.Operation = s.EnumU8(nameof(Operation), e.Operation); e.Immediate = s.UInt8(nameof(Immediate), e.Immediate); e.Unk4 = s.UInt8(nameof(Unk4), e.Unk4); e.Unk5 = s.UInt8(nameof(Unk5), e.Unk5); e._value = e.AssetType != AssetType.None && e.AssetType != AssetType.Unknown ? AssetId.SerdesU16("Argument", AssetId.FromUInt32(e._value), e.AssetType, mapping, s).ToUInt32() : s.UInt16("Argument", (ushort)e._value); ApiUtil.Assert(e.Unk4 == 0); ApiUtil.Assert(e.Unk5 == 0); return(e); }