Exemplo n.º 1
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);
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
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);
        }