Skip to content

Commit d07f396

Browse files
committed
FullKey: equality members, GetHashCode
1 parent 918c751 commit d07f396

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

TACTLib/Client/ClientHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public ClientHandler(string? basePath, ClientCreateArgs createArgs) {
148148
} else {
149149
ngdpClient = new NGDPClient(CreateArgs.OnlineRootHost);
150150
}
151-
151+
152152
using var _ = new PerfCounter("NGDPClientBase::CreateInstallationInfo`string`string");
153153
var installationInfoData = ngdpClient.CreateInstallationInfo(GetProduct()!, CreateArgs.OnlineRegion);
154154
InstallationInfo = new InstallationInfo(installationInfoData);
@@ -242,7 +242,7 @@ public ClientHandler(string? basePath, ClientCreateArgs createArgs) {
242242

243243
public IProductHandler? CreateProductHandler() {
244244
using var _ = new PerfCounter("ProductHandlerFactory::GetHandler`TACTProduct`ClientHandler`Stream");
245-
return ProductHandlerFactory.GetHandler(Product, this, OpenCKey(ConfigHandler.BuildConfig.Root.ContentKey)!);
245+
return ProductHandlerFactory.GetHandler(Product, this, ConfigHandler.BuildConfig.Root.ContentKey == default ? null : OpenCKey(ConfigHandler.BuildConfig.Root.ContentKey)!);
246246
}
247247

248248
private bool CanShareCDNData([NotNullWhen(true)] ClientHandler? other) {
@@ -258,14 +258,14 @@ private bool CanShareCDNData([NotNullWhen(true)] ClientHandler? other) {
258258
}
259259
return archivesMatch;
260260
}
261-
261+
262262
private static bool CanShareCDNData(CDNConfig cdnConfig, CDNConfig otherCDNConfig) {
263263
if (otherCDNConfig.Archives.Count != cdnConfig.Archives.Count) return false;
264-
264+
265265
for (var i = 0; i < cdnConfig.Archives.Count; i++) {
266266
if (otherCDNConfig.Archives[i] != cdnConfig.Archives[i]) return false;
267267
}
268-
268+
269269
return true;
270270
}
271271

TACTLib/Core/Key/FullKey.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace TACTLib.Core.Key {
1515
[InlineArray(CASC_FULL_KEY_SIZE)]
1616
[DebuggerDisplay("{ToHexString()}")]
1717
[SuppressMessage("ReSharper", "UseSymbolAlias")]
18-
public struct FullKey : IComparable<FullKey> {
18+
public struct FullKey : IComparable<FullKey>, IEquatable<FullKey> {
1919
// ReSharper disable once InconsistentNaming
2020
/// <summary>Content Key size, in bytes</summary>
2121
public const int CASC_FULL_KEY_SIZE = 16;
@@ -74,5 +74,22 @@ public static int FullKeyCompare(FullKey left, FullKey right) {
7474
var rightU1 = BinaryPrimitives.ReadUInt64BigEndian(rightSpan.Slice(8));
7575
return leftU1.CompareTo(rightU1);
7676
}
77+
78+
public bool Equals(FullKey other) {
79+
var span = MemoryMarshal.Cast<byte, ulong>(this);
80+
var otherSpan = MemoryMarshal.Cast<byte, ulong>(this);
81+
return span[0] == otherSpan[0] && span[1] == otherSpan[1];
82+
}
83+
84+
public override bool Equals(object? obj) => obj is FullKey other && Equals(other);
85+
86+
public static bool operator ==(FullKey left, FullKey right) => left.Equals(right);
87+
public static bool operator !=(FullKey left, FullKey right) => !(left == right);
88+
89+
public override int GetHashCode() {
90+
var h = new HashCode();
91+
h.AddBytes(this);
92+
return h.ToHashCode();
93+
}
7794
}
78-
}
95+
}

TACTLib/Core/Product/ProductHandlerFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace TACTLib.Core.Product {
1111
public static class ProductHandlerFactory {
1212
private static readonly Dictionary<TACTProduct, Type> _handlers = new Dictionary<TACTProduct, Type>();
1313

14-
public static IProductHandler? GetHandler(TACTProduct product, ClientHandler client, Stream root) {
14+
public static IProductHandler? GetHandler(TACTProduct product, ClientHandler client, Stream? root) {
1515
var handlerType = GetHandlerType(product);
1616
if (handlerType == null) return null;
1717

0 commit comments

Comments
 (0)