Decompiled source of KannasQualityofLife v0.2.2

KannaQoL.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Duplicator;
using EntityStates.Scrapper;
using IL.EntityStates.Duplicator;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.EntityStates.Duplicator;
using On.RoR2;
using R2API.Utils;
using RoR2;
using UnityEngine;
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("KannaQoL")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KannaQoL")]
[assembly: AssemblyTitle("KannaQoL")]
[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 SylmarDev.KannasQoL
{
	public class KannasConfig
	{
		public static ConfigEntry<bool> enableFastScrapper;

		public static ConfigEntry<bool> enableBazaarScrapper;

		public static ConfigEntry<bool> enableSeerPing;

		public static ConfigEntry<bool> enableInstaTeleporter;

		public static ConfigEntry<bool> enableCleansingPool;

		public static ConfigEntry<bool> enableSingleFrog;

		public static ConfigEntry<int> frogStatueCost;

		public void Init(string configPath)
		{
			//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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			ConfigFile val = new ConfigFile(Path.Combine(configPath, "SylmarDev.KannasQualityofLife.cfg"), true);
			enableFastScrapper = val.Bind<bool>("Tweaks", "Enable Fast Scrapper", true, "Set to true to enable fast scrapper.");
			enableBazaarScrapper = val.Bind<bool>("Tweaks", "Enable Scrapper in Bazaar", true, "Set to true to put scrapper in the Bazaar in Time.");
			enableSeerPing = val.Bind<bool>("Tweaks", "Enable Seer Ping", true, "Set to true to ping Lunar Seers for destination.");
			enableInstaTeleporter = val.Bind<bool>("Tweaks", "Enable Instant Teleporter", true, "Set to true to instantly finish charging teleporter after boss is killed, with time adjusted.");
			enableCleansingPool = val.Bind<bool>("Tweaks", "Enable Cleansing Pool", true, "Set to true for guaranteed Cleansing Pool on Alphesian Sanctuary.");
			enableSingleFrog = val.Bind<bool>("Tweaks", "Enable Single Frog Pet", true, "Set to true to only pet the Glass Frog once for Deep Void Portal.");
			frogStatueCost = val.Bind<int>("Tweaks", "Frog Statue Cost", 10, "Required Lunar Coins per Glass Frog Pet.");
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("SylmarDev.KannasQualityofLife", "KannasQualityofLife", "0.2.2")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class KannasQoL : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Instruction, bool> <>9__8_1;

			public static Func<Instruction, bool> <>9__8_2;

			public static Func<Instruction, bool> <>9__8_3;

			public static Func<Instruction, bool> <>9__8_4;

			public static Func<Instruction, bool> <>9__8_5;

			public static Func<Instruction, bool> <>9__8_6;

			public static Func<Instruction, bool> <>9__8_7;

			public static Func<Instruction, bool> <>9__8_8;

			public static Func<Instruction, bool> <>9__8_9;

			public static Manipulator <>9__8_0;

			internal void <Awake>b__8_0(ILContext il)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected O, but got Unknown
				//IL_0162: Unknown result type (might be due to invalid IL or missing references)
				//IL_0188: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val = new ILCursor(il);
				if (val.TryGotoNext(new Func<Instruction, bool>[9]
				{
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<EntityState>(x, "get_fixedAge"),
					(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("initialDelayDuration")),
					(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Blt_Un_S),
					(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Ldarg_0),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Duplicating>(x, "BeginCooking"),
					(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Ldarg_0),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<EntityState>(x, "get_fixedAge"),
					(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("initialDelayDuration")),
					(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("timeBetweenStartAndDropDroplet"))
				}))
				{
					int index = val.Index;
					val.Index = index + 1;
					val.Remove();
					val.Emit<KannasQoL>(OpCodes.Ldsfld, "zeroInitialDelayDuration");
					val.Index += 5;
					val.Remove();
					val.Emit<KannasQoL>(OpCodes.Ldsfld, "zeroInitialDelayDuration");
					val.Remove();
					val.Emit<KannasQoL>(OpCodes.Ldsfld, "zeroTimeBetweenStartAndDropDroplet");
				}
				else
				{
					Log.LogError("Printer couldn't shortcut");
				}
			}

			internal bool <Awake>b__8_1(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<EntityState>(x, "get_fixedAge");
			}

			internal bool <Awake>b__8_2(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("initialDelayDuration"));
			}

			internal bool <Awake>b__8_3(Instruction x)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return ILPatternMatchingExt.Match(x, OpCodes.Blt_Un_S);
			}

			internal bool <Awake>b__8_4(Instruction x)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return ILPatternMatchingExt.Match(x, OpCodes.Ldarg_0);
			}

			internal bool <Awake>b__8_5(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<Duplicating>(x, "BeginCooking");
			}

			internal bool <Awake>b__8_6(Instruction x)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return ILPatternMatchingExt.Match(x, OpCodes.Ldarg_0);
			}

			internal bool <Awake>b__8_7(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<EntityState>(x, "get_fixedAge");
			}

			internal bool <Awake>b__8_8(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("initialDelayDuration"));
			}

			internal bool <Awake>b__8_9(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("timeBetweenStartAndDropDroplet"));
			}
		}

		public const string PluginAuthor = "SylmarDev";

		public const string PluginName = "KannasQualityofLife";

		public const string PluginGUID = "SylmarDev.KannasQualityofLife";

		public const string PluginVersion = "0.2.2";

		public static AssetBundle assets;

		public static float zeroInitialDelayDuration;

		public static float zeroTimeBetweenStartAndDropDroplet;

		public List<ScrapperLocation> slocations = new List<ScrapperLocation>
		{
			new ScrapperLocation
			{
				Position = new Vector3(-82.1f, -23.7f, -5.2f),
				Rotation = new Vector3(0f, 72.6f, 0f)
			},
			new ScrapperLocation
			{
				Position = new Vector3(-95.1f, -25.2f, -45.2f),
				Rotation = new Vector3(0f, 72.6f, 0f)
			},
			new ScrapperLocation
			{
				Position = new Vector3(-134.1f, -25.4f, -20.2f),
				Rotation = new Vector3(0f, 72.6f, 0f)
			},
			new ScrapperLocation
			{
				Position = new Vector3(-122.1f, -23.7f, -5.2f),
				Rotation = new Vector3(0f, 72.6f, 0f)
			}
		};

		public void Awake()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			new KannasConfig().Init(Paths.ConfigPath);
			Log.LogInfo("SylmarDev.KannasQualityofLife // ver 0.2.2");
			Log.LogInfo("Loading Resources. . .");
			Log.LogInfo("Assigning hooks. . .");
			if (KannasConfig.enableFastScrapper.Value)
			{
				Stage.onStageStartGlobal += Stage_Start;
				Duplicating.BeginCooking += new hook_BeginCooking(Duplicating_BeginCooking);
				object obj = <>c.<>9__8_0;
				if (obj == null)
				{
					Manipulator val = delegate(ILContext il)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						//IL_0007: Expected O, but got Unknown
						//IL_0162: Unknown result type (might be due to invalid IL or missing references)
						//IL_0188: Unknown result type (might be due to invalid IL or missing references)
						//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
						ILCursor val2 = new ILCursor(il);
						if (val2.TryGotoNext(new Func<Instruction, bool>[9]
						{
							(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<EntityState>(x, "get_fixedAge"),
							(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("initialDelayDuration")),
							(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Blt_Un_S),
							(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Ldarg_0),
							(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Duplicating>(x, "BeginCooking"),
							(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Ldarg_0),
							(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<EntityState>(x, "get_fixedAge"),
							(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("initialDelayDuration")),
							(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Duplicating).GetField("timeBetweenStartAndDropDroplet"))
						}))
						{
							int index = val2.Index;
							val2.Index = index + 1;
							val2.Remove();
							val2.Emit<KannasQoL>(OpCodes.Ldsfld, "zeroInitialDelayDuration");
							val2.Index += 5;
							val2.Remove();
							val2.Emit<KannasQoL>(OpCodes.Ldsfld, "zeroInitialDelayDuration");
							val2.Remove();
							val2.Emit<KannasQoL>(OpCodes.Ldsfld, "zeroTimeBetweenStartAndDropDroplet");
						}
						else
						{
							Log.LogError("Printer couldn't shortcut");
						}
					};
					<>c.<>9__8_0 = val;
					obj = (object)val;
				}
				Duplicating.FixedUpdate += (Manipulator)obj;
				Duplicating.DropDroplet += new hook_DropDroplet(Duplicating_DropDroplet);
			}
			if (KannasConfig.enableBazaarScrapper.Value)
			{
				BazaarController.Awake += new hook_Awake(BazaarController_Awake);
			}
			if (KannasConfig.enableSeerPing.Value)
			{
				Util.GetBestBodyName += new hook_GetBestBodyName(Util_GetBestBodyName);
			}
			if (KannasConfig.enableInstaTeleporter.Value)
			{
				TeleporterInteraction.UpdateMonstersClear += new hook_UpdateMonstersClear(TeleporterInteraction_UpdateMonstersClear);
			}
			if (KannasConfig.enableCleansingPool.Value)
			{
				Stage.onStageStartGlobal += Stage_Start_CleansingPool;
			}
			if (KannasConfig.enableSingleFrog.Value)
			{
				FrogController.Pet += new hook_Pet(FrogController_Pet);
			}
			if (KannasConfig.frogStatueCost.Value != 1)
			{
				PurchaseInteraction.Awake += new hook_Awake(PurchaseInteraction_Awake);
			}
			Log.LogInfo("Awake done.");
		}

		private void Stage_onStageStartGlobal(Stage obj)
		{
			throw new NotImplementedException();
		}

		private void Stage_Start(Stage self)
		{
			((BaseUnityPlugin)this).Logger.Log((LogLevel)32, (object)"Called Stage_Start()");
			WaitToBeginScrapping.duration = 0f;
			Scrapping.duration = 0f;
			ScrappingToIdle.duration = 0f;
			Duplicating.initialDelayDuration = 0.01f;
			Duplicating.timeBetweenStartAndDropDroplet = 0.01f;
		}

		private void Duplicating_BeginCooking(orig_BeginCooking orig, Duplicating self)
		{
			if (!NetworkServer.active)
			{
				orig.Invoke(self);
			}
		}

		private void Duplicating_DropDroplet(orig_DropDroplet orig, Duplicating self)
		{
			orig.Invoke(self);
			if (NetworkServer.active)
			{
				((Component)((EntityState)self).outer).GetComponent<PurchaseInteraction>().Networkavailable = true;
			}
		}

		private void BazaarController_Awake(orig_Awake orig, BazaarController self)
		{
			orig.Invoke(self);
			bool active = NetworkServer.active;
			int num = 0;
			if (!active)
			{
				return;
			}
			foreach (ScrapperLocation slocation in slocations)
			{
				if (num >= PlayerCharacterMasterController.instances.Count)
				{
					break;
				}
				SpawnScrapper(slocation);
				num++;
			}
		}

		private void SpawnScrapper(ScrapperLocation location)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0008: 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_001f: 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_003a: Expected O, but got Unknown
			//IL_0035: 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)
			DirectorPlacementRule val = new DirectorPlacementRule();
			val.placementMode = (PlacementMode)0;
			SpawnCard val2 = Resources.Load<SpawnCard>("SpawnCards/InteractableSpawnCard/iscScrapper");
			GameObject spawnedInstance = val2.DoSpawn(location.Position, Quaternion.identity, new DirectorSpawnRequest(val2, val, Run.instance.runRNG)).spawnedInstance;
			spawnedInstance.transform.eulerAngles = location.Rotation;
			NetworkServer.Spawn(spawnedInstance);
		}

		private string Util_GetBestBodyName(orig_GetBestBodyName orig, GameObject bodyObject)
		{
			if (((Object)bodyObject).name.Contains("SeerStation"))
			{
				string text = Language.GetString(SceneCatalog.GetSceneDef((SceneIndex)bodyObject.GetComponent<SeerStationController>().NetworktargetSceneDefIndex).portalSelectionMessageString).Substring(31).Trim();
				Log.LogMessage(text);
				return "A dream of " + text.Split('<')[0] + " ";
			}
			return orig.Invoke(bodyObject);
		}

		private void TeleporterInteraction_UpdateMonstersClear(orig_UpdateMonstersClear orig, TeleporterInteraction self)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (self.monstersCleared && Object.op_Implicit((Object)(object)self.holdoutZoneController) && (int)self.activationState == 2 && self.chargeFraction > 0.02f)
			{
				int displayChargePercent = TeleporterInteraction.instance.holdoutZoneController.displayChargePercent;
				float runStopwatch = Run.instance.GetRunStopwatch();
				int num = Math.Min(Util.GetItemCountForTeam(self.holdoutZoneController.chargingTeam, Items.FocusConvergence.itemIndex, true, true), 3);
				float num2 = (100f - (float)displayChargePercent) / 100f * (TeleporterInteraction.instance.holdoutZoneController.baseChargeDuration / (1f + 0.3f * (float)num));
				num2 = (float)Math.Round(num2, 2);
				float runStopwatch2 = runStopwatch + (float)Math.Round(num2, 2);
				Run.instance.SetRunStopwatch(runStopwatch2);
				TeleporterInteraction.instance.holdoutZoneController.FullyChargeHoldoutZone();
			}
		}

		private void Stage_Start_CleansingPool(Stage self)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0035: 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_005d: 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_0078: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.Log((LogLevel)32, (object)"Called Stage_Start_CleansingPool()");
			if (SceneInfo.instance.sceneDef.baseSceneName == "ancientloft")
			{
				DirectorPlacementRule val = new DirectorPlacementRule();
				val.placementMode = (PlacementMode)0;
				SpawnCard val2 = Resources.Load<SpawnCard>("SpawnCards/InteractableSpawnCard/iscShrineCleanse");
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor(-68f, 40.5f, 6.3f);
				GameObject spawnedInstance = val2.DoSpawn(val3, Quaternion.identity, new DirectorSpawnRequest(val2, val, Run.instance.runRNG)).spawnedInstance;
				spawnedInstance.transform.eulerAngles = new Vector3(0f, 0f, 0f);
				NetworkServer.Spawn(spawnedInstance);
			}
		}

		private void FrogController_Pet(orig_Pet orig, FrogController self, Interactor interactor)
		{
			self.maxPets = 1;
			Log.LogInfo(((Object)self.purchaseInteraction).name);
			orig.Invoke(self, interactor);
		}

		private void PurchaseInteraction_Awake(orig_Awake orig, PurchaseInteraction self)
		{
			orig.Invoke(self);
			AdjustFrogPrice(self);
		}

		private static void AdjustFrogPrice(PurchaseInteraction self)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)self).name.StartsWith("FrogInteractable"))
			{
				self.cost = KannasConfig.frogStatueCost.Value;
				if (KannasConfig.frogStatueCost.Value == 0)
				{
					self.costType = (CostTypeIndex)0;
				}
			}
		}
	}
	public class ScrapperLocation
	{
		public Vector3 Position;

		public Vector3 Rotation;
	}
	internal static class Log
	{
		internal static ManualLogSource _logSource;

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

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

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

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

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

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

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