Decompiled source of PaintTheDoor v1.0.5

plugins/PaintTheSecDoor.dll

Decompiled 9 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using System.Text.Json.Serialization;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GTFO.API;
using GTFO.API.JSON;
using GTFO.API.Utilities;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using MTFO.API;
using Microsoft.CodeAnalysis;
using PaintTheSecDoor.API;
using PaintTheSecDoor.Configs;
using PaintTheSecDoor.Configs.Datas;
using PaintTheSecDoor.Utils;
using PaintTheSecDoor.Utils.InteropHelpers;
using TexturePainterAPI.PaintableTextures;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PaintTheSecDoor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+git467db48-dirty-master")]
[assembly: AssemblyProduct("PaintTheSecDoor")]
[assembly: AssemblyTitle("PaintTheSecDoor")]
[assembly: TargetPlatform("Windows7.0")]
[assembly: SupportedOSPlatform("Windows7.0")]
[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 PaintTheSecDoor
{
	internal static class Assets
	{
		public static Texture2D BaseTex_4x4;

		public static Texture2D MaskTex_4x4;

		public static Texture2D BaseTex_8x4;

		public static Texture2D MaskTex_8x4;

		public static Texture2D BaseTex_Apex_4x4;

		public static Texture2D MaskTex_Apex_4x4;

		public static Texture2D BaseTex_Apex_8x4;

		public static Texture2D MaskTex_Apex_8x4;

		public static Texture2D BaseTex_Bulk_4x4;

		public static Texture2D MaskTex_Bulk_4x4;

		public static Texture2D BaseTex_Bulk_8x4;

		public static Texture2D MaskTex_Bulk_8x4;

		public static void LoadAll()
		{
			BaseTex_4x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/4x4_base.png");
			MaskTex_4x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/4x4_mask.png");
			BaseTex_8x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/8x4_base.png");
			MaskTex_8x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/8x4_mask.png");
			BaseTex_Apex_4x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/apex_4x4_base.png");
			MaskTex_Apex_4x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/apex_4x4_mask.png");
			BaseTex_Apex_8x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/apex_8x4_base.png");
			MaskTex_Apex_8x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/apex_8x4_mask.png");
			BaseTex_Bulk_4x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/bulk_4x4_base.png");
			MaskTex_Bulk_4x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/bulk_4x4_mask.png");
			BaseTex_Bulk_8x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/bulk_8x4_base.png");
			MaskTex_Bulk_8x4 = AssetAPI.GetLoadedAsset<Texture2D>("Assets/Modding/SecDoorPainting/bulk_8x4_mask.png");
		}
	}
	[BepInPlugin("PaintTheSecDoor", "PaintTheSecDoor", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class EntryPoint : BasePlugin
	{
		private Harmony _Harmony;

		public override void Load()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_Harmony = new Harmony("PaintTheSecDoor.Harmony");
			_Harmony.PatchAll();
			AssetAPI.OnStartupAssetsLoaded += AssetAPI_OnStartupAssetsLoaded;
		}

		private void AssetAPI_OnStartupAssetsLoaded()
		{
			Assets.LoadAll();
			StyleManager.Init();
		}

		public override bool Unload()
		{
			_Harmony.UnpatchSelf();
			return ((BasePlugin)this).Unload();
		}
	}
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			_Logger = new ManualLogSource("PaintTheSecDoor");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}

		[Conditional("DEBUG")]
		public static void DebugOnly(object data)
		{
		}
	}
	[GeneratedCode("VersionInfoGenerator", "2.1.3+git35c0c2a-master")]
	[CompilerGenerated]
	internal static class VersionInfo
	{
		public const string RootNamespace = "PaintTheSecDoor";

		public const string Version = "1.0.0";

		public const string VersionPrerelease = null;

		public const string VersionMetadata = "git467db48-dirty-master";

		public const string SemVer = "1.0.0+git467db48-dirty-master";

		public const string GitRevShort = "467db48-dirty";

		public const string GitRevLong = "467db48b98181f37904a04a0413d4890136f379b-dirty";

		public const string GitBranch = "master";

		public const string GitTag = null;

		public const int GitCommitsSinceTag = 0;

		public const bool GitIsDirty = true;
	}
}
namespace PaintTheSecDoor.Utils
{
	internal class UnityColorHexConverter : JsonConverter<Color>
	{
		public override Color Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return ColorExt.Hex(reader.GetString());
		}

		public override void Write(Utf8JsonWriter writer, Color value, JsonSerializerOptions options)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			writer.WriteStringValue(ColorExt.ToHex(value));
		}
	}
}
namespace PaintTheSecDoor.Utils.InteropHelpers
{
	internal static class MTFOPathInfo
	{
		public static bool HasMTFO => ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("com.dak.MTFO");

		public static bool HasCustomPath => MTFOPathAPI.HasCustomPath;

		public static string CustomPath => MTFOPathAPI.CustomPath;
	}
}
namespace PaintTheSecDoor.Patch
{
	[HarmonyPatch(typeof(LG_SecurityDoor), "Setup")]
	internal class Patch_SecurityDoor
	{
		private static void Postfix(LG_SecurityDoor __instance)
		{
			StyleManager.TryApplyToDoor(__instance);
		}
	}
}
namespace PaintTheSecDoor.Configs
{
	internal static class StyleManager
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static LiveEditEventHandler <0>__Listener_FileChanged;
		}

		private static readonly Dictionary<string, LayoutDTO> _LayoutLookup = new Dictionary<string, LayoutDTO>();

		private static readonly Dictionary<string, StyleDTO> _StyleLookup = new Dictionary<string, StyleDTO>();

		private static StyleDTO _GlobalStyle;

		private static string _ConfigPath;

		public static void Init()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			if (!MTFOPathInfo.HasMTFO || !MTFOPathInfo.HasCustomPath)
			{
				return;
			}
			_ConfigPath = Path.Combine(MTFOPathInfo.CustomPath, "SecDoorStyles.json");
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(12, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Json Path: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(_ConfigPath);
			}
			Logger.Info(val);
			if (File.Exists(_ConfigPath))
			{
				LiveEditListener obj = LiveEdit.CreateListener(MTFOPathInfo.CustomPath, "SecDoorStyles.json", false);
				object obj2 = <>O.<0>__Listener_FileChanged;
				if (obj2 == null)
				{
					LiveEditEventHandler val2 = Listener_FileChanged;
					<>O.<0>__Listener_FileChanged = val2;
					obj2 = (object)val2;
				}
				obj.FileChanged += (LiveEditEventHandler)obj2;
				Load(File.ReadAllText(_ConfigPath));
				Logger.Info(" Loaded! ");
			}
		}

		private static void Listener_FileChanged(LiveEditEventArgs e)
		{
			LiveEdit.TryReadFileContent(_ConfigPath, (Action<string>)delegate(string json)
			{
				Load(json);
				Logger.Info(" Reloaded! ");
				LG_Floor currentFloor = Builder.CurrentFloor;
				if ((Object)(object)currentFloor != (Object)null)
				{
					foreach (LG_SecurityDoor componentsInChild in ((Component)currentFloor).GetComponentsInChildren<LG_SecurityDoor>(true))
					{
						TryApplyToDoor(componentsInChild);
					}
				}
			});
		}

		public static void Load(string json)
		{
			ConfigDTO configDTO = JsonSerializer.Deserialize<ConfigDTO>(json, (JsonSerializerOptions)null);
			Clear();
			bool flag = !string.IsNullOrEmpty(configDTO.GlobalStyle);
			StyleDTO[] styles = configDTO.Styles;
			foreach (StyleDTO styleDTO in styles)
			{
				_StyleLookup.Add(styleDTO.StyleName, styleDTO);
				if (flag && styleDTO.StyleName.Equals(configDTO.GlobalStyle))
				{
					_GlobalStyle = styleDTO;
				}
				styleDTO.AllocateTextures();
			}
			LayoutDTO[] layouts = configDTO.Layouts;
			foreach (LayoutDTO layoutDTO in layouts)
			{
				_LayoutLookup.Add(layoutDTO.LayoutBlockName, layoutDTO);
			}
		}

		public static void Clear()
		{
			foreach (StyleDTO value in _StyleLookup.Values)
			{
				value.DeallocateTextures();
			}
			_StyleLookup.Clear();
			_LayoutLookup.Clear();
		}

		public static bool TryApplyToDoor(LG_SecurityDoor secDoor)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetStyle(secDoor, out var style))
			{
				return false;
			}
			LG_GateType type = secDoor.Gate.Type;
			switch (DoorType.Get(secDoor))
			{
			case SecDoorTypes.Security_Small:
			case SecDoorTypes.Security_Medium:
				if (!style.Security.Enabled)
				{
					return false;
				}
				style.Security.Apply(((Component)secDoor).transform, type);
				return true;
			case SecDoorTypes.InternalBulkhead_Small:
			case SecDoorTypes.InternalBulkhead_Medium:
				if (!style.InternalBulkhead.Enabled)
				{
					return false;
				}
				style.InternalBulkhead.Apply(((Component)secDoor).transform, type);
				return true;
			case SecDoorTypes.Bulkhead_Small:
			case SecDoorTypes.Bulkhead_Medium:
				if (!style.Bulkhead.Enabled)
				{
					return false;
				}
				style.Bulkhead.Apply(((Component)secDoor).transform, type);
				return true;
			case SecDoorTypes.Apex_Small:
			case SecDoorTypes.Apex_Medium:
				if (!style.Apex.Enabled)
				{
					return false;
				}
				style.Apex.Apply(((Component)secDoor).transform, type);
				return true;
			default:
				return false;
			}
		}

		public static bool TryGetStyle(LG_SecurityDoor secDoor, out StyleDTO style)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (RundownManager.ActiveExpedition != null)
			{
				string layoutName = GetLayoutName(secDoor.Gate.DimensionIndex, secDoor.LinksToLayerType);
				if (!string.IsNullOrEmpty(layoutName) && _LayoutLookup.TryGetValue(layoutName, out var value) && value.TryGetDoorInfo(((LG_ZoneExpander)secDoor.Gate).m_linksTo.m_zone.LocalIndex, out var info) && _StyleLookup.TryGetValue(info.StyleName, out style))
				{
					return true;
				}
			}
			style = _GlobalStyle;
			return style != null;
		}

		public static string GetLayoutName(eDimensionIndex dimensionIndex, LG_LayerType linkedLayer)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected I4, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			ExpeditionInTierData activeExpedition = RundownManager.ActiveExpedition;
			if (activeExpedition == null)
			{
				return string.Empty;
			}
			if ((int)dimensionIndex == 0)
			{
				return (int)linkedLayer switch
				{
					0 => ((GameDataBlockBase<LevelLayoutDataBlock>)(object)GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(activeExpedition.LevelLayoutData))?.name ?? string.Empty, 
					1 => ((GameDataBlockBase<LevelLayoutDataBlock>)(object)GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(activeExpedition.SecondaryLayout))?.name ?? string.Empty, 
					2 => ((GameDataBlockBase<LevelLayoutDataBlock>)(object)GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(activeExpedition.ThirdLayout))?.name ?? string.Empty, 
					_ => string.Empty, 
				};
			}
			Enumerator<DimensionInExpeditionData> enumerator = activeExpedition.DimensionDatas.GetEnumerator();
			while (enumerator.MoveNext())
			{
				DimensionInExpeditionData current = enumerator.Current;
				if (current.DimensionIndex == dimensionIndex)
				{
					return ((GameDataBlockBase<LevelLayoutDataBlock>)(object)GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(current.DimensionData))?.name ?? string.Empty;
				}
			}
			return string.Empty;
		}
	}
}
namespace PaintTheSecDoor.Configs.Datas
{
	internal class ConfigDTO
	{
		public StyleDTO[] Styles { get; set; } = Array.Empty<StyleDTO>();


		public string GlobalStyle { get; set; } = string.Empty;


		public LayoutDTO[] Layouts { get; set; } = Array.Empty<LayoutDTO>();

	}
	internal sealed class LayoutDTO
	{
		public string LayoutBlockName { get; set; }

		public DoorInfoDTO[] SecDoors { get; set; } = Array.Empty<DoorInfoDTO>();


		public bool TryGetDoorInfo(eLocalZoneIndex localIndex, out DoorInfoDTO info)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			info = SecDoors.FirstOrDefault((DoorInfoDTO x) => x.LocalIndex == localIndex);
			return info != null;
		}
	}
	internal sealed class DoorInfoDTO
	{
		public eLocalZoneIndex LocalIndex { get; set; }

		public string StyleName { get; set; }
	}
	internal sealed class StyleDTO
	{
		public string StyleName { get; set; }

		public SecurityDoorDTO Security { get; set; } = new SecurityDoorDTO(ColorExt.Hex("#4a6c94"), ColorExt.Hex("#ce5142"));


		public ApexDoorDTO Apex { get; set; } = new ApexDoorDTO();


		public BulkheadDoorDTO Bulkhead { get; set; } = new BulkheadDoorDTO();


		public SecurityDoorDTO InternalBulkhead { get; set; } = new SecurityDoorDTO(ColorExt.Hex("#919091"), Color.white);


		public void AllocateTextures()
		{
			Security?.AllocateTexture(isBulkhead: false);
			Apex?.AllocateTexture();
			Bulkhead?.AllocateTexture();
			InternalBulkhead?.AllocateTexture(isBulkhead: true);
		}

		public void DeallocateTextures()
		{
			Security?.DeallocateTexture();
			Apex?.DeallocateTexture();
			Bulkhead?.DeallocateTexture();
			InternalBulkhead?.DeallocateTexture();
		}
	}
	internal sealed class SecurityDoorDTO
	{
		[JsonIgnore]
		public SecurityDoorTexture Texture_4x4;

		[JsonIgnore]
		public SecurityDoorTexture Texture_8x4;

		public bool Enabled { get; set; } = true;


		[JsonConverter(typeof(UnityColorHexConverter))]
		public Color Main { get; set; }

		[JsonConverter(typeof(UnityColorHexConverter))]
		public Color Strip { get; set; }

		public SecurityDoorDTO(Color main, Color strip)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			Main = main;
			Strip = strip;
		}

		public void AllocateTexture(bool isBulkhead)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			DeallocateTexture();
			Texture_4x4 = new SecurityDoorTexture((LG_GateType)0, isBulkhead);
			Texture_4x4.SetColor(Main, Strip);
			Texture_8x4 = new SecurityDoorTexture((LG_GateType)1, isBulkhead);
			Texture_8x4.SetColor(Main, Strip);
		}

		public void DeallocateTexture()
		{
			Texture_4x4?.DestroyTexture();
			Texture_8x4?.DestroyTexture();
			Texture_4x4 = null;
			Texture_8x4 = null;
		}

		public void Apply(Transform rootTransform, LG_GateType gateType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if ((int)gateType == 0)
			{
				Texture_4x4.ReplaceMaterialsInChild(rootTransform);
			}
			else if ((int)gateType == 1)
			{
				Texture_8x4.ReplaceMaterialsInChild(rootTransform);
			}
		}
	}
	internal sealed class BulkheadDoorDTO
	{
		[JsonIgnore]
		public BulkheadDoorTexture Texture_4x4;

		[JsonIgnore]
		public BulkheadDoorTexture Texture_8x4;

		public bool Enabled { get; set; } = true;


		[JsonConverter(typeof(UnityColorHexConverter))]
		public Color Main { get; set; } = ColorExt.Hex("#705736");


		[JsonConverter(typeof(UnityColorHexConverter))]
		public Color Strip1 { get; set; } = Color.white;


		[JsonConverter(typeof(UnityColorHexConverter))]
		public Color Strip2 { get; set; } = Color.black;


		public void AllocateTexture()
		{
			//IL_0019: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			DeallocateTexture();
			Texture_4x4 = new BulkheadDoorTexture((LG_GateType)0);
			Texture_4x4.SetColor(Main, Strip1, Strip2);
			Texture_8x4 = new BulkheadDoorTexture((LG_GateType)1);
			Texture_8x4.SetColor(Main, Strip1, Strip2);
		}

		public void DeallocateTexture()
		{
			Texture_4x4?.DestroyTexture();
			Texture_8x4?.DestroyTexture();
			Texture_4x4 = null;
			Texture_8x4 = null;
		}

		public void Apply(Transform rootTransform, LG_GateType gateType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if ((int)gateType == 0)
			{
				Texture_4x4.ReplaceMaterialsInChild(rootTransform);
			}
			else if ((int)gateType == 1)
			{
				Texture_8x4.ReplaceMaterialsInChild(rootTransform);
			}
		}
	}
	internal sealed class ApexDoorDTO
	{
		[JsonIgnore]
		public ApexDoorTexture Texture_4x4;

		[JsonIgnore]
		public ApexDoorTexture Texture_8x4;

		public bool Enabled { get; set; } = true;


		[JsonConverter(typeof(UnityColorHexConverter))]
		public Color Main { get; set; } = ColorExt.Hex("#703d0b");


		[JsonConverter(typeof(UnityColorHexConverter))]
		public Color Strip { get; set; } = Color.black;


		[JsonConverter(typeof(UnityColorHexConverter))]
		public Color Emission { get; set; } = ColorExt.Hex("#fe310d");


		public float EmissionIntensity { get; set; } = 1.25f;


		public void AllocateTexture()
		{
			//IL_0019: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			DeallocateTexture();
			Texture_4x4 = new ApexDoorTexture((LG_GateType)0);
			Texture_4x4.SetColor(Main, Strip);
			Texture_4x4.SetLightEmission(Emission, EmissionIntensity);
			Texture_8x4 = new ApexDoorTexture((LG_GateType)1);
			Texture_8x4.SetColor(Main, Strip);
			Texture_8x4.SetLightEmission(Emission, EmissionIntensity);
		}

		public void DeallocateTexture()
		{
			Texture_4x4?.DestroyTexture();
			Texture_8x4?.DestroyTexture();
			Texture_4x4 = null;
			Texture_8x4 = null;
		}

		public void Apply(Transform rootTransform, LG_GateType gateType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if ((int)gateType == 0)
			{
				Texture_4x4.ReplaceMaterialsInChild(rootTransform);
			}
			else if ((int)gateType == 1)
			{
				Texture_8x4.ReplaceMaterialsInChild(rootTransform);
			}
		}
	}
}
namespace PaintTheSecDoor.API
{
	public sealed class ApexDoorTexture : IMaterialReplacer
	{
		private PaintableChannelMaskedTexture _Texture;

		private readonly string _ReplaceMaterialName;

		private Material _BakedMat;

		private Material _BakedLightMat;

		private Color _EmissionColor = new Color(1.781479f, 0.3357761f, 0.083944f);

		public ApexDoorTexture(LG_GateType gateType)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val;
			Texture2D maskTexture;
			if ((int)gateType != 0)
			{
				if ((int)gateType != 1)
				{
					throw new NotImplementedException($"GateType: {gateType} is not supported!");
				}
				val = Assets.BaseTex_Apex_8x4;
				maskTexture = Assets.MaskTex_Apex_8x4;
				_ReplaceMaterialName = "apexDoor_8x4";
			}
			else
			{
				val = Assets.BaseTex_Apex_4x4;
				maskTexture = Assets.MaskTex_Apex_4x4;
				_ReplaceMaterialName = "apexDoor_4x4";
			}
			_Texture = new PaintableChannelMaskedTexture(val);
			_Texture.SetMaskTexture(maskTexture);
		}

		public void SetColor(Color main, Color strip)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			PaintableChannelMaskedTexture texture = _Texture;
			if (texture != null)
			{
				texture.SetTintColor(main, strip);
			}
		}

		public void SetLightEmission(Color color, float intensity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			Color emissionColor = color * intensity;
			_EmissionColor = emissionColor;
			if ((Object)(object)_BakedLightMat != (Object)null)
			{
				_BakedLightMat.SetColor("_EmissionColor", _EmissionColor);
			}
		}

		public void ReplaceMaterialsInChild(Transform target)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer[] array = Il2CppArrayBase<MeshRenderer>.op_Implicit(((Component)target).GetComponentsInChildren<MeshRenderer>());
			foreach (MeshRenderer val in array)
			{
				if ((Object)(object)((Renderer)val).sharedMaterial == (Object)null)
				{
					continue;
				}
				string name = ((Object)((Renderer)val).sharedMaterial).name;
				if (string.IsNullOrEmpty(name))
				{
					continue;
				}
				if (name.Equals("ApexLights"))
				{
					if ((Object)(object)_BakedLightMat == (Object)null)
					{
						_BakedLightMat = new Material(((Renderer)val).sharedMaterial);
						_BakedLightMat.SetColor("_EmissionColor", _EmissionColor);
						((Object)_BakedLightMat).name = "ApexLights";
					}
					((Renderer)val).sharedMaterial = _BakedLightMat;
				}
				if (name.Equals(_ReplaceMaterialName))
				{
					if ((Object)(object)_BakedMat == (Object)null)
					{
						_BakedMat = new Material(((Renderer)val).sharedMaterial);
						_BakedMat.SetTexture("_MainTex", ((PaintableTexture)_Texture).CurrentTexture);
						_BakedMat.SetVector("_Color", Vector4.one);
						((Object)_BakedMat).name = _ReplaceMaterialName;
					}
					((Renderer)val).sharedMaterial = _BakedMat;
				}
			}
		}

		public void DestroyTexture()
		{
			PaintableChannelMaskedTexture texture = _Texture;
			if (texture != null)
			{
				((PaintableTexture)texture).Destroy();
			}
			_Texture = null;
		}
	}
	public sealed class BulkheadDoorTexture : IMaterialReplacer
	{
		private PaintableChannelMaskedTexture _Texture;

		private readonly string _ReplaceMaterialName;

		private Material _BakedMat;

		public BulkheadDoorTexture(LG_GateType gateType)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val;
			Texture2D maskTexture;
			if ((int)gateType != 0)
			{
				if ((int)gateType != 1)
				{
					throw new NotImplementedException($"GateType: {gateType} is not supported!");
				}
				val = Assets.BaseTex_Bulk_8x4;
				maskTexture = Assets.MaskTex_Bulk_8x4;
				_ReplaceMaterialName = "BulkheadDoor_8x4";
			}
			else
			{
				val = Assets.BaseTex_Bulk_4x4;
				maskTexture = Assets.MaskTex_Bulk_4x4;
				_ReplaceMaterialName = "BulkheadDoor";
			}
			_Texture = new PaintableChannelMaskedTexture(val);
			_Texture.SetMaskTexture(maskTexture);
		}

		public void SetColor(Color main, Color strip1, Color strip2)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			PaintableChannelMaskedTexture texture = _Texture;
			if (texture != null)
			{
				texture.SetTintColor(main, strip1, strip2);
			}
		}

		public void ReplaceMaterialsInChild(Transform target)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer[] array = Il2CppArrayBase<MeshRenderer>.op_Implicit(((Component)target).GetComponentsInChildren<MeshRenderer>());
			foreach (MeshRenderer val in array)
			{
				if ((Object)(object)((Renderer)val).sharedMaterial == (Object)null)
				{
					continue;
				}
				string name = ((Object)((Renderer)val).sharedMaterial).name;
				if (!string.IsNullOrEmpty(name) && name.Equals(_ReplaceMaterialName))
				{
					if ((Object)(object)_BakedMat == (Object)null)
					{
						_BakedMat = new Material(((Renderer)val).sharedMaterial);
						_BakedMat.SetTexture("_MainTex", ((PaintableTexture)_Texture).CurrentTexture);
						_BakedMat.SetVector("_Color", Vector4.one);
						((Object)_BakedMat).name = _ReplaceMaterialName;
					}
					((Renderer)val).sharedMaterial = _BakedMat;
				}
			}
		}

		public void DestroyTexture()
		{
			PaintableChannelMaskedTexture texture = _Texture;
			if (texture != null)
			{
				((PaintableTexture)texture).Destroy();
			}
			_Texture = null;
		}
	}
	public static class DoorType
	{
		public static SecDoorTypes Get(LG_SecurityDoor secDoor)
		{
			//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)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected I4, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			LG_GateType type = secDoor.Gate.Type;
			if ((int)type != 0 && (int)type != 1)
			{
				throw new NotImplementedException($"GateType: {type} is not supported");
			}
			bool flag = (int)type == 0;
			eSecurityDoorType securityDoorType = secDoor.m_securityDoorType;
			switch ((int)securityDoorType)
			{
			case 0:
				if (flag)
				{
					return SecDoorTypes.Security_Small;
				}
				return SecDoorTypes.Security_Medium;
			case 1:
				if (flag)
				{
					return SecDoorTypes.Apex_Small;
				}
				return SecDoorTypes.Apex_Medium;
			case 2:
				if (((Il2CppObjectBase)secDoor.m_anim).Cast<LG_SecurityDoor_Anim>().m_isBulkheadDoor)
				{
					if (flag)
					{
						return SecDoorTypes.Bulkhead_Small;
					}
					return SecDoorTypes.Bulkhead_Medium;
				}
				if (flag)
				{
					return SecDoorTypes.InternalBulkhead_Small;
				}
				return SecDoorTypes.InternalBulkhead_Medium;
			default:
				throw new NotImplementedException($"SecurityDoorType: {secDoor.m_securityDoorType} is not supported");
			}
		}

		public static WeakDoorTypes Get(LG_WeakDoor weakDoor)
		{
			//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)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			LG_GateType type = weakDoor.Gate.Type;
			if ((int)type != 0)
			{
				if ((int)type == 1)
				{
					return WeakDoorTypes.Weak_Medium;
				}
				throw new NotImplementedException($"GateType: {weakDoor.Gate.Type} is not supported");
			}
			return WeakDoorTypes.Weak_Small;
		}
	}
	public enum WeakDoorTypes
	{
		Weak_Small,
		Weak_Medium
	}
	public enum SecDoorTypes
	{
		Apex_Small,
		Apex_Medium,
		Security_Small,
		Security_Medium,
		Bulkhead_Small,
		Bulkhead_Medium,
		InternalBulkhead_Small,
		InternalBulkhead_Medium
	}
	public interface IMaterialReplacer
	{
		void ReplaceMaterialsInChild(Transform target);
	}
	public sealed class SecurityDoorTexture : IMaterialReplacer
	{
		private PaintableChannelMaskedTexture _Texture;

		private readonly string _ReplaceMaterialName;

		private Material _BakedMat;

		public SecurityDoorTexture(LG_GateType gateType, bool isMainBulkhead)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			Texture2D val;
			Texture2D maskTexture;
			if ((int)gateType != 0)
			{
				if ((int)gateType != 1)
				{
					throw new NotImplementedException($"GateType: {gateType} is not supported!");
				}
				val = Assets.BaseTex_8x4;
				maskTexture = Assets.MaskTex_8x4;
				_ReplaceMaterialName = ((!isMainBulkhead) ? "securityDoor_8x4_tech" : "securityDoor_8x4_tech_bulkhead");
			}
			else
			{
				val = Assets.BaseTex_4x4;
				maskTexture = Assets.MaskTex_4x4;
				_ReplaceMaterialName = ((!isMainBulkhead) ? "securityDoor_4x4_tech" : "securityDoor_4x4_bulkhead");
			}
			_Texture = new PaintableChannelMaskedTexture(val);
			_Texture.SetMaskTexture(maskTexture);
		}

		public void SetColor(Color mainColor, Color stripColor)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			PaintableChannelMaskedTexture texture = _Texture;
			if (texture != null)
			{
				texture.SetTintColor(mainColor, stripColor);
			}
		}

		public void ReplaceMaterialsInChild(Transform target)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer[] array = Il2CppArrayBase<MeshRenderer>.op_Implicit(((Component)target).GetComponentsInChildren<MeshRenderer>());
			foreach (MeshRenderer val in array)
			{
				if ((Object)(object)((Renderer)val).sharedMaterial == (Object)null)
				{
					continue;
				}
				string name = ((Object)((Renderer)val).sharedMaterial).name;
				if (!string.IsNullOrEmpty(name) && name.Equals(_ReplaceMaterialName))
				{
					if ((Object)(object)_BakedMat == (Object)null)
					{
						_BakedMat = new Material(((Renderer)val).sharedMaterial);
						_BakedMat.SetTexture("_MainTex", ((PaintableTexture)_Texture).CurrentTexture);
						_BakedMat.SetVector("_Color", Vector4.one);
						((Object)_BakedMat).name = _ReplaceMaterialName;
					}
					((Renderer)val).sharedMaterial = _BakedMat;
				}
			}
		}

		public void DestroyTexture()
		{
			PaintableChannelMaskedTexture texture = _Texture;
			if (texture != null)
			{
				((PaintableTexture)texture).Destroy();
			}
			_Texture = null;
		}
	}
}