Decompiled source of LunarRework v0.1.0

LunarRework.dll

Decompiled 4 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 HG;
using HarmonyLib;
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 = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
namespace Prototype;

[BepInPlugin("prototype.lunar.rework", "LunarRework", "0.1.0")]
public class LunarRework : BaseUnityPlugin
{
	public const string version = "0.1.0";

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

	private static AsyncOperationHandle<GameObject> shop;

	private static AsyncOperationHandle<GameObject> pickup;

	private static AsyncOperationHandle<GameObject> model;

	internal 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;
		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);
					}
				}
			}
		}
	}

	[HarmonyPatch(typeof(Stage), "BeginServer")]
	[HarmonyPrefix]
	private static void BeginServer(Stage __instance)
	{
		//IL_00c4: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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")
				{
					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;
		ArrayUtils.ArrayRemoveAtAndResize<SeerStationController>(ref __instance.seerStations, num, 1);
		((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");
		foreach (CodeInstruction item in IL)
		{
			if (CodeInstructionExtensions.Calls(item, method))
			{
				yield return Transpilers.EmitDelegate<Action<List<SceneDef>, SceneDef>>((Action<List<SceneDef>, SceneDef>)delegate(List<SceneDef> choices, SceneDef stage)
				{
					choices.Add(stage);
					if (choices.Count > 1)
					{
						choices.Remove(Run.instance?.nextStageScene);
					}
				});
			}
			else
			{
				yield return item;
			}
		}
	}

	[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), "ItemDrop")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> ItemDrop(IEnumerable<CodeInstruction> IL)
	{
		MethodInfo method = typeof(PickupDropletController).GetMethod("CreatePickupDroplet", new Type[3]
		{
			typeof(PickupIndex),
			typeof(Vector3),
			typeof(Vector3)
		});
		foreach (CodeInstruction item in IL)
		{
			if (CodeInstructionExtensions.Calls(item, method))
			{
				yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				yield return CodeInstruction.Call(typeof(LunarRework), "CreatePickupDroplet", (Type[])null, (Type[])null);
			}
			else
			{
				yield return item;
			}
		}
	}

	private static void CreatePickupDroplet(PickupIndex index, Vector3 position, Vector3 velocity, ChestBehavior chest)
	{
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_004e: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: 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 val;
			do
			{
				val = dropTable.GenerateDrop(chest.rng);
			}
			while (index == val);
			CreatePickupInfo val2 = default(CreatePickupInfo);
			((CreatePickupInfo)(ref val2)).pickupIndex = PickupCatalog.FindPickupIndex((ItemTier)3);
			val2.prefabOverride = pickup.WaitForCompletion();
			val2.pickerOptions = PickupPickerController.GenerateOptionsFromArray((PickupIndex[])(object)new PickupIndex[2] { index, val });
			PickupDropletController.CreatePickupDroplet(val2, position, velocity);
		}
		else
		{
			PickupDropletController.CreatePickupDroplet(index, position, velocity);
		}
	}

	[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");
	}
}