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

42 lines
1.4 KiB
C#
Raw Normal View History

2023-03-03 18:52:31 +00:00
using Aki.Reflection.Patching;
using HarmonyLib;
using System;
using System.Reflection;
2023-12-27 17:10:25 +02:00
using EFT;
2023-03-03 18:52:31 +00:00
namespace Aki.SinglePlayer.Patches.RaidFix
{
public class PostRaidHealingPricePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
2023-12-27 17:10:25 +02:00
var desiredType = typeof(Profile.TraderInfo);
2023-03-03 18:52:31 +00:00
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]
2023-12-27 17:10:25 +02:00
protected static void PatchPrefix(Profile.TraderInfo __instance)
2023-03-03 18:52:31 +00:00
{
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.");
}
2023-12-27 21:45:33 +02:00
// Backing field of the "CurrentLoyalty" property
Traverse.Create(__instance).Field("<CurrentLoyalty>k__BackingField").SetValue(loyaltyLevelSettings.Value);
2023-03-03 18:52:31 +00:00
}
}
}