Exemplo n.º 1
0
        /// <summary>
        /// Initiates loading of walls.
        /// </summary>
        public void Init()
        {
            var wallGlobalsPath = ContentManager.GetPath("objectdata/globals/walls.iff");

            WallGlobals = new IffFile(wallGlobalsPath);

            var buildGlobalsPath = ContentManager.GetPath("objectdata/globals/build.iff");

            BuildGlobals = new IffFile(buildGlobalsPath); //todo: centralize?

            InitGlobals();
            ushort wallID = 256;

            var archives = new string[]
            {
                "housedata/walls/walls.far",
                "housedata/walls2/walls2.far",
                "housedata/walls3/walls3.far",
                "housedata/walls4/walls4.far"
            };

            for (var i = 0; i < archives.Length; i++)
            {
                var archivePath = ContentManager.GetPath(archives[i]);
                var archive     = new FAR1Archive(archivePath, true);
                var entries     = archive.GetAllEntries();

                foreach (var entry in entries)
                {
                    var iff = new IffFile();
                    DynamicWallFromID[new string(entry.Key.TakeWhile(x => x != '.').ToArray()).ToLowerInvariant()] = wallID;
                    var bytes = archive.GetEntry(entry);
                    using (var stream = new MemoryStream(bytes))
                    {
                        iff.Read(stream);
                    }

                    var catStrings = iff.Get <STR>(0);

                    Entries.Add(wallID, new WallReference(this)
                    {
                        ID       = wallID,
                        FileName = entry.Key,

                        Name        = catStrings.GetString(0),
                        Price       = int.Parse(catStrings.GetString(1)),
                        Description = catStrings.GetString(2)
                    });

                    wallID++;
                }
                archive.Close();
            }

            var far1 = new FAR1Provider <IffFile>(ContentManager, new IffCodec(), new Regex(".*/walls.*\\.far"));

            far1.Init();
            Walls    = far1;
            NumWalls = wallID;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initiates loading of world objects.
        /// </summary>
        public void Init()
        {
            Iffs         = new FAR1Provider <Iff>(ContentManager, new IffCodec(), "objectdata\\objects\\objiff.far");
            Sprites      = new FAR1Provider <Iff>(ContentManager, new IffCodec(), new Regex(".*\\\\objspf.*\\.far"));
            TuningTables = new FAR1Provider <OTF>(ContentManager, new OTFCodec(), new Regex(".*\\\\objotf.*\\.far"));

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

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

            var packingslip = new XmlDataDocument();

            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
                });
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new cache for loading of globals.
        /// </summary>
        public void Init()
        {
            Cache = new Dictionary <string, GameGlobal>();

            List <string> GlobalFiles = new List <string>();

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/Global"))
            {
                GlobalFiles.Add(FSOEnvironment.SimsCompleteDir + "/Global/Global.far");

                GlobalIffs = new FAR1Provider <Files.Formats.IFF.IffFile>(ContentManager, new IffCodec(), GlobalFiles.ToArray());

                GlobalIffs.Init();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initiates loading of walls.
        /// </summary>
        public void Init()
        {
            WallStyleToIndex = WallStyleIDs.ToDictionary(x => x, x => Array.IndexOf(WallStyleIDs, x));

            this.Entries    = new Dictionary <ushort, WallReference>();
            this.ById       = new Dictionary <ushort, Wall>();
            this.StyleById  = new Dictionary <ushort, WallStyle>();
            this.WallStyles = new List <WallStyle>();

            var wallGlobalsPath = ContentManager.GetPath("objectdata/globals/walls.iff");

            WallGlobals = new IffFile(wallGlobalsPath);

            var buildGlobalsPath = ContentManager.GetPath("objectdata/globals/build.iff");
            var buildGlobals     = new IffFile(buildGlobalsPath); //todo: centralize?

            /** Get wall styles from globals file **/
            var    styleStrs = buildGlobals.Get <STR>(0x81);
            ushort wallID    = 1;

            for (ushort i = 2; i < 512; i += 2)
            {
                var far    = WallGlobals.Get <SPR>((ushort)(i));
                var medium = WallGlobals.Get <SPR>((ushort)(i + 512));
                var near   = WallGlobals.Get <SPR>((ushort)(i + 1024));

                var fard    = WallGlobals.Get <SPR>((ushort)(i + 1));
                var mediumd = WallGlobals.Get <SPR>((ushort)(i + 513));
                var neard   = WallGlobals.Get <SPR>((ushort)(i + 1025));

                if (fard == null)
                { //no walls down, just render exactly the same
                    fard    = far;
                    mediumd = medium;
                    neard   = near;
                }

                string name = null, description = null;
                int    price    = -1;
                int    buyIndex = -1;
                WallStyleToIndex.TryGetValue(wallID, out buyIndex);

                if (buyIndex != -1)
                {
                    price       = int.Parse(styleStrs.GetString(buyIndex * 3));
                    name        = styleStrs.GetString(buyIndex * 3 + 1);
                    description = styleStrs.GetString(buyIndex * 3 + 2);
                }

                this.AddWallStyle(new WallStyle
                {
                    ID              = wallID,
                    WallsUpFar      = far,
                    WallsUpMedium   = medium,
                    WallsUpNear     = near,
                    WallsDownFar    = fard,
                    WallsDownMedium = mediumd,
                    WallsDownNear   = neard,

                    Price       = price,
                    Name        = name,
                    Description = description
                });

                wallID++;
            }

            DynamicStyleID = 256; //styles loaded from objects start at 256. The objd reference is dynamically altered to reference this new id,
            //so only refresh wall cache at same time as obj cache! (do this on lot unload)

            /** Get wall patterns from globals file **/
            var wallStrs = buildGlobals.Get <STR>(0x83);

            wallID = 0;
            for (ushort i = 0; i < 256; i++)
            {
                var far    = WallGlobals.Get <SPR>((ushort)(i + 1536));
                var medium = WallGlobals.Get <SPR>((ushort)(i + 1536 + 256));
                var near   = WallGlobals.Get <SPR>((ushort)(i + 1536 + 512));

                this.AddWall(new Wall
                {
                    ID     = wallID,
                    Far    = far,
                    Medium = medium,
                    Near   = near,
                });

                if (i > 0 && i < (wallStrs.Length / 3) + 1)
                {
                    Entries.Add(wallID, new WallReference(this)
                    {
                        ID       = wallID,
                        FileName = "global",

                        Name        = wallStrs.GetString((i - 1) * 3 + 1),
                        Price       = int.Parse(wallStrs.GetString((i - 1) * 3 + 0)),
                        Description = wallStrs.GetString((i - 1) * 3 + 2)
                    });
                }

                wallID++;
            }

            Junctions = new Wall
            {
                ID     = wallID,
                Far    = WallGlobals.Get <SPR>(4096),
                Medium = WallGlobals.Get <SPR>(4097),
                Near   = WallGlobals.Get <SPR>(4098),
            };

            wallID = 256;

            var archives = new string[]
            {
                "housedata/walls/walls.far",
                "housedata/walls2/walls2.far",
                "housedata/walls3/walls3.far",
                "housedata/walls4/walls4.far"
            };

            DynamicWallFromID = new Dictionary <string, ushort>();

            for (var i = 0; i < archives.Length; i++)
            {
                var archivePath = ContentManager.GetPath(archives[i]);
                var archive     = new FAR1Archive(archivePath, true);
                var entries     = archive.GetAllEntries();

                foreach (var entry in entries)
                {
                    var iff = new IffFile();
                    DynamicWallFromID[new string(entry.Key.TakeWhile(x => x != '.').ToArray()).ToLowerInvariant()] = wallID;
                    var bytes = archive.GetEntry(entry);
                    using (var stream = new MemoryStream(bytes))
                    {
                        iff.Read(stream);
                    }

                    var catStrings = iff.Get <STR>(0);

                    Entries.Add(wallID, new WallReference(this)
                    {
                        ID       = wallID,
                        FileName = entry.Key,

                        Name        = catStrings.GetString(0),
                        Price       = int.Parse(catStrings.GetString(1)),
                        Description = catStrings.GetString(2)
                    });

                    wallID++;
                }
                archive.Close();
            }

            this.Walls = new FAR1Provider <IffFile>(ContentManager, new IffCodec(), new Regex(".*/walls.*\\.far"));
            Walls.Init();
            NumWalls = wallID;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initiates loading of world objects.
        /// </summary>
        public void Init(bool withSprites)
        {
            List <string> FarFiles    = new List <string>();
            List <string> SpriteFiles = new List <string>();

            WithSprites = withSprites;

            for (int i = 1; i <= 9; i++)
            {
                SpriteFiles.Add("objectdata/objects/objspf" + i + ".far");
            }

            FarFiles.Add("objectdata/objects/objiff.far");

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

            var packingslip = new XmlDocument();

            packingslip.Load("Content/objects.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),
                    EpObject = false
                });
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack"))
            {
                string EpFile = FSOEnvironment.SimsCompleteDir + "/ExpansionPack/ExpansionPack.far";
                FarFiles.Add(EpFile);
                SpriteFiles.Add(EpFile);



                var ep1objects = new XmlDocument();
                ep1objects.Load("Content/ep1.xml");
                var objectInfos1 = ep1objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos1)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack2"))
            {
                string Ep2File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack2/ExpansionPack2.far";
                FarFiles.Add(Ep2File);
                SpriteFiles.Add(Ep2File);



                var ep2objects = new XmlDocument();
                ep2objects.Load("Content/ep2.xml");
                var objectInfos2 = ep2objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos2)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack3"))
            {
                string Ep3File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack3/ExpansionPack3.far";
                FarFiles.Add(Ep3File);
                SpriteFiles.Add(Ep3File);



                var ep3objects = new XmlDocument();
                ep3objects.Load("Content/ep3.xml");
                var objectInfos3 = ep3objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos3)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }


            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack4"))
            {
                string Ep4File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack4/ExpansionPack4.far";
                FarFiles.Add(Ep4File);
                SpriteFiles.Add(Ep4File);



                var ep4objects = new XmlDocument();
                ep4objects.Load("Content/ep4.xml");
                var objectInfos4 = ep4objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos4)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack5"))
            {
                string Ep5File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack5/ExpansionPack5.far";
                FarFiles.Add(Ep5File);
                SpriteFiles.Add(Ep5File);



                var ep5objects = new XmlDocument();
                ep5objects.Load("Content/ep5.xml");
                var objectInfos5 = ep5objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos5)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }


            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack6"))
            {
                string Ep6File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack6/ExpansionPack6.far";
                FarFiles.Add(Ep6File);
                SpriteFiles.Add(Ep6File);



                var ep6objects = new XmlDocument();
                ep6objects.Load("Content/ep6.xml");
                var objectInfos6 = ep6objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos6)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack7"))
            {
                string Ep7File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack7/ExpansionPack7.far";
                FarFiles.Add(Ep7File);
                SpriteFiles.Add(Ep7File);



                var ep7objects = new XmlDocument();
                ep7objects.Load("Content/ep7.xml");
                var objectInfos7 = ep7objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos7)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            StreamWriter writer = new StreamWriter("entries.txt");

            foreach (var entry in Entries)
            {
                writer.WriteLine(entry.Key.ToString("X") + "-" + entry.Value.FileName);
            }
            writer.Close();

            Iffs = new FAR1Provider <IffFile>(ContentManager, new IffCodec(), FarFiles.ToArray());

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

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

            if (withSprites)
            {
                Sprites = new FAR1Provider <IffFile>(ContentManager, new IffCodec(), SpriteFiles.ToArray());
                Sprites.Init();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initiates loading of world objects.
        /// </summary>
        public void Init(bool withSprites)
        {
            List <string> FarFiles    = new List <string>();
            List <string> SpriteFiles = new List <string>();

            WithSprites = withSprites;

            for (int i = 1; i <= 9; i++)
            {
                SpriteFiles.Add("objectdata/objects/objspf" + i + ".far");
            }

            FarFiles.Add("objectdata/objects/objiff.far");

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

            var packingslip = new XmlDocument();

            packingslip.Load("Content/objects.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),
                    EpObject = false
                });
            }

            if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Content/Objects"))
            {
                string GFile = AppDomain.CurrentDomain.BaseDirectory + "Content/Objects/npcs.far";
                FarFiles.Add(GFile);
                SpriteFiles.Add(GFile);

                var gobjects = new XmlDocument();
                gobjects.Load("Content/npc.xml");
                var nobjectInfos = gobjects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in nobjectInfos)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }


            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack"))
            {
                string EpFile = FSOEnvironment.SimsCompleteDir + "/ExpansionPack/ExpansionPack.far";
                FarFiles.Add(EpFile);
                SpriteFiles.Add(EpFile);



                var ep1objects = new XmlDocument();
                ep1objects.Load("Content/ep1.xml");
                var objectInfos1 = ep1objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos1)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack2"))
            {
                string Ep2File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack2/ExpansionPack2.far";
                FarFiles.Add(Ep2File);
                SpriteFiles.Add(Ep2File);



                var ep2objects = new XmlDocument();
                ep2objects.Load("Content/ep2.xml");
                var objectInfos2 = ep2objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos2)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack3"))
            {
                string Ep3File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack3/ExpansionPack3.far";
                FarFiles.Add(Ep3File);
                SpriteFiles.Add(Ep3File);



                var ep3objects = new XmlDocument();
                ep3objects.Load("Content/ep3.xml");
                var objectInfos3 = ep3objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos3)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }


            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack4"))
            {
                string Ep4File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack4/ExpansionPack4.far";
                FarFiles.Add(Ep4File);
                SpriteFiles.Add(Ep4File);



                var ep4objects = new XmlDocument();
                ep4objects.Load("Content/ep4.xml");
                var objectInfos4 = ep4objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos4)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack5"))
            {
                string Ep5File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack5/ExpansionPack5.far";
                FarFiles.Add(Ep5File);
                SpriteFiles.Add(Ep5File);



                var ep5objects = new XmlDocument();
                ep5objects.Load("Content/ep5.xml");
                var objectInfos5 = ep5objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos5)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }


            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack6"))
            {
                string Ep6File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack6/ExpansionPack6.far";
                FarFiles.Add(Ep6File);
                SpriteFiles.Add(Ep6File);



                var ep6objects = new XmlDocument();
                ep6objects.Load("Content/ep6.xml");
                var objectInfos6 = ep6objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos6)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/ExpansionPack7"))
            {
                string Ep7File = FSOEnvironment.SimsCompleteDir + "/ExpansionPack7/ExpansionPack7.far";
                FarFiles.Add(Ep7File);
                SpriteFiles.Add(Ep7File);



                var ep7objects = new XmlDocument();
                ep7objects.Load("Content/ep7.xml");
                var objectInfos7 = ep7objects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos7)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            if (Directory.Exists(FSOEnvironment.SimsCompleteDir + "/Downloads"))
            {
                DirectoryInfo downloadsDir = new DirectoryInfo(FSOEnvironment.SimsCompleteDir + "/Downloads");

                foreach (DirectoryInfo dir in downloadsDir.GetDirectories())
                {
                    if (dir.GetFiles().Count() > 0)
                    {
                        foreach (FileInfo file in dir.GetFiles())
                        {
                            if (file.Extension == ".far")
                            {
                                FarFiles.Add(file.FullName);
                            }
                        }
                    }
                }

                var dobjects = new XmlDocument();
                dobjects.Load("Content/downloads.xml");
                var objectInfos8 = dobjects.GetElementsByTagName("P");

                foreach (XmlNode objectInfo in objectInfos8)
                {
                    ulong FileID = Convert.ToUInt32(objectInfo.Attributes["g"].Value, 16);

                    if (!Entries.ContainsKey(FileID))
                    {
                        Entries.Add(FileID, new GameObjectReference(this)
                        {
                            ID       = FileID,
                            FileName = objectInfo.Attributes["n"].Value,
                            Source   = GameObjectSource.Far,
                            Group    = Convert.ToInt16(objectInfo.Attributes["m"].Value),
                            SubIndex = Convert.ToInt16(objectInfo.Attributes["i"].Value),
                            EpObject = true
                        });
                    }
                }
            }

            Iffs = new FAR1Provider <Files.Formats.IFF.IffFile>(ContentManager, new IffCodec(), FarFiles.ToArray());

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

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

            if (withSprites)
            {
                Sprites = new FAR1Provider <Files.Formats.IFF.IffFile>(ContentManager, new IffCodec(), SpriteFiles.ToArray());
                Sprites.Init();
            }


            //init local objects, piff clones
            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
                    });
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initiates loading of floors.
        /// </summary>
        public void Init()
        {
            this.Entries            = new Dictionary <ushort, FloorReference>();
            this.ById               = new Dictionary <ushort, Floor>();
            this.DynamicFloorFromID = new Dictionary <string, ushort>();

            var floorGlobalsPath = ContentManager.GetPath("objectdata/globals/floors.iff");
            var floorGlobals     = new Files.Formats.IFF.IffFile(floorGlobalsPath);

            FloorGlobals = floorGlobals;

            var buildGlobalsPath = ContentManager.GetPath("objectdata/globals/build.iff");
            var buildGlobals     = new Files.Formats.IFF.IffFile(buildGlobalsPath); //todo: centralize?

            /** There is a small handful of floors in a global file for some reason **/
            ushort floorID   = 1;
            var    floorStrs = buildGlobals.Get <STR>(0x83);

            for (ushort i = 1; i < (floorStrs.Length / 3); i++)
            {
                var far    = floorGlobals.Get <SPR2>(i);
                var medium = floorGlobals.Get <SPR2>((ushort)(i + 256));
                var near   = floorGlobals.Get <SPR2>((ushort)(i + 512)); //2048 is water tile

                this.AddFloor(new Floor
                {
                    ID     = floorID,
                    Far    = far,
                    Medium = medium,
                    Near   = near
                });

                Entries.Add(floorID, new FloorReference(this)
                {
                    ID       = floorID,
                    FileName = "global",

                    Name        = floorStrs.GetString((i - 1) * 3 + 1),
                    Price       = int.Parse(floorStrs.GetString((i - 1) * 3 + 0)),
                    Description = floorStrs.GetString((i - 1) * 3 + 2)
                });

                floorID++;
            }

            var waterStrs = buildGlobals.Get <STR>(0x85);

            //add pools for catalog logic
            Entries.Add(65535, new FloorReference(this)
            {
                ID       = 65535,
                FileName = "global",

                Price       = int.Parse(waterStrs.GetString(0)),
                Name        = waterStrs.GetString(1),
                Description = waterStrs.GetString(2)
            });

            floorID = 256;

            var archives = new string[]
            {
                "housedata/floors/floors.far",
                "housedata/floors2/floors2.far",
                "housedata/floors3/floors3.far",
                "housedata/floors4/floors4.far"
            };

            for (var i = 0; i < archives.Length; i++)
            {
                var archivePath = ContentManager.GetPath(archives[i]);
                var archive     = new FAR1Archive(archivePath, true);
                var entries     = archive.GetAllEntries();

                foreach (var entry in entries)
                {
                    var iff = new Files.Formats.IFF.IffFile();
                    DynamicFloorFromID[new string(entry.Key.TakeWhile(x => x != '.').ToArray()).ToLowerInvariant()] = floorID;
                    var bytes = archive.GetEntry(entry);
                    using (var stream = new MemoryStream(bytes))
                    {
                        iff.Read(stream);
                    }


                    var catStrings = iff.Get <STR>(0);

                    Entries.Add(floorID, new FloorReference(this)
                    {
                        ID       = floorID,
                        FileName = entry.Key,

                        Name        = catStrings.GetString(0),
                        Price       = int.Parse(catStrings.GetString(1)),
                        Description = catStrings.GetString(2)
                    });

                    floorID++;
                }
                archive.Close();
            }

            NumFloors   = floorID;
            this.Floors = new FAR1Provider <Files.Formats.IFF.IffFile>(ContentManager, new IffCodec(), new Regex(".*/floors.*\\.far"));
            Floors.Init();
        }
Exemplo n.º 8
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
                    });
                }
            }
        }
Exemplo n.º 9
0
 public TS1Provider(Content contentManager, GraphicsDevice device)
 {
     FarProvider = new FAR1Provider <object>(contentManager, null, new Regex(@".*\.far"));
     //todo: files provider?
 }