Decompiled source of BucketPourFurther v1.0.0

BepInEx/plugins/BucketPourFurther/BucketPourFurther.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("BucketPourFurther")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BucketPourFurther")]
[assembly: AssemblyTitle("BucketPourFurther")]
[assembly: AssemblyVersion("1.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 BucketPourFurther
{
	[BepInPlugin("com.DogEggz.BucketPourFurther", "BucketPourFurther", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private const string PluginGuid = "com.DogEggz.BucketPourFurther";

		private const string PluginName = "BucketPourFurther";

		private const string PluginVersion = "1.0.0";

		private Harmony harmony;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			harmony = new Harmony("com.DogEggz.BucketPourFurther");
			harmony.PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BucketPourFurther 1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(Mug), "Spill")]
	internal static class MugSpillPatch
	{
		private const float VanillaPourOffset = 0.3f;

		private static readonly FieldInfo BottleField = AccessTools.Field(typeof(Mug), "bottle");

		private static readonly MethodInfo VectorMultiplyMethod = AccessTools.Method(typeof(Vector3), "op_Multiply", new Type[2]
		{
			typeof(Vector3),
			typeof(float)
		}, (Type[])null);

		private static readonly MethodInfo SelectPourOffsetMethod = AccessTools.Method(typeof(MugSpillPatch), "SelectPourOffset", (Type[])null, (Type[])null);

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (LoadsVanillaPourOffset(list[i]) && object.Equals(list[i + 1].operand, VectorMultiplyMethod))
				{
					CodeInstruction val = list[i];
					CodeInstruction val2 = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					val2.labels.AddRange(val.labels);
					val2.blocks.AddRange(val.blocks);
					list[i] = val2;
					list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)SelectPourOffsetMethod));
					return list;
				}
			}
			Debug.LogError((object)"[BucketPourFurther] Could not find the vanilla Mug.Spill pour offset.");
			return list;
		}

		private static float SelectPourOffset(Mug mug)
		{
			if (!IsSeaWaterBucket(mug))
			{
				return 0.3f;
			}
			return 0.6f;
		}

		private static bool IsSeaWaterBucket(Mug mug)
		{
			ShipItemBottle val = (ShipItemBottle)(((Object)(object)mug == (Object)null || BottleField == null) ? null : /*isinst with value type is only supported in some contexts*/);
			if ((Object)(object)val != (Object)null && val.GetCapacity() == 9f)
			{
				return ((ShipItem)val).amount == 9f;
			}
			return false;
		}

		private static bool LoadsVanillaPourOffset(CodeInstruction instruction)
		{
			if (instruction.opcode == OpCodes.Ldc_R4 && instruction.operand is float num)
			{
				return num == 0.3f;
			}
			return false;
		}
	}
}