Decompiled source of UpgradedTrashCans Mono v1.5.4

Mods/UpgradedTrashCans_Mono.dll

Decompiled a month 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.Security;
using System.Security.Permissions;
using System.Text;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using ScheduleOne;
using ScheduleOne.DevUtilities;
using ScheduleOne.Equipping;
using ScheduleOne.ItemFramework;
using ScheduleOne.Levelling;
using ScheduleOne.Networking;
using ScheduleOne.ObjectScripts;
using ScheduleOne.ObjectScripts.WateringCan;
using ScheduleOne.Storage;
using ScheduleOne.Trash;
using ScheduleOne.UI.Items;
using ScheduleOne.UI.Shop;
using Steamworks;
using TMPro;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("UpgradedTrashCans_Mono")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.5.4")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UpgradedTrashCans_Mono")]
[assembly: AssemblyTitle("UpgradedTrashCans_Mono")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.4.0")]
[module: UnverifiableCode]
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>, IDisposable, IEnumerator
		{
			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_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_0247: Unknown result type (might be due to invalid IL or missing references)
				//IL_0254: Unknown result type (might be due to invalid IL or missing references)
				//IL_025b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0268: Unknown result type (might be due to invalid IL or missing references)
				//IL_0275: Expected O, but got Unknown
				//IL_0364: Unknown result type (might be due to invalid IL or missing references)
				//IL_0369: Unknown result type (might be due to invalid IL or missing references)
				//IL_0376: Unknown result type (might be due to invalid IL or missing references)
				//IL_0383: Unknown result type (might be due to invalid IL or missing references)
				//IL_038a: 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_03a4: 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
				{
					foreach (ShopInterface allShop in ShopInterface.AllShops)
					{
						if (IsValidHardwareStore(allShop))
						{
							list.Add(allShop);
						}
					}
				}
				catch (Exception)
				{
					Log.Warn("[TrashInjector] Failed to access ShopInterface.AllShops — using fallback");
					ShopInterface[] array = Object.FindObjectsOfType<ShopInterface>();
					foreach (ShopInterface val in array)
					{
						if (IsValidHardwareStore(val))
						{
							list.Add(val);
						}
					}
				}
				if (list.Count == 0)
				{
					Log.Warn("[TrashInjector] No hardware store interfaces found.");
					return false;
				}
				ShopInterface val2 = list[0];
				ShopListing[] source = val2?.Listings?.ToArray() ?? 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 item in TrashCanVariants.All)
					{
						InjectCustomTrashCan(val2, val3, item);
					}
				}
				if (val4 != null)
				{
					foreach (TrashGrabberVariant item2 in TrashGrabberVariants.All)
					{
						InjectCustomTrashGrabber(val2, val4, item2);
					}
				}
				foreach (ShopInterface item3 in list)
				{
					foreach (Variants item4 in TrashCanVariants.All)
					{
						if ((Object)(object)item4?.Definition == (Object)null)
						{
							Log.Warn("Skipped injecting trash can variant " + item4?.Name + " due to missing definition.");
							continue;
						}
						try
						{
							ShopListing val5 = new ShopListing
							{
								Item = (StorableItemDefinition)(object)item4.Definition,
								name = item4.Name,
								OverridePrice = true,
								OverriddenPrice = item4.Price,
								CurrentStock = 999
							};
							item3.Listings.Add(val5);
							item3.CreateListingUI(val5);
							Log.Debug("Injected " + item4.Name + " with ID " + item4.ID + " into shop.");
						}
						catch (Exception ex2)
						{
							Log.Error("Failed to inject trash can variant " + item4.Name + ": " + ex2.Message);
						}
					}
					foreach (TrashGrabberVariant item5 in TrashGrabberVariants.All)
					{
						if ((Object)(object)item5?.Definition == (Object)null)
						{
							Log.Warn("Skipped injecting trash grabber variant " + item5?.Name + " due to missing definition.");
							continue;
						}
						try
						{
							ShopListing val6 = new ShopListing
							{
								Item = (StorableItemDefinition)(object)item5.Definition,
								name = item5.Name,
								OverridePrice = true,
								OverriddenPrice = item5.Price,
								CurrentStock = 999
							};
							item3.Listings.Add(val6);
							item3.CreateListingUI(val6);
							Log.Debug("Injected " + item5.Name + " with ID " + item5.ID + " into shop.");
						}
						catch (Exception ex3)
						{
							Log.Error("Failed to inject trash grabber variant " + item5.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_00a9: 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)
			StorableItemDefinition item = baseListing.Item;
			BuildableItemDefinition val = (BuildableItemDefinition)(object)((item is BuildableItemDefinition) ? item : null);
			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_00a9: 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)
			StorableItemDefinition item = baseListing.Item;
			TrashGrabberDefinition val = (TrashGrabberDefinition)(object)((item is TrashGrabberDefinition) ? item : null);
			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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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(new char[1] { ',' });
			if (array.Length != 3)
			{
				Log.Warn("RGB string does not contain 3 components: \"" + input + "\"");
				return false;
			}
			if (float.TryParse(array[0].TrimEnd(new char[1] { 'f' }), out var result) && float.TryParse(array[1].TrimEnd(new char[1] { 'f' }), out var result2) && float.TryParse(array[2].TrimEnd(new char[1] { '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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00a8: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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[] pixels = val.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				Color val3 = pixels[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);
				pixels[i] = new Color(val5.r, val5.g, val5.b, val3.a);
			}
			val2.SetPixels(pixels);
			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 ((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 = (ItemDefinition)(object)((trackedDefinition is ItemDefinition) ? trackedDefinition : null);
				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>, IDisposable, IEnumerator
		{
			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_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0500: Unknown result type (might be due to invalid IL or missing references)
			//IL_0502: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Expected I4, but got Unknown
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: 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 num3 = (item3.UnlockImmediately ? 1 : 0);
					stringBuilder.Append($"{item3.ID}:{item3.Price},{item3.Capacity},{item3.Radius},{item3.Color.r:F2},{item3.Color.g:F2},{item3.Color.b:F2},{(int)item3.RequiredRank},{item3.Tier},{num3};");
				}
				foreach (TrashGrabberVariant item4 in TrashGrabberVariants.All)
				{
					int num4 = (item4.UnlockImmediately ? 1 : 0);
					stringBuilder.Append($"{item4.ID}:{item4.Price},{item4.Capacity},0.0,{item4.Color.r:F2},{item4.Color.g:F2},{item4.Color.b:F2},{(int)item4.RequiredRank},{item4.Tier},{num4};");
				}
				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_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: 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(new char[1] { '|' });
			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(new char[1] { ';' });
				foreach (string text3 in array2)
				{
					if (string.IsNullOrWhiteSpace(text3))
					{
						continue;
					}
					string[] array3 = text3.Split(new char[1] { ':' });
					if (array3.Length != 2)
					{
						continue;
					}
					string id = array3[0];
					string[] array4 = array3[1].Split(new char[1] { ',' });
					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?.TrashContent == (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_004f: Unknown result type (might be due to invalid IL or missing references)
			StoredItem[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<StoredItem>(true);
			foreach (StoredItem val in componentsInChildren)
			{
				StorableItemInstance item = val.item;
				if (item != null && ((ItemInstance)item).Definition?.ID != null && VariantLookup.GrabberByID.TryGetValue(((ItemInstance)item).Definition.ID, out var value))
				{
					VisualHelper.TintRenderers(((Component)val).transform, value.Color, "Body", "Trigger");
				}
			}
		}
	}
	[HarmonyPatch(typeof(TrashContainerItem), "Start")]
	public static class Patch_TrashContainerItem_Start
	{
		[CompilerGenerated]
		private sealed class <WaitForValidName>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			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_00df;
				}
				<>1__state = -1;
				<attempts>5__2 = 0;
				goto IL_00e8;
				IL_00df:
				if (<i>5__3 < 2)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				goto IL_00e8;
				IL_00e8:
				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_00df;
				}
				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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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)
			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;
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}