public void LoadGxt2(Gxt2File gxt) { fileName = gxt?.Name; if (string.IsNullOrEmpty(fileName)) { fileName = gxt?.FileEntry?.Name; } UpdateFormTitle(); StringBuilder sb = new StringBuilder(); if ((gxt != null) && (gxt.TextEntries != null)) { foreach (var entry in gxt.TextEntries) { sb.Append("0x"); sb.Append(entry.Hash.ToString("X").PadLeft(8, '0')); sb.Append(" = "); sb.Append(entry.Text); sb.AppendLine(); } } MainTextBox.Text = sb.ToString(); }
public void LoadGxt2(string filename, string filepath, Gxt2File gxt) { fileType = TextFileType.GXT2; FileName = filename; FilePath = filepath; TextValue = gxt?.ToText() ?? ""; rpfFileEntry = gxt?.FileEntry; modified = false; }
static void HandleCompileGxt2Options(string[] args) { CommandLine.Parse <CompileGxt2Optionns>(args, (opts, gOpts) => { Init(args); if (opts.OutputDirectory == null) { Console.WriteLine("Please provide output directory with -o --output"); return; } var entries = new Dictionary <uint, string>(); ArchiveUtilities.ForEachBinaryFile(Settings.Default.GTAFolder, (string fullFileName, IArchiveBinaryFile file, RageArchiveEncryption7 encryption) => { if (fullFileName.EndsWith(".gxt2") && fullFileName.ToLowerInvariant().Contains(opts.Lang.ToLowerInvariant())) { Console.WriteLine(fullFileName); var gxt2 = new Gxt2File(); byte[] data = Utils.GetBinaryFileData(file, encryption); gxt2.Load(data); for (int i = 0; i < gxt2.TextEntries.Count; i++) { entries[gxt2.TextEntries[i].Hash] = gxt2.TextEntries[i].Text; } } }); var sb = new StringBuilder(); foreach (var entry in entries) { sb.AppendLine(entry.Key + " = " + entry.Value); } File.WriteAllText(opts.OutputDirectory + "\\" + opts.Lang + ".gxt2.txt", sb.ToString()); }); }
private void OpenDocument() { if (OpenFileDialog.ShowDialog() != DialogResult.OK) { return; } if (!CloseDocument()) { return; } var fn = OpenFileDialog.FileName; if (!File.Exists(fn)) { return; //couldn't find file? } var fnl = fn.ToLowerInvariant(); if (fnl.EndsWith(".gxt2")) { var gxt = new Gxt2File(); gxt.Load(File.ReadAllBytes(fn), null); fileType = TextFileType.GXT2; TextValue = gxt.ToText(); } else if (fnl.EndsWith(".nametable")) { fileType = TextFileType.Nametable; TextValue = File.ReadAllText(fn).Replace('\0', '\n'); } else { fileType = TextFileType.Text; TextValue = File.ReadAllText(fn); } modified = false; FilePath = fn; FileName = new FileInfo(fn).Name; }
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 bool SaveToRPF(string txt) { if (!(exploreForm?.EditMode ?? false)) { return(false); } if (rpfFileEntry?.Parent == null) { return(false); } byte[] data = null; if (fileType == TextFileType.Text) { data = Encoding.UTF8.GetBytes(txt); } else if (fileType == TextFileType.GXT2) { var gxt = Gxt2File.FromText(txt); data = gxt.Save(); } else if (fileType == TextFileType.Nametable) { if (!txt.EndsWith("\n")) { txt = txt + "\n"; } txt = txt.Replace("\r", ""); var lines = txt.Split('\n'); foreach (var line in lines) { var str = line.Trim(); if (string.IsNullOrEmpty(str)) { continue; } var strl = str.ToLowerInvariant(); JenkIndex.Ensure(strl); } data = Encoding.UTF8.GetBytes(txt.Replace('\n', '\0')); } if (data == null) { MessageBox.Show("Unspecified error - data was null!", "Cannot save file"); return(false); } if (!rpfFileEntry.Path.ToLowerInvariant().StartsWith("mods")) { if (MessageBox.Show("This file is NOT located in the mods folder - Are you SURE you want to save this file?\r\nWARNING: This could cause permanent damage to your game!!!", "WARNING: Are you sure about this?", MessageBoxButtons.YesNo) != DialogResult.Yes) { return(false);//that was a close one } } try { if (!(exploreForm?.EnsureRpfValidEncryption(rpfFileEntry.File) ?? false)) { return(false); } var newentry = RpfFile.CreateFile(rpfFileEntry.Parent, rpfFileEntry.Name, data); if (newentry != rpfFileEntry) { } rpfFileEntry = newentry; exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer... modified = false; StatusLabel.Text = fileType.ToString() + " file saved successfully at " + DateTime.Now.ToString(); return(true); //victory! } catch (Exception ex) { MessageBox.Show("Error saving file to RPF! The RPF archive may be corrupted...\r\n" + ex.ToString(), "Really Bad Error"); } return(false); }
private void SaveDocument(bool saveAs = false) { if (saveAs == false) { if (SaveToRPF(textValue)) { return; } //if saving to RPF failed for whatever reason, fallback to saving the file in the filesystem. saveAs = true; } if (string.IsNullOrEmpty(FileName)) { saveAs = true; } if (string.IsNullOrEmpty(FilePath)) { saveAs = true; } else if ((FilePath.ToLowerInvariant().StartsWith(GTAFolder.CurrentGTAFolder.ToLowerInvariant()))) { saveAs = true; } if (!File.Exists(FilePath)) { saveAs = true; } var fn = FilePath; if (saveAs) { if (!string.IsNullOrEmpty(fn)) { var dir = new FileInfo(fn).DirectoryName; if (!Directory.Exists(dir)) { dir = ""; } SaveFileDialog.InitialDirectory = dir; } SaveFileDialog.FileName = FileName; if (SaveFileDialog.ShowDialog() != DialogResult.OK) { return; } fn = SaveFileDialog.FileName; } if (fileType == TextFileType.Text) { File.WriteAllText(fn, textValue); } else if (fileType == TextFileType.GXT2) { var gxt = Gxt2File.FromText(textValue); var data = gxt.Save(); File.WriteAllBytes(fn, data); } else if (fileType == TextFileType.Nametable) { File.WriteAllText(fn, textValue.Replace("\r", "").Replace('\n', '\0')); } modified = false; FilePath = fn; FileName = new FileInfo(fn).Name; }