Decompiled source of Easier Customer samples v1.0.1

EasierCustomerSamples.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using EasierCustomerSamples;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Product;
using Il2CppScheduleOne.Properties;
using Il2CppScheduleOne.UI.Handover;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using ModManagerPhoneApp;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(EntryPoint), "EasierCustomerSamples", "1.0.0", "_peron", null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("EasierCustomerSamples")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EasierCustomerSamples")]
[assembly: AssemblyTitle("EasierCustomerSamples")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace EasierCustomerSamples
{
	public class EntryPoint : MelonMod
	{
		[HarmonyPatch(typeof(Player))]
		[HarmonyPatch("PlayerLoaded")]
		private class ConfigLoad
		{
			[HarmonyPostfix]
			private static void PostfixPlayerLoaded(Player __instance)
			{
				ConfigLoads();
			}
		}

		[HarmonyPatch(typeof(HandoverScreen))]
		private class AllowUnpacked
		{
			[HarmonyPatch("GetError")]
			[HarmonyPrefix]
			public static bool GetErrorPrefix(HandoverScreen __instance)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Invalid comparison between Unknown and I4
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Invalid comparison between Unknown and I4
				if (!(bool)((MelonPreferences_Entry)allowUnpacked).BoxedValue)
				{
					return true;
				}
				if (((int)__instance.Mode == 1 || (int)__instance.Mode == 2) && __instance.GetCustomerItemsCount(true) == 0)
				{
					foreach (ItemSlot item in (Il2CppArrayBase<ItemSlot>)(object)__instance.CustomerSlots)
					{
						if (item.ItemInstance == null)
						{
							return true;
						}
						ProductItemInstance val = ((Il2CppObjectBase)item.ItemInstance).TryCast<ProductItemInstance>();
						if (val == null)
						{
							return true;
						}
						if ((Object)(object)val.AppliedPackaging == (Object)null)
						{
							return false;
						}
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Customer))]
		private class Main
		{
			[HarmonyPatch("GetSampleSuccess")]
			[HarmonyPrefix]
			public static bool GetSampleSuccessPrefix(Customer __instance, ref float __result, List<ItemInstance> items, float price)
			{
				try
				{
					if ((bool)((MelonPreferences_Entry)alwaysGuarantee).BoxedValue)
					{
						__result = 1f;
						return false;
					}
					__result = (float)((MelonPreferences_Entry)baseValue).BoxedValue;
					__instance.customerData.GuaranteeFirstSampleSuccess = false;
					ItemInstance val = null;
					try
					{
						Il2CppReferenceArray<ItemSlot> customerSlots = Singleton<HandoverScreen>.Instance.CustomerSlots;
						foreach (ItemSlot item in (Il2CppArrayBase<ItemSlot>)(object)customerSlots)
						{
							if (item.Quantity != 0)
							{
								try
								{
									val = item.ItemInstance;
								}
								catch (Exception)
								{
									return true;
								}
							}
						}
					}
					catch (Exception)
					{
					}
					if (__instance.consumedSample != null)
					{
						val = (ItemInstance)(object)__instance.consumedSample;
					}
					ProductItemInstance val2 = ((Il2CppObjectBase)val).TryCast<ProductItemInstance>();
					ProductDefinition val3 = ((Il2CppObjectBase)((ItemInstance)val2).Definition).TryCast<ProductDefinition>();
					int num = 0;
					int count = __instance.customerData.PreferredProperties.Count;
					int num2 = 0;
					for (int i = 0; i < count; i++)
					{
						Property val4 = __instance.customerData.PreferredProperties[i];
						if (((PropertyItemDefinition)val3).Properties.Contains(val4))
						{
							num2++;
						}
					}
					if (count > 0)
					{
						switch (num2)
						{
						case 1:
							__result += (float)((MelonPreferences_Entry)oneEffect).BoxedValue;
							break;
						case 2:
							__result += (float)((MelonPreferences_Entry)twoEffect).BoxedValue;
							break;
						case 3:
							__result += (float)((MelonPreferences_Entry)threeEffect).BoxedValue;
							break;
						}
						return false;
					}
					return true;
				}
				catch (Exception value)
				{
					Console.WriteLine(value);
					return true;
				}
			}
		}

		public static MelonPreferences_Category category;

		public static MelonPreferences_Entry<bool> alwaysGuarantee;

		public static MelonPreferences_Entry<bool> allowUnpacked;

		public static MelonPreferences_Entry<float> baseValue;

		public static MelonPreferences_Entry<float> oneEffect;

		public static MelonPreferences_Entry<float> twoEffect;

		public static MelonPreferences_Entry<float> threeEffect;

		public override void OnInitializeMelon()
		{
			category = MelonPreferences.CreateCategory("EasierCustomerSamples_Settings", "Easier Customer Samples Settings");
			alwaysGuarantee = category.CreateEntry<bool>("AlwaysGuarantee", false, "Always guarantee sample success", (string)null, false, false, (ValueValidator)null, (string)null);
			allowUnpacked = category.CreateEntry<bool>("AllowUnpacked", false, "Allow unpacked items to be sampled", (string)null, false, false, (ValueValidator)null, (string)null);
			baseValue = category.CreateEntry<float>("BaseValue", 0.7f, "Base sample success chance", (string)null, false, false, (ValueValidator)null, (string)null);
			oneEffect = category.CreateEntry<float>("OneEffect", 0.1f, "Sample success chance for 1 property match", (string)null, false, false, (ValueValidator)null, (string)null);
			twoEffect = category.CreateEntry<float>("TwoEffect", 0.2f, "Sample success chance for 2 property matches", (string)null, false, false, (ValueValidator)null, (string)null);
			threeEffect = category.CreateEntry<float>("ThreeEffect", 0.3f, "Sample success chance for 3 property matches", (string)null, false, false, (ValueValidator)null, (string)null);
			category.SetFilePath("UserData/EasierCustomerSamples.cfg");
			MelonPreferences.Save();
			try
			{
				ModSettingsEvents.OnPreferencesSaved += ConfigLoads;
				((MelonBase)this).LoggerInstance.Msg("Successfully subscribed to Mod Manager save event.");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Could not subscribe to Mod Manager event (Mod Manager may not be installed/compatible): " + ex.Message);
			}
		}

		public static void ConfigLoads()
		{
			category.LoadFromFile(true);
		}
	}
}