Skip to content

Commit

Permalink
Fix FARC loading for PSMD files with filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
evandixon committed Mar 9, 2020
1 parent 8336abf commit 3442acf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
18 changes: 15 additions & 3 deletions SkyEditor.ROMEditor/MysteryDungeon/PSMD/Farc.vb
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ Namespace MysteryDungeon.PSMD
DataOffset = Await f.ReadInt32Async(&H2C)
Dim dataLength = Await f.ReadInt32Async(&H30)

If Sir0Type <> 5 AndAlso Sir0Type <> 4 Then
Dim header As FarcFat5
If Sir0Type = 5 Then
header = New FarcFat5
ElseIf Sir0Type = 4 Then
header = New FarcFat4
Else
Throw New NotSupportedException("Only FARC v4 and v5 are supported for the time being")
End If

Dim header = New FarcFat5
Await header.OpenFile(Await f.ReadAsync(sir0Offset, sir0Length))
Sir0FatType = header.Sir0Fat5Type
UseFilenames = header.UsesFilenames
Expand Down Expand Up @@ -446,7 +450,15 @@ Namespace MysteryDungeon.PSMD
f.EnableInMemoryLoad = False
Await f.OpenFile(filename, provider)

Dim fat As New FarcFat5
Dim fat As FarcFat5
If Sir0Type = 5 Then
fat = New FarcFat5
ElseIf Sir0Type = 4 Then
fat = New FarcFat4
Else
Throw New NotSupportedException("Only FARC v4 and v5 are supported for the time being")
End If

fat.Sir0Fat5Type = If(Me.UseFilenames, 0, 1)
Dim fileData As New List(Of Byte)

Expand Down
31 changes: 19 additions & 12 deletions SkyEditor.ROMEditor/MysteryDungeon/PSMD/FarcFat5.vb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ Namespace MysteryDungeon.PSMD
End Get
End Property

Protected Overridable ReadOnly Property EntryLength As Integer
Get
Return 12
End Get
End Property

Public Async Function OpenFile(filename As String, provider As IFileSystem) As Task Implements IOpenableFile.OpenFile
Entries = New List(Of Entry)

Expand All @@ -87,22 +93,13 @@ Namespace MysteryDungeon.PSMD
Dim fileCount = BitConverter.ToInt32(sir0.ContentHeader, 4)
Sir0Fat5Type = BitConverter.ToInt32(sir0.ContentHeader, 8)

Dim entryLength As Integer
If Sir0Fat5Type = 0 Then
entryLength = 16
ElseIf Sir0Fat5Type = 1 Then
entryLength = 12
Else
Throw New NotSupportedException("FAT type not supported: " & Sir0Fat5Type.ToString())
End If

For count = 0 To fileCount - 1
Dim info As New Entry
info.Index = count

Dim filenameOffset = Await sir0.ReadUInt32Async(dataOffset + count * entryLength + 0)
info.DataOffset = Await sir0.ReadInt32Async(dataOffset + count * entryLength + 4)
info.DataLength = Await sir0.ReadInt32Async(dataOffset + count * entryLength + 8)
Dim filenameOffset = Await sir0.ReadUInt32Async(dataOffset + count * EntryLength + 0)
info.DataOffset = Await sir0.ReadInt32Async(dataOffset + count * EntryLength + 4)
info.DataLength = Await sir0.ReadInt32Async(dataOffset + count * EntryLength + 8)

If Sir0Fat5Type = 0 Then
info.Filename = Await sir0.ReadNullTerminatedUnicodeStringAsync(filenameOffset)
Expand Down Expand Up @@ -218,5 +215,15 @@ Namespace MysteryDungeon.PSMD
End Function

End Class

Public Class FarcFat4
Inherits FarcFat5

Protected Overrides ReadOnly Property EntryLength As Integer
Get
Return 16
End Get
End Property
End Class
End Namespace

0 comments on commit 3442acf

Please sign in to comment.