Decompiled source of PassThroughSkeletts v0.1.0

PassThroughSkeletts.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("PassThroughSkeletts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+c365c14c117255007897a79889218087931a8db4")]
[assembly: AssemblyProduct("PassThroughSkeletts")]
[assembly: AssemblyTitle("PassThroughSkeletts")]
[assembly: AssemblyVersion("0.1.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 PassThroughSkeletts
{
	internal static class DebugCommands
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static ConsoleEvent <0>__Report;
		}

		private const float SearchRadius = 60f;

		internal static void Register()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			object obj = <>O.<0>__Report;
			if (obj == null)
			{
				ConsoleEvent val = Report;
				<>O.<0>__Report = val;
				obj = (object)val;
			}
			new ConsoleCommand("pts_status", "every summoned skeleton nearby, and how many of its collisions with players are off", (ConsoleEvent)obj, false, false, false, true, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}

		private static void Report(ConsoleEventArgs args)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				args.Context.AddString("No player yet.");
				return;
			}
			args.Context.AddString("Enabled: " + ModConfig.Enabled.Value + ", players known to this game: " + Player.GetAllPlayers().Count);
			Vector3 position = ((Component)localPlayer).transform.position;
			List<Character> allCharacters = Character.GetAllCharacters();
			int num = 0;
			for (int i = 0; i < allCharacters.Count; i++)
			{
				Character val = allCharacters[i];
				if (Passthrough.IsSummoned(val))
				{
					float num2 = Vector3.Distance(position, ((Component)val).transform.position);
					if (!(num2 > 60f))
					{
						num++;
						Passthrough.Tally(val, out var ignored, out var total);
						string text = (string.IsNullOrEmpty(val.m_name) ? ((Object)val).name : val.m_name);
						args.Context.AddString(text + " (" + Mathf.RoundToInt(num2) + "m) - " + (val.IsOwner() ? "ours" : "owned elsewhere") + " - " + ignored + "/" + total + " pairs ignored");
					}
				}
			}
			if (num == 0)
			{
				args.Context.AddString("No summoned Skeletts within " + Mathf.RoundToInt(60f) + "m.");
			}
		}
	}
	internal static class ModConfig
	{
		internal static ConfigEntry<bool> Enabled;

		internal static void Init(ConfigFile cfg)
		{
			Enabled = cfg.Bind<bool>("General", "Enabled", true, "Master switch. Turn this off and Skeletts go back to being solid: you are blocked and pushed by them exactly as in vanilla. It takes effect within a fraction of a second, no restart needed.");
		}
	}
	internal static class Passthrough
	{
		private static readonly List<Collider> Colliders = new List<Collider>();

		internal static bool IsSummoned(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return false;
			}
			Tameable component = ((Component)character).GetComponent<Tameable>();
			if ((Object)(object)component != (Object)null)
			{
				if (!(component.m_unsummonDistance > 0f))
				{
					return component.m_unsummonOnOwnerLogoutSeconds > 0f;
				}
				return true;
			}
			return false;
		}

		internal static void Sweep(bool ignore)
		{
			List<Player> allPlayers = Player.GetAllPlayers();
			if (allPlayers.Count == 0)
			{
				return;
			}
			List<Character> allCharacters = Character.GetAllCharacters();
			for (int i = 0; i < allCharacters.Count; i++)
			{
				Character val = allCharacters[i];
				if (!IsSummoned(val))
				{
					continue;
				}
				((Component)val).GetComponentsInChildren<Collider>(true, Colliders);
				for (int j = 0; j < allPlayers.Count; j++)
				{
					Collider val2 = (Collider)(object)(((Object)(object)allPlayers[j] == (Object)null) ? null : ((Character)allPlayers[j]).GetCollider());
					if (!Usable(val2))
					{
						continue;
					}
					for (int k = 0; k < Colliders.Count; k++)
					{
						Collider val3 = Colliders[k];
						if (Usable(val3) && Physics.GetIgnoreCollision(val2, val3) != ignore)
						{
							Physics.IgnoreCollision(val2, val3, ignore);
						}
					}
				}
			}
		}

		internal static void Tally(Character skelett, out int ignored, out int total)
		{
			ignored = 0;
			total = 0;
			((Component)skelett).GetComponentsInChildren<Collider>(true, Colliders);
			List<Player> allPlayers = Player.GetAllPlayers();
			for (int i = 0; i < allPlayers.Count; i++)
			{
				Collider val = (Collider)(object)(((Object)(object)allPlayers[i] == (Object)null) ? null : ((Character)allPlayers[i]).GetCollider());
				if (!Usable(val))
				{
					continue;
				}
				for (int j = 0; j < Colliders.Count; j++)
				{
					if (Usable(Colliders[j]))
					{
						total++;
						if (Physics.GetIgnoreCollision(val, Colliders[j]))
						{
							ignored++;
						}
					}
				}
			}
		}

		private static bool Usable(Collider collider)
		{
			if ((Object)(object)collider != (Object)null && collider.enabled)
			{
				return ((Component)collider).gameObject.activeInHierarchy;
			}
			return false;
		}
	}
	[BepInPlugin("pandincus.passthroughskeletts", "PassThroughSkeletts", "0.1.0")]
	[BepInProcess("valheim.exe")]
	public class PassThroughSkelettsPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "pandincus.passthroughskeletts";

		public const string PluginName = "PassThroughSkeletts";

		public const string PluginVersion = "0.1.0";

		private const float SweepInterval = 0.1f;

		internal static ManualLogSource Log;

		private float _sinceSweep;

		private bool _sweeping = true;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				ModConfig.Init(((BaseUnityPlugin)this).Config);
				DebugCommands.Register();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("PassThroughSkeletts could not set itself up, so it will do nothing this session. " + ex));
				_sweeping = false;
				return;
			}
			Log.LogInfo((object)"PassThroughSkeletts v0.1.0 loaded.");
		}

		private void Update()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				_sinceSweep = 0f;
				_sweeping = ModConfig.Enabled != null;
			}
			else
			{
				if (!_sweeping)
				{
					return;
				}
				_sinceSweep += Time.deltaTime;
				if (!(_sinceSweep < 0.1f))
				{
					_sinceSweep = 0f;
					try
					{
						Passthrough.Sweep(ModConfig.Enabled.Value);
					}
					catch (Exception ex)
					{
						_sweeping = false;
						Log.LogError((object)("PassThroughSkeletts could not sweep for Skeletts, so it is off until you next load a world. " + ex));
					}
				}
			}
		}
	}
}