Example #1
0
        private void ExtractButton_Click(object sender, EventArgs e)
        {
            if (MainListView.SelectedIndices.Count != 0 && MainListView.SelectedIndices[0] >= 0)
            {
                ProgBarUpdater.ChangeProgressBar(0, 1);

                // KFreon: Select mip to replace
                List<string> names = new List<string>();
                int index = GetSelectedTexInd();
                TreeTexInfo tex = Tree.GetTex(index);
                Textures.ITexture2D tex2D = tex.Textures[0];
                for (int i = 0; i < tex2D.imgList.Count; i++)
                {
                    bool pccstored = tex2D.imgList[i].CompareStorage("pccSto");

                    // KFreon: Ignore null entries
                    int offset = (int)((pccstored) ? tex2D.imgList[i].offset + tex2D.pccOffset : tex2D.imgList[i].offset);
                    if (offset != -1)
                        names.Add("Image: " + tex2D.imgList[i].imgSize + " stored inside " + (pccstored ? "PCC file" : "Archive file") + " at offset " + offset.ToString());
                }

                string selectedImage = "";
                using (Helpers.SelectionForm sf = new Helpers.SelectionForm(names, "Select ONE image to extract.", "Extract Image Selector", false))
                {
                    sf.ShowDialog();
                    if (sf.SelectedInds.Count == 0)
                        return;
                    else if (sf.SelectedInds.Count == 1)
                        selectedImage = sf.SelectedItems[0];
                    else
                    {
                        MessageBox.Show("You must select ONLY ONE image to extract.");
                        return;
                    }
                }
                string imgsize = selectedImage.Split(' ')[1];
                string savepath = "";
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.Title = "Select destination for file. Hash will be appended to filename.";
                    sfd.FileName = tex.TexName + Textures.Methods.FormatTexmodHashAsString(tex.Hash) + ".dds";
                    sfd.Filter = "DDS Files|*.dds";
                    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        savepath = sfd.FileName;
                    else
                        return;
                }

                // KFreon: Make sure hash is there
                if (!savepath.Contains(Textures.Methods.FormatTexmodHashAsString(tex.Hash)))
                    savepath = Path.Combine(Path.GetDirectoryName(savepath), Path.GetFileNameWithoutExtension(savepath) + "_" + Textures.Methods.FormatTexmodHashAsString(tex.Hash) + Path.GetExtension(savepath));

                // KFreon: Save file
                File.WriteAllBytes(savepath, tex2D.extractImage(imgsize, false));

                StatusUpdater.UpdateText("Image extracted and saved!");
                ProgBarUpdater.ChangeProgressBar(1, 1);
            }
        }
Example #2
0
 private void updateTOCsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (WhichGame == 3)
     {
         List<string> dlcs = Directory.EnumerateFiles(DLCPath, "*.sfar", SearchOption.AllDirectories) as List<string>;
         using (Helpers.SelectionForm sf = new Helpers.SelectionForm(dlcs, "Select DLC's to update.", "DLC TOC Update Selector", true))
         {
             sf.ShowDialog();
             if (sf.SelectedInds.Count == 0)
                 return;
             else
             {
                 dlcs.Clear();
                 foreach (string item in sf.SelectedItems)
                     dlcs.Add(item);
                 Task.Run(() => UpdateTOCs(pathBIOGame, WhichGame, DLCPath, dlcs));
             }
         }
     }
     else
         Task.Run(() => UpdateTOCs(pathBIOGame, WhichGame, DLCPath));
 }
Example #3
0
        private void ReplaceButton_Click(object sender, EventArgs e)
        {
            if (MainListView.SelectedIndices.Count != 0 && MainListView.SelectedIndices[0] >= 0)
            {
                // KFreon: Select mip to replace
                List<string> names = new List<string>();
                int index = GetSelectedTexInd();
                TreeTexInfo tex = Tree.GetTex(index);
                Textures.ITexture2D tex2D = tex.Textures[0];
                for (int i = 0; i < tex2D.imgList.Count; i++)
                {
                    bool pccstored = tex2D.imgList[i].CompareStorage("pccSto");
                    names.Add("Image: " + tex2D.imgList[i].imgSize + " stored inside " + (pccstored ? "PCC file" : "Archive file") + " at offset " + ((pccstored) ? (tex2D.imgList[i].offset + tex2D.pccOffset).ToString() : tex2D.imgList[i].offset.ToString()));
                }

                string selectedImage = "";
                using (Helpers.SelectionForm sf = new Helpers.SelectionForm(names, "Select ONE image to replace.", "Replace Image Selector", false))
                {
                    sf.ShowDialog();
                    if (sf.SelectedInds.Count == 0)
                        return;
                    else if (sf.SelectedInds.Count == 1)
                        selectedImage = sf.SelectedItems[0];
                    else
                    {
                        MessageBox.Show("You must select ONLY ONE image to replace.");
                        return;
                    }
                }
                string imgsize = selectedImage.Split(' ')[1];
                string replacingfile = "";
                using (OpenFileDialog ofd = new OpenFileDialog())
                {
                    ofd.Title = "Select Image to replace with";
                    ofd.Filter = "Image File|*.dds";

                    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        replacingfile = ofd.FileName;
                    else
                        return;
                }

                byte[] imgData = File.ReadAllBytes(replacingfile);
                ImageMipMapHandler mip = new ImageMipMapHandler("", imgData);
                string[] sizes = imgsize.Split('x');
                ImageFile im = mip.imageList.First(img => img.imgSize.width.ToString() == sizes[0] && img.imgSize.height.ToString() == sizes[1]);

                DebugOutput.PrintLn("Replacing image in " + tex.TexName + " at " + imgsize + " with " + replacingfile);

                tex2D.replaceImage(imgsize, im, pathBIOGame);
                UpdateModifiedTex(tex2D, tex, index);
                DebugOutput.PrintLn("Image replaced.");

                StatusUpdater.UpdateText("Image replaced!");
                MainProgressBar.Value = MainProgressBar.Maximum;

                DisplayTextureProperties(tex2D, tex2D.GenerateImageInfo());

                RegenerateThumbnail(tex, index, false);

                if (ModMakerMode)
                {
                    AddModJob(tex2D, replacingfile);
                    StatusUpdater.UpdateText("Replacement complete and job added to modmaker!");
                }

                if (TPFMode)
                {
                    AddTPFToolsJob(replacingfile, tex.Hash);
                    StatusUpdater.UpdateText("Replacement Complete and job added to TPFTools!");
                }
            }
        }