Decompiled source of EnhancedCartel v1.1.0

EnhancedCartel-IL2CPP.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using EnhancedCartel;
using EnhancedCartel.Helpers;
using HarmonyLib;
using Il2CppFishNet;
using Il2CppFishNet.Connection;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Cartel;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Levelling;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Product;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
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(global::EnhancedCartel.EnhancedCartel), "EnhancedCartel", "1.1.0", "k073l", null)]
[assembly: MelonColor(1, 255, 0, 0)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("EnhancedCartel-IL2CPP")]
[assembly: AssemblyConfiguration("Release IL2CPP")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1a85c59247a4f1b6e27acca5a7a89da2b2d9fb7f")]
[assembly: AssemblyProduct("EnhancedCartel-IL2CPP")]
[assembly: AssemblyTitle("EnhancedCartel-IL2CPP")]
[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.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;
		}
	}
	[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 EnhancedCartel
{
	public static class BuildInfo
	{
		public const string Name = "EnhancedCartel";

		public const string Description = "Allows cartel to request other products than default";

		public const string Author = "k073l";

		public const string Version = "1.1.0";
	}
	public class EnhancedCartel : MelonMod
	{
		private static Instance Logger;

		public static MelonPreferences_Category Category;

		public static MelonPreferences_Entry<int> ProductQuantityMin;

		public static MelonPreferences_Entry<int> ProductQuantityMax;

		public static MelonPreferences_Entry<bool> UseListedProducts;

		public static MelonPreferences_Entry<bool> UseDiscoveredProducts;

		public static MelonPreferences_Entry<int> RoundingMultiple;

		public static int CeilToNearest(int value, int multiple)
		{
			return (value + multiple - 1) / multiple * multiple;
		}

		public override void OnInitializeMelon()
		{
			Logger = ((MelonBase)this).LoggerInstance;
			Logger.Msg("EnhancedCartel initialized");
			Category = MelonPreferences.CreateCategory("EnhancedCartel", "Enhanced Cartel Settings");
			ProductQuantityMin = Category.CreateEntry<int>("ProductQuantityMin", 10, (string)null, "Minimum quantity of products in cartel requests", false, false, (ValueValidator)null, (string)null);
			ProductQuantityMax = Category.CreateEntry<int>("ProductQuantityMax", 40, (string)null, "Maximum quantity of products in cartel requests", false, false, (ValueValidator)null, (string)null);
			UseListedProducts = Category.CreateEntry<bool>("UseListedProducts", true, (string)null, "Use products that are listed for sale in cartel requests", false, false, (ValueValidator)null, (string)null);
			UseDiscoveredProducts = Category.CreateEntry<bool>("UseDiscoveredProducts", false, (string)null, "Use products that have been discovered in cartel requests. Overrides UseListedProducts if true", false, false, (ValueValidator)null, (string)null);
			RoundingMultiple = Category.CreateEntry<int>("RoundingMultiple", 1, (string)null, "Round requested product quantities to nearest multiple of this value (1 = no rounding) [1-20]", false, false, (ValueValidator)(object)new ValueRange<int>(1, 20), (string)null);
		}
	}
	[HarmonyPatch(typeof(CartelDealManager), "StartDeal")]
	internal class CartelDealManager_StartDeal_Patch
	{
		public static bool Prefix(CartelDealManager __instance)
		{
			//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)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			if (InstanceFinder.IsServer)
			{
				__instance.ProductQuantityMin = EnhancedCartel.ProductQuantityMin.Value;
				__instance.ProductQuantityMax = EnhancedCartel.ProductQuantityMax.Value;
				if (!EnhancedCartel.UseDiscoveredProducts.Value && !EnhancedCartel.UseListedProducts.Value)
				{
					return true;
				}
				FullRank val = default(FullRank);
				((FullRank)(ref val))..ctor((ERank)10, 0);
				FullRank fullRank = NetworkSingleton<LevelManager>.Instance.GetFullRank();
				float num = Mathf.Clamp01(((FullRank)(ref fullRank)).ToFloat() / ((FullRank)(ref val)).ToFloat());
				IEnumerable<ProductDefinition> first = ((EnhancedCartel.UseListedProducts.Value && !EnhancedCartel.UseDiscoveredProducts.Value) ? ProductManager.ListedProducts.AsEnumerable<ProductDefinition>() : Enumerable.Empty<ProductDefinition>());
				IEnumerable<ProductDefinition> second = (EnhancedCartel.UseDiscoveredProducts.Value ? ProductManager.DiscoveredProducts.AsEnumerable<ProductDefinition>() : Enumerable.Empty<ProductDefinition>());
				List<ProductDefinition> list = first.Union(second).ToList();
				ProductDefinition val2 = list[Random.Range(0, list.Count)];
				int num2 = EnhancedCartel.CeilToNearest(Mathf.RoundToInt(Mathf.Lerp((float)__instance.ProductQuantityMin, (float)__instance.ProductQuantityMax, num)), EnhancedCartel.RoundingMultiple.Value);
				GameDateTime dateTime = NetworkSingleton<TimeManager>.Instance.GetDateTime();
				dateTime.elapsedDays += 3;
				dateTime.time = 401;
				int num3 = Mathf.RoundToInt(val2.MarketValue * (float)num2 * 0.65f);
				CartelDealInfo val3 = new CartelDealInfo(((ItemDefinition)val2).ID, num2, num3, dateTime, (EStatus)0);
				__instance.InitializeDealQuest((NetworkConnection)null, val3);
				__instance.SendRequestMessage(val3);
				__instance.ActiveDeal = val3;
				return false;
			}
			return true;
		}
	}
}
namespace EnhancedCartel.Helpers
{
	public static class MelonLoggerExtensions
	{
		public static void Debug(this Instance logger, string message, bool stacktrace = true)
		{
		}

		private static string GetLoggerName(Instance logger)
		{
			return typeof(Instance).GetField("Name", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(logger) as string;
		}

		private static void InvokeNativeMsg(Color namesectionColor, Color textColor, string nameSection, string message)
		{
			typeof(MelonLogger).GetMethod("NativeMsg", BindingFlags.Static | BindingFlags.NonPublic)?.Invoke(null, new object[5]
			{
				namesectionColor,
				textColor,
				nameSection,
				message ?? "null",
				false
			});
		}

		private static string GetCallerInfo()
		{
			StackTrace stackTrace = new StackTrace();
			for (int i = 2; i < stackTrace.FrameCount; i++)
			{
				StackFrame frame = stackTrace.GetFrame(i);
				MethodBase method = frame.GetMethod();
				if (!(method?.DeclaringType == null))
				{
					return method.DeclaringType.FullName + "." + method.Name;
				}
			}
			return "unknown";
		}
	}
	public static class Il2CppListExtensions
	{
		public static IEnumerable<T> AsEnumerable<T>(this List<T> list)
		{
			return list ?? new List<T>();
		}

		public static List<T> ToIl2CppList<T>(this IEnumerable<T> source)
		{
			List<T> val = new List<T>();
			foreach (T item in source)
			{
				val.Add(item);
			}
			return val;
		}

		public static List<T> ConvertToList<T>(List<T> il2CppList)
		{
			List<T> list = new List<T>();
			T[] collection = Il2CppArrayBase<T>.op_Implicit(il2CppList.ToArray());
			list.AddRange(collection);
			return list;
		}

		public static IEnumerable<T> AsEnumerable<T>(this List<T> list)
		{
			IEnumerable<T> result;
			if (list != null)
			{
				result = ((IEnumerable<T>)list._items).Take(list._size);
			}
			else
			{
				IEnumerable<T> enumerable = Array.Empty<T>();
				result = enumerable;
			}
			return result;
		}
	}
	public static class Utils
	{
		[CompilerGenerated]
		private sealed class <WaitForNetwork>d__6 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public IEnumerator routine;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForNetwork>d__6(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (!InstanceFinder.IsServer && !InstanceFinder.IsClient)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				MelonCoroutines.Start(routine);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForNetworkSingleton>d__8<T> : IEnumerator<object>, IEnumerator, IDisposable where T : notnull, NetworkSingleton<T>
		{
			private int <>1__state;

			private object <>2__current;

			public IEnumerator coroutine;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForNetworkSingleton>d__8(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					goto IL_0044;
				case 1:
					<>1__state = -1;
					goto IL_0044;
				case 2:
					{
						<>1__state = -1;
						return false;
					}
					IL_0044:
					if (!NetworkSingleton<T>.InstanceExists)
					{
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					<>2__current = coroutine;
					<>1__state = 2;
					return true;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForNotNull>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public object obj;

			public float timeout;

			public Action onTimeout;

			public Action onFinish;

			private float <startTime>5__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForNotNull>d__7(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<startTime>5__1 = Time.time;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (obj == null)
				{
					if (!float.IsNaN(timeout) && Time.time - <startTime>5__1 > timeout)
					{
						onTimeout?.Invoke();
						return false;
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				onFinish?.Invoke();
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForPlayer>d__5 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public IEnumerator routine;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForPlayer>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((Object)(object)Player.Local == (Object)null || (Object)(object)((Component)Player.Local).gameObject == (Object)null)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				MelonCoroutines.Start(routine);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static readonly Instance Logger = new Instance("EnhancedCartel-Utils");

		public static T FindObjectByName<T>(string objectName) where T : Object
		{
			try
			{
				foreach (T item in Resources.FindObjectsOfTypeAll<T>())
				{
					if (((Object)item).name != objectName)
					{
						continue;
					}
					Logger.Debug($"Found {typeof(T).Name} '{objectName}' directly in loaded objects");
					return item;
				}
				return default(T);
			}
			catch (Exception ex)
			{
				Logger.Error($"Error finding {typeof(T).Name} '{objectName}': {ex.Message}");
				return default(T);
			}
		}

		public static List<T> GetAllComponentsInChildrenRecursive<T>(GameObject obj) where T : Component
		{
			List<T> list = new List<T>();
			if ((Object)(object)obj == (Object)null)
			{
				return list;
			}
			T[] array = Il2CppArrayBase<T>.op_Implicit(obj.GetComponents<T>());
			if (array.Length != 0)
			{
				list.AddRange(array);
			}
			for (int i = 0; i < obj.transform.childCount; i++)
			{
				Transform child = obj.transform.GetChild(i);
				list.AddRange(GetAllComponentsInChildrenRecursive<T>(((Component)child).gameObject));
			}
			return list;
		}

		public static bool Is<T>(object obj, out T result) where T : Object
		{
			Object val = (Object)((obj is Object) ? obj : null);
			if (val != null)
			{
				Type val2 = Il2CppType.Of<T>();
				Type il2CppType = val.GetIl2CppType();
				if (val2.IsAssignableFrom(il2CppType))
				{
					result = ((Il2CppObjectBase)val).TryCast<T>();
					return result != null;
				}
			}
			result = default(T);
			return false;
		}

		public static List<StorableItemDefinition> GetAllStorableItemDefinitions()
		{
			List<ItemRegister> list = Il2CppListExtensions.ConvertToList<ItemRegister>(Singleton<Registry>.Instance.ItemRegistry);
			List<StorableItemDefinition> list2 = new List<StorableItemDefinition>();
			foreach (ItemRegister item in list)
			{
				if (Utils.Is<StorableItemDefinition>((object)item.Definition, out StorableItemDefinition result))
				{
					list2.Add(result);
				}
				else
				{
					Logger.Warning("Definition " + ((object)item.Definition)?.GetType().FullName + " is not a StorableItemDefinition");
				}
			}
			return list2.ToList();
		}

		[IteratorStateMachine(typeof(<WaitForPlayer>d__5))]
		public static IEnumerator WaitForPlayer(IEnumerator routine)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForPlayer>d__5(0)
			{
				routine = routine
			};
		}

		[IteratorStateMachine(typeof(<WaitForNetwork>d__6))]
		public static IEnumerator WaitForNetwork(IEnumerator routine)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForNetwork>d__6(0)
			{
				routine = routine
			};
		}

		[IteratorStateMachine(typeof(<WaitForNotNull>d__7))]
		public static IEnumerator WaitForNotNull(object? obj, float timeout = float.NaN, Action onTimeout = null, Action onFinish = null)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForNotNull>d__7(0)
			{
				obj = obj,
				timeout = timeout,
				onTimeout = onTimeout,
				onFinish = onFinish
			};
		}

		[IteratorStateMachine(typeof(<WaitForNetworkSingleton>d__8<>))]
		public static IEnumerator WaitForNetworkSingleton<T>(IEnumerator coroutine) where T : NetworkSingleton<T>
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForNetworkSingleton>d__8<T>(0)
			{
				coroutine = coroutine
			};
		}
	}
}

EnhancedCartel-Mono.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using EnhancedCartel;
using EnhancedCartel.Helpers;
using FishNet;
using FishNet.Connection;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using ScheduleOne;
using ScheduleOne.Cartel;
using ScheduleOne.DevUtilities;
using ScheduleOne.GameTime;
using ScheduleOne.ItemFramework;
using ScheduleOne.Levelling;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Product;
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(global::EnhancedCartel.EnhancedCartel), "EnhancedCartel", "1.1.0", "k073l", null)]
[assembly: MelonColor(1, 255, 0, 0)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EnhancedCartel-Mono")]
[assembly: AssemblyConfiguration("Release Mono")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1a85c59247a4f1b6e27acca5a7a89da2b2d9fb7f")]
[assembly: AssemblyProduct("EnhancedCartel-Mono")]
[assembly: AssemblyTitle("EnhancedCartel-Mono")]
[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.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;
		}
	}
	[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 EnhancedCartel
{
	public static class BuildInfo
	{
		public const string Name = "EnhancedCartel";

		public const string Description = "Allows cartel to request other products than default";

		public const string Author = "k073l";

		public const string Version = "1.1.0";
	}
	public class EnhancedCartel : MelonMod
	{
		private static Instance Logger;

		public static MelonPreferences_Category Category;

		public static MelonPreferences_Entry<int> ProductQuantityMin;

		public static MelonPreferences_Entry<int> ProductQuantityMax;

		public static MelonPreferences_Entry<bool> UseListedProducts;

		public static MelonPreferences_Entry<bool> UseDiscoveredProducts;

		public static MelonPreferences_Entry<int> RoundingMultiple;

		public static int CeilToNearest(int value, int multiple)
		{
			return (value + multiple - 1) / multiple * multiple;
		}

		public override void OnInitializeMelon()
		{
			Logger = ((MelonBase)this).LoggerInstance;
			Logger.Msg("EnhancedCartel initialized");
			Category = MelonPreferences.CreateCategory("EnhancedCartel", "Enhanced Cartel Settings");
			ProductQuantityMin = Category.CreateEntry<int>("ProductQuantityMin", 10, (string)null, "Minimum quantity of products in cartel requests", false, false, (ValueValidator)null, (string)null);
			ProductQuantityMax = Category.CreateEntry<int>("ProductQuantityMax", 40, (string)null, "Maximum quantity of products in cartel requests", false, false, (ValueValidator)null, (string)null);
			UseListedProducts = Category.CreateEntry<bool>("UseListedProducts", true, (string)null, "Use products that are listed for sale in cartel requests", false, false, (ValueValidator)null, (string)null);
			UseDiscoveredProducts = Category.CreateEntry<bool>("UseDiscoveredProducts", false, (string)null, "Use products that have been discovered in cartel requests. Overrides UseListedProducts if true", false, false, (ValueValidator)null, (string)null);
			RoundingMultiple = Category.CreateEntry<int>("RoundingMultiple", 1, (string)null, "Round requested product quantities to nearest multiple of this value (1 = no rounding) [1-20]", false, false, (ValueValidator)(object)new ValueRange<int>(1, 20), (string)null);
		}
	}
	[HarmonyPatch(typeof(CartelDealManager), "StartDeal")]
	internal class CartelDealManager_StartDeal_Patch
	{
		public static bool Prefix(CartelDealManager __instance)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Expected O, but got Unknown
			if (InstanceFinder.IsServer)
			{
				__instance.ProductQuantityMin = EnhancedCartel.ProductQuantityMin.Value;
				__instance.ProductQuantityMax = EnhancedCartel.ProductQuantityMax.Value;
				if (!EnhancedCartel.UseDiscoveredProducts.Value && !EnhancedCartel.UseListedProducts.Value)
				{
					return true;
				}
				FullRank val = default(FullRank);
				((FullRank)(ref val))..ctor((ERank)10, 0);
				FullRank fullRank = NetworkSingleton<LevelManager>.Instance.GetFullRank();
				float num = Mathf.Clamp01(((FullRank)(ref fullRank)).ToFloat() / ((FullRank)(ref val)).ToFloat());
				IEnumerable<ProductDefinition> first = ((EnhancedCartel.UseListedProducts.Value && !EnhancedCartel.UseDiscoveredProducts.Value) ? ProductManager.ListedProducts.AsEnumerable() : Enumerable.Empty<ProductDefinition>());
				IEnumerable<ProductDefinition> second = (EnhancedCartel.UseDiscoveredProducts.Value ? ProductManager.DiscoveredProducts.AsEnumerable() : Enumerable.Empty<ProductDefinition>());
				List<ProductDefinition> list = first.Union(second).ToList();
				ProductDefinition val2 = list[Random.Range(0, list.Count)];
				int num2 = EnhancedCartel.CeilToNearest(Mathf.RoundToInt(Mathf.Lerp((float)__instance.ProductQuantityMin, (float)__instance.ProductQuantityMax, num)), EnhancedCartel.RoundingMultiple.Value);
				GameDateTime dateTime = NetworkSingleton<TimeManager>.Instance.GetDateTime();
				dateTime.elapsedDays += 3;
				dateTime.time = 401;
				int num3 = Mathf.RoundToInt(val2.MarketValue * (float)num2 * 0.65f);
				CartelDealInfo val3 = new CartelDealInfo(((ItemDefinition)val2).ID, num2, num3, dateTime, (EStatus)0);
				__instance.InitializeDealQuest((NetworkConnection)null, val3);
				__instance.SendRequestMessage(val3);
				__instance.ActiveDeal = val3;
				return false;
			}
			return true;
		}
	}
}
namespace EnhancedCartel.Helpers
{
	public static class MelonLoggerExtensions
	{
		public static void Debug(this Instance logger, string message, bool stacktrace = true)
		{
		}

		private static string GetLoggerName(Instance logger)
		{
			return typeof(Instance).GetField("Name", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(logger) as string;
		}

		private static void InvokeNativeMsg(Color namesectionColor, Color textColor, string nameSection, string message)
		{
			typeof(MelonLogger).GetMethod("NativeMsg", BindingFlags.Static | BindingFlags.NonPublic)?.Invoke(null, new object[5]
			{
				namesectionColor,
				textColor,
				nameSection,
				message ?? "null",
				false
			});
		}

		private static string GetCallerInfo()
		{
			StackTrace stackTrace = new StackTrace();
			for (int i = 2; i < stackTrace.FrameCount; i++)
			{
				StackFrame frame = stackTrace.GetFrame(i);
				MethodBase method = frame.GetMethod();
				if (!(method?.DeclaringType == null))
				{
					return method.DeclaringType.FullName + "." + method.Name;
				}
			}
			return "unknown";
		}
	}
	public static class Il2CppListExtensions
	{
		public static IEnumerable<T> AsEnumerable<T>(this List<T> list)
		{
			return list ?? new List<T>();
		}
	}
	public static class Utils
	{
		[CompilerGenerated]
		private sealed class <WaitForNetwork>d__6 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public IEnumerator routine;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForNetwork>d__6(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (!InstanceFinder.IsServer && !InstanceFinder.IsClient)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				MelonCoroutines.Start(routine);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForNetworkSingleton>d__8<T> : IEnumerator<object>, IEnumerator, IDisposable where T : notnull, NetworkSingleton<T>
		{
			private int <>1__state;

			private object <>2__current;

			public IEnumerator coroutine;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForNetworkSingleton>d__8(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					goto IL_0044;
				case 1:
					<>1__state = -1;
					goto IL_0044;
				case 2:
					{
						<>1__state = -1;
						return false;
					}
					IL_0044:
					if (!NetworkSingleton<T>.InstanceExists)
					{
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					<>2__current = coroutine;
					<>1__state = 2;
					return true;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForNotNull>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public object obj;

			public float timeout;

			public Action onTimeout;

			public Action onFinish;

			private float <startTime>5__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForNotNull>d__7(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<startTime>5__1 = Time.time;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (obj == null)
				{
					if (!float.IsNaN(timeout) && Time.time - <startTime>5__1 > timeout)
					{
						onTimeout?.Invoke();
						return false;
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				onFinish?.Invoke();
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForPlayer>d__5 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public IEnumerator routine;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForPlayer>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((Object)(object)Player.Local == (Object)null || (Object)(object)((Component)Player.Local).gameObject == (Object)null)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				MelonCoroutines.Start(routine);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static readonly Instance Logger = new Instance("EnhancedCartel-Utils");

		public static T FindObjectByName<T>(string objectName) where T : Object
		{
			try
			{
				T[] array = Resources.FindObjectsOfTypeAll<T>();
				foreach (T val in array)
				{
					if (!(((Object)val).name != objectName))
					{
						Logger.Debug("Found " + typeof(T).Name + " '" + objectName + "' directly in loaded objects");
						return val;
					}
				}
				return default(T);
			}
			catch (Exception ex)
			{
				Logger.Error("Error finding " + typeof(T).Name + " '" + objectName + "': " + ex.Message);
				return default(T);
			}
		}

		public static List<T> GetAllComponentsInChildrenRecursive<T>(GameObject obj) where T : Component
		{
			List<T> list = new List<T>();
			if ((Object)(object)obj == (Object)null)
			{
				return list;
			}
			T[] components = obj.GetComponents<T>();
			if (components.Length != 0)
			{
				list.AddRange(components);
			}
			for (int i = 0; i < obj.transform.childCount; i++)
			{
				Transform child = obj.transform.GetChild(i);
				list.AddRange(GetAllComponentsInChildrenRecursive<T>(((Component)child).gameObject));
			}
			return list;
		}

		public static bool Is<T>(object obj, out T result) where T : class
		{
			if (obj is T val)
			{
				result = val;
				return true;
			}
			result = null;
			return false;
		}

		public static List<StorableItemDefinition> GetAllStorableItemDefinitions()
		{
			List<ItemRegister> list = Singleton<Registry>.Instance.ItemRegistry.ToList();
			List<StorableItemDefinition> list2 = new List<StorableItemDefinition>();
			foreach (ItemRegister item in list)
			{
				if (Is<StorableItemDefinition>(item.Definition, out var result))
				{
					list2.Add(result);
				}
				else
				{
					Logger.Warning("Definition " + ((object)item.Definition)?.GetType().FullName + " is not a StorableItemDefinition");
				}
			}
			return list2.ToList();
		}

		[IteratorStateMachine(typeof(<WaitForPlayer>d__5))]
		public static IEnumerator WaitForPlayer(IEnumerator routine)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForPlayer>d__5(0)
			{
				routine = routine
			};
		}

		[IteratorStateMachine(typeof(<WaitForNetwork>d__6))]
		public static IEnumerator WaitForNetwork(IEnumerator routine)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForNetwork>d__6(0)
			{
				routine = routine
			};
		}

		[IteratorStateMachine(typeof(<WaitForNotNull>d__7))]
		public static IEnumerator WaitForNotNull(object? obj, float timeout = float.NaN, Action onTimeout = null, Action onFinish = null)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForNotNull>d__7(0)
			{
				obj = obj,
				timeout = timeout,
				onTimeout = onTimeout,
				onFinish = onFinish
			};
		}

		[IteratorStateMachine(typeof(<WaitForNetworkSingleton>d__8<>))]
		public static IEnumerator WaitForNetworkSingleton<T>(IEnumerator coroutine) where T : NetworkSingleton<T>
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForNetworkSingleton>d__8<T>(0)
			{
				coroutine = coroutine
			};
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}