Decompiled source of AdvancedStructureSkins v2.0.0

Mods/AdvancedStructureSkins.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using AdvancedStructureSkins;
using AdvancedStructureSkins.API;
using AdvancedStructureSkins.ShaderFeatures;
using AdvancedStructureSkins.Shared.SDK;
using AdvancedStructureSkins.Shared.SDK.Binary;
using AdvancedStructureSkins.Skins;
using AdvancedStructureSkins.UI;
using AdvancedStructureSkins.Util;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppPhoton.Pun;
using Il2CppRUMBLE.Combat.ShiftStones;
using Il2CppRUMBLE.MoveSystem;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using Il2CppSmartLocalization;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using RumbleModdingAPI;
using RumbleModdingAPI.RMAPI;
using UIFramework;
using UIFramework.Adapters;
using UIFramework.Models;
using UIFramework.UiExtensions;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
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: MelonInfo(typeof(ASS), "Advanced Structure Skins", "2.0.0", "Cxntrxl", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 210, 180, 145)]
[assembly: MelonAuthorColor(255, 5, 210, 240)]
[assembly: MelonAdditionalDependencies(new string[] { "UIFramework" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("AdvancedStructureSkins")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AdvancedStructureSkins")]
[assembly: AssemblyTitle("AdvancedStructureSkins")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
}
namespace AdvancedStructureSkins
{
	public static class ModInfo
	{
		public const string ModName = "Advanced Structure Skins";

		public const string ModVersion = "2.0.0";

		public const string ModAuthor = "Cxntrxl";

		public const string Description = "Allows custom shaders and skins to be applied to structures, and provides mod developers with a simple API for loading their own shaders.";

		public const bool ExperimentalBuild = true;
	}
	public class ASS : MelonMod
	{
		public static ASS Instance;

		public static Random Random = new Random();

		private static AssetBundle _cosmeticBundle;

		private static GameObject _cosmeticPrefab;

		private static Texture2D _hasAssIcon;

		private static bool VerboseLogging => !UIHandler.Initialized || UIHandler.DebugMode.Value;

		public override void OnInitializeMelon()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			((MelonBase)this).OnInitializeMelon();
			if (Instance == null)
			{
				Instance = this;
			}
			ClassInjector.RegisterTypeInIl2Cpp<AdvancedSkin>();
			ClassInjector.RegisterTypeInIl2Cpp<GameObjectDebugger>();
			ClassInjector.RegisterTypeInIl2Cpp<SkinManifest>();
			ClassInjector.RegisterTypeInIl2Cpp<SkinSelector>();
			ClassInjector.RegisterTypeInIl2Cpp<ShaderSelector>();
			ClassInjector.RegisterTypeInIl2Cpp<TextureSelector>();
			AssAPI.Init();
			UIHandler.Init();
			BulkPatcher.ApplyPatches(new Harmony("AdvancedStructureSkins.ASS"));
			LoadCosmeticBundle();
			Actions.onPlayerSpawned += OnPlayerSpawned;
			_hasAssIcon = LoadIcon();
		}

		public override void OnLateInitializeMelon()
		{
			//IL_0036: 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)
			((MelonBase)this).OnLateInitializeMelon();
			SkinHandler.Init();
			InputHandler.Init();
			AddInputs();
			ModDebug.AddInputs();
			Lighting.UseBounceLighting(true);
			Lighting.SetHorizonLightColor((Color?)new Color(0.5f, 0.5f, 0.55f));
			Lighting.SetGroundLightColor((Color?)new Color(0.35f, 0.35f, 0.42f));
			Log("Advanced Structure Skins Initialized!");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			((MelonMod)this).OnSceneWasLoaded(buildIndex, sceneName);
			Random = new Random(sceneName.GetHashCode());
		}

		private void LoadCosmeticBundle()
		{
			_cosmeticBundle = AssetBundles.LoadAssetBundleFromStream((MelonMod)(object)this, "AdvancedStructureSkins.Resources.Cosmetics");
			_cosmeticPrefab = ((IEnumerable<GameObject>)_cosmeticBundle.LoadAllAssets<GameObject>()).FirstOrDefault();
			((Object)_cosmeticBundle).hideFlags = (HideFlags)32;
			if ((Object)(object)_cosmeticPrefab != (Object)null)
			{
				((Object)_cosmeticPrefab).hideFlags = (HideFlags)61;
			}
		}

		private static void OnPlayerSpawned(Player player)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			ApplyCosmetics(player);
			if ((int)player.Controller.ControllerType != 1 && Players.GetLocalPlayer().Data.GeneralData.PlayFabMasterId == "932BFF1427FC3A2D")
			{
				AddHasModCheck(player);
			}
		}

		private static void ApplyCosmetics(Player player)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Invalid comparison between Unknown and I4
			if (!(player.Data.GeneralData.PlayFabMasterId != "932BFF1427FC3A2D"))
			{
				Transform val = ((Component)player.Controller).transform.FindChild("Visuals/Skelington/Bone_Pelvis/Bone_Spine_A/Bone_Chest/Bone_Neck/Bone_Head");
				Object.Instantiate<GameObject>(_cosmeticPrefab, val);
				if ((int)player.Controller.ControllerType != 1)
				{
					CreateAssIcon(player);
				}
			}
		}

		private static void AddHasModCheck(Player player)
		{
			if (Mods.doesOpponentHaveMod("Advanced Structure Skins", "", false))
			{
				CreateAssIcon(player);
			}
		}

		private static void CreateAssIcon(Player player)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			PlayerUIBar remoteUIBar = player.Controller.GetSubsystem<PlayerUI>().remoteUIBar;
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)5);
			val.transform.SetParent(((Component)remoteUIBar).transform);
			val.transform.localPosition = new Vector3(0.4727f, 0f, 0f);
			val.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
			val.transform.localScale = Vector3.one * 0.15f;
			MeshRenderer component = val.GetComponent<MeshRenderer>();
			((Renderer)component).material = new Material(Shader.Find("Universal Render Pipeline/Unlit"))
			{
				mainTexture = (Texture)(object)_hasAssIcon
			};
			((Renderer)component).material.SetFloat("_Surface", 1f);
			((Renderer)component).material.SetOverrideTag("RenderType", "Transparent");
			((Renderer)component).material.SetInt("_SrcBlend", 5);
			((Renderer)component).material.SetInt("_DstBlend", 10);
			((Renderer)component).material.SetInt("_ZWrite", 0);
			((Renderer)component).material.renderQueue = 3000;
			((Renderer)component).material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
		}

		private static Texture2D LoadIcon()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using Stream stream = executingAssembly.GetManifestResourceStream(executingAssembly.GetName().Name + ".Resources.icon.png");
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array));
			((Object)val).hideFlags = (HideFlags)32;
			return val;
		}

		private static void AddInputs()
		{
			InputHandler.GetKeyDown((KeyCode)286, (Action)delegate
			{
				foreach (Structure item in Object.FindObjectsOfType<Structure>())
				{
					SkinHandler.ApplySkinTo(item);
				}
			});
		}

		public static void Log(object msg)
		{
			MelonLogger.Msg(msg);
		}

		public static void Warn(object msg)
		{
			MelonLogger.Warning(msg);
		}

		public static void Error(object msg)
		{
			MelonLogger.Error(msg);
		}

		public static void LogVerbose(object msg)
		{
			if (VerboseLogging)
			{
				Log("[Verbose] " + msg);
			}
		}

		public static void WarnVerbose(object msg)
		{
			if (VerboseLogging)
			{
				Warn("[Verbose] " + msg);
			}
		}

		public static void ErrorVerbose(object msg)
		{
			if (VerboseLogging)
			{
				Error("[Verbose] " + msg);
			}
		}
	}
}
namespace AdvancedStructureSkins.Util
{
	[RegisterTypeInIl2Cpp]
	public class GameObjectDebugger : MonoBehaviour
	{
		private Transform _uiRoot;

		private Canvas _canvas;

		private TextMeshProUGUI _persistentText;

		private TextMeshProUGUI _logText;

		private readonly List<string> _logs = new List<string>();

		private readonly Dictionary<string, Func<string>> _persistentData = new Dictionary<string, Func<string>>();

		private const int MaxLogs = 8;

		private readonly Vector3 _worldOffset = new Vector3(0f, 0f, 0f);

		private readonly StringBuilder _builder = new StringBuilder();

		public GameObjectDebugger(IntPtr ptr)
			: base(ptr)
		{
		}//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)


		private void Awake()
		{
			CreateCanvas();
		}

		private void LateUpdate()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			UpdatePersistentData();
			((Component)_uiRoot).transform.rotation = Quaternion.identity;
			((Component)_uiRoot).transform.position = ((Component)this).transform.position + _worldOffset;
		}

		private void OnWillRenderObject()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				Vector3 val = ((Component)_canvas).transform.position - ((Component)main).transform.position;
				val.y = 0f;
				if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
				{
					((Component)_canvas).transform.rotation = Quaternion.LookRotation(val, Vector3.up);
				}
			}
		}

		private void CreateCanvas()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_004b: 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_009e: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			_uiRoot = new GameObject("UI Root").transform;
			_uiRoot.SetParent(((Component)this).transform);
			GameObject val = new GameObject("DebugCanvas");
			val.transform.SetParent(_uiRoot);
			val.transform.localScale = Vector3.one * 0.0075f;
			_canvas = val.AddComponent<Canvas>();
			_canvas.renderMode = (RenderMode)2;
			CanvasScaler val2 = val.AddComponent<CanvasScaler>();
			val2.dynamicPixelsPerUnit = 20f;
			RectTransform component = val.GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(400f, 300f);
			_logText = CreateText("Logs", val.transform, new Vector2(0f, 100f));
			_persistentText = CreateText("Persistent", val.transform, new Vector2(0f, -100f));
			((TMP_Text)_persistentText).alignment = (TextAlignmentOptions)1026;
		}

		private TextMeshProUGUI CreateText(string name, Transform parent, Vector2 anchoredPos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.sizeDelta = new Vector2(400f, 200f);
			val2.anchoredPosition = anchoredPos;
			TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).fontSize = 20f;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)258;
			((TMP_Text)val3).text = "";
			return val3;
		}

		public void Log(string message)
		{
			_logs.Add(message);
			while (_logs.Count > 8)
			{
				_logs.RemoveAt(0);
			}
			RefreshLogs();
		}

		private void RefreshLogs()
		{
			_builder.Clear();
			foreach (string log in _logs)
			{
				_builder.AppendLine(log);
			}
			((TMP_Text)_logText).text = _builder.ToString();
		}

		public void BindPersistent(string label, Func<string> getter)
		{
			_persistentData[label] = getter;
		}

		private void UpdatePersistentData()
		{
			_builder.Clear();
			foreach (KeyValuePair<string, Func<string>> persistentDatum in _persistentData)
			{
				StringBuilder builder = _builder;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(2, 2, builder);
				handler.AppendFormatted(persistentDatum.Key);
				handler.AppendLiteral(": ");
				handler.AppendFormatted(persistentDatum.Value());
				builder.AppendLine(ref handler);
			}
			((TMP_Text)_persistentText).text = _builder.ToString();
		}

		public void Clear()
		{
			_logs.Clear();
			_persistentData.Clear();
		}

		public void BindDefaults(AdvancedSkin skin)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				BindPersistent("Tint", ((object)((Renderer)skin.MeshRenderer).material.GetColor("Color_D943764B")).ToString);
				BindPersistent("Velocity", ((object)skin.structure.currentVelocity).ToString);
				BindPersistent("Shader", (skin.currentShader != null) ? new Func<string>(skin.currentShader.name.ToString) : ((Func<string>)(() => "null")));
				BindPersistent("Texture Set", (skin.currentTexture != null) ? new Func<string>(skin.currentTexture.name.ToString) : ((Func<string>)(() => "null")));
			}
			catch
			{
			}
		}

		public void SetEnabled(bool toggle)
		{
			((Component)_uiRoot).gameObject.SetActive(toggle);
		}
	}
	public static class InputHandler
	{
		private static readonly List<KeyInput> KeyDown = new List<KeyInput>();

		private static readonly List<KeyHeldInput> KeyHeld = new List<KeyHeldInput>();

		private static readonly List<KeyInput> Key = new List<KeyInput>();

		private static readonly List<KeyInput> KeyUp = new List<KeyInput>();

		public static void Init()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			((MelonEventBase<LemonAction>)(object)MelonEvents.OnUpdate).Subscribe(new LemonAction(Update), 0, false);
			ASS.LogVerbose("InputHandler Initialized");
		}

		public static void GetKeyDown(KeyCode key, Delegate action)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected I4, but got Unknown
			KeyDown.Add(new KeyInput((KeyCode[])(object)new KeyCode[1] { (KeyCode)(int)key }, action));
		}

		public static void GetKeyDown(KeyCode[] key, Delegate action)
		{
			KeyDown.Add(new KeyInput(key, action));
		}

		public static void GetKeyHeld(KeyCode key, Delegate action, float holdTime)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected I4, but got Unknown
			KeyHeld.Add(new KeyHeldInput((KeyCode[])(object)new KeyCode[1] { (KeyCode)(int)key }, action, holdTime));
		}

		public static void GetKeyHeld(KeyCode[] key, Delegate action, float holdTime)
		{
			KeyHeld.Add(new KeyHeldInput(key, action, holdTime));
		}

		public static void GetKey(KeyCode key, Delegate action)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected I4, but got Unknown
			Key.Add(new KeyInput((KeyCode[])(object)new KeyCode[1] { (KeyCode)(int)key }, action));
		}

		public static void GetKey(KeyCode[] key, Delegate action)
		{
			Key.Add(new KeyInput(key, action));
		}

		public static void GetKeyUp(KeyCode key, Delegate action)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected I4, but got Unknown
			KeyUp.Add(new KeyInput((KeyCode[])(object)new KeyCode[1] { (KeyCode)(int)key }, action));
		}

		public static void GetKeyUp(KeyCode[] key, Delegate action)
		{
			KeyUp.Add(new KeyInput(key, action));
		}

		private static void Update()
		{
			foreach (KeyInput item in KeyDown)
			{
				if (((IEnumerable<KeyCode>)item.key).All((Func<KeyCode, bool>)Input.GetKey) && ((IEnumerable<KeyCode>)item.key).Any((Func<KeyCode, bool>)Input.GetKeyDown))
				{
					item.action.DynamicInvoke();
				}
			}
			foreach (KeyHeldInput item2 in KeyHeld)
			{
				if (((IEnumerable<KeyCode>)item2.key).All((Func<KeyCode, bool>)Input.GetKey))
				{
					item2.time += Time.deltaTime;
					if (item2.time >= item2.holdTime)
					{
						item2.time = -100f;
						item2.action.DynamicInvoke();
					}
				}
				if (((IEnumerable<KeyCode>)item2.key).Any((Func<KeyCode, bool>)Input.GetKeyUp))
				{
					item2.time = 0f;
				}
			}
			foreach (KeyInput item3 in Key)
			{
				if (((IEnumerable<KeyCode>)item3.key).All((Func<KeyCode, bool>)Input.GetKey))
				{
					item3.action.DynamicInvoke();
				}
			}
			foreach (KeyInput item4 in KeyUp)
			{
				if (((IEnumerable<KeyCode>)item4.key).All((Func<KeyCode, bool>)Input.GetKeyUp))
				{
					item4.action.DynamicInvoke();
				}
			}
		}
	}
	public class KeyInput
	{
		public KeyCode[] key;

		public Delegate action;

		protected KeyInput()
		{
		}

		public KeyInput(KeyCode[] key, Delegate action)
		{
			this.key = key;
			this.action = action;
		}
	}
	public class KeyHeldInput : KeyInput
	{
		public readonly float holdTime;

		public float time;

		public KeyHeldInput(KeyCode[] key, Delegate action, float holdTime)
		{
			base.key = key;
			base.action = action;
			this.holdTime = holdTime;
		}
	}
	public class LocalizationHandler
	{
		public static void AddLocalizationKey(string key, string value)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			LanguageManager.instance.RawTextDatabase.Add(key, value);
			LocalizedObject val = new LocalizedObject(LanguageManager.instance.LanguageDatabase["Rank.Mountain.Name"]);
			val.textValue = value;
			LanguageManager.instance.LanguageDatabase.Add(key, val);
		}
	}
	public class ModDebug
	{
		public static void AddInputs()
		{
			bool flag = false;
			ASS.Log("ExperimentalBuild enabled. Adding debug binds");
			InputHandler.GetKeyDown((KeyCode)282, new Action(LogPropertyNames));
			InputHandler.GetKeyDown((KeyCode)283, new Action(ScanForTextureReference));
			InputHandler.GetKeyDown((KeyCode[])(object)new KeyCode[2]
			{
				(KeyCode)308,
				(KeyCode)110
			}, new Action(ReplaceProperties));
		}

		private static void LogPropertyNames()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = ((IEnumerable<GameObject>)Object.FindObjectsOfType<GameObject>()).First((GameObject x) => ((Object)x.gameObject).name == "SmallRock");
			Material material = ((Renderer)val.GetComponentInChildren<MeshRenderer>()).material;
			for (int i = 0; i < 6; i++)
			{
				MaterialPropertyType val2 = (MaterialPropertyType)i;
				ASS.Log("[" + ((object)(MaterialPropertyType)(ref val2)).ToString() + "]: \n");
				foreach (string item in (Il2CppArrayBase<string>)(object)material.GetPropertyNames((MaterialPropertyType)i))
				{
					ASS.Log(item);
				}
			}
		}

		private static void ReplaceProperties()
		{
			foreach (Structure item in Object.FindObjectsOfType<Structure>())
			{
				((Renderer)item.meshRenderer).material.SetTexture("Texture2D_2058E65A", (Texture)(object)Texture2D.normalTexture);
				ASS.Log("Replaced textures for " + ((Object)((Component)item).gameObject).name);
			}
		}

		private static void ScanForTextureReference()
		{
			ASS.Log("[Texture Scan]: Starting...");
			Texture2D val = null;
			foreach (Texture2D item in Resources.FindObjectsOfTypeAll<Texture2D>())
			{
				if (((Object)item).name == "Largerock_Lighting")
				{
					val = item;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				ASS.Log("[Texture Scan]: Could not find Largerock_Lighting");
			}
			foreach (Material item2 in Resources.FindObjectsOfTypeAll<Material>())
			{
				foreach (string item3 in (Il2CppArrayBase<string>)(object)item2.GetTexturePropertyNames())
				{
					if ((Object)(object)item2.GetTexture(item3) == (Object)(object)val)
					{
						ASS.Log("[Texture Scan]: Found Largerock_Lighting on material \"" + ((Object)item2).name + "\"");
						ASS.Log("[Texture Scan]: Material shader is " + ((Object)item2.shader).name);
						ASS.Log("[Texture Scan]: Property name is \"" + item3 + "\"");
						return;
					}
				}
			}
		}
	}
}
namespace AdvancedStructureSkins.UI
{
	public class ShaderSelector : SkinSelector
	{
		protected override void DisplayEntryInfo(string displayName, string description)
		{
			_widgets = new SkinSelectorWidget[8];
			for (int num = 7; num >= 0; num--)
			{
				int num2 = ((num == 7) ? 7 : (6 - num));
				_widgets[num2] = new ShaderSelectorWidget(this, num2);
			}
		}
	}
	public class ShaderSelectorWidget : SkinSelectorWidget
	{
		private readonly Toggle _shaderGroupToggle;

		internal ShaderSelectorWidget(SkinSelector parent, int index)
			: base(parent, index)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			_shaderGroupToggle = ((Component)widget.transform.Find("Data/Toggle")).GetComponent<Toggle>();
			StructureFlags val = (StructureFlags)bitmask;
			string text = ((object)(StructureFlags)(ref val)).ToString();
			((Component)widget.transform.Find("Data/Label")).GetComponent<TMP_Text>().text = text + " Shader Group";
			if (bitmask != 128)
			{
				((Component)widget.transform.Find("Description")).GetComponent<TMP_Text>().text = "If this structure group is enabled, it will override any selections from the Global Shader Group when the mod applies shaders to " + text + "s";
			}
		}

		public override void Populate()
		{
			base.Populate();
			_shaderGroupToggle.isOn = (AssAPI.ShaderGroups & bitmask) != 0 || bitmask == 128;
			((Component)_shaderGroupToggle).gameObject.SetActive(bitmask != 128);
			((UnityEvent<bool>)(object)_shaderGroupToggle.onValueChanged).AddListener(UnityAction<bool>.op_Implicit((Action<bool>)delegate(bool toggle)
			{
				ToggleBit(ref AssAPI.ShaderGroups, toggle);
				Submit();
			}));
			foreach (AssShader shader in AssAPI.Shaders)
			{
				if (shader.defaultShaderFor == 0 || shader.defaultShaderFor == bitmask)
				{
					Toggle val = CreateSkinItem(shader.name, shader.previewTexture);
					val.isOn = (shader.enabledForStructure & bitmask) != 0;
					((UnityEvent<bool>)(object)val.onValueChanged).AddListener(UnityAction<bool>.op_Implicit((Action<bool>)delegate(bool toggle)
					{
						ToggleBit(ref shader.enabledForStructure, toggle);
						Submit();
					}));
					buttons.Add(shader.name, val);
				}
			}
		}
	}
	public class SkinSelector : DataEntryAdapter
	{
		protected SkinSelectorWidget[] _widgets;

		protected override void DisplayData(object boxedValue)
		{
			((DataEntryAdapter)this).DisplayData(boxedValue);
			if (!(boxedValue is string))
			{
				ASS.Error("DisplayData is not string");
				return;
			}
			SkinSelectorWidget[] widgets = _widgets;
			foreach (SkinSelectorWidget skinSelectorWidget in widgets)
			{
				skinSelectorWidget.Populate();
				skinSelectorWidget.PostPopulate();
			}
		}

		public override void PreSaveAction()
		{
			((DataEntryAdapter)this).PreSaveAction();
			SkinSelectorWidget[] widgets = _widgets;
			foreach (SkinSelectorWidget skinSelectorWidget in widgets)
			{
				skinSelectorWidget.SetScrollPoint();
			}
		}

		internal void Submit()
		{
			((DataEntryAdapter)this).SubmitValue((object)AssAPI.Serialize());
		}
	}
	public class SkinSelectorWidget
	{
		protected readonly SkinSelector parent;

		protected readonly byte bitmask;

		protected readonly Dictionary<string, Toggle> buttons = new Dictionary<string, Toggle>();

		protected readonly GameObject widget;

		protected readonly ScrollRect skinGroupScrollRect;

		private RectTransform ContentRect
		{
			get
			{
				ScrollRect obj = skinGroupScrollRect;
				return (obj != null) ? obj.content : null;
			}
		}

		protected SkinSelectorWidget(SkinSelector parent, int index)
		{
			this.parent = parent;
			widget = Object.Instantiate<GameObject>(UIHandler.SkinSelectorPrefab, ((Component)parent).transform);
			skinGroupScrollRect = ((Component)widget.transform.Find("Scroll View")).GetComponent<ScrollRect>();
			bitmask = (byte)(1 << index);
		}

		public virtual void Populate()
		{
			foreach (Toggle value in buttons.Values)
			{
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
			buttons.Clear();
		}

		public virtual void PostPopulate()
		{
			skinGroupScrollRect.horizontalScrollbar.value = GetScrollPoint();
		}

		protected void ToggleBit(ref byte currentValue, bool toggle)
		{
			currentValue = (toggle ? ((byte)(currentValue | bitmask)) : ((byte)(currentValue & ~bitmask)));
		}

		protected Toggle CreateSkinItem(string name, Texture preview = null, Color? color = null)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			Toggle component = Object.Instantiate<GameObject>(UIHandler.SkinItemPrefab, (Transform)(object)ContentRect).GetComponent<Toggle>();
			((Component)((Component)component).transform.Find("Description")).GetComponent<TMP_Text>().text = name;
			if ((Object)(object)preview != (Object)null)
			{
				((Component)((Component)component).transform.Find("Background/Preview")).GetComponent<RawImage>().texture = preview;
			}
			if (color.HasValue)
			{
				((Graphic)((Component)((Component)component).transform.Find("Background/Preview")).GetComponent<RawImage>()).color = color.Value;
			}
			return component;
		}

		protected void Submit()
		{
			SetScrollPoint();
			parent.Submit();
		}

		public void SetScrollPoint()
		{
			UIHandler.scrollPoints[$"{GetType().Name}_{bitmask}"] = skinGroupScrollRect.horizontalScrollbar.value;
		}

		private float GetScrollPoint()
		{
			return UIHandler.scrollPoints.GetValueOrDefault($"{GetType().Name}_{bitmask}", 0f);
		}
	}
	public class TextureSelector : SkinSelector
	{
		protected override void DisplayEntryInfo(string displayName, string description)
		{
			_widgets = new SkinSelectorWidget[7];
			for (int i = 0; i < 7; i++)
			{
				_widgets[i] = new TextureSelectorWidget(this, i);
			}
		}
	}
	public class TextureSelectorWidget : SkinSelectorWidget
	{
		internal TextureSelectorWidget(SkinSelector parent, int index)
			: base(parent, index)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			((Component)widget.transform.Find("Data/Toggle")).gameObject.SetActive(false);
			StructureFlags val = (StructureFlags)bitmask;
			string text = ((object)(StructureFlags)(ref val)).ToString();
			((Component)widget.transform.Find("Data/Label")).GetComponent<TMP_Text>().text = text + " Texture Group";
			if (bitmask != 128)
			{
				((Component)widget.transform.Find("Description")).GetComponent<TMP_Text>().text = "Select which texture sets you want " + text + "s to use!";
			}
		}

		public override void Populate()
		{
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			base.Populate();
			foreach (AssTextureSet textureSet in AssAPI.TextureSets)
			{
				if ((!textureSet.isDefaultTextureSet || textureSet.targets == bitmask) && (textureSet.targets & bitmask) != 0)
				{
					Toggle val = CreateSkinItem(textureSet.name, ((Object)(object)textureSet.previewTexture == (Object)null) ? textureSet.GetRandomTexture((TextureType)0) : textureSet.previewTexture, (Color)(textureSet.isDefaultTextureSet ? new Color(0.6901961f, 0.5568628f, 23f / 51f) : Color.white));
					val.isOn = (textureSet.enabledForStructure & bitmask) != 0;
					((UnityEvent<bool>)(object)val.onValueChanged).AddListener(UnityAction<bool>.op_Implicit((Action<bool>)delegate(bool toggle)
					{
						ToggleBit(ref textureSet.enabledForStructure, toggle);
						Submit();
					}));
					buttons.Add(textureSet.name, val);
				}
			}
		}
	}
	public enum PreferenceType
	{
		None,
		Global,
		Shader,
		Texture,
		Mesh
	}
	public class UIHandler
	{
		public static Dictionary<string, float> scrollPoints = new Dictionary<string, float>();

		private static MelonPreferences_Category _settings;

		private static MelonPreferences_Category _shaders;

		private static MelonPreferences_Category _textures;

		public static MelonPreferences_Entry<bool> CompMode;

		public static MelonPreferences_Entry<bool> DebugMode;

		public static MelonPreferences_Entry<string> ShaderSettings;

		public static MelonPreferences_Entry<string> TextureSettings;

		private static AssetBundle PrefabBundle;

		public static GameObject ShaderUIPrefab;

		public static GameObject TextureUIPrefab;

		public static GameObject SkinSelectorPrefab;

		public static GameObject SkinItemPrefab;

		public static bool Initialized;

		public static void Init()
		{
			LoadUIPrefabs();
			RegisterUIModels();
			SyncUIWithAssAPI();
			ASS.LogVerbose("UIFramework Setup Initialized");
			Initialized = true;
		}

		private static void LoadUIPrefabs()
		{
			//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_002d: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			PrefabBundle = AssetBundles.LoadAssetBundleFromStream((MelonMod)(object)ASS.Instance, "AdvancedStructureSkins.Resources.UIFramework");
			ShaderUIPrefab = new GameObject("ShaderUI")
			{
				hideFlags = (HideFlags)32
			};
			((Transform)ShaderUIPrefab.AddComponent<RectTransform>()).localPosition = new Vector3(5f, -7f, 0f);
			((HorizontalOrVerticalLayoutGroup)ShaderUIPrefab.AddComponent<VerticalLayoutGroup>()).spacing = 5f;
			ShaderUIPrefab.AddComponent<ShaderSelector>();
			Object.DontDestroyOnLoad((Object)(object)ShaderUIPrefab);
			TextureUIPrefab = new GameObject("TextureUI")
			{
				hideFlags = (HideFlags)32
			};
			((Transform)TextureUIPrefab.AddComponent<RectTransform>()).localPosition = new Vector3(5f, -7f, 0f);
			((HorizontalOrVerticalLayoutGroup)TextureUIPrefab.AddComponent<VerticalLayoutGroup>()).spacing = 5f;
			TextureUIPrefab.AddComponent<TextureSelector>();
			Object.DontDestroyOnLoad((Object)(object)TextureUIPrefab);
			SkinSelectorPrefab = PrefabBundle.LoadAsset<GameObject>("skinselector");
			((Object)SkinSelectorPrefab).hideFlags = (HideFlags)61;
			ASS.LogVerbose("ShaderSelectorPrefab Loaded. Is Null?: " + ((Object)(object)SkinSelectorPrefab == (Object)null));
			foreach (Component componentsInChild in SkinSelectorPrefab.GetComponentsInChildren<Component>(true))
			{
				if ((Object)(object)componentsInChild == (Object)null)
				{
					ASS.ErrorVerbose("Missing component in prefab!!!");
				}
			}
			SkinItemPrefab = PrefabBundle.LoadAsset<GameObject>("skinitem");
			((Object)SkinItemPrefab).hideFlags = (HideFlags)61;
			ASS.LogVerbose("SkinItemPrefab Loaded. Is Null?: " + ((Object)(object)SkinItemPrefab == (Object)null));
			foreach (Component componentsInChild2 in SkinItemPrefab.GetComponentsInChildren<Component>(true))
			{
				if ((Object)(object)componentsInChild2 == (Object)null)
				{
					ASS.ErrorVerbose("Missing component in prefab!!!");
				}
			}
		}

		private static void RegisterUIModels()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			_settings = MelonPreferences.CreateCategory("ass_settings", "Settings");
			_shaders = MelonPreferences.CreateCategory("ass_shaders", "Shaders");
			_textures = MelonPreferences.CreateCategory("ass_textures", "Textures");
			CompMode = _settings.CreateEntry<bool>("compMode", false, "Competitive Mode", "Disables shaders which provide a competitive advantage through enhanced feedback systems.", false, false, (ValueValidator)null, (string)null);
			DebugMode = _settings.CreateEntry<bool>("debugMode", false, "Debug Mode", "Enables verbose debug logs and extra debugging tools.", false, false, (ValueValidator)null, (string)null);
			ShaderSettings = _shaders.CreateEntry<string>("shaders", "", "shaders", "", false, false, (ValueValidator)new CustomViewProvider
			{
				EntryViewPrefab = ShaderUIPrefab
			});
			TextureSettings = _textures.CreateEntry<string>("textures", "", "textures", "", false, false, (ValueValidator)new CustomViewProvider
			{
				EntryViewPrefab = TextureUIPrefab
			});
			((ModModelBase)UI.Register((MelonMod)(object)ASS.Instance, (MelonPreferences_Category[])(object)new MelonPreferences_Category[3] { _settings, _shaders, _textures })).OnModSaved += ModSaved;
		}

		private static void ModSaved()
		{
			SyncUIWithAssAPI();
			foreach (Structure item in Object.FindObjectsOfType<Structure>())
			{
				SkinHandler.ApplySkinTo(item);
			}
			foreach (AdvancedSkin item2 in Object.FindObjectsOfType<AdvancedSkin>())
			{
				item2.debugger?.SetEnabled(DebugMode.Value);
			}
		}

		private static void SyncUIWithAssAPI()
		{
			string input = AssAPI.SyncUI(BuildSerializedSettings());
			ShaderSettings.Value = ExtractSerializedSettings(input, PreferenceType.Shader);
			TextureSettings.Value = ExtractSerializedSettings(input, PreferenceType.Texture);
		}

		private static string ExtractSerializedSettings(string input, PreferenceType type)
		{
			string[] array = input.Split('\n');
			List<string> list = new List<string>();
			PreferenceType preferenceType = PreferenceType.None;
			string[] array2 = array;
			foreach (string text in array2)
			{
				string text2 = text.TrimEnd('\r');
				switch (text2)
				{
				case "[Shader Settings]":
				case "[Shaders]":
					preferenceType = PreferenceType.Shader;
					if (type == PreferenceType.Shader)
					{
						list.Add(text2);
					}
					break;
				case "[Textures]":
					preferenceType = PreferenceType.Texture;
					if (type == PreferenceType.Texture)
					{
						list.Add(text2);
					}
					break;
				default:
					if (type == preferenceType)
					{
						list.Add(text2);
					}
					break;
				}
			}
			return string.Join("\n", list);
		}

		private static string BuildSerializedSettings()
		{
			return ShaderSettings.Value + TextureSettings.Value;
		}
	}
}
namespace AdvancedStructureSkins.Skins
{
	[RegisterTypeInIl2Cpp]
	public class AdvancedSkin : MonoBehaviour
	{
		public Structure structure;

		public GameObjectDebugger debugger;

		public AssShader currentShader;

		public AssTextureSet currentTexture;

		public Dictionary<Type, ShaderFeature> shaderFeatures = new Dictionary<Type, ShaderFeature>();

		public MeshRenderer MeshRenderer => structure.MeshRenderer;

		public AdvancedSkin(IntPtr ptr)
			: base(ptr)
		{
		}

		private void OnEnable()
		{
			if (UIHandler.DebugMode.Value && (Object)(object)debugger == (Object)null)
			{
				debugger = ((Component)this).gameObject.AddComponent<GameObjectDebugger>();
			}
			debugger?.Clear();
			debugger?.BindDefaults(this);
			shaderFeatures = AssAPI.GetFeaturesFor(this);
			foreach (ShaderFeature value in shaderFeatures.Values)
			{
				value.OnEnable();
			}
			Actions.onPlayerHealthChanged += PlayerHit;
		}

		private void OnDisable()
		{
			Actions.onPlayerHealthChanged -= PlayerHit;
			shaderFeatures.Clear();
		}

		private void PlayerHit(Player player, int change)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			if ((int)player.Controller.ControllerType == 1)
			{
				GetShaderFeature<TimeSinceLocalDamageTaken>().ResetTimer();
				GetShaderFeature<LastLocalDamageTaken>().SetProperty((float)change);
			}
			else
			{
				GetShaderFeature<TimeSinceRemoteDamageTaken>().ResetTimer();
				GetShaderFeature<LastRemoteDamageTaken>().SetProperty((float)change);
			}
		}

		private void Update()
		{
			foreach (ShaderFeature value in shaderFeatures.Values)
			{
				value.Update();
			}
		}

		private void FixedUpdate()
		{
			foreach (ShaderFeature value in shaderFeatures.Values)
			{
				value.FixedUpdate();
			}
		}

		public T GetShaderFeature<T>() where T : ShaderFeature
		{
			if (shaderFeatures.TryGetValue(typeof(T), out var value))
			{
				return (T)value;
			}
			ASS.ErrorVerbose("Could not find requested shader feature '" + typeof(T).Name + "'");
			return null;
		}

		public void RefreshEnabledShaderFeatures()
		{
			foreach (ShaderFeature value in shaderFeatures.Values)
			{
				value.enabled = !UIHandler.CompMode.Value && ((Renderer)MeshRenderer).material.HasProperty(value.propertyName);
				value.OnEnable();
			}
		}
	}
	public static class BulkPatcher
	{
		public static void ApplyPatches(Harmony harmony)
		{
			PatchModifiers(harmony);
		}

		public static void PatchModifiers(Harmony harmony)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			Type baseType = typeof(Modifier);
			Assembly assembly = baseType.Assembly;
			IEnumerable<Type> enumerable = from t in assembly.GetTypes()
				where !t.IsAbstract && baseType.IsAssignableFrom(t)
				select t;
			foreach (Type item in enumerable)
			{
				try
				{
					MethodInfo method = item.GetMethod("Execute", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (!(method == null) && !(method.DeclaringType != item))
					{
						harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(BulkPatcher).GetMethod("ModifierExecutePostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						ASS.LogVerbose("Patched: " + item.FullName + ".Execute");
					}
				}
				catch (Exception value)
				{
					ASS.ErrorVerbose($"Failed patching {item.FullName}: {value}");
				}
			}
		}

		public static void ModifierExecutePostfix(Modifier __instance, IProcessor processor, StackConfiguration config)
		{
			try
			{
				ProcessableComponent processorComponent = config.TargetProcessable.GetProcessorComponent<ProcessableComponent>(false);
				if ((Object)(object)processorComponent == (Object)null)
				{
					return;
				}
				((Component)processorComponent).GetComponent<AdvancedSkin>()?.GetShaderFeature<TimeSinceLastModified>().ResetTimer();
				foreach (AdvancedSkin item in ((IEnumerable<AdvancedSkin>)Object.FindObjectsOfType<AdvancedSkin>()).Where((AdvancedSkin skin) => skin.shaderFeatures[typeof(TimeSinceLastPose)].enabled))
				{
					item.GetShaderFeature<TimeSinceLastPose>().ResetTimer();
				}
			}
			catch (Exception msg)
			{
				ASS.ErrorVerbose(msg);
			}
		}
	}
	public static class SkinHandler
	{
		private static readonly Dictionary<string, int> Types = new Dictionary<string, int>
		{
			{ "Disc", 0 },
			{ "Pillar", 1 },
			{ "Ball", 2 },
			{ "RockCube", 3 },
			{ "Wall", 4 },
			{ "SmallRock", 5 },
			{ "LargeRock", 6 },
			{ "StructureTarget", 0 },
			{ "DockedDisk", 0 },
			{ "PrisonedPillar", 1 },
			{ "BoulderBall", 2 },
			{ "CageCube", 3 },
			{ "WrappedWall", 4 }
		};

		private static readonly string[] TEXProperties = new string[4] { "Texture2D_3812B1EC", "Texture2D_2058E65A", "Texture2D_8F187FEF", "_Grounded_noise" };

		private static readonly string[] TEXTypes = new string[4] { "Normal", "Main", "Mat", "Grounded" };

		public static void Init()
		{
			ASS.LogVerbose("SkinHandler Initialized");
		}

		public static void ApplySkinTo(Structure structure)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected I4, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (!Types.Keys.Contains(((Object)((Component)structure).gameObject).name))
			{
				ASS.Warn("Found unsupported structure with name '" + ((Object)((Component)structure).gameObject).name + "'");
				return;
			}
			MeshRenderer meshRenderer = structure.meshRenderer;
			AdvancedSkin component = ((Component)structure).GetComponent<AdvancedSkin>();
			StructureFlags val = (StructureFlags)AssAPI.GetStructureFlag(Types[((Object)((Component)structure).gameObject).name]);
			if ((Object)(object)meshRenderer == (Object)null)
			{
				ASS.Error("Could not find MeshRenderer on structure!");
				return;
			}
			TrySaveDefaults(component, val);
			ApplyTexturesTo(component, val);
			AssShader[] shadersFor = AssAPI.GetShadersFor((byte)(int)val);
			if (shadersFor.Length != 0)
			{
				AssShader shader = shadersFor[ASS.Random.Next(0, shadersFor.Length)];
				ApplyShaderTo(component, val, shader);
				ApplyOverridesTo(component, val, shader);
			}
		}

		private static void TrySaveDefaults(AdvancedSkin advancedSkin, StructureFlags type)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected I4, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer meshRenderer = advancedSkin.MeshRenderer;
			AssShader defaultShaderFor = AssAPI.GetDefaultShaderFor((byte)(int)type);
			AssTextureSet defaultTextureSetFor = AssAPI.GetDefaultTextureSetFor(type);
			if (!defaultShaderFor.initialized)
			{
				defaultShaderFor.shaders[0].material = new Material(((Renderer)meshRenderer).material)
				{
					hideFlags = (HideFlags)32
				};
				defaultShaderFor.initialized = true;
			}
			if (defaultTextureSetFor.initialized)
			{
				return;
			}
			foreach (TextureType value in Enum.GetValues(typeof(TextureType)))
			{
				Texture texture = ((Renderer)meshRenderer).material.GetTexture(TEXProperties[value]);
				if ((Object)(object)texture == (Object)null)
				{
					ASS.Warn("Texture Property " + TEXProperties[value] + " doesn't exist.");
				}
				else
				{
					defaultTextureSetFor.AddExistingTexture(value, texture);
				}
			}
			defaultTextureSetFor.initialized = true;
		}

		private static void ApplyTexturesTo(AdvancedSkin advancedSkin, StructureFlags type)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_005d: 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)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			AssTextureSet[] enabledTextureSetsForStructure = AssAPI.GetEnabledTextureSetsForStructure(type);
			if (enabledTextureSetsForStructure.Length == 0)
			{
				return;
			}
			AssTextureSet assTextureSet = enabledTextureSetsForStructure[ASS.Random.Next(enabledTextureSetsForStructure.Length)];
			MaterialPropertyBlock val = new MaterialPropertyBlock();
			MeshRenderer meshRenderer = advancedSkin.MeshRenderer;
			((Renderer)meshRenderer).GetPropertyBlock(val);
			for (int i = 0; i < TEXProperties.Length; i++)
			{
				Texture randomTexture = assTextureSet.GetRandomTexture((TextureType)i);
				if ((Object)(object)randomTexture == (Object)null)
				{
					ApplyDefaultTexturesTo(val, type, i);
				}
				else
				{
					val.SetTexture(TEXProperties[i], randomTexture);
				}
			}
			val.SetColor("Color_D943764B", (Color)(assTextureSet.isDefaultTextureSet ? new Color(0.6901961f, 0.5568628f, 23f / 51f) : Color.white));
			((Renderer)meshRenderer).SetPropertyBlock(val);
			advancedSkin.currentTexture = assTextureSet;
		}

		private static void ApplyDefaultTexturesTo(MaterialPropertyBlock properties, StructureFlags type, int tIndex)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			properties.SetTexture(TEXProperties[tIndex], (Texture)(object)Texture2D.blackTexture);
			Texture randomTexture = AssAPI.GetDefaultTextureSetFor(type).GetRandomTexture((TextureType)tIndex);
			if (!((Object)(object)randomTexture == (Object)null))
			{
				properties.SetTexture(TEXProperties[tIndex], randomTexture);
			}
		}

		private static void ApplyShaderTo(AdvancedSkin advancedSkin, StructureFlags type, AssShader shader)
		{
			if (shader.shaders == null)
			{
				ASS.WarnVerbose("Could not find material list on AssShader, gave up executing ApplyShaderTo()");
				return;
			}
			MeshRenderer meshRenderer = advancedSkin.MeshRenderer;
			Material[] materials = GetMaterials(shader, meshRenderer);
			if (materials.Length == 0)
			{
				ASS.WarnVerbose("AssShader returned no materials. Gave up executing ApplyShaderTo()");
				return;
			}
			((Renderer)meshRenderer).materials = Il2CppReferenceArray<Material>.op_Implicit(materials);
			advancedSkin.RefreshEnabledShaderFeatures();
			advancedSkin.currentShader = shader;
		}

		private static Material[] GetMaterials(AssShader shader, MeshRenderer meshRenderer)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			List<Material> list = new List<Material>();
			foreach (ShaderManifest shader2 in shader.shaders)
			{
				Material val = new Material(shader2.material);
				val.CopyMatchingPropertiesFromMaterial(((Il2CppArrayBase<Material>)(object)((Renderer)meshRenderer).materials)[0]);
				list.Add(val);
			}
			return list.ToArray();
		}

		private static void ApplyOverridesTo(AdvancedSkin advancedSkin, StructureFlags type, AssShader shader)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Invalid comparison between Unknown and I4
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected I4, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			List<ShaderManifest> shaders = shader.shaders;
			if (shaders == null)
			{
				return;
			}
			MeshRenderer meshRenderer = advancedSkin.MeshRenderer;
			for (int i = 0; i < shader.shaders.Count; i++)
			{
				for (int j = 0; j < shader.shaders[i].overrides.Count; j++)
				{
					ShaderManifest val = shader.shaders[i];
					MaterialPropertyOverride val2 = val.overrides[j];
					if (val.overrides[j] != null && (val.overrides[j].targetStructures & type) != 0 && ((Il2CppArrayBase<Material>)(object)((Renderer)meshRenderer).materials).Count >= i && !((Object)(object)((Il2CppArrayBase<Material>)(object)((Renderer)meshRenderer).materials)[i] == (Object)null))
					{
						ShaderPropertyType propertyType = val.overrides[j].propertyType;
						ShaderPropertyType val3 = propertyType;
						switch ((int)val3)
						{
						case 0:
							((Il2CppArrayBase<Material>)(object)((Renderer)meshRenderer).materials)[i].SetColor(val2.propertyName, val2.colorValue);
							break;
						case 1:
							((Il2CppArrayBase<Material>)(object)((Renderer)meshRenderer).materials)[i].SetVector(val2.propertyName, val2.vectorValue);
							break;
						case 2:
						case 3:
							((Il2CppArrayBase<Material>)(object)((Renderer)meshRenderer).materials)[i].SetFloat(val2.propertyName, val2.floatValue);
							break;
						case 4:
							((Il2CppArrayBase<Material>)(object)((Renderer)meshRenderer).materials)[i].SetTexture(val2.propertyName, val2.textureValue);
							break;
						case 5:
							((Il2CppArrayBase<Material>)(object)((Renderer)meshRenderer).materials)[i].SetInt(val2.propertyName, val2.intValue);
							break;
						}
					}
				}
			}
		}
	}
	public class SkinTextures
	{
		public string Name;

		private Texture2D[][] _textures = new Texture2D[4][];

		private static Random _random = new Random();

		private readonly string[] _texTypes = new string[4] { "Normal", "Main", "Mat", "Grounded" };

		public SkinTextures(string folderPath)
		{
			Name = Path.GetFileName(folderPath);
			_textures = LoadTexturesFromPath(folderPath);
		}

		private Texture2D[][] LoadTexturesFromPath(string folderPath)
		{
			Texture2D[][] array = new Texture2D[4][];
			for (int i = 0; i < array.Length; i++)
			{
				string path = Path.Combine(folderPath, _texTypes[i] + ".png");
				if (File.Exists(path))
				{
					array[i] = (Texture2D[])(object)new Texture2D[1];
					array[i][0] = LoadTexture(path, i);
					continue;
				}
				string path2 = Path.Combine(folderPath, _texTypes[i]);
				if (Directory.Exists(path2))
				{
					string[] files = Directory.GetFiles(path2);
					array[i] = (Texture2D[])(object)new Texture2D[files.Length];
					for (int j = 0; j < files.Length; j++)
					{
						array[i][j] = LoadTexture(files[j], i);
					}
				}
			}
			return array;
		}

		private Texture2D LoadTexture(string path, int textureType)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (!File.Exists(path))
			{
				return null;
			}
			Texture2D val = new Texture2D(2, 2);
			byte[] array = File.ReadAllBytes(path);
			ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array));
			((Object)val).hideFlags = (HideFlags)61;
			if (textureType == 0)
			{
				Texture2D val2 = new Texture2D(((Texture)val).width, ((Texture)val).height, val.format, true, true);
				Color[] array2 = Il2CppArrayBase<Color>.op_Implicit((Il2CppArrayBase<Color>)(object)val.GetPixels());
				Color[] array3 = (Color[])(object)new Color[array2.Length];
				for (int i = 0; i < array2.Length; i++)
				{
					array3[i] = ((Color)(ref array2[i])).linear;
				}
				val2.SetPixels(Il2CppStructArray<Color>.op_Implicit(array3));
				((Object)val2).hideFlags = (HideFlags)61;
				val2.Apply();
				if ((Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
			return val;
		}

		public Texture2D GetTexture(int textureType)
		{
			if (_textures[textureType] == null)
			{
				ASS.Error("Requested SkinTexture type is null.");
				return null;
			}
			if (_textures[textureType].Length == 0)
			{
				ASS.Error("Requested SkinTexture type is empty.");
				return null;
			}
			int num = _random.Next(_textures[textureType].Length);
			if ((Object)(object)_textures[textureType][num] == (Object)null)
			{
				ASS.Error("Requested SkinTexture image is null");
				return null;
			}
			return _textures[textureType][num];
		}

		public bool HasTextureFor(int textureType)
		{
			if (_textures[textureType] == null)
			{
				return false;
			}
			return _textures[textureType].Length != 0;
		}
	}
	[HarmonyPatch(typeof(Structure), "OnFetchFromPool")]
	public static class StructureSpawnPatch
	{
		private static void Postfix(ref Structure __instance)
		{
			try
			{
				SkinHandler.ApplySkinTo(__instance);
				((Component)__instance).GetComponent<AdvancedSkin>().GetShaderFeature<IsExplodeApplied>().SetProperty(0f);
			}
			catch (Exception msg)
			{
				ASS.Error(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Structure), "Awake")]
	public static class StructureStartPatch
	{
		private static void Postfix(ref Structure __instance)
		{
			try
			{
				AdvancedSkin advancedSkin = ((Component)__instance).gameObject.AddComponent<AdvancedSkin>();
				advancedSkin.structure = __instance;
			}
			catch (Exception msg)
			{
				ASS.Error(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Structure), "OnPhysicsStateChanged")]
	public static class StructurePhysicsStateChangedPatch
	{
		private static void Postfix(PhysicsState previousState, PhysicsState newState, Structure __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (DidChangeGroundState(previousState, newState))
				{
					((Component)__instance).GetComponent<AdvancedSkin>().GetShaderFeature<TimeSinceGroundStateChanged>().ResetTimer();
				}
			}
			catch (Exception msg)
			{
				ASS.ErrorVerbose(msg);
			}
		}

		private static bool DidChangeGroundState(PhysicsState currentState, PhysicsState newState)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			PhysicsState[] source = (PhysicsState[])(object)new PhysicsState[2]
			{
				(PhysicsState)1,
				(PhysicsState)2
			};
			return source.Contains(currentState) != source.Contains(newState);
		}
	}
	[HarmonyPatch(typeof(Structure), "Shake")]
	public static class StructureShakePatch
	{
		private static void Postfix(float time, Structure __instance)
		{
			try
			{
				((Component)__instance).gameObject.GetComponent<AdvancedSkin>().GetShaderFeature<TimeSinceHitstop>().ResetTimer();
			}
			catch (Exception msg)
			{
				ASS.ErrorVerbose(msg);
			}
		}
	}
	[HarmonyPatch(typeof(ExplodeModifier), "Execute")]
	public static class ExplodeModifierExecutePatch
	{
		public static void Postfix(ExplodeModifier __instance, IProcessor processor, StackConfiguration config)
		{
			try
			{
				ProcessableComponent processorComponent = config.TargetProcessable.GetProcessorComponent<ProcessableComponent>(false);
				if (!((Object)(object)processorComponent == (Object)null))
				{
					AdvancedSkin component = ((Component)processorComponent).GetComponent<AdvancedSkin>();
					component?.GetShaderFeature<IsExplodeApplied>().SetProperty(1f);
					component?.GetShaderFeature<TimeSinceExplodeApplied>().ResetTimer();
				}
			}
			catch (Exception msg)
			{
				ASS.ErrorVerbose(msg);
			}
		}
	}
	[HarmonyPatch(typeof(__c__DisplayClass11_0), "_Execute_g__OnStructureDetroyed_0")]
	public static class OnExplodePatch
	{
		public static void Prefix(__c__DisplayClass11_0 __instance)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Structure structure = __instance.structure;
				PlayerShiftstoneSystem shiftstoneSystem = __instance.shiftstoneSystem;
				float totalMultiplier = shiftstoneSystem.GetTotalMultiplier((MultiplierType)5, 1f, true, structure);
				int num = default(int);
				Structure[] array = Il2CppArrayBase<Structure>.op_Implicit((Il2CppArrayBase<Structure>)(object)SceneSingleton<CombatManager>.Instance.GetStructuresInRange(((Component)structure).transform.position, 3f, false, ref num));
				Structure[] array2 = array;
				foreach (Structure val in array2)
				{
					if (!((Object)(object)val == (Object)(object)structure))
					{
						AdvancedSkin component = ((Component)val).GetComponent<AdvancedSkin>();
						component?.GetShaderFeature<TimeSinceHitByExplosion>().ResetTimer();
						Vector3 val2 = ((Component)structure).transform.position - ((Component)val).transform.position;
						Vector3 val3 = ((Vector3)(ref val2)).normalized * (float)(1000 * structure.GetTotalTier()) * totalMultiplier;
						component?.GetShaderFeature<LastExplosionStrength>().SetProperty(((Vector3)(ref val3)).magnitude);
					}
				}
			}
			catch (Exception msg)
			{
				ASS.ErrorVerbose(msg);
			}
		}
	}
}
namespace AdvancedStructureSkins.ShaderFeatures
{
	public class ClosestRemotePlayerPosition : ShaderFeature
	{
		private PlayerVR ClosestRemotePlayer
		{
			get
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				Player closestPlayer = Players.GetClosestPlayer(((Component)target).transform.position, true);
				object result;
				if (closestPlayer == null)
				{
					result = null;
				}
				else
				{
					PlayerController controller = closestPlayer.Controller;
					result = ((controller != null) ? controller.PlayerVR : null);
				}
				return (PlayerVR)result;
			}
		}

		public ClosestRemotePlayerPosition(AdvancedSkin target)
			: base(target, (ShaderPropertyType)1, "_closestRemotePlayerPosition", Vector3.zero)
		{
		}//IL_0008: Unknown result type (might be due to invalid IL or missing references)


		protected override void OnUpdate()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			base.OnUpdate();
			if (!((Object)(object)ClosestRemotePlayer == (Object)null))
			{
				SetProperty<Vector3>(ClosestRemotePlayer.GetFeetPosition() + Vector3.up * (ClosestRemotePlayer.GetCurrentPlayerHeight(0f, 2.5f) * 0.5f));
			}
		}
	}
	public class CurrentVelocity : ShaderFeature
	{
		private Structure Structure => target.structure;

		public CurrentVelocity(AdvancedSkin target)
			: base(target, (ShaderPropertyType)1, "_currentVelocity", Vector3.Zero)
		{
		}

		protected override void OnUpdate()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			base.OnUpdate();
			SetProperty<Vector3>(Structure.CurrentVelocity);
		}
	}
	public class IsExplodeApplied : ShaderFeature
	{
		public IsExplodeApplied(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_isExplodeApplied", 0)
		{
		}
	}
	public class IsHost : ShaderFeature
	{
		private static bool Host => !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient;

		public IsHost(AdvancedSkin target)
			: base(target, (ShaderPropertyType)5, "_isHost", 0)
		{
		}

		public override void OnEnable()
		{
			base.OnEnable();
			SetProperty(Host ? 1 : 0);
		}
	}
	public class LastExplosionStrength : ShaderFeature
	{
		public LastExplosionStrength(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_lastExplosionStrength", 0)
		{
		}
	}
	public class LastLocalDamageTaken : ShaderFeature
	{
		public LastLocalDamageTaken(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_lastLocalDamageTaken", 0)
		{
		}
	}
	public class LastRemoteDamageTaken : ShaderFeature
	{
		public LastRemoteDamageTaken(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_lastRemoteDamageTaken", 0)
		{
		}
	}
	public class LocalPlayerPosition : ShaderFeature
	{
		private PlayerVR LocalPlayer => Players.GetLocalPlayerController().PlayerVR;

		public LocalPlayerPosition(AdvancedSkin target)
			: base(target, (ShaderPropertyType)1, "_localPlayerPosition", Vector3.zero)
		{
		}//IL_0008: Unknown result type (might be due to invalid IL or missing references)


		protected override void OnUpdate()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			base.OnUpdate();
			if (!((Object)(object)LocalPlayer == (Object)null))
			{
				SetProperty<Vector3>(LocalPlayer.GetFeetPosition() + Vector3.up * (LocalPlayer.GetCurrentPlayerHeight(0f, 2.5f) * 0.5f));
			}
		}
	}
	public class ShaderFeature
	{
		public bool enabled = false;

		internal readonly AdvancedSkin target;

		internal readonly string propertyName;

		internal readonly ShaderPropertyType type;

		internal readonly object defaultValue;

		private Material[] Materials => Il2CppArrayBase<Material>.op_Implicit((Il2CppArrayBase<Material>)(object)((Renderer)target.MeshRenderer).materials);

		public ShaderFeature(AdvancedSkin target, ShaderPropertyType type, string propertyName, object defaultValue)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			this.target = target;
			this.type = type;
			this.propertyName = propertyName;
			this.defaultValue = defaultValue;
		}

		public virtual void OnEnable()
		{
			if (enabled)
			{
				SetProperty(defaultValue);
			}
		}

		public void Update()
		{
			if (enabled)
			{
				OnUpdate();
			}
		}

		public void FixedUpdate()
		{
			if (enabled)
			{
				OnFixedUpdate();
			}
		}

		protected virtual void OnUpdate()
		{
		}

		protected virtual void OnFixedUpdate()
		{
		}

		public virtual void SetProperty<T>(T value)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected I4, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (!enabled)
			{
				return;
			}
			try
			{
				ShaderPropertyType val = type;
				ShaderPropertyType val2 = val;
				switch ((int)val2)
				{
				case 0:
					if (value is Color)
					{
						object obj2 = value;
						Color color = (Color)((obj2 is Color) ? obj2 : null);
						if (true)
						{
							SetColor(color);
							break;
						}
					}
					ASS.WarnVerbose("Tried setting colour on ShaderFeature with a non-color value.");
					break;
				case 1:
					if (value is Vector2)
					{
						object obj4 = value;
						Vector2 val3 = (Vector2)((obj4 is Vector2) ? obj4 : null);
						SetVector(Vector4.op_Implicit(val3));
					}
					else if (value is Vector3)
					{
						object obj5 = value;
						Vector3 val4 = (Vector3)((obj5 is Vector3) ? obj5 : null);
						SetVector(Vector4.op_Implicit(val4));
					}
					else if (value is Vector4)
					{
						object obj6 = value;
						Vector4 vector = (Vector4)((obj6 is Vector4) ? obj6 : null);
						SetVector(vector);
					}
					else
					{
						ASS.WarnVerbose("Tried setting vector on ShaderFeature with a non-vector value.");
					}
					break;
				case 2:
				case 3:
					if (value is float)
					{
						object obj3 = value;
						float @float = (float)((obj3 is float) ? obj3 : null);
						if (true)
						{
							SetFloat(@float);
							break;
						}
					}
					ASS.WarnVerbose("Tried setting float on ShaderFeature with a non-float value.");
					break;
				case 4:
				{
					object obj7 = value;
					Texture val5 = (Texture)((obj7 is Texture) ? obj7 : null);
					if (val5 != null)
					{
						SetTexture(val5);
					}
					else
					{
						ASS.WarnVerbose("Tried setting texture on ShaderFeature with a non-texture value.");
					}
					break;
				}
				case 5:
					if (value is int)
					{
						object obj = value;
						int @int = (int)((obj is int) ? obj : null);
						if (true)
						{
							SetInt(@int);
							break;
						}
					}
					ASS.WarnVerbose("Tried setting int on ShaderFeature with a non-int value.");
					break;
				default:
					ASS.Warn("Tried setting invalid type on ShaderFeature");
					break;
				}
			}
			catch (Exception msg)
			{
				ASS.ErrorVerbose(msg);
			}
		}

		private void SetColor(Color value)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Material[] materials = Materials;
			foreach (Material val in materials)
			{
				val.SetColor(propertyName, value);
			}
		}

		private void SetVector(Vector4 value)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Material[] materials = Materials;
			foreach (Material val in materials)
			{
				val.SetVector(propertyName, value);
			}
		}

		private void SetFloat(float value)
		{
			Material[] materials = Materials;
			foreach (Material val in materials)
			{
				val.SetFloat(propertyName, value);
			}
		}

		private void SetTexture(Texture value)
		{
			Material[] materials = Materials;
			foreach (Material val in materials)
			{
				val.SetTexture(propertyName, value);
			}
		}

		private void SetInt(int value)
		{
			Material[] materials = Materials;
			foreach (Material val in materials)
			{
				val.SetInt(propertyName, value);
			}
		}
	}
	public class SmoothVelocity : ShaderFeature
	{
		private struct Sample
		{
			public Vector3 velocity;

			public float time;
		}

		private readonly Queue<Sample> _samples = new Queue<Sample>();

		private Vector3 _sum = Vector3.zero;

		private const float TimeWindow = 2f;

		public SmoothVelocity(AdvancedSkin target)
			: base(target, (ShaderPropertyType)1, "_smoothVelocity", Vector3.zero)
		{
		}//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)


		private void Add(Vector3 value)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			_samples.Enqueue(new Sample
			{
				velocity = value,
				time = time
			});
			_sum += value;
			while (_samples.Count > 0 && time - _samples.Peek().time > 2f)
			{
				Sample sample = _samples.Dequeue();
				_sum -= sample.velocity;
			}
		}

		private Vector3 GetAverage()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0018: 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)
			if (_samples.Count == 0)
			{
				return Vector3.zero;
			}
			return _sum / (float)_samples.Count;
		}

		protected override void OnUpdate()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			base.OnUpdate();
			SetProperty<Vector3>(GetAverage());
		}

		protected override void OnFixedUpdate()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			base.OnFixedUpdate();
			Add(target.structure.rigidBody.velocity);
		}
	}
	public class TimedShaderFeature : ShaderFeature
	{
		private float _time = 0f;

		private bool _counting = true;

		public TimedShaderFeature(AdvancedSkin target, ShaderPropertyType type, string propertyName, float defaultValue = 999f)
			: base(target, type, propertyName, defaultValue)
		{
		}//IL_0014: Unknown result type (might be due to invalid IL or missing references)


		public override void OnEnable()
		{
			base.OnEnable();
			if (enabled)
			{
				_time = (float)defaultValue;
			}
		}

		protected override void OnUpdate()
		{
			base.OnUpdate();
			if (_counting)
			{
				_time += Time.deltaTime;
			}
			SetProperty(_time);
		}

		public virtual void ResetTimer()
		{
			_time = 0f;
		}

		public virtual void PauseTimer(bool counting = false)
		{
			_counting = counting;
		}

		public virtual void ResumeTimer(bool counting = true)
		{
			_counting = counting;
		}
	}
	public class TimeSinceExplodeApplied : TimedShaderFeature
	{
		public TimeSinceExplodeApplied(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_timeSinceExplodeApplied")
		{
		}
	}
	public class TimeSinceGroundStateChanged : TimedShaderFeature
	{
		public TimeSinceGroundStateChanged(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_timeSinceGroundStateChanged")
		{
		}
	}
	public class TimeSinceHitByExplosion : TimedShaderFeature
	{
		public TimeSinceHitByExplosion(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_timeSinceHitByExplosion")
		{
		}
	}
	public class TimeSinceHitstop : TimedShaderFeature
	{
		public TimeSinceHitstop(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_timeSinceHitstop")
		{
		}
	}
	public class TimeSinceLastModified : TimedShaderFeature
	{
		public TimeSinceLastModified(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_timeSinceLastModified")
		{
		}
	}
	public class TimeSinceLastPose : TimedShaderFeature
	{
		public TimeSinceLastPose(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_timeSinceLastPose")
		{
		}
	}
	public class TimeSinceLocalDamageTaken : TimedShaderFeature
	{
		public TimeSinceLocalDamageTaken(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_timeSinceLocalDamageTaken")
		{
		}
	}
	public class TimeSinceRemoteDamageTaken : TimedShaderFeature
	{
		public TimeSinceRemoteDamageTaken(AdvancedSkin target)
			: base(target, (ShaderPropertyType)2, "_timeSinceRemoteDamageTaken")
		{
		}
	}
}
namespace AdvancedStructureSkins.API
{
	public static class AssAPI
	{
		internal static byte ShaderGroups;

		internal static readonly List<AssShader> Shaders = new List<AssShader>();

		private static string _skinDirectory = Path.Combine(MelonEnvironment.UserDataDirectory, "Skins");

		internal static readonly List<AssTextureSet> TextureSets = new List<AssTextureSet>();

		private static readonly Dictionary<StructureFlags, List<AssTextureSet>> TextureSetsByTarget = new Dictionary<StructureFlags, List<AssTextureSet>>();

		private static readonly Dictionary<string, StructureFlags> StructureFlagMap = new Dictionary<string, StructureFlags>(StringComparer.OrdinalIgnoreCase)
		{
			{
				"Disc",
				(StructureFlags)1
			},
			{
				"Pillar",
				(StructureFlags)2
			},
			{
				"Ball",
				(StructureFlags)4
			},
			{
				"Cube",
				(StructureFlags)8
			},
			{
				"Wall",
				(StructureFlags)16
			},
			{
				"SmallRock",
				(StructureFlags)32
			},
			{
				"LargeRock",
				(StructureFlags)64
			}
		};

		private static readonly List<Type> ShaderFeatures = new List<Type>();

		public static void Init()
		{
			ASS.LogVerbose("Initializing AssAPI");
			RegisterModShaderFeatures();
			_skinDirectory = Path.Combine(MelonEnvironment.UserDataDirectory, "Skins");
			LoadTextureSets();
			LoadAdvancedSkinBundles();
			CreatePlaceholderDefaultShaders();
			CreatePlaceholderDefaultTextures();
			BuildTextureCache();
			ASS.LogVerbose("AssAPI Initialized");
		}

		private static void LoadAdvancedSkinBundles()
		{
			string[] skinNames = GetSkinNames();
			int num = 0;
			string[] array = skinNames;
			foreach (string path in array)
			{
				string text = Path.Combine(_skinDirectory, path);
				if (!File.Exists(text))
				{
					ASS.Error("Skin loading failed attempting to load a skin that doesn't exist.. how??");
					continue;
				}
				AssetBundle val = AssetBundles.LoadAssetBundleFromFile(text);
				if ((Object)(object)val == (Object)null)
				{
					ASS.Error("Failed to load .asb: " + text);
					continue;
				}
				string text2 = ((IEnumerable<string>)val.GetAllAssetNames()).FirstOrDefault((string x) => x.ToLower().Contains("manifest"));
				if (text2 == null)
				{
					AssShader assShader = LoadShaderFromBundle(val);
					if (assShader == null)
					{
						ASS.ErrorVerbose("[Invalid Bundle] Failed to load .asb at: " + text);
						continue;
					}
					Shaders.Add(assShader);
				}
				else
				{
					TextAsset val2 = val.LoadAsset<TextAsset>(text2);
					if ((Object)(object)val2 == (Object)null)
					{
						ASS.ErrorVerbose("[No Manifest] Failed to load .asb at " + text);
						continue;
					}
					try
					{
						SkinManifestBinary val3 = BinaryHandler.Read(Il2CppArrayBase<byte>.op_Implicit((Il2CppArrayBase<byte>)(object)val2.bytes));
						SkinManifest skinManifestFromBundle = val3.GetSkinManifestFromBundle(val);
						if (skinManifestFromBundle.shaders.Count > 0)
						{
							Shaders.Add(LoadShaderFromManifest(skinManifestFromBundle));
						}
						TextureSets.AddRange(LoadTextureSetsFromManifest(skinManifestFromBundle));
					}
					catch (Exception ex)
					{
						ASS.Error("Failed to load " + Path.GetFileName(text) + ": " + ex.Message);
						num--;
					}
				}
				num++;
			}
			ASS.LogVerbose(num + " .asb Files Loaded");
		}

		private static string[] GetSkinNames()
		{
			if (Directory.Exists(_skinDirectory))
			{
				return (from f in Directory.GetFiles(_skinDirectory, "*.*", SearchOption.TopDirectoryOnly)
					where f.EndsWith(".bundle", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".asb", StringComparison.OrdinalIgnoreCase)
					select f).Select(Path.GetFileName).ToArray();
			}
			Directory.CreateDirectory(_skinDirectory);
			return Array.Empty<string>();
		}

		private static void RegisterModShaderFeatures()
		{
			RegisterShaderFeature<CurrentVelocity>();
			RegisterShaderFeature<TimeSinceLastModified>();
			RegisterShaderFeature<TimeSinceLastPose>();
			RegisterShaderFeature<TimeSinceGroundStateChanged>();
			RegisterShaderFeature<TimeSinceHitstop>();
			RegisterShaderFeature<TimeSinceLocalDamageTaken>();
			RegisterShaderFeature<TimeSinceRemoteDamageTaken>();
			RegisterShaderFeature<LastLocalDamageTaken>();
			RegisterShaderFeature<LastRemoteDamageTaken>();
			RegisterShaderFeature<IsHost>();
			RegisterShaderFeature<IsExplodeApplied>();
			RegisterShaderFeature<TimeSinceExplodeApplied>();
			RegisterShaderFeature<LocalPlayerPosition>();
			RegisterShaderFeature<ClosestRemotePlayerPosition>();
			RegisterShaderFeature<TimeSinceHitByExplosion>();
			RegisterShaderFeature<LastExplosionStrength>();
			RegisterShaderFeature<SmoothVelocity>();
		}

		public static void RegisterShaderFeature<T>() where T : ShaderFeature
		{
			if (!ShaderFeatures.Contains(typeof(T)))
			{
				ShaderFeatures.Add(typeof(T));
			}
			else
			{
				ASS.Warn("Tried registering second " + typeof(T).Name + " ShaderFeature, ignored request.");
			}
		}

		public static Dictionary<Type, ShaderFeature> GetFeaturesFor(AdvancedSkin skin)
		{
			return ShaderFeatures.ToDictionary((Type t) => t, delegate(Type t)
			{
				ConstructorInfo constructor = t.GetConstructor(new Type[1] { typeof(AdvancedSkin) });
				if (constructor != null)
				{
					return (ShaderFeature)constructor.Invoke(new object[1] { skin });
				}
				ASS.Error("Could not locate \"AdvancedSkin target\" Constructor for " + t.FullName);
				return null;
			});
		}

		internal static string Serialize()
		{
			List<string> list = new List<string>();
			list.Add("[Shader Settings]");
			list.Add("Shader Groups=" + ShaderGroups);
			list.Add("");
			list.Add("[Shaders]");
			list.AddRange(Shaders.Select((AssShader shader) => shader.name + "=" + shader.enabledForStructure));
			list.Add("");
			list.Add("[Textures]");
			list.AddRange(TextureSets.Select((AssTextureSet textures) => $"{textures.name}={textures.enabledForStructure}"));
			list.Add("");
			return string.Join("\n", list);
		}

		private static void Deserialize(string text)
		{
			Shaders.RemoveAll((AssShader x) => x == null);
			Dictionary<string, AssShader> dictionary = Shaders.Where((AssShader x) => x != null && !string.IsNullOrEmpty(x.name)).ToDictionary((AssShader x) => x.name, (AssShader x) => x);
			string text2 = "";
			string[] array = text.Split('\n');
			string[] array2 = array;
			foreach (string text3 in array2)
			{
				string text4 = text3.Trim();
				if (string.IsNullOrEmpty(text4))
				{
					continue;
				}
				if (text4.StartsWith("[") && text4.EndsWith("]"))
				{
					text2 = text4.Substring(1, text4.Length - 2);
					continue;
				}
				int num = text4.IndexOf('=');
				if (num <= 0)
				{
					continue;
				}
				string key = text4.Substring(0, num).Trim();
				string text5 = text4;
				int num2 = num + 1;
				string s = text5.Substring(num2, text5.Length - num2).Trim();
				switch (text2)
				{
				case "Shader Settings":
				{
					string text6 = key;
					string text7 = text6;
					if (text7 == "Shader Groups")
					{
						ShaderGroups = byte.Parse(s);
					}
					break;
				}
				case "Shaders":
				{
					if (dictionary.TryGetValue(key, out var value))
					{
						value.enabledForStructure = byte.Parse(s);
					}
					break;
				}
				case "Textures":
				{
					AssTextureSet assTextureSet = TextureSets.FirstOrDefault((AssTextureSet t) => t.name == key);
					if (assTextureSet != null)
					{
						assTextureSet.enabledForStructure = byte.Parse(s);
					}
					break;
				}
				}
			}
		}

		public static string SyncUI(string text)
		{
			if (!string.IsNullOrEmpty(text))
			{
				Deserialize(text);
			}
			return Serialize();
		}

		private static AssShader LoadShaderFromBundle(AssetBundle bundle)
		{
			return ((Il2CppArrayBase<string>)(object)bundle.GetAllAssetNames()).Contains("material") ? new AssShader(Path.GetFileNameWithoutExtension(((Object)bundle).name), bundle) : null;
		}

		private static AssShader LoadShaderFromManifest(SkinManifest manifest)
		{
			return new AssShader(manifest);
		}

		public static byte GetStructureFlag(int index)
		{
			if (1 == 0)
			{
			}
			byte result = index switch
			{
				0 => 1, 
				1 => 2, 
				2 => 4, 
				3 => 8, 
				4 => 16, 
				5 => 32, 
				6 => 64, 
				7 => 128, 
				_ => 0, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		public static AssShader[] GetShadersFor(byte type)
		{
			AssShader[] array = (((type & ShaderGroups) == 0) ? Shaders.Where((AssShader shader) => (shader.enabledForStructure & 0x80u) != 0 && (!UIHandler.CompMode.Value || shader.allowedInComp)).ToArray() : Shaders.Where((AssShader shader) => (shader.enabledForStructure & type) != 0 && (!UIHandler.CompMode.Value || shader.allowedInComp)).ToArray());
			if (array.Length != 0)
			{
				return array;
			}
			return new AssShader[1] { GetDefaultShaderFor(type) };
		}

		private static void CreatePlaceholderDefaultShaders()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected I4, but got Unknown
			foreach (StructureFlags value in Enum.GetValues(typeof(StructureFlags)))
			{
				if ((int)value != 0 && (int)value != 128)
				{
					Shaders.Add(new AssShader($"Default_{value}", (byte)(int)value));
				}
			}
		}

		public static AssShader GetDefaultShaderFor(byte type)
		{
			return Shaders.FirstOrDefault((AssShader shader) => (shader.defaultShaderFor & type) != 0);
		}

		private static void LoadTextureSets()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			TextureSets.Clear();
			if (!Directory.Exists(_skinDirectory))
			{
				Directory.CreateDirectory(_skinDirectory);
			}
			string[] directories = Directory.GetDirectories(_skinDirectory);
			foreach (string text in directories)
			{
				string fileName = Path.GetFileName(text);
				if (StructureFlagMap.TryGetValue(fileName, out var value))
				{
					LoadStructureDirectory(text, value);
				}
			}
			ASS.Log($"Loaded {TextureSets.Count} texture sets.");
		}

		private static void LoadStructureDirectory(string structurePath, StructureFlags target)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected I4, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected I4, but got Unknown
			if (AssTextureSet.IsSingleSkin(structurePath))
			{
				TextureSets.Add(new AssTextureSet(structurePath, (byte)(int)target));
			}
			else if (AssTextureSet.IsMultiSkin(structurePath))
			{
				string[] directories = Directory.GetDirectories(structurePath);
				foreach (string folderPath in directories)
				{
					TextureSets.Add(new AssTextureSet(folderPath, (byte)(int)target));
				}
			}
		}

		private static void BuildTextureCache()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_004b: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			TextureSetsByTarget.Clear();
			foreach (StructureFlags value in Enum.GetValues(typeof(StructureFlags)))
			{
				if ((int)value != 0 && (int)value != 128)
				{
					TextureSetsByTarget[value] = new List<AssTextureSet>();
				}
			}
			foreach (AssTextureSet set in TextureSets)
			{
				foreach (StructureFlags item in TextureSetsByTarget.Keys.Where((StructureFlags targetFlag) => (set.targets & targetFlag) > 0))
				{
					TextureSetsByTarget[item].Add(set);
				}
			}
		}

		public static AssTextureSet[] GetEnabledTextureSetsForStructure(StructureFlags structureType)
		{
			//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)
			//IL_0014: 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)
			AssTextureSet[] array = TextureSetsByTarget[structureType].Where((AssTextureSet set) => (set.enabledForStructure & structureType) > 0).ToArray();
			if (array.Length != 0)
			{
				return array;
			}
			return TextureSetsByTarget[structureType].Where((AssTextureSet set) => set.isDefaultTextureSet).ToArray();
		}

		public static AssTextureSet GetDefaultTextureSetFor(StructureFlags structureType)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return TextureSetsByTarget[structureType].FirstOrDefault((AssTextureSet set) => set.isDefaultTextureSet);
		}

		private static void CreatePlaceholderDefaultTextures()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected I4, but got Unknown
			foreach (StructureFlags value in Enum.GetValues(typeof(StructureFlags)))
			{
				if ((int)value != 0 && (int)value != 128)
				{
					TextureSets.Add(new AssTextureSet($"Default_{value}", (byte)(int)value, isDefault: true));
				}
			}
		}

		private static AssTextureSet[] LoadTextureSetsFromManifest(SkinManifest manifest)
		{
			return manifest.textures.Select((TextureSetManifest setManifest) => new AssTextureSet(setManifest)).ToArray();
		}
	}
	[Serializable]
	public class AssShader
	{
		public readonly string name;

		public Texture previewTexture;

		public List<ShaderManifest> shaders = new List<ShaderManifest>();

		public byte enabledForStructure;

		public bool initialized = false;

		public byte defaultShaderFor = 0;

		public bool allowedInComp = true;

		public AssShader(SkinManifest manifest)
		{
			name = manifest.skinName;
			enabledForStructure = 0;
			previewTexture = manifest.previewTexture;
			shaders = manifest.shaders;
			allowedInComp = manifest.allowedInComp;
			initialized = true;
		}

		public AssShader(string name, byte defaultFor)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			this.name = name;
			enabledForStructure = 0;
			shaders.Add(new ShaderManifest
			{
				overrides = new List<MaterialPropertyOverride>()
			});
			defaultShaderFor = defaultFor;
		}

		public AssShader(string name, AssetBundle bundle)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			foreach (string item in (Il2CppArrayBase<string>)(object)bundle.AllAssetNames())
			{
				ASS.LogVerbose(item);
			}
			this.name = name;
			enabledForStructure = 0;
			TextAsset val = bundle.LoadAsset<TextAsset>("overrides");
			shaders = new List<ShaderManifest>
			{
				new ShaderManifest
				{
					material = bundle.LoadAsset<Material>("material"),
					overrides = ReadDataFile(((Object)(object)val != (Object)null) ? val.text : "").ToList()
				}
			};
			((Object)shaders[0].material).hideFlags = (HideFlags)32;
			initialized = true;
		}

		private static List<MaterialPropertyOverride> ReadDataFile(string data)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected I4, but got Unknown
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			List<MaterialPropertyOverride> list = new List<MaterialPropertyOverride>();
			if (string.IsNullOrEmpty(data))
			{
				return list;
			}
			string[] array = data.Split("|");
			int num = 0;
			while (num < array.Length - 1)
			{
				MaterialPropertyOverride val = new MaterialPropertyOverride
				{
					propertyName = array[num]
				};
				num++;
				val.propertyType = (ShaderPropertyType)int.Parse(array[num]);
				num++;
				switch ((int)val.propertyType)
				{
				case 0:
					val.colorValue.r = float.Parse(array[num]);
					val.colorValue.g = float.Parse(array[num + 1]);
					val.colorValue.b = float.Parse(array[num + 2]);
					val.colorValue.a = float.Parse(array[num + 3]);
					num += 4;
					break;
				case 1:
					val.vectorValue.x = float.Parse(array[num]);
					val.vectorValue.y = float.Parse(array[num + 1]);
					val.vectorValue.z = float.Parse(array[num + 2]);
					val.vectorValue.w = float.Parse(array[num + 3]);
					num += 4;
					break;
				case 2:
				case 3:
					val.floatValue = float.Parse(array[num]);
					num++;
					break;
				case 4:
					ASS.Error("What? How did you even build a texture in your overrides? Dude, this feature isn't even implemented yet..");
					break;
				case 5:
					val.intValue = int.Parse(array[num]);
					num++;
					break;
				}
				int num2 = int.Parse(array[num]);
				num++;
				for (int i = 0; i < num2; i++)
				{
					val.targetStructures = (StructureFlags)(val.targetStructures | (byte)(1 << int.Parse(array[num])));
					num++;
				}
				list.Add(val);
			}
			return list;
		}
	}
	[Serializable]
	public class AssTextureSet
	{
		public string name;

		public Texture previewTexture;

		public byte targets;

		public byte enabledForStructure;

		public bool initialized = false;

		public bool isDefaultTextureSet = false;

		private readonly Dictionary<TextureType, List<Texture>> _textures = new Dictionary<TextureType, List<Texture>>();

		private static readonly Random Random = new Random();

		public AssTextureSet(string name, byte targets, bool isDefault)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			this.name = name;
			this.targets = targets;
			enabledForStructure = 0;
			isDefaultTextureSet = isDefault;
			foreach (TextureType item in Enum.GetValues(typeof(TextureType)).Cast<TextureType>())
			{
				_textures[item] = new List<Texture>();
			}
		}

		public AssTextureSet(string folderPath, byte targets)
		{
			name = GetSkinName(folderPath);
			this.targets = targets;
			enabledForStructure = 0;
			Load(folderPath);
			initialized = true;
		}

		public AssTextureSet(TextureSetManifest manifest)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected I4, but got Unknown
			name = manifest.name;
			targets = (byte)(int)manifest.targets;
			enabledForStructure = 0;
			previewTexture = manifest.previewTexture;
			_textures = LoadFromManifest(manifest);
		}

		private void Load(string folderPath)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			foreach (TextureType value in Enum.GetValues(typeof(TextureType)))
			{
				_textures[value] = LoadTextureGroup(folderPath, value);
			}
		}

		public static bool DirectoryContainsTextures(string path)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			foreach (TextureType value in Enum.GetValues(typeof(TextureType)))
			{
				TextureType val = value;
				string path2 = Path.Combine(path, ((object)(TextureType)(ref val)).ToString() + ".png");
				if (File.Exists(path2))
				{
					return true;
				}
				string path3 = Path.Combine(path, ((object)(TextureType)(ref val)).ToString());
				if (Directory.Exists(path3))
				{
					return true;
				}
			}
			return false;
		}

		private static bool DirectoryContainsTypedFolders(string path)
		{
			return Enum.GetValues(typeof(TextureType)).Cast<TextureType>().Select(delegate(TextureType type)
			{
				//IL_0006: 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)
				string path2 = path;
				TextureType val = type;
				return Directory.Exists(Path.Combine(path2, ((object)(TextureType)(ref val)).ToString()));
			})
				.FirstOrDefault();
		}

		private static bool IsSingleSkinSingleTexture(string path)
		{
			return Enum.GetValues(typeof(TextureType)).Cast<TextureType>().Any((TextureType type) => File.Exists(Path.Combine(path, ((object)(TextureType)(ref type)).ToString() + ".png")));
		}

		private static bool IsMultiSkinSingleTexture(string path)
		{
			return !DirectoryContainsTypedFolders(path) && (from <>h__TransparentIdentifier0 in (from dir in Directory.GetDirectories(path)
					from type in Enum.GetValues(typeof(TextureType)).Cast<TextureType>()
					select new { dir, type }).Where(<>h__TransparentIdentifier0 =>
				{
					//IL_0007: 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)
					string dir2 = <>h__TransparentIdentifier0.dir;
					TextureType type2 = <>h__TransparentIdentifier0.type;
					return dir2.Contains(((object)(TextureType)(ref type2)).ToString());
				})
				select <>h__TransparentIdentifier0.dir).Any();
		}

		private static bool IsSingleSkinMultiTexture(string path)
		{
			return Enum.GetValues(typeof(TextureType)).Cast<TextureType>().Any((TextureType type) => Directory.Exists(Path.Combine(path, ((object)(TextureType)(ref type)).ToString())));
		}

		private static bool IsMultiSkinMultiTexture(string path)
		{
			return !DirectoryContainsTypedFolders(path) && Directory.GetDirectories(path).Any(IsSingleSkinMultiTexture);
		}

		public static bool IsSingleSkin(string path)
		{
			return IsSingleSkinSingleTexture(path) || IsSingleSkinMultiTexture(path);
		}

		public static bool IsMultiSkin(string path)
		{
			return IsMultiSkinSingleTexture(path) || IsMultiSkinMultiTexture(path);
		}

		private List<Texture> LoadTextureGroup(string folderPath, TextureType type)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			List<Texture> list = new List<Texture>();
			if (IsSingleSkinSingleTexture(folderPath))
			{
				Texture2D val = LoadSingleTexture(folderPath, type);
				if ((Object)(object)val != (Object)null)
				{
					list.Add((Texture)(object)val);
				}
				return list;
			}
			if (IsSingleSkinMultiTexture(folderPath))
			{
				list.AddRange((IEnumerable<Texture>)(object)LoadMultiTexture(folderPath, type));
				return list;
			}
			ASS.Error("Invalid UserData/Skins/ folder structure detected. Please contact @cxntrxl on Discord if you need help.");
			return list;
		}

		private static Texture2D LoadSingleTexture(string folderPath, TextureType type)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			string text = ((object)(TextureType)(ref type)).ToString();
			string path = Path.Combine(folderPath, text + ".png");
			return LoadTexture(path, type);
		}

		private static Texture2D[] LoadMultiTexture(string folderPath, TextureType type)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			List<Texture2D> list = new List<Texture2D>();
			string path = ((object)(TextureType)(ref type)).ToString();
			string path2 = Path.Combine(folderPath, path);
			string[] files = Directory.GetFiles(path2);
			foreach (string text in files)
			{
				if (text.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
				{
					Texture2D val = LoadTexture(text, type);
					if ((Object)(object)val != (Object)null)
					{
						list.Add(val);
					}
				}
			}
			return l

UserLibs/AdvancedStructureSkins.Shared.dll

Decompiled 2 weeks ago
using System;
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 UnityEngine;
using UnityEngine.Rendering;

[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 = "")]
[assembly: AssemblyCompany("AdvancedStructureSkins.Shared")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AdvancedStructureSkins.Shared")]
[assembly: AssemblyTitle("AdvancedStructureSkins.Shared")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AdvancedStructureSkins.Shared.SDK
{
	[Serializable]
	public class MaterialPropertyOverride
	{
		public string propertyName = "";

		public ShaderPropertyType propertyType;

		public Color colorValue;

		public float floatValue;

		public int intValue;

		public Vector4 vectorValue;

		public Texture textureValue;

		public StructureFlags targetStructures;
	}
	public enum StructureType
	{
		Disc,
		Pillar,
		Ball,
		Cube,
		Wall,
		SmallRock,
		LargeRock
	}
	[Serializable]
	public class MaterialPropertyOverrideManifest
	{
		public List<MaterialPropertyOverride> overrides;
	}
	[Serializable]
	public class ShaderManifest
	{
		public Material material;

		public List<MaterialPropertyOverride> overrides;
	}
	public class SkinManifest : ScriptableObject
	{
		public string skinName;

		public Texture previewTexture;

		public bool allowedInComp;

		public List<ShaderManifest> shaders;

		public List<TextureSetManifest> textures;
	}
	[Flags]
	public enum StructureFlags : byte
	{
		None = 0,
		Disc = 1,
		Pillar = 2,
		Ball = 4,
		Cube = 8,
		Wall = 0x10,
		SmallRock = 0x20,
		LargeRock = 0x40,
		Global = 0x80
	}
	[Serializable]
	public class TextureSetManifest
	{
		public string name;

		public Texture previewTexture;

		public List<TextureEntry> textures = new List<TextureEntry>();

		public StructureFlags targets;
	}
	[Serializable]
	public class TextureEntry
	{
		public TextureType type;

		public List<Texture> textures;
	}
	public enum TextureType
	{
		Main,
		Normal,
		Mat,
		Ground
	}
}
namespace AdvancedStructureSkins.Shared.SDK.Binary
{
	public class BinaryHandler
	{
		public static byte[] Write(SkinManifest manifest)
		{
			using MemoryStream memoryStream = new MemoryStream();
			using BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
			binaryWriter.Write(1);
			binaryWriter.Write(string.IsNullOrEmpty(manifest.skinName) ? ((Object)manifest).name : manifest.skinName);
			binaryWriter.Write(((Object)(object)manifest.previewTexture != (Object)null) ? ((Object)manifest.previewTexture).name : "");
			binaryWriter.Write(manifest.allowedInComp);
			binaryWriter.Write(manifest.shaders?.Count ?? 0);
			if (manifest.shaders != null)
			{
				foreach (ShaderManifest shader in manifest.shaders)
				{
					WriteShaderManifest(binaryWriter, shader);
				}
			}
			binaryWriter.Write(manifest.textures?.Count ?? 0);
			if (manifest.textures != null)
			{
				foreach (TextureSetManifest texture in manifest.textures)
				{
					WriteTextureSet(binaryWriter, texture);
				}
			}
			return memoryStream.ToArray();
		}

		public static void WriteShaderManifest(BinaryWriter writer, ShaderManifest manifest)
		{
			Material material = manifest.material;
			writer.Write(((material != null) ? ((Object)material).name : null) ?? "");
			writer.Write(manifest.overrides?.Count ?? 0);
			if (manifest.overrides == null)
			{
				return;
			}
			foreach (MaterialPropertyOverride @override in manifest.overrides)
			{
				WriteOverride(writer, @override);
			}
		}

		private static void WriteOverride(BinaryWriter writer, MaterialPropertyOverride o)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(o.propertyName ?? "");
			writer.Write((byte)o.propertyType);
			writer.Write(o.colorValue.r);
			writer.Write(o.colorValue.g);
			writer.Write(o.colorValue.b);
			writer.Write(o.colorValue.a);
			writer.Write(o.floatValue);
			writer.Write(o.intValue);
			writer.Write(o.vectorValue.x);
			writer.Write(o.vectorValue.y);
			writer.Write(o.vectorValue.z);
			writer.Write(o.vectorValue.w);
			writer.Write(((Object)(object)o.textureValue == (Object)null) ? string.Empty : ((Object)o.textureValue).name);
			writer.Write((byte)o.targetStructures);
		}

		private static void WriteTextureSet(BinaryWriter writer, TextureSetManifest t)
		{
			writer.Write(t.name);
			writer.Write(((Object)(object)t.previewTexture != (Object)null) ? ((Object)t.previewTexture).name : "");
			writer.Write(t.textures?.Count ?? 0);
			if (t.textures != null)
			{
				foreach (TextureEntry texture in t.textures)
				{
					WriteTextureEntry(writer, texture);
				}
			}
			writer.Write((byte)t.targets);
		}

		private static void WriteTextureEntry(BinaryWriter writer, TextureEntry e)
		{
			writer.Write((byte)e.type);
			writer.Write(e.textures?.Count ?? 0);
			if (e.textures == null)
			{
				return;
			}
			foreach (Texture texture in e.textures)
			{
				writer.Write(((Object)(object)texture != (Object)null) ? ((Object)texture).name : string.Empty);
			}
		}

		public static SkinManifestBinary Read(byte[] bytes)
		{
			using (MemoryStream input = new MemoryStream(bytes))
			{
				using BinaryReader binaryReader = new BinaryReader(input);
				int num = binaryReader.ReadInt32();
				int num2 = num;
				if (num2 == 1)
				{
					return ReadV1Manifest(binaryReader);
				}
			}
			return null;
		}

		private static SkinManifestBinary ReadV1Manifest(BinaryReader reader)
		{
			SkinManifestBinary skinManifestBinary = new SkinManifestBinary();
			skinManifestBinary.skinName = reader.ReadString();
			skinManifestBinary.previewTextureName = reader.ReadString();
			skinManifestBinary.allowedInComp = reader.ReadBoolean();
			int num = reader.ReadInt32();
			skinManifestBinary.shaders = new ShaderManifestBinary[num];
			for (int i = 0; i < num; i++)
			{
				skinManifestBinary.shaders[i] = ReadShaderManifest(reader);
			}
			int num2 = reader.ReadInt32();
			skinManifestBinary.textures = new TextureSetBinary[num2];
			for (int j = 0; j < num2; j++)
			{
				skinManifestBinary.textures[j] = ReadTextureSet(reader);
			}
			return skinManifestBinary;
		}

		private static ShaderManifestBinary ReadShaderManifest(BinaryReader reader)
		{
			ShaderManifestBinary shaderManifestBinary = new ShaderManifestBinary();
			shaderManifestBinary.materialName = reader.ReadString();
			int num = reader.ReadInt32();
			shaderManifestBinary.overrides = new MaterialOverrideBinary[num];
			for (int i = 0; i < num; i++)
			{
				shaderManifestBinary.overrides[i] = ReadOverride(reader);
			}
			return shaderManifestBinary;
		}

		private static MaterialOverrideBinary ReadOverride(BinaryReader reader)
		{
			//IL_001a: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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)
			MaterialOverrideBinary materialOverrideBinary = new MaterialOverrideBinary();
			materialOverrideBinary.propertyName = reader.ReadString();
			materialOverrideBinary.type = (ShaderPropertyType)reader.ReadByte();
			float num = reader.ReadSingle();
			float num2 = reader.ReadSingle();
			float num3 = reader.ReadSingle();
			float num4 = reader.ReadSingle();
			materialOverrideBinary.colorValue = new Color(num, num2, num3, num4);
			materialOverrideBinary.floatValue = reader.ReadSingle();
			materialOverrideBinary.intValue = reader.ReadInt32();
			float num5 = reader.ReadSingle();
			float num6 = reader.ReadSingle();
			float num7 = reader.ReadSingle();
			float num8 = reader.ReadSingle();
			materialOverrideBinary.vectorValue = new Vector4(num5, num6, num7, num8);
			materialOverrideBinary.textureValue = reader.ReadString();
			materialOverrideBinary.targetStructures = (StructureFlags)reader.ReadByte();
			return materialOverrideBinary;
		}

		private static TextureSetBinary ReadTextureSet(BinaryReader reader)
		{
			TextureSetBinary textureSetBinary = new TextureSetBinary();
			textureSetBinary.name = reader.ReadString();
			textureSetBinary.previewTextureName = reader.ReadString();
			int num = reader.ReadInt32();
			textureSetBinary.textures = new TextureEntryBinary[num];
			for (int i = 0; i < num; i++)
			{
				textureSetBinary.textures[i] = ReadTextureEntry(reader);
			}
			textureSetBinary.targets = (StructureFlags)reader.ReadByte();
			return textureSetBinary;
		}

		private static TextureEntryBinary ReadTextureEntry(BinaryReader reader)
		{
			TextureEntryBinary textureEntryBinary = new TextureEntryBinary();
			textureEntryBinary.type = (TextureType)reader.ReadByte();
			int num = reader.ReadInt32();
			textureEntryBinary.textures = new string[num];
			for (int i = 0; i < num; i++)
			{
				textureEntryBinary.textures[i] = reader.ReadString();
			}
			return textureEntryBinary;
		}
	}
	public class MaterialOverrideBinary
	{
		public string propertyName;

		public ShaderPropertyType type;

		public float floatValue;

		public int intValue;

		public Color colorValue;

		public Vector4 vectorValue;

		public string textureValue;

		public StructureFlags targetStructures;

		public MaterialPropertyOverride GetOverrideFromBundle(AssetBundle bundle)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected I4, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			MaterialPropertyOverride materialPropertyOverride = new MaterialPropertyOverride
			{
				propertyName = propertyName,
				propertyType = type,
				targetStructures = targetStructures
			};
			ShaderPropertyType val = type;
			ShaderPropertyType val2 = val;
			switch ((int)val2)
			{
			case 0:
				materialPropertyOverride.colorValue = colorValue;
				break;
			case 1:
				materialPropertyOverride.vectorValue = vectorValue;
				break;
			case 2:
			case 3:
				materialPropertyOverride.floatValue = floatValue;
				break;
			case 4:
				materialPropertyOverride.textureValue = GetTextureFromBundle(bundle);
				((Object)materialPropertyOverride.textureValue).hideFlags = (HideFlags)32;
				break;
			case 5:
				materialPropertyOverride.intValue = intValue;
				break;
			}
			return materialPropertyOverride;
		}

		public Texture GetTextureFromBundle(AssetBundle bundle)
		{
			if (string.IsNullOrEmpty(textureValue))
			{
				return null;
			}
			string text = ((IEnumerable<string>)bundle.GetAllAssetNames()).FirstOrDefault((string n) => n.EndsWith(textureValue, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				return null;
			}
			return bundle.LoadAsset<Texture>(text);
		}
	}
	public class ShaderManifestBinary
	{
		public string materialName;

		public MaterialOverrideBinary[] overrides;

		public ShaderManifest GetShaderManifestFromBundle(AssetBundle bundle)
		{
			ShaderManifest shaderManifest = new ShaderManifest();
			string text = ((IEnumerable<string>)bundle.GetAllAssetNames()).FirstOrDefault((string n) => n.EndsWith(materialName, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				return null;
			}
			Material val = bundle.LoadAsset<Material>(text);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			((Object)val).hideFlags = (HideFlags)32;
			shaderManifest.material = val;
			shaderManifest.overrides = new List<MaterialPropertyOverride>();
			MaterialOverrideBinary[] array = overrides;
			foreach (MaterialOverrideBinary materialOverrideBinary in array)
			{
				shaderManifest.overrides.Add(materialOverrideBinary.GetOverrideFromBundle(bundle));
			}
			return shaderManifest;
		}
	}
	[Serializable]
	public class SkinManifestBinary
	{
		public string skinName;

		public string previewTextureName;

		public bool allowedInComp;

		public ShaderManifestBinary[] shaders;

		public TextureSetBinary[] textures;

		public SkinManifest GetSkinManifestFromBundle(AssetBundle bundle)
		{
			SkinManifest manifest = ScriptableObject.CreateInstance<SkinManifest>();
			manifest.skinName = skinName;
			manifest.previewTexture = GetTextureFromBundle(bundle);
			manifest.allowedInComp = allowedInComp;
			manifest.shaders = GetShaderManifestListFromBundle(bundle);
			manifest.textures = textures.Select((TextureSetBinary t) => t.GetManifestFromBundle(bundle)).ToList();
			manifest.textures.ForEach(delegate(TextureSetManifest t)
			{
				if ((Object)(object)t.previewTexture == (Object)null)
				{
					t.previewTexture = manifest.previewTexture;
				}
			});
			return manifest;
		}

		public List<ShaderManifest> GetShaderManifestListFromBundle(AssetBundle bundle)
		{
			List<ShaderManifest> list = new List<ShaderManifest>();
			ShaderManifestBinary[] array = shaders;
			foreach (ShaderManifestBinary shaderManifestBinary in array)
			{
				list.Add(shaderManifestBinary.GetShaderManifestFromBundle(bundle));
			}
			return list;
		}

		public Texture GetTextureFromBundle(AssetBundle bundle)
		{
			string text = ((IEnumerable<string>)bundle.GetAllAssetNames()).FirstOrDefault((string n) => n.EndsWith(previewTextureName, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				return null;
			}
			Texture val = bundle.LoadAsset<Texture>(text);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			((Object)val).hideFlags = (HideFlags)61;
			return val;
		}
	}
	[Serializable]
	public class MaterialOverrideBinaryArray
	{
		public MaterialOverrideBinary[] overrides;

		public MaterialPropertyOverrideManifest GetOverrideManifestFromBundle(AssetBundle bundle)
		{
			return new MaterialPropertyOverrideManifest
			{
				overrides = overrides.Select((MaterialOverrideBinary ob) => ob.GetOverrideFromBundle(bundle)).ToList()
			};
		}
	}
	public class TextureSetBinary
	{
		public string name;

		public string previewTextureName;

		public TextureEntryBinary[] textures;

		public StructureFlags targets;

		public TextureSetManifest GetManifestFromBundle(AssetBundle bundle)
		{
			TextureSetManifest textureSetManifest = new TextureSetManifest
			{
				name = name,
				previewTexture = GetPreviewTextureFromBundle(bundle),
				targets = targets,
				textures = new List<TextureEntry>()
			};
			TextureEntryBinary[] array = textures;
			foreach (TextureEntryBinary textureEntryBinary in array)
			{
				TextureEntry textureEntry = new TextureEntry
				{
					type = textureEntryBinary.type,
					textures = new List<Texture>()
				};
				string[] array2 = textureEntryBinary.textures;
				foreach (string assetName in array2)
				{
					if (string.IsNullOrEmpty(assetName))
					{
						continue;
					}
					string text = ((IEnumerable<string>)bundle.GetAllAssetNames()).FirstOrDefault((string n) => n.EndsWith(assetName, StringComparison.OrdinalIgnoreCase));
					if (text != null)
					{
						Texture val = bundle.LoadAsset<Texture>(text);
						if ((Object)(object)val != (Object)null)
						{
							textureEntry.textures.Add(val);
						}
					}
				}
				textureSetManifest.textures.Add(textureEntry);
			}
			return textureSetManifest;
		}

		public Texture GetPreviewTextureFromBundle(AssetBundle bundle)
		{
			string text = ((IEnumerable<string>)bundle.GetAllAssetNames()).FirstOrDefault((string n) => n.EndsWith(previewTextureName, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				return null;
			}
			Texture val = bundle.LoadAsset<Texture>(text);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			((Object)val).hideFlags = (HideFlags)61;
			return val;
		}
	}
	public class TextureEntryBinary
	{
		public TextureType type;

		public string[] textures;
	}
}