PR #84 changes

This commit is contained in:
dexy 2024-07-10 22:31:16 +10:00
parent f9a3559263
commit 9b8331e696
2 changed files with 8 additions and 10 deletions

View File

@ -139,7 +139,7 @@ namespace CodeWalker.GameFiles
} }
} }
public static void AssignPositions(IList<IResourceBlock> blocks, uint basePosition, out RpfResourcePageFlags pageFlags) public static void AssignPositions(IList<IResourceBlock> blocks, uint basePosition, out RpfResourcePageFlags pageFlags, uint maxPageCount)
{ {
if ((blocks.Count > 0) && (blocks[0] is Meta)) if ((blocks.Count > 0) && (blocks[0] is Meta))
{ {
@ -256,7 +256,7 @@ namespace CodeWalker.GameFiles
pageFlags = new RpfResourcePageFlags(pageCounts, baseShift); 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; break;
} }
@ -338,10 +338,10 @@ namespace CodeWalker.GameFiles
GetBlocks(fileBase, out systemBlocks, out graphicBlocks); GetBlocks(fileBase, out systemBlocks, out graphicBlocks);
RpfResourcePageFlags systemPageFlags; RpfResourcePageFlags systemPageFlags;
AssignPositions(systemBlocks, 0x50000000, out systemPageFlags); AssignPositions(systemBlocks, 0x50000000, out systemPageFlags, 128);
RpfResourcePageFlags graphicsPageFlags; RpfResourcePageFlags graphicsPageFlags;
AssignPositions(graphicBlocks, 0x60000000, out graphicsPageFlags); AssignPositions(graphicBlocks, 0x60000000, out graphicsPageFlags, 128 - systemPageFlags.Count);
fileBase.FilePagesInfo.SystemPagesCount = (byte)systemPageFlags.Count; fileBase.FilePagesInfo.SystemPagesCount = (byte)systemPageFlags.Count;

View File

@ -96,17 +96,16 @@ namespace CodeWalker.GameFiles
{ {
public override long BlockLength public override long BlockLength
{ {
get { return 20 + (256 * 16); } get { return 16 + (8 * (SystemPagesCount + GraphicsPagesCount)); }
} }
// structure data // structure data
public uint Unknown_0h { get; set; } public uint Unknown_0h { get; set; }
public uint Unknown_4h { 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 byte GraphicsPagesCount { get; set; }
public ushort Unknown_Ah { get; set; } public ushort Unknown_Ah { get; set; }
public uint Unknown_Ch { get; set; } public uint Unknown_Ch { get; set; }
public uint Unknown_10h { get; set; }
/// <summary> /// <summary>
/// Reads the data-block from a stream. /// Reads the data-block from a stream.
@ -120,7 +119,7 @@ namespace CodeWalker.GameFiles
this.GraphicsPagesCount = reader.ReadByte(); this.GraphicsPagesCount = reader.ReadByte();
this.Unknown_Ah = reader.ReadUInt16(); this.Unknown_Ah = reader.ReadUInt16();
this.Unknown_Ch = reader.ReadUInt32(); this.Unknown_Ch = reader.ReadUInt32();
this.Unknown_10h = reader.ReadUInt32(); reader.Position += 8 * (SystemPagesCount + GraphicsPagesCount);
} }
/// <summary> /// <summary>
@ -135,9 +134,8 @@ namespace CodeWalker.GameFiles
writer.Write(this.GraphicsPagesCount); writer.Write(this.GraphicsPagesCount);
writer.Write(this.Unknown_Ah); writer.Write(this.Unknown_Ah);
writer.Write(this.Unknown_Ch); writer.Write(this.Unknown_Ch);
writer.Write(this.Unknown_10h);
var pad = 256 * 16; var pad = 8 * (SystemPagesCount + GraphicsPagesCount);
writer.Write(new byte[pad]); writer.Write(new byte[pad]);
} }