예제 #1
0
        public void Init()
        {
            if (Initialized)
            {
                return;
            }
            Initialized = true;
            Cache       = new TimedReferenceCache <ulong, T>();
            lock (Cache)
            {
                EntriesById   = new Dictionary <ulong, Far3ProviderEntry <T> >();
                EntriesByName = new Dictionary <string, Far3ProviderEntry <T> >();

                if (FarFilePattern != null)
                {
                    List <string> FarFiles = new List <string>();
                    foreach (var File in ContentManager.AllFiles)
                    {
                        if (FarFilePattern.IsMatch(File.Replace('\\', '/')))
                        {
                            FarFiles.Add(File);
                        }
                    }

                    m_FarFiles = FarFiles.ToArray();
                }

                foreach (var FarPath in m_FarFiles)
                {
                    var archive = new FAR3Archive(ContentManager.GetPath(FarPath));
                    var entries = archive.GetAllFAR3Entries();

                    foreach (var entry in entries)
                    {
                        var fileID = ((ulong)entry.FileID) << 32;

                        var referenceItem = new Far3ProviderEntry <T>(this)
                        {
                            ID       = fileID | entry.TypeID,
                            Archive  = archive,
                            FarEntry = entry
                        };

                        EntriesById.Add(referenceItem.ID, referenceItem);
                        if (entry.Filename != null)
                        {
                            EntriesByName[entry.Filename.ToLowerInvariant()] = referenceItem;
                        }
                    }
                }
            }
        }
예제 #2
0
        public void Init()
        {
            Cache         = new TimedReferenceCache <string, T>();
            EntriesByName = new Dictionary <string, Far1ProviderEntry <T> >();
            EntriesOfType = new Dictionary <string, List <Far1ProviderEntry <T> > >();

            if (FarFilePattern != null)
            {
                List <string> farFiles = new List <string>();
                string[]      allFiles = (TS1) ? ContentManager.TS1AllFiles : ContentManager.AllFiles;
                foreach (var file in allFiles)
                {
                    if (FarFilePattern.IsMatch(file.Replace('\\', '/')))
                    {
                        farFiles.Add(file);
                    }
                }
                FarFiles = farFiles.ToArray();
            }

            foreach (var farPath in FarFiles)
            {
                var archive = new FAR1Archive((TS1)?Path.Combine(ContentManager.TS1BasePath, farPath):ContentManager.GetPath(farPath), !TS1);
                var entries = archive.GetAllFarEntries();

                foreach (var entry in entries)
                {
                    var referenceItem = new Far1ProviderEntry <T>(this)
                    {
                        Archive  = archive,
                        FarEntry = entry
                    };
                    if (entry.Filename != null)
                    {
                        EntriesByName[entry.Filename] = referenceItem;
                        var ext = Path.GetExtension(entry.Filename).ToLowerInvariant();
                        List <Far1ProviderEntry <T> > group = null;
                        if (!EntriesOfType.TryGetValue(ext, out group))
                        {
                            group = new List <Far1ProviderEntry <T> >();
                            EntriesOfType[ext] = group;
                        }
                        group.Add(referenceItem);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Initiates loading of world objects.
        /// </summary>
        public void Init(bool withSprites)
        {
            WithSprites = withSprites;
            Iffs        = new FAR1Provider <IffFile>(ContentManager, new IffCodec(), "objectdata/objects/objiff.far");

            TuningTables = new FAR1Provider <OTFFile>(ContentManager, new OTFCodec(), new Regex(".*/objotf.*\\.far"));

            Iffs.Init();
            TuningTables.Init();

            if (withSprites)
            {
                Sprites = new FAR1Provider <IffFile>(ContentManager, new IffCodec(), new Regex(".*/objspf.*\\.far"));
                Sprites.Init();
            }

            /** Load packingslip **/
            Entries = new Dictionary <ulong, GameObjectReference>();
            Cache   = new TimedReferenceCache <ulong, GameObject>();

            var packingslip = new XmlDocument();

            packingslip.Load(ContentManager.GetPath("packingslips/objecttable.xml"));
            var objectInfos = packingslip.GetElementsByTagName("I");

            foreach (XmlNode objectInfo in objectInfos)
            {
                ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);
                Entries.Add(FileID, new GameObjectReference(this)
                {
                    ID       = FileID,
                    FileName = objectInfo.Attributes["n"].Value,
                    Source   = GameObjectSource.Far,
                    Name     = objectInfo.Attributes["o"].Value,
                    Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                    SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value)
                });
            }

            //init local objects, piff clones

            //Directory.CreateDirectory(Path.Combine(FSOEnvironment.ContentDir, "Objects"));
            string[] paths = Directory.GetFiles(Path.Combine(FSOEnvironment.ContentDir, "Objects"), "*.iff", SearchOption.AllDirectories);
            for (int i = 0; i < paths.Length; i++)
            {
                string  entry    = paths[i];
                string  filename = Path.GetFileName(entry);
                IffFile iffFile  = new IffFile(entry);

                var objs = iffFile.List <OBJD>();
                foreach (var obj in objs)
                {
                    Entries.Add(obj.GUID, new GameObjectReference(this)
                    {
                        ID       = obj.GUID,
                        FileName = entry,
                        Source   = GameObjectSource.Standalone,
                        Name     = obj.ChunkLabel,
                        Group    = (short)obj.MasterID,
                        SubIndex = obj.SubIndex
                    });
                }
            }
        }
예제 #4
0
        public void Init()
        {
            GameObjects.Init();

            Entries = new Dictionary <ulong, GameObjectReference>();
            Cache   = new TimedReferenceCache <ulong, GameObject>();

            ItemsByGUID     = new Dictionary <uint, ObjectCatalogItem>();
            ItemsByCategory = new List <ObjectCatalogItem> [30];
            for (int i = 0; i < 30; i++)
            {
                ItemsByCategory[i] = new List <ObjectCatalogItem>();
            }

            var allIffs = GameObjects.ListGeneric();

            foreach (var iff in allIffs)
            {
                var file = (IffFile)iff.GetThrowawayGeneric();
                file.MarkThrowaway();
                var objects = file.List <OBJD>();
                var slots   = file.List <SLOT>();
                if (objects != null)
                {
                    foreach (var obj in objects)
                    {
                        Entries[obj.GUID] = new GameObjectReference(this)
                        {
                            FileName        = Path.GetFileName(iff.ToString().Replace('\\','/')),
                            ID              = obj.GUID,
                            Name            = obj.ChunkLabel,
                            Source          = GameObjectSource.Far,
                            Group           = (short)obj.MasterID,
                            SubIndex        = obj.SubIndex,
                            GlobalSimObject = obj.ObjectType == OBJDType.SimType && obj.Global == 1
                        };
                        if (obj.ObjectType == OBJDType.Person)
                        {
                            PersonGUIDs.Add(obj.GUID);
                        }

                        //does this object appear in the catalog?
                        if ((obj.FunctionFlags > 0 || obj.BuildModeType > 0) && obj.Disabled == 0 && (obj.MasterID == 0 || obj.SubIndex == -1))
                        {
                            //todo: more than one of these set? no normal game objects do this
                            //todo: room sort
                            var cat = (sbyte)Math.Log(obj.FunctionFlags,2);
                            if (obj.FunctionFlags == 0)
                            {
                                cat = (sbyte)(obj.BuildModeType + 7);
                            }
                            var item = new ObjectCatalogItem()
                            {
                                Category     = (sbyte)(cat), //0-7 buy categories. 8-15 build mode categories
                                GUID         = obj.GUID,
                                DisableLevel = 0,
                                Price        = obj.Price,
                                Name         = obj.ChunkLabel,

                                Subsort        = (byte)obj.FunctionSubsort,
                                CommunitySort  = (byte)obj.CommunitySubsort,
                                DowntownSort   = (byte)obj.DTSubsort,
                                MagictownSort  = (byte)obj.MTSubsort,
                                StudiotownSort = (byte)obj.STSubsort,
                                VacationSort   = (byte)obj.VacationSubsort
                            };
                            ItemsByCategory[item.Category].Add(item);
                            ItemsByGUID[item.GUID] = item;
                        }
                    }
                }
            }

            var globalSims = Entries.Values.Where(x => x.GlobalSimObject);

            ControllerObjects.Clear();
            ControllerObjects.AddRange(globalSims);

            ContentManager.Neighborhood.LoadCharacters(false);
        }
예제 #5
0
        public void Init()
        {
            GameObjects.Init();

            Entries = new Dictionary<ulong, GameObjectReference>();
            Cache = new TimedReferenceCache<ulong, GameObject>();

            ItemsByGUID = new Dictionary<uint, ObjectCatalogItem>();
            ItemsByCategory = new List<ObjectCatalogItem>[30];
            for (int i = 0; i < 30; i++) ItemsByCategory[i] = new List<ObjectCatalogItem>();

            var allIffs = GameObjects.ListGeneric();
            foreach (var iff in allIffs)
            {
                var file = (IffFile)iff.GetThrowawayGeneric();
                file.MarkThrowaway();
                var objects = file.List<OBJD>();
                if (objects != null)
                {
                    foreach (var obj in objects)
                    {
                        Entries.Add(obj.GUID, new GameObjectReference(this)
                        {
                            FileName = iff.ToString(),
                            ID = obj.GUID,
                            Name = obj.ChunkLabel,
                            Source = GameObjectSource.Far,
                            Group = (short)obj.MasterID,
                            SubIndex = obj.SubIndex
                        });

                        //does this object appear in the catalog?
                        if (obj.FunctionFlags > 0 && (obj.MasterID == 0 || obj.SubIndex == -1))
                        {
                            var cat = (sbyte)Math.Log(obj.FunctionFlags, 2);
                            var item = new ObjectCatalogItem()
                            {
                                Category = (sbyte)(cat + 11), //debug for now
                                GUID = obj.GUID,
                                DisableLevel = 0,
                                Price = obj.Price,
                                Name = obj.ChunkLabel
                            };
                            ItemsByCategory[item.Category].Add(item);
                            ItemsByGUID[item.GUID] = item;
                        }
                    }
                }
            }

            var path = Path.Combine(ContentManager.TS1BasePath, "UserData/Characters/");
            var files = Directory.EnumerateFiles(path);
            foreach (var filename in files)
            {
                if (Path.GetExtension(filename) != ".iff") return;
                var file = new IffFile(filename);
                file.MarkThrowaway();
                var objects = file.List<OBJD>();
                if (objects != null)
                {
                    foreach (var obj in objects)
                    {
                        Entries.Add(obj.GUID, new GameObjectReference(this)
                        {
                            FileName = filename,
                            ID = obj.GUID,
                            Name = obj.ChunkLabel,
                            Source = GameObjectSource.Standalone,
                            Group = (short)obj.MasterID,
                            SubIndex = obj.SubIndex
                        });
                    }
                }
            }
        }