Decompiled source of BeetleOfDoom v1.0.0

ImmortalBeetle.dll

Decompiled 14 hours ago
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 On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.CharacterAI;
using RoR2.Navigation;
using UnityEngine;
using UnityEngine.AddressableAssets;
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 = "")]
[assembly: AssemblyCompany("ImmortalBeetle")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ImmortalBeetle")]
[assembly: AssemblyTitle("ImmortalBeetle")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ImmortalBeetle;

internal class Assets
{
	public static AssetBundle MainAssetBundle;

	public static T Load<T>(string name) where T : Object
	{
		return MainAssetBundle.LoadAsset<T>(name);
	}

	public static void PopulateAssets()
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		if ((Object)(object)MainAssetBundle == (Object)null)
		{
			using (Stream stream = executingAssembly.GetManifestResourceStream("ImmortalBeetle.AssetBundle." + "ImmortalBeetle".ToLower() + "assets"))
			{
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}
}
internal class ImmortalBehaviour : MonoBehaviour
{
	private Material material;

	private Material overlayMaterial = Prefabs.Load<Material>("RoR2/Base/Grandparent/matOverheatOverlay.mat");

	private TemporaryOverlayInstance temporaryOverlay = null;

	private CharacterModel model;

	private float stopwatch;

	private BaseAI baseAI;

	public float maxDistance = 600f;

	public float tpDistance = 200f;

	private CharacterBody body;

	private void Start()
	{
		//IL_004c: 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)
		body = ((Component)this).GetComponent<CharacterBody>();
		baseAI = ((Component)body.master).GetComponent<BaseAI>();
		ModelLocator component = ((Component)this).GetComponent<ModelLocator>();
		if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.modelTransform))
		{
			Transform modelTransform = component.modelTransform;
			modelTransform.localScale *= 1.5f;
			model = ((Component)component.modelTransform).GetComponent<CharacterModel>();
		}
	}

	private void FixedUpdate()
	{
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Expected O, but got Unknown
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: 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)
		stopwatch += Time.fixedDeltaTime;
		if (stopwatch >= 1f)
		{
			stopwatch = 0f;
			if (NetworkServer.active && !body.HasBuff(Buffs.Immune))
			{
				body.AddBuff(Buffs.Immune);
			}
			if (Object.op_Implicit((Object)(object)baseAI) && Object.op_Implicit((Object)(object)baseAI.currentEnemy.gameObject))
			{
				Vector3 position = baseAI.currentEnemy.gameObject.transform.position;
				if (Vector3.Distance(position, ((Component)this).transform.position) > maxDistance)
				{
					Vector3 val = ((Component)this).transform.position - position;
					Vector3 val2 = Utils.FindNearestNodePosition(position + ((Vector3)(ref val)).normalized * tpDistance, (GraphType)0);
					TeleportHelper.TeleportGameObject(((Component)this).gameObject, val2 + Vector3.up * 2f);
					EffectManager.SimpleEffect(Prefabs.Load<GameObject>("RoR2/Base/Huntress/HuntressBlinkEffect.prefab"), val2, Quaternion.identity, false);
					AkSoundEngine.PostEvent("Play_huntress_shift_mini_blink", ((Component)this).gameObject);
					if (NetworkServer.active)
					{
						body.AddTimedBuff(Buffs.Slow80, 5f);
					}
				}
			}
		}
		if (temporaryOverlay == null)
		{
			if (Object.op_Implicit((Object)(object)model) && model.baseRendererInfos != null && model.baseRendererInfos.Length != 0)
			{
				RendererInfo val3 = model.baseRendererInfos[0];
				material = new Material(val3.defaultMaterial);
				material.SetColor("_Color", Color32.op_Implicit(new Color32(byte.MaxValue, (byte)119, (byte)117, byte.MaxValue)));
				val3.defaultMaterial = material;
				model.forceUpdate = true;
				temporaryOverlay = TemporaryOverlayManager.AddOverlay(((Component)model).gameObject);
				temporaryOverlay.originalMaterial = overlayMaterial;
				temporaryOverlay.AddToCharacterModel(model);
			}
		}
		else if (Object.op_Implicit((Object)(object)model) && (Object)(object)model.baseRendererInfos[0].defaultMaterial != (Object)(object)material)
		{
			model.baseRendererInfos[0].defaultMaterial = material;
			model.forceUpdate = true;
		}
	}

	private void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)material))
		{
			Object.Destroy((Object)(object)material);
		}
	}
}
internal class Hook
{
	internal static void Hooks()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		Stage.onServerStageBegin += Stage_onServerStageBegin;
		CharacterBody.onBodyStartGlobal += CharacterBody_onBodyStartGlobal;
		MapZone.TryZoneStart += new hook_TryZoneStart(MapZone_TryZoneStart);
		GlobalEventManager.onServerDamageDealt += GlobalEventManager_onServerDamageDealt;
	}

	private static void GlobalEventManager_onServerDamageDealt(DamageReport damageReport)
	{
		//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)
		if (Object.op_Implicit((Object)(object)damageReport.attacker) && Object.op_Implicit((Object)(object)damageReport.attacker.GetComponent<ImmortalBehaviour>()) && !damageReport.damageInfo.rejected && Object.op_Implicit((Object)(object)damageReport.victim))
		{
			damageReport.victim.Suicide(damageReport.attacker, damageReport.attacker, default(DamageTypeCombo));
		}
	}

	private static void Stage_onServerStageBegin(Stage obj)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		if (!NetworkServer.active || !Object.op_Implicit((Object)(object)RunArtifactManager.instance) || !RunArtifactManager.instance.IsArtifactEnabled(Prefabs.artifact))
		{
			return;
		}
		MasterSummon val = new MasterSummon
		{
			masterPrefab = Prefabs.Load<GameObject>("RoR2/Base/Beetle/BeetleMaster.prefab"),
			position = Utils.FindNearestNodePosition(Object.op_Implicit((Object)(object)TeleporterInteraction.instance) ? ((Component)TeleporterInteraction.instance).transform.position : Vector3.zero, (GraphType)0),
			rotation = Quaternion.identity,
			teamIndexOverride = (TeamIndex)2,
			ignoreTeamMemberLimit = true,
			useAmbientLevel = true
		};
		CharacterMaster val2 = val.Perform();
		if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.inventory))
		{
			val2.inventory.GiveItemPermanent(Items.BoostHp, 9999);
			val2.inventory.GiveItemPermanent(Items.BoostDamage, 9999);
			val2.inventory.GiveItemPermanent(Items.ExtraLife, 9999);
			CharacterBody body = val2.GetBody();
			if (Object.op_Implicit((Object)(object)body))
			{
				body.AddBuff(Buffs.Immune);
			}
		}
	}

	private static void CharacterBody_onBodyStartGlobal(CharacterBody body)
	{
		if (Object.op_Implicit((Object)(object)RunArtifactManager.instance) && RunArtifactManager.instance.IsArtifactEnabled(Prefabs.artifact) && Object.op_Implicit((Object)(object)body.inventory) && body.inventory.GetItemCountEffective(Items.ExtraLife) >= 999 && body.HasBuff(Buffs.Immune) && Object.op_Implicit((Object)(object)body.inventory) && body.inventory.GetItemCountEffective(Items.BoostDamage) >= 999)
		{
			((Component)body).gameObject.AddComponent<ImmortalBehaviour>();
		}
	}

	private static void MapZone_TryZoneStart(orig_TryZoneStart orig, MapZone self, Collider other)
	{
		if (Object.op_Implicit((Object)(object)RunArtifactManager.instance) && RunArtifactManager.instance.IsArtifactEnabled(Prefabs.artifact))
		{
			ImmortalBehaviour component = ((Component)other).GetComponent<ImmortalBehaviour>();
			if (Object.op_Implicit((Object)(object)component))
			{
				self.TeleportBody(((Component)other).GetComponent<CharacterBody>());
				return;
			}
		}
		orig.Invoke(self, other);
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Dragonyck.ImmortalBeetle", "ImmortalBeetle", "1.0.0")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class MainPlugin : BaseUnityPlugin
{
	public const string MODUID = "com.Dragonyck.ImmortalBeetle";

	public const string MODNAME = "ImmortalBeetle";

	public const string VERSION = "1.0.0";

	internal const string MODKEY = "IMMORTALBEETLE_";

	private void Awake()
	{
		Assets.PopulateAssets();
		Prefabs.CreatePrefabs();
		Hook.Hooks();
	}
}
internal class Prefabs
{
	internal static ArtifactDef artifact;

	internal static void CreatePrefabs()
	{
		artifact = ScriptableObject.CreateInstance<ArtifactDef>();
		artifact.cachedName = "IMMORTALBEETLE_ARTIFACT";
		artifact.nameToken = artifact.cachedName;
		artifact.descriptionToken = artifact.cachedName + "_DESC";
		artifact.smallIconSelectedSprite = Assets.Load<Sprite>("artifactIcon");
		artifact.smallIconDeselectedSprite = Assets.Load<Sprite>("artifactIconDisabled");
		ContentAddition.AddArtifactDef(artifact);
		LanguageAPI.Add(artifact.cachedName, "Artifact of Inevitability");
		LanguageAPI.Add(artifact.cachedName + "_DESC", "An immortal beetle hunts you relentlessly. One strike spells your demise.");
	}

	internal static T Load<T>(string path)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Addressables.LoadAssetAsync<T>((object)path).WaitForCompletion();
	}
}
internal class Utils
{
	public static Vector3 FindNearestNodePosition(Vector3 targetPosition, GraphType nodeGraphType)
	{
		//IL_0009: 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_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		SpawnCard val = ScriptableObject.CreateInstance<SpawnCard>();
		val.hullSize = (HullClassification)1;
		val.nodeGraphType = nodeGraphType;
		val.prefab = Prefabs.Load<GameObject>("RoR2/Base/Common/DirectorSpawnProbeHelperPrefab.prefab");
		Vector3 result = targetPosition;
		GameObject val2 = DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(val, new DirectorPlacementRule
		{
			placementMode = (PlacementMode)3,
			position = targetPosition
		}, RoR2Application.rng));
		if (Object.op_Implicit((Object)(object)val2))
		{
			result = val2.transform.position;
		}
		if (Object.op_Implicit((Object)(object)val2))
		{
			Object.Destroy((Object)(object)val2);
		}
		Object.Destroy((Object)(object)val);
		return result;
	}
}