Decompiled source of NoVegvisir v1.0.2

NoVegvisir.dll

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

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

[BepInPlugin("com.coarstal.novegvisir", "NoVegvisir", "1.0.2")]
[BepInProcess("valheim.exe")]
public class NoVegvisirPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZNetScene), "CreateObject")]
	public static class ZNetScene_CreateObject_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(ref GameObject __result)
		{
			if ((Object)(object)__result != (Object)null && ModEnabled.Value)
			{
				CleanVegvisir(__result);
			}
		}
	}

	[HarmonyPatch(typeof(Room), "Awake")]
	public static class Room_Awake_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(Room __instance)
		{
			if ((Object)(object)__instance != (Object)null && ModEnabled.Value)
			{
				CleanVegvisir(((Component)__instance).gameObject);
			}
		}
	}

	[HarmonyPatch(typeof(Vegvisir), "Interact")]
	public static class Vegvisir_Interact_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if (ModEnabled.Value)
			{
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Vegvisir), "GetHoverText")]
	public static class Vegvisir_HoverText_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix(ref string __result)
		{
			if (ModEnabled.Value)
			{
				__result = string.Empty;
				return false;
			}
			return true;
		}
	}

	public const string PluginGUID = "com.coarstal.novegvisir";

	public const string PluginName = "NoVegvisir";

	public const string PluginVersion = "1.0.2";

	public static ConfigEntry<bool> ModEnabled;

	public static ConfigEntry<bool> DestroyEntireStructure;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Включить/отключить мод NoVegvisir.");
		DestroyEntireStructure = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DestroyEntireGameObject", true, "Если true, полностью удаляет 3D-модель и объект вигвизёра из мира. Если false, оставляет камень, но блокирует взаимодействие с ним.");
		if (!ModEnabled.Value)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"NoVegvisir отключен в конфигурации.");
			return;
		}
		_harmony = new Harmony("com.coarstal.novegvisir");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"NoVegvisir v1.0.2 успешно загружен!");
	}

	private void OnDestroy()
	{
		if (_harmony != null)
		{
			_harmony.UnpatchSelf();
		}
	}

	public static void CleanVegvisir(GameObject go)
	{
		if ((Object)(object)go == (Object)null || !ModEnabled.Value)
		{
			return;
		}
		Vegvisir[] componentsInChildren = go.GetComponentsInChildren<Vegvisir>(true);
		if (componentsInChildren == null || componentsInChildren.Length == 0)
		{
			return;
		}
		foreach (Vegvisir val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			if (DestroyEntireStructure.Value)
			{
				if ((Object)(object)ZNetScene.instance != (Object)null && (Object)(object)((Component)val).gameObject.GetComponent<ZNetView>() != (Object)null)
				{
					ZNetScene.instance.Destroy(((Component)val).gameObject);
				}
				else
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			else
			{
				Object.Destroy((Object)(object)val);
			}
		}
	}
}