Decompiled source of NoBigTree v1.0.0

plugins/NoBigTree.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("nussbacker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Removes the giant World Tree from Valheim's sky.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoBigTree")]
[assembly: AssemblyTitle("NoBigTree")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NoBigTree
{
	[BepInPlugin("nussbacker.nobigtree", "NoBigTree", "1.0.0")]
	public sealed class NoBigTreePlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(EnvMan), "Awake")]
		private static class EnvManAwakePatch
		{
			private static void Postfix()
			{
				if (!((Object)(object)_instance == (Object)null))
				{
					int num = RemoveSkyTreeObjects();
					if (num > 0)
					{
						((BaseUnityPlugin)_instance).Logger.LogInfo((object)string.Format("Removed {0} {1} object(s).", num, "YggdrasilBranch"));
					}
					else
					{
						((MonoBehaviour)_instance).StartCoroutine(_instance.RemoveWhenAvailable());
					}
				}
			}
		}

		public const string PluginGuid = "nussbacker.nobigtree";

		public const string PluginName = "NoBigTree";

		public const string PluginVersion = "1.0.0";

		private const string TargetObjectPrefix = "YggdrasilBranch";

		private const int DelayedPassCount = 20;

		private const float DelayedPassInterval = 0.5f;

		private static NoBigTreePlugin _instance;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			_instance = this;
			_harmony = new Harmony("nussbacker.nobigtree");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"NoBigTree 1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
			}
		}

		private static int RemoveSkyTreeObjects()
		{
			int num = 0;
			GameObject[] array = Object.FindObjectsOfType<GameObject>();
			foreach (GameObject val in array)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name.StartsWith("YggdrasilBranch", StringComparison.OrdinalIgnoreCase))
				{
					Object.Destroy((Object)(object)val);
					num++;
				}
			}
			return num;
		}

		private IEnumerator RemoveWhenAvailable()
		{
			for (int pass = 0; pass < 20; pass++)
			{
				yield return (object)new WaitForSeconds(0.5f);
				int num = RemoveSkyTreeObjects();
				if (num > 0)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Removed {0} {1} object(s).", num, "YggdrasilBranch"));
					break;
				}
			}
		}
	}
}