예제 #1
0
        private bool checkTXTCEntry(DatabasePackedFile.Entry entry, Database db)
        {
            if (entry.Key.typeId == 0x033A1435)
            {
                //textBox1.Text += "  " + entry.Key.ToString() + Environment.NewLine;
                // textBox1.Text += "    Checking for corrupted TGI offset... ";

                // Quick and dirty way
                Stream TXTC = db.GetResourceStream(entry.Key);
                // Read offset, first 4 bytes after ID
                StreamHelpers.ReadValueU32(TXTC);

                uint offset = StreamHelpers.ReadValueU32(TXTC);
                // textBox1.Text += offset.ToString() + "...";

                // Seek to this offset + 8 and read the number there.
                TXTC.Seek(offset + 8, SeekOrigin.Begin);

                uint numTGIs = StreamHelpers.ReadValueU8(TXTC);
                // textBox1.Text += numTGIs.ToString() + " TGIs... ";

                // Since each TGI is 16 bytes we can calculate how many bytes they are.
                uint tgiSize      = numTGIs * 16;
                uint tgiOffsetEnd = offset + 8 + 1 + tgiSize;

                //textBox1.Text += "TGI block end is at " + tgiOffsetEnd.ToString() + "...";

                if (tgiOffsetEnd == TXTC.Length)
                {
                    TXTC = null;
                    return(true);
                }
                else
                {
                    TXTC = null;
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
        public static bool fixTXTR(Database db)
        {
            uint numFixed = 0;

            // textBox1.Text += "Checking for corrupted TXTC entries... " + Environment.NewLine;
            for (int i = 0; i < db.dbpf.Entries.Count; i++)
            {
                DatabasePackedFile.Entry entry = db.dbpf.Entries[i];
                if (entry.Key.typeId == 0x033A1435)
                {
                    //textBox1.Text += "  " + entry.Key.ToString() + Environment.NewLine;
                    // textBox1.Text += "    Checking for corrupted TGI offset... ";

                    // Quick and dirty way
                    Stream TXTC = db.GetResourceStream(entry.Key);
                    // Read offset, first 4 bytes after ID
                    StreamHelpers.ReadValueU32(TXTC);

                    uint offset = StreamHelpers.ReadValueU32(TXTC);
                    // textBox1.Text += offset.ToString() + "...";

                    // Seek to this offset + 8 and read the number there.
                    TXTC.Seek(offset + 8, SeekOrigin.Begin);

                    uint numTGIs = StreamHelpers.ReadValueU8(TXTC);
                    // textBox1.Text += numTGIs.ToString() + " TGIs... ";

                    // Since each TGI is 16 bytes we can calculate how many bytes they are.
                    uint tgiSize      = numTGIs * 16;
                    uint tgiOffsetEnd = offset + 8 + 1 + tgiSize;

                    //textBox1.Text += "TGI block end is at " + tgiOffsetEnd.ToString() + "...";

                    if (tgiOffsetEnd == TXTC.Length)
                    {
                        return(false);
                    }
                    else
                    {
                        // Try offset - 1
                        offset = offset - 1;

                        // Seek to this offset + 8 and read the number there.
                        TXTC.Seek(offset + 8, SeekOrigin.Begin);

                        numTGIs = StreamHelpers.ReadValueU8(TXTC);
                        // textBox1.Text += numTGIs.ToString() + " TGIs... ";

                        // Since each TGI is 16 bytes we can calculate how many bytes they are.
                        tgiSize      = numTGIs * 16;
                        tgiOffsetEnd = offset + 8 + 1 + tgiSize;

                        //textBox1.Text += "TGI block end is at " + tgiOffsetEnd.ToString() + "...";

                        if (tgiOffsetEnd == TXTC.Length)
                        {
                            //   textBox1.Text += "Correct!";
                            // Offset it minus 1

                            TXTC.Seek(4, SeekOrigin.Begin);
                            StreamHelpers.WriteValueU32(TXTC, offset);

                            MemoryStream newTXTC = new MemoryStream();
                            StreamHelpers.CopyStream(TXTC, newTXTC, true);

                            db.SetResourceStream(entry.Key, newTXTC);

                            //    textBox1.Text += Environment.NewLine;
                            //     textBox1.Text += "The above resource has been fixed.";

                            numFixed++;

                            newTXTC.Close();
                        }
                        else
                        {
                            //   textBox1.Text += "Incorrect!";
                        }
                    }

                    // textBox1.Text += Environment.NewLine;


                    TXTC = null;
                }
            }

            if (numFixed == 0)
            {
                //textBox1.Text += Environment.NewLine;
                //textBox1.Text += "This file appears OK!";
                return(false);
            }
            else
            {
                //this.filesFixed++;
                //textBox1.Text += Environment.NewLine;
                //textBox1.Text += "This file had some corrupted TXTCs! They are now fixed.";
                //textBox1.Text += "Fixed " + filename + Environment.NewLine;
                //saveToolStripMenuItem.Enabled = true;
                db.Commit(true);
            }

            return(true);
        }