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

            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);
        }
        private void OnSave(object sender, EventArgs e)
        {
            using (var data = new MemoryStream())
            {
                _Resource.Serialize(_ResourceEntry.Version, data, _Endian);
                data.Flush();
                _ResourceEntry.Data = data.ToArray();
            }

            // Update
            var resource = new ResourceFormats.FlashResource();

            using (var data = new MemoryStream(_ResourceEntry.Data, false))
            {
                resource.Deserialize(_ResourceEntry.Version, data, _Endian);
            }
            _Resource            = resource;
            _HexBox.ByteProvider = new DynamicByteProvider(resource.Data);
        }
Example #3
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");
            }
        }