Decompiled source of LessGuaranteedAccessNodes v1.0.0

plugins/LessGuaranteedAccessNodes/LessGuaranteedAccessNodes.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
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 IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;

[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("LessGuaranteedAccessNodes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4ef438676309b73f5a5a9a05422149e05c0dfea6")]
[assembly: AssemblyProduct("LessGuaranteedAccessNodes")]
[assembly: AssemblyTitle("LessGuaranteedAccessNodes")]
[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 RoR2LessGuaranteedAccessNodes
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

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

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

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

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

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

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("SSM24.LessGuaranteedAccessNodes", "LessGuaranteedAccessNodes", "1.0.0")]
	public class RoR2LessGuaranteedAccessNodes : BaseUnityPlugin
	{
		public const string PluginGUID = "SSM24.LessGuaranteedAccessNodes";

		public const string PluginAuthor = "SSM24";

		public const string PluginName = "LessGuaranteedAccessNodes";

		public const string PluginVersion = "1.0.0";

		private static readonly Dictionary<string, float> defaultStageConfigs = new Dictionary<string, float>
		{
			["Scorched Acres"] = 0.2f,
			["Rallypoint Delta"] = 0.5f,
			["Sulfur Pools"] = 0.33f,
			["Iron Alluvium/Aurora"] = 0.75f,
			["Repurposed Crater"] = 0.6f,
			["Fogbound Lagoon"] = 0.33f,
			["Remote Village"] = 0.33f
		};

		private static readonly HashSet<string> moddedStages = new HashSet<string> { "Fogbound Lagoon", "Remote Village" };

		private static readonly Dictionary<string, float> stageConfigs = new Dictionary<string, float>();

		private const string RejectedAccessNodesOnce = "ssm_RejectedAccessNodes";

		private const string SeenAccessNodesOnce = "ssm_SeenAccessNodes";

		public void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			InitializeSettings();
			AccessCodesMissionController.OnStartServer += new Manipulator(IL_ModifyAccessCodesMissionController);
		}

		public void OnDestroy()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			AccessCodesMissionController.OnStartServer -= new Manipulator(IL_ModifyAccessCodesMissionController);
		}

		private void InitializeSettings()
		{
			foreach (KeyValuePair<string, float> defaultStageConfig in defaultStageConfigs)
			{
				string key = defaultStageConfig.Key;
				string text = (moddedStages.Contains(key) ? "Modded Stages" : "Default Stages");
				ConfigEntry<float> val = ((BaseUnityPlugin)this).Config.Bind<float>(text, key, defaultStageConfig.Value, "Chance for spawn on " + key);
				stageConfigs[key] = val.Value;
			}
		}

		private void IL_ModifyAccessCodesMissionController(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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.MatchStloc(instr, 0)
			}))
			{
				val.Emit(OpCodes.Ldloc_0);
				val.EmitDelegate<Func<bool>>((Func<bool>)ShouldAccessNodesSpawn);
				val.Emit(OpCodes.And);
				val.Emit(OpCodes.Stloc_0);
			}
		}

		private bool ShouldAccessNodesSpawn()
		{
			if (Run.instance.GetEventFlag("ssm_RejectedAccessNodes") && !Run.instance.GetEventFlag("ssm_SeenAccessNodes"))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Guaranteeing Access Node spawn...");
				Run.instance.SetEventFlag("ssm_SeenAccessNodes");
				return true;
			}
			string baseSceneName = SceneCatalog.GetSceneDefForCurrentScene().baseSceneName;
			float num = baseSceneName switch
			{
				"wispgraveyard" => stageConfigs["Scorched Acres"], 
				"frozenwall" => stageConfigs["Rallypoint Delta"], 
				"sulfurpools" => stageConfigs["Sulfur Pools"], 
				"ironalluvium" => stageConfigs["Iron Alluvium/Aurora"], 
				"ironalluvium2" => stageConfigs["Iron Alluvium/Aurora"], 
				"FBLScene" => stageConfigs["Fogbound Lagoon"], 
				"agatevillage" => stageConfigs["Remote Village"], 
				"repurposedcrater" => stageConfigs["Repurposed Crater"], 
				_ => 0.5f, 
			};
			float nextNormalizedFloat = Run.instance.stageRng.nextNormalizedFloat;
			((BaseUnityPlugin)this).Logger.LogDebug((object)$"{baseSceneName}: rolled {nextNormalizedFloat} (needed: <{num})");
			if (nextNormalizedFloat < num)
			{
				Run.instance.SetEventFlag("ssm_SeenAccessNodes");
				return true;
			}
			Run.instance.SetEventFlag("ssm_RejectedAccessNodes");
			return false;
		}
	}
}