示例#1
0
        Stream OpenLstIndex(ArcView file, string dat_name, HibikiDatScheme scheme)
        {
            var lst_name = Path.ChangeExtension(file.Name, ".lst");

            if (VFS.FileExists(lst_name))
            {
                return(VFS.OpenStream(lst_name));
            }
            else if ("init.dat" == dat_name)
            {
                return(file.CreateStream());
            }
            // try to open 'init.dat' archive in the same directory
            var init_dat = VFS.CombinePath(VFS.GetDirectoryName(file.Name), "init.dat");

            if (!VFS.FileExists(init_dat))
            {
                return(file.CreateStream());
            }
            try
            {
                using (var init = VFS.OpenView(init_dat))
                    using (var init_arc = TryOpenWithScheme(init, ReadCount(init), scheme))
                    {
                        lst_name = Path.GetFileName(lst_name);
                        var lst_entry = init_arc.Dir.First(e => e.Name == lst_name);
                        return(init_arc.OpenEntry(lst_entry));
                    }
            }
            catch
            {
                return(file.CreateStream());
            }
        }
示例#2
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (RctMetaData)info;

            byte[] base_image = null;
            if (meta.FileName != null && meta.AddSize > 0 && OverlayFrames)
            {
                base_image = ReadBaseImage(file, meta);
            }

            var pixels = ReadPixelsData(file, meta);

            if (base_image != null)
            {
                pixels = CombineImage(base_image, pixels);
            }

            if (ApplyMask)
            {
                var base_name = Path.GetFileNameWithoutExtension(meta.FileName);
                var mask_name = base_name + "_.rc8";
                mask_name = VFS.CombinePath(VFS.GetDirectoryName(meta.FileName), mask_name);
                if (VFS.FileExists(mask_name))
                {
                    try
                    {
                        return(ApplyMaskToImage(meta, pixels, mask_name));
                    }
                    catch { /* ignore mask read errors */ }
                }
            }
            return(ImageData.Create(meta, PixelFormats.Bgr24, null, pixels, (int)meta.Width * 3));
        }
示例#3
0
        public override ArcFile TryOpen(ArcView file)
        {
            string lst_name = Path.ChangeExtension(file.Name, ".lst");

            if (lst_name == file.Name || !VFS.FileExists(lst_name))
            {
                return(null);
            }
            var lst_entry = VFS.FindFile(lst_name);
            int count     = (int)(lst_entry.Size / 0x16);

            if (count > 0xffff || count * 0x16 != lst_entry.Size)
            {
                return(null);
            }
            using (var lst = VFS.OpenView(lst_entry))
            {
                var  dir          = new List <Entry> (count);
                uint index_offset = 0;
                for (int i = 0; i < count; ++i)
                {
                    string name  = lst.View.ReadString(index_offset, 14);
                    var    entry = FormatCatalog.Instance.Create <Entry> (name);
                    entry.Offset = lst.View.ReadUInt32(index_offset + 14);
                    entry.Size   = lst.View.ReadUInt32(index_offset + 18);
                    if (!entry.CheckPlacement(file.MaxOffset))
                    {
                        return(null);
                    }
                    dir.Add(entry);
                    index_offset += 0x16;
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#4
0
文件: ImageRCT.cs 项目: zxc120/GARbro
 byte[] ReadBaseImage(IBinaryStream file, RctMetaData meta)
 {
     try
     {
         file.Position = meta.DataOffset;
         var    name     = file.ReadCString(meta.BaseNameLength);
         string dir_name = VFS.GetDirectoryName(meta.FileName);
         name = VFS.CombinePath(dir_name, name);
         if (VFS.FileExists(name))
         {
             using (var base_file = VFS.OpenBinaryStream(name))
             {
                 var base_info = ReadMetaData(base_file) as RctMetaData;
                 if (null != base_info &&
                     meta.Width == base_info.Width && meta.Height == base_info.Height)
                 {
                     base_info.BaseRecursionDepth = meta.BaseRecursionDepth + 1;
                     base_info.FileName           = name;
                     return(ReadPixelsData(base_file, base_info));
                 }
             }
         }
     }
     catch { /* ignore baseline image read errors */ }
     return(null);
 }
示例#5
0
        public override ArcFile TryOpen(ArcView file)
        {
            string lstname = file.Name + ".lst";

            if (!VFS.FileExists(lstname))
            {
                return(null);
            }
            using (var lst = VFS.OpenView(lstname))
            {
                List <Entry> dir = null;
                try
                {
                    dir = OpenMoon(lst, file.MaxOffset);
                }
                catch { /* ignore parse errors */ }
                if (null == dir)
                {
                    dir = OpenNexton(lst, file.MaxOffset);
                }
                if (null == dir)
                {
                    return(null);
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#6
0
文件: ArcBIN.cs 项目: zxc120/GARbro
        IList <string> GetFileNames(string arc_name)
        {
            var dir_name = VFS.GetDirectoryName(arc_name);
            var lst_name = Path.ChangeExtension(arc_name, ".lst");

            if (VFS.FileExists(lst_name))
            {
                return(ReadListFile(lst_name));
            }

            var lists_lst_name = VFS.CombinePath(dir_name, "lists.lst");

            if (!VFS.FileExists(lists_lst_name))
            {
                return(null);
            }
            var base_name = Path.GetFileNameWithoutExtension(arc_name);
            var arcs      = ReadListFile(lists_lst_name);
            var arc_no    = arcs.IndexOf(base_name);

            if (-1 == arc_no)
            {
                return(null);
            }
            var lists_bin_name = VFS.CombinePath(dir_name, "lists.bin");

            using (var lists_bin = VFS.OpenView(lists_bin_name))
                return(ReadFileNames(lists_bin, arc_no));
        }
示例#7
0
 /// <summary>
 // Try to parse file containing game meta-information.
 /// </summary>
 internal string TryParseMeta(string meta_arc_name)
 {
     if (!VFS.FileExists(meta_arc_name))
     {
         return(null);
     }
     using (var unpacker = new TocUnpacker(meta_arc_name))
     {
         if (unpacker.Length > 0x1000)
         {
             return(null);
         }
         var data = unpacker.Unpack(8);
         if (null == data)
         {
             return(null);
         }
         using (var content = new BinMemoryStream(data))
         {
             int title_length = content.ReadInt32();
             if (title_length <= 0 || title_length > content.Length)
             {
                 return(null);
             }
             var title = content.ReadBytes(title_length);
             if (title.Length != title_length)
             {
                 return(null);
             }
             return(Encodings.cp932.GetString(title));
         }
     }
 }
示例#8
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.Name.HasExtension(".BND"))
            {
                return(null);
            }
            var idx_name = Path.ChangeExtension(file.Name, "idx");

            if (!VFS.FileExists(idx_name))
            {
                return(null);
            }
            using (var idx = VFS.OpenBinaryStream(idx_name))
            {
                int count = (int)idx.Length / 0x18;
                if (!IsSaneCount(count) || count * 0x18 != idx.Length)
                {
                    return(null);
                }
                var dir = new List <Entry> (count);
                for (int i = 0; i < count; ++i)
                {
                    var name  = idx.ReadCString(0x10);
                    var entry = Create <Entry> (name);
                    entry.Size   = idx.ReadUInt32();
                    entry.Offset = idx.ReadUInt32();
                    if (!entry.CheckPlacement(file.MaxOffset))
                    {
                        return(null);
                    }
                    dir.Add(entry);
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#9
0
        public Dictionary <string, ArcView> GenerateResourceMap(List <Entry> dir)
        {
            var res_map   = new Dictionary <string, ArcView>();
            var asset_dir = VFS.GetDirectoryName(m_res_name);

            foreach (AssetEntry entry in dir)
            {
                if (null == entry.Bundle)
                {
                    continue;
                }
                if (res_map.ContainsKey(entry.Bundle.Name))
                {
                    continue;
                }
                var bundle_name = VFS.CombinePath(asset_dir, entry.Bundle.Name);
                if (!VFS.FileExists(bundle_name))
                {
                    entry.Bundle = null;
                    entry.Offset = entry.AssetObject.Offset;
                    entry.Size   = entry.AssetObject.Size;
                    continue;
                }
                res_map[entry.Bundle.Name] = VFS.OpenView(bundle_name);
            }
            return(res_map);
        }
示例#10
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            BitmapPalette palette = null;
            PixelFormat   format  = PixelFormats.Gray8;

            foreach (var pal_name in GetPaletteNames(info.FileName))
            {
                if (!VFS.FileExists(pal_name))
                {
                    continue;
                }
                try
                {
                    using (var pal = VFS.OpenStream(pal_name))
                    {
                        palette = ReadPalette(pal, 0x100, PaletteFormat.Bgr);
                        format  = PixelFormats.Indexed8;
                    }
                }
                catch { /* ignore palette read errors */ }
                break;
            }
            file.Position = 0x10;
            var pixels = file.ReadBytes((int)info.Width * (int)info.Height);

            return(ImageData.Create(info, format, palette, pixels));
        }
示例#11
0
 byte[] ReadBaseImage(Stream file, RctMetaData meta)
 {
     file.Position = meta.DataOffset;
     byte[] name_bin = new byte[meta.AddSize];
     if (name_bin.Length != file.Read(name_bin, 0, name_bin.Length))
     {
         throw new EndOfStreamException();
     }
     try
     {
         string name     = Encodings.cp932.GetString(name_bin, 0, name_bin.Length - 1);
         string dir_name = Path.GetDirectoryName(meta.FileName);
         name = VFS.CombinePath(dir_name, name);
         if (VFS.FileExists(name))
         {
             using (var base_file = VFS.OpenSeekableStream(name))
             {
                 var base_info = ReadMetaData(base_file) as RctMetaData;
                 if (null != base_info && 0 == base_info.AddSize &&
                     meta.Width == base_info.Width && meta.Height == base_info.Height)
                 {
                     base_info.FileName = name;
                     return(ReadPixelsData(base_file, base_info));
                 }
             }
         }
     }
     catch { /* ignore baseline image read errors */ }
     return(null);
 }
        public override ArcFile TryOpen(ArcView file)
        {
            string lstname = file.Name + ".lst"; //we find the name of the file with the name of the original file

            if (!VFS.FileExists(lstname))
            {
                return(null);
            }
            using (var lst = VFS.OpenView(lstname)) //lst is a view on the file lst that is created with the name of the file of the view
            {
                List <Entry> dir = null;
                try
                {
                    dir = OpenMoon(lst, file.MaxOffset);
                }
                catch { /* ignore parse errors */ }
                if (null == dir)
                {
                    dir = OpenNexton(lst, file.MaxOffset);
                }
                if (null == dir)
                {
                    return(null);
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#13
0
文件: ArcCPN.cs 项目: zxc120/GARbro
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.Name.HasExtension(".dat"))
            {
                return(null);
            }
            var cpn_name = Path.ChangeExtension(file.Name, ".cpn");

            if (!VFS.FileExists(cpn_name))
            {
                return(null);
            }
            byte   key;
            string cpn_index;

            using (var cpn = VFS.OpenView(cpn_name))
            {
                key = cpn.View.ReadByte(0);
                var cpn_data = cpn.View.ReadBytes(1, (uint)(cpn.MaxOffset - 1));
                for (int i = 0; i < cpn_data.Length; ++i)
                {
                    cpn_data[i] ^= key;
                }
                cpn_index = Encodings.cp932.GetString(cpn_data);
            }
            int idx = cpn_index.IndexOf('#', 1);

            if (idx <= 1)
            {
                return(null);
            }
            var data_name = cpn_index.Substring(1, idx - 1);

            if (!VFS.IsPathEqualsToFileName(file.Name, data_name))
            {
                return(null);
            }
            var dir   = new List <Entry>();
            var match = CpnEntryRe.Match(cpn_index, idx);

            while (match.Success)
            {
                var name  = match.Groups["name"].Value;
                var entry = FormatCatalog.Instance.Create <Entry> (name);
                entry.Offset = UInt32.Parse(match.Groups["offset"].Value);
                entry.Size   = UInt32.Parse(match.Groups["size"].Value);
                if (!entry.CheckPlacement(file.MaxOffset))
                {
                    return(null);
                }
                dir.Add(entry);
                match = match.NextMatch();
            }
            if (0 == dir.Count)
            {
                return(null);
            }
            return(new CpnArchive(file, this, dir, key));
        }
示例#14
0
 internal byte[] ReadToc(string toc_name, int num_length)
 {
     if (!VFS.FileExists(toc_name))
     {
         return(null);
     }
     using (var toc_unpacker = new TocUnpacker(toc_name))
         return(toc_unpacker.Unpack(num_length));
 }
示例#15
0
        public override ArcFile TryOpen(ArcView file)
        {
            var name = Path.GetFileName(file.Name);

            if (!NamePattern.IsMatch(name))
            {
                return(null);
            }
            var match   = NamePattern.Match(name);
            int name_id = 1;
            var num_str = match.Groups["num"].Value;

            if (!string.IsNullOrEmpty(num_str))
            {
                name_id = Int32.Parse(num_str);
            }
            if (name_id < 1)
            {
                return(null);
            }
            ArcView index = file;

            try
            {
                if (name_id != 1)
                {
                    string index_name;
                    if (file.Name.HasExtension(".dat"))
                    {
                        index_name = VFS.ChangeFileName(file.Name, "0001.dat");
                    }
                    else
                    {
                        index_name = VFS.ChangeFileName(file.Name, "data");
                    }
                    if (!VFS.FileExists(index_name))
                    {
                        return(null);
                    }
                    index = VFS.OpenView(index_name);
                }
                var dir = ReadIndex(index, name_id, file.MaxOffset);
                if (null == dir || 0 == dir.Count)
                {
                    return(null);
                }
                return(new ArcFile(file, this, dir));
            }
            finally
            {
                if (index != file)
                {
                    index.Dispose();
                }
            }
        }
示例#16
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.Name.HasExtension("DAT"))
            {
                return(null);
            }
            var hed_name = Path.ChangeExtension(file.Name, "HED");

            if (!VFS.FileExists(hed_name))
            {
                return(null);
            }
            using (var hed = VFS.OpenBinaryStream(hed_name))
            {
                var base_name   = Path.GetFileNameWithoutExtension(file.Name);
                var dir         = new List <Entry>();
                var name_buffer = new byte[0x100];
                while (hed.PeekByte() != -1)
                {
                    int    name_length = hed.ReadUInt8();
                    string name;
                    if (name_length != 0)
                    {
                        if (hed.Read(name_buffer, 0, name_length) != name_length)
                        {
                            return(null);
                        }
                        for (int i = 0; i < name_length; ++i)
                        {
                            name_buffer[i] ^= 0xFF;
                        }
                        name = Binary.GetCString(name_buffer, 0, name_length);
                    }
                    else
                    {
                        name = string.Format("{0}#{1:D4}", base_name, dir.Count);
                    }
                    var entry = new Entry {
                        Name   = name,
                        Offset = hed.ReadUInt32(),
                    };
                    if (entry.Offset > file.MaxOffset)
                    {
                        return(null);
                    }
                    dir.Add(entry);
                }
                if (0 == dir.Count)
                {
                    return(null);
                }
                AdjustSizes(dir, file.MaxOffset);
                DetectFileTypes(dir, file);
                return(new ArcFile(file, this, dir));
            }
        }
示例#17
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.Name.HasExtension(".lay"))
            {
                return(null);
            }
            int tile_count  = file.View.ReadInt32(0);
            int coord_count = file.View.ReadInt32(4);

            if (!IsSaneCount(tile_count) || !IsSaneCount(coord_count))
            {
                return(null);
            }
            var base_name = Path.GetFileNameWithoutExtension(file.Name).TrimEnd('_');
            var png_name  = VFS.ChangeFileName(file.Name, base_name + ".png");

            if (!VFS.FileExists(png_name))
            {
                return(null);
            }
            ImageData image;
            var       png_entry = VFS.FindFile(png_name);

            using (var decoder = VFS.OpenImage(png_entry))
                image = decoder.Image;
            using (var input = file.CreateStream())
                using (var index = new BinaryReader(input))
                {
                    input.Position = 8;
                    var dir = new List <Entry> (tile_count);
                    for (int i = 0; i < tile_count; ++i)
                    {
                        uint id    = index.ReadUInt32();
                        int  first = index.ReadInt32();
                        int  count = index.ReadInt32();
                        var  name  = string.Format("{0}#{1:X8}", base_name, id);
                        var  entry = new LayEntry {
                            Name = name, Type = "image", Offset = 0,
                            Id   = id, First = first, Count = count
                        };
                        dir.Add(entry);
                    }
                    var tiles = new List <LayCoord> (coord_count);
                    for (int i = 0; i < coord_count; ++i)
                    {
                        var tile = new LayCoord();
                        tile.TargetX = index.ReadSingle() + 1;
                        tile.TargetY = index.ReadSingle() + 1;
                        tile.SourceX = index.ReadSingle() - 1;
                        tile.SourceY = index.ReadSingle() - 1;
                        tiles.Add(tile);
                    }
                    return(new LayArchive(file, this, dir, image.Bitmap, tiles));
                }
        }
示例#18
0
        public override ArcFile TryOpen(ArcView file)
        {
            string lst_name = IndexExtensions.Select(ext => file.Name + ext)
                              .FirstOrDefault(name => VFS.FileExists(name));

            if (null == lst_name)
            {
                return(null);
            }
            using (var lst = VFS.OpenBinaryStream(lst_name))
            {
                const int name_length = 0x41;
                var       dir         = new List <Entry>();
                var       name_buffer = new byte[name_length];
                while (lst.Read(name_buffer, 0, name_length) == name_length)
                {
                    int name_end;
                    for (name_end = 0; name_end < name_length; ++name_end)
                    {
                        if (0 == name_buffer[name_end])
                        {
                            break;
                        }
                        name_buffer[name_end] ^= DefaultKey;
                    }
                    var  name   = Binary.GetCString(name_buffer, 0, name_end);
                    uint offset = lst.ReadUInt32();
                    if (offset > file.MaxOffset)
                    {
                        return(null);
                    }
                    byte type = lst.ReadUInt8();
                    if (type < KnownTypes.Length)
                    {
                        name = Path.ChangeExtension(name, KnownTypes[type]);
                    }
                    var entry = FormatCatalog.Instance.Create <YuEntry> (name);
                    entry.Offset      = offset;
                    entry.ContentType = type;
                    dir.Add(entry);
                }
                if (0 == dir.Count)
                {
                    return(null);
                }
                for (int i = 0; i < dir.Count; ++i)
                {
                    long next_offset = i + 1 == dir.Count ? file.MaxOffset : dir[i + 1].Offset;
                    dir[i].Size = (uint)(next_offset - dir[i].Offset);
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#19
0
文件: ArcSPD.cs 项目: zxc120/GARbro
        public override ArcFile TryOpen(ArcView file)
        {
            if (file.Name.HasExtension(".SPL"))
            {
                return(null);
            }
            var index_name = Path.ChangeExtension(file.Name, ".SPL");

            if (!VFS.FileExists(index_name))
            {
                return(null);
            }
            using (var idx = VFS.OpenView(index_name))
            {
                if (!idx.View.AsciiEqual(0, "SFP\0"))
                {
                    return(null);
                }
                uint align        = idx.View.ReadUInt32(0xC);
                uint index_offset = 0x20;
                uint names_offset = idx.View.ReadUInt32(index_offset);
                if (names_offset > idx.MaxOffset || names_offset <= index_offset)
                {
                    return(null);
                }
                int count = (int)(names_offset - index_offset) / 0x10;
                if (!IsSaneCount(count))
                {
                    return(null);
                }
                var dir = new List <Entry> (count);
                for (int i = 0; i < count; ++i)
                {
                    uint name_offset = idx.View.ReadUInt32(index_offset);
                    var  name        = idx.View.ReadString(name_offset, (uint)(idx.MaxOffset - name_offset));
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        return(null);
                    }
                    var entry = FormatCatalog.Instance.Create <Entry> (name);
                    entry.Size   = idx.View.ReadUInt32(index_offset + 4);
                    entry.Offset = (long)idx.View.ReadUInt32(index_offset + 8) * align;
                    if (!entry.CheckPlacement(file.MaxOffset))
                    {
                        return(null);
                    }
                    dir.Add(entry);
                    index_offset += 0x10;
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#20
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            var fge_name = Path.ChangeExtension(file.Name, ".fge");

            if (!VFS.FileExists(fge_name))
            {
                return(null);
            }
            using (var fg = OpenFg(file))
            {
                return(Fwgi.Value.ReadMetaData(fg));
            }
        }
示例#21
0
文件: ArcDAT.cs 项目: zxc120/GARbro
        public override ArcFile TryOpen(ArcView file)
        {
            var  arc_list   = new List <Entry>();
            long max_offset = file.MaxOffset;

            for (int i = 1; i < 100; ++i)
            {
                var part_name = Path.ChangeExtension(file.Name, string.Format("a{0:D02}", i));
                if (!VFS.FileExists(part_name))
                {
                    break;
                }
                var part = VFS.FindFile(part_name);
                arc_list.Add(part);
                max_offset += part.Size;
            }
            uint index_length = file.View.ReadUInt32(8);
            uint data_offset  = file.View.ReadUInt32(0x10);

            using (var zindex = file.CreateStream(0x20, index_length))
                using (var uindex = new ZLibStream(zindex, CompressionMode.Decompress))
                    using (var index = new BinaryStream(uindex, file.Name))
                    {
                        var buffer = new byte[500];
                        var dir    = new List <Entry>();
                        while (index.PeekByte() != -1)
                        {
                            int entry_length = index.ReadInt32();
                            if (entry_length <= 528)
                            {
                                return(null);
                            }
                            bool is_deleted = index.ReadUInt32() != 0;
                            var  entry      = new PackedEntry();
                            entry.Offset = index.ReadInt64() + data_offset;
                            index.ReadUInt32();
                            entry.Size         = index.ReadUInt32();
                            entry.UnpackedSize = index.ReadUInt32();
                            entry.IsPacked     = entry.Size != entry.UnpackedSize;
                            index.Read(buffer, 0, 500);
                            int name_length = index.Read(buffer, 0, entry_length - 528);
                            if (!is_deleted && entry.CheckPlacement(max_offset))
                            {
                                entry.Name = Encoding.Unicode.GetString(buffer, 0, name_length);
                                entry.Type = FormatCatalog.Instance.GetTypeFromName(entry.Name);
                                dir.Add(entry);
                            }
                        }
                        return(new Mpf2Archive(file, this, dir, arc_list));
                    }
        }
示例#22
0
文件: ArcGD.cs 项目: zxc120/GARbro
        public override ArcFile TryOpen(ArcView file)
        {
            string index_name = Path.ChangeExtension(file.Name, ".dll");

            if (index_name == file.Name || !VFS.FileExists(index_name))
            {
                return(null);
            }
            var index_entry = VFS.FindFile(index_name);

            if (index_entry.Size < 12)
            {
                return(null);
            }
            int count = file.View.ReadInt32(0);

            if (!IsSaneCount(count) || (count & 0xFFFF) == 0x5A4D)  // 'MZ'
            {
                return(null);
            }

            var base_name = Path.GetFileNameWithoutExtension(file.Name);

            using (var idx = VFS.OpenView(index_entry))
            {
                var  dir          = new List <Entry> (count);
                uint index_offset = 4;
                int  i            = 0;
                uint last_offset  = 3;
                while (index_offset + 8 <= idx.MaxOffset)
                {
                    uint offset = idx.View.ReadUInt32(index_offset);
                    if (offset <= last_offset)
                    {
                        return(null);
                    }
                    var name  = string.Format("{0}#{1:D5}", base_name, i++);
                    var entry = AutoEntry.Create(file, offset, name);
                    entry.Size = idx.View.ReadUInt32(index_offset + 4);
                    if (!entry.CheckPlacement(file.MaxOffset))
                    {
                        return(null);
                    }
                    dir.Add(entry);
                    last_offset   = offset;
                    index_offset += 8;
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#23
0
文件: ArcDAT.cs 项目: zxc120/GARbro
        public override ArcFile TryOpen(ArcView file)
        {
            int count = file.View.ReadInt32(4);

            if (!IsSaneCount(count))
            {
                return(null);
            }
            var pac_name = Path.GetFileNameWithoutExtension(file.Name);
            int pac_num;

            if (!Int32.TryParse(pac_name, out pac_num))
            {
                return(null);
            }
            var hdr_name = string.Format("{0:D3}.dat", pac_num - 1);

            hdr_name = VFS.ChangeFileName(file.Name, hdr_name);
            if (!VFS.FileExists(hdr_name))
            {
                return(null);
            }
            using (var index = VFS.OpenBinaryStream(hdr_name))
            {
                var header = index.ReadHeader(8);
                if (!header.AsciiEqual("\x89HDR"))
                {
                    return(null);
                }
                if (header.ToInt32(4) != count)
                {
                    return(null);
                }
                var dir = new List <Entry> (count);
                for (int i = 0; i < count; ++i)
                {
                    var name  = index.ReadCString(0x10);
                    var entry = FormatCatalog.Instance.Create <Entry> (name);
                    entry.Size   = index.ReadUInt32();
                    entry.Offset = index.ReadUInt32();
                    if (!entry.CheckPlacement(file.MaxOffset))
                    {
                        return(null);
                    }
                    dir.Add(entry);
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#24
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (file.Name.HasExtension(".lst"))
            {
                return(null);
            }
            var lst_name = Path.ChangeExtension(file.Name, ".lst");

            if (!VFS.FileExists(lst_name))
            {
                return(null);
            }
            using (var lst = VFS.OpenView(lst_name))
            {
                if (!lst.View.AsciiEqual(0, "ARC1.00"))
                {
                    return(null);
                }
                int count = lst.View.ReadInt32(8);
                if (!IsSaneCount(count))
                {
                    return(null);
                }
                uint lst_pos     = 0x10;
                var  name_buffer = new byte[0x20];
                var  dir         = new List <Entry> (count);
                for (int i = 0; i < count; ++i)
                {
                    lst.View.Read(lst_pos + 0x10, name_buffer, 0, 0x20);
                    for (int j = 0; j < 0x20 && name_buffer[j] != 0; ++j)
                    {
                        name_buffer[j] ^= 0x80;
                    }
                    var name  = Binary.GetCString(name_buffer, 0);
                    var entry = Create <PackedEntry> (name);
                    entry.Size   = lst.View.ReadUInt32(lst_pos + 8);
                    entry.Offset = lst.View.ReadUInt32(lst_pos + 0xC);
                    if (!entry.CheckPlacement(file.MaxOffset))
                    {
                        return(null);
                    }
                    entry.UnpackedSize = lst.View.ReadUInt32(lst_pos + 4);
                    entry.IsPacked     = lst.View.ReadInt32(lst_pos) != 0;
                    dir.Add(entry);
                    lst_pos += 0x30;
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#25
0
        public List <Entry> ReadIndex(ArcView file)
        {
            string       ari_name = Path.ChangeExtension(file.Name, "ari");
            List <Entry> dir      = null;

            if (file.Name != ari_name && VFS.FileExists(ari_name))
            {
                dir = ReadAriIndex(file, ari_name);
            }
            if (null == dir || 0 == dir.Count)
            {
                dir = BuildIndex(file);
            }
            return(dir);
        }
示例#26
0
文件: ArcDATA.cs 项目: zxc120/GARbro
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.View.AsciiEqual(0, "PF"))
            {
                return(null);
            }
            var base_name = Path.GetFileName(file.Name);

            if (!base_name.Equals("data02", StringComparison.InvariantCultureIgnoreCase))
            {
                return(null);
            }
            var index_name = VFS.CombinePath(VFS.GetDirectoryName(file.Name), "data01");

            if (!VFS.FileExists(index_name))
            {
                return(null);
            }
            using (var index = VFS.OpenView(index_name))
            {
                if (!index.View.AsciiEqual(0, "IF"))
                {
                    return(null);
                }
                int count = index.View.ReadInt16(2);
                if (!IsSaneCount(count) || 4 + 0x18 * count > index.MaxOffset)
                {
                    return(null);
                }

                uint index_offset = 4;
                var  dir          = new List <Entry> (count);
                for (int i = 0; i < count; ++i)
                {
                    var name  = index.View.ReadString(index_offset, 0x10);
                    var entry = FormatCatalog.Instance.Create <Entry> (name);
                    entry.Offset = index.View.ReadUInt32(index_offset + 0x10);
                    entry.Size   = index.View.ReadUInt32(index_offset + 0x14);
                    if (!entry.CheckPlacement(file.MaxOffset))
                    {
                        return(null);
                    }
                    dir.Add(entry);
                    index_offset += 0x18;
                }
                return(new ArcFile(file, this, dir));
            }
        }
示例#27
0
文件: ImageWBM.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            file.Position = 12;
            var           pixels       = file.ReadBytes((int)info.Width * (int)info.Height);
            var           format       = PixelFormats.Gray8;
            BitmapPalette palette      = null;
            var           palette_name = VFS.ChangeFileName(file.Name, "data.act");

            if (VFS.FileExists(palette_name))
            {
                using (var pal_file = VFS.OpenStream(palette_name))
                    palette = ReadPalette(pal_file, 0x100, PaletteFormat.Rgb);
                format = PixelFormats.Indexed8;
            }
            return(ImageData.Create(info, format, palette, pixels));
        }
示例#28
0
文件: ArcLINK.cs 项目: zxc120/GARbro
        public virtual LinkEncryption GetEncryption()
        {
            var params_dir = VFS.GetDirectoryName(m_input.Name);
            var params_dat = VFS.CombinePath(params_dir, "params.dat");

            if (!VFS.FileExists(params_dat))
            {
                return(null);
            }

            using (var input = VFS.OpenBinaryStream(params_dat))
            {
                var param = ParamsDeserializer.Create(input);
                return(param.GetEncryption());
            }
        }
示例#29
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.Name.EndsWith(".det", StringComparison.InvariantCultureIgnoreCase))
            {
                return(null);
            }
            var name_file  = Path.ChangeExtension(file.Name, "nme");
            var index_file = Path.ChangeExtension(file.Name, "atm");

            if (!VFS.FileExists(name_file) || !VFS.FileExists(index_file))
            {
                return(null);
            }
            using (var nme = VFS.OpenView(name_file))
                using (var idx = VFS.OpenView(index_file))
                {
                    int count = (int)(idx.MaxOffset / 0x14);
                    if (!IsSaneCount(count))
                    {
                        return(null);
                    }
                    uint idx_offset = 0;
                    var  name_table = nme.View.ReadBytes(0, (uint)nme.MaxOffset);
                    var  dir        = new List <Entry> (count);
                    for (int i = 0; i < count; ++i)
                    {
                        int name_offset = idx.View.ReadInt32(idx_offset);
                        if (name_offset < 0 || name_offset >= name_table.Length)
                        {
                            return(null);
                        }
                        var name  = Binary.GetCString(name_table, name_offset, name_table.Length - name_offset);
                        var entry = FormatCatalog.Instance.Create <PackedEntry> (name);
                        entry.Offset = idx.View.ReadUInt32(idx_offset + 4);
                        entry.Size   = idx.View.ReadUInt32(idx_offset + 8);
                        if (!entry.CheckPlacement(file.MaxOffset))
                        {
                            return(null);
                        }
                        entry.UnpackedSize = idx.View.ReadUInt32(idx_offset + 0x10);
                        entry.IsPacked     = true;
                        dir.Add(entry);
                        idx_offset += 0x14;
                    }
                    return(new ArcFile(file, this, dir));
                }
        }
示例#30
0
        public override ArcFile TryOpen(ArcView file)
        {
            var pft_name = Path.ChangeExtension(file.Name, "pft");

            if (file.Name.Equals(pft_name, StringComparison.InvariantCultureIgnoreCase) ||
                !VFS.FileExists(pft_name))
            {
                return(null);
            }
            using (var pft_view = VFS.OpenView(pft_name))
                using (var pft = pft_view.CreateStream())
                {
                    var    arc_name = Path.GetFileNameWithoutExtension(file.Name);
                    string ext      = "";
                    ExtensionMap.TryGetValue(arc_name, out ext);
                    uint header_size  = pft.ReadUInt16();
                    uint cluster_size = pft.ReadUInt16();
                    int  count        = pft.ReadInt32();
                    if (!IsSaneCount(count))
                    {
                        return(null);
                    }

                    pft.Position = header_size;
                    var dir = new List <Entry> (count);
                    for (int i = 0; i < count; ++i)
                    {
                        var name = pft.ReadCString(8);
                        if (name.Length > 0)
                        {
                            if (!string.IsNullOrEmpty(ext))
                            {
                                name = Path.ChangeExtension(name, ext);
                            }
                            var entry = FormatCatalog.Instance.Create <Entry> (name);
                            entry.Offset = cluster_size * (long)pft.ReadUInt32();
                            entry.Size   = pft.ReadUInt32();
                            if (!entry.CheckPlacement(file.MaxOffset))
                            {
                                return(null);
                            }
                            dir.Add(entry);
                        }
                    }
                    return(new ArcFile(file, this, dir));
                }
        }