Decompiled source of Butter Take Wind Cover v1.0.0

WindCover.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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;
		}
	}
}
[BepInPlugin("dairymods.windcover", "Wind Cover", "1.0.0")]
public class WindCoverPlugin : BaseUnityPlugin
{
	private ConfigEntry<bool> enabledCfg;

	private ConfigEntry<bool> showCountdown;

	private static readonly MethodInfo intensityAt = AccessTools.Method(typeof(WindChillZone), "GetWindIntensityAtPoint", (Type[])null, (Type[])null);

	private static readonly FieldInfo windDir = AccessTools.Field(typeof(WindChillZone), "currentWindDirection");

	private static readonly FieldInfo untilSwitch = AccessTools.Field(typeof(WindChillZone), "untilSwitch");

	private WindChillZone[] zones = (WindChillZone[])(object)new WindChillZone[0];

	private float nextScan;

	private string line1;

	private string line2;

	private Color colour;

	private void Awake()
	{
		enabledCfg = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "");
		showCountdown = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Show Countdown", true, "Seconds until the wind starts or stops.");
		if (intensityAt == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"WindChillZone.GetWindIntensityAtPoint not found: game update changed it. Wind Cover is off.");
		}
	}

	private void Update()
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		line1 = null;
		Character localCharacter = Character.localCharacter;
		if (!enabledCfg.Value || intensityAt == null || !Object.op_Implicit((Object)(object)localCharacter))
		{
			return;
		}
		if (Time.time >= nextScan)
		{
			nextScan = Time.time + 2f;
			zones = Object.FindObjectsByType<WindChillZone>((FindObjectsSortMode)0);
		}
		WindChillZone val = null;
		WindChillZone[] array = zones;
		foreach (WindChillZone val2 in array)
		{
			if (Object.op_Implicit((Object)(object)val2) && ((Behaviour)val2).isActiveAndEnabled && ((Bounds)(ref val2.windZoneBounds)).Contains(localCharacter.Center))
			{
				val = val2;
				break;
			}
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		float num = (float)intensityAt.Invoke(null, new object[3] { localCharacter.Center, val.lightVolumeSampleThreshold_lower, val.lightVolumeSampleThreshold_margin });
		int num2 = Mathf.RoundToInt((1f - num) * 100f);
		colour = ((num2 >= 99) ? new Color(0.3f, 1f, 0.4f) : ((num2 > 0) ? new Color(1f, 0.9f, 0.3f) : new Color(1f, 0.35f, 0.3f)));
		line1 = ((num2 >= 99) ? "Wind cover: full" : ((num2 > 0) ? $"Wind cover: {num2}%" : "Wind cover: none"));
		line2 = (val.windActive ? "Wind blowing" : "Calm");
		if (showCountdown.Value && untilSwitch != null)
		{
			float num3 = (float)untilSwitch.GetValue(val);
			if (num3 > 0f)
			{
				line2 += (val.windActive ? $", ends in {num3:0} s" : $", wind in {num3:0} s");
			}
		}
		if (val.windActive && val.useRaycast && windDir != null)
		{
			Vector3 val3 = (Vector3)windDir.GetValue(val);
			RaycastHit val4 = default(RaycastHit);
			if (val3 != Vector3.zero && Physics.Raycast(localCharacter.Center, -val3, ref val4, val.maxRaycastDistance, LayerMask.op_Implicit(HelperFunctions.terrainMapMask)))
			{
				float num4 = Mathf.Clamp01(Mathf.InverseLerp(val.minRaycastDistance, val.maxRaycastDistance, ((RaycastHit)(ref val4)).distance) + 1f - Mathf.Clamp01(Vector3.Dot(((RaycastHit)(ref val4)).normal, val3)));
				line2 += $", push {num4 * 100f:0}%";
			}
		}
	}

	private void OnGUI()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		if ((int)Event.current.type == 7 && line1 != null)
		{
			Draw.Text(new Rect(0f, (float)Screen.height * 0.05f, (float)Screen.width, 30f), line1, colour, 20, (TextAnchor)1);
			Draw.Text(new Rect(0f, (float)Screen.height * 0.05f + 26f, (float)Screen.width, 24f), line2, Color.white, 15, (TextAnchor)1);
		}
	}
}
internal static class Draw
{
	private static GUIStyle style;

	public static Camera Cam
	{
		get
		{
			MainCamera instance = MainCamera.instance;
			Camera val = (Object.op_Implicit((Object)(object)instance) ? ((Component)instance).GetComponent<Camera>() : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return Camera.main;
			}
			return val;
		}
	}

	public static bool ToGui(Camera cam, Vector3 world, out Vector2 gui)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//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_0033: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = cam.WorldToViewportPoint(world);
		gui = new Vector2(val.x * (float)Screen.width, (1f - val.y) * (float)Screen.height);
		return val.z > 0f;
	}

	public static void Line(Vector2 a, Vector2 b, Color c, float width)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		Matrix4x4 matrix = GUI.matrix;
		Vector2 val = b - a;
		GUI.color = c;
		GUIUtility.RotateAroundPivot(Mathf.Atan2(val.y, val.x) * 57.29578f, a);
		GUI.DrawTexture(new Rect(a.x, a.y - width / 2f, ((Vector2)(ref val)).magnitude, width), (Texture)(object)Texture2D.whiteTexture);
		GUI.matrix = matrix;
		GUI.color = Color.white;
	}

	public static void Dot(Vector2 p, Color c, float size)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		GUI.color = c;
		GUI.DrawTexture(new Rect(p.x - size / 2f, p.y - size / 2f, size, size), (Texture)(object)Texture2D.whiteTexture);
		GUI.color = Color.white;
	}

	public static void Text(Rect r, string s, Color c, int size = 18, TextAnchor anchor = (TextAnchor)0)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		if (style == null)
		{
			style = new GUIStyle(GUI.skin.label)
			{
				fontStyle = (FontStyle)1,
				wordWrap = false
			};
		}
		style.fontSize = size;
		style.alignment = anchor;
		style.normal.textColor = new Color(0f, 0f, 0f, c.a * 0.8f);
		GUI.Label(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), s, style);
		style.normal.textColor = c;
		GUI.Label(r, s, style);
	}
}