Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        public void SetActiveResource(IffChunk chunk, GameIffResource res)
        {
            OTFFile tuning = null;

            if (res is GameObjectResource)
            {
                tuning = ((GameObjectResource)res).Tuning;
            }
            else if (res is GameGlobalResource)
            {
                tuning = ((GameGlobalResource)res).Tuning;
            }
            if (tuning == null)
            {
                XMLDisplay.Text = "No OTF is present for this iff.";
            }
            else
            {
                using (var stream = new StringWriter())
                {
                    var writer = new XmlTextWriter(stream);
                    writer.Formatting  = Formatting.Indented;
                    writer.Indentation = 2;

                    tuning.Document.Save(writer);

                    XMLDisplay.Text = stream.ToString();
                }
            }
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #5
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);
            });
        }
        public GameObjectResource(IffFile iff, IffFile sprites, OTFFile tuning, string name)
        {
            this.Iff     = iff;
            this.Sprites = sprites;
            this.Tuning  = tuning;
            this.Name    = name;

            if (iff == null)
            {
                return;
            }
            var GLOBChunks = iff.List <GLOB>();

            if (GLOBChunks != null && GLOBChunks[0].Name != "")
            {
                var sg = FSO.Content.Content.Get().WorldObjectGlobals.Get(GLOBChunks[0].Name);
                if (sg != null)
                {
                    SemiGlobal = sg.Resource;             //used for tuning constant fetching.
                }
            }
        }
Beispiel #7
0
 public GameGlobalResource(Files.Formats.IFF.IffFile iff, OTFFile tuning)
 {
     this.Iff    = iff;
     this.Tuning = tuning;
 }
Beispiel #8
0
 public GameGlobalResource(IffFile iff, OTFFile tuning)
 {
     this.Iff    = iff;
     this.Tuning = tuning;
 }
Beispiel #9
0
        public GameObjectResource(IffFile iff, IffFile sprites, OTFFile tuning, string iname)
        {
            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 != "")
            {
                var sg = FSO.Content.Content.Get().WorldObjectGlobals.Get(GLOBChunks[0].Name);
                if (sg != null)
                {
                    SemiGlobal = sg.Resource;             //used for tuning constant fetching.
                }
            }

            TreeByName = new Dictionary <string, VMTreeByNameTableEntry>();
            var bhavs = List <BHAV>();

            if (bhavs != null)
            {
                foreach (var bhav in bhavs)
                {
                    string name = bhav.ChunkLabel;
                    for (var i = 0; i < name.Length; i++)
                    {
                        if (name[i] == 0)
                        {
                            name = name.Substring(0, i);
                            break;
                        }
                    }
                    if (!TreeByName.ContainsKey(name))
                    {
                        TreeByName.Add(name, new VMTreeByNameTableEntry(bhav));
                    }
                }
            }
            //also add semiglobals

            if (SemiGlobal != null)
            {
                bhavs = SemiGlobal.List <BHAV>();
                if (bhavs != null)
                {
                    foreach (var bhav in bhavs)
                    {
                        string name = bhav.ChunkLabel;
                        for (var i = 0; i < name.Length; i++)
                        {
                            if (name[i] == 0)
                            {
                                name = name.Substring(0, i);
                                break;
                            }
                        }
                        if (!TreeByName.ContainsKey(name))
                        {
                            TreeByName.Add(name, new VMTreeByNameTableEntry(bhav));
                        }
                    }
                }
            }
        }
Beispiel #10
0
        public GameObject Get(ulong id)
        {
            if (Cache.ContainsKey(id))
            {
                return(Cache[id]);
            }

            lock (Cache)
            {
                if (!Cache.ContainsKey(id))
                {
                    GameObjectReference reference;
                    GameObjectResource  resource = null;

                    lock (Entries)
                    {
                        Entries.TryGetValue(id, out reference);
                        if (reference == null)
                        {
                            //Console.WriteLine("Failed to get Object ID: " + id.ToString() + " (no resource)");
                            return(null);
                        }
                        lock (ProcessedFiles)
                        {
                            //if a file is processed but an object in it is not in the cache, it may have changed.
                            //check for it again!
                            ProcessedFiles.TryGetValue(reference.FileName, out resource);
                        }
                    }

                    if (resource == null)
                    {
                        /** 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.RuntimeInfo.Path = reference.FileName;
                            if (WithSprites)
                            {
                                if (reference.EpObject)
                                {
                                    sprites = this.Sprites.Get(reference.FileName + ".iff");
                                }
                                else
                                {
                                    sprites = this.Sprites.Get(reference.FileName + ".spf");
                                }
                            }


                            tuning = this.TuningTables.Get(reference.FileName + ".otf");
                        }
                        else
                        {
                            iff = new IffFile(reference.FileName);
                            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;
                        }

                        resource = new GameObjectResource(iff, sprites, tuning, reference.FileName);

                        lock (ProcessedFiles)
                        {
                            ProcessedFiles.Add(reference.FileName, resource);
                        }
                    }

                    foreach (var objd in resource.MainIff.List <OBJD>())
                    {
                        var item = new GameObject
                        {
                            GUID     = objd.GUID,
                            OBJ      = objd,
                            Resource = resource
                        };
                        Cache.GetOrAdd(item.GUID, item);
                    }
                    //0x3BAA9787
                    if (!Cache.ContainsKey(id))
                    {
                        // Console.WriteLine("Failed to get Object ID: " + id.ToString() + " from resource " + resource.Name);
                        return(null);
                    }
                    return(Cache[id]);
                }
                return(Cache[id]);
            }
        }
Beispiel #11
0
        /// <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);
            }
        }