From f0b8b1d7c89cf7bcaa7bb914aed9f46d1cd1100a Mon Sep 17 00:00:00 2001 From: Austin Blake Date: Thu, 25 Jul 2024 13:49:03 -0500 Subject: [PATCH] MessageScript: Use relocation table if IsRelocated is set; hack to fix unknown endianness issue with message text sizes --- .../IO/MessageScriptBinaryReader.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Source/AtlusScriptLibrary/MessageScriptLanguage/BinaryModel/IO/MessageScriptBinaryReader.cs b/Source/AtlusScriptLibrary/MessageScriptLanguage/BinaryModel/IO/MessageScriptBinaryReader.cs index b8385ef8..2648831e 100644 --- a/Source/AtlusScriptLibrary/MessageScriptLanguage/BinaryModel/IO/MessageScriptBinaryReader.cs +++ b/Source/AtlusScriptLibrary/MessageScriptLanguage/BinaryModel/IO/MessageScriptBinaryReader.cs @@ -1,4 +1,5 @@ using AtlusScriptLibrary.Common.IO; +using AtlusScriptLibrary.MessageScriptLanguage.IO; using System; using System.Collections.Generic; using System.Diagnostics; @@ -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; @@ -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++) { @@ -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; @@ -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