예제 #1
0
        protected string AddTxtr(IPackageFile newpkg, GenericRcol txtr, string unique, GenericRcol txmt, MaterialDefinition md)
        {
            string name = AddTxtr(txtr, unique, txmt, md);

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

            return(name);
        }
예제 #2
0
        private bool addFromPkg(String name, uint type, String pkg)
        {
            IPackageFile p = SimPe.Packages.File.LoadFromFile(pkg);

            if (p == null)
            {
                return(false);
            }

            IPackedFileDescriptor[] pfa = p.FindFiles(SimPe.Data.MetaData.NAME_MAP);
            if (pfa == null || pfa.Length != 1)
            {
                return(false);
            }

            SimPe.Plugin.Nmap nmap = new SimPe.Plugin.Nmap(null);
            nmap.ProcessData(pfa[0], p);
            pfa = nmap.FindFiles(name + "_");
            if (pfa == null || pfa.Length != 1)
            {
                return(false);
            }

            IPackedFileDescriptor pfd = null;

            for (int j = 0; j < p.Index.Length && pfd == null; j++)
            {
                if (p.Index[j].Type == type &&
                    p.Index[j].Group == pfa[0].Group &&
                    p.Index[j].Instance == pfa[0].Instance)
                {
                    pfd = p.Index[j];
                }
            }
            if (pfd == null)
            {
                return(false);
            }
            if (isInPFDList(currentPackage.Index, pfd))
            {
                return(true);
            }

            IPackedFileDescriptor npfd = pfd.Clone();

            npfd.UserData = p.Read(pfd).UncompressedData;
            currentPackage.Add(npfd, true);

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Adds the MMAT Files specified in the map to the new package
        /// </summary>
        /// <param name="newpkg"></param>
        /// <param name="map">Contains the MMATs that should be added</param>
        /// <param name="fullmap">Contains a List of all available MMATs</param>
        public void ProcessMmatMap(IPackageFile newpkg, Hashtable map, Hashtable fullmap)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Loading Slave Subsets");
            }
            AddSlavesSubsets(map, fullmap);
            Hashtable slaves = Scenegraph.GetSlaveSubsets(package);

            uint   inst   = 0x6000;
            string unique = RenameForm.GetUniqueName(true);

            foreach (Hashtable ht in map.Values)
            {
                foreach (ArrayList list in ht.Values)
                {
                    string family = System.Guid.NewGuid().ToString();
                    if (unique == null)
                    {
                        unique = family;
                    }

                    foreach (SimPe.Plugin.MmatWrapper mmat in list)
                    {
                        mmat.FileDescriptor          = Scenegraph.Clone(mmat.FileDescriptor);
                        mmat.FileDescriptor.Instance = inst++;
                        mmat.FileDescriptor.Group    = Data.MetaData.LOCAL_GROUP;
                        mmat.Family          = family;
                        mmat.DefaultMaterial = false;

                        GenericRcol txmt = mmat.TXMT;
                        GenericRcol txtr = mmat.TXTR;
                        this.AddTxmt(newpkg, mmat, txmt, txtr, unique, slaves);

                        mmat.SynchronizeUserData();
                        newpkg.Add(mmat.FileDescriptor);
                    }
                }
            }
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// Add a small Scenegraph Chain
        /// </summary>
        /// <param name="mmat">the MAterial override File for this Subset</param>
        /// <param name="txmt">The Material Definition File for this Subset</param>
        /// <param name="txtr">The Txtr File for this Subset (can be null)</param>
        /// <param name="unique">A unique String for the Filenames</param>
        /// <param name="slavemap">The Slavemap as generated by Scenegraph.GetSlaveSubsets() (if null, no slave txmts are loaded)</param>
        void AddTxmt(IPackageFile newpkg, SimPe.Plugin.MmatWrapper mmat, GenericRcol txmt, GenericRcol txtr, string unique, Hashtable slavemap)
        {
            //Get/Update Material Definition
            if (txmt != null)
            {
                string name = Hashes.StripHashFromName(txmt.FileName.Trim());

                //load Slave TXMTs
                if (slavemap != null)
                {
                    LoadSlaveTxmt(newpkg, mmat, name, unique, slavemap);
                }

                if (name.ToLower().EndsWith("_txmt"))
                {
                    name = name.Substring(0, name.Length - 5);
                }
                txmt.FileName       = FixObject.GetUniqueTxmtName(name, unique, mmat.SubsetName, true);          ///*"##0x"+Helper.HexString(Data.MetaData.CUSTOM_GROUP)+"!"+*/name+"_"+unique+"_txmt";
                txmt.FileDescriptor = ScenegraphHelper.BuildPfd(txmt.FileName, Data.MetaData.TXMT, Data.MetaData.CUSTOM_GROUP);

                mmat.Name = "##0x" + Helper.HexString(txmt.FileDescriptor.Group) + "!" + FixObject.GetUniqueTxmtName(name, unique, mmat.SubsetName, false);

                MaterialDefinition md = (MaterialDefinition)txmt.Blocks[0];
                if (txtr == null)
                {
                    txtr = mmat.GetTxtr(txmt);
                    if (txtr != null)
                    {
                        txtr.FileDescriptor = (Interfaces.Files.IPackedFileDescriptor)txtr.FileDescriptor.Clone();
                    }
                }

                //Get/Update Texture
                if (txtr != null)
                {
                    name = AddTxtr(txtr, unique, txmt, md);

                    md.FileDescription = Hashes.StripHashFromName(txmt.FileName).Trim();
                    if (md.FileDescription.ToLower().EndsWith("_txmt"))
                    {
                        md.FileDescription = md.FileDescription.Substring(0, md.FileDescription.Length - 5);
                    }
                }

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

                AddReferencedTxtr(newpkg, txmt, md, unique);

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