Decompiled source of KLINE Il2Cpp v1.0.0

Mods/KLINE_Standard.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2Cpp;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Delivery;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.UI.Phone.Delivery;
using Il2CppSystem;
using Il2CppSystem.Collections;
using Il2CppSystem.Collections.Generic;
using KLINE_Standard;
using MelonLoader;
using Microsoft.CodeAnalysis;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(KLINEMod), "KLINE_Standard", "1.0.0", "Archie", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: HarmonyDontPatchAll]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("KLINE_Standard")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a525f806a9265c0a16d808e2c2606e790d97f2a7")]
[assembly: AssemblyProduct("KLINE_Standard")]
[assembly: AssemblyTitle("KLINE_Standard")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 KLINE_Standard
{
	[HarmonyPatch(typeof(DeliveryApp))]
	public class DeliveryAppPatch
	{
	}
	[HarmonyPatch(typeof(DeliveryShop))]
	public class DeliveryShopPatch
	{
		private static List<List<StringIntPair>> SplitItemsIntoVehicles(List<StringIntPair> items)
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			try
			{
				if (items == null)
				{
					if (KLINEMod.debugLog)
					{
						MelonLogger.Warning("Items list is null in SplitItemsIntoVehicles.");
					}
					return new List<List<StringIntPair>>();
				}
				List<List<StringIntPair>> list = new List<List<StringIntPair>>();
				List<StringIntPair> list2 = new List<StringIntPair>();
				int num = 0;
				foreach (StringIntPair item2 in items)
				{
					ItemDefinition item = Registry.GetItem(item2.String);
					if ((Object)(object)item == (Object)null)
					{
						if (KLINEMod.debugLog)
						{
							MelonLogger.Warning("Item definition not found for ID: " + item2.String + ".");
						}
						continue;
					}
					int num2 = item2.Int;
					int stackLimit = item.StackLimit;
					while (num2 > 0)
					{
						int num3 = Mathf.Min(num2, stackLimit);
						int num4 = Mathf.CeilToInt((float)num3 / (float)stackLimit);
						if (num + num4 > 16)
						{
							list.Add(list2);
							list2 = new List<StringIntPair>();
							num = 0;
						}
						list2.Add(new StringIntPair(item2.String, num3));
						num += num4;
						num2 -= num3;
					}
				}
				if (list2.Count > 0)
				{
					list.Add(list2);
				}
				return list;
			}
			catch (Exception value)
			{
				if (KLINEMod.debugLog)
				{
					MelonLogger.Error($"Error in SplitItemsIntoVehicles: {value}");
				}
				return new List<List<StringIntPair>>();
			}
		}

		private static int CalculateVehicleCount(List<ListingEntry> entries)
		{
			List<StringIntPair> items = entries.Where((ListingEntry le) => le.SelectedQuantity > 0).Select((Func<ListingEntry, StringIntPair>)((ListingEntry le) => new StringIntPair(((ItemDefinition)le.MatchingListing.Item).ID, le.SelectedQuantity))).ToList();
			return math.max(SplitItemsIntoVehicles(items).Count, 1);
		}

		[HarmonyPrefix]
		[HarmonyPatch("WillCartFitInVehicle")]
		public static bool WillCartFitInVehiclePrefix(ref bool __result)
		{
			__result = true;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("GetOrderTotal")]
		public static bool GetOrderTotalPrefix(DeliveryShop __instance, ref float __result)
		{
			float cartCost = __instance.GetCartCost();
			int num = CalculateVehicleCount(KLINEUtilities.ConvertList<ListingEntry>(__instance.listingEntries));
			__result = cartCost + __instance.DeliveryFee * (float)num;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OrderPressed")]
		public static bool OrderPressedPrefix(DeliveryShop __instance)
		{
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			string text = default(string);
			if (!__instance.CanOrder(ref text))
			{
				if (KLINEMod.debugLog)
				{
					MelonLogger.Warning("Cannot order: " + text);
				}
				return false;
			}
			float orderTotal = __instance.GetOrderTotal();
			List<StringIntPair> list = (from le in KLINEUtilities.ConvertList<ListingEntry>(__instance.listingEntries)
				where le.SelectedQuantity > 0
				select le).Select((Func<ListingEntry, StringIntPair>)((ListingEntry le) => new StringIntPair(((ItemDefinition)le.MatchingListing.Item).ID, le.SelectedQuantity))).ToList();
			int num = list.Sum((StringIntPair i) => i.Int);
			int num2 = Mathf.RoundToInt(Mathf.Lerp(60f, 360f, Mathf.Clamp01((float)num / 160f)));
			List<List<StringIntPair>> list2 = SplitItemsIntoVehicles(list);
			foreach (List<StringIntPair> item in list2)
			{
				Guid val = GUIDManager.GenerateUniqueGUID();
				DeliveryInstance val2 = new DeliveryInstance(((object)(Guid)(ref val)).ToString(), __instance.MatchingShopInterfaceName, __instance.destinationProperty.PropertyCode, __instance.loadingDockIndex - 1, Il2CppReferenceArray<StringIntPair>.op_Implicit(item.ToArray()), (EDeliveryStatus)0, num2);
				NetworkSingleton<DeliveryManager>.Instance.SendDelivery(val2);
				if (KLINEMod.debugLog)
				{
					MelonLogger.Msg($"Created delivery {val2.DeliveryID} with {item.Sum((StringIntPair i) => i.Int)} items.");
				}
			}
			NetworkSingleton<MoneyManager>.Instance.CreateOnlineTransaction("Delivery from " + __instance.MatchingShop.ShopName, 0f - orderTotal, 1f, string.Empty);
			PlayerSingleton<DeliveryApp>.Instance.PlayOrderSubmittedAnim();
			__instance.ResetCart();
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("RefreshCart")]
		public static bool RefreshCartPrefix(DeliveryShop __instance)
		{
			__instance.ItemTotalLabel.text = MoneyManager.FormatAmount(__instance.GetCartCost(), false, false);
			__instance.OrderTotalLabel.text = MoneyManager.FormatAmount(__instance.GetOrderTotal(), false, false);
			int num = CalculateVehicleCount(KLINEUtilities.ConvertList<ListingEntry>(__instance.listingEntries));
			float num2 = __instance.DeliveryFee * (float)num;
			__instance.DeliveryFeeLabel.text = MoneyManager.FormatAmount(num2, false, false);
			return false;
		}
	}
	[HarmonyPatch(typeof(DeliveryStatusDisplay))]
	public class DeliveryStatusDisplayPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("AssignDelivery")]
		public static bool AssignDeliveryPrefix(DeliveryInstance instance, DeliveryStatusDisplay __instance)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			if (instance == null || (Object)(object)__instance == (Object)null)
			{
				return false;
			}
			__instance.DeliveryInstance = instance;
			__instance.DestinationLabel.text = $"{instance.Destination.PropertyName} [{instance.LoadingDockIndex + 1}]";
			__instance.ShopLabel.text = instance.StoreName;
			IEnumerator enumerator = ((Transform)__instance.ItemEntryContainer).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Transform val = (Transform)enumerator.Current;
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			finally
			{
				if (enumerator is IDisposable disposable)
				{
					disposable.Dispose();
				}
			}
			StringIntPair[] array = (from item in (IEnumerable<StringIntPair>)instance.Items
				group item by item.String).Select((Func<IGrouping<string, StringIntPair>, StringIntPair>)((IGrouping<string, StringIntPair> group) => new StringIntPair(group.Key, group.Sum((StringIntPair item) => item.Int)))).ToArray();
			StringIntPair[] array2 = array;
			foreach (StringIntPair val2 in array2)
			{
				Transform component = (Transform)(object)Object.Instantiate<GameObject>(__instance.ItemEntryPrefab, (Transform)(object)__instance.ItemEntryContainer).GetComponent<RectTransform>();
				ItemDefinition item2 = Registry.GetItem(val2.String);
				((Component)component.Find("Label")).GetComponent<Text>().text = $"{val2.Int}x {item2.Name}";
			}
			int num = Mathf.CeilToInt((float)array.Length / 2f);
			__instance.Rect.sizeDelta = new Vector2(__instance.Rect.sizeDelta.x, (float)(70 + 20 * num));
			__instance.RefreshStatus();
			if (KLINEMod.debugLog)
			{
				MelonLogger.Msg($"Assigned delivery {instance.DeliveryID} with {array.Length} consolidated items, sizeDelta={__instance.Rect.sizeDelta}");
			}
			return false;
		}
	}
	public class KLINEMod : MelonMod
	{
		public static readonly bool debugLog;

		public override void OnInitializeMelon()
		{
			try
			{
				((MelonBase)this).HarmonyInstance.PatchAll();
				if (debugLog)
				{
					MelonLogger.Msg("KLINE_Standard loaded!");
				}
			}
			catch (Exception value)
			{
				MelonLogger.Error($"Failed to initialize KLINE_Standard: {value}");
			}
		}
	}
	public class KLINEUtilities
	{
		public static List<T> ConvertList<T>(List<T> systemList) where T : Object
		{
			if (systemList == null)
			{
				return new List<T>();
			}
			List<T> val = new List<T>(systemList.Count);
			foreach (T system in systemList)
			{
				if (system != null)
				{
					val.Add(system);
				}
			}
			return val;
		}

		public static List<T> ConvertList<T>(List<T> il2cppList) where T : Object
		{
			if (il2cppList == null)
			{
				return new List<T>();
			}
			List<T> list = new List<T>(il2cppList.Count);
			for (int i = 0; i < il2cppList.Count; i++)
			{
				T val = il2cppList[i];
				if (val != null)
				{
					list.Add(val);
				}
			}
			return list;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}