Advertisement
SciresM

ExtractXenobladeARC

Apr 17th, 2015
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. private void ExtractXenobladeARC(byte[] data, string arcname)
  2.         {
  3.             int count = BitConverter.ToInt32(data, 0x4);
  4.             int stringtableofs = BitConverter.ToInt32(data, 0xC);
  5.             if (count < 1) return;
  6.             string outdir = Path.GetDirectoryName(arcname) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(arcname) + "_" + Path.DirectorySeparatorChar;
  7.  
  8.             for (int i = 0; i < count; i++)
  9.             {
  10.                 Tuple<int, int> offset_size = Tuple.Create(BitConverter.ToInt32(data, 0x18 + 0x10 * i), BitConverter.ToInt32(data, 0x1C + 0x10 * i));
  11.                 byte[] fdata = new byte[offset_size.Item2];
  12.                 string filename;
  13.                 if (stringtableofs > 0)                    
  14.                     filename = new string(data.Skip((int)(stringtableofs + BitConverter.ToUInt32(data, (int)(stringtableofs + i * 0x4)))).TakeWhile(b => b != 0).Select(b => (char)b).ToArray());
  15.                 else
  16.                     filename = "arc/" + i.ToString("0000") + ".bin";
  17.                 string fileout = filename.Replace("arc/", outdir).Replace("/", String.Empty + Path.DirectorySeparatorChar);
  18.                 if (!Directory.Exists(Path.GetDirectoryName(fileout)))
  19.                     Directory.CreateDirectory(Path.GetDirectoryName(fileout));
  20.                 using (var fs = File.OpenRead(arcname))
  21.                 {
  22.                     fs.Seek(offset_size.Item1, SeekOrigin.Begin);
  23.                     fs.Read(fdata, 0, fdata.Length);
  24.                     fs.Close();
  25.                 }
  26.                 File.WriteAllBytes(fileout, fdata);
  27.             }
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement