Decompiled source of SnailMucusIl2cpp v1.1.0

SnailMucus_Il2cpp.dll

Decompiled 20 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HS_SFW;
using HS_SFW.Patches;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.Trash;
using Il2CppScheduleOne.UI.Items;
using Il2CppScheduleOne.UI.Shop;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "SnailMucus", "1.0.0", "Bars", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SnailMucus_Il2cpp")]
[assembly: AssemblyConfiguration("Il2cpp")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+422eba022c13427396211cd90abf822930b78668")]
[assembly: AssemblyProduct("SnailMucus_Il2cpp")]
[assembly: AssemblyTitle("SnailMucus_Il2cpp")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HS_SFW
{
	public class Core : MelonMod
	{
		[CompilerGenerated]
		private sealed class <DelayedGraffitiReplacement>d__12 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Core <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					((MelonBase)<>4__this).LoggerInstance.Msg("Replacing graffiti materials...");
					GraffitiPatches.ReplaceGraffitiMaterials();
					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 MelonPreferences_Category customizationCategory;

		public static MelonPreferences_Entry<string> itemNamePref;

		public static MelonPreferences_Entry<string> itemDescriptionPref;

		public static MelonPreferences_Entry<Color> bodyColorPref;

		public static MelonPreferences_Entry<string> customUIIconPath;

		public static MelonPreferences_Entry<string> customLabelIconPath;

		public static MelonPreferences_Entry<bool> useDefaultAppearance;

		public static MelonPreferences_Entry<bool> enableGraffitiReplacement;

		public override void OnInitializeMelon()
		{
			InitializePreferences();
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
			((MelonBase)this).LoggerInstance.Msg("Starting initialization of custom assets...");
			ItemUIPatches.InitializeCustomIcon();
			EquippableViewmodelPatches.InitializeCustomLabelMaterial();
			ItemShelfPatches.InitializeCustomLabelMaterial();
			((MelonBase)this).LoggerInstance.Msg("Pre-caching IL2CPP materials...");
			Material orCreateCachedMaterial = ItemShelfPatches.GetOrCreateCachedMaterial();
			Material orCreateCachedMaterial2 = EquippableViewmodelPatches.GetOrCreateCachedMaterial();
			((MelonBase)this).LoggerInstance.Msg($"IL2CPP shelf material cached: {(Object)(object)orCreateCachedMaterial != (Object)null}");
			((MelonBase)this).LoggerInstance.Msg($"IL2CPP viewmodel material cached: {(Object)(object)orCreateCachedMaterial2 != (Object)null}");
			GraffitiPatches.InitializeCustomGraffitiMaterial();
			Material labelMaterial = ItemShelfPatches.GetLabelMaterial();
			((MelonBase)this).LoggerInstance.Msg($"- Shelf Material: {(Object)(object)labelMaterial != (Object)null}, Same as Viewmodel: {(Object)(object)labelMaterial == (Object)(object)EquippableViewmodelPatches.GetLabelMaterial()}");
			ApplyPatches();
		}

		private void InitializePreferences()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			customizationCategory = MelonPreferences.CreateCategory("SnailMucusCustomization");
			itemNamePref = customizationCategory.CreateEntry<string>("ItemName", "Snail Mucus", "The name to display for the horse semen item", (string)null, false, false, (ValueValidator)null, (string)null);
			itemDescriptionPref = customizationCategory.CreateEntry<string>("ItemDescription", "A viscous secretion from a rare snail species. NOT RECOMMENDED FOR CONSUMPTION", "The description to display for the horse semen item", (string)null, false, false, (ValueValidator)null, (string)null);
			bodyColorPref = customizationCategory.CreateEntry<Color>("BodyColor", new Color(0.6039f, 0.651f, 0.6314f, 1f), "The color to use for the item's body", (string)null, false, false, (ValueValidator)null, (string)null);
			customUIIconPath = customizationCategory.CreateEntry<string>("CustomUIIconPath", "", "Path to a custom PNG file to use for the UI icon (leave empty to use the default)", (string)null, false, false, (ValueValidator)null, (string)null);
			customLabelIconPath = customizationCategory.CreateEntry<string>("CustomLabelIconPath", "", "Path to a custom PNG file to use for the label (leave empty to use the default)", (string)null, false, false, (ValueValidator)null, (string)null);
			useDefaultAppearance = customizationCategory.CreateEntry<bool>("UseDefaultAppearance", false, "If true, will not change the appearance of the item", (string)null, false, false, (ValueValidator)null, (string)null);
			enableGraffitiReplacement = customizationCategory.CreateEntry<bool>("EnableGraffitiReplacement", true, "If true, will replace graffiti textures with custom ones", (string)null, false, false, (ValueValidator)null, (string)null);
		}

		private void ApplyPatches()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			((MelonBase)this).LoggerInstance.Msg("Applying patches...");
			try
			{
				Harmony val = new Harmony("com.bars.hs-sfw");
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				val.PatchAll(executingAssembly);
				((MelonBase)this).LoggerInstance.Msg("Snail Mucus Patches applied successfully!");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Error applying patches: " + ex.Message);
				((MelonBase)this).LoggerInstance.Error(ex.StackTrace);
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			((MelonMod)this).OnSceneWasLoaded(buildIndex, sceneName);
			if (sceneName != "Main")
			{
				return;
			}
			try
			{
				MelonCoroutines.Start(DelayedGraffitiReplacement());
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Error in OnSceneWasLoaded: " + ex.Message);
				((MelonBase)this).LoggerInstance.Error(ex.StackTrace);
			}
		}

		[IteratorStateMachine(typeof(<DelayedGraffitiReplacement>d__12))]
		private IEnumerator DelayedGraffitiReplacement()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedGraffitiReplacement>d__12(0)
			{
				<>4__this = this
			};
		}
	}
}
namespace HS_SFW.Patches
{
	public class EquippableViewmodelPatches
	{
		[HarmonyPatch]
		public static class EquippableViewmodelParameterCountPatch
		{
			public static MethodBase TargetMethod()
			{
				Type typeFromHandle = typeof(Equippable_Viewmodel);
				MethodInfo[] methods = typeFromHandle.GetMethods();
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name == "Equip" && methodInfo.GetParameters().Length == 1)
					{
						return methodInfo;
					}
				}
				MelonLogger.Error("[EquippableViewmodelPatches] Could not find method");
				return null;
			}

			public static void Postfix(Component __instance, object __0)
			{
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (Core.useDefaultAppearance.Value)
					{
						return;
					}
					PropertyInfo propertyInfo = __0?.GetType().GetProperty("ID");
					if (propertyInfo == null)
					{
						return;
					}
					string text = propertyInfo.GetValue(__0, null) as string;
					if (text != "horsesemen")
					{
						return;
					}
					Il2CppArrayBase<MeshRenderer> componentsInChildren = __instance.GetComponentsInChildren<MeshRenderer>(false);
					bool flag = false;
					bool flag2 = false;
					foreach (MeshRenderer item in componentsInChildren)
					{
						string name = ((Object)((Component)item).gameObject).name;
						if (name == "Label" && !flag)
						{
							flag = true;
							if ((Object)(object)cleanLabelMaterial != (Object)null)
							{
								((Renderer)item).material = cleanLabelMaterial;
							}
						}
						else if (name == "Body" && !flag2)
						{
							flag2 = true;
							((Renderer)item).material.color = Core.bodyColorPref.Value;
						}
						if (flag && flag2)
						{
							break;
						}
					}
					if (!flag)
					{
						MelonLogger.Warning("[EquippableViewmodelPatches] No Label object found in mesh renderers");
					}
					if (!flag2)
					{
						MelonLogger.Warning("[EquippableViewmodelPatches] No Body object found in mesh renderers");
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Error in parameter count patch: " + ex.Message);
					MelonLogger.Error(ex.StackTrace);
				}
			}
		}

		[HarmonyPatch]
		public static class EquippableViewmodelGenericPatch
		{
			public static MethodBase TargetMethod()
			{
				Type typeFromHandle = typeof(Equippable_Viewmodel);
				MethodInfo[] methods = typeFromHandle.GetMethods();
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name == "Equip" && methodInfo.GetParameters().Length == 1)
					{
						return methodInfo;
					}
				}
				MelonLogger.Error("[EquippableViewmodelPatches] Could not find Equip method with one parameter");
				return null;
			}

			public static void Postfix(object __instance, object __0)
			{
				//IL_014a: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (Core.useDefaultAppearance.Value)
					{
						return;
					}
					Component val = (Component)((__instance is Component) ? __instance : null);
					if ((Object)(object)val == (Object)null)
					{
						MelonLogger.Error("[EquippableViewmodelPatches] Instance is not a Component");
						return;
					}
					string text = null;
					try
					{
						PropertyInfo propertyInfo = __0?.GetType().GetProperty("ID");
						if (propertyInfo != null)
						{
							text = propertyInfo.GetValue(__0, null) as string;
						}
					}
					catch (Exception ex)
					{
						MelonLogger.Error("[EquippableViewmodelPatches] Error getting ID: " + ex.Message);
					}
					if (text != "horsesemen")
					{
						return;
					}
					Il2CppArrayBase<MeshRenderer> componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(false);
					bool flag = false;
					bool flag2 = false;
					foreach (MeshRenderer item in componentsInChildren)
					{
						string name = ((Object)((Component)item).gameObject).name;
						if (name == "Label" && !flag)
						{
							flag = true;
							if ((Object)(object)cleanLabelMaterial != (Object)null)
							{
								((Renderer)item).material = cleanLabelMaterial;
							}
						}
						else if (name == "Body" && !flag2)
						{
							flag2 = true;
							((Renderer)item).material.color = Core.bodyColorPref.Value;
						}
						if (flag && flag2)
						{
							break;
						}
					}
					if (!flag)
					{
						MelonLogger.Warning("[EquippableViewmodelPatches] No Label object found in mesh renderers");
					}
					if (!flag2)
					{
						MelonLogger.Warning("[EquippableViewmodelPatches] No Body object found in mesh renderers");
					}
				}
				catch (Exception ex2)
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Error in generic patch: " + ex2.Message);
					MelonLogger.Error(ex2.StackTrace);
				}
			}
		}

		[HarmonyPatch(typeof(Equippable_Viewmodel), "Equip")]
		public static class EquippableViewmodelEquipPatch
		{
			public static void Postfix(Equippable_Viewmodel __instance, ItemInstance item)
			{
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (Core.useDefaultAppearance.Value)
					{
						return;
					}
					StorableItemInstance val = (StorableItemInstance)(object)((item is StorableItemInstance) ? item : null);
					if (((val != null) ? ((ItemInstance)val).ID : null) != "horsesemen")
					{
						return;
					}
					Il2CppArrayBase<MeshRenderer> componentsInChildren = ((Component)__instance).gameObject.GetComponentsInChildren<MeshRenderer>(false);
					bool flag = false;
					bool flag2 = false;
					foreach (MeshRenderer item2 in componentsInChildren)
					{
						string name = ((Object)((Component)item2).gameObject).name;
						if (name == "Label" && !flag)
						{
							flag = true;
							if ((Object)(object)cleanLabelMaterial != (Object)null)
							{
								((Renderer)item2).material = cleanLabelMaterial;
							}
						}
						else if (name == "Body" && !flag2)
						{
							flag2 = true;
							((Renderer)item2).material.color = Core.bodyColorPref.Value;
						}
						if (flag && flag2)
						{
							break;
						}
					}
					if (!flag)
					{
						MelonLogger.Warning("[EquippableViewmodelPatches] No Label object found in mesh renderers");
					}
					if (!flag2)
					{
						MelonLogger.Warning("[EquippableViewmodelPatches] No Body object found in mesh renderers");
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Error in equip patch: " + ex.Message);
					MelonLogger.Error(ex.StackTrace);
				}
			}
		}

		[HarmonyPatch(typeof(Equippable_Viewmodel), "Equip")]
		public static class EquippableViewmodelEquipIl2CppPatch
		{
			public static void Postfix(Equippable_Viewmodel __instance, ItemInstance item)
			{
				try
				{
					if (!Core.useDefaultAppearance.Value && IsHorseSemenItem(item))
					{
						ApplyCustomAppearance(((Component)__instance).gameObject);
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Error in IL2CPP Equip patch: " + ex.Message);
				}
			}
		}

		private static Material cleanLabelMaterial = null;

		private static Material cachedIl2CppLabelMaterial = null;

		private static readonly Dictionary<string, bool> itemIdCache = new Dictionary<string, bool>();

		public static Material GetLabelMaterial()
		{
			return GetOrCreateCachedMaterial();
		}

		public static void InitializeCustomLabelMaterial()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			try
			{
				if (Core.useDefaultAppearance.Value)
				{
					MelonLogger.Msg("Using default label appearance for horsesemen item");
					return;
				}
				if (!string.IsNullOrEmpty(Core.customLabelIconPath.Value) && File.Exists(Core.customLabelIconPath.Value))
				{
					MelonLogger.Msg("Loading custom label texture from: " + Core.customLabelIconPath.Value);
					byte[] array = File.ReadAllBytes(Core.customLabelIconPath.Value);
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
					{
						CreateMaterialFromTexture(val);
						return;
					}
					MelonLogger.Error("Failed to load custom label texture from: " + Core.customLabelIconPath.Value);
				}
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				using Stream stream = executingAssembly.GetManifestResourceStream("HS_SFW.Assets.HorseSemenLabel_icon.png");
				if (stream == null)
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Failed to find embedded resource: HorseSemenLabel_icon.png");
					return;
				}
				byte[] array2 = new byte[stream.Length];
				stream.Read(array2, 0, array2.Length);
				Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false);
				if (ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(array2)))
				{
					CreateMaterialFromTexture(val2);
				}
				else
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Failed to load custom label texture");
				}
				if ((Object)(object)cleanLabelMaterial == (Object)null)
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Material is still null after initialization!");
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[EquippableViewmodelPatches] Error initializing custom label material: " + ex.Message);
				MelonLogger.Error(ex.StackTrace);
			}
		}

		private static void CreateMaterialFromTexture(Texture2D texture)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			Material val = null;
			Shader val2 = Shader.Find("Universal Render Pipeline/Lit");
			if ((Object)(object)val2 != (Object)null)
			{
				val = new Material(val2);
			}
			if ((Object)(object)val == (Object)null)
			{
				Shader val3 = Shader.Find("Standard");
				if ((Object)(object)val3 != (Object)null)
				{
					val = new Material(val3);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Shader val4 = Shader.Find("Unlit/Texture");
				if ((Object)(object)val4 != (Object)null)
				{
					val = new Material(val4);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Shader val5 = Shader.Find("Default-Diffuse");
				if ((Object)(object)val5 != (Object)null)
				{
					val = new Material(val5);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = new Material(Shader.Find("Diffuse"));
			}
			if ((Object)(object)val != (Object)null)
			{
				val.mainTexture = (Texture)(object)texture;
				int num = Shader.PropertyToID("_MainTex");
				val.SetTexture(num, (Texture)(object)texture);
				cleanLabelMaterial = val;
			}
			else
			{
				MelonLogger.Error("[EquippableViewmodelPatches] Failed to create material - no suitable shader found");
			}
		}

		private static bool IsHorseSemenItem(object item)
		{
			if (item == null)
			{
				return false;
			}
			string key = item.GetHashCode().ToString();
			if (itemIdCache.TryGetValue(key, out var value))
			{
				return value;
			}
			bool flag = false;
			try
			{
				StorableItemInstance val = (StorableItemInstance)((item is StorableItemInstance) ? item : null);
				if (val != null)
				{
					flag = ((ItemInstance)val).ID == "horsesemen";
				}
				else
				{
					ItemInstance val2 = (ItemInstance)((item is ItemInstance) ? item : null);
					if (val2 != null)
					{
						flag = val2.ID == "horsesemen";
					}
					else
					{
						FieldInfo field = item.GetType().GetField("ID");
						if (field != null)
						{
							flag = field.GetValue(item) as string == "horsesemen";
						}
						else
						{
							PropertyInfo property = item.GetType().GetProperty("ID");
							if (property != null)
							{
								flag = property.GetValue(item, null) as string == "horsesemen";
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[EquippableViewmodelPatches] Error checking item ID: " + ex.Message);
				flag = false;
			}
			itemIdCache[key] = flag;
			return flag;
		}

		public static Material GetOrCreateCachedMaterial()
		{
			if ((Object)(object)cachedIl2CppLabelMaterial != (Object)null)
			{
				return cachedIl2CppLabelMaterial;
			}
			if ((Object)(object)cleanLabelMaterial != (Object)null)
			{
				cachedIl2CppLabelMaterial = cleanLabelMaterial;
				return cachedIl2CppLabelMaterial;
			}
			cachedIl2CppLabelMaterial = CreateCustomMaterial();
			return cachedIl2CppLabelMaterial;
		}

		private static void ApplyCustomAppearance(GameObject gameObject)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)gameObject == (Object)null)
			{
				return;
			}
			Il2CppArrayBase<MeshRenderer> componentsInChildren = gameObject.GetComponentsInChildren<MeshRenderer>(false);
			foreach (MeshRenderer item in componentsInChildren)
			{
				string name = ((Object)((Component)item).gameObject).name;
				if (name == "Label")
				{
					Material orCreateCachedMaterial = GetOrCreateCachedMaterial();
					if ((Object)(object)orCreateCachedMaterial != (Object)null)
					{
						((Renderer)item).material = orCreateCachedMaterial;
					}
				}
				else if (name == "Body")
				{
					((Renderer)item).material.color = Core.bodyColorPref.Value;
				}
			}
		}

		public static void ClearCache()
		{
			itemIdCache.Clear();
			MelonLogger.Msg("[EquippableViewmodelPatches] IL2CPP cache cleared");
		}

		private static Material CreateCustomMaterial()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			try
			{
				if (!string.IsNullOrEmpty(Core.customLabelIconPath.Value) && File.Exists(Core.customLabelIconPath.Value))
				{
					byte[] array = File.ReadAllBytes(Core.customLabelIconPath.Value);
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
					{
						return CreateMaterialWithTexture(val);
					}
					MelonLogger.Error("[EquippableViewmodelPatches] Failed to load custom label texture from file");
				}
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				using Stream stream = executingAssembly.GetManifestResourceStream("HS_SFW.Assets.HorseSemenLabel_icon.png");
				if (stream == null)
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Failed to find embedded resource for new material");
					return null;
				}
				byte[] array2 = new byte[stream.Length];
				stream.Read(array2, 0, array2.Length);
				Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(array2)))
				{
					MelonLogger.Error("[EquippableViewmodelPatches] Failed to load texture for new material");
					return null;
				}
				return CreateMaterialWithTexture(val2);
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[EquippableViewmodelPatches] Error creating custom material: " + ex.Message);
				return null;
			}
		}

		private static Material CreateMaterialWithTexture(Texture2D texture)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			Shader val = null;
			string[] array = new string[5] { "Universal Render Pipeline/Lit", "Standard", "Unlit/Texture", "Diffuse", "Legacy Shaders/Diffuse" };
			string[] array2 = array;
			foreach (string text in array2)
			{
				val = Shader.Find(text);
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Error("[EquippableViewmodelPatches] No suitable shader found for new material");
				return null;
			}
			Material val2 = new Material(val);
			((Object)val2).name = "CustomHorseSemenLabel_" + DateTime.Now.Ticks;
			val2.mainTexture = (Texture)(object)texture;
			try
			{
				int num = Shader.PropertyToID("_MainTex");
				val2.SetTexture(num, (Texture)(object)texture);
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[EquippableViewmodelPatches] Couldn't set texture with property ID: " + ex.Message);
			}
			return val2;
		}

		private static bool IlCppBuild()
		{
			return true;
		}
	}
	public class GraffitiPatches
	{
		private static Material customGraffitiMaterial;

		public static void InitializeCustomGraffitiMaterial()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			try
			{
				if (!Core.enableGraffitiReplacement.Value || Core.useDefaultAppearance.Value)
				{
					return;
				}
				if ((Object)(object)EquippableViewmodelPatches.GetLabelMaterial() != (Object)null)
				{
					customGraffitiMaterial = EquippableViewmodelPatches.GetLabelMaterial();
					return;
				}
				if (!string.IsNullOrEmpty(Core.customLabelIconPath.Value) && File.Exists(Core.customLabelIconPath.Value))
				{
					byte[] array = File.ReadAllBytes(Core.customLabelIconPath.Value);
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
					{
						CreateMaterialFromTexture(val);
						return;
					}
					MelonLogger.Error("Failed to load custom graffiti texture from: " + Core.customLabelIconPath.Value);
				}
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				using Stream stream = executingAssembly.GetManifestResourceStream("HS_SFW.Assets.HorseSemenLabel_icon.png");
				if (stream == null)
				{
					MelonLogger.Error("[GraffitiPatches] Failed to find embedded resource: HorseSemenLabel_icon.png");
					return;
				}
				byte[] array2 = new byte[stream.Length];
				stream.Read(array2, 0, array2.Length);
				Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false);
				if (ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(array2)))
				{
					CreateMaterialFromTexture(val2);
				}
				else
				{
					MelonLogger.Error("[GraffitiPatches] Failed to load custom graffiti texture");
				}
				if ((Object)(object)customGraffitiMaterial == (Object)null)
				{
					MelonLogger.Error("[GraffitiPatches] Material is still null after initialization!");
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[GraffitiPatches] Error initializing custom graffiti material: " + ex.Message);
				MelonLogger.Error(ex.StackTrace);
			}
		}

		private static void CreateMaterialFromTexture(Texture2D texture)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			Material val = null;
			Shader val2 = Shader.Find("Universal Render Pipeline/Lit");
			if ((Object)(object)val2 != (Object)null)
			{
				val = new Material(val2);
			}
			if ((Object)(object)val == (Object)null)
			{
				Shader val3 = Shader.Find("Standard");
				if ((Object)(object)val3 != (Object)null)
				{
					val = new Material(val3);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Shader val4 = Shader.Find("Unlit/Texture");
				if ((Object)(object)val4 != (Object)null)
				{
					val = new Material(val4);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Shader val5 = Shader.Find("Default-Diffuse");
				if ((Object)(object)val5 != (Object)null)
				{
					val = new Material(val5);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = new Material(Shader.Find("Diffuse"));
			}
			if ((Object)(object)val != (Object)null)
			{
				val.mainTexture = (Texture)(object)texture;
				int num = Shader.PropertyToID("_MainTex");
				val.SetTexture(num, (Texture)(object)texture);
				customGraffitiMaterial = val;
			}
			else
			{
				MelonLogger.Error("[GraffitiPatches] Failed to create material - no suitable shader found");
			}
		}

		public static void ReplaceGraffitiMaterials()
		{
			try
			{
				if (!Core.enableGraffitiReplacement.Value || Core.useDefaultAppearance.Value || (Object)(object)customGraffitiMaterial == (Object)null)
				{
					return;
				}
				GameObject val = GameObject.Find("Map/Container/Motel/Peter's Room/Graffiti_J");
				if ((Object)(object)val != (Object)null)
				{
					MeshRenderer component = val.GetComponent<MeshRenderer>();
					if ((Object)(object)component != (Object)null)
					{
						((Renderer)component).material = customGraffitiMaterial;
					}
					else
					{
						MelonLogger.Error("Graffiti_J found but has no MeshRenderer component");
					}
				}
				else
				{
					MelonLogger.Error("Could not find Graffiti_J object at Map/Container/Motel/Peter's Room/");
				}
				GameObject val2 = GameObject.Find("Map/Container/Overpass/Overpass Segment (13)/Overpass Support/Graffiti");
				if ((Object)(object)val2 != (Object)null)
				{
					MeshRenderer component2 = val2.GetComponent<MeshRenderer>();
					if ((Object)(object)component2 != (Object)null)
					{
						((Renderer)component2).material = customGraffitiMaterial;
					}
					else
					{
						MelonLogger.Error("Overpass Support graffiti found but has no MeshRenderer component");
					}
				}
				else
				{
					MelonLogger.Error("Could not find graffiti object at Map/Container/Overpass/Overpass Segment (13)/Overpass Support/");
				}
				GameObject val3 = GameObject.Find("Map/Container/Slums Gas Station/Graffiti");
				if ((Object)(object)val3 != (Object)null)
				{
					MeshRenderer component3 = val3.GetComponent<MeshRenderer>();
					if ((Object)(object)component3 != (Object)null)
					{
						((Renderer)component3).material = customGraffitiMaterial;
					}
					else
					{
						MelonLogger.Error("Slums Gas Station graffiti found but has no MeshRenderer component");
					}
				}
				else
				{
					MelonLogger.Error("Could not find graffiti object at Map/Container/Slums Gas Station/");
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[GraffitiPatches] Error replacing graffiti materials: " + ex.Message);
				MelonLogger.Error(ex.StackTrace);
			}
		}
	}
	public class ItemShelfPatches
	{
		[HarmonyPatch(typeof(StoredItem), "InitializeStoredItem")]
		public static class StoredItem_InitializeStoredItem_Patch
		{
			public static void Postfix(StoredItem __instance, StorableItemInstance _item)
			{
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (_item == null || !(((ItemInstance)_item).ID == "horsesemen") || Core.useDefaultAppearance.Value)
					{
						return;
					}
					Il2CppArrayBase<MeshRenderer> componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(true);
					bool flag = false;
					foreach (MeshRenderer item in componentsInChildren)
					{
						if (!(((Object)((Component)item).gameObject).name != "Label"))
						{
							flag = true;
							if (!((Object)(object)cleanLabelMaterial == (Object)null))
							{
								Material material = ((Renderer)item).material;
								((Renderer)item).material = cleanLabelMaterial;
								break;
							}
						}
					}
					if (!flag)
					{
						MelonLogger.Warning("[ItemShelfPatches] No Label object found in mesh renderers");
					}
					bool flag2 = false;
					foreach (MeshRenderer item2 in componentsInChildren)
					{
						if (((Object)((Component)item2).gameObject).name != "Body")
						{
							continue;
						}
						flag2 = true;
						Color color = ((Renderer)item2).material.color;
						((Renderer)item2).material.color = Core.bodyColorPref.Value;
						break;
					}
					if (!flag2)
					{
						MelonLogger.Warning("[ItemShelfPatches] No Body object found in mesh renderers");
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("[ItemShelfPatches] Error in StoredItem.InitializeStoredItem patch: " + ex.Message);
					MelonLogger.Error(ex.StackTrace);
				}
			}
		}

		[HarmonyPatch(typeof(StoredItem), "CreateGhostModel")]
		public static class StoredItem_CreateGhostModel_Patch
		{
			public static void Postfix(ref GameObject __result, ItemInstance _item)
			{
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (_item == null || !(_item.ID == "horsesemen") || (Object)(object)__result == (Object)null || Core.useDefaultAppearance.Value)
					{
						return;
					}
					Il2CppArrayBase<MeshRenderer> componentsInChildren = __result.GetComponentsInChildren<MeshRenderer>(true);
					bool flag = false;
					foreach (MeshRenderer item in componentsInChildren)
					{
						if (!(((Object)((Component)item).gameObject).name != "Label"))
						{
							flag = true;
							if (!((Object)(object)cleanLabelMaterial == (Object)null))
							{
								Material material = ((Renderer)item).material;
								((Renderer)item).material = cleanLabelMaterial;
								break;
							}
						}
					}
					if (!flag)
					{
						MelonLogger.Warning("[ItemShelfPatches] No Label object found in ghost mesh renderers");
					}
					bool flag2 = false;
					foreach (MeshRenderer item2 in componentsInChildren)
					{
						if (((Object)((Component)item2).gameObject).name != "Body")
						{
							continue;
						}
						flag2 = true;
						Color color = ((Renderer)item2).material.color;
						((Renderer)item2).material.color = Core.bodyColorPref.Value;
						break;
					}
					if (!flag2)
					{
						MelonLogger.Warning("[ItemShelfPatches] No Body object found in ghost mesh renderers");
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("[ItemShelfPatches] Error in StoredItem.CreateGhostModel patch: " + ex.Message);
					MelonLogger.Error(ex.StackTrace);
				}
			}
		}

		[HarmonyPatch(typeof(StoredItem), "InitializeStoredItem")]
		public static class StoredItem_InitializeStoredItem_Il2CppPatch
		{
			public static void Postfix(StoredItem __instance, StorableItemInstance _item)
			{
				try
				{
					if (!Core.useDefaultAppearance.Value && IsHorseSemenItem(_item))
					{
						ApplyCustomAppearance(((Component)__instance).gameObject);
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("[ItemShelfPatches] Error in IL2CPP InitializeStoredItem patch: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(StoredItem), "CreateGhostModel")]
		public static class StoredItem_CreateGhostModel_Il2CppPatch
		{
			public static void Postfix(ref GameObject __result, ItemInstance _item)
			{
				try
				{
					if (!((Object)(object)__result == (Object)null) && !Core.useDefaultAppearance.Value && IsHorseSemenItem(_item))
					{
						ApplyCustomAppearance(__result);
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("[ItemShelfPatches] Error in IL2CPP CreateGhostModel patch: " + ex.Message);
				}
			}
		}

		private static Material cleanLabelMaterial = null;

		private static Material cachedIl2CppLabelMaterial = null;

		private static readonly Dictionary<string, bool> itemIdCache = new Dictionary<string, bool>();

		public static Material GetLabelMaterial()
		{
			return GetOrCreateCachedMaterial();
		}

		public static void InitializeCustomLabelMaterial()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00c4: 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_00d7: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Expected O, but got Unknown
			try
			{
				if (Core.useDefaultAppearance.Value)
				{
					MelonLogger.Msg("Using default shelf appearance for horsesemen item");
					return;
				}
				if ((Object)(object)EquippableViewmodelPatches.GetLabelMaterial() != (Object)null)
				{
					cleanLabelMaterial = EquippableViewmodelPatches.GetLabelMaterial();
					return;
				}
				if (!string.IsNullOrEmpty(Core.customLabelIconPath.Value) && File.Exists(Core.customLabelIconPath.Value))
				{
					MelonLogger.Msg("Loading custom shelf label texture from: " + Core.customLabelIconPath.Value);
					byte[] array = File.ReadAllBytes(Core.customLabelIconPath.Value);
					Texture2D val = new Texture2D(2, 2);
					if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
					{
						cleanLabelMaterial = new Material(Shader.Find("Universal Render Pipeline/Lit"))
						{
							mainTexture = (Texture)(object)val
						};
						return;
					}
					MelonLogger.Error("Failed to load custom shelf label texture from: " + Core.customLabelIconPath.Value);
				}
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				using Stream stream = executingAssembly.GetManifestResourceStream("HS_SFW.Assets.HorseSemenLabel_icon.png");
				if (stream == null)
				{
					MelonLogger.Error("[ItemShelfPatches] Failed to find embedded resource: HorseSemenLabel_icon.png");
					return;
				}
				byte[] array2 = new byte[stream.Length];
				stream.Read(array2, 0, array2.Length);
				Texture2D val2 = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(array2)))
				{
					cleanLabelMaterial = new Material(Shader.Find("Universal Render Pipeline/Lit"))
					{
						mainTexture = (Texture)(object)val2
					};
				}
				else
				{
					MelonLogger.Error("[ItemShelfPatches] Failed to load custom label texture");
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[ItemShelfPatches] Error initializing custom label material for shelf items: " + ex.Message);
				MelonLogger.Error(ex.StackTrace);
			}
		}

		private static bool IsHorseSemenItem(object item)
		{
			if (item == null)
			{
				return false;
			}
			string key = item.GetHashCode().ToString();
			if (itemIdCache.TryGetValue(key, out var value))
			{
				return value;
			}
			bool flag = false;
			try
			{
				StorableItemInstance val = (StorableItemInstance)((item is StorableItemInstance) ? item : null);
				if (val != null)
				{
					flag = ((ItemInstance)val).ID == "horsesemen";
				}
				else
				{
					ItemInstance val2 = (ItemInstance)((item is ItemInstance) ? item : null);
					if (val2 != null)
					{
						flag = val2.ID == "horsesemen";
					}
					else
					{
						FieldInfo field = item.GetType().GetField("ID");
						if (field != null)
						{
							flag = field.GetValue(item) as string == "horsesemen";
						}
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[ItemShelfPatches] Error checking item ID: " + ex.Message);
				flag = false;
			}
			itemIdCache[key] = flag;
			return flag;
		}

		public static Material GetOrCreateCachedMaterial()
		{
			if ((Object)(object)cachedIl2CppLabelMaterial != (Object)null)
			{
				return cachedIl2CppLabelMaterial;
			}
			if ((Object)(object)EquippableViewmodelPatches.GetLabelMaterial() != (Object)null)
			{
				cachedIl2CppLabelMaterial = EquippableViewmodelPatches.GetLabelMaterial();
				return cachedIl2CppLabelMaterial;
			}
			cachedIl2CppLabelMaterial = CreateCustomMaterial();
			return cachedIl2CppLabelMaterial;
		}

		private static void ApplyCustomAppearance(GameObject gameObject)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)gameObject == (Object)null)
			{
				return;
			}
			Il2CppArrayBase<MeshRenderer> componentsInChildren = gameObject.GetComponentsInChildren<MeshRenderer>(false);
			foreach (MeshRenderer item in componentsInChildren)
			{
				string name = ((Object)((Component)item).gameObject).name;
				if (name == "Label")
				{
					Material orCreateCachedMaterial = GetOrCreateCachedMaterial();
					if ((Object)(object)orCreateCachedMaterial != (Object)null)
					{
						((Renderer)item).material = orCreateCachedMaterial;
					}
				}
				else if (name == "Body")
				{
					((Renderer)item).material.color = Core.bodyColorPref.Value;
				}
			}
		}

		private static Material CreateCustomMaterial()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			try
			{
				if (!string.IsNullOrEmpty(Core.customLabelIconPath.Value) && File.Exists(Core.customLabelIconPath.Value))
				{
					byte[] array = File.ReadAllBytes(Core.customLabelIconPath.Value);
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
					{
						return CreateMaterialWithTexture(val);
					}
					MelonLogger.Error("[ItemShelfPatches] Failed to load custom label texture from file");
				}
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				using Stream stream = executingAssembly.GetManifestResourceStream("HS_SFW.Assets.HorseSemenLabel_icon.png");
				if (stream == null)
				{
					MelonLogger.Error("[ItemShelfPatches] Failed to find embedded resource for new material");
					return null;
				}
				byte[] array2 = new byte[stream.Length];
				stream.Read(array2, 0, array2.Length);
				Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(array2)))
				{
					MelonLogger.Error("[ItemShelfPatches] Failed to load texture for new material");
					return null;
				}
				return CreateMaterialWithTexture(val2);
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[ItemShelfPatches] Error creating custom material: " + ex.Message);
				return null;
			}
		}

		private static Material CreateMaterialWithTexture(Texture2D texture)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			Shader val = null;
			string[] array = new string[5] { "Universal Render Pipeline/Lit", "Standard", "Unlit/Texture", "Diffuse", "Legacy Shaders/Diffuse" };
			string[] array2 = array;
			foreach (string text in array2)
			{
				val = Shader.Find(text);
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Error("[ItemShelfPatches] No suitable shader found for new material");
				return null;
			}
			Material val2 = new Material(val);
			((Object)val2).name = "CustomHorseSemenLabel_Shelf_" + DateTime.Now.Ticks;
			val2.mainTexture = (Texture)(object)texture;
			try
			{
				int num = Shader.PropertyToID("_MainTex");
				val2.SetTexture(num, (Texture)(object)texture);
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[ItemShelfPatches] Couldn't set texture with property ID: " + ex.Message);
			}
			return val2;
		}

		public static void ClearCache()
		{
			itemIdCache.Clear();
			MelonLogger.Msg("[ItemShelfPatches] IL2CPP cache cleared");
		}

		private static bool IlCppBuild()
		{
			return true;
		}
	}
	public class ItemUIPatches
	{
		[HarmonyPatch(typeof(ItemUI), "UpdateUI")]
		public static class ItemUI_UpdateUI_Patch
		{
			public static void Postfix(ItemUI __instance)
			{
				try
				{
					ItemInstance itemInstance = __instance.itemInstance;
					if (itemInstance != null && itemInstance.ID == "horsesemen" && !Core.useDefaultAppearance.Value && !((Object)(object)cleanHorseSemenIcon == (Object)null))
					{
						__instance.IconImg.sprite = cleanHorseSemenIcon;
						__instance.IconImg.overrideSprite = cleanHorseSemenIcon;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in ItemUI.UpdateUI patch: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(ItemInstance), "get_Name")]
		public static class ItemInstance_Name_Patch
		{
			public static bool Prefix(ItemInstance __instance, ref string __result)
			{
				try
				{
					if (__instance.ID == "horsesemen" && !Core.useDefaultAppearance.Value)
					{
						__result = Core.itemNamePref.Value;
						return false;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in ItemInstance.get_Name patch: " + ex.Message);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemInstance), "get_Description")]
		public static class ItemInstance_Description_Patch
		{
			public static bool Prefix(ItemInstance __instance, ref string __result)
			{
				try
				{
					if (__instance.ID == "horsesemen" && !Core.useDefaultAppearance.Value)
					{
						__result = Core.itemDescriptionPref.Value;
						return false;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in ItemInstance.get_Description patch: " + ex.Message);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemInfoContent), "Initialize", new Type[] { typeof(ItemInstance) })]
		public static class ItemInfoContent_Initialize_Patch
		{
			public static void Postfix(ItemInfoContent __instance, ItemInstance instance)
			{
				try
				{
					if (instance != null && instance.ID == "horsesemen" && !Core.useDefaultAppearance.Value)
					{
						((TMP_Text)__instance.NameLabel).text = Core.itemNamePref.Value;
						((TMP_Text)__instance.DescriptionLabel).text = Core.itemDescriptionPref.Value;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in ItemInfoContent.Initialize postfix: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(ListingUI), "Initialize")]
		public static class ListingUI_Initialize_Patch
		{
			public static void Postfix(ListingUI __instance, ShopListing listing)
			{
				try
				{
					if (listing != null && !((Object)(object)listing.Item == (Object)null) && !(((ItemDefinition)listing.Item).ID != "horsesemen") && !Core.useDefaultAppearance.Value)
					{
						if ((Object)(object)cleanHorseSemenIcon != (Object)null)
						{
							__instance.Icon.sprite = cleanHorseSemenIcon;
						}
						((TMP_Text)__instance.NameLabel).text = Core.itemNamePref.Value;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in ListingUI.Initialize patch: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(ShopInterfaceDetailPanel), "Open")]
		public static class ShopDetailPanel_Open_Patch
		{
			public static void Postfix(ShopInterfaceDetailPanel __instance, ListingUI _listing)
			{
				try
				{
					if (!((Object)(object)_listing == (Object)null) && _listing.Listing != null && !((Object)(object)_listing.Listing.Item == (Object)null) && !(((ItemDefinition)_listing.Listing.Item).ID != "horsesemen") && !Core.useDefaultAppearance.Value && (Object)(object)__instance.DescriptionLabel != (Object)null)
					{
						((TMP_Text)__instance.DescriptionLabel).text = Core.itemDescriptionPref.Value;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in ShopInterfaceDetailPanel.Open patch: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(StorableItemDefinition), "GetDefaultInstance")]
		public static class ItemDefinition_GetDefaultInstance_Patch
		{
			public static void Prefix(StorableItemDefinition __instance)
			{
				try
				{
					if (!((Object)(object)__instance == (Object)null) && !(((ItemDefinition)__instance).ID != "horsesemen") && !Core.useDefaultAppearance.Value)
					{
						((ItemDefinition)__instance).Name = Core.itemNamePref.Value;
						((ItemDefinition)__instance).Description = Core.itemDescriptionPref.Value;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in ItemDefinition.GetDefaultInstance patch: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(Registry), "_GetItem")]
		public static class Registry_GetItem_Patch
		{
			public static void Postfix(ref ItemDefinition __result)
			{
				try
				{
					if (!((Object)(object)__result == (Object)null) && !(__result.ID != "horsesemen") && !Core.useDefaultAppearance.Value)
					{
						__result.Name = Core.itemNamePref.Value;
						__result.Description = Core.itemDescriptionPref.Value;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in Registry._GetItem patch: " + ex.Message);
				}
			}
		}

		private static Sprite cleanHorseSemenIcon;

		public static void InitializeCustomIcon()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00b5: 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)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_016f: 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)
			try
			{
				if (Core.useDefaultAppearance.Value)
				{
					MelonLogger.Msg("Using default UI appearance for horsesemen item");
					return;
				}
				if (!string.IsNullOrEmpty(Core.customUIIconPath.Value) && File.Exists(Core.customUIIconPath.Value))
				{
					MelonLogger.Msg("Loading custom UI icon from: " + Core.customUIIconPath.Value);
					byte[] array = File.ReadAllBytes(Core.customUIIconPath.Value);
					Texture2D val = new Texture2D(2, 2);
					if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
					{
						cleanHorseSemenIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
						return;
					}
					MelonLogger.Error("Failed to load custom UI icon from: " + Core.customUIIconPath.Value);
				}
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				using Stream stream = executingAssembly.GetManifestResourceStream("HS_SFW.Assets.HorseSemen_Icon.png");
				if (stream == null)
				{
					MelonLogger.Error("Failed to find embedded resource: HorseSemen_Icon.png");
					return;
				}
				byte[] array2 = new byte[stream.Length];
				stream.Read(array2, 0, array2.Length);
				Texture2D val2 = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(array2)))
				{
					cleanHorseSemenIcon = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
				}
				else
				{
					MelonLogger.Error("Failed to load custom icon texture");
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("Error initializing custom icon: " + ex.Message);
				MelonLogger.Error(ex.StackTrace);
			}
		}
	}
	public class TrashItemPatches
	{
		[HarmonyPatch(typeof(TrashItem), "Awake")]
		public static class TrashItem_Awake_Patch
		{
			public static void Postfix(TrashItem __instance)
			{
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (__instance.ID != "chemicaljug" || Core.useDefaultAppearance.Value)
					{
						return;
					}
					Il2CppArrayBase<MeshRenderer> componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(true);
					foreach (MeshRenderer item in componentsInChildren)
					{
						if (((Object)((Component)item).gameObject).name != "Body")
						{
							continue;
						}
						((Renderer)item).material.color = Core.bodyColorPref.Value;
						break;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in TrashItem.Awake patch: " + ex.Message);
					MelonLogger.Error(ex.StackTrace);
				}
			}
		}

		[HarmonyPatch(typeof(TrashItem), "Start")]
		public static class TrashItem_Start_Patch
		{
			public static void Postfix(TrashItem __instance)
			{
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (__instance.ID != "chemicaljug" || Core.useDefaultAppearance.Value)
					{
						return;
					}
					Il2CppArrayBase<MeshRenderer> componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(true);
					foreach (MeshRenderer item in componentsInChildren)
					{
						if (((Object)((Component)item).gameObject).name != "Body")
						{
							continue;
						}
						((Renderer)item).material.color = Core.bodyColorPref.Value;
						break;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error in TrashItem.Start patch: " + ex.Message);
					MelonLogger.Error(ex.StackTrace);
				}
			}
		}
	}
}