(NonColor): handle formats with different 8-to-32 bits integers conversion.

This commit is contained in:
morkt 2018-08-20 14:47:34 +04:00
parent 493a9c9922
commit 50ca23ec03
2 changed files with 19 additions and 5 deletions

View File

@ -286,6 +286,7 @@ namespace GameRes.Formats.NonColor
public long IndexPosition { get; set; } public long IndexPosition { get; set; }
public long MaxOffset { get { return m_max_offset; } } public long MaxOffset { get { return m_max_offset; } }
public bool ExtendByteSign { get; protected set; }
protected NcIndexReaderBase (ArcView file, int count) protected NcIndexReaderBase (ArcView file, int count)
{ {
@ -330,23 +331,33 @@ namespace GameRes.Formats.NonColor
Trace.WriteLine (string.Format ("[{0}] {1}", i, known_rec.Name), "[noncolor]"); Trace.WriteLine (string.Format ("[{0}] {1}", i, known_rec.Name), "[noncolor]");
last_reported = i; last_reported = i;
} }
entry.Offset ^= raw_name[raw_name.Length >> 1]; entry.Offset ^= Extend8Bit (raw_name[raw_name.Length >> 1]);
entry.Size ^= raw_name[raw_name.Length >> 2]; entry.Size ^= Extend8Bit (raw_name[raw_name.Length >> 2]);
entry.UnpackedSize ^= raw_name[raw_name.Length >> 3]; entry.UnpackedSize ^= Extend8Bit (raw_name[raw_name.Length >> 3]);
} }
} }
last_name = known_rec.Name; last_name = known_rec.Name;
if (!entry.CheckPlacement (MaxOffset)) if (!entry.CheckPlacement (MaxOffset))
return null; {
Trace.WriteLine (string.Format ("{0}: invalid placement [key:{1:X8}] [{2:X8}:{3:X8}]", entry.Name, entry.Hash, entry.Offset, entry.Size));
continue;
}
if (string.IsNullOrEmpty (entry.Name)) if (string.IsNullOrEmpty (entry.Name))
entry.Name = string.Format ("{0:D5}#{1:X8}", i, entry.Hash); entry.Name = string.Format ("{0:D5}#{1:X8}", i, entry.Hash);
m_dir.Add (entry); m_dir.Add (entry);
} }
if (skipped != 0) if (skipped != 0)
Trace.WriteLine (string.Format ("Missing {0} names", skipped), "[noncolor]"); Trace.WriteLine (string.Format ("Missing {0} names", skipped), "[noncolor]");
if (0 == m_dir.Count)
return null;
return m_dir; return m_dir;
} }
uint Extend8Bit (byte v)
{
return ExtendByteSign ? (uint)(int)(sbyte)v : v;
}
protected abstract ArcDatEntry ReadEntry (); protected abstract ArcDatEntry ReadEntry ();
#region IDisposable Members #region IDisposable Members

View File

@ -82,7 +82,10 @@ namespace GameRes.Formats.Minato
internal class MinatoIndexReader : NcIndexReaderBase internal class MinatoIndexReader : NcIndexReaderBase
{ {
public MinatoIndexReader (ArcView file, int count) : base (file, count) { } public MinatoIndexReader (ArcView file, int count) : base (file, count)
{
ExtendByteSign = true;
}
protected override ArcDatEntry ReadEntry () protected override ArcDatEntry ReadEntry ()
{ {