Ejemplo n.º 1
0
        private void RenderVehicle()
        {
            YftFile yft = GameFileCache.GetYft(SelectedModelHash);

            if (yft != null)
            {
                if (yft.Loaded)
                {
                    if (yft.Fragment != null)
                    {
                        var f = yft.Fragment;

                        var txdhash = SelectedVehicleHash;// yft.RpfFileEntry?.ShortNameHash ?? 0;

                        var namelower = yft.RpfFileEntry?.GetShortNameLower();
                        if (namelower?.EndsWith("_hi") ?? false)
                        {
                            txdhash = JenkHash.GenHash(namelower.Substring(0, namelower.Length - 3));
                        }

                        Archetype arch = null;// TryGetArchetype(hash);

                        Renderer.RenderFragment(arch, null, f, txdhash);

                        //seldrwbl = f.Drawable;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void SelectTexture(TextureBase texbase, bool mipchange)
        {
            Texture tex    = texbase as Texture;
            YtdFile ytd    = null;
            string  errstr = string.Empty;

            if ((tex == null) && (texbase != null))
            {
                tex = TryGetTexture(texbase, out ytd, ref errstr);
            }
            if (tex != null)
            {
                currentTex = tex;
                int mip = 0;
                if (mipchange)
                {
                    mip = SelTextureMipTrackBar.Value;
                    if (mip >= tex.Levels)
                    {
                        mip = tex.Levels - 1;
                    }
                }
                else
                {
                    SelTextureMipTrackBar.Maximum = tex.Levels - 1;
                }
                DisplayTexture(tex, mip);


                //try get owner drawable to get the name for the dictionary textbox...
                object owner = null;
                if (Selection.Drawable != null)
                {
                    owner = Selection.Drawable.Owner;
                }
                YdrFile ydr = owner as YdrFile;
                YddFile ydd = owner as YddFile;
                YftFile yft = owner as YftFile;

                SelTextureNameTextBox.Text       = tex.Name;
                SelTextureDictionaryTextBox.Text = (ytd != null) ? ytd.Name : (ydr != null) ? ydr.Name : (ydd != null) ? ydd.Name : (yft != null) ? yft.Name : string.Empty;
                SaveTextureButton.Enabled        = true;
            }
            else
            {
                SelDrawableTexturePictureBox.Image = null;
                SelTextureNameTextBox.Text         = errstr;
                SelTextureDictionaryTextBox.Text   = string.Empty;
                SelTextureMipTrackBar.Value        = 0;
                SelTextureMipTrackBar.Maximum      = 0;
                SelTextureDimensionsLabel.Text     = "-";
                SaveTextureButton.Enabled          = false;
                currentTex = null;
            }
        }
Ejemplo n.º 3
0
 public bool ContainsYft(YftFile yft)
 {
     foreach (var f in YftFiles)
     {
         if (f == yft)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        public void LoadModel(YftFile yft)
        {
            if (yft == null)
            {
                return;
            }

            FileName = yft.Name;
            Yft      = yft;

            UpdateModelsUI(yft.Fragment.Drawable);
        }
Ejemplo n.º 5
0
        public YftFile AddYftFile(string filename)
        {
            YftFile yft = new YftFile();

            yft.RpfFileEntry      = new RpfResourceFileEntry();
            yft.RpfFileEntry.Name = Path.GetFileName(filename);
            yft.FilePath          = GetFullFilePath(filename);
            yft.Name = yft.RpfFileEntry.Name;
            if (!AddYftFile(yft))
            {
                return(null);
            }
            return(yft);
        }
Ejemplo n.º 6
0
        public void RemoveYftFile(YftFile yft)
        {
            if (yft == null)
            {
                return;
            }
            var relpath = GetRelativePath(yft.FilePath);

            if (string.IsNullOrEmpty(relpath))
            {
                relpath = yft.Name;
            }
            YftFiles.Remove(yft);
            YftFilenames.Remove(relpath);
            HasChanged = true;
        }
Ejemplo n.º 7
0
        public bool AddYftFile(YftFile yft)
        {
            string relpath = GetRelativePath(yft.FilePath);

            if (string.IsNullOrEmpty(relpath))
            {
                relpath = yft.Name;
            }
            if (YftFilenames.Contains(relpath))
            {
                return(false);
            }
            YftFilenames.Add(relpath);
            YftFiles.Add(yft);
            return(true);
        }
Ejemplo n.º 8
0
        public void LoadModel(YftFile yft, bool movecamera = true)
        {
            if (yft == null)
            {
                return;
            }

            //FileName = yft.Name;
            //Yft = yft;

            var dr = yft.Fragment?.Drawable;

            if (movecamera && (dr != null))
            {
                MoveCameraToView(dr.BoundingCenter, dr.BoundingSphereRadius);
            }

            UpdateModelsUI(yft.Fragment.Drawable);
        }
Ejemplo n.º 9
0
        public void LoadVehicle()
        {
            var      modelname   = VehicleModelComboBox.Text;
            var      modelnamel  = modelname.ToLowerInvariant();
            MetaHash modelhash   = JenkHash.GenHash(modelnamel);
            MetaHash modelhashhi = JenkHash.GenHash(modelnamel + "_hi");
            bool     hidet       = VehicleHighDetailCheckBox.Checked;
            var      yfthash     = hidet ? modelhashhi : modelhash;

            VehicleInitData vid = null;

            if (GameFileCache.VehiclesInitDict.TryGetValue(modelhash, out vid))
            {
                bool vehiclechange = SelectedVehicleHash != modelhash;
                SelectedModelHash   = yfthash;
                SelectedVehicleHash = modelhash;
                SelectedVehicleInit = vid;
                SelectedVehicleYft  = GameFileCache.GetYft(SelectedModelHash);
                while ((SelectedVehicleYft != null) && (!SelectedVehicleYft.Loaded))
                {
                    Thread.Sleep(20);//kinda hacky
                    SelectedVehicleYft = GameFileCache.GetYft(SelectedModelHash);
                }
                LoadModel(SelectedVehicleYft, vehiclechange);
                VehicleMakeLabel.Text = GlobalText.TryGetString(JenkHash.GenHash(vid.vehicleMakeName.ToLower()));
                VehicleNameLabel.Text = GlobalText.TryGetString(JenkHash.GenHash(vid.gameName.ToLower()));
            }
            else
            {
                SelectedModelHash     = 0;
                SelectedVehicleHash   = 0;
                SelectedVehicleInit   = null;
                SelectedVehicleYft    = null;
                VehicleMakeLabel.Text = "-";
                VehicleNameLabel.Text = "-";
            }
        }
Ejemplo n.º 10
0
        private void SelectTexture(TextureBase texbase, bool mipchange)
        {
            Texture tex    = texbase as Texture;
            YtdFile ytd    = null;
            string  errstr = string.Empty;

            if ((tex == null) && (texbase != null))
            {
                //need to load from txd.
                var  arch    = Selection.Archetype;
                uint texhash = texbase.NameHash;
                uint txdHash = (arch != null) ? arch.TextureDict.Hash : 0;
                tex = TryGetTextureFromYtd(texhash, txdHash, out ytd);
                if (tex == null)
                { //search parent ytds...
                    uint ptxdhash = WorldForm.GameFileCache.TryGetParentYtdHash(txdHash);
                    while ((ptxdhash != 0) && (tex == null))
                    {
                        tex = TryGetTextureFromYtd(texhash, ptxdhash, out ytd);
                        if (tex == null)
                        {
                            ptxdhash = WorldForm.GameFileCache.TryGetParentYtdHash(ptxdhash);
                        }
                        else
                        {
                        }
                    }
                    if (tex == null)
                    {
                        ytd = WorldForm.GameFileCache.TryGetTextureDictForTexture(texhash);
                        if (ytd != null)
                        {
                            int tries = 0;
                            while (!ytd.Loaded && (tries < 500)) //wait upto ~5 sec
                            {
                                System.Threading.Thread.Sleep(10);
                                tries++;
                            }
                            if (ytd.Loaded)
                            {
                                tex = ytd.TextureDict.Lookup(texhash);
                            }
                        }
                        if (tex == null)
                        {
                            ytd    = null;
                            errstr = "<Couldn't find texture!>";
                        }
                    }
                }
            }
            if (tex != null)
            {
                int mip = 0;
                if (mipchange)
                {
                    mip = SelTextureMipTrackBar.Value;
                    if (mip >= tex.Levels)
                    {
                        mip = tex.Levels - 1;
                    }
                }
                else
                {
                    SelTextureMipTrackBar.Maximum = tex.Levels - 1;
                }
                DisplayTexture(tex, mip);


                //try get owner drawable to get the name for the dictionary textbox...
                object owner = null;
                if (Selection.Drawable != null)
                {
                    owner = Selection.Drawable.Owner;
                }
                YdrFile ydr = owner as YdrFile;
                YddFile ydd = owner as YddFile;
                YftFile yft = owner as YftFile;

                SelTextureNameTextBox.Text       = tex.Name;
                SelTextureDictionaryTextBox.Text = (ytd != null) ? ytd.Name : (ydr != null) ? ydr.Name : (ydd != null) ? ydd.Name : (yft != null) ? yft.Name : string.Empty;
            }
            else
            {
                SelDrawableTexturePictureBox.Image = null;
                SelTextureNameTextBox.Text         = errstr;
                SelTextureDictionaryTextBox.Text   = string.Empty;
                SelTextureMipTrackBar.Value        = 0;
                SelTextureMipTrackBar.Maximum      = 0;
                SelTextureDimensionsLabel.Text     = "-";
            }
        }
Ejemplo n.º 11
0
        private void SelectFile(RpfEntry entry, int offset, int length)
        {
            SelectedEntry  = entry;
            SelectedOffset = offset;
            SelectedLength = length;

            RpfFileEntry rfe = entry as RpfFileEntry;

            if (rfe == null)
            {
                RpfDirectoryEntry rde = entry as RpfDirectoryEntry;
                if (rde != null)
                {
                    FileInfoLabel.Text = rde.Path + " (Directory)";
                    DataTextBox.Text   = "[Please select a data file]";
                }
                else
                {
                    FileInfoLabel.Text = "[Nothing selected]";
                    DataTextBox.Text   = "[Please select a data file]";
                }
                ShowTextures(null);
                return;
            }


            Cursor = Cursors.WaitCursor;

            string typestr = "Resource";

            if (rfe is RpfBinaryFileEntry)
            {
                typestr = "Binary";
            }

            byte[] data = rfe.File.ExtractFile(rfe);

            int datalen = (data != null) ? data.Length : 0;

            FileInfoLabel.Text = rfe.Path + " (" + typestr + " file)  -  " + TextUtil.GetBytesReadable(datalen);


            if (ShowLargeFileContentsCheckBox.Checked || (datalen < 524287)) //512K
            {
                DisplayFileContentsText(rfe, data, length, offset);
            }
            else
            {
                DataTextBox.Text = "[Filesize >512KB. Select the Show large files option to view its contents]";
            }



            bool istexdict = false;


            if (rfe.NameLower.EndsWith(".ymap"))
            {
                YmapFile ymap = new YmapFile(rfe);
                ymap.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ymap;
            }
            else if (rfe.NameLower.EndsWith(".ytyp"))
            {
                YtypFile ytyp = new YtypFile();
                ytyp.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ytyp;
            }
            else if (rfe.NameLower.EndsWith(".ymf"))
            {
                YmfFile ymf = new YmfFile();
                ymf.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ymf;
            }
            else if (rfe.NameLower.EndsWith(".ymt"))
            {
                YmtFile ymt = new YmtFile();
                ymt.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ymt;
            }
            else if (rfe.NameLower.EndsWith(".ybn"))
            {
                YbnFile ybn = new YbnFile();
                ybn.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ybn;
            }
            else if (rfe.NameLower.EndsWith(".fxc"))
            {
                FxcFile fxc = new FxcFile();
                fxc.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = fxc;
            }
            else if (rfe.NameLower.EndsWith(".yft"))
            {
                YftFile yft = new YftFile();
                yft.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = yft;

                if ((yft.Fragment != null) && (yft.Fragment.Drawable != null) && (yft.Fragment.Drawable.ShaderGroup != null) && (yft.Fragment.Drawable.ShaderGroup.TextureDictionary != null))
                {
                    ShowTextures(yft.Fragment.Drawable.ShaderGroup.TextureDictionary);
                    istexdict = true;
                }
            }
            else if (rfe.NameLower.EndsWith(".ydr"))
            {
                YdrFile ydr = new YdrFile();
                ydr.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ydr;

                if ((ydr.Drawable != null) && (ydr.Drawable.ShaderGroup != null) && (ydr.Drawable.ShaderGroup.TextureDictionary != null))
                {
                    ShowTextures(ydr.Drawable.ShaderGroup.TextureDictionary);
                    istexdict = true;
                }
            }
            else if (rfe.NameLower.EndsWith(".ydd"))
            {
                YddFile ydd = new YddFile();
                ydd.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ydd;
                //todo: show embedded texdicts in ydd's? is this possible?
            }
            else if (rfe.NameLower.EndsWith(".ytd"))
            {
                YtdFile ytd = new YtdFile();
                ytd.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ytd;
                ShowTextures(ytd.TextureDict);
                istexdict = true;
            }
            else if (rfe.NameLower.EndsWith(".ycd"))
            {
                YcdFile ycd = new YcdFile();
                ycd.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ycd;
            }
            else if (rfe.NameLower.EndsWith(".ynd"))
            {
                YndFile ynd = new YndFile();
                ynd.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ynd;
            }
            else if (rfe.NameLower.EndsWith(".ynv"))
            {
                YnvFile ynv = new YnvFile();
                ynv.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = ynv;
            }
            else if (rfe.NameLower.EndsWith("_cache_y.dat"))
            {
                CacheDatFile cdf = new CacheDatFile();
                cdf.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = cdf;
            }
            else if (rfe.NameLower.EndsWith(".rel"))
            {
                RelFile rel = new RelFile(rfe);
                rel.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = rel;
            }
            else if (rfe.NameLower.EndsWith(".gxt2"))
            {
                Gxt2File gxt2 = new Gxt2File();
                gxt2.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = gxt2;
            }
            else if (rfe.NameLower.EndsWith(".pso"))
            {
                JPsoFile pso = new JPsoFile();
                pso.Load(data, rfe);
                DetailsPropertyGrid.SelectedObject = pso;
            }
            else
            {
                DetailsPropertyGrid.SelectedObject = null;
            }


            if (!istexdict)
            {
                ShowTextures(null);
            }


            Cursor = Cursors.Default;
        }
Ejemplo n.º 12
0
        private void ExtractButton_Click(object sender, EventArgs e)
        {
            if (InProgress)
            {
                return;
            }

            if (!KeysLoaded)
            {
                MessageBox.Show("Please scan a GTA 5 exe dump for keys first, or include key files in this app's folder!");
                return;
            }
            if (!Directory.Exists(FolderTextBox.Text))
            {
                MessageBox.Show("Folder doesn't exist: " + FolderTextBox.Text);
                return;
            }
            if (!Directory.Exists(OutputFolderTextBox.Text))
            {
                MessageBox.Show("Folder doesn't exist: " + OutputFolderTextBox.Text);
                return;
            }
            //if (Directory.GetFiles(OutputFolderTextBox.Text, "*.ysc", SearchOption.AllDirectories).Length > 0)
            //{
            //    if (MessageBox.Show("Output folder already contains .ysc files. Are you sure you want to continue?", "Output folder already contains .ysc files", MessageBoxButtons.OKCancel) != DialogResult.OK)
            //    {
            //        return;
            //    }
            //}

            InProgress     = true;
            AbortOperation = false;

            string searchpath = FolderTextBox.Text;
            string outputpath = OutputFolderTextBox.Text;
            string replpath   = searchpath + "\\";
            bool   bytd       = YtdChecBox.Checked;
            bool   bydr       = YdrCheckBox.Checked;
            bool   bydd       = YddCheckBox.Checked;
            bool   byft       = YftCheckBox.Checked;

            Task.Run(() =>
            {
                UpdateExtractStatus("Keys loaded.");



                RpfManager rpfman = new RpfManager();
                rpfman.Init(searchpath, UpdateExtractStatus, UpdateExtractStatus);


                UpdateExtractStatus("Beginning texture extraction...");
                StringBuilder errsb = new StringBuilder();
                foreach (RpfFile rpf in rpfman.AllRpfs)
                {
                    foreach (RpfEntry entry in rpf.AllEntries)
                    {
                        if (AbortOperation)
                        {
                            UpdateExtractStatus("Operation aborted");
                            InProgress = false;
                            return;
                        }
                        try
                        {
                            if (bytd && entry.NameLower.EndsWith(".ytd"))
                            {
                                UpdateExtractStatus(entry.Path);
                                YtdFile ytd = rpfman.GetFile <YtdFile>(entry);
                                if (ytd == null)
                                {
                                    throw new Exception("Couldn't load file.");
                                }
                                if (ytd.TextureDict == null)
                                {
                                    throw new Exception("Couldn't load texture dictionary.");
                                }
                                if (ytd.TextureDict.Textures == null)
                                {
                                    throw new Exception("Couldn't load texture dictionary texture array.");
                                }
                                if (ytd.TextureDict.Textures.data_items == null)
                                {
                                    throw new Exception("Texture dictionary had no entries...");
                                }
                                foreach (var tex in ytd.TextureDict.Textures.data_items)
                                {
                                    SaveTexture(tex, entry, outputpath);
                                }
                            }
                            else if (bydr && entry.NameLower.EndsWith(".ydr"))
                            {
                                UpdateExtractStatus(entry.Path);
                                YdrFile ydr = rpfman.GetFile <YdrFile>(entry);
                                if (ydr == null)
                                {
                                    throw new Exception("Couldn't load file.");
                                }
                                if (ydr.Drawable == null)
                                {
                                    throw new Exception("Couldn't load drawable.");
                                }
                                if (ydr.Drawable.ShaderGroup != null)
                                {
                                    var ydrtd = ydr.Drawable.ShaderGroup.TextureDictionary;
                                    if ((ydrtd != null) && (ydrtd.Textures != null) && (ydrtd.Textures.data_items != null))
                                    {
                                        foreach (var tex in ydrtd.Textures.data_items)
                                        {
                                            SaveTexture(tex, entry, outputpath);
                                        }
                                    }
                                }
                            }
                            else if (bydd && entry.NameLower.EndsWith(".ydd"))
                            {
                                UpdateExtractStatus(entry.Path);
                                YddFile ydd = rpfman.GetFile <YddFile>(entry);
                                if (ydd == null)
                                {
                                    throw new Exception("Couldn't load file.");
                                }
                                //if (ydd.DrawableDict == null) throw new Exception("Couldn't load drawable dictionary.");
                                //if (ydd.DrawableDict.Drawables == null) throw new Exception("Drawable dictionary had no items...");
                                //if (ydd.DrawableDict.Drawables.data_items == null) throw new Exception("Drawable dictionary had no items...");
                                if ((ydd.Dict == null) || (ydd.Dict.Count == 0))
                                {
                                    throw new Exception("Drawable dictionary had no items...");
                                }
                                foreach (var drawable in ydd.Dict.Values)
                                {
                                    if (drawable.ShaderGroup != null)
                                    {
                                        var ydrtd = drawable.ShaderGroup.TextureDictionary;
                                        if ((ydrtd != null) && (ydrtd.Textures != null) && (ydrtd.Textures.data_items != null))
                                        {
                                            foreach (var tex in ydrtd.Textures.data_items)
                                            {
                                                SaveTexture(tex, entry, outputpath);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (byft && entry.NameLower.EndsWith(".yft"))
                            {
                                UpdateExtractStatus(entry.Path);
                                YftFile yft = rpfman.GetFile <YftFile>(entry);
                                if (yft == null)
                                {
                                    throw new Exception("Couldn't load file.");
                                }
                                if (yft.Fragment == null)
                                {
                                    throw new Exception("Couldn't load fragment.");
                                }
                                if (yft.Fragment.Drawable != null)
                                {
                                    if (yft.Fragment.Drawable.ShaderGroup != null)
                                    {
                                        var ydrtd = yft.Fragment.Drawable.ShaderGroup.TextureDictionary;
                                        if ((ydrtd != null) && (ydrtd.Textures != null) && (ydrtd.Textures.data_items != null))
                                        {
                                            foreach (var tex in ydrtd.Textures.data_items)
                                            {
                                                SaveTexture(tex, entry, outputpath);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string err = entry.Name + ": " + ex.Message;
                            UpdateExtractStatus(err);
                            errsb.AppendLine(err);
                        }
                    }
                }

                File.WriteAllText(outputpath + "\\_errors.txt", errsb.ToString());

                UpdateExtractStatus("Complete.");
                InProgress = false;
            });
        }
Ejemplo n.º 13
0
        private void startButton_Click(object sender, EventArgs e)
        {
            var watch = Stopwatch.StartNew();

            TimeLabel.Text       = "Time Elapsed: 0ms";
            cancelButton.Enabled = true;
            var errorFiles = new List <string>()
            {
            };

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                for (var j = 0; j < CurrentList.Items.Count; j++)
                {
                    if (CancelLoop)
                    {
                        FilesAddedLabel.Text = "Cancelled";
                        CancelLoop           = false;
                        return;
                    }
                    string filename      = CurrentList.Items[j].ToString();
                    FilesAddedLabel.Text = "Processing " + Path.GetFileName(filename) + " (" + (j + 1) + " of " + CurrentList.Items.Count + ")";

                    if (filename.EndsWith(".ybn"))
                    {
                        YbnFile ybn = new YbnFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }
                        try
                        {
                            ybn.Load(oldData);
                            byte[] newData = ybn.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                            var elapsedMss = watch.ElapsedMilliseconds;
                            TimeLabel.Text = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMss).ToString();
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                    else if (filename.EndsWith(".ydr"))
                    {
                        YdrFile ydr = new YdrFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }
                        try
                        {
                            RpfFile.LoadResourceFile(ydr, oldData, 165);
                            byte[] newData = ydr.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                            var elapsedMss = watch.ElapsedMilliseconds;
                            TimeLabel.Text = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMss).ToString();
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                    else if (filename.EndsWith(".ydd"))
                    {
                        YddFile ydd = new YddFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }
                        try
                        {
                            RpfFile.LoadResourceFile(ydd, oldData, 165);
                            byte[] newData = ydd.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                            var elapsedMss = watch.ElapsedMilliseconds;
                            TimeLabel.Text = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMss).ToString();
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                    else if (filename.EndsWith(".yft"))
                    {
                        YftFile yft = new YftFile();
                        RpfDirectoryEntry RPFFilesDirectory;
                        byte[] oldData;
                        if (filename.Contains(".rpf"))
                        {
                            string fileDirectory = StringFunctions.TopMostRPF(filename);
                            if (File.Exists(filename))
                            {
                                RPFFilesDirectory = null;
                                oldData           = File.ReadAllBytes(filename);
                            }
                            else
                            {
                                RpfFile TopRPF = new RpfFile(fileDirectory, fileDirectory);
                                TopRPF.ScanStructure(null, null);
                                (RPFFilesDirectory, oldData) = RPFFunctions.GetFileData(TopRPF, Path.GetFileName(filename));
                            }
                        }
                        else
                        {
                            RPFFilesDirectory = null;
                            oldData           = File.ReadAllBytes(filename);
                        }
                        try
                        {
                            RpfFile.LoadResourceFile(yft, oldData, 162);
                            byte[] newData = yft.Save();
                            if (filename.Contains(".rpf"))
                            {
                                if (File.Exists(filename))
                                {
                                    RPFFilesDirectory = null;
                                    oldData           = File.ReadAllBytes(filename);
                                }
                                else
                                {
                                    RPFFunctions.AddFileBackToRPF(RPFFilesDirectory, filename, newData);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(filename, newData);
                            }
                            var elapsedMss = watch.ElapsedMilliseconds;
                            TimeLabel.Text = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMss).ToString();
                        }
                        catch (Exception)
                        {
                            errorFiles.Add(filename);
                        }
                    }
                }
                if (errorFiles.Count != 0)
                {
                    string message = "The following file(s) were corrupted and were not edited.\n\n";
                    foreach (string item in errorFiles)
                    {
                        message = message + item + "\n";
                    }
                    MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                FilesAddedLabel.Text = "Complete";
                var elapsedMs        = watch.ElapsedMilliseconds;
                TimeLabel.Text       = "Time Elapsed: " + StringFunctions.ConvertMillisecondsToSeconds(elapsedMs).ToString();
                cancelButton.Enabled = false;
            }).Start();
        }