private static void Unpack(string output, List <byte> buffer, long offset) { var data = buffer.ToArray(); using (var ms = new MemoryStream(data)) { var name = output + $@"\{offset:X8}"; GCX.Unpack(ms, data.Length, name, offset); } }
private static void ExtractAllGCX() { var path = @"E:\Games\Metal Gear Solid\TS\DISC1\stage"; foreach (var file in Directory.GetFiles(path, "*.gcx", SearchOption.AllDirectories)) { using (var fs = File.OpenRead(file)) { GCX.Unpack(fs, (int)fs.Length, file, 0); } } path = @"E:\Games\Metal Gear Solid\TS\DISC2\stage"; foreach (var file in Directory.GetFiles(path, "*.gcx", SearchOption.AllDirectories)) { using (var fs = File.OpenRead(file)) { GCX.Unpack(fs, (int)fs.Length, file, 0); } } return; }
public static void Unpack(Stream stream, int length, string output, long position) { var gcx = new GCX(); gcx.Offset = position; gcx.Length = length; gcx.Magic = stream.ReadInt32BE(); while (true) { var value1 = stream.ReadUInt32BE(); var value2 = stream.ReadUInt32BE(); if (value1 == 0 && value2 == 0) { break; } else { gcx.Headers.Add(new Header { Unknown1 = value1, Unknown2 = value2 }); } } var start = stream.Position; var length2 = stream.ReadInt32(); var endian = stream.ReadInt32(); var textStart = stream.ReadInt32() + start; var fontStart = stream.ReadInt32() + start; while (stream.Position < textStart) { gcx.Entities.Add(new TextEntity { OffsetValue = stream.ReadUInt32() }); } foreach (var item in gcx.Entities) { var offset = item.OffsetValue & 0xFFFFFF; stream.Position = textStart + offset; item.Text = TextTable.GetString(stream.ReadToNull(), TextTable.Empty); } stream.Position = fontStart; var fontLength = stream.ReadInt32(); if (fontLength > 0) { gcx.FontData = stream.ReadBytes(fontLength); } Directory.CreateDirectory(Path.GetDirectoryName(output)); if (stream.Position < stream.Length) { File.WriteAllBytes(output + ".seq", stream.ReadBytes(stream.ReadInt32())); } if (stream.Position < stream.Length) { File.WriteAllBytes(output + ".unk", stream.ReadBytes(stream.ReadInt32())); } SerializationHelper.Save(gcx, output + ".xml"); }