Ejemplo n.º 1
0
 internal static FARC analyzeFARC(string path)
 {
     FARC farc = new FARC
     {
         FileName = Path.GetFileNameWithoutExtension(path),
         FilePath = Path.GetDirectoryName(path),
         Extension = Path.GetExtension(path)
     };
     BinaryReader br = new BinaryReader(File.OpenRead(path));
     long len = br.BaseStream.Length;
     farc.Magic = br.ReadUInt32();
     UInt32 m = farc.Magic;
     farc.HeaderOffset = 0;
     while (m != 0x43524146 && farc.HeaderOffset < len - 4) //FARC
     {
         m = br.ReadUInt32();
         farc.HeaderOffset += 4;
     }
     if (farc.HeaderOffset >= len - 4)
     {
         farc.valid = false;
         return farc;
     }
     farc.Magic = m;
     farc.valid = true;
     br.BaseStream.Seek(farc.HeaderOffset + 0x24, SeekOrigin.Begin);
     farc.SirOffset = br.ReadUInt32() + farc.HeaderOffset;
     br.ReadUInt32(); //unk
     farc.DataOffset = br.ReadUInt32() + farc.HeaderOffset;
     br.BaseStream.Seek(farc.SirOffset, SeekOrigin.Begin);
     farc.SirMagic = br.ReadUInt32();
     if (farc.SirMagic != 0x30524953)
     {
         farc.valid = false;
         return farc;
     }
     farc.MetaPointer = farc.SirOffset + br.ReadUInt32();
     br.BaseStream.Seek(farc.MetaPointer, SeekOrigin.Begin);
     farc.TableOffset = farc.SirOffset + br.ReadUInt32();
     farc.FileCount = br.ReadUInt32();
     br.BaseStream.Seek(farc.TableOffset, SeekOrigin.Begin);
     FARCFileTable ft = new FARCFileTable
     {
         Files = new List<FARCFile>(),
         FileNames = new List<string>()
     };
     for (int i = 0; i < farc.FileCount; i++)
     {
         FARCFile file = new FARCFile
         {
             NameOffset = br.ReadUInt32(),
             Offset = br.ReadUInt32(),
             Length = br.ReadUInt32()
         };
         br.ReadUInt32(); //align to 0x10
         FARCFile f2 = file;
         ft.Files.Add(f2);
     }
     for (int i = 0; i < farc.FileCount; i++)
     {
         br.BaseStream.Seek(ft.Files[i].NameOffset + farc.SirOffset, SeekOrigin.Begin);
         MemoryStream stream = new MemoryStream();
         int firstByte = 1, secondByte = 1;
         while (firstByte != 0 || secondByte != 0)
         {
             firstByte = br.ReadByte();
             secondByte = br.ReadByte();
             stream.WriteByte((byte) firstByte);
             stream.WriteByte((byte) secondByte);
         }
         ft.FileNames.Add(Encoding.Unicode.GetString(stream.ToArray()));
         stream.Close();
     }
     farc.Files = ft;
     farc.FileName = Path.GetFileNameWithoutExtension(path);
     farc.FilePath = Path.GetDirectoryName(path);
     farc.Extension = Path.GetExtension(path);
     return farc;
 }
Ejemplo n.º 2
0
        internal static FARC analyzeFARC(string path)
        {
            FARC farc = new FARC
            {
                FileName  = Path.GetFileNameWithoutExtension(path),
                FilePath  = Path.GetDirectoryName(path),
                Extension = Path.GetExtension(path)
            };
            BinaryReader br  = new BinaryReader(File.OpenRead(path));
            long         len = br.BaseStream.Length;

            farc.Magic = br.ReadUInt32();
            uint m = farc.Magic;

            farc.HeaderOffset = 0;
            while (m != 0x43524146 && farc.HeaderOffset < len - 4) //FARC
            {
                m = br.ReadUInt32();
                farc.HeaderOffset += 4;
            }
            if (farc.HeaderOffset >= len - 4)
            {
                farc.valid = false;
                return(farc);
            }
            farc.Magic = m;
            farc.valid = true;
            br.BaseStream.Seek(farc.HeaderOffset + 0x24, SeekOrigin.Begin);
            farc.SirOffset = br.ReadUInt32() + farc.HeaderOffset;
            br.ReadUInt32(); //unk
            farc.DataOffset = br.ReadUInt32() + farc.HeaderOffset;
            br.BaseStream.Seek(farc.SirOffset, SeekOrigin.Begin);
            farc.SirMagic = br.ReadUInt32();
            if (farc.SirMagic != 0x30524953)
            {
                farc.valid = false;
                return(farc);
            }
            farc.MetaPointer = farc.SirOffset + br.ReadUInt32();
            br.BaseStream.Seek(farc.MetaPointer, SeekOrigin.Begin);
            farc.TableOffset = farc.SirOffset + br.ReadUInt32();
            farc.FileCount   = br.ReadUInt32();
            br.BaseStream.Seek(farc.TableOffset, SeekOrigin.Begin);
            FARCFileTable ft = new FARCFileTable
            {
                Files     = new List <FARCFile>(),
                FileNames = new List <string>()
            };

            for (int i = 0; i < farc.FileCount; i++)
            {
                FARCFile file = new FARCFile
                {
                    NameOffset = br.ReadUInt32(),
                    Offset     = br.ReadUInt32(),
                    Length     = br.ReadUInt32()
                };
                br.ReadUInt32(); //align to 0x10
                FARCFile f2 = file;
                ft.Files.Add(f2);
            }
            for (int i = 0; i < farc.FileCount; i++)
            {
                br.BaseStream.Seek(ft.Files[i].NameOffset + farc.SirOffset, SeekOrigin.Begin);
                MemoryStream stream = new MemoryStream();
                int          firstByte = 1, secondByte = 1;
                while (firstByte != 0 || secondByte != 0)
                {
                    firstByte  = br.ReadByte();
                    secondByte = br.ReadByte();
                    stream.WriteByte((byte)firstByte);
                    stream.WriteByte((byte)secondByte);
                }
                ft.FileNames.Add(Encoding.Unicode.GetString(stream.ToArray()));
                stream.Close();
            }
            farc.Files     = ft;
            farc.FileName  = Path.GetFileNameWithoutExtension(path);
            farc.FilePath  = Path.GetDirectoryName(path);
            farc.Extension = Path.GetExtension(path);
            return(farc);
        }