Decompiled source of Ishihara Company v1.1.0

BepInEx/plugins/IshiharaCompany.dll

Decompiled 10 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using IshiharaCompany.Patches;
using TMPro;
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: AssemblyTitle("ColourBlindMode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColourBlindMode")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2bae5d2d-f82e-470b-b6c6-d833ce9c0994")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace IshiharaCompany
{
	[BepInPlugin("Starman_x64.IshiharaCompany", "Ishihara Company", "1.1.0")]
	public class IshiharaCompanyModBase : BaseUnityPlugin
	{
		public const string modGUID = "Starman_x64.IshiharaCompany";

		public const string modName = "Ishihara Company";

		public const string modVersion = "1.1.0";

		private readonly Harmony harmony = new Harmony("Starman_x64.IshiharaCompany");

		private static IshiharaCompanyModBase Instance;

		public static ManualLogSource mls;

		public static AssetBundle assetBundle;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Starman_x64.IshiharaCompany");
			assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "IshiharaCompany/ishiharacompany"));
			mls.LogInfo((object)"Plugin Ishihara Company is loaded!");
			harmony.PatchAll(typeof(IshiharaCompanyModBase));
			harmony.PatchAll(typeof(TerminalAccessibleObjectPatch));
			harmony.PatchAll(typeof(EnemyAIPatch));
		}
	}
}
namespace IshiharaCompany.Patches
{
	internal class EnemyAIPatch
	{
		[HarmonyPatch(typeof(BaboonBirdAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectFBaboonBirdSpawn(BaboonBirdAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(DocileLocustBeesAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectDocileLocustBeesSpawn(DocileLocustBeesAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(DoublewingAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectDoublewingSpawn(DoublewingAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(JesterAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectJesterSpawn(JesterAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(LassoManAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectLassoManSpawn(LassoManAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(NutcrackerEnemyAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectNutcrackerEnemySpawn(NutcrackerEnemyAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(PufferAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectPufferSpawn(PufferAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(SandSpiderAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectSandSpiderSpawn(SandSpiderAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(SandWormAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectSandWormSpawn(SandWormAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(BlobAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectBlobSpawn(BlobAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(CentipedeAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectCentipedeSpawn(CentipedeAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(CrawlerAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectCrawlerSpawn(CrawlerAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(RedLocustBees), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectRedLocustBeesSpawn(RedLocustBees __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(DressGirlAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectDressGirlSpawn(DressGirlAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(FlowermanAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectFlowermanSpawn(FlowermanAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(ForestGiantAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectForestGiantSpawn(ForestGiantAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(HoarderBugAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectHoarderBugSpawn(HoarderBugAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(MouthDogAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectMouthDogSpawn(MouthDogAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(SpringManAI), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectSpringManSpawn(SpringManAI __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(TestEnemy), "__initializeVariables")]
		[HarmonyPostfix]
		public static void DetectTestEnemySpawn(TestEnemy __instance)
		{
			DetectSpawn((EnemyAI)(object)__instance);
		}

		public static void DetectSpawn(EnemyAI __instance)
		{
			ManualLogSource mls = IshiharaCompanyModBase.mls;
			mls.LogInfo((object)$"{((Object)__instance).name} Summoned");
			Transform transform = ((Component)__instance).transform;
			if ((Object)(object)transform == (Object)null)
			{
				mls.LogInfo((object)"Transform Not Found");
			}
			else
			{
				mls.LogInfo((object)"Transform Found");
			}
			GameObject val = null;
			Regex regex = new Regex("MapDot.*");
			Transform[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Transform>();
			Transform[] array = componentsInChildren;
			foreach (Transform val2 in array)
			{
				MatchCollection matchCollection = regex.Matches(((Object)val2).name);
				mls.LogInfo((object)(((Object)val2).name + ": " + matchCollection.Count));
				if (matchCollection.Count > 0)
				{
					val = ((Component)val2).gameObject;
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				mls.LogWarning((object)$"Object \"{((Object)transform).name}\" has no map dot object!");
				return;
			}
			mls.LogMessage((object)$"Found map dot object \"{((Object)val).name}\" in \"{((Object)transform).name}\".");
			((Renderer)val.GetComponent<MeshRenderer>()).material = IshiharaCompanyModBase.assetBundle.LoadAsset<Material>("MapDotPink");
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	internal class MenuManagerPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AddColourBlindOption(MenuManager __instance)
		{
			ManualLogSource mls = IshiharaCompanyModBase.mls;
			Transform parent = ((Component)__instance).transform.parent;
			Transform[] componentsInChildren = ((Component)parent).GetComponentsInChildren<Transform>(true);
			Transform val = null;
			GameObject val2 = null;
			mls.LogInfo((object)((Object)parent).name);
			Transform[] array = componentsInChildren;
			foreach (Transform val3 in array)
			{
				mls.LogInfo((object)((Object)val3).name);
				if (((Object)val3).name == "ControlsOptions")
				{
					val = val3;
				}
				else if (((Object)val3).name == "ArachniphobiaMode")
				{
					val2 = ((Component)val3).gameObject;
				}
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val2))
				{
					break;
				}
			}
			mls.LogInfo((object)$"Targeted objects on \"{((Object)parent).name}\":\n- ControlsOptions: {Object.op_Implicit((Object)(object)val)}\n- AracnaphobiaMode: {Object.op_Implicit((Object)(object)val2)}");
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
			{
				mls.LogWarning((object)"Some objects not found, returning function.");
				return;
			}
			GameObject val4 = Object.Instantiate<GameObject>(val2);
			((Object)val4).name = "ColourBlindMode";
			TextMeshProUGUI componentInChildren = val4.GetComponentInChildren<TextMeshProUGUI>();
			((TMP_Text)componentInChildren).text = "Colour Blind Mode";
			val4.transform.SetParent(val);
			val4.SetActive(true);
		}
	}
	[HarmonyPatch(typeof(Landmine))]
	internal class LandminePatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch(Landmine __instance)
		{
			ManualLogSource mls = IshiharaCompanyModBase.mls;
			Transform transform = ((Component)__instance).transform;
			for (int i = 0; i < ((Component)__instance).transform.childCount; i++)
			{
				mls.LogInfo((object)((Component)__instance).transform.GetChild(i));
			}
			Transform[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Transform>();
			GameObject val = null;
			Transform[] array = componentsInChildren;
			foreach (Transform val2 in array)
			{
				if (((Object)val2).name == "ScanSphere")
				{
					val = ((Component)val2).gameObject;
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				mls.LogWarning((object)$"Could not find ScanSphere in {((Object)transform).name}");
				return;
			}
			mls.LogInfo((object)$"Found {((Object)val).name} in {((Object)transform).name}!");
			((Renderer)val.GetComponent<MeshRenderer>()).material = IshiharaCompanyModBase.assetBundle.LoadAsset<Material>("MapDotPink");
		}
	}
	[HarmonyPatch(typeof(TerminalAccessibleObject))]
	internal class TerminalAccessibleObjectPatch
	{
		[HarmonyPatch("OnPowerSwitch")]
		[HarmonyPostfix]
		public static void OnPowerSwitchFix(ref string ___objectCode, ref bool ___isDoorOpen, ref TextMeshProUGUI ___mapRadarText, ref Image ___mapRadarBox)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource mls = IshiharaCompanyModBase.mls;
			mls.LogInfo((object)"Power Switched, running AdjustDoorClosedColour...");
			if (!___isDoorOpen)
			{
				((Graphic)___mapRadarText).color = Color.magenta;
				((Graphic)___mapRadarBox).color = Color.magenta;
				mls.LogInfo((object)("Changed colour of closed door " + ___objectCode + " to magenta."));
			}
		}

		[HarmonyPatch("SetDoorOpen")]
		[HarmonyPostfix]
		public static void SetDoorOpenFix(ref string ___objectCode, ref bool ___isDoorOpen, ref TextMeshProUGUI ___mapRadarText, ref Image ___mapRadarBox)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource mls = IshiharaCompanyModBase.mls;
			mls.LogInfo((object)"Set Door Open, running AdjustDoorClosedColour...");
			if (!___isDoorOpen)
			{
				((Graphic)___mapRadarText).color = Color.magenta;
				((Graphic)___mapRadarBox).color = Color.magenta;
				mls.LogInfo((object)("Changed colour of closed door " + ___objectCode + " to magenta."));
			}
		}

		[HarmonyPatch("CallFunctionFromTerminal")]
		[HarmonyPostfix]
		public static void CallFunctionFromTerminalFix(ref string ___objectCode, ref bool ___isDoorOpen, ref TextMeshProUGUI ___mapRadarText, ref Image ___mapRadarBox)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource mls = IshiharaCompanyModBase.mls;
			mls.LogInfo((object)"Called Function From Terminal, running AdjustDoorClosedColour...");
			if (!___isDoorOpen)
			{
				((Graphic)___mapRadarText).color = Color.magenta;
				((Graphic)___mapRadarBox).color = Color.magenta;
				mls.LogInfo((object)("Changed colour of closed door " + ___objectCode + " to magenta."));
			}
		}

		[HarmonyPatch("InitializeValues")]
		[HarmonyPostfix]
		public static void InitializeValuesFix(ref string ___objectCode, ref bool ___isDoorOpen, ref TextMeshProUGUI ___mapRadarText, ref Image ___mapRadarBox)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource mls = IshiharaCompanyModBase.mls;
			mls.LogInfo((object)"Initialized values, running AdjustDoorClosedColour...");
			if (!___isDoorOpen)
			{
				((Graphic)___mapRadarText).color = Color.magenta;
				((Graphic)___mapRadarBox).color = Color.magenta;
				mls.LogInfo((object)("Changed colour of closed door " + ___objectCode + " to magenta."));
			}
		}
	}
}