private static void RemoveGeneralComponents(GameObject avatar, bool local, bool friend) { ComponentBlacklist blacklist = Config.ComponentBlacklist; if (blacklist.IgnoreFriends && friend) { Log.Debug("Component limit - skipping scan because user is a friend"); return; } if (blacklist.IgnoreSelf && local) { Log.Debug("Component limit - skipping scan because user is local"); return; } void DestroyAll(string type, Component[] components) { Log.Debug($"Component limit - destroyed {components.Length} {type} objects"); for (int i = 0; i < components.Length; i++) { UnityEngine.Object.Destroy(components[i]); } } if (!blacklist.AudioSourcesEnabled) { DestroyAll("AudioSource", avatar.GetComponentsInChildren <AudioSource>(true)); } if (!blacklist.ParticleSystemsEnabled) { DestroyAll("ParticleSystem", avatar.GetComponentsInChildren <ParticleSystem>(true)); } if (!blacklist.StandardAnimatorEnabled) { DestroyAll("Animator", avatar.GetComponentsInChildren <Animator>(true)); } if (!blacklist.LegacyAnimatorEnabled) { DestroyAll("Animation", avatar.GetComponentsInChildren <Animation>(true)); } if (!blacklist.MeshFiltersEnabled) { DestroyAll("MeshFilters", avatar.GetComponentsInChildren <MeshFilter>(true)); } if (!blacklist.SpringJointEnabled) { DestroyAll("SpringJoint", avatar.GetComponentsInChildren <SpringJoint>(true)); } if (!blacklist.ClothEnabled) { DestroyAll("Cloth", avatar.GetComponentsInChildren <Cloth>(true)); } if (!blacklist.DynamicBonesEnabled) { DestroyAll("DynamicBones", avatar.GetComponentsInChildren <DynamicBone>(true)); } }
private static void EnforceShaderBlacklist(GameObject avatar) { ComponentBlacklist components = Config.ComponentBlacklist; Shader standard = Shader.Find("Standard"); foreach (Renderer renderer in avatar.GetComponentsInChildren <Renderer>(true)) { Material[] materials = renderer.materials; Material poiMat = materials.FirstOrDefault(m => m.shader.name.ToLowerInvariant().Contains(".poiyomi/master/opaque")); if (poiMat != null && m_poiShader == null) { m_poiShader = poiMat.shader; } if (components.MaterialsEnabled) { for (int x = 0; x < materials.Length; x++) { ShaderInfo shader = new ShaderInfo() { Name = materials[x].shader.name.ToLowerInvariant(), Blocked = false }; if (!m_shaderList.Any(s => s.Name == shader.Name)) { m_shaderList.Add(shader); } if (!components.ShadersEnabled) { UnityEngine.Object.Destroy(materials[x].shader); } else { ShaderInfo target = m_shaderList.First(s => s.Name == shader.Name); if (materials[x].shader.name.ToLowerInvariant().Contains("cubedparadox/flat lit toon") && components.ReplaceWithPoiyomi) { Material mat = materials[x]; Texture mainTex = mat.GetTexture("_MainTex"); Texture bumpTex = mat.GetTexture("_BumpMap"); Color col = mat.GetColor("_Color"); float cutoff = mat.GetFloat("_Cutoff"); if (m_poiShader != null) { Material newMat = new Material(m_poiShader); // use reference to poi's master newMat.SetTexture("_MainTex", mainTex); newMat.SetTexture("_NormalMap", bumpTex); newMat.SetColor("_Color", col); newMat.SetFloat("_Lit", 1.0f); newMat.SetFloat("_Clip", cutoff); Log.Debug($"Replaced {mat.name} ({mat.shader.name}) with poiyomi's master shader"); materials[x].shader = m_poiShader; materials[x] = newMat; } else { Log.Debug("poi's shader is null, skipping replacement"); } } else if (target.Blocked) { if (!components.ReplaceInsteadDelete) { Log.Debug($"Shader check - destroying an object for shader {shader.Name}"); UnityEngine.Object.Destroy(renderer); break; } else { Log.Debug($"Shader check - replacing shader {shader.Name} on object {renderer.name}"); materials[x].shader = standard; } } } if (materials[x].shader != null && shader.Name == "standard" && components.ReplaceStandard) { materials[x].shader = standard; } } new Thread(() => { SaveShaderList(); }).Start(); } else { foreach (Material mat in materials) { UnityEngine.Object.Destroy(mat); } } } }