/// <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);
            }
        }
Esempio n. 2
0
        protected override Func <string, GameObjectResource> GenerateResource(GameObjectReference reference)
        {
            return((fname) =>
            {
                /** Better set this up! **/
                IffFile sprites = null, iff = null;
                OTFFile tuning = null;

                if (reference.Source == GameObjectSource.Far)
                {
                    iff = this.Iffs.Get(reference.FileName + ".iff");
                    iff.InitHash();
                    iff.RuntimeInfo.Path = reference.FileName;
                    if (WithSprites)
                    {
                        sprites = this.Sprites.Get(reference.FileName + ".spf");
                    }
                    var rewrite = PIFFRegistry.GetOTFRewrite(reference.FileName + ".otf");
                    try
                    {
                        tuning = (rewrite != null) ? new OTFFile(rewrite) : this.TuningTables.Get(reference.FileName + ".otf");
                    }
                    catch (Exception)
                    {
                        //if any issues occur loading an otf, just silently ignore it.
                    }
                }
                else
                {
                    iff = new IffFile(reference.FileName);
                    iff.InitHash();
                    iff.RuntimeInfo.Path = reference.FileName;
                    iff.RuntimeInfo.State = IffRuntimeState.Standalone;
                }

                if (iff.RuntimeInfo.State == IffRuntimeState.PIFFPatch)
                {
                    //OBJDs may have changed due to patch. Remove all file references
                    ResetFile(iff);
                }

                iff.RuntimeInfo.UseCase = IffUseCase.Object;
                if (sprites != null)
                {
                    sprites.RuntimeInfo.UseCase = IffUseCase.ObjectSprites;
                }

                return new GameObjectResource(iff, sprites, tuning, reference.FileName, ContentManager);
            });
        }
        protected override Func <string,GameObjectResource> GenerateResource(GameObjectReference reference)
        {
            return((fname) =>
            {
                /** Better set this up! **/
                IffFile iff = null;

                if (reference.Source == GameObjectSource.Far)
                {
                    iff = GameObjects.Get(reference.FileName.ToLower());
                    iff.InitHash();
                    if (iff != null)
                    {
                        iff.RuntimeInfo.Path = reference.FileName;
                    }
                }
                else
                {
                    //unused
                    iff = new IffFile(reference.FileName,reference.Source == GameObjectSource.User);
                    iff.InitHash();
                    iff.RuntimeInfo.Path = reference.FileName;
                    iff.RuntimeInfo.State = IffRuntimeState.Standalone;
                }

                if (iff != null)
                {
                    if (iff != null && iff.RuntimeInfo.State == IffRuntimeState.PIFFPatch)
                    {
                        //OBJDs may have changed due to patch. Remove all file references
                        ResetFile(iff);
                    }
                    iff.RuntimeInfo.UseCase = IffUseCase.Object;
                }

                return new GameObjectResource(iff,null,null,reference.FileName,ContentManager);
            });
        }