Decompiled source of CheapEva v1.0.0

CheapEva.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
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 CheapEva.Settings;
using HarmonyLib;
using HutongGames.PlayMaker.Actions;
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: AssemblyCompany("CheapEva")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CheapEva")]
[assembly: AssemblyTitle("CheapEva")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CheapEva
{
	[BepInPlugin("com.supersonicsalt.cheapEva", "CheapEva", "1.0.0")]
	public class CheapEvaMod : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(CountCrestUnlockPoints), "OnEnter")]
		public class CountCrestUnlockPoints_OnEnter_Patch
		{
			[HarmonyPostfix]
			public static void Postfix(CountCrestUnlockPoints __instance)
			{
				if (modEnabled && __instance?.StoreCurrentPoints != null)
				{
					int value = __instance.StoreCurrentPoints.Value;
					int num = RemapEvaProgress(value);
					if (num != value)
					{
						__instance.StoreCurrentPoints.Value = num;
						ModLogger.LogInfo((object)$"Eva progress remapped: {value} -> {num} (CrestCountMode={useCrestCountMilestones})");
					}
				}
			}
		}

		internal const string modGUID = "com.supersonicsalt.cheapEva";

		private const string modName = "CheapEva";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("com.supersonicsalt.cheapEva");

		internal static ManualLogSource ModLogger;

		public static bool modEnabled;

		public static bool useCrestCountMilestones;

		public static int thresholdVesticrestYellow = 12;

		public static int thresholdVesticrestBlue = 20;

		public static int thresholdHunterCrestUpgrade2 = 27;

		public static int thresholdEvaBindSylphsong = 32;

		public static int crestholdVesticrestYellow = 3;

		public static int crestholdVesticrestBlue = 4;

		public static int crestholdHunterCrestUpgrade2 = 5;

		public static int crestholdEvaBindSylphsong = 6;

		public static CheapEvaMod Instance;

		public void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			ModLogger = Logger.CreateLogSource("CheapEva");
			try
			{
				harmony.PatchAll();
			}
			catch (Exception arg)
			{
				ModLogger.LogInfo((object)string.Format("Plugin {0} threw {1}", "CheapEva", arg));
				throw;
			}
			ModLogger.LogInfo((object)"Plugin CheapEva is loaded!");
		}

		public void Start()
		{
			ConfigSettings.Initialize(((BaseUnityPlugin)this).Config);
		}

		private static int RemapToVanillaMilestoneBands(int value, int m1, int m2, int m3, int m4)
		{
			int num = Math.Max(0, m1);
			int num2 = Math.Max(num, m2);
			int num3 = Math.Max(num2, m3);
			int num4 = Math.Max(num3, m4);
			if (value < num)
			{
				return Math.Min(value, 11);
			}
			if (value < num2)
			{
				return Math.Max(12, Math.Min(value, 19));
			}
			if (value < num3)
			{
				return Math.Max(20, Math.Min(value, 26));
			}
			if (value < num4)
			{
				return Math.Max(27, Math.Min(value, 31));
			}
			return Math.Max(value, 32);
		}

		private static int RemapEvaProgress(int slotUnlockPoints)
		{
			if (useCrestCountMilestones)
			{
				int unlockedCrestsCount = ToolItemManager.GetUnlockedCrestsCount();
				return RemapToVanillaMilestoneBands(unlockedCrestsCount, crestholdVesticrestYellow, crestholdVesticrestBlue, crestholdHunterCrestUpgrade2, crestholdEvaBindSylphsong);
			}
			return RemapToVanillaMilestoneBands(slotUnlockPoints, thresholdVesticrestYellow, thresholdVesticrestBlue, thresholdHunterCrestUpgrade2, thresholdEvaBindSylphsong);
		}
	}
}
namespace CheapEva.Settings
{
	internal class ConfigSettings
	{
		public static ConfigEntry<bool> modEnabled;

		public static ConfigEntry<bool> useCrestCountMilestones;

		public static ConfigEntry<int> thresholdVesticrestYellow;

		public static ConfigEntry<int> thresholdVesticrestBlue;

		public static ConfigEntry<int> thresholdHunterCrestUpgrade2;

		public static ConfigEntry<int> thresholdEvaBindSylphsong;

		public static ConfigEntry<int> crestholdVesticrestYellow;

		public static ConfigEntry<int> crestholdVesticrestBlue;

		public static ConfigEntry<int> crestholdHunterCrestUpgrade2;

		public static ConfigEntry<int> crestholdEvaBindSylphsong;

		public static void Initialize(ConfigFile config)
		{
			modEnabled = config.Bind<bool>("Cheap eva", "Enabled", true, "Enables and disables the mod");
			thresholdVesticrestYellow = config.Bind<int>("slot", "Vesticrest Yellow Slot", 12, "Unlock-point threshold for Eva reward #1 (Vesticrest yellow slot).");
			thresholdVesticrestBlue = config.Bind<int>("slot", "Vesticrest Blue Slot", 20, "Unlock-point threshold for Eva reward #2 (Vesticrest blue slot).");
			thresholdHunterCrestUpgrade2 = config.Bind<int>("slot", "Hunter Crest Upgrade 2", 27, "Unlock-point threshold for Eva reward #3 (second Hunter Crest upgrade).");
			thresholdEvaBindSylphsong = config.Bind<int>("slot", "Eva Bind Sylphsong", 32, "Unlock-point threshold for Eva reward #4 (bind Eva and gain Sylphsong).");
			useCrestCountMilestones = config.Bind<bool>("crest", "Use Crest Count Milestones", false, "If true, Eva rewards are based on owned crest count (3/4/5/6) instead of slot unlock points.");
			crestholdVesticrestYellow = config.Bind<int>("crest", "Vesticrest Yellow Slot", 3, "Unlock-crest threshold for Eva reward #1 (Vesticrest yellow slot).");
			crestholdVesticrestBlue = config.Bind<int>("crest", "Vesticrest Blue Slot", 4, "Unlock-crest threshold for Eva reward #2 (Vesticrest blue slot).");
			crestholdHunterCrestUpgrade2 = config.Bind<int>("crest", "Hunter Crest Upgrade 2", 5, "Unlock-crest threshold for Eva reward #3 (second Hunter Crest upgrade).");
			crestholdEvaBindSylphsong = config.Bind<int>("crest", "Eva Bind Sylphsong", 6, "Unlock-crest threshold for Eva reward #4 (bind Eva and gain Sylphsong).");
			modEnabled.SettingChanged += OnSettingChanged;
			useCrestCountMilestones.SettingChanged += OnSettingChanged;
			thresholdVesticrestYellow.SettingChanged += OnSettingChanged;
			thresholdVesticrestBlue.SettingChanged += OnSettingChanged;
			thresholdHunterCrestUpgrade2.SettingChanged += OnSettingChanged;
			thresholdEvaBindSylphsong.SettingChanged += OnSettingChanged;
			crestholdVesticrestYellow.SettingChanged += OnSettingChanged;
			crestholdVesticrestBlue.SettingChanged += OnSettingChanged;
			crestholdHunterCrestUpgrade2.SettingChanged += OnSettingChanged;
			crestholdEvaBindSylphsong.SettingChanged += OnSettingChanged;
			OnSettingChanged(null, null);
		}

		private static void OnSettingChanged(object sender, EventArgs e)
		{
			CheapEvaMod.modEnabled = modEnabled.Value;
			CheapEvaMod.useCrestCountMilestones = useCrestCountMilestones.Value;
			CheapEvaMod.thresholdVesticrestYellow = thresholdVesticrestYellow.Value;
			CheapEvaMod.thresholdVesticrestBlue = thresholdVesticrestBlue.Value;
			CheapEvaMod.thresholdHunterCrestUpgrade2 = thresholdHunterCrestUpgrade2.Value;
			CheapEvaMod.thresholdEvaBindSylphsong = thresholdEvaBindSylphsong.Value;
			CheapEvaMod.crestholdVesticrestYellow = thresholdVesticrestYellow.Value;
			CheapEvaMod.crestholdVesticrestBlue = thresholdVesticrestBlue.Value;
			CheapEvaMod.crestholdHunterCrestUpgrade2 = thresholdHunterCrestUpgrade2.Value;
			CheapEvaMod.crestholdEvaBindSylphsong = thresholdEvaBindSylphsong.Value;
		}
	}
}