Decompiled source of BiggerBullets v1.0.4

BiggerBullets.dll

Decompiled 18 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.Projectile;
using RoR2;
using RoR2.Projectile;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BiggerBullets")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("BiggerBullets")]
[assembly: AssemblyTitle("BiggerBullets")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 BiggerBullets
{
	[BepInPlugin("dileppy.biggerbullets", "BiggerBullets", "1.0.4")]
	public class BiggerBulletsPlugin : BaseUnityPlugin
	{
		private class BiggerBulletsMarker : MonoBehaviour
		{
			public Vector3 baseScale;

			public float baseDamage;

			public bool hasBaseDamage;
		}

		public const string PluginGUID = "dileppy.biggerbullets";

		public const string PluginName = "BiggerBullets";

		public const string PluginVersion = "1.0.4";

		public static ConfigEntry<float> SizeMultiplier;

		public static ConfigEntry<bool> ScaleHitscanWeapons;

		public static ConfigEntry<bool> ScaleProjectileWeapons;

		public static ConfigEntry<bool> PlayerWeaponsOnly;

		public static ConfigEntry<float> MinimumHitscanRadius;

		public static ConfigEntry<bool> ScaleHitscanTracers;

		public static ConfigEntry<bool> DebugLogging;

		private static bool insideScaledHitscanFire;

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			SizeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SizeMultiplier", 2f, new ConfigDescription("How much bigger bullets/projectiles get, and how much extra damage that grants. 2 = double size & double damage. 1 = vanilla. Can be edited live with the BepInEx Configuration Manager mod.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			ScaleHitscanWeapons = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ScaleHitscanWeapons", true, "Apply the size/damage boost to hitscan (instant-hit) weapons, e.g. Commando, Bandit, MUL-T's rivet gun, Loader, REX, turrets.");
			ScaleProjectileWeapons = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ScaleProjectileWeapons", true, "Apply the size/damage boost to true projectile weapons, e.g. Commando's grenade, Railgunner's shots, Huntress's arrows, Captain's turret rockets.");
			PlayerWeaponsOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PlayerWeaponsOnly", true, "If true, only attacks owned by a player-controlled character are scaled up. If false, monsters/turrets that use the same attack code are boosted too.");
			MinimumHitscanRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Advanced", "MinimumHitscanRadius", 0.15f, new ConfigDescription("Most hitscan guns fire a zero-width ray by default (radius 0), so there's nothing to multiply. This is the baseline radius (in meters) used for those guns before the SizeMultiplier is applied, so the size boost is always noticeable.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Advanced", "DebugLogging", false, "Log every scaled attack (name, size, damage before/after) to the BepInEx console/log. Turn on to verify the mod is working, off for normal play.");
			ScaleHitscanTracers = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ScaleHitscanTracers", true, "Visually enlarge the tracer/muzzle flash/impact effects of hitscan weapons to match the size boost, so instant-hit guns LOOK bigger too, not just hit a wider area.");
			BulletAttack.Fire += new hook_Fire(BulletAttack_Fire);
			EffectManager.SpawnEffect_GameObject_EffectData_bool += new hook_SpawnEffect_GameObject_EffectData_bool(EffectManager_SpawnEffect);
			ProjectileController.Start += new hook_Start(ProjectileController_Start);
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} loaded. SizeMultiplier={2}", "BiggerBullets", "1.0.4", SizeMultiplier.Value));
		}

		private void OnDestroy()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			BulletAttack.Fire -= new hook_Fire(BulletAttack_Fire);
			EffectManager.SpawnEffect_GameObject_EffectData_bool -= new hook_SpawnEffect_GameObject_EffectData_bool(EffectManager_SpawnEffect);
			ProjectileController.Start -= new hook_Start(ProjectileController_Start);
		}

		private void BulletAttack_Fire(orig_Fire orig, BulletAttack self)
		{
			if (!ScaleHitscanWeapons.Value || !ShouldScale(self.owner))
			{
				orig.Invoke(self);
				return;
			}
			float radius = self.radius;
			float damage = self.damage;
			try
			{
				float value = SizeMultiplier.Value;
				float num = ((self.radius > 0f) ? self.radius : MinimumHitscanRadius.Value);
				self.radius = num * value;
				self.damage *= value;
				if (DebugLogging.Value)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"BiggerBullets hitscan: radius {radius:F2}->{self.radius:F2}, damage {damage:F1}->{self.damage:F1}");
				}
				insideScaledHitscanFire = true;
				orig.Invoke(self);
			}
			finally
			{
				insideScaledHitscanFire = false;
				self.radius = radius;
				self.damage = damage;
			}
		}

		private void EffectManager_SpawnEffect(orig_SpawnEffect_GameObject_EffectData_bool orig, GameObject effectPrefab, EffectData effectData, bool transmit)
		{
			if (insideScaledHitscanFire && ScaleHitscanTracers.Value && effectData != null)
			{
				float scale = effectData.scale;
				float num = ((scale > 0f) ? scale : 1f);
				effectData.scale = num * SizeMultiplier.Value;
				if (DebugLogging.Value)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("BiggerBullets tracer/effect: {0} scale {1:F2}->{2:F2}", Object.op_Implicit((Object)(object)effectPrefab) ? ((Object)effectPrefab).name : "null", scale, effectData.scale));
				}
			}
			orig.Invoke(effectPrefab, effectData, transmit);
		}

		private void ProjectileController_Start(orig_Start orig, ProjectileController self)
		{
			//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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!ScaleProjectileWeapons.Value || !ShouldScale(self.owner))
			{
				return;
			}
			Scene scene = ((Component)self).gameObject.scene;
			if (!((Scene)(ref scene)).IsValid())
			{
				return;
			}
			try
			{
				float value = SizeMultiplier.Value;
				BiggerBulletsMarker biggerBulletsMarker = ((Component)self).GetComponent<BiggerBulletsMarker>();
				if (!Object.op_Implicit((Object)(object)biggerBulletsMarker))
				{
					biggerBulletsMarker = ((Component)self).gameObject.AddComponent<BiggerBulletsMarker>();
					biggerBulletsMarker.baseScale = ((Component)self).transform.localScale;
					ProjectileDamage component = ((Component)self).GetComponent<ProjectileDamage>();
					if (Object.op_Implicit((Object)(object)component))
					{
						biggerBulletsMarker.baseDamage = component.damage;
						biggerBulletsMarker.hasBaseDamage = true;
					}
				}
				((Component)self).transform.localScale = biggerBulletsMarker.baseScale * value;
				float num = 0f;
				float num2 = 0f;
				ProjectileDamage component2 = ((Component)self).GetComponent<ProjectileDamage>();
				if (Object.op_Implicit((Object)(object)component2) && biggerBulletsMarker.hasBaseDamage)
				{
					num = component2.damage;
					component2.damage = biggerBulletsMarker.baseDamage * value;
					num2 = component2.damage;
				}
				if (Object.op_Implicit((Object)(object)self.ghost))
				{
					scene = ((Component)self.ghost).gameObject.scene;
					if (((Scene)(ref scene)).IsValid())
					{
						GameObject gameObject = ((Component)self.ghost).gameObject;
						BiggerBulletsMarker biggerBulletsMarker2 = gameObject.GetComponent<BiggerBulletsMarker>();
						if (!Object.op_Implicit((Object)(object)biggerBulletsMarker2))
						{
							biggerBulletsMarker2 = gameObject.AddComponent<BiggerBulletsMarker>();
							biggerBulletsMarker2.baseScale = gameObject.transform.localScale;
						}
						gameObject.transform.localScale = biggerBulletsMarker2.baseScale * value;
					}
				}
				if (DebugLogging.Value)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"BiggerBullets projectile: {((Object)((Component)self).gameObject).name} scale {biggerBulletsMarker.baseScale.x:F2}->{((Component)self).transform.localScale.x:F2}, damage {biggerBulletsMarker.baseDamage:F1}->{num2:F1} (was {num:F1} on arrival)");
				}
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"BiggerBullets: failed to scale projectile instance: {arg}");
			}
		}

		private static bool ShouldScale(GameObject owner)
		{
			if (!PlayerWeaponsOnly.Value)
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)owner))
			{
				return false;
			}
			CharacterBody component = owner.GetComponent<CharacterBody>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.master))
			{
				return Object.op_Implicit((Object)(object)component.master.playerCharacterMasterController);
			}
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BiggerBullets";

		public const string PLUGIN_NAME = "BiggerBullets";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}