35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using AnotherReplayReader.PluginSystem;
|
|
using AnotherReplayReader.Utils;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AnotherReplayReader
|
|
{
|
|
internal static class Auth
|
|
{
|
|
private static readonly TaskCompletionSource<Task<string?>> _source = new();
|
|
public static Task<string?> Id { get; } = _source.Task.Unwrap();
|
|
|
|
public static void LoadPlugin(IPlugin plugin)
|
|
{
|
|
var authService = plugin.CreateAuthService(RegistryUtils.RetrieveInHklm64, Cache.CacheDirectory);
|
|
authService.Id.ContinueWith(_source.TrySetResult);
|
|
}
|
|
|
|
public static async Task<byte[]?> IdAsKey()
|
|
{
|
|
var id = await Id.ConfigureAwait(false);
|
|
if (string.IsNullOrEmpty(id))
|
|
{
|
|
return null;
|
|
}
|
|
var bytes = Encoding.UTF8.GetBytes(id);
|
|
var destination = Enumerable.Repeat<byte>(0xEA, 24).ToArray();
|
|
Array.Copy(bytes, destination, Math.Min(bytes.Length, destination.Length));
|
|
return destination;
|
|
}
|
|
}
|
|
}
|