Decompiled source of LEBWeatherFix v0.1.0

Sniper1_1.LEBWeatherFix.dll

Decompiled 2 months 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;
using VoxxWeatherPlugin;
using VoxxWeatherPlugin.Utils;
using VoxxWeatherPlugin.Weathers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("voxx.LethalElementsPlugin")]
[assembly: AssemblyCompany("Sniper1_1.LEBWeatherFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+34d75445c41f7e1ff564620a660c9993331f740a")]
[assembly: AssemblyProduct("LEBWeatherFix")]
[assembly: AssemblyTitle("Sniper1_1.LEBWeatherFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 LEBWeatherFix
{
	[BepInPlugin("Sniper1_1.LEBWeatherFix", "LEBWeatherFix", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LEBWeatherFix : BaseUnityPlugin
	{
		internal static bool HasPatched;

		public static LEBWeatherFix Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"Come back v0xx. We miss you :(");
			Logger.LogInfo((object)"Sniper1_1.LEBWeatherFix v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Sniper1_1.LEBWeatherFix");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Sniper1_1.LEBWeatherFix";

		public const string PLUGIN_NAME = "LEBWeatherFix";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LEBWeatherFix.Patches
{
	[HarmonyPatch(typeof(SnowfallVFXManager), "PopulateLevelWithVFX")]
	public class SnowfallWeatherPatch
	{
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			LEBWeatherFix.Logger.LogDebug((object)"Transpiler called for Snowfall's PopulateLevelWithVFX");
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(SnowfallVFXManager), "JingleBells", (Type[])null, (Type[])null);
			LEBWeatherFix.Logger.LogDebug((object)$"Found original JingleBells method call: {methodInfo != null}");
			MethodInfo methodInfo2 = AccessTools.Method(typeof(SnowfallWeatherPatch), "JingleBells_Replacement", (Type[])null, (Type[])null);
			LEBWeatherFix.Logger.LogDebug((object)$"Found replacement JingleBells_Replacement method: {methodInfo2 != null}");
			if (methodInfo == null || methodInfo2 == null)
			{
				LEBWeatherFix.Logger.LogError((object)"Failed to find one of the above methods!");
				return list;
			}
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(list[i], methodInfo))
				{
					LEBWeatherFix.Logger.LogDebug((object)$"Replacing call at index {i} with custom method.");
					list[i] = new CodeInstruction(OpCodes.Call, (object)methodInfo2);
				}
			}
			return list;
		}

		public static void JingleBells_Replacement(SnowfallVFXManager __instance)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			LEBWeatherFix.Logger.LogDebug((object)"Calling JingleBells_Replacement");
			if ((Object)(object)__instance.giftBoxItem == (Object)null)
			{
				Debug.LogError("Gift box item not found in the item database!");
				return;
			}
			Debug.Log("Merry Christmas!");
			int num = 24;
			bool flag = false;
			Vector3 val = Vector3.zero;
			while (num-- > 0)
			{
				int num2 = ((BaseVFXManager)__instance).SeededRandom?.Next(0, RoundManager.Instance.outsideAINodes.Length) ?? 0;
				Vector3 position = RoundManager.Instance.outsideAINodes[num2].transform.position;
				RoundManager instance = RoundManager.Instance;
				Random seededRandom = ((BaseVFXManager)__instance).SeededRandom;
				Vector3 randomNavMeshPositionInBoxPredictable = instance.GetRandomNavMeshPositionInBoxPredictable(position, 25f, default(NavMeshHit), seededRandom, -1, 1f);
				randomNavMeshPositionInBoxPredictable = RoundManager.Instance.PositionEdgeCheck(randomNavMeshPositionInBoxPredictable, 7f);
				if (randomNavMeshPositionInBoxPredictable != Vector3.zero)
				{
					val = randomNavMeshPositionInBoxPredictable;
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				Debug.LogDebug("Failed to place a Christmas tree in the level, too many attempts!");
				return;
			}
			Quaternion val2 = Quaternion.Euler(0f, ((float?)((BaseVFXManager)__instance).SeededRandom?.Next(0, 360)) ?? 0f, 0f);
			Object.Instantiate<GameObject>(__instance.christmasTreePrefab, val, val2);
			if (!GameNetworkManager.Instance.isHostingGame)
			{
				return;
			}
			int num3 = Mathf.Min(GameNetworkManager.Instance.connectedPlayers, 4);
			NavMeshHit val4 = default(NavMeshHit);
			for (int i = 0; i < num3; i++)
			{
				int num4 = ((BaseVFXManager)__instance).SeededRandom?.Next(1, 24) ?? 1;
				Vector3 val3 = val + 2f * new Vector3(Mathf.Cos((float)(i * 2) * MathF.PI / (float)num3), 0f, Mathf.Sin((float)(i * 2) * MathF.PI / (float)num3));
				if (NavMesh.SamplePosition(val3, ref val4, 2f, -1))
				{
					RandomExtensions.SpawnAtPosition(__instance.giftBoxItem, ((NavMeshHit)(ref val4)).position, num4);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ToxicSmogVFXManager), "SpawnFumes")]
	public class ToxicSmogWeatherPatch
	{
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			LEBWeatherFix.Logger.LogDebug((object)"Transpiler called for SpawnFumes");
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(ToxicSmogVFXManager), "GetValidSpawnPosition", new Type[4]
			{
				typeof(Vector3),
				typeof(List<Vector3>),
				typeof(NavMeshHit).MakeByRefType(),
				typeof(Random)
			}, (Type[])null);
			LEBWeatherFix.Logger.LogDebug((object)$"Found original GetValidSpawnPosition method call: {methodInfo != null}");
			MethodInfo methodInfo2 = AccessTools.Method(typeof(ToxicSmogWeatherPatch), "GetValidSpawnPosition_Replacement", (Type[])null, (Type[])null);
			LEBWeatherFix.Logger.LogDebug((object)$"Found replacement GetValidSpawnPosition_Replacement method: {methodInfo2 != null}");
			if (methodInfo == null || methodInfo2 == null)
			{
				LEBWeatherFix.Logger.LogError((object)"Failed to find one of the above methods!");
				return list;
			}
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(list[i], methodInfo))
				{
					LEBWeatherFix.Logger.LogDebug((object)$"Replacing call at index {i} with custom method.");
					list[i] = new CodeInstruction(OpCodes.Call, (object)methodInfo2);
				}
			}
			return list;
		}

		public static Vector3 GetValidSpawnPosition_Replacement(ToxicSmogVFXManager __instance, Vector3 objectPosition, List<Vector3> blockedPositions, ref NavMeshHit navHit, Random random)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			LEBWeatherFix.Logger.LogDebug((object)"Calling GetValidSpawnPosition_Replacement");
			Vector3 randomNavMeshPositionInBoxPredictable = RoundManager.Instance.GetRandomNavMeshPositionInBoxPredictable(objectPosition, __instance.spawnRadius, navHit, random, -1, 1f);
			if (__instance.IsPositionValid(randomNavMeshPositionInBoxPredictable, blockedPositions))
			{
				return randomNavMeshPositionInBoxPredictable;
			}
			return Vector3.zero;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}