fix: improve Sas5 formats handling

This commit is contained in:
scientificworld
2025-12-23 11:34:26 +08:00
parent 256672fc01
commit eddc66e958
2 changed files with 34 additions and 34 deletions

View File

@@ -59,21 +59,14 @@ namespace GameRes.Formats.Sas5
var GetEntryName = CreateEntryNameDelegate (file.Name); var GetEntryName = CreateEntryNameDelegate (file.Name);
index_offset += 0x20; index_offset += 0x20;
int real_count = 0; var dir = new List<Entry> ();
for (int i = 0; i < count; ++i)
{
int block = file.View.ReadInt32 (index_offset + i * 0x14);
real_count += Convert.ToInt32 (block != block_start);
}
var dir = new List<Entry> (real_count);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
int block = file.View.ReadInt32 (index_offset); int block = file.View.ReadInt32 (index_offset);
if (block == block_start) if (block == block_start)
continue; continue;
var entry = new Entry { var entry = new Entry {
Name = GetEntryName (i), Name = GetEntryName (i, block - block_start - 1),
Offset = file.View.ReadUInt32 (index_offset + 4), Offset = file.View.ReadUInt32 (index_offset + 4),
Size = file.View.ReadUInt32 (index_offset + 12), Size = file.View.ReadUInt32 (index_offset + 12),
}; };
@@ -89,17 +82,17 @@ namespace GameRes.Formats.Sas5
return new ArcFile (file, this, dir); return new ArcFile (file, this, dir);
} }
internal Func<int, string> CreateEntryNameDelegate (string arc_name) internal Func<int, int, string> CreateEntryNameDelegate (string arc_name)
{ {
var index = Sec5Opener.LookupIndex (arc_name); var index = Sec5Opener.LookupIndex (arc_name);
string base_name = Path.GetFileNameWithoutExtension (arc_name); string base_name = Path.GetFileNameWithoutExtension (arc_name);
if (null == index) if (null == index)
return n => GetDefaultName (base_name, n); return (n, m) => GetDefaultName (base_name, n);
else else
return (n) => { return (n, m) => {
Entry entry; Entry entry;
if (index.TryGetValue (n, out entry)) if (index.TryGetValue (m, out entry))
return entry.Name; return entry.Name.Substring (1); // remove leading slash
return GetDefaultName (base_name, n); return GetDefaultName (base_name, n);
}; };
} }

View File

@@ -112,29 +112,32 @@ namespace GameRes.Formats.Sas5
} }
if (0 == match.Length) if (0 == match.Length)
return null; return null;
using (var sec5 = new ArcView (match[0])) foreach (var m in match)
{ {
if (!sec5.View.AsciiEqual (0, "SEC5")) using (var sec5 = new ArcView (m))
return null;
uint offset = 8;
while (offset < sec5.MaxOffset)
{ {
string id = sec5.View.ReadString (offset, 4, Encoding.ASCII); if (!sec5.View.AsciiEqual (0, "SEC5"))
if ("ENDS" == id) continue;
break; uint offset = 8;
uint section_size = sec5.View.ReadUInt32 (offset+4); while (offset < sec5.MaxOffset)
offset += 8;
if ("RESR" == id)
{ {
using (var resr = sec5.CreateStream (offset, section_size)) string id = sec5.View.ReadString (offset, 4, Encoding.ASCII);
return ReadResrSection (resr); if ("ENDS" == id)
break;
uint section_size = sec5.View.ReadUInt32 (offset+4);
offset += 8;
if ("RESR" == id)
{
using (var resr = sec5.CreateStream (offset, section_size))
return ReadResrSection (resr);
}
if ("RES2" == id)
{
using (var res2 = sec5.CreateStream (offset, section_size))
return ReadRes2Section (res2);
}
offset += section_size;
} }
if ("RES2" == id)
{
using (var res2 = sec5.CreateStream (offset, section_size))
return ReadRes2Section (res2);
}
offset += section_size;
} }
} }
return null; return null;
@@ -413,10 +416,12 @@ namespace GameRes.Formats.Sas5
arc_name = ReadString(); arc_name = ReadString();
else if ("arc-index" == param_name) else if ("arc-index" == param_name)
arc_index = ReadInteger(); arc_index = ReadInteger();
else if ("arc-path" == param_name)
name = ReadString();
else else
SkipObject(); SkipObject();
} }
if (!string.IsNullOrEmpty (arc_name) && arc_index != null) if (!string.IsNullOrEmpty (arc_name))
{ {
arc_name = Path.GetFileName (arc_name); arc_name = Path.GetFileName (arc_name);
if (!map.ContainsKey (arc_name)) if (!map.ContainsKey (arc_name))
@@ -426,6 +431,8 @@ namespace GameRes.Formats.Sas5
Name = name, Name = name,
Type = type, Type = type,
}; };
if (arc_index == null)
arc_index = map[arc_name].Count;
map[arc_name][arc_index.Value] = entry; map[arc_name][arc_index.Value] = entry;
} }
} }