Exemplo n.º 1
0
        public void ExecuteEventHandler(object sender, SimPe.Events.ResourceEventArgs e)
        {
            if (!RealChangeEnabledStateEventHandler(null, e))
            {
                System.Windows.Forms.MessageBox.Show(Localization.GetString("This is not an appropriate context in which to use this tool"),
                                                     Localization.GetString(this.ToString()));
                return;
            }

            if (Message.Show(SimPe.Localization.GetString("Fix_Fence_Warning"), SimPe.Localization.GetString("Warning"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }



            try
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = e.LoadedPackage.Package.FindFiles(Data.MetaData.XFNC);
                foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf();
                    cpf.ProcessData(pfd, e.LoadedPackage.Package);

                    uint guid = cpf.GetSaveItem("guid").UIntegerValue;
                    //load the Descriptor for the String Resource
                    SimPe.Interfaces.Files.IPackedFileDescriptor p = e.LoadedPackage.Package.FindFile(
                        cpf.GetSaveItem("stringsetrestypeid").UIntegerValue,
                        0,
                        cpf.GetSaveItem("stringsetgroupid").UIntegerValue,
                        cpf.GetSaveItem("stringsetid").UIntegerValue
                        );

                    //change the Properties
                    cpf.GetSaveItem("resourcegroupid").UIntegerValue  = 0x4c8cc5c0;
                    cpf.GetSaveItem("resourceid").UIntegerValue       = guid;
                    cpf.GetSaveItem("stringsetgroupid").UIntegerValue = guid;

                    cpf.SynchronizeUserData(true, true);

                    //change the Descriptor for the XML
                    cpf.FileDescriptor.Instance = guid;
                    cpf.FileDescriptor.Group    = 0x4c8cc5c0;

                    //change the descriptor for the CTSS
                    if (p != null)
                    {
                        p.Group = guid;
                    }
                }
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage(ex);
            }
        }
Exemplo 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.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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Changes all guids (ignore the current GUID)
        /// </summary>
        /// <param name="newguid">The new GUID</param>
        public void FixGuids(uint newguid)
        {
            Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT);

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf();
                mmat.ProcessData(pfd, package);

                mmat.GetSaveItem("objectGUID").UIntegerValue = newguid;
                mmat.SynchronizeUserData();
            }
        }
Exemplo n.º 4
0
        protected void FixSkin(Hashtable namemap, Hashtable refmap, string grphash)
        {
            SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf();
            Random rnd = new Random();

            //set list of critical types
            uint[]   types          = new uint[] { Data.MetaData.XOBJ, Data.MetaData.XFLR, Data.MetaData.XFNC, Data.MetaData.XROF, Data.MetaData.XNGB };
            string[] txtr_props     = new string[] { "textureedges", "texturetop", "texturetopbump", "texturetrim", "textureunder", "texturetname", "texturetname" };
            string[] txmt_props     = new string[] { "material", "diagrail", "post", "rail" };
            string[] cres_props     = new string[] { "diagrail", "post", "rail" };
            string[] cres_props_ngb = new string[] { "modelname" };
            string[] groups         = new string[] { "stringsetgroupid", "resourcegroupid" };
            string[] set_to_guid    = new string[] {};          //"thumbnailinstanceid"

            //now fix the texture References in those Resources
            foreach (uint t in types)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(t);

                foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    cpf.ProcessData(pfd, package);
                    uint guid = (uint)rnd.Next();

                    string pfx = grphash; if (t == Data.MetaData.XFNC)
                    {
                        pfx = "";
                    }

                    FixCpfProperties(cpf, txtr_props, namemap, pfx, "_txtr");
                    FixCpfProperties(cpf, txmt_props, namemap, pfx, "_txmt");
                    FixCpfProperties(cpf, cres_props, namemap, pfx, "_cres");
                    if (pfd.Type == Data.MetaData.XNGB)
                    {
                        FixCpfProperties(cpf, cres_props_ngb, namemap, pfx, "_cres");
                    }

                    FixCpfProperties(cpf, groups, Data.MetaData.LOCAL_GROUP);
                    FixCpfProperties(cpf, set_to_guid, guid);
#if DEBUG
                    FixCpfProperties(cpf, "guid", (uint)((guid & 0x00fffffe) | 0xfb000001));
#else
                    FixCpfProperties(cpf, "guid", (uint)((guid & 0xfffffffe) | 0x00000001));
#endif

                    cpf.SynchronizeUserData();
                }
            }
        }
Exemplo n.º 5
0
        void AddToMMAT(SimPe.Events.ResourceContainer rc)
        {
            SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf();
            mmat.ProcessData(rc.Resource);
            RemoveFromMMAT(mmat);

            if (mmat.GetItem("copyright") == null)
            {
                SimPe.PackedFiles.Wrapper.CpfItem item = new SimPe.PackedFiles.Wrapper.CpfItem();
                item.Name  = "copyright";
                mmat.Items = (SimPe.PackedFiles.Wrapper.CpfItem[])Helper.Add(mmat.Items, item);
            }

            mmat.GetItem("copyright").StringValue = form.tbMMAT.Text;
            mmat.SynchronizeUserData(true, true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Changes all guids (Depends on the passed Replacement Map)
        /// </summary>
        /// <param name="guids">List of GuidSet Objects</param>
        public void FixGuids(ArrayList guids)
        {
            Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT);

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf();
                mmat.ProcessData(pfd, package);


                if (guids != null)
                {
                    foreach (GuidSet sget in guids)
                    {
                        if (mmat.GetSaveItem("objectGUID").UIntegerValue == sget.oldguid)
                        {
                            mmat.GetSaveItem("objectGUID").UIntegerValue = sget.guid;
                            mmat.SynchronizeUserData();
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add a MMAT to the package
        /// </summary>
        protected SimPe.PackedFiles.Wrapper.Cpf AddMMAT(SimPe.Plugin.Rcol matd, string subset, string cresname, uint instance, bool substate)
        {
            //now add the default MMAT
            System.IO.BinaryReader br = new System.IO.BinaryReader(this.GetType().Assembly.GetManifestResourceStream("SimPe.Plugin.mmat.simpe"));
            SimPe.Packages.PackedFileDescriptor pfd1 = new SimPe.Packages.PackedFileDescriptor();
            pfd1.Group    = 0xffffffff; pfd1.SubType = 0x00000000; pfd1.Instance = instance; pfd1.Type = 0x4C697E5A;          //MMAT
            pfd1.UserData = br.ReadBytes((int)br.BaseStream.Length);

            package.Add(pfd1);
            SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf();
            mmat.ProcessData(pfd1, package);

            if (!substate)
            {
                mmat.GetSaveItem("family").StringValue = System.Guid.NewGuid().ToString();
            }
            mmat.GetSaveItem("name").StringValue       = matd.FileName.Substring(0, matd.FileName.Length - 5);
            mmat.GetSaveItem("subsetName").StringValue = subset;
            mmat.GetSaveItem("modelName").StringValue  = cresname;

            //Get the GUID
            Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.OBJD_FILE);
            mmat.GetSaveItem("objectGUID").UIntegerValue = 0x00000000;
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.PackedFiles.Wrapper.Objd objd = new SimPe.PackedFiles.Wrapper.Objd(null);
                objd.ProcessData(pfds[0], package);
                mmat.GetSaveItem("objectGUID").UIntegerValue = objd.SimId;

                if (pfd.Instance == 0x000041A7)
                {
                    break;
                }
            }

            ObjectRecolor.FixMMAT(mmat);
            mmat.SynchronizeUserData();

            gm_pkg.Add(mmat.FileDescriptor);

            //alternate states
            if (!substate)
            {
                string name = mmat.GetSaveItem("name").StringValue;
                pfds = ObjectCloner.FindStateMatchingMatd(name, package);


                if (pfds != null)
                {
                    if (pfds.Length > 0)
                    {
                        SimPe.Plugin.Rcol submatd = new GenericRcol(null, false);
                        submatd.ProcessData(pfds[0], package);

                        SimPe.PackedFiles.Wrapper.Cpf mmat2 = AddMMAT(submatd, subset, cresname, instance, true);
                        mmat2.GetSaveItem("family").StringValue = mmat.GetSaveItem("family").StringValue;
                    }
                }
            }

            return(mmat);
        }