示例#1
0
        private void LoadHouse(string path)
        {
            FileInfo housefile = new FileInfo(path);

            label5.Text = housefile.Name;

            IffFile iff = new IffFile(path);

            foreach (BMP bmp in iff.List <BMP>())
            {
                if (bmp.ChunkID == 512)
                {
                    pictureBox1.BackgroundImage = bmp.GetBitmap();
                }
            }

            foreach (OBJT obj in iff.List <OBJT>())
            {
                var entries = obj.Entries;

                foreach (OBJTEntry entry in entries)
                {
                    if (entry.Name != null)
                    {
                        listBox4.Items.Add(entry.Name);
                    }
                }
            }
        }
示例#2
0
        public TS1NeighborhoodProvider(Content contentManager)
        {
            ContentManager = contentManager;
            MainResource   = new IffFile(Path.Combine(contentManager.TS1BasePath, "UserData/Neighborhood.iff"));
            LotLocations   = new IffFile(Path.Combine(contentManager.TS1BasePath, "UserData/LotLocations.iff"));
            var lotZoning = new IffFile(Path.Combine(contentManager.TS1BasePath, "UserData/LotZoning.iff"));

            var zones = lotZoning.Get <STR>(1);

            for (int i = 0; i < zones.Length; i++)
            {
                var split = zones.GetString(i).Split(',');
                ZoningDictionary[short.Parse(split[0])] = (short)((split[1] == " community") ? 1 : 0);
            }
            Neighbors    = MainResource.List <NBRS>().FirstOrDefault();
            Neighborhood = MainResource.List <NGBH>().FirstOrDefault();

            FamilyForHouse = new Dictionary <short, FAMI>();
            var families = MainResource.List <FAMI>();

            foreach (var fam in families)
            {
                FamilyForHouse[(short)fam.HouseNumber] = fam;
            }
        }
示例#3
0
        public void ResetFile(IffFile iff)
        {
            lock (Entries)
            {
                var ToRemove = new List <uint>();
                foreach (var objt in Entries)
                {
                    var obj = objt.Value;
                    if (obj.FileName == iff.RuntimeInfo.Path)
                    {
                        ToRemove.Add((uint)objt.Key);
                    }
                }
                foreach (var guid in ToRemove)
                {
                    Entries.Remove(guid);
                }

                //add all OBJDs
                var list = iff.List <OBJD>();
                if (list != null)
                {
                    foreach (var obj in list)
                    {
                        AddObject(iff, obj);
                    }
                }
            }
        }
示例#4
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();
        }
示例#5
0
        public void Render()
        {
            EntryList.Items.Clear();

            PIFFName.Enabled    = ActivePIFF != null;
            PIFFComment.Enabled = ActivePIFF != null;
            if (ActivePIFF != null)
            {
                var piffs = ActivePIFF.List <PIFF>();
                if ((piffs?.Count ?? 0) == 0)
                {
                    RenderEmpty(); return;
                }
                var piff = piffs[0];
                ActivePIFFChunk = piff;

                PIFFName.Text    = ActivePIFF.Filename;
                PIFFComment.Text = piff.Comment;

                PIFFBox.Enabled = true;

                foreach (var entry in piff.Entries)
                {
                    EntryList.Items.Add(new PIFFListItem(entry, ActiveIff));
                }
            }
            else
            {
                PIFFName.Text    = "None";
                PIFFComment.Text = "Make changes and save then using the volcanic main window to view or edit the PIFF.";
            }
        }
        public void LoadCharacters(bool clearLast)
        {
            var objs = (TS1ObjectProvider)ContentManager.WorldObjects;

            if (objs.Entries == null)
            {
                return;
            }
            if (clearLast)
            {
                foreach (var obj in objs.Entries.Where(x => x.Value.Source == GameObjectSource.User))
                {
                    objs.RemoveObject((uint)obj.Key);
                    objs.PersonGUIDs.Add((uint)obj.Key);
                }
            }

            NextSim = 0;
            var path  = Path.Combine(UserPath, "Characters/");
            var files = Directory.EnumerateFiles(path);

            foreach (var filename in files)
            {
                if (Path.GetExtension(filename) != ".iff")
                {
                    return;
                }

                int userID;
                var name = Path.GetFileName(filename);
                if (name.Length > 8 && int.TryParse(name.Substring(4, 5), out userID) && userID >= NextSim)
                {
                    NextSim = userID + 1;
                }

                var file = new IffFile(filename);
                file.MarkThrowaway();

                var objects = file.List <OBJD>();
                if (objects != null)
                {
                    foreach (var obj in objects)
                    {
                        objs.Entries[obj.GUID] = new GameObjectReference(objs)
                        {
                            FileName = filename,
                            ID       = obj.GUID,
                            Name     = obj.ChunkLabel,
                            Source   = GameObjectSource.User,
                            Group    = (short)obj.MasterID,
                            SubIndex = obj.SubIndex
                        };
                        if (obj.ObjectType == OBJDType.Person)
                        {
                            objs.PersonGUIDs.Add(obj.GUID);
                        }
                    }
                }
            }
        }
示例#7
0
        public void Print <T>(IffFile iff)
        {
            var type  = typeof(T);
            var items = iff.List <T>();

            if (items == null)
            {
                return;
            }

            if (type == typeof(SPR2))
            {
                Printer.H1("SPR2");
                foreach (var item in items)
                {
                    PrintSPR2((SPR2)(object)item);
                }
            }
            else if (type == typeof(OBJD))
            {
                Printer.H1("OBJD");
                foreach (var item in items)
                {
                    PrintOBJD((OBJD)(object)item);
                }
            }
            else if (type == typeof(SPR))
            {
                Printer.H1("SPR");
                foreach (var item in items)
                {
                    PrintSPR((SPR)(object)item);
                }
            }
        }
示例#8
0
        private void openExternalIffToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.Title = "Select an iff file. (iff)";
            SaveFile(dialog);
            try
            {
                var iff = new IffFile(dialog.FileName);
                iff.TSBO = true;
                var obj = new GameObject();
                obj.OBJ  = iff.List <OBJD>()?.FirstOrDefault() ?? new OBJD();
                obj.GUID = obj.OBJ.GUID;

                //var res = new GameObjectResource(iff, null, null, "what", Content.Content.Get());
                var res  = new GameObjectResource(iff, null, null, "what", Content.Content.Get());
                var res2 = new GameGlobalResource(iff, null);
                obj.Resource = res;

                IffManager.OpenResourceWindow(res2, obj);
            }
            catch
            {
            }
        }
        public override bool Execute(VM vm)
        {
            //the client should ignore these. Can be sent before state sync when joining job lots (by accident)
            if (!vm.BlueprintRestore)
            {
                return(true);
            }

            vm.SetGlobalValue(11, JobLevel); //set job level beforehand

            if (IffData)
            {
                var iff = new IffFile();
                using (var stream = new MemoryStream(XMLData))
                {
                    iff.Read(stream);
                }
                var fsov = iff.List <FSOV>()?.FirstOrDefault();
                if (fsov != null)
                {
                    var marshal = new VMMarshal();
                    using (var read = new BinaryReader(new MemoryStream(fsov.Data)))
                        marshal.Deserialize(read);
                    vm.Load(marshal);
                }
                else
                {
                    var activator = new VMTS1Activator(vm, vm.Context.World, JobLevel);
                    var blueprint = activator.LoadFromIff(iff);
                }
                var entClone = new List <VMEntity>(vm.Entities);
                foreach (var nobj in entClone)
                {
                    nobj.ExecuteEntryPoint(2, vm.Context, true);
                }
                vm.TS1State.VerifyFamily(vm);
            }
            else
            {
                XmlHouseData lotInfo;
                using (var stream = new MemoryStream(XMLData))
                {
                    lotInfo = XmlHouseData.Parse(stream);
                }

                var activator = new VMWorldActivator(vm, vm.Context.World);
                activator.FloorClip  = new Microsoft.Xna.Framework.Rectangle(FloorClipX, FloorClipY, FloorClipWidth, FloorClipHeight);
                activator.Offset     = new Microsoft.Xna.Framework.Point(OffsetX, OffsetY);
                activator.TargetSize = TargetSize;
                var blueprint = activator.LoadFromXML(lotInfo);
            }

            /*if (VM.UseWorld)
             * {
             *  vm.Context.World.InitBlueprint(blueprint);
             *  vm.Context.Blueprint = blueprint;
             * }*/

            return(true);
        }
示例#10
0
        public void LoadTS1()
        {
            var path = Path.Combine(Content.GameContent.TS1HybridBasePath, "GameData/UIText.iff");
            var iff  = new IffFile(path);

            var dirName = "UIText";

            if (!StringTable.TryGetValue(dirName, out var table))
            {
                table = new Dictionary <string, Dictionary <string, string> >();
                StringTable.Add(dirName, table);
            }

            var tables = iff.List <STR>();

            foreach (var str in tables)
            {
                var tableData = new Dictionary <string, string>();
                for (int i = 0; i < str.Length; i++)
                {
                    tableData[i.ToString()] = str.GetString(i);
                }
                table[str.ChunkID.ToString()] = tableData; //overwrites previous.
            }
        }
示例#11
0
        private void CreateTableFile(string path)
        {
            InfoTable infotable = new InfoTable();

            infotable.Items = new List <TableItem>();

            //Far = new FAR1Archive(path, 0);
            DirectoryInfo dir = new DirectoryInfo(path);

            foreach (FileInfo file in dir.GetFiles())
            {
                if (file.Extension == ".iff")
                {
                    var   iff    = new IffFile(path + "/" + file.Name);
                    ulong FileID = 0;


                    foreach (OBJD obj in iff.List <OBJD>())
                    {
                        if (obj.IsMultiTile)
                        {
                            FileID = obj.GUID;
                            string name = Path.GetFileNameWithoutExtension(file.Name);

                            infotable.Items.Add(new TableItem()
                            {
                                GUID     = FileID.ToString("X"),
                                FileName = name,
                                Name     = iff.Filename.Substring(0, iff.Filename.Length - 4),
                                Group    = obj.MasterID.ToString(),
                                SubIndex = obj.SubIndex.ToString()
                            });

                            listBox2.Items.Add(file.Name + " " + FileID);
                            InfoTable.Save("table.xml", infotable);
                        }
                        else if (!obj.IsMultiTile)
                        {
                            FileID = obj.GUID;
                            string name = Path.GetFileNameWithoutExtension(file.Name);

                            infotable.Items.Add(new TableItem()
                            {
                                GUID     = FileID.ToString("X"),
                                FileName = name,
                                Name     = iff.Filename.Substring(0, iff.Filename.Length - 4),
                                Group    = obj.MasterID.ToString(),
                                SubIndex = obj.SubIndex.ToString()
                            });

                            listBox2.Items.Add(file.Name + " " + FileID);
                            InfoTable.Save("table.xml", infotable);
                        }
                    }
                }
            }
        }
示例#12
0
        private void CreateCatalogFile(string path)
        {
            CatalogTable catalog = new CatalogTable();

            catalog.Items = new List <CatalogItem>();

            //Far = new FAR1Archive(path, 0);
            DirectoryInfo dir = new DirectoryInfo(path);


            foreach (FileInfo file in dir.GetFiles())
            {
                if (file.Extension == ".iff")
                {
                    var   iff    = new IffFile(path + "/" + file.Name);
                    ulong FileID = 0;


                    foreach (OBJD obj in iff.List <OBJD>())
                    {
                        if (obj.IsMultiTile && obj.SubIndex == -1)
                        {
                            FileID = obj.GUID;
                            string name = Path.GetFileNameWithoutExtension(file.Name);

                            catalog.Items.Add(new CatalogItem()
                            {
                                GUID     = FileID.ToString("X"),
                                Name     = name,
                                Category = GetCategoryName(name),
                                Price    = obj.Price
                            });

                            listBox2.Items.Add(file.Name + " " + FileID);
                            CatalogTable.Save("catalog.xml", catalog);
                        }
                        else if (!obj.IsMultiTile)
                        {
                            FileID = obj.GUID;
                            string name = Path.GetFileNameWithoutExtension(file.Name);

                            catalog.Items.Add(new CatalogItem()
                            {
                                GUID     = FileID.ToString("X"),
                                Name     = name,
                                Category = GetCategoryName(name),
                                Price    = obj.Price
                            });

                            listBox2.Items.Add(file.Name + " " + FileID);
                            CatalogTable.Save("catalog.xml", catalog);
                        }
                    }
                }
            }
        }
示例#13
0
        public void RegisterObjects(IffFile file)
        {
            var objRegistry = Content.Get().WorldObjects;
            var defs        = file.List <OBJD>();

            if (defs != null)
            {
                foreach (var def in defs)
                {
                    objRegistry.AddObject(file, def);
                }
            }
        }
示例#14
0
        public void UnregisterObjects(IffFile file)
        {
            var objRegistry = Content.Get().WorldObjects;
            var defs        = file.List <OBJD>();

            if (defs != null)
            {
                foreach (var def in defs)
                {
                    objRegistry.RemoveObject(def.GUID);
                }
            }
        }
        /// <summary>
        /// Intializes a specific neighbourhood. Also counts as a save discard, since it unloads the current neighbourhood.
        /// </summary>
        /// <param name="id"></param>
        public void InitSpecific(int id)
        {
            DirtyAvatars.Clear();
            ZoningDictionary.Clear();
            FamilyForHouse.Clear();

            var udName = "UserData" + ((id == 0) ? "" : (id + 1).ToString());
            //simitone shouldn't modify existing ts1 data, since our house saves are incompatible.
            //therefore we should copy to the simitone user data.

            var userPath = FSOEnvironment.ContentDir;


            UserPath = userPath;

            MainResource = new IffFile(Path.Combine(UserPath, "Neighborhood.iff"));

            Neighbors    = MainResource.List <NBRS>().FirstOrDefault();
            Neighborhood = MainResource.List <NGBH>().FirstOrDefault();


            //todo: manage avatar iffs here
        }
示例#16
0
        public string TranslateIff(IffFile file)
        {
            Context.Filename      = CSTranslationContext.FormatName(file.Filename.Replace(".iff", ""));
            Context.ModuleName    = Context.Filename + "Module";
            Context.NamespaceName = "FSO.Scripts." + Context.Filename;
            Context.CurrentFile   = file;

            var bhavs = file.List <BHAV>() ?? new List <BHAV>();

            foreach (var bhav in bhavs)
            {
                Context.CurrentBHAV = bhav;
                var sbhav = new StructuredBHAV(bhav);
                sbhav.Analyse(Context);
                Context.BHAVInfo[bhav.ChunkID] = sbhav;
            }

            foreach (var bhav in Context.BHAVInfo.Values)
            {
                PropagateYieldFromCalls(bhav);
            }

            foreach (var bhav in Context.BHAVInfo.Values)
            {
                foreach (var inst in bhav.Instructions.Values)
                {
                    (inst.Translator as CSSubroutinePrimitive)?.InitInfo(Context);
                }
            }

            foreach (var bhav in Context.BHAVInfo.Values)
            {
                bhav.BuildStructure();
            }

            foreach (var bhav in Context.BHAVInfo.Values)
            {
                Context.AllClasses.Add(TranslateBHAV(bhav));
            }

            return(BuildCSFile());
        }
示例#17
0
        public void RefreshAnimTable()
        {
            InternalChange = true;
            FWAVTable      = SourceIff.List <FWAV>();
            if (FWAVTable == null)
            {
                FWAVTable = new List <FWAV>();
            }

            MyList.Items.Clear();
            if (FWAVTable != null)
            {
                foreach (var item in FWAVTable)
                {
                    MyList.Items.Add(item.Name);
                }

                MyList.SelectedItem = FWAVTable.FindIndex(x => x.ChunkID == SelectedFWAV);
            }

            InternalChange = false;
        }
示例#18
0
        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.
                }
            }
        }
示例#19
0
        public static void Init(string basePath)
        {
            PIFFsByName = new Dictionary<string, List<IffFile>>();
            IsPIFFUser = new Dictionary<string, bool>();

            //Directory.CreateDirectory(basePath);
            string[] paths = Directory.GetFiles(basePath, "*.piff", SearchOption.AllDirectories);
            for (int i = 0; i < paths.Length; i++)
            {
                string entry = paths[i].Replace('\\', '/');
                bool user = entry.Contains("User/");
                string filename = Path.GetFileName(entry);

                IffFile piffFile = new IffFile(entry);
                PIFF piff = piffFile.List<PIFF>()[0];

                if (IsPIFFUser.ContainsKey(piff.SourceIff))
                {
                    var old = IsPIFFUser[piff.SourceIff];
                    if (old != user)
                    {
                        if (user)
                        {
                            //remove old piffs, as they have been overwritten by this user piff.
                            PIFFsByName[piff.SourceIff].Clear();
                            IsPIFFUser[piff.SourceIff] = true;
                        }
                        else continue; //a user piff exists. ignore these ones.
                    }
                }
                else IsPIFFUser.Add(piff.SourceIff, user);

                if (!PIFFsByName.ContainsKey(piff.SourceIff)) PIFFsByName.Add(piff.SourceIff, new List<IffFile>());
                PIFFsByName[piff.SourceIff].Add(piffFile);
            }
        }
示例#20
0
 public void UnregisterObjects(IffFile file)
 {
     var objRegistry = Content.Get().WorldObjects;
     var defs = file.List<OBJD>();
     if (defs != null)
     {
         foreach (var def in defs)
         {
             objRegistry.RemoveObject(def.GUID);
         }
     }
 }
示例#21
0
 public void RegisterObjects(IffFile file)
 {
     var objRegistry = Content.Get().WorldObjects;
     var defs = file.List<OBJD>();
     if (defs != null)
     {
         foreach (var def in defs)
         {
             objRegistry.AddObject(file, def);
         }
     }
 }
示例#22
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
                    });
                }
            }
        }
示例#23
0
        /// <summary>
        /// Intializes a specific neighbourhood. Also counts as a save discard, since it unloads the current neighbourhood.
        /// </summary>
        /// <param name="id"></param>
        public void InitSpecific(int id)
        {
            DirtyAvatars.Clear();
            ZoningDictionary.Clear();
            FamilyForHouse.Clear();

            var udName = "UserData" + ((id == 0) ? "" : (id + 1).ToString());
            //simitone shouldn't modify existing ts1 data, since our house saves are incompatible.
            //therefore we should copy to the simitone user data.

            var userPath = Path.Combine(FSOEnvironment.UserDir, udName + "/");

            if (!Directory.Exists(userPath))
            {
                var source      = Path.Combine(ContentManager.TS1BasePath, udName + "/");
                var destination = userPath;

                //quick and dirty copy.

                foreach (string dirPath in Directory.GetDirectories(source, "*",
                                                                    SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dirPath.Replace('\\', '/').Replace(source, destination));
                }

                foreach (string newPath in Directory.GetFiles(source, "*.*",
                                                              SearchOption.AllDirectories))
                {
                    File.Copy(newPath, newPath.Replace('\\', '/').Replace(source, destination), true);
                }
            }

            UserPath = userPath;

            MainResource = new IffFile(Path.Combine(UserPath, "Neighborhood.iff"));
            LotLocations = new IffFile(Path.Combine(UserPath, "LotLocations.iff"));
            var lotZoning = new IffFile(Path.Combine(UserPath, "LotZoning.iff"));

            StreetNames       = new IffFile(Path.Combine(UserPath, "StreetNames.iff"));
            NeighbourhoodDesc = new IffFile(Path.Combine(UserPath, "Houses/NeighborhoodDesc.iff"));
            STDesc            = new IffFile(Path.Combine(UserPath, "Houses/STDesc.iff"));
            MTDesc            = new IffFile(Path.Combine(UserPath, "Houses/MTDesc.iff"));

            var zones = lotZoning.Get <STR>(1);

            for (int i = 0; i < zones.Length; i++)
            {
                var split = zones.GetString(i).Split(',');
                ZoningDictionary[short.Parse(split[0])] = (short)((split[1] == " community") ? 1 : 0);
            }
            Neighbors      = MainResource.List <NBRS>().FirstOrDefault();
            Neighborhood   = MainResource.List <NGBH>().FirstOrDefault();
            TypeAttributes = MainResource.List <TATT>().FirstOrDefault();

            FamilyForHouse = new Dictionary <short, FAMI>();
            var families = MainResource.List <FAMI>();

            foreach (var fam in families)
            {
                FamilyForHouse[(short)fam.HouseNumber] = fam;
            }

            LoadCharacters(true);

            //todo: manage avatar iffs here
        }
示例#24
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            var  name  = ChunkLabelEntry.Text;
            var  guidT = GUIDEntry.Text;
            uint guid;
            var  objProvider = Content.Content.Get().WorldObjects;

            if (name == "")
            {
                MessageBox.Show("Name cannot be empty!", "Invalid Object Name");
            }
            else if (guidT == "")
            {
                MessageBox.Show("GUID cannot be empty!", "Invalid GUID");
            }
            else if (!uint.TryParse(guidT, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out guid))
            {
                MessageBox.Show("GUID is invalid! Make sure it is a hex string of size 8. (eg. 6789ABCD)", "Invalid GUID");
            }
            else
            {
                lock (objProvider.Entries)
                {
                    if (objProvider.Entries.ContainsKey(guid))
                    {
                        MessageBox.Show("This GUID is already being used!", "GUID is Taken!");
                        return;
                    }

                    //OK, it's valid. Now to add it to the objects system...
                    //This is a little tricky because we want to add an object that does not exist yet.
                    //There's a special function just for this! But first, we need an OBJD...

                    var obj = new OBJD()
                    {
                        GUID             = guid,
                        ObjectType       = OBJDType.Normal,
                        ChunkLabel       = name,
                        ChunkID          = 1,
                        ChunkProcessed   = true,
                        ChunkType        = "OBJD",
                        ChunkParent      = TargetIff,
                        AnimationTableID = 128,
                        AddedByPatch     = true
                    };

                    Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
                    {
                        //find a free space to place the object
                        ushort id = 16807; //todo: why???
                        var list  = TargetIff.List <OBJD>();
                        if (list != null)
                        {
                            foreach (var chk in list.OrderBy(x => x.ChunkID))
                            {
                                if (chk.ChunkID == id)
                                {
                                    id++;
                                }
                            }
                        }
                        obj.ChunkID = id;
                        //add it to the iff file
                        TargetIff.AddChunk(obj);
                    }, obj));

                    if (IsNew)
                    {
                        //add a default animation table, for quality of life reasons

                        var anim = new STR()
                        {
                            ChunkLabel     = name,
                            ChunkID        = 128,
                            ChunkProcessed = true,
                            ChunkType      = "STR#",
                            ChunkParent    = TargetIff,
                        };

                        anim.InsertString(0, new STRItem {
                            Value = "", Comment = ""
                        });
                        TargetIff.AddChunk(anim);

                        var filename = TargetIff.RuntimeInfo.Path;
                        Directory.CreateDirectory(Path.GetDirectoryName(filename));
                        using (var stream = new FileStream(filename, FileMode.Create))
                            TargetIff.Write(stream);
                    }

                    //add it to the provider
                    objProvider.AddObject(TargetIff, obj);

                    DialogResult = DialogResult.OK;
                    ResultGUID   = guid;
                    Close();
                }
            }
        }
示例#25
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
                    });
                }
            }
        }
示例#26
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));
                        }
                    }
                }
            }
        }
示例#27
0
 public TS1JobProvider(TS1Provider provider)
 {
     JobResource = (IffFile)provider.Get("work.iff");
     NumJobs     = JobResource.List <CARR>().Count - 1; //loads all jobs
 }
示例#28
0
 public short SetToNext(short current)
 {
     return((short)(JobResource.List <CARR>().FirstOrDefault(x => x.ChunkID > current)?.ChunkID ?? -1));
 }
示例#29
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
                        });
                    }
                }
            }
        }