Beispiel #1
0
        public static ModifyEvent Serdes(ModifyEvent genericEvent, ISerializer s)
        {
            var subType = s.EnumU8("SubType", genericEvent?.SubType ?? ModifyType.Unk2);

            switch (subType)
            {
            case ModifyType.SetTemporarySwitch:     return(SetTemporarySwitchEvent.Serdes((SetTemporarySwitchEvent)genericEvent, s));

            case ModifyType.DisableEventChain:      return(DisableEventChainEvent.Serdes((DisableEventChainEvent)genericEvent, s));

            case ModifyType.SetNpcActive:           return(SetNpcActiveEvent.Serdes((SetNpcActiveEvent)genericEvent, s));

            case ModifyType.AddPartyMember:         return(AddPartyMemberEvent.Serdes((AddPartyMemberEvent)genericEvent, s));

            case ModifyType.AddRemoveInventoryItem: return(AddRemoveInventoryItemEvent.Serdes((AddRemoveInventoryItemEvent)genericEvent, s));

            case ModifyType.SetMapLighting:         return(SetMapLightingEvent.Serdes((SetMapLightingEvent)genericEvent, s));

            case ModifyType.ChangePartyGold:        return(ChangePartyGoldEvent.Serdes((ChangePartyGoldEvent)genericEvent, s));

            case ModifyType.ChangePartyRations:     return(ChangePartyRationsEvent.Serdes((ChangePartyRationsEvent)genericEvent, s));

            case ModifyType.ChangeTime:             return(ChangeTimeEvent.Serdes((ChangeTimeEvent)genericEvent, s));

            case ModifyType.SetPartyLeader:         return(SetPartyLeaderEvent.Serdes((SetPartyLeaderEvent)genericEvent, s));

            case ModifyType.SetTicker:              return(SetTickerEvent.Serdes((SetTickerEvent)genericEvent, s));

            case ModifyType.Unk2:                   return(DummyModifyEvent.Serdes((DummyModifyEvent)genericEvent, s));

            default: throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
        public static EventNode Load(BinaryReader br, int id, MapEventType type)
        {
            var subType = (ModifyType)br.ReadByte();

            switch (subType)
            {
            case ModifyType.SetTemporarySwitch:     return(SetTemporarySwitchEvent.Load(br, id, type, subType));

            case ModifyType.DisableEventChain:      return(DisableEventChainEvent.Load(br, id, type, subType));

            case ModifyType.SetNpcActive:           return(SetNpcActiveEvent.Load(br, id, type, subType));

            case ModifyType.AddPartyMember:         return(AddPartyMemberEvent.Load(br, id, type, subType));

            case ModifyType.AddRemoveInventoryItem: return(AddRemoveInventoryItemEvent.Load(br, id, type, subType));

            case ModifyType.SetMapLighting:         return(SetMapLightingEvent.Load(br, id, type, subType));

            case ModifyType.ChangePartyGold:        return(ChangePartyGoldEvent.Load(br, id, type, subType));

            case ModifyType.ChangePartyRations:     return(ChangePartyRationsEvent.Load(br, id, type, subType));

            case ModifyType.ChangeTime:             return(ChangeTimeEvent.Load(br, id, type, subType));

            case ModifyType.SetPartyLeader:         return(SetPartyLeaderEvent.Load(br, id, type, subType));

            case ModifyType.SetTicker:              return(SetTickerEvent.Load(br, id, type, subType));

            case ModifyType.Unk2:                   return(DummyModifyEvent.Load(br, id, type, subType));

            default: throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #3
0
 public static DisableEventChainEvent Serdes(DisableEventChainEvent e, ISerializer s)
 {
     e ??= new DisableEventChainEvent();
     s.Begin();
     e.Unk2        = s.UInt8(nameof(Unk2), e.Unk2);
     e.ChainNumber = s.UInt8(nameof(ChainNumber), e.ChainNumber);
     e.Unk4        = s.UInt8(nameof(Unk4), e.Unk4);
     e.Unk5        = s.UInt8(nameof(Unk5), e.Unk5);
     e.Unk6        = s.UInt16(nameof(Unk6), e.Unk6);
     e.Unk8        = s.UInt16(nameof(Unk8), e.Unk8);
     ApiUtil.Assert(e.Unk2 == 1 || e.Unk2 == 0 || e.Unk2 == 2); // Usually 1
     s.End();
     return(e);
 }
Beispiel #4
0
        public static EventNode Load(BinaryReader br, int id, MapEventType type, ModifyType subType)
        {
            var e = new DisableEventChainEvent
            {
                Unk2        = br.ReadByte(),   // 2
                ChainNumber = br.ReadByte(),   // 3
                Unk4        = br.ReadByte(),   // 4
                Unk5        = br.ReadByte(),   // 5
                Unk6        = br.ReadUInt16(), // 6
                Unk8        = br.ReadUInt16(), // 8
            };

            Debug.Assert(e.Unk2 == 1 || e.Unk2 == 0 || e.Unk2 == 2); // Usually 1
            return(new EventNode(id, e));
        }
Beispiel #5
0
 public static DisableEventChainEvent Serdes(DisableEventChainEvent e, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     e ??= new DisableEventChainEvent();
     e.Unk2        = s.UInt8(nameof(Unk2), e.Unk2);
     e.ChainNumber = s.UInt8(nameof(ChainNumber), e.ChainNumber);
     e.Unk4        = s.UInt8(nameof(Unk4), e.Unk4);
     e.Unk5        = s.UInt8(nameof(Unk5), e.Unk5);
     e.Unk6        = s.UInt16(nameof(Unk6), e.Unk6);
     e.Unk8        = s.UInt16(nameof(Unk8), e.Unk8);
     ApiUtil.Assert(e.Unk2 == 1 || e.Unk2 == 0 || e.Unk2 == 2); // Usually 1
     return(e);
 }
        public static DisableEventChainEvent Serdes(DisableEventChainEvent e, AssetId chainSource, ISerializer s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            e ??= new DisableEventChainEvent();
            e.Unk2        = s.UInt8(nameof(Unk2), e.Unk2);
            e.ChainSource = chainSource;
            e.ChainNumber = s.UInt8(nameof(ChainNumber), e.ChainNumber);
            int zeroes = s.UInt8(null, 0);

            zeroes += s.UInt8(null, 0);
            e.Unk6  = s.UInt16(nameof(Unk6), e.Unk6);
            zeroes += s.UInt16(null, 0);
            s.Assert(e.Unk2 == 0 || e.Unk2 == 1 || e.Unk2 == 2, "DisableEventChain: field 2 expected to be in [0..2]"); // Usually 1
            s.Assert(zeroes == 0, "DisableEventChain: fields 4,5,8 are expected to be 0");

            return(e);
        }
Beispiel #7
0
        public static ModifyEvent Serdes(ModifyEvent genericEvent, ISerializer s)
        {
            var subType = s.EnumU8("SubType", genericEvent?.SubType ?? ModifyType.Unk2);

            return(subType switch
            {
                ModifyType.SetTemporarySwitch => SetTemporarySwitchEvent.Serdes((SetTemporarySwitchEvent)genericEvent, s),
                ModifyType.DisableEventChain => DisableEventChainEvent.Serdes((DisableEventChainEvent)genericEvent, s),
                ModifyType.SetNpcActive => SetNpcActiveEvent.Serdes((SetNpcActiveEvent)genericEvent, s),
                ModifyType.AddPartyMember => AddPartyMemberEvent.Serdes((AddPartyMemberEvent)genericEvent, s),
                ModifyType.AddRemoveInventoryItem => AddRemoveInventoryItemEvent.Serdes((AddRemoveInventoryItemEvent)genericEvent, s),
                ModifyType.SetMapLighting => SetMapLightingEvent.Serdes((SetMapLightingEvent)genericEvent, s),
                ModifyType.ChangePartyGold => ChangePartyGoldEvent.Serdes((ChangePartyGoldEvent)genericEvent, s),
                ModifyType.ChangePartyRations => ChangePartyRationsEvent.Serdes((ChangePartyRationsEvent)genericEvent, s),
                ModifyType.ChangeTime => ChangeTimeEvent.Serdes((ChangeTimeEvent)genericEvent, s),
                ModifyType.SetPartyLeader => SetPartyLeaderEvent.Serdes((SetPartyLeaderEvent)genericEvent, s),
                ModifyType.SetTicker => SetTickerEvent.Serdes((SetTickerEvent)genericEvent, s),
                ModifyType.Unk2 => DummyModifyEvent.Serdes((DummyModifyEvent)genericEvent, s),
                _ => throw new ArgumentOutOfRangeException()
            });
Beispiel #8
0
        public static ModifyEvent BaseSerdes(ModifyEvent genericEvent, AssetMapping mapping, ISerializer s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            var subType = s.EnumU8("SubType", genericEvent?.SubType ?? ModifyType.Unk2);

            return(subType switch
            {
                ModifyType.SetTemporarySwitch => SetTemporarySwitchEvent.Serdes((SetTemporarySwitchEvent)genericEvent, mapping, s),
                ModifyType.DisableEventChain => DisableEventChainEvent.Serdes((DisableEventChainEvent)genericEvent, s),
                ModifyType.SetNpcActive => SetNpcActiveEvent.Serdes((SetNpcActiveEvent)genericEvent, s),
                ModifyType.AddPartyMember => AddPartyMemberEvent.Serdes((AddPartyMemberEvent)genericEvent, mapping, s),
                ModifyType.AddRemoveInventoryItem => AddRemoveInventoryItemEvent.Serdes((AddRemoveInventoryItemEvent)genericEvent, mapping, s),
                ModifyType.SetMapLighting => SetMapLightingEvent.Serdes((SetMapLightingEvent)genericEvent, s),
                ModifyType.ChangePartyGold => ChangePartyGoldEvent.Serdes((ChangePartyGoldEvent)genericEvent, s),
                ModifyType.ChangePartyRations => ChangePartyRationsEvent.Serdes((ChangePartyRationsEvent)genericEvent, s),
                ModifyType.ChangeTime => ChangeTimeEvent.Serdes((ChangeTimeEvent)genericEvent, s),
                ModifyType.SetPartyLeader => SetPartyLeaderEvent.Serdes((SetPartyLeaderEvent)genericEvent, mapping, s),
                ModifyType.SetTicker => SetTickerEvent.Serdes((SetTickerEvent)genericEvent, mapping, s),
                ModifyType.Unk2 => DummyModifyEvent.Serdes((DummyModifyEvent)genericEvent, s),
                _ => throw new InvalidEnumArgumentException(nameof(subType), (int)subType, typeof(ModifyType))
            });