Decompiled source of Flashbang v1.1.0

plugins/Flashbang.dll

Decompiled a day ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using R2API;
using R2API.Networking;
using R2API.Networking.Interfaces;
using RoR2;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.UI;

[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: AssemblyCompany("Flashbang")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3b669d6b6c787141b88de75935e61475b13297ca")]
[assembly: AssemblyProduct("Flashbang")]
[assembly: AssemblyTitle("Flashbang")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 Flashbang
{
	public static class Assets
	{
		public static AssetBundle mainAssetBundle = null;

		internal static string assetBundleName = "flashbang";

		internal static string assemblyDir => Path.GetDirectoryName(Flashbang.pluginInfo.Location);

		public static void PopulateAssets()
		{
			mainAssetBundle = AssetBundle.LoadFromFile(Path.Combine(assemblyDir, assetBundleName));
		}
	}
	internal static class SoundBanks
	{
		private static bool initialized;

		public static string SoundBankDirectory => Path.Combine(Assets.assemblyDir);

		public static void Init()
		{
			//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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Invalid comparison between Unknown and I4
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			if (!initialized)
			{
				initialized = true;
				AKRESULT val = AkSoundEngine.AddBasePath(SoundBankDirectory);
				if ((int)val == 1)
				{
					Log.Info("Added bank base path : " + SoundBankDirectory);
				}
				else
				{
					Log.Error("Error adding base path : " + SoundBankDirectory + " " + $"Error code : {val}");
				}
				uint num = default(uint);
				AkSoundEngine.LoadBank("flashbang.bnk", ref num);
				if ((int)val == 1)
				{
					Log.Info("Added bank : flashbang.bnk");
				}
				else
				{
					Log.Error("Error loading bank : flashbang.bnk " + $"Error code : {val}");
				}
			}
		}
	}
	[BepInPlugin("bouncyshield.Flashbang", "Flashbang", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Flashbang : BaseUnityPlugin
	{
		public class Sink : INetMessage, ISerializableObject
		{
			private NetworkInstanceId playerId;

			private NetworkInstanceId sourceId;

			private bool withinRange;

			public Sink()
			{
			}

			public Sink(NetworkInstanceId playerId, NetworkInstanceId sourceId, bool withinRange)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: 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)
				this.playerId = playerId;
				this.sourceId = sourceId;
				this.withinRange = withinRange;
			}

			public void Serialize(NetworkWriter writer)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				writer.Write(playerId);
				writer.Write(sourceId);
				writer.Write(withinRange);
			}

			public void Deserialize(NetworkReader reader)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: 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)
				playerId = reader.ReadNetworkId();
				sourceId = reader.ReadNetworkId();
				withinRange = reader.ReadBoolean();
			}

			public void OnReceived()
			{
				//IL_0002: 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_0045: Unknown result type (might be due to invalid IL or missing references)
				if (playerId == LocalUserManager.GetFirstLocalUser().cachedMaster.networkIdentity.netId)
				{
					if (withinRange)
					{
						Instance.FlashbangPlayer();
					}
					else
					{
						Instance.BangPlayer(sourceId);
					}
				}
			}
		}

		public const string PluginGUID = "bouncyshield.Flashbang";

		public const string PluginAuthor = "bouncyshield";

		public const string PluginName = "Flashbang";

		public const string PluginVersion = "1.0.0";

		public static PluginInfo pluginInfo;

		public static Flashbang Instance;

		private HUD hud;

		private GameObject Whitescreen;

		private GameObject Dizzyscreen;

		private float alpha;

		private EquipmentDef flashbang;

		public void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			pluginInfo = ((BaseUnityPlugin)this).Info;
			Log.Init(((BaseUnityPlugin)this).Logger);
			Assets.PopulateAssets();
			Instance = this;
			HUD.Awake += new hook_Awake(GetHud);
			EquipmentSlot.PerformEquipmentAction += new hook_PerformEquipmentAction(EquipmentActivate);
			CreateEquipment();
			NetworkingAPI.RegisterMessageType<Sink>();
		}

		public void OnDestroy()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			HUD.Awake -= new hook_Awake(GetHud);
			EquipmentSlot.PerformEquipmentAction -= new hook_PerformEquipmentAction(EquipmentActivate);
		}

		private void GetHud(orig_Awake orig, HUD self)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0054: 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)
			//IL_006c: 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)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			SoundBanks.Init();
			hud = self;
			Dizzyscreen = new GameObject("Dizzyscreen");
			Dizzyscreen.transform.SetParent(hud.mainContainer.transform);
			RectTransform val = Dizzyscreen.AddComponent<RectTransform>();
			val.anchorMin = Vector2.zero;
			val.anchorMax = Vector2.one;
			val.sizeDelta = Vector2.zero;
			val.anchoredPosition = Vector2.zero;
			Dizzyscreen.AddComponent<Image>();
			Whitescreen = new GameObject("Whitescreen");
			Whitescreen.transform.SetParent(hud.mainContainer.transform);
			val = Whitescreen.AddComponent<RectTransform>();
			val.anchorMin = Vector2.zero;
			val.anchorMax = Vector2.one;
			val.sizeDelta = Vector2.zero;
			val.anchoredPosition = Vector2.zero;
			Image val2 = Whitescreen.AddComponent<Image>();
			val2.sprite = Sprite.Create(Texture2D.whiteTexture, new Rect(0f, 0f, 4f, 4f), Vector2.zero);
			FlashAlpha(0f);
		}

		private void FlashAlpha(float x)
		{
			//IL_001c: 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)
			((Graphic)Whitescreen.GetComponent<Image>()).color = new Color(1f, 1f, 1f, x);
			((Graphic)Dizzyscreen.GetComponent<Image>()).color = new Color(1f, 1f, 1f, x);
		}

		private void FlashbangPlayer()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Whitescreen != (Object)null && (Object)(object)Dizzyscreen != (Object)null)
			{
				Texture2D val = ScreenCapture.CaptureScreenshotAsTexture();
				Dizzyscreen.GetComponent<Image>().sprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero);
				((MonoBehaviour)this).StartCoroutine(Fade());
				AkSoundEngine.PostEvent(2753768932u, ((Component)Run.instance).gameObject);
				Log.Info("Flashbang!");
			}
			else
			{
				Log.Warning("Bad flashbang...");
			}
		}

		private void BangPlayer(NetworkInstanceId sourceId)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			CharacterMaster val = CharacterMaster.instancesList.Find((CharacterMaster x) => x.networkIdentity.netId == sourceId);
			AkSoundEngine.PostEvent(2315197877u, ((Component)val.GetBody()).gameObject);
		}

		private IEnumerator Fade()
		{
			alpha = 1f;
			FlashAlpha(alpha);
			while (alpha >= 0f)
			{
				yield return (object)new WaitForSeconds(0.04f);
				alpha -= 0.01f * (2f - alpha);
				FlashAlpha(alpha);
			}
		}

		private void CreateEquipment()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			flashbang = ScriptableObject.CreateInstance<EquipmentDef>();
			((Object)flashbang).name = "FLASHBANG_NAME";
			flashbang.nameToken = "FLASHBANG_NAME";
			flashbang.pickupToken = "FLASHBANG_PICKUP";
			flashbang.descriptionToken = "FLASHBANG_DESC";
			flashbang.loreToken = "FLASHBANG_LORE";
			flashbang.pickupIconSprite = Assets.mainAssetBundle.LoadAsset<Sprite>("flashbang.png");
			flashbang.pickupModelPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/StunChanceOnHit/PickupStunGrenade.prefab").WaitForCompletion();
			flashbang.appearsInMultiPlayer = true;
			flashbang.appearsInSinglePlayer = true;
			flashbang.canBeRandomlyTriggered = true;
			flashbang.enigmaCompatible = true;
			flashbang.canDrop = true;
			flashbang.cooldown = 25f;
			ItemAPI.Add(new CustomEquipment(flashbang, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
		}

		private bool EquipmentActivate(orig_PerformEquipmentAction orig, EquipmentSlot self, EquipmentDef def)
		{
			if ((Object)(object)def == (Object)(object)flashbang && NetworkServer.active)
			{
				FireFlashbang(self.characterBody);
				return true;
			}
			return orig.Invoke(self, def);
		}

		private void FireFlashbang(CharacterBody body)
		{
			//IL_000c: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			Vector3 position = ((Component)body).gameObject.transform.position;
			foreach (CharacterBody instances in CharacterBody.instancesList)
			{
				double num = Vector3.Distance(((Component)instances).gameObject.transform.position, position);
				if (instances.isPlayerControlled)
				{
					NetMessageExtensions.Send((INetMessage)(object)new Sink(instances.master.networkIdentity.netId, body.master.networkIdentity.netId, num <= 80.0), (NetworkDestination)1);
				}
				else if (num <= 80.0)
				{
					if (instances.teamComponent.teamIndex != body.teamComponent.teamIndex)
					{
						DamageInfo val = new DamageInfo
						{
							damage = Math.Max(instances.healthComponent.fullCombinedHealth / 10f, body.baseDamage * 1.5f),
							attacker = ((Component)body).gameObject,
							crit = Util.CheckRoll(body.crit, body.master),
							procCoefficient = 3f
						};
						instances.healthComponent.TakeDamage(val);
						GlobalEventManager.instance.OnHitEnemy(val, ((Component)instances.healthComponent).gameObject);
						SetStateOnHurt.SetStunOnObject(((Component)instances).gameObject, 5f);
					}
					else
					{
						SetStateOnHurt.SetStunOnObject(((Component)instances).gameObject, 5f);
					}
				}
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}
namespace Flashbang.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("Flashbang.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}