Decompiled source of HoneyPlus v5.3.2

HoneyPlus.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HoneyPlus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HoneyPlus")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace HoneyPlus;

[BepInPlugin("OhhLoz-HoneyPlus", "HoneyPlus", "5.3.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class HoneyPlus : BaseUnityPlugin
{
	public const string PluginGUID = "OhhLoz-HoneyPlus";

	public const string PluginName = "HoneyPlus";

	public const string PluginVersion = "5.3.2";

	private const string AssetBundleName = "honeyplusassets";

	private const string RecipeFileName = "recipes.json";

	private const string PieceFileName = "pieces.json";

	private const string cookingConversionFileName = "conversions_cooking.json";

	private const string fermenterConversionFileName = "conversions_fermenter.json";

	private const string enTranslationFileName = "translation_EN.json";

	private const string cnTranslationFileName = "translation_CN.json";

	private const string esTranslationFileName = "translation_ES.json";

	private const string deTranslationFileName = "translation_DE.json";

	private const string ptbrTranslationFileName = "translation_PT-BR.json";

	private const string koTranslationFileName = "translation_KO.json";

	private CustomLocalization Localization;

	private Assembly ModAssembly;

	private AssetBundle HoneyPlusAssetBundle;

	private ConfigEntry<bool> useOldRecipes;

	private ConfigEntry<bool> useMeadRecipes;

	private ConfigEntry<bool> useVanillaRecipeChanges;

	private ConfigEntry<bool> useVanillaRecipeAdditions;

	private ConfigEntry<bool> addJerkysCauldron;

	private GameObject HoneyAttach;

	private void Awake()
	{
		ModAssembly = typeof(HoneyPlus).Assembly;
		HoneyPlusAssetBundle = AssetUtils.LoadAssetBundleFromResources("honeyplusassets", ModAssembly);
		Logger.LogInfo((object)$"Loaded asset bundle: {HoneyPlusAssetBundle}");
		CreateConfigValues();
		ItemManager.OnItemsRegistered += OnItemsRegistered;
		if (!useOldRecipes.Value)
		{
			AddCustomPieces();
		}
		HoneyAttach = HoneyPlusAssetBundle.LoadAsset<GameObject>("HoneyAttach");
		AddCustomItems();
		AddItemConversions();
		AddLocalizations();
		HoneyPlusAssetBundle.Unload(false);
	}

	private void AddCustomItems()
	{
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Expected O, but got Unknown
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Expected O, but got Unknown
		List<RecipeConfig> list = RecipeConfig.ListFromJson(AssetUtils.LoadTextFromResources("recipes.json", ModAssembly));
		Logger.LogInfo((object)"Loaded recipes list");
		foreach (RecipeConfig item in list)
		{
			if ((!useVanillaRecipeAdditions.Value && (item.Item == "Tar" || item.Item == "RoyalJelly")) || (!useMeadRecipes.Value && item.Item.Contains("Mead")))
			{
				continue;
			}
			if (item.Name != null)
			{
				if ((useOldRecipes.Value && item.CraftingStation == "piece_apiary") || (addJerkysCauldron.Value && item.Item.Contains("Jerky")))
				{
					item.CraftingStation = "piece_cauldron";
				}
				ItemManager.Instance.AddRecipe(new CustomRecipe(item));
			}
			if (!(item.Item == "Tar") && !(item.Item == "RoyalJelly"))
			{
				CustomItem val = new CustomItem(HoneyPlusAssetBundle.LoadAsset<GameObject>(item.Item), true);
				ItemManager.Instance.AddItem(val);
				Logger.LogInfo((object)("Loaded Item: " + item.Item));
			}
		}
	}

	private void AddCustomPieces()
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		List<PieceConfig> list = PieceConfig.ListFromJson(AssetUtils.LoadTextFromResources("pieces.json", ModAssembly));
		foreach (PieceConfig item in list)
		{
			if (HoneyPlusAssetBundle.Contains(item.Name))
			{
				PieceManager.Instance.AddPiece(new CustomPiece(HoneyPlusAssetBundle.LoadAsset<GameObject>(item.Name), "Hammer", true));
				Logger.LogInfo((object)("Loaded Piece: " + item.Name));
			}
		}
	}

	private void OnItemsRegistered()
	{
		try
		{
			if (useVanillaRecipeChanges.Value)
			{
				ChangeRecipes();
			}
			ChangeItems();
		}
		catch (Exception ex)
		{
			Logger.LogInfo((object)("Error OnItemsRegistered : " + ex.Message));
		}
		finally
		{
			PrefabManager.OnPrefabsRegistered -= OnItemsRegistered;
		}
	}

	private void ChangeRecipes()
	{
		foreach (Recipe recipe in ObjectDB.instance.m_recipes)
		{
			if (((Object)recipe).name == "Recipe_BoarJerky")
			{
				recipe.m_craftingStation = null;
				Logger.LogInfo((object)"Changed Recipe: BoarJerky");
			}
			else if (((Object)recipe).name == "Recipe_WolfJerky")
			{
				recipe.m_craftingStation = null;
				Logger.LogInfo((object)"Changed Recipe: WolfJerky");
			}
		}
	}

	private void ChangeItems()
	{
		GameObject val = ObjectDB.instance.m_items.Find((GameObject x) => ((Object)x).name == "Honey");
		((Object)HoneyAttach).name = "attach";
		HoneyAttach.transform.SetParent(val.transform);
		Logger.LogInfo((object)"Changed Item: Honey");
	}

	private void AddLocalizations()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Localization = new CustomLocalization();
		LocalizationManager.Instance.AddLocalization(Localization);
		string text = AssetUtils.LoadTextFromResources("translation_EN.json", ModAssembly);
		Localization.AddJsonFile("English", text);
		string text2 = AssetUtils.LoadTextFromResources("translation_CN.json", ModAssembly);
		Localization.AddJsonFile("Chinese", text2);
		string text3 = AssetUtils.LoadTextFromResources("translation_DE.json", ModAssembly);
		Localization.AddJsonFile("German", text3);
		string text4 = AssetUtils.LoadTextFromResources("translation_ES.json", ModAssembly);
		Localization.AddJsonFile("Spanish", text4);
		string text5 = AssetUtils.LoadTextFromResources("translation_PT-BR.json", ModAssembly);
		Localization.AddJsonFile("Portuguese_Brazilian", text5);
		string text6 = AssetUtils.LoadTextFromResources("translation_KO.json", ModAssembly);
		Localization.AddJsonFile("Korean", text6);
	}

	private void AddItemConversions()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		List<CookingConversionConfig> list = CookingConversionConfig.ListFromJson(AssetUtils.LoadTextFromResources("conversions_cooking.json", ModAssembly));
		foreach (CookingConversionConfig item in list)
		{
			ItemManager.Instance.AddItemConversion(new CustomItemConversion((ConversionConfig)(object)item));
		}
		if (!useMeadRecipes.Value)
		{
			return;
		}
		List<FermenterConversionConfig> list2 = FermenterConversionConfig.ListFromJson(AssetUtils.LoadTextFromResources("conversions_fermenter.json", ModAssembly));
		foreach (FermenterConversionConfig item2 in list2)
		{
			ItemManager.Instance.AddItemConversion(new CustomItemConversion((ConversionConfig)(object)item2));
		}
	}

	private void CreateConfigValues()
	{
		//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_0042: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected O, but got Unknown
		//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_00c8: Expected O, but got Unknown
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Expected O, but got Unknown
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Expected O, but got Unknown
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Expected O, but got Unknown
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Expected O, but got Unknown
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		useOldRecipes = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "Use legacy recipes", false, new ConfigDescription("Set to true to add all recipes to the cauldron instead of the custom crafting station (apiary)", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		useVanillaRecipeAdditions = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Add vanilla recipes", true, new ConfigDescription("Set to false to disable addition of vanilla recipes (Tar & Royal Jelly) to apiary/cauldron", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		useVanillaRecipeChanges = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Change vanilla recipes", true, new ConfigDescription("Set to false to disable changing of vanilla recipes (Wolf & Boar Jerky) to hand crafting", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		addJerkysCauldron = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Add jerkys to cauldron", false, new ConfigDescription("Set to true to add the new Jerkys (Neck, Deer & Lox) to the cauldron instead of the hand crafting", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		useMeadRecipes = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Use mead recipes", true, new ConfigDescription("Set to false to disable addition of new meads (Speed & Damage) to the apiary/cauldron", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
	}
}