private static byte[] SerializeRelaData(SortedDictionary <long, SectionPointer> stringRelocTable, GameDataType dataType) { using MemoryStream stream = new MemoryStream(); using BinaryWriter writer = new BinaryWriter(stream); foreach ((long originOffset, SectionPointer pointer) in stringRelocTable) { if (pointer == SectionPointer.NULL) { continue; } SectionRela rela = dataType switch { // 0xB7E00000101 for strings and 0xB7F00000101 for pointers to .rodata GameDataType.DataNpcModel => new SectionRela(originOffset, pointer.Metadata - 0x600000101 + 0xB7E00000101, pointer.Pointer), _ => new SectionRela(originOffset, pointer.Metadata, pointer.Pointer), }; rela.ToBinaryWriter(writer); } return(stream.ToArray()); }
private static List <SectionRela> ParseRelocations(Section relaSection) { List <SectionRela> relas = new List <SectionRela>(); BinaryReader reader = relaSection.CreateBinaryReader(); while (reader.BaseStream.Position != reader.BaseStream.Length) { relas.Add(SectionRela.FromBinary(reader)); } reader.Dispose(); return(relas); }