Decompiled source of Kirks Pack v1.0.0

BepInEx/plugins/KirksPack/KirksPack.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;

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

[BepInPlugin("kirk.kirkspack", "Kirk's Pack", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "kirk.kirkspack";

	public const string Version = "1.0.0";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony harmony = new Harmony("kirk.kirkspack");
		IndoorHazardPlaceholderFix.Apply(harmony);
	}
}
internal static class IndoorHazardPlaceholderFix
{
	internal static void Apply(Harmony harmony)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method("LethalLevelLoader.AssetBundleLoader:NetworkRegisterDungeonContent", (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			Plugin.Log.LogInfo((object)"LethalLevelLoader not found (or changed); indoor hazard fix not needed.");
			return;
		}
		harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(IndoorHazardPlaceholderFix), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		Plugin.Log.LogInfo((object)"Indoor hazard placeholder fix applied.");
	}

	private static void Prefix(object extendedDungeonFlow, NetworkManager networkManager)
	{
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		if (extendedDungeonFlow == null)
		{
			return;
		}
		if ((Object)(object)networkManager == (Object)null)
		{
			networkManager = NetworkManager.Singleton;
		}
		if ((Object)(object)networkManager == (Object)null || networkManager.NetworkConfig == null)
		{
			return;
		}
		List<IndoorMapHazard> value = Traverse.Create(extendedDungeonFlow).Property("IndoorMapHazards", (object[])null).GetValue<List<IndoorMapHazard>>();
		if (value == null || value.Count == 0)
		{
			return;
		}
		Dictionary<string, GameObject> dictionary = new Dictionary<string, GameObject>();
		foreach (NetworkPrefab prefab in networkManager.NetworkConfig.Prefabs.Prefabs)
		{
			if (prefab != null && (Object)(object)prefab.Prefab != (Object)null && !dictionary.ContainsKey(((Object)prefab.Prefab).name))
			{
				dictionary.Add(((Object)prefab.Prefab).name, prefab.Prefab);
			}
		}
		string name = ((Object)extendedDungeonFlow).name;
		foreach (IndoorMapHazard item in value)
		{
			if (item == null || (Object)(object)item.hazardType == (Object)null)
			{
				continue;
			}
			GameObject prefabToSpawn = item.hazardType.prefabToSpawn;
			if (!((Object)(object)prefabToSpawn == (Object)null) && !((Object)(object)prefabToSpawn.GetComponent<NetworkObject>() != (Object)null))
			{
				if (dictionary.TryGetValue(((Object)prefabToSpawn).name, out var value2))
				{
					item.hazardType.prefabToSpawn = value2;
					Plugin.Log.LogInfo((object)("[" + name + "] Restored indoor hazard placeholder '" + ((Object)prefabToSpawn).name + "' to the vanilla prefab."));
				}
				else
				{
					Plugin.Log.LogWarning((object)("[" + name + "] Indoor hazard '" + ((Object)prefabToSpawn).name + "' has no NetworkObject and no vanilla prefab matches its name; leaving it to LethalLevelLoader."));
				}
			}
		}
	}
}