mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Misc tweaks (#111)
- Use System.HashCode in GetHashCode methods - Update master key revisions. - Remove some unneeded utility functions - Suppress a spurious ReSharper warning
This commit is contained in:
parent
1ae973a346
commit
35b82f5d6e
7 changed files with 24 additions and 94 deletions
|
@ -44,10 +44,7 @@ namespace LibHac.Common
|
|||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (High.GetHashCode() * 397) ^ Low.GetHashCode();
|
||||
}
|
||||
return HashCode.Combine(High, Low);
|
||||
}
|
||||
|
||||
public int CompareTo(Id128 other)
|
||||
|
|
|
@ -36,10 +36,7 @@ namespace LibHac.Common
|
|||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hashCode = -1653217991;
|
||||
hashCode = hashCode * -1521134295 + _dummy1.GetHashCode();
|
||||
hashCode = hashCode * -1521134295 + _dummy2.GetHashCode();
|
||||
return hashCode;
|
||||
return HashCode.Combine(_dummy1, _dummy2);
|
||||
}
|
||||
|
||||
public static bool operator ==(Key128 left, Key128 right) => left.Equals(right);
|
||||
|
|
|
@ -33,14 +33,7 @@ namespace LibHac.Fs
|
|||
public override int GetHashCode()
|
||||
{
|
||||
// ReSharper disable NonReadonlyMemberInGetHashCode
|
||||
int hashCode = 487790375;
|
||||
hashCode = hashCode * -1521134295 + TitleId.GetHashCode();
|
||||
hashCode = hashCode * -1521134295 + Type.GetHashCode();
|
||||
hashCode = hashCode * -1521134295 + UserId.GetHashCode();
|
||||
hashCode = hashCode * -1521134295 + SaveDataId.GetHashCode();
|
||||
hashCode = hashCode * -1521134295 + Rank.GetHashCode();
|
||||
hashCode = hashCode * -1521134295 + Index.GetHashCode();
|
||||
return hashCode;
|
||||
return HashCode.Combine(TitleId, Type, UserId, SaveDataId, Rank, Index);
|
||||
// ReSharper restore NonReadonlyMemberInGetHashCode
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace LibHac.Fs.Shim
|
|||
|
||||
static Result Run(FileSystemClient fs, U8Span mountName, U8Span path)
|
||||
{
|
||||
// ReSharper disable once VariableHidesOuterVariable
|
||||
Result rc = MountHelpers.CheckMountName(mountName);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
|
|
|
@ -50,16 +50,9 @@ namespace LibHac.Ncm
|
|||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
// ReSharper disable NonReadonlyMemberInGetHashCode
|
||||
int hashCode = TitleId.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ (int)Version;
|
||||
hashCode = (hashCode * 397) ^ Type.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Attributes.GetHashCode();
|
||||
return hashCode;
|
||||
// ReSharper restore NonReadonlyMemberInGetHashCode
|
||||
}
|
||||
// ReSharper disable NonReadonlyMemberInGetHashCode
|
||||
return HashCode.Combine(TitleId, Version, Type, Attributes);
|
||||
// ReSharper restore NonReadonlyMemberInGetHashCode
|
||||
}
|
||||
|
||||
public int CompareTo(ContentMetaKey other)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// ReSharper disable UnusedVariable
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
|
||||
namespace LibHac.Npdm
|
||||
|
@ -53,10 +54,10 @@ namespace LibHac.Npdm
|
|||
reader.ReadInt32();
|
||||
|
||||
//System resource size (max size as of 5.x: 534773760).
|
||||
SystemResourceSize = Util.Swap32(reader.ReadInt32());
|
||||
SystemResourceSize = BinaryPrimitives.ReverseEndianness(reader.ReadInt32());
|
||||
|
||||
//ProcessCategory (0: regular title, 1: kernel built-in). Should be 0 here.
|
||||
ProcessCategory = Util.Swap32(reader.ReadInt32());
|
||||
ProcessCategory = BinaryPrimitives.ReverseEndianness(reader.ReadInt32());
|
||||
|
||||
//Main entrypoint stack size.
|
||||
MainEntrypointStackSize = reader.ReadInt32();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
@ -471,7 +470,6 @@ namespace LibHac
|
|||
|
||||
public static void MemDump(this StringBuilder sb, string prefix, byte[] data)
|
||||
{
|
||||
|
||||
int max = 32;
|
||||
int remaining = data.Length;
|
||||
bool first = true;
|
||||
|
@ -501,21 +499,21 @@ namespace LibHac
|
|||
}
|
||||
}
|
||||
|
||||
public static string GetKeyRevisionSummary(int revision)
|
||||
public static string GetKeyRevisionSummary(int revision) => revision switch
|
||||
{
|
||||
switch (revision)
|
||||
{
|
||||
case 0: return "1.0.0-2.3.0";
|
||||
case 1: return "3.0.0";
|
||||
case 2: return "3.0.1-3.0.2";
|
||||
case 3: return "4.0.0-4.1.0";
|
||||
case 4: return "5.0.0-5.1.0";
|
||||
case 5: return "6.0.0-6.0.1";
|
||||
case 6: return "6.2.0";
|
||||
case 7: return "7.0.0-8.0.1";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
0 => "1.0.0-2.3.0",
|
||||
1 => "3.0.0",
|
||||
2 => "3.0.1-3.0.2",
|
||||
3 => "4.0.0-4.1.0",
|
||||
4 => "5.0.0-5.1.0",
|
||||
5 => "6.0.0-6.0.1",
|
||||
6 => "6.2.0",
|
||||
7 => "7.0.0-8.0.1",
|
||||
8 => "8.1.0-8.1.1",
|
||||
9 => "9.0.0-9.0.1",
|
||||
0xA => "9.1.0-",
|
||||
_ => "Unknown"
|
||||
};
|
||||
|
||||
public static bool IsSubRange(long startIndex, long subLength, long length)
|
||||
{
|
||||
|
@ -523,16 +521,6 @@ namespace LibHac
|
|||
return !isOutOfRange;
|
||||
}
|
||||
|
||||
public static int Swap32(int value)
|
||||
{
|
||||
uint uintVal = (uint)value;
|
||||
|
||||
return (int)(((uintVal >> 24) & 0x000000ff) |
|
||||
((uintVal >> 8) & 0x0000ff00) |
|
||||
((uintVal << 8) & 0x00ff0000) |
|
||||
((uintVal << 24) & 0xff000000));
|
||||
}
|
||||
|
||||
public static int GetMasterKeyRevision(int keyGeneration)
|
||||
{
|
||||
if (keyGeneration == 0) return 0;
|
||||
|
@ -540,44 +528,4 @@ namespace LibHac
|
|||
return keyGeneration - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public class ByteArray128BitComparer : EqualityComparer<byte[]>
|
||||
{
|
||||
public override bool Equals(byte[] first, byte[] second)
|
||||
{
|
||||
if (first == null || second == null)
|
||||
{
|
||||
// null == null returns true.
|
||||
// non-null == null returns false.
|
||||
return first == second;
|
||||
}
|
||||
if (ReferenceEquals(first, second))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (first.Length != second.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Util.ArraysEqual(first, second);
|
||||
}
|
||||
|
||||
public override int GetHashCode(byte[] obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
if (obj.Length != 16)
|
||||
{
|
||||
throw new ArgumentException("Length must be 16 bytes");
|
||||
}
|
||||
|
||||
ulong hi = BitConverter.ToUInt64(obj, 0);
|
||||
ulong lo = BitConverter.ToUInt64(obj, 8);
|
||||
|
||||
return (hi.GetHashCode() * 397) ^ lo.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue