Formerly TexNodeHash. Provides an object to store TPFTools texture objects.
Inheritance: abstractTexInfo, IDisposable
Exemplo n.º 1
0
        /// <summary>
        /// Clones current TPF texture object.
        /// </summary>
        /// <returns>New TPF texture object.</returns>
        public TPFTexInfo Clone()
        {
            TPFTexInfo retval = new TPFTexInfo(FileName, TPFInd, FilePath, zippy, GameVersion);

            retval.Files           = new List <string>(Files);
            retval.OriginalFiles   = new List <string>(OriginalFiles);
            retval.ExpIDs          = new List <int>(ExpIDs);
            retval.OriginalExpIDs  = new List <int>(OriginalExpIDs);
            retval.Hash            = Hash;
            retval.OriginalHash    = OriginalHash;
            retval.found           = found;
            retval.Format          = Format;
            retval.ExpectedFormat  = ExpectedFormat;
            retval.NumMips         = NumMips;
            retval.AutofixSuccess  = AutofixSuccess;
            retval.ThumbInd        = ThumbInd;
            retval.Thumbnail       = new MemoryStream(Thumbnail.ToArray());
            retval.FileDuplicates  = new List <TPFTexInfo>(FileDuplicates);
            retval.TreeDuplicates  = new List <int>(TreeDuplicates);
            retval.Height          = Height;
            retval.Width           = Width;
            retval.TexName         = TexName;
            retval.GameVersion     = GameVersion;
            retval.ValidDimensions = ValidDimensions;

            return(retval);
        }
Exemplo n.º 2
0
        private int GetTexFromNode(myTreeNode node, out TPFTexInfo tex)
        {
            tex = null;

            // Heff: Cancellation check
            if (cts.IsCancellationRequested)
                return -1;

            if (node.TexInd >= LoadedTexes.Count)
                return 0;

            if (node.TexInds.Count != 0)
                tex = LoadedTexes[node.TexInds[0]].FileDuplicates[node.TexInds[1]];
            else
                tex = LoadedTexes[node.TexInd];
            return node.TexInd;
        }
Exemplo n.º 3
0
        private int GetSelectedTex(out TPFTexInfo tex)
        {
            tex = null;
            // Heff: Cancellation check
            if (cts.IsCancellationRequested)
                return -1;

            myTreeNode node = MainTreeView.SelectedNode as myTreeNode;
            if (node == null)
                return -1;

            return GetTexFromNode(node, out tex);
        }
Exemplo n.º 4
0
        private void Extractor(string ExtractPath, TPFTexInfo tex, Predicate<TPFTexInfo> predicate)
        {
            // Heff: Cancellation check
            if (cts.IsCancellationRequested)
                return;

            // KFreon: Move to backbone if necessary
            if (!MainTreeView.InvokeRequired)
            {
                backbone.AddToBackBone(b =>
                {
                    Extractor(ExtractPath, tex, predicate);
                    return true;
                });
                return;
            }

            DebugOutput.PrintLn("Extracting textures to somewhere like: " + ExtractPath);
            OverallProg.ChangeProgressBar(0, 1);

            // KFreon: Extract single texture
            if (tex != null && tex.Files != null)
            {
                DebugOutput.PrintLn("Extracting single texture: " + tex.TexName);
                tex.Extract(ExtractPath);
            }
            else
            {
                // KFreon: Extract many based on predicate
                List<TPFTexInfo> filtered = new List<TPFTexInfo>(LoadedTexes.Where(texn => predicate(texn)));
                OverallProg.ChangeProgressBar(0, filtered.Count);

                foreach (TPFTexInfo texn in filtered)
                {
                    texn.Extract(ExtractPath);
                    OverallProg.IncrementBar();
                }
            }

            OverallProg.ChangeProgressBar(1, 1);
        }
Exemplo n.º 5
0
        private void LoadTPF(string file)
        {
            EnableSecondProgressBar(true);

            // KFreon: Open TPF and set some properties
            SaltTPF.ZipReader zippy = new SaltTPF.ZipReader(file);
            zippy.Description = "TPF Details\n\nFilename:  \n" + zippy._filename + "\n\nComment:  \n" + zippy.EOFStrct.Comment + "\nNumber of stored files:  " + zippy.Entries.Count;
            zippy.Scanned = false;
            int zippyInd = zippys.Count;
            zippys.Add(zippy);
            int numEntries = zippy.Entries.Count;

            // KFreon: Setup nodes and GUI elements
            this.Invoke(new Action(() =>
            {
                CurrentProg.ChangeProgressBar(0, numEntries);
                CurrentStatusLabel.Text = "Processing file: " + Path.GetFileName(file);
            }));
            DebugOutput.PrintLn("Loading file: " + Path.GetFileName(file));

            // KFreon: Get hash info from TPF
            // KFreon: Get individual hashes without duplicate lines
            // Heff: Fix weird uppercase X
            List<string> parts = GetHashesFromTPF(zippy);
            if (parts == null)
                return;


            // KFreon: Thread TPF loading
            ParallelOptions po = new ParallelOptions();
            po.MaxDegreeOfParallelism = Properties.Settings.Default.NumThreads;
            DebugOutput.PrintLn("Reading TPF using " + po.MaxDegreeOfParallelism + " threads.");
            List<TPFTexInfo> temptexes = new List<TPFTexInfo>();
            for (int i = 0; i < numEntries; i++)
            {
                temptexes.Add(new TPFTexInfo());
            }
            Parallel.For(0, numEntries, po, i =>
            {
                // KFreon: Add TPF entries to TotalTexes list
                TPFTexInfo tmpTex = new TPFTexInfo(zippy.Entries[i].Filename, i, null, zippy, WhichGame);

                // KFreon: Find and set hash
                foreach (string line in parts)
                    if (line.ToLowerInvariant().Contains(tmpTex.FileName.ToLowerInvariant()))
                    {
                        tmpTex.Hash = KFreonLib.Textures.Methods.FormatTexmodHashAsUint(line);
                        tmpTex.OriginalHash = tmpTex.Hash;
                        tmpTex.FileName = line.Split('|')[1].Replace("\r", "");
                        break;
                    }

                // KFreon: If hash gen failed, notify
                if (!tmpTex.isDef && tmpTex.Hash == 0)
                    DebugOutput.PrintLn("Failure to get hash for entry " + i + " in " + file);

                // KFreon: Get details
                if (!tmpTex.isDef)
                    tmpTex.EnumerateDetails();

                temptexes[i] = tmpTex;

                // Heff: cancel background loaders
                if (cts.IsCancellationRequested)
                    return;

                CurrentProg.IncrementBar();
            });

            // KFreon: Load textures into list and treeview
            LoadedTexes.AddRange(temptexes);
            EnableSecondProgressBar(false);
        }
Exemplo n.º 6
0
        private void PreviewObject(TPFTexInfo tex)
        {
            // KFreon: Clear old image
            ClearPreview();

            // Clean cache if required
            if (Previews.Keys.Count > 10)
            {
                var img = Previews.First();
                img.Value.Dispose();
                Previews.Remove(img.Key);
            }

            // KFreon: Gather from cache if available
            if (Previews.ContainsKey(tex.PreviewKey))
            {
                Bitmap img = Previews[tex.PreviewKey];
                try
                {
                    this.Invoke(new Action(() => PreviewBox.Image = img));
                }
                catch (ObjectDisposedException)
                { } // DOn't care - it's when the form is closing. The form can become disposed while the preview is trying to be shown.

                DisappearTextBox(true);
                return;
            }


            // KFreon: Get data
            byte[] data = tex.Extract(null, true);
            if (data == null)
                return;

            // KFreon: Load new one
            if (tex.isDef)
            {
                DisappearTextBox(false);
                try
                {
                    string message = Encoding.UTF8.GetString(data);
                    this.Invoke(new Action(() => texmodPreviewBox.Text = message));
                }
                catch (Exception e)
                {
                    DebugOutput.PrintLn("Unable to get text from data: " + e.Message);
                }
            }
            else
            {
                Bitmap img = null;
                using (MemoryStream ms = new MemoryStream(data))
                    using (ImageEngineImage image = new ImageEngineImage(ms, null, 512, false))
                        img = image.GetGDIBitmap(true, false, 512);

                this.Invoke(new Action(() => PreviewBox.Image = img));
                Previews.Add(tex.PreviewKey, img);
                DisappearTextBox(true);
            }
        }
        private void PreviewObject(TPFTexInfo tex)
        {
            // KFreon: Clear old image
            ClearPreview();

            // KFreon: Get data
            byte[] data = tex.Extract(null, true);
            if (data == null)
                return;

            // KFreon: Load new one
            if (tex.isDef)
            {
                DisappearTextBox(false);
                try
                {
                    string message = Encoding.UTF8.GetString(data);
                    this.Invoke(new Action(() => texmodPreviewBox.Text = message));
                }
                catch (Exception e)
                {
                    DebugOutput.PrintLn("Unable to get text from data: " + e.Message);
                }
            }
            else
            {
                //KFreonLib.Textures.Methods.GetImage(tex.Format, data);
                Bitmap img = null;
                using (ResILImage kfimg = new ResILImage(data))
                    img = new Bitmap(new MemoryStream(kfimg.ToArray(ResIL.Unmanaged.ImageType.Jpg)));
                if (img == null)
                    return;

                try
                {
                    this.Invoke(new Action(() => PreviewBox.Image = KFreonLib.Textures.Creation.GenerateThumbImage(img, 512)));
                }
                catch { }

                DisappearTextBox(true);
                img.Dispose();
            }
        }
Exemplo n.º 8
0
        myTreeNode GetDupNode(TPFTexInfo tex, int forwardDupIndex)
        {
            List<int> indicies = new List<int>(tex.TreeDuplicates.Where(ind => ind > forwardDupIndex));
            if (indicies.Count == 0)
                indicies = tex.TreeDuplicates;
            myTreeNode node = (myTreeNode)MainTreeView.Nodes[indicies[0]];

            return node;
        }
        private bool FixMips(TPFTexInfo info, ResILImage img)
        {
            // KFreon: Build or remove mips depending on requirements. Note case where expected == existing not present as that's what MipsCorrect is.
            if (info.ExpectedMips > info.NumMips)
            {
                if (!img.BuildMipmaps(info.NumMips == 1))
                {
                    DebugOutput.PrintLn(String.Format("Failed to build mipmaps for {0}: {1}", info.TexName, ResILImage.GetResILError()));
                    return false;
                }
            }
            else
            {
                if (!img.RemoveMipmaps(info.NumMips == 1))
                {
                    DebugOutput.PrintLn(String.Format("Failed to remove mipmaps for {0}: {1}", info.TexName, ResILImage.GetResILError()));
                    return false;
                }
            }

            //img.Mips = info.ExpectedMips;
            info.NumMips = info.ExpectedMips;

            return true;
        }
        private void LoadTPF(string file)
        {
            EnableSecondProgressBar(true);

            // KFreon: Open TPF and set some properties
            SaltTPF.ZipReader zippy = new SaltTPF.ZipReader(file);
            zippy.Description = "TPF Details\n\nFilename:  \n" + zippy._filename + "\n\nComment:  \n" + zippy.EOFStrct.Comment + "\nNumber of stored files:  " + zippy.Entries.Count;
            zippy.Scanned = false;
            int zippyInd = zippys.Count;
            zippys.Add(zippy);
            int numEntries = zippy.Entries.Count;

            // KFreon: Setup nodes and GUI elements
            this.Invoke(new Action(() =>
            {
                CurrentProg.ChangeProgressBar(0, numEntries);
                CurrentStatusLabel.Text = "Processing file: " + Path.GetFileName(file);
            }));
            DebugOutput.PrintLn("Loading file: " + Path.GetFileName(file));

            // KFreon: Get hash info from TPF
            string alltext = "";
            try
            {
                byte[] data = zippy.Entries[numEntries - 1].Extract(true);
                char[] chars = new char[data.Length];
                for (int i = 0; i < data.Length; i++)
                    chars[i] = (char)data[i];
                alltext = new string(chars);
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occurred during extraction: " + e.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // KFreon: Get individual hashes without duplicate lines
            List<string> parts = alltext.Replace("\r", "").Split('\n').ToList();
            parts.RemoveAll(s => s == "\0");
            List<string> tempparts = new List<string>();
            foreach (string part in parts)
                if (!tempparts.Contains(part))
                    tempparts.Add(part);
            parts = tempparts;


            // KFreon: Thread TPF loading
            ParallelOptions po = new ParallelOptions();
            po.MaxDegreeOfParallelism = 1;//Properties.Settings.Default.NumThreads;
            DebugOutput.PrintLn("Reading TPF using " + po.MaxDegreeOfParallelism + " threads.");
            List<TPFTexInfo> temptexes = new List<TPFTexInfo>();
            for (int i = 0; i < numEntries; i++)
            {
                temptexes.Add(new TPFTexInfo());
            }

            Parallel.For(0, numEntries, po, i =>
            {
                // KFreon: Add TPF entries to TotalTexes list
                TPFTexInfo tmpTex = new TPFTexInfo(zippy.Entries[i].Filename, i, null, zippy, WhichGame);

                // KFreon: Find and set hash
                foreach (string line in parts)
                    if (line.ToLowerInvariant().Contains(tmpTex.FileName.ToLowerInvariant()))
                    {
                        tmpTex.Hash = KFreonLib.Textures.Methods.FormatTexmodHashAsUint(line);
                        tmpTex.OriginalHash = tmpTex.Hash;
                        tmpTex.FileName = line.Split('|')[1].Replace("\r", "");
                        break;
                    }

                // KFreon: If hash gen failed, notify
                if (!tmpTex.isDef && tmpTex.Hash == 0)
                    DebugOutput.PrintLn("Failure to get hash for entry " + i + " in " + file);

                // KFreon: Get details
                if (!tmpTex.isDef)
                    tmpTex.EnumerateDetails();

                temptexes[i] = tmpTex;
                
                CurrentProg.IncrementBar();
            });

            // KFreon: Load textures into list and treeview
            LoadedTexes.AddRange(temptexes);
            EnableSecondProgressBar(false);
        }
        private void Extractor(string ExtractPath, TPFTexInfo tex, Predicate<TPFTexInfo> predicate)
        {
            DebugOutput.PrintLn("Extracting textures to somewhere like: " + ExtractPath);
            OverallProg.ChangeProgressBar(0, 1);

            // KFreon: Extract single texture
            if (tex != null && tex.Files != null)
            {
                DebugOutput.PrintLn("Extracting single texture: " + tex.TexName);
                tex.Extract(ExtractPath);
            }
            else  
            {
                // KFreon: Extract many based on predicate
                List<TPFTexInfo> filtered = new List<TPFTexInfo>(LoadedTexes.Where(texn => predicate(texn)));
                OverallProg.ChangeProgressBar(0, filtered.Count);

                foreach (TPFTexInfo texn in filtered)
                {
                    var tpfName = texn.zippy._filename.Substring(ExtractPath.Length + 1,
                        texn.zippy._filename.Length - ExtractPath.Length - 5);
                    var dir = System.IO.Directory.CreateDirectory(ExtractPath + "\\" + tpfName);
                    texn.Extract(dir.FullName);
                    OverallProg.IncrementBar();
                }
            }

            OverallProg.ChangeProgressBar(1, 1);
        }
 private int GetParentTex(out TPFTexInfo tex)
 {
     myTreeNode node = MainTreeView.SelectedNode as myTreeNode;
     myTreeNode parent = (node.Parent as myTreeNode);
     tex = LoadedTexes[parent.TexInd];
     return parent.TexInd;
 }
        private int GetSelectedTex(out TPFTexInfo tex)
        {
            tex = null;
            myTreeNode node = MainTreeView.SelectedNode as myTreeNode;
            if (node == null)
                return -1;

            if (node.TexInd >= LoadedTexes.Count)
                return 0;

            if (node.TexInds.Count != 0)
                tex = LoadedTexes[node.TexInds[0]].FileDuplicates[node.TexInds[1]];
            else
                tex = LoadedTexes[node.TexInd];
            return node.TexInd;
        }
Exemplo n.º 14
0
        private int GetParentTex(out TPFTexInfo tex)
        {
            tex = null;
            // Heff: Cancellation check
            if (cts.IsCancellationRequested)
                return -1;

            myTreeNode node = MainTreeView.SelectedNode as myTreeNode;
            myTreeNode parent = (node.Parent as myTreeNode);
            tex = LoadedTexes[parent.TexInd];
            return parent.TexInd;
        }
Exemplo n.º 15
0
        private void DisplayInfo(TPFTexInfo tex)
        {
            try
            {
                PCCsCheckListBox.Items.Clear();
            }
            catch
            {
                // Irrelevent
            }
            string message = "";
            FirstHalfInfoState(true);

            // KFreon: Display top info
            if (tex.isExternal)
                message = "External file\n\nPath: " + tex.FilePath + "\\" + tex.FileName;
            else
                message = tex.zippy.Description;
            GeneralInfoRTB.Text = message;

            // KFreon: Disappear stuff if unnecessary
            SecondHalfInfoState(!AnalyseButton.Enabled && !CancelButton.Visible && !tex.isDef);
            if (tex.isDef)
            {
                FirstHalfInfoState(false);
                return;
            }
            GotoInvalidButton.Visible = !AnalyseButton.Enabled && LoadedTexes.Where(ter => !ter.isDef && !ter.Valid).Count() > 1;
            GotoDupButton.Visible = tex.TreeDuplicates.Count != 0;
            PromoteButton.Visible = tex.ThumbInd == -1;
            InstallSingleButton.Visible = !AnalyseButton.Enabled && !tex.isDef;

            // KFreon: Tree details
            TreeMipsEntry.Text = (tex.ExpectedMips == 0 ? "¯\\_(ツ)_/¯" : tex.ExpectedMips.ToString());
            TreeFormatEntry.Text = (tex.ExpectedFormat == ImageEngineFormat.Unknown) ? "¯\\_(ツ)_/¯" : tex.ExpectedFormat.ToString().Replace("DDS_", "");

            // KFreon: Display main info
            TPFFormatEntry.Text = tex.Format.ToString().Replace("DDS_", "");
            HashTextBox.Text = (tex.Hash == 0) ? "Unknown" : KFreonLib.Textures.Methods.FormatTexmodHashAsString(tex.Hash);
            TPFMipsEntry.Text = tex.NumMips.ToString();
            ImageSizeEntry.Text = tex.Width + "x" + tex.Height;

            // KFreon: Set resethash button visibility
            if (!CancelButton.Visible)
                ResetHashButton.Visible = (tex.isDef) ? false : (tex.Hash != tex.OriginalHash);

            // KFreon: Deal with duplicates
            if (tex.TreeDuplicates.Count != 0)
            {
                DisappearDuplicatesBox(false);
                DuplicatesTextBox.Text = "TREE DUPLICATES:" + Environment.NewLine;
                for (int i = 0; i < tex.TreeDuplicates.Count; i++)
                    DuplicatesTextBox.Text += LoadedTexes[tex.TreeDuplicates[i]].TexName + Environment.NewLine;
            }
            else
                DisappearDuplicatesBox(true);


            // KFreon: Do PCC stuff
            PreventPCC = true;

            // KFreon: Show pccs
            if (tex.TexName != null && !tex.isDef)
            {
                int count = 0;
                foreach (string file in tex.OriginalFiles)
                {
                    string displaystring = tex.DisplayString(file);
                    string filedisp = tex.GetFileFromDisplay(file);
                    PCCsCheckListBox.Items.Add(displaystring);
                    bool isChecked = true;
                    if (!tex.Files.Contains(filedisp))
                        isChecked = false;
                    PCCsCheckListBox.Items[count++].Checked = isChecked;
                }
                /*PCCsCheckListBox.SuspendLayout();
                PCCsCheckListBox.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
                PCCsCheckListBox.ResumeLayout();*/
            }
            PCCsCheckListBox.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            PreventPCC = false;
        }
Exemplo n.º 16
0
        private void Extractor(string ExtractPath, TPFTexInfo tex, Predicate<TPFTexInfo> predicate)
        {
            // Heff: Cancellation check
            if (cts.IsCancellationRequested)
                return;

            // KFreon: Move to backbone if necessary
            if (!MainTreeView.InvokeRequired)
            {
                backbone.AddToBackBone(b =>
                {
                    Extractor(ExtractPath, tex, predicate);
                    return true;
                });
                return;
            }

            DebugOutput.PrintLn("Extracting textures to somewhere like: " + ExtractPath);
            OverallProg.ChangeProgressBar(0, 1);

            // KFreon: Extract single texture
            if (tex != null && tex.Files != null)
            {
                DebugOutput.PrintLn("Extracting single texture: " + tex.TexName);
                tex.Extract(ExtractPath);
            }
            else
            {
                // KFreon: Filter out duplicates so multiples of the same texture under different names don't get extracted
                List<TPFTexInfo> filteredDupsOut = new List<TPFTexInfo>();
                for (int i = 0; i < LoadedTexes.Count; i++)
                {
                    var filt = LoadedTexes[i];
                    if (filt.TreeDuplicates != null && filt.TreeDuplicates.Count > 0)
                    {
                        // KFreon: Any dup that refers to a previous index has already been added as that previous index.
                        if (filt.TreeDuplicates.Any(ind => ind < i))
                            continue;
                    }

                    filteredDupsOut.Add(filt);
                }

                // KFreon: Extract many based on predicate
                List<TPFTexInfo> filtered = new List<TPFTexInfo>(filteredDupsOut.Where(texn => predicate(texn)));
                OverallProg.ChangeProgressBar(0, filtered.Count);

                foreach (TPFTexInfo texn in filtered)
                {
                    texn.Extract(ExtractPath);
                    OverallProg.IncrementBar();
                }
            }

            OverallProg.ChangeProgressBar(1, 1);
        }
Exemplo n.º 17
0
        private void UpdateSelectedTexPCCList(TPFTexInfo tex, int index, bool SelectAll = false)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action(() => UpdateSelectedTexPCCList(tex, index, SelectAll)));
            else
            {
                if (tex == null)
                    return;

                CheckSelectAllPCCsList(SelectAll, false);

                List<string> newfiles = new List<string>();
                List<int> newexpids = new List<int>();
                for (int i = 0; i < PCCsCheckListBox.Items.Count; i++)
                {

                    if (PCCsCheckListBox.Items[i].Checked)
                    {
                        newfiles.Add(tex.OriginalFiles[i]);
                        newexpids.Add(tex.OriginalExpIDs[i]);
                    }
                }
                tex.Files = new List<string>(newfiles);
                tex.ExpIDs = new List<int>(newexpids);
            }
        }
Exemplo n.º 18
0
        private bool AutofixInternal(TPFTexInfo tex)
        {
            bool retval = false;

            TPFTexInfo backup = tex.Clone();

            string path = tex.Autofixedpath(TemporaryPath);
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            byte[] imgData = tex.Extract(Path.GetDirectoryName(path), true);

            using (ImageEngineImage img = new ImageEngineImage(imgData))
            {
                var destFormat = tex.ExpectedFormat;
                img.Resize(UsefulThings.General.RoundToNearestPowerOfTwo(img.Width), false);
                retval = img.Save(path, destFormat, tex.ExpectedMips > 1 ? MipHandling.Default : MipHandling.KeepTopOnly);
            }

            if (!retval)
            {
                tex.AutofixSuccess = false;
                return false;
            }

            tex.FilePath = Path.GetDirectoryName(tex.Autofixedpath(TemporaryPath));

            tex.FileName = Path.GetFileName(path);

            // Heff: Cancellation check
            if (cts.IsCancellationRequested)
                return false;
            tex.EnumerateDetails();

            // Heff: if fix was successfull, but the number of mips are still wrong,
            // force it and let texplorer skip the lowest resolutions
            // Heff: this should no longer happen, but keeping this as it might help in some real odd case.
            if (tex.ExpectedMips > 1 && (tex.NumMips < tex.ExpectedMips || tex.NumMips < TPFTexInfo.CalculateMipCount(tex.Width, tex.Height)))
                tex.NumMips = Math.Max(tex.ExpectedMips, TPFTexInfo.CalculateMipCount(tex.Width, tex.Height));

            if (!tex.Valid)
            {
                tex = backup;
                tex.AutofixSuccess = false;
            }
            else
                tex.AutofixSuccess = true;

            return tex.AutofixSuccess;
        }
Exemplo n.º 19
0
 public void UpdateHashAndReplace(TPFTexInfo tex, int index, string hash)
 {
     if ((tex = UpdateHash(tex, hash)).Files != null)
         LoadedTexes[index] = tex;
 }
Exemplo n.º 20
0
        public int LoadExternal(string file, bool isDef)
        {
            EnableSecondProgressBar(false);
            TPFTexInfo tmpTex = new TPFTexInfo(Path.GetFileName(file), -1, Path.GetDirectoryName(file), null, WhichGame);
            // KFreon: Get hash
            if (!isDef)
            {
                string hash = "";

                // KFreon: Check if hash in filename
                // Heff: fix weird uppercase X
                file = Path.GetFileName(file).Replace("0X", "0x");
                if (file.Contains("0x"))
                    hash = file.Substring(file.IndexOf("0x"), 10);
                else  // KFreon: If not in filename, look in all non TPF .defs
                    foreach (TPFTexInfo tex in LoadedTexes)
                    {
                        if (tex.isDef && tex.isExternal)
                        {
                            using (StreamReader sr = new StreamReader(Path.Combine(tex.FilePath, tex.FileName)))
                                while (!sr.EndOfStream)
                                {
                                    string line = sr.ReadLine();
                                    if (line.Contains(file + '|'))
                                    {
                                        int start = line.IndexOf('|');
                                        hash = line.Substring(start + 1, line.Length - (start + 1));
                                        break;
                                    }
                                }
                            if (hash != "")
                                break;
                        }
                    }


                // KFreon: Convert hash to uint
                if (hash != "")
                    tmpTex.Hash = KFreonLib.Textures.Methods.FormatTexmodHashAsUint(hash);

                tmpTex.OriginalHash = tmpTex.Hash;
            }


            // KFreon: Get details
            if (!tmpTex.isDef)
                tmpTex.EnumerateDetails();

            // KFreon: Add node and its index to current node
            myTreeNode temp = new myTreeNode(Path.GetFileName(file));
            temp.TexInd = LoadedTexes.Count;
            // Heff: cancellation check
            if (!cts.IsCancellationRequested)
            {
                this.Invoke(new Action(() =>
                {
                    MainTreeView.Nodes.Add(temp);
                    OverallProg.IncrementBar();
                }));
            }

            LoadedTexes.Add(tmpTex);

            return temp.TexInd;
        }
Exemplo n.º 21
0
        private TPFTexInfo UpdateHash(TPFTexInfo tex, string hash)
        {
            // KFreon: Check new hash
            uint newhash = 0;
            try
            {
                newhash = KFreonLib.Textures.Methods.FormatTexmodHashAsUint(hash);
            }
            catch (Exception e)
            {
                DebugOutput.PrintLn("Specified hash invalid: " + e.Message);
                MessageBox.Show("Hash specified is invalid. Got enough characters? Remember you need 0x at the start.");
                return null;
            }

            tex.Hash = newhash;
            return tex;
        }
Exemplo n.º 22
0
 /// <summary>
 /// Clones current TPF texture object.
 /// </summary>
 /// <returns>New TPF texture object.</returns>
 public TPFTexInfo Clone()
 {
     TPFTexInfo retval = new TPFTexInfo(FileName, TPFInd, FilePath, zippy, GameVersion);
     retval.Files = new List<string>(Files);
     retval.OriginalFiles = new List<string>(OriginalFiles);
     retval.ExpIDs = new List<int>(ExpIDs);
     retval.OriginalExpIDs = new List<int>(OriginalExpIDs);
     retval.Hash = Hash;
     retval.OriginalHash = OriginalHash;
     retval.found = found;
     retval.Format = Format;
     retval.ExpectedFormat = ExpectedFormat;
     retval.NumMips = NumMips;
     retval.AutofixSuccess = AutofixSuccess;
     retval.ThumbInd = ThumbInd;
     if (retval.Thumbnail != null)
         retval.Thumbnail = new MemoryStream(Thumbnail.ToArray());
     retval.FileDuplicates = new List<TPFTexInfo>(FileDuplicates);
     retval.TreeDuplicates = new List<int>(TreeDuplicates);
     retval.Height = Height;
     retval.Width = Width;
     retval.TexName = TexName;
     retval.GameVersion = GameVersion;
     retval.ValidDimensions = ValidDimensions;
     retval.OrigHeight = OrigHeight;
     retval.OrigWidth = OrigWidth;
     retval.wasAnalysed = wasAnalysed;
     return retval;
 }
Exemplo n.º 23
0
 private TPFTexInfo UpdateHash(TPFTexInfo tex, uint hash)
 {
     tex.Hash = hash;
     return tex;
 }
Exemplo n.º 24
0
        /// <summary>
        /// Updates current texture object from tree.
        /// </summary>
        /// <param name="treeInd">Index of texture in tree.</param>
        /// <param name="treetex">Tree texture object to get info from.</param>
        public void UpdateTex(int treeInd, TreeTexInfo treetex)
        {
            found   = true;
            TreeInd = treeInd;
            TexName = treetex.TexName;

            // KFreon: Reorder files so DLC isn't first

            /*List<string> files = new List<string>(treetex.Files);
             * List<int> ids = new List<int>(treetex.ExpIDs);
             *
             * int count = files.Count;
             * int index = -1;
             *
             * if (files[0].Contains("DLC"))
             *  for (int i = 0; i < count; i++)
             *      if (!files[i].Contains("DLC"))
             *      {
             *          index = i;
             *          break;
             *      }
             *
             * if (index != -1)
             * {
             *  string thing = files[index];
             *  files.RemoveAt(index);
             *  files.Insert(0, thing);
             *
             *  int thing2 = ids[index];
             *  ids.RemoveAt(index);
             *  ids.Insert(0, thing2);
             * }
             *
             * Files.AddRange(files);
             * ExpIDs.AddRange(ids);*/
            Files.AddRange(treetex.Files);
            ExpIDs.AddRange(treetex.ExpIDs);



            List <PCCExpID> things = new List <PCCExpID>();

            for (int i = 0; i < Files.Count; i++)
            {
                things.Add(new PCCExpID(Files[i], ExpIDs[i]));
            }


            // KFreon: Reorder ME1 files
            if (GameVersion == 1)
            {
                things = things.OrderByDescending(t => t.file.Length).ToList();

                Files.Clear();
                ExpIDs.Clear();

                foreach (var item in things)
                {
                    Files.Add(item.file);
                    ExpIDs.Add(item.expid);
                }
            }

            //ExpIDs.AddRange(treetex.ExpIDs);

            OriginalFiles  = new List <string>(Files);
            OriginalExpIDs = new List <int>(ExpIDs);

            ExpectedMips   = treetex.NumMips;
            ExpectedFormat = treetex.Format.Replace("PF_", "");
            if (ExpectedFormat.ToUpperInvariant().Contains("NORMALMAP"))
            {
                ExpectedFormat = "ATI2_3Dc";
            }

            if (ExpectedFormat.ToUpperInvariant().Contains("A8R8G8B8"))
            {
                ExpectedFormat = "ARGB";
            }

            // KFreon: File Dups
            List <TPFTexInfo> dups = new List <TPFTexInfo>(FileDuplicates);

            FileDuplicates.Clear();
            foreach (TPFTexInfo tex in dups)
            {
                TPFTexInfo texn = tex;
                texn.found   = true;
                texn.TreeInd = TreeInd;
                texn.TexName = treetex.TexName;

                texn.Files.AddRange(treetex.Files);
                texn.ExpIDs.AddRange(treetex.ExpIDs);

                texn.ExpectedFormat = treetex.Format;
                texn.ExpectedMips   = treetex.NumMips;

                texn.OriginalExpIDs = new List <int>(ExpIDs);
                texn.OriginalFiles  = new List <string>(Files);

                FileDuplicates.Add(texn);
            }

            ValidDimensions = ValidateDimensions();
        }
Exemplo n.º 25
0
        private int GetSelectedTex(out TPFTexInfo tex)
        {
            tex = null;
            // Heff: Cancellation check
            if (cts.IsCancellationRequested)
                return -1;

            myTreeNode node = MainTreeView.SelectedNode as myTreeNode;
            if (node == null)
                return -1;

            if (node.TexInd >= LoadedTexes.Count)
                return 0;

            if (node.TexInds.Count != 0)
                tex = LoadedTexes[node.TexInds[0]].FileDuplicates[node.TexInds[1]];
            else
                tex = LoadedTexes[node.TexInd];
            return node.TexInd;
        }