示例#1
0
        private XPathDocument CheckForCrySDS()
        {
            int CrySDSType = -1;

            for (int i = 0; i != ResourceTypes.Count; i++)
            {
                // check if resource type has empty name
                if (ResourceTypes[i].Name == "")
                {
                    CrySDSType = (int)ResourceTypes[i].Id;
                }
            }

            // iterate entries and try to find the XML
            if (CrySDSType != -1)
            {
                for (int i = 0; i < ResourceEntries.Count; i++)
                {
                    if (ResourceEntries[i].TypeId == CrySDSType)
                    {
                        // Fix for CrySDS archives
                        using (MemoryStream stream = new MemoryStream(ResourceEntries[i].Data))
                        {
                            // Skip passwords
                            ushort authorLen = stream.ReadValueU16();
                            stream.ReadBytes(authorLen);
                            int fileSize = stream.ReadValueS32();
                            int password = stream.ReadValueS32();

                            // pull XML and create a new document
                            XPathDocument XMLDoc = null;
                            using (var reader = new StringReader(Encoding.UTF8.GetString(stream.ReadBytes(fileSize))))
                            {
                                XMLDoc = new XPathDocument(reader);
                            }

                            // Remove CrySDS lock
                            ResourceEntries.RemoveAt(i);
                            ResourceTypes.RemoveAt(CrySDSType);

                            // Return document
                            if (XMLDoc != null)
                            {
                                return(XMLDoc);
                            }
                        }
                    }
                }
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Save resource data from given sds data.
        /// </summary>
        /// <param name="xml"></param>
        public void SaveResources(FileInfo file)
        {
            XPathDocument doc = null;

            if (string.IsNullOrEmpty(ResourceInfoXml) == false)
            {
                using (var reader = new StringReader(ResourceInfoXml))
                    doc = new XPathDocument(reader);
            }
            else
            {
                int type = -1;
                for (int i = 0; i != ResourceTypes.Count; i++)
                {
                    if (ResourceTypes[i].Name == "")
                    {
                        type = (int)ResourceTypes[i].Id;
                    }
                }

                if (type != -1)
                {
                    for (int i = 0; i < ResourceEntries.Count; i++)
                    {
                        if (ResourceEntries[i].TypeId == type)
                        {
                            using (MemoryStream stream = new MemoryStream(ResourceEntries[i].Data))
                            {
                                ushort authorLen = stream.ReadValueU16();
                                stream.ReadBytes(authorLen);
                                int fileSize = stream.ReadValueS32();
                                int password = stream.ReadValueS32();

                                using (var reader = new StringReader(Encoding.UTF8.GetString(stream.ReadBytes(fileSize))))
                                {
                                    doc = new XPathDocument(reader);
                                }
                            }
                            ResourceEntries.RemoveAt(i);
                            ResourceTypes.RemoveAt(type);
                        }
                    }
                }
            }

            if (doc != null)
            {
                var nav   = doc.CreateNavigator();
                var nodes = nav.Select("/xml/ResourceInfo/SourceDataDescription");
                while (nodes.MoveNext() == true)
                {
                    _ResourceNames.Add(nodes.Current.Value);
                }
                Log.WriteLine("Found all items; count is " + nodes.Count);
            }


            if (_ResourceNames.Count == 0)
            {
                //Fix for friends for life SDS files.
                //MessageBox.Show("Detected SDS with no ResourceXML. I do not recommend repacking this SDS. It could cause crashes!", "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Log.WriteLine("Detected SDS with no ResourceXML. I do not recommend repacking this SDS. It could cause crashes!", LoggingTypes.WARNING);
                for (int i = 0; i != ResourceEntries.Count; i++)
                {
                    ResourceEntry Entry    = ResourceEntries[i];
                    string        Typename = _ResourceTypes[Entry.TypeId].Name;

                    // TODO: Find a new place for this.
                    string Extension = ".bin";
                    if (Typename == "Texture")
                    {
                        Extension = ".dds";
                    }
                    else if (Typename == "Generic")
                    {
                        Extension = ".genr";
                    }
                    else if (Typename == "Flash")
                    {
                        Extension = ".fla";
                    }
                    else if (Typename == "hkAnimation")
                    {
                        Extension = ".hkx";
                    }

                    string FileName = string.Format("File_{0}{1}", i, Extension);
                    _ResourceNames.Add(FileName);
                }
            }

            if (Version == 19)
            {
                SaveResourcesVersion19(file, _ResourceNames);
            }
            else if (Version == 20)
            {
                SaveResourcesVersion20(file, _ResourceNames);
            }
        }