public Sir0 ToSir0() { var sir0 = new Sir0Builder(8); void align(int length) { var paddingLength = length - (sir0.Length % length); if (paddingLength != length) { sir0.WritePadding(sir0.Length, paddingLength); } } var pointers = new List <int>(); var entriesSectionStart = sir0.Length; // Write the strings foreach (var entry in Entries) { pointers.Add(sir0.Length); sir0.WriteNullTerminatedString(sir0.Length, encoding, entry); } // Write the pointers align(8); sir0.SubHeaderOffset = sir0.Length; sir0.WriteInt64(sir0.Length, Entries.Count); foreach (int pointer in pointers) { sir0.WritePointer(sir0.Length, pointer); } return(sir0.Build()); }
public Sir0 ToSir0() { var sir0 = new Sir0Builder(8); void align(int length) { var paddingLength = length - (sir0.Length % length); if (paddingLength != length) { sir0.WritePadding(sir0.Length, paddingLength); } } var allStringValues = Strings.Values.SelectMany(strList => strList).ToArray(); // Ensure that the order in the generated message.bin matches the original if possible var orderedStrings = allStringValues.OrderBy(str => str.Hash).ToArray(); foreach (var entry in orderedStrings) { entry.StringOffset = sir0.Length; sir0.WriteNullTerminatedString(sir0.Length, Encoding.Unicode, entry.Value); } align(8); int entriesOffset = sir0.Length; foreach (var entry in allStringValues) { sir0.MarkPointer(sir0.Length); sir0.WriteInt64(sir0.Length, entry.StringOffset); sir0.WriteInt32(sir0.Length, entry.Hash); sir0.WriteInt32(sir0.Length, entry.Unknown); } sir0.SubHeaderOffset = sir0.Length; sir0.WriteInt32(sir0.Length, Strings.Count); sir0.WriteInt32(sir0.Length, Strings.Count); sir0.MarkPointer(sir0.Length); sir0.WriteInt64(sir0.Length, entriesOffset); return(sir0.Build()); }
public Sir0 ToSir0() { var sir0 = new Sir0Builder(8); void align(int length) { var paddingLength = length - (sir0.Length % length); if (paddingLength != length) { sir0.WritePadding(sir0.Length, paddingLength); } } // Write the strings foreach (var entry in Entries) { align(8); entry.ModelNamePointer = sir0.Length; sir0.WriteNullTerminatedString(sir0.Length, Encoding.Unicode, entry.ModelName); align(8); entry.AnimationNamePointer = sir0.Length; sir0.WriteNullTerminatedString(sir0.Length, Encoding.Unicode, entry.AnimationName); align(8); entry.BaseFormModelNamePointer = sir0.Length; sir0.WriteNullTerminatedString(sir0.Length, Encoding.Unicode, entry.BaseFormModelName); align(8); entry.PortraitSheetNamePointer = sir0.Length; sir0.WriteNullTerminatedString(sir0.Length, Encoding.Unicode, entry.PortraitSheetName); align(8); entry.RescueCampSheetNamePointer = sir0.Length; sir0.WriteNullTerminatedString(sir0.Length, Encoding.Unicode, entry.RescueCampSheetName); align(8); entry.RescueCampSheetReverseNamePointer = sir0.Length; sir0.WriteNullTerminatedString(sir0.Length, Encoding.Unicode, entry.RescueCampSheetReverseName); } // Write the data align(8); var entriesSectionStart = sir0.Length; foreach (var entry in Entries) { var entryOffset = sir0.Length; sir0.Write(sir0.Length, entry.ToByteArray()); sir0.MarkPointer(entryOffset + 0); sir0.MarkPointer(entryOffset + 8); sir0.MarkPointer(entryOffset + 16); sir0.MarkPointer(entryOffset + 24); sir0.MarkPointer(entryOffset + 32); sir0.MarkPointer(entryOffset + 40); } // Write the content header sir0.SubHeaderOffset = sir0.Length; sir0.WriteString(sir0.Length, Encoding.ASCII, "PGDB"); align(8); sir0.WritePointer(sir0.Length, entriesSectionStart); sir0.WriteInt64(sir0.Length, Entries.Count); return(sir0.Build()); }