Пример #1
0
        public static Image GetXThumbnail(SimPe.PackedFiles.Wrapper.Cpf cpf)
        {
            if (xthumbs == null)
            {
                xthumbs = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.SimSavegameFolder, "Thumbnails\\BuildModeThumbnails.package"));
            }

            SimPe.Packages.File      tmbs = xthumbs;
            Data.XObjFunctionSubSort fss  = GetFunctionSort(cpf);

            uint inst = cpf.GetSaveItem("guid").UIntegerValue;
            uint grp  = cpf.FileDescriptor.Group;

            if (cpf.GetItem("thumbnailinstanceid") != null)
            {
                inst = cpf.GetSaveItem("thumbnailinstanceid").UIntegerValue;
                grp  = cpf.GetSaveItem("thumbnailgroupid").UIntegerValue;
            }


            //get Thumbnail Type
            uint[] types = new uint[] { 0x8C311262, 0x8C31125E }; //floors, walls
            if (fss == Data.XObjFunctionSubSort.Roof)
            {
                types = new uint[] { 0xCC489E46 }
            }
            ;
            else if (fss == Data.XObjFunctionSubSort.Fence_Rail || fss == Data.XObjFunctionSubSort.Fence_Halfwall)
            {
                types = new uint[] { 0xCC30CDF8 }
            }
            ;
            else if (fss == Data.XObjFunctionSubSort.Roof)
            {
                types = new uint[] { 0xCC489E46 }
            }
            ;
            else if (fss == Data.XObjFunctionSubSort.Terrain)
            {
                types = new uint[] { 0xEC3126C4 };
                if (cpf.GetItem("texturetname") != null)
                {
                    inst = Hashes.GetCrc32(Hashes.StripHashFromName(cpf.GetItem("texturetname").StringValue.Trim().ToLower()));
                }
            }
            else if (cpf.FileDescriptor.Type == Data.MetaData.XNGB)
            {
                types = new uint[] { 0x4D533EDD };
                if (nthumbs == null)
                {
                    nthumbs = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.SimSavegameFolder, "Thumbnails\\CANHObjectsThumbnails.package"));
                }
                tmbs = nthumbs;
            }


            return(GetThumbnail(cpf.GetSaveItem("name").StringValue, types, grp, inst, tmbs));
            //tmbs = null;
        }
Пример #2
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);
        }
Пример #3
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;
                }
            }
        }
Пример #4
0
 /// <summary>
 /// adds the passed value if it doesn't already exist
 /// </summary>
 /// <param name="val">The value to add</param>
 public bool AddMMAT(SimPe.PackedFiles.Wrapper.Cpf mmat)
 {
     if (this.AddObjectStateIndex(mmat.GetItem("objectStateIndex").UIntegerValue))
     {
         mmats = (SimPe.PackedFiles.Wrapper.Cpf[])Helper.Add(mmats, mmat);
         return(true);
     }
     return(false);
 }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #7
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;
            }
        }
Пример #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);
                    }
                }
            }
        }
Пример #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);
        }
Пример #10
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);
        }
Пример #11
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();
        }
Пример #12
0
        static void ConsumeFromXobj(SimPe.Cache.ObjectCacheItem oci, Interfaces.Scenegraph.IScenegraphFileIndexItem nrefitem, SimPe.Data.MetaData.Languages deflang)
        {
            SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf();
            nrefitem.FileDescriptor.UserData = nrefitem.Package.Read(nrefitem.FileDescriptor).UncompressedData;
            cpf.ProcessData(nrefitem);

            oci.FileDescriptor = nrefitem.FileDescriptor;
            oci.LocalGroup     = nrefitem.LocalGroup;
            oci.ObjectType     = SimPe.Data.ObjectTypes.Normal;

            SetFunctionSortForXObj(cpf, oci);

            oci.ObjectFileName = cpf.GetSaveItem("filename").StringValue;
            if (oci.ObjectFileName == "")
            {
                oci.ObjectFileName = cpf.GetSaveItem("name").StringValue;
            }

            oci.Useable = true;
            oci.Class   = SimPe.Cache.ObjectClass.XObject;



            Interfaces.Scenegraph.IScenegraphFileIndexItem[] ctssitems = FileTable.FileIndex.FindFile(cpf.GetSaveItem("stringsetrestypeid").UIntegerValue, cpf.GetSaveItem("stringsetgroupid").UIntegerValue, cpf.GetSaveItem("stringsetid").UIntegerValue, null);             //Data.MetaData.STRING_FILE
            if (ctssitems.Length > 0)
            {
                SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                str.ProcessData(ctssitems[0]);
                SimPe.PackedFiles.Wrapper.StrItemList items = str.LanguageItems(deflang);
                if (items.Length > 0)
                {
                    oci.Name = items[0].Title;
                }
                else
                {
                    items = str.LanguageItems(1);
                    if (items.Length > 0)
                    {
                        oci.Name = items[0].Title;
                    }
                    else
                    {
                        oci.Name = "";
                    }
                }
            }
            else
            {
                oci.Name = "";
            }

            if (oci.Name == "")
            {
                oci.Name = oci.ObjectFileName;
            }

            //now the ModeName File
            if (cpf.GetItem("texturetname") != null)
            {
                oci.ModelName = cpf.GetItem("texturetname").StringValue;
            }
            else if (cpf.GetItem("filename") != null)
            {
                oci.ModelName = cpf.GetItem("filename").StringValue;
            }
            else
            {
                oci.ModelName = cpf.GetSaveItem("material").StringValue;
            }

            //oci.Name = cpf.GetSaveItem("type").StringValue + " - "+ cpf.GetSaveItem("subsort").StringValue;


            if (oci.Thumbnail == null)
            {
                oci.Thumbnail = ObjectPreview.GetXThumbnail(cpf);
            }
            ObjectReader.changedcache = true;
        }
Пример #13
0
        /// <summary>
        /// Add Resources referenced from XML Files
        /// </summary>
        /// <param name="names"></param>
        public void AddFromXml(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            SimPe.Interfaces.Files.IPackedFileDescriptor[] index = (SimPe.Interfaces.Files.IPackedFileDescriptor[])pkg.Index.Clone();
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in index)
            {
                SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf();
                if (!cpf.CanHandleType(pfd.Type))
                {
                    continue;
                }

                cpf.ProcessData(pfd, pkg);

                //xobj
                AddFromXml(cpf.GetItem("material"), "_txmt", Data.MetaData.TXMT);

                //hood object
                if (pfd.Type == Data.MetaData.XNGB)
                {
                    AddFromXml(cpf.GetItem("modelname"), "_cres", Data.MetaData.CRES);
                }

                //fences
                AddFromXml(cpf.GetItem("diagrail"), "_cres", Data.MetaData.CRES);
                AddFromXml(cpf.GetItem("post"), "_cres", Data.MetaData.CRES);
                AddFromXml(cpf.GetItem("rail"), "_cres", Data.MetaData.CRES);
                AddFromXml(cpf.GetItem("diagrail"), "_txmt", Data.MetaData.TXMT);
                AddFromXml(cpf.GetItem("post"), "_txmt", Data.MetaData.TXMT);
                AddFromXml(cpf.GetItem("rail"), "_txmt", Data.MetaData.TXMT);

                //terrain
                AddFromXml(cpf.GetItem("texturetname"), "_txtr", Data.MetaData.TXTR);
                AddFromXml(cpf.GetItem("texturetname"), "_detail_txtr", Data.MetaData.TXTR);
                AddFromXml(cpf.GetItem("texturetname"), "-bump_txtr", Data.MetaData.TXTR);

                //roof
                AddFromXml(cpf.GetItem("textureedges"), "_txtr", Data.MetaData.TXTR);
                AddFromXml(cpf.GetItem("texturetop"), "_txtr", Data.MetaData.TXTR);
                AddFromXml(cpf.GetItem("texturetopbump"), "_txtr", Data.MetaData.TXTR);
                AddFromXml(cpf.GetItem("texturetrim"), "_txtr", Data.MetaData.TXTR);
                AddFromXml(cpf.GetItem("textureunder"), "_txtr", Data.MetaData.TXTR);

                SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items =
                    FileTable.FileIndex.FindFile(
                        cpf.GetSaveItem("stringsetrestypeid").UIntegerValue,
                        cpf.GetSaveItem("stringsetgroupid").UIntegerValue,
                        cpf.GetSaveItem("stringsetid").UIntegerValue,
                        null
                        );
                AddFromXml(items);
            }
        }