Decompiled source of AtomGrenade v1.0.3

AtomGrenade.dll

Decompiled 6 months ago
using System;
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.Configuration;
using BepInEx.Logging;
using BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("AtomGrenade")]
[assembly: AssemblyConfiguration("Thunderstore")]
[assembly: AssemblyDescription("Grenade explosion go brrrrrrrr!")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+5d59a5290143a34dc966085d9181057a02c31991")]
[assembly: AssemblyProduct("AtomGrenade")]
[assembly: AssemblyTitle("AtomGrenade")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AtomGrenade
{
	[BepInPlugin("com.almafa64.AtomGrenade", "AtomGrenade", "1.0.3")]
	[BepInProcess("BoplBattle.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Harmony harmony;

		internal static ManualLogSource logger;

		internal static ConfigFile config;

		internal static ConfigEntry<double> grenadePower;

		internal static Sprite atomSprite;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			logger = ((BaseUnityPlugin)this).Logger;
			config = ((BaseUnityPlugin)this).Config;
			grenadePower = config.Bind<double>("Settings", "grenade power multiplier", 5.0, "Minimum is 0.0 (negative will set it to 1.0). Maximum somewhere around 5");
			if (grenadePower.Value < 1.0)
			{
				grenadePower.Value = 1.0;
			}
			harmony.Patch((MethodBase)AccessTools.Method(typeof(GrenadeExplode), "Detonate", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "Detonate_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(GameSessionHandler), "SpawnPlayers", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "SpawnPlayers_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Texture2D val = Utils.LoadDLLTexture("AtomGrenade.atom_grenade.png");
			atomSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 45f);
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name.Contains("Select"))
			{
				ChSelectSceneLoaded();
			}
		}

		private void ChSelectSceneLoaded()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			AbilityGrid[] array = Object.FindObjectsOfType<AbilityGrid>();
			foreach (AbilityGrid val in array)
			{
				new Traverse((object)val).Field<AbilityGridEntry[]>("grid").Value[2].SetSprite(atomSprite);
			}
		}
	}
	internal class Patches
	{
		public static bool Detonate_Prefix(GrenadeExplode __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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)
			IPhysicsCollider value = new Traverse((object)__instance).Field<IPhysicsCollider>("hitbox").Value;
			value.Scale *= (Fix)Plugin.grenadePower.Value;
			return true;
		}

		public static void SpawnPlayers_Postfix()
		{
			if (Plugin.grenadePower.Value <= 1.0)
			{
				return;
			}
			SpriteRenderer[] array = Resources.FindObjectsOfTypeAll<SpriteRenderer>();
			foreach (SpriteRenderer val in array)
			{
				if (!(((Object)val).name != "dummyGrenade"))
				{
					ThrowItem2 component = ((Component)((Component)val).transform.parent).GetComponent<ThrowItem2>();
					if (((Object)component).name.Contains("Grenade"))
					{
						((Component)component.ItemPrefab).GetComponent<SpriteRenderer>().sprite = Plugin.atomSprite;
						val.sprite = Plugin.atomSprite;
					}
				}
			}
		}

		public static void Test_Postfix()
		{
			Plugin.logger.LogWarning((object)"something");
		}
	}
	internal class Utils
	{
		public static Texture2D LoadDLLTexture(string path)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(256, 256);
			ImageConversion.LoadImage(val, array);
			return val;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "AtomGrenade";

		public const string PLUGIN_NAME = "AtomGrenade";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}