Decompiled source of CraftingItemListFix v1.0.1

CraftingItemListFix.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WildSkies.Gameplay.Crafting;
using WildSkies.Gameplay.Items;
using Wildskies.UI.Panel;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CraftingItemListFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Nines (Natives)")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("CraftingItemListFix")]
[assembly: AssemblyTitle("CraftingItemListFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 CraftingItemListFix
{
	[BepInPlugin("CraftingItemListFix", "CraftingItemListFix", "1.0.1")]
	public class Plugin : BasePlugin
	{
		private class CraftableItemListEntryComparer : Comparer<CraftableItemListEntry>
		{
			public CraftableItemListEntryComparer(IntPtr pointer)
				: base(pointer)
			{
			}

			public CraftableItemListEntryComparer()
				: base(ClassInjector.DerivedConstructorPointer<CraftableItemListEntryComparer>())
			{
				ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
			}

			public override int Compare(CraftableItemListEntry item1, CraftableItemListEntry item2)
			{
				int num = item2.CanCraftItem.CompareTo(item1.CanCraftItem);
				if (num == 0)
				{
					num = ((!TestEnvironmentUtils.IsRunningTests) ? string.Compare(item1.AssociatedItem.Name.GetLocalizedString(), item2.AssociatedItem.Name.GetLocalizedString(), StringComparison.Ordinal) : string.Compare(item1.AssociatedItem.NameRaw, item2.AssociatedItem.NameRaw, StringComparison.Ordinal));
				}
				return num;
			}
		}

		internal static ManualLogSource Log;

		internal static Harmony harmonyInstance;

		private static IComparer<CraftableItemListEntry> _CraftableItemListEntryComparer;

		public override void Load()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CraftingItemListFix");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			RegisterTypeOptions val2 = new RegisterTypeOptions();
			val2.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(new Type[1] { typeof(IComparer<CraftableItemListEntry>) }));
			ClassInjector.RegisterTypeInIl2Cpp<CraftableItemListEntryComparer>(val2);
			_CraftableItemListEntryComparer = ((Il2CppObjectBase)new CraftableItemListEntryComparer()).Cast<IComparer<CraftableItemListEntry>>();
			harmonyInstance = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		public override bool Unload()
		{
			Harmony obj = harmonyInstance;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			_CraftableItemListEntryComparer = null;
			return true;
		}

		[HarmonyPatch(typeof(CraftingItemList), "TrySetCategoriesList")]
		[HarmonyPostfix]
		public static void CraftingItemList_TrySetCategoriesListPostfix(CraftingItemList __instance, bool __result)
		{
			if (Object.op_Implicit((Object)(object)__instance._currentItemSelection))
			{
				__instance._currentSelectedMainCategoryIndex = __instance._mainCategoriesKeys.IndexOf(__instance._currentItemSelection._associatedItem.CraftingCategoryId);
			}
		}

		[HarmonyPatch(typeof(CraftingItemList), "TrySetItemsList")]
		[HarmonyPrefix]
		public static bool CraftingItemList_TrySetItemsList(CraftingItemList __instance, List<CraftableItemBlueprint> listToShow, ref bool __result)
		{
			Enumerator<CraftableItemBlueprint> enumerator = listToShow.GetEnumerator();
			IItemDefinition val = default(IItemDefinition);
			while (enumerator.MoveNext())
			{
				CraftableItemBlueprint current = enumerator.Current;
				if (!((Object)(object)current == (Object)null) && __instance.TryGetItemFromBlueprint(current, ref val))
				{
					__instance.AddItemListEntry(current, val);
				}
			}
			__instance.SortItemListEntryToCraftableFirst();
			__result = __instance._currentItemListEntries.Count > 0;
			return false;
		}

		[HarmonyPatch(typeof(CraftingItemList), "SortItemListEntryToCraftableFirst")]
		[HarmonyPrefix]
		public static bool CraftingItemList_SortItemListEntryToCraftableFirst(CraftingItemList __instance)
		{
			__instance._currentItemListEntries.Sort(_CraftableItemListEntryComparer);
			for (int i = 0; i < __instance._currentItemListEntries.Count; i++)
			{
				((Component)__instance._currentItemListEntries[i]).transform.SetSiblingIndex(i);
			}
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CraftingItemListFix";

		public const string PLUGIN_NAME = "CraftingItemListFix";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}