Skip to content

Commit

Permalink
Merge pull request #82 from austinleroy/Relocation
Browse files Browse the repository at this point in the history
Use relocation table
  • Loading branch information
tge-was-taken authored Nov 25, 2024
2 parents 60c49e9 + f0b8b1d commit c332fbd
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AtlusScriptLibrary.Common.IO;
using AtlusScriptLibrary.MessageScriptLanguage.IO;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -29,7 +30,7 @@ public MessageScriptBinary ReadBinary()
mHeader = ReadHeader()
};

binary.mDialogHeaders = ReadDialogHeaders(binary.mHeader.DialogCount);
binary.mDialogHeaders = ReadDialogHeaders(binary.mHeader);
binary.mSpeakerTableHeader = ReadSpeakerTableHeader();
binary.mFormatVersion = mVersion;

Expand Down Expand Up @@ -105,9 +106,10 @@ private void SwapHeader(ref BinaryHeader header)
EndiannessHelper.Swap(ref header.Version);
}

public BinaryDialogHeader[] ReadDialogHeaders(int count)
public BinaryDialogHeader[] ReadDialogHeaders(BinaryHeader mHeader)
{
BinaryDialogHeader[] headers = new BinaryDialogHeader[count];
BinaryDialogHeader[] headers = new BinaryDialogHeader[mHeader.DialogCount];
var offsets = RelocationTableEncoding.Decode(mHeader.RelocationTable.Value, 0);

for (int i = 0; i < headers.Length; i++)
{
Expand All @@ -116,7 +118,13 @@ public BinaryDialogHeader[] ReadDialogHeaders(int count)
header.Data.Offset = mReader.ReadInt32();

if (header.Data.Offset != 0)
header.Data.Value = ReadDialog(header.Kind, header.Data.Offset);
{
if (mHeader.IsRelocated) {
header.Data.Value = ReadDialog(header.Kind, header.Data.Offset + offsets[i]);
} else {
header.Data.Value = ReadDialog(header.Kind, header.Data.Offset);
}
}
}

return headers;
Expand Down Expand Up @@ -210,6 +218,8 @@ public BinaryMessageDialog ReadMessageDialog()
{
message.PageStartAddresses = mReader.ReadInt32s(message.PageCount);
message.TextBufferSize = mReader.ReadInt32();
if(message.TextBufferSize < 0 || message.TextBufferSize > (1 << 24)) // Endianness for this value seems to be swapped in some files... not sure what triggers it
EndiannessHelper.Swap(ref message.TextBufferSize);
message.TextBuffer = mReader.ReadBytes(message.TextBufferSize);
}
else
Expand Down

0 comments on commit c332fbd

Please sign in to comment.