Decompiled source of MithrixSurprise v1.0.6

MithrixSurprise.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.ExpansionManagement;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[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("MithrixSurprise")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6c43b7a651d506ee2a26ea45e5101e5306fdfedc")]
[assembly: AssemblyProduct("MithrixSurprise")]
[assembly: AssemblyTitle("MithrixSurprise")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MithrixSurprise;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Nuxlar.MithrixSurprise", "MithrixSurprise", "1.0.6")]
public class MithrixSurprise : BaseUnityPlugin
{
	internal static ConfigEntry<float> probability;

	private static SpawnCard theBoi = Addressables.LoadAssetAsync<SpawnCard>((object)"RoR2/Base/Brother/cscBrother.asset").WaitForCompletion();

	internal static ConfigEntry<float> probabilityFalse;

	private static readonly ExpansionDef dlc2 = Addressables.LoadAssetAsync<ExpansionDef>((object)"RoR2/DLC2/Common/DLC2.asset").WaitForCompletion();

	private static readonly SpawnCard theFalseBoi = Addressables.LoadAssetAsync<SpawnCard>((object)"RoR2/DLC2/FalseSonBoss/cscFalseSonBoss.asset").WaitForCompletion();

	private static ConfigFile RoRConfig { get; set; }

	public void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Expected O, but got Unknown
		RoRConfig = new ConfigFile(Paths.ConfigPath + "\\MithrixSurprise.cfg", true);
		probability = RoRConfig.Bind<float>("General", "Spawn Chance", 0.5f, "Mithrix spawn chance.");
		probabilityFalse = RoRConfig.Bind<float>("General", "Spawn Chance False Son", 0f, "False Son spawn chance. (Requires SotS)");
		if (!File.Exists(Paths.ConfigPath + "\\MithrixSurpriseFirstRun.cfg"))
		{
			if (probability.Value != (float)((ConfigEntryBase)probability).DefaultValue)
			{
				ConfigEntry<float> obj = probability;
				obj.Value *= 100f;
			}
			File.Create(Paths.ConfigPath + "\\MithrixSurpriseFirstRun.cfg");
		}
		Math.Clamp(probability.Value, 0f, 100f);
		Math.Clamp(probabilityFalse.Value, 0f, 100f);
		if (RoO.Enabled)
		{
			string text = Assembly.GetExecutingAssembly().Location.Replace("MithrixSurprise.dll", "icon.png");
			if (!File.Exists(text))
			{
				text = "";
			}
			RoO.AddOptions(text);
		}
		PurchaseInteraction.OnInteractionBegin += new hook_OnInteractionBegin(PurchaseInteraction_OnInteractionBegin);
	}

	private static void PurchaseInteraction_OnInteractionBegin(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
	{
		if (self.CanBeAffordedByInteractor(activator))
		{
			if (RoR2Application.rng.RangeFloat(0f, 1f) < probability.Value / 100f)
			{
				SpawnTheBoi(((Component)activator).GetComponent<CharacterBody>(), theBoi);
			}
			if (!Run.instance.IsExpansionEnabled(dlc2))
			{
				orig.Invoke(self, activator);
				return;
			}
			if (RoR2Application.rng.RangeFloat(0f, 1f) < probabilityFalse.Value / 100f)
			{
				SpawnTheBoi(((Component)activator).GetComponent<CharacterBody>(), theFalseBoi);
			}
			orig.Invoke(self, activator);
		}
		else
		{
			orig.Invoke(self, activator);
		}
	}

	private static void SpawnTheBoi(CharacterBody activatorBody, SpawnCard spawnCard)
	{
		//IL_0008: 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_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		Transform coreTransform = activatorBody.coreTransform;
		MonsterSpawnDistance val = (MonsterSpawnDistance)2;
		DirectorPlacementRule val2 = new DirectorPlacementRule
		{
			spawnOnTarget = coreTransform,
			placementMode = (PlacementMode)3
		};
		DirectorCore.GetMonsterSpawnDistance(val, ref val2.minDistance, ref val2.maxDistance);
		GameObject val3 = DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(spawnCard, val2, RoR2Application.rng)
		{
			teamIndexOverride = (TeamIndex)2
		});
		val3.GetComponent<CharacterMaster>().isBoss = true;
		if (Object.op_Implicit((Object)(object)val3))
		{
			NetworkServer.Spawn(val3);
		}
	}
}
internal static class RoO
{
	public static bool Enabled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void AddOptions(string iconPath)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		StepSliderConfig val = new StepSliderConfig
		{
			min = 0f,
			max = 100f,
			increment = 0.25f,
			FormatString = "{0}%"
		};
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(MithrixSurprise.probability, val));
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(MithrixSurprise.probabilityFalse, val));
		if (iconPath != "")
		{
			Texture2D val2 = new Texture2D(256, 256, (TextureFormat)5, 3, false);
			if (ImageConversion.LoadImage(val2, File.ReadAllBytes(iconPath)))
			{
				Sprite modIcon = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), Vector2.zero);
				ModSettingsManager.SetModIcon(modIcon);
			}
		}
		ModSettingsManager.SetModDescription("Goodbye Moon Man");
	}
}