/// <summary> /// Gets a resource. /// </summary> /// <param name="filename">The filename of the resource to get.</param> /// <returns>A GameGlobal instance containing the resource.</returns> public GameGlobal Get(string filename) { filename = filename.ToLowerInvariant(); lock (Cache) { if (Cache.ContainsKey(filename)) { return(Cache[filename]); } //if we can't load this let it throw an exception... //probably sanity check this when we add user objects. var iff = new IffFile(Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".iff")); OTFFile otf = null; try { otf = new OTFFile(Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".otf")); } catch (IOException) { //if we can't load an otf, it probably doesn't exist. } var resource = new GameGlobalResource(iff, otf); var item = new GameGlobal { Resource = resource }; Cache.Add(filename, item); return(item); } }
public GameObjectResource(IffFile iff, IffFile sprites, OTFFile tuning, string iname, Content content) { this.Iff = iff; this.Sprites = sprites; this.Tuning = tuning; this.Name = iname; if (iff == null) { return; } var GLOBChunks = iff.List <GLOB>(); if (GLOBChunks != null && GLOBChunks[0].Name != "") { GameGlobal sg = null; try { sg = content.WorldObjectGlobals.Get(GLOBChunks[0].Name); } catch (Exception) { } if (sg != null) { SemiGlobal = sg.Resource; //used for tuning constant fetching. } } Recache(); }
/// <summary> /// Gets a resource. /// </summary> /// <param name="filename">The filename of the resource to get.</param> /// <returns>A GameGlobal instance containing the resource.</returns> public GameGlobal Get(string filename) { filename = filename.ToLowerInvariant(); lock (Cache) { if (Cache.ContainsKey(filename)) { return(Cache[filename]); } //if we can't load this let it throw an exception... //probably sanity check this when we add user objects. GameGlobalResource resource = null; if (TS1Provider != null) { var data = TS1Provider.GetEntry( TS1Provider.GetAllEntries().FirstOrDefault(x => x.Key.ToLowerInvariant() == (filename + ".iff").ToLowerInvariant())); if (data != null) { using (var stream = new MemoryStream(data)) { var iff = new IffFile(); iff.Read(stream); iff.InitHash(); iff.SetFilename(filename + ".iff"); resource = new GameGlobalResource(iff, null); } } } else { var iff = new IffFile(Path.Combine(ContentManager.BasePath, "objectdata/globals/" + filename + ".iff")); iff.InitHash(); OTFFile otf = null; try { var rewrite = PIFFRegistry.GetOTFRewrite(filename + ".otf"); otf = new OTFFile(rewrite ?? Path.Combine(ContentManager.BasePath, ("objectdata/globals/" + filename + ".otf"))); } catch (IOException) { //if we can't load an otf, it probably doesn't exist. } resource = new GameGlobalResource(iff, otf); } var item = new GameGlobal { Resource = resource }; Cache.Add(filename, item); return(item); } }
/// <summary> /// Gets a resource. /// </summary> /// <param name="filename">The filename of the resource to get.</param> /// <returns>A GameGlobal instance containing the resource.</returns> public GameGlobal Get(string filename, bool ts1) { string filepath; Files.Formats.IFF.IffFile iff = null; filename = filename.ToLowerInvariant(); lock (Cache) { if (Cache.ContainsKey(filename)) { return(Cache[filename]); } if (!ts1) { filepath = Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".iff"); //if we can't load this let it throw an exception... //probably sanity check this when we add user objects. if (File.Exists(filepath)) { iff = new Files.Formats.IFF.IffFile(filepath); } } if (GlobalFar != null && iff == null) { var Giff = new IffFile(); var bytes = GlobalFar.GetEntry(GlobalFar.GetAllEntries().FirstOrDefault(x => x.Key.ToLowerInvariant() == (filename + ".iff").ToLowerInvariant())); using (var stream = new MemoryStream(bytes)) { Giff.Read(stream); } if (Giff != null) { iff = Giff; } } OTFFile otf = null; try { otf = new OTFFile(Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".otf")); } catch (IOException) { //if we can't load an otf, it probably doesn't exist. } var resource = new GameGlobalResource(iff, otf); var item = new GameGlobal { Resource = resource }; Cache.Add(filename, item); return(item); } }