Decompiled source of BetterCounterOfferUI v3.1.0

BetterCounterOffer-Il2Cpp_3.0.0.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BetterCounterOffer;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Product;
using Il2CppScheduleOne.UI.Handover;
using Il2CppScheduleOne.UI.Phone;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(CounterOfferUI), "Better Counter Offer UI", "3.0.0", "OverweightUnicorn", "")]
[assembly: MelonColor(255, 191, 0, 255)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BetterCounterOffer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e03d286d86878d8544c93563a109debad9604901")]
[assembly: AssemblyProduct("BetterCounterOffer")]
[assembly: AssemblyTitle("BetterCounterOffer")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BetterCounterOffer;

public static class CounterOfferConfig
{
	private static string folderName = "CounterOfferUI";

	private static string fileName = "CounterOffer_Config.ini";

	public static bool disableAllLabels = false;

	public static bool disableSuccessRate = false;

	public static bool disableMaxLimit = false;

	public static bool disableInitialOffer = false;

	public static void LoadConfig()
	{
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), folderName);
		if (!Directory.Exists(text))
		{
			Directory.CreateDirectory(text);
		}
		string path = Path.Combine(text, fileName);
		if (!File.Exists(path))
		{
			SaveConfig();
			MelonLogger.Msg(ConsoleColor.Magenta, "CounterOffer Config file created with default values.");
		}
		string[] array = File.ReadAllLines(path);
		foreach (string text2 in array)
		{
			if (string.IsNullOrWhiteSpace(text2) || text2.TrimStart().StartsWith("#"))
			{
				continue;
			}
			string[] array2 = text2.Split('=');
			string text3 = array2[0].Trim();
			if (bool.TryParse(array2[1].Trim(), out var result))
			{
				switch (text3)
				{
				case "DisableAllLabels":
					disableAllLabels = result;
					break;
				case "DisableInitialOffer":
					disableInitialOffer = result;
					break;
				case "DisableMaxLimit":
					disableMaxLimit = result;
					break;
				case "DisableSuccessRate":
					disableSuccessRate = result;
					break;
				}
			}
		}
		MelonLogger.Msg(ConsoleColor.Magenta, $"\nCounterOffer Config loaded:\n  Disable All Labels={disableAllLabels}\n  Disable Initial Offer={disableInitialOffer}\n  Disable Max Limit={disableMaxLimit}\n  Disable Success Rate={disableSuccessRate}");
	}

	public static void SaveConfig()
	{
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), folderName);
		if (!Directory.Exists(text))
		{
			Directory.CreateDirectory(text);
		}
		string path = Path.Combine(text, fileName);
		string[] contents = new string[5]
		{
			"# CounterOffer configuration",
			"DisableAllLabels=" + disableAllLabels,
			"DisableInitialOffer=" + disableInitialOffer,
			"DisableMaxLimit=" + disableMaxLimit,
			"DisableSuccessRate=" + disableSuccessRate
		};
		File.WriteAllLines(path, contents);
	}
}
[HarmonyPatch(typeof(CounterofferInterface), "Awake")]
internal static class CounterOfferAwakePatch
{
	public static bool Prefix(CounterofferInterface __instance)
	{
		MelonLogger.Msg("Waking Up, Lets Modify this UI and make it Better");
		CounterOfferUI.InitOnWake();
		return true;
	}
}
[HarmonyPatch(typeof(CounterofferInterface), "Open")]
internal static class CounterOfferInterfaceOpenPatch
{
	public static void Postfix(CounterofferInterface __instance)
	{
		if ((Object)(object)__instance != (Object)null)
		{
			CounterOfferUI.OnPopupOpen(__instance);
		}
	}
}
[HarmonyPatch(typeof(CounterofferInterface), "ChangePrice")]
internal static class CounterOfferInterfaceChangePricePatch
{
	public static void Postfix(CounterofferInterface __instance)
	{
		if (!CounterOfferConfig.disableSuccessRate)
		{
			CounterOfferUI.UpdateSuccessRate(__instance);
		}
	}
}
[HarmonyPatch(typeof(CounterofferInterface), "ChangeQuantity")]
internal static class CounterOfferInterfaceChangeQuantityPatch
{
	public static void Postfix(CounterofferInterface __instance)
	{
		ProductDefinition selectedProduct = __instance.selectedProduct;
		float num = (float)__instance.quantity * selectedProduct.Price - __instance.price;
		__instance.ChangePrice(num);
		if (!CounterOfferConfig.disableSuccessRate)
		{
			CounterOfferUI.UpdateSuccessRate(__instance);
		}
	}
}
[HarmonyPatch(typeof(CounterofferInterface), "SetProduct")]
internal static class CounterOfferInterfaceSetProductPatch
{
	public static void Postfix(CounterofferInterface __instance)
	{
		float num = (float)__instance.quantity * __instance.selectedProduct.Price - __instance.price;
		__instance.ChangePrice(num);
		if (!CounterOfferConfig.disableSuccessRate)
		{
			CounterOfferUI.UpdateSuccessRate(__instance);
		}
	}
}
[HarmonyPatch(typeof(CounterOfferProductSelector), "Open")]
internal static class CounterOfferProductSelectorOpenPatch
{
	public static void Postfix(CounterOfferProductSelector __instance)
	{
		if ((Object)(object)CounterOfferUI.selectorInterface == (Object)null)
		{
			MelonLogger.Msg(ConsoleColor.Magenta, "Attempting to caputre ProductSelector interface");
			CounterOfferUI.selectorInterface = __instance;
		}
	}
}
[HarmonyPatch(typeof(CounterOfferProductSelector), "GetMatchingProducts")]
internal static class CounterOfferProductSelectorGetMatchingProductsPatch
{
	public static void Postfix(CounterofferInterface __instance, ref List<ProductDefinition> __result, ref string searchTerm)
	{
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		HashSet<EDrugType> hashSet = new HashSet<EDrugType>();
		List<ProductDefinition> val = ((CounterOfferUI.currTab == "Listed") ? ProductManager.ListedProducts : ((!(CounterOfferUI.currTab == "Favorites")) ? ProductManager.DiscoveredProducts : ProductManager.FavouritedProducts));
		List<ProductDefinition> val2 = new List<ProductDefinition>();
		if (searchTerm.ToLower().Contains("weed"))
		{
			hashSet.Add((EDrugType)0);
		}
		if (searchTerm.ToLower().Contains("coke"))
		{
			hashSet.Add((EDrugType)2);
		}
		if (searchTerm.ToLower().Contains("meth"))
		{
			hashSet.Add((EDrugType)1);
		}
		Enumerator<ProductDefinition> enumerator = val.GetEnumerator();
		while (enumerator.MoveNext())
		{
			ProductDefinition current = enumerator.Current;
			if (hashSet.Contains(current.DrugType) || ((ItemDefinition)current).Name.ToLower().Contains(searchTerm))
			{
				val2.Add(current);
			}
		}
		__result = val2;
	}
}
public static class BuildInfo
{
	public const string Name = "Better Counter Offer UI";

	public const string Description = "A mod that improves the Counter Offer UI";

	public const string Author = "OverweightUnicorn";

	public const string Company = "UnicornsCanMod";

	public const string Version = "3.0.0";

	public const string DownloadLink = "";
}
public class CounterOfferUI : MelonMod
{
	public static GameObject PlayerRef = null;

	public static GameObject popupRef = null;

	public static GameObject productSelectorRef = null;

	public static GameObject offerInfoGO = null;

	public static Text initialOfferText = null;

	public static Text successRateText = null;

	public static Text maxCashText = null;

	public static Text btnText = null;

	public static Image btnBg = null;

	public static Font gameFont = null;

	public static TabController selectorTabControl;

	public static bool displayAll = false;

	public static string currTab = "Favorites";

	public static float prevTime = 0f;

	public static Gradient colorMap = new Gradient();

	public static List<ProductDefinition> currList = null;

	public static CounterOfferProductSelector selectorInterface = null;

	public static CounterofferInterface offerInterface = null;

	public static int labelCount = 0;

	public static Dictionary<string, Vector2[]> uiPositions = new Dictionary<string, Vector2[]>
	{
		{
			"Shade/Content",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(-160f, -160f),
				new Vector2(-160f, -180f),
				new Vector2(-160f, -140f),
				new Vector2(-160f, -90f)
			}
		},
		{
			"Selection",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, -182f),
				new Vector2(0f, -230f),
				new Vector2(0f, -250f),
				new Vector2(0f, -250f)
			}
		},
		{
			"Subtitle",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, -117f),
				new Vector2(0f, -150f),
				new Vector2(0f, -190f),
				new Vector2(0f, -220f)
			}
		},
		{
			"Remove",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(-210f, 74f),
				new Vector2(-210f, 30f),
				new Vector2(-210f, 10f),
				new Vector2(-210f, 10f)
			}
		},
		{
			"Add",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(210f, 74f),
				new Vector2(210f, 30f),
				new Vector2(210f, 10f),
				new Vector2(210f, 10f)
			}
		},
		{
			"Product",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 74f),
				new Vector2(0f, 30f),
				new Vector2(0f, 10f),
				new Vector2(0f, 10f)
			}
		},
		{
			"Subtitle (1)",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, -258.12f),
				new Vector2(0f, -260f),
				new Vector2(0f, -300f),
				new Vector2(0f, -335f)
			}
		},
		{
			"Price",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, -313.12f),
				new Vector2(0f, -310f),
				new Vector2(0f, -350f),
				new Vector2(0f, -390f)
			}
		},
		{
			"Fair price",
			(Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, -362f),
				new Vector2(0f, -370f),
				new Vector2(0f, -405f),
				new Vector2(0f, -450f)
			}
		}
	};

	public static void OnPopupOpen(CounterofferInterface instance)
	{
		Customer component = ((Component)instance.conversation.sender).GetComponent<Customer>();
		if ((Object)(object)component == (Object)null)
		{
			((Component)offerInterface.conversation.sender).GetComponent<Customer>();
		}
		prevTime = 0f;
		if (!CounterOfferConfig.disableAllLabels)
		{
			if (!CounterOfferConfig.disableInitialOffer)
			{
				SetInitialPriceText(instance.price);
			}
			if (!CounterOfferConfig.disableMaxLimit)
			{
				SetMaxCashText(CalculateSpendingLimits(component));
			}
			if (!CounterOfferConfig.disableSuccessRate)
			{
				SetSuccessRateText(CalculateSuccessProbability(component, instance.selectedProduct, instance.quantity, instance.price));
			}
		}
	}

	public static void SetSuccessRateText(float success)
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)successRateText == (Object)null)
		{
			MelonLogger.Msg("successRateText is null??");
			return;
		}
		successRateText.text = $"<b>{Mathf.RoundToInt(success * 100f)}% Chance of Success</b>";
		((Graphic)successRateText).color = colorMap.Evaluate(success);
	}

	public static void SetMaxCashText(float maxSpend)
	{
		if (!((Object)(object)maxCashText == (Object)null))
		{
			maxCashText.text = $"<b>Spend Limit: ${Mathf.RoundToInt(maxSpend)}</b>";
		}
	}

	public static void SetInitialPriceText(float initialPrice)
	{
		if (!((Object)(object)initialOfferText == (Object)null))
		{
			initialOfferText.text = $"<b>Initial Offer ${Mathf.RoundToInt(initialPrice)}</b>";
		}
	}

	public static float CalculateSpendingLimits(Customer customer)
	{
		CustomerData customerData = customer.CustomerData;
		float adjustedWeeklySpend = customerData.GetAdjustedWeeklySpend(customer.NPC.RelationData.RelationDelta / 5f);
		List<EDay> orderDays = customerData.GetOrderDays(customer.CurrentAddiction, customer.NPC.RelationData.RelationDelta / 5f);
		return adjustedWeeklySpend / (float)orderDays.Count * 3f;
	}

	public static float CalculateSuccessProbability(Customer customer, ProductDefinition product, int quantity, float price)
	{
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		float adjustedWeeklySpend = customer.customerData.GetAdjustedWeeklySpend(customer.NPC.RelationData.RelationDelta / 5f);
		List<EDay> orderDays = customer.customerData.GetOrderDays(customer.CurrentAddiction, customer.NPC.RelationData.RelationDelta / 5f);
		float num = adjustedWeeklySpend / (float)orderDays.Count;
		if (price >= num * 3f)
		{
			return 0f;
		}
		float valueProposition = Customer.GetValueProposition(Registry.GetItem<ProductDefinition>(customer.OfferedContractInfo.Products.entries[0].ProductID), customer.OfferedContractInfo.Payment / (float)customer.OfferedContractInfo.Products.entries[0].Quantity);
		float productEnjoyment = customer.GetProductEnjoyment(product, StandardsMethod.GetCorrespondingQuality(customer.customerData.Standards));
		float num2 = Mathf.InverseLerp(-1f, 1f, productEnjoyment);
		float valueProposition2 = Customer.GetValueProposition(product, price / (float)quantity);
		float num3 = Mathf.Pow((float)quantity / (float)customer.OfferedContractInfo.Products.entries[0].Quantity, 0.6f);
		float num4 = Mathf.Lerp(0f, 2f, num3 * 0.5f);
		float num5 = Mathf.Lerp(1f, 0f, Mathf.Abs(num4 - 1f));
		if (valueProposition2 * num5 > valueProposition)
		{
			return 1f;
		}
		if (valueProposition2 < 0.12f)
		{
			return 0f;
		}
		float num6 = productEnjoyment * valueProposition;
		float num7 = num2 * num5 * valueProposition2;
		if (num7 > num6)
		{
			return 1f;
		}
		float num8 = num6 - num7;
		float num9 = Mathf.Lerp(0f, 1f, num8 / 0.2f);
		float num10 = Mathf.Max(customer.CurrentAddiction, customer.NPC.RelationData.NormalizedRelationDelta);
		float num11 = Mathf.Lerp(0f, 0.2f, num10);
		if (num9 <= num11)
		{
			return 1f;
		}
		if (num9 - num11 >= 0.9f)
		{
			return 0f;
		}
		return Mathf.Clamp((0.9f + num11 - num9) / 0.9f, 0f, 1f);
	}

	public static void UpdateSuccessRate(CounterofferInterface instance)
	{
		if ((Object)(object)instance == (Object)null)
		{
			MelonLogger.Msg(ConsoleColor.Red, "CounterofferInterface Instance was Null!!");
		}
		else if ((Object)(object)successRateText == (Object)null)
		{
			MelonLogger.Msg(ConsoleColor.Red, "successRateText Instance was Null!!");
		}
		else
		{
			SetSuccessRateText(CalculateSuccessProbability(((Component)instance.conversation.sender).GetComponent<Customer>(), instance.selectedProduct, instance.quantity, instance.price));
		}
	}

	public static void InitOnWake()
	{
		GameObject val = GameObject.Find("UI/HandoverScreen");
		if ((Object)(object)val != (Object)null)
		{
			HandoverScreen component = val.GetComponent<HandoverScreen>();
			if ((Object)(object)val != (Object)null)
			{
				colorMap = component.SuccessColorMap;
			}
		}
		GameObject val2 = GameObject.Find("Player_Local");
		if (!((Object)(object)val2 != (Object)null))
		{
			return;
		}
		PlayerRef = val2;
		Transform val3 = PlayerRef.transform.Find("CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/Messages/Container/CounterofferInterface/Shade/Content");
		if ((Object)(object)(((Object)(object)val3 != (Object)null) ? ((Component)val3).gameObject : null) != (Object)null)
		{
			MelonLogger.Msg(ConsoleColor.Magenta, "CounterOffer Container Found Lets Make it Better");
			if (!CounterOfferConfig.disableAllLabels)
			{
				CreateLabels(val3);
				GrowPopUpWindow(val3);
				ShiftOfferElements(val3);
			}
			UpdateSelectorUI(val3);
		}
	}

	private static void GrowPopUpWindow(Transform transform)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)transform != (Object)null)
		{
			Vector2 sizeDelta = uiPositions["Shade/Content"][labelCount];
			((Component)transform).GetComponent<RectTransform>().sizeDelta = sizeDelta;
		}
	}

	private static void AdjustUiElements(Transform parent, string searchStr)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		Transform val = parent.Find(searchStr);
		if ((Object)(object)val != (Object)null)
		{
			Vector2 anchoredPosition = uiPositions[searchStr][labelCount];
			((Component)val).GetComponent<RectTransform>().anchoredPosition = anchoredPosition;
		}
		else
		{
			MelonLogger.Msg(ConsoleColor.Red, searchStr + " Couldn't be Found");
		}
	}

	private static void ShiftOfferElements(Transform parent)
	{
		AdjustUiElements(parent, "Fair price");
		AdjustUiElements(parent, "Price");
		AdjustUiElements(parent, "Subtitle (1)");
		AdjustUiElements(parent, "Product");
		AdjustUiElements(parent, "Add");
		AdjustUiElements(parent, "Remove");
		AdjustUiElements(parent, "Subtitle");
		AdjustUiElements(parent, "Selection");
	}

	private static void UpdateSelectorUI(Transform parent)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		Transform val = parent.Find("Selection");
		if ((Object)(object)val != (Object)null)
		{
			MelonLogger.Msg(ConsoleColor.Magenta, "The Selector UI now has Tabs....AWESOME");
			selectorInterface = ((Component)val).GetComponent<CounterOfferProductSelector>();
			Transform val2 = val.Find("SearchInput");
			if ((Object)(object)val2 != (Object)null)
			{
				((Component)val2).GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, -83f);
				((Component)val2).GetComponent<InputField>();
			}
			Transform val3 = val.Find("Window");
			if ((Object)(object)val3 != (Object)null)
			{
				((Component)val3).GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, -87f);
				if (selectorTabControl == null)
				{
					selectorTabControl = new TabController(val);
					selectorTabControl.font = gameFont;
					selectorTabControl.AddTab("Favorites", "<b>Fave</b>");
					selectorTabControl.AddTab("Listed", "<b>Listed</b>");
					selectorTabControl.AddTab("Discovered", "<b>All</b>");
					selectorTabControl.SetSelected(currTab);
				}
			}
		}
		else
		{
			MelonLogger.Msg(ConsoleColor.Red, "Selection Couldn't be Found");
		}
	}

	public static void TabSelected(Tab selected)
	{
		currTab = selected.id;
		if ((Object)(object)selectorInterface != (Object)null)
		{
			selectorInterface.RebuildResultsList();
		}
	}

	private static void CreateLabels(Transform parent)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		Transform val = parent.Find("Title");
		if ((Object)(object)val != (Object)null)
		{
			gameFont = ((Component)val).GetComponent<Text>().font;
		}
		offerInfoGO = new GameObject("OfferInformation");
		offerInfoGO.transform.SetParent(parent, false);
		offerInfoGO.transform.localPosition = new Vector3(181.5444f, 1.175f, -9.2547f);
		offerInfoGO.AddComponent<CanvasRenderer>();
		RectTransform obj = offerInfoGO.AddComponent<RectTransform>();
		obj.anchoredPosition = new Vector2(-270.0037f, -150f);
		obj.anchorMin = new Vector2(1f, 1f);
		obj.anchorMax = new Vector2(1f, 1f);
		obj.pivot = new Vector2(0.5f, 0.5f);
		obj.sizeDelta = new Vector2(300f, 100f);
		float num = 40f;
		if ((Object)(object)initialOfferText == (Object)null && !CounterOfferConfig.disableInitialOffer)
		{
			initialOfferText = CreateLabel(offerInfoGO.transform, "InitialCash", "Initial Offer Price: ", new Vector3(0f, num, 0f));
			num -= 35f;
			labelCount++;
		}
		if ((Object)(object)maxCashText == (Object)null && !CounterOfferConfig.disableMaxLimit)
		{
			maxCashText = CreateLabel(offerInfoGO.transform, "MaxCash", "$1000 Max", new Vector3(0f, num, 0f));
			num -= 35f;
			labelCount++;
		}
		if ((Object)(object)successRateText == (Object)null && !CounterOfferConfig.disableSuccessRate)
		{
			successRateText = CreateLabel(offerInfoGO.transform, "SuccessRate", "100% Success Rate", new Vector3(0f, num, 0f));
			labelCount++;
		}
	}

	public static Text CreateLabel(Transform parent, string title, string text, Vector3 localPosition)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(title);
		val.transform.SetParent(parent, false);
		val.transform.localPosition = localPosition;
		Text obj = val.AddComponent<Text>();
		obj.text = text;
		obj.font = (((Object)(object)gameFont != (Object)null) ? gameFont : Resources.GetBuiltinResource<Font>("Arial.ttf"));
		obj.fontSize = 30;
		((Graphic)obj).color = Color.gray;
		obj.alignment = (TextAnchor)4;
		((Component)val.transform).GetComponent<RectTransform>().sizeDelta = new Vector2(600f, 100f);
		return obj;
	}

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg(ConsoleColor.Magenta, "Initializing Better Counter Offer...Go Make that Money");
		MelonLogger.Msg(ConsoleColor.Magenta, "If you find any bugs,");
		MelonLogger.Msg(ConsoleColor.Magenta, "first check that your game is updated and on the main branch,");
		MelonLogger.Msg(ConsoleColor.Magenta, "Then if the bug persists message me on nexus");
		MelonLogger.Msg(ConsoleColor.Magenta, "- OverweightUnicorn\n");
		CounterOfferConfig.LoadConfig();
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (sceneName.ToLower() == "main")
		{
			labelCount = 0;
			selectorTabControl = null;
		}
	}
}
public class Tab
{
	public string id;

	public Button button;

	public Image background;

	public Text buttonText;

	public void SetColor(Color bgColor, Color textColor)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		SetBgColor(bgColor);
		SetTextColor(textColor);
	}

	public void SetBgColor(Color newColor)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		((Graphic)background).color = newColor;
	}

	public void SetTextColor(Color newColor)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		((Graphic)buttonText).color = newColor;
	}
}
public class TabController
{
	public Dictionary<string, Tab> allTabs = new Dictionary<string, Tab>();

	public Tab selectedTab;

	public float clickBuffer = 0.7f;

	public float prevTime;

	public GameObject filterbuttons;

	public Transform parent;

	public Font font;

	public Color textActive = new Color(0.961f, 0.961f, 0.961f);

	public Color textDisabled = new Color(0.686f, 0.686f, 0.686f);

	public Color tabIdle = new Color(0.051f, 0.286f, 0.451f);

	public Color tabHover = new Color(0.114f, 0.353f, 0.525f);

	public Color tabActive = new Color(0.204f, 0.522f, 0.737f);

	public TabController(Transform parent)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		this.parent = parent;
		InitFilterButtons();
	}

	private void InitFilterButtons()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		filterbuttons = new GameObject("Filter_Buttons");
		if ((Object)(object)parent != (Object)null)
		{
			filterbuttons.transform.SetParent(parent, false);
		}
		filterbuttons.AddComponent<CanvasRenderer>();
		RectTransform obj = filterbuttons.AddComponent<RectTransform>();
		obj.anchorMin = new Vector2(0f, 0.5f);
		obj.anchorMax = new Vector2(1f, 0.5f);
		obj.anchoredPosition = new Vector2(0f, 200f);
		obj.sizeDelta = new Vector2(1f, 60f);
		((Graphic)filterbuttons.AddComponent<Image>()).color = new Color(0.9608f, 0.9608f, 0.9608f);
		GridLayoutGroup obj2 = filterbuttons.AddComponent<GridLayoutGroup>();
		obj2.cellSize = new Vector2(100f, 45f);
		obj2.spacing = new Vector2(15f, 0f);
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		obj2.constraint = (Constraint)1;
		obj2.constraintCount = 3;
	}

	public void AddTab(string id, string text)
	{
		if (allTabs.ContainsKey(id))
		{
			throw new Exception("The key " + id + " already exists in the tab list");
		}
		if ((Object)(object)filterbuttons == (Object)null)
		{
			throw new Exception("Filter Buttons has not been initialized");
		}
		Tab value = CreateNewTab(filterbuttons.transform, id, text);
		allTabs.Add(id, value);
	}

	public void SetSelected(string key)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		if (!allTabs.ContainsKey(key))
		{
			throw new Exception(key + " Does Not Exist in the TabController Dictionary");
		}
		Tab tab = allTabs[key];
		selectedTab = allTabs[key];
		tab.SetColor(tabActive, textActive);
	}

	public Tab CreateNewTab(Transform parent, string title, string text)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Expected O, but got Unknown
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Expected O, but got Unknown
		GameObject val = new GameObject(title + "_Button");
		val.transform.SetParent(parent, false);
		val.AddComponent<CanvasRenderer>();
		Button button = val.AddComponent<Button>();
		Image val2 = val.AddComponent<Image>();
		((Graphic)val2).color = tabIdle;
		GameObject val3 = new GameObject(title + "_Button_Text");
		val3.transform.SetParent(val.transform, false);
		Text val4 = val3.AddComponent<Text>();
		val4.text = text;
		val4.font = (((Object)(object)font != (Object)null) ? font : Resources.GetBuiltinResource<Font>("Arial.ttf"));
		val4.fontSize = 30;
		((Graphic)val4).color = textDisabled;
		val4.alignment = (TextAnchor)4;
		RectTransform component = val3.GetComponent<RectTransform>();
		component.pivot = new Vector2(0.5f, 0.5f);
		component.sizeDelta = new Vector2(60f, 40f);
		component.anchorMin = new Vector2(0f, 0f);
		component.anchorMax = new Vector2(1f, 1f);
		component.anchoredPosition = new Vector2(0f, 0f);
		Tab newTab = new Tab();
		newTab.id = title;
		newTab.button = button;
		newTab.background = val2;
		newTab.buttonText = val4;
		Entry val5 = new Entry();
		val5.eventID = (EventTriggerType)0;
		((UnityEvent<BaseEventData>)(object)val5.callback).AddListener(DelegateSupport.ConvertDelegate<UnityAction<BaseEventData>>((Delegate)(Action<BaseEventData>)delegate
		{
			HandleButtonEnter(newTab);
		}));
		Entry val6 = new Entry();
		val6.eventID = (EventTriggerType)1;
		((UnityEvent<BaseEventData>)(object)val6.callback).AddListener(DelegateSupport.ConvertDelegate<UnityAction<BaseEventData>>((Delegate)(Action<BaseEventData>)delegate
		{
			HandleButtonExit(newTab);
		}));
		Entry val7 = new Entry();
		val7.eventID = (EventTriggerType)4;
		((UnityEvent<BaseEventData>)(object)val7.callback).AddListener(DelegateSupport.ConvertDelegate<UnityAction<BaseEventData>>((Delegate)(Action<BaseEventData>)delegate
		{
			HandleButtonClick(newTab);
		}));
		EventTrigger obj = val.AddComponent<EventTrigger>();
		obj.triggers.Add(val5);
		obj.triggers.Add(val6);
		obj.triggers.Add(val7);
		return newTab;
	}

	public void HandleButtonEnter(Tab currTab)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		ResetTabs();
		if (selectedTab == null || selectedTab != currTab)
		{
			currTab.SetBgColor(tabHover);
		}
	}

	public void HandleButtonExit(Tab currTab)
	{
		ResetTabs();
	}

	public void HandleButtonClick(Tab currTab)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		float time = Time.time;
		if (time - prevTime > clickBuffer)
		{
			CounterOfferUI.TabSelected(currTab);
			selectedTab = currTab;
			ResetTabs();
			currTab.SetColor(tabActive, textActive);
			prevTime = time;
		}
	}

	public void ResetTabs()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		foreach (KeyValuePair<string, Tab> allTab in allTabs)
		{
			if (selectedTab == null || selectedTab != allTab.Value)
			{
				allTab.Value.SetColor(tabIdle, textDisabled);
			}
		}
	}
}

BetterCounterOfferUI-Mono_3.0.0.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BetterCounterOffer;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ScheduleOne;
using ScheduleOne.Economy;
using ScheduleOne.GameTime;
using ScheduleOne.ItemFramework;
using ScheduleOne.Product;
using ScheduleOne.UI.Handover;
using ScheduleOne.UI.Phone;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(CounterOfferUI), "Better Counter Offer UI", "3.0.0", "OverweightUnicorn", "")]
[assembly: MelonColor(255, 191, 0, 255)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("BetterCounterOfferUI-Mono_3.0.0")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("3.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7224677b32d7c4ecba8a21f5f8f5c7f5d79269e7")]
[assembly: AssemblyProduct("BetterCounterOfferUI-Mono_3.0.0")]
[assembly: AssemblyTitle("BetterCounterOfferUI-Mono_3.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterCounterOffer
{
	public static class BuildInfo
	{
		public const string Name = "Better Counter Offer UI";

		public const string Description = "A mod that improves the Counter Offer UI";

		public const string Author = "OverweightUnicorn";

		public const string Company = "UnicornsCanMod";

		public const string Version = "3.0.0";

		public const string DownloadLink = "";
	}
	public class CounterOfferUI : MelonMod
	{
		public static GameObject PlayerRef = null;

		public static GameObject popupRef = null;

		public static GameObject productSelectorRef = null;

		public static GameObject offerInfoGO = null;

		public static Text initialOfferText = null;

		public static Text successRateText = null;

		public static Text maxCashText = null;

		public static Text btnText = null;

		public static Image btnBg = null;

		public static Font gameFont = null;

		public static TabController selectorTabControl;

		public static bool displayAll = false;

		public static string currTab = "Favorites";

		public static float prevTime = 0f;

		public static Gradient colorMap = new Gradient();

		public static CounterOfferProductSelector selectorInterface = null;

		public static CounterofferInterface offerInterface = null;

		public static int labelCount = 0;

		public static Dictionary<string, Vector2[]> uiPositions = new Dictionary<string, Vector2[]>
		{
			{
				"Shade/Content",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(-160f, -160f),
					new Vector2(-160f, -180f),
					new Vector2(-160f, -140f),
					new Vector2(-160f, -90f)
				}
			},
			{
				"Selection",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(0f, -182f),
					new Vector2(0f, -230f),
					new Vector2(0f, -250f),
					new Vector2(0f, -250f)
				}
			},
			{
				"Subtitle",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(0f, -117f),
					new Vector2(0f, -150f),
					new Vector2(0f, -190f),
					new Vector2(0f, -220f)
				}
			},
			{
				"Remove",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(-210f, 74f),
					new Vector2(-210f, 30f),
					new Vector2(-210f, 10f),
					new Vector2(-210f, 10f)
				}
			},
			{
				"Add",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(210f, 74f),
					new Vector2(210f, 30f),
					new Vector2(210f, 10f),
					new Vector2(210f, 10f)
				}
			},
			{
				"Product",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(0f, 74f),
					new Vector2(0f, 30f),
					new Vector2(0f, 10f),
					new Vector2(0f, 10f)
				}
			},
			{
				"Subtitle (1)",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(0f, -258.12f),
					new Vector2(0f, -260f),
					new Vector2(0f, -300f),
					new Vector2(0f, -335f)
				}
			},
			{
				"Price",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(0f, -313.12f),
					new Vector2(0f, -310f),
					new Vector2(0f, -350f),
					new Vector2(0f, -390f)
				}
			},
			{
				"Fair price",
				(Vector2[])(object)new Vector2[4]
				{
					new Vector2(0f, -362f),
					new Vector2(0f, -370f),
					new Vector2(0f, -405f),
					new Vector2(0f, -450f)
				}
			}
		};

		public static void OnPopupOpen(CounterofferInterface instance)
		{
			Customer component = ((Component)instance.conversation.sender).GetComponent<Customer>();
			if ((Object)(object)component == (Object)null)
			{
				((Component)offerInterface.conversation.sender).GetComponent<Customer>();
			}
			prevTime = 0f;
			if (!CounterOfferConfig.disableAllLabels)
			{
				if (!CounterOfferConfig.disableInitialOffer)
				{
					SetInitialPriceText(instance.price);
				}
				if (!CounterOfferConfig.disableMaxLimit)
				{
					SetMaxCashText(CalculateSpendingLimits(component));
				}
				if (!CounterOfferConfig.disableSuccessRate)
				{
					SetSuccessRateText(CalculateSuccessProbability(component, instance.selectedProduct, instance.quantity, instance.price));
				}
			}
		}

		public static void SetSuccessRateText(float success)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)successRateText == (Object)null)
			{
				MelonLogger.Msg("successRateText is null??");
				return;
			}
			successRateText.text = $"<b>{Mathf.RoundToInt(success * 100f)}% Chance of Success</b>";
			((Graphic)successRateText).color = colorMap.Evaluate(success);
		}

		public static void SetMaxCashText(float maxSpend)
		{
			if (!((Object)(object)maxCashText == (Object)null))
			{
				maxCashText.text = $"<b>Spend Limit: ${Mathf.RoundToInt(maxSpend)}</b>";
			}
		}

		public static void SetInitialPriceText(float initialPrice)
		{
			if (!((Object)(object)initialOfferText == (Object)null))
			{
				initialOfferText.text = $"<b>Initial Offer ${Mathf.RoundToInt(initialPrice)}</b>";
			}
		}

		public static float CalculateSpendingLimits(Customer customer)
		{
			CustomerData customerData = customer.CustomerData;
			float adjustedWeeklySpend = customerData.GetAdjustedWeeklySpend(customer.NPC.RelationData.RelationDelta / 5f);
			List<EDay> orderDays = customerData.GetOrderDays(customer.CurrentAddiction, customer.NPC.RelationData.RelationDelta / 5f);
			return adjustedWeeklySpend / (float)orderDays.Count * 3f;
		}

		public static float CalculateSuccessProbability(Customer customer, ProductDefinition product, int quantity, float price)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			float adjustedWeeklySpend = customer.customerData.GetAdjustedWeeklySpend(customer.NPC.RelationData.RelationDelta / 5f);
			List<EDay> orderDays = customer.customerData.GetOrderDays(customer.CurrentAddiction, customer.NPC.RelationData.RelationDelta / 5f);
			float num = adjustedWeeklySpend / (float)orderDays.Count;
			if (price >= num * 3f)
			{
				return 0f;
			}
			float valueProposition = Customer.GetValueProposition(Registry.GetItem<ProductDefinition>(customer.OfferedContractInfo.Products.entries[0].ProductID), customer.OfferedContractInfo.Payment / (float)customer.OfferedContractInfo.Products.entries[0].Quantity);
			float productEnjoyment = customer.GetProductEnjoyment(product, StandardsMethod.GetCorrespondingQuality(customer.customerData.Standards));
			float num2 = Mathf.InverseLerp(-1f, 1f, productEnjoyment);
			float valueProposition2 = Customer.GetValueProposition(product, price / (float)quantity);
			float num3 = Mathf.Pow((float)quantity / (float)customer.OfferedContractInfo.Products.entries[0].Quantity, 0.6f);
			float num4 = Mathf.Lerp(0f, 2f, num3 * 0.5f);
			float num5 = Mathf.Lerp(1f, 0f, Mathf.Abs(num4 - 1f));
			if (valueProposition2 * num5 > valueProposition)
			{
				return 1f;
			}
			if (valueProposition2 < 0.12f)
			{
				return 0f;
			}
			float num6 = productEnjoyment * valueProposition;
			float num7 = num2 * num5 * valueProposition2;
			if (num7 > num6)
			{
				return 1f;
			}
			float num8 = num6 - num7;
			float num9 = Mathf.Lerp(0f, 1f, num8 / 0.2f);
			float num10 = Mathf.Max(customer.CurrentAddiction, customer.NPC.RelationData.NormalizedRelationDelta);
			float num11 = Mathf.Lerp(0f, 0.2f, num10);
			if (num9 <= num11)
			{
				return 1f;
			}
			if (num9 - num11 >= 0.9f)
			{
				return 0f;
			}
			return Mathf.Clamp((0.9f + num11 - num9) / 0.9f, 0f, 1f);
		}

		public static void UpdateSuccessRate(CounterofferInterface instance)
		{
			if ((Object)(object)instance == (Object)null)
			{
				MelonLogger.Msg(ConsoleColor.Red, "CounterofferInterface Instance was Null!!");
			}
			else if ((Object)(object)successRateText == (Object)null)
			{
				MelonLogger.Msg(ConsoleColor.Red, "successRateText Instance was Null!!");
			}
			else
			{
				SetSuccessRateText(CalculateSuccessProbability(((Component)instance.conversation.sender).GetComponent<Customer>(), instance.selectedProduct, instance.quantity, instance.price));
			}
		}

		public static void InitOnWake()
		{
			GameObject val = GameObject.Find("UI/HandoverScreen");
			if ((Object)(object)val != (Object)null)
			{
				HandoverScreen component = val.GetComponent<HandoverScreen>();
				if ((Object)(object)val != (Object)null)
				{
					colorMap = component.SuccessColorMap;
				}
			}
			GameObject val2 = GameObject.Find("Player_Local");
			if (!((Object)(object)val2 != (Object)null))
			{
				return;
			}
			PlayerRef = val2;
			Transform val3 = PlayerRef.transform.Find("CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/Messages/Container/CounterofferInterface/Shade/Content");
			if ((Object)(object)(((Object)(object)val3 != (Object)null) ? ((Component)val3).gameObject : null) != (Object)null)
			{
				MelonLogger.Msg(ConsoleColor.Magenta, "CounterOffer Container Found Lets Make it Better");
				if (!CounterOfferConfig.disableAllLabels)
				{
					CreateLabels(val3);
					GrowPopUpWindow(val3);
					ShiftOfferElements(val3);
				}
				UpdateSelectorUI(val3);
			}
		}

		private static void GrowPopUpWindow(Transform transform)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)transform != (Object)null)
			{
				Vector2 sizeDelta = uiPositions["Shade/Content"][labelCount];
				((Component)transform).GetComponent<RectTransform>().sizeDelta = sizeDelta;
			}
		}

		private static void AdjustUiElements(Transform parent, string searchStr)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Transform val = parent.Find(searchStr);
			if ((Object)(object)val != (Object)null)
			{
				Vector2 anchoredPosition = uiPositions[searchStr][labelCount];
				((Component)val).GetComponent<RectTransform>().anchoredPosition = anchoredPosition;
			}
			else
			{
				MelonLogger.Msg(ConsoleColor.Red, searchStr + " Couldn't be Found");
			}
		}

		private static void ShiftOfferElements(Transform parent)
		{
			AdjustUiElements(parent, "Fair price");
			AdjustUiElements(parent, "Price");
			AdjustUiElements(parent, "Subtitle (1)");
			AdjustUiElements(parent, "Product");
			AdjustUiElements(parent, "Add");
			AdjustUiElements(parent, "Remove");
			AdjustUiElements(parent, "Subtitle");
			AdjustUiElements(parent, "Selection");
		}

		private static void UpdateSelectorUI(Transform parent)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			Transform val = parent.Find("Selection");
			if ((Object)(object)val != (Object)null)
			{
				MelonLogger.Msg(ConsoleColor.Magenta, "The Selector UI now has Tabs....AWESOME");
				selectorInterface = ((Component)val).GetComponent<CounterOfferProductSelector>();
				Transform val2 = val.Find("SearchInput");
				if ((Object)(object)val2 != (Object)null)
				{
					((Component)val2).GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, -83f);
					((Component)val2).GetComponent<InputField>();
				}
				Transform val3 = val.Find("Window");
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)val3).GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, -87f);
					if (selectorTabControl == null)
					{
						selectorTabControl = new TabController(val);
						selectorTabControl.font = gameFont;
						selectorTabControl.AddTab("Favorites", "<b>Fave</b>");
						selectorTabControl.AddTab("Listed", "<b>Listed</b>");
						selectorTabControl.AddTab("Discovered", "<b>All</b>");
						selectorTabControl.SetSelected(currTab);
					}
				}
			}
			else
			{
				MelonLogger.Msg(ConsoleColor.Red, "Selection Couldn't be Found");
			}
		}

		public static void TabSelected(Tab selected)
		{
			currTab = selected.id;
			if ((Object)(object)selectorInterface != (Object)null)
			{
				selectorInterface.RebuildResultsList();
			}
		}

		private static void CreateLabels(Transform parent)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			Transform val = parent.Find("Title");
			if ((Object)(object)val != (Object)null)
			{
				gameFont = ((Component)val).GetComponent<Text>().font;
			}
			offerInfoGO = new GameObject("OfferInformation");
			offerInfoGO.transform.SetParent(parent, false);
			offerInfoGO.transform.localPosition = new Vector3(181.5444f, 1.175f, -9.2547f);
			offerInfoGO.AddComponent<CanvasRenderer>();
			RectTransform obj = offerInfoGO.AddComponent<RectTransform>();
			obj.anchoredPosition = new Vector2(-270.0037f, -150f);
			obj.anchorMin = new Vector2(1f, 1f);
			obj.anchorMax = new Vector2(1f, 1f);
			obj.pivot = new Vector2(0.5f, 0.5f);
			obj.sizeDelta = new Vector2(300f, 100f);
			float num = 40f;
			if ((Object)(object)initialOfferText == (Object)null && !CounterOfferConfig.disableInitialOffer)
			{
				initialOfferText = CreateLabel(offerInfoGO.transform, "InitialCash", "Initial Offer Price: ", new Vector3(0f, num, 0f));
				num -= 35f;
				labelCount++;
			}
			if ((Object)(object)maxCashText == (Object)null && !CounterOfferConfig.disableMaxLimit)
			{
				maxCashText = CreateLabel(offerInfoGO.transform, "MaxCash", "$1000 Max", new Vector3(0f, num, 0f));
				num -= 35f;
				labelCount++;
			}
			if ((Object)(object)successRateText == (Object)null && !CounterOfferConfig.disableSuccessRate)
			{
				successRateText = CreateLabel(offerInfoGO.transform, "SuccessRate", "100% Success Rate", new Vector3(0f, num, 0f));
				labelCount++;
			}
		}

		public static Text CreateLabel(Transform parent, string title, string text, Vector3 localPosition)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(title);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			Text obj = val.AddComponent<Text>();
			obj.text = text;
			obj.font = (((Object)(object)gameFont != (Object)null) ? gameFont : Resources.GetBuiltinResource<Font>("Arial.ttf"));
			obj.fontSize = 30;
			((Graphic)obj).color = Color.gray;
			obj.alignment = (TextAnchor)4;
			((Component)val.transform).GetComponent<RectTransform>().sizeDelta = new Vector2(600f, 100f);
			return obj;
		}

		public override void OnInitializeMelon()
		{
			MelonLogger.Msg(ConsoleColor.Magenta, "Initializing Better Counter Offer...Go Make that Money");
			MelonLogger.Msg(ConsoleColor.Magenta, "If you find any bugs,");
			MelonLogger.Msg(ConsoleColor.Magenta, "first check that your game is updated and on the main branch,");
			MelonLogger.Msg(ConsoleColor.Magenta, "Then if the bug persists message me on nexus");
			MelonLogger.Msg(ConsoleColor.Magenta, "- OverweightUnicorn\n");
			CounterOfferConfig.LoadConfig();
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName.ToLower() == "main")
			{
				labelCount = 0;
				selectorTabControl = null;
			}
		}
	}
	public static class CounterOfferConfig
	{
		private static string folderName = "CounterOfferUI";

		private static string fileName = "CounterOffer_Config.ini";

		public static bool disableAllLabels = false;

		public static bool disableSuccessRate = false;

		public static bool disableMaxLimit = false;

		public static bool disableInitialOffer = false;

		public static void LoadConfig()
		{
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), folderName);
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string path = Path.Combine(text, fileName);
			if (!File.Exists(path))
			{
				SaveConfig();
				MelonLogger.Msg(ConsoleColor.Magenta, "CounterOffer Config file created with default values.");
			}
			string[] array = File.ReadAllLines(path);
			foreach (string text2 in array)
			{
				if (string.IsNullOrWhiteSpace(text2) || text2.TrimStart().StartsWith("#"))
				{
					continue;
				}
				string[] array2 = text2.Split('=');
				string text3 = array2[0].Trim();
				if (bool.TryParse(array2[1].Trim(), out var result))
				{
					switch (text3)
					{
					case "DisableAllLabels":
						disableAllLabels = result;
						break;
					case "DisableInitialOffer":
						disableInitialOffer = result;
						break;
					case "DisableMaxLimit":
						disableMaxLimit = result;
						break;
					case "DisableSuccessRate":
						disableSuccessRate = result;
						break;
					}
				}
			}
			MelonLogger.Msg(ConsoleColor.Magenta, "CounterOffer Config loaded:");
			MelonLogger.Msg(ConsoleColor.Magenta, $"  Disable All Labels={disableAllLabels}");
			MelonLogger.Msg(ConsoleColor.Magenta, $"  Disable Initial Offer={disableInitialOffer}");
			MelonLogger.Msg(ConsoleColor.Magenta, $"  Disable Max Limit={disableMaxLimit}");
			MelonLogger.Msg(ConsoleColor.Magenta, $"  Disable Success Rate={disableSuccessRate}");
		}

		public static void SaveConfig()
		{
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), folderName);
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string path = Path.Combine(text, fileName);
			string[] contents = new string[5]
			{
				"# CounterOffer configuration",
				"DisableAllLabels=" + disableAllLabels,
				"DisableInitialOffer=" + disableInitialOffer,
				"DisableMaxLimit=" + disableMaxLimit,
				"DisableSuccessRate=" + disableSuccessRate
			};
			File.WriteAllLines(path, contents);
		}
	}
	[HarmonyPatch(typeof(CounterofferInterface), "Awake")]
	internal static class CounterOfferAwakePatch
	{
		public static bool Prefix(CounterofferInterface __instance)
		{
			MelonLogger.Msg("Waking Up, Lets Modify this UI and make it Better");
			CounterOfferUI.InitOnWake();
			return true;
		}
	}
	[HarmonyPatch(typeof(CounterofferInterface), "Open")]
	internal static class CounterOfferInterfaceOpenPatch
	{
		public static void Postfix(CounterofferInterface __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				CounterOfferUI.OnPopupOpen(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(CounterofferInterface), "ChangePrice")]
	internal static class CounterOfferInterfaceChangePricePatch
	{
		public static void Postfix(CounterofferInterface __instance)
		{
			if (!CounterOfferConfig.disableSuccessRate)
			{
				CounterOfferUI.UpdateSuccessRate(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(CounterofferInterface), "ChangeQuantity")]
	internal static class CounterOfferInterfaceChangeQuantityPatch
	{
		public static void Postfix(CounterofferInterface __instance)
		{
			ProductDefinition selectedProduct = __instance.selectedProduct;
			float num = (float)__instance.quantity * selectedProduct.Price - __instance.price;
			__instance.ChangePrice(num);
			if (!CounterOfferConfig.disableSuccessRate)
			{
				CounterOfferUI.UpdateSuccessRate(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(CounterofferInterface), "SetProduct")]
	internal static class CounterOfferInterfaceSetProductPatch
	{
		public static void Postfix(CounterofferInterface __instance)
		{
			float num = (float)__instance.quantity * __instance.selectedProduct.Price - __instance.price;
			__instance.ChangePrice(num);
			if (!CounterOfferConfig.disableSuccessRate)
			{
				CounterOfferUI.UpdateSuccessRate(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(CounterOfferProductSelector), "Open")]
	internal static class CounterOfferProductSelectorOpenPatch
	{
		public static void Postfix(CounterOfferProductSelector __instance)
		{
			if ((Object)(object)CounterOfferUI.selectorInterface == (Object)null)
			{
				MelonLogger.Msg(ConsoleColor.Magenta, "Attempting to caputre ProductSelector interface");
				CounterOfferUI.selectorInterface = __instance;
			}
		}
	}
	[HarmonyPatch(typeof(CounterOfferProductSelector), "GetMatchingProducts")]
	internal static class CounterOfferProductSelectorGetMatchingProductsPatch
	{
		public static void Postfix(CounterofferInterface __instance, ref List<ProductDefinition> __result, ref string searchTerm)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			HashSet<EDrugType> hashSet = new HashSet<EDrugType>();
			List<ProductDefinition> list = ((CounterOfferUI.currTab == "Listed") ? ProductManager.ListedProducts : ((!(CounterOfferUI.currTab == "Favorites")) ? ProductManager.DiscoveredProducts : ProductManager.FavouritedProducts));
			List<ProductDefinition> list2 = new List<ProductDefinition>();
			if (searchTerm.ToLower().Contains("weed"))
			{
				hashSet.Add((EDrugType)0);
			}
			if (searchTerm.ToLower().Contains("coke"))
			{
				hashSet.Add((EDrugType)2);
			}
			if (searchTerm.ToLower().Contains("meth"))
			{
				hashSet.Add((EDrugType)1);
			}
			foreach (ProductDefinition item in list)
			{
				if (hashSet.Contains(item.DrugType) || ((ItemDefinition)item).Name.ToLower().Contains(searchTerm))
				{
					list2.Add(item);
				}
			}
			__result = list2;
		}
	}
	public class Tab
	{
		public string id;

		public Button button;

		public Image background;

		public Text buttonText;

		public void SetColor(Color bgColor, Color textColor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			SetBgColor(bgColor);
			SetTextColor(textColor);
		}

		public void SetBgColor(Color newColor)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)background).color = newColor;
		}

		public void SetTextColor(Color newColor)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)buttonText).color = newColor;
		}
	}
	public class TabController
	{
		public Dictionary<string, Tab> allTabs = new Dictionary<string, Tab>();

		public Tab selectedTab;

		public float clickBuffer = 0.7f;

		public float prevTime;

		public GameObject filterbuttons;

		public Transform parent;

		public Font font;

		public Color textActive = new Color(0.961f, 0.961f, 0.961f);

		public Color textDisabled = new Color(0.686f, 0.686f, 0.686f);

		public Color tabIdle = new Color(0.051f, 0.286f, 0.451f);

		public Color tabHover = new Color(0.114f, 0.353f, 0.525f);

		public Color tabActive = new Color(0.204f, 0.522f, 0.737f);

		public TabController(Transform parent)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			this.parent = parent;
			InitFilterButtons();
		}

		private void InitFilterButtons()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			filterbuttons = new GameObject("Filter_Buttons");
			if ((Object)(object)parent != (Object)null)
			{
				filterbuttons.transform.SetParent(parent, false);
			}
			filterbuttons.AddComponent<CanvasRenderer>();
			RectTransform obj = filterbuttons.AddComponent<RectTransform>();
			obj.anchorMin = new Vector2(0f, 0.5f);
			obj.anchorMax = new Vector2(1f, 0.5f);
			obj.anchoredPosition = new Vector2(0f, 200f);
			obj.sizeDelta = new Vector2(1f, 60f);
			((Graphic)filterbuttons.AddComponent<Image>()).color = new Color(0.9608f, 0.9608f, 0.9608f);
			GridLayoutGroup obj2 = filterbuttons.AddComponent<GridLayoutGroup>();
			obj2.cellSize = new Vector2(100f, 45f);
			obj2.spacing = new Vector2(15f, 0f);
			((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
			obj2.constraint = (Constraint)1;
			obj2.constraintCount = 3;
		}

		public void AddTab(string id, string text)
		{
			if (allTabs.ContainsKey(id))
			{
				throw new Exception("The key " + id + " already exists in the tab list");
			}
			if ((Object)(object)filterbuttons == (Object)null)
			{
				throw new Exception("Filter Buttons has not been initialized");
			}
			Tab value = CreateNewTab(filterbuttons.transform, id, text);
			allTabs.Add(id, value);
		}

		public void SetSelected(string key)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!allTabs.ContainsKey(key))
			{
				throw new Exception(key + " Does Not Exist in the TabController Dictionary");
			}
			Tab tab = allTabs[key];
			selectedTab = allTabs[key];
			tab.SetColor(tabActive, textActive);
		}

		public Tab CreateNewTab(Transform parent, string title, string text)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Expected O, but got Unknown
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(title + "_Button");
			val.transform.SetParent(parent, false);
			val.AddComponent<CanvasRenderer>();
			Button button = val.AddComponent<Button>();
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = tabIdle;
			GameObject val3 = new GameObject(title + "_Button_Text");
			val3.transform.SetParent(val.transform, false);
			Text val4 = val3.AddComponent<Text>();
			val4.text = text;
			val4.font = (((Object)(object)font != (Object)null) ? font : Resources.GetBuiltinResource<Font>("Arial.ttf"));
			val4.fontSize = 30;
			((Graphic)val4).color = textDisabled;
			val4.alignment = (TextAnchor)4;
			RectTransform component = val3.GetComponent<RectTransform>();
			component.pivot = new Vector2(0.5f, 0.5f);
			component.sizeDelta = new Vector2(60f, 40f);
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.anchoredPosition = new Vector2(0f, 0f);
			Tab newTab = new Tab();
			newTab.id = title;
			newTab.button = button;
			newTab.background = val2;
			newTab.buttonText = val4;
			Entry val5 = new Entry();
			val5.eventID = (EventTriggerType)0;
			((UnityEvent<BaseEventData>)(object)val5.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				HandleButtonEnter(newTab);
			});
			Entry val6 = new Entry();
			val6.eventID = (EventTriggerType)1;
			((UnityEvent<BaseEventData>)(object)val6.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				HandleButtonExit(newTab);
			});
			Entry val7 = new Entry();
			val7.eventID = (EventTriggerType)4;
			((UnityEvent<BaseEventData>)(object)val7.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				HandleButtonClick(newTab);
			});
			EventTrigger obj = val.AddComponent<EventTrigger>();
			obj.triggers.Add(val5);
			obj.triggers.Add(val6);
			obj.triggers.Add(val7);
			return newTab;
		}

		public void HandleButtonEnter(Tab currTab)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			ResetTabs();
			if (selectedTab == null || selectedTab != currTab)
			{
				currTab.SetBgColor(tabHover);
			}
		}

		public void HandleButtonExit(Tab currTab)
		{
			ResetTabs();
		}

		public void HandleButtonClick(Tab currTab)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			if (time - prevTime > clickBuffer)
			{
				CounterOfferUI.TabSelected(currTab);
				selectedTab = currTab;
				ResetTabs();
				currTab.SetColor(tabActive, textActive);
				prevTime = time;
			}
		}

		public void ResetTabs()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<string, Tab> allTab in allTabs)
			{
				if (selectedTab == null || selectedTab != allTab.Value)
				{
					allTab.Value.SetColor(tabIdle, textDisabled);
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}