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 floorInfoPointer = sir0.Length; foreach (var floor in FloorInfos) { sir0.Write(sir0.Length, floor.ToByteArray()); } align(16); var wildPokemonPointer = sir0.Length; if (WildPokemon != null) { sir0.Write(sir0.Length, WildPokemon.ToSir0().Data.ReadArray()); } align(16); var data3Pointer = sir0.Length; if (Data3 != null) { sir0.Write(sir0.Length, Data3.ToSir0().Data.ReadArray()); } align(16); var data4Pointer = sir0.Length; if (Data4 != null) { sir0.Write(sir0.Length, Data4.ToSir0().Data.ReadArray()); } // Write the content header align(16); sir0.SubHeaderOffset = sir0.Length; sir0.WritePointer(sir0.Length, floorInfoPointer); sir0.WritePointer(sir0.Length, wildPokemonPointer); sir0.WritePointer(sir0.Length, data3Pointer); sir0.WritePointer(sir0.Length, data4Pointer); 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 stats foreach (var stats in Stats) { stats.Pointer = sir0.Length; sir0.Write(sir0.Length, stats.ToByteArray()); } // Write the stats pointers var statsPointer = sir0.Length; foreach (var stats in Stats) { sir0.WritePointer(sir0.Length, stats.Pointer); } // Write the floor infos foreach (var floor in Floors) { floor.Pointer = sir0.Length; foreach (var floorEntry in floor.Entries) { sir0.Write(sir0.Length, floorEntry.ToByteArray()); } sir0.WritePadding(sir0.Length, 16, 0xFF); } // Write the content header align(16); sir0.SubHeaderOffset = sir0.Length; sir0.WriteInt64(sir0.Length, Stats.Length); sir0.WritePointer(sir0.Length, statsPointer); sir0.WriteInt64(sir0.Length, Floors.Length); foreach (var floor in Floors) { sir0.WritePointer(sir0.Length, floor.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); } } // Write the records foreach (var record in Records) { record.Pointer = sir0.Length; sir0.Write(sir0.Length, record.ToByteArray()); } // Write the content header align(16); sir0.SubHeaderOffset = sir0.Length; sir0.WriteInt64(sir0.Length, Records.Length); foreach (var record in Records) { sir0.WritePointer(sir0.Length, record.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 entriesSectionStart = sir0.Length; // Write the entries foreach (var entry in Entries) { align(8); sir0.Write(sir0.Length, entry.ToByteArray()); } // Write the content header sir0.SubHeaderOffset = sir0.Length; sir0.WriteString(sir0.Length, Encoding.ASCII, "PFDB"); align(8); sir0.WritePointer(sir0.Length, entriesSectionStart); sir0.WriteInt64(sir0.Length, Entries.Count); 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 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 void CanBuildSir0() { // Arrange var builder = new Sir0Builder(8); var testData = new int[] { 1, 2, 3, 7, 11, 13 }; // Act var pointers = new List <long>(); foreach (var value in testData) { pointers.Add(builder.Length); builder.WriteInt32(builder.Length, value); } builder.SubHeaderOffset = builder.Length; builder.WriteInt32(builder.Length, pointers.Count); foreach (var pointer in pointers) { builder.WritePointer(builder.Length, pointer); } var sir0 = builder.Build(); // Assert sir0.Data.Length.Should().BeGreaterThan( 0x20 // Header + (testData.Length * 4) // The integers from testData + (testData.Length * 8) // Pointers to each integer + (testData.Length)); // Minimum footer size. Testing the size of the footer is outside the scope of this test, but is covered by checking each pointer later sir0.PointerOffsets[0].Should().Be(8); // Index of the subheader pointer sir0.PointerOffsets[1].Should().Be(16); // Index of the footer pointer var entryCount = sir0.SubHeader.ReadInt32(0); entryCount.Should().Be(testData.Length); for (int i = 0; i < entryCount; i++) { var entryPointerOffset = sir0.SubHeaderOffset + 4 + i * 8; sir0.PointerOffsets[i + 2].Should().Be(entryPointerOffset); var entryPointer = sir0.SubHeader.ReadInt64(4 + i * 8); var entryPointerFromAbsolute = sir0.Data.ReadInt64(sir0.SubHeaderOffset + 4 + i * 8); entryPointerFromAbsolute.Should().Be(entryPointer); var entry = sir0.Data.ReadInt32(entryPointer); entry.Should().Be(testData[i]); } }
public Sir0 Build() { var builder = new Sir0Builder(8, 0x20 + Entries.Count * EntrySize + (Entries.Count + 1) * 8 + Entries.Count + 0x20); var pointers = new List <long>(); foreach (var entry in Entries) { pointers.Add(builder.Length); builder.Write(builder.Length, entry.ToByteArray()); } builder.SubHeaderOffset = builder.Length; builder.WriteInt64(builder.Length, Entries.Count); foreach (var pointer in pointers) { builder.WritePointer(builder.Length, pointer); } return(builder.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()); }