(SakanaGL): support new version

This commit is contained in:
Crsky 2023-01-09 16:31:09 +08:00
parent 99778823f1
commit 1ab7087fe7

View File

@ -28,17 +28,25 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
namespace GameRes.Formats.Sakana namespace GameRes.Formats.Sakana
{ {
internal class SxEntry : PackedEntry internal class SxEntry : PackedEntry
{ {
public int Storage;
public ushort Flags; public ushort Flags;
public bool IsEncrypted { get { return 0 == (Flags & 0x10); } } public bool IsEncrypted { get { return 0 == (Flags & 0x10); } }
} }
internal class SxStorage
{
public uint Size;
public ulong Timestamp;
}
[Export(typeof(ArchiveFormat))] [Export(typeof(ArchiveFormat))]
public class SxOpener : ArchiveFormat public class SxOpener : ArchiveFormat
{ {
@ -52,9 +60,7 @@ namespace GameRes.Formats.Sakana
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
var base_name = Path.GetFileName (file.Name); var sx_name = FindSxName (file.Name);
var sx_name = base_name.Substring (0, 4) + "(00).sx";
sx_name = VFS.ChangeFileName (file.Name, sx_name);
if (!VFS.FileExists (sx_name) || file.Name.Equals (sx_name, StringComparison.InvariantCultureIgnoreCase)) if (!VFS.FileExists (sx_name) || file.Name.Equals (sx_name, StringComparison.InvariantCultureIgnoreCase))
return null; return null;
byte[] index_data; byte[] index_data;
@ -140,6 +146,20 @@ namespace GameRes.Formats.Sakana
} }
} }
} }
internal static string FindSxName(string name)
{
var base_name = Path.GetFileName (name);
var file_name = Path.GetFileNameWithoutExtension (base_name);
for (var i = 1; i <= file_name.Length; i++)
{
var sx_name = file_name.Substring (0, i) + "(00).sx";
sx_name = VFS.ChangeFileName (name, sx_name);
if (VFS.FileExists (sx_name))
return sx_name;
}
return name;
}
} }
internal class SxIndexDeserializer internal class SxIndexDeserializer
@ -170,36 +190,47 @@ namespace GameRes.Formats.Sakana
m_dir = new List<Entry> (count); m_dir = new List<Entry> (count);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
m_index.ReadUInt16(); m_index.ReadByte();
int storage = m_index.ReadByte();
ushort flags = Binary.BigEndian (m_index.ReadUInt16()); ushort flags = Binary.BigEndian (m_index.ReadUInt16());
uint offset = Binary.BigEndian (m_index.ReadUInt32()); uint offset = Binary.BigEndian (m_index.ReadUInt32());
uint size = Binary.BigEndian (m_index.ReadUInt32()); uint size = Binary.BigEndian (m_index.ReadUInt32());
var entry = new SxEntry { var entry = new SxEntry {
Storage = storage,
Flags = flags, Flags = flags,
Offset = (long)offset << 4, Offset = (long)offset << 4,
Size = size, Size = size,
IsPacked = 0 != (flags & 0x03), IsPacked = 0 != (flags & 0x03),
}; };
if (!entry.CheckPlacement (m_max_offset))
return null;
m_dir.Add (entry); m_dir.Add (entry);
} }
count = Binary.BigEndian (m_index.ReadUInt16()); count = Binary.BigEndian (m_index.ReadUInt16());
var storages = new List<SxStorage>(count);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
m_index.ReadUInt32(); m_index.ReadUInt32();
m_index.ReadUInt32(); m_index.ReadUInt32();
m_index.ReadUInt32(); m_index.ReadUInt32();
Binary.BigEndian (m_index.ReadUInt32()); // archive body length var storage = new SxStorage {
m_index.ReadUInt64(); Size = Binary.BigEndian (m_index.ReadUInt32()) << 4,
m_index.Seek (16, SeekOrigin.Current); // MD5 sum Timestamp = Binary.BigEndian (m_index.ReadUInt64()),
};
storages.Add (storage);
m_index.Seek (16, SeekOrigin.Current); // MD5
} }
count = Binary.BigEndian (m_index.ReadUInt16()); count = Binary.BigEndian (m_index.ReadUInt16());
if (count > 0) if (count > 0)
m_index.Seek (count * 24, SeekOrigin.Current); m_index.Seek (count * 24, SeekOrigin.Current);
DeserializeTree(); DeserializeTree();
// Remove entries in other archives
// Note using file size as archive identification can be problematic, but faster than MD5
var current_storage = storages.FindIndex (s => m_max_offset == s.Size);
if (-1 != current_storage)
{
m_dir = m_dir.Where (e => e.CheckPlacement (m_max_offset) && (e as SxEntry).Storage == current_storage).ToList();
}
return m_dir; return m_dir;
} }