Decompiled source of NoWoodPortals v1.0.1

NoWoodPortals.dll

Decompiled 3 days 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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("NoWoodPortals")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoWoodPortals")]
[assembly: AssemblyTitle("NoWoodPortals")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 NoWoodPortals
{
	[BepInPlugin("dumba.nowoodportals", "No Wood Portals", "1.0.1")]
	public class NoWoodPortalsPlugin : BaseUnityPlugin
	{
		public const string ModGuid = "dumba.nowoodportals";

		public const string ModName = "No Wood Portals";

		public const string ModVersion = "1.0.1";

		private Harmony _harmony;

		internal static NoWoodPortalsPlugin Instance { get; private set; }

		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("dumba.nowoodportals");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded No Wood Portals");
		}

		private void OnDestroy()
		{
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
			}
			if (Instance == this)
			{
				Instance = null;
			}
		}

		internal void Log(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)msg);
		}

		internal void LogWarn(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)msg);
		}

		internal void LogErr(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)msg);
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	internal static class Patch_ObjectDB_Awake
	{
		private static void Postfix()
		{
			NoWoodPortalsPlugin instance = NoWoodPortalsPlugin.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				((MonoBehaviour)instance).StartCoroutine(WaitThenDisablePortalWood());
			}
		}

		private static IEnumerator WaitThenDisablePortalWood()
		{
			while ((Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items == null || ObjectDB.instance.m_items.Count == 0)
			{
				yield return null;
			}
			while ((Object)(object)ZNetScene.instance == (Object)null)
			{
				yield return null;
			}
			int safety = 600;
			while (safety-- > 0 && (Object)(object)ZNetScene.instance.GetPrefab("portal_wood") == (Object)null)
			{
				yield return null;
			}
			DisablePieceInHammer("portal_wood");
		}

		private static void DisablePieceInHammer(string piecePrefabName)
		{
			NoWoodPortalsPlugin instance = NoWoodPortalsPlugin.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab(piecePrefabName);
			if ((Object)(object)prefab == (Object)null)
			{
				instance.LogWarn("Prefab '" + piecePrefabName + "' not found in ZNetScene.");
				return;
			}
			Piece component = prefab.GetComponent<Piece>();
			if ((Object)(object)component == (Object)null)
			{
				instance.LogWarn("Prefab '" + piecePrefabName + "' has no Piece component.");
				return;
			}
			component.m_enabled = false;
			instance.Log("Disabled '" + piecePrefabName + "' piece (m_enabled = false).");
		}
	}
}