public void Load(string filename) { using (var br = new BinaryReaderX(File.OpenRead(filename))) { // Set endianess if (br.PeekString() == "\0DMG") { br.ByteOrder = GMDContent.ByteOrder = ByteOrder.BigEndian; } // Header var Header = br.ReadStruct <Header>(); var Name = br.ReadCStringA(); var HeaderLength = (int)br.BaseStream.Position; GMDContent.Name = Name; // Label Entries var LabelEntries = (Header.LabelCount > 0) ? br.ReadMultiple <LabelEntry>(Header.LabelCount) : new List <LabelEntry>(); var LabelDataOffset = (int)br.BaseStream.Position; // Text br.BaseStream.Position = 0x28 + (Header.NameSize + 1) + (Header.LabelCount * 0x8) + Header.LabelSize; var text = br.ReadBytes(Header.SectionSize); // Text deobfuscation var deXor = XOR.DeXOR(text); using (var brt = new BinaryReaderX(deXor)) { var counter = 0; for (var i = 0; i < Header.SectionCount; i++) { var bk = brt.BaseStream.Position; var tmp = brt.ReadByte(); while (tmp != 0) { tmp = brt.ReadByte(); } var textSize = brt.BaseStream.Position - bk; brt.BaseStream.Position = bk; //Get Label if existent var label = ""; if (LabelEntries.Find(l => l.SectionID == i) != null) { bk = br.BaseStream.Position; br.BaseStream.Position = LabelEntries.Find(l => l.SectionID == i).LabelOffset - LabelEntries.First().LabelOffset + (HeaderLength + Header.LabelCount * 0x8); label = br.ReadCStringA(); br.BaseStream.Position = bk; } GMDContent.Content.Add(new Label { Name = label == "" ? "no_name_" + counter++.ToString() : label, Text = brt.ReadString((int)textSize, Encoding.UTF8).Replace("\r\n", "\xa").Replace("\xa", "\r\n"), TextID = i }); } } } }
public void Load(string filename) { using (var br = new BinaryReaderX(File.OpenRead(filename))) { // Set endianess if (br.PeekString() == "\0DMG") { br.ByteOrder = GMDContent.ByteOrder = ByteOrder.BigEndian; } // Header var Header = br.ReadStruct <Header>(); var Name = br.ReadCStringA(); GMDContent.Name = Name; //Check for platform difference var fullSize = 0x28 + Name.Length + 1 + Header.LabelCount * 0x14 + ((Header.LabelCount > 0) ? 0x100 * 0x4 : 0) + Header.LabelSize + Header.SectionSize; if (fullSize != br.BaseStream.Length) { //Mobile structure //Entry var LabelEntries = (Header.LabelCount > 0) ? br.ReadMultiple <LabelEntryMobile>(Header.LabelCount) : new List <LabelEntryMobile>(); //Bucketlist var Buckets = (Header.LabelCount > 0) ? br.ReadMultiple <long>(0x100) : new List <long>(); var LabelDataOffset = (int)br.BaseStream.Position; // Text br.BaseStream.Position = 0x28 + (Header.NameSize + 1) + (Header.LabelCount * 0x20 + ((Header.LabelCount > 0) ? 0x100 * 0x8 : 0)) + Header.LabelSize; var text = br.ReadBytes(Header.SectionSize); // Text deobfuscation var deXor = XOR.DeXOR(text); using (var brt = new BinaryReaderX(deXor)) { var counter = 0; for (var i = 0; i < Header.SectionCount; i++) { var bk = brt.BaseStream.Position; var tmp = brt.ReadByte(); while (tmp != 0) { tmp = brt.ReadByte(); } var textSize = brt.BaseStream.Position - bk; brt.BaseStream.Position = bk; //Get Label if existent var label = ""; if (LabelEntries.Find(l => l.SectionID == i) != null) { bk = br.BaseStream.Position; br.BaseStream.Position = LabelDataOffset + LabelEntries.Find(l => l.SectionID == i).LabelOffset; label = br.ReadCStringA(); br.BaseStream.Position = bk; } GMDContent.Content.Add(new Label { Name = label == "" ? "no_name_" + counter++.ToString("000") : label, Text = brt.ReadString((int)textSize, Encoding.UTF8).Replace("\r\n", "\xa").Replace("\xa", "\r\n"), TextID = i }); } } } else { //CTR structure //Entry var LabelEntries = (Header.LabelCount > 0) ? br.ReadMultiple <LabelEntry>(Header.LabelCount) : new List <LabelEntry>(); //Bucketlist var Buckets = (Header.LabelCount > 0) ? br.ReadMultiple <int>(0x100) : new List <int>(); var LabelDataOffset = (int)br.BaseStream.Position; // Text br.BaseStream.Position = 0x28 + (Header.NameSize + 1) + (Header.LabelCount * 0x14 + ((Header.LabelCount > 0) ? 0x100 * 0x4 : 0)) + Header.LabelSize; var text = br.ReadBytes(Header.SectionSize); // Text deobfuscation var deXor = XOR.DeXOR(text); using (var brt = new BinaryReaderX(deXor)) { var counter = 0; for (var i = 0; i < Header.SectionCount; i++) { var bk = brt.BaseStream.Position; var tmp = brt.ReadByte(); while (tmp != 0) { tmp = brt.ReadByte(); } var textSize = brt.BaseStream.Position - bk; brt.BaseStream.Position = bk; //Get Label if existent var label = ""; if (LabelEntries.Find(l => l.SectionID == i) != null) { bk = br.BaseStream.Position; br.BaseStream.Position = LabelDataOffset + LabelEntries.Find(l => l.SectionID == i).LabelOffset; label = br.ReadCStringA(); br.BaseStream.Position = bk; } GMDContent.Content.Add(new Label { Name = label == "" ? "no_name_" + counter++.ToString("000") : label, Text = brt.ReadString((int)textSize, Encoding.UTF8).Replace("\r\n", "\xa").Replace("\xa", "\r\n"), TextID = i }); } } } } }