Decompiled source of ChildTweaks v1.0.0

ChildTweaks.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using EntityStates;
using EntityStates.ChildMonster;
using Microsoft.CodeAnalysis;
using On.EntityStates.ChildMonster;
using On.RoR2;
using R2API;
using RoR2;
using RoR2.CharacterAI;
using RoR2.Navigation;
using RoR2.Projectile;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("ChildTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChildTweaks")]
[assembly: AssemblyTitle("ChildTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ChildTweaks
{
	[BepInPlugin("com.Nuxlar.ChildTweaks", "ChildTweaks", "1.0.0")]
	public class ChildTweaks : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_GetMinimumInterruptPriority <>9__14_0;

			public static hook_GetMinimumInterruptPriority <>9__14_1;

			public static hook_GetMinimumInterruptPriority <>9__14_2;

			public static hook_HandleCumulativeDamage <>9__14_3;

			public static hook_RegisterTeleport <>9__14_4;

			public static hook_TeleportAway <>9__14_5;

			internal InterruptPriority <Awake>b__14_0(orig_GetMinimumInterruptPriority orig, Frolic self)
			{
				return (InterruptPriority)1;
			}

			internal InterruptPriority <Awake>b__14_1(orig_GetMinimumInterruptPriority orig, FrolicAway self)
			{
				return (InterruptPriority)1;
			}

			internal InterruptPriority <Awake>b__14_2(orig_GetMinimumInterruptPriority orig, SparkBallCharge self)
			{
				return (InterruptPriority)5;
			}

			internal void <Awake>b__14_3(orig_HandleCumulativeDamage orig, ChildMonsterController self)
			{
			}

			internal void <Awake>b__14_4(orig_RegisterTeleport orig, ChildMonsterController self, bool addInvincibility)
			{
				self.lastTeleportTimestamp = Time.time;
				self.healthAtLastTeleport = self.characterBody.healthComponent.health;
				self.requestedTeleportState = null;
			}

			internal void <Awake>b__14_5(orig_TeleportAway orig, FrolicAway self)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: 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_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: 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_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				((Component)((EntityState)self).GetComponent<ModelLocator>().modelTransform).GetComponent<CharacterModel>();
				_ = ((EntityState)self).characterBody.corePosition;
				NodeGraph nodeGraph = SceneInfo.instance.GetNodeGraph((GraphType)0);
				Vector3 position = ((Component)((EntityState)self).characterBody.master).GetComponent<BaseAI>().currentEnemy.characterBody.coreTransform.position;
				List<NodeIndex> list = nodeGraph.FindNodesInRange(position, 25f, 50f, (HullMask)1);
				Vector3 val = default(Vector3);
				bool flag = false;
				int num = 35;
				while (!flag)
				{
					NodeIndex val2 = list.ElementAt(Random.Range(1, list.Count));
					nodeGraph.GetNodePosition(val2, ref val);
					double num2 = Vector3.Distance(((EntityState)self).characterBody.coreTransform.position, val);
					num--;
					if (num2 > 35.0 || num < 0)
					{
						flag = true;
					}
				}
				if (num < 0)
				{
					Debug.LogWarning((object)"Child.Frolic state entered a loop where it ran more than 35 times without getting out - check what it's doing");
				}
				TeleportHelper.TeleportBody(((EntityState)self).characterBody, val + Vector3.up * 1.5f);
			}
		}

		private GameObject childMasterPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Child/ChildMaster.prefab").WaitForCompletion();

		private GameObject childBodyPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Child/ChildBody.prefab").WaitForCompletion();

		private SkillDef childFrolicDef = Addressables.LoadAssetAsync<SkillDef>((object)"RoR2/DLC2/Child/ChildBodyFrolic.asset").WaitForCompletion();

		private GameObject childProjectilePrefabOrig = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Child/ChildTrackingSparkBall.prefab").WaitForCompletion();

		public static GameObject childProjectilePrefab = PrefabAPI.InstantiateClone(Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Child/ChildTrackingSparkBall.prefab").WaitForCompletion(), "ChildProjectileNux");

		private GameObject childProjectileGhostPrefab = PrefabAPI.InstantiateClone(Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Child/ChildTrackingSparkBallGhost.prefab").WaitForCompletion(), "ChildProjectileGhostNux");

		public static GameObject shootVFXPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Child/ChildTrackingSparkBallShootExplosion.prefab").WaitForCompletion();

		public static ConfigEntry<bool> removeDefensiveTP;

		public static ConfigEntry<bool> changeAI;

		public static ConfigEntry<bool> addLockheedMartin;

		private static ConfigFile CTConfig { get; set; }

		public void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Expected O, but got Unknown
			//IL_0184: 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_018f: Expected O, but got Unknown
			CTConfig = new ConfigFile(Paths.ConfigPath + "\\com.Nuxlar.ChildTweaks.cfg", true);
			changeAI = CTConfig.Bind<bool>("General", "Change AI", true, "Should the AI be changed?");
			addLockheedMartin = CTConfig.Bind<bool>("General", "Add Mini-Projectiles", true, "Should the main projectile fire smaller projectiles?");
			removeDefensiveTP = CTConfig.Bind<bool>("General", "Remove Defensive TP", true, "Should the Child's teleport be a normal ability with a cooldown?");
			if (removeDefensiveTP.Value)
			{
				childFrolicDef.rechargeStock = 1;
				childFrolicDef.activationState = new SerializableEntityStateType(typeof(FrolicAway));
				childFrolicDef.baseRechargeInterval = 10f;
				object obj = <>c.<>9__14_0;
				if (obj == null)
				{
					hook_GetMinimumInterruptPriority val = (orig_GetMinimumInterruptPriority orig, Frolic self) => (InterruptPriority)1;
					<>c.<>9__14_0 = val;
					obj = (object)val;
				}
				Frolic.GetMinimumInterruptPriority += (hook_GetMinimumInterruptPriority)obj;
				object obj2 = <>c.<>9__14_1;
				if (obj2 == null)
				{
					hook_GetMinimumInterruptPriority val2 = (orig_GetMinimumInterruptPriority orig, FrolicAway self) => (InterruptPriority)1;
					<>c.<>9__14_1 = val2;
					obj2 = (object)val2;
				}
				FrolicAway.GetMinimumInterruptPriority += (hook_GetMinimumInterruptPriority)obj2;
				object obj3 = <>c.<>9__14_2;
				if (obj3 == null)
				{
					hook_GetMinimumInterruptPriority val3 = (orig_GetMinimumInterruptPriority orig, SparkBallCharge self) => (InterruptPriority)5;
					<>c.<>9__14_2 = val3;
					obj3 = (object)val3;
				}
				SparkBallCharge.GetMinimumInterruptPriority += (hook_GetMinimumInterruptPriority)obj3;
				object obj4 = <>c.<>9__14_3;
				if (obj4 == null)
				{
					hook_HandleCumulativeDamage val4 = delegate
					{
					};
					<>c.<>9__14_3 = val4;
					obj4 = (object)val4;
				}
				ChildMonsterController.HandleCumulativeDamage += (hook_HandleCumulativeDamage)obj4;
				object obj5 = <>c.<>9__14_4;
				if (obj5 == null)
				{
					hook_RegisterTeleport val5 = delegate(orig_RegisterTeleport orig, ChildMonsterController self, bool addInvincibility)
					{
						self.lastTeleportTimestamp = Time.time;
						self.healthAtLastTeleport = self.characterBody.healthComponent.health;
						self.requestedTeleportState = null;
					};
					<>c.<>9__14_4 = val5;
					obj5 = (object)val5;
				}
				ChildMonsterController.RegisterTeleport += (hook_RegisterTeleport)obj5;
				object obj6 = <>c.<>9__14_5;
				if (obj6 == null)
				{
					hook_TeleportAway val6 = delegate(orig_TeleportAway orig, FrolicAway self)
					{
						//IL_0017: Unknown result type (might be due to invalid IL or missing references)
						//IL_0048: Unknown result type (might be due to invalid IL or missing references)
						//IL_004d: Unknown result type (might be due to invalid IL or missing references)
						//IL_004f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0063: Unknown result type (might be due to invalid IL or missing references)
						//IL_007f: 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_0087: Unknown result type (might be due to invalid IL or missing references)
						//IL_009c: 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_00da: Unknown result type (might be due to invalid IL or missing references)
						//IL_00db: Unknown result type (might be due to invalid IL or missing references)
						//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
						//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
						((Component)((EntityState)self).GetComponent<ModelLocator>().modelTransform).GetComponent<CharacterModel>();
						_ = ((EntityState)self).characterBody.corePosition;
						NodeGraph nodeGraph = SceneInfo.instance.GetNodeGraph((GraphType)0);
						Vector3 position = ((Component)((EntityState)self).characterBody.master).GetComponent<BaseAI>().currentEnemy.characterBody.coreTransform.position;
						List<NodeIndex> list = nodeGraph.FindNodesInRange(position, 25f, 50f, (HullMask)1);
						Vector3 val7 = default(Vector3);
						bool flag = false;
						int num = 35;
						while (!flag)
						{
							NodeIndex val8 = list.ElementAt(Random.Range(1, list.Count));
							nodeGraph.GetNodePosition(val8, ref val7);
							double num2 = Vector3.Distance(((EntityState)self).characterBody.coreTransform.position, val7);
							num--;
							if (num2 > 35.0 || num < 0)
							{
								flag = true;
							}
						}
						if (num < 0)
						{
							Debug.LogWarning((object)"Child.Frolic state entered a loop where it ran more than 35 times without getting out - check what it's doing");
						}
						TeleportHelper.TeleportBody(((EntityState)self).characterBody, val7 + Vector3.up * 1.5f);
					};
					<>c.<>9__14_5 = val6;
					obj6 = (object)val6;
				}
				FrolicAway.TeleportAway += (hook_TeleportAway)obj6;
			}
			if (addLockheedMartin.Value)
			{
				Transform child = childProjectileGhostPrefab.transform.GetChild(0);
				Object.Destroy((Object)(object)((Component)child).GetComponent<ObjectScaleCurve>());
				Object.Destroy((Object)(object)((Component)child).GetComponent<ObjectTransformCurve>());
				Object.Destroy((Object)(object)((Component)child).GetComponent<ObjectScaleCurve>());
				child.localScale = new Vector3(1f, 1f, 1f);
				childProjectilePrefabOrig.AddComponent<LockheedMartinController>();
				childProjectilePrefab.GetComponent<ProjectileController>().ghostPrefab = childProjectileGhostPrefab;
				childProjectilePrefab.GetComponent<SphereCollider>().radius = 0.1f;
				((ProjectileExplosion)childProjectilePrefab.GetComponent<ProjectileImpactExplosion>()).blastRadius = 1.25f;
				childProjectileGhostPrefab.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
				ContentAddition.AddEffect(childProjectileGhostPrefab);
				ContentAddition.AddProjectile(childProjectilePrefab);
			}
			if (!changeAI.Value)
			{
				return;
			}
			foreach (AISkillDriver item in childMasterPrefab.GetComponents<AISkillDriver>().ToList())
			{
				if (item.customName == "FireSparkBall")
				{
					item.minDistance = 25f;
					item.maxDistance = 50f;
				}
				if (item.customName == "RunAway")
				{
					item.maxDistance = 25f;
				}
			}
		}
	}
	public class LockheedMartinController : MonoBehaviour
	{
		private float damage;

		private bool crit;

		private float stopwatch;

		private float interval = 1f;

		private GameObject projectilePrefab = ChildTweaks.childProjectilePrefab;

		private void Start()
		{
			ProjectileDamage component = ((Component)this).GetComponent<ProjectileDamage>();
			if (Object.op_Implicit((Object)(object)component))
			{
				damage = component.damage * 0.25f;
				crit = component.crit;
			}
		}

		private void FixedUpdate()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			stopwatch += Time.fixedDeltaTime;
			if (stopwatch >= interval)
			{
				stopwatch -= interval;
				EffectManager.SpawnEffect(ChildTweaks.shootVFXPrefab, new EffectData
				{
					origin = ((Component)this).transform.position,
					scale = 0.5f
				}, true);
				ProjectileManager.instance.FireProjectile(projectilePrefab, ((Component)this).transform.position, ((Component)this).transform.rotation, ((Component)this).gameObject, damage, 0f, crit, (DamageColorIndex)0, (GameObject)null, 30f);
			}
		}
	}
}