Decompiled source of FoodBagExtraFoodBridge v1.1.0

FoodBagExtraFoodBridge.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 FoodBagExtraFoodBridge
{
	[BepInPlugin("local.foodbag.extrafoodbridge", "FoodBag ExtraFood Bridge", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BridgePlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "local.foodbag.extrafoodbridge";

		public const string PluginName = "FoodBag ExtraFood Bridge";

		public const string PluginVersion = "1.1.0";

		private const string FoodBagGuid = "ValheimLiteni.FoodBag";

		private const string FoodBagPluginType = "ValheimLiteni.FoodBag.Plugin";

		private const string FoodBagSlotsSection = "2 - Food bag";

		private const string FoodBagSlotsKey = "Slots";

		private const string TargetMethod = "EatOnce";

		private const int NewLimit = 4;

		internal static ManualLogSource Log;

		private Harmony harmony;

		private ConfigEntry<bool> raiseSlots;

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			raiseSlots = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Set Food Bag slots to 4", true, "If Food Bag's Slots setting is exactly 3 (its default), change it to 4. Any other value is left alone. The bag only gets its 4th slot after you restart the game.");
			Type type = AccessTools.TypeByName("ValheimLiteni.FoodBag.Plugin");
			MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "EatOnce", (Type[])null, (Type[])null));
			if (methodInfo == null)
			{
				Log.LogWarning((object)"No se encontro ValheimLiteni.FoodBag.Plugin::EatOnce. La version de FoodBag cambio; no se aplica el parche.");
				return;
			}
			harmony = new Harmony("local.foodbag.extrafoodbridge");
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(BridgePlugin), "EatOnceTranspiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
			Log.LogInfo((object)("Listo: FoodBag ahora come hasta " + 4 + " comidas activas."));
			if (raiseSlots.Value)
			{
				RaiseFoodBagSlots();
			}
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private static void RaiseFoodBagSlots()
		{
			if (!Chainloader.PluginInfos.TryGetValue("ValheimLiteni.FoodBag", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				Log.LogWarning((object)"No se encontro el plugin de FoodBag; no se cambia Slots.");
				return;
			}
			ConfigEntry<int> val = default(ConfigEntry<int>);
			if (!value.Instance.Config.TryGetEntry<int>("2 - Food bag", "Slots", ref val))
			{
				Log.LogWarning((object)"No se encontro la opcion '2 - Food bag / Slots' de FoodBag; no se cambia.");
				return;
			}
			if (val.Value != 3)
			{
				Log.LogInfo((object)("Slots de FoodBag esta en " + val.Value + "; se deja como esta."));
				return;
			}
			val.Value = 4;
			Log.LogInfo((object)("Slots de FoodBag estaba en 3 y ahora es " + 4 + ". Reinicia el juego para que aparezca el cuarto slot de la bolsa."));
		}

		private static IEnumerable<CodeInstruction> EatOnceTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			List<int> list2 = new List<int>();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_I4_3)
				{
					list2.Add(i);
				}
			}
			if (list2.Count != 1)
			{
				Log.LogWarning((object)("EatOnce cambio (se esperaba un ldc.i4.3, hay " + list2.Count + "). Parche omitido por seguridad."));
				return list;
			}
			list[list2[0]].opcode = OpCodes.Ldc_I4_4;
			list[list2[0]].operand = null;
			return list;
		}
	}
}