public static bool Prefix(InventoryItem item, int button) { if (ItemDragManager.isDragging) { return(true); } bool hasLMBaction = RegisteredLMBActions.TryGetValue(item.item.GetTechType(), out ItemActionHelper LMBaction); bool hasMMBaction = RegisteredMMBActions.TryGetValue(item.item.GetTechType(), out ItemActionHelper MMBaction); if (!hasLMBaction && !hasMMBaction) { return(true); } if (hasLMBaction && button == (int)MouseButton.Left && (LMBaction?.Condition(item)).ToNormalBool()) { Inventory.main.GetInstanceMethod("ExecuteItemAction").Invoke(Inventory.main, new object[] { LeftClickItemAction, item }); return(false); } if (hasMMBaction && button == (int)MouseButton.Middle && (MMBaction?.Condition(item)).ToNormalBool()) { Inventory.main.GetInstanceMethod("ExecuteItemAction").Invoke(Inventory.main, new object[] { MiddleClickItemAction, item }); return(false); } else { return(true); } }
public static bool Prefix(ItemAction action, InventoryItem item) { bool hasLMBaction = RegisteredLMBActions.TryGetValue(item.item.GetTechType(), out ItemActionHelper LMBaction); bool hasMMBaction = RegisteredMMBActions.TryGetValue(item.item.GetTechType(), out ItemActionHelper MMBaction); if (!hasLMBaction && !hasMMBaction) { return(true); } if (hasLMBaction && action == LeftClickItemAction && (LMBaction?.Condition(item)).ToNormalBool()) { LMBaction.Callback(item); return(false); } if (hasMMBaction && action == MiddleClickItemAction && (MMBaction?.Condition(item)).ToNormalBool()) { MMBaction.Callback(item); return(false); } else { return(true); } }
public static void Postfix(StringBuilder sb, InventoryItem item) { bool hasLMBaction = RegisteredLMBActions.TryGetValue(item.item.GetTechType(), out ItemActionHelper LMBaction); bool hasMMBaction = RegisteredMMBActions.TryGetValue(item.item.GetTechType(), out ItemActionHelper MMBaction); if (hasLMBaction || hasMMBaction) { sb.Append("\n"); } if (hasLMBaction && (LMBaction?.Condition(item)).ToNormalBool()) { string mouseLeft = typeof(TooltipFactory).GetField("stringLeftHand", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null) as string; typeof(TooltipFactory).GetMethod("WriteAction", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { sb, mouseLeft, LMBaction.Tooltip }); } if (hasMMBaction && (MMBaction?.Condition(item)).ToNormalBool()) { string mouseMiddle = "<color=#ADF8FFFF></color>"; typeof(TooltipFactory).GetMethod("WriteAction", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { sb, mouseMiddle, MMBaction.Tooltip }); } }