Files
bd2/plugins/CashShop/RewardBuffRefresh.cs

33 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Reflection;
using BD2.GameNames;
using HarmonyLib;
using Proto.Net;
namespace Bd2CashShop;
// BuffItem rewards unlock account stats rather than an inventory item. Native
// reward handling ignores them, so refresh the authoritative collection stats.
internal static class RewardBuffRefresh
{
internal static void Install(Harmony harmony)
{
MethodInfo target = typeof(DataManager).GetGameMethod("AddRewardInfoBundle",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null,
[typeof(RewardDBInfoBundle), typeof(List<ItemBaseInfo>).MakeByRefType(), typeof(bool)], null) ?? throw new MissingMethodException("DataManager.AddRewardInfoBundle");
harmony.Patch(target, postfix: new HarmonyMethod(typeof(RewardBuffRefresh), nameof(Refresh)));
}
private static void Refresh(RewardDBInfoBundle __0, bool __2)
{
if (__0 == null || !__2) return;
foreach (ItemDBInfo item in __0.ViewItemInfo)
{
if (item.Type != (int)EElementType.BuffItem) continue;
ContentsPacket.SendRefreshCollectionBuff(null);
return;
}
}
}