Decompiled source of LoadoutMetamorphosis v1.1.1

plugins/LoadoutMetamorphosis/LoadoutMetamorphosis.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using InLobbyConfig;
using InLobbyConfig.Fields;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour.HookGen;
using PartialMetamorphosis;
using RoR2;
using RoR2.Skills;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
namespace LoadoutMetamorphosis;

public static class InLobbyConfigIntegration
{
	public const string GUID = "com.KingEnderBrine.InLobbyConfig";

	private static bool Enabled => Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.InLobbyConfig");

	private static object ModConfig { get; set; }

	public static void OnStart()
	{
		if (Enabled)
		{
			OnStartInternal();
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	private static void OnStartInternal()
	{
		//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_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_0069: Expected O, but got Unknown
		ModConfigEntry val = new ModConfigEntry
		{
			DisplayName = "Loadout Metamorphosis",
			EnableField = new BooleanConfigField("", (Func<bool>)(() => LoadoutMetamorphosisPlugin.IsEnabled.Value), (Action<bool>)delegate(bool newValue)
			{
				LoadoutMetamorphosisPlugin.IsEnabled.Value = newValue;
			})
		};
		ModConfigCatalog.Add(val);
		ModConfig = (object)val;
	}

	public static void OnDestroy()
	{
		if (Enabled)
		{
			OnDestroyInternal();
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	private static void OnDestroyInternal()
	{
		object modConfig = ModConfig;
		ModConfigCatalog.Remove((ModConfigEntry)((modConfig is ModConfigEntry) ? modConfig : null));
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.KingEnderBrine.LoadoutMetamorphosis", "Loadout Metamorphosis", "1.1.1")]
public class LoadoutMetamorphosisPlugin : BaseUnityPlugin
{
	public const string GUID = "com.KingEnderBrine.LoadoutMetamorphosis";

	public const string Name = "Loadout Metamorphosis";

	public const string Version = "1.1.1";

	internal static ConfigEntry<bool> IsEnabled { get; set; }

	public void Start()
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		IsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "enabled", true, "Is mod enabled");
		HookEndpointManager.Modify((MethodBase)typeof(CharacterMaster).GetMethod("SpawnBody", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[1] { typeof(SpawnBodyArgs) }, null), (Delegate)new Manipulator(CharacterMasterSpawnBody));
		InLobbyConfigIntegration.OnStart();
	}

	public void Destroy()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		HookEndpointManager.Unmodify((MethodBase)typeof(CharacterMaster).GetMethod("SpawnBody"), (Delegate)new Manipulator(CharacterMasterSpawnBody));
		InLobbyConfigIntegration.OnDestroy();
	}

	private static void CharacterMasterSpawnBody(ILContext il)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		int bodyIndex = -1;
		FieldReference val2 = default(FieldReference);
		val.GotoNext(new Func<Instruction, bool>[4]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref bodyIndex),
			(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
			(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val2),
			(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, typeof(CharacterBody), "SetLoadoutServer")
		});
		int index = val.Index;
		val.Index = index + 1;
		val.Emit(OpCodes.Dup);
		val.Index += 2;
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Func<CharacterBody, Loadout, CharacterMaster, Loadout>>((Func<CharacterBody, Loadout, CharacterMaster, Loadout>)BeforeSetLoadout);
	}

	private static Loadout BeforeSetLoadout(CharacterBody body, Loadout loadout, CharacterMaster master)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)master.playerCharacterMasterController) || !RunArtifactManager.instance.IsArtifactEnabled(Artifacts.RandomSurvivorOnRespawn) || !PartialMetamorphosisIntegration.ShouldChange(master))
		{
			return loadout;
		}
		Loadout val = new Loadout();
		loadout.Copy(val);
		List<UnlockableDef> unlockables = master.playerCharacterMasterController.networkUser.unlockables;
		GenericSkill[] bodyPrefabSkillSlots = BodyCatalog.GetBodyPrefabSkillSlots(body.bodyIndex);
		for (int i = 0; i < bodyPrefabSkillSlots.Length; i++)
		{
			GenericSkill val2 = bodyPrefabSkillSlots[i];
			List<uint> list = new List<uint>();
			for (uint num = 0u; num < val2.skillFamily.variants.Length; num++)
			{
				Variant val3 = val2.skillFamily.variants[num];
				if (!Object.op_Implicit((Object)(object)val3.unlockableDef) || unlockables.Contains(val3.unlockableDef))
				{
					list.Add(num);
				}
			}
			val.bodyLoadoutManager.SetSkillVariant(body.bodyIndex, i, list[Random.Range(0, list.Count)]);
		}
		return val;
	}
}
public static class PartialMetamorphosisIntegration
{
	public const string GUID = "com.KingEnderBrine.PartialMetamorphosis";

	private static bool Enabled => Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.PartialMetamorphosis");

	public static bool ShouldChange(CharacterMaster master)
	{
		if (Enabled)
		{
			return ShouldChangeInternal(master);
		}
		return true;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	private static bool ShouldChangeInternal(CharacterMaster master)
	{
		return PartialMetamorphosisPlugin.ShouldChangeCharacter(master);
	}
}