Decompiled source of TulipSnakeFlashbang v1.0.0

plugins/SnakeFlashbang.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using EmotesAPI;
using GameNetcodeStuff;
using LcEmotes2AndKnucklesFeaturingDante.Common;
using LcEmotes2AndKnucklesFeaturingDante.Utils;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using SnakeFlashbang.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;

[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("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("LethalVRM")]
[assembly: IgnoresAccessChecksTo("MToon")]
[assembly: IgnoresAccessChecksTo("UniGLTF")]
[assembly: IgnoresAccessChecksTo("UniGLTF.Utils")]
[assembly: IgnoresAccessChecksTo("UniHumanoid")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("VRM10")]
[assembly: IgnoresAccessChecksTo("VrmLib")]
[assembly: IgnoresAccessChecksTo("VRMShaders.GLTF.IO.Runtime")]
[assembly: IgnoresAccessChecksTo("VRMShaders.VRM.IO.Runtime")]
[assembly: IgnoresAccessChecksTo("VRMShaders.VRM10.Format.Runtime")]
[assembly: IgnoresAccessChecksTo("VRMShaders.VRM10.MToon10.Runtime")]
[assembly: AssemblyCompany("SnakeFlashbang")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+83e3cfacfa0a0934f3b22b24680b5ce3850465cf")]
[assembly: AssemblyProduct("SnakeFlashbang")]
[assembly: AssemblyTitle("SnakeFlashbang")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 LcEmotes2AndKnucklesFeaturingDante
{
	internal static class Assets
	{
		private static readonly List<AssetBundle> AssetBundles = new List<AssetBundle>();

		private static readonly Dictionary<string, int> AssetIndices = new Dictionary<string, int>();

		public static void LoadAllAssetBundles()
		{
			foreach (string item in Directory.EnumerateFiles(FsUtils.AssetBundlesDir, "*", SearchOption.AllDirectories))
			{
				string text = item;
				if (text.StartsWith(FsUtils.AssetBundlesDir))
				{
					string text2 = text;
					int length = FsUtils.AssetBundlesDir.Length;
					text = text2.Substring(length, text2.Length - length);
				}
				while (text.StartsWith("/") || text.StartsWith("\\"))
				{
					string text2 = text;
					text = text2.Substring(1, text2.Length - 1);
				}
				AddBundle(text);
			}
		}

		public static void AddBundle(string bundleName)
		{
			string text = Path.Combine(FsUtils.AssetBundlesDir, bundleName);
			AssetBundle val = AssetBundle.LoadFromFile(text);
			int count = AssetBundles.Count;
			AssetBundles.Add(val);
			string[] allAssetNames = val.GetAllAssetNames();
			foreach (string text2 in allAssetNames)
			{
				string text3 = text2.ToLowerInvariant();
				if (text3.StartsWith("assets/"))
				{
					string text4 = text3;
					int length = "assets/".Length;
					text3 = text4.Substring(length, text4.Length - length);
				}
				AssetIndices[text3] = count;
			}
		}

		public static T? Load<T>(string assetName) where T : Object
		{
			try
			{
				assetName = assetName.ToLowerInvariant();
				if (assetName.StartsWith("assets/"))
				{
					string text = assetName;
					int length = "assets/".Length;
					assetName = text.Substring(length, text.Length - length);
				}
				int index = AssetIndices[assetName];
				return AssetBundles[index].LoadAsset<T>("assets/" + assetName);
			}
			catch (Exception arg)
			{
				ManualLogSource? logger = SnakeFlashbang.Logger;
				if (logger != null)
				{
					logger.LogError((object)$"Couldn't load asset [{assetName}] exception: {arg}");
				}
				return default(T);
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.gemumoddo.snake_flashbang", "Snake Flashbang", "1.0.0")]
	public class SnakeFlashbang : BaseUnityPlugin
	{
		public const string ModGuid = "com.gemumoddo.snake_flashbang";

		public const string ModName = "Snake Flashbang";

		public const string ModVersion = "1.0.0";

		public static PluginInfo? PluginInfo { get; private set; }

		public static ManualLogSource? Logger { get; private set; }

		private void Awake()
		{
			PluginInfo = ((BaseUnityPlugin)this).Info;
			Logger = ((BaseUnityPlugin)this).Logger;
			Assets.LoadAllAssetBundles();
			GameEventBus.InitHooks();
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				try
				{
					MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo[] array2 = methods;
					foreach (MethodInfo methodInfo in array2)
					{
						object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
						if (customAttributes.Length != 0)
						{
							methodInfo.Invoke(null, null);
						}
					}
				}
				catch (Exception)
				{
				}
			}
		}
	}
}
namespace LcEmotes2AndKnucklesFeaturingDante.Utils
{
	internal static class ArrayUtils
	{
		public static T[] Copy<T>(this T[] orig)
		{
			T[] array = new T[orig.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = orig[i];
			}
			return array;
		}
	}
	internal static class FsUtils
	{
		private static string? _assetBundlesDir;

		public static string AssetBundlesDir
		{
			get
			{
				if (_assetBundlesDir == null)
				{
					_assetBundlesDir = GetAssetBundlesDir();
				}
				if (string.IsNullOrEmpty(_assetBundlesDir))
				{
					return "";
				}
				return _assetBundlesDir;
			}
		}

		private static string? GetAssetBundlesDir()
		{
			PluginInfo pluginInfo = SnakeFlashbang.PluginInfo;
			if (pluginInfo == null)
			{
				return null;
			}
			string location = pluginInfo.Location;
			DirectoryInfo parent = Directory.GetParent(location);
			if (parent == null)
			{
				throw new NotSupportedException(BadInstallError());
			}
			string text = Path.Combine(parent.FullName, "AssetBundles");
			if (!Directory.Exists(text))
			{
				throw new NotSupportedException(BadInstallError());
			}
			return text;
			static string BadInstallError()
			{
				string text2 = "Snake Flashbang";
				string text3 = "LcEmotes2AndKnucklesFeaturingDante.dll";
				string text4 = text2 + " can't find it's required AssetBundles!\n Make sure that the file `" + text3 + "` is in its own folder like `BepInEx/plugins/" + text2 + "/" + text3 + "` and that the folder `AssetBundles` is in the same folder as `" + text3 + "`!";
				ManualLogSource? logger = SnakeFlashbang.Logger;
				if (logger != null)
				{
					logger.LogError((object)text4);
				}
				return text4;
			}
		}
	}
	internal static class HookUtils
	{
		private const BindingFlags DefaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private const BindingFlags StaticFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		public static Hook NewHook<TTarget, TDest>(string targetMethodName, string destMethodName, TDest instance)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			MethodInfo method = typeof(TTarget).GetMethod(targetMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo method2 = typeof(TDest).GetMethod(destMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			return new Hook((MethodBase)method, method2, (object)instance);
		}

		public static Hook NewHook<TTarget>(string targetMethodName, MethodInfo destMethod)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			MethodInfo method = typeof(TTarget).GetMethod(targetMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			return new Hook((MethodBase)method, destMethod);
		}

		public static Hook NewHook<TTarget>(string targetMethodName, Type destType, string destMethodName, bool isStatic)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			if (isStatic)
			{
				MethodInfo method = typeof(TTarget).GetMethod(targetMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo method2 = destType.GetMethod(destMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				return new Hook((MethodBase)method, method2);
			}
			MethodInfo method3 = typeof(TTarget).GetMethod(targetMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo method4 = destType.GetMethod(destMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			return new Hook((MethodBase)method3, method4);
		}
	}
	public readonly struct Optional<T>
	{
		private readonly T? _value;

		public bool HasValue { get; }

		private Optional(T value)
		{
			HasValue = false;
			_value = value;
			HasValue = true;
		}

		public bool TryGetValue(out T? value)
		{
			value = _value;
			return HasValue;
		}

		public static Optional<T> Some(T value)
		{
			return new Optional<T>(value);
		}

		public static Optional<T> None()
		{
			return default(Optional<T>);
		}
	}
}
namespace LcEmotes2AndKnucklesFeaturingDante.Common
{
	public class FaceCameraProxy : MonoBehaviour
	{
		private Camera? _targetCamera;

		public Transform? targetToRotate;

		public bool copyX;

		public bool copyY;

		public bool copyZ;

		private void Update()
		{
			if (targetToRotate != null)
			{
				if (_targetCamera == null)
				{
					_targetCamera = FindBestCamera();
				}
				if (_targetCamera != null)
				{
					((Component)this).transform.LookAt(((Component)_targetCamera).transform);
					((Component)this).transform.Rotate(0f, 180f, 0f, (Space)1);
				}
			}
		}

		private void LateUpdate()
		{
			//IL_0019: 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_0025: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (targetToRotate != null)
			{
				Vector3 eulerAngles = ((Component)this).transform.eulerAngles;
				Vector3 eulerAngles2 = targetToRotate.eulerAngles;
				if (!copyX)
				{
					((Vector3)(ref eulerAngles))..ctor(eulerAngles2.x, eulerAngles.y, eulerAngles.z);
				}
				if (!copyY)
				{
					((Vector3)(ref eulerAngles))..ctor(eulerAngles.x, eulerAngles2.y, eulerAngles.z);
				}
				if (!copyZ)
				{
					((Vector3)(ref eulerAngles))..ctor(eulerAngles.x, eulerAngles.y, eulerAngles2.z);
				}
				targetToRotate.eulerAngles = eulerAngles;
			}
		}

		private Camera? FindBestCamera()
		{
			if (StartOfRound.Instance != null && StartOfRound.Instance.localPlayerController != null)
			{
				return StartOfRound.Instance.localPlayerController.gameplayCamera;
			}
			if (Camera.current != null)
			{
				return Camera.current;
			}
			return null;
		}
	}
	internal static class GameEventBus
	{
		private static Hook? snakeAttachHook;

		public static event Action? OnRadiationWarningHUD;

		public static void InitHooks()
		{
			snakeAttachHook = HookUtils.NewHook<FlowerSnakeEnemy>("SetClingToPlayer", typeof(GameEventBus), "SetClingToPlayer", isStatic: false);
		}

		private static void SetClingToPlayer(Action<FlowerSnakeEnemy, PlayerControllerB, int, float> orig, FlowerSnakeEnemy self, PlayerControllerB playerToCling, int setClingPosition, float clingTime)
		{
			orig(self, playerToCling, setClingPosition, clingTime);
			CustomEmotesAPI.PlayAnimation("com.weliveinasociety.badasscompany__Float", BoneMapper.playersToMappers[((Component)self).gameObject], -2);
		}
	}
	public class Emotes2Networking : NetworkBehaviour
	{
		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "Emotes2Networking";
		}
	}
	public class SelfDestruct : MonoBehaviour
	{
		public float timeUntilDestruction = 5f;

		private void OnEnable()
		{
			Object.Destroy((Object)(object)((Component)this).gameObject, timeUntilDestruction);
		}
	}
}
namespace LcEmotes2AndKnucklesFeaturingDante.Common.Rand
{
	public abstract class WeightedEntry<TEntry> : ScriptableObject
	{
		public float weight;

		[SerializeReference]
		public TEntry? entry;

		public void Deconstruct(out float weight, out TEntry? entry)
		{
			weight = this.weight;
			entry = this.entry;
		}
	}
	public abstract class WeightedRandomData<TEntry> : ScriptableObject
	{
		public WeightedEntry<TEntry>[] weightedEntries = Array.Empty<WeightedEntry<TEntry>>();

		public Optional<TEntry> GetRandomEntry()
		{
			if (weightedEntries.Length == 0)
			{
				return Optional<TEntry>.None();
			}
			float num = 0f;
			WeightedEntry<TEntry>[] array = weightedEntries;
			float weight;
			TEntry entry;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].Deconstruct(out weight, out entry);
				float num2 = weight;
				TEntry val = entry;
				if (val != null)
				{
					if (float.IsPositiveInfinity(num2))
					{
						return Optional<TEntry>.Some(val);
					}
					if (num2 >= 0f && !float.IsNaN(num2))
					{
						num += num2;
					}
				}
			}
			float value = Random.value;
			float num3 = 0f;
			WeightedEntry<TEntry>[] array2 = weightedEntries;
			for (int j = 0; j < array2.Length; j++)
			{
				array2[j].Deconstruct(out weight, out entry);
				float num4 = weight;
				TEntry val2 = entry;
				if (val2 != null && !float.IsNaN(num4) && !(num4 <= 0f))
				{
					num3 += num4 / num;
					if (num3 >= value)
					{
						return Optional<TEntry>.Some(val2);
					}
				}
			}
			return Optional<TEntry>.None();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace SnakeFlashbang.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}