Decompiled source of LunarRework v0.2.0

LunarRework.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.EntityLogic;
using RoR2.Navigation;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[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 Prototype
{
	[BepInPlugin("prototype.lunar.rework", "LunarRework", "0.1.1")]
	internal class LunarRework : BaseUnityPlugin
	{
		public const string version = "0.1.1";

		public const string identifier = "prototype.lunar.rework";

		private static AsyncOperationHandle<GameObject> shop;

		private static AsyncOperationHandle<GameObject> pickup;

		private static AsyncOperationHandle<GameObject> model;

		protected void Awake()
		{
			//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_0036: 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_0045: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationHandle<GameObject> val = load("RoR2/Base/LunarChest/LunarChest.prefab");
			val.Completed += delegate(AsyncOperationHandle<GameObject> operation)
			{
				PurchaseInteraction component = operation.Result.GetComponent<PurchaseInteraction>();
				component.cost++;
			};
			shop = load("RoR2/Base/LunarCauldrons/LunarCauldron, RedToWhite Variant.prefab");
			pickup = load("RoR2/DLC1/OptionPickup/OptionPickup.prefab");
			model = load("RoR2/Base/moon/LunarPod, Opened.prefab");
			SceneDirector.onGenerateInteractableCardSelection += OnGenerateInteractableCardSelection;
			Stage.onStageStartGlobal += OnStageStartGlobal;
			Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
			static AsyncOperationHandle<GameObject> load(string key)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return Addressables.LoadAssetAsync<GameObject>((object)key);
			}
		}

		private void OnGenerateInteractableCardSelection(object _, DirectorCardCategorySelection selection)
		{
			//IL_0010: 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)
			//IL_0088: 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)
			Category[] categories = selection.categories;
			for (int i = 0; i < categories.Length; i++)
			{
				DirectorCard[] cards = categories[i].cards;
				for (int j = 0; j < cards.Length; j++)
				{
					ref SpawnCard spawnCard = ref cards[j].spawnCard;
					SpawnCard obj = spawnCard;
					if (((obj != null) ? ((Object)obj).name : null) == "iscLunarChest")
					{
						spawnCard = Object.Instantiate<SpawnCard>(spawnCard);
						SpawnCard obj2 = spawnCard;
						((InteractableSpawnCard)((obj2 is InteractableSpawnCard) ? obj2 : null)).maxSpawnsPerStage = 1;
						SceneDef currentSceneDef = SceneCatalog.currentSceneDef;
						if (((currentSceneDef != null) ? currentSceneDef.cachedName : null) == "ancientloft")
						{
							SpawnCard obj3 = spawnCard;
							obj3.requiredFlags = (NodeFlags)(obj3.requiredFlags & 0xFE);
						}
					}
				}
			}
		}

		private static void OnStageStartGlobal(Stage __instance)
		{
			//IL_00cb: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			string[] delete = new string[1] { "LunarChest" };
			string replace = "mdlLunarChest";
			SceneDef sceneDef = __instance.sceneDef;
			if (Object.op_Implicit((Object)(object)sceneDef))
			{
				switch (sceneDef.stageOrder)
				{
				case 1:
				case 2:
				case 3:
					return;
				case 4:
				case 5:
					if (RoR2Application.isInMultiPlayer)
					{
						return;
					}
					break;
				default:
					if (sceneDef.cachedName == "bazaar")
					{
						if (NetworkServer.active)
						{
							NetworkServer.Spawn(Object.Instantiate<GameObject>(shop.WaitForCompletion(), new Vector3(-123f, -23.67f, -6f), Quaternion.Euler(0f, 90f, 0f)));
						}
						delete = new string[3] { "LunarTable", "LunarRecycler", "DisplayLunarChest" };
					}
					break;
				}
			}
			Scene activeScene = SceneManager.GetActiveScene();
			GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
			for (int i = 0; i < rootGameObjects.Length; i++)
			{
				disable(rootGameObjects[i].transform);
			}
			void disable(Transform transform)
			{
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Expected O, but got Unknown
				GameObject gameObject = ((Component)transform).gameObject;
				string[] array = delete;
				foreach (string value in array)
				{
					if (((Object)gameObject).name.StartsWith(value))
					{
						gameObject.SetActive(false);
						return;
					}
				}
				if (((Object)gameObject).name == replace)
				{
					gameObject.SetActive(false);
					if (Random.value <= 0.75f)
					{
						Object.Instantiate<GameObject>(model.WaitForCompletion(), transform.position, transform.rotation);
					}
					return;
				}
				foreach (Transform item in transform)
				{
					disable(item);
				}
			}
		}

		[HarmonyPatch(typeof(BazaarController), "OnStartServer")]
		[HarmonyPrefix]
		private static void OnStartServer(BazaarController __instance)
		{
			int num = __instance.seerStations.Length - 1;
			GameObject obj = ((Component)__instance.seerStations[num]).gameObject;
			((MonoBehaviour)__instance).StartCoroutine(delay());
			IEnumerator delay()
			{
				yield return (object)new WaitForEndOfFrame();
				obj.SetActive(false);
			}
		}

		[HarmonyPatch(typeof(BazaarController), "SetUpSeerStations")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> SetUpSeerStations(IEnumerable<CodeInstruction> IL)
		{
			MethodInfo method = typeof(List<SceneDef>).GetMethod("Add");
			MethodInfo property = typeof(Xoroshiro128Plus).GetProperty("nextNormalizedFloat").GetMethod;
			bool multiple = true;
			foreach (CodeInstruction instruction in IL)
			{
				if (CodeInstructionExtensions.Calls(instruction, method))
				{
					yield return Transpilers.EmitDelegate<Action<List<SceneDef>, SceneDef>>((Action<List<SceneDef>, SceneDef>)delegate(List<SceneDef> choices, SceneDef stage)
					{
						choices.Add(stage);
						if (multiple = choices.Count > 1)
						{
							choices.Remove(Run.instance?.nextStageScene);
						}
					});
					continue;
				}
				yield return instruction;
				if (CodeInstructionExtensions.Calls(instruction, property))
				{
					yield return Transpilers.EmitDelegate<Func<float, float>>((Func<float, float>)((float roll) => (!multiple) ? (roll * roll * roll) : roll));
				}
			}
		}

		[HarmonyPatch(typeof(PurchaseInteraction), "Awake")]
		[HarmonyPostfix]
		private static void Awake(PurchaseInteraction __instance)
		{
			if (((Object)__instance).name.StartsWith(((Object)shop.WaitForCompletion()).name))
			{
				((UnityEventBase)((Component)__instance).GetComponent<DelayedEvent>().action).SetPersistentListenerState(0, (UnityEventCallState)0);
			}
		}

		[HarmonyPatch(typeof(ChestBehavior), "BaseItemDrop")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> ItemDrop(IEnumerable<CodeInstruction> IL)
		{
			foreach (CodeInstruction instruction in IL)
			{
				if (instruction.opcode == OpCodes.Initobj && typeof(CreatePickupInfo) == instruction.operand as Type)
				{
					yield return new CodeInstruction(OpCodes.Dup, (object)null);
					yield return instruction;
					yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					yield return CodeInstruction.Call(typeof(LunarRework), "ChangePickupDroplet", (Type[])null, (Type[])null);
				}
				else
				{
					yield return instruction;
				}
			}
		}

		private static void ChangePickupDroplet(ref CreatePickupInfo info, ChestBehavior chest)
		{
			//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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_004b: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			PickupDropTable dropTable = chest.dropTable;
			if (Object.op_Implicit((Object)(object)dropTable) && ((Object)chest).name.StartsWith("LunarChest") && dropTable.GetPickupCount() > 1)
			{
				PickupIndex dropPickup = chest.dropPickup;
				chest.dropPickup = PickupCatalog.FindPickupIndex((ItemTier)3);
				PickupIndex val;
				do
				{
					val = dropTable.GenerateDrop(chest.rng);
				}
				while (dropPickup == val);
				info.prefabOverride = pickup.WaitForCompletion();
				info.pickerOptions = PickupPickerController.GenerateOptionsFromArray((PickupIndex[])(object)new PickupIndex[2] { dropPickup, val });
			}
		}

		[HarmonyPatch(typeof(RepeatHealComponent), "FixedUpdate")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> RepeatHeal(IEnumerable<CodeInstruction> IL)
		{
			MethodInfo method = typeof(HealthComponent).GetMethod("Heal");
			foreach (CodeInstruction item in IL)
			{
				if (CodeInstructionExtensions.Calls(item, method))
				{
					yield return new CodeInstruction(OpCodes.Pop, (object)null);
					yield return Transpilers.EmitDelegate<Action<HealthComponent, float, ProcChainMask>>((Action<HealthComponent, float, ProcChainMask>)delegate(HealthComponent health, float amount, ProcChainMask flag)
					{
						//IL_000b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0011: Invalid comparison between Unknown and I4
						//IL_002b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0018: Unknown result type (might be due to invalid IL or missing references)
						//IL_001e: Invalid comparison between Unknown and I4
						if ((int)health.body.teamComponent.teamIndex == 1 && (int)Run.instance.selectedDifficulty >= 7)
						{
							amount /= 0.5f;
						}
						health.Heal(amount, flag, true);
					});
					yield return new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
				}
				else
				{
					yield return item;
				}
			}
		}

		[HarmonyPatch(typeof(EclipseRun), "OverrideRuleChoices")]
		[HarmonyPostfix]
		private static void OverrideRuleChoices(EclipseRun __instance, RuleChoiceMask mustInclude, RuleChoiceMask mustExclude)
		{
			((Run)__instance).ForceChoice(mustInclude, mustExclude, "Items." + ((Object)Items.ShieldOnly).name + ".Off");
		}
	}
}