Decompiled source of UpgradedTrashCans v1.5.4

Mods/UpgradedTrashCans_Il2Cpp.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Levelling;
using Il2CppScheduleOne.Networking;
using Il2CppScheduleOne.ObjectScripts;
using Il2CppScheduleOne.ObjectScripts.WateringCan;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.Trash;
using Il2CppScheduleOne.UI.Items;
using Il2CppScheduleOne.UI.Shop;
using Il2CppSteamworks;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UpgradedTrashCans;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "UpgradedTrashCans", "1.5.4", "j0ckinjz", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyMetadata("NexusModID", "928")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("UpgradedTrashCans_Il2Cpp")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.5.4")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UpgradedTrashCans_Il2Cpp")]
[assembly: AssemblyTitle("UpgradedTrashCans_Il2Cpp")]
[assembly: AssemblyVersion("1.5.4.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;
		}
	}
}
namespace UpgradedTrashCans
{
	public class Core : MelonMod
	{
		public override void OnInitializeMelon()
		{
			ModManager.InitializeSettings();
			Log.Msg("Mod Initialized. Version " + ((MelonBase)this).Info.Version);
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Main")
			{
				VariantSyncManager.SyncSettingsToVariants();
				DefinitionTracker.ClearAll();
				MelonCoroutines.Start(TrashInjector.InitializeShopListings());
			}
		}
	}
	internal static class Log
	{
		public static void Msg(string msg)
		{
			Melon<Core>.Logger.Msg(msg);
		}

		public static void Warn(string msg)
		{
			Melon<Core>.Logger.Warning(msg);
		}

		public static void Error(string msg)
		{
			Melon<Core>.Logger.Error(msg);
		}

		public static void Debug(string message)
		{
			MelonPreferences_Entry<bool> debugLogs = ModManager.DebugLogs;
			if (debugLogs != null && debugLogs.Value)
			{
				Msg(message);
			}
		}
	}
	public static class TrashInjector
	{
		[CompilerGenerated]
		private sealed class <InitializeShopListings>d__0 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

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

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

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

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

			private bool MoveNext()
			{
				//IL_023d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0242: Unknown result type (might be due to invalid IL or missing references)
				//IL_024f: Unknown result type (might be due to invalid IL or missing references)
				//IL_025c: 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_0270: Unknown result type (might be due to invalid IL or missing references)
				//IL_027d: Expected O, but got Unknown
				//IL_0386: Unknown result type (might be due to invalid IL or missing references)
				//IL_038b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0398: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c6: Expected O, but got Unknown
				if (<>1__state != 0)
				{
					return false;
				}
				<>1__state = -1;
				Lobby instance = Singleton<Lobby>.Instance;
				if (instance != null && !instance.IsHost && !VariantSyncManager.HasReceivedHostVariants)
				{
					Log.Msg("[TrashInjector] Skipping injection — host mod is disabled or missing.");
					return false;
				}
				List<ShopInterface> list = new List<ShopInterface>();
				try
				{
					Enumerator<ShopInterface> enumerator = ShopInterface.AllShops.GetEnumerator();
					while (enumerator.MoveNext())
					{
						ShopInterface current = enumerator.Current;
						if (IsValidHardwareStore(current))
						{
							list.Add(current);
						}
					}
				}
				catch (Exception)
				{
					Log.Warn("[TrashInjector] Failed to access ShopInterface.AllShops — using fallback");
					foreach (ShopInterface item in Object.FindObjectsOfType<ShopInterface>())
					{
						if (IsValidHardwareStore(item))
						{
							list.Add(item);
						}
					}
				}
				if (list.Count == 0)
				{
					Log.Warn("[TrashInjector] No hardware store interfaces found.");
					return false;
				}
				ShopInterface val = list[0];
				Il2CppArrayBase<ShopListing> val2 = ((val == null) ? null : val.Listings?.ToArray());
				object source = ((val2 != null) ? ((object)Il2CppArrayBase<ShopListing>.op_Implicit(val2)) : ((object)Array.Empty<ShopListing>()));
				ShopListing val3 = ((IEnumerable<ShopListing>)source).FirstOrDefault((Func<ShopListing, bool>)delegate(ShopListing l)
				{
					try
					{
						return !IsUnityNull((Object)(object)l.Item) && ((Object)l.Item).name == "TrashCan";
					}
					catch
					{
						return false;
					}
				});
				ShopListing val4 = ((IEnumerable<ShopListing>)source).FirstOrDefault((Func<ShopListing, bool>)delegate(ShopListing l)
				{
					try
					{
						return !IsUnityNull((Object)(object)l.Item) && ((Object)l.Item).name == "TrashGrabber";
					}
					catch
					{
						return false;
					}
				});
				if (val3 != null)
				{
					foreach (Variants item2 in TrashCanVariants.All)
					{
						InjectCustomTrashCan(val, val3, item2);
					}
				}
				if (val4 != null)
				{
					foreach (TrashGrabberVariant item3 in TrashGrabberVariants.All)
					{
						InjectCustomTrashGrabber(val, val4, item3);
					}
				}
				foreach (ShopInterface item4 in list)
				{
					foreach (Variants item5 in TrashCanVariants.All)
					{
						if ((Object)(object)item5?.Definition == (Object)null)
						{
							Log.Warn("Skipped injecting trash can variant " + item5?.Name + " due to missing definition.");
							continue;
						}
						try
						{
							ShopListing val5 = new ShopListing
							{
								Item = (StorableItemDefinition)(object)item5.Definition,
								name = item5.Name,
								OverridePrice = true,
								OverriddenPrice = item5.Price,
								CurrentStock = 999
							};
							item4.Listings.Add(val5);
							item4.CreateListingUI(val5);
							Log.Debug($"Injected {item5.Name} with ID {item5.ID} into shop.");
						}
						catch (Exception ex2)
						{
							Log.Error("Failed to inject trash can variant " + item5.Name + ": " + ex2.Message);
						}
					}
					foreach (TrashGrabberVariant item6 in TrashGrabberVariants.All)
					{
						if ((Object)(object)item6?.Definition == (Object)null)
						{
							Log.Warn("Skipped injecting trash grabber variant " + item6?.Name + " due to missing definition.");
							continue;
						}
						try
						{
							ShopListing val6 = new ShopListing
							{
								Item = (StorableItemDefinition)(object)item6.Definition,
								name = item6.Name,
								OverridePrice = true,
								OverriddenPrice = item6.Price,
								CurrentStock = 999
							};
							item4.Listings.Add(val6);
							item4.CreateListingUI(val6);
							Log.Debug($"Injected {item6.Name} with ID {item6.ID} into shop.");
						}
						catch (Exception ex3)
						{
							Log.Error("Failed to inject trash grabber variant " + item6.Name + ": " + ex3.Message);
						}
					}
				}
				Log.Msg("Upgraded items injected successfully into all Hardware Stores!");
				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();
			}
		}

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

		private static bool IsValidHardwareStore(ShopInterface shop)
		{
			if ((Object)(object)shop == (Object)null || shop.Listings == null || shop.Listings.Count == 0)
			{
				return false;
			}
			try
			{
				return ((Object)shop).name == "HardwareStoreInterface" || ((Object)shop).name == "HardwareStoreInterface (North Store)";
			}
			catch
			{
				return false;
			}
		}

		private static bool IsUnityNull(Object obj)
		{
			if (!(obj == (Object)null))
			{
				return ((Object)obj).Equals((Object)null);
			}
			return true;
		}

		private static void InjectCustomTrashCan(ShopInterface shop, ShopListing baseListing, Variants variant)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			BuildableItemDefinition val = ((Il2CppObjectBase)baseListing.Item).TryCast<BuildableItemDefinition>();
			if ((Object)(object)val == (Object)null || (Object)(object)val.BuiltItem == (Object)null)
			{
				Log.Debug("Invalid base listing for trash can injection.");
				return;
			}
			BuildableItemDefinition val2 = Object.Instantiate<BuildableItemDefinition>(val);
			((ItemDefinition)val2).Name = variant.Name;
			((ItemDefinition)val2).ID = variant.ID;
			((ItemDefinition)val2).Description = variant.Description;
			((StorableItemDefinition)val2).BasePurchasePrice = variant.Price;
			((Object)val2).name = variant.Name.Replace(" ", "");
			((StorableItemDefinition)val2).RequiresLevelToPurchase = !variant.UnlockImmediately;
			if (!variant.UnlockImmediately)
			{
				((StorableItemDefinition)val2).RequiredRank = new FullRank(variant.RequiredRank, variant.Tier);
			}
			if ((Object)(object)((ItemDefinition)val).Icon != (Object)null)
			{
				((ItemDefinition)val2).Icon = SpriteLoader.TintSprite(((ItemDefinition)val).Icon, variant.Color, variant.Name + "_Icon");
			}
			else
			{
				Log.Warn(((ItemDefinition)val).Name + " has no icon.");
			}
			val2.BuiltItem = val.BuiltItem;
			DefinitionTracker.TrackDefinition((ItemDefinition)(object)val2);
			variant.Definition = val2;
		}

		private static void InjectCustomTrashGrabber(ShopInterface shop, ShopListing baseListing, TrashGrabberVariant variant)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			TrashGrabberDefinition val = ((Il2CppObjectBase)baseListing.Item).TryCast<TrashGrabberDefinition>();
			if ((Object)(object)val == (Object)null || (Object)(object)((ItemDefinition)val).Equippable == (Object)null)
			{
				Log.Debug("Invalid base listing for trash grabber injection.");
				return;
			}
			TrashGrabberDefinition val2 = Object.Instantiate<TrashGrabberDefinition>(val);
			((ItemDefinition)val2).ID = variant.ID;
			((ItemDefinition)val2).Name = variant.Name;
			((Object)val2).name = variant.Name.Replace(" ", "");
			((ItemDefinition)val2).Description = variant.Description;
			((StorableItemDefinition)val2).BasePurchasePrice = variant.Price;
			((StorableItemDefinition)val2).RequiresLevelToPurchase = !variant.UnlockImmediately;
			if (!variant.UnlockImmediately)
			{
				((StorableItemDefinition)val2).RequiredRank = new FullRank(variant.RequiredRank, variant.Tier);
			}
			if ((Object)(object)((ItemDefinition)val).Icon != (Object)null)
			{
				((ItemDefinition)val2).Icon = SpriteLoader.TintSprite(((ItemDefinition)val).Icon, variant.Color, variant.Name + "_Icon");
			}
			else
			{
				Log.Debug(((ItemDefinition)val).Name + " icon not found.");
			}
			((ItemDefinition)val2).Equippable = ((ItemDefinition)val).Equippable;
			DefinitionTracker.TrackDefinition((ItemDefinition)(object)val2);
			variant.Definition = val2;
		}
	}
	public enum TrashCanType
	{
		Bin,
		Compactor
	}
	public class Variants
	{
		public string Name;

		public string ID;

		public float Price;

		public string Description;

		public int Capacity;

		public Color Color;

		public float Radius;

		public ERank RequiredRank;

		public int Tier;

		public BuildableItemDefinition Definition;

		public bool UnlockImmediately;

		public TrashCanType Type;
	}
	public static class TrashCanVariants
	{
		public static List<Variants> All = new List<Variants>
		{
			new Variants
			{
				Name = "Trash Bin",
				ID = "trash_bin",
				Description = "A slightly larger trash bin.",
				Price = 250f,
				Capacity = 40,
				Color = Color.green,
				Radius = 5f,
				RequiredRank = (ERank)1,
				Tier = 1,
				Type = TrashCanType.Bin
			},
			new Variants
			{
				Name = "Trash Compactor",
				ID = "trash_compactor",
				Description = "A high-capacity trash compactor.",
				Price = 1000f,
				Capacity = 100,
				Color = Color.blue,
				Radius = 8f,
				RequiredRank = (ERank)3,
				Tier = 5,
				Type = TrashCanType.Compactor
			}
		};
	}
	public class TrashGrabberVariant
	{
		public string Name;

		public string ID;

		public string Description;

		public float Price;

		public Color Color;

		public ERank RequiredRank;

		public int Tier;

		public bool UnlockImmediately;

		public int Capacity;

		public TrashGrabberDefinition Definition;
	}
	public static class TrashGrabberVariants
	{
		public static List<TrashGrabberVariant> All = new List<TrashGrabberVariant>
		{
			new TrashGrabberVariant
			{
				Name = "Trash Grabber Pro",
				ID = "trash_grabber_pro",
				Description = "An advanced trash grabber with increased capacity.",
				Price = 750f,
				Color = Color.green,
				RequiredRank = (ERank)3,
				Tier = 5,
				UnlockImmediately = false,
				Capacity = 50
			}
		};
	}
	public static class ColorExtensions
	{
		public static Color ToUnityColor(this ColorOption option)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(option switch
			{
				ColorOption.Green => Color.green, 
				ColorOption.Blue => Color.blue, 
				ColorOption.Red => Color.red, 
				ColorOption.Yellow => Color.yellow, 
				ColorOption.Cyan => Color.cyan, 
				ColorOption.Magenta => Color.magenta, 
				ColorOption.Black => Color.black, 
				_ => Color.white, 
			});
		}

		public static Color ToUnityColor(this ExtendedColorOption option)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(option switch
			{
				ExtendedColorOption.Purple => new Color(0.63f, 0.13f, 0.94f), 
				ExtendedColorOption.Orange => new Color(1f, 0.65f, 0f), 
				ExtendedColorOption.Pink => new Color(1f, 0.75f, 0.8f), 
				ExtendedColorOption.Brown => new Color(0.6f, 0.3f, 0.15f), 
				ExtendedColorOption.Lime => new Color(0.2f, 0.8f, 0.2f), 
				ExtendedColorOption.Teal => new Color(0f, 0.5f, 0.5f), 
				ExtendedColorOption.Indigo => new Color(0.29f, 0f, 0.51f), 
				ExtendedColorOption.Violet => new Color(0.93f, 0.51f, 0.93f), 
				_ => Color.white, 
			});
		}

		public static bool TryParseRGB(string input, out Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			color = Color.white;
			if (string.IsNullOrWhiteSpace(input))
			{
				Log.Warn("RGB string is null or empty: \"" + input + "\"");
				return false;
			}
			string[] array = input.Split(',');
			if (array.Length != 3)
			{
				Log.Warn("RGB string does not contain 3 components: \"" + input + "\"");
				return false;
			}
			if (float.TryParse(array[0].TrimEnd('f'), out var result) && float.TryParse(array[1].TrimEnd('f'), out var result2) && float.TryParse(array[2].TrimEnd('f'), out var result3))
			{
				color = new Color(result, result2, result3, 1f);
				return true;
			}
			Log.Warn("Failed to parse float values from RGB string: \"" + input + "\"");
			return false;
		}
	}
	public static class SpriteLoader
	{
		public static Sprite TintSprite(Sprite original, Color tint, string name = null)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = MakeReadableCopy(original.texture);
			Texture2D val2 = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, false);
			Color[] array = Il2CppArrayBase<Color>.op_Implicit((Il2CppArrayBase<Color>)(object)val.GetPixels());
			for (int i = 0; i < array.Length; i++)
			{
				Color val3 = array[i];
				Color val4 = Color.Lerp(val3, Color.black, 0.2f);
				float num = 0.3f * val3.r + 0.59f * val3.g + 0.11f * val3.b;
				Color val5 = Color.Lerp(val4, tint * num, 0.7f);
				array[i] = new Color(val5.r, val5.g, val5.b, val3.a);
			}
			val2.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
			val2.Apply();
			Sprite val6 = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
			if (!string.IsNullOrEmpty(name))
			{
				((Object)val6).name = name;
			}
			return val6;
		}

		private static Texture2D MakeReadableCopy(Texture2D source)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)1);
			Graphics.Blit((Texture)(object)source, temporary);
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(((Texture)source).width, ((Texture)source).height, (TextureFormat)4, false);
			val.ReadPixels(new Rect(0f, 0f, (float)((Texture)temporary).width, (float)((Texture)temporary).height), 0, 0);
			val.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return val;
		}
	}
	internal static class VisualHelper
	{
		public static void TintRenderers(Transform root, Color color, params string[] targetNames)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			foreach (MeshRenderer item in from t in (IEnumerable<Transform>)((Component)root).GetComponentsInChildren<Transform>(true)
				where targetNames.Contains(((Object)t).name)
				select ((Component)t).GetComponent<MeshRenderer>() into r
				where (Object)(object)r != (Object)null
				select r)
			{
				((Renderer)item).material.color = color;
			}
		}
	}
	public static class DefinitionTracker
	{
		private static readonly List<Object> TrackedDefinitions = new List<Object>();

		private static readonly List<GameObject> TrackedGameObjects = new List<GameObject>();

		private static readonly Dictionary<GameObject, BuildableItemDefinition> GameObjectToDefinitionMap = new Dictionary<GameObject, BuildableItemDefinition>();

		public static void TrackDefinition(ItemDefinition def)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			if (!((Object)(object)def == (Object)null))
			{
				Singleton<Registry>.Instance.AddToRegistry(def);
				Singleton<Registry>.Instance.AddToItemDictionary(new ItemRegister
				{
					ID = def.ID,
					Definition = def
				});
				Log.Debug("Tracking definition: " + def.ID);
				TrackedDefinitions.Add((Object)(object)def);
			}
		}

		public static void TrackGameObject(GameObject go)
		{
			if ((Object)(object)go != (Object)null && !TrackedGameObjects.Contains(go))
			{
				TrackedGameObjects.Add(go);
			}
		}

		public static void TrackGameObject(GameObject go, BuildableItemDefinition def)
		{
			if (!((Object)(object)go == (Object)null) && !((Object)(object)def == (Object)null))
			{
				TrackGameObject(go);
				if (!GameObjectToDefinitionMap.ContainsKey(go))
				{
					GameObjectToDefinitionMap.Add(go, def);
				}
			}
		}

		public static bool IsTrackedGameObject(GameObject go, BuildableItemDefinition def)
		{
			if ((Object)(object)go != (Object)null && (Object)(object)def != (Object)null && GameObjectToDefinitionMap.TryGetValue(go, out var value))
			{
				return (Object)(object)value == (Object)(object)def;
			}
			return false;
		}

		public static void ClearAll()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			foreach (Object trackedDefinition in TrackedDefinitions)
			{
				ItemDefinition val = ((Il2CppObjectBase)trackedDefinition).TryCast<ItemDefinition>();
				if ((Object)(object)val != (Object)null)
				{
					Singleton<Registry>.Instance.RemoveFromRegistry(val);
					Singleton<Registry>.Instance.RemoveItemFromDictionary(new ItemRegister
					{
						ID = val.ID,
						Definition = val
					});
				}
			}
			TrackedDefinitions.Clear();
			foreach (GameObject trackedGameObject in TrackedGameObjects)
			{
				if ((Object)(object)trackedGameObject != (Object)null)
				{
					Object.Destroy((Object)(object)trackedGameObject);
				}
			}
			TrackedGameObjects.Clear();
			GameObjectToDefinitionMap.Clear();
			Log.Msg("Cleared all tracked definitions and GameObjects.");
		}
	}
	public enum ColorOption
	{
		Green,
		Blue,
		Red,
		Yellow,
		Cyan,
		Magenta,
		Black,
		White
	}
	public enum ExtendedColorOption
	{
		Purple,
		Orange,
		Pink,
		Brown,
		Lime,
		Teal,
		Indigo,
		Violet
	}
	public enum ColorSource
	{
		Standard,
		Extended,
		CustomRGB
	}
	public enum RankOption
	{
		Street_Rat,
		Hoodlum,
		Peddler,
		Hustler,
		Bagman,
		Enforcer,
		Shot_Caller,
		Block_Boss,
		Underlord,
		Baron,
		Kingpin
	}
	public static class ModManager
	{
		public class ModSettingsGroup
		{
			public MelonPreferences_Category Category;

			public MelonPreferences_Entry<ColorOption> Color;

			public MelonPreferences_Entry<ExtendedColorOption> ExtendedColor;

			public MelonPreferences_Entry<int> Capacity;

			public MelonPreferences_Entry<float> Radius;

			public MelonPreferences_Entry<RankOption> Rank;

			public MelonPreferences_Entry<int> Tier;

			public MelonPreferences_Entry<bool> UnlockImmediately;

			public MelonPreferences_Entry<float> Price;

			public MelonPreferences_Entry<string> CustomRGB;

			public MelonPreferences_Entry<ColorSource> Source;

			public void ApplyTo(Variants variant)
			{
				//IL_0051: 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_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				variant.Price = Price.Value;
				variant.Color = (Color)(Source.Value switch
				{
					ColorSource.CustomRGB => ColorExtensions.TryParseRGB(CustomRGB.Value, out var color) ? color : Color.white, 
					ColorSource.Extended => ExtendedColor.Value.ToUnityColor(), 
					_ => Color.Value.ToUnityColor(), 
				});
				variant.Capacity = Capacity.Value;
				variant.Radius = Radius.Value;
				variant.RequiredRank = (ERank)Rank.Value;
				variant.Tier = Tier.Value;
				variant.UnlockImmediately = UnlockImmediately.Value;
			}
		}

		public static ModSettingsGroup TrashBinSettings;

		public static ModSettingsGroup TrashCompactorSettings;

		public static MelonPreferences_Category DebugCategory;

		public static MelonPreferences_Category GrabberCategory;

		public static MelonPreferences_Entry<ColorSource> Grabber_Source;

		public static MelonPreferences_Entry<ColorOption> Grabber_Color;

		public static MelonPreferences_Entry<ExtendedColorOption> Grabber_ExtendedColor;

		public static MelonPreferences_Entry<int> Grabber_Capacity;

		public static MelonPreferences_Entry<RankOption> Grabber_Rank;

		public static MelonPreferences_Entry<int> Grabber_Tier;

		public static MelonPreferences_Entry<bool> Grabber_UnlockImmediately;

		public static MelonPreferences_Entry<float> Grabber_Price;

		public static MelonPreferences_Entry<string> Grabber_CustomRGB;

		public static MelonPreferences_Entry<bool> DebugLogs;

		public static void InitializeSettings()
		{
			TrashBinSettings = CreateGroup("01_TrashBin", "Upgraded Trash Bin", ColorOption.Green, ExtendedColorOption.Lime, 40, 5f, RankOption.Hoodlum, 1, unlockImmediately: false, 250f);
			TrashCompactorSettings = CreateGroup("02_TrashCompactor", "Upgraded Trash Compactor", ColorOption.Blue, ExtendedColorOption.Indigo, 100, 8f, RankOption.Hustler, 5, unlockImmediately: false, 1000f);
			GrabberCategory = MelonPreferences.CreateCategory("UpgradedTrashCans_03_UpgradedTrashGrabber", "Trash Grabber Pro");
			Grabber_Price = GrabberCategory.CreateEntry<float>("01_Price", 750f, "Price", "Set the shop price for the Trash Grabber Pro.", false, false, (ValueValidator)null, (string)null);
			Grabber_Capacity = GrabberCategory.CreateEntry<int>("02_Capacity", 50, "Capacity", "Set the capacity of the Trash Grabber Pro.", false, false, (ValueValidator)null, (string)null);
			Grabber_Rank = GrabberCategory.CreateEntry<RankOption>("03_Rank", RankOption.Hustler, "Rank Unlock", "Required rank to unlock the Trash Grabber Pro.", false, false, (ValueValidator)null, (string)null);
			Grabber_Tier = GrabberCategory.CreateEntry<int>("04_Tier", 1, "Tier Unlock", "Required tier at the rank to unlock the Trash Grabber Pro.", false, false, (ValueValidator)null, (string)null);
			Grabber_UnlockImmediately = GrabberCategory.CreateEntry<bool>("05_UnlockImmediately", false, "Unlock Immediately", "Skip rank requirement for Trash Grabber Pro.", false, false, (ValueValidator)null, (string)null);
			Grabber_Source = GrabberCategory.CreateEntry<ColorSource>("06_ColorSource", ColorSource.Standard, "Color Source", "Choose which color mode to use (Base, Extended, Custom RGB).", false, false, (ValueValidator)null, (string)null);
			Grabber_Color = GrabberCategory.CreateEntry<ColorOption>("07_Color", ColorOption.Cyan, "Standard Colors", "Select the color of the Trash Grabber Pro.", false, false, (ValueValidator)null, (string)null);
			Grabber_ExtendedColor = GrabberCategory.CreateEntry<ExtendedColorOption>("08_ExtendedColor", ExtendedColorOption.Teal, "Extended Colors", "Custom expanded tints.", false, false, (ValueValidator)null, (string)null);
			Grabber_CustomRGB = GrabberCategory.CreateEntry<string>("09_CustomRGB", "0.5f, 0.5f, 0.5f", "Custom RGB Values", "Format: R,G,B (0–1 range)", false, false, (ValueValidator)null, (string)null);
			DebugCategory = MelonPreferences.CreateCategory("UpgradedTrashCans_04_DebugLogs", "Enable Debug Logging");
			DebugLogs = DebugCategory.CreateEntry<bool>("01_Debug", false, "Enable Debug Logs", (string)null, false, false, (ValueValidator)null, (string)null);
			Log.Msg("ModManager Settings initialized.");
		}

		private static ModSettingsGroup CreateGroup(string keyPrefix, string displayName, ColorOption defaultColor, ExtendedColorOption defaultExtendedColor, int defaultCapacity, float defaultRadius, RankOption defaultRank, int defaultTier, bool unlockImmediately, float defaultPrice)
		{
			MelonPreferences_Category val = MelonPreferences.CreateCategory("UpgradedTrashCans_" + keyPrefix, displayName);
			return new ModSettingsGroup
			{
				Category = val,
				Price = val.CreateEntry<float>("01_Price", defaultPrice, "Price", "Shop purchase price for the " + displayName + ".", false, false, (ValueValidator)null, (string)null),
				Capacity = val.CreateEntry<int>("02_Capacity", defaultCapacity, "Capacity", "Number of trash items the " + displayName + " can hold.", false, false, (ValueValidator)null, (string)null),
				Radius = val.CreateEntry<float>("03_Radius", defaultRadius, "Cleaner Pickup Radius", "Cleaner pickup radius for the " + displayName + " (units).", false, false, (ValueValidator)null, (string)null),
				Rank = val.CreateEntry<RankOption>("04_Rank", defaultRank, "Rank Unlock", "Rank required to unlock the " + displayName + " in shop.", false, false, (ValueValidator)null, (string)null),
				Tier = val.CreateEntry<int>("05_Tier", defaultTier, "Tier Unlock", "Tier at required rank for the " + displayName + " to unlock.", false, false, (ValueValidator)null, (string)null),
				UnlockImmediately = val.CreateEntry<bool>("06_UnlockImmediately", unlockImmediately, "Unlock Immediately", "If true, the " + displayName + " is available immediately.", false, false, (ValueValidator)null, (string)null),
				Source = val.CreateEntry<ColorSource>("07_ColorSource", ColorSource.Standard, "Color Source", "Choose which color mode to use (Base, Extended, Custom RGB).", false, false, (ValueValidator)null, (string)null),
				Color = val.CreateEntry<ColorOption>("08_Color", defaultColor, "Standard Colors", "Color tint for the " + displayName + " model.", false, false, (ValueValidator)null, (string)null),
				ExtendedColor = val.CreateEntry<ExtendedColorOption>("09_ExtendedColor", defaultExtendedColor, "Extended Colors", "Expanded color tints for the " + displayName + " model.", false, false, (ValueValidator)null, (string)null),
				CustomRGB = val.CreateEntry<string>("10_CustomRGB", "0.5f, 0.5f, 0.5f", "Custom RGB Values", "Format: R,G,B (0–1 range)", false, false, (ValueValidator)null, (string)null)
			};
		}
	}
	public static class VariantSyncManager
	{
		[CompilerGenerated]
		private sealed class <WaitForLobbyPayload>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private int <i>5__2;

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

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

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

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

			private bool MoveNext()
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<i>5__2 = 0;
					break;
				case 1:
					<>1__state = -1;
					<i>5__2++;
					break;
				}
				if (<i>5__2 < 10)
				{
					string lobbyData = SteamMatchmaking.GetLobbyData(Singleton<Lobby>.Instance.LobbySteamID, "UpgradedTrashSync");
					if (!string.IsNullOrEmpty(lobbyData))
					{
						Log.Msg("[MultiplayerSync] Host sync payload found. Applying...");
						OnLobbyMessageReceived(lobbyData);
						return false;
					}
					Log.Debug($"[MultiplayerSync] Waiting for host sync... ({<i>5__2 + 1}/{10})");
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				}
				Log.Warn("[MultiplayerSync] Timed out waiting for host variant sync.");
				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 const string LobbyTagPrefix = "UpgradedTrashCans_Settings:";

		private static readonly string CurrentSyncVersion = typeof(Core).Assembly.GetName().Version.ToString();

		public static bool HasReceivedHostVariants { get; private set; } = false;


		public static void SyncSettingsToVariants()
		{
			//IL_00c5: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_064e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0653: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_066a: Unknown result type (might be due to invalid IL or missing references)
			//IL_066c: Unknown result type (might be due to invalid IL or missing references)
			//IL_068e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0637: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Expected I4, but got Unknown
			//IL_0640: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0500: Expected I4, but got Unknown
			Lobby instance = Singleton<Lobby>.Instance;
			bool num = instance != null && instance.IsHost;
			Lobby instance2 = Singleton<Lobby>.Instance;
			int num2;
			if (instance2 != null && !instance2.IsHost)
			{
				Lobby instance3 = Singleton<Lobby>.Instance;
				num2 = ((instance3 != null && instance3.IsInLobby) ? 1 : 0);
			}
			else
			{
				num2 = 0;
			}
			bool flag = (byte)num2 != 0;
			if (num)
			{
				foreach (Variants item in TrashCanVariants.All)
				{
					if (item.Type == TrashCanType.Compactor)
					{
						ModManager.TrashCompactorSettings.ApplyTo(item);
					}
					else
					{
						ModManager.TrashBinSettings.ApplyTo(item);
					}
					Log.Debug($"Applied settings to {item.Name} — Capacity: {item.Capacity}, Color: {item.Color}");
				}
				foreach (TrashGrabberVariant item2 in TrashGrabberVariants.All)
				{
					item2.Price = ModManager.Grabber_Price.Value;
					TrashGrabberVariant trashGrabberVariant = item2;
					trashGrabberVariant.Color = (Color)(ModManager.Grabber_Source.Value switch
					{
						ColorSource.CustomRGB => ColorExtensions.TryParseRGB(ModManager.Grabber_CustomRGB.Value, out var color) ? color : Color.white, 
						ColorSource.Extended => ModManager.Grabber_ExtendedColor.Value.ToUnityColor(), 
						_ => ModManager.Grabber_Color.Value.ToUnityColor(), 
					});
					item2.Capacity = ModManager.Grabber_Capacity.Value;
					item2.RequiredRank = (ERank)ModManager.Grabber_Rank.Value;
					item2.Tier = ModManager.Grabber_Tier.Value;
					item2.UnlockImmediately = ModManager.Grabber_UnlockImmediately.Value;
					Log.Debug($"Applied settings to {item2.Name} — Capacity: {item2.Capacity}, Color: {item2.Color}, Unlock: {item2.UnlockImmediately}");
				}
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("UpgradedTrashCans_Settings:" + CurrentSyncVersion + "|");
				foreach (Variants item3 in TrashCanVariants.All)
				{
					int value = (item3.UnlockImmediately ? 1 : 0);
					StringBuilder stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder3 = stringBuilder2;
					StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(10, 10, stringBuilder2);
					handler.AppendFormatted(item3.ID);
					handler.AppendLiteral(":");
					handler.AppendFormatted(item3.Price);
					handler.AppendLiteral(",");
					handler.AppendFormatted(item3.Capacity);
					handler.AppendLiteral(",");
					handler.AppendFormatted(item3.Radius);
					handler.AppendLiteral(",");
					handler.AppendFormatted(item3.Color.r, "F2");
					handler.AppendLiteral(",");
					handler.AppendFormatted(item3.Color.g, "F2");
					handler.AppendLiteral(",");
					handler.AppendFormatted(item3.Color.b, "F2");
					handler.AppendLiteral(",");
					handler.AppendFormatted((int)item3.RequiredRank);
					handler.AppendLiteral(",");
					handler.AppendFormatted(item3.Tier);
					handler.AppendLiteral(",");
					handler.AppendFormatted(value);
					handler.AppendLiteral(";");
					stringBuilder3.Append(ref handler);
				}
				foreach (TrashGrabberVariant item4 in TrashGrabberVariants.All)
				{
					int value2 = (item4.UnlockImmediately ? 1 : 0);
					StringBuilder stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder4 = stringBuilder2;
					StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(13, 9, stringBuilder2);
					handler.AppendFormatted(item4.ID);
					handler.AppendLiteral(":");
					handler.AppendFormatted(item4.Price);
					handler.AppendLiteral(",");
					handler.AppendFormatted(item4.Capacity);
					handler.AppendLiteral(",0.0,");
					handler.AppendFormatted(item4.Color.r, "F2");
					handler.AppendLiteral(",");
					handler.AppendFormatted(item4.Color.g, "F2");
					handler.AppendLiteral(",");
					handler.AppendFormatted(item4.Color.b, "F2");
					handler.AppendLiteral(",");
					handler.AppendFormatted((int)item4.RequiredRank);
					handler.AppendLiteral(",");
					handler.AppendFormatted(item4.Tier);
					handler.AppendLiteral(",");
					handler.AppendFormatted(value2);
					handler.AppendLiteral(";");
					stringBuilder4.Append(ref handler);
				}
				Singleton<Lobby>.Instance.SetLobbyData("UpgradedTrashSync", stringBuilder.ToString());
			}
			else if (flag)
			{
				MelonCoroutines.Start(WaitForLobbyPayload());
			}
			else
			{
				foreach (Variants item5 in TrashCanVariants.All)
				{
					if (item5.Type == TrashCanType.Compactor)
					{
						ModManager.TrashCompactorSettings.ApplyTo(item5);
					}
					else
					{
						ModManager.TrashBinSettings.ApplyTo(item5);
					}
				}
				foreach (TrashGrabberVariant item6 in TrashGrabberVariants.All)
				{
					item6.Price = ModManager.Grabber_Price.Value;
					TrashGrabberVariant trashGrabberVariant = item6;
					trashGrabberVariant.Color = (Color)(ModManager.Grabber_Source.Value switch
					{
						ColorSource.CustomRGB => ColorExtensions.TryParseRGB(ModManager.Grabber_CustomRGB.Value, out var color2) ? color2 : Color.white, 
						ColorSource.Extended => ModManager.Grabber_ExtendedColor.Value.ToUnityColor(), 
						_ => ModManager.Grabber_Color.Value.ToUnityColor(), 
					});
					item6.Capacity = ModManager.Grabber_Capacity.Value;
					item6.RequiredRank = (ERank)ModManager.Grabber_Rank.Value;
					item6.Tier = ModManager.Grabber_Tier.Value;
					item6.UnlockImmediately = ModManager.Grabber_UnlockImmediately.Value;
				}
			}
			VariantLookup.Refresh();
			Log.Msg("Trash can and grabber settings synced.");
		}

		[IteratorStateMachine(typeof(<WaitForLobbyPayload>d__7))]
		private static IEnumerator WaitForLobbyPayload()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForLobbyPayload>d__7(0);
		}

		public static void OnLobbyMessageReceived(string rawMessage)
		{
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			if (!rawMessage.StartsWith("UpgradedTrashCans_Settings:"))
			{
				return;
			}
			string[] array = rawMessage.Substring("UpgradedTrashCans_Settings:".Length).Split('|');
			if (array.Length != 2)
			{
				Log.Error("[MultiplayerSync] Invalid payload format.");
				return;
			}
			string text = array[0];
			string text2 = array[1];
			if (text != CurrentSyncVersion)
			{
				Log.Warn($"[MultiplayerSync] Host mod version ({text}) does not match client mod version ({CurrentSyncVersion}).");
				return;
			}
			try
			{
				string[] array2 = text2.Split(';');
				foreach (string text3 in array2)
				{
					if (string.IsNullOrWhiteSpace(text3))
					{
						continue;
					}
					string[] array3 = text3.Split(':');
					if (array3.Length != 2)
					{
						continue;
					}
					string id = array3[0];
					string[] array4 = array3[1].Split(',');
					if (array4.Length != 9 || !float.TryParse(array4[0], out var result) || !int.TryParse(array4[1], out var result2) || !float.TryParse(array4[2], out var result3) || !float.TryParse(array4[3], out var result4) || !float.TryParse(array4[4], out var result5) || !float.TryParse(array4[5], out var result6) || !int.TryParse(array4[6], out var result7) || !int.TryParse(array4[7], out var result8) || !int.TryParse(array4[8], out var result9))
					{
						continue;
					}
					Variants variants = TrashCanVariants.All.FirstOrDefault((Variants v) => v.ID == id);
					if (variants != null)
					{
						variants.Price = result;
						variants.Capacity = result2;
						variants.Radius = result3;
						variants.Color = new Color(result4, result5, result6);
						variants.RequiredRank = (ERank)result7;
						variants.Tier = result8;
						variants.UnlockImmediately = result9 == 1;
						continue;
					}
					TrashGrabberVariant trashGrabberVariant = TrashGrabberVariants.All.FirstOrDefault((TrashGrabberVariant v) => v.ID == id);
					if (trashGrabberVariant != null)
					{
						trashGrabberVariant.Price = result;
						trashGrabberVariant.Capacity = result2;
						trashGrabberVariant.Color = new Color(result4, result5, result6);
						trashGrabberVariant.RequiredRank = (ERank)result7;
						trashGrabberVariant.Tier = result8;
						trashGrabberVariant.UnlockImmediately = result9 == 1;
					}
				}
				VariantLookup.Refresh();
				HasReceivedHostVariants = true;
				Log.Msg("[MultiplayerSync] Synced variant settings received from host.");
			}
			catch (Exception ex)
			{
				Log.Error("[MultiplayerSync] Failed to parse variant sync message: " + ex.Message);
			}
		}
	}
	public static class VariantLookup
	{
		public static HashSet<string> KnownGrabberIDs { get; private set; } = new HashSet<string>();


		public static Dictionary<string, TrashGrabberVariant> GrabberByID { get; private set; } = new Dictionary<string, TrashGrabberVariant>();


		public static void Refresh()
		{
			KnownGrabberIDs = TrashGrabberVariants.All.Select((TrashGrabberVariant v) => v.ID).ToHashSet();
			GrabberByID = TrashGrabberVariants.All.ToDictionary((TrashGrabberVariant v) => v.ID);
		}
	}
	[HarmonyPatch(typeof(Equippable_TrashGrabber), "GetCapacity")]
	public static class Patch_TrashGrabber_GetCapacity
	{
		public static void Postfix(Equippable_TrashGrabber __instance, ref int __result)
		{
			object obj;
			if (__instance == null)
			{
				obj = null;
			}
			else
			{
				ItemInstance itemInstance = ((Equippable)__instance).itemInstance;
				obj = ((itemInstance != null) ? itemInstance.Definition : null);
			}
			ItemDefinition val = (ItemDefinition)obj;
			if (val != null && val.ID != null && VariantLookup.KnownGrabberIDs.Contains(val.ID) && VariantLookup.GrabberByID.TryGetValue(val.ID, out var value))
			{
				TrashGrabberInstance trashGrabberInstance = __instance.trashGrabberInstance;
				int num = ((trashGrabberInstance != null) ? trashGrabberInstance.GetTotalSize() : 0);
				__result = Mathf.Max(0, value.Capacity - num);
			}
		}
	}
	[HarmonyPatch(typeof(Equippable_TrashGrabber), "RefreshVisuals")]
	public static class Patch_TrashGrabber_RefreshVisuals
	{
		public static void Postfix(Equippable_TrashGrabber __instance)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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)
			if (!((Object)(object)((__instance != null) ? __instance.TrashContent : null) == (Object)null) && !((Object)(object)__instance.TrashContent_Min == (Object)null) && !((Object)(object)__instance.TrashContent_Max == (Object)null))
			{
				ItemInstance itemInstance = ((Equippable)__instance).itemInstance;
				ItemDefinition val = ((itemInstance != null) ? itemInstance.Definition : null);
				if (val != null && val.ID != null && VariantLookup.KnownGrabberIDs.Contains(val.ID) && VariantLookup.GrabberByID.TryGetValue(val.ID, out var value))
				{
					TrashGrabberInstance trashGrabberInstance = __instance.trashGrabberInstance;
					float num = Mathf.Clamp01((float)((trashGrabberInstance != null) ? trashGrabberInstance.GetTotalSize() : 0) / (float)value.Capacity);
					Vector3 val2 = __instance.TrashContent_Max.localPosition - __instance.TrashContent_Min.localPosition;
					Vector3 localPosition = __instance.TrashContent_Min.localPosition;
					__instance.TrashContent.localPosition = localPosition + val2 * num;
					VisualHelper.TintRenderers(((Component)__instance).transform, value.Color, "Body", "Trigger");
				}
			}
		}
	}
	[HarmonyPatch(typeof(TrashGrabberItemUI), "UpdateUI")]
	public static class Patch_TrashGrabberItemUI_UpdateUI
	{
		public static void Postfix(TrashGrabberItemUI __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			TextMeshProUGUI valueLabel = __instance.ValueLabel;
			ItemInstance itemInstance = ((ItemUI)__instance).itemInstance;
			ItemDefinition val = ((itemInstance != null) ? itemInstance.Definition : null);
			if (!((Object)(object)valueLabel == (Object)null) && val != null && val.ID != null && VariantLookup.KnownGrabberIDs.Contains(val.ID) && VariantLookup.GrabberByID.TryGetValue(val.ID, out var value))
			{
				TrashGrabberInstance trashGrabberInstance = __instance.trashGrabberInstance;
				if (trashGrabberInstance != null)
				{
					float num = Mathf.Clamp01((float)trashGrabberInstance.GetTotalSize() / (float)value.Capacity);
					((TMP_Text)valueLabel).text = $"{Mathf.RoundToInt(num * 100f)}%";
				}
			}
		}
	}
	[HarmonyPatch(typeof(StorageVisualizer), "RefreshVisuals")]
	public static class Patch_StorageVisualizer_RefreshVisuals
	{
		public static void Postfix(StorageVisualizer __instance)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			foreach (StoredItem componentsInChild in ((Component)__instance).GetComponentsInChildren<StoredItem>(true))
			{
				StorableItemInstance item = componentsInChild.item;
				if (item != null)
				{
					ItemDefinition definition = ((ItemInstance)item).Definition;
					if (((definition != null) ? definition.ID : null) != null && VariantLookup.GrabberByID.TryGetValue(((ItemInstance)item).Definition.ID, out var value))
					{
						VisualHelper.TintRenderers(((Component)componentsInChild).transform, value.Color, "Body", "Trigger");
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(TrashContainerItem), "Start")]
	public static class Patch_TrashContainerItem_Start
	{
		[CompilerGenerated]
		private sealed class <WaitForValidName>d__1 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public TrashContainerItem instance;

			private int <attempts>5__2;

			private int <i>5__3;

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

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

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

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

			private bool MoveNext()
			{
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
					<i>5__3++;
					goto IL_0148;
				}
				<>1__state = -1;
				<attempts>5__2 = 0;
				goto IL_0151;
				IL_0148:
				if (<i>5__3 < 2)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				goto IL_0151;
				IL_0151:
				if (<attempts>5__2 < 10)
				{
					string text = null;
					try
					{
						TrashContainerItem obj = instance;
						text = ((obj != null) ? obj.Name : null);
					}
					catch (Exception ex)
					{
						Log.Debug($"[TrashContainerItem Start] Exception accessing Name on attempt {<attempts>5__2 + 1}: {ex.Message}");
					}
					if (!string.IsNullOrWhiteSpace(text))
					{
						ApplyVariantSettings(instance, text);
						return false;
					}
					<attempts>5__2++;
					Log.Debug($"[TrashContainerItem Start] Name was null or errored on attempt {<attempts>5__2}/{10}. Retrying after {2} frames...");
					<i>5__3 = 0;
					goto IL_0148;
				}
				Log.Debug("[TrashContainerItem Start] Name remained null after all retry attempts.");
				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();
			}
		}

		public static void Postfix(TrashContainerItem __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				MelonCoroutines.Start(WaitForValidName(__instance));
			}
		}

		[IteratorStateMachine(typeof(<WaitForValidName>d__1))]
		private static IEnumerator WaitForValidName(TrashContainerItem instance)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForValidName>d__1(0)
			{
				instance = instance
			};
		}

		private static void ApplyVariantSettings(TrashContainerItem instance, string name)
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			TrashContainer val = default(TrashContainer);
			foreach (Variants item in TrashCanVariants.All)
			{
				if (string.Equals(item.Name, name, StringComparison.OrdinalIgnoreCase))
				{
					if (((Component)instance).TryGetComponent<TrashContainer>(ref val))
					{
						val.TrashCapacity = item.Capacity;
					}
					instance.PickupRadius = item.Radius;
					if ((Object)(object)instance.PickupAreaProjector != (Object)null)
					{
						float num = item.Radius * 2f;
						instance.PickupAreaProjector.size = new Vector3(num, num, instance.PickupAreaProjector.size.z);
						Log.Debug($"[TrashContainer] Set projector size to ({num:F2}, {num:F2}, {instance.PickupAreaProjector.size.z:F2}) for radius {item.Radius:F2}");
					}
					VisualHelper.TintRenderers(((Component)instance).transform, item.Color, "Body");
					break;
				}
			}
		}
	}
}