Exemplo n.º 1
0
        private void saveChangesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (pcc == null || currentPCC == "")
            {
                return;
            }
            pcc.altSaveToFile(currentPCC, true);
            FileStream fs   = new FileStream(currentPCC, FileMode.Open, FileAccess.Read);
            uint       size = (uint)fs.Length;
            string     name = Path.GetFileName(currentPCC);

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

            tc.MdiParent = this.ParentForm;
            string tocpath = ME3Directory.tocFile;

            if (File.Exists(tocpath))
            {
                if (!tc.UpdateFile(name, size, tocpath))
                {
                    MessageBox.Show("Didn't found Entry");
                }
            }
            else
            {
                if (!tc.UpdateFile(name, size))
                {
                    MessageBox.Show("Didn't found Entry");
                }
            }
            tc.Close();
            MessageBox.Show("File " + Path.GetFileName(currentPCC) + " saved.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 2
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string         path        = string.Empty;
            SaveFileDialog FileDialog1 = new SaveFileDialog();

            FileDialog1.Filter          = "*.cnd|*.cnd";
            BitConverter.IsLittleEndian = true;
            if (FileDialog1.ShowDialog() == DialogResult.OK)
            {
                path = FileDialog1.FileName;
                FileStream   fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
                MemoryStream m          = new MemoryStream();
                m.Write(BitConverter.GetBytes((uint)0x434F4E44), 0, 4);
                m.Write(BitConverter.GetBytes((int)1), 0, 4);
                m.Write(BitConverter.GetBytes((Int16)UnknownInt16), 0, 2);
                m.Write(BitConverter.GetBytes((Int16)Entry.Count), 0, 2);
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    m.Write(BitConverter.GetBytes(en.id), 0, 4);
                    m.Write(BitConverter.GetBytes(en.off), 0, 4);
                }
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    en.off   = (int)m.Position;
                    Entry[i] = en;
                    m.Write(en.data, 0, en.size);
                }
                int pos = 16;
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    m.Seek(pos, SeekOrigin.Begin);
                    m.Write(BitConverter.GetBytes((uint)en.off), 0, 4);
                    pos += 8;
                }
                fileStream.Write(m.ToArray(), 0, (int)m.Length);
                fileStream.Close();

                TOCeditor tc = new TOCeditor();
                tc.MdiParent = this.ParentForm;
                tc.Show();
                string fname = Path.GetFileName(path);
                if (!tc.UpdateFile(fname, (uint)memsize))
                {
                    MessageBox.Show("Didn't found entry!");
                }
                tc.Close();
                LoadFile(path);
            }
        }
Exemplo n.º 3
0
        private void saveChangesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int size = Level.pcc.memsize;

            for (int i = 0; i < Level.UStatColl.Count; i++)
            {
                if (Level.UStatColl[i].CHANGED)
                {
                    Level.pcc.appendStream(Level.UStatColl[i].memory);
                    Level.pcc.RedirectEntry(Level.UStatColl[i].LP.sourceentry, size, Level.UStatColl[i].memsize);
                }
            }
            if (Level.pcc.memsize != size)
            {
                TOCeditor tc = new TOCeditor();
                if (!tc.UpdateFile(Level.pcc.loadedFilename, (uint)size))
                {
                    MessageBox.Show("Didn't found Entry");
                }
            }
        }
Exemplo n.º 4
0
 private void saveChangesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     int size = Level.pcc.memsize;
     for (int i = 0; i < Level.UStatColl.Count; i++)
         if (Level.UStatColl[i].CHANGED)
         {
             Level.pcc.appendStream(Level.UStatColl[i].memory);
             Level.pcc.RedirectEntry(Level.UStatColl[i].LP.sourceentry, size, Level.UStatColl[i].memsize);
         }
     if (Level.pcc.memsize != size)
     {
         TOCeditor tc = new TOCeditor();
         if (!tc.UpdateFile(Level.pcc.loadedFilename, (uint)size))
             MessageBox.Show("Didn't found Entry");
     }
 }
Exemplo n.º 5
0
        private void addBiggestImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string currentDir = pathCooked;
                string texGroupToAdd;
                OpenFileDialog openImage = openFileDialog;
                openImage.Title = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                if (openImage.ShowDialog() != DialogResult.OK)
                    return;

                // add function
                int numTexBegin = tex2D.imgList.Count;
                tex2D.OneImageToRuleThemAll(openImage.FileName, currentDir, out texGroupToAdd);
                int numTexEnd = tex2D.imgList.Count;

                //--------- update the pcc with the new replaced infos ----------
                // select export index
                ListViewItem item = listView1.SelectedItems[0];
                int index = Convert.ToInt32(item.Name);
                // copy export data
                PCCObject.ExportEntry expEntry = pcc.Exports[index];
                // change data with new tex data
                expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                // updating pcc file
                //pcc.ChangeExportEntry(index, expEntry);
                //pcc.UpdateAllOffsets();

                // changing tfc size
                // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                {
                    TOCeditor tc = new TOCeditor();
                    uint arcSize;
                    string arcPath = currentDir + tex2D.arcName + ".tfc";
                    using (FileStream archiveStream = File.OpenRead(arcPath))
                        arcSize = (uint)archiveStream.Length;
                    string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                    if (File.Exists(tocpath))
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                        {
                            openImage = openFileDialog;
                            openImage.Title = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    else
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                        {
                            openImage = openFileDialog;
                            openImage.Title = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                }

                //---------------- end of replace -------------------------------
                if(texGroupToAdd != null)
                    MessageBox.Show("Texture replaced correctly. Make sure to add " + texGroupToAdd + " inside coalesced.bin", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                else
                    MessageBox.Show("Texture replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            /*catch (Exception exc)
            {
                MessageBox.Show("An error occurred while replacing texture: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }*/
        }
Exemplo n.º 6
0
        private void upscaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string currentDir = pathCooked;
                OpenFileDialog openImage = openFileDialog;
                openImage.Title = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                if (openImage.ShowDialog() != DialogResult.OK)
                    return;

                // add function
                tex2D.addBiggerImage(openImage.FileName, currentDir);

                //--------- update the pcc with the new replaced infos ----------
                // select export index
                ListViewItem item = listView1.SelectedItems[0];
                int index = Convert.ToInt32(item.Name);
                // copy export data
                PCCObject.ExportEntry expEntry = pcc.Exports[index];
                // change data with new tex data
                expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                // updating pcc file
                //pcc.ChangeExportEntry(index, expEntry);
                //pcc.UpdateAllOffsets();

                // changing tfc size
                // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                {
                    TOCeditor tc = new TOCeditor();
                    uint arcSize;
                    string arcPath = currentDir + tex2D.arcName + ".tfc";
                    using (FileStream archiveStream = File.OpenRead(arcPath))
                        arcSize = (uint)archiveStream.Length;
                    string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                    if (File.Exists(tocpath))
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                        {
                            openImage = openFileDialog;
                            openImage.Title = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    else
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                        {
                            openImage = openFileDialog;
                            openImage.Title = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                }
                //---------------- end of replace -------------------------------

                /*
                // code test to prove that tex2d works, just decomment it and comment precedent code
                byte[] pccFile = PCCHandler.Decompress(pcc.pccFileName);
                using (FileStream debugStr = File.OpenWrite(pcc.pccFileName))
                {
                    debugStr.Write(pccFile, 0, pccFile.Length);
                    debugStr.Seek(expEntry.DataOffset, SeekOrigin.Begin);
                    byte[] buffer = tex2D.ToArray(expEntry.DataOffset);
                    debugStr.Write(buffer, 0, buffer.Length);
                }*/
                MessageBox.Show("Image was added correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exc)
            {
                MessageBox.Show("An error occurred while adding image: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 7
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentDir = ME3Directory.cookedPath;

            // setting TexSelection Form to export images
            TexSelection texSelection = new TexSelection(tex2D, true);
            texSelection.FormTitle = "Select images to replace";
            texSelection.btnSelectionText = "Replace";
            if (tex2D.imgList.Count > 1)
            {
                texSelection.ShowDialog();
                texSelection.Dispose();
            }
            else
                texSelection.bOk = true;

            if (texSelection.bOk)
            {
                try
                {
                    // main replace loop
                    foreach (Object entry in texSelection.imageListBox.CheckedItems)
                    {
                        string imgSize = entry.ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."

                        OpenFileDialog openImage = openFileDialog;
                        openImage.Title = "Select the image to replace with size " + imgSize;
                        openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                        if (openImage.ShowDialog() != DialogResult.OK)
                            return;

                        // replace function
                        tex2D.replaceImage(imgSize, openImage.FileName, currentDir);
                    }

                    //--------- update the pcc with the new replaced infos ----------
                    // select export index
                    ListViewItem item = listView1.SelectedItems[0];
                    int index = Convert.ToInt32(item.Name);
                    // copy export data
                    PCCObject.ExportEntry expEntry = pcc.Exports[index];
                    // change data with new tex data
                    expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                    // updating pcc file
                    //pcc.ChangeExportEntry(index, expEntry);
                    //pcc.UpdateAllOffsets();

                    // changing tfc size
                    // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                    if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                    {
                        TOCeditor tc = new TOCeditor();
                        uint arcSize;
                        string arcPath = currentDir + tex2D.arcName + ".tfc";
                        using (FileStream archiveStream = File.OpenRead(arcPath))
                            arcSize = (uint)archiveStream.Length;
                        string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                        if (File.Exists(tocpath))
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                        else
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                    }

                    //---------------- end of replace -------------------------------
                    MessageBox.Show("All images are replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error occurred while replacing images: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 8
0
 private void saveChangesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (pcc == null || currentPCC == "")
         return;
     pcc.altSaveToFile(currentPCC, true);
     FileStream fs = new FileStream(currentPCC, FileMode.Open, FileAccess.Read);
     uint size = (uint)fs.Length;
     string name = Path.GetFileName(currentPCC);
     fs.Close();
     TOCeditor tc = new TOCeditor();
     tc.MdiParent = this.ParentForm;
     string tocpath = ME3Directory.tocFile;
     if (File.Exists(tocpath))
     {
         if (!tc.UpdateFile(name, size, tocpath))
             MessageBox.Show("Didn't found Entry");
     }
     else
     {
         if (!tc.UpdateFile(name, size))
             MessageBox.Show("Didn't found Entry");
     }
     tc.Close();
     MessageBox.Show("File " + Path.GetFileName(currentPCC) + " saved.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Exemplo n.º 9
0
        private void addBiggestImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string         currentDir = pathCooked;
                string         texGroupToAdd;
                OpenFileDialog openImage = openFileDialog;
                openImage.Title  = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                if (openImage.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // add function
                int numTexBegin = tex2D.imgList.Count;
                tex2D.OneImageToRuleThemAll(openImage.FileName, currentDir, out texGroupToAdd);
                int numTexEnd = tex2D.imgList.Count;

                //--------- update the pcc with the new replaced infos ----------
                // select export index
                ListViewItem item  = listView1.SelectedItems[0];
                int          index = Convert.ToInt32(item.Name);
                // copy export data
                PCCObject.ExportEntry expEntry = pcc.Exports[index];
                // change data with new tex data
                expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                // updating pcc file
                //pcc.ChangeExportEntry(index, expEntry);
                //pcc.UpdateAllOffsets();

                // changing tfc size
                // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                {
                    TOCeditor tc = new TOCeditor();
                    uint      arcSize;
                    string    arcPath = currentDir + tex2D.arcName + ".tfc";
                    using (FileStream archiveStream = File.OpenRead(arcPath))
                        arcSize = (uint)archiveStream.Length;
                    string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                    if (File.Exists(tocpath))
                    {
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                        {
                            openImage        = openFileDialog;
                            openImage.Title  = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    }
                    else
                    {
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                        {
                            openImage        = openFileDialog;
                            openImage.Title  = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    }
                }

                //---------------- end of replace -------------------------------
                if (texGroupToAdd != null)
                {
                    MessageBox.Show("Texture replaced correctly. Make sure to add " + texGroupToAdd + " inside coalesced.bin", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Texture replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            /*catch (Exception exc)
             * {
             *  MessageBox.Show("An error occurred while replacing texture: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/
        }
Exemplo n.º 10
0
        private void upscaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string         currentDir = pathCooked;
                OpenFileDialog openImage  = openFileDialog;
                openImage.Title  = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                if (openImage.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // add function
                tex2D.addBiggerImage(openImage.FileName, currentDir);

                //--------- update the pcc with the new replaced infos ----------
                // select export index
                ListViewItem item  = listView1.SelectedItems[0];
                int          index = Convert.ToInt32(item.Name);
                // copy export data
                PCCObject.ExportEntry expEntry = pcc.Exports[index];
                // change data with new tex data
                expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                // updating pcc file
                //pcc.ChangeExportEntry(index, expEntry);
                //pcc.UpdateAllOffsets();

                // changing tfc size
                // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                {
                    TOCeditor tc = new TOCeditor();
                    uint      arcSize;
                    string    arcPath = currentDir + tex2D.arcName + ".tfc";
                    using (FileStream archiveStream = File.OpenRead(arcPath))
                        arcSize = (uint)archiveStream.Length;
                    string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                    if (File.Exists(tocpath))
                    {
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                        {
                            openImage        = openFileDialog;
                            openImage.Title  = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    }
                    else
                    {
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                        {
                            openImage        = openFileDialog;
                            openImage.Title  = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    }
                }
                //---------------- end of replace -------------------------------

                /*
                 * // code test to prove that tex2d works, just decomment it and comment precedent code
                 * byte[] pccFile = PCCHandler.Decompress(pcc.pccFileName);
                 * using (FileStream debugStr = File.OpenWrite(pcc.pccFileName))
                 * {
                 *  debugStr.Write(pccFile, 0, pccFile.Length);
                 *  debugStr.Seek(expEntry.DataOffset, SeekOrigin.Begin);
                 *  byte[] buffer = tex2D.ToArray(expEntry.DataOffset);
                 *  debugStr.Write(buffer, 0, buffer.Length);
                 * }*/
                MessageBox.Show("Image was added correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exc)
            {
                MessageBox.Show("An error occurred while adding image: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 11
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentDir = ME3Directory.cookedPath;

            // setting TexSelection Form to export images
            TexSelection texSelection = new TexSelection(tex2D, true);

            texSelection.FormTitle        = "Select images to replace";
            texSelection.btnSelectionText = "Replace";
            if (tex2D.imgList.Count > 1)
            {
                texSelection.ShowDialog();
                texSelection.Dispose();
            }
            else
            {
                texSelection.bOk = true;
            }

            if (texSelection.bOk)
            {
                try
                {
                    // main replace loop
                    foreach (Object entry in texSelection.imageListBox.CheckedItems)
                    {
                        string imgSize = entry.ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."

                        OpenFileDialog openImage = openFileDialog;
                        openImage.Title  = "Select the image to replace with size " + imgSize;
                        openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                        if (openImage.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }

                        // replace function
                        tex2D.replaceImage(imgSize, openImage.FileName, currentDir);
                    }

                    //--------- update the pcc with the new replaced infos ----------
                    // select export index
                    ListViewItem item  = listView1.SelectedItems[0];
                    int          index = Convert.ToInt32(item.Name);
                    // copy export data
                    PCCObject.ExportEntry expEntry = pcc.Exports[index];
                    // change data with new tex data
                    expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                    // updating pcc file
                    //pcc.ChangeExportEntry(index, expEntry);
                    //pcc.UpdateAllOffsets();

                    // changing tfc size
                    // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                    if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                    {
                        TOCeditor tc = new TOCeditor();
                        uint      arcSize;
                        string    arcPath = currentDir + tex2D.arcName + ".tfc";
                        using (FileStream archiveStream = File.OpenRead(arcPath))
                            arcSize = (uint)archiveStream.Length;
                        string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                        if (File.Exists(tocpath))
                        {
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title  = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                        }
                        else
                        {
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title  = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                        }
                    }

                    //---------------- end of replace -------------------------------
                    MessageBox.Show("All images are replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error occurred while replacing images: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 12
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path = string.Empty;
            SaveFileDialog FileDialog1 = new SaveFileDialog();
            FileDialog1.Filter = "*.cnd|*.cnd";
            BitConverter.IsLittleEndian = true;
            if (FileDialog1.ShowDialog() == DialogResult.OK)
            {
                path = FileDialog1.FileName;
                FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
                MemoryStream m = new MemoryStream();
                m.Write(BitConverter.GetBytes((uint)0x434F4E44), 0, 4);
                m.Write(BitConverter.GetBytes((int)1), 0, 4);
                m.Write(BitConverter.GetBytes((Int16)UnknownInt16), 0, 2);
                m.Write(BitConverter.GetBytes((Int16)Entry.Count), 0, 2);
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    m.Write(BitConverter.GetBytes(en.id), 0, 4);
                    m.Write(BitConverter.GetBytes(en.off), 0, 4);
                }
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    en.off = (int)m.Position;
                    Entry[i] = en;
                    m.Write(en.data, 0, en.size);
                }
                int pos = 16;
                for (int i = 0; i < Entry.Count; i++)
                {
                    Entries en = Entry[i];
                    m.Seek(pos, SeekOrigin.Begin);
                    m.Write(BitConverter.GetBytes((uint)en.off), 0, 4);
                    pos += 8;
                }
                fileStream.Write(m.ToArray(), 0, (int)m.Length);
                fileStream.Close();

                TOCeditor tc = new TOCeditor();
                tc.MdiParent = this.ParentForm;
                tc.Show();
                string fname = Path.GetFileName(path);
                if (!tc.UpdateFile(fname, (uint)memsize))
                    MessageBox.Show("Didn't found entry!");
                tc.Close();
                LoadFile(path);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Will update PCConsoleTOC.bin for a particular filename s
        /// </summary>
        /// <param name="s">The filename of the file to be updated</param>
        private bool tocUpdater(string s)
        {
            FileInfo finfo = new FileInfo(s);
            if (!finfo.Exists)
                throw new FileNotFoundException("File: " + s + " not found");
            if (String.IsNullOrEmpty(tocpath))
                tocpath = Path.Combine(pathBIOGame, "PCConsoleTOC.bin");
            TOCeditor tc = new TOCeditor();
            if (!File.Exists(tocpath))
            {
                OpenFileDialog tocopen = new OpenFileDialog();
                tocopen.Title = "Select the PCConsoleTOC.bin file to use";
                tocopen.Filter = "TOC.bin|PCConsoleTOC.bin";
                if (tocopen.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    MessageBox.Show("Since you have elected not to select your TOC.bin file, you'll get harrassed every time the program wants to update it and the game will crash unless you run the TOCbinUpdater tool", "I hope you're happy", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
                tocpath = tocopen.FileName;
            }

            // KFreon: If normal TOC update fails, try with WV's
            if (!tc.UpdateFile(Path.GetFileName(s), (uint)finfo.Length, tocpath))
                return false;
            else
                return true;
        }