public void Save(string filename, Platform platform, Game game) { //Get Text Blob var TextBlob = Encoding.UTF8.GetBytes(GMDContent.Content.Aggregate("", (output, c) => output + c.Text.Replace("\r\n", "\xa").Replace("\xa", "\r\n") + "\0")); //ReXOR, if needed if (platform == Platform.CTR && game == Game.DGS2) { TextBlob = new BinaryReaderX(XOR.ReXOR(TextBlob, 1)).ReadAllBytes(); } //Get Label Blob var LabelBlob = Encoding.ASCII.GetBytes(GMDContent.Content.Aggregate("", (output, c) => output + (c.Name.Contains("no_name") ? "" : c.Name + "\0"))); if (platform == Platform.Mobile || platform == Platform.Switch) { //Create Entries var LabelEntries = new List <LabelEntryMobile>(); var Buckets = new Dictionary <byte, int>(); int LabelOffset = 0; var LabelCount = GMDContent.Content.Count(c => !c.Name.Contains("no_name")); var counter = 0; for (var i = 0; i < GMDContent.Content.Count(); i++) { if (!GMDContent.Content[i].Name.Contains("no_name")) { LabelEntries.Add(new LabelEntryMobile { SectionID = i, Hash1 = ~Crc32.Create(GMDContent.Content[i].Name + GMDContent.Content[i].Name), Hash2 = ~Crc32.Create(GMDContent.Content[i].Name + GMDContent.Content[i].Name + GMDContent.Content[i].Name), LabelOffset = LabelOffset, ListLink = 0, ZeroPadding = platform == Platform.Switch ? 0xCDCDCDCD : 0 }); LabelOffset += Encoding.ASCII.GetByteCount(GMDContent.Content[i].Name) + 1; var bucket = (byte)(~Crc32.Create(GMDContent.Content[i].Name) & 0xff); if (Buckets.ContainsKey(bucket)) { LabelEntries[Buckets[bucket]].ListLink = counter; Buckets[bucket] = counter; } else { Buckets.Add(bucket, counter); } counter++; } } //Create bucketList Blob var BucketBlob = new long[0x100]; if (LabelCount > 0) { var counter2 = 0; for (var i = 0; i < GMDContent.Content.Count(); i++) { if (!GMDContent.Content[i].Name.Contains("no_name")) { var bucket = (byte)(~Crc32.Create(GMDContent.Content[i].Name) & 0xff); if (BucketBlob[bucket] == 0) { BucketBlob[bucket] = (counter2 == 0) ? -1 : counter2; } counter2++; } } } //Create Header var Header = new Header { Magic = "GMD\0", Version = 0x00010302, Language = Language.ENGLISH, LabelCount = LabelCount, SectionCount = GMDContent.Content.Count(), LabelSize = LabelBlob.Length, SectionSize = TextBlob.Length, NameSize = Encoding.ASCII.GetByteCount(GMDContent.Name) }; //Write Stuff using (var bw = new BinaryWriterX(File.Create(filename))) { //Header bw.WriteStruct(Header); bw.Write(Encoding.ASCII.GetBytes(GMDContent.Name + "\0")); //Entries foreach (var entry in LabelEntries) { bw.WriteStruct(entry); } //BucketList if (LabelCount > 0) { foreach (var bucket in BucketBlob) { bw.Write(bucket); } } //Labels bw.Write(LabelBlob); //Text Sections bw.Write(TextBlob); } } else if (platform == Platform.CTR) { //Create Entries var LabelEntries = new List <LabelEntry>(); var Buckets = new Dictionary <byte, int>(); int LabelOffset = 0; var LabelCount = GMDContent.Content.Count(c => !c.Name.Contains("no_name")); var counter = 0; for (var i = 0; i < GMDContent.Content.Count(); i++) { if (!GMDContent.Content[i].Name.Contains("no_name")) { LabelEntries.Add(new LabelEntry { SectionID = i, Hash1 = ~Crc32.Create(GMDContent.Content[i].Name + GMDContent.Content[i].Name), Hash2 = ~Crc32.Create(GMDContent.Content[i].Name + GMDContent.Content[i].Name + GMDContent.Content[i].Name), LabelOffset = LabelOffset, ListLink = 0 }); LabelOffset += Encoding.ASCII.GetByteCount(GMDContent.Content[i].Name) + 1; var bucket = (byte)(~Crc32.Create(GMDContent.Content[i].Name) & 0xff); if (Buckets.ContainsKey(bucket)) { LabelEntries[Buckets[bucket]].ListLink = counter; Buckets[bucket] = counter; } else { Buckets.Add(bucket, counter); } counter++; } } //Create bucketList Blob var BucketBlob = new int[0x100]; if (LabelCount > 0) { var counter2 = 0; for (var i = 0; i < GMDContent.Content.Count(); i++) { if (!GMDContent.Content[i].Name.Contains("no_name")) { var bucket = (byte)(~Crc32.Create(GMDContent.Content[i].Name) & 0xff); if (BucketBlob[bucket] == 0) { BucketBlob[bucket] = (counter2 == 0) ? -1 : counter2; } counter2++; } } } //Create Header var Header = new Header { Magic = "GMD\0", Version = 0x00010302, Language = Language.ENGLISH, LabelCount = LabelCount, SectionCount = GMDContent.Content.Count(), LabelSize = LabelBlob.Length, SectionSize = TextBlob.Length, NameSize = Encoding.ASCII.GetByteCount(GMDContent.Name) }; //Write Stuff using (var bw = new BinaryWriterX(File.Create(filename))) { //Header bw.WriteStruct(Header); bw.Write(Encoding.ASCII.GetBytes(GMDContent.Name + "\0")); //Entries foreach (var entry in LabelEntries) { bw.WriteStruct(entry); } //BucketList if (LabelCount > 0) { foreach (var bucket in BucketBlob) { bw.Write(bucket); } } //Labels bw.Write(LabelBlob); //Text Sections bw.Write(TextBlob); } } }
public void Save(string filename, Platform platform, Game game) { //Get Text Section var TextBlob = Encoding.UTF8.GetBytes(GMDContent.Content.Aggregate("", (output, c) => output + c.Text.Replace("\r\n", "\xa").Replace("\xa", "\r\n") + "\0")); //XOR, if needed if (platform == Platform.CTR && game == Game.DD) { TextBlob = new BinaryReaderX(XOR.ReXOR(TextBlob, 0)).ReadAllBytes(); } //Get Label Blob var LabelBlob = Encoding.ASCII.GetBytes(GMDContent.Content.Aggregate("", (output, c) => output + (c.Name.Contains("no_name") ? "" : c.Name + "\0"))); //Create LabelEntries var Entries = new List <LabelEntry>(); var LabelOffset = 0; var LabelCount = GMDContent.Content.Count(c => !c.Name.Contains("no_name")); for (int i = 0; i < GMDContent.Content.Count(); i++) { if (!GMDContent.Content[i].Name.Contains("no_name")) { Entries.Add(new LabelEntry { SectionID = i, LabelOffset = LabelOffset + (0x29080170 + LabelCount * 0x80) }); LabelOffset += Encoding.ASCII.GetByteCount(GMDContent.Content[i].Name) + 1; } } //Header var Header = new Header { Magic = GMDContent.ByteOrder == ByteOrder.BigEndian ? "\0DMG" : "GMD\0", Version = 0x00010201, Language = Language.ENGLISH, Zero1 = 0, LabelCount = LabelCount, SectionCount = GMDContent.Content.Count(), LabelSize = LabelBlob.Length, SectionSize = TextBlob.Length, NameSize = Encoding.ASCII.GetByteCount(GMDContent.Name) }; //Write stuff using (var bw = new BinaryWriterX(File.Create(filename), GMDContent.ByteOrder)) { //Header bw.WriteStruct(Header); bw.Write(Encoding.ASCII.GetBytes(GMDContent.Name + "\0")); //LabelEntries foreach (var entry in Entries) { bw.WriteStruct(entry); } //Labels bw.Write(LabelBlob); //Text Sections bw.Write(TextBlob); } }
public void Save(string filename, Platform platform, Game game) { //Get Text Section var TextBlob = Encoding.UTF8.GetBytes(GMDContent.Content.Aggregate("", (output, c) => output + c.Text.Replace("\r\n", "\xa").Replace("\xa", "\r\n") + "\0")); //XOR, if needed if (platform == Platform.CTR && game == Game.DD) { TextBlob = new BinaryReaderX(XOR.ReXOR(TextBlob, 0)).ReadAllBytes(); } //Get Label Blob var LabelBlob = Encoding.ASCII.GetBytes(GMDContent.Content.Aggregate("", (output, c) => output + (c.Name.Contains("no_name_") ? "" : c.Name + "\0"))); //Create LabelEntries var LabelEntries = new List <LabelEntry>(); var LabelOffset = 0; var LabelCount = GMDContent.Content.Count(c => !c.Name.Contains("no_name_")); for (var i = 0; i < GMDContent.Content.Count(); i++) { if (GMDContent.Content[i].Name.Contains("no_name_")) { continue; } LabelEntries.Add(new LabelEntry { SectionID = i, LabelOffset = LabelOffset + _firstLabelOffset }); LabelOffset += Encoding.ASCII.GetByteCount(GMDContent.Content[i].Name) + 1; } //Header FileHeader.LabelCount = LabelCount; FileHeader.SectionCount = GMDContent.Content.Count; FileHeader.LabelSize = LabelBlob.Length; FileHeader.SectionSize = TextBlob.Length; FileHeader.NameSize = Encoding.ASCII.GetByteCount(GMDContent.Name); //Write stuff using (var bw = new BinaryWriterX(File.Create(filename), GMDContent.ByteOrder)) { //Header bw.WriteStruct(FileHeader); bw.Write(Encoding.ASCII.GetBytes(GMDContent.Name + "\0")); //LabelEntries foreach (var entry in LabelEntries) { bw.WriteStruct(entry); } //Labels bw.Write(LabelBlob); //Text Sections bw.Write(TextBlob); } }