mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 13:45:34 +08:00
(TcdOpener): rearranged OpenEntry.
This commit is contained in:
parent
0faa25b356
commit
a244509039
@ -115,24 +115,20 @@ namespace GameRes.Formats.TopCat
|
|||||||
|
|
||||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||||
{
|
{
|
||||||
var tcde = entry as TcdEntry;
|
|
||||||
var tcda = arc as TcdArchive;
|
|
||||||
if (null == tcde || null == tcda)
|
|
||||||
return arc.File.CreateStream (entry.Offset, entry.Size);
|
|
||||||
if (entry.Name.EndsWith (".SPD", StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
return OpenSpdc (tcda, tcde);
|
|
||||||
if (entry.Name.EndsWith (".OGG", StringComparison.InvariantCultureIgnoreCase))
|
if (entry.Name.EndsWith (".OGG", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return RestoreOggStream (arc, entry);
|
return RestoreOggStream (arc, entry);
|
||||||
if (entry.Name.EndsWith (".TSF", StringComparison.InvariantCultureIgnoreCase) ||
|
if (entry.Name.EndsWith (".TSF", StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
entry.Name.EndsWith (".TCT", StringComparison.InvariantCultureIgnoreCase))
|
entry.Name.EndsWith (".TCT", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return OpenScript (tcda, tcde);
|
return OpenScript (arc, entry);
|
||||||
|
if (entry.Name.EndsWith (".SPD", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return OpenSpdc (arc, entry);
|
||||||
return arc.File.CreateStream (entry.Offset, entry.Size);
|
return arc.File.CreateStream (entry.Offset, entry.Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream OpenSpdc (TcdArchive arc, TcdEntry entry)
|
Stream OpenSpdc (ArcFile arc, Entry entry)
|
||||||
{
|
{
|
||||||
int signature = arc.File.View.ReadInt32 (entry.Offset);
|
int signature = arc.File.View.ReadInt32 (entry.Offset);
|
||||||
if (0x43445053 == signature || entry.Size <= 0x14) // 'SPDC'
|
if (0x43445053 == signature || 0x38445053 == signature || entry.Size <= 0x14)
|
||||||
return arc.File.CreateStream (entry.Offset, entry.Size);
|
return arc.File.CreateStream (entry.Offset, entry.Size);
|
||||||
|
|
||||||
var header = arc.File.View.ReadBytes (entry.Offset, 0x14);
|
var header = arc.File.View.ReadBytes (entry.Offset, 0x14);
|
||||||
@ -145,32 +141,37 @@ namespace GameRes.Formats.TopCat
|
|||||||
if (!spdc_entry)
|
if (!spdc_entry)
|
||||||
{
|
{
|
||||||
LittleEndian.Pack (signature, header, 0);
|
LittleEndian.Pack (signature, header, 0);
|
||||||
if (null == arc.Key)
|
var tcde = entry as TcdEntry;
|
||||||
|
var tcda = arc as TcdArchive;
|
||||||
|
if (tcda != null && tcde != null)
|
||||||
{
|
{
|
||||||
foreach (var key in TcdOpener.KnownKeys.Values)
|
if (null == tcda.Key)
|
||||||
{
|
{
|
||||||
int first = signature + key * (entry.Index + 3);
|
foreach (var key in TcdOpener.KnownKeys.Values)
|
||||||
if (0x43445053 == first) // 'SPDC'
|
|
||||||
{
|
{
|
||||||
arc.Key = key;
|
int first = signature + key * (tcde.Index + 3);
|
||||||
spdc_entry = true;
|
if (0x43445053 == first) // 'SPDC'
|
||||||
break;
|
{
|
||||||
|
tcda.Key = key;
|
||||||
|
spdc_entry = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (0x43445053 == (signature + tcda.Key.Value * (tcde.Index + 3)))
|
||||||
else if (0x43445053 == (signature + arc.Key.Value * (entry.Index + 3)))
|
|
||||||
{
|
|
||||||
spdc_entry = true;
|
|
||||||
}
|
|
||||||
if (spdc_entry && 0 != arc.Key.Value)
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
{
|
||||||
fixed (byte* raw = header)
|
spdc_entry = true;
|
||||||
|
}
|
||||||
|
if (spdc_entry && 0 != tcda.Key.Value)
|
||||||
|
{
|
||||||
|
unsafe
|
||||||
{
|
{
|
||||||
int* dw = (int*)raw;
|
fixed (byte* raw = header)
|
||||||
for (int i = 0; i < 5; ++i)
|
{
|
||||||
dw[i] += arc.Key.Value * (entry.Index + 3 + i);
|
int* dw = (int*)raw;
|
||||||
|
for (int i = 0; i < 5; ++i)
|
||||||
|
dw[i] += tcda.Key.Value * (tcde.Index + 3 + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +180,7 @@ namespace GameRes.Formats.TopCat
|
|||||||
return new PrefixStream (header, rest);
|
return new PrefixStream (header, rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream OpenScript (TcdArchive arc, TcdEntry entry)
|
Stream OpenScript (ArcFile arc, Entry entry)
|
||||||
{
|
{
|
||||||
int unpacked_size = arc.File.View.ReadInt32 (entry.Offset);
|
int unpacked_size = arc.File.View.ReadInt32 (entry.Offset);
|
||||||
byte[] data = new byte[unpacked_size];
|
byte[] data = new byte[unpacked_size];
|
||||||
|
Loading…
Reference in New Issue
Block a user