Decompiled source of UncappedChances v1.0.1

UncappedChances.dll

Decompiled 19 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.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.Projectile;
using RoR2;
using RoR2.Projectile;
using UnityEngine;
using UnityEngine.Networking;

[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("UncappedChances")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+6c354d2b63b4af6cecc0f7a418b1481360610ce5")]
[assembly: AssemblyProduct("UncappedChances")]
[assembly: AssemblyTitle("UncappedChances")]
[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 UncappedChances
{
	[BepInPlugin("com.iaguito.UncappedChances", "UncappedChances", "1.0.1")]
	public class UncappedChancesPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.iaguito.UncappedChances";

		public const string PluginName = "UncappedChances";

		public const string PluginVersion = "1.0.1";

		private static GameObject cachedMoneyPackPrefab;

		private static GameObject cachedStickyPrefab;

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			cachedMoneyPackPrefab = LegacyResourcesAPI.Load<GameObject>("Prefabs/NetworkedObjects/BonusMoneyPack");
			cachedStickyPrefab = LegacyResourcesAPI.Load<GameObject>("Prefabs/Projectiles/StickyBomb");
			GlobalEventManager.OnCharacterDeath += new hook_OnCharacterDeath(GlobalEventManager_OnCharacterDeath);
			GlobalEventManager.ProcessHitEnemy += new hook_ProcessHitEnemy(GlobalEventManager_ProcessHitEnemy);
			ProjectileController.Start += new hook_Start(ProjectileController_Start);
			Log.Info("UncappedChances 1.0.1 loaded.");
		}

		private void GlobalEventManager_OnCharacterDeath(orig_OnCharacterDeath orig, GlobalEventManager self, DamageReport damageReport)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, damageReport);
			if (!NetworkServer.active || damageReport == null || (Object)(object)damageReport.attackerMaster == (Object)null || (Object)(object)damageReport.attackerMaster.inventory == (Object)null || (Object)(object)damageReport.victimBody == (Object)null)
			{
				return;
			}
			int effectiveCount = GetEffectiveCount(damageReport.attackerMaster.inventory, Items.BonusGoldPackOnKill);
			if (effectiveCount <= 0)
			{
				return;
			}
			float num = 4f * (float)effectiveCount;
			int num2 = (int)(num / 100f);
			float num3 = num % 100f;
			int num4 = num2;
			if (num3 > 0f && Util.CheckRoll(num3, damageReport.attackerMaster))
			{
				num4++;
			}
			int num5 = num4 - 1;
			if (num5 <= 0 || !((Object)(object)cachedMoneyPackPrefab != (Object)null))
			{
				return;
			}
			Vector3 corePosition = damageReport.victimBody.corePosition;
			TeamIndex attackerTeamIndex = damageReport.attackerTeamIndex;
			for (int i = 0; i < num5; i++)
			{
				GameObject obj = Object.Instantiate<GameObject>(cachedMoneyPackPrefab, corePosition, Random.rotation);
				TeamFilter componentInChildren = obj.GetComponentInChildren<TeamFilter>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					componentInChildren.teamIndex = attackerTeamIndex;
				}
				Rigidbody component = obj.GetComponent<Rigidbody>();
				if (Object.op_Implicit((Object)(object)component))
				{
					Vector3 val = Random.insideUnitSphere * 4f;
					val.y = Mathf.Abs(val.y) + 6f;
					component.velocity = val;
				}
				NetworkServer.Spawn(obj);
			}
		}

		private void GlobalEventManager_ProcessHitEnemy(orig_ProcessHitEnemy orig, GlobalEventManager self, DamageInfo damageInfo, GameObject victim)
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)damageInfo.attacker == (Object)null || (Object)(object)victim == (Object)null || damageInfo.procCoefficient <= 0f)
			{
				orig.Invoke(self, damageInfo, victim);
				return;
			}
			CharacterBody component = damageInfo.attacker.GetComponent<CharacterBody>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.inventory == (Object)null)
			{
				orig.Invoke(self, damageInfo, victim);
				return;
			}
			int effectiveCount = GetEffectiveCount(component.inventory, Items.StickyBomb);
			if (effectiveCount >= 20)
			{
				float num = 5f * (float)effectiveCount * damageInfo.procCoefficient;
				int num2 = (int)(num / 100f);
				float num3 = num % 100f;
				int num4 = num2;
				if (num3 > 0f && Util.CheckRoll(num3, component.master))
				{
					num4++;
				}
				if (num4 > 0 && (Object)(object)cachedStickyPrefab != (Object)null)
				{
					Vector3 val = damageInfo.position - victim.transform.position;
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					Quaternion rotation = ((normalized != Vector3.zero) ? Util.QuaternionSafeLookRotation(normalized) : Random.rotation);
					float damage = damageInfo.damage * 1.8f * (float)num4;
					FireProjectileInfo val2 = new FireProjectileInfo
					{
						projectilePrefab = cachedStickyPrefab,
						position = damageInfo.position,
						rotation = rotation,
						owner = damageInfo.attacker,
						damage = damage,
						force = 100f,
						crit = damageInfo.crit,
						damageColorIndex = (DamageColorIndex)3,
						target = victim
					};
					StickyBombScaleTracker.LastCreatedBombCount = num4;
					ProjectileManager.instance.FireProjectile(val2);
				}
				float procCoefficient = damageInfo.procCoefficient;
				damageInfo.procCoefficient = 0f;
				try
				{
					orig.Invoke(self, damageInfo, victim);
					return;
				}
				finally
				{
					damageInfo.procCoefficient = procCoefficient;
				}
			}
			orig.Invoke(self, damageInfo, victim);
		}

		private void ProjectileController_Start(orig_Start orig, ProjectileController self)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (((Object)self).name.StartsWith("StickyBomb") && StickyBombScaleTracker.LastCreatedBombCount > 1)
			{
				int lastCreatedBombCount = StickyBombScaleTracker.LastCreatedBombCount;
				StickyBombScaleTracker.LastCreatedBombCount = 1;
				float num = Mathf.Clamp(1f + 0.3f * (float)(lastCreatedBombCount - 1), 1f, 3.2f);
				Transform transform = ((Component)self).transform;
				transform.localScale *= num;
			}
		}

		private static int GetEffectiveCount(Inventory inventory, ItemDef itemDef)
		{
			if ((Object)(object)inventory == (Object)null || (Object)(object)itemDef == (Object)null)
			{
				return 0;
			}
			try
			{
				MethodInfo method = typeof(Inventory).GetMethod("GetItemCountEffective", new Type[1] { typeof(ItemDef) });
				if (method != null)
				{
					return (int)method.Invoke(inventory, new object[1] { itemDef });
				}
			}
			catch
			{
			}
			return inventory.GetItemCount(itemDef);
		}
	}
	public static class StickyBombScaleTracker
	{
		public static int LastCreatedBombCount = 1;
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

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

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}

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