Decompiled source of HanestadCompany v1.0.0

BepInEx/plugins/HanestadCompany/HanestadCompany.dll

Decompiled 4 hours ago
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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: AssemblyTitle("HanestadCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HanestadCompany")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("22b5da28-53da-4491-9244-4326f9716c18")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HanestadCompany;

[BepInPlugin("no.hanestad.hanestadcompany", "Hanestad Company", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private Texture2D logoTexture;

	private Sprite logoSprite;

	private Canvas modifiedCanvas = null;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"=================================");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"HANESTAD COMPANY 1.0.0 LASTET");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"=================================");
		SceneManager.sceneLoaded += OnSceneLoaded;
		((MonoBehaviour)this).StartCoroutine(MenuWatcher());
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Scene lastet: " + ((Scene)(ref scene)).name));
		modifiedCanvas = null;
	}

	private IEnumerator MenuWatcher()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Starter rask Hanestad hovedmeny-overvåkning...");
		while (true)
		{
			yield return (object)new WaitForSeconds(0.1f);
			Canvas menuCanvas = FindActualMainMenu();
			if (!((Object)(object)menuCanvas == (Object)null))
			{
				if ((Object)(object)modifiedCanvas != (Object)(object)menuCanvas)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("HOVEDMENY FUNNET: " + GetFullPath(((Component)menuCanvas).transform)));
					HideOldCompanyLogo(menuCanvas);
					CreateHanestadLogo(menuCanvas);
					CreateVersionText(menuCanvas);
					modifiedCanvas = menuCanvas;
					((BaseUnityPlugin)this).Logger.LogInfo((object)"HANESTAD COMPANY AKTIV PÅ HOVEDMENY.");
				}
				else
				{
					HideOldCompanyLogo(menuCanvas);
					EnsureHanestadLogoOnTop(menuCanvas);
					EnsureVersionTextOnTop(menuCanvas);
				}
			}
		}
	}

	private Canvas FindActualMainMenu()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		Canvas[] array = Resources.FindObjectsOfTypeAll<Canvas>();
		Canvas[] array2 = array;
		foreach (Canvas val in array2)
		{
			if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)null))
			{
				Scene scene = ((Component)val).gameObject.scene;
				if (((Scene)(ref scene)).IsValid() && ((Component)val).gameObject.activeInHierarchy && IsActualMainMenu(val))
				{
					return val;
				}
			}
		}
		return null;
	}

	private bool IsActualMainMenu(Canvas canvas)
	{
		if ((Object)(object)canvas == (Object)null)
		{
			return false;
		}
		Button[] componentsInChildren = ((Component)canvas).GetComponentsInChildren<Button>(true);
		bool flag = false;
		bool flag2 = false;
		bool flag3 = false;
		bool flag4 = false;
		Button[] array = componentsInChildren;
		foreach (Button val in array)
		{
			if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeInHierarchy)
			{
				string text = ((Object)((Component)val).gameObject).name.ToLowerInvariant();
				string text2 = GetFullPath(((Component)val).transform).ToLowerInvariant();
				string text3 = text + " " + text2;
				if (text3.Contains("host"))
				{
					flag = true;
				}
				if (text3.Contains("join"))
				{
					flag2 = true;
				}
				if (text3.Contains("setting") || text3.Contains("option"))
				{
					flag3 = true;
				}
				if (text3.Contains("quit") || text3.Contains("exit"))
				{
					flag4 = true;
				}
			}
		}
		return flag && flag2 && (flag3 || flag4);
	}

	private void HideOldCompanyLogo(Canvas canvas)
	{
		Transform[] componentsInChildren = ((Component)canvas).GetComponentsInChildren<Transform>(true);
		Transform[] array = componentsInChildren;
		foreach (Transform val in array)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			GameObject gameObject = ((Component)val).gameObject;
			if (((Object)gameObject).name == "HanestadCompanyLogo" || ((Object)gameObject).name == "HanestadCompanyVersion")
			{
				continue;
			}
			Image component = gameObject.GetComponent<Image>();
			RawImage component2 = gameObject.GetComponent<RawImage>();
			SpriteRenderer component3 = gameObject.GetComponent<SpriteRenderer>();
			string text = GetFullPath(val).ToLowerInvariant();
			string text2 = ((Object)gameObject).name.ToLowerInvariant();
			bool flag = false;
			if (text.Contains("morecompany") || text.Contains("more company") || text2.Contains("morecompany") || text2.Contains("more company"))
			{
				flag = true;
			}
			if ((Object)(object)component != (Object)null && (Object)(object)component.sprite != (Object)null)
			{
				string text3 = ((Object)component.sprite).name.ToLowerInvariant();
				if (text3.Contains("morecompany") || text3.Contains("more company") || text3.Contains("more_company"))
				{
					flag = true;
				}
				if ((Object)(object)component.sprite.texture != (Object)null)
				{
					string text4 = ((Object)component.sprite.texture).name.ToLowerInvariant();
					if (text4.Contains("morecompany") || text4.Contains("more company") || text4.Contains("more_company"))
					{
						flag = true;
					}
				}
			}
			if ((Object)(object)component2 != (Object)null && (Object)(object)component2.texture != (Object)null)
			{
				string text5 = ((Object)component2.texture).name.ToLowerInvariant();
				if (text5.Contains("morecompany") || text5.Contains("more company") || text5.Contains("more_company"))
				{
					flag = true;
				}
			}
			if ((Object)(object)component3 != (Object)null && (Object)(object)component3.sprite != (Object)null)
			{
				string text6 = ((Object)component3.sprite).name.ToLowerInvariant();
				if (text6.Contains("morecompany") || text6.Contains("more company") || text6.Contains("more_company"))
				{
					flag = true;
				}
				if ((Object)(object)component3.sprite.texture != (Object)null)
				{
					string text7 = ((Object)component3.sprite.texture).name.ToLowerInvariant();
					if (text7.Contains("morecompany") || text7.Contains("more company") || text7.Contains("more_company"))
					{
						flag = true;
					}
				}
			}
			if (flag)
			{
				if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Skjuler MoreCompany Image: " + GetFullPath(val)));
					((Behaviour)component).enabled = false;
				}
				if ((Object)(object)component2 != (Object)null && ((Behaviour)component2).enabled)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Skjuler MoreCompany RawImage: " + GetFullPath(val)));
					((Behaviour)component2).enabled = false;
				}
				if ((Object)(object)component3 != (Object)null && ((Renderer)component3).enabled)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Skjuler MoreCompany SpriteRenderer: " + GetFullPath(val)));
					((Renderer)component3).enabled = false;
				}
			}
		}
	}

	private void CreateHanestadLogo(Canvas targetCanvas)
	{
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Expected O, but got Unknown
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Expected O, but got Unknown
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		Transform[] componentsInChildren = ((Component)targetCanvas).GetComponentsInChildren<Transform>(true);
		Transform[] array = componentsInChildren;
		foreach (Transform val in array)
		{
			if ((Object)(object)val != (Object)null && ((Object)((Component)val).gameObject).name == "HanestadCompanyLogo")
			{
				return;
			}
		}
		string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
		string text = Path.Combine(directoryName, "assets", "hanestadcompany_logo.png");
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Laster Hanestad-logo: " + text));
		if (!File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"FANT IKKE hanestadcompany_logo.png!");
			return;
		}
		byte[] array2 = File.ReadAllBytes(text);
		logoTexture = new Texture2D(2, 2, (TextureFormat)4, false);
		if (!ImageConversion.LoadImage(logoTexture, array2))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Kunne ikke laste Hanestad PNG.");
			return;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("PNG LASTET: " + ((Texture)logoTexture).width + "x" + ((Texture)logoTexture).height));
		((Object)logoTexture).name = "HanestadCompanyLogoTexture";
		logoSprite = Sprite.Create(logoTexture, new Rect(0f, 0f, (float)((Texture)logoTexture).width, (float)((Texture)logoTexture).height), new Vector2(0.5f, 0.5f), 100f);
		((Object)logoSprite).name = "HanestadCompanyLogoSprite";
		GameObject val2 = new GameObject("HanestadCompanyLogo");
		RectTransform val3 = val2.AddComponent<RectTransform>();
		Image val4 = val2.AddComponent<Image>();
		val2.transform.SetParent(((Component)targetCanvas).transform, false);
		val4.sprite = logoSprite;
		((Graphic)val4).color = Color.white;
		val4.preserveAspect = true;
		((Graphic)val4).raycastTarget = false;
		val3.anchorMin = new Vector2(0.5f, 1f);
		val3.anchorMax = new Vector2(0.5f, 1f);
		val3.pivot = new Vector2(0.5f, 1f);
		val3.anchoredPosition = new Vector2(0f, -8f);
		val3.sizeDelta = new Vector2(500f, 150f);
		val2.transform.SetAsLastSibling();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"HANESTAD-LOGO OPPRETTET.");
	}

	private void CreateVersionText(Canvas targetCanvas)
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		Transform[] componentsInChildren = ((Component)targetCanvas).GetComponentsInChildren<Transform>(true);
		Transform[] array = componentsInChildren;
		foreach (Transform val in array)
		{
			if ((Object)(object)val != (Object)null && ((Object)((Component)val).gameObject).name == "HanestadCompanyVersion")
			{
				return;
			}
		}
		GameObject val2 = new GameObject("HanestadCompanyVersion");
		RectTransform val3 = val2.AddComponent<RectTransform>();
		TextMeshProUGUI val4 = val2.AddComponent<TextMeshProUGUI>();
		val2.transform.SetParent(((Component)targetCanvas).transform, false);
		((TMP_Text)val4).text = "HANESTAD COMPANY v1.0.0";
		((TMP_Text)val4).fontSize = 9f;
		((TMP_Text)val4).alignment = (TextAlignmentOptions)1026;
		((Graphic)val4).color = new Color(1f, 0.65f, 0.78f, 0.85f);
		((Graphic)val4).raycastTarget = false;
		val3.anchorMin = new Vector2(0.85f, 0f);
		val3.anchorMax = new Vector2(0.85f, 0f);
		val3.pivot = new Vector2(0.5f, 0f);
		val3.anchoredPosition = new Vector2(0f, 12f);
		val3.sizeDelta = new Vector2(300f, 30f);
		val2.transform.SetAsLastSibling();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"HANESTAD COMPANY VERSJONSTEKST OPPRETTET.");
	}

	private void EnsureHanestadLogoOnTop(Canvas canvas)
	{
		Transform[] componentsInChildren = ((Component)canvas).GetComponentsInChildren<Transform>(true);
		Transform[] array = componentsInChildren;
		foreach (Transform val in array)
		{
			if (!((Object)(object)val == (Object)null) && ((Object)((Component)val).gameObject).name == "HanestadCompanyLogo")
			{
				val.SetAsLastSibling();
				break;
			}
		}
	}

	private void EnsureVersionTextOnTop(Canvas canvas)
	{
		Transform[] componentsInChildren = ((Component)canvas).GetComponentsInChildren<Transform>(true);
		Transform[] array = componentsInChildren;
		foreach (Transform val in array)
		{
			if (!((Object)(object)val == (Object)null) && ((Object)((Component)val).gameObject).name == "HanestadCompanyVersion")
			{
				val.SetAsLastSibling();
				break;
			}
		}
	}

	private string GetFullPath(Transform transform)
	{
		if ((Object)(object)transform == (Object)null)
		{
			return "NULL";
		}
		string text = ((Object)transform).name;
		Transform parent = transform.parent;
		while ((Object)(object)parent != (Object)null)
		{
			text = ((Object)parent).name + "/" + text;
			parent = parent.parent;
		}
		return text;
	}
}