Decompiled source of Choose Deal Locations v2.0.2

ChooseDealLocationOnAccept_IL2CPP.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.Quests;
using Il2CppScheduleOne.UI.Phone.Messages;
using Il2CppSystem;
using MelonLoader;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(ChooseDealLocationOnAccept), "Choose Deal Location", "2.0.2", "meiscool125 and JumbleBumble", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonColor(143, 45, 162, 1)]
[assembly: MelonAuthorColor(0, 255, 252, 1)]
[assembly: AssemblyTitle("ChooseDealLocationOnAccept")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChooseDealLocationOnAccept")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2ce5a4b9-304b-4bc7-8922-21427bd6c86c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public class ChooseDealLocationOnAccept : MelonMod
{
	[HarmonyPatch(typeof(Customer), "PlayerAcceptedContract")]
	public static class Customer_PlayerAcceptedContract_Patch
	{
		public static bool Prefix(Customer __instance, ref EDealWindow window)
		{
			ContractInfo offeredContractInfo = __instance.OfferedContractInfo;
			if (offeredContractInfo != null && currentSelectedDeliveryLocation != "none" && !useRandomDeliveryLocation)
			{
				offeredContractInfo.DeliveryLocationGUID = currentSelectedGUID;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Customer), "AcceptContractClicked")]
	public class Customer_AcceptContractClicked_Patch
	{
		public static bool Prefix(Customer __instance)
		{
			if (__instance.OfferedContractInfo == null)
			{
				MelonLogger.Warning("Offered contract is null!");
				return false;
			}
			GameObject obj = GameObject.Find("Messages");
			object obj2;
			if (obj == null)
			{
				obj2 = null;
			}
			else
			{
				Transform obj3 = obj.transform.Find("Container");
				if (obj3 == null)
				{
					obj2 = null;
				}
				else
				{
					Transform obj4 = ((Component)obj3).transform.Find("DealWindowSelector");
					obj2 = ((obj4 != null) ? ((Component)obj4).transform : null);
				}
			}
			Transform val = (Transform)obj2;
			if ((Object)(object)val != (Object)null)
			{
				((Component)val).gameObject.SetActive(true);
				Transform val2 = val.Find("Background");
				Transform val3 = val.Find("Shade");
				Transform val4 = ((val3 != null) ? val3.Find("Content") : null);
				if ((Object)(object)val2 != (Object)null)
				{
					((Component)val2).gameObject.SetActive(true);
				}
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)val3).gameObject.SetActive(true);
				}
				if ((Object)(object)val4 != (Object)null)
				{
					((Component)val4).gameObject.SetActive(false);
				}
			}
			else
			{
				MelonLogger.Warning("Could not find DealWindowSelector hierarchy to modify.");
			}
			pendingCustomer = __instance;
			showUI = true;
			selectedDeliveryLocation = false;
			return false;
		}
	}

	public static Dictionary<string, string> LocationGuids = new Dictionary<string, string>();

	private static string currentSelectedDeliveryLocation = "none";

	private static string currentSelectedGUID = "none";

	private static bool useRandomDeliveryLocation = true;

	private static bool selectedDeliveryLocation = false;

	private static Customer pendingCustomer = null;

	private static bool showUI = false;

	private static Rect windowUIRect;

	private Vector2 scrollUIPosition;

	private GUIStyle squareWindowStyle;

	private GUIStyle squareButtonStyle;

	private GUIStyle squareLabelStyle;

	private GUIStyle squareVerticalScrollStyle;

	private GUIStyle squareVerticalScrollThumbStyle;

	private Texture2D blackTex;

	private Texture2D buttonColorTex;

	private Texture2D buttonHoverColorTex;

	private Texture2D scrollBarTex;

	private static Dictionary<string, GUIContent> buttonLabels = new Dictionary<string, GUIContent>();

	private int prevScreenWidth = -1;

	private int prevScreenHeight = -1;

	public static void Print(string s)
	{
		MelonLogger.Msg(s);
	}

	public override void OnInitializeMelon()
	{
		Print("Initialized");
	}

	public override void OnLateInitializeMelon()
	{
		Singleton<LoadManager>.Instance.onLoadComplete.AddListener(UnityAction.op_Implicit((Action)MakeDeliveryLocationsDict));
		buttonColorTex = Texture2D.grayTexture;
		buttonHoverColorTex = Texture2D.grayTexture;
		blackTex = Texture2D.blackTexture;
		scrollBarTex = Texture2D.grayTexture;
	}

	private void DrawUI()
	{
		//IL_004b: 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_007e: 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_00e3: Expected O, but got Unknown
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Expected O, but got Unknown
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Expected O, but got Unknown
		float num = ((Rect)(ref windowUIRect)).width - 20f;
		if (GUILayout.Button("Let the customer choose", squareButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
		{
			showUI = false;
			selectedDeliveryLocation = true;
			useRandomDeliveryLocation = true;
		}
		scrollUIPosition = GUILayout.BeginScrollView(scrollUIPosition, GUIStyle.none, squareVerticalScrollStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(((Rect)(ref windowUIRect)).height - 90f) });
		int num2 = 0;
		int count = LocationGuids.Count;
		foreach (KeyValuePair<string, string> locationGuid in LocationGuids)
		{
			if (!buttonLabels.ContainsKey(locationGuid.Key))
			{
				buttonLabels[locationGuid.Key] = new GUIContent(locationGuid.Key);
			}
			if (num2 == count - 1)
			{
				GUIStyle val = new GUIStyle(squareButtonStyle);
				val.margin = new RectOffset(3, 3, 3, 1);
				if (GUILayout.Button(buttonLabels[locationGuid.Key], val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
				{
					currentSelectedDeliveryLocation = locationGuid.Key;
					currentSelectedGUID = locationGuid.Value;
					showUI = false;
					selectedDeliveryLocation = true;
					useRandomDeliveryLocation = false;
				}
			}
			else if (GUILayout.Button(buttonLabels[locationGuid.Key], squareButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
			{
				currentSelectedDeliveryLocation = locationGuid.Key;
				currentSelectedGUID = locationGuid.Value;
				showUI = false;
				selectedDeliveryLocation = true;
				useRandomDeliveryLocation = false;
			}
			num2++;
		}
		GUILayout.EndScrollView();
	}

	private void UpdateWindowRect()
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		if (Screen.width != prevScreenWidth || Screen.height != prevScreenHeight)
		{
			prevScreenWidth = Screen.width;
			prevScreenHeight = Screen.height;
			windowUIRect = new Rect((float)Screen.width * 0.5f - 122.5f, (float)Screen.height * 0.5f - 167.5f, 245f, 335f);
		}
	}

	public override void OnGUI()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		if (squareWindowStyle == null)
		{
			InitializeStyles();
		}
		if (showUI)
		{
			UpdateWindowRect();
			GUILayout.BeginArea(windowUIRect, squareWindowStyle);
			GUILayout.Label("Choose where to meet the customer:", squareWindowStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
			DrawUI();
			GUILayout.EndArea();
		}
		if ((Object)(object)pendingCustomer != (Object)null && selectedDeliveryLocation)
		{
			HandleDeferredContractAcceptance();
		}
	}

	private void InitializeStyles()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: 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)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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_00d7: Expected O, but got Unknown
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Expected O, but got Unknown
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Expected O, but got Unknown
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Expected O, but got Unknown
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Expected O, but got Unknown
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Expected O, but got Unknown
		//IL_018b: 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_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Expected O, but got Unknown
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Expected O, but got Unknown
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Expected O, but got Unknown
		//IL_01ef: Expected O, but got Unknown
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Expected O, but got Unknown
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Expected O, but got Unknown
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Expected O, but got Unknown
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Expected O, but got Unknown
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Expected O, but got Unknown
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Expected O, but got Unknown
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Expected O, but got Unknown
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Expected O, but got Unknown
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Expected O, but got Unknown
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Expected O, but got Unknown
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Expected O, but got Unknown
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Expected O, but got Unknown
		Texture2D whiteTexture = Texture2D.whiteTexture;
		scrollUIPosition = Vector2.zero;
		prevScreenWidth = Screen.width;
		prevScreenHeight = Screen.height;
		windowUIRect = new Rect((float)Screen.width * 0.5f - 122.5f, (float)Screen.height * 0.5f - 167.5f, 245f, 335f);
		squareWindowStyle = new GUIStyle
		{
			padding = new RectOffset(10, 10, 15, 10),
			normal = new GUIStyleState
			{
				background = whiteTexture,
				textColor = new Color(0.1f, 0.1f, 0.1f)
			},
			onNormal = new GUIStyleState
			{
				background = whiteTexture,
				textColor = new Color(0.1f, 0.1f, 0.1f)
			},
			fontSize = 12,
			fontStyle = (FontStyle)1
		};
		squareButtonStyle = new GUIStyle
		{
			normal = new GUIStyleState
			{
				background = buttonColorTex,
				textColor = Color.white
			},
			hover = new GUIStyleState
			{
				background = buttonHoverColorTex,
				textColor = Color.white
			},
			active = new GUIStyleState
			{
				background = buttonHoverColorTex,
				textColor = Color.white
			},
			alignment = (TextAnchor)4,
			padding = new RectOffset(8, 8, 6, 6),
			margin = new RectOffset(3, 3, 3, 3),
			wordWrap = true,
			fontSize = 12,
			fontStyle = (FontStyle)1
		};
		squareLabelStyle = new GUIStyle
		{
			normal = new GUIStyleState
			{
				textColor = Color.blue
			},
			wordWrap = true,
			fontSize = 12,
			padding = new RectOffset(10, 10, 3, 3)
		};
		squareVerticalScrollStyle = new GUIStyle(GUI.skin.verticalScrollbar)
		{
			normal = new GUIStyleState
			{
				background = whiteTexture
			},
			border = new RectOffset(1, 1, 1, 1),
			fixedWidth = 10f
		};
		squareVerticalScrollThumbStyle = new GUIStyle(GUI.skin.verticalScrollbarThumb)
		{
			normal = new GUIStyleState
			{
				background = scrollBarTex
			},
			onNormal = new GUIStyleState
			{
				background = scrollBarTex
			},
			onFocused = new GUIStyleState
			{
				background = scrollBarTex
			},
			onActive = new GUIStyleState
			{
				background = scrollBarTex
			},
			onHover = new GUIStyleState
			{
				background = scrollBarTex
			},
			hover = new GUIStyleState
			{
				background = scrollBarTex
			},
			focused = new GUIStyleState
			{
				background = scrollBarTex
			},
			active = new GUIStyleState
			{
				background = scrollBarTex
			},
			fixedWidth = 10f
		};
		GUI.skin.verticalScrollbarThumb = squareVerticalScrollThumbStyle;
	}

	public static void MakeDeliveryLocationsDict()
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = null;
		try
		{
			val = GameObject.Find("Delivery Locations");
			Print("Got deliveryLocations");
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("Could not get deliveryLocations: " + ex);
			return;
		}
		for (int i = 0; i < val.transform.childCount; i++)
		{
			Transform child = val.transform.GetChild(i);
			DeliveryLocation component = ((Component)child).GetComponent<DeliveryLocation>();
			if ((Object)(object)component != (Object)null)
			{
				string locationName = component.LocationName;
				Guid gUID = component.GUID;
				string value = ((object)(Guid)(ref gUID)).ToString();
				if (!LocationGuids.ContainsKey(locationName))
				{
					LocationGuids.Add(locationName, value);
				}
				else
				{
					MelonLogger.Warning("Duplicate location \"" + locationName + "\" skipped building DeliveryLocation dict.");
				}
			}
		}
	}

	private void HandleDeferredContractAcceptance()
	{
		if (!((Object)(object)pendingCustomer != (Object)null) || !selectedDeliveryLocation)
		{
			return;
		}
		GameObject obj = GameObject.Find("Messages");
		object obj2;
		if (obj == null)
		{
			obj2 = null;
		}
		else
		{
			Transform obj3 = obj.transform.Find("Container");
			if (obj3 == null)
			{
				obj2 = null;
			}
			else
			{
				Transform obj4 = ((Component)obj3).transform.Find("DealWindowSelector");
				obj2 = ((obj4 != null) ? ((Component)obj4).transform : null);
			}
		}
		Transform val = (Transform)obj2;
		object obj5;
		if (val == null)
		{
			obj5 = null;
		}
		else
		{
			Transform obj6 = ((Component)val).transform.Find("Shade");
			obj5 = ((obj6 != null) ? ((Component)obj6).transform : null);
		}
		Transform val2 = (Transform)obj5;
		object obj7;
		if (val2 == null)
		{
			obj7 = null;
		}
		else
		{
			Transform obj8 = val2.Find("Content");
			obj7 = ((obj8 != null) ? ((Component)obj8).transform : null);
		}
		Transform val3 = (Transform)obj7;
		if ((Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null)
		{
			((Component)val2).gameObject.SetActive(true);
			((Component)val3).gameObject.SetActive(true);
		}
		else
		{
			MelonLogger.Warning("Could not find Shade/Content GameObjects to enable.");
		}
		MethodInfo methodInfo = AccessTools.Method(typeof(Customer), "PlayerAcceptedContract", (Type[])null, (Type[])null);
		if (methodInfo != null)
		{
			Action<EDealWindow> action = (Action<EDealWindow>)Delegate.CreateDelegate(typeof(Action<EDealWindow>), pendingCustomer, methodInfo);
			PlayerSingleton<MessagesApp>.Instance.DealWindowSelector.SetIsOpen(true, pendingCustomer.NPC.MSGConversation, Action<EDealWindow>.op_Implicit(action));
		}
		else
		{
			MelonLogger.Warning("Could not find PlayerAcceptedContract method!");
		}
		pendingCustomer = null;
		selectedDeliveryLocation = false;
	}
}

ChooseDealLocationOnAccept_Mono.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using ScheduleOne.DevUtilities;
using ScheduleOne.Economy;
using ScheduleOne.Persistence;
using ScheduleOne.Quests;
using ScheduleOne.UI.Phone.Messages;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(ChooseDealLocationOnAccept), "Choose Deal Location", "2.0.2", "meiscool125 and JumbleBumble", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonColor(143, 45, 162, 1)]
[assembly: MelonAuthorColor(0, 255, 252, 1)]
[assembly: AssemblyTitle("ChooseDealLocationOnAccept")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChooseDealLocationOnAccept")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2ce5a4b9-304b-4bc7-8922-21427bd6c86c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public class ChooseDealLocationOnAccept : MelonMod
{
	[HarmonyPatch(typeof(Customer), "PlayerAcceptedContract")]
	public static class Customer_PlayerAcceptedContract_Patch
	{
		public static bool Prefix(Customer __instance, ref EDealWindow window)
		{
			ContractInfo offeredContractInfo = __instance.OfferedContractInfo;
			if (offeredContractInfo != null && currentSelectedDeliveryLocation != "none" && !useRandomDeliveryLocation)
			{
				offeredContractInfo.DeliveryLocationGUID = currentSelectedGUID;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Customer), "AcceptContractClicked")]
	public class Customer_AcceptContractClicked_Patch
	{
		public static bool Prefix(Customer __instance)
		{
			if (__instance.OfferedContractInfo == null)
			{
				MelonLogger.Warning("Offered contract is null!");
				return false;
			}
			GameObject obj = GameObject.Find("Messages");
			object obj2;
			if (obj == null)
			{
				obj2 = null;
			}
			else
			{
				Transform obj3 = obj.transform.Find("Container");
				if (obj3 == null)
				{
					obj2 = null;
				}
				else
				{
					Transform obj4 = ((Component)obj3).transform.Find("DealWindowSelector");
					obj2 = ((obj4 != null) ? ((Component)obj4).transform : null);
				}
			}
			Transform val = (Transform)obj2;
			if ((Object)(object)val != (Object)null)
			{
				((Component)val).gameObject.SetActive(true);
				Transform val2 = val.Find("Background");
				Transform val3 = val.Find("Shade");
				Transform val4 = ((val3 != null) ? val3.Find("Content") : null);
				if ((Object)(object)val2 != (Object)null)
				{
					((Component)val2).gameObject.SetActive(true);
				}
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)val3).gameObject.SetActive(true);
				}
				if ((Object)(object)val4 != (Object)null)
				{
					((Component)val4).gameObject.SetActive(false);
				}
			}
			else
			{
				MelonLogger.Warning("Could not find DealWindowSelector hierarchy to modify.");
			}
			pendingCustomer = __instance;
			showUI = true;
			selectedDeliveryLocation = false;
			return false;
		}
	}

	public static Dictionary<string, string> LocationGuids = new Dictionary<string, string>();

	private static string currentSelectedDeliveryLocation = "none";

	private static string currentSelectedGUID = "none";

	private static bool useRandomDeliveryLocation = true;

	private static bool selectedDeliveryLocation = false;

	private static Customer pendingCustomer = null;

	private static bool showUI = false;

	private static Rect windowUIRect;

	private Vector2 scrollUIPosition;

	private GUIStyle squareWindowStyle;

	private GUIStyle squareButtonStyle;

	private GUIStyle squareLabelStyle;

	private GUIStyle squareVerticalScrollStyle;

	private GUIStyle squareVerticalScrollThumbStyle;

	private Texture2D blackTex;

	private Texture2D buttonColorTex;

	private Texture2D buttonHoverColorTex;

	private Texture2D scrollBarTex;

	private static Dictionary<string, GUIContent> buttonLabels = new Dictionary<string, GUIContent>();

	private int prevScreenWidth = -1;

	private int prevScreenHeight = -1;

	public static void Print(string s)
	{
		MelonLogger.Msg(s);
	}

	public override void OnInitializeMelon()
	{
		Print("Initialized");
	}

	public override void OnLateInitializeMelon()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		Singleton<LoadManager>.Instance.onLoadComplete.AddListener(new UnityAction(MakeDeliveryLocationsDict));
		buttonColorTex = new Texture2D(1, 1);
		buttonColorTex.SetPixel(0, 0, new Color(0.2901961f, 35f / 51f, 0.8784314f));
		((Texture)buttonColorTex).wrapMode = (TextureWrapMode)0;
		buttonColorTex.Apply();
		buttonHoverColorTex = new Texture2D(1, 1);
		buttonHoverColorTex.SetPixel(0, 0, new Color(39f / 85f, 0.7607843f, 46f / 51f));
		((Texture)buttonHoverColorTex).wrapMode = (TextureWrapMode)0;
		buttonHoverColorTex.Apply();
		blackTex = new Texture2D(1, 1);
		blackTex.SetPixel(0, 0, new Color(38f / 51f, 38f / 51f, 38f / 51f));
		((Texture)blackTex).wrapMode = (TextureWrapMode)0;
		blackTex.Apply();
		scrollBarTex = new Texture2D(1, 1);
		scrollBarTex.SetPixel(0, 0, new Color(38f / 51f, 38f / 51f, 38f / 51f));
		((Texture)scrollBarTex).wrapMode = (TextureWrapMode)0;
		scrollBarTex.Apply();
	}

	private void DrawUI()
	{
		//IL_004b: 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_007e: 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_00e3: Expected O, but got Unknown
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Expected O, but got Unknown
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Expected O, but got Unknown
		float num = ((Rect)(ref windowUIRect)).width - 20f;
		if (GUILayout.Button("Let the customer choose", squareButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
		{
			showUI = false;
			selectedDeliveryLocation = true;
			useRandomDeliveryLocation = true;
		}
		scrollUIPosition = GUILayout.BeginScrollView(scrollUIPosition, GUIStyle.none, squareVerticalScrollStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(((Rect)(ref windowUIRect)).height - 90f) });
		int num2 = 0;
		int count = LocationGuids.Count;
		foreach (KeyValuePair<string, string> locationGuid in LocationGuids)
		{
			if (!buttonLabels.ContainsKey(locationGuid.Key))
			{
				buttonLabels[locationGuid.Key] = new GUIContent(locationGuid.Key);
			}
			if (num2 == count - 1)
			{
				GUIStyle val = new GUIStyle(squareButtonStyle);
				val.margin = new RectOffset(3, 3, 3, 1);
				if (GUILayout.Button(buttonLabels[locationGuid.Key], val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
				{
					currentSelectedDeliveryLocation = locationGuid.Key;
					currentSelectedGUID = locationGuid.Value;
					showUI = false;
					selectedDeliveryLocation = true;
					useRandomDeliveryLocation = false;
				}
			}
			else if (GUILayout.Button(buttonLabels[locationGuid.Key], squareButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
			{
				currentSelectedDeliveryLocation = locationGuid.Key;
				currentSelectedGUID = locationGuid.Value;
				showUI = false;
				selectedDeliveryLocation = true;
				useRandomDeliveryLocation = false;
			}
			num2++;
		}
		GUILayout.EndScrollView();
	}

	private void UpdateWindowRect()
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		if (Screen.width != prevScreenWidth || Screen.height != prevScreenHeight)
		{
			prevScreenWidth = Screen.width;
			prevScreenHeight = Screen.height;
			windowUIRect = new Rect((float)Screen.width * 0.5f - 122.5f, (float)Screen.height * 0.5f - 167.5f, 245f, 335f);
		}
	}

	public override void OnGUI()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		if (squareWindowStyle == null)
		{
			InitializeStyles();
		}
		if (showUI)
		{
			UpdateWindowRect();
			GUILayout.BeginArea(windowUIRect, squareWindowStyle);
			GUILayout.Label("Choose where to meet the customer:", squareWindowStyle, Array.Empty<GUILayoutOption>());
			DrawUI();
			GUILayout.EndArea();
		}
		if ((Object)(object)pendingCustomer != (Object)null && selectedDeliveryLocation)
		{
			HandleDeferredContractAcceptance();
		}
	}

	private void InitializeStyles()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: 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)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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_00d7: Expected O, but got Unknown
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Expected O, but got Unknown
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Expected O, but got Unknown
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Expected O, but got Unknown
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Expected O, but got Unknown
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Expected O, but got Unknown
		//IL_018b: 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_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Expected O, but got Unknown
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Expected O, but got Unknown
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Expected O, but got Unknown
		//IL_01fe: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Expected O, but got Unknown
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Expected O, but got Unknown
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Expected O, but got Unknown
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Expected O, but got Unknown
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Expected O, but got Unknown
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Expected O, but got Unknown
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Expected O, but got Unknown
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Expected O, but got Unknown
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Expected O, but got Unknown
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Expected O, but got Unknown
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Expected O, but got Unknown
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Expected O, but got Unknown
		Texture2D whiteTexture = Texture2D.whiteTexture;
		scrollUIPosition = Vector2.zero;
		prevScreenWidth = Screen.width;
		prevScreenHeight = Screen.height;
		windowUIRect = new Rect((float)Screen.width * 0.5f - 122.5f, (float)Screen.height * 0.5f - 167.5f, 245f, 335f);
		squareWindowStyle = new GUIStyle
		{
			padding = new RectOffset(10, 10, 15, 10),
			normal = new GUIStyleState
			{
				background = whiteTexture,
				textColor = new Color(0.1f, 0.1f, 0.1f)
			},
			onNormal = new GUIStyleState
			{
				background = whiteTexture,
				textColor = new Color(0.1f, 0.1f, 0.1f)
			},
			fontSize = 12,
			fontStyle = (FontStyle)1
		};
		squareButtonStyle = new GUIStyle
		{
			normal = new GUIStyleState
			{
				background = buttonColorTex,
				textColor = Color.white
			},
			hover = new GUIStyleState
			{
				background = buttonHoverColorTex,
				textColor = Color.white
			},
			active = new GUIStyleState
			{
				background = buttonHoverColorTex,
				textColor = Color.white
			},
			alignment = (TextAnchor)4,
			padding = new RectOffset(8, 8, 6, 6),
			margin = new RectOffset(3, 3, 3, 3),
			wordWrap = true,
			fontSize = 12,
			fontStyle = (FontStyle)1
		};
		squareLabelStyle = new GUIStyle
		{
			normal = new GUIStyleState
			{
				textColor = new Color(0.2f, 0.2f, 0.2f)
			},
			wordWrap = true,
			fontSize = 12,
			padding = new RectOffset(10, 10, 3, 3)
		};
		squareVerticalScrollStyle = new GUIStyle(GUI.skin.verticalScrollbar)
		{
			normal = new GUIStyleState
			{
				background = whiteTexture
			},
			border = new RectOffset(1, 1, 1, 1),
			fixedWidth = 10f
		};
		squareVerticalScrollThumbStyle = new GUIStyle(GUI.skin.verticalScrollbarThumb)
		{
			normal = new GUIStyleState
			{
				background = scrollBarTex
			},
			onNormal = new GUIStyleState
			{
				background = scrollBarTex
			},
			onFocused = new GUIStyleState
			{
				background = scrollBarTex
			},
			onActive = new GUIStyleState
			{
				background = scrollBarTex
			},
			onHover = new GUIStyleState
			{
				background = scrollBarTex
			},
			hover = new GUIStyleState
			{
				background = scrollBarTex
			},
			focused = new GUIStyleState
			{
				background = scrollBarTex
			},
			active = new GUIStyleState
			{
				background = scrollBarTex
			},
			fixedWidth = 10f
		};
		GUI.skin.verticalScrollbarThumb = squareVerticalScrollThumbStyle;
	}

	public static void MakeDeliveryLocationsDict()
	{
		GameObject val = null;
		try
		{
			val = GameObject.Find("Delivery Locations");
			Print("Got deliveryLocations");
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("Could not get deliveryLocations: " + ex);
			return;
		}
		for (int i = 0; i < val.transform.childCount; i++)
		{
			Transform child = val.transform.GetChild(i);
			DeliveryLocation component = ((Component)child).GetComponent<DeliveryLocation>();
			if ((Object)(object)component != (Object)null)
			{
				string locationName = component.LocationName;
				string value = component.GUID.ToString();
				if (!LocationGuids.ContainsKey(locationName))
				{
					LocationGuids.Add(locationName, value);
				}
				else
				{
					MelonLogger.Warning("Duplicate location \"" + locationName + "\" skipped building DeliveryLocation dict.");
				}
			}
		}
	}

	private void HandleDeferredContractAcceptance()
	{
		if (!((Object)(object)pendingCustomer != (Object)null) || !selectedDeliveryLocation)
		{
			return;
		}
		GameObject obj = GameObject.Find("Messages");
		object obj2;
		if (obj == null)
		{
			obj2 = null;
		}
		else
		{
			Transform obj3 = obj.transform.Find("Container");
			if (obj3 == null)
			{
				obj2 = null;
			}
			else
			{
				Transform obj4 = ((Component)obj3).transform.Find("DealWindowSelector");
				obj2 = ((obj4 != null) ? ((Component)obj4).transform : null);
			}
		}
		Transform val = (Transform)obj2;
		object obj5;
		if (val == null)
		{
			obj5 = null;
		}
		else
		{
			Transform obj6 = ((Component)val).transform.Find("Shade");
			obj5 = ((obj6 != null) ? ((Component)obj6).transform : null);
		}
		Transform val2 = (Transform)obj5;
		object obj7;
		if (val2 == null)
		{
			obj7 = null;
		}
		else
		{
			Transform obj8 = val2.Find("Content");
			obj7 = ((obj8 != null) ? ((Component)obj8).transform : null);
		}
		Transform val3 = (Transform)obj7;
		if ((Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null)
		{
			((Component)val2).gameObject.SetActive(true);
			((Component)val3).gameObject.SetActive(true);
		}
		else
		{
			MelonLogger.Warning("Could not find Shade/Content GameObjects to enable.");
		}
		MethodInfo methodInfo = AccessTools.Method(typeof(Customer), "PlayerAcceptedContract", (Type[])null, (Type[])null);
		if (methodInfo != null)
		{
			Action<EDealWindow> action = (Action<EDealWindow>)Delegate.CreateDelegate(typeof(Action<EDealWindow>), pendingCustomer, methodInfo);
			PlayerSingleton<MessagesApp>.Instance.DealWindowSelector.SetIsOpen(true, pendingCustomer.NPC.MSGConversation, action);
		}
		else
		{
			MelonLogger.Warning("Could not find PlayerAcceptedContract method!");
		}
		pendingCustomer = null;
		selectedDeliveryLocation = false;
	}
}