0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.SinglePlayer/Patches/RaidFix/PostRaidHealingPricePatch.cs
2023-05-26 13:28:50 +01:00

42 lines
1.4 KiB
C#

using Aki.Reflection.Patching;
using HarmonyLib;
using System;
using System.Reflection;
using TraderInfo = EFT.Profile.GClass1666;
namespace Aki.SinglePlayer.Patches.RaidFix
{
public class PostRaidHealingPricePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
var desiredType = typeof(TraderInfo);
var desiredMethod = desiredType.GetMethod("UpdateLevel", BindingFlags.NonPublic | BindingFlags.Instance);
Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}");
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}");
return desiredMethod;
}
[PatchPrefix]
protected static void PatchPrefix(TraderInfo __instance)
{
if (__instance.Settings == null)
{
return;
}
var loyaltyLevel = __instance.Settings.GetLoyaltyLevel(__instance);
var loyaltyLevelSettings = __instance.Settings.GetLoyaltyLevelSettings(loyaltyLevel);
if (loyaltyLevelSettings == null)
{
throw new IndexOutOfRangeException($"Loyalty level {loyaltyLevel} not found.");
}
// Backing field of the "CurrentLoyalty" property
Traverse.Create(__instance).Field("traderLoyaltyLevel_0").SetValue(loyaltyLevelSettings.Value);
}
}
}