Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cs"></param>
        /// <param name="cpf"></param>
        /// <returns>ResourceDescriptor for the references String</returns>
        protected static SimPe.Interfaces.Files.IPackedFileDescriptor UpdateDescription(OWCloneSettings cs, SimPe.Packages.GeneratableFile package, SimPe.PackedFiles.Wrapper.Cpf cpf)
        {
            cpf.GetSaveItem("cost").UIntegerValue      = (uint)cs.Price;
            cpf.GetSaveItem("name").StringValue        = cs.Title.Replace("\n", " ").Replace("\t", "    ").Replace("\r", " ");
            cpf.GetSaveItem("description").StringValue = cs.Description.Replace("\n", " ").Replace("\t", "    ").Replace("\r", " ");
            cpf.SynchronizeUserData();

            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = package.FindFile(cpf.GetSaveItem("stringsetrestypeid").UIntegerValue, 0, cpf.GetSaveItem("stringsetgroupid").UIntegerValue, cpf.GetSaveItem("stringsetid").UIntegerValue);

            return(pfd);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cs"></param>
        /// <param name="cpf"></param>
        /// <returns>ResourceDescriptor for the references String</returns>
        protected static SimPe.Interfaces.Files.IPackedFileDescriptor UpdateDescription(OWCloneSettings cs, SimPe.Packages.GeneratableFile package, SimPe.PackedFiles.Wrapper.ExtObjd obj)
        {
            obj.Price      = cs.Price;
            obj.Data[0x22] = (short)Math.Floor(cs.Price * 0.035); // sale price
            obj.Data[0x23] = (short)Math.Floor(cs.Price * 0.15);  // initial depreciation
            obj.Data[0x24] = (short)Math.Floor(cs.Price * 0.10);  // daily depreciation
            obj.Data[0x25] = 0;                                   // self depreciation
            obj.Data[0x26] = (short)Math.Floor(cs.Price * 0.40);  // depreciation limit
            obj.SynchronizeUserData();
            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = package.FindFile(Data.MetaData.CTSS_FILE, 0, obj.FileDescriptor.Group, obj.CTSSInstance);

            return(pfd);
        }
Esempio n. 3
0
        private void tsmi_Click(object sender, EventArgs e)
        {
            pjse.FileTable.Entry fe;
            SimPe.ExpansionItem  exp;
            int i = cmenuCompare.Items.IndexOf((ToolStripItem)sender);

            if (i < 0)
            {
                throw new ArgumentOutOfRangeException("menuItem", "Unrecognised object triggered event");
            }
            else if (i == 0)
            {
                pjse.FileTable.Entry[] items =
                    pjse.FileTable.GFT[wrapper.FileDescriptor.Type, wrapper.FileDescriptor.Group, wrapper.FileDescriptor.Instance, pjse.FileTable.Source.Maxis];
                if (items == null || items.Length == 0)
                {
                    MessageBox.Show(pjse.Localization.GetString("cmpNFCurrent", wrapperName),
                                    this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                fe  = items[0];
                exp = null;
            }
            else
            {
                exp = (SimPe.ExpansionItem)cmenuCompare.Items[i].Tag;
                SimPe.Packages.GeneratableFile op = SimPe.Packages.GeneratableFile.LoadFromFile(
                    System.IO.Path.Combine(System.IO.Path.Combine(exp.InstallFolder, exp.ObjectsSubFolder), "objects.package"));
                if (op == null)
                {
                    throw new Exception("Could not read " + exp.Name + " objects.package");
                }
                IPackedFileDescriptor pfd = op.FindFile(wrapper.FileDescriptor);
                if (pfd == null)
                {
                    MessageBox.Show(pjse.Localization.GetString("cmpNFExp", wrapperName, exp.Name),
                                    this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                fe = new pjse.FileTable.Entry(op, pfd, true, false);
            }

            OnCompareWith(this, new CompareWithEventArgs(fe, exp));
        }
Esempio n. 4
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);
        }