Decompiled source of StandaloneMajorConstruct v1.0.0

StandaloneMajorConstruct.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.EngiTurret.EngiTurretWeapon;
using EntityStates.MajorConstruct;
using EntityStates.MajorConstruct.Stance;
using EntityStates.MajorConstruct.Weapon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using On.EntityStates;
using On.EntityStates.MajorConstruct.Stance;
using On.EntityStates.MajorConstruct.Weapon;
using R2API;
using RoR2;
using RoR2.ExpansionManagement;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("StandaloneMajorConstruct")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StandaloneMajorConstruct")]
[assembly: AssemblyTitle("StandaloneMajorConstruct")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 StandaloneMajorConstruct
{
	[BepInPlugin("Saltlords.StandaloneMajorConstruct", "StandaloneMajorConstruct", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Main : BaseUnityPlugin
	{
		public const string PluginGUID = "Saltlords.StandaloneMajorConstruct";

		public const string PluginAuthor = "Saltlords";

		public const string PluginName = "StandaloneMajorConstruct";

		public const string PluginVersion = "1.0.0";

		public static ManualLogSource Log;

		public static PluginInfo pluginInfo;

		public static Harmony Harmony;

		public static ConfigFile Config;

		public static ConfigEntry<string> MajorConstructSpawn;

		public static ConfigEntry<int> MajorConstructMinStage;

		public static ConfigEntry<float> MajorConstructHealth;

		public static ConfigEntry<float> MajorConstructHealthStack;

		public static ConfigEntry<float> MajorConstructDamage;

		public static ConfigEntry<float> MajorConstructDamageStack;

		public static ConfigEntry<float> MajorConstructAttackSpeed;

		public static ConfigEntry<float> MajorConstructArmor;

		public static ConfigEntry<int> MajorConstructCost;

		public static ConfigEntry<float> MajorConstructDeathTimer;

		public static ConfigEntry<int> MajorConstructSpawnAmount;

		public static ConfigEntry<bool> MajorConstructSpawnAlt;

		public static ConfigEntry<float> MajorConstructBeamDistance;

		public static ConfigEntry<float> MajorConstructAimSpeed;

		public static ExpansionDef DLC1 = null;

		public static List<DirectorCardCategorySelection> customFamilies = new List<DirectorCardCategorySelection>();

		public static event Action<ClassicStageInfo> onRebuildCards;

		public void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Expected O, but got Unknown
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Expected O, but got Unknown
			pluginInfo = ((BaseUnityPlugin)this).Info;
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony = new Harmony("Saltlords.StandaloneMajorConstruct");
			Config = new ConfigFile(Path.Combine(Paths.ConfigPath, "Saltlords.StandaloneMajorConstruct.cfg"), true);
			MajorConstructSpawn = Config.Bind<string>("Spawns", "Major Construct Spawn Scenes", "skymeadow, itskymeadow, sulfurpools, itgolemplains, golemplains, golemplains2, forgottenhaven, FBLScene", "List of scene names, separated by comma. By default, where Xi Construct spawns.");
			MajorConstructMinStage = Config.Bind<int>("Spawns", "Major Construct Minimum Stage", 4, "Starting stage.");
			MajorConstructHealth = Config.Bind<float>("Basic Stats", "Major Construct Base Health", 2100f, "");
			MajorConstructHealthStack = Config.Bind<float>("Basic Stats", "Major Construct Health Increase Per Level", 630f, "");
			MajorConstructDamage = Config.Bind<float>("Basic Stats", "Major Construct Base Damage", 25f, "");
			MajorConstructDamageStack = Config.Bind<float>("Basic Stats", "Major Construct Damage Increase Per Level", 5f, "");
			MajorConstructAttackSpeed = Config.Bind<float>("Basic Stats", "Major Construct Attack Speed", 1f, "");
			MajorConstructArmor = Config.Bind<float>("Basic Stats", "Major Construct Armor", 15f, "");
			MajorConstructCost = Config.Bind<int>("Basic Stats", "Major Construct Director Cost", 800, "");
			MajorConstructDeathTimer = Config.Bind<float>("Major Construct", "Death Timer", 5f, "Amount of seconds to show death animation for");
			MajorConstructSpawnAmount = Config.Bind<int>("Major Construct", "Spawn Amount", 3, "Amount of enemies to spawn in pillar raise phase");
			MajorConstructSpawnAlt = Config.Bind<bool>("Major Construct", "Dont chhange this", true, "Dont change");
			MajorConstructBeamDistance = Config.Bind<float>("Major Construct", "Beam Distance", 150f, "Used to be 999");
			MajorConstructAimSpeed = Config.Bind<float>("Major Construct", "Aim Speed", 10f, "Strafe around!");
			Reworks.MajorConstruct();
			DLC1 = vanilla<ExpansionDef>("DLC1/Common/DLC1");
			((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)delegate
			{
				CharacterBody component = BodyCatalog.FindBodyPrefab("MajorConstructBody").GetComponent<CharacterBody>();
				component.baseMaxHealth = MajorConstructHealth.Value;
				component.levelMaxHealth = MajorConstructHealthStack.Value;
				component.baseDamage = MajorConstructDamage.Value;
				component.levelDamage = MajorConstructDamageStack.Value;
				component.baseAttackSpeed = MajorConstructAttackSpeed.Value;
				component.baseArmor = MajorConstructArmor.Value;
				component.isChampion = true;
				if (!string.IsNullOrWhiteSpace(MajorConstructSpawn.Value))
				{
					((Component)component).GetComponent<DeathRewards>().bossDropTable = (PickupDropTable)(object)vanilla<ExplicitPickupDropTable>("DLC1/MajorAndMinorConstruct/dtBossMegaConstruct");
					((Component)component).GetComponent<DeathRewards>().logUnlockableDef = LegacyResourcesAPI.Load<UnlockableDef>("UnlockableDefs/Logs.MajorConstructBody");
				}
			});
			CharacterSpawnCard val = vanilla<CharacterSpawnCard>("DLC1/MajorAndMinorConstruct/cscMajorConstruct");
			((SpawnCard)val).directorCreditCost = MajorConstructCost.Value;
			DirectorCard card = new DirectorCard
			{
				spawnCard = (SpawnCard)(object)val,
				selectionWeight = 1,
				spawnDistance = (MonsterSpawnDistance)0,
				minimumStageCompletions = MajorConstructMinStage.Value - 1,
				preventOverhead = true
			};
			DirectorCardHolder majorConstructDCH = new DirectorCardHolder
			{
				Card = card,
				MonsterCategory = (MonsterCategory)4
			};
			string[] majorlist = listify(MajorConstructSpawn.Value).ToArray();
			Dictionary<string, List<DirectorCardHolder>> dictionary = new Dictionary<string, List<DirectorCardHolder>>();
			if (!string.IsNullOrWhiteSpace(MajorConstructSpawn.Value))
			{
				Helpers.AddNewMonsterToStagesWhere(majorConstructDCH, false, (Predicate<StageInfo>)((StageInfo info) => majorlist.Contains(info.CustomStageName) || majorlist.Contains(((StageInfo)(ref info)).ToInternalStageName())));
				RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
				{
					DirectorAPI.AddCard(RoR2Content.mixEnemyMonsterCards, majorConstructDCH);
				});
			}
		}

		public static DirectorCard GetDirectorCard(CharacterSpawnCard csc)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			return new DirectorCard
			{
				spawnCard = (SpawnCard)(object)csc,
				selectionWeight = 1,
				preventOverhead = false,
				minimumStageCompletions = 0,
				spawnDistance = (MonsterSpawnDistance)0
			};
		}

		public static bool Mods(params string[] arr)
		{
			for (int i = 0; i < arr.Length; i++)
			{
				if (!Chainloader.PluginInfos.ContainsKey(arr[i]))
				{
					return false;
				}
			}
			return true;
		}

		public static List<string> listify(string list)
		{
			return list.Split(new char[1] { ',' }).ToList().ConvertAll((string x) => x.Trim());
		}

		public static Dictionary<string, string> pairify(string list)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (string item in list.Split(new char[1] { ',' }).ToList())
			{
				List<string> list2 = item.Split(new char[1] { '-' }).ToList().ConvertAll((string x) => x.Trim());
				dictionary.Add(list2[0], list2[1]);
			}
			return dictionary;
		}

		public static T vanilla<T>(string path)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			return Addressables.LoadAssetAsync<T>((object)("RoR2/" + path + ".asset")).WaitForCompletion();
		}
	}
	public class Reworks
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_FixedUpdate <>9__1_0;

			public static hook_OnEnter <>9__1_1;

			public static Action<DamageReport> <>9__1_3;

			internal void <MajorConstruct>b__1_0(orig_FixedUpdate orig, GenericCharacterDeath self)
			{
				orig.Invoke(self);
				if (Main.MajorConstructDeathTimer.Value >= 0f && self is Death && !(((EntityState)self).fixedAge <= Main.MajorConstructDeathTimer.Value) && NetworkServer.active)
				{
					self.DestroyBodyAsapServer();
				}
			}

			internal void <MajorConstruct>b__1_1(orig_OnEnter orig, FireLaser self)
			{
				orig.Invoke(self);
				if (((Object)((EntityState)self).characterBody).name.Contains("MajorConstruct"))
				{
					((FireBeam)self).maxDistance = Main.MajorConstructBeamDistance.Value;
					self.aimMaxSpeed = Main.MajorConstructAimSpeed.Value;
				}
			}

			internal void <MajorConstruct>b__1_3(DamageReport report)
			{
				if (spawnedConstructs.ContainsKey(report.victimBody))
				{
					foreach (GameObject item in spawnedConstructs[report.victimBody])
					{
						if (item == null)
						{
							continue;
						}
						CharacterMaster component = item.GetComponent<CharacterMaster>();
						if (component == null)
						{
							continue;
						}
						GameObject bodyInstanceObject = component.bodyInstanceObject;
						if (bodyInstanceObject != null)
						{
							HealthComponent component2 = bodyInstanceObject.GetComponent<HealthComponent>();
							if (component2 != null)
							{
								component2.Suicide(((Component)report.attackerBody).gameObject, (GameObject)null, (DamageType)0);
							}
						}
					}
				}
				spawnedConstructs.Remove(report.victimBody);
			}
		}

		public static Dictionary<CharacterBody, List<GameObject>> spawnedConstructs = new Dictionary<CharacterBody, List<GameObject>>();

		public static void MajorConstruct()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//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)
			//IL_0079: Expected O, but got Unknown
			object obj = <>c.<>9__1_0;
			if (obj == null)
			{
				hook_FixedUpdate val = delegate(orig_FixedUpdate orig, GenericCharacterDeath self)
				{
					orig.Invoke(self);
					if (Main.MajorConstructDeathTimer.Value >= 0f && self is Death && !(((EntityState)self).fixedAge <= Main.MajorConstructDeathTimer.Value) && NetworkServer.active)
					{
						self.DestroyBodyAsapServer();
					}
				};
				<>c.<>9__1_0 = val;
				obj = (object)val;
			}
			GenericCharacterDeath.FixedUpdate += (hook_FixedUpdate)obj;
			string constructToSpawn = (Main.MajorConstructSpawnAlt.Value ? "SigmaConstructBody" : "MinorConstructBody");
			CharacterSpawnCard card = LegacyResourcesAPI.Load<CharacterSpawnCard>("SpawnCards/CharacterSpawnCards/cscMinorConstruct");
			object obj2 = <>c.<>9__1_1;
			if (obj2 == null)
			{
				hook_OnEnter val2 = delegate(orig_OnEnter orig, FireLaser self)
				{
					orig.Invoke(self);
					if (((Object)((EntityState)self).characterBody).name.Contains("MajorConstruct"))
					{
						((FireBeam)self).maxDistance = Main.MajorConstructBeamDistance.Value;
						self.aimMaxSpeed = Main.MajorConstructAimSpeed.Value;
					}
				};
				<>c.<>9__1_1 = val2;
				obj2 = (object)val2;
			}
			FireLaser.OnEnter += (hook_OnEnter)obj2;
			LoweredToRaised.OnEnter += (hook_OnEnter)delegate(orig_OnEnter orig, LoweredToRaised self)
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: 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_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
				//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_00d8: 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_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: 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_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_0139: 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_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_015e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Expected O, but got Unknown
				//IL_016f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Unknown result type (might be due to invalid IL or missing references)
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_0194: Expected O, but got Unknown
				//IL_018f: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
				orig.Invoke(self);
				if (Main.MajorConstructSpawnAmount.Value > 0 && NetworkServer.active)
				{
					HurtBox[] hurtBoxes = new SphereSearch
					{
						origin = ((EntityState)self).gameObject.transform.position,
						radius = 37.5f,
						mask = ((LayerIndex)(ref LayerIndex.entityPrecise)).mask
					}.RefreshCandidates().FilterCandidatesByDistinctHurtBoxEntities().GetHurtBoxes();
					foreach (HurtBox val3 in hurtBoxes)
					{
						CharacterBody body = val3.healthComponent.body;
						if (Object.op_Implicit((Object)(object)body) && ((Object)body).name == constructToSpawn)
						{
							return;
						}
					}
					Quaternion val4 = Quaternion.AngleAxis(120f, Vector3.up);
					Vector3 val5 = ((EntityState)self).transform.forward * 16f;
					if (!spawnedConstructs.ContainsKey(((EntityState)self).characterBody))
					{
						spawnedConstructs.Add(((EntityState)self).characterBody, new List<GameObject>());
					}
					for (int j = 0; j < Main.MajorConstructSpawnAmount.Value; j++)
					{
						Vector3 val6 = val5 + ((EntityState)self).transform.position;
						GameObject spawnedInstance = ((SpawnCard)card).DoSpawn(val6, Quaternion.Euler(((EntityState)self).transform.forward), new DirectorSpawnRequest((SpawnCard)(object)card, new DirectorPlacementRule
						{
							position = val6,
							placementMode = (PlacementMode)0
						}, Run.instance.spawnRng)
						{
							teamIndexOverride = ((EntityState)self).characterBody.teamComponent.teamIndex
						}).spawnedInstance;
						NetworkServer.Spawn(spawnedInstance);
						spawnedConstructs[((EntityState)self).characterBody].Add(spawnedInstance);
						val5 = val4 * val5;
					}
				}
			};
			GlobalEventManager.onCharacterDeathGlobal += delegate(DamageReport report)
			{
				if (spawnedConstructs.ContainsKey(report.victimBody))
				{
					foreach (GameObject item in spawnedConstructs[report.victimBody])
					{
						if (item != null)
						{
							CharacterMaster component = item.GetComponent<CharacterMaster>();
							if (component != null)
							{
								GameObject bodyInstanceObject = component.bodyInstanceObject;
								if (bodyInstanceObject != null)
								{
									HealthComponent component2 = bodyInstanceObject.GetComponent<HealthComponent>();
									if (component2 != null)
									{
										component2.Suicide(((Component)report.attackerBody).gameObject, (GameObject)null, (DamageType)0);
									}
								}
							}
						}
					}
				}
				spawnedConstructs.Remove(report.victimBody);
			};
			LanguageAPI.Add("MAJORCONSTRUCT_BODY_NAME", "Major Construct");
			LanguageAPI.Add("MAJORCONSTRUCT_BODY_SUBTITLE", "Nadir Design");
			LanguageAPI.Add("MAJORCONSTRUCT_BODY_LORE", "<style=cMono>======================================== ====   MyBabel\r\nMachine Translator   ====\r\n$ Resolving... done.\r\n====     [Version 12.45.1.009 ]   ======\r\n========================================\r\nTraining… <100000000 cycles>\r\nTraining… <100000000 cycles>\r\nTraining… <100000000 cycles>\r\nTraining... <103412 cycles>\r\nComplete!\r\nDisplay result? Y/N\r\nY\r\n========================================</style>\r\nENERGY LEVELS: SUSTAINABLE\r\nTHREATS DETECTED; 2147483647\r\nATTEMPTING PRELIMINARY ASSAULT\r\nSCANNING NEARBY AREA; RANGE 200 UNITS\r\nNullReferenceException: Object reference not set to an instance of an object\r\n at MajorConstruct.OnEnter()");
		}
	}
}