Fix repair context menu checking for hideout upgrades even when using traders

This commit is contained in:
Tyfon
2024-07-09 11:09:23 -07:00
parent ccdd6f3c21
commit 3038c71ed7
2 changed files with 30 additions and 12 deletions

View File

@@ -41,10 +41,11 @@ namespace UIFixes
{ {
text = string.Format("<b><color=#C6C4B2>{0}</color></b>", repairer.LocalizedName); text = string.Format("<b><color=#C6C4B2>{0}</color></b>", repairer.LocalizedName);
} }
else if (repairer is GClass803 repairKit) else if (R.RepairKit.Type.IsInstanceOfType(repairer))
{ {
var repairKit = new R.RepairKit(repairer);
float pointsLeft = repairKit.GetRepairPoints(); float pointsLeft = repairKit.GetRepairPoints();
double amount = repairStrategy.GetRepairPrice(repairAmount, repairKit); double amount = repairStrategy.GetRepairPrice(repairAmount, repairKit.Value);
string costColor = amount > pointsLeft ? "#FF0000" : "#ADB8BC"; string costColor = amount > pointsLeft ? "#FF0000" : "#ADB8BC";
text = string.Format("<b><color=#C6C4B2>{0}</color> <color={1}>({2} {3})</color></b>", repairer.LocalizedName, costColor, Math.Round(amount, 2).ToString(CultureInfo.InvariantCulture), "RP".Localized()); text = string.Format("<b><color=#C6C4B2>{0}</color> <color={1}>({2} {3})</color></b>", repairer.LocalizedName, costColor, Math.Round(amount, 2).ToString(CultureInfo.InvariantCulture), "RP".Localized());
@@ -96,14 +97,21 @@ namespace UIFixes
float repairAmount = GetClampedRepairAmount(repairStrategy); float repairAmount = GetClampedRepairAmount(repairStrategy);
if (repairer is GClass803 repairKit) if (R.RepairKit.Type.IsInstanceOfType(repairer))
{ {
var repairKit = new R.RepairKit(repairer);
float pointsLeft = repairKit.GetRepairPoints(); float pointsLeft = repairKit.GetRepairPoints();
double amount = repairStrategy.GetRepairPrice(repairAmount, repairKit); double amount = repairStrategy.GetRepairPrice(repairAmount, repairKit.Value);
if (amount > pointsLeft) if (amount > pointsLeft)
{ {
return new FailedResult(ERepairStatusWarning.NotEnoughRepairPoints.ToString()); return new FailedResult(ERepairStatusWarning.NotEnoughRepairPoints.ToString());
} }
// This check is only for repair kits
if (repairStrategy.IsNoCorrespondingArea())
{
return new FailedResult(ERepairStatusWarning.NoCorrespondingArea.ToString());
}
} }
else else
{ {
@@ -126,11 +134,6 @@ namespace UIFixes
return new FailedResult(ERepairStatusWarning.BrokenItem.ToString()); return new FailedResult(ERepairStatusWarning.BrokenItem.ToString());
}*/ }*/
if (repairStrategy.IsNoCorrespondingArea())
{
return new FailedResult(ERepairStatusWarning.NoCorrespondingArea.ToString());
}
return SuccessfulResult.New; return SuccessfulResult.New;
} }

21
R.cs
View File

@@ -54,6 +54,7 @@ namespace UIFixes
GridWindow.InitTypes(); GridWindow.InitTypes();
GridSortPanel.InitTypes(); GridSortPanel.InitTypes();
RepairStrategy.InitTypes(); RepairStrategy.InitTypes();
RepairKit.InitTypes();
ContextMenuHelper.InitTypes(); ContextMenuHelper.InitTypes();
RagfairNewOfferItemView.InitTypes(); RagfairNewOfferItemView.InitTypes();
TradingTableGridView.InitTypes(); TradingTableGridView.InitTypes();
@@ -597,9 +598,9 @@ namespace UIFixes
public static void InitTypes() public static void InitTypes()
{ {
Type = PatchConstants.EftTypes.Single(t => t.IsInterface && t.GetMethod("HowMuchRepairScoresCanAccept") != null); Type = PatchConstants.EftTypes.Single(t => t.IsInterface && t.GetMethod("HowMuchRepairScoresCanAccept") != null); // GInterface34
ArmorStrategyType = PatchConstants.EftTypes.Single(t => t.IsClass && Type.IsAssignableFrom(t) && t.GetField("repairableComponent_0", BindingFlags.Instance | BindingFlags.NonPublic) == null); ArmorStrategyType = PatchConstants.EftTypes.Single(t => t.IsClass && Type.IsAssignableFrom(t) && t.GetField("repairableComponent_0", BindingFlags.Instance | BindingFlags.NonPublic) == null); // GClass805
DefaultStrategyType = PatchConstants.EftTypes.Single(t => Type.IsAssignableFrom(t) && t.GetField("repairableComponent_0", BindingFlags.Instance | BindingFlags.NonPublic) != null); DefaultStrategyType = PatchConstants.EftTypes.Single(t => Type.IsAssignableFrom(t) && t.GetField("repairableComponent_0", BindingFlags.Instance | BindingFlags.NonPublic) != null); // GClass804
RepairersProperty = AccessTools.Property(Type, "Repairers"); RepairersProperty = AccessTools.Property(Type, "Repairers");
CurrentRepairerProperty = AccessTools.Property(Type, "CurrentRepairer"); CurrentRepairerProperty = AccessTools.Property(Type, "CurrentRepairer");
HowMuchRepairScoresCanAcceptMethod = AccessTools.Method(Type, "HowMuchRepairScoresCanAccept"); HowMuchRepairScoresCanAcceptMethod = AccessTools.Method(Type, "HowMuchRepairScoresCanAccept");
@@ -640,6 +641,20 @@ namespace UIFixes
public bool IsNoCorrespondingArea() => (bool)IsNoCorrespondingAreaMethod.Invoke(Value, []); public bool IsNoCorrespondingArea() => (bool)IsNoCorrespondingAreaMethod.Invoke(Value, []);
} }
public class RepairKit(object value) : Wrapper(value)
{
public static Type Type { get; private set; }
private static MethodInfo GetRepairPointsMethod;
public static void InitTypes()
{
Type = R.RepairStrategy.Type.GetMethod("GetRepairPrice").GetParameters()[1].ParameterType; // GClass803
GetRepairPointsMethod = AccessTools.Method(Type, "GetRepairPoints");
}
public float GetRepairPoints() => (float)GetRepairPointsMethod.Invoke(Value, []);
}
public class ContextMenuHelper(object value) : Wrapper(value) public class ContextMenuHelper(object value) : Wrapper(value)
{ {
public static Type Type { get; private set; } public static Type Type { get; private set; }