Decompiled source of KeyItemSlotFix v1.0.0

KeyItemSlotFix.dll

Decompiled 2 weeks ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace DSH.KeyItemFix;

[BepInPlugin("com.dsh.keyitemfix", "KeyItem Slot Fix", "1.0.0")]
public class KeyItemFixPlugin : BaseUnityPlugin
{
	public static KeyItemFixPlugin Inst;

	public static ManualLogSource Log;

	private void Awake()
	{
		Inst = this;
		Log = ((BaseUnityPlugin)this).Logger;
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(FixSurvivors));
		((BaseUnityPlugin)this).Logger.LogInfo((object)"KeyItem Slot Fix v1.0.0 loaded");
	}

	private void FixSurvivors()
	{
		int num = 0;
		try
		{
			foreach (SurvivorDef allSurvivorDef in SurvivorCatalog.allSurvivorDefs)
			{
				if (!((Object)(object)allSurvivorDef == (Object)null) && !((Object)(object)allSurvivorDef.bodyPrefab == (Object)null))
				{
					GameObject bodyPrefab = allSurvivorDef.bodyPrefab;
					if (!((Object)(object)bodyPrefab.GetComponent<CharacterBody>() == (Object)null) && !((Object)(object)bodyPrefab.GetComponent<InputBankTest>() == (Object)null) && !((Object)(object)bodyPrefab.GetComponent<KeyItemSlot>() != (Object)null))
					{
						bodyPrefab.AddComponent<KeyItemSlot>();
						num++;
						Log.LogWarning((object)("[KeyItemFix] added KeyItemSlot to survivor '" + (allSurvivorDef.displayNameToken ?? ((Object)bodyPrefab).name) + "' (" + ((Object)bodyPrefab).name + ")"));
					}
				}
			}
			Log.LogInfo((object)("[KeyItemFix] done, patched " + num + " survivor prefab(s)"));
		}
		catch (Exception ex)
		{
			Log.LogError((object)("FixSurvivors: " + ex));
		}
	}
}