Beispiel #1
0
        void FixCpfProperties(SimPe.PackedFiles.Wrapper.Cpf cpf, string[] props, Hashtable namemap, string prefix, string sufix)
        {
            foreach (string p in props)
            {
                SimPe.PackedFiles.Wrapper.CpfItem item = cpf.GetItem(p);
                if (item == null)
                {
                    continue;
                }

                string name = Hashes.StripHashFromName(item.StringValue.Trim().ToLower());
                if (!name.EndsWith(sufix))
                {
                    name += sufix;
                }
                string newname = (string)namemap[name];

                if (newname != null)
                {
                    if (newname.EndsWith(sufix))
                    {
                        newname = newname.Substring(0, newname.Length - sufix.Length);
                    }
                    item.StringValue = prefix + newname;
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Add Resources referenced from XML Files
 /// </summary>
 protected void AddFromXml(SimPe.PackedFiles.Wrapper.CpfItem item, string prefix, uint type)
 {
     if (item == null)
     {
         return;
     }
     AddFromXml(item.StringValue + prefix, type);
 }
Beispiel #3
0
        SimPe.PackedFiles.Wrapper.CpfItem FixCpfProperties(SimPe.PackedFiles.Wrapper.Cpf cpf, string prop, uint val)
        {
            SimPe.PackedFiles.Wrapper.CpfItem item = cpf.GetItem(prop);
            if (item == null)
            {
                return(null);
            }

            item.UIntegerValue = val;
            return(item);
        }
Beispiel #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);
        }
Beispiel #5
0
        void FixCpfProperties(SimPe.PackedFiles.Wrapper.Cpf cpf, string[] props, uint val)
        {
            foreach (string p in props)
            {
                SimPe.PackedFiles.Wrapper.CpfItem item = cpf.GetItem(p);
                if (item == null)
                {
                    continue;
                }

                item.UIntegerValue = val;
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ocpf">The MMAT or Property Set describing the Model</param>
        /// <returns>The Texture or null</returns>
        public object FindTxtrName(object ocpf)
        {
            SimPe.PackedFiles.Wrapper.Cpf     cpf  = (SimPe.PackedFiles.Wrapper.Cpf)ocpf;
            SimPe.PackedFiles.Wrapper.CpfItem item = cpf.GetSaveItem("name");

            if (cpf.Package != BasePackage)
            {
                string name = FindTxtrName(cpf.FileDescriptor);
                return(FindUserTxtr(name));
            }
            else
            {
                string name = FindTxtrName(item.StringValue + "_txmt");
                return(FindTxtr(name));
            }
        }
Beispiel #8
0
        protected void GetCpf(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            foreach (uint t in xtypes)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(t);
                foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    cpf = new SimPe.PackedFiles.Wrapper.Cpf();
                    cpf.ProcessData(pfd, pkg);

                    SimPe.PackedFiles.Wrapper.CpfItem item = cpf.GetItem("guid");
                    if (item != null)
                    {
                        nfo.AddGuid(item.UIntegerValue);
                    }
                }
            }
        }
Beispiel #9
0
        private SimPe.Plugin.GenericRcol getRcol(SimPe.PackedFiles.Wrapper.Cpf srcCpf,
                                                 SimPe.Plugin.RefFile src3idr, String cpfItemKey, List <String> pkgs)
        {
            SimPe.PackedFiles.Wrapper.CpfItem cpfItem = srcCpf.GetItem(cpfItemKey);
            if (cpfItem == null || cpfItem.Datatype != SimPe.Data.MetaData.DataTypes.dtUInteger)
            {
                return(null);
            }

            foreach (String pkg in pkgs)
            {
                SimPe.Plugin.GenericRcol tgt = getRcolPkg(src3idr.Items[cpfItem.UIntegerValue], pkg);
                if (tgt != null)
                {
                    return(tgt);
                }
            }
            return(null);
        }
Beispiel #10
0
        /// <summary>
        /// Load Informations about a specific Want
        /// </summary>
        /// <param name="guid">The GUID of the want</param>
        /// <returns>A Want Information Structure</returns>
        public static WantCacheInformation LoadWant(SimPe.Cache.WantCacheItem wci)
        {
            WantCacheInformation ret = new WantCacheInformation();

            ret.icon = wci.Icon;
            ret.name = wci.Name;
            ret.guid = wci.Guid;

            XWant w = new XWant();

            SimPe.PackedFiles.Wrapper.CpfItem i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "id"; i.UIntegerValue = wci.Guid; w.AddItem(i, true);
            i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "folder"; i.StringValue = wci.Folder; w.AddItem(i, true);
            i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "score"; i.IntegerValue = wci.Score; w.AddItem(i, true);
            i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "influence"; i.IntegerValue = wci.Influence; w.AddItem(i, true);
            i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "objectType"; i.StringValue = wci.ObjectType; w.AddItem(i, true);

            ret.wnt = w;

            return(ret);
        }
Beispiel #11
0
        private void addStr(SimPe.PackedFiles.Wrapper.Cpf srcCpf, SimPe.Plugin.RefFile src3idr)
        {
            SimPe.PackedFiles.Wrapper.CpfItem cpfItem = srcCpf.GetItem("stringsetidx");
            if (cpfItem == null || cpfItem.Datatype != SimPe.Data.MetaData.DataTypes.dtUInteger)
            {
                return;
            }

            IPackedFileDescriptor ps = srcCpf.Package.FindFile(src3idr.Items[cpfItem.UIntegerValue]);

            if (ps == null)
            {
                return;
            }

            SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
            str.ProcessData(ps, srcCpf.Package);

            addFile(str);
        }
Beispiel #12
0
        protected override void Unserialize(System.IO.BinaryReader reader)
        {
            items = new List <XWNTItem>();

            #region Un-break Quaxified XWNTs
            // Because Quaxi's CPF wrapper rewrites XML as binary, we handle that case here
            byte[] hdr = reader.ReadBytes(6);
            reader.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);

            bool   isCpf = true;
            byte[] id    = new byte[] { 0xE0, 0x50, 0xE7, 0xCB, 0x02, 0x00, };
            for (int i = 0; i < hdr.Length && isCpf; i++)
            {
                isCpf = hdr[i] == id[i];
            }

            if (isCpf)
            {
                SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf();
                cpf.ProcessData(this.FileDescriptor, this.Package);
                XWNTWrapper xwnt = new XWNTWrapper();
                foreach (XWNTItem item in xwnt)
                {
                    if (item.Key.StartsWith("<!"))
                    {
                        Add(new XWNTItem(this, item.Key, ""));
                    }
                    else
                    {
                        SimPe.PackedFiles.Wrapper.CpfItem cpfitem = cpf.GetItem(item.Key);
                        if (cpfitem != null)
                        {
                            string value = "";
                            switch (cpfitem.Datatype) // Argh... So broken...
                            {
                            case SimPe.Data.MetaData.DataTypes.dtInteger: value = cpfitem.IntegerValue.ToString(); break;

                            case SimPe.Data.MetaData.DataTypes.dtBoolean: value = cpfitem.BooleanValue.ToString(); break;

                            default: value = cpfitem.StringValue; break;
                            }
                            items.Add(new XWNTItem(this, item.Key, value));
                        }
                        else
                        {
                            items.Add(new XWNTItem(this, item.Key, item.Value));
                        }
                    }
                }
                return;
            }
            #endregion

            XmlReaderSettings xrs = new XmlReaderSettings();
            //xrs.IgnoreComments = true;
            xrs.IgnoreProcessingInstructions = true;
            xrs.IgnoreWhitespace             = true;
            XmlReader xr = XmlReader.Create(reader.BaseStream, xrs);

            if (xr.IsStartElement() && xr.NodeType.Equals(XmlNodeType.Element) && xr.Name.Equals("cGZPropertySetString"))
            {
                setVersion(xr["version"]);
            }
            else
            {
                throw new Exception("Invalid XWNT format");
            }
            xr.Read();

            while (xr.IsStartElement())
            {
                items.Add(new XWNTItem(this, xr));

                if (!xr.IsEmptyElement)
                {
                    xr.ReadEndElement();
                }
                else
                {
                    xr.Skip();
                }
            }
            xr.ReadEndElement();
        }
Beispiel #13
0
        private List <SimPe.Plugin.GenericRcol> findrcolChain()
        {
            List <SimPe.Plugin.GenericRcol> rcolChain = new List <SimPe.Plugin.GenericRcol>();

            SimPe.Plugin.GenericRcol tgt = null;

            foreach (String s in new String[] { "shapekeyidx", "maskshapekeyidx" })
            {
                tgt = getRcol(objKeyCPF, objKey3IDR, s, shpepkg);
                if (tgt != null)
                {
                    rcolChain.Add(tgt);
                    foreach (IPackedFileDescriptor i in tgt.ReferencedFiles)
                    {
                        if (i.Type == SimPe.Data.MetaData.GMND)
                        {
                            SimPe.Plugin.GenericRcol gmnd = getRcol(i, gmndpkg);
                            if (gmnd != null)
                            {
                                rcolChain.Add(gmnd);
                                foreach (IPackedFileDescriptor j in gmnd.ReferencedFiles)
                                {
                                    if (j.Type == SimPe.Data.MetaData.GMDC)
                                    {
                                        SimPe.Plugin.GenericRcol gmdc = getRcol(j, gmdcpkg);
                                        if (gmdc != null)
                                        {
                                            rcolChain.Add(gmdc);
                                        }
                                    }
                                }
                            }
                        }
                        else if (i.Type == SimPe.Data.MetaData.TXMT)
                        {
                            SimPe.Plugin.GenericRcol txmt = getRcol(i, txmtpkg);
                            if (txmt != null)
                            {
                                rcolChain.Add(txmt);
                                findMaterials(ref rcolChain, txmt);
                            }
                        }
                    }
                }
            }

            foreach (String s in new String[] { "resourcekeyidx", "maskresourcekeyidx" })
            {
                tgt = getRcol(objKeyCPF, objKey3IDR, s, crespkg);
                if (tgt != null)
                {
                    rcolChain.Add(tgt);
                }
            }

            uint numOverrides = 0;

            SimPe.PackedFiles.Wrapper.CpfItem cpfItem = objKeyCPF.GetItem("numoverrides");
            if (cpfItem.Datatype == SimPe.Data.MetaData.DataTypes.dtUInteger)
            {
                numOverrides = cpfItem.UIntegerValue;
            }
            for (int i = 0; i < numOverrides; i++)
            {
                tgt = getRcol(objKeyCPF, objKey3IDR, "override" + i.ToString() + "resourcekeyidx", txmtpkg);
                if (tgt != null)
                {
                    rcolChain.Add(tgt);
                    findMaterials(ref rcolChain, tgt);
                }
            }

            return(rcolChain);
        }