Decompiled source of Manto do Corvo v0.3.0

plugins/RavenCloak.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was created with the assistance of Generative AI (code generation).")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic (Claude)")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RavenCloak
{
	[BepInPlugin("pandherya.ravencloak", "Manto do Corvo (Pandherya)", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "pandherya.ravencloak";

		public const string ItemPrefab = "CapeRavenPandherya";

		public const string ZInvis = "rc_invis";

		internal static ConfigEntry<float> Duration;

		internal static ConfigEntry<float> Cooldown;

		internal static ConfigEntry<float> SelfAlpha;

		internal static ConfigEntry<bool> BreakOnAttack;

		internal static ConfigEntry<bool> HideFromPlayers;

		internal static ConfigEntry<bool> PetInvisible;

		internal static ManualLogSource Log;

		internal static StatusEffect SeInvis;

		internal static StatusEffect SeCooldown;

		internal static int SeInvisHash;

		internal static int SeCooldownHash;

		private bool _wasCrouching;

		private bool _wasInvis;

		private static volatile bool _reload;

		private float _reloadAt;

		private static Type _companionType;

		private static bool _companionSearched;

		private static Object[] _pets = (Object[])(object)new Object[0];

		private static float _petsScan;

		internal static ConfigurationManagerAttributes Admin()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			return new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
		}

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Duration = ((BaseUnityPlugin)this).Config.Bind<float>("Manto", "DuracaoInvisivel", 30f, new ConfigDescription("Segundos de invisibilidade.", (AcceptableValueBase)null, new object[1] { Admin() }));
			Cooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Manto", "Recarga", 120f, new ConfigDescription("Segundos até poder usar de novo (contando a partir do fim da invisibilidade).", (AcceptableValueBase)null, new object[1] { Admin() }));
			BreakOnAttack = ((BaseUnityPlugin)this).Config.Bind<bool>("Manto", "QuebraAoAtacar", true, new ConfigDescription("true = atacar encerra a invisibilidade na hora.", (AcceptableValueBase)null, new object[1] { Admin() }));
			HideFromPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Manto", "InvisivelParaJogadores", true, new ConfigDescription("true = outros jogadores também deixam de te ver.", (AcceptableValueBase)null, new object[1] { Admin() }));
			PetInvisible = ((BaseUnityPlugin)this).Config.Bind<bool>("Manto", "CompanheiroInvisivel", true, new ConfigDescription("true = o companheiro do Northarun (corvo, lobo...) fica invisível junto com você. false = continua visível.", (AcceptableValueBase)null, new object[1] { Admin() }));
			SelfAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("Manto", "TransparenciaParaVoce", 0.3f, "Quanto você se vê enquanto invisível (0 = nada, 1 = normal).");
			try
			{
				FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, "pandherya.ravencloak.cfg");
				fileSystemWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite;
				fileSystemWatcher.Changed += delegate
				{
					_reload = true;
				};
				fileSystemWatcher.Created += delegate
				{
					_reload = true;
				};
				fileSystemWatcher.Renamed += delegate
				{
					_reload = true;
				};
				fileSystemWatcher.EnableRaisingEvents = true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Sem recarga automática do cfg: " + ex.Message));
			}
			PrefabManager.OnVanillaPrefabsAvailable += AddContent;
			new Harmony("pandherya.ravencloak").PatchAll(typeof(Patches));
		}

		private void AddContent()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected O, but got Unknown
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= AddContent;
			try
			{
				ItemConfig val = new ItemConfig
				{
					Name = "Manto do Corvo",
					Description = "Penas negras tecidas com eitr. Plana como a capa de penas e, ao agachar, esconde quem o veste dos olhos de homens e feras por alguns instantes.",
					CraftingStation = "piece_magetable",
					MinStationLevel = 2
				};
				val.AddRequirement(new RequirementConfig("CapeFeather", 1, 0, false));
				val.AddRequirement(new RequirementConfig("Eitr", 20, 5, true));
				val.AddRequirement(new RequirementConfig("BlackCore", 3, 1, true));
				val.AddRequirement(new RequirementConfig("Feathers", 20, 5, true));
				CustomItem val2 = new CustomItem("CapeRavenPandherya", "CapeFeather", val);
				SharedData shared = val2.ItemDrop.m_itemData.m_shared;
				shared.m_armor = 4f;
				shared.m_armorPerLevel = 1f;
				Tint(val2.ItemPrefab, new Color(0.12f, 0.12f, 0.16f));
				ItemManager.Instance.AddItem(val2);
				Sprite icon = ((shared.m_icons != null && shared.m_icons.Length != 0) ? shared.m_icons[0] : null);
				SeInvis = ScriptableObject.CreateInstance<StatusEffect>();
				((Object)SeInvis).name = "SE_RavenCloakInvis";
				SeInvis.m_name = "Invisível";
				SeInvis.m_tooltip = "Inimigos e outros jogadores não te veem.";
				SeInvis.m_icon = icon;
				SeInvis.m_ttl = Duration.Value;
				SeInvis.m_startMessageType = (MessageType)1;
				SeInvis.m_startMessage = "As penas do corvo te envolvem...";
				ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(SeInvis, false));
				SeCooldown = ScriptableObject.CreateInstance<StatusEffect>();
				((Object)SeCooldown).name = "SE_RavenCloakCooldown";
				SeCooldown.m_name = "Manto recarregando";
				SeCooldown.m_tooltip = "O Manto do Corvo ainda não pode ser usado.";
				SeCooldown.m_icon = icon;
				SeCooldown.m_ttl = Cooldown.Value;
				ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(SeCooldown, false));
				SeInvisHash = SeInvis.NameHash();
				SeCooldownHash = SeCooldown.NameHash();
				Log.LogInfo((object)"Manto do Corvo registrado.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Falha ao criar o Manto do Corvo: " + ex));
			}
		}

		private static void Tint(GameObject prefab, Color c)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (val is ParticleSystemRenderer)
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (!((Object)(object)sharedMaterials[j] == (Object)null))
					{
						Material val2 = new Material(sharedMaterials[j]);
						if (val2.HasProperty("_Color"))
						{
							val2.color = c;
						}
						sharedMaterials[j] = val2;
					}
				}
				val.sharedMaterials = sharedMaterials;
			}
		}

		private void Update()
		{
			if (_reload)
			{
				_reload = false;
				_reloadAt = Time.time + 0.3f;
			}
			if (_reloadAt > 0f && Time.time >= _reloadAt)
			{
				_reloadAt = 0f;
				try
				{
					((BaseUnityPlugin)this).Config.Reload();
					Log.LogInfo((object)"Config do manto recarregada.");
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("Falha ao recarregar cfg do manto: " + ex.Message));
				}
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && (Object)(object)SeInvis != (Object)null)
			{
				UpdateLocal(localPlayer);
			}
			UpdateOthers();
		}

		private void UpdateLocal(Player p)
		{
			SEMan sEMan = ((Character)p).GetSEMan();
			bool flag = ((Character)p).IsCrouching();
			bool flag2 = sEMan.HaveStatusEffect(SeInvisHash);
			if (flag && !_wasCrouching && !flag2 && WearingCloak(p) && !sEMan.HaveStatusEffect(SeCooldownHash))
			{
				SeInvis.m_ttl = Duration.Value;
				sEMan.AddStatusEffect(SeInvisHash, true, 0, 0f, (short)(-1));
				flag2 = true;
				DropAggro(p);
			}
			_wasCrouching = flag;
			if (flag2 && (!WearingCloak(p) || (BreakOnAttack.Value && ((Character)p).InAttack())))
			{
				sEMan.RemoveStatusEffect(SeInvisHash, true);
				flag2 = false;
			}
			if (_wasInvis && !flag2)
			{
				SeCooldown.m_ttl = Cooldown.Value;
				sEMan.AddStatusEffect(SeCooldownHash, true, 0, 0f, (short)(-1));
			}
			_wasInvis = flag2;
			ZNetView component = ((Component)p).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO().GetBool("rc_invis", false) != flag2)
			{
				component.GetZDO().Set("rc_invis", flag2);
			}
			Visual.SetTranslucent(((Component)p).gameObject, flag2, Mathf.Clamp01(SelfAlpha.Value));
		}

		private static void UpdatePets()
		{
			if (!_companionSearched)
			{
				_companionSearched = true;
				_companionType = AccessTools.TypeByName("Companions.Companion");
			}
			if (_companionType == null)
			{
				return;
			}
			if (Time.time >= _petsScan)
			{
				_petsScan = Time.time + 1f;
				_pets = Object.FindObjectsOfType(_companionType);
				Visual.Prune();
			}
			Player localPlayer = Player.m_localPlayer;
			Object[] pets = _pets;
			foreach (Object obj in pets)
			{
				Component val = (Component)(object)((obj is Component) ? obj : null);
				if (val == null || (Object)(object)val == (Object)null)
				{
					continue;
				}
				ZNetView component = val.GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid())
				{
					Player player = Player.GetPlayer(component.GetZDO().GetLong("nc_owner", 0L));
					bool flag = PetInvisible.Value && (Object)(object)player != (Object)null && IsInvisible((Character)(object)player);
					if ((Object)(object)player != (Object)null && (Object)(object)player == (Object)(object)localPlayer)
					{
						Visual.SetTranslucent(val.gameObject, flag, Mathf.Clamp01(SelfAlpha.Value));
					}
					else
					{
						Visual.SetHidden(val.gameObject, flag && HideFromPlayers.Value);
					}
				}
			}
		}

		private static void UpdateOthers()
		{
			UpdatePets();
			foreach (Player allPlayer in Player.GetAllPlayers())
			{
				if (!((Object)(object)allPlayer == (Object)null) && !((Object)(object)allPlayer == (Object)(object)Player.m_localPlayer))
				{
					Visual.SetHidden(((Component)allPlayer).gameObject, HideFromPlayers.Value && IsInvisible((Character)(object)allPlayer));
				}
			}
		}

		internal static bool WearingCloak(Player p)
		{
			foreach (ItemData equippedItem in ((Humanoid)p).GetInventory().GetEquippedItems())
			{
				if ((Object)(object)equippedItem?.m_dropPrefab != (Object)null && ((Object)equippedItem.m_dropPrefab).name == "CapeRavenPandherya")
				{
					return true;
				}
			}
			return false;
		}

		internal static bool IsInvisible(Character c)
		{
			if ((Object)(object)c == (Object)null || !c.IsPlayer())
			{
				return false;
			}
			ZNetView component = ((Component)c).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				return component.GetZDO().GetBool("rc_invis", false);
			}
			return false;
		}

		private static void DropAggro(Player p)
		{
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (!((Object)(object)allCharacter == (Object)null) && !allCharacter.IsPlayer())
				{
					BaseAI baseAI = allCharacter.GetBaseAI();
					MonsterAI val = (MonsterAI)(object)((baseAI is MonsterAI) ? baseAI : null);
					if (val != null)
					{
						Patches.ClearTargetIf(val, (Character)(object)p);
					}
				}
			}
		}
	}
	internal static class Patches
	{
		private static readonly FieldRef<MonsterAI, Character> TargetCreature = AccessTools.FieldRefAccess<MonsterAI, Character>("m_targetCreature");

		internal static void ClearTargetIf(MonsterAI m, Character who)
		{
			if ((Object)(object)TargetCreature.Invoke(m) == (Object)(object)who)
			{
				TargetCreature.Invoke(m) = null;
			}
		}

		[HarmonyPatch(typeof(Character), "InGhostMode")]
		[HarmonyPostfix]
		private static void CharGhost(Character __instance, ref bool __result)
		{
			if (!__result && Plugin.IsInvisible(__instance))
			{
				__result = true;
			}
		}

		[HarmonyPatch(typeof(Player), "InGhostMode")]
		[HarmonyPostfix]
		private static void PlayerGhost(Player __instance, ref bool __result)
		{
			if (!__result && Plugin.IsInvisible((Character)(object)__instance))
			{
				__result = true;
			}
		}

		[HarmonyPatch(typeof(BaseAI), "CanSeeTarget", new Type[] { typeof(Character) })]
		[HarmonyPostfix]
		private static void NoSee(Character target, ref bool __result)
		{
			if (__result && Plugin.IsInvisible(target))
			{
				__result = false;
			}
		}

		[HarmonyPatch(typeof(BaseAI), "CanHearTarget", new Type[] { typeof(Character) })]
		[HarmonyPostfix]
		private static void NoHear(Character target, ref bool __result)
		{
			if (__result && Plugin.IsInvisible(target))
			{
				__result = false;
			}
		}

		[HarmonyPatch(typeof(MonsterAI), "UpdateTarget")]
		[HarmonyPostfix]
		private static void ForgetInvisible(MonsterAI __instance)
		{
			Character val = TargetCreature.Invoke(__instance);
			if ((Object)(object)val != (Object)null && Plugin.IsInvisible(val))
			{
				TargetCreature.Invoke(__instance) = null;
			}
		}
	}
	internal static class Visual
	{
		private class Entry
		{
			public Material[] Orig;

			public Material[] Applied;

			public MaterialPropertyBlock Block;

			public bool HadBlock;
		}

		private static readonly Dictionary<GameObject, Dictionary<Renderer, Entry>> _trans = new Dictionary<GameObject, Dictionary<Renderer, Entry>>();

		private static readonly Dictionary<GameObject, float> _transAlpha = new Dictionary<GameObject, float>();

		private static Shader _shader;

		private static bool _shaderSearched;

		private static readonly Dictionary<GameObject, List<Renderer>> _hidden = new Dictionary<GameObject, List<Renderer>>();

		private static Shader FindShader()
		{
			if (_shaderSearched)
			{
				return _shader;
			}
			_shaderSearched = true;
			string[] array = new string[4] { "Legacy Shaders/Particles/Alpha Blended", "Sprites/Default", "Unlit/Transparent", "Legacy Shaders/Transparent/Diffuse" };
			foreach (string text in array)
			{
				_shader = Shader.Find(text);
				if ((Object)(object)_shader != (Object)null)
				{
					Plugin.Log.LogInfo((object)("Translúcido usando shader " + text));
					break;
				}
			}
			if ((Object)(object)_shader == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Nenhum shader transparente encontrado; você não ficará translúcido para si mesmo.");
			}
			return _shader;
		}

		internal static void SetTranslucent(GameObject root, bool on, float alpha)
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			if (!on)
			{
				Restore(root);
				return;
			}
			Shader val = FindShader();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (_transAlpha.TryGetValue(root, out var value) && !Mathf.Approximately(value, alpha))
			{
				Restore(root);
			}
			_transAlpha[root] = alpha;
			if (!_trans.TryGetValue(root, out var value2))
			{
				value2 = (_trans[root] = new Dictionary<Renderer, Entry>());
			}
			Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>();
			foreach (Renderer val2 in componentsInChildren)
			{
				if ((Object)(object)val2 == (Object)null || val2 is ParticleSystemRenderer)
				{
					continue;
				}
				Material[] sharedMaterials = val2.sharedMaterials;
				if (value2.TryGetValue(val2, out var value3))
				{
					if (SameArray(sharedMaterials, value3.Applied) || AllOurs(sharedMaterials))
					{
						value3.Applied = sharedMaterials;
						if (val2.HasPropertyBlock())
						{
							val2.SetPropertyBlock((MaterialPropertyBlock)null);
						}
						continue;
					}
					value3.Orig = sharedMaterials;
				}
				else
				{
					if (AllOurs(sharedMaterials))
					{
						continue;
					}
					value3 = new Entry();
					value3.HadBlock = val2.HasPropertyBlock();
					if (value3.HadBlock)
					{
						value3.Block = new MaterialPropertyBlock();
						val2.GetPropertyBlock(value3.Block);
					}
					value3.Orig = sharedMaterials;
					value2[val2] = value3;
				}
				value3.Applied = MakeTranslucent(val, sharedMaterials, alpha);
				val2.sharedMaterials = value3.Applied;
				val2.SetPropertyBlock((MaterialPropertyBlock)null);
				val2.shadowCastingMode = (ShadowCastingMode)0;
			}
		}

		private static bool IsOurs(Material m)
		{
			if ((Object)(object)m != (Object)null && (Object)(object)_shader != (Object)null)
			{
				return (Object)(object)m.shader == (Object)(object)_shader;
			}
			return false;
		}

		private static bool AllOurs(Material[] a)
		{
			if (a == null || a.Length == 0 || (Object)(object)_shader == (Object)null)
			{
				return false;
			}
			foreach (Material val in a)
			{
				if ((Object)(object)val != (Object)null && !IsOurs(val))
				{
					return false;
				}
			}
			return true;
		}

		private static bool AnyOurs(Material[] a)
		{
			if (a == null)
			{
				return false;
			}
			for (int i = 0; i < a.Length; i++)
			{
				if (IsOurs(a[i]))
				{
					return true;
				}
			}
			return false;
		}

		private static bool SameArray(Material[] a, Material[] b)
		{
			if (a == null || b == null || a.Length != b.Length)
			{
				return false;
			}
			for (int i = 0; i < a.Length; i++)
			{
				if ((Object)(object)a[i] != (Object)(object)b[i])
				{
					return false;
				}
			}
			return true;
		}

		private static Material[] MakeTranslucent(Shader sh, Material[] src, float alpha)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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)
			Material[] array = (Material[])(object)new Material[src.Length];
			Color val2 = default(Color);
			for (int i = 0; i < src.Length; i++)
			{
				Material val = new Material(sh);
				if ((Object)(object)src[i] != (Object)null && src[i].HasProperty("_MainTex") && val.HasProperty("_MainTex"))
				{
					val.mainTexture = src[i].mainTexture;
				}
				((Color)(ref val2))..ctor(0.6f, 0.65f, 0.8f, alpha);
				if (val.HasProperty("_TintColor"))
				{
					val.SetColor("_TintColor", val2 * 0.5f);
				}
				if (val.HasProperty("_Color"))
				{
					val.color = val2;
				}
				array[i] = val;
			}
			return array;
		}

		private static void Restore(GameObject root)
		{
			if (!_trans.TryGetValue(root, out var value))
			{
				return;
			}
			foreach (KeyValuePair<Renderer, Entry> item in value)
			{
				Renderer key = item.Key;
				if (!((Object)(object)key == (Object)null))
				{
					if (AnyOurs(key.sharedMaterials))
					{
						key.sharedMaterials = item.Value.Orig;
					}
					key.SetPropertyBlock(item.Value.HadBlock ? item.Value.Block : null);
					key.shadowCastingMode = (ShadowCastingMode)1;
				}
			}
			_trans.Remove(root);
			_transAlpha.Remove(root);
		}

		internal static void SetHidden(GameObject root, bool hide)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			if (hide)
			{
				if (!_hidden.TryGetValue(root, out var value))
				{
					value = (_hidden[root] = new List<Renderer>());
				}
				Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>();
				foreach (Renderer val in componentsInChildren)
				{
					if ((Object)(object)val != (Object)null && val.enabled)
					{
						val.enabled = false;
						value.Add(val);
					}
				}
			}
			else
			{
				if (!_hidden.TryGetValue(root, out var value2))
				{
					return;
				}
				foreach (Renderer item in value2)
				{
					if ((Object)(object)item != (Object)null)
					{
						item.enabled = true;
					}
				}
				_hidden.Remove(root);
			}
		}

		internal static void Prune()
		{
			List<GameObject> list = new List<GameObject>();
			foreach (GameObject key in _trans.Keys)
			{
				if ((Object)(object)key == (Object)null)
				{
					list.Add(key);
				}
			}
			foreach (GameObject item in list)
			{
				_trans.Remove(item);
				_transAlpha.Remove(item);
			}
			list.Clear();
			foreach (GameObject key2 in _hidden.Keys)
			{
				if ((Object)(object)key2 == (Object)null)
				{
					list.Add(key2);
				}
			}
			foreach (GameObject item2 in list)
			{
				_hidden.Remove(item2);
			}
		}
	}
}