예제 #1
0
        public static LMTM3AEntry PrepareTheKeyframes(LMTM3AEntry M3a)
        {
            M3a.KeyFrames = new List <KeyFrame>();

            foreach (Track track in M3a.Tracks)
            {
                IEnumerable <KeyFrame> Key = LMTM3ATrackBuffer.Convert(track.BufferType, track.Buffer, track.ExtremesArray, track.BoneID, track.BufferKind);
                M3a.KeyFrames.AddRange(Key.ToList());
            }

            return(M3a);
        }
예제 #2
0
        public LMTM3AEntry FillM3AProprties(LMTM3AEntry Anim, int datalength, int ID, int RowTotal, int SecondOffset, BinaryReader bnr, int SecondaryCount, LMTEntry lmtentry)
        {
            //Reads the AnnimBlock Header.
            LMTM3AEntry M3a = new LMTM3AEntry();

            M3a.KeyFrames           = new List <KeyFrame>();
            M3a._FileType           = ".m3a";
            M3a.FileExt             = M3a._FileType;
            bnr.BaseStream.Position = lmtentry.OffsetList[ID];
            M3a.TrackPointer        = bnr.ReadInt32();
            bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
            M3a.TrackCount          = bnr.ReadInt32();
            M3a.FrameCount          = bnr.ReadInt32();
            M3a._FrameTotal         = M3a.FrameCount;
            M3a.LoopFrame           = bnr.ReadInt32();

            M3a.UnknownValue14 = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), M3a.UnknownValue14);
            M3a.UnknownValue18 = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), M3a.UnknownValue18);
            M3a.UnknownValue1C = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), M3a.UnknownValue1C);

            M3a.EndFramesAdditiveScenePosition.W = bnr.ReadSingle();
            M3a.EndFramesAdditiveScenePosition.X = bnr.ReadSingle();
            M3a.EndFramesAdditiveScenePosition.Y = bnr.ReadSingle();
            M3a.EndFramesAdditiveScenePosition.Z = bnr.ReadSingle();

            M3a.EndFramesAdditiveSceneRotation.W = bnr.ReadSingle();
            M3a.EndFramesAdditiveSceneRotation.X = bnr.ReadSingle();
            M3a.EndFramesAdditiveSceneRotation.Y = bnr.ReadSingle();
            M3a.EndFramesAdditiveSceneRotation.Z = bnr.ReadSingle();

            M3a.AnimationFlags = bnr.ReadInt64();

            M3a.EventClassesPointer = bnr.ReadInt32();
            bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
            M3a.AnimDataSize        = (M3a.EventClassesPointer - M3a.TrackPointer) + 352;
            M3a.FloatTracksPointer  = bnr.ReadInt32();
            bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

            M3a.Unknown58 = bnr.ReadInt32();
            M3a.Unknown5C = bnr.ReadSingle();

            PrevOffsetThree         = Convert.ToInt32(bnr.BaseStream.Position);
            bnr.BaseStream.Position = M3a.TrackPointer;
            M3a.RawData             = new byte[M3a.AnimDataSize];
            M3a.RawData             = bnr.ReadBytes(M3a.AnimDataSize);
            M3a.MotionData          = new byte[96];
            bnr.BaseStream.Position = lmtentry.OffsetList[ID];
            M3a.MotionData          = bnr.ReadBytes(96);
            bnr.BaseStream.Position = PrevOffsetThree;

            //Gets the Tracks.
            M3a.Tracks = new List <Track>();
            bnr.BaseStream.Position = M3a.TrackPointer;

            for (int j = 0; j < M3a.TrackCount; j++)
            {
                Track track = new Track();
                track.TrackNumber   = j;
                track.ExtremesArray = new float[8];
                track.BufferType    = bnr.ReadByte();
                BufferType type = (BufferType)track.BufferType;
                track.BufferKind        = type.ToString();
                track.TrackType         = bnr.ReadByte();
                track.BoneType          = bnr.ReadByte();
                track.BoneID            = bnr.ReadByte();
                track.Weight            = bnr.ReadSingle();
                track.BufferSize        = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                track.BufferPointer     = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                track.ReferenceData.W   = bnr.ReadSingle();
                track.ReferenceData.X   = bnr.ReadSingle();
                track.ReferenceData.Y   = bnr.ReadSingle();
                track.ReferenceData.Z   = bnr.ReadSingle();
                track.ExtremesPointer   = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                PrevOffset = Convert.ToInt32(bnr.BaseStream.Position);


                if (track.BufferSize != 0)
                {
                    //MessageBox.Show("Track #" + j + " inside " + lmtentry.EntryName + "\nhas a buffer size that is NOT ZERO.", "Debug Note");
                    bnr.BaseStream.Position = track.BufferPointer;
                    track.Buffer            = bnr.ReadBytes(track.BufferSize);
                }

                else
                {
                    track.Buffer = new byte[0];
                }


                if (track.ExtremesPointer != 0)
                {
                    //MessageBox.Show("Track # " + j + " inside " + lmtentry.EntryName + "\nhas an actual extremes pointer.", "Debug Note");
                    bnr.BaseStream.Position = Convert.ToInt32(track.ExtremesPointer);

                    track.Extremes = new Extremes();

                    track.Extremes.min.W = bnr.ReadSingle();
                    track.Extremes.min.X = bnr.ReadSingle();
                    track.Extremes.min.Y = bnr.ReadSingle();
                    track.Extremes.min.Z = bnr.ReadSingle();

                    track.Extremes.max.W = bnr.ReadSingle();
                    track.Extremes.max.X = bnr.ReadSingle();
                    track.Extremes.max.Y = bnr.ReadSingle();
                    track.Extremes.max.Z = bnr.ReadSingle();

                    track.ExtremesArray[0] = track.Extremes.min.W;
                    track.ExtremesArray[1] = track.Extremes.min.X;
                    track.ExtremesArray[2] = track.Extremes.min.Y;
                    track.ExtremesArray[3] = track.Extremes.min.Z;
                    track.ExtremesArray[4] = track.Extremes.max.W;
                    track.ExtremesArray[5] = track.Extremes.max.X;
                    track.ExtremesArray[6] = track.Extremes.max.Y;
                    track.ExtremesArray[7] = track.Extremes.max.Z;

                    //Keyframes Take 1.

                    IEnumerable <KeyFrame> Key = LMTM3ATrackBuffer.Convert(track.BufferType, track.Buffer, track.ExtremesArray, track.BoneID, track.BufferKind);
                    M3a.KeyFrames.AddRange(Key.ToList());
                }

                else
                {
                    IEnumerable <KeyFrame> Key = LMTM3ATrackBuffer.Convert(track.BufferType, track.Buffer, track.ExtremesArray, track.BoneID, track.BufferKind);
                    M3a.KeyFrames.AddRange(Key.ToList());
                }

                bnr.BaseStream.Position = PrevOffset;
                M3a.Tracks.Add(track);
            }

            bnr.BaseStream.Position = M3a.EventClassesPointer;
            //Animation Events.
            M3a.Events = new List <AnimEvent>();

            for (int k = 0; k < 4; k++)
            {
                AnimEvent animEvent = new AnimEvent();

                for (int l = 0; l < 32; l++)
                {
                    animEvent.EventRemap = new List <int>();
                    animEvent.EventRemap.Add(bnr.ReadInt16());
                }

                animEvent.EventCount    = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

                animEvent.EventsPointer = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

                PrevOffsetTwo           = Convert.ToInt32(bnr.BaseStream.Position);
                bnr.BaseStream.Position = animEvent.EventsPointer;
                animEvent.EventBit      = bnr.ReadInt32();
                animEvent.FrameNumber   = bnr.ReadInt32();

                M3a.Events.Add(animEvent);
                bnr.BaseStream.Position = PrevOffsetTwo;
            }

            M3a.AnimationID = ID;
            M3a.FileName    = "AnimationID" + M3a.AnimationID + ".m3a";
            M3a.ShortName   = "AnimationID" + M3a.AnimationID;
            M3a._IsBlank    = false;
            Anim            = M3a;

            //Subtracts pointers in there by the data offset to get their base value.
            int OffTemp = 0;

            using (MemoryStream msm3a = new MemoryStream(M3a.RawData))
            {
                using (BinaryReader brm3a = new BinaryReader(msm3a))
                {
                    using (BinaryWriter bwm3a = new BinaryWriter(msm3a))
                    {
                        //Adjusts the offsets in the Rawdata of the m3a.
                        bwm3a.BaseStream.Position = 0;

                        for (int y = 0; y < M3a.TrackCount; y++)
                        {
                            bwm3a.BaseStream.Position = 0;
                            bwm3a.BaseStream.Position = 16 + (48 * y);
                            OffTemp = brm3a.ReadInt32();
                            bwm3a.BaseStream.Position = (bwm3a.BaseStream.Position - 4);
                            if (OffTemp > 0)
                            {
                                OffTemp = OffTemp - M3a.TrackPointer;
                                bwm3a.Write(OffTemp);
                            }
                            bwm3a.BaseStream.Position = 40 + (48 * y);
                            OffTemp = brm3a.ReadInt32();
                            bwm3a.BaseStream.Position = (bwm3a.BaseStream.Position - 4);
                            if (OffTemp > 0)
                            {
                                OffTemp = OffTemp - M3a.TrackPointer;
                                bwm3a.Write(OffTemp);
                            }
                        }

                        //Adjusts the offsets in the Events.
                        bwm3a.BaseStream.Position = (bwm3a.BaseStream.Length - 280);

                        OffTemp = M3a.RawData.Length - 32;

                        bwm3a.Write(OffTemp);
                        bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                        OffTemp = M3a.RawData.Length - 24;

                        bwm3a.Write(OffTemp);
                        bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                        OffTemp = M3a.RawData.Length - 16;

                        bwm3a.Write(OffTemp);
                        bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                        OffTemp = M3a.RawData.Length - 8;

                        bwm3a.Write(OffTemp);
                    }
                }
            }

            //Appends the Animation Block Data to the FullData.
            M3a.FullData    = new byte[(M3a.AnimDataSize + 96)];
            M3a._FileLength = M3a.FullData.LongLength;
            Array.Copy(M3a.RawData, 0, M3a.FullData, 0, M3a.RawData.Length);
            Array.Copy(M3a.MotionData, 0, M3a.FullData, M3a.RawData.Length, M3a.MotionData.Length);

            return(Anim);
        }