public void LoadResourceEntry(ResourceEntry resourceEntry, string description, Endian endian)
        {
            var resource = new ResourceFormats.MemFileResource();

            using (var data = new MemoryStream(resourceEntry.Data, false))
            {
                resource.Deserialize(resourceEntry.Version, data, endian);
            }

            _ResourceEntry = resourceEntry;
            _Endian        = endian;
            _Description   = description;
            _Resource      = resource;

            _HexBox.ByteProvider = new DynamicByteProvider(resource.Data);
            _HexBox.ReadOnly     = true;
        }
Example #2
0
        private void OnContextMenuExtract(object sender, EventArgs e)
        {
            string pathSDS   = Program.ExtractPath(Program.FilePath);
            var    entryType = (ResourceType)_EntryTreeView.SelectedNode.Tag;
            string pathType  = Path.Combine(pathSDS, entryType.Name);

            var type = _Archive.ResourceTypes.SingleOrDefault(r => r.Name == entryType.Name);

            if (type != null && type.Name == entryType.Name)
            {
                var ResourceEntrys = new List <ResourceEntry>(_Archive.ResourceEntries.Where(c => c.TypeId == type.Id));
                if (ResourceEntrys.Count > 0)
                {
                    if (!Directory.Exists(pathType))
                    {
                        Directory.CreateDirectory(pathType);
                    }
                }

                for (int i = 0; i < ResourceEntrys.Count; i++)
                {
                    // string descript = i < _Descr.Count ? _Descr[i] : "unknown_" + i + ".bin";

                    string descript = "unknown_" + i + ".bin";

                    switch (type.Name)
                    {
                    case "XML":
                    {
                        var resource = new ResourceFormats.XmlResource();
                        using (var data = new MemoryStream(ResourceEntrys[i].Data, false))
                        {
                            resource.Deserialize(ResourceEntrys[i].Version, data, _Archive.Endian);
                        }
                        string path = pathType + resource.Name.Replace("/", "\\");
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        using (var sr = new StreamWriter(path + ".xml", false, System.Text.Encoding.UTF8))
                        {
                            sr.Write(resource.Content);
                        }
                        resource = null;
                    }
                    break;

                    case "MemFile":
                    {
                        var resource = new ResourceFormats.MemFileResource();
                        using (var data = new MemoryStream(ResourceEntrys[i].Data, false))
                        {
                            resource.Deserialize(ResourceEntrys[i].Version, data, _Archive.Endian);
                        }
                        string path = pathType + resource.Name.Replace("/", "\\");
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        File.WriteAllBytes(path, resource.Data);     //
                        resource = null;
                    }
                    break;

                    case "Texture":
                    {
                        var resource = new ResourceFormats.TextureResource();
                        using (var data = new MemoryStream(ResourceEntrys[i].Data, false))
                        {
                            resource.Deserialize(ResourceEntrys[i].Version, data, _Archive.Endian);
                        }
                        descript = FileFormats.Hashing.FileHash.Name(resource.NameHash);
                        if (!descript.Contains(".dds"))
                        {
                            descript += ".dds";
                        }
                        File.WriteAllBytes(Path.Combine(pathType, descript), resource.Data);
                        resource = null;
                    }
                    break;

                    case "Flash":
                    {
                        var resource = new ResourceFormats.FlashResource();
                        using (var data = new MemoryStream(ResourceEntrys[i].Data, false))
                        {
                            resource.Deserialize(ResourceEntrys[i].Version, data, _Archive.Endian);
                        }
                        string path = pathType + resource.Name.Replace("/", "\\");
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        // gfx
                        File.WriteAllBytes(path, resource.Data);     //

#if DEBUG
                        // swf (FWS)
                        if (resource.Data.Length >= 4)
                        {
                            resource.Data[0] = 0x46;
                            resource.Data[1] = 0x57;
                            resource.Data[2] = 0x53;
                        }
                        File.WriteAllBytes(Path.ChangeExtension(path, ".swf"), resource.Data);
#endif
                        resource = null;
                    }
                    break;

                    default:
                    {
                        File.WriteAllBytes(Path.Combine(pathType, descript), ResourceEntrys[i].Data);
                    }
                    break;
                    }

                    Application.DoEvents();
                }

                Helpers.ShowInformation("Output: " + pathType + "\r\nCompleted.", "Extracted");
            }
        }
Example #3
0
        public void LoadResourceEntry(ResourceEntry resourceEntry, string description, Endian endian)
        {
            var resource = new ResourceFormats.MemFileResource();

            using (var data = new MemoryStream(resourceEntry.Data, false))
            {
                resource.Deserialize(resourceEntry.Version, data, endian);
            }

            _ResourceEntry = resourceEntry;
            _Endian        = endian;
            _Description   = description;
            _Resource      = resource;

            //
            textLog.Clear();
            _LastPlaySound = 0;
            _LastWemPath   = "";

            _HeaderGeneral = null;
            _DIDXSection   = null;
            if (_DIDXData != null)
            {
                _DIDXData.Close();
                _DIDXData = null;
            }
            _Section.Clear();

            var input = new MemoryStream(resource.Data, false);

            if (input.ReadValueU32() != 0x44484b42)
            {
                Console.WriteLine("Invalid .bnk file");
                return;
            }

            uint headerSize = input.ReadValueU32();

            _HeaderGeneral = input.ReadBytes(headerSize);

#if DEBUG
            string hex = BitConverter.ToString(_HeaderGeneral).Replace("-", "");
            Console.WriteLine("header=" + hex);
#endif

            while (input.Position != input.Length)
            {
                uint section = input.ReadValueU32();
                if (section == 0x58444944) // DIDX
                {
                    _DIDXSection = ReadDIDXSection(input);
                }
                else if (section == 0x41544144) // DATA
                {
                    uint SectionSize = input.ReadValueU32();;
                    _DIDXData = new FileStream(_PathCache, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                    _DIDXData.WriteFromStream(input, SectionSize);
                    _DIDXData.Seek(0L, SeekOrigin.Begin);
                    Console.WriteLine("section='{0}' {1}", "DATA", SectionSize);
                }
                else if (section == 0x43524948) // HIRC
                {
#if _DEBUG
                    var posBegin = input.Position;
#endif

                    uint SectionSize = input.ReadValueU32();
                    _Section.Add(section, input.ReadBytes(SectionSize));
                    Console.WriteLine("section='{0}' {1}", "HIRC", SectionSize);
#if _DEBUG
                    var posEnd = input.Position;
                    input.Seek(posBegin, SeekOrigin.Begin);
                    var pHIRCSection = ReadHIRCSection(input);
                    input.Seek(posEnd, SeekOrigin.Begin);
#endif
                }
                else
                {
                    uint   SectionSize = input.ReadValueU32();
                    byte[] buffer      = input.ReadBytes(SectionSize);
                    _Section.Add(section, buffer);
                    string name = Encoding.ASCII.GetString(BitConverter.GetBytes(section));
                    Console.WriteLine("section='{0}' {1}", name, SectionSize);
                }
            }

            BuildEntryTree();

            input.Close();
        }