Decompiled source of DeathsquitoSurfingFix v1.0.0

DeathsquitoSurfingFix.dll

Decompiled a day 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 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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("DeathsquitoSurfingFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b779526d3487d56d0157b799c569a346fc137d52")]
[assembly: AssemblyProduct("DeathsquitoSurfingFix")]
[assembly: AssemblyTitle("DeathsquitoSurfingFix")]
[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 DeathsquitoSurfingFix
{
	[BepInPlugin("alari.valheim.deathsquitosurfingfix", "Deathsquito Surfing Fix", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Fix Valheim 1.0's ice-slipping layer check so standing on creatures no longer counts as ice. Requires restart.");
			harmony = new Harmony("alari.valheim.deathsquitosurfingfix");
			harmony.PatchAll(typeof(Plugin).Assembly);
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch]
	internal static class SlipperyLayerFix
	{
		private static readonly FieldInfo Mask = AccessTools.Field(typeof(Character), "s_slipperyStuffMask");

		private static readonly MethodInfo GetLayer = AccessTools.PropertyGetter(typeof(GameObject), "layer");

		private static readonly MethodInfo Bit = AccessTools.Method(typeof(SlipperyLayerFix), "LayerBit", (Type[])null, (Type[])null);

		private static bool Prepare()
		{
			return Plugin.Enabled.Value;
		}

		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(Character), "UpdateWalking", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Character), "ApplySlippery", (Type[])null, (Type[])null);
		}

		private static int LayerBit(int layer)
		{
			return 1 << layer;
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes, MethodBase original)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(codes);
			int num = 0;
			for (int i = 0; i < list.Count; i++)
			{
				if (!CodeInstructionExtensions.LoadsField(list[i], Mask, false))
				{
					continue;
				}
				for (int j = i + 1; j < list.Count && j <= i + 6; j++)
				{
					if (CodeInstructionExtensions.Calls(list[j], GetLayer) && j + 1 < list.Count && !(list[j + 1].opcode != OpCodes.And))
					{
						list.Insert(j + 1, new CodeInstruction(OpCodes.Call, (object)Bit));
						num++;
						break;
					}
				}
			}
			if (num == 1)
			{
				Plugin.Log.LogInfo((object)("Fixed slippery layer check in Character." + original.Name + "."));
			}
			else
			{
				Plugin.Log.LogWarning((object)("Expected 1 slippery layer check in Character." + original.Name + ", fixed " + num + ". The game may have changed or already fixed this; the patch did nothing here."));
			}
			return list;
		}
	}
}