Exemplo n.º 1
0
        public void DecompressPCC(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }
            PCCObjects.Misc.PCCDecompress(path);
            string     filen = Path.GetFileName(path);
            FileStream fs2   = new FileStream(path, FileMode.Open, FileAccess.Read);
            uint       fsize = (uint)fs2.Length;

            fs2.Close();
            TOCeditor tc = new TOCeditor();

            if (!tc.UpdateFile(filen, fsize))
            {
                MessageBox.Show("Didn't found Entry");
            }
            tc.Close();
        }
Exemplo n.º 2
0
        public static void DLCTocFix(String path)
        {
            if (String.Compare(Path.GetFileName(path), "PCConsoleTOC.bin", true) != 0)
            {
                throw new FileFormatException("Incorrect file passed!");
            }
            else if (!File.Exists(path))
            {
                throw new FileNotFoundException("PCConsoleTOC.bin file not found!");
            }

            TOCeditor tc = new TOCeditor();

            FileInfo[] files = new DirectoryInfo(Path.GetDirectoryName(path)).GetFiles();
            for (int i = 0; i < files.Length; i++)
            {
                if (String.Compare(".bin", files[i].Extension, true) == 0)
                {
                    continue;
                }

                tc.UpdateFile("\\" + Path.GetFileName(files[i].FullName), (uint)files[i].Length, path);
            }
        }
Exemplo n.º 3
0
        public static void DLCTocFix(String path)
        {
            if (String.Compare(Path.GetFileName(path), "PCConsoleTOC.bin", true) != 0)
                throw new FileFormatException("Incorrect file passed!");
            else if (!File.Exists(path))
                throw new FileNotFoundException("PCConsoleTOC.bin file not found!");

            TOCeditor tc = new TOCeditor();
            FileInfo[] files = new DirectoryInfo(Path.GetDirectoryName(path)).GetFiles();
            for (int i = 0; i < files.Length; i++)
            {
                if (String.Compare(".bin", files[i].Extension, true) == 0)
                    continue;

                tc.UpdateFile("\\" + Path.GetFileName(files[i].FullName), (uint)files[i].Length, path);
            }
        }
Exemplo n.º 4
0
 public void ImportFromFile(int tfc)
 {
     OpenFileDialog Dialog = new OpenFileDialog();
     if (T2D.PixelFormat == "PF_DXT1\0" ||
         T2D.PixelFormat == "PF_DXT5\0")
         Dialog.Filter = "DDS Files (*.dds)|*.dds";
     if (T2D.PixelFormat == "PF_G8\0" ||
         T2D.PixelFormat == "PF_V8U8\0" ||
         T2D.PixelFormat == "PF_A8R8G8B8\0")
         Dialog.Filter = "TGA Files (*.tga)|*.tga";
     int format = -1;
     if (T2D.PixelFormat == "PF_DXT1\0")
         format = 0;
     if (T2D.PixelFormat == "PF_DXT5\0")
         format = 1;
     if (T2D.PixelFormat == "PF_V8U8\0")
         format = 2;
     if (T2D.PixelFormat == "PF_A8R8G8B8\0")
         format = 3;
     if (T2D.PixelFormat == "PF_G8\0")
         format = 4;
     if (!TextureTFCs[tfc].InCache)
     {
         if (Dialog.ShowDialog() == DialogResult.OK)
         {
             if (format == 0 || format == 1)
             {
                 ImageFile t = new ImageFile();
                 t.ImportFromFile(Dialog.FileName);
                 if (t.ImageSizeX == TextureTFCs[tfc].sizeX &&
                     t.ImageSizeY == TextureTFCs[tfc].sizeY &&
                     t.ImageFormat == format &&
                     t.memsize == TextureTFCs[tfc].size)
                 {
                     for (int i = 0; i < t.memsize; i++)
                         memory[TextureTFCs[tfc].offset + i] = t.memory[i];
                     MessageBox.Show("Done.");
                 }
             }
             if (format > 1 && format < 5)
             {
                 ImageFile t = new ImageFile();
                 t.ImportFromFile(Dialog.FileName);
                 if (t.ImageSizeX == TextureTFCs[tfc].sizeX &&
                     t.ImageSizeY == TextureTFCs[tfc].sizeY)
                     if (t.ImageBits != 32)
                     {
                         MessageBox.Show("Please use 32 bit Targa image!");
                     }
                     else
                     {
                         switch (format)
                         {
                             case 2:
                                 for (int i = 0; i < t.memsize / 4; i++)
                                 {
                                     memory[TextureTFCs[tfc].offset + i * 2] = t.memory[i * 4];
                                     memory[TextureTFCs[tfc].offset + i * 2 + 1] = t.memory[i * 4 + 2];
                                 }
                                 break;
                             case 3:
                                 for (int i = 0; i < t.memsize; i++)
                                     memory[TextureTFCs[tfc].offset + i] = t.memory[i];
                                 break;
                             case 4:
                                 for (int i = 0; i < t.memsize / 4; i++)
                                     memory[TextureTFCs[tfc].offset + i] = t.memory[i * 4];
                                 break;
                         }
                         MessageBox.Show("Done.");
                     }
             }
         }
     }
     else
         if (Dialog.ShowDialog() == DialogResult.OK)
         {
             ImageFile t = new ImageFile();
             t.ImportFromFile(Dialog.FileName);
             if ((format == 0 || format == 1) && t.ImageFormat == format)
                 if (t.ImageSizeX == TextureTFCs[tfc].sizeX &&
                     t.ImageSizeY == TextureTFCs[tfc].sizeY)
                 {
                     TFCFile TFCf = new TFCFile(T2D.Tsource);
                     byte[] buff;
                     if (TFCf.isTFCCompressed())
                         buff = ZBlock.Compress(t.memory);
                     else
                         buff = t.memory;
                     byte[] buff2 = BitConverter.GetBytes(TFCf.getFileSize());
                     for (int i = 0; i < 4; i++)
                         memory[TextureTFCs[tfc].HeaderOffset + 20 + i] = buff2[i];
                     buff2 = BitConverter.GetBytes(buff.Length);
                     for (int i = 0; i < 4; i++)
                         memory[TextureTFCs[tfc].HeaderOffset + 16 + i] = buff2[i];
                     TFCf.AppendToTFC(buff);
                     int size = TFCf.getFileSize();
                     if (size != -1)
                     {
                         TOCeditor tc = new TOCeditor();
                         if (!tc.UpdateFile(T2D.Tsource + ".tfc", (uint)size))
                             MessageBox.Show("Didn't found Entry");
                         tc.Close();
                     }
                 }
                 else
                 {
                     System.Windows.Forms.DialogResult m = MessageBox.Show("The size doesn't match, import anyway?", "ME3 Explorer", MessageBoxButtons.YesNo);
                     if (m == DialogResult.Yes)
                     {
                         TFCFile TFCf = new TFCFile(T2D.Tsource);
                         byte[] buff;
                         if (TFCf.isTFCCompressed())
                             buff = ZBlock.Compress(t.memory);
                         else
                             buff = t.memory;
                         byte[] buff2 = BitConverter.GetBytes(TFCf.getFileSize());
                         for (int i = 0; i < 4; i++)
                             memory[TextureTFCs[tfc].HeaderOffset + 20 + i] = buff2[i];
                         buff2 = BitConverter.GetBytes(buff.Length);
                         for (int i = 0; i < 4; i++)
                             memory[TextureTFCs[tfc].HeaderOffset + 16 + i] = buff2[i];
                         if (tfc == 0)
                         {
                             buff2 = BitConverter.GetBytes(t.ImageSizeX);
                             for (int i = 0; i < 4; i++)
                                 memory[T2D.offSizeX + i] = buff2[i];
                             buff2 = BitConverter.GetBytes(t.ImageSizeY);
                             for (int i = 0; i < 4; i++)
                                 memory[T2D.offSizeY + i] = buff2[i];
                         }
                         else
                         {
                             buff2 = BitConverter.GetBytes(t.ImageSizeX * 2);
                             for (int i = 0; i < 4; i++)
                                 memory[TextureTFCs[tfc].HeaderOffset + i] = buff2[i];
                             buff2 = BitConverter.GetBytes(t.ImageSizeY * 2);
                             for (int i = 0; i < 4; i++)
                                 memory[TextureTFCs[tfc].HeaderOffset + 4 + i] = buff2[i];
                             TFCf.AppendToTFC(buff);
                         }
                         TFCf.AppendToTFC(buff);
                         int size = TFCf.getFileSize();
                         if (size != -1)
                         {
                             TOCeditor tc = new TOCeditor();
                             if (!tc.UpdateFile(T2D.Tsource + ".tfc", (uint)size))
                                 MessageBox.Show("Didn't found Entry");
                             tc.Close();
                         }
                     }
                 }
             if (format > 1 && format < 5)
             {
                 if (t.ImageSizeX == TextureTFCs[tfc].sizeX &&
                     t.ImageSizeY == TextureTFCs[tfc].sizeY)
                     if (t.ImageBits != 32)
                     {
                         MessageBox.Show("Please use 32 bit Targa image!");
                     }
                     else
                     {
                         byte[] buf = new byte[0];
                         switch (format)
                         {
                             case 2:
                                 buf = new byte[t.memsize / 2];
                                 for (int i = 0; i < t.memsize / 4; i++)
                                 {
                                     buf[i * 2] = t.memory[i * 4];
                                     buf[i * 2 + 1] = t.memory[i * 4 + 2];
                                 }
                                 break;
                             case 3:
                                 buf = t.memory;
                                 break;
                             case 4:
                                 buf = new byte[t.memsize / 4];
                                 for (int i = 0; i < t.memsize / 4; i++)
                                     buf[i] = t.memory[i * 4];
                                 break;
                         }
                         TFCFile TFCf = new TFCFile(T2D.Tsource);
                         byte[] buff;
                         if (TFCf.isTFCCompressed())
                             buff = ZBlock.Compress(t.memory);
                         else
                             buff = t.memory;
                         byte[] buff2 = BitConverter.GetBytes(TFCf.getFileSize());
                         for (int i = 0; i < 4; i++)
                             memory[TextureTFCs[tfc].HeaderOffset + 20 + i] = buff2[i];
                         buff2 = BitConverter.GetBytes(buff.Length);
                         for (int i = 0; i < 4; i++)
                             memory[TextureTFCs[tfc].HeaderOffset + 12 + i] = buff2[i];
                         TFCf.AppendToTFC(buff);
                         int size = TFCf.getFileSize();
                         if (size != -1)
                         {
                             TOCeditor tc = new TOCeditor();
                             if (!tc.UpdateFile(T2D.Tsource + ".tfc", (uint)size))
                                 MessageBox.Show("Didn't found Entry");
                             tc.Close();
                         }
                         MessageBox.Show("Done.");
                     }
             }
         }
 }
Exemplo n.º 5
0
 public void CloneEntry(int entry)
 {
     byte[] buffdata;
     DialogResult r = MessageBox.Show("Clone with new data?","", MessageBoxButtons.YesNo);
     if (r == DialogResult.No)
     {
         buffdata = EntryToBuff(entry);                
     }
     else
     {
         OpenFileDialog d = new OpenFileDialog();
         d.Filter = "bin files (*.bin)|*.bin|all files|*.*";
         if (d.ShowDialog() == DialogResult.OK)
         {
             FileStream f = new FileStream(d.FileName, FileMode.Open, FileAccess.Read);
             int size = (int)f.Length;
             buffdata = new byte[size];
             int count;
             int sum = 0;
             while ((count = f.Read(buffdata, sum, size - sum)) > 0) sum += count;
         }
         else
             return;
     }
     int sizebefore = memsize;
     MemoryStream m = new MemoryStream();
     m.Write(memory, 0, (int)Header.offinfo + 8);
     byte[] buff = BitConverter.GetBytes(Header.ExportCount + 1);
     m.Write(buff, 0, 4);
     buff = BitConverter.GetBytes(sizebefore);
     m.Write(buff, 0, 4);
     m.Write(memory, (int)Header.offinfo + 16,sizebefore - ((int)Header.offinfo + 16));
     for (int i = 0; i < Export.Length; i++)
     {
         uint len = Export[i].end - Export[i].start;
         m.Write(memory, (int)Export[i].start, (int)len);
     }
     int pos =(int)m.Length;
     uint len2 = Export[entry].end - Export[entry].start;
     m.Write(memory, (int)Export[entry].start, 32);
     buff = BitConverter.GetBytes(buffdata.Length);
     m.Write(buff, 0, 4);
     buff = BitConverter.GetBytes(pos + (int)len2);
     m.Write(buff, 0, 4);
     m.Write(memory, (int)Export[entry].start + 40, (int)len2- 40);
     m.Write(buffdata, 0, buffdata.Length);
     Header.ExportCount++;
     Header.ExportOffset = (uint)sizebefore;
     exports ex = new exports();
     ex.Class = Export[entry].Class;
     ex.DataOffset = (uint)pos + len2;
     ex.DataSize = (uint)buffdata.Length;
     ex.end = (uint)pos + len2;
     ex.Link  = Export[entry].Link;
     ex.Name = Export[entry].Name;
     ex.off = Export[entry].off;
     ex.start = (uint)pos;
     exports[] t = new exports[Header.ExportCount];
     for (int i = 0; i < Header.ExportCount - 1; i++)
         t[i] = Export[i];
     t[Header.ExportCount - 1] = ex;
     Export = t;
     memory = m.ToArray();
     TOCeditor tc = new TOCeditor();
     if (!tc.UpdateFile(loadedFilename, (uint)memsize))
         MessageBox.Show("Didn't found Entry");
 }
Exemplo n.º 6
0
        private void ImportWav(string pathafc, string pathwav, int off, string pathBIO, bool updateTOC = true)
        {
            if (!File.Exists(pathafc) || !File.Exists(pathwav))
            {
                return;
            }
            FileStream fs = new FileStream(pathafc, FileMode.Open, FileAccess.Read);

            byte[] Header = new byte[94];
            fs.Seek(DataOffset, SeekOrigin.Begin);
            for (int i = 0; i < 94; i++)
            {
                Header[i] = (byte)fs.ReadByte();
            }
            fs.Close();
            fs = new FileStream(pathwav, FileMode.Open, FileAccess.Read);
            byte[] newfile = new byte[fs.Length];
            for (int i = 0; i < fs.Length; i++)
            {
                newfile[i] = (byte)fs.ReadByte();
            }
            fs.Close();
            newfile = ModifyHeader(newfile, Header);
            fs      = new FileStream(pathafc, FileMode.Append, FileAccess.Write, FileShare.Write);
            int newoff  = (int)fs.Length;
            int newsize = newfile.Length;

            for (int i = 0; i < newsize; i++)
            {
                fs.WriteByte(newfile[i]);
            }
            uint newafcsize = (uint)fs.Length;

            fs.Close();
            byte[] buff = BitConverter.GetBytes(newsize);
            for (int i = 0; i < 4; i++)
            {
                memory[ValueOffset + i - 4] = buff[i];
            }
            for (int i = 0; i < 4; i++)
            {
                memory[ValueOffset + i] = buff[i];
            }
            buff = BitConverter.GetBytes(newoff);
            for (int i = 0; i < 4; i++)
            {
                memory[ValueOffset + i + 4] = buff[i];
            }
            DataSize   = newsize;
            DataOffset = newoff;
            TOCeditor tc = new TOCeditor();
            string    s  = Path.GetFileName(pathafc);

            if (updateTOC)
            {
                if (!tc.UpdateFile("\\" + s, newafcsize, pathBIO + "PCConsoleTOC.bin"))
                {
                    MessageBox.Show("Didn't found Entry!");
                }
            }
        }
Exemplo n.º 7
0
 private void ImportWav(string pathafc, string pathwav, int off, string pathBIO, bool updateTOC = true)
 {
     if (!File.Exists(pathafc) || !File.Exists(pathwav))
         return;
     FileStream fs = new FileStream(pathafc, FileMode.Open, FileAccess.Read);
     byte[] Header = new byte[94];
     fs.Seek(DataOffset, SeekOrigin.Begin);
     for (int i = 0; i < 94; i++)
         Header[i] = (byte)fs.ReadByte();
     fs.Close();
     fs = new FileStream(pathwav, FileMode.Open, FileAccess.Read);
     byte[] newfile = new byte[fs.Length];
     for (int i = 0; i < fs.Length; i++)
         newfile[i] = (byte)fs.ReadByte();
     fs.Close();
     newfile = ModifyHeader(newfile, Header);
     fs = new FileStream(pathafc, FileMode.Append, FileAccess.Write, FileShare.Write);
     int newoff = (int)fs.Length;
     int newsize = newfile.Length;
     for (int i = 0; i < newsize; i++)
         fs.WriteByte(newfile[i]);
     uint newafcsize = (uint)fs.Length;
     fs.Close();
     byte[] buff = BitConverter.GetBytes(newsize);
     for (int i = 0; i < 4; i++)
         memory[ValueOffset + i - 4] = buff[i];
     for (int i = 0; i < 4; i++)
         memory[ValueOffset + i] = buff[i];
     buff = BitConverter.GetBytes(newoff);
     for (int i = 0; i < 4; i++)
         memory[ValueOffset + i + 4] = buff[i];
     DataSize = newsize;
     DataOffset = newoff;
     TOCeditor tc = new TOCeditor();
     string s = Path.GetFileName(pathafc);
     if (updateTOC)
         if (!tc.UpdateFile("\\" + s, newafcsize, pathBIO + "PCConsoleTOC.bin"))
             MessageBox.Show("Didn't found Entry!");
 }
Exemplo n.º 8
0
        public void ImportFromFile(int tfc)
        {
            OpenFileDialog Dialog = new OpenFileDialog();

            if (T2D.PixelFormat == "PF_DXT1\0" ||
                T2D.PixelFormat == "PF_DXT5\0")
            {
                Dialog.Filter = "DDS Files (*.dds)|*.dds";
            }
            if (T2D.PixelFormat == "PF_G8\0" ||
                T2D.PixelFormat == "PF_V8U8\0" ||
                T2D.PixelFormat == "PF_A8R8G8B8\0")
            {
                Dialog.Filter = "TGA Files (*.tga)|*.tga";
            }
            int format = -1;

            if (T2D.PixelFormat == "PF_DXT1\0")
            {
                format = 0;
            }
            if (T2D.PixelFormat == "PF_DXT5\0")
            {
                format = 1;
            }
            if (T2D.PixelFormat == "PF_V8U8\0")
            {
                format = 2;
            }
            if (T2D.PixelFormat == "PF_A8R8G8B8\0")
            {
                format = 3;
            }
            if (T2D.PixelFormat == "PF_G8\0")
            {
                format = 4;
            }
            if (!TextureTFCs[tfc].InCache)
            {
                if (Dialog.ShowDialog() == DialogResult.OK)
                {
                    if (format == 0 || format == 1)
                    {
                        ImageFile t = new ImageFile();
                        t.ImportFromFile(Dialog.FileName);
                        if (t.ImageSizeX == TextureTFCs[tfc].sizeX &&
                            t.ImageSizeY == TextureTFCs[tfc].sizeY &&
                            t.ImageFormat == format &&
                            t.memsize == TextureTFCs[tfc].size)
                        {
                            for (int i = 0; i < t.memsize; i++)
                            {
                                memory[TextureTFCs[tfc].offset + i] = t.memory[i];
                            }
                            MessageBox.Show("Done.");
                        }
                    }
                    if (format > 1 && format < 5)
                    {
                        ImageFile t = new ImageFile();
                        t.ImportFromFile(Dialog.FileName);
                        if (t.ImageSizeX == TextureTFCs[tfc].sizeX &&
                            t.ImageSizeY == TextureTFCs[tfc].sizeY)
                        {
                            if (t.ImageBits != 32)
                            {
                                MessageBox.Show("Please use 32 bit Targa image!");
                            }
                            else
                            {
                                switch (format)
                                {
                                case 2:
                                    for (int i = 0; i < t.memsize / 4; i++)
                                    {
                                        memory[TextureTFCs[tfc].offset + i * 2]     = t.memory[i * 4];
                                        memory[TextureTFCs[tfc].offset + i * 2 + 1] = t.memory[i * 4 + 2];
                                    }
                                    break;

                                case 3:
                                    for (int i = 0; i < t.memsize; i++)
                                    {
                                        memory[TextureTFCs[tfc].offset + i] = t.memory[i];
                                    }
                                    break;

                                case 4:
                                    for (int i = 0; i < t.memsize / 4; i++)
                                    {
                                        memory[TextureTFCs[tfc].offset + i] = t.memory[i * 4];
                                    }
                                    break;
                                }
                                MessageBox.Show("Done.");
                            }
                        }
                    }
                }
            }
            else
            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                ImageFile t = new ImageFile();
                t.ImportFromFile(Dialog.FileName);
                if ((format == 0 || format == 1) && t.ImageFormat == format)
                {
                    if (t.ImageSizeX == TextureTFCs[tfc].sizeX &&
                        t.ImageSizeY == TextureTFCs[tfc].sizeY)
                    {
                        TFCFile TFCf = new TFCFile(T2D.Tsource);
                        byte[]  buff;
                        if (TFCf.isTFCCompressed())
                        {
                            buff = ZBlock.Compress(t.memory);
                        }
                        else
                        {
                            buff = t.memory;
                        }
                        byte[] buff2 = BitConverter.GetBytes(TFCf.getFileSize());
                        for (int i = 0; i < 4; i++)
                        {
                            memory[TextureTFCs[tfc].HeaderOffset + 20 + i] = buff2[i];
                        }
                        buff2 = BitConverter.GetBytes(buff.Length);
                        for (int i = 0; i < 4; i++)
                        {
                            memory[TextureTFCs[tfc].HeaderOffset + 16 + i] = buff2[i];
                        }
                        TFCf.AppendToTFC(buff);
                        int size = TFCf.getFileSize();
                        if (size != -1)
                        {
                            TOCeditor tc = new TOCeditor();
                            if (!tc.UpdateFile(T2D.Tsource + ".tfc", (uint)size))
                            {
                                MessageBox.Show("Didn't found Entry");
                            }
                            tc.Close();
                        }
                    }
                    else
                    {
                        System.Windows.Forms.DialogResult m = MessageBox.Show("The size doesn't match, import anyway?", "ME3 Explorer", MessageBoxButtons.YesNo);
                        if (m == DialogResult.Yes)
                        {
                            TFCFile TFCf = new TFCFile(T2D.Tsource);
                            byte[]  buff;
                            if (TFCf.isTFCCompressed())
                            {
                                buff = ZBlock.Compress(t.memory);
                            }
                            else
                            {
                                buff = t.memory;
                            }
                            byte[] buff2 = BitConverter.GetBytes(TFCf.getFileSize());
                            for (int i = 0; i < 4; i++)
                            {
                                memory[TextureTFCs[tfc].HeaderOffset + 20 + i] = buff2[i];
                            }
                            buff2 = BitConverter.GetBytes(buff.Length);
                            for (int i = 0; i < 4; i++)
                            {
                                memory[TextureTFCs[tfc].HeaderOffset + 16 + i] = buff2[i];
                            }
                            if (tfc == 0)
                            {
                                buff2 = BitConverter.GetBytes(t.ImageSizeX);
                                for (int i = 0; i < 4; i++)
                                {
                                    memory[T2D.offSizeX + i] = buff2[i];
                                }
                                buff2 = BitConverter.GetBytes(t.ImageSizeY);
                                for (int i = 0; i < 4; i++)
                                {
                                    memory[T2D.offSizeY + i] = buff2[i];
                                }
                            }
                            else
                            {
                                buff2 = BitConverter.GetBytes(t.ImageSizeX * 2);
                                for (int i = 0; i < 4; i++)
                                {
                                    memory[TextureTFCs[tfc].HeaderOffset + i] = buff2[i];
                                }
                                buff2 = BitConverter.GetBytes(t.ImageSizeY * 2);
                                for (int i = 0; i < 4; i++)
                                {
                                    memory[TextureTFCs[tfc].HeaderOffset + 4 + i] = buff2[i];
                                }
                                TFCf.AppendToTFC(buff);
                            }
                            TFCf.AppendToTFC(buff);
                            int size = TFCf.getFileSize();
                            if (size != -1)
                            {
                                TOCeditor tc = new TOCeditor();
                                if (!tc.UpdateFile(T2D.Tsource + ".tfc", (uint)size))
                                {
                                    MessageBox.Show("Didn't found Entry");
                                }
                                tc.Close();
                            }
                        }
                    }
                }
                if (format > 1 && format < 5)
                {
                    if (t.ImageSizeX == TextureTFCs[tfc].sizeX &&
                        t.ImageSizeY == TextureTFCs[tfc].sizeY)
                    {
                        if (t.ImageBits != 32)
                        {
                            MessageBox.Show("Please use 32 bit Targa image!");
                        }
                        else
                        {
                            byte[] buf = new byte[0];
                            switch (format)
                            {
                            case 2:
                                buf = new byte[t.memsize / 2];
                                for (int i = 0; i < t.memsize / 4; i++)
                                {
                                    buf[i * 2]     = t.memory[i * 4];
                                    buf[i * 2 + 1] = t.memory[i * 4 + 2];
                                }
                                break;

                            case 3:
                                buf = t.memory;
                                break;

                            case 4:
                                buf = new byte[t.memsize / 4];
                                for (int i = 0; i < t.memsize / 4; i++)
                                {
                                    buf[i] = t.memory[i * 4];
                                }
                                break;
                            }
                            TFCFile TFCf = new TFCFile(T2D.Tsource);
                            byte[]  buff;
                            if (TFCf.isTFCCompressed())
                            {
                                buff = ZBlock.Compress(t.memory);
                            }
                            else
                            {
                                buff = t.memory;
                            }
                            byte[] buff2 = BitConverter.GetBytes(TFCf.getFileSize());
                            for (int i = 0; i < 4; i++)
                            {
                                memory[TextureTFCs[tfc].HeaderOffset + 20 + i] = buff2[i];
                            }
                            buff2 = BitConverter.GetBytes(buff.Length);
                            for (int i = 0; i < 4; i++)
                            {
                                memory[TextureTFCs[tfc].HeaderOffset + 12 + i] = buff2[i];
                            }
                            TFCf.AppendToTFC(buff);
                            int size = TFCf.getFileSize();
                            if (size != -1)
                            {
                                TOCeditor tc = new TOCeditor();
                                if (!tc.UpdateFile(T2D.Tsource + ".tfc", (uint)size))
                                {
                                    MessageBox.Show("Didn't found Entry");
                                }
                                tc.Close();
                            }
                            MessageBox.Show("Done.");
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void CloneEntry(int entry)
        {
            byte[]       buffdata;
            DialogResult r = MessageBox.Show("Clone with new data?", "", MessageBoxButtons.YesNo);

            if (r == DialogResult.No)
            {
                buffdata = EntryToBuff(entry);
            }
            else
            {
                OpenFileDialog d = new OpenFileDialog();
                d.Filter = "bin files (*.bin)|*.bin|all files|*.*";
                if (d.ShowDialog() == DialogResult.OK)
                {
                    FileStream f    = new FileStream(d.FileName, FileMode.Open, FileAccess.Read);
                    int        size = (int)f.Length;
                    buffdata = new byte[size];
                    int count;
                    int sum = 0;
                    while ((count = f.Read(buffdata, sum, size - sum)) > 0)
                    {
                        sum += count;
                    }
                }
                else
                {
                    return;
                }
            }
            int          sizebefore = memsize;
            MemoryStream m          = new MemoryStream();

            m.Write(memory, 0, (int)Header.offinfo + 8);
            byte[] buff = BitConverter.GetBytes(Header.ExportCount + 1);
            m.Write(buff, 0, 4);
            buff = BitConverter.GetBytes(sizebefore);
            m.Write(buff, 0, 4);
            m.Write(memory, (int)Header.offinfo + 16, sizebefore - ((int)Header.offinfo + 16));
            for (int i = 0; i < Export.Length; i++)
            {
                uint len = Export[i].end - Export[i].start;
                m.Write(memory, (int)Export[i].start, (int)len);
            }
            int  pos  = (int)m.Length;
            uint len2 = Export[entry].end - Export[entry].start;

            m.Write(memory, (int)Export[entry].start, 32);
            buff = BitConverter.GetBytes(buffdata.Length);
            m.Write(buff, 0, 4);
            buff = BitConverter.GetBytes(pos + (int)len2);
            m.Write(buff, 0, 4);
            m.Write(memory, (int)Export[entry].start + 40, (int)len2 - 40);
            m.Write(buffdata, 0, buffdata.Length);
            Header.ExportCount++;
            Header.ExportOffset = (uint)sizebefore;
            exports ex = new exports();

            ex.Class      = Export[entry].Class;
            ex.DataOffset = (uint)pos + len2;
            ex.DataSize   = (uint)buffdata.Length;
            ex.end        = (uint)pos + len2;
            ex.Link       = Export[entry].Link;
            ex.Name       = Export[entry].Name;
            ex.off        = Export[entry].off;
            ex.start      = (uint)pos;
            exports[] t = new exports[Header.ExportCount];
            for (int i = 0; i < Header.ExportCount - 1; i++)
            {
                t[i] = Export[i];
            }
            t[Header.ExportCount - 1] = ex;
            Export = t;
            memory = m.ToArray();
            TOCeditor tc = new TOCeditor();

            if (!tc.UpdateFile(loadedFilename, (uint)memsize))
            {
                MessageBox.Show("Didn't found Entry");
            }
        }