Allow insure on inner items
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Aki.Reflection.Patching;
|
using Aki.Reflection.Patching;
|
||||||
using Aki.Reflection.Utils;
|
using Aki.Reflection.Utils;
|
||||||
|
using Comfort.Common;
|
||||||
using EFT.InventoryLogic;
|
using EFT.InventoryLogic;
|
||||||
using EFT.UI;
|
using EFT.UI;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
@@ -70,6 +71,8 @@ namespace UIFixes
|
|||||||
|
|
||||||
new SniffInteractionButtonCreationPatch().Enable();
|
new SniffInteractionButtonCreationPatch().Enable();
|
||||||
new ChangeInteractionButtonCreationPatch().Enable();
|
new ChangeInteractionButtonCreationPatch().Enable();
|
||||||
|
|
||||||
|
new EnableInsureInnerItemsPatch().Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeclareSubInteractionsInventoryPatch : ModulePatch
|
public class DeclareSubInteractionsInventoryPatch : ModulePatch
|
||||||
@@ -243,5 +246,35 @@ namespace UIFixes
|
|||||||
CreatedButtonInteractionId = null;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
using Aki.Reflection.Patching;
|
using Aki.Reflection.Patching;
|
||||||
using Aki.Reflection.Utils;
|
|
||||||
using EFT.InventoryLogic;
|
using EFT.InventoryLogic;
|
||||||
using EFT.UI;
|
using EFT.UI;
|
||||||
using EFT.UI.DragAndDrop;
|
using EFT.UI.DragAndDrop;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -24,8 +22,7 @@ namespace UIFixes
|
|||||||
{
|
{
|
||||||
protected override MethodBase GetTargetMethod()
|
protected override MethodBase GetTargetMethod()
|
||||||
{
|
{
|
||||||
Type type = PatchConstants.EftTypes.Single(t => t.GetProperty("IsOwnedByPlayer") != null);
|
return AccessTools.Method(R.ContextMenuHelper.Type, "IsActive");
|
||||||
return AccessTools.Method(type, "IsActive");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[PatchPrefix]
|
[PatchPrefix]
|
||||||
|
19
R.cs
19
R.cs
@@ -57,6 +57,7 @@ namespace UIFixes
|
|||||||
GridWindow.InitTypes();
|
GridWindow.InitTypes();
|
||||||
GridSortPanel.InitTypes();
|
GridSortPanel.InitTypes();
|
||||||
RepairStrategy.InitTypes();
|
RepairStrategy.InitTypes();
|
||||||
|
ContextMenuHelper.InitTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class Wrapper(object value)
|
public abstract class Wrapper(object value)
|
||||||
@@ -659,12 +660,26 @@ namespace UIFixes
|
|||||||
public bool BrokenItemError() => (bool)BrokenItemErrorMethod.Invoke(Value, []);
|
public bool BrokenItemError() => (bool)BrokenItemErrorMethod.Invoke(Value, []);
|
||||||
public bool IsNoCorrespondingArea() => (bool)IsNoCorrespondingAreaMethod.Invoke(Value, []);
|
public bool IsNoCorrespondingArea() => (bool)IsNoCorrespondingAreaMethod.Invoke(Value, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ContextMenuHelper(object value) : Wrapper(value)
|
||||||
|
{
|
||||||
|
public static Type Type { get; private set; }
|
||||||
|
private static FieldInfo InsuranceCompanyField;
|
||||||
|
|
||||||
|
public static void InitTypes()
|
||||||
|
{
|
||||||
|
Type = PatchConstants.EftTypes.Single(t => t.GetProperty("IsOwnedByPlayer") != null); // GClass3052
|
||||||
|
InsuranceCompanyField = AccessTools.GetDeclaredFields(Type).Single(f => f.FieldType == typeof(InsuranceCompanyClass));
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsuranceCompanyClass InsuranceCompany { get { return (InsuranceCompanyClass)InsuranceCompanyField.GetValue(Value); } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RExtentensions
|
public static class RExtentensions
|
||||||
{
|
{
|
||||||
public static R.UIElement R(this UIElement value) => new R.UIElement(value);
|
public static R.UIElement R(this UIElement value) => new(value);
|
||||||
public static R.UIInputNode R(this UIInputNode value) => new R.UIInputNode(value);
|
public static R.UIInputNode R(this UIInputNode value) => new(value);
|
||||||
public static R.ProductionPanel R(this ProductionPanel value) => new(value);
|
public static R.ProductionPanel R(this ProductionPanel value) => new(value);
|
||||||
public static R.AreaScreenSubstrate R(this AreaScreenSubstrate value) => new(value);
|
public static R.AreaScreenSubstrate R(this AreaScreenSubstrate value) => new(value);
|
||||||
public static R.ItemSpecificationPanel R(this ItemSpecificationPanel value) => new(value);
|
public static R.ItemSpecificationPanel R(this ItemSpecificationPanel value) => new(value);
|
||||||
|
Reference in New Issue
Block a user