コード例 #1
0
        private AbstractWrapper[] getCpf3idrPairInPkg(IPackedFileDescriptor tgtpfd, String pkg)
        {
            IPackageFile p = SimPe.Packages.File.LoadFromFile(pkg);

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

            IPackedFileDescriptor pc = p.FindFile(tgtpfd);

            if (pc == null)
            {
                return(null);
            }

            IPackedFileDescriptor p3 = p.FindFile(SimPe.Data.MetaData.REF_FILE /*3IDR*/, pc.SubType, pc.Group, pc.Instance);

            if (p3 == null)
            {
                return(null);
            }

            AbstractWrapper[] tgt = new AbstractWrapper[] { new SimPe.PackedFiles.Wrapper.Cpf(), new SimPe.Plugin.RefFile() };
            tgt[0].ProcessData(pc, p);
            tgt[1].ProcessData(p3, p);

            return(tgt);
        }
コード例 #2
0
        AbstractWrapper findInPackage(String pkg, uint Filetype, IPackedFileDescriptor pfd)
        {
            IPackageFile p = SimPe.Packages.File.LoadFromFile(pkg);

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

            IPackedFileDescriptor pt = p.FindFile(Filetype, pfd.SubType, pfd.Group, pfd.Instance);

            if (pt == null)
            {
                return(null);
            }

            AbstractWrapper tgt;

            if (Filetype == SimPe.Data.MetaData.REF_FILE)
            {
                tgt = new SimPe.Plugin.RefFile();
            }
            else
            {
                tgt = new SimPe.PackedFiles.Wrapper.Cpf();
            }
            tgt.ProcessData(pt, p);
            return(tgt);
        }
コード例 #3
0
        /// <summary>
        /// Returns the Primary Guid of the Object
        /// </summary>
        /// <returns>0 or the default guid</returns>
        public uint GetPrimaryGuid()
        {
            uint guid = 0;

            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFile(Data.MetaData.OBJD_FILE, 0, 0x41A7);
            if (pfds.Length == 0)
            {
                pfds = package.FindFiles(Data.MetaData.OBJD_FILE);
            }
            if (pfds.Length > 0)
            {
                SimPe.PackedFiles.Wrapper.ExtObjd objd = new SimPe.PackedFiles.Wrapper.ExtObjd();
                objd.ProcessData(pfds[0], package);
                guid = objd.Guid;
            }
            return(guid);
        }
コード例 #4
0
        private List <AbstractWrapper[]> findFragKeys()
        {
            List <AbstractWrapper[]> fragKeys = new List <AbstractWrapper[]>();

            foreach (String pkg in fragkeys)
            {
                IPackageFile p = SimPe.Packages.File.LoadFromFile(pkg);
                if (p == null)
                {
                    continue;
                }

                IPackedFileDescriptor[] apfd = p.FindFiles(0x0C560F39 /*BINX*/);
                SimPe.Wait.SubStart(apfd.Length);
                foreach (IPackedFileDescriptor bx in apfd)
                {
                    try
                    {
                        // is there a paired 3idr?
                        IPackedFileDescriptor pfd = p.FindFile(SimPe.Data.MetaData.REF_FILE /*3IDR*/, bx.SubType, bx.Group, bx.Instance);
                        if (pfd == null)
                        {
                            continue;
                        }

                        // load the pair
                        SimPe.Plugin.RefFile fk3idr = new SimPe.Plugin.RefFile();
                        fk3idr.ProcessData(pfd, p);
                        SimPe.PackedFiles.Wrapper.Cpf fkCpf = new SimPe.PackedFiles.Wrapper.Cpf();
                        fkCpf.ProcessData(bx, p);

                        // does the pair point to the object we're working on?
                        SimPe.PackedFiles.Wrapper.CpfItem objKeyIdx = fkCpf.GetItem("objectidx");
                        if (objKeyIdx == null || objKeyIdx.Datatype != SimPe.Data.MetaData.DataTypes.dtUInteger)
                        {
                            continue;
                        }
                        if (!fk3idr.Items[objKeyIdx.UIntegerValue].Equals(objKeyCPF))
                        {
                            continue;
                        }

                        // success - save the fragkey
                        fragKeys.Add(new AbstractWrapper[] { fkCpf, fk3idr });
                    }
                    finally
                    {
                        SimPe.Wait.Progress++;
                    }
                }
                SimPe.Wait.SubStop();
            }
            return(fragKeys);
        }
コード例 #5
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);
        }
コード例 #6
0
        /// <summary>
        /// Find the second MMAT that matches the state
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Interfaces.Files.IPackedFileDescriptor[] FindStateMatchingMatd(string name, IPackageFile package)
        {
            Interfaces.Files.IPackedFileDescriptor[] pfds = null;

            //railingleft1 railingleft2 railingleft3 railingleft4
            if (name.EndsWith("_clean"))
            {
                name = name.Substring(0, name.Length - 6) + "_dirty";
                pfds = package.FindFile(name + "_txmt", 0x49596978);
            }
            else if (name.EndsWith("_dirty"))
            {
                name = name.Substring(0, name.Length - 6) + "_clean";
                pfds = package.FindFile(name + "_txmt", 0x49596978);
            }
            else if (name.EndsWith("_lit"))
            {
                name = name.Substring(0, name.Length - 4) + "_unlit";
                pfds = package.FindFile(name + "_txmt", 0x49596978);
            }
            else if (name.EndsWith("_unlit"))
            {
                name = name.Substring(0, name.Length - 6) + "_lit";
                pfds = package.FindFile(name + "_txmt", 0x49596978);
            }
            else if (name.EndsWith("_on"))
            {
                name = name.Substring(0, name.Length - 3) + "_off";
                pfds = package.FindFile(name + "_txmt", 0x49596978);
            }
            else if (name.EndsWith("_off"))
            {
                name = name.Substring(0, name.Length - 4) + "_on";
                pfds = package.FindFile(name + "_txmt", 0x49596978);
            }
            else if (name.EndsWith("_shadeinside"))
            {
                name = name.Substring(0, name.Length - 4) + "_shadeoutside";
                pfds = package.FindFile(name + "_txmt", 0x49596978);
            }
            else if (name.EndsWith("_shadeoutside"))
            {
                name = name.Substring(0, name.Length - 4) + "_shadeinside";
                pfds = package.FindFile(name + "_txmt", 0x49596978);
            }
            return(pfds);
        }
コード例 #7
0
        /// <summary>
        /// This adds all second Leve Textures to the Recolor (like normal Maps)
        /// </summary>
        /// <param name="newpkg"></param>
        /// <param name="md"></param>
        protected void AddReferencedTxtr(IPackageFile newpkg, GenericRcol txmt, MaterialDefinition md, string unique)
        {
            foreach (string k in txmt.ReferenceChains.Keys)
            {
                if (k.ToLower() == "stdmatnormalmaptexturename")               //at the moment i only know of NormalMaps that need to be added
                {
                    MaterialDefinitionProperty mdp = md.GetProperty(k);
                    if (mdp != null)
                    {
                        string name = Hashes.StripHashFromName(mdp.Value).Trim();
                        if (!name.EndsWith("_txtr"))
                        {
                            name += "_txtr";
                        }

                        //Console.Write("loading second txtr "+mdp.Name+" = "+mdp.Value);
                        IPackageFile pkg = txmt.Package;
                        SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(name, Data.MetaData.TXTR);
                        if (pfds.Length > 0)
                        {
                            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pfds[0];
                            //Console.Write(" [found in local Package]");

                            GenericRcol txtr = new GenericRcol();
                            txtr.ProcessData(pfd, pkg);

                            AddTxtr(newpkg, txtr, unique, txmt, md);
                        }

                        /*else  //we don't pull from the Filetable, as we expect, that all needed Files are already cloned!
                         * {
                         *      SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(name, Data.MetaData.TXTR, Hashes.GetHashGroupFromName(mdp.Value, Data.MetaData.GLOBAL_GROUP), true);
                         *      if (item!=null)
                         *      {
                         *              Console.Write(" [found in FileTable]");
                         *      }
                         * }*/


                        //Console.WriteLine();
                    }
                }
            }
        }
コード例 #8
0
        private SimPe.Plugin.GenericRcol getRcolPkg(String filename, String pkg)
        {
            IPackageFile p = SimPe.Packages.File.LoadFromFile(pkg);

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

            IPackedFileDescriptor[] apr = p.FindFile(filename);
            if (apr == null || apr.Length != 1)
            {
                return(null);
            }

            SimPe.Plugin.GenericRcol tgt = new SimPe.Plugin.GenericRcol();
            tgt.ProcessData(apr[0], p);

            return(tgt);
        }
コード例 #9
0
        private SimPe.Plugin.GenericRcol getRcolPkg(IPackedFileDescriptor tgtpfd, String pkg)
        {
            IPackageFile p = SimPe.Packages.File.LoadFromFile(pkg);

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

            IPackedFileDescriptor pr = p.FindFile(tgtpfd);

            if (pr == null)
            {
                return(null);
            }

            SimPe.Plugin.GenericRcol tgt = new SimPe.Plugin.GenericRcol();
            tgt.ProcessData(pr, p);

            return(tgt);
        }
コード例 #10
0
        /// <summary>
        /// Add a small Scenegraph Chain
        /// </summary>
        /// <param name="newpkg"></param>
        /// <param name="mmat">the MAterial override File for this Subset</param>
        /// <param name="txmtname">Name of the MAster TXMT</param>
        /// <param name="unique">A unique String for the Filenames</param>
        void LoadSlaveTxmt(IPackageFile newpkg, SimPe.Plugin.MmatWrapper mmat, string txmtname, string unique, Hashtable slavemap)
        {
            foreach (string k in slavemap.Keys)
            {
                foreach (string slave in (ArrayList)slavemap[k])
                {
                    string newname = txmtname.Replace("_" + k + "_", "_" + slave + "_");
                    if (newname != txmtname)
                    {
                        Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFile(newname, Data.MetaData.TXMT);
                        if (pfds.Length > 0)
                        {
                            GenericRcol txmt = new GenericRcol(null, false);
                            txmt.ProcessData(pfds[0], package);

                            AddTxmt(newpkg, mmat, txmt, null, unique, null);
                        }
                    }
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// adds the subsets to the tsDesignMode.. Block and returns a List of all added Subsets
        /// </summary>
        /// <param name="shpes"></param>
        /// <param name="gmnd"></param>
        /// <param name="subsets"></param>
        protected void GetSubsets(SimPe.Plugin.Rcol[] shpes, SimPe.Plugin.Rcol gmnd, ArrayList subsets)
        {
            ArrayList         list         = new ArrayList();
            ArrayList         localsubsets = new ArrayList();
            DataListExtension dle          = new DataListExtension(gmnd);
            uint index = (uint)(gm_pkg.FindFiles(0x4C697E5A).Length + 1);

            foreach (SimPe.Plugin.Rcol shpe in shpes)
            {
                SimPe.Plugin.Shape sh   = (SimPe.Plugin.Shape)shpe.Blocks[0];
                SimPe.Plugin.Rcol  cres = FindResourceNode(shpe);

                foreach (SimPe.Plugin.ShapePart part in sh.Parts)
                {
                    if (subsets.Contains(part.Subset))
                    {
                        continue;
                    }
                    if (localsubsets.Contains(part.Subset))
                    {
                        continue;
                    }

                    //Read the MATD
                    Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFile(part.FileName + "_txmt", 0x49596978);
                    foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                    {
                        SimPe.Plugin.Rcol matd = new GenericRcol(null, false);
                        matd.ProcessData(pfd, package);
                        SimPe.Plugin.MaterialDefinition md = (SimPe.Plugin.MaterialDefinition)matd.Blocks[0];

                        //check that the Material is not transparent
                        if (md.GetProperty("stdMatAlphaBlendMode").Value == "none")
                        {
                            //check that the Material references a texture
                            if (package.FindFile(md.GetProperty("stdMatBaseTextureName").Value + "_txtr", 0x1C4A276C).Length > 0)
                            {
                                localsubsets.Add(part.Subset);

                                SimPe.Plugin.ExtensionItem ei = new ExtensionItem();
                                ei.Name     = part.Subset;
                                ei.Typecode = ExtensionItem.ItemTypes.Array;

                                WorkshopMMAT i   = new WorkshopMMAT(part.Subset);
                                object[]     tag = new object[3];
                                tag[0] = matd;
                                tag[1] = cres.FileName;
                                tag[2] = ei;
                                i.Tag  = tag;

                                //if (md.GetProperty("stdMatAlphaBlendMode").Value!="none") i.AddObjectStateIndex(1);
                                list.Add(i);
                                //dle.Extension.Items = (ExtensionItem[])Helper.Add(dle.Extension.Items, ei);
                                //AddMMAT(matd, part.Type, cres.FileName, index++);
                            }
                        }
                    }
                }
            }

            WorkshopMMAT[] mmats = new WorkshopMMAT[list.Count];
            list.CopyTo(mmats);

            Listing li = new Listing();

            if (mmats.Length > 0)
            {
                mmats = li.Execute(mmats);
            }

            foreach (WorkshopMMAT mmat in mmats)
            {
                subsets.Add(mmat.Subset);
                dle.Extension.Items = (ExtensionItem[])Helper.Add(dle.Extension.Items, (ExtensionItem)mmat.Tag[2]);
                AddMMAT((SimPe.Plugin.Rcol)mmat.Tag[0], mmat.Subset, (string)mmat.Tag[1], index++, false);
            }

            if (dle.Extension.Items.Length > 0)
            {
                AddDesignModeBlock(gmnd, dle);
                gmnd.SynchronizeUserData();
                dn_pkg.Add(gmnd.FileDescriptor);
            }
        }
コード例 #12
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);
                    }
                }
            }
        }