Decompiled source of ScalingEndlessMode v0.2.0

ScalingEndlessMode.dll

Decompiled a month 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 Battle.Enemies;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Loading;
using Map;
using Microsoft.CodeAnalysis;
using PeglinUI;
using ToolBox.Serialization;

[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("ScalingEndlessMode")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds a debug console to Peglin, like Slay the Spire's BaseMod console")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+0ecf9a2d334c861e0286a4efc22ba8bf03ffeff0")]
[assembly: AssemblyProduct("ScalingEndlessMode")]
[assembly: AssemblyTitle("ScalingEndlessMode")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 ScalingEndlessMode
{
	[BepInPlugin("com.angelcaru.peglin.ScalingEndlessMode", "ScalingEndlessMode", "0.0.1")]
	[BepInProcess("Peglin.exe")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("com.angelcaru.peglin.ScalingEndlessMode");

		internal static ManualLogSource Logger;

		public static int iteration;

		private void Awake()
		{
			harmony.PatchAll();
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin com.angelcaru.peglin.ScalingEndlessMode is loaded!");
		}

		[HarmonyPatch(typeof(GameInit), "Start")]
		[HarmonyPrefix]
		private static void PatchStart(GameInit __instance)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)"PatchStart()");
			if (((LoadMapData)typeof(GameInit).InvokeMember("LoadData", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, __instance, null)).NewGame)
			{
				iteration = 0;
				EndlessModeSaveData.SaveData(iteration);
			}
			else
			{
				iteration = EndlessModeSaveData.LoadData();
			}
		}

		[HarmonyPatch(typeof(MapController), "ProceedAfterBattle")]
		[HarmonyPrefix]
		private static void PatchProceedAfterBattle(MapController __instance)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)$"PatchProceedAfterBattle({__instance})");
			if (StaticGameData.loadNextScene && (int)__instance.nextScene == 8)
			{
				__instance.nextScene = (Scene)3;
				iteration++;
				EndlessModeSaveData.SaveData(iteration);
			}
		}

		[HarmonyPatch(typeof(Enemy), "Initialize")]
		[HarmonyPrefix]
		private static void PatchEnemyInitialize(ref float ___StartingHealth)
		{
			___StartingHealth *= 1 << iteration;
		}

		[HarmonyPatch(typeof(PlayerInfoUI), "ChangeFloorText")]
		[HarmonyPrefix]
		private static void PatchChangeFloorText(ref string mapName)
		{
			mapName = $"Iteration {iteration + 1}\n" + mapName;
		}
	}
	public class EndlessModeSaveData : SaveObjectData
	{
		public static readonly string KEY = "com.angelcaru.peglin.ScalingEndlessMode_SaveData";

		public int iteration;

		public override string Name => KEY;

		public EndlessModeSaveData()
			: base(true, (SaveType)1)
		{
			iteration = 0;
		}

		public static int LoadData()
		{
			EndlessModeSaveData endlessModeSaveData = (EndlessModeSaveData)(object)DataSerializer.Load<SaveObjectData>(KEY, (SaveType)1);
			if (endlessModeSaveData == null)
			{
				endlessModeSaveData = new EndlessModeSaveData();
			}
			return endlessModeSaveData.iteration;
		}

		public static void SaveData(int iteration)
		{
			((SaveObjectData)new EndlessModeSaveData
			{
				iteration = iteration
			}).Save();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.angelcaru.peglin.ScalingEndlessMode";

		public const string PLUGIN_NAME = "ScalingEndlessMode";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}