Decompiled source of RopeMod v1.0.0

RopeMod.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Sons.Crafting;
using Sons.Inventory;
using Sons.Items.Core;
using TheForest.Items.Inventory;
using TheForest.Utils;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RopeMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2e9ff00a542ad7190a6403a3b6673c888f7162bd")]
[assembly: AssemblyProduct("RopeMod")]
[assembly: AssemblyTitle("RopeMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RopeMod;

internal sealed class DumpComponent : MonoBehaviour
{
	internal static ConfigEntry<Key> DumpKey;

	internal static ManualLogSource Log;

	private bool _announced;

	public DumpComponent(IntPtr ptr)
		: base(ptr)
	{
	}

	public void Update()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if (!_announced)
		{
			_announced = true;
			Log.LogInfo((object)"[ItemDump] key listener running");
		}
		Keyboard current = Keyboard.current;
		Key value = DumpKey.Value;
		if (current == null || (int)value == 0 || !((ButtonControl)current[value]).wasPressedThisFrame)
		{
			return;
		}
		try
		{
			DoItemDump();
		}
		catch (Exception ex)
		{
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(11, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ItemDump] ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
			}
			log.LogError(val);
		}
	}

	private static void DoItemDump()
	{
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Expected O, but got Unknown
		StringBuilder stringBuilder = new StringBuilder(65536);
		int num = 0;
		stringBuilder.AppendLine("=== ITEMS ===");
		bool flag = (Object)(object)ItemDatabaseManager._instance != (Object)null;
		List<ItemData> val = (flag ? ItemDatabaseManager.Items : null);
		StringBuilder stringBuilder2;
		StringBuilder.AppendInterpolatedStringHandler handler;
		if (val == null)
		{
			stringBuilder.AppendLine("Items unavailable (item database or item list is null). Load a world and retry.");
		}
		else
		{
			for (int i = 0; i < val.Count; i++)
			{
				ItemData val2 = val[i];
				if ((Object)(object)val2 == (Object)null)
				{
					stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder3 = stringBuilder2;
					handler = new StringBuilder.AppendInterpolatedStringHandler(21, 1, stringBuilder2);
					handler.AppendLiteral("(null item at index ");
					handler.AppendFormatted(i);
					handler.AppendLiteral(")");
					stringBuilder3.AppendLine(ref handler);
				}
				else
				{
					stringBuilder.Append(val2.Id).Append('\t').AppendLine(val2.Name ?? "(unnamed item)");
					num++;
				}
			}
		}
		int? num2 = (flag ? new int?(ItemDatabase.RopeId) : ((int?)null));
		bool ropeFound = false;
		bool incomplete = false;
		int num3 = 0;
		stringBuilder.AppendLine().AppendLine("=== RECIPES (all) ===");
		List<CraftingRecipe> val3 = FindRecipes(stringBuilder);
		if (val3 == null)
		{
			stringBuilder.AppendLine("Recipes unavailable (see source lines above). Load a world and retry.");
			incomplete = true;
		}
		else
		{
			for (int j = 0; j < val3.Count; j++)
			{
				CraftingRecipe val4 = val3[j];
				if ((Object)(object)val4 == (Object)null)
				{
					stringBuilder.AppendLine("(null recipe)");
					incomplete = true;
					continue;
				}
				stringBuilder.Append(val4.Name ?? "(unnamed recipe)").Append(" | ").Append(val4.RecipeType);
				stringBuilder.Append(" | ingredients: ").Append(FormatIngredients(val4));
				stringBuilder.Append(" | results: ").Append(FormatResults(val4, num2, ref ropeFound, ref incomplete));
				stringBuilder.Append(" | generated: ").AppendLine(RopeRecipeComponent.Describe(val4._generatedResultingItems));
				num3++;
			}
		}
		AppendMatLayouts(stringBuilder);
		string text = (ropeFound ? "YES" : ((!num2.HasValue || incomplete) ? "UNKNOWN (some result data unavailable)" : "NO"));
		string text2 = "Recipe outputs rope (ID " + (num2?.ToString() ?? "unavailable") + "): " + text;
		stringBuilder2 = stringBuilder.AppendLine();
		StringBuilder stringBuilder4 = stringBuilder2;
		handler = new StringBuilder.AppendInterpolatedStringHandler(16, 2, stringBuilder2);
		handler.AppendLiteral("items=");
		handler.AppendFormatted(num);
		handler.AppendLiteral("  recipes=");
		handler.AppendFormatted(num3);
		stringBuilder4.AppendLine(ref handler);
		string text3 = Path.Combine(Paths.BepInExRootPath, "RopeMod_dump.txt");
		File.WriteAllText(text3, text2 + Environment.NewLine + Environment.NewLine + stringBuilder, Encoding.UTF8);
		ManualLogSource log = Log;
		bool flag2 = default(bool);
		BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(40, 3, ref flag2);
		if (flag2)
		{
			((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("[ItemDump] wrote ");
			((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(num);
			((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" items and ");
			((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(num3);
			((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" recipes to ");
			((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(text3);
		}
		log.LogInfo(val5);
	}

	private static List<CraftingRecipe> FindRecipes(StringBuilder body)
	{
		CraftingSystem instance = CraftingSystem.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			body.AppendLine("source: CraftingSystem.Instance is null");
		}
		else if ((Object)(object)instance._recipeDatabase == (Object)null)
		{
			body.AppendLine("source: CraftingSystem.Instance._recipeDatabase is null");
		}
		else
		{
			if (instance._recipeDatabase._recipes != null)
			{
				body.AppendLine("source: CraftingSystem.Instance._recipeDatabase");
				return instance._recipeDatabase._recipes;
			}
			body.AppendLine("source: CraftingSystem.Instance._recipeDatabase._recipes is null");
		}
		Il2CppReferenceArray<Object> val = Resources.FindObjectsOfTypeAll(Il2CppType.Of<CraftingRecipeDatabase>());
		int num = ((Il2CppArrayBase<Object>)(object)val)?.Length ?? 0;
		StringBuilder stringBuilder = body;
		StringBuilder stringBuilder2 = stringBuilder;
		StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(78, 1, stringBuilder);
		handler.AppendLiteral("source: Resources.FindObjectsOfTypeAll found ");
		handler.AppendFormatted(num);
		handler.AppendLiteral(" CraftingRecipeDatabase object(s)");
		stringBuilder2.AppendLine(ref handler);
		List<CraftingRecipe> val2 = null;
		for (int i = 0; i < num; i++)
		{
			Object obj = ((Il2CppArrayBase<Object>)(object)val)[i];
			CraftingRecipeDatabase val3 = ((obj != null) ? ((Il2CppObjectBase)obj).TryCast<CraftingRecipeDatabase>() : null);
			List<CraftingRecipe> val4 = ((val3 != null) ? val3._recipes : null);
			stringBuilder = body;
			StringBuilder stringBuilder3 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(7, 3, stringBuilder);
			handler.AppendLiteral("  [");
			handler.AppendFormatted(i);
			handler.AppendLiteral("] ");
			handler.AppendFormatted(((val3 != null) ? ((Object)val3).name : null) ?? "(null)");
			handler.AppendLiteral(": ");
			handler.AppendFormatted((val4 == null) ? "null list" : (val4.Count + " recipes"));
			stringBuilder3.AppendLine(ref handler);
			if (val4 != null && (val2 == null || val4.Count > val2.Count))
			{
				val2 = val4;
			}
		}
		return val2;
	}

	private static void AppendMatLayouts(StringBuilder body)
	{
		body.AppendLine().AppendLine("=== CRAFTING MAT LAYOUTS ===");
		Il2CppReferenceArray<Object> val = Resources.FindObjectsOfTypeAll(Il2CppType.Of<CraftingSystem>());
		int num = ((Il2CppArrayBase<Object>)(object)val)?.Length ?? 0;
		StringBuilder stringBuilder = body;
		StringBuilder stringBuilder2 = stringBuilder;
		StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(24, 1, stringBuilder);
		handler.AppendLiteral("CraftingSystem objects: ");
		handler.AppendFormatted(num);
		stringBuilder2.AppendLine(ref handler);
		for (int i = 0; i < num; i++)
		{
			Object obj = ((Il2CppArrayBase<Object>)(object)val)[i];
			CraftingSystem val2 = ((obj != null) ? ((Il2CppObjectBase)obj).TryCast<CraftingSystem>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				stringBuilder = body;
				StringBuilder stringBuilder3 = stringBuilder;
				handler = new StringBuilder.AppendInterpolatedStringHandler(11, 1, stringBuilder);
				handler.AppendLiteral("  [");
				handler.AppendFormatted(i);
				handler.AppendLiteral("] (null)");
				stringBuilder3.AppendLine(ref handler);
				continue;
			}
			stringBuilder = body;
			StringBuilder stringBuilder4 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(30, 4, stringBuilder);
			handler.AppendLiteral("  [");
			handler.AppendFormatted(i);
			handler.AppendLiteral("] ");
			handler.AppendFormatted(((Object)val2).name);
			handler.AppendLiteral(": initialized=");
			handler.AppendFormatted(val2._isInitialized);
			handler.AppendLiteral(" available=");
			handler.AppendFormatted((val2._availableRecipes == null) ? "null" : val2._availableRecipes.Count.ToString());
			stringBuilder4.AppendLine(ref handler);
			List<CraftingResultLayoutItemGroup> craftingResultLayoutItemGroups = val2._craftingResultLayoutItemGroups;
			List<string> list = new List<string>();
			int num2 = 0;
			while (craftingResultLayoutItemGroups != null && num2 < craftingResultLayoutItemGroups.Count)
			{
				list.Add(((Object)(object)craftingResultLayoutItemGroups[num2] == (Object)null) ? "null" : ((LayoutItemGroup<CraftingResultLayoutItem>)(object)craftingResultLayoutItemGroups[num2]).ItemId.ToString());
				num2++;
			}
			stringBuilder = body;
			StringBuilder stringBuilder5 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(23, 2, stringBuilder);
			handler.AppendLiteral("    result layouts (");
			handler.AppendFormatted(list.Count);
			handler.AppendLiteral("): ");
			handler.AppendFormatted(string.Join(", ", list));
			stringBuilder5.AppendLine(ref handler);
			List<IngredientLayoutItemGroup> ingredientLayoutItemGroups = val2._ingredientLayoutItemGroups;
			List<string> list2 = new List<string>();
			int num3 = 0;
			while (ingredientLayoutItemGroups != null && num3 < ingredientLayoutItemGroups.Count)
			{
				list2.Add(((Object)(object)ingredientLayoutItemGroups[num3] == (Object)null) ? "null" : ((LayoutItemGroup<IngredientLayoutItem>)(object)ingredientLayoutItemGroups[num3]).ItemId.ToString());
				num3++;
			}
			stringBuilder = body;
			StringBuilder stringBuilder6 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(27, 2, stringBuilder);
			handler.AppendLiteral("    ingredient layouts (");
			handler.AppendFormatted(list2.Count);
			handler.AppendLiteral("): ");
			handler.AppendFormatted(string.Join(", ", list2));
			stringBuilder6.AppendLine(ref handler);
		}
	}

	private static string FormatIngredients(CraftingRecipe recipe)
	{
		List<CraftingIngredient> ingredients = recipe.Ingredients;
		if (ingredients == null)
		{
			return "(null ingredients)";
		}
		if (ingredients.Count == 0)
		{
			return "(none)";
		}
		List<string> list = new List<string>();
		for (int i = 0; i < ingredients.Count; i++)
		{
			CraftingIngredient val = ingredients[i];
			list.Add((val == null) ? "(null ingredient)" : $"{val.ItemId} x {val.Count}");
		}
		return string.Join(", ", list);
	}

	private static string FormatResults(CraftingRecipe recipe, int? ropeId, ref bool ropeFound, ref bool incomplete)
	{
		List<ResultingItem> val = (recipe._useContainerDataForResultingItems ? recipe._generatedResultingItems : recipe._resultingItems);
		if (val == null || (recipe._useContainerDataForResultingItems && val.Count == 0))
		{
			incomplete = true;
			if (!recipe._useContainerDataForResultingItems)
			{
				return "(null results)";
			}
			return "(generated results unavailable)";
		}
		Dictionary<int, int> dictionary = new Dictionary<int, int>();
		bool flag = false;
		for (int i = 0; i < val.Count; i++)
		{
			ResultingItem val2 = val[i];
			if (val2 == null)
			{
				flag = true;
				incomplete = true;
				continue;
			}
			dictionary.TryGetValue(val2.Id, out var value);
			dictionary[val2.Id] = value + 1;
			if (val2.Id == ropeId)
			{
				ropeFound = true;
			}
		}
		List<string> list = new List<string>();
		foreach (KeyValuePair<int, int> item in dictionary)
		{
			list.Add($"{item.Key} x {item.Value}");
		}
		if (flag)
		{
			list.Add("(null result)");
		}
		if (list.Count != 0)
		{
			return string.Join(", ", list);
		}
		return "(none)";
	}
}
[BepInPlugin("andre.sotf.ropemod", "RopeMod", "1.0.0")]
public sealed class Plugin : BasePlugin
{
	public const string Version = "1.0.0";

	public override void Load()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		ManualLogSource log = ((BasePlugin)this).Log;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(15, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("RopeMod ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
		}
		log.LogInfo(val);
		ConfigEntry<Key> val2 = (DumpComponent.DumpKey = ((BasePlugin)this).Config.Bind<Key>("Hotkeys", "DumpKey", (Key)99, "Key to write RopeMod_dump.txt with all item IDs and recipes"));
		DumpComponent.Log = ((BasePlugin)this).Log;
		((BasePlugin)this).AddComponent<DumpComponent>();
		ManualLogSource log2 = ((BasePlugin)this).Log;
		val = new BepInExInfoLogInterpolatedStringHandler(59, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RopeMod] ItemDump ready — press ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Key>(val2.Value);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" to write RopeMod_dump.txt");
		}
		log2.LogInfo(val);
		RopeRecipeComponent.Enabled = ((BasePlugin)this).Config.Bind<bool>("Recipe", "Enabled", true, "Add the rope recipe to the crafting mat");
		RopeRecipeComponent.IngredientId = ((BasePlugin)this).Config.Bind<int>("Recipe", "IngredientItemId", 484, "Item ID used as fiber (484 = Leaf; see docs/item-dump.txt for others)");
		RopeRecipeComponent.IngredientAmount = ((BasePlugin)this).Config.Bind<int>("Recipe", "IngredientAmount", 10, "How many of the fiber item make one rope (minimum 1)");
		RopeRecipeComponent.Log = ((BasePlugin)this).Log;
		((BasePlugin)this).AddComponent<RopeRecipeComponent>();
		RopeCraftPatch.Log = ((BasePlugin)this).Log;
		new Harmony("andre.sotf.ropemod").PatchAll(typeof(RopeCraftPatch));
	}
}
[HarmonyPatch(typeof(CraftingSystem), "CraftResultingItem")]
internal static class RopeCraftPatch
{
	internal static ManualLogSource Log;

	[HarmonyPrefix]
	private static bool Prefix(CraftingRecipe recipe, ResultingItem resultingItem)
	{
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Expected O, but got Unknown
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Expected O, but got Unknown
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Expected O, but got Unknown
		if ((Object)(object)recipe == (Object)null || ((Object)recipe).name != "RopeMod_RopeRecipe")
		{
			return true;
		}
		bool flag = default(bool);
		try
		{
			int num = ((resultingItem != null) ? resultingItem.Id : ItemDatabase.RopeId);
			PlayerInventory inventory = LocalPlayer.Inventory;
			if ((Object)(object)inventory == (Object)null)
			{
				Log.LogWarning((object)"[RopeRecipe] craft: no local player inventory; rope not given");
				return false;
			}
			int num2 = inventory.AmountOf(num, false, false);
			if (inventory.HasRoomFor(num, 1))
			{
				inventory.AddItem(num, 1, true, true, (ItemInstance)null);
			}
			int num3 = inventory.AmountOf(num, false, false);
			if (num3 > num2)
			{
				ManualLogSource log = Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(37, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RopeRecipe] crafted 1 x rope ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (now ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num3);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
				}
				log.LogInfo(val);
				return false;
			}
			int num4 = Math.Max(1, RopeRecipeComponent.IngredientAmount.Value);
			bool flag2 = inventory.AddItem(RopeRecipeComponent.IngredientId.Value, num4, true, false, (ItemInstance)null);
			ManualLogSource log2 = Log;
			BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(43, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[RopeRecipe] craft: rope full (");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num3);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("); ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(flag2 ? "refunded" : "could not refund");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num4);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" x item ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(RopeRecipeComponent.IngredientId.Value);
			}
			log2.LogWarning(val2);
		}
		catch (Exception ex)
		{
			ManualLogSource log3 = Log;
			BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(27, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[RopeRecipe] craft failed: ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
			}
			log3.LogError(val3);
		}
		return false;
	}
}
internal sealed class RopeRecipeComponent : MonoBehaviour
{
	internal const string RecipeName = "RopeMod_RopeRecipe";

	private const string TemplateName = "LeafArmourRecipe";

	private const float SearchInterval = 5f;

	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<int> IngredientId;

	internal static ConfigEntry<int> IngredientAmount;

	internal static ManualLogSource Log;

	private CraftingRecipeDatabase _database;

	private float _nextCheck;

	private bool _reportedFailure;

	public RopeRecipeComponent(IntPtr ptr)
		: base(ptr)
	{
	}

	public void Update()
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Expected O, but got Unknown
		if (!Enabled.Value || Time.unscaledTime < _nextCheck)
		{
			return;
		}
		_nextCheck = Time.unscaledTime + 5f;
		try
		{
			if (!((Object)(object)_database != (Object)null) || !Contains(_database._recipes))
			{
				_database = null;
				TryRegister();
			}
		}
		catch (Exception ex)
		{
			if (!_reportedFailure)
			{
				_reportedFailure = true;
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(34, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RopeRecipe] registration failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}
	}

	private void TryRegister()
	{
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Expected O, but got Unknown
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Expected O, but got Unknown
		if ((Object)(object)ItemDatabaseManager._instance == (Object)null)
		{
			return;
		}
		CraftingRecipeDatabase val = FindDatabase();
		List<CraftingRecipe> val2 = ((val != null) ? val._recipes : null);
		if (val2 == null)
		{
			return;
		}
		if (Contains(val2))
		{
			_database = val;
			return;
		}
		CraftingRecipe val3 = null;
		for (int i = 0; i < val2.Count; i++)
		{
			if ((Object)(object)val2[i] != (Object)null && ((Object)val2[i]).name == "LeafArmourRecipe")
			{
				val3 = val2[i];
				break;
			}
		}
		if ((Object)(object)val3 == (Object)null)
		{
			ReportOnce("[RopeRecipe] template LeafArmourRecipe not found in recipe database; rope recipe not added");
			return;
		}
		int num = Math.Max(1, IngredientAmount.Value);
		CraftingRecipe val4 = ((Il2CppObjectBase)Object.Instantiate(((Il2CppObjectBase)val3).Cast<Object>())).Cast<CraftingRecipe>();
		((Object)val4).name = "RopeMod_RopeRecipe";
		((Object)val4).hideFlags = (HideFlags)32;
		val4._recipeType = (Type)0;
		val4._useContainerDataForResultingItems = false;
		List<CraftingIngredient> val5 = new List<CraftingIngredient>();
		CraftingIngredient val6 = new CraftingIngredient();
		val6.ItemId = IngredientId.Value;
		val6.Count = num;
		val6.IsReusable = false;
		val5.Add(val6);
		val4._ingredients = val5;
		string text = Describe(val4._generatedResultingItems);
		val4._resultingItems = RopeList();
		val4._generatedResultingItems = RopeList();
		val2.Add(val4);
		_database = val;
		CraftingSystem instance = CraftingSystem.Instance;
		if ((Object)(object)instance != (Object)null)
		{
			instance.RefreshAvailableRecipes(false);
		}
		ManualLogSource log = Log;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val7 = new BepInExInfoLogInterpolatedStringHandler(96, 6, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val7).AppendLiteral("[RopeRecipe] registered: ");
			((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<int>(num);
			((BepInExLogInterpolatedStringHandler)val7).AppendLiteral(" x item ");
			((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<int>(IngredientId.Value);
			((BepInExLogInterpolatedStringHandler)val7).AppendLiteral(" -> 1 x rope ");
			((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<int>(ItemDatabase.RopeId);
			((BepInExLogInterpolatedStringHandler)val7).AppendLiteral(" (");
			((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<int>(val2.Count);
			((BepInExLogInterpolatedStringHandler)val7).AppendLiteral(" recipes, mat ");
			((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<string>(((Object)(object)instance != (Object)null) ? "refreshed" : "not active yet");
			((BepInExLogInterpolatedStringHandler)val7).AppendLiteral(";");
			((BepInExLogInterpolatedStringHandler)val7).AppendLiteral(" clone's generated results were ");
			((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<string>(text);
			((BepInExLogInterpolatedStringHandler)val7).AppendLiteral(")");
		}
		log.LogInfo(val7);
	}

	private static List<ResultingItem> RopeList()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		List<ResultingItem> obj = new List<ResultingItem>();
		ResultingItem val = new ResultingItem();
		val.Id = ItemDatabase.RopeId;
		obj.Add(val);
		return obj;
	}

	internal static string Describe(List<ResultingItem> list)
	{
		if (list == null)
		{
			return "null";
		}
		if (list.Count == 0)
		{
			return "empty";
		}
		string[] array = new string[list.Count];
		for (int i = 0; i < list.Count; i++)
		{
			array[i] = ((list[i] == null) ? "null" : list[i].Id.ToString());
		}
		return "[" + string.Join(", ", array) + "]";
	}

	private static CraftingRecipeDatabase FindDatabase()
	{
		CraftingSystem instance = CraftingSystem.Instance;
		if ((Object)(object)instance != (Object)null && (Object)(object)instance._recipeDatabase != (Object)null)
		{
			return instance._recipeDatabase;
		}
		Il2CppReferenceArray<Object> val = Resources.FindObjectsOfTypeAll(Il2CppType.Of<CraftingRecipeDatabase>());
		CraftingRecipeDatabase val2 = null;
		int num = 0;
		while (val != null && num < ((Il2CppArrayBase<Object>)(object)val).Length)
		{
			Object obj = ((Il2CppArrayBase<Object>)(object)val)[num];
			CraftingRecipeDatabase val3 = ((obj != null) ? ((Il2CppObjectBase)obj).TryCast<CraftingRecipeDatabase>() : null);
			if (((val3 != null) ? val3._recipes : null) != null && ((Object)(object)val2 == (Object)null || val3._recipes.Count > val2._recipes.Count))
			{
				val2 = val3;
			}
			num++;
		}
		return val2;
	}

	private static bool Contains(List<CraftingRecipe> recipes)
	{
		if (recipes == null)
		{
			return false;
		}
		for (int i = 0; i < recipes.Count; i++)
		{
			if ((Object)(object)recipes[i] != (Object)null && ((Object)recipes[i]).name == "RopeMod_RopeRecipe")
			{
				return true;
			}
		}
		return false;
	}

	private void ReportOnce(string message)
	{
		if (!_reportedFailure)
		{
			_reportedFailure = true;
			Log.LogWarning((object)message);
		}
	}
}