Decompiled source of Fair SnowStorm Winds v1.0.4

plugins/An0n_Fair_SnowStorm.dll

Decompiled 3 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using An0n_Patches.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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("An0n_Patches")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("An0n_Patches")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("415f18a2-c213-4036-b3f0-7673c0a38c58")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace An0n_Patches
{
	[BepInPlugin("com.an0n.fairSnowStorm", "An0n Fair SnowStorm", "1.0.1")]
	public class An0n_Patch_Plugin : BaseUnityPlugin
	{
		public const string pluginGUID = "com.an0n.fairSnowStorm";

		private const string pluginName = "An0n Fair SnowStorm";

		private const string pluginVersion = "1.0.1";

		public static ConfigEntry<float> objectDist;

		public static ManualLogSource mls = Logger.CreateLogSource("com.an0n.fairSnowStorm");

		private Harmony harmony = new Harmony("com.an0n.fairSnowStorm");

		public static An0n_Patch_Plugin instance;

		public static string soundLoc;

		private Harmony patcher;

		private void Awake()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			objectDist = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Object Distance", 10f, "How far away a wall/tree/rock/object is to consider you shielded from the wind. (Lower = you need to be closer)");
			instance = this;
			Debug.Log((object)"[An0nPatch] An0n Fair SnowStorm Plugin 1.0.1 Loaded!");
			patcher = new Harmony("com.an0n.fairSnowStorm");
			patcher.PatchAll(typeof(WindPatch));
		}
	}
}
namespace An0n_Patches.Patches
{
	public static class WindPatch
	{
		public static class WindProtection
		{
			public static float checkDistance = An0n_Patch_Plugin.objectDist.Value;

			public static bool IsPlayerProtectedFromWind(Vector3 player)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = (Vector3)Traverse.Create((object)wind).Field("currentWindDirection").GetValue();
				Vector3 val2 = -((Vector3)(ref val)).normalized;
				RaycastHit[] array = (RaycastHit[])(object)new RaycastHit[1];
				int num = Physics.RaycastNonAlloc(player, val2, array, checkDistance, -1, (QueryTriggerInteraction)1);
				if (num > 0)
				{
					return true;
				}
				return false;
			}
		}

		public static WindChillZone wind;

		private static int checkNum;

		private static bool wasProtected;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StormVisual), "Start")]
		public static void AwakePatchWind(WindChillZone __instance)
		{
			wind = GameObject.Find("SnowStorm").GetComponent<WindChillZone>();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(WindChillZone), "AddWindForceToCharacter")]
		public static bool manageWind(WindChillZone __instance)
		{
			if (((Object)__instance).name == "SnowStorm")
			{
				if (wasProtected)
				{
					return false;
				}
				return true;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(WindChillZone), "ApplyCold")]
		public static bool isProtectCheck(WindChillZone __instance)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)__instance).name == "SnowStorm")
			{
				if (checkNum == 10)
				{
					checkNum = 0;
					if (((Object)__instance).name == "SnowStorm")
					{
						if (WindProtection.IsPlayerProtectedFromWind(Character.localCharacter.Center))
						{
							wasProtected = true;
							__instance.characterInsideBounds = false;
							return false;
						}
						wasProtected = false;
					}
				}
				checkNum++;
				if (wasProtected)
				{
					return false;
				}
				return true;
			}
			return true;
		}
	}
}