Exemple #1
0
        protected virtual DirectedEventGroup ReadGroupEvent(AwesomeReader ar)
        {
            var eventGroup = new DirectedEventGroup();

            var num1 = ar.ReadInt32();
            var num2 = ar.ReadInt32();

            if (num1 != num2)
            {
                throw new NotSupportedException($"Expected \"{num1}\" to equal \"{num2}\" for start of directed event group");
            }

            if (!Enum.IsDefined(typeof(DirectedEventType), num1))
            {
                throw new NotSupportedException($"Value of \'{num1}\' is not supported for directed event!");
            }

            eventGroup.EventType    = (DirectedEventType)num1;
            eventGroup.DirectorName = ar.ReadString();
            ar.BaseStream.Position += 11; // Skip constants

            eventGroup.PropName  = ar.ReadString();
            eventGroup.Unknown1  = ar.ReadInt32();  // Usually 0
            eventGroup.PropName2 = ar.ReadString(); // Usually empty
            eventGroup.Unknown2  = ar.ReadInt32();  // Unknown enum... hopefully it's not important

            var count = ar.ReadInt32();

            eventGroup.Events = new List <IDirectedEvent>();

            switch (eventGroup.EventType)
            {
            case DirectedEventType.Float:
                eventGroup.Events.AddRange(RepeatFor <IDirectedEvent>(count,
                                                                      () => new DirectedEventFloat()
                {
                    Value    = ar.ReadSingle(),
                    Position = ar.ReadSingle()
                }));
                break;

            case DirectedEventType.TextFloat:
                eventGroup.Events.AddRange(RepeatFor <IDirectedEvent>(count,
                                                                      () => new DirectedEventTextFloat()
                {
                    Value    = ar.ReadSingle(),
                    Text     = ar.ReadString(),
                    Position = ar.ReadSingle()
                }));
                break;

            case DirectedEventType.Boolean:
                eventGroup.Events.AddRange(RepeatFor <IDirectedEvent>(count,
                                                                      () => new DirectedEventBoolean()
                {
                    Enabled  = ar.ReadBoolean(),
                    Position = ar.ReadSingle()
                }));
                break;

            case DirectedEventType.Vector4:
                eventGroup.Events.AddRange(RepeatFor <IDirectedEvent>(count,
                                                                      () => new DirectedEventVector4()
                {
                    Value = new Vector4()
                    {
                        X = ar.ReadSingle(),
                        Y = ar.ReadSingle(),
                        Z = ar.ReadSingle(),
                        W = ar.ReadSingle()
                    },
                    Position = ar.ReadSingle()
                }));
                break;

            case DirectedEventType.Vector3:
                eventGroup.Events.AddRange(RepeatFor <IDirectedEvent>(count,
                                                                      () => new DirectedEventVector3()
                {
                    Value = new Vector3()
                    {
                        X = ar.ReadSingle(),
                        Y = ar.ReadSingle(),
                        Z = ar.ReadSingle()
                    },
                    Position = ar.ReadSingle()
                }));
                break;

            case DirectedEventType.Text:
                eventGroup.Events.AddRange(RepeatFor <IDirectedEvent>(count,
                                                                      () => new DirectedEventText()
                {
                    Text     = ar.ReadString(),
                    Position = ar.ReadSingle()
                }));
                break;
            }

            return(eventGroup);
        }
Exemple #2
0
        protected void WriteGroupEvent(DirectedEventGroup eventGroup, AwesomeWriter aw)
        {
            // Write event type + director
            aw.Write((int)eventGroup.EventType);
            aw.Write((int)eventGroup.EventType);
            aw.Write((string)eventGroup.DirectorName);

            // Constants
            aw.Write((bool)true);
            aw.Write((bool)false);
            aw.Write((bool)true);
            aw.Write((int)0);
            aw.Write((int)5);

            // Write prop names + unknown ints
            aw.Write((string)eventGroup.PropName);
            aw.Write((int)eventGroup.Unknown1);
            aw.Write((string)eventGroup.PropName2);
            aw.Write((int)eventGroup.Unknown2);

            if (eventGroup.Events is null)
            {
                aw.Write((int)0);
                return;
            }

            // Write events
            aw.Write((int)eventGroup.Events.Count);

            switch (eventGroup.EventType)
            {
            case DirectedEventType.Float:
                var fEvents = CastEvents <DirectedEventFloat>(eventGroup.Events);

                foreach (var ev in fEvents)
                {
                    aw.Write((float)ev.Value);
                    aw.Write((float)ev.Position);
                }
                break;

            case DirectedEventType.TextFloat:
                var tfEvents = CastEvents <DirectedEventTextFloat>(eventGroup.Events);

                foreach (var ev in tfEvents)
                {
                    aw.Write((float)ev.Value);
                    aw.Write((string)ev.Text);
                    aw.Write((float)ev.Position);
                }
                break;

            case DirectedEventType.Boolean:
                var bEvents = CastEvents <DirectedEventBoolean>(eventGroup.Events);

                foreach (var ev in bEvents)
                {
                    aw.Write((bool)ev.Enabled);
                    aw.Write((float)ev.Position);
                }
                break;

            case DirectedEventType.Vector4:
                var v4Events = CastEvents <DirectedEventVector4>(eventGroup.Events);

                foreach (var ev in v4Events)
                {
                    aw.Write((float)ev.Value.X);
                    aw.Write((float)ev.Value.Y);
                    aw.Write((float)ev.Value.Z);
                    aw.Write((float)ev.Value.W);
                    aw.Write((float)ev.Position);
                }
                break;

            case DirectedEventType.Vector3:
                var v3Events = CastEvents <DirectedEventVector3>(eventGroup.Events);

                foreach (var ev in v3Events)
                {
                    aw.Write((float)ev.Value.X);
                    aw.Write((float)ev.Value.Y);
                    aw.Write((float)ev.Value.Z);
                    aw.Write((float)ev.Position);
                }
                break;

            case DirectedEventType.Text:
                var tEvents = CastEvents <DirectedEventText>(eventGroup.Events);

                foreach (var ev in tEvents)
                {
                    aw.Write((string)ev.Text);
                    aw.Write((float)ev.Position);
                }
                break;
            }
        }