Decompiled source of PushingTheLimits v1.0.0

plugins/PushingTheLimits.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Dungeonator;
using Gunfiguration;
using HarmonyLib;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Mod")]
[assembly: AssemblyCopyright("Copyright ©  2020")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d6d7a494-722e-4763-959b-c2d6b6a42b01")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PushingTheLimits;

public static class GunfigConfig
{
	public static Gunfig _Gunfig = null;

	internal const string RAINBOWRUN_LABEL = "Rainbow Run Start";

	internal const string RAINBOWCOOP_LABEL = "Rainbow Run Co-Op Chest";

	internal const string SYNERGYCHEST_LABEL = "Synergy Chest Success Rate";

	internal const string SYNERGYFUSE_LABEL = "Synergy Chests have Normal Chest Fuse Rate";

	internal const string SYNERGYFACTOR_LABEL = "Synergy Factor";

	internal const string MAGNIFICENCE_LABEL = "Magnificence";

	internal const string CAP_LABEL = "Boss DPS Cap";

	private static readonly List<string> RAINBOWRUN_OPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Vanilla"),
		GunfigHelpers.Yellow("Rainbow Run Lite"),
		GunfigHelpers.Green("Rainbow Run Lite Lite"),
		GunfigHelpers.Blue("Rainbow Run Lite Lite Lite"),
		GunfigHelpers.Red("Rainbow Run Plus")
	};

	private static readonly List<string> RAINBOWRUN_DESCRIPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Rainbow Chests spawn at the start of floors but no other items can be collected."),
		GunfigHelpers.Gray("Only receive the first Rainbow Run chest but you can still collect all other regular run items."),
		GunfigHelpers.Gray("Same as Rainbow Run Lite but the Rainbow Chest has fewer A items and more C/D items."),
		GunfigHelpers.Gray("Same as Rainbow Run Lite but the initial chest only has items of B quality or lower."),
		GunfigHelpers.Gray("Rainbow Run chests spawn on every floor AND you can collect regular run items!")
	};

	private static readonly List<string> SYNERGYCHEST_OPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Vanilla"),
		GunfigHelpers.Yellow("Better Synergy Chests"),
		GunfigHelpers.Cyan("Best Synergy Chests")
	};

	private static readonly List<string> SYNERGYCHEST_DESCRIPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Synergy Chests have a roughly 50% chance of completing a Synergy."),
		GunfigHelpers.Gray("Raise Synergy Chest chance of success to always be 75%"),
		GunfigHelpers.Gray("Synergy Chests will always try to complete a Synergy if possible.")
	};

	private static readonly List<string> SYNERGYFACTOR_OPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Vanilla"),
		GunfigHelpers.Yellow("Synergy Factor Amplified"),
		GunfigHelpers.Green("Synergy Factor Synchrony"),
		GunfigHelpers.Cyan("Synergy Factor Hatsune Miku")
	};

	private static readonly List<string> SYNERGYFACTOR_DESCRIPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Higher chance of completing at least one synergy with a small boost to a second."),
		GunfigHelpers.Gray("Increase the boosted chance of getting your second or third synergy."),
		GunfigHelpers.Gray("2x Synergy Factor effect in addition to second and third synergy chance boost."),
		GunfigHelpers.Gray("5x Synergy Factor effect in addition to second and third synergy chance boost.")
	};

	private static readonly List<string> MAGNIFICENCE_OPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Vanilla"),
		GunfigHelpers.Yellow("Prettygoodicence"),
		GunfigHelpers.Green("Okayicence"),
		GunfigHelpers.Red("Mehicence")
	};

	private static readonly List<string> MAGNIFICENCE_DESCRIPTIONS = new List<string>
	{
		GunfigHelpers.Gray("You have an 80% chance of rerolling an A or S quality drop if you already have one and <95% after."),
		GunfigHelpers.Gray("Magnificence reroll chance reduced to 40%/60%/80%/99.5%"),
		GunfigHelpers.Gray("Magnificence reroll chance reduced to 30%/45%/60%"),
		GunfigHelpers.Gray("Magnificence disabled")
	};

	private static readonly List<string> CAP_OPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Vanilla"),
		GunfigHelpers.Yellow("DPS Cap low"),
		GunfigHelpers.Green("DPS Cap lower than that"),
		GunfigHelpers.Blue("DPS Cap even lower than that"),
		GunfigHelpers.Red("DPS Cap just turn it off")
	};

	private static readonly List<string> CAP_DESCRIPTIONS = new List<string>
	{
		GunfigHelpers.Gray("Normal Damage Per Second cap on hurting bosses."),
		GunfigHelpers.Gray("Increase the Boss DPS cap by 25%"),
		GunfigHelpers.Gray("Increase the Boss DPS cap by 50%"),
		GunfigHelpers.Gray("Increase the Boss DPS cap by 100%"),
		GunfigHelpers.Gray("Disable Boss DPS cap")
	};

	internal static void Init()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		_Gunfig = Gunfig.Get(GunfigHelpers.WithColor("Pushing the Limits", Color.yellow));
		_Gunfig.AddScrollBox("Rainbow Run Start", RAINBOWRUN_OPTIONS, (string)null, (Action<string, string>)null, RAINBOWRUN_DESCRIPTIONS, (Update)1);
		_Gunfig.AddToggle("Rainbow Run Co-Op Chest", false, (string)null, (Action<string, string>)null, (Update)1);
		_Gunfig.AddScrollBox("Synergy Chest Success Rate", SYNERGYCHEST_OPTIONS, (string)null, (Action<string, string>)null, SYNERGYCHEST_DESCRIPTIONS, (Update)1);
		_Gunfig.AddToggle("Synergy Chests have Normal Chest Fuse Rate", false, (string)null, (Action<string, string>)null, (Update)1);
		_Gunfig.AddScrollBox("Synergy Factor", SYNERGYFACTOR_OPTIONS, (string)null, (Action<string, string>)null, SYNERGYFACTOR_DESCRIPTIONS, (Update)1);
		_Gunfig.AddScrollBox("Magnificence", MAGNIFICENCE_OPTIONS, (string)null, (Action<string, string>)null, MAGNIFICENCE_DESCRIPTIONS, (Update)1);
		_Gunfig.AddScrollBox("Boss DPS Cap", CAP_OPTIONS, (string)null, (Action<string, string>)null, CAP_DESCRIPTIONS, (Update)1);
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("bassforte.etg.pushingthelimits", "Pushing The Limits", "1.0.0")]
public class PushingTheLimitsModule : BaseUnityPlugin
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class RainbowRunPatch
	{
		public static bool newRainbowCheck;

		public static void Postfix(ref bool __result)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			GameManager instance = GameManager.Instance;
			if ((int)instance.CurrentLevelOverrideState != 5 && (int)instance.CurrentLevelOverrideState != 1 && (int)instance.CurrentLevelOverrideState != 2 && GameStatsManager.Instance.rainbowRunToggled)
			{
				newRainbowCheck = GunfigConfig._Gunfig.Value("Rainbow Run Start") != "Vanilla" && (GameManager.Instance.CurrentFloor == 1 || (GameManager.Instance.CurrentFloor >= 1 && GunfigConfig._Gunfig.Value("Rainbow Run Start") == "Rainbow Run Plus"));
				__result = GunfigConfig._Gunfig.Value("Rainbow Run Start") == "Vanilla";
			}
			else
			{
				newRainbowCheck = false;
				__result = false;
			}
		}
	}

	[HarmonyPatch(typeof(Chest), "SpewContentsOntoGround")]
	public class SpewContentsOntoGroundPatch
	{
		private static bool Prefix(Chest __instance, List<Transform> spawnTransforms)
		{
			//IL_0016: 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)
			if (__instance.IsRainbowChest && RainbowRunPatch.newRainbowCheck && Vector3Extensions.GetAbsoluteRoom(((BraveBehaviour)__instance).transform.position) == GameManager.Instance.Dungeon.data.Entrance)
			{
				List<DebrisObject> list = new List<DebrisObject>();
				for (int i = 0; i < __instance.contents.Count; i++)
				{
					List<GameObject> list2 = new List<GameObject>();
					list2.Add(((Component)__instance.contents[i]).gameObject);
					List<DebrisObject> list3 = LootEngine.SpewLoot(list2, spawnTransforms[i].position);
					list.AddRange(list3);
					for (int j = 0; j < list3.Count; j++)
					{
						if (Object.op_Implicit((Object)(object)list3[j]))
						{
							list3[j].PreventFallingInPits = true;
						}
						if (!((Object)(object)((Component)list3[j]).GetComponent<Gun>() != (Object)null) && !((Object)(object)((Component)list3[j]).GetComponent<CurrencyPickup>() != (Object)null) && (Object)(object)((BraveBehaviour)list3[j]).specRigidbody != (Object)null)
						{
							((BraveBehaviour)list3[j]).specRigidbody.CollideWithOthers = false;
							DebrisObject val = list3[j];
							val.OnTouchedGround = (Action<DebrisObject>)Delegate.Combine(val.OnTouchedGround, new Action<DebrisObject>(__instance.BecomeViableItem));
						}
					}
				}
				((MonoBehaviour)GameManager.Instance.Dungeon).StartCoroutine(__instance.HandleRainbowRunLootProcessing(list));
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Chest), "BecomeRainbowChest")]
	public class BecomeRainbowChestPatch
	{
		public static void Postfix(Chest __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (!RainbowRunPatch.newRainbowCheck || Vector3Extensions.GetAbsoluteRoom(((BraveBehaviour)__instance).transform.position) != GameManager.Instance.Dungeon.data.Entrance)
			{
				return;
			}
			__instance.lootTable.S_Chance = 0.2f;
			__instance.lootTable.A_Chance = 0.7f;
			__instance.lootTable.B_Chance = 0.4f;
			__instance.lootTable.C_Chance = 0.2f;
			__instance.lootTable.D_Chance = 0.2f;
			if (GunfigConfig._Gunfig.Value("Rainbow Run Start") == "Rainbow Run Lite Lite")
			{
				__instance.lootTable.S_Chance = 0.1f;
				__instance.lootTable.A_Chance = 0.2f;
				__instance.lootTable.C_Chance = 0.4f;
				__instance.lootTable.D_Chance = 0.4f;
			}
			if (GunfigConfig._Gunfig.Value("Rainbow Run Start") == "Rainbow Run Lite Lite Lite")
			{
				__instance.lootTable.S_Chance = 0f;
				__instance.lootTable.A_Chance = 0f;
				__instance.lootTable.C_Chance = 0.6f;
				__instance.lootTable.D_Chance = 0.6f;
			}
			__instance.lootTable.overrideItemQualities = new List<ItemQuality>();
			if (GunfigConfig._Gunfig.Value("Rainbow Run Start") != "Rainbow Run Lite Lite Lite")
			{
				float value = Random.value;
				if (value < 0.5f)
				{
					__instance.lootTable.overrideItemQualities.Add((ItemQuality)5);
					__instance.lootTable.overrideItemQualities.Add((ItemQuality)4);
				}
				else
				{
					__instance.lootTable.overrideItemQualities.Add((ItemQuality)4);
					__instance.lootTable.overrideItemQualities.Add((ItemQuality)5);
				}
			}
		}
	}

	[HarmonyPatch(typeof(Dungeon), "FloorReached")]
	private class FloorReachedPatch
	{
		private static void Postfix()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			bool isRainbowRun = GameStatsManager.Instance.IsRainbowRun;
			if (RainbowRunPatch.newRainbowCheck)
			{
				SpawnInitialRainbowChest();
			}
			if ((isRainbowRun || RainbowRunPatch.newRainbowCheck) && (int)GameManager.Instance.CurrentGameType == 1 && GunfigConfig._Gunfig.Enabled("Rainbow Run Co-Op Chest"))
			{
				SpawnInitialRainbowChest();
			}
		}
	}

	[HarmonyPatch(typeof(Chest), "GenerateContents")]
	private class GenerateContentsPatch
	{
		[HarmonyILManipulator]
		private static void GenerateContentsIL(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchCallOrCallvirt<Mathf>(instr, "Clamp")
			}))
			{
				val.Emit(OpCodes.Call, (MethodBase)typeof(PushingTheLimitsModule).GetMethod("AssignSynergyChestValue"));
			}
		}
	}

	[HarmonyPatch(typeof(Chest), "RoomEntered")]
	private class RoomEnteredPatch
	{
		[HarmonyILManipulator]
		private static void GenerateContentsIL(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdcR4(instr, 1f)
			}))
			{
				val.Emit(OpCodes.Ldloc_0);
				val.Emit(OpCodes.Call, (MethodBase)typeof(PushingTheLimitsModule).GetMethod("SynergyFuseValue"));
				int index = val.Index;
				val.Index = index + 1;
				val.Emit(OpCodes.Pop);
			}
		}
	}

	[HarmonyPatch(typeof(FloorRewardData), "GetTargetQualityFromChances")]
	private class Magcheck
	{
		[HarmonyPostfix]
		private static void Postfix(FloorRewardData __instance)
		{
			currMagnificence = __instance.DetermineCurrentMagnificence(false);
		}
	}

	[HarmonyPatch(typeof(MagnificenceConstants), "ModifyQualityByMagnificence")]
	private class MagnificenceConstantsPatch
	{
		[HarmonyILManipulator]
		private static void ModifyQualityByMagnificenceIL(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchCallOrCallvirt<Mathf>(instr, "Clamp01")
			}))
			{
				val.Emit(OpCodes.Call, (MethodBase)typeof(PushingTheLimitsModule).GetMethod("AssignMagnificenceValue"));
			}
		}
	}

	[HarmonyPatch(typeof(SynergyFactorConstants), "GetSynergyFactor")]
	private class SynergyFactorPatch
	{
		[HarmonyILManipulator]
		private static void ModifyGetSynergyFactor(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdloc(instr, 3)
			}))
			{
				val.Emit(OpCodes.Call, (MethodBase)typeof(PushingTheLimitsModule).GetMethod("MultSynergyFactor"));
			}
		}
	}

	[HarmonyPatch(typeof(HealthHaver), "Start")]
	private class HealthHaverStartPatch
	{
		[HarmonyPostfix]
		private static void HealthHaverStartPostfix(HealthHaver __instance)
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Invalid comparison between Unknown and I4
			float num = 1f;
			if (GunfigConfig._Gunfig.Value("Boss DPS Cap") == "Vanilla")
			{
				num = 1f;
			}
			if (GunfigConfig._Gunfig.Value("Boss DPS Cap") == "DPS Cap low")
			{
				num = 1.25f;
			}
			if (GunfigConfig._Gunfig.Value("Boss DPS Cap") == "DPS Cap lower than that")
			{
				num = 1.5f;
			}
			if (GunfigConfig._Gunfig.Value("Boss DPS Cap") == "DPS Cap even lower than that")
			{
				num = 2f;
			}
			if (GunfigConfig._Gunfig.Value("Boss DPS Cap") == "DPS Cap just turn it off")
			{
				num = 50f;
			}
			GameLevelDefinition lastLoadedLevelDefinition = GameManager.Instance.GetLastLoadedLevelDefinition();
			if (__instance.IsBoss && !__instance.IsSubboss && lastLoadedLevelDefinition.bossDpsCap > 0f)
			{
				float num2 = 1f;
				if ((int)GameManager.Instance.CurrentGameType == 1)
				{
					num2 = (GameManager.Instance.COOP_ENEMY_HEALTH_MULTIPLIER + 2f) / 2f;
				}
				__instance.m_bossDpsCap = lastLoadedLevelDefinition.bossDpsCap * num2 * num;
			}
		}
	}

	public const string GUID = "bassforte.etg.pushingthelimits";

	public const string NAME = "Pushing The Limits";

	public const string VERSION = "1.0.0";

	public const string TEXT_COLOR = "#00FFFF";

	internal static float currMagnificence;

	public void Start()
	{
		ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
	}

	public void GMStart(GameManager g)
	{
		Log("Pushing The Limits v1.0.0 started successfully.", "#00FFFF");
		GunfigConfig.Init();
	}

	internal void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("bassforte.etg.rainbowrunlite");
		val.PatchAll();
	}

	private static void SpawnInitialRainbowChest()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		bool flag = default(bool);
		Chest val = Chest.Spawn(GameManager.Instance.RewardManager.A_Chest, GameManager.Instance.Dungeon.data.Entrance.GetCenteredVisibleClearSpot(2, 2, ref flag, false));
		val.m_isMimic = false;
		val.IsRainbowChest = true;
		val.BecomeRainbowChest();
	}

	public static float AssignSynergyChestValue(float curr)
	{
		if (GunfigConfig._Gunfig.Value("Synergy Chest Success Rate") == "Better Synergy Chests")
		{
			return 0.25f;
		}
		if (GunfigConfig._Gunfig.Value("Synergy Chest Success Rate") == "Best Synergy Chests")
		{
			return -1f;
		}
		return curr;
	}

	public static float SynergyFuseValue(float curr)
	{
		if (GunfigConfig._Gunfig.Enabled("Synergy Chests have Normal Chest Fuse Rate"))
		{
			return curr;
		}
		return 1f;
	}

	public static float AssignMagnificenceValue(float curr)
	{
		if (GunfigConfig._Gunfig.Value("Magnificence") == "Vanilla")
		{
			return curr;
		}
		float num = -1f;
		if (currMagnificence == 0f)
		{
			num = 0f;
		}
		else
		{
			if (GunfigConfig._Gunfig.Value("Magnificence") == "Prettygoodicence")
			{
				num = Mathf.Clamp(0.2f + 0.2f * currMagnificence, 0f, 0.995f);
			}
			if (GunfigConfig._Gunfig.Value("Magnificence") == "Okayicence")
			{
				num = Mathf.Clamp(0.15f + 0.15f * currMagnificence, 0f, 0.6f);
			}
			if (GunfigConfig._Gunfig.Value("Magnificence") == "Mehicence")
			{
				num = 0f;
			}
		}
		return 1f - num;
	}

	public static float MultSynergyFactor(float curr)
	{
		if (GunfigConfig._Gunfig.Value("Synergy Factor") == "Vanilla")
		{
			return curr;
		}
		int numberOfSynergiesEncounteredThisRun = GameStatsManager.Instance.GetNumberOfSynergiesEncounteredThisRun();
		float num = 1f;
		curr -= 1f;
		if (numberOfSynergiesEncounteredThisRun != 0)
		{
			num = 4f;
		}
		if (GunfigConfig._Gunfig.Value("Synergy Factor") == "Synergy Factor Synchrony")
		{
			num *= 2f;
		}
		if (GunfigConfig._Gunfig.Value("Synergy Factor") == "Synergy Factor Hatsune Miku")
		{
			num *= 5f;
		}
		return 1f + curr * num;
	}

	public static void Log(string text, string color = "#FFFFFF")
	{
		ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
	}
}