Пример #1
0
        public static ChainListEntry RenewCSTList(TextBox texbox, ChainListEntry chlste)
        {

            //Reconstructs the Lists.
            string txbtxt = texbox.Text;
            string[] SPLT = new string[] { };
            string ExtTemp = "";

            SPLT = txbtxt.Split('\n');
            int index = 0;

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

            for (int i = 0; i < SPLT.Length; i++)
            {
                bool Isvalidline = SPLT[i].Contains(".");

                if (Isvalidline == true)
                {
                    index = SPLT[i].LastIndexOf(".");
                    ExtTemp = SPLT[i].Substring(index,4);

                    if (ExtTemp == ".chn" || ExtTemp == "chn")
                    {
                        CHNEntry cHN = new CHNEntry();
                        cHN.FullPath = SPLT[i].Substring(0, index);
                        cHN.TypeHash = "3E363245";
                        cHN.TotalName = cHN.FullPath + ExtTemp;
                        cHN.FileExt = SPLT[i].Substring((index),4);
                        chlste.ChainEntries.Add(cHN);

                    }
                    else if (ExtTemp == ".ccl" || ExtTemp == "ccl")
                    {
                        CCLEntry cCL = new CCLEntry();
                        cCL.FullPath = SPLT[i].Substring(0, index);
                        cCL.TypeHash = "0026E7FF";
                        cCL.TotalName = cCL.FullPath + ExtTemp;
                        cCL.FileExt = SPLT[i].Substring((index),4);
                        chlste.ChainCollEntries.Add(cCL);
                    }
                }
            }

            chlste.CHNEntryCount = chlste.ChainEntries.Count;
            chlste.CCLEntryCount = chlste.ChainCollEntries.Count;

            //Rebuilds the raw file itself.
            List<byte> NEWCST = new List<byte>();
            byte[] HeaderCST = { 0x43, 0x53, 0x54, 0x00, 0x00, 0x01, 0xFE, 0xFF, 0x00, 0x00, 0x00, 0x00 };
            byte[] CHNHash = { 0x45, 0x32, 0x36, 0x3E };
            byte[] CCLHash = { 0xFF, 0xE7, 0x26, 0x00 };
            byte[] FillerLine = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
            byte[] EndingFiller = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};


            NEWCST.AddRange(HeaderCST);

            //Converts the CHN and CCL counts and puts them in the array.
            byte[] BufferA = BitConverter.GetBytes(chlste.ChainEntries.Count);
            NEWCST.AddRange(BufferA);

            byte[] BufferB = BitConverter.GetBytes(chlste.ChainCollEntries.Count);
            NEWCST.AddRange(BufferA);

            //Inserts the CHN data.
            int NewEntryCount = chlste.CHNEntryCount;
            int ChainCount = 0; 
            int ChainColCount = 0;
            if (chlste.CHNEntryCount > 0)
            {
                if (string.IsNullOrWhiteSpace(chlste.ChainEntries[(chlste.CHNEntryCount - 1)].TotalName))
                {
                    NewEntryCount--;
                }
                //int ProjectedSize = NewEntryCount * 84;
                //int EstimatedSizeCHN = ((int)Math.Round(ProjectedSize / 16.0, MidpointRounding.AwayFromZero) * 16);

                for (int k = 0; k < NewEntryCount; k++)
                {

                    int NumberChars = chlste.ChainEntries[k].FullPath.Length;
                    byte[] namebuffer = Encoding.ASCII.GetBytes(chlste.ChainEntries[k].FullPath);
                    int nblength = namebuffer.Length;
                    byte[] writenamedata = new byte[64];
                    Array.Clear(writenamedata, 0, writenamedata.Length);

                    for (int l = 0; l < namebuffer.Length; ++l)
                    {
                        writenamedata[l] = namebuffer[l];
                    }

                    NEWCST.AddRange(writenamedata);
                    NEWCST.AddRange(CHNHash);
                    NEWCST.AddRange(FillerLine);
                    ChainCount++;
                }
            }


            //Inserts the CCL data.
            NewEntryCount = chlste.CCLEntryCount;

            if (chlste.CCLEntryCount > 0)
            {
                if (string.IsNullOrWhiteSpace(chlste.ChainCollEntries[(chlste.CCLEntryCount - 1)].TotalName))
                {
                    NewEntryCount--;
                }

                for (int m = 0; m < NewEntryCount; m++)
                {

                    int NumberChars = chlste.ChainCollEntries[m].FullPath.Length;
                    byte[] namebuffer = Encoding.ASCII.GetBytes(chlste.ChainCollEntries[m].FullPath);
                    int nblength = namebuffer.Length;
                    byte[] writenamedata = new byte[64];
                    Array.Clear(writenamedata, 0, writenamedata.Length);

                    for (int l = 0; l < namebuffer.Length; ++l)
                    {
                        writenamedata[l] = namebuffer[l];
                    }

                    NEWCST.AddRange(writenamedata);
                    NEWCST.AddRange(CCLHash);
                    ChainColCount++;
                }
            }
            //Fills in 48 blank bytes at the end.
            NEWCST.AddRange(EndingFiller);

            //Updates the parameters of the ChainListEntry.
            chlste.UncompressedData = NEWCST.ToArray();

            //Updates the counts in the byte array.
            int entrysize = (NEWCST.Count - 20);
            byte[] ETemp = new byte[4];
            ETemp = BitConverter.GetBytes(entrysize);
            Buffer.BlockCopy(ETemp, 0, chlste.UncompressedData, 8, 4);

            ETemp = BitConverter.GetBytes(ChainCount);
            Buffer.BlockCopy(ETemp, 0, chlste.UncompressedData, 12, 4);

            ETemp = BitConverter.GetBytes(ChainColCount);
            Buffer.BlockCopy(ETemp, 0, chlste.UncompressedData, 16, 4);


            chlste.DSize = chlste.UncompressedData.Length;

            chlste.CompressedData = Zlibber.Compressor(chlste.UncompressedData);
            chlste.CSize = chlste.CompressedData.Length;

            chlste.CCLEntryCount = ChainColCount;
            chlste.CHNEntryCount = ChainCount;

            return chlste;

        }
Пример #2
0
        public static MSDEntry UpdateMSDFromTexEditorForm(RichTextBox texbox, MSDEntry msde)
        {
            //This gets the line count of the text box and eliminates the last line if empty.
            int lineCount = texbox.Lines.Count();

            lineCount -= String.IsNullOrWhiteSpace(texbox.Lines.Last()) ? 1 : 0;

            //Builds a new MSD File to replace the uncompressed and compressed data variables.
            List <byte> newMSDData = new List <byte>();

            byte[] MSDTemp = new byte[4] {
                0x4D, 0x53, 0x44, 0x00
            };
            newMSDData.AddRange(MSDTemp);
            MSDTemp = BitConverter.GetBytes(lineCount);
            newMSDData.AddRange(MSDTemp);

            string STemp   = "";
            string HexTemp = "";
            byte   ByTemp;

            byte[] WTemp = new byte[4];
            byte[] HTemp = new byte[2];
            int    LTemp;

            Encoding ShouldBeShiftJIS = Encoding.GetEncoding(932);

            for (int i = 0; i < lineCount; i++)
            {
                //Gets the line.
                STemp  = texbox.Lines[i];
                LTemp  = texbox.Lines[i].Length;
                ByTemp = Convert.ToByte(LTemp);
                newMSDData.Add(ByTemp);
                newMSDData.Add(0x00);

                //Iterates through each character in the line and does its thing.

                for (int j = 0; j < STemp.Length; j++)
                {
                    //This if statement is to check for line breaks in the middle of entries and if so, puts in the appropriate text and skips ahead to the next character.
                    if (STemp[j] == 91 && STemp[j + 1] == 108)
                    {
                        newMSDData.Add(0xFE);
                        newMSDData.Add(0xFF);
                        j = j + 12;
                    }
                    else
                    {
                        HexTemp = STemp[j].ToString();
                        try
                        {
                            using (var sr = new StreamReader("MSDTable.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? HexTemp;
                                    var line    = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line))
                                    {
                                        continue;
                                    }
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        HexTemp = line;
                                        HexTemp = HexTemp.Split(' ')[0];
                                        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 so I cannot continue parsing the file.");
                            }
                        }
                        if (HexTemp == "")
                        {
                            HexTemp = "0000";
                        }
                        HTemp[0] = (byte)Int16.Parse(HexTemp.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
                        HTemp[1] = (byte)Int16.Parse(HexTemp.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
                        newMSDData.AddRange(HTemp);

                        /*
                         * HexTemp = (Convert.ToByte(STemp[j]) - 32).ToString("X2");
                         * ByTemp = Convert.ToByte(HexTemp, 16);
                         * newMSDData.Add(ByTemp);
                         * newMSDData.Add(0x00);
                         */
                    }
                }

                byte[] TerTemp = { 0xFF, 0xFF };
                newMSDData.AddRange(TerTemp);

                msde.UncompressedData = newMSDData.ToArray();
                msde.UncompressedData = Zlibber.Compressor(msde.CompressedData);
            }


            return(msde);
        }
Пример #3
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);
        }
Пример #4
0
        public static LMTEntry ReplaceLMTEntry(TreeView tree, ArcEntryWrapper node, ArcEntryWrapper OldNode, string filename, Type filetype = null)
        {
            LMTEntry lmtentry = new LMTEntry();
            LMTEntry oldentry = new LMTEntry();

            oldentry = OldNode.Tag as LMTEntry;

            tree.BeginUpdate();

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

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

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

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

                    string TypeHash = "";

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


                    int count          = 0;
                    int SecondaryCount = 0;

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

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

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


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


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

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

                    tag = lmtentry;

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

                    var aew = node as ArcEntryWrapper;

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

                    node           = aew;
                    node.entryfile = lmtentry;

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



            return(node.entryfile as LMTEntry);
        }
Пример #5
0
        private void btnReplaceReplace_Click(object sender, EventArgs e)
        {
            if (AllFiles == true)
            {
                //Checks All filenames for searched term. Gets to the parent node, checks all the children nodes, their tags, filenames, etc. for the term.

                //Goes to top node to begin iteration.
                TreeNode tn = Mainfrm.FindRootNode(Mainfrm.TreeSource.SelectedNode);
                Mainfrm.TreeSource.SelectedNode = tn;

                List <TreeNode> Nodes = new List <TreeNode>();
                Mainfrm.AddChildren(Nodes, Mainfrm.TreeSource.SelectedNode);

                Mainfrm.TreeSource.BeginUpdate();

                int RenameCount = 0;

                foreach (TreeNode tno in Nodes)
                {
                    //Gets the node as a ArcEntryWrapper to allow access to all the variables and data.
                    ArcEntryWrapper awrapper = tno as ArcEntryWrapper;

                    if (awrapper != null)
                    {
                        if (awrapper.Tag as MaterialTextureReference == null || awrapper.Tag as LMTM3AEntry == null || awrapper.Tag as ModelBoneEntry == null ||
                            awrapper.Tag as MaterialMaterialEntry == null || awrapper.Tag as ModelGroupEntry == null || awrapper.Tag as Mission == null ||
                            awrapper.Tag as EffectNode == null)
                        {
                            {
                                if (awrapper.Tag as string != null)
                                {
                                    //Replaces the Term in the folder.
                                    string FolderName = awrapper.Tag as string;
                                    FolderName = FolderName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    tno.Text   = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    tno.Name   = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    RenameCount++;
                                }
                                else
                                {
                                    //Goes through the treenode to replace all the names of the node.
                                    ArcEntry              enty     = new ArcEntry();
                                    TextureEntry          tenty    = new TextureEntry();
                                    ResourcePathListEntry lrpenty  = new ResourcePathListEntry();
                                    MSDEntry              msdenty  = new MSDEntry();
                                    MaterialEntry         matent   = new MaterialEntry();
                                    LMTEntry              lmtenty  = new LMTEntry();
                                    ChainListEntry        cstenty  = new ChainListEntry();
                                    ChainEntry            chnenty  = new ChainEntry();
                                    ChainCollisionEntry   cclentry = new ChainCollisionEntry();
                                    ModelEntry            mdlentry = new ModelEntry();
                                    MissionEntry          misenty  = new MissionEntry();
                                    GemEntry              gementy  = new GemEntry();
                                    EffectListEntry       eflenty  = new EffectListEntry();

                                    if (tno.Tag as ArcEntry != null)
                                    {
                                        enty           = tno.Tag as ArcEntry;
                                        enty.EntryName = enty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        enty.TrueName  = enty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        enty.FileName  = enty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag        = enty;
                                        tno.Text       = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name       = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as TextureEntry != null)
                                    {
                                        tenty           = tno.Tag as TextureEntry;
                                        tenty.EntryName = tenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tenty.TrueName  = tenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tenty.FileName  = tenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag         = tenty;
                                        tno.Text        = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name        = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ResourcePathListEntry != null)
                                    {
                                        lrpenty           = tno.Tag as ResourcePathListEntry;
                                        lrpenty.EntryName = lrpenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        lrpenty.TrueName  = lrpenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        lrpenty.FileName  = lrpenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = lrpenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as LMTEntry != null)
                                    {
                                        lmtenty           = tno.Tag as LMTEntry;
                                        lmtenty.EntryName = lmtenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        lmtenty.TrueName  = lmtenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        lmtenty.FileName  = lmtenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = lmtenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as MaterialEntry != null)
                                    {
                                        matent           = tno.Tag as MaterialEntry;
                                        matent.EntryName = matent.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        matent.TrueName  = matent.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        matent.FileName  = matent.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag          = matent;
                                        tno.Text         = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name         = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as MSDEntry != null)
                                    {
                                        msdenty           = tno.Tag as MSDEntry;
                                        msdenty.EntryName = msdenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        msdenty.TrueName  = msdenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        msdenty.FileName  = msdenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = msdenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ChainListEntry != null)
                                    {
                                        cstenty           = tno.Tag as ChainListEntry;
                                        cstenty.EntryName = cstenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        cstenty.TrueName  = cstenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        cstenty.FileName  = cstenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = cstenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ChainEntry != null)
                                    {
                                        chnenty           = tno.Tag as ChainEntry;
                                        chnenty.EntryName = chnenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        chnenty.TrueName  = chnenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        chnenty.FileName  = chnenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = chnenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ChainCollisionEntry != null)
                                    {
                                        cclentry           = tno.Tag as ChainCollisionEntry;
                                        cclentry.EntryName = cclentry.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        cclentry.TrueName  = cclentry.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        cclentry.FileName  = cclentry.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag            = cclentry;
                                        tno.Text           = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name           = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ModelEntry != null)
                                    {
                                        mdlentry           = tno.Tag as ModelEntry;
                                        mdlentry.EntryName = mdlentry.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        mdlentry.TrueName  = mdlentry.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        mdlentry.FileName  = mdlentry.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag            = mdlentry;
                                        tno.Text           = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name           = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as MissionEntry != null)
                                    {
                                        misenty           = tno.Tag as MissionEntry;
                                        misenty.EntryName = misenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        misenty.TrueName  = misenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        misenty.FileName  = misenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = misenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as GemEntry != null)
                                    {
                                        gementy           = tno.Tag as GemEntry;
                                        gementy.EntryName = gementy.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        gementy.TrueName  = gementy.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        gementy.FileName  = gementy.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = gementy;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as EffectListEntry != null)
                                    {
                                        eflenty           = tno.Tag as EffectListEntry;
                                        eflenty.EntryName = eflenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        eflenty.TrueName  = eflenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        eflenty.FileName  = eflenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = eflenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }

                                    RenameCount++;
                                }
                            }
                        }
                    }

                    if (tno.Tag as string != null && tno.Tag as string == "Folder")
                    {
                        //Replaces the Term in the folder.
                        string FolderName = tno.Text as string;
                        FolderName = FolderName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        tno.Text   = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        tno.Name   = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        RenameCount++;
                    }
                }

                Mainfrm.TreeSource.Update();

                Mainfrm.TreeSource.EndUpdate();

                MessageBox.Show("Replaced " + txtReplaceFind.Text + " with " + txtReplaceReplace.Text + " in " + RenameCount + " file and folder names.");

                Mainfrm.OpenFileModified = true;
                RenameCount = 0;
            }
            else
            {
                if (Mainfrm.TreeSource.SelectedNode.Tag is ResourcePathListEntry)
                {
                    //Gets the text, then replaces every instance of the search term with the new term.
                    string text = Mainfrm.txtRPList.Text;
                    text = text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                    Mainfrm.txtRPList.Text = text;
                }
                else if (Mainfrm.TreeSource.SelectedNode.Tag is MaterialEntry)
                {
                    TreeNodeCollection TNoCollection = Mainfrm.TreeSource.SelectedNode.Nodes;

                    foreach (TreeNode node in TNoCollection)
                    {
                        if (node.Tag as string != null)
                        {
                            if (node.Text as string == "Textures")
                            {
                                Mainfrm.TreeSource.SelectedNode = node;
                                break;
                            }
                        }
                    }

                    TNoCollection = Mainfrm.TreeSource.SelectedNode.Nodes;
                    Mainfrm.TreeSource.BeginUpdate();

                    foreach (TreeNode node in TNoCollection)
                    {
                        string Namer = node.Name as string;
                        node.Text = node.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        Namer     = Namer.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        node.Name = Namer;
                    }

                    Mainfrm.TreeSource.SelectedNode = Mainfrm.TreeSource.SelectedNode.Parent;

                    //Now to update the Material file with all these, Whether they're changed or not.
                    TreeNode                 Parentnode    = Mainfrm.TreeSource.SelectedNode;
                    MaterialEntry            ParentMateial = Parentnode.Tag as MaterialEntry;
                    MaterialTextureReference texref        = new MaterialTextureReference();
                    string TermToInject = "";
                    //int count = 0;

                    for (int i = 0; i < TNoCollection.Count; i++)
                    {
                        texref = TNoCollection[i].Tag as MaterialTextureReference;

                        TermToInject = TNoCollection[i].Text;

                        //Now for the actual file update.
                        List <byte> NameToInject = new List <byte>();
                        NameToInject.AddRange(Encoding.ASCII.GetBytes(TermToInject));
                        int OffsetToUse;
                        OffsetToUse = 64 + (88 * (texref.Index - 1));
                        byte[] NewName = new byte[64];
                        Array.Copy(NameToInject.ToArray(), 0, NewName, 0, NameToInject.ToArray().Length);
                        Array.Copy(NewName, 0, ParentMateial.UncompressedData, OffsetToUse, NewName.Length);
                        ParentMateial.CompressedData = Zlibber.Compressor(ParentMateial.UncompressedData);
                    }

                    Mainfrm.TreeSource.SelectedNode.Tag = ParentMateial;

                    Mainfrm.OpenFileModified = true;
                    Mainfrm.TreeSource.Update();
                    Mainfrm.TreeSource.EndUpdate();
                }
            }
        }
Пример #6
0
        public static LMTEntry InsertLMTEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            LMTEntry lmtentry = new LMTEntry();

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

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

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

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

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

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

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

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

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

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

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

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



            return(lmtentry);
        }
Пример #7
0
        public static GemEntry RenewGemEntry(TextBox texbox, GemEntry gem)
        {
            //Reconstructs the Entry List.
            string txbtxt = texbox.Text;

            string[] SPLT = new string[] { };

            SPLT = txbtxt.Split('\n');

            gem.EntryCountTotal      = SPLT.Length;
            gem.InterpolatedFileSize = gem.EntryCountTotal * 64;
            gem.EntryList            = new List <GEMEntries>();

            for (int g = 0; g < gem.EntryCountTotal; g++)
            {
                GEMEntries pe = new GEMEntries();
                pe.TotalName = SPLT[g];
                gem.EntryList.Add(pe);
            }

            //Rebuilds the Decompressed data Array.
            List <byte> NEWGEM = new List <byte>();

            byte[] HeaderGEM = { 0x47, 0x45, 0x4D, 0x00, 0x01, 0x01, 0xFE, 0xFF };
            NEWGEM.AddRange(HeaderGEM);
            int NewEntryCount = gem.EntryCountTotal;

            //Converts an integer to 4 bytes in a roundabout way.
            string GEMSize = 192.ToString("X8");

            byte[] GEMProjSize = new byte[4];
            GEMProjSize = ByteUtilitarian.StringToByteArray(GEMSize);
            Array.Reverse(GEMProjSize);

            NEWGEM.AddRange(GEMProjSize);

            string ENTemp = "";

            //string RPTemp = "";
            //string HashStr = "";
            byte[] HashTempDX = new byte[4];
            int    counter    = gem.EntryCountTotal - 1;

            for (int k = 0; k < counter; k++)
            {
                ENTemp = gem.EntryList[k].TotalName;
                ENTemp = ENTemp.Replace("\r", "");
                int    NumberChars = ENTemp.Length;
                byte[] namebuffer  = Encoding.ASCII.GetBytes(ENTemp);
                int    nblength    = namebuffer.Length;

                //Space for name is 64 bytes so we make a byte array with that size and then inject the name data in it.
                byte[] writenamedata = new byte[64];
                Array.Clear(writenamedata, 0, writenamedata.Length);

                for (int i = 0; i < namebuffer.Length; ++i)
                {
                    writenamedata[i] = namebuffer[i];
                }

                NEWGEM.AddRange(writenamedata);
            }

            gem.UncompressedData = NEWGEM.ToArray();
            gem.DSize            = gem.UncompressedData.Length;
            gem.CompressedData   = Zlibber.Compressor(gem.UncompressedData);
            gem.CSize            = gem.CompressedData.Length;
            gem._FileLength      = gem.UncompressedData.Length;

            return(gem);
        }
Пример #8
0
        public static ResourcePathListEntry RenewRPLList(TextBox texbox, ResourcePathListEntry rple)
        {
            //Reconstructs the Entry List.
            string txbtxt = texbox.Text;

            string[] SPLT = new string[] { };

            SPLT = txbtxt.Split('\n');

            rple.EntryCount = SPLT.Length;
            rple.EntryList  = new List <PathEntries>();

            for (int g = 0; g < rple.EntryCount; g++)
            {
                PathEntries pe = new PathEntries();
                pe.TotalName = SPLT[g];
                rple.EntryList.Add(pe);
            }

            //Rebuilds the Decompressed data Array.
            //byte[] NewLRP = new byte[] { };
            List <byte> NEWLRP = new List <byte>();

            byte[] HeaderLRP = { 0x4C, 0x52, 0x50, 0x00, 0x00, 0x01, 0xFE, 0xFF };
            NEWLRP.AddRange(HeaderLRP);
            int NewEntryCount = rple.EntryCount;

            //if (rple.EntryList[(rple.EntryCount - 1)].TotalName == "" || rple.EntryList[(rple.EntryCount - 1)].TotalName == " ")
            if (string.IsNullOrWhiteSpace(rple.EntryList[(rple.EntryCount - 1)].TotalName))
            {
                NewEntryCount--;
            }
            int ProjectedSize = NewEntryCount * 68;
            int EstimatedSize = ((int)Math.Round(ProjectedSize / 16.0, MidpointRounding.AwayFromZero) * 16);

            EstimatedSize = EstimatedSize + 48;

            //byte[] LRPEntryTotal = { Convert.ToByte(NewEntryCount), 0x00};
            byte[] LRPEntryTotal = new byte[4];
            LRPEntryTotal[3] = Convert.ToByte(NewEntryCount);
            Array.Reverse(LRPEntryTotal);

            //Converts an integer to 4 bytes in a roundabout way.
            string LRPSize = EstimatedSize.ToString("X8");

            byte[] LRPProjSize = new byte[4];
            LRPProjSize = ByteUtilitarian.StringToByteArray(LRPSize);
            Array.Reverse(LRPProjSize);

            //Finishes the header for the new LRP built from what you see on the textbox.
            NEWLRP.AddRange(LRPProjSize);
            NEWLRP.AddRange(LRPEntryTotal);

            string ENTemp  = "";
            string RPTemp  = "";
            string HashStr = "";

            byte[] HashTempDX = new byte[4];

            //Starts building the entries.
            for (int k = 0; k < NewEntryCount; k++)
            {
                ENTemp = rple.EntryList[k].TotalName;
                ENTemp = ENTemp.Replace("\r", "");
                int      inp     = (ENTemp.IndexOf("."));
                string[] SplTemp = ENTemp.Split('.');
                if (inp < 0)
                {
                    RPTemp = "";
                }
                else
                {
                    RPTemp = ENTemp.Substring(inp, ENTemp.Length - inp);
                }
                ENTemp = SplTemp[0];
                bool ExtFound = false;

                int    NumberChars = ENTemp.Length;
                byte[] namebuffer  = Encoding.ASCII.GetBytes(ENTemp);
                int    nblength    = namebuffer.Length;

                //Space for name is 64 bytes so we make a byte array with that size and then inject the name data in it.
                byte[] writenamedata = new byte[64];
                Array.Clear(writenamedata, 0, writenamedata.Length);

                for (int i = 0; i < namebuffer.Length; ++i)
                {
                    writenamedata[i] = namebuffer[i];
                }

                NEWLRP.AddRange(writenamedata);

                if (RPTemp == "")
                {
                    HashTempDX[0] = 0xFF;
                    HashTempDX[1] = 0xFF;
                    HashTempDX[2] = 0xFF;
                    HashTempDX[3] = 0xFF;
                }
                else
                {
                    //Typehash stuff.
                    try
                    {
                        using (var sr = new StreamReader("archive_filetypes.cfg"))
                        {
                            while (!sr.EndOfStream)
                            {
                                var keyword = Console.ReadLine() ?? RPTemp;
                                var line    = sr.ReadLine();
                                if (String.IsNullOrEmpty(line))
                                {
                                    continue;
                                }
                                if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                {
                                    ExtFound = true;
                                    HashStr  = line;
                                    HashStr  = HashStr.Split(' ')[0];
                                    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);
                    }
                }
                if (ExtFound == true)
                {
                    HashTempDX = ByteUtilitarian.StringToByteArray(HashStr);
                    Array.Reverse(HashTempDX);
                }
                else
                {
                    HashTempDX[0] = 0xFF;
                    HashTempDX[1] = 0xFF;
                    HashTempDX[2] = 0xFF;
                    HashTempDX[3] = 0xFF;
                }

                NEWLRP.AddRange(HashTempDX);
            }

            if (EstimatedSize > (NEWLRP.Count - 16))
            {
                for (int vv = 0; EstimatedSize > (NEWLRP.Count - 16); vv++)
                {
                    NEWLRP.Add(0x00);
                }
            }

            rple.UncompressedData = NEWLRP.ToArray();
            rple.DSize            = rple.UncompressedData.Length;

            rple.CompressedData = Zlibber.Compressor(rple.UncompressedData);
            rple.CSize          = rple.CompressedData.Length;

            rple._FileLength = rple.UncompressedData.Length;
            rple._EntryTotal = NewEntryCount;

            return(rple);
        }
Пример #9
0
        private void btnROK_Click(object sender, EventArgs e)
        {
            string newname = txtRename.Text;

            //Checks for blank/null names.
            if (newname == null || newname == "")
            {
                MessageBox.Show("This must have a name and cannot be null!", "Ahem");
                return;
            }

            if (OriginalName == txtRename.Text)
            {
                DialogResult = DialogResult.OK;
                Hide();
                return;
            }

            //Checks for existing name in directory.
            foreach (TreeNode c in node_.Parent.Nodes)
            {
                ArcEntry ae = new ArcEntry();
                ArcEntry se = new ArcEntry();
                if (node_.Tag is ArcEntry)
                {
                    ae = node_.Tag as ArcEntry;
                }

                if (c.Tag is ArcEntry)
                {
                    se = c.Tag as ArcEntry;
                }

                /*
                 * //Checks the nodes in the same directory for existing name AND extension and will stop if there's a node with the same type in the same directory.
                 * if (c.Text == txtRename.Text && c.Tag as string != "MaterialChildTexture")
                 * {
                 *  if (ae != se && ae.FileExt == se.FileExt)
                 *  {
                 *      MessageBox.Show("That name already exists on a resource of the same type on the same level. \nTry a different name.", "Oh Boy");
                 *      return;
                 *  }
                 * }
                 */
            }

            //Changes the name to what was chosen. Should reflect on the Treeview.
            treeview.SelectedNode.Text = txtRename.Text;
            treeview.SelectedNode.Name = txtRename.Text;

            //Ensures the TrueName gets change so it gets reflected in the save.
            ArcEntry aey = new ArcEntry();

            if (treeview.SelectedNode.Tag is ArcEntry)
            {
                aey          = treeview.SelectedNode.Tag as ArcEntry;
                aey.TrueName = txtRename.Text;
            }
            else if (treeview.SelectedNode.Tag != null && treeview.SelectedNode.Tag as string == "Folder")
            {
            }
            else if (treeview.SelectedNode.Tag != null && treeview.SelectedNode.Tag is MaterialTextureReference)
            {
                //Goes about accessing and updating the data inside the material in a roundabout way.
                MaterialTextureReference texref = treeview.SelectedNode.Tag as MaterialTextureReference;
                MaterialEntry            mentry = new MaterialEntry();
                TreeNode parent = treeview.SelectedNode.Parent;
                TreeNode child  = treeview.SelectedNode;
                treeview.SelectedNode = parent;
                parent = treeview.SelectedNode.Parent;
                treeview.SelectedNode = parent;
                mentry = treeview.SelectedNode.Tag as MaterialEntry;
                if (mentry != null)
                {
                    //Now for the actual file update.
                    List <byte> NameToInject = new List <byte>();
                    NameToInject.AddRange(Encoding.ASCII.GetBytes(txtRename.Text));
                    int OffsetToUse;
                    OffsetToUse = 64 + (88 * (texref.Index - 1));
                    byte[] NewName = new byte[64];
                    Array.Copy(NameToInject.ToArray(), 0, NewName, 0, NameToInject.ToArray().Length);
                    Array.Copy(NewName, 0, mentry.UncompressedData, OffsetToUse, NewName.Length);
                    mentry.CompressedData     = Zlibber.Compressor(mentry.UncompressedData);
                    treeview.SelectedNode.Tag = mentry;
                }
                treeview.SelectedNode = child;
            }

            Mainfrm.OpenFileModified = true;

            //Closes form with changes made above.
            DialogResult = DialogResult.OK;
            Hide();
        }
Пример #10
0
        public static MissionEntry SaveMissionEntry(MissionEntry misentry, TreeNode node)
        {
            using (MemoryStream MisStream = new MemoryStream(misentry.UncompressedData))
            {
                using (BinaryWriter bwr = new BinaryWriter(MisStream))
                {
                    //Gets All The Mission Files From Child Nodes variables and writes to the main mission file.
                    foreach (ArcEntryWrapper youngn in node.Nodes)
                    {
                        Mission msn = youngn.Tag as Mission;
                        bwr.BaseStream.Position = msn.DataOffset;
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 104;
                        bwr.Write(msn.Player1PointCharacter);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;
                        bwr.Write(msn.P1PointCharacterAIFlag);
                        bwr.Write(msn.P1PointCharacterAssistType);
                        bwr.Write(msn.P1PointCharacterUnkownParamA);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 16;
                        bwr.Write(msn.P1PointCharacterUnkownParamB);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;

                        bwr.Write(msn.P1Assist1CharID);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;
                        bwr.Write(msn.P1Assist1CharAIFlag);
                        bwr.Write(msn.P1Assist1CharAssistType);
                        bwr.Write(msn.P1Assist1CharUnkownParamA);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 16;
                        bwr.Write(msn.P1Assist1CharUnkownParamB);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;

                        bwr.Write(msn.P1Assist2CharID);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;
                        bwr.Write(msn.P1Assist2CharAIFlag);
                        bwr.Write(msn.P1Assist2CharAssistType);
                        bwr.Write(msn.P1Assist2CharUnkownParamA);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 16;
                        bwr.Write(msn.P1Assist2CharUnkownParamB);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 4;

                        bwr.Write(msn.Unknown100);

                        bwr.Write(msn.P2PointCharacterID);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;
                        bwr.Write(msn.P2PointCharacterAIFlag);
                        bwr.Write(msn.P2PointCharacterAssistType);
                        bwr.Write(msn.P2PointCharacterUnkownParamA);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 16;
                        bwr.Write(msn.P2PointCharacterUnkownParamB);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;

                        bwr.Write(msn.P2Assist1CharID);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;
                        bwr.Write(msn.P2Assist1CharAIFlag);
                        bwr.Write(msn.P2Assist1CharAssistType);
                        bwr.Write(msn.P2Assist1CharUnkownParamA);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 16;
                        bwr.Write(msn.P2Assist1CharUnkownParamB);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;

                        bwr.Write(msn.P2Assist2CharID);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 8;
                        bwr.Write(msn.P2Assist2CharAIFlag);
                        bwr.Write(msn.P2Assist2CharAssistType);
                        bwr.Write(msn.P2Assist2CharUnkownParamA);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 16;
                        bwr.Write(msn.P2Assist2CharUnkownParamB);
                        bwr.BaseStream.Position = bwr.BaseStream.Position + 424;

                        bwr.Write(msn.ComboListFlagA);
                        bwr.Write(msn.ComboListFlagB);

                        for (int j = 0; j < 82; j++)
                        {
                            bwr.Write(msn.AnmChrMoveIDList[j]);
                        }
                    }
                }
            }

            misentry.CompressedData = Zlibber.Compressor(misentry.UncompressedData);


            return(misentry);
        }
Пример #11
0
        public static void ReplaceKnownEntry(TreeView tree, ArcEntryWrapper node, string filename, DefaultWrapper entrytobuild, DefaultWrapper entrytoreplace, Type filetype = null)
        {
            tree.BeginUpdate();


            //We build the entrytobuild starting from the uncompressed data.
            entrytobuild.UncompressedData = System.IO.File.ReadAllBytes(filename);

            //Then Compress.
            entrytobuild.CompressedData = Zlibber.Compressor(entrytobuild.UncompressedData);

            entrytobuild.DSize = entrytobuild.UncompressedData.Length;
            entrytobuild.CSize = entrytobuild.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);
            }



            //Code that replaces the name with the new node's name.

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

            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() ?? entrytobuild.FileExt;
                        var line    = sr2.ReadLine();
                        if (String.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                        {
                            TypeHash = line;
                            TypeHash = TypeHash.Split(' ')[0];
                            entrytobuild.TypeHash = TypeHash;
                            break;
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Cannot find archive_filetypes.cfg so I cannot continue parsing this file.\n Find archive_filetypes.cfg and then restart this program.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                }
                Process.GetCurrentProcess().Kill();
                return;
            }

            var tag = node.Tag;

            if (tag is DefaultWrapper)
            {
                entrytoreplace = tag as DefaultWrapper;
            }

            string path  = "";
            int    index = entrytoreplace.EntryName.LastIndexOf("\\");

            if (index > 0)
            {
                path = entrytoreplace.EntryName.Substring(0, index);
            }

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

            //Enters name related parameters of the entrytobuild. Meant to preserve the orignal filename.
            entrytobuild.TrueName  = entrytoreplace.TrueName;
            entrytobuild.FileExt   = entrytoreplace.FileExt;
            entrytobuild.EntryName = entrytoreplace.EntryName;

            tag = entrytobuild;

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

            var aew = node as ArcEntryWrapper;

            string type = node.GetType().ToString();

            if (type == "ThreeWorkTool.Resources.Wrappers.ArcEntryWrapper")
            {
                aew.entryfile = entrytobuild;
            }

            node           = aew;
            node.entryfile = entrytobuild;
        }
Пример #12
0
        public static void InsertKnownEntry(TreeView tree, ArcEntryWrapper node, string filename, DefaultWrapper entrytobuild, BinaryReader bnr, Type filetype = null)
        {
            //We build the entrytobuild starting from the uncompressed data.
            entrytobuild.UncompressedData = System.IO.File.ReadAllBytes(filename);
            entrytobuild.DSize            = entrytobuild.UncompressedData.Length;

            //Then Compress.
            entrytobuild.CompressedData = Zlibber.Compressor(entrytobuild.UncompressedData);
            entrytobuild.CSize          = entrytobuild.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);
            }

            entrytobuild.TrueName = trname;
            entrytobuild.TrueName = Path.GetFileNameWithoutExtension(trname);
            entrytobuild.FileExt  = trname.Substring(trname.LastIndexOf("."));

            //Gets the path of the selected node to inject here.
            string nodepath = tree.SelectedNode.FullPath;

            nodepath = nodepath.Substring(nodepath.IndexOf("\\") + 1);

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

            //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() ?? entrytobuild.FileExt;
                        var line    = sr2.ReadLine();
                        if (String.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                        {
                            entrytobuild.TypeHash = line;
                            entrytobuild.TypeHash = entrytobuild.TypeHash.Split(' ')[0];

                            break;
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Cannot find archive_filetypes.cfg so I cannot continue parsing this file.\n Find archive_filetypes.cfg and then restart this program.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                }
                Process.GetCurrentProcess().Kill();
            }
        }
Пример #13
0
        public static void ReplaceEntry(TreeView tree, ArcEntryWrapper node, string filename, DefaultWrapper entrytobuild, DefaultWrapper entrytoreplace, Type filetype = null)
        {
            tree.BeginUpdate();

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

                    //Then Compress.
                    entrytobuild.CompressedData = Zlibber.Compressor(entrytobuild.UncompressedData);


                    //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 entrytobuild.
                    entrytobuild.TrueName = trname;
                    entrytobuild.TrueName = Path.GetFileNameWithoutExtension(trname);
                    entrytobuild.FileExt  = trname.Substring(trname.LastIndexOf("."));

                    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() ?? entrytobuild.FileExt;
                                var line    = sr2.ReadLine();
                                if (String.IsNullOrEmpty(line))
                                {
                                    continue;
                                }
                                if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                {
                                    TypeHash = line;
                                    TypeHash = TypeHash.Split(' ')[0];
                                    entrytobuild.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;
                    }



                    var tag = node.Tag;
                    if (tag is DefaultWrapper)
                    {
                        entrytoreplace = tag as DefaultWrapper;
                    }

                    string path  = "";
                    int    index = entrytoreplace.EntryName.LastIndexOf("\\");
                    if (index > 0)
                    {
                        path = entrytoreplace.EntryName.Substring(0, index);
                    }

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

                    tag = entrytobuild;

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

                    var aew = node as ArcEntryWrapper;

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

                    node           = aew;
                    node.entryfile = entrytobuild;

                    /*
                     * //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 ArcEntry;
        }