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; } }
public bool ContainsYdd(YddFile ydd) { foreach (var f in YddFiles) { if (f == ydd) { return(true); } } return(false); }
public void LoadModels(YddFile ydd) { if (ydd == null) { return; } FileName = ydd.Name; Ydd = ydd; UpdateModelsUI(ydd.Dict); DetailsPropertyGrid.SelectedObject = ydd; }
public YddFile AddYddFile(string filename) { YddFile ydd = new YddFile(); ydd.RpfFileEntry = new RpfResourceFileEntry(); ydd.RpfFileEntry.Name = Path.GetFileName(filename); ydd.FilePath = GetFullFilePath(filename); ydd.Name = ydd.RpfFileEntry.Name; if (!AddYddFile(ydd)) { return(null); } return(ydd); }
public void RemoveYddFile(YddFile ydd) { if (ydd == null) { return; } var relpath = GetRelativePath(ydd.FilePath); if (string.IsNullOrEmpty(relpath)) { relpath = ydd.Name; } YddFiles.Remove(ydd); YddFilenames.Remove(relpath); HasChanged = true; }
public bool AddYddFile(YddFile ydd) { string relpath = GetRelativePath(ydd.FilePath); if (string.IsNullOrEmpty(relpath)) { relpath = ydd.Name; } if (YddFilenames.Contains(relpath)) { return(false); } YddFilenames.Add(relpath); YddFiles.Add(ydd); return(true); }
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 = "-"; } }
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; }
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; }); }
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(); }
static void HandleCompileDrawableShadersOptions(string[] args) { CommandLine.Parse <CompileDrawableShadersOptions>(args, (opts, gOpts) => { EnsurePath(); EnsureKeys(); var shaderNames = new Dictionary <uint, string>(); var shaderParameterSetNames = new Dictionary <uint, string>(); var fxcShaders = new Dictionary <uint, FxcFile>(); ArchiveUtilities.ForEachBinaryFile(Settings.Default.GTAFolder, (fullFileName, binaryFile, encryption) => { if (fullFileName.EndsWith(".fxc")) { string nameLower = binaryFile.Name.ToLowerInvariant().Replace(".fxc", ""); var hash = Jenkins.Hash(nameLower); if (!shaderNames.ContainsKey(hash)) { shaderNames.Add(hash, nameLower); } byte[] data = Utils.GetBinaryFileData((IArchiveBinaryFile)binaryFile, encryption); var fxc = new FxcFile(); fxc.Load(data, nameLower); if (!fxcShaders.ContainsKey(hash)) { fxcShaders.Add(hash, fxc); } } else if (fullFileName.EndsWith(".sps")) { string nameLower = binaryFile.Name.ToLowerInvariant(); var hash = Jenkins.Hash(nameLower); if (!shaderParameterSetNames.ContainsKey(hash)) { shaderParameterSetNames.Add(hash, nameLower); } } }); ArchiveUtilities.ForEachResourceFile(Settings.Default.GTAFolder, (fullFileName, resourceFile, encryption) => { if (fullFileName.EndsWith(".ydr")) { var ms = new MemoryStream(); resourceFile.Export(ms); var ydr = new YdrFile(); ydr.Load(ms); Console.WriteLine(fullFileName.Replace(Settings.Default.GTAFolder, "")); CompileDrawableShaders_ProcessDrawable(ydr.Drawable, shaderNames, fxcShaders); Console.WriteLine(""); } else if (fullFileName.EndsWith(".ydd")) { var ms = new MemoryStream(); resourceFile.Export(ms); var ydd = new YddFile(); ydd.Load(ms); Console.WriteLine(fullFileName.Replace(Settings.Default.GTAFolder, "")); var drawables = ydd.DrawableDictionary.Drawables; for (int d = 0; d < drawables.Count; d++) { var drawable = drawables[d]; Console.WriteLine(" " + drawable.Name.Value); CompileDrawableShaders_ProcessDrawable(drawable, shaderNames, fxcShaders); } Console.WriteLine(""); } }); }); }