public void Load(byte[] data, RpfFileEntry entry) { Name = entry.Name; RpfFileEntry = entry; RpfResourceFileEntry resentry = entry as RpfResourceFileEntry; if (resentry == null) { throw new Exception("File entry wasn't a resource! (is it binary data?)"); } ResourceDataReader rd = new ResourceDataReader(resentry, data); //MemoryUsage = 0; try { PtfxList = rd.ReadBlock <ParticleEffectsList>(); //Drawable.Owner = this; //MemoryUsage += Drawable.MemoryUsage; //uses decompressed filesize now... } catch (Exception ex) { ErrorMessage = ex.ToString(); } var dDict = PtfxList?.DrawableDictionary; if ((dDict != null) && (dDict.Drawables != null) && (dDict.Drawables.data_items != null) && (dDict.Hashes != null)) { DrawableDict = new Dictionary <uint, Drawable>(); var drawables = dDict.Drawables.data_items; var hashes = dDict.Hashes; for (int i = 0; (i < drawables.Length) && (i < hashes.Length); i++) { var drawable = drawables[i]; var hash = hashes[i]; DrawableDict[hash] = drawable; drawable.Owner = this; } for (int i = 0; (i < drawables.Length) && (i < hashes.Length); i++) { var drawable = drawables[i]; var hash = hashes[i]; if ((drawable.Name == null) || (drawable.Name.EndsWith("#dd"))) { string hstr = JenkIndex.TryGetString(hash); if (!string.IsNullOrEmpty(hstr)) { drawable.Name = hstr; } else { drawable.Name = "0x" + hash.ToString("X").PadLeft(8, '0'); } } } } Loaded = true; }
public YldFile(RpfFileEntry entry) : base(entry, GameFileType.Yld) { }
public GtxdFile(RpfFileEntry entry) : base(entry, GameFileType.Gtxd) { }
private void ExportButton_Click(object sender, EventArgs e) { if (InProgress) { return; } if (ScannedFiles.Count == 0) { MessageBox.Show("Please scan the GTAV folder first."); return; } TreeNode node = MainTreeView.SelectedNode; if (node == null) { MessageBox.Show("Please select a file to export."); return; } RpfFileEntry rfe = node.Tag as RpfFileEntry; if (rfe == null) { MessageBox.Show("Please select a file to export."); return; } SaveFileDialog.FileName = rfe.Name; if (SaveFileDialog.ShowDialog() == DialogResult.OK) { string fpath = SaveFileDialog.FileName; byte[] data = rfe.File.ExtractFile(rfe); if (ExportCompressCheckBox.Checked) { data = ResourceBuilder.Compress(data); } RpfResourceFileEntry rrfe = rfe as RpfResourceFileEntry; if (rrfe != null) //add resource header if this is a resource file. { data = ResourceBuilder.AddResourceHeader(rrfe, data); } if (data == null) { MessageBox.Show("Error extracting file! " + rfe.File.LastError); return; } try { File.WriteAllBytes(fpath, data); } catch (Exception ex) { MessageBox.Show("Error saving file! " + ex.ToString()); } } }
private void Search() { if (InProgress) { return; } if (ScannedFiles.Count == 0) { MessageBox.Show("Please scan the GTAV folder first."); return; } if (SearchTextBox.Text.Length == 0) { MessageBox.Show("Please enter a search term."); return; } string searchtxt = SearchTextBox.Text; bool hex = SearchHexRadioButton.Checked; bool casesen = SearchCaseSensitiveCheckBox.Checked || hex; bool bothdirs = SearchBothDirectionsCheckBox.Checked; string[] ignoreexts = null; byte[] searchbytes1; byte[] searchbytes2; int bytelen; if (!casesen) { searchtxt = searchtxt.ToLowerInvariant(); //case sensitive search in lower case. } if (SearchIgnoreCheckBox.Checked) { ignoreexts = SearchIgnoreTextBox.Text.Split(','); for (int i = 0; i < ignoreexts.Length; i++) { ignoreexts[i] = ignoreexts[i].Trim(); } } if (hex) { if (searchtxt.Length < 2) { MessageBox.Show("Please enter at least one byte of hex (2 characters)."); return; } try { bytelen = searchtxt.Length / 2; searchbytes1 = new byte[bytelen]; searchbytes2 = new byte[bytelen]; for (int i = 0; i < bytelen; i++) { searchbytes1[i] = Convert.ToByte(searchtxt.Substring(i * 2, 2), 16); searchbytes2[bytelen - i - 1] = searchbytes1[i]; } } catch { MessageBox.Show("Please enter a valid hex string."); return; } } else { bytelen = searchtxt.Length; searchbytes1 = new byte[bytelen]; searchbytes2 = new byte[bytelen]; //reversed text... for (int i = 0; i < bytelen; i++) { searchbytes1[i] = (byte)searchtxt[i]; searchbytes2[bytelen - i - 1] = searchbytes1[i]; } } SearchTextBox.Enabled = false; SearchHexRadioButton.Enabled = false; SearchTextRadioButton.Enabled = false; SearchCaseSensitiveCheckBox.Enabled = false; SearchBothDirectionsCheckBox.Enabled = false; SearchIgnoreCheckBox.Enabled = false; SearchIgnoreTextBox.Enabled = false; SearchButton.Enabled = false; SearchSaveResultsButton.Enabled = false; InProgress = true; AbortOperation = false; SearchResultsListView.VirtualListSize = 0; SearchResults.Clear(); int totfiles = TotalFileCount; int curfile = 0; Task.Run(() => { DateTime starttime = DateTime.Now; int resultcount = 0; for (int f = 0; f < ScannedFiles.Count; f++) { var rpffile = ScannedFiles[f]; //UpdateStatus(string.Format("Searching {0}/{1} : {2}", f, ScannedFiles.Count, rpffile.Path)); foreach (var entry in rpffile.AllEntries) { var duration = DateTime.Now - starttime; if (AbortOperation) { UpdateStatus(duration.ToString(@"hh\:mm\:ss") + " - Search aborted."); InProgress = false; SearchComplete(); return; } RpfFileEntry fentry = entry as RpfFileEntry; if (fentry == null) { continue; } curfile++; if (fentry.NameLower.EndsWith(".rpf")) { continue; } if (ignoreexts != null) { bool ignore = false; for (int i = 0; i < ignoreexts.Length; i++) { if (fentry.NameLower.EndsWith(ignoreexts[i])) { ignore = true; break; } } if (ignore) { continue; } } UpdateStatus(string.Format("{0} - Searching {1}/{2} : {3}", duration.ToString(@"hh\:mm\:ss"), curfile, totfiles, fentry.Path)); byte[] filebytes = fentry.File.ExtractFile(fentry); if (filebytes == null) { continue; } int hitlen1 = 0; int hitlen2 = 0; for (int i = 0; i < filebytes.Length; i++) { byte b = casesen ? filebytes[i] : LowerCaseByte(filebytes[i]); byte b1 = searchbytes1[hitlen1]; //current test byte 1 byte b2 = searchbytes2[hitlen2]; if (b == b1) { hitlen1++; } else { hitlen1 = 0; } if (hitlen1 == bytelen) { AddSearchResult(new SearchResult(fentry, (i - bytelen), bytelen)); resultcount++; hitlen1 = 0; } if (bothdirs) { if (b == b2) { hitlen2++; } else { hitlen2 = 0; } if (hitlen2 == bytelen) { AddSearchResult(new SearchResult(fentry, (i - bytelen), bytelen)); resultcount++; hitlen2 = 0; } } } } } var totdur = DateTime.Now - starttime; UpdateStatus(totdur.ToString(@"hh\:mm\:ss") + " - Search complete. " + resultcount.ToString() + " results found."); InProgress = false; SearchComplete(); }); }
private bool SaveRel(XmlDocument doc) { if (!(exploreForm?.EditMode ?? false)) { return(false); } if (rpfFileEntry?.Parent == null) { return(false); } byte[] data = null; #if !DEBUG try #endif { switch (metaFormat) { default: case MetaFormat.XML: return(false); //what are we even doing here? case MetaFormat.AudioRel: var rel = XmlRel.GetRel(doc); if ((rel?.RelDatasSorted == null) || (rel.RelDatasSorted.Length == 0)) { MessageBox.Show("Schema not supported.", "Cannot import REL XML"); return(false); } data = rel.Save(); break; } } #if !DEBUG catch (Exception ex) { MessageBox.Show("Exception encountered!\r\n" + ex.ToString(), "Cannot convert XML"); return(false); } #endif if (data == null) { MessageBox.Show("Schema not supported. (Unspecified error - data was null!)", "Cannot convert XML"); 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 = metaFormat.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 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; }
public void Init(MetaHash pedhash, GameFileCache gfc) { Name = string.Empty; NameHash = 0; InitData = null; Ydd = null; Ytd = null; Ycd = null; Yft = null; Ymt = null; AnimClip = null; for (int i = 0; i < 12; i++) { Drawables[i] = null; Textures[i] = null; } CPedModelInfo__InitData initdata = null; if (!gfc.PedsInitDict.TryGetValue(pedhash, out initdata)) { return; } var ycdhash = JenkHash.GenHash(initdata.ClipDictionaryName.ToLowerInvariant()); //bool pedchange = NameHash != pedhash; //Name = pedname; NameHash = pedhash; InitData = initdata; Ydd = gfc.GetYdd(pedhash); Ytd = gfc.GetYtd(pedhash); Ycd = gfc.GetYcd(ycdhash); Yft = gfc.GetYft(pedhash); PedFile pedFile = null; gfc.PedVariationsDict?.TryGetValue(pedhash, out pedFile); Ymt = pedFile; Dictionary <MetaHash, RpfFileEntry> peddict = null; gfc.PedDrawableDicts.TryGetValue(NameHash, out peddict); DrawableFilesDict = peddict; DrawableFiles = DrawableFilesDict?.Values.ToArray(); gfc.PedTextureDicts.TryGetValue(NameHash, out peddict); TextureFilesDict = peddict; TextureFiles = TextureFilesDict?.Values.ToArray(); gfc.PedClothDicts.TryGetValue(NameHash, out peddict); ClothFilesDict = peddict; ClothFiles = ClothFilesDict?.Values.ToArray(); RpfFileEntry clothFile = null; if (ClothFilesDict?.TryGetValue(pedhash, out clothFile) ?? false) { Yld = gfc.GetFileUncached <YldFile>(clothFile); while ((Yld != null) && (!Yld.Loaded)) { Thread.Sleep(1);//kinda hacky gfc.TryLoadEnqueue(Yld); } } while ((Ydd != null) && (!Ydd.Loaded)) { Thread.Sleep(1);//kinda hacky Ydd = gfc.GetYdd(pedhash); } while ((Ytd != null) && (!Ytd.Loaded)) { Thread.Sleep(1);//kinda hacky Ytd = gfc.GetYtd(pedhash); } while ((Ycd != null) && (!Ycd.Loaded)) { Thread.Sleep(1);//kinda hacky Ycd = gfc.GetYcd(ycdhash); } while ((Yft != null) && (!Yft.Loaded)) { Thread.Sleep(1);//kinda hacky Yft = gfc.GetYft(pedhash); } Skeleton = Yft?.Fragment?.Drawable?.Skeleton?.Clone(); MetaHash cliphash = JenkHash.GenHash("idle"); ClipMapEntry cme = null; Ycd?.ClipMap?.TryGetValue(cliphash, out cme); AnimClip = cme; UpdateEntity(); }
public void Load(byte[] data, RpfFileEntry entry) { FileEntry = entry; RpfResourceFileEntry resentry = entry as RpfResourceFileEntry; if (resentry == null) { MemoryStream ms = new MemoryStream(data); if (RbfFile.IsRBF(ms)) { Rbf = new RbfFile(); Rbf.Load(ms); } else if (PsoFile.IsPSO(ms)) { Pso = new PsoFile(); Pso.Load(ms); //PsoTypes.EnsurePsoTypes(Pso); } else { } return; } ResourceDataReader rd = new ResourceDataReader(resentry, data); Meta = rd.ReadBlock <Meta>(); CMapTypes = MetaTypes.GetTypedData <CMapTypes>(Meta, MetaName.CMapTypes); List <Archetype> allarchs = new List <Archetype>(); var ptrs = MetaTypes.GetPointerArray(Meta, CMapTypes.archetypes); if (ptrs != null) { for (int i = 0; i < ptrs.Length; i++) { var ptr = ptrs[i]; var offset = ptr.Offset; var block = Meta.GetBlock(ptr.BlockID); if (block == null) { continue; } if ((offset < 0) || (block.Data == null) || (offset >= block.Data.Length)) { continue; } Archetype a = null; switch (block.StructureNameHash) { case MetaName.CBaseArchetypeDef: var basearch = PsoTypes.ConvertDataRaw <CBaseArchetypeDef>(block.Data, offset); a = new Archetype(); a.Init(this, ref basearch); a.Extensions = MetaTypes.GetExtensions(Meta, basearch.extensions); break; case MetaName.CTimeArchetypeDef: var timearch = PsoTypes.ConvertDataRaw <CTimeArchetypeDef>(block.Data, offset); var ta = new TimeArchetype(); ta.Init(this, ref timearch); ta.Extensions = MetaTypes.GetExtensions(Meta, timearch._BaseArchetypeDef.extensions); a = ta; break; case MetaName.CMloArchetypeDef: var mloarch = PsoTypes.ConvertDataRaw <CMloArchetypeDef>(block.Data, offset); var ma = new MloArchetype(); ma.Init(this, ref mloarch); ma.Extensions = MetaTypes.GetExtensions(Meta, mloarch._BaseArchetypeDef.extensions); var mlodef = mloarch.MloArchetypeDef; ma.entities = MetaTypes.ConvertDataArray <CEntityDef>(Meta, MetaName.CEntityDef, mlodef.entities); ma.rooms = MetaTypes.ConvertDataArray <CMloRoomDef>(Meta, MetaName.CMloRoomDef, mlodef.rooms); ma.portals = MetaTypes.ConvertDataArray <CMloPortalDef>(Meta, MetaName.CMloPortalDef, mlodef.portals); ma.entitySets = MetaTypes.ConvertDataArray <CMloEntitySet>(Meta, MetaName.CMloEntitySet, mlodef.entitySets); ma.timeCycleModifiers = MetaTypes.ConvertDataArray <CMloTimeCycleModifier>(Meta, MetaName.CMloTimeCycleModifier, mlodef.timeCycleModifiers); if (ma.entities != null) { //for (int e = 0; e < ma.entities.Length; e++) //{ // if (ma.entities[e].extensions.Count1 > 0) // { // var exts = MetaTypes.GetExtensions(Meta, ma.entities[e].extensions); // if (exts != null) // { } // } //} } a = ma; break; default: continue; } if (a != null) { allarchs.Add(a); } } } AllArchetypes = allarchs.ToArray(); Extensions = MetaTypes.GetExtensions(Meta, CMapTypes.extensions); if (Extensions != null) { } //AudioEmitters = MetaTypes.GetTypedDataArray<CExtensionDefAudioEmitter>(Meta, MetaName.CExtensionDefAudioEmitter); //if (AudioEmitters != null) //{ } //CEntityDefs = MetaTypes.GetTypedDataArray<CEntityDef>(Meta, MetaName.CEntityDef); CompositeEntityTypes = MetaTypes.ConvertDataArray <CCompositeEntityType>(Meta, MetaName.CCompositeEntityType, CMapTypes.compositeEntityTypes); if (CompositeEntityTypes != null) { } NameHash = CMapTypes.name; if (NameHash == 0) { int ind = entry.NameLower.LastIndexOf('.'); if (ind > 0) { NameHash = JenkHash.GenHash(entry.NameLower.Substring(0, ind)); } else { NameHash = JenkHash.GenHash(entry.NameLower); } } Strings = MetaTypes.GetStrings(Meta); if (Strings != null) { foreach (string str in Strings) { JenkIndex.Ensure(str); //just shove them in there } } //foreach (var block in Meta.DataBlocks) //{ // switch(block.StructureNameHash) // { // case MetaName.CMapTypes: // case MetaName.CTimeArchetypeDef: // case MetaName.CBaseArchetypeDef: // case MetaName.CMloArchetypeDef: // case MetaName.CMloTimeCycleModifier: // case MetaName.CMloRoomDef: // case MetaName.CMloPortalDef: // case MetaName.CMloEntitySet: // case MetaName.CEntityDef: // case MetaName.CExtensionDefParticleEffect: // case MetaName.CExtensionDefAudioCollisionSettings: // case MetaName.CExtensionDefSpawnPoint: // case MetaName.CExtensionDefSpawnPointOverride: // case MetaName.CExtensionDefExplosionEffect: // case MetaName.CExtensionDefAudioEmitter: // case MetaName.CExtensionDefLadder: // case MetaName.CExtensionDefBuoyancy: // case MetaName.CExtensionDefExpression: // case MetaName.CExtensionDefLightShaft: // case MetaName.CExtensionDefLightEffect: // case MetaName.CExtensionDefDoor: // case MetaName.CExtensionDefWindDisturbance: // case MetaName.CExtensionDefProcObject: // case MetaName.CLightAttrDef: // case MetaName.STRING: // case MetaName.POINTER: // case MetaName.UINT: // case MetaName.VECTOR4: // break; // default: // break; // } //} //MetaTypes.ParseMetaData(Meta); }
public YtypFile(RpfFileEntry entry) : base(entry, GameFileType.Ytyp) { }
public void SetComponentDrawable(int index, string name, string tex, GameFileCache gfc) { if (string.IsNullOrEmpty(name)) { DrawableNames[index] = null; Drawables[index] = null; Textures[index] = null; return; } MetaHash namehash = JenkHash.GenHash(name.ToLowerInvariant()); Drawable d = null; if (Ydd?.Dict != null) { Ydd.Dict.TryGetValue(namehash, out d); } if ((d == null) && (DrawableFilesDict != null)) { RpfFileEntry file = null; if (DrawableFilesDict.TryGetValue(namehash, out file)) { var ydd = gfc.GetFileUncached <YddFile>(file); while ((ydd != null) && (!ydd.Loaded)) { Thread.Sleep(1);//kinda hacky gfc.TryLoadEnqueue(ydd); } if (ydd?.Drawables?.Length > 0) { d = ydd.Drawables[0];//should only be one in this dict } } } MetaHash texhash = JenkHash.GenHash(tex.ToLowerInvariant()); Texture t = null; if (Ytd?.TextureDict?.Dict != null) { Ytd.TextureDict.Dict.TryGetValue(texhash, out t); } if ((t == null) && (TextureFilesDict != null)) { RpfFileEntry file = null; if (TextureFilesDict.TryGetValue(texhash, out file)) { var ytd = gfc.GetFileUncached <YtdFile>(file); while ((ytd != null) && (!ytd.Loaded)) { Thread.Sleep(1);//kinda hacky gfc.TryLoadEnqueue(ytd); } if (ytd?.TextureDict?.Textures?.data_items.Length > 0) { t = ytd.TextureDict.Textures.data_items[0];//should only be one in this dict } } } CharacterCloth cc = null; if (Yld?.Dict != null) { Yld.Dict.TryGetValue(namehash, out cc); } if ((cc == null) && (ClothFilesDict != null)) { RpfFileEntry file = null; if (ClothFilesDict.TryGetValue(namehash, out file)) { var yld = gfc.GetFileUncached <YldFile>(file); while ((yld != null) && (!yld.Loaded)) { Thread.Sleep(1);//kinda hacky gfc.TryLoadEnqueue(yld); } if (yld?.ClothDictionary?.Clothes?.data_items?.Length > 0) { cc = yld.ClothDictionary.Clothes.data_items[0];//should only be one in this dict } } } ClothInstance c = null; if (cc != null) { c = new ClothInstance(); c.Init(cc, Skeleton); } if (d != null) { Drawables[index] = d.ShallowCopy() as Drawable; } if (t != null) { Textures[index] = t; } if (c != null) { Clothes[index] = c; } DrawableNames[index] = name; }
public void Load(byte[] data, RpfFileEntry entry) { FileEntry = entry; MemoryStream ms = new MemoryStream(data); BinaryReader br = new BinaryReader(ms); StringBuilder sb = new StringBuilder(); for (int i = 0; (i < 100) && (i < data.Length); i++) { //read version string. byte b = data[i]; if (b == 0) { break; } sb.Append((char)b); } Version = sb.ToString().Replace("[VERSION]", "").Replace("\r", "").Replace("\n", ""); sb.Clear(); int lastn = 0; int lspos = 0; uint structcount = 0; uint modlen; bool indates = false; List <string> lines = new List <string>(); var dates = new List <CacheFileDate>(); var allMapNodes = new List <MapDataStoreNode>(); var allCInteriorProxies = new List <CInteriorProxy>(); var allBoundsStoreItems = new List <BoundsStoreItem>(); for (int i = 100; i < data.Length; i++) { byte b = data[i]; if (b == 0) { break; } if (b == 0xA) { lastn = i; string line = sb.ToString(); lines.Add(line); switch (line) { case "<fileDates>": indates = true; break; case "</fileDates>": indates = false; break; case "<module>": break; case "</module>": break; case "fwMapDataStore": ms.Position = i + 1; modlen = br.ReadUInt32(); structcount = modlen / 64; lspos = i + (int)modlen + 5; while (ms.Position < lspos) { allMapNodes.Add(new MapDataStoreNode(br)); } //if (allMapNodes.Count != structcount) //{ }//test fail due to variable length struct i += (int)(modlen + 4); break; case "CInteriorProxy": ms.Position = i + 1; modlen = br.ReadUInt32(); structcount = modlen / 104; lspos = i + (int)modlen + 5; while (ms.Position < lspos) { allCInteriorProxies.Add(new CInteriorProxy(br)); } if (allCInteriorProxies.Count != structcount) { } //all pass here i += (int)(modlen + 4); break; case "BoundsStore": ms.Position = i + 1; modlen = br.ReadUInt32(); structcount = modlen / 32; lspos = i + (int)modlen + 5; while (ms.Position < lspos) { allBoundsStoreItems.Add(new BoundsStoreItem(br)); } if (allBoundsStoreItems.Count != structcount) { } //all pass here i += (int)(modlen + 4); break; default: if (!indates) { } //just testing else { dates.Add(new CacheFileDate(line)); //eg: 2740459947 (hash of: platform:/data/cdimages/scaleform_frontend.rpf) 130680580712018938 8944 } break; } sb.Clear(); } else { sb.Append((char)b); } } FileDates = dates.ToArray(); AllMapNodes = allMapNodes.ToArray(); AllCInteriorProxies = allCInteriorProxies.ToArray(); AllBoundsStoreItems = allBoundsStoreItems.ToArray(); MapNodeDict = new Dictionary <uint, MapDataStoreNode>(); var rootMapNodes = new List <MapDataStoreNode>(); foreach (var mapnode in AllMapNodes) { MapNodeDict[mapnode.Name] = mapnode; if (mapnode.ParentName == 0) { rootMapNodes.Add(mapnode); } if (mapnode.UnkExtra != null) { } //notsure what to do with this } foreach (var mapnode in AllMapNodes) { MapDataStoreNode pnode; if (MapNodeDict.TryGetValue(mapnode.ParentName, out pnode)) { pnode.AddChildToList(mapnode); } else if ((mapnode.ParentName != 0)) { } } foreach (var mapnode in AllMapNodes) { mapnode.ChildrenListToArray(); } RootMapNodes = rootMapNodes.ToArray(); BoundsStoreDict = new Dictionary <MetaHash, BoundsStoreItem>(); foreach (BoundsStoreItem item in AllBoundsStoreItems) { BoundsStoreItem mbsi = null; if (BoundsStoreDict.TryGetValue(item.Name, out mbsi)) { } BoundsStoreDict[item.Name] = item; } //InteriorProxyDict = new Dictionary<MetaHash, CInteriorProxy>(); foreach (CInteriorProxy prx in AllCInteriorProxies) { //CInteriorProxy mprx = null; //if (InteriorProxyDict.TryGetValue(prx.Name, out mprx)) //{ } //InteriorProxyDict[prx.Name] = prx;//can't do this! multiples with same name different pos MapDataStoreNode mnode = null; if (MapNodeDict.TryGetValue(prx.Parent, out mnode)) { mnode.AddInteriorToList(prx); } else { } } foreach (var mapnode in AllMapNodes) { mapnode.InteriorProxyListToArray(); } br.Dispose(); ms.Dispose(); }
public VehiclesFile(RpfFileEntry entry) : base(entry, GameFileType.Vehicles) { }
public YbnFile(RpfFileEntry entry) : base(entry, GameFileType.Ybn) { }
public void Load(byte[] data, RpfFileEntry entry) { Name = entry.Name; RpfFileEntry = entry; //Hash = entry.ShortNameHash; RpfResourceFileEntry resentry = entry as RpfResourceFileEntry; if (resentry == null) { throw new Exception("File entry wasn't a resource! (is it binary data?)"); } ResourceDataReader rd = new ResourceDataReader(resentry, data); ClipDictionary = rd.ReadBlock <ClipDictionary>(); ClipMap = new Dictionary <MetaHash, ClipMapEntry>(); AnimMap = new Dictionary <MetaHash, AnimationMapEntry>(); if (ClipDictionary != null) { if ((ClipDictionary.Clips != null) && (ClipDictionary.Clips.data_items != null)) { foreach (var cme in ClipDictionary.Clips.data_items) { if (cme != null) { ClipMap[cme.Hash] = cme; var nxt = cme.Next; while (nxt != null) { ClipMap[nxt.Hash] = nxt; nxt = nxt.Next; } } } } if ((ClipDictionary.Animations != null) && (ClipDictionary.Animations.Animations != null) && (ClipDictionary.Animations.Animations.data_items != null)) { foreach (var ame in ClipDictionary.Animations.Animations.data_items) { if (ame != null) { AnimMap[ame.Hash] = ame; var nxt = ame.NextEntry; while (nxt != null) { AnimMap[nxt.Hash] = nxt; nxt = nxt.NextEntry; } } } } } foreach (var cme in ClipMap.Values) { var clip = cme.Clip; if (clip == null) { continue; } clip.Ycd = this; if (string.IsNullOrEmpty(clip.Name)) { continue; } string name = clip.Name.Replace('\\', '/'); var slidx = name.LastIndexOf('/'); if ((slidx >= 0) && (slidx < name.Length - 1)) { name = name.Substring(slidx + 1); } var didx = name.LastIndexOf('.'); if ((didx > 0) && (didx < name.Length)) { name = name.Substring(0, didx); } clip.ShortName = name; name = name.ToLowerInvariant(); JenkIndex.Ensure(name); //if (name.EndsWith("_uv_0")) //hash for these entries match string with this removed, +1 //{ //} //if (name.EndsWith("_uv_1")) //same as above, but +2 //{ //} } foreach (var ame in AnimMap.Values) { var anim = ame.Animation; if (anim == null) { continue; } anim.Ycd = this; } ClipMapEntries = ClipMap.Values.ToArray(); AnimMapEntries = AnimMap.Values.ToArray(); }
public void Load(byte[] data, RpfFileEntry entry) { //adapted from libertyV code //MemoryStream ms = new MemoryStream(data); Name = entry.Name; FileEntry = entry; Data = data; if ((data == null) || (data.Length < 8)) { ErrorMessage = "Data null or too short!"; return; //nothing to do, not enough data... } Magic = BitConverter.ToUInt32(data, 0); Endianess endianess = Endianess.LittleEndian; switch (Magic) { default: ErrorMessage = "Unexpected Magic 0x" + Magic.ToString("X"); return; case 0x54414441: endianess = Endianess.LittleEndian; break; case 0x41444154: endianess = Endianess.BigEndian; break; } using (MemoryStream ms = new MemoryStream(data)) { DataReader r = new DataReader(ms, endianess); Magic = r.ReadUInt32(); Version = r.ReadUInt16(); Flags = r.ReadUInt16(); StreamCount = r.ReadInt32(); InfoOffset = r.ReadInt32(); //notes from libertyV: // first bit - means that there are unknown word for each stream after this header // second bit - I think that it means that not all the tags are in the start of the file, but all the tags of a stream are near the data tag // third bit - Multi channel audio if ((Flags >> 8) != 0xFF) { ErrorMessage = "Flags 0 not supported!"; return; } if ((Flags & 0xF8) != 0) { //ErrorMessage = "Flags 1 not supported!"; //return; } MultiChannel = ((Flags & 4) == 4); var flag0 = ((Flags & 1) == 1); var infoStart = 16 + (flag0 ? (StreamCount * 2) : 0); ms.Position = infoStart; List <AwcStreamInfo> infos = new List <AwcStreamInfo>(); Dictionary <uint, AwcStreamInfo> infoDict = new Dictionary <uint, AwcStreamInfo>(); List <uint> audioIds = new List <uint>(); List <AwcAudio> audios = new List <AwcAudio>(); for (int i = 0; i < StreamCount; i++) { var info = new AwcStreamInfo(r); infos.Add(info); infoDict[info.Id] = info; } for (int i = 0; i < StreamCount; i++) { var info = infos[i]; for (int j = 0; j < info.TagCount; j++) { var chunk = new AwcChunkInfo(r); info.Chunks[chunk.Tag] = chunk; } } StreamInfos = infos.ToArray(); byte hformat = 0xFA; // 250 0x6061D4FA & 0xFF; //JenkHash.GenHash("format"); byte hdata = 0x55; // 85 0x5EB5E655 & 0xFF; //JenkHash.GenHash("data"); byte hycd = 0x5C; // 92 YCD resource chunk... lip sync anims? byte hunk = 0x36; // 54 unk chunk? small number of bytes (2+) if (MultiChannel) { AwcStreamInfo stream0 = null; if (!infoDict.TryGetValue(0, out stream0)) { ErrorMessage = "Couldn't find MultiChannel stream0"; return; } AwcChunkInfo chunk72 = null; if (!stream0.Chunks.TryGetValue(72, out chunk72)) { ErrorMessage = "Couldn't find MultiChannel chunk72"; return; } ms.Position = chunk72.Offset; AwcChannelChunkInfo chanInfo = new AwcChannelChunkInfo(r); if (chanInfo.ChannelCount != StreamCount - 1) { ErrorMessage = "Channel Count did not match Stream Count"; return; } List <AwcChannelChunkItemInfo> chunkItems = new List <AwcChannelChunkItemInfo>(); for (int i = 0; i < chanInfo.ChannelCount; i++) { var itemInfo = new AwcChannelChunkItemInfo(r); chunkItems.Add(itemInfo); audioIds.Add(infos[i + 1].Id); } //AudioStreams.Add(new MultiChannelAudio(new ChunkStream(this.Stream, streamsChunks[0][Tag("data")]), channelsInfoHeader, streamsInfo, header.BigEndian)); AwcChunkInfo cdata = null; if (!stream0.Chunks.TryGetValue(hdata, out cdata)) { ErrorMessage = "Couldn't find Stream 0 data chunk"; return; } ms.Position = cdata.Offset; var lastPos = cdata.Offset + cdata.Size; //int chunkSize = 0x800; uint bigChunkSize = chanInfo.ChunkSize; var chanCount = chanInfo.ChannelCount; MultiChannelData = r.ReadBytes(cdata.Size); ms.Position = cdata.Offset; //var d = data;//temporary ////this doesn't seem to work :( //while (ms.Position < lastPos) //{ // uint totalChunks = 0; // var startPos = ms.Position; // var curPos = startPos; // //byte[] chunkdata = r.ReadBytes(chunkSize); // //ms.Position = startPos; // AwcChannelChunkHeader[] chanHeaders = new AwcChannelChunkHeader[chanCount]; // for (int i = 0; i < chanCount; i++) // { // var chanHeader = new AwcChannelChunkHeader(r); // chanHeaders[i] = chanHeader; // totalChunks += chanHeader.ChunkCount; // } // int headerSize = (int)(totalChunks * 4 + chanInfo.ChannelCount * AwcChannelChunkHeader.Size); // headerSize += (((-headerSize) % chunkSize) + chunkSize) % chunkSize; //todo: simplify this! // curPos += headerSize; // AwcChannelChunk[] chanChunks = new AwcChannelChunk[chanCount]; // for (int i = 0; i < chanCount; i++) // { // var chanChunk = new AwcChannelChunk(r, chanHeaders[i], chunkItems[i]); // chanChunks[i] = chanChunk; // curPos += chanChunk.TotalDataSize; // } // if (curPos - startPos > chanInfo.ChunkSize) // { // ErrorMessage = "Chunk was bigger than the chunk size"; // break; // } // if ((totalChunks == 0) || ((startPos + chanInfo.ChunkSize) > lastPos)) // { // ErrorMessage = "Unable to read chunk"; // break; // } // var newPos = startPos + bigChunkSize; // if (newPos >= lastPos) break; // ms.Position = newPos; //} } else { for (int i = 0; i < StreamCount; i++) { var info = infos[i]; AwcChunkInfo cformat = null; if (!info.Chunks.TryGetValue(hformat, out cformat)) { ErrorMessage = "Couldn't find Stream " + i.ToString() + " format chunk"; continue; } AwcChunkInfo cdata = null; if (!info.Chunks.TryGetValue(hdata, out cdata)) { ErrorMessage = "Couldn't find Stream " + i.ToString() + " data chunk"; continue; } AwcChunkInfo cycd = null; AwcAudioAnimClipDict oycd = null; if (info.Chunks.TryGetValue(hycd, out cycd)) { ms.Position = cycd.Offset; oycd = new AwcAudioAnimClipDict(r, cycd); } AwcChunkInfo cunk = null; AwcAudioUnk ounk = null; if (info.Chunks.TryGetValue(hunk, out cunk)) { ms.Position = cunk.Offset; ounk = new AwcAudioUnk(r, cunk); } ms.Position = cformat.Offset; AwcFormatChunk formatChunk = new AwcFormatChunk(r); ms.Position = cdata.Offset; AwcAudio audio = new AwcAudio(r, info, formatChunk, cdata); audio.ClipDict = oycd; audio.UnkData = ounk; audios.Add(audio); audioIds.Add(info.Id); } } Audios = audios.ToArray(); AudioIds = audioIds.ToArray(); } }
public void LoadRel(RelFile rel) { fileName = rel?.Name; if (string.IsNullOrEmpty(fileName)) { fileName = rel?.RpfFileEntry?.Name; } UpdateFormTitle(); RelPropertyGrid.SelectedObject = rel; CurrentFile = rel; rpfFileEntry = rel?.RpfFileEntry; Xml = RelXml.GetXml(rel); metaFormat = MetaFormat.AudioRel; StringBuilder sb = new StringBuilder(); if (rel != null) { if (rel.NameTable != null) { sb.AppendLine("NameTable - " + rel.NameTable.Length.ToString() + " entries"); foreach (var name in rel.NameTable) { sb.AppendLine(name); } sb.AppendLine(); } if (rel.IndexStrings != null) { sb.AppendLine("IndexStrings - " + rel.IndexStrings.Length.ToString() + " entries"); foreach (var rstr in rel.IndexStrings) { sb.AppendLine(rstr.Name); } sb.AppendLine(); } if (rel.IndexHashes != null) { sb.AppendLine("IndexHashes - " + rel.IndexHashes.Length.ToString() + " entries"); foreach (var rhash in rel.IndexHashes) { uint h = rhash.Name; var jstr = JenkIndex.TryGetString(h); if (!string.IsNullOrEmpty(jstr)) { sb.AppendLine(jstr); } else { sb.AppendLine("0x" + h.ToString("X").PadLeft(8, '0')); } } sb.AppendLine(); } } MainTextBox.Text = sb.ToString(); }
public void Load(byte[] data, RpfFileEntry entry) { Name = entry.Name; RpfFileEntry = entry; RpfResourceFileEntry resentry = entry as RpfResourceFileEntry; if (resentry == null) { throw new Exception("File entry wasn't a resource! (is it binary data?)"); } ResourceDataReader rd = new ResourceDataReader(resentry, data); DrawableDict = rd.ReadBlock <DrawableDictionary>(); //MemoryUsage = 0; //uses decompressed filesize now... //if (DrawableDict != null) //{ // MemoryUsage += DrawableDict.MemoryUsage; //} if ((DrawableDict != null) && (DrawableDict.Drawables != null) && (DrawableDict.Drawables.data_items != null) && (DrawableDict.Hashes != null)) { Dict = new Dictionary <uint, Drawable>(); var drawables = DrawableDict.Drawables.data_items; var hashes = DrawableDict.Hashes; for (int i = 0; (i < drawables.Length) && (i < hashes.Length); i++) { var drawable = drawables[i]; var hash = hashes[i]; Dict[hash] = drawable; drawable.Owner = this; } for (int i = 0; (i < drawables.Length) && (i < hashes.Length); i++) { var drawable = drawables[i]; var hash = hashes[i]; if ((drawable.Name == null) || (drawable.Name.EndsWith("#dd"))) { string hstr = JenkIndex.TryGetString(hash); if (!string.IsNullOrEmpty(hstr)) { drawable.Name = hstr; } else { } } } Drawables = Dict.Values.ToArray(); } Loaded = true; }
public YftFile(RpfFileEntry entry) : base(entry, GameFileType.Yft) { }
public void Load(byte[] data, RpfFileEntry entry) { Name = entry.Name; RpfFileEntry = entry; RpfResourceFileEntry resentry = entry as RpfResourceFileEntry; if (resentry == null) { throw new Exception("File entry wasn't a resource! (is it binary data?)"); } ResourceDataReader rd = new ResourceDataReader(resentry, data); NodeDictionary = rd.ReadBlock <NodeDictionary>(); if (NodeDictionary != null) { if (NodeDictionary.Nodes != null) { var nodes = NodeDictionary.Nodes; Nodes = new YndNode[nodes.Length]; for (int i = 0; i < nodes.Length; i++) { var n = new YndNode(); n.Init(this, nodes[i]); Nodes[i] = n; if (n.NodeID != i) { } //never hit here - nodeid's have to match the index! } } if ((NodeDictionary.JunctionRefs != null) && (NodeDictionary.Junctions != null)) { var juncrefs = NodeDictionary.JunctionRefs; var juncs = NodeDictionary.Junctions; Junctions = new YndJunction[juncrefs.Length]; for (int i = 0; i < juncrefs.Length; i++) { var juncref = NodeDictionary.JunctionRefs[i]; if (juncref.JunctionID >= juncs.Length) { continue; } var j = new YndJunction(); j.Init(this, juncs[juncref.JunctionID], juncref); j.Heightmap = new YndJunctionHeightmap(NodeDictionary.JunctionHeightmapBytes, j); Junctions[i] = j; } } } UpdateAllNodePositions(); //links will be populated by the space... maybe move that code here? string areaidstr = Name.ToLower().Replace("nodes", "").Replace(".ynd", ""); int areaid = 0; int.TryParse(areaidstr, out areaid); AreaID = areaid; UpdateBoundingBox(); BuildBVH(); Loaded = true; LoadQueued = true; }
private void DisplayFileContentsText(RpfFileEntry rfe, byte[] data, int length, int offset) { if (data == null) { Cursor = Cursors.Default; DataTextBox.Text = "[Error extracting file! " + rfe.File.LastError + "]"; return; } int selline = -1; int selstartc = -1; int selendc = -1; if (DataHexRadio.Checked) { int charsperln = int.Parse(DataHexLineCombo.Text); int lines = (data.Length / charsperln) + (((data.Length % charsperln) > 0) ? 1 : 0); StringBuilder hexb = new StringBuilder(); StringBuilder texb = new StringBuilder(); StringBuilder finb = new StringBuilder(); if (offset > 0) { selline = offset / charsperln; } for (int i = 0; i < lines; i++) { int pos = i * charsperln; int poslim = pos + charsperln; hexb.Clear(); texb.Clear(); hexb.AppendFormat("{0:X4}: ", pos); for (int c = pos; c < poslim; c++) { if (c < data.Length) { byte b = data[c]; hexb.AppendFormat("{0:X2} ", b); if (char.IsControl((char)b)) { texb.Append("."); } else { texb.Append(Encoding.ASCII.GetString(data, c, 1)); } } else { hexb.Append(" "); texb.Append(" "); } } if (i == selline) { selstartc = finb.Length; } finb.AppendLine(hexb.ToString() + "| " + texb.ToString()); if (i == selline) { selendc = finb.Length - 1; } } DataTextBox.Text = finb.ToString(); } else { string text = Encoding.UTF8.GetString(data); DataTextBox.Text = text; if (offset > 0) { selstartc = offset; selendc = offset + length; } } if ((selstartc > 0) && (selendc > 0)) { DataTextBox.SelectionStart = selstartc; DataTextBox.SelectionLength = selendc - selstartc; DataTextBox.ScrollToCaret(); } }
public override string ToString() { return(RpfFileEntry?.ToString() ?? string.Empty); }
public SearchResult(RpfFileEntry entry, int offset, int length) { FileEntry = entry; Offset = offset; Length = length; }
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); }
public bool SaveMeta(XmlDocument doc) { //if explorer is in edit mode, and the current RpfFileEntry is valid, convert XML to the //current meta format and then save the file into the RPF. //otherwise, save the generated file to disk? //(currently just return false and revert to XML file save) if (!(exploreForm?.EditMode ?? false)) { return(false); } byte[] data = null; #if !DEBUG try #endif { switch (metaFormat) { default: case MetaFormat.XML: return(false); //what are we even doing here? case MetaFormat.RSC: var meta = XmlMeta.GetMeta(doc); if ((meta.DataBlocks?.Data == null) || (meta.DataBlocks.Count == 0)) { MessageBox.Show("Schema not supported.", "Cannot import Meta XML"); return(false); } data = ResourceBuilder.Build(meta, 2); //meta is RSC "Version":2 (it's actually a type identifier, not a version!) break; case MetaFormat.PSO: var pso = XmlPso.GetPso(doc); if ((pso.DataSection == null) || (pso.DataMapSection == null) || (pso.SchemaSection == null)) { MessageBox.Show("Schema not supported.", "Cannot import PSO XML"); return(false); } data = pso.Save(); break; case MetaFormat.RBF: var rbf = XmlRbf.GetRbf(doc); if (rbf.current == null) { MessageBox.Show("Schema not supported.", "Cannot import RBF XML"); return(false); } data = rbf.Save(); break; case MetaFormat.Ynd: var ynd = XmlYnd.GetYnd(doc); if (ynd.NodeDictionary == null) { MessageBox.Show("Schema not supported.", "Cannot import YND XML"); return(false); } data = ynd.Save(); break; case MetaFormat.Yld: var yld = XmlYld.GetYld(doc); if (yld.ClothDictionary == null) { MessageBox.Show("Schema not supported.", "Cannot import YLD XML"); return(false); } data = yld.Save(); break; case MetaFormat.Yed: var yed = XmlYed.GetYed(doc); if (yed.ExpressionDictionary == null) { MessageBox.Show("Schema not supported.", "Cannot import YED XML"); return(false); } data = yed.Save(); break; case MetaFormat.CacheFile: MessageBox.Show("Sorry, CacheFile import is not supported.", "Cannot import CacheFile XML"); return(false); case MetaFormat.Heightmap: var hmap = XmlHmap.GetHeightmap(doc); if (hmap.MaxHeights == null) { MessageBox.Show("Schema not supported.", "Cannot import Heightmap XML"); return(false); } data = hmap.Save(); break; } } #if !DEBUG catch (Exception ex) { MessageBox.Show("Exception encountered!\r\n" + ex.ToString(), "Cannot convert XML"); return(false); } #endif if (data == null) { MessageBox.Show("Schema not supported. (Unspecified error - data was null!)", "Cannot convert XML"); return(false); } if (rpfFileEntry?.Parent != null) { 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 = metaFormat.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"); } } else if (!string.IsNullOrEmpty(rpfFileEntry?.Path)) { try { File.WriteAllBytes(rpfFileEntry.Path, data); exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer... modified = false; StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString(); return(true); //victory! } catch (Exception ex) { MessageBox.Show("Error saving file to filesystem!\r\n" + ex.ToString(), "File I/O Error"); } } return(false); }
private void AddRpfFile(RpfFile file, bool isdlc, bool ismod) { isdlc = isdlc || (file.NameLower == "update.rpf") || (file.NameLower.StartsWith("dlc") && file.NameLower.EndsWith(".rpf")); ismod = ismod || (file.Path.StartsWith("mods\\")); if (file.AllEntries != null) { AllRpfs.Add(file); if (!ismod) { AllNoModRpfs.Add(file); } if (isdlc) { DlcRpfs.Add(file); if (!ismod) { DlcNoModRpfs.Add(file); } } else { if (ismod) { ModRpfs.Add(file); } else { BaseRpfs.Add(file); } } if (ismod) { ModRpfDict[file.Path.Substring(5)] = file; } RpfDict[file.Path] = file; foreach (RpfEntry entry in file.AllEntries) { try { if (!string.IsNullOrEmpty(entry.Name)) { if (ismod) { ModEntryDict[entry.Path] = entry; ModEntryDict[entry.Path.Substring(5)] = entry; } else { EntryDict[entry.Path] = entry; } if (entry is RpfFileEntry) { RpfFileEntry fentry = entry as RpfFileEntry; entry.NameHash = JenkHash.GenHash(entry.NameLower); int ind = entry.NameLower.LastIndexOf('.'); entry.ShortNameHash = (ind > 0) ? JenkHash.GenHash(entry.NameLower.Substring(0, ind)) : entry.NameHash; if (entry.ShortNameHash != 0) { //EntryHashDict[entry.ShortNameHash] = entry; } } } } catch (Exception ex) { file.LastError = ex.ToString(); file.LastException = ex; ErrorLog(entry.Path + ": " + ex.ToString()); } } } if (file.Children != null) { foreach (RpfFile cfile in file.Children) { AddRpfFile(cfile, isdlc, ismod); } } }
public YdrFile(RpfFileEntry entry) : base(entry, GameFileType.Ydr) { }
public void Load(byte[] data, RpfFileEntry entry) { FileEntry = entry; Name = entry.Name; Hash = entry.ShortNameHash; LastError = string.Empty; MemoryStream ms = new MemoryStream(data); BinaryReader br = new BinaryReader(ms); uint magic_rgxe = br.ReadUInt32(); if (magic_rgxe != 1702389618) //"rgxe" { return; } VertexType = (VertexType)br.ReadUInt32(); byte ec0 = br.ReadByte(); var exts1 = new List <FxcHeaderExt>(); for (int e = 0; e < ec0; e++) { FxcHeaderExt ext = new FxcHeaderExt(); ext.Name = ReadString(br); ext.Unk0Byte = br.ReadByte(); //0 ext.Unk1Uint = br.ReadUInt32(); //2 exts1.Add(ext); } Exts = exts1.ToArray(); List <FxcShader>[] shadergrps = new List <FxcShader> [6]; var chunks = new List <FxcHeaderChunk>(); var shaders = new List <FxcShader>(); int gindex = 0; while (gindex < 6)// (sc0 > 0) { var shadergrp = new List <FxcShader>(); shadergrps[gindex] = shadergrp; gindex++; byte sc0 = br.ReadByte(); if (sc0 == 0) { sc0 = br.ReadByte(); //this is a little odd, sometimes a byte skip } FxcHeaderChunk chunk = new FxcHeaderChunk(); chunk.Read(br); chunk.Gindex = gindex; chunk.ShaderCount = sc0; chunks.Add(chunk); for (int s = 1; s < sc0; s++) { bool exbyteflag1 = (gindex == 5); //GS seems to be in diff format?? bool vsgsps = (gindex == 1) || (gindex == 2) || (gindex == 5); FxcShader shader = new FxcShader(); if (!shader.Read(br, exbyteflag1, vsgsps)) { LastError += shader.LastError; //gindex = 6; //get outta the loop? //break; } shaders.Add(shader); shadergrp.Add(shader); } } Shaders = shaders.ToArray(); VertexShaders = shadergrps[0]?.ToArray(); PixelShaders = shadergrps[1]?.ToArray(); ComputeShaders = shadergrps[2]?.ToArray(); DomainShaders = shadergrps[3]?.ToArray(); GeometryShaders = shadergrps[4]?.ToArray(); HullShaders = shadergrps[5]?.ToArray(); Chunks = chunks.ToArray(); //ms.Dispose(); //return; List <FxcVariable> globalVars = new List <FxcVariable>(); CBufferDict = new Dictionary <uint, FxcCBuffer>(); FxcCBuffer cbtmp = null; try //things can be uncertain after this... { byte cbCount1 = br.ReadByte(); if (cbCount1 > 0) { var cbuffers1 = new List <FxcCBuffer>(); for (int i = 0; i < cbCount1; i++) //cbuffers? includes? { FxcCBuffer cbuf = new FxcCBuffer(); cbuf.Read(br); cbuffers1.Add(cbuf); CBufferDict[cbuf.NameHash] = cbuf; } CBuffers1 = cbuffers1.ToArray(); } byte varCount1 = br.ReadByte(); if (varCount1 > 0) { var vars1 = new List <FxcVariable>(); //cbuffer contents/vars for (int i = 0; i < varCount1; i++) { FxcVariable vari = new FxcVariable(); vari.Read(br); vars1.Add(vari); if (CBufferDict.TryGetValue(vari.CBufferName, out cbtmp)) { cbtmp.AddVariable(vari); } else { globalVars.Add(vari); } } Variables1 = vars1.ToArray(); } byte cbCount2 = br.ReadByte(); //0,1, +? if (cbCount2 > 0) { var cbuffers2 = new List <FxcCBuffer>(); //more cbuffers.. for (int i = 0; i < cbCount2; i++) { FxcCBuffer cbuf = new FxcCBuffer(); cbuf.Read(br); cbuffers2.Add(cbuf); CBufferDict[cbuf.NameHash] = cbuf; } CBuffers2 = cbuffers2.ToArray(); } byte varCount2 = br.ReadByte(); if (varCount2 > 0) { var vars2 = new List <FxcVariable>(); for (int i = 0; i < varCount2; i++) //textures/samplers { FxcVariable vari = new FxcVariable(); vari.Read(br); vars2.Add(vari); if (CBufferDict.TryGetValue(vari.CBufferName, out cbtmp)) { cbtmp.AddVariable(vari); } else { globalVars.Add(vari); } } Variables2 = vars2.ToArray(); } byte techCount = br.ReadByte(); if (techCount > 0) { var techniques = new List <FxcTechnique>(); for (int i = 0; i < techCount; i++) { FxcTechnique tech = new FxcTechnique(); tech.Read(br); techniques.Add(tech); } Techniques = techniques.ToArray(); } foreach (var cbuf in CBufferDict.Values) { cbuf.ConsolidateVariables(); } GlobalVariables = globalVars.ToArray(); if (ms.Position != ms.Length) { } } catch (Exception ex) { LastError = ex.ToString(); } ms.Dispose(); }
public YnvFile(RpfFileEntry entry) : base(entry, GameFileType.Ynv) { }
public PedsFile(RpfFileEntry entry) : base(entry, GameFileType.Peds) { }