Beispiel #1
0
        public static GemEntry InsertGEM(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            GemEntry gem = new GemEntry();

            InsertEntry(tree, node, filename, gem);

            //Decompression Time.
            gem.UncompressedData = ZlibStream.UncompressBuffer(gem.CompressedData);
            ASCIIEncoding ascii = new ASCIIEncoding();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    BuildGemEntry(bnr, gem, ascii);
                }
            }
            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(gem);
        }
        public static EffectListEntry InsertEFL(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            EffectListEntry effectList = new EffectListEntry();

            InsertEntry(tree, node, filename, effectList);

            //Decompression Time.
            effectList.UncompressedData = ZlibStream.UncompressBuffer(effectList.CompressedData);

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    BuildEffectListEntry(bnr, effectList);
                }
            }
            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(effectList);
        }
        public static MaterialEntry ReplaceMat(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            MaterialEntry matentry = new MaterialEntry();
            MaterialEntry oldentry = new MaterialEntry();

            tree.BeginUpdate();

            ReplaceKnownEntry(tree, node, filename, matentry, oldentry);

            return(node.entryfile as MaterialEntry);
        }
        public static MaterialEntry InsertEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            MaterialEntry matentry = new MaterialEntry();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    InsertKnownEntry(tree, node, filename, matentry, bnr);
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Caught an exception using the BinaryReader. Here's the details:\n" + ex);
                }
            }

            //Decompression Time.
            matentry.UncompressedData = ZlibStream.UncompressBuffer(matentry.CompressedData);

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    //Material specific work here.
                    using (MemoryStream MatStream = new MemoryStream(matentry.UncompressedData))
                    {
                        using (BinaryReader MBR = new BinaryReader(MatStream))
                        {
                            BuildMatEntry(MBR, matentry);
                        }
                    }
                }
            }
            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(matentry);
        }
        public static ChainEntry InsertChainEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ChainEntry chnentry = new ChainEntry();

            InsertEntry(tree, node, filename, chnentry);

            chnentry.DecompressedFileLength  = chnentry.UncompressedData.Length;
            chnentry._DecompressedFileLength = chnentry.UncompressedData.Length;
            chnentry.CompressedFileLength    = chnentry.CompressedData.Length;
            chnentry._CompressedFileLength   = chnentry.CompressedData.Length;
            chnentry._FileName = chnentry.TrueName;
            chnentry._FileType = chnentry.FileExt;
            chnentry.EntryName = chnentry.FileName;



            return(chnentry);
        }
        public static ChainEntry ReplaceChainEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ChainEntry chnentry = new ChainEntry();
            ChainEntry oldentry = new ChainEntry();

            tree.BeginUpdate();

            ReplaceEntry(tree, node, filename, chnentry, oldentry);

            chnentry.DecompressedFileLength  = chnentry.UncompressedData.Length;
            chnentry._DecompressedFileLength = chnentry.UncompressedData.Length;
            chnentry.CompressedFileLength    = chnentry.CompressedData.Length;
            chnentry._CompressedFileLength   = chnentry.CompressedData.Length;
            chnentry._FileName = chnentry.TrueName;
            chnentry._FileType = chnentry.FileExt;

            return(node.entryfile as ChainEntry);
        }
        public static EffectListEntry ReplaceEFL(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            EffectListEntry eflentry = new EffectListEntry();
            EffectListEntry oldentry = new EffectListEntry();

            tree.BeginUpdate();

            ReplaceEntry(tree, node, filename, eflentry, oldentry);

            //Type Specific Work Here.
            using (MemoryStream LmtStream = new MemoryStream(eflentry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(LmtStream))
                {
                    BuildEffectListEntry(bnr, eflentry);
                }
            }

            return(node.entryfile as EffectListEntry);
        }
Beispiel #8
0
        public static MissionEntry ReplaceMIS(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            MissionEntry MISNentry   = new MissionEntry();
            MissionEntry MISoldentry = new MissionEntry();

            tree.BeginUpdate();

            ReplaceEntry(tree, node, filename, MISNentry, MISoldentry);

            //Type Specific Work Here.
            using (MemoryStream LmtStream = new MemoryStream(MISNentry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(LmtStream))
                {
                    BuildMissionEntry(bnr, MISNentry);
                }
            }

            return(node.entryfile as MissionEntry);
        }
Beispiel #9
0
        public static GemEntry ReplaceGEM(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            GemEntry gementry = new GemEntry();
            GemEntry oldentry = new GemEntry();

            tree.BeginUpdate();

            ReplaceEntry(tree, node, filename, gementry, oldentry);

            ASCIIEncoding ascii = new ASCIIEncoding();

            //Type Specific Work Here.
            using (MemoryStream LmtStream = new MemoryStream(gementry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(LmtStream))
                {
                    BuildGemEntry(bnr, gementry, ascii);
                }
            }

            return(node.entryfile as GemEntry);
        }
Beispiel #10
0
        public static ModelEntry ReplaceModelEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ModelEntry mdlentry = new ModelEntry();
            ModelEntry oldentry = new ModelEntry();

            tree.BeginUpdate();

            ReplaceEntry(tree, node, filename, mdlentry, oldentry);

            mdlentry.DecompressedFileLength = mdlentry.UncompressedData.Length;
            mdlentry.CompressedFileLength   = mdlentry.CompressedData.Length;

            //Type Specific Work Here.
            using (MemoryStream LmtStream = new MemoryStream(mdlentry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(LmtStream))
                {
                    BuildModelEntry(bnr, mdlentry);
                }
            }

            return(node.entryfile as ModelEntry);
        }
Beispiel #11
0
        public static MSDEntry InsertMSD(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            MSDEntry msdentry = new MSDEntry();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    InsertKnownEntry(tree, node, filename, msdentry, bnr);

                    //Gets the Magic.
                    msdentry.Magic = BitConverter.ToString(msdentry.UncompressedData, 0, 4).Replace("-", string.Empty);

                    bnr.BaseStream.Position = 4;
                    //Apparently the entry count is 32-bit and not 16-bit. Considering that some of these MSDs end up with over 10,000 entries...  yeah.
                    msdentry.EntryCount  = bnr.ReadInt32();
                    msdentry._EntryTotal = msdentry.EntryCount;
                    msdentry._FileLength = msdentry.UncompressedData.Length;
                    msdentry._FileName   = msdentry.TrueName;
                    msdentry._FileType   = msdentry.FileExt;
                    msdentry.EntryName   = msdentry.FileName;
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Caught the exception:" + ex);
                }
            }

            msdentry.TextBackup = new List <string>();


            return(msdentry);
        }
Beispiel #12
0
        //Makes a new node from scratch for the imported file.
        public static ArcEntryWrapper EntryCreator(ArcEntryWrapper node, TreeView Tree, string filename, Type filetype = null)
        {
            //           node.entryData = ArcEntry.InsertEntry(Tree,node,filename);

            return(node);
        }
Beispiel #13
0
        public static MSDEntry ReplaceMSD(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            MSDEntry MSDNentry   = new MSDEntry();
            MSDEntry MSDoldentry = new MSDEntry();

            tree.BeginUpdate();

            ReplaceKnownEntry(tree, node, filename, MSDNentry, MSDoldentry);

            //Gets the Magic.
            MSDNentry.Magic = BitConverter.ToString(MSDNentry.UncompressedData, 0, 4).Replace("-", string.Empty);
            try
            {
                using (MemoryStream mstream = new MemoryStream(MSDNentry.UncompressedData))
                {
                    using (BinaryReader bnr = new BinaryReader(mstream))
                    {
                        bnr.BaseStream.Position = 4;
                        //Apparently the entry count is 32-bit and not 16-bit. Considering that some of these MSDs end up with over 10,000 entries...  yeah.
                        MSDNentry.EntryCount  = bnr.ReadInt32();
                        MSDNentry._EntryTotal = MSDNentry.EntryCount;
                        MSDNentry._FileLength = MSDNentry.UncompressedData.Length;
                    }
                }

                MSDNentry.TextBackup = new List <string>();

                //Hmmm.

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

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

                tag = MSDNentry;

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

                var aew = node as ArcEntryWrapper;

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

                node           = aew;
                node.entryfile = MSDNentry;
                tree.EndUpdate();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read error. Cannot access the file:" + filename + "\n" + ex);
                }
            }

            return(node.entryfile as MSDEntry);
        }
Beispiel #14
0
        public static ChainListEntry InsertChainListEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ChainListEntry clstentry = new ChainListEntry();

            InsertEntry(tree, node, filename, clstentry);

            clstentry.DecompressedFileLength = clstentry.UncompressedData.Length;
            clstentry._DecompressedFileLength = clstentry.UncompressedData.Length;
            clstentry.CompressedFileLength = clstentry.CompressedData.Length;
            clstentry._CompressedFileLength = clstentry.CompressedData.Length;
            clstentry._FileName = clstentry.TrueName;
            clstentry.EntryName = clstentry.FileName;

            clstentry.TypeHash = "326F732E";

            //Type specific work here.
            using (MemoryStream CslStream = new MemoryStream(clstentry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(CslStream))
                {

                    bnr.BaseStream.Position = 4;
                    clstentry.Unknown04 = bnr.ReadInt32();
                    clstentry.TotalEntrySize = bnr.ReadInt32();
                    clstentry.CHNEntryCount = bnr.ReadInt32();
                    clstentry.CCLEntryCount = bnr.ReadInt32();

                    clstentry.ChainEntries = new List<CHNEntry>();
                    clstentry.ChainCollEntries = new List<CCLEntry>();

                    for (int g = 0; g < clstentry.CHNEntryCount; g++)
                    {
                        CHNEntry cHN = new CHNEntry();
                        cHN.FullPath = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
                        cHN.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), cHN.TypeHash);

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? cHN.TypeHash;
                                    var line = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line)) continue;
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        cHN.FileExt = line;
                                        cHN.FileExt = cHN.FileExt.Split(' ')[1];
                                        cHN.TotalName = cHN.FullPath + cHN.FileExt;
                                        break;
                                    }
                                }
                            }

                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find 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 and thus cannot continue parsing.");
                            }
                            return null;
                        }

                        clstentry.ChainEntries.Add(cHN);
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 16;
                    }

                    for (int h = 0; h < clstentry.CCLEntryCount; h++)
                    {
                        CCLEntry cCL = new CCLEntry();
                        cCL.FullPath = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
                        cCL.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), cCL.TypeHash);

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? cCL.TypeHash;
                                    var line = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line)) continue;
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        cCL.FileExt = line;
                                        cCL.FileExt = cCL.FileExt.Split(' ')[1];
                                        cCL.TotalName = cCL.FullPath + cCL.FileExt;
                                        break;
                                    }
                                }
                            }

                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find 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 and thus cannot continue parsing.");
                            }
                            return null;
                        }

                        clstentry.ChainCollEntries.Add(cCL);
                    }

                }
            }

            clstentry.TextBackup = new List<string>();

            return clstentry;
        }
Beispiel #15
0
        public static ChainListEntry ReplaceCST(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ChainListEntry cstnentry = new ChainListEntry();
            ChainListEntry cstoldentry = new ChainListEntry();

            tree.BeginUpdate();

            //Gotta Fix this up then test insert and replacing.
            try
            {
                using (BinaryReader br = new BinaryReader(File.OpenRead(filename)))
                {

                    ReplaceKnownEntry(tree, node, filename, cstnentry, cstoldentry);

                    cstnentry._FileName = cstnentry.TrueName;
                    cstnentry._DecompressedFileLength = cstnentry.UncompressedData.Length;
                    cstnentry._CompressedFileLength = cstnentry.CompressedData.Length;

                    cstnentry.TypeHash = "326F732E";

                    //Type specific work here.
                    using (MemoryStream CslStream = new MemoryStream(cstnentry.UncompressedData))
                    {
                        using (BinaryReader bnr = new BinaryReader(CslStream))
                        {

                            bnr.BaseStream.Position = 4;
                            cstnentry.Unknown04 = bnr.ReadInt32();
                            cstnentry.TotalEntrySize = bnr.ReadInt32();
                            cstnentry.CHNEntryCount = bnr.ReadInt32();
                            cstnentry.CCLEntryCount = bnr.ReadInt32();

                            cstnentry.ChainEntries = new List<CHNEntry>();
                            cstnentry.ChainCollEntries = new List<CCLEntry>();

                            for (int g = 0; g < cstnentry.CHNEntryCount; g++)
                            {
                                CHNEntry cHN = new CHNEntry();
                                cHN.FullPath = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
                                cHN.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), cHN.TypeHash);

                                try
                                {
                                    using (var sr = new StreamReader("archive_filetypes.cfg"))
                                    {
                                        while (!sr.EndOfStream)
                                        {
                                            var keyword = Console.ReadLine() ?? cHN.TypeHash;
                                            var line = sr.ReadLine();
                                            if (String.IsNullOrEmpty(line)) continue;
                                            if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                            {
                                                cHN.FileExt = line;
                                                cHN.FileExt = cHN.FileExt.Split(' ')[1];
                                                cHN.TotalName = cHN.FullPath + cHN.FileExt;
                                                break;
                                            }
                                        }
                                    }

                                }
                                catch (FileNotFoundException)
                                {
                                    MessageBox.Show("I cannot find 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 and thus cannot continue parsing.");
                                    }
                                    return null;
                                }

                                cstnentry.ChainEntries.Add(cHN);
                                bnr.BaseStream.Position = bnr.BaseStream.Position + 16;
                            }

                            for (int h = 0; h < cstnentry.CCLEntryCount; h++)
                            {
                                CCLEntry cCL = new CCLEntry();
                                cCL.FullPath = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
                                cCL.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), cCL.TypeHash);

                                try
                                {
                                    using (var sr = new StreamReader("archive_filetypes.cfg"))
                                    {
                                        while (!sr.EndOfStream)
                                        {
                                            var keyword = Console.ReadLine() ?? cCL.TypeHash;
                                            var line = sr.ReadLine();
                                            if (String.IsNullOrEmpty(line)) continue;
                                            if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                            {
                                                cCL.FileExt = line;
                                                cCL.FileExt = cCL.FileExt.Split(' ')[1];
                                                cCL.TotalName = cCL.FullPath + cCL.FileExt;
                                                break;
                                            }
                                        }
                                    }

                                }
                                catch (FileNotFoundException)
                                {
                                    MessageBox.Show("I cannot find 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 and thus cannot continue parsing.");
                                    }
                                    return null;
                                }

                                cstnentry.ChainCollEntries.Add(cCL);
                            }

                        }
                    }

                    cstnentry.TextBackup = new List<string>();


                    //Hmmm.

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

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

                    tag = cstnentry;

                    if (node.Tag is ChainListEntry)
                    {
                        node.Tag = cstnentry;
                        node.Name = Path.GetFileNameWithoutExtension(cstnentry.EntryName);
                        node.Text = Path.GetFileNameWithoutExtension(cstnentry.EntryName);

                    }

                    var aew = node as ArcEntryWrapper;

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

                    node = aew;
                    node.entryfile = cstnentry;
                    tree.EndUpdate();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read error. Cannot access the file:" + filename + "\n" + ex);
                }
            }



            return node.entryfile as ChainListEntry;
        }
Beispiel #16
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);
        }
Beispiel #17
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);
        }
Beispiel #18
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);
        }
        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);
        }
Beispiel #20
0
        public static ResourcePathListEntry InsertRPL(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ResourcePathListEntry rplentry = new ResourcePathListEntry();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    InsertKnownEntry(tree, node, filename, rplentry, bnr);

                    //Specific file type work goes here!
                    ASCIIEncoding ascii = new ASCIIEncoding();

                    //Gets the Magic.
                    byte[] MTemp = new byte[4];
                    string STemp = " ";
                    Array.Copy(rplentry.UncompressedData, 0, MTemp, 0, 4);
                    rplentry.Magic = ByteUtilitarian.BytesToString(MTemp, rplentry.Magic);

                    Array.Copy(rplentry.UncompressedData, 12, MTemp, 0, 4);
                    Array.Reverse(MTemp);
                    STemp = ByteUtilitarian.BytesToString(MTemp, STemp);

                    int ECTemp = Convert.ToInt32(STemp, 16);
                    rplentry._EntryTotal = ECTemp;
                    rplentry.EntryCount  = ECTemp;

                    //Starts occupying the entry list via structs.
                    rplentry.EntryList = new List <PathEntries>();
                    byte[] PLName  = new byte[] { };
                    byte[] PTHName = new byte[] { };

                    int    p = 16;
                    string Teme;
                    string Hame;

                    for (int g = 0; g < rplentry.EntryCount; g++)
                    {
                        PathEntries pe = new PathEntries();
                        PLName = rplentry.UncompressedData.Skip(p).Take(64).Where(x => x != 0x00).ToArray();
                        Teme   = ascii.GetString(PLName);

                        pe.FullPath = Teme;
                        p           = p + 64;
                        PTHName     = rplentry.UncompressedData.Skip(p).Take(4).Where(x => x != 0x00).ToArray();
                        Array.Reverse(PTHName);

                        Teme        = ByteUtilitarian.BytesToString(PTHName, Teme);
                        pe.TypeHash = Teme;

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? Teme;
                                    var line    = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line))
                                    {
                                        continue;
                                    }
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        Hame         = line;
                                        Hame         = Hame.Split(' ')[1];
                                        pe.TotalName = pe.FullPath + Hame;
                                        pe.FileExt   = Hame;
                                        break;
                                    }
                                }
                            }
                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find 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 and thus cannot continue parsing.");
                            }
                            return(null);
                        }

                        rplentry.EntryList.Add(pe);
                        p = p + 4;
                    }

                    rplentry.TextBackup = new List <string>();
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Caught the exception:" + ex);
                }
            }

            return(rplentry);
        }
Beispiel #21
0
        public static ResourcePathListEntry ReplaceRPL(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ResourcePathListEntry rpathentry = new ResourcePathListEntry();
            ResourcePathListEntry rpoldentry = new ResourcePathListEntry();

            tree.BeginUpdate();

            //Gotta Fix this up then test insert and replacing.
            try
            {
                using (BinaryReader br = new BinaryReader(File.OpenRead(filename)))
                {
                    ReplaceKnownEntry(tree, node, filename, rpathentry, rpoldentry);

                    ASCIIEncoding ascii = new ASCIIEncoding();

                    //Gets the Magic.
                    byte[] MTemp = new byte[4];
                    string STemp = " ";
                    Array.Copy(rpathentry.UncompressedData, 0, MTemp, 0, 4);
                    rpathentry.Magic = ByteUtilitarian.BytesToString(MTemp, rpathentry.Magic);

                    Array.Copy(rpathentry.UncompressedData, 12, MTemp, 0, 4);
                    Array.Reverse(MTemp);
                    STemp = ByteUtilitarian.BytesToString(MTemp, STemp);

                    int ECTemp = Convert.ToInt32(STemp, 16);
                    rpathentry._EntryTotal = ECTemp;
                    rpathentry.EntryCount  = ECTemp;

                    //Starts occupying the entry list via structs.
                    rpathentry.EntryList = new List <PathEntries>();
                    byte[] PLName  = new byte[] { };
                    byte[] PTHName = new byte[] { };

                    int    p = 16;
                    string Teme;
                    string Hame;

                    for (int g = 0; g < rpathentry.EntryCount; g++)
                    {
                        PathEntries pe = new PathEntries();
                        PLName = rpathentry.UncompressedData.Skip(p).Take(64).Where(x => x != 0x00).ToArray();
                        Teme   = ascii.GetString(PLName);

                        pe.FullPath = Teme;
                        p           = p + 64;
                        PTHName     = rpathentry.UncompressedData.Skip(p).Take(4).Where(x => x != 0x00).ToArray();
                        Array.Reverse(PTHName);

                        Teme        = ByteUtilitarian.BytesToString(PTHName, Teme);
                        pe.TypeHash = Teme;

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? Teme;
                                    var line    = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line))
                                    {
                                        continue;
                                    }
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        Hame         = line;
                                        Hame         = Hame.Split(' ')[1];
                                        pe.TotalName = pe.FullPath + Hame;
                                        pe.FileExt   = Hame;
                                        break;
                                    }
                                }
                            }
                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                            br.Close();
                        }

                        rpathentry.EntryList.Add(pe);
                        p = p + 4;
                    }

                    rpathentry.TextBackup  = new List <string>();
                    rpathentry._FileLength = rpathentry.UncompressedData.Length;

                    //Hmmm.

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

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

                    tag = rpathentry;

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

                    var aew = node as ArcEntryWrapper;

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

                    node           = aew;
                    node.entryfile = rpathentry;
                    tree.EndUpdate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read error. Cannot access the file:" + filename + "\n" + ex);
                }
            }



            return(node.entryfile as ResourcePathListEntry);
        }