quantum-space-buddies/EpicRerouter/ExeSide/EpicEntitlementRetriever.cs

56 lines
1.6 KiB
C#
Raw Normal View History

2022-02-07 06:22:58 +00:00
using Epic.OnlineServices;
using Epic.OnlineServices.Ecom;
2022-02-07 06:40:55 +00:00
using System;
2022-02-07 06:22:58 +00:00
using static EntitlementsManager;
2022-02-07 07:09:55 +00:00
namespace EpicRerouter.ExeSide
2022-02-07 06:22:58 +00:00
{
public static class EpicEntitlementRetriever
{
2022-02-07 06:37:44 +00:00
private const string _eosDlcItemID = "49a9ac61fe464cbf8c8c73f46b3f1133";
2022-02-07 06:22:58 +00:00
private static EcomInterface _ecomInterface;
private static OwnershipStatus _epicDlcOwnershipStatus;
private static bool _epicResultReceived;
2022-02-07 06:40:55 +00:00
public static void Init() =>
2022-02-07 06:37:44 +00:00
EpicPlatformManager.OnAuthSuccess += EOSQueryOwnership;
2022-02-07 06:22:58 +00:00
2022-02-07 06:40:55 +00:00
public static void Uninit() =>
2022-02-07 06:37:44 +00:00
EpicPlatformManager.OnAuthSuccess -= EOSQueryOwnership;
2022-02-07 06:22:58 +00:00
public static AsyncOwnershipStatus GetOwnershipStatus()
{
if (!_epicResultReceived)
{
return AsyncOwnershipStatus.NotReady;
}
2022-02-07 06:40:55 +00:00
return _epicDlcOwnershipStatus == OwnershipStatus.Owned ?
AsyncOwnershipStatus.Owned : AsyncOwnershipStatus.NotOwned;
2022-02-07 06:22:58 +00:00
}
2022-02-07 06:37:44 +00:00
private static void EOSQueryOwnership()
2022-02-07 06:22:58 +00:00
{
2022-02-07 06:40:55 +00:00
Console.WriteLine("[EOS] querying DLC ownership");
2022-02-07 06:22:58 +00:00
_ecomInterface = EpicPlatformManager.PlatformInterface.GetEcomInterface();
var queryOwnershipOptions = new QueryOwnershipOptions
{
LocalUserId = EpicPlatformManager.LocalUserId,
2022-02-07 06:37:44 +00:00
CatalogItemIds = new[] { _eosDlcItemID }
2022-02-07 06:22:58 +00:00
};
_ecomInterface.QueryOwnership(queryOwnershipOptions, null, OnEOSQueryOwnershipComplete);
}
private static void OnEOSQueryOwnershipComplete(QueryOwnershipCallbackInfo data)
{
if (data.ResultCode == Result.Success)
{
_epicDlcOwnershipStatus = data.ItemOwnership[0].OwnershipStatus;
_epicResultReceived = true;
2022-02-07 06:40:55 +00:00
Console.WriteLine($"[EOS] Query DLC ownership complete: {_epicDlcOwnershipStatus}");
2022-02-07 06:22:58 +00:00
}
}
}
}