Allow insure on inner items

This commit is contained in:
Tyfon
2024-06-13 12:35:11 -07:00
parent bd1ae66fc1
commit 0fcbf2479e
3 changed files with 51 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using Comfort.Common;
using EFT.InventoryLogic;
using EFT.UI;
using HarmonyLib;
@@ -70,6 +71,8 @@ namespace UIFixes
new SniffInteractionButtonCreationPatch().Enable();
new ChangeInteractionButtonCreationPatch().Enable();
new EnableInsureInnerItemsPatch().Enable();
}
public class DeclareSubInteractionsInventoryPatch : ModulePatch
@@ -243,5 +246,35 @@ namespace UIFixes
CreatedButtonInteractionId = null;
}
}
public class EnableInsureInnerItemsPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(R.ContextMenuHelper.Type, "IsInteractive");
}
[PatchPrefix]
public static bool Prefix(object __instance, EItemInfoButton button, ref IResult __result, Item ___item_0)
{
if (button != EItemInfoButton.Insure)
{
return true;
}
InsuranceCompanyClass insurance = new R.ContextMenuHelper(__instance).InsuranceCompany;
ItemClass itemClass = ItemClass.FindOrCreate(___item_0);
IEnumerable<ItemClass> insurableItems = insurance.GetItemChildren(itemClass).Flatten(insurance.GetItemChildren).Concat([itemClass])
.Where(i => insurance.ItemTypeAvailableForInsurance(i) && !insurance.InsuredItems.Contains(i));
if (insurableItems.Any())
{
__result = SuccessfulResult.New;
return false;
}
return true;
}
}
}
}