Decompiled source of ScorchWurmTweaks v1.0.2

ScorchWurmTweaks.dll

Decompiled 3 months 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.Scorchling;
using KinematicCharacterController;
using Microsoft.CodeAnalysis;
using On;
using On.EntityStates.Scorchling;
using On.RoR2;
using RoR2;
using RoR2.CharacterAI;
using RoR2.Projectile;
using UnityEngine;
using UnityEngine.AddressableAssets;
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("ScorchWurmTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScorchWurmTweaks")]
[assembly: AssemblyTitle("ScorchWurmTweaks")]
[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 ScorchWurmTweaks
{
	[BepInPlugin("com.Nuxlar.ScorchWurmTweaks", "ScorchWurmTweaks", "1.0.2")]
	public class ScorchWurmTweaks : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_OnBodyStart <>9__13_0;

			public static hook_Burrow <>9__13_1;

			public static hook_Breach <>9__13_2;

			internal void <Awake>b__13_0(orig_OnBodyStart orig, CharacterMaster self, CharacterBody body)
			{
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				orig.Invoke(self, body);
				if (((Object)body).name == "ScorchlingBody(Clone)")
				{
					Transform modelTransform = body.modelLocator.modelTransform;
					HurtBoxGroup component = ((Component)modelTransform).GetComponent<HurtBoxGroup>();
					Transform child = modelTransform.GetChild(0);
					GameObject obj = Object.Instantiate<GameObject>(((Component)modelTransform.GetChild(0).GetChild(0).GetChild(0)
						.GetChild(0)
						.GetChild(0)
						.GetChild(1)).gameObject, child);
					obj.transform.localPosition = new Vector3(0f, 0.5f, 0f);
					obj.transform.localScale = new Vector3(2f, 1.5f, 2f);
					HurtBox component2 = obj.GetComponent<HurtBox>();
					component.hurtBoxes = new List<HurtBox>(component.hurtBoxes) { component2 }.ToArray();
				}
			}

			internal void <Awake>b__13_1(orig_Burrow orig, ScorchlingController self)
			{
				//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)
				self.isRecentlyBurrowed = true;
				self.isBurrowed = true;
				self.SetTeleportPermission(true);
				if (NetworkServer.active)
				{
					self.breachSkill.stock = 1;
					self.lavaBombSkill.stock = 0;
					self.ensureBurrowSkill.stock = 5;
					self.characterMotor.walkSpeedPenaltyCoefficient = 1f;
				}
				self.originalLayer = ((Component)self).gameObject.layer;
				((Component)self).gameObject.layer = LayerIndex.GetAppropriateFakeLayerForTeam(self.characterBody.teamComponent.teamIndex).intVal;
				((BaseCharacterController)self.characterMotor).Motor.RebuildCollidableLayers();
				if (Object.op_Implicit((Object)(object)self.baseDirt) && Object.op_Implicit((Object)(object)self.dustTrail))
				{
					self.baseDirt.SetActive(false);
					self.dustTrail.SetActive(true);
					self.dustTrailActive = true;
					((Component)self.armatureObject.transform.GetChild(0)).gameObject.SetActive(false);
					((Component)self.armatureObject.transform.GetChild(1)).gameObject.SetActive(true);
					self.meshObject.SetActive(false);
				}
			}

			internal void <Awake>b__13_2(orig_Breach orig, ScorchlingController self)
			{
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: 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)
				//IL_00d3: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				self.isBurrowed = false;
				self.SetTeleportPermission(false);
				if (NetworkServer.active)
				{
					self.breachSkill.stock = 0;
					self.lavaBombSkill.stock = 1;
					self.ensureBurrowSkill.stock = 5;
					self.characterMotor.walkSpeedPenaltyCoefficient = 0f;
					if (Object.op_Implicit((Object)(object)self.characterBody))
					{
						self.characterBody.isSprinting = false;
					}
					if (Object.op_Implicit((Object)(object)self.rigidBodyMotor))
					{
						self.rigidBodyMotor.moveVector = Vector3.zero;
					}
					self.breachBaseDirtRotation = self.baseDirt.transform.rotation;
					((Quaternion)(ref self.breachBaseDirtRotation)).eulerAngles = new Vector3(((Quaternion)(ref self.breachBaseDirtRotation)).eulerAngles.x, Mathf.Floor(((Quaternion)(ref self.breachBaseDirtRotation)).eulerAngles.y), ((Quaternion)(ref self.breachBaseDirtRotation)).eulerAngles.z);
					self.baseDirt.transform.localEulerAngles = Vector3.zero;
					self.baseDirt.transform.rotation = self.breachBaseDirtRotation;
				}
				((Component)self).gameObject.layer = self.originalLayer;
				((BaseCharacterController)self.characterMotor).Motor.RebuildCollidableLayers();
				if (Object.op_Implicit((Object)(object)self.baseDirt) && Object.op_Implicit((Object)(object)self.dustTrail))
				{
					self.baseDirt.SetActive(true);
					self.dustTrail.SetActive(false);
					self.dustTrailActive = false;
					((Component)self.armatureObject.transform.GetChild(0)).gameObject.SetActive(true);
					((Component)self.armatureObject.transform.GetChild(1)).gameObject.SetActive(false);
					self.meshObject.SetActive(true);
				}
			}
		}

		private GameObject scorchlingProjectile = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Scorchling/ScorchlingBombProjectile.prefab").WaitForCompletion();

		private GameObject scorchlingDOTProjectile = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Scorchling/LavaBombHeatOrbProjectile.prefab").WaitForCompletion();

		private GameObject scorchlingMaster = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Scorchling/ScorchlingMaster.prefab").WaitForCompletion();

		private GameObject scorchlingOrbGhost = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Scorchling/LavaBombHeatOrbGhost.prefab").WaitForCompletion();

		private SurfaceDef scorchlingDef = Addressables.LoadAssetAsync<SurfaceDef>((object)"RoR2/DLC2/Scorchling/sdScorchling.asset").WaitForCompletion();

		public static ConfigEntry<bool> changeDOTDuration;

		public static ConfigEntry<bool> changeAI;

		public static ConfigEntry<bool> changeDamage;

		public static ConfigEntry<bool> removeImmune;

		private static ConfigFile SWTConfig { 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_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			SWTConfig = new ConfigFile(Paths.ConfigPath + "\\com.Nuxlar.ScorchWurmTweaks.cfg", true);
			changeDOTDuration = SWTConfig.Bind<bool>("General", "Change duration of DOT sphere", true, "Should the duration of the fire orb be reduced? 7s -> 5s");
			changeAI = SWTConfig.Bind<bool>("General", "Change AI", true, "Should the AI be changed?");
			changeDamage = SWTConfig.Bind<bool>("General", "Change damage", true, "Should the damage of the lava bomb be reduced?");
			removeImmune = SWTConfig.Bind<bool>("General", "Remove Immune", true, "Should a hurtbox be added so the wurm can be damaged underground?");
			scorchlingOrbGhost.AddComponent<WurmProjFixer>();
			if (changeDOTDuration.Value)
			{
				scorchlingDOTProjectile.GetComponent<DestroyOnTimer>().duration = 5f;
				scorchlingDOTProjectile.GetComponent<ProjectileDotZone>().lifetime = 5f;
			}
			if (changeAI.Value)
			{
				foreach (AISkillDriver item in scorchlingMaster.GetComponents<AISkillDriver>().ToList())
				{
					if (item.customName == "LavaBomb")
					{
						item.selectionRequiresAimTarget = true;
						item.selectionRequiresTargetLoS = true;
						item.activationRequiresTargetLoS = true;
						item.activationRequiresAimTargetLoS = true;
						item.minDistance = 0f;
					}
					if (item.customName == "FollowNodeGraphToTarget")
					{
						item.minDistance = 5f;
					}
					if (item.customName == "ChaseOffNodegraph" || item.customName == "ChaseOffNodegraphClose")
					{
						Object.Destroy((Object)(object)item);
					}
				}
				ScorchlingBreach.OnEnter += new hook_OnEnter(TweakBreach);
			}
			if (changeDamage.Value)
			{
				ScorchlingLavaBomb.OnEnter += new hook_OnEnter(TweakLavaBomb);
			}
			if (!removeImmune.Value)
			{
				return;
			}
			object obj = <>c.<>9__13_0;
			if (obj == null)
			{
				hook_OnBodyStart val = delegate(orig_OnBodyStart orig, CharacterMaster self, CharacterBody body)
				{
					//IL_007b: Unknown result type (might be due to invalid IL or missing references)
					//IL_009a: Unknown result type (might be due to invalid IL or missing references)
					orig.Invoke(self, body);
					if (((Object)body).name == "ScorchlingBody(Clone)")
					{
						Transform modelTransform = body.modelLocator.modelTransform;
						HurtBoxGroup component = ((Component)modelTransform).GetComponent<HurtBoxGroup>();
						Transform child = modelTransform.GetChild(0);
						GameObject obj4 = Object.Instantiate<GameObject>(((Component)modelTransform.GetChild(0).GetChild(0).GetChild(0)
							.GetChild(0)
							.GetChild(0)
							.GetChild(1)).gameObject, child);
						obj4.transform.localPosition = new Vector3(0f, 0.5f, 0f);
						obj4.transform.localScale = new Vector3(2f, 1.5f, 2f);
						HurtBox component2 = obj4.GetComponent<HurtBox>();
						component.hurtBoxes = new List<HurtBox>(component.hurtBoxes) { component2 }.ToArray();
					}
				};
				<>c.<>9__13_0 = val;
				obj = (object)val;
			}
			CharacterMaster.OnBodyStart += (hook_OnBodyStart)obj;
			object obj2 = <>c.<>9__13_1;
			if (obj2 == null)
			{
				hook_Burrow val2 = delegate(orig_Burrow orig, ScorchlingController self)
				{
					//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)
					self.isRecentlyBurrowed = true;
					self.isBurrowed = true;
					self.SetTeleportPermission(true);
					if (NetworkServer.active)
					{
						self.breachSkill.stock = 1;
						self.lavaBombSkill.stock = 0;
						self.ensureBurrowSkill.stock = 5;
						self.characterMotor.walkSpeedPenaltyCoefficient = 1f;
					}
					self.originalLayer = ((Component)self).gameObject.layer;
					((Component)self).gameObject.layer = LayerIndex.GetAppropriateFakeLayerForTeam(self.characterBody.teamComponent.teamIndex).intVal;
					((BaseCharacterController)self.characterMotor).Motor.RebuildCollidableLayers();
					if (Object.op_Implicit((Object)(object)self.baseDirt) && Object.op_Implicit((Object)(object)self.dustTrail))
					{
						self.baseDirt.SetActive(false);
						self.dustTrail.SetActive(true);
						self.dustTrailActive = true;
						((Component)self.armatureObject.transform.GetChild(0)).gameObject.SetActive(false);
						((Component)self.armatureObject.transform.GetChild(1)).gameObject.SetActive(true);
						self.meshObject.SetActive(false);
					}
				};
				<>c.<>9__13_1 = val2;
				obj2 = (object)val2;
			}
			ScorchlingController.Burrow += (hook_Burrow)obj2;
			object obj3 = <>c.<>9__13_2;
			if (obj3 == null)
			{
				hook_Breach val3 = delegate(orig_Breach orig, ScorchlingController self)
				{
					//IL_008e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0093: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b4: 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)
					//IL_00d3: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
					//IL_0078: Unknown result type (might be due to invalid IL or missing references)
					//IL_007d: Unknown result type (might be due to invalid IL or missing references)
					self.isBurrowed = false;
					self.SetTeleportPermission(false);
					if (NetworkServer.active)
					{
						self.breachSkill.stock = 0;
						self.lavaBombSkill.stock = 1;
						self.ensureBurrowSkill.stock = 5;
						self.characterMotor.walkSpeedPenaltyCoefficient = 0f;
						if (Object.op_Implicit((Object)(object)self.characterBody))
						{
							self.characterBody.isSprinting = false;
						}
						if (Object.op_Implicit((Object)(object)self.rigidBodyMotor))
						{
							self.rigidBodyMotor.moveVector = Vector3.zero;
						}
						self.breachBaseDirtRotation = self.baseDirt.transform.rotation;
						((Quaternion)(ref self.breachBaseDirtRotation)).eulerAngles = new Vector3(((Quaternion)(ref self.breachBaseDirtRotation)).eulerAngles.x, Mathf.Floor(((Quaternion)(ref self.breachBaseDirtRotation)).eulerAngles.y), ((Quaternion)(ref self.breachBaseDirtRotation)).eulerAngles.z);
						self.baseDirt.transform.localEulerAngles = Vector3.zero;
						self.baseDirt.transform.rotation = self.breachBaseDirtRotation;
					}
					((Component)self).gameObject.layer = self.originalLayer;
					((BaseCharacterController)self.characterMotor).Motor.RebuildCollidableLayers();
					if (Object.op_Implicit((Object)(object)self.baseDirt) && Object.op_Implicit((Object)(object)self.dustTrail))
					{
						self.baseDirt.SetActive(true);
						self.dustTrail.SetActive(false);
						self.dustTrailActive = false;
						((Component)self.armatureObject.transform.GetChild(0)).gameObject.SetActive(true);
						((Component)self.armatureObject.transform.GetChild(1)).gameObject.SetActive(false);
						self.meshObject.SetActive(true);
					}
				};
				<>c.<>9__13_2 = val3;
				obj3 = (object)val3;
			}
			ScorchlingController.Breach += (hook_Breach)obj3;
		}

		private void TweakLavaBomb(orig_OnEnter orig, ScorchlingLavaBomb self)
		{
			ScorchlingLavaBomb.mortarDamageCoefficient = 1.5f;
			orig.Invoke(self);
		}

		private void TweakBreach(orig_OnEnter orig, ScorchlingBreach self)
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			IntPtr functionPointer = typeof(BaseState).GetMethod("OnEnter").MethodHandle.GetFunctionPointer();
			((Action)Activator.CreateInstance(typeof(Action), self, functionPointer))();
			self.proceedImmediatelyToLavaBomb = true;
			self.amServer = NetworkServer.active;
			self.scorchlingController = ((Component)((EntityState)self).characterBody).GetComponent<ScorchlingController>();
			Util.PlaySound(self.preBreachSoundString, ((EntityState)self).gameObject);
			if (self.amServer)
			{
				if (self.proceedImmediatelyToLavaBomb)
				{
					self.breachToBurrow = 1f;
				}
				self.breachToBurrow += self.crackToBreachTime;
				self.burrowToEndOfTime += self.breachToBurrow;
				self.breachPosition = ((EntityState)self).characterBody.footPosition;
				if (Object.op_Implicit((Object)(object)((EntityState)self).characterMotor))
				{
					((EntityState)self).characterMotor.walkSpeedPenaltyCoefficient = 0f;
				}
				((EntityState)self).characterBody.SetAimTimer(self.breachToBurrow);
				TeleportHelper.TeleportBody(((EntityState)self).characterBody, self.breachPosition);
				EffectManager.SpawnEffect(self.crackEffectPrefab, new EffectData
				{
					origin = self.breachPosition,
					scale = self.crackRadius
				}, true);
				self.scorchlingController.SetTeleportPermission(false);
			}
		}
	}
	public class WurmProjFixer : MonoBehaviour
	{
		private void Start()
		{
			Object.Destroy((Object)(object)((Component)this).GetComponent<EffectManagerHelper>());
		}
	}
}