Ejemplo n.º 1
0
        /// <summary>
        /// Clone the Makeup of a Sim
        /// </summary>
        /// <returns>the new Package for the patient Sim</returns>
        /// <param name="eyecolor">true, if you want to alter the eyecolor</param>
        /// <param name="makeups">true, if you want to alter the makeup</param>
        public SimPe.Packages.GeneratableFile CloneMakeup(bool eyecolor, bool makeups)
        {
            SimPe.Packages.GeneratableFile ret = SimPe.Packages.GeneratableFile.LoadFromFile((string)null);

            ArrayList list = new ArrayList();

            list.Add((uint)0xE86B1EEF);             //make sure the compressed Directory won't be copied!
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in patient.Index)
            {
                if (!list.Contains(pfd.Type))
                {
                    Interfaces.Files.IPackedFile fl = patient.Read(pfd);

                    Interfaces.Files.IPackedFileDescriptor newpfd = ret.NewDescriptor(pfd.Type, pfd.SubType, pfd.Group, pfd.Instance);
                    newpfd.UserData = fl.UncompressedData;
                    ret.Add(newpfd);
                }
            }

            //Update TXMT Files for the Face
            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = ret.FindFiles(Data.MetaData.TXMT);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                rcol.ProcessData(pfd, ret);

                MaterialDefinition md = (MaterialDefinition)rcol.Blocks[0];
                this.UpdateMakeup(md, eyecolor, makeups);

                rcol.SynchronizeUserData();
            }

            if (eyecolor)
            {
                //Update DNA File
                Interfaces.Files.IPackedFileDescriptor dna  = ngbh.FindFile(0xEBFEE33F, 0, Data.MetaData.LOCAL_GROUP, spatient.Instance);
                Interfaces.Files.IPackedFileDescriptor adna = ngbh.FindFile(0xEBFEE33F, 0, Data.MetaData.LOCAL_GROUP, sarchetype.Instance);
                if ((dna != null) && (adna != null))
                {
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                    cpf.ProcessData(dna, ngbh);

                    SimPe.PackedFiles.Wrapper.Cpf acpf = new Cpf();
                    acpf.ProcessData(adna, ngbh);
                    cpf.GetSaveItem("3").StringValue = acpf.GetSaveItem("3").StringValue;

                    cpf.SynchronizeUserData();
                }
            }
            return(ret);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the Hasvalue used for the Patient
        /// </summary>
        /// <returns></returns>
        string GetSkintone(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pkg.Index)
            {
                ///This is a scenegraph Resource so get the Hash from there!
                if (pfd.Type == Data.MetaData.GZPS)
                {
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                    cpf.ProcessData(pfd, pkg);
                    return(cpf.GetSaveItem("skintone").StringValue);
                }
            }

            return("");
        }
Ejemplo n.º 3
0
        public void ScanPackage(ScannerItem si, SimPe.Cache.PackageState ps, System.Windows.Forms.ListViewItem lvi)
        {
            if (si.PackageCacheItem.Type == SimPe.Cache.PackageType.Cloth ||
                si.PackageCacheItem.Type == SimPe.Cache.PackageType.Skin ||
                ((uint)si.PackageCacheItem.Type & (uint)SimPe.Cache.PackageType.Makeup) == (uint)SimPe.Cache.PackageType.Makeup ||
                ((uint)si.PackageCacheItem.Type & (uint)SimPe.Cache.PackageType.Accessory) == (uint)SimPe.Cache.PackageType.Accessory ||
                si.PackageCacheItem.Type == SimPe.Cache.PackageType.Hair
                )
            {
                Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.GZPS);
                if (pfds.Length == 0)
                {
                    pfds = si.Package.FindFiles(0xCCA8E925);                                 //Object XML
                }
                if (pfds.Length == 0)
                {
                    pfds = si.Package.FindFiles(0x2C1FD8A1);                                 //TextureOverlay XML
                }
                if (pfds.Length == 0)
                {
                    pfds = si.Package.FindFiles(0x8C1580B5);                                 //Hairtone XML
                }
                if (pfds.Length == 0)
                {
                    pfds = si.Package.FindFiles(0x0C1FE246);                                 //Mesh Overlay XML
                }
                ArrayList data = new ArrayList();
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                    cpf.ProcessData(pfd, si.Package, false);

                    data.Add(cpf.GetSaveItem("age").UIntegerValue);
                    data.Add(cpf.GetSaveItem("category").UIntegerValue);
                }

                ps.Data = new uint[data.Count];
                data.CopyTo(ps.Data);
                ps.State = TriState.True;
            }
            else
            {
                ps.State = TriState.False;
            }

            UpdateState(si, ps, lvi);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates the SkinTone References in the 3IDR Files
        /// </summary>
        /// <param name="reffile">the 3IDR File</param><param name="skin">the new skintone</param>
        /// <param name="skinfiles">a Hashtable listing al Proerty Sets for each available skintone (key=skintone string, value= ArrayList of Cpf Objects)</param>
        void UpdateSkintone(SimPe.Plugin.RefFile reffile, string skin, Hashtable skinfiles)
        {
            if (reffile == null)
            {
                return;
            }
            if (reffile.Items == null)
            {
                return;
            }
            if (reffile.Package == null)
            {
                return;
            }

            for (int i = 0; i < reffile.Items.Length; i++)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor pfd = (SimPe.Interfaces.Files.IPackedFileDescriptor)reffile.Items[i];
                if (pfd == null)
                {
                    continue;
                }
                if (pfd.Type == Data.MetaData.GZPS)
                {
                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] fii = FileTable.FileIndex.FindFile(pfd, reffile.Package);
                    if (fii.Length > 0)
                    {
                        Cpf skinfile = new Cpf();
                        skinfile.ProcessData(fii[0]);

                        reffile.Items[i] = UpdateSkintone(skinfile, skin, skinfiles);
                    }
                }
            }

            reffile.SynchronizeUserData();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Change the SkinTone of a Sim
        /// </summary>
        /// <param name="skin">the new skintone</param>
        /// param name="skinfiles">a Hashtable listing al Proerty Sets for each available skintone (key=skintone string, value= ArrayList of Cpf Objects)</param>
        /// <returns>the new Package for the patient Sim</returns>
        public SimPe.Packages.GeneratableFile CloneSkinTone(string skin, Hashtable skinfiles)
        {
            SimPe.Packages.GeneratableFile ret = SimPe.Packages.GeneratableFile.LoadFromFile((string)null);
            string pskin = GetSkintone(this.patient);

            ArrayList list = new ArrayList();

            list.Add((uint)0xE86B1EEF);             //make sure the compressed Directory won't be copied!
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in patient.Index)
            {
                if (!list.Contains(pfd.Type))
                {
                    Interfaces.Files.IPackedFile fl = patient.Read(pfd);

                    Interfaces.Files.IPackedFileDescriptor newpfd = ret.NewDescriptor(pfd.Type, pfd.SubType, pfd.Group, pfd.Instance);
                    newpfd.UserData = fl.UncompressedData;
                    ret.Add(newpfd);

                    switch (newpfd.Type)
                    {
                    case (uint)0xAC598EAC:                             //AGED
                    {
                        SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                        cpf.ProcessData(newpfd, ret);
                        cpf.GetSaveItem("skincolor").StringValue = skin;

                        cpf.SynchronizeUserData();
                        break;
                    }

                    case Data.MetaData.GZPS:
                    {
                        SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                        cpf.ProcessData(newpfd, ret);
                        cpf.GetSaveItem("skintone").StringValue = skin;

                        cpf.SynchronizeUserData();
                        break;
                    }

                    case Data.MetaData.TXMT:
                    {
                        SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                        rcol.ProcessData(newpfd, ret);
                        MaterialDefinition txmt = (MaterialDefinition)rcol.Blocks[0];
                        txmt.FindProperty("cafSkinTone").Value = skin;

                        rcol.SynchronizeUserData();
                        break;
                    }
                    }
                }
            }

            //Update DNA File
            Interfaces.Files.IPackedFileDescriptor dna = ngbh.FindFile(0xEBFEE33F, 0, Data.MetaData.LOCAL_GROUP, spatient.Instance);
            if (dna != null)
            {
                SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                cpf.ProcessData(dna, ngbh);
                cpf.GetSaveItem("2").StringValue = skin;
                cpf.GetSaveItem("6").StringValue = skin;

                cpf.SynchronizeUserData();
            }

            //Update 3IDR Files
            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = ret.FindFiles(0xAC506764);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.RefFile reffile = new RefFile();
                reffile.ProcessData(pfd, ret);

                UpdateSkintone(reffile, skin, skinfiles);
            }

            //Update TXMT Files for the Face
            pfds = ret.FindFiles(Data.MetaData.TXMT);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                rcol.ProcessData(pfd, ret);

                MaterialDefinition md = (MaterialDefinition)rcol.Blocks[0];
                this.UpdateSkintone(md, skin, skinfiles);

                rcol.SynchronizeUserData();
            }


            return(ret);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Set the Age of the Files
        /// </summary>
        /// <param name="name"></param>
        /// <param name="cbs"></param>
        /// <param name="yacheck">true, if you want to perform a check for YoungAdulst and add apropriate Filds to the cpf</param>
        void SetProperty(string name, CheckBox[] cbs, bool yacheck)
        {
            if (selection == null)
            {
                return;
            }

            WaitingScreen.Wait();
            try
            {
                bool chg = false;
                foreach (ScannerItem si in selection)
                {
                    if (si.PackageCacheItem.Type == SimPe.Cache.PackageType.Cloth ||
                        si.PackageCacheItem.Type == SimPe.Cache.PackageType.Skin ||
                        ((uint)si.PackageCacheItem.Type & (uint)SimPe.Cache.PackageType.Makeup) == (uint)SimPe.Cache.PackageType.Makeup ||
                        ((uint)si.PackageCacheItem.Type & (uint)SimPe.Cache.PackageType.Accessory) == (uint)SimPe.Cache.PackageType.Accessory ||
                        si.PackageCacheItem.Type == SimPe.Cache.PackageType.Hair
                        )
                    {
                        if (si.PackageCacheItem.Thumbnail != null)
                        {
                            WaitingScreen.Update(si.PackageCacheItem.Thumbnail, si.FileName);
                        }
                        else
                        {
                            WaitingScreen.UpdateMessage(si.FileName);
                        }

                        //make sure, the file is rescanned on the next Cache Update
                        SimPe.Cache.PackageState ps = si.PackageCacheItem.FindState(this.Uid, true);
                        ps.State = TriState.Null;

                        Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.GZPS);
                        if (pfds.Length == 0)
                        {
                            pfds = si.Package.FindFiles(0xCCA8E925);                                         //Object XML
                        }
                        if (pfds.Length == 0)
                        {
                            pfds = si.Package.FindFiles(0x2C1FD8A1);                                         //TextureOverlay XML
                        }
                        if (pfds.Length == 0)
                        {
                            pfds = si.Package.FindFiles(0x8C1580B5);                                         //Hairtone XML
                        }
                        if (pfds.Length == 0)
                        {
                            pfds = si.Package.FindFiles(0x0C1FE246);                                         //Mesh Overlay XML
                        }
                        ArrayList data = new ArrayList();
                        foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                        {
                            SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                            cpf.ProcessData(pfd, si.Package, false);

                            uint age = cpf.GetSaveItem(name).UIntegerValue;
                            foreach (CheckBox cb in cbs)
                            {
                                if (cb.CheckState == CheckState.Indeterminate)
                                {
                                    continue;
                                }

                                age |= (uint)cb.Tag;
                                if (cb.CheckState == CheckState.Unchecked)
                                {
                                    age ^= (uint)cb.Tag;
                                }
                            }

                            if (yacheck)
                            {
                                //when Young Adult is set, we need to make sure that the Version is updated accordingly!
                                if ((age & (uint)Data.Ages.YoungAdult) != 0)
                                {
                                    AddUniversityFields(cpf);
                                }
                            }

                            if (cpf.GetSaveItem(name).UIntegerValue != age)
                            {
                                chg = true;
                            }
                            cpf.GetSaveItem(name).UIntegerValue = age;

                            cpf.SynchronizeUserData();
                        }

                        si.Package.Save();
                    }
                }                //foreach
                if (chg && this.CallbackFinish != null)
                {
                    this.CallbackFinish(false, false);
                }
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage("", ex);
            }
            finally
            {
                WaitingScreen.Stop();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This will build a SkinTone Replacement for the passed Skintone
        /// </summary>
        /// <param name="skintone">the skintone string</param>
        /// <param name="addtxtr">true, if you want to replace the default TXTR Files</param>
        /// <param name="addtxmt">true if you want to replace the default TXMT Files</param>
        /// <param name="sitem"></param>
        /// <param name="src"></param>
        /// <returns>the replacement package</returns>
        public SimPe.Packages.GeneratableFile BuildOverride(ScannerItem sitem, string skintone, string family, SimPe.Interfaces.Files.IPackageFile src, bool addtxmt, bool addtxtr, bool addref)
        {
            FileTable.FileIndex.Load();
            SimPe.Packages.GeneratableFile pkg = SimPe.Packages.GeneratableFile.LoadFromStream((System.IO.BinaryReader)null);

            WaitingScreen.Wait();
            //Save the old FileTable and the source File
            FileTable.FileIndex.Load();
            FileTable.FileIndex.StoreCurrentState();
            FileTable.FileIndex.AddIndexFromPackage(src);

            bool usefam = (skintone == "00000000-0000-0000-0000-000000000000");

            try
            {
                //find al description Files that belong to the Skintone that should be replaced
                ArrayList basecpf = new ArrayList();

                SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile(Data.MetaData.GZPS, true);
                foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item in items)
                {
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                    cpf.ProcessData(item);

                    if (cpf.GetSaveItem("skintone").StringValue != skintone)
                    {
                        continue;
                    }
                    //if (usefam)
                    if (cpf.GetSaveItem("family").StringValue != family)
                    {
                        continue;
                    }
                    if (cpf.GetSaveItem("type").StringValue != "skin")
                    {
                        continue;
                    }

                    SimPe.Plugin.SkinChain sc = new SkinChain(cpf);
                    basecpf.Add(sc);
                    WaitingScreen.UpdateMessage(cpf.GetSaveItem("name").StringValue);
                }

                ArrayList compare = new ArrayList();
                compare.Add("age");
                //compare.Add("category");
                compare.Add("fitness");
                compare.Add("gender");
                //compare.Add("outfit");
                compare.Add("override0subset");
                //compare.Add("override0resourcekeyidx");
                //compare.Add("shapekeyidx");

                //now select matching Files
                Interfaces.Files.IPackedFileDescriptor[] pfds = src.FindFiles(Data.MetaData.GZPS);

#if DEBUG
                //we could add Debug Code here to see which cpfs were pulled :)

                /*SimPe.Packages.GeneratableFile f = SimPe.Packages.GeneratableFile.CreateNew();
                 *
                 * foreach (SimPe.Plugin.SkinChain sc in basecpf)
                 * {
                 *      sc.Cpf.SynchronizeUserData();
                 *      f.Add(sc.Cpf.FileDescriptor);
                 *
                 *      RefFile r = sc.ReferenceFile;
                 *      if (r!=null)
                 *      {
                 *              r.SynchronizeUserData();
                 *              f.Add(r.FileDescriptor);
                 *      }
                 *
                 *      //foreach (GenericRcol rcol in sc.TXTRs)
                 *      GenericRcol rcol = sc.TXTR;
                 *              if (rcol!=null)
                 *              {
                 *                      rcol.SynchronizeUserData();
                 *                      f.Add(rcol.FileDescriptor);
                 *              }
                 *
                 *      //foreach (GenericRcol rcol in sc.TXMTs)
                 *      rcol = sc.TXMT;
                 *              if (rcol!=null)
                 *              {
                 *                      rcol.SynchronizeUserData();
                 *                      f.Add(rcol.FileDescriptor);
                 *              }
                 * }
                 *
                 * f.Save(@"G:\skinbase.package");
                 * return f;*/
#endif
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    //load a description File for the new Skintone
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                    cpf.ProcessData(pfd, src);

                    int index    = -1;
                    int maxpoint = 0;
                    //check if File is a match
                    for (int i = 0; i < basecpf.Count; i++)
                    {
                        SimPe.Plugin.SkinChain sc = (SimPe.Plugin.SkinChain)basecpf[i];
                        int point = compare.Count;
                        //scan for valid CPF Files
                        foreach (string s in compare)
                        {
                            if (s == "age" || s == "category" || s == "outfit")
                            {
                                if ((sc.Cpf.GetSaveItem(s).UIntegerValue & cpf.GetSaveItem(s).UIntegerValue) == 0)
                                {
                                    point--;
                                }
                            }
                            else if (s == "override0subset")
                            {
                                string s1 = sc.Cpf.GetSaveItem(s).StringValue.Trim().ToLower();
                                string s2 = cpf.GetSaveItem(s).StringValue.Trim().ToLower();

                                if (s1 == "bottom")
                                {
                                    s1 = "body";
                                }
                                else if (s1 == "top")
                                {
                                    s1 = "body";
                                }
                                if (s2 == "bottom")
                                {
                                    s2 = "body";
                                }
                                else if (s2 == "top")
                                {
                                    s2 = "body";
                                }

                                if (s1 != s2)
                                {
                                    point--;
                                }
                            }
                            else if (sc.Cpf.GetSaveItem(s).UIntegerValue != cpf.GetSaveItem(s).UIntegerValue)
                            {
                                point--;
                            }
                        }

                        if (point > maxpoint)
                        {
                            index    = i;
                            maxpoint = point;
                        }
                    }



                    //yes, yes :D this is a match
                    if (index >= 0 && maxpoint == compare.Count)
                    {
                        SimPe.Plugin.SkinChain sc = (SimPe.Plugin.SkinChain)basecpf[index];

                        SkinChain newsc = new SkinChain(cpf);

                        if (sc.ReferenceFile != null && newsc.ReferenceFile != null && addref)
                        {
                            RefFile r = newsc.ReferenceFile;
                            r.FileDescriptor = sc.ReferenceFile.FileDescriptor.Clone();

                            r.SynchronizeUserData();
                            if (pkg.FindFile(r.FileDescriptor) == null)
                            {
                                pkg.Add(r.FileDescriptor);
                            }
                        }

                        if (sc.TXTR != null && newsc.TXTR != null && addtxtr)
                        {
                            SimPe.Plugin.GenericRcol txtr = newsc.TXTR;
                            txtr.FileDescriptor = sc.TXTR.FileDescriptor.Clone();
#if DEBUG
#else
                            txtr.FileDescriptor.MarkForReCompress = true;
#endif

                            txtr.FileName = sc.TXTR.FileName;

                            txtr.SynchronizeUserData();
                            if (pkg.FindFile(txtr.FileDescriptor) == null)
                            {
                                pkg.Add(txtr.FileDescriptor);
                            }
                        }

                        if (sc.TXMT != null && newsc.TXMT != null && addtxmt)
                        {
                            SimPe.Plugin.GenericRcol txmt = newsc.TXMT;
                            txmt.FileDescriptor = sc.TXMT.FileDescriptor.Clone();
#if DEBUG
#else
                            txmt.FileDescriptor.MarkForReCompress = true;
#endif

                            MaterialDefinition md    = (MaterialDefinition)txmt.Blocks[0];
                            MaterialDefinition mdorg = (MaterialDefinition)sc.TXMT.Blocks[0];
                            txmt.FileName      = sc.TXMT.FileName;
                            md.FileDescription = mdorg.FileDescription;

                            txmt.SynchronizeUserData();
                            if (pkg.FindFile(txmt.FileDescriptor) == null)
                            {
                                pkg.Add(txmt.FileDescriptor);
                            }
                        }
                    }
                }

                SimPe.PackedFiles.Wrapper.Str str = new Str();
                str.Add(new StrToken(0, 0, "SimPE Skin Override: " + skintone + " (from " + sitem.PackageCacheItem.Name + ")", ""));

                str.FileDescriptor              = new SimPe.Packages.PackedFileDescriptor();
                str.FileDescriptor.Type         = Data.MetaData.STRING_FILE;
                str.FileDescriptor.Group        = Data.MetaData.LOCAL_GROUP;
                str.FileDescriptor.LongInstance = 0;

                str.SynchronizeUserData();
                pkg.Add(str.FileDescriptor);
            }
            finally
            {
                //restore the Previous FileTable
                FileTable.FileIndex.RestoreLastState();
                WaitingScreen.Stop();
            }

            return(pkg);
        }