コード例 #1
0
        public LMTM3AEntry FillBlankM3A(LMTM3AEntry Anim, int datalength, int ID, int RowTotal, int SecondOffset, BinaryReader bnr, int SecondaryCount, LMTEntry lmtentry)
        {
            LMTM3AEntry M3a = new LMTM3AEntry();

            M3a._FileType           = ".m3a";
            M3a.FileExt             = ".m3a";
            M3a.TrackPointer        = -1;
            M3a.TrackCount          = -1;
            M3a.FrameCount          = -1;
            M3a._FrameTotal         = -1;
            M3a.LoopFrame           = -1;
            M3a.AnimationFlags      = -1;
            M3a.EventClassesPointer = -1;
            M3a.AnimDataSize        = -1;
            M3a.AnimationID         = ID;
            M3a.FileName            = "AnimationID" + M3a.AnimationID + ".m3a";
            M3a.ShortName           = "AnimationID" + M3a.AnimationID;
            M3a.RawData             = new byte[1];
            M3a.RawData[0]          = 0x00;
            M3a.MotionData          = new byte[1];
            M3a.MotionData[0]       = 0x00;
            M3a.FullData            = new byte[1];
            M3a.FullData[0]         = 0x00;
            M3a.IsBlank             = true;
            Anim = M3a;
            return(Anim);
        }
コード例 #2
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);
        }
コード例 #3
0
        public static LMTM3AEntry ParseM3AYMLPart1(LMTM3AEntry M3a, string filename, LMTM3AEntry OLdM3a)
        {
            LMTM3AEntry NewM3a = new LMTM3AEntry();

            using (var input = File.OpenText(filename))
            {
                var deserializer = new DeserializerBuilder().WithTagMapping("!LMTM3AEntry", typeof(ThreeWorkTool.Resources.Wrappers.LMTM3AEntry)).Build();
                NewM3a = deserializer.Deserialize <LMTM3AEntry>(input);
            }

            foreach (KeyFrame Key in NewM3a.KeyFrames)
            {
            }

            return(NewM3a);
        }
コード例 #4
0
        public static LMTEntry ReplaceLMTEntry(TreeView tree, ArcEntryWrapper node, ArcEntryWrapper OldNode, string filename, Type filetype = null)
        {
            LMTEntry lmtentry = new LMTEntry();
            LMTEntry oldentry = new LMTEntry();

            oldentry = OldNode.Tag as LMTEntry;

            tree.BeginUpdate();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    //We build the lmtentry starting from the uncompressed data.
                    lmtentry.UncompressedData        = System.IO.File.ReadAllBytes(filename);
                    lmtentry.DecompressedFileLength  = lmtentry.UncompressedData.Length;
                    lmtentry._DecompressedFileLength = lmtentry.UncompressedData.Length;

                    //Then Compress.
                    lmtentry.CompressedData        = Zlibber.Compressor(lmtentry.UncompressedData);
                    lmtentry.CompressedFileLength  = lmtentry.CompressedData.Length;
                    lmtentry._CompressedFileLength = lmtentry.CompressedData.Length;

                    //Gets the filename of the file to inject without the directory.
                    string trname = filename;
                    while (trname.Contains("\\"))
                    {
                        trname = trname.Substring(trname.IndexOf("\\") + 1);
                    }

                    //Enters name related parameters of the lmtentry.
                    lmtentry.TrueName  = trname;
                    lmtentry._FileName = lmtentry.TrueName;
                    lmtentry.TrueName  = Path.GetFileNameWithoutExtension(trname);
                    lmtentry.FileExt   = trname.Substring(trname.LastIndexOf("."));
                    lmtentry._FileType = lmtentry.FileExt;

                    string TypeHash = "";

                    //Looks through the archive_filetypes.cfg file to find the typehash associated with the extension.
                    try
                    {
                        using (var sr2 = new StreamReader("archive_filetypes.cfg"))
                        {
                            while (!sr2.EndOfStream)
                            {
                                var keyword = Console.ReadLine() ?? lmtentry.FileExt;
                                var line    = sr2.ReadLine();
                                if (String.IsNullOrEmpty(line))
                                {
                                    continue;
                                }
                                if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                {
                                    TypeHash          = line;
                                    TypeHash          = TypeHash.Split(' ')[0];
                                    lmtentry.TypeHash = TypeHash;
                                    break;
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        MessageBox.Show("I cannot find and/or access archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                        using (StreamWriter sw = File.AppendText("Log.txt"))
                        {
                            sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                        }
                        return(null);
                    }


                    int count          = 0;
                    int SecondaryCount = 0;

                    using (MemoryStream msm3a = new MemoryStream(lmtentry.UncompressedData))
                    {
                        using (BinaryReader brm3a = new BinaryReader(msm3a))
                        {
                            bnr.BaseStream.Position = 6;
                            lmtentry.Version        = bnr.ReadInt16();
                            lmtentry.EntryCount     = lmtentry.Version;
                            lmtentry.OffsetList     = new List <int>();
                            lmtentry.LstM3A         = new List <LMTM3AEntry>();

                            //Gets all the offsets. ALL OF THEM.
                            while (count < (lmtentry.Version))
                            {
                                lmtentry.OffsetList.Add(bnr.ReadInt32());
                                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                                count++;
                            }

                            count = 0;
                            //Goes through the offsets to get the data. Ignores offsets of 0.
                            for (int i = 0; i < lmtentry.OffsetList.Count; i++)
                            {
                                if (lmtentry.OffsetList[i] != 0)
                                {
                                    LMTM3AEntry aEntry = new LMTM3AEntry();
                                    aEntry = aEntry.FillM3AProprties(aEntry, lmtentry.Length, i, lmtentry.RowCount, lmtentry.SecondOffsetList, bnr, SecondaryCount, lmtentry);
                                    lmtentry.LstM3A.Add(aEntry);
                                }
                                else
                                {
                                    LMTM3AEntry aEntry = new LMTM3AEntry();
                                    aEntry = aEntry.FillBlankM3A(aEntry, lmtentry.Length, i, lmtentry.RowCount, lmtentry.SecondOffsetList, bnr, SecondaryCount, lmtentry);
                                    lmtentry.LstM3A.Add(aEntry);
                                }
                            }
                        }
                    }


                    lmtentry.TrueName  = oldentry.TrueName;
                    lmtentry._FileName = oldentry._FileName;
                    lmtentry.EntryName = oldentry.EntryName;


                    var tag = node.Tag;
                    if (tag is LMTEntry)
                    {
                        oldentry = tag as LMTEntry;
                    }
                    string path  = "";
                    int    index = oldentry.EntryName.LastIndexOf("\\");
                    if (index > 0)
                    {
                        path = oldentry.EntryName.Substring(0, index);
                    }

                    lmtentry.EntryName = path + "\\" + lmtentry.TrueName;

                    tag = lmtentry;

                    if (node.Tag is LMTEntry)
                    {
                        node.Tag  = lmtentry;
                        node.Name = Path.GetFileNameWithoutExtension(lmtentry.EntryName);
                        node.Text = Path.GetFileNameWithoutExtension(lmtentry.EntryName);
                    }

                    var aew = node as ArcEntryWrapper;

                    string type = node.GetType().ToString();
                    if (type == "ThreeWorkTool.Resources.Wrappers.ArcEntryWrapper")
                    {
                        aew.entryfile = lmtentry;
                    }

                    node           = aew;
                    node.entryfile = lmtentry;

                    /*
                     * //ArcEntryWrapper aew = new ArcEntryWrapper();
                     * if (node is ArcEntryWrapper)
                     * {
                     *  node.entryfile as ArcEntryWrapper = node.Tag;
                     * }
                     */
                    tree.EndUpdate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read Error! Here's the exception info:\n" + ex);
                }
            }



            return(node.entryfile as LMTEntry);
        }
コード例 #5
0
        public static LMTEntry RebuildLMTEntry(TreeView tree, ArcEntryWrapper node, Type filetype = null)
        {
            //Gets the nodes and stuff and starts rebuilding from scratch.
            LMTEntry lMT = new LMTEntry();

            int ChildCount = 0;

            //Fetches and Iterates through all the children and extracts the files tagged in the nodes.
            List <TreeNode> Children = new List <TreeNode>();

            foreach (TreeNode thisNode in tree.SelectedNode.Nodes)
            {
                Children.Add(thisNode);
                ChildCount++;
            }



            //Now to rebuild from scratch.
            List <byte> NewUncompressedData = new List <byte>();

            byte[] Header           = { 0x4C, 0x4D, 0x54, 0x00, 0x43, 0x00 };
            byte[] PlaceHolderEntry = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            byte[] BlankLine        = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            byte[] BlankHalf        = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

            //Gets Entry Count.
            short Total = Convert.ToInt16(Children.Count);

            NewUncompressedData.AddRange(Header);
            NewUncompressedData.AddRange(BitConverter.GetBytes(Total));
            //Adds in dummy bytes for Entry Offset List based on amount of child nodes of the lmt node. Adds an extra entry because the default LMTs do.
            NewUncompressedData.AddRange(PlaceHolderEntry);
            for (int w = 0; w < Children.Count; w++)
            {
                NewUncompressedData.AddRange(PlaceHolderEntry);
            }
            int MA3DataStart = NewUncompressedData.Count;

            lMT.OffsetList = new List <int>();
            List <int>  DataOffsetList = new List <int>();
            List <bool> IsBlank        = new List <bool>();

            //Starts putting in the Block Data and updating the offset list.
            lMT.OffsetList.Add(NewUncompressedData.Count);
            for (int x = 0; x < Children.Count; x++)
            {
                TreeNode    TN  = tree.SelectedNode.Nodes.Find(x.ToString(), true)[0];
                LMTM3AEntry tag = TN.Tag as LMTM3AEntry;
                if (tag != null)
                {
                    IsBlank.Add(tag.IsBlank);
                    if (tag.IsBlank == false)
                    {
                        NewUncompressedData.AddRange(tag.MotionData);

                        /*
                         * //The ending of the block data segments always has the raw data start on the 8 of the hex instead of the 0 of the hex offset for some reason.
                         * //This is there to preserve that.
                         * if (x == (Children.Count - 1))
                         * {
                         *  NewUncompressedData.AddRange(BlankHalf);
                         * }
                         * else
                         * {
                         *  NewUncompressedData.AddRange(BlankLine);
                         * }
                         */
                    }
                }
                lMT.OffsetList.Add(NewUncompressedData.Count);
            }
            //Now for the RawData. Oh joy.
            DataOffsetList.Add(NewUncompressedData.Count);
            for (int y = 0; y < Children.Count; y++)
            {
                TreeNode    TN  = tree.SelectedNode.Nodes.Find(y.ToString(), true)[0];
                LMTM3AEntry tag = TN.Tag as LMTM3AEntry;
                if (tag != null)
                {
                    if (IsBlank[y] == false)
                    {
                        NewUncompressedData.AddRange(tag.RawData);
                        DataOffsetList.Add(NewUncompressedData.Count);
                    }
                }
            }
            byte[]     UnCompressedBuffer = NewUncompressedData.ToArray();
            int        Capacity           = UnCompressedBuffer.Length;
            int        EntryAmount        = lMT.OffsetList.Count - 1;
            List <int> IndexRows          = new List <int>();

            using (MemoryStream ms3 = new MemoryStream(UnCompressedBuffer))
            {
                using (BinaryReader br3 = new BinaryReader(ms3))
                {
                    using (BinaryWriter bw3 = new BinaryWriter(ms3))
                    {
                        bw3.BaseStream.Position = 8;
                        //Offsets For The Block Data.
                        for (int z = 0; z < EntryAmount; z++)
                        {
                            if (IsBlank[z] == false)
                            {
                                bw3.Write(lMT.OffsetList[z]);
                                bw3.BaseStream.Position = bw3.BaseStream.Position + 4;
                            }
                            else
                            {
                                bw3.BaseStream.Position = bw3.BaseStream.Position + 8;
                            }
                        }
                        //Offsets For the Raw Data.
                        int EndingOffset = 0;
                        int OffTemp      = 0;
                        bw3.BaseStream.Position = lMT.OffsetList[0];
                        for (int zz = 0; zz < DataOffsetList.Count; zz++)
                        {
                            bw3.Write(DataOffsetList[zz]);

                            bw3.BaseStream.Position = bw3.BaseStream.Position + 4;
                            IndexRows.Add(br3.ReadInt32());
                            bw3.BaseStream.Position = bw3.BaseStream.Position + 60;
                            //bw3.BaseStream.Position = bw3.BaseStream.Position + 68;
                            if (zz == (DataOffsetList.Count - 1))
                            {
                                EndingOffset = UnCompressedBuffer.Length;
                                bw3.Write(EndingOffset);
                            }
                            else
                            {
                                EndingOffset = (DataOffsetList[zz + 1] - 352);
                                bw3.Write(EndingOffset);
                            }


                            bw3.BaseStream.Position = bw3.BaseStream.Position + 20;
                        }
                        //Lastly the offsets in the M3A entries themeslves. Sigh........
                        bw3.BaseStream.Position = DataOffsetList[0];
                        int CountTemp = DataOffsetList.Count - 1;
                        for (int yy = 0; yy < CountTemp; yy++)
                        {
                            bw3.BaseStream.Position = DataOffsetList[yy];
                            //bw3.BaseStream.Position = IndexRows[yy];
                            for (int xx = 0; xx < IndexRows[yy]; xx++)
                            {
                                bw3.BaseStream.Position = DataOffsetList[yy];
                                bw3.BaseStream.Position = DataOffsetList[yy] + 16 + (48 * xx);
                                OffTemp = br3.ReadInt32();
                                bw3.BaseStream.Position = (bw3.BaseStream.Position - 4);
                                if (OffTemp > 0)
                                {
                                    OffTemp = OffTemp + DataOffsetList[yy];
                                    bw3.Write(OffTemp);
                                }
                                bw3.BaseStream.Position = DataOffsetList[yy] + 40 + (48 * xx);
                                OffTemp = br3.ReadInt32();
                                bw3.BaseStream.Position = (bw3.BaseStream.Position - 4);
                                if (OffTemp > 0)
                                {
                                    OffTemp = OffTemp + DataOffsetList[yy];
                                    bw3.Write(OffTemp);
                                }
                            }

                            //Footer Things.
                            bw3.BaseStream.Position = (DataOffsetList[(yy + 1)] - 280);
                            //OffTemp = br3.ReadInt32();
                            OffTemp = DataOffsetList[(yy + 1)] - 32;
                            //bw3.BaseStream.Position = (bw3.BaseStream.Position - 4);
                            bw3.Write(OffTemp);
                            bw3.BaseStream.Position = bw3.BaseStream.Position + 76;
                            //OffTemp = br3.ReadInt32();
                            OffTemp = DataOffsetList[(yy + 1)] - 24;
                            //bw3.BaseStream.Position = (bw3.BaseStream.Position - 4);
                            bw3.Write(OffTemp);
                            bw3.BaseStream.Position = bw3.BaseStream.Position + 76;
                            //OffTemp = br3.ReadInt32();
                            OffTemp = DataOffsetList[(yy + 1)] - 16;
                            //bw3.BaseStream.Position = (bw3.BaseStream.Position - 4);
                            bw3.Write(OffTemp);
                            bw3.BaseStream.Position = bw3.BaseStream.Position + 76;
                            //OffTemp = br3.ReadInt32();
                            OffTemp = DataOffsetList[(yy + 1)] - 8;
                            //bw3.BaseStream.Position = (bw3.BaseStream.Position - 4);
                            bw3.Write(OffTemp);
                        }
                    }
                }
            }

            lMT.UncompressedData = UnCompressedBuffer;
            lMT.CompressedData   = Zlibber.Compressor(lMT.UncompressedData);
            lMT.EntryCount       = Children.Count;
            lMT._EntryCount      = Children.Count;
            lMT._FileType        = ".lmt";
            lMT.FileExt          = ".lmt";

            return(lMT);
        }
コード例 #6
0
        public static LMTEntry InsertLMTEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            LMTEntry lmtentry = new LMTEntry();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    //We build the lmtentry starting from the uncompressed data.
                    lmtentry.UncompressedData        = System.IO.File.ReadAllBytes(filename);
                    lmtentry.DecompressedFileLength  = lmtentry.UncompressedData.Length;
                    lmtentry._DecompressedFileLength = lmtentry.UncompressedData.Length;
                    lmtentry.DSize = lmtentry.UncompressedData.Length;

                    //Then Compress.
                    lmtentry.CompressedData        = Zlibber.Compressor(lmtentry.UncompressedData);
                    lmtentry.CompressedFileLength  = lmtentry.CompressedData.Length;
                    lmtentry._CompressedFileLength = lmtentry.CompressedData.Length;
                    lmtentry.CSize = lmtentry.CompressedData.Length;

                    //Gets the filename of the file to inject without the directory.
                    string trname = filename;
                    while (trname.Contains("\\"))
                    {
                        trname = trname.Substring(trname.IndexOf("\\") + 1);
                    }

                    lmtentry.TrueName  = trname;
                    lmtentry._FileName = lmtentry.TrueName;
                    lmtentry.TrueName  = Path.GetFileNameWithoutExtension(trname);
                    lmtentry.FileExt   = trname.Substring(trname.LastIndexOf("."));
                    lmtentry._FileType = lmtentry.FileExt;

                    lmtentry.LstM3A     = new List <LMTM3AEntry>();
                    lmtentry.OffsetList = new List <int>();

                    bnr.BaseStream.Position = 6;
                    lmtentry.Version        = bnr.ReadInt16();
                    lmtentry.EntryCount     = lmtentry.Version;

                    int count          = 0;
                    int SecondaryCount = 0;
                    //Gets all the offsets. ALL OF THEM.
                    while (count < (lmtentry.Version))
                    {
                        lmtentry.OffsetList.Add(bnr.ReadInt32());
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                        count++;
                    }

                    count = 0;
                    //Goes through the offsets to get the data. Ignores offsets of 0.
                    for (int i = 0; i < lmtentry.OffsetList.Count; i++)
                    {
                        if (lmtentry.OffsetList[i] != 0)
                        {
                            LMTM3AEntry aEntry = new LMTM3AEntry();
                            aEntry = aEntry.FillM3AProprties(aEntry, lmtentry.Length, i, lmtentry.RowCount, lmtentry.SecondOffsetList, bnr, SecondaryCount, lmtentry);
                            lmtentry.LstM3A.Add(aEntry);
                        }
                        else
                        {
                            LMTM3AEntry aEntry = new LMTM3AEntry();
                            aEntry = aEntry.FillBlankM3A(aEntry, lmtentry.Length, i, lmtentry.RowCount, lmtentry.SecondOffsetList, bnr, SecondaryCount, lmtentry);
                            lmtentry.LstM3A.Add(aEntry);
                        }
                    }

                    //Gets the path of the selected node to inject here.
                    string nodepath = tree.SelectedNode.FullPath;
                    nodepath = nodepath.Substring(nodepath.IndexOf("\\") + 1);

                    string[] sepstr = { "\\" };
                    lmtentry.EntryDirs = nodepath.Split(sepstr, StringSplitOptions.RemoveEmptyEntries);
                    lmtentry.EntryName = lmtentry.FileName;

                    //Looks through the archive_filetypes.cfg file to find the typehash associated with the extension.
                    try
                    {
                        using (var sr2 = new StreamReader("archive_filetypes.cfg"))
                        {
                            while (!sr2.EndOfStream)
                            {
                                var keyword = Console.ReadLine() ?? lmtentry.FileExt;
                                var line    = sr2.ReadLine();
                                if (String.IsNullOrEmpty(line))
                                {
                                    continue;
                                }
                                if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                {
                                    lmtentry.TypeHash = line;
                                    lmtentry.TypeHash = lmtentry.TypeHash.Split(' ')[0];

                                    break;
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        MessageBox.Show("I cannot find and/or access archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                        using (StreamWriter sw = File.AppendText("Log.txt"))
                        {
                            sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Caught an exception using the BinaryReader. Here's the details:\n" + ex);
                }
            }



            return(lmtentry);
        }
コード例 #7
0
        public static LMTEntry FillLMTEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, Type filetype = null)
        {
            LMTEntry    lmtentry = new LMTEntry();
            List <byte> BTemp    = new List <byte>();

            FillEntry(filename, subnames, tree, br, c, ID, lmtentry, filetype);

            lmtentry._FileName = lmtentry.TrueName + lmtentry.FileExt;
            lmtentry._FileType = lmtentry.FileExt;

            //Decompression Time.
            lmtentry.UncompressedData        = ZlibStream.UncompressBuffer(lmtentry.CompressedData);
            lmtentry._DecompressedFileLength = lmtentry.UncompressedData.Length;
            lmtentry._CompressedFileLength   = lmtentry.CompressedData.Length;

            int count = 0;

            byte[] STemp = new byte[2];
            byte[] OTemp = new byte[4];

            lmtentry.LstM3A     = new List <LMTM3AEntry>();
            lmtentry.OffsetList = new List <int>();
            int SecondaryCount = 0;

            using (MemoryStream LmtStream = new MemoryStream(lmtentry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(LmtStream))
                {
                    bnr.BaseStream.Position = 6;
                    lmtentry.Version        = bnr.ReadInt16();
                    lmtentry.EntryCount     = lmtentry.Version;

                    //Gets all the offsets. ALL OF THEM.
                    while (count < (lmtentry.Version))
                    {
                        lmtentry.OffsetList.Add(bnr.ReadInt32());
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                        count++;
                    }

                    count = 0;
                    //Goes through the offsets to get the data. Ignores offsets of 0.
                    for (int i = 0; i < lmtentry.OffsetList.Count; i++)
                    {
                        if (lmtentry.OffsetList[i] != 0)
                        {
                            LMTM3AEntry aEntry = new LMTM3AEntry();
                            aEntry = aEntry.FillM3AProprties(aEntry, lmtentry.Length, i, lmtentry.RowCount, lmtentry.SecondOffsetList, bnr, SecondaryCount, lmtentry);
                            lmtentry.LstM3A.Add(aEntry);
                        }
                        else
                        {
                            LMTM3AEntry aEntry = new LMTM3AEntry();
                            aEntry = aEntry.FillBlankM3A(aEntry, lmtentry.Length, i, lmtentry.RowCount, lmtentry.SecondOffsetList, bnr, SecondaryCount, lmtentry);
                            lmtentry.LstM3A.Add(aEntry);
                        }
                    }
                }

                return(lmtentry);
            }
        }
コード例 #8
0
        public static LMTM3AEntry ReplaceLMTM3AEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            LMTM3AEntry m3aentry = new LMTM3AEntry();
            LMTM3AEntry oldentry = new LMTM3AEntry();

            tree.BeginUpdate();

            var tag = node.Tag;

            if (tag is LMTM3AEntry)
            {
                oldentry = tag as LMTM3AEntry;
            }

            //Builds the ma3entry.
            m3aentry._FileType   = ".m3a";
            m3aentry.FileExt     = m3aentry._FileType;
            m3aentry.FullData    = System.IO.File.ReadAllBytes(filename);
            m3aentry.AnimationID = oldentry.AnimationID;
            m3aentry.FileName    = oldentry.FileName;
            m3aentry.ShortName   = oldentry.ShortName;
            m3aentry._IsBlank    = false;

            using (MemoryStream MAThreeStream = new MemoryStream(m3aentry.FullData))
            {
                using (BinaryReader bnr = new BinaryReader(MAThreeStream))
                {
                    if (bnr.BaseStream.Length < 5)
                    {
                        MessageBox.Show("The entry you are trying to import is a blank one,\nso the replace command has been aborted.", "We have a problem here.");
                        return(null);
                    }


                    int projdatlength = m3aentry.FullData.Length - 96;
                    m3aentry.RawData = new byte[(projdatlength)];
                    Array.Copy(m3aentry.FullData, 0, m3aentry.RawData, 0, projdatlength);
                    m3aentry.MotionData = new byte[96];
                    projdatlength       = m3aentry.FullData.Length - 96;
                    Array.Copy(m3aentry.FullData, projdatlength, m3aentry.MotionData, 0, 96);
                    bnr.BaseStream.Position = (bnr.BaseStream.Length - 96);

                    m3aentry.TrackPointer   = bnr.ReadInt32();
                    bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                    m3aentry.TrackCount     = bnr.ReadInt32();
                    m3aentry.FrameCount     = bnr.ReadInt32();
                    m3aentry._FrameTotal    = m3aentry.FrameCount;
                    m3aentry.IsBlank        = false;
                    m3aentry.LoopFrame      = bnr.ReadInt32();

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

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

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

                    m3aentry.AnimationFlags = bnr.ReadInt64();

                    m3aentry.EventClassesPointer = bnr.ReadInt32();

                    //m3aentry.EventClassesPointer = bnr.ReadInt32();
                    //bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

                    m3aentry.AnimDataSize = (m3aentry.EventClassesPointer - m3aentry.TrackPointer) + 352;


                    m3aentry.AnimDataSize       = m3aentry.FullData.Length - 448;
                    m3aentry.FloatTracksPointer = bnr.ReadInt32();
                    bnr.BaseStream.Position     = bnr.BaseStream.Position + 4;

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

                    m3aentry.PrevOffsetThree = Convert.ToInt32(bnr.BaseStream.Position);
                    bnr.BaseStream.Position  = m3aentry.TrackPointer;
                    m3aentry.RawData         = new byte[m3aentry.AnimDataSize];
                    Array.Copy(m3aentry.FullData, m3aentry.RawData, m3aentry.AnimDataSize);
                    m3aentry.MotionData     = new byte[96];
                    bnr.BaseStream.Position = (m3aentry.FullData.Length - 96);
                    m3aentry.MotionData     = bnr.ReadBytes(96);
                    bnr.BaseStream.Position = m3aentry.PrevOffsetThree;

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

                    for (int j = 0; j < m3aentry.TrackCount; j++)
                    {
                        Track track = new Track();
                        track.TrackNumber = j;
                        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;
                        m3aentry.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);
                        }

                        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();
                        }
                        bnr.BaseStream.Position = m3aentry.PrevOffset;
                        m3aentry.Tracks.Add(track);
                    }


                    bnr.BaseStream.Position = m3aentry.FullData.Length - 448;
                    //Animation Events.
                    m3aentry.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;

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

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

                    //Subtracts pointers in there by the data offset to get their base value.
                    int OffTemp = 0;
                    using (MemoryStream msm3a = new MemoryStream(m3aentry.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 < m3aentry.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 - m3aentry.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 - m3aentry.TrackPointer;
                                        bwm3a.Write(OffTemp);
                                    }
                                }

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

                                OffTemp = m3aentry.RawData.Length - 32;

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

                                OffTemp = m3aentry.RawData.Length - 24;

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

                                OffTemp = m3aentry.RawData.Length - 16;

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

                                OffTemp = m3aentry.RawData.Length - 8;

                                bwm3a.Write(OffTemp);
                            }
                        }
                    }

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

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    m3aentry.RawData = System.IO.File.ReadAllBytes(filename);


                    /*
                     * var tag = node.Tag;
                     * if (tag is LMTM3AEntry)
                     * {
                     *  oldentry = tag as LMTM3AEntry;
                     * }
                     */

                    tag = m3aentry;

                    if (node.Tag is LMTM3AEntry)
                    {
                        node.Tag = m3aentry;
                    }

                    var aew = node as ArcEntryWrapper;

                    string type = node.GetType().ToString();
                    if (type == "ThreeWorkTool.Resources.Wrappers.ArcEntryWrapper")
                    {
                        aew.entryfile = m3aentry;
                    }

                    node           = aew;
                    node.entryfile = m3aentry;

                    /*
                     * //ArcEntryWrapper aew = new ArcEntryWrapper();
                     * if (node is ArcEntryWrapper)
                     * {
                     *  node.entryfile as ArcEntryWrapper = node.Tag;
                     * }
                     */
                    tree.EndUpdate();
                    node.ImageIndex         = 18;
                    node.SelectedImageIndex = 18;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read Error! Here's the exception info:\n" + ex);
                }
            }



            return(node.entryfile as LMTM3AEntry);
        }
コード例 #9
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);
        }
コード例 #10
0
 public static void TestFromKeyframesToM3A(LMTM3AEntry M3a)
 {
     LMTM3AEntry NewM3a = new LMTM3AEntry();
 }