Decompiled source of Act1BossExhibitReplacer v1.1.0

Act1BossExhibitReplacer.dll

Decompiled a month 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 AddWatermark;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LBoL.Base;
using LBoL.Base.Extensions;
using LBoL.Core;
using LBoL.Core.Stations;
using LBoLEntitySideloader;
using LBoLEntitySideloader.Resource;
using UnityEngine;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("LBoL.Base")]
[assembly: IgnoresAccessChecksTo("LBoL.ConfigData")]
[assembly: IgnoresAccessChecksTo("LBoL.Core")]
[assembly: IgnoresAccessChecksTo("LBoL.EntityLib")]
[assembly: IgnoresAccessChecksTo("LBoL.Presentation")]
[assembly: IgnoresAccessChecksTo("Untitled.ConfigDataBuilder.Base")]
[assembly: AssemblyCompany("Act1BossExhibitReplacer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+15a541c22b2a16a091ee99cf71f34b4599b0b782")]
[assembly: AssemblyProduct("Act1BossExhibitReplacer")]
[assembly: AssemblyTitle("Act1BossExhibitReplacer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Act1BossExhibitReplacer
{
	[BepInPlugin("cramps-act1exhibitreplacer", "Act1BossExhibitReplacer", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("LBoL.exe")]
	public class BepinexPlugin : BaseUnityPlugin
	{
		private static readonly Harmony harmony = PInfo.harmony;

		internal static ManualLogSource log;

		internal static TemplateSequenceTable sequenceTable = new TemplateSequenceTable(0);

		internal static IResourceSource embeddedSource = (IResourceSource)new EmbeddedSource(Assembly.GetExecutingAssembly());

		internal static DirectorySource directorySource = new DirectorySource("cramps-act1exhibitreplacer", "");

		public static ConfigEntry<bool> replaceLeftExhibit;

		public static ConfigEntry<bool> replaceBottomExhibit;

		public static ConfigEntry<bool> replaceBossExhibit;

		public static ConfigEntry<bool> doReplaceAct1;

		public static ConfigEntry<bool> doReplaceAct2;

		public static ConfigEntry<bool> doReplaceAct3;

		public static ConfigEntry<bool> allowDifferentColorReplacement;

		public static ConfigEntry<bool> allowSameCharacterExhibit;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			replaceLeftExhibit = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceExhibits", "ReplaceLeftExhibit", false, "Replace the left exhibit for act1 boss reward, with a random modded exhibit");
			replaceBottomExhibit = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceExhibits", "ReplaceBottomExhibit", false, "Replace the bottom exhibit for act1 boss reward, with a random modded exhibit");
			replaceBossExhibit = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceExhibits", "ReplaceBossExhibit", true, "Replace the boss exhibit for act1 boss reward, with a random modded exhibit");
			doReplaceAct1 = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceExhibits", "DoReplaceAct1", true, "Replace exhibits for act1");
			doReplaceAct2 = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceExhibits", "DoReplaceAct2", false, "Replace exhibits for act2");
			doReplaceAct3 = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceExhibits", "DoReplaceAct3", false, "Replace exhibits for act3");
			allowDifferentColorReplacement = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceExhibits", "AllowDifferentColorReplacement", true, "Allows replacing individual exhibits with different colored exhibits");
			allowSameCharacterExhibit = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceExhibits", "AllowSameCharacterExhibit", true, "Allows obtaining exhibits from the same character");
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			EntityManager.RegisterSelf();
			harmony.PatchAll();
			if (Chainloader.PluginInfos.ContainsKey("neo.lbol.tools.watermark"))
			{
				WatermarkWrapper.ActivateWatermark();
			}
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class PInfo
	{
		public const string GUID = "cramps-act1exhibitreplacer";

		public const string Name = "Act1BossExhibitReplacer";

		public const string version = "1.1.0";

		public static readonly Harmony harmony = new Harmony("cramps-act1exhibitreplacer");
	}
	[HarmonyPatch]
	internal class Act1ExhibitReplacer
	{
		private static readonly string[] OWNER_TO_IGNORE = new string[5] { "Reimu", "Marisa", "Sakuya", "Cirno", "Koishi" };

		private const int BOSS_EXHIBIT_INDEX = 1;

		private const int LEFT_EXHIBIT_INDEX = 0;

		private const int BOTTOM_EXHIBIT_INDEX = 2;

		[HarmonyPatch(typeof(BossStation), "GenerateBossRewards")]
		private static void Postfix(BossStation __instance)
		{
			if (!BepinexPlugin.doReplaceAct1.Value && ((Station)__instance).Stage.Level == 1)
			{
				BepinexPlugin.log.LogInfo((object)"Not allow replacing in act1");
				return;
			}
			if (!BepinexPlugin.doReplaceAct2.Value && ((Station)__instance).Stage.Level == 2)
			{
				BepinexPlugin.log.LogInfo((object)"Not allow replacing in act2");
				return;
			}
			if (!BepinexPlugin.doReplaceAct3.Value && ((Station)__instance).Stage.Level == 3)
			{
				BepinexPlugin.log.LogInfo((object)"Not allow replacing in act3");
				return;
			}
			BepinexPlugin.log.LogInfo((object)("Starting act " + ((Station)__instance).Stage.Level + " replacements"));
			ConfigLogging();
			List<Exhibit> list = new List<Exhibit>();
			foreach (Type item in ((Station)__instance).GameRun.ShiningExhibitPool)
			{
				Exhibit val = Library.CreateExhibit(item);
				if (!OWNER_TO_IGNORE.Contains(val.OwnerId) && val.OwnerId != null)
				{
					list.Add(val);
				}
			}
			Exhibit[] bossRewards = __instance.BossRewards;
			int num = 0;
			if (BepinexPlugin.replaceBossExhibit.Value && CollectionsExtensions.NotEmpty<Exhibit>((IReadOnlyCollection<Exhibit>)list) && DoReplacement(__instance, 1, list, bossRewards))
			{
				num++;
			}
			if (BepinexPlugin.replaceLeftExhibit.Value && CollectionsExtensions.NotEmpty<Exhibit>((IReadOnlyCollection<Exhibit>)list) && DoReplacement(__instance, 0, list, bossRewards))
			{
				num++;
			}
			if (BepinexPlugin.replaceBottomExhibit.Value && CollectionsExtensions.NotEmpty<Exhibit>((IReadOnlyCollection<Exhibit>)list) && DoReplacement(__instance, 2, list, bossRewards))
			{
				num++;
			}
			__instance.BossRewards = bossRewards;
			if (num <= 0)
			{
				BepinexPlugin.log.LogInfo((object)"Replaced nothing");
			}
		}

		private static void ConfigLogging()
		{
			if (BepinexPlugin.allowDifferentColorReplacement.Value)
			{
				BepinexPlugin.log.LogInfo((object)"Allowing different color replacements");
			}
			else
			{
				BepinexPlugin.log.LogInfo((object)"Not allowing different color replacements");
			}
			if (BepinexPlugin.allowSameCharacterExhibit.Value)
			{
				BepinexPlugin.log.LogInfo((object)"Allowing exhibits from same character");
			}
			else
			{
				BepinexPlugin.log.LogInfo((object)"Not allowing exhibits from same character");
			}
		}

		private static bool DoReplacement(BossStation __instance, int index, List<Exhibit> moddedExhibits, Exhibit[] newRewards)
		{
			List<Exhibit> list = moddedExhibits;
			if (!BepinexPlugin.allowDifferentColorReplacement.Value)
			{
				list = list.Where(delegate(Exhibit e)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_0009: Unknown result type (might be due to invalid IL or missing references)
					//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_0023: Unknown result type (might be due to invalid IL or missing references)
					BaseManaGroup baseMana = e.BaseMana;
					ManaGroup value = ((BaseManaGroup)(ref baseMana)).Value;
					baseMana = newRewards[index].BaseMana;
					return value == ((BaseManaGroup)(ref baseMana)).Value;
				}).ToList();
			}
			if (!BepinexPlugin.allowSameCharacterExhibit.Value)
			{
				IEnumerable<string> uniqueOwners = ((Station)__instance).GameRun.Player.Exhibits.Select((Exhibit e) => e.OwnerId).Distinct();
				list = list.Where((Exhibit e) => !uniqueOwners.Contains(e.OwnerId)).ToList();
			}
			if (!list.Any())
			{
				return false;
			}
			Exhibit val = newRewards[index];
			newRewards[index] = CollectionsExtensions.Sample<Exhibit>((IEnumerable<Exhibit>)list, ((Station)__instance).GameRun.ExhibitRng);
			moddedExhibits.Remove(newRewards[index]);
			BepinexPlugin.log.LogInfo((object)("Replacing " + ((GameEntity)val).Name + " with " + ((GameEntity)newRewards[index]).Name));
			return true;
		}
	}
	internal class WatermarkWrapper
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void ActivateWatermark()
		{
			API.ActivateWatermark();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}