Decompiled source of ChildTweaks v1.1.0

plugins/ChildTweaks/ChildTweaks.dll

Decompiled 2 days 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 EntityStates;
using HG.Reflection;
using Microsoft.CodeAnalysis;
using R2API;
using RoR2;
using RoR2.Audio;
using RoR2.CharacterAI;
using RoR2.Projectile;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ChildTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+50eceed591db94dfe1112b953c561a47018b0279")]
[assembly: AssemblyProduct("ChildTweaks")]
[assembly: AssemblyTitle("ChildTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ChildTweaks
{
	public class ChildBlink : BaseState
	{
		public static GameObject blinkPrefab = Main.teleportVFX;

		public float duration = 0.3f;

		public float speedCoefficient = 5f;

		public float destealthDuration = 0.5f;

		public Material destealtMat = Main.destealthMat;

		public string beginSoundString = "Play_child_attack2_teleport";

		public string endSoundString = "Play_child_attack2_reappear";

		private Transform modelTransform;

		private float stopwatch;

		private Vector3 blinkVector = Vector3.zero;

		private CharacterModel characterModel;

		private HurtBoxGroup hurtboxGroup;

		public override void OnEnter()
		{
			//IL_00b8: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			((BaseState)this).OnEnter();
			((EntityState)this).PlayAnimation("Gesture, Override", "FrolicEnter", "FrolicEnter.playbackRate", 1f, 0f);
			Util.PlaySound(beginSoundString, ((EntityState)this).gameObject);
			modelTransform = ((EntityState)this).GetModelTransform();
			if (Object.op_Implicit((Object)(object)modelTransform))
			{
				characterModel = ((Component)modelTransform).GetComponent<CharacterModel>();
				hurtboxGroup = ((Component)modelTransform).GetComponent<HurtBoxGroup>();
			}
			if (Object.op_Implicit((Object)(object)characterModel))
			{
				CharacterModel obj = characterModel;
				int invisibilityCount = obj.invisibilityCount + 1;
				obj.invisibilityCount = invisibilityCount;
			}
			if (Object.op_Implicit((Object)(object)hurtboxGroup))
			{
				HurtBoxGroup obj2 = hurtboxGroup;
				int invisibilityCount = obj2.hurtBoxesDeactivatorCounter + 1;
				obj2.hurtBoxesDeactivatorCounter = invisibilityCount;
			}
			blinkVector = GetBlinkVector();
			CreateBlinkEffect(Util.GetCorePosition(((EntityState)this).gameObject));
		}

		protected virtual Vector3 GetBlinkVector()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return ((EntityState)this).inputBank.aimDirection;
		}

		private void CreateBlinkEffect(Vector3 origin)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			EffectManager.SpawnEffect(blinkPrefab, new EffectData
			{
				rotation = Util.QuaternionSafeLookRotation(blinkVector),
				origin = origin
			}, false);
		}

		public override void FixedUpdate()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			((EntityState)this).FixedUpdate();
			stopwatch += ((EntityState)this).GetDeltaTime();
			if (Object.op_Implicit((Object)(object)((EntityState)this).characterMotor) && Object.op_Implicit((Object)(object)((EntityState)this).characterDirection))
			{
				((EntityState)this).characterMotor.velocity = Vector3.zero;
				CharacterMotor characterMotor = ((EntityState)this).characterMotor;
				characterMotor.rootMotion += blinkVector * (base.moveSpeedStat * speedCoefficient * ((EntityState)this).GetDeltaTime());
			}
			if (!((double)stopwatch < (double)duration) && ((EntityState)this).isAuthority)
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override void OnExit()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!((EntityState)this).outer.destroying)
			{
				Util.PlaySound(endSoundString, ((EntityState)this).gameObject);
				CreateBlinkEffect(Util.GetCorePosition(((EntityState)this).gameObject));
				modelTransform = ((EntityState)this).GetModelTransform();
				if (Object.op_Implicit((Object)(object)modelTransform))
				{
					TemporaryOverlayInstance obj = TemporaryOverlayManager.AddOverlay(((Component)modelTransform).gameObject);
					obj.duration = destealthDuration;
					obj.destroyComponentOnEnd = true;
					obj.originalMaterial = destealtMat;
					obj.inspectorCharacterModel = ((Component)modelTransform).gameObject.GetComponent<CharacterModel>();
					obj.alphaCurve = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f);
					obj.animateShaderAlpha = true;
				}
			}
			if (Object.op_Implicit((Object)(object)characterModel))
			{
				CharacterModel obj2 = characterModel;
				int invisibilityCount = obj2.invisibilityCount - 1;
				obj2.invisibilityCount = invisibilityCount;
			}
			if (Object.op_Implicit((Object)(object)hurtboxGroup))
			{
				HurtBoxGroup obj3 = hurtboxGroup;
				int invisibilityCount = obj3.hurtBoxesDeactivatorCounter - 1;
				obj3.hurtBoxesDeactivatorCounter = invisibilityCount;
			}
			if (Object.op_Implicit((Object)(object)((EntityState)this).characterMotor))
			{
				((EntityState)this).characterMotor.disableAirControlUntilCollision = false;
			}
			((EntityState)this).OnExit();
		}
	}
	internal static class Log
	{
		internal static ManualLogSource _logSource;

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

		private static string getLogPrefix(string callerPath, string callerMemberName, int callerLineNumber)
		{
			int num = callerPath.LastIndexOf("ChildTweaks");
			if (num >= 0)
			{
				callerPath = callerPath.Substring(num + "ChildTweaks".Length + 1);
			}
			return $"{callerPath}:{callerLineNumber} ({callerMemberName}) ";
		}

		internal static void Error(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogError((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

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

		internal static void Fatal(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogFatal((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Fatal_NoCallerPrefix(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogInfo((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

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

		internal static void Message(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogMessage((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Message_NoCallerPrefix(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogWarning((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Warning_NoCallerPrefix(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("Nuxlar.ChildTweaks", "ChildTweaks", "1.1.0")]
	public class Main : BaseUnityPlugin
	{
		public const string PluginGUID = "Nuxlar.ChildTweaks";

		public const string PluginAuthor = "Nuxlar";

		public const string PluginName = "ChildTweaks";

		public const string PluginVersion = "1.1.0";

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

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

		private SpawnCard spawnCard = Addressables.LoadAssetAsync<SpawnCard>((object)"RoR2/DLC2/Child/cscChild.asset").WaitForCompletion();

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

		public LoopSoundDef lsdSparkProjectile = ScriptableObject.CreateInstance<LoopSoundDef>();

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

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

		public static Material destealthMat = Addressables.LoadAssetAsync<Material>((object)"RoR2/Base/Parent/matParentDissolve.mat").WaitForCompletion();

		private SkillDef skillDef = ScriptableObject.CreateInstance<SkillDef>();

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

		internal static Main Instance { get; private set; }

		public static string PluginDirectory { get; private set; }

		public void Awake()
		{
			//IL_0019: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			CreateSkill();
			bool flag = default(bool);
			ContentAddition.AddEntityState<ChildBlink>(ref flag);
			childBody.transform.GetChild(0).GetChild(0).GetChild(1)
				.GetChild(2)
				.position = new Vector3(0f, 2.5f, 0f);
			lsdSparkProjectile.startSoundName = "Play_spark_projectile_loop";
			lsdSparkProjectile.stopSoundName = "Stop_spark_projectile_loop";
			sparkProjectile.GetComponent<ProjectileController>().flightSoundLoop = lsdSparkProjectile;
			Transform child = sparkProjectileGhost.transform.GetChild(0);
			Object.Destroy((Object)(object)((Component)child).GetComponent<ObjectScaleCurve>());
			Object.Destroy((Object)(object)((Component)child).GetComponent<ObjectScaleCurve>());
			Object.Destroy((Object)(object)((Component)child).GetComponent<ObjectTransformCurve>());
			sparkProjectile.GetComponent<ProjectileSimple>().enableVelocityOverLifetime = false;
			Object.Destroy((Object)(object)childBody.GetComponent<ChildMonsterController>());
			Object.Destroy((Object)(object)childBody.GetComponent<SetStateOnHurt>());
			spawnCard.directorCreditCost = 20;
			AISkillDriver[] components = childMaster.GetComponents<AISkillDriver>();
			foreach (AISkillDriver val in components)
			{
				if (val.customName == "Frolic")
				{
					val.movementType = (MovementType)3;
					val.aimType = (AimType)4;
					val.shouldSprint = true;
					val.requiredSkill = null;
				}
				if (val.customName == "RunAway")
				{
					val.maxDistance = 20f;
				}
				if (val.customName == "FireSparkBall")
				{
					val.maxDistance = 45f;
					val.minDistance = 15f;
				}
				if (val.customName == "PathFromAfar")
				{
					val.movementType = (MovementType)1;
					val.minDistance = 25f;
					val.shouldSprint = true;
				}
			}
			SetAddressableEntityStateField("RoR2/DLC2/Child/EntityStates.ChildMonster.FireTrackingSparkBall.asset", "bombDamageCoefficient", "2");
		}

		public static bool SetAddressableEntityStateField(string fullEntityStatePath, string fieldName, string value)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			EntityStateConfiguration val = Addressables.LoadAssetAsync<EntityStateConfiguration>((object)fullEntityStatePath).WaitForCompletion();
			for (int i = 0; i < val.serializedFieldsCollection.serializedFields.Length; i++)
			{
				if (val.serializedFieldsCollection.serializedFields[i].fieldName == fieldName)
				{
					val.serializedFieldsCollection.serializedFields[i].fieldValue.stringValue = value;
					return true;
				}
			}
			return false;
		}

		private void CreateSkill()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_011e: 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)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			skillDef.skillName = "ChildBlink";
			((Object)skillDef).name = "ChildBlink";
			skillDef.activationState = new SerializableEntityStateType(typeof(ChildBlink));
			skillDef.activationStateMachineName = "Body";
			skillDef.interruptPriority = (InterruptPriority)5;
			skillDef.baseMaxStock = 1;
			skillDef.baseRechargeInterval = 8f;
			skillDef.rechargeStock = 1;
			skillDef.requiredStock = 1;
			skillDef.stockToConsume = 1;
			skillDef.dontAllowPastMaxStocks = true;
			skillDef.beginSkillCooldownOnSkillEnd = false;
			skillDef.canceledFromSprinting = false;
			skillDef.forceSprintDuringState = true;
			skillDef.fullRestockOnAssign = true;
			skillDef.resetCooldownTimerOnUse = true;
			skillDef.isCombatSkill = false;
			skillDef.mustKeyPress = false;
			skillDef.cancelSprintingOnActivation = false;
			SkillFamily val = ScriptableObject.CreateInstance<SkillFamily>();
			((Object)val).name = "ChildSecondaryAltFamily";
			val.variants = (Variant[])(object)new Variant[1]
			{
				new Variant
				{
					skillDef = skillDef
				}
			};
			GenericSkill val2 = childBody.AddComponent<GenericSkill>();
			val2._skillFamily = val;
			childBody.GetComponent<SkillLocator>().secondary = val2;
			ContentAddition.AddSkillFamily(val);
			ContentAddition.AddSkillDef(skillDef);
		}
	}
}