Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of TranslucentCart v1.0.1
TranslucentCart.dll
Decompiled 3 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("Tolga")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("TranslucentCart")] [assembly: AssemblyTitle("TranslucentCart")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.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; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace TranslucentCart { [HarmonyPatch(typeof(PhysGrabCart))] internal static class PhysGrabCartPatch { [HarmonyPostfix] [HarmonyPatch("Start")] private static void Start_Postfix(PhysGrabCart __instance) { TranslucentCart.ApplyCartTransparency(__instance); } [HarmonyPostfix] [HarmonyPatch("StateSwitchRPC")] private static void StateSwitchRPC_Postfix(PhysGrabCart __instance) { TranslucentCart.ApplyCartTransparency(__instance); } } [HarmonyPatch(typeof(PhysGrabObject))] internal static class PhysGrabObjectCartGrabPatch { [HarmonyPostfix] [HarmonyPatch("GrabStarted")] private static void GrabStarted_Postfix(PhysGrabObject __instance) { PhysGrabCart component = ((Component)__instance).GetComponent<PhysGrabCart>(); if (Object.op_Implicit((Object)(object)component)) { TranslucentCart.ApplyCartTransparency(component); } } [HarmonyPostfix] [HarmonyPatch("GrabEnded")] private static void GrabEnded_Postfix(PhysGrabObject __instance) { PhysGrabCart component = ((Component)__instance).GetComponent<PhysGrabCart>(); if (Object.op_Implicit((Object)(object)component)) { TranslucentCart.ApplyCartTransparency(component); } } } [BepInPlugin("Tolga.TranslucentCart", "TranslucentCart", "1.0")] public class TranslucentCart : BaseUnityPlugin { private struct MaterialSnapshot { public bool Initialized; public int RenderQueue; public string RenderTypeTag; public bool HasSurface; public float Surface; public bool HasMode; public float Mode; public bool HasSrcBlend; public int SrcBlend; public bool HasDstBlend; public int DstBlend; public bool HasZWrite; public int ZWrite; public bool HasAlphaClip; public float AlphaClip; public bool HasCutoff; public float Cutoff; public bool AlphaTestKeyword; public bool AlphaBlendKeyword; public bool AlphaPremultiplyKeyword; public bool HasColor; public Color Color; public bool HasBaseColor; public Color BaseColor; public bool HasTintColor; public Color TintColor; } private struct RendererSnapshot { public bool Initialized; public bool Enabled; public ShadowCastingMode ShadowCastingMode; public bool ReceiveShadows; } private static readonly Dictionary<int, MaterialSnapshot> MaterialSnapshots = new Dictionary<int, MaterialSnapshot>(); private static readonly Dictionary<int, RendererSnapshot> RendererSnapshots = new Dictionary<int, RendererSnapshot>(); private static readonly HashSet<string> VanillaCartNames = new HashSet<string> { "Item Cart Small", "Item Cart Medium" }; private static readonly HashSet<string> CustomCartNames = new HashSet<string> { "Shopping Cart" }; private static readonly HashSet<string> SeenCartNames = new HashSet<string>(); private static bool _refreshAllCartsRequested; internal static TranslucentCart Instance { get; private set; } = null; internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } internal static ConfigEntry<float> CartTransparencyPercent { get; private set; } = null; internal static ConfigEntry<bool> OnlyWhenGrabbing { get; private set; } = null; internal static ConfigEntry<bool> IncludeCustomCarts { get; private set; } = null; internal static float CartAlpha { get { float num = Mathf.Clamp(CartTransparencyPercent.Value, 0f, 100f) / 100f; return Mathf.Clamp01(1f - num); } } private void Awake() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown Instance = this; CartTransparencyPercent = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CartTransparencyPercent", 40f, new ConfigDescription("How transparent the cart should be as a percent. 0 = opaque, 100 = invisible.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); OnlyWhenGrabbing = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OnlyWhenGrabbing", false, "If true, only apply transparency while you are grabbing the cart (local player). If false, always apply."); IncludeCustomCarts = ((BaseUnityPlugin)this).Config.Bind<bool>("Compatibility", "IncludeCustomCarts", false, "If true, also apply translucency to custom/modded carts (not just vanilla carts). Uses a safer cutout-preserving transparency mode for basket/wire meshes to avoid black/solid artifacts."); CartTransparencyPercent.SettingChanged += OnAnySettingChanged; OnlyWhenGrabbing.SettingChanged += OnAnySettingChanged; IncludeCustomCarts.SettingChanged += OnAnySettingChanged; ((BaseUnityPlugin)this).Config.ConfigReloaded += OnConfigReloaded; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Patch(); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } private void OnDestroy() { try { CartTransparencyPercent.SettingChanged -= OnAnySettingChanged; OnlyWhenGrabbing.SettingChanged -= OnAnySettingChanged; IncludeCustomCarts.SettingChanged -= OnAnySettingChanged; ((BaseUnityPlugin)this).Config.ConfigReloaded -= OnConfigReloaded; } catch { } } private static void OnAnySettingChanged(object sender, EventArgs e) { RequestRefreshAllCarts(); } private static void OnConfigReloaded(object sender, EventArgs e) { RequestRefreshAllCarts(); } private static void RequestRefreshAllCarts() { _refreshAllCartsRequested = true; } internal void Patch() { //IL_0019: 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) //IL_0020: Expected O, but got Unknown //IL_0025: Expected O, but got Unknown if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); } internal void Unpatch() { Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void Update() { if (_refreshAllCartsRequested) { _refreshAllCartsRequested = false; RefreshAllCarts(); } } internal static void RefreshAllCarts() { PhysGrabCart[] array; try { array = Object.FindObjectsOfType<PhysGrabCart>(); } catch { return; } PhysGrabCart[] array2 = array; foreach (PhysGrabCart cart in array2) { ApplyCartTransparency(cart); } } internal static void ApplyCartTransparency(PhysGrabCart cart) { if (!Object.op_Implicit((Object)(object)cart)) { return; } string text = ((Object)cart).name.Replace("(Clone)", "").Trim(); if (!SeenCartNames.Contains(text)) { SeenCartNames.Add(text); Logger.LogInfo((object)("[CartDiscovery] New cart type seen: '" + text + "'")); } bool flag = IsLikelyCustomCart(cart); if (flag && !IncludeCustomCarts.Value) { Logger.LogInfo((object)("[CartTransparency] '" + text + "' → SKIPPED (custom cart, IncludeCustomCarts=false)")); RestoreCartOpacity(cart); return; } if (!flag) { Logger.LogInfo((object)("[CartTransparency] '" + text + "' → APPLYING (vanilla cart)")); } else { Logger.LogInfo((object)("[CartTransparency] '" + text + "' → APPLYING (custom cart, IncludeCustomCarts=true)")); } float effectiveAlpha = GetEffectiveAlpha(cart); Renderer[] componentsInChildren = ((Component)cart).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if ((val is MeshRenderer || val is SkinnedMeshRenderer) && !((Object)(object)((Component)val).GetComponent("TMPro.TMP_Text") != (Object)null) && !((Object)(object)((Component)val).GetComponent("TMPro.TextMeshPro") != (Object)null)) { Material[] materials; try { materials = val.materials; } catch { continue; } Material[] array = materials; foreach (Material material in array) { bool preferCutout = flag || IsBasketLike(((Object)((Component)val).gameObject).name); ApplyMaterialFade(material, effectiveAlpha, preferCutout); } ApplyRendererShadowRules(val, effectiveAlpha); } } } private static void RestoreCartOpacity(PhysGrabCart cart) { Renderer[] componentsInChildren = ((Component)cart).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (val is MeshRenderer || val is SkinnedMeshRenderer) { Material[] materials; try { materials = val.materials; } catch { continue; } Material[] array = materials; foreach (Material material in array) { ApplyMaterialFade(material, 1f, preferCutout: false); } ApplyRendererShadowRules(val, 1f); } } } private static float GetEffectiveAlpha(PhysGrabCart cart) { if (!OnlyWhenGrabbing.Value) { return CartAlpha; } PhysGrabObject val; try { val = ((Component)cart).GetComponent<PhysGrabObject>(); } catch { val = null; } if (!((Object)(object)val != (Object)null) || !val.grabbedLocal) { return 1f; } return CartAlpha; } private static void ApplyRendererShadowRules(Renderer renderer, float alphaMultiplier) { //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) //IL_0091: Unknown result type (might be due to invalid IL or missing references) alphaMultiplier = Mathf.Clamp01(alphaMultiplier); int instanceID = ((Object)renderer).GetInstanceID(); if (!RendererSnapshots.TryGetValue(instanceID, out var value) || !value.Initialized) { RendererSnapshot rendererSnapshot = default(RendererSnapshot); rendererSnapshot.Initialized = true; rendererSnapshot.Enabled = renderer.enabled; rendererSnapshot.ShadowCastingMode = renderer.shadowCastingMode; rendererSnapshot.ReceiveShadows = renderer.receiveShadows; value = rendererSnapshot; RendererSnapshots[instanceID] = value; } if (alphaMultiplier <= 0.001f) { renderer.enabled = false; renderer.shadowCastingMode = (ShadowCastingMode)0; } else { renderer.enabled = value.Enabled; renderer.shadowCastingMode = value.ShadowCastingMode; } renderer.receiveShadows = value.ReceiveShadows; } private static void ApplyMaterialFade(Material material, float alphaMultiplier, bool preferCutout) { //IL_0083: 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_008c: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)material)) { return; } alphaMultiplier = Mathf.Clamp01(alphaMultiplier); int instanceID = ((Object)material).GetInstanceID(); if (!MaterialSnapshots.TryGetValue(instanceID, out var value) || !value.Initialized) { value = CaptureSnapshot(material); MaterialSnapshots[instanceID] = value; } if (alphaMultiplier >= 0.999f) { RestoreSnapshot(material, value); return; } if (preferCutout || IsCutoutLike(material, value)) { SetMaterialTransparentPreserveCutout(material, value); } else { SetMaterialTransparent(material); } if (value.HasColor && material.HasProperty("_Color")) { Color color = value.Color; color.a = Mathf.Clamp01(value.Color.a * alphaMultiplier); material.color = color; } if (value.HasBaseColor && material.HasProperty("_BaseColor")) { Color baseColor = value.BaseColor; baseColor.a = Mathf.Clamp01(value.BaseColor.a * alphaMultiplier); material.SetColor("_BaseColor", baseColor); } if (value.HasTintColor && material.HasProperty("_TintColor")) { Color tintColor = value.TintColor; tintColor.a = Mathf.Clamp01(value.TintColor.a * alphaMultiplier); material.SetColor("_TintColor", tintColor); } } private static MaterialSnapshot CaptureSnapshot(Material material) { //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) MaterialSnapshot materialSnapshot = default(MaterialSnapshot); materialSnapshot.Initialized = true; materialSnapshot.RenderQueue = material.renderQueue; materialSnapshot.RenderTypeTag = material.GetTag("RenderType", false, ""); MaterialSnapshot result = materialSnapshot; if (material.HasProperty("_Surface")) { result.HasSurface = true; result.Surface = material.GetFloat("_Surface"); } if (material.HasProperty("_Mode")) { result.HasMode = true; result.Mode = material.GetFloat("_Mode"); } if (material.HasProperty("_SrcBlend")) { result.HasSrcBlend = true; result.SrcBlend = material.GetInt("_SrcBlend"); } if (material.HasProperty("_DstBlend")) { result.HasDstBlend = true; result.DstBlend = material.GetInt("_DstBlend"); } if (material.HasProperty("_ZWrite")) { result.HasZWrite = true; result.ZWrite = material.GetInt("_ZWrite"); } if (material.HasProperty("_AlphaClip")) { result.HasAlphaClip = true; result.AlphaClip = material.GetFloat("_AlphaClip"); } if (material.HasProperty("_Cutoff")) { result.HasCutoff = true; result.Cutoff = material.GetFloat("_Cutoff"); } result.AlphaTestKeyword = material.IsKeywordEnabled("_ALPHATEST_ON"); result.AlphaBlendKeyword = material.IsKeywordEnabled("_ALPHABLEND_ON"); result.AlphaPremultiplyKeyword = material.IsKeywordEnabled("_ALPHAPREMULTIPLY_ON"); if (material.HasProperty("_Color")) { result.HasColor = true; result.Color = material.color; } if (material.HasProperty("_BaseColor")) { result.HasBaseColor = true; result.BaseColor = material.GetColor("_BaseColor"); } if (material.HasProperty("_TintColor")) { result.HasTintColor = true; result.TintColor = material.GetColor("_TintColor"); } return result; } private static void RestoreSnapshot(Material material, MaterialSnapshot snap) { //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) material.renderQueue = snap.RenderQueue; material.SetOverrideTag("RenderType", snap.RenderTypeTag); if (snap.HasSurface && material.HasProperty("_Surface")) { material.SetFloat("_Surface", snap.Surface); } if (snap.HasMode && material.HasProperty("_Mode")) { material.SetFloat("_Mode", snap.Mode); } if (snap.HasSrcBlend && material.HasProperty("_SrcBlend")) { material.SetInt("_SrcBlend", snap.SrcBlend); } if (snap.HasDstBlend && material.HasProperty("_DstBlend")) { material.SetInt("_DstBlend", snap.DstBlend); } if (snap.HasZWrite && material.HasProperty("_ZWrite")) { material.SetInt("_ZWrite", snap.ZWrite); } if (snap.HasAlphaClip && material.HasProperty("_AlphaClip")) { material.SetFloat("_AlphaClip", snap.AlphaClip); } if (snap.HasCutoff && material.HasProperty("_Cutoff")) { material.SetFloat("_Cutoff", snap.Cutoff); } if (snap.AlphaTestKeyword) { material.EnableKeyword("_ALPHATEST_ON"); } else { material.DisableKeyword("_ALPHATEST_ON"); } if (snap.AlphaBlendKeyword) { material.EnableKeyword("_ALPHABLEND_ON"); } else { material.DisableKeyword("_ALPHABLEND_ON"); } if (snap.AlphaPremultiplyKeyword) { material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); } else { material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); } if (snap.HasColor && material.HasProperty("_Color")) { material.color = snap.Color; } if (snap.HasBaseColor && material.HasProperty("_BaseColor")) { material.SetColor("_BaseColor", snap.BaseColor); } if (snap.HasTintColor && material.HasProperty("_TintColor")) { material.SetColor("_TintColor", snap.TintColor); } } private static void SetMaterialTransparent(Material material) { material.SetOverrideTag("RenderType", "Transparent"); if (material.HasProperty("_Surface")) { material.SetFloat("_Surface", 1f); } if (material.HasProperty("_Mode")) { material.SetFloat("_Mode", 3f); } if (material.HasProperty("_SrcBlend")) { material.SetInt("_SrcBlend", 5); } if (material.HasProperty("_DstBlend")) { material.SetInt("_DstBlend", 10); } if (material.HasProperty("_ZWrite")) { material.SetInt("_ZWrite", 0); } material.DisableKeyword("_ALPHATEST_ON"); material.EnableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 3000; } private static bool IsLikelyCustomCart(PhysGrabCart cart) { string text = ((Object)cart).name.Replace("(Clone)", "").Trim(); if (CustomCartNames.Contains(text)) { Logger.LogInfo((object)("[CartDetection] '" + text + "' → CUSTOM (in explicit custom list)")); return true; } if (VanillaCartNames.Count > 0 && !VanillaCartNames.Contains(text)) { Logger.LogInfo((object)("[CartDetection] '" + text + "' → CUSTOM (not in vanilla whitelist)")); return true; } int num = 0; try { MonoBehaviour[] componentsInChildren = ((Component)cart).GetComponentsInChildren<MonoBehaviour>(true); MonoBehaviour[] array = componentsInChildren; foreach (MonoBehaviour val in array) { if ((Object)(object)val == (Object)null) { num++; } } if (num > 0) { Logger.LogInfo((object)$"[CartDetection] '{text}' → CUSTOM (found {num} missing script(s))"); return true; } } catch { } List<string> list = new List<string>(); try { Component[] componentsInChildren2 = ((Component)cart).GetComponentsInChildren<Component>(true); Component[] array2 = componentsInChildren2; foreach (Component val2 in array2) { if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)cart)) { Type type = ((object)val2).GetType(); string text2 = type.Assembly.GetName().Name ?? string.Empty; if (!IsVanillaAssemblyName(text2) && !list.Contains(text2)) { list.Add(text2); } } } if (list.Count > 0) { Logger.LogInfo((object)("[CartDetection] '" + text + "' → CUSTOM (non-vanilla assemblies: " + string.Join(", ", list) + ")")); return true; } } catch { } Logger.LogInfo((object)("[CartDetection] '" + text + "' → VANILLA (passed all custom checks)")); return false; } private static bool IsVanillaAssemblyName(string assemblyName) { if (string.IsNullOrEmpty(assemblyName)) { return true; } if (assemblyName == "Assembly-CSharp") { return true; } if (assemblyName.StartsWith("Assembly-CSharp-", StringComparison.OrdinalIgnoreCase)) { return true; } if (assemblyName.StartsWith("Unity", StringComparison.OrdinalIgnoreCase)) { return true; } if (assemblyName.IndexOf("Photon", StringComparison.OrdinalIgnoreCase) >= 0) { return true; } switch (assemblyName) { case "TMPro": return true; default: if (!assemblyName.StartsWith("System.", StringComparison.OrdinalIgnoreCase)) { if (assemblyName == "netstandard") { return true; } return false; } goto case "mscorlib"; case "mscorlib": case "System": return true; } } private static bool IsBasketLike(string name) { if (string.IsNullOrEmpty(name)) { return false; } string text = name.ToLowerInvariant(); if (!text.Contains("basket") && !text.Contains("wire") && !text.Contains("grid") && !text.Contains("net") && !text.Contains("mesh")) { return text.Contains("cage"); } return true; } private static bool IsCutoutLike(Material material, MaterialSnapshot snap) { if (snap.AlphaTestKeyword) { return true; } if (!string.IsNullOrEmpty(snap.RenderTypeTag) && snap.RenderTypeTag.ToLowerInvariant().Contains("cutout")) { return true; } if (material.HasProperty("_AlphaClip")) { try { if (material.GetFloat("_AlphaClip") > 0.5f) { return true; } } catch { } } if (material.HasProperty("_Cutoff")) { return true; } if (snap.HasMode && Mathf.Abs(snap.Mode - 1f) < 0.01f) { return true; } return false; } private static void SetMaterialTransparentPreserveCutout(Material material, MaterialSnapshot snap) { material.SetOverrideTag("RenderType", "TransparentCutout"); if (material.HasProperty("_Surface")) { material.SetFloat("_Surface", 1f); } if (material.HasProperty("_AlphaClip")) { material.SetFloat("_AlphaClip", 1f); } if (material.HasProperty("_Cutoff")) { float num = 0.5f; try { if (snap.HasCutoff) { num = snap.Cutoff; } } catch { } material.SetFloat("_Cutoff", num); } if (material.HasProperty("_Mode")) { material.SetFloat("_Mode", 3f); } if (material.HasProperty("_SrcBlend")) { material.SetInt("_SrcBlend", 5); } if (material.HasProperty("_DstBlend")) { material.SetInt("_DstBlend", 10); } if (material.HasProperty("_ZWrite")) { material.SetInt("_ZWrite", 0); } if (snap.AlphaTestKeyword) { material.EnableKeyword("_ALPHATEST_ON"); } material.EnableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 3000; } private static void SetMaterialOpaque(Material material) { material.SetOverrideTag("RenderType", "Opaque"); if (material.HasProperty("_Surface")) { material.SetFloat("_Surface", 0f); } if (material.HasProperty("_Mode")) { material.SetFloat("_Mode", 0f); } if (material.HasProperty("_SrcBlend")) { material.SetInt("_SrcBlend", 1); } if (material.HasProperty("_DstBlend")) { material.SetInt("_DstBlend", 0); } if (material.HasProperty("_ZWrite")) { material.SetInt("_ZWrite", 1); } material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 2000; } } }