Decompiled source of GojoInfinity v1.0.0

GojoInfinity/GojoInfinity.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using R2API;
using RoR2;
using RoR2.Projectile;
using UnityEngine;
using UnityEngine.Networking;

[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("GojoInfinity")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GojoInfinity")]
[assembly: AssemblyTitle("GojoInfinity")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 GojoInfinity
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.seunome.GojoInfinity", "GojoInfinity", "1.0.0")]
	public class GojoInfinityPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.seunome.GojoInfinity";

		public const string PluginName = "GojoInfinity";

		public const string PluginVersion = "1.0.0";

		public static ItemDef InfinityItem;

		public void Awake()
		{
			CreateItem();
			CharacterBody.onBodyInventoryChangedGlobal += OnInventoryChanged;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"GojoInfinity carregado!");
		}

		private static void OnInventoryChanged(CharacterBody body)
		{
			if (NetworkServer.active && Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.inventory))
			{
				int itemCount = body.inventory.GetItemCount(InfinityItem);
				body.AddItemBehavior<InfinityBehavior>(itemCount);
			}
		}

		private void CreateItem()
		{
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			InfinityItem = ScriptableObject.CreateInstance<ItemDef>();
			((Object)InfinityItem).name = "GojoInfinity";
			InfinityItem.nameToken = "GOJOINFINITY_NAME";
			InfinityItem.pickupToken = "GOJOINFINITY_PICKUP";
			InfinityItem.descriptionToken = "GOJOINFINITY_DESC";
			InfinityItem.loreToken = "GOJOINFINITY_LORE";
			InfinityItem.tier = (ItemTier)2;
			InfinityItem.tags = (ItemTag[])(object)new ItemTag[1] { (ItemTag)3 };
			InfinityItem.canRemove = true;
			InfinityItem.hidden = false;
			InfinityItem.pickupIconSprite = MakeIcon();
			InfinityItem.pickupModelPrefab = LegacyResourcesAPI.Load<GameObject>("Prefabs/PickupModels/PickupMystery");
			LanguageAPI.Add("GOJOINFINITY_NAME", "Infinity");
			LanguageAPI.Add("GOJOINFINITY_PICKUP", "Enemy projectiles slow down and vanish before reaching you.");
			LanguageAPI.Add("GOJOINFINITY_DESC", "Enemy projectiles within <style=cIsUtility>18m</style> of you are <style=cIsUtility>slowed</style> and then <style=cIsDamage>destroyed</style>. Radius increases by <style=cStack>+3m</style> per stack.");
			LanguageAPI.Add("GOJOINFINITY_LORE", "Between you and the world, there is an infinite distance.");
			LanguageAPI.Add("GOJOINFINITY_NAME", "Infinito", "pt-BR");
			LanguageAPI.Add("GOJOINFINITY_PICKUP", "Projéteis inimigos desaceleram e somem antes de te alcançar.", "pt-BR");
			LanguageAPI.Add("GOJOINFINITY_DESC", "Projéteis inimigos a até <style=cIsUtility>18m</style> de você são <style=cIsUtility>desacelerados</style> e depois <style=cIsDamage>destruídos</style>. O raio aumenta em <style=cStack>+3m</style> por acúmulo.", "pt-BR");
			LanguageAPI.Add("GOJOINFINITY_LORE", "Entre você e o mundo, existe uma distância infinita.", "pt-BR");
			ItemAPI.Add(new CustomItem(InfinityItem, (ItemDisplayRule[])(object)new ItemDisplayRule[0]));
		}

		private static Sprite MakeIcon()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
			float num = 63.5f;
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num2 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(num, num));
					float num3 = Mathf.Clamp01(1f - Mathf.Abs(num2 - 48f) / 5f);
					float num4 = Mathf.Clamp01(1f - num2 / 22f);
					float num5 = Mathf.Max(num3, num4);
					val.SetPixel(j, i, new Color(0.4f + 0.45f * num4, 0.3f + 0.4f * num4, 1f, num5));
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f));
		}
	}
	public class InfinityBehavior : ItemBehavior
	{
		private const float BaseOuterRadius = 18f;

		private const float RadiusPerStack = 3f;

		private const float InnerRadius = 3f;

		private const float MaxHoldTime = 1.2f;

		private const float SlowFar = 0.92f;

		private const float SlowNear = 0.6f;

		private static readonly Collider[] buffer = (Collider[])(object)new Collider[256];

		private readonly HashSet<ProjectileController> seen = new HashSet<ProjectileController>();

		private readonly Dictionary<ProjectileController, float> timeInside = new Dictionary<ProjectileController, float>();

		private readonly List<ProjectileController> toRemove = new List<ProjectileController>();

		private void FixedUpdate()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)base.body) || !Object.op_Implicit((Object)(object)base.body.teamComponent))
			{
				return;
			}
			float num = 18f + 3f * (float)(base.stack - 1);
			Vector3 corePosition = base.body.corePosition;
			int num2 = Physics.OverlapSphereNonAlloc(corePosition, num, buffer, LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.projectile)).mask), (QueryTriggerInteraction)2);
			seen.Clear();
			for (int i = 0; i < num2; i++)
			{
				ProjectileController componentInParent = ((Component)buffer[i]).GetComponentInParent<ProjectileController>();
				if (Object.op_Implicit((Object)(object)componentInParent) && seen.Add(componentInParent) && (!Object.op_Implicit((Object)(object)componentInParent.teamFilter) || componentInParent.teamFilter.teamIndex != base.body.teamComponent.teamIndex))
				{
					HandleProjectile(componentInParent, corePosition, num);
				}
			}
			toRemove.Clear();
			foreach (KeyValuePair<ProjectileController, float> item in timeInside)
			{
				if (!Object.op_Implicit((Object)(object)item.Key) || !seen.Contains(item.Key))
				{
					toRemove.Add(item.Key);
				}
			}
			foreach (ProjectileController item2 in toRemove)
			{
				timeInside.Remove(item2);
			}
		}

		private void HandleProjectile(ProjectileController pc, Vector3 center, float outer)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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)
			float num = Vector3.Distance(((Component)pc).transform.position, center);
			timeInside.TryGetValue(pc, out var value);
			value += Time.fixedDeltaTime;
			timeInside[pc] = value;
			if (num <= 3f || value >= 1.2f)
			{
				timeInside.Remove(pc);
				NetworkServer.Destroy(((Component)pc).gameObject);
				return;
			}
			float num2 = 1f - Mathf.InverseLerp(3f, outer, num);
			float num3 = Mathf.Lerp(0.92f, 0.6f, num2);
			Rigidbody component = ((Component)pc).GetComponent<Rigidbody>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.useGravity = false;
				component.velocity *= num3;
			}
			ProjectileSimple component2 = ((Component)pc).GetComponent<ProjectileSimple>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.desiredForwardSpeed *= num3;
			}
		}
	}
}