NHSE/NHSE.Core/Hashing/FileHashRegion.cs
Kurt 3ff7c251fd Add updated hashes
Thanks @3096 for github.com/3096/effective-guacamole -- used to dump the hash list.

Refine the FileHashRegion struct; in the savefile it's just:
u32 hash
byte[length] data

we can compute start offset (= hash offset + 4) rather than storing an extra int, simplifies things so that we can just copypaste from guac into a hash,len definition list :D
2020-07-02 22:29:08 -05:00

55 lines
1.7 KiB
C#

namespace NHSE.Core
{
/// <summary>
/// Specifies the region that a validation hash is calculated over.
/// </summary>
public readonly struct FileHashRegion
{
/// <summary>
/// Offset of the calculated hash.
/// </summary>
public readonly int HashOffset;
/// <summary>
/// Length of the hashed data.
/// </summary>
public readonly int Size;
/// <summary>
/// Offset where the data to be hashed starts at (calculated).
/// </summary>
public int BeginOffset => HashOffset + 4;
/// <summary>
/// Offset where the data to be hashed ends at (calculated).
/// </summary>
public int EndOffset => BeginOffset + Size;
public override string ToString() => $"0x{HashOffset:X}: (0x{BeginOffset:X}-0x{EndOffset:X})";
public FileHashRegion(int hashOfs, int size)
{
HashOffset = hashOfs;
Size = size;
}
#region Equality Comparison
public override bool Equals(object obj) => obj is FileHashRegion r && r == this;
// ReSharper disable once PossiblyImpureMethodCallOnReadonlyVariable
public override int GetHashCode() => BeginOffset.GetHashCode();
public static bool operator !=(FileHashRegion left, FileHashRegion right) => !(left == right);
public static bool operator ==(FileHashRegion left, FileHashRegion right)
{
if (left.HashOffset != right.HashOffset)
return false;
if (left.BeginOffset != right.BeginOffset)
return false;
if (left.Size != right.Size)
return false;
return true;
}
#endregion
}
}