Decompiled source of KarmaDressUp v1.0.0

KarmaDressUp.dll

Decompiled a week ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using RoR2;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace KarmaDressUp;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("binma.karmadressup", "Karma Dress-Up Mithrix", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ConfigEntry<int> RequiredKarma;

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		RequiredKarma = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Required Karma", 8, "Mithrix only appears dressed up at this Karma or higher.");
		Harmony val = new Harmony("binma.karmadressup");
		val.Patch((MethodBase)AccessTools.Method(typeof(ModelSkinController), "ApplySkin", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "Gate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo = AccessTools.Method(typeof(ModelSkinController), "ApplySkinAsync", (Type[])null, (Type[])null);
		if (methodInfo != null)
		{
			val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "Gate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static void Gate(ModelSkinController __instance, ref int skinIndex)
	{
		try
		{
			SkinDef[] skins = __instance.skins;
			if (skins != null && skinIndex > 0 && skinIndex < skins.Length && Object.op_Implicit((Object)(object)skins[skinIndex]))
			{
				string nameToken = skins[skinIndex].nameToken;
				if (nameToken != null && nameToken.StartsWith("BIGBADPIGEON_SKIN_BROTHER") && nameToken.Contains("DRESSUP") && !KarmaIsHighEnough())
				{
					skinIndex = 0;
				}
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)ex);
		}
	}

	private static bool KarmaIsHighEnough()
	{
		KarmaManager instance = KarmaManager.instance;
		if (!Object.op_Implicit((Object)(object)instance) || !instance.IsKarmaEnabled())
		{
			return false;
		}
		return instance.GetEffectiveKarma() >= RequiredKarma.Value;
	}
}