Decompiled source of BuilderIcon v1.0.0

BuilderIcon.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Eremite.Characters;
using Eremite.Characters.Villagers;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("BuilderIcon")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Example Mod for Against The Storm")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d6ada77561ccfe85ca4c2c807fd24c8c3fc0d51c")]
[assembly: AssemblyProduct("BuilderIcon")]
[assembly: AssemblyTitle("BuilderIcon")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 BuilderIcon
{
	public class BuilderIcon : MonoBehaviour
	{
		private Villager villager;

		private GameObject iconGO;

		private SpriteRenderer renderer;

		public BuilderIcon(Villager v)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			villager = v;
			iconGO = new GameObject("BuilderIcon");
			renderer = iconGO.AddComponent<SpriteRenderer>();
			renderer.sprite = Plugin.BuilderMarkerSprite;
			((Renderer)renderer).material = new Material(Shader.Find("Sprites/Default"));
			((Renderer)renderer).sortingLayerName = "UI";
			((Renderer)renderer).sortingOrder = 5000;
			iconGO.transform.SetParent(((Component)v.view).transform, false);
			iconGO.transform.localPosition = new Vector3(0f, 1.8f, 0f);
			iconGO.transform.localScale = Vector3.one;
			iconGO.AddComponent<BuilderBillboard>();
			iconGO.AddComponent<BuilderIconUpdater>().Init(this);
		}

		public void Refresh()
		{
			if (!((Object)(object)renderer == (Object)null))
			{
				((Renderer)renderer).enabled = Plugin.IconsEnabled;
			}
		}

		public void Destroy()
		{
			if ((Object)(object)iconGO != (Object)null)
			{
				Object.Destroy((Object)(object)iconGO);
			}
		}
	}
	public class BuilderBillboard : MonoBehaviour
	{
		private void LateUpdate()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				((Component)this).transform.forward = ((Component)main).transform.forward;
			}
		}
	}
	public class BuilderIconUpdater : MonoBehaviour
	{
		private BuilderIcon parent;

		public void Init(BuilderIcon p)
		{
			parent = p;
		}

		private void Update()
		{
			parent.Refresh();
		}
	}
	[BepInPlugin("Buildericon", "Builder Icon", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <LoadMarkerSpriteWhenHUDReady>d__6 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Plugin <>4__this;

			private GameObject <hud>5__1;

			private Image <src>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadMarkerSpriteWhenHUDReady>d__6(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<hud>5__1 = null;
				<src>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<hud>5__1 = null;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((Object)(object)<hud>5__1 == (Object)null)
				{
					<hud>5__1 = GameObject.Find("/HUD/GoodsHUD/SacrificeMarker/Content");
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				<src>5__2 = <hud>5__1.GetComponent<Image>();
				if ((Object)(object)<src>5__2 != (Object)null)
				{
					BuilderMarkerSprite = <src>5__2.sprite;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		internal static Plugin Instance;

		internal static Harmony Harmony;

		public static ConfigEntry<KeyboardShortcut> ToggleHotkey;

		public static bool IconsEnabled = true;

		public static Sprite BuilderMarkerSprite;

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Instance = this;
			ToggleHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleBuilderIcons", new KeyboardShortcut((KeyCode)39, Array.Empty<KeyCode>()), "Hotkey to toggle builder icons on/off.");
			Harmony = new Harmony("Buildericon.harmony");
			Harmony.PatchAll();
			((MonoBehaviour)this).StartCoroutine(LoadMarkerSpriteWhenHUDReady());
		}

		[IteratorStateMachine(typeof(<LoadMarkerSpriteWhenHUDReady>d__6))]
		private IEnumerator LoadMarkerSpriteWhenHUDReady()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadMarkerSpriteWhenHUDReady>d__6(0)
			{
				<>4__this = this
			};
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = ToggleHotkey.Value;
			if (!((KeyboardShortcut)(ref value)).IsDown())
			{
				return;
			}
			IconsEnabled = !IconsEnabled;
			foreach (KeyValuePair<int, BuilderIcon> activeBuilder in BuilderTracker.ActiveBuilders)
			{
				activeBuilder.Value.Refresh();
			}
		}
	}
	public static class BuilderTracker
	{
		public static Dictionary<int, BuilderIcon> ActiveBuilders = new Dictionary<int, BuilderIcon>();

		public static void RegisterBuilder(Villager villager)
		{
			int instanceID = ((Object)villager).GetInstanceID();
			if (!ActiveBuilders.ContainsKey(instanceID))
			{
				BuilderIcon value = new BuilderIcon(villager);
				ActiveBuilders.Add(instanceID, value);
			}
		}

		public static void UnregisterBuilder(Villager villager)
		{
			int instanceID = ((Object)villager).GetInstanceID();
			if (ActiveBuilders.TryGetValue(instanceID, out var value))
			{
				value.Destroy();
				ActiveBuilders.Remove(instanceID);
			}
		}
	}
	[HarmonyPatch(typeof(Villager), "Restore")]
	public static class VillagerRestorePatch
	{
		private static void Postfix(Villager __instance)
		{
			if (((Actor)__instance).Profession == "Builder")
			{
				BuilderTracker.RegisterBuilder(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Villager), "ChangeProfession")]
	public static class ChangeProfessionPatch
	{
		private static void Prefix(Villager __instance, string profession)
		{
			string profession2 = ((Actor)__instance).Profession;
			if (profession2 == "Builder" && profession != "Builder")
			{
				BuilderTracker.UnregisterBuilder(__instance);
			}
			if (profession == "Builder")
			{
				BuilderTracker.RegisterBuilder(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Villager), "OnDisable")]
	public static class VillagerDisablePatch
	{
		private static void Prefix(Villager __instance)
		{
			BuilderTracker.UnregisterBuilder(__instance);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BuilderIcon";

		public const string PLUGIN_NAME = "BuilderIcon";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}