diff --git a/CodeWalker.Core/GameFiles/Resources/ResourceBuilder.cs b/CodeWalker.Core/GameFiles/Resources/ResourceBuilder.cs index 773c9ec..a6ba380 100644 --- a/CodeWalker.Core/GameFiles/Resources/ResourceBuilder.cs +++ b/CodeWalker.Core/GameFiles/Resources/ResourceBuilder.cs @@ -139,7 +139,7 @@ namespace CodeWalker.GameFiles } } - public static void AssignPositions(IList blocks, uint basePosition, out RpfResourcePageFlags pageFlags) + public static void AssignPositions(IList blocks, uint basePosition, out RpfResourcePageFlags pageFlags, uint maxPageCount) { if ((blocks.Count > 0) && (blocks[0] is Meta)) { @@ -256,7 +256,7 @@ namespace CodeWalker.GameFiles pageFlags = new RpfResourcePageFlags(pageCounts, baseShift); - if ((pageCount == pageFlags.Count) && (pageFlags.Size >= currentPosition)) //make sure page counts fit in the flags value + if ((pageCount == pageFlags.Count) && (pageFlags.Size >= currentPosition) && (pageCount <= maxPageCount)) //make sure page counts fit in the flags value { break; } @@ -338,10 +338,10 @@ namespace CodeWalker.GameFiles GetBlocks(fileBase, out systemBlocks, out graphicBlocks); RpfResourcePageFlags systemPageFlags; - AssignPositions(systemBlocks, 0x50000000, out systemPageFlags); + AssignPositions(systemBlocks, 0x50000000, out systemPageFlags, 128); RpfResourcePageFlags graphicsPageFlags; - AssignPositions(graphicBlocks, 0x60000000, out graphicsPageFlags); + AssignPositions(graphicBlocks, 0x60000000, out graphicsPageFlags, 128 - systemPageFlags.Count); fileBase.FilePagesInfo.SystemPagesCount = (byte)systemPageFlags.Count; diff --git a/CodeWalker.Core/GameFiles/Resources/ResourceFile.cs b/CodeWalker.Core/GameFiles/Resources/ResourceFile.cs index 65d9b2d..6d9ff99 100644 --- a/CodeWalker.Core/GameFiles/Resources/ResourceFile.cs +++ b/CodeWalker.Core/GameFiles/Resources/ResourceFile.cs @@ -96,17 +96,16 @@ namespace CodeWalker.GameFiles { public override long BlockLength { - get { return 20 + (256 * 16); } + get { return 16 + (8 * (SystemPagesCount + GraphicsPagesCount)); } } // structure data public uint Unknown_0h { get; set; } public uint Unknown_4h { get; set; } - public byte SystemPagesCount { get; set; } + public byte SystemPagesCount { get; set; } = 128;//default sizing to ensure there is enough space allocated when writing files public byte GraphicsPagesCount { get; set; } public ushort Unknown_Ah { get; set; } public uint Unknown_Ch { get; set; } - public uint Unknown_10h { get; set; } /// /// Reads the data-block from a stream. @@ -120,7 +119,7 @@ namespace CodeWalker.GameFiles this.GraphicsPagesCount = reader.ReadByte(); this.Unknown_Ah = reader.ReadUInt16(); this.Unknown_Ch = reader.ReadUInt32(); - this.Unknown_10h = reader.ReadUInt32(); + reader.Position += 8 * (SystemPagesCount + GraphicsPagesCount); } /// @@ -135,9 +134,8 @@ namespace CodeWalker.GameFiles writer.Write(this.GraphicsPagesCount); writer.Write(this.Unknown_Ah); writer.Write(this.Unknown_Ch); - writer.Write(this.Unknown_10h); - var pad = 256 * 16; + var pad = 8 * (SystemPagesCount + GraphicsPagesCount); writer.Write(new byte[pad]); }