private static void SetMaterialsOriginal(GameObject go)
    {
        ChaCustomHairComponent chaCustomHairComponent = go.GetComponentInChildren <ChaCustomHairComponent>();

        if (chaCustomHairComponent != null)
        {
            chaCustomHairComponent.SetMaterialsOriginal();
        }
        ChaClothesComponent chaClothesComponent = go.GetComponentInChildren <ChaClothesComponent>();

        if (chaClothesComponent != null)
        {
            chaClothesComponent.SetMaterialsOriginal();
        }
        Studio.ItemComponent itemComponent = go.GetComponentInChildren <Studio.ItemComponent>();
        if (itemComponent != null)
        {
            itemComponent.SetMaterialsOriginal();
        }
        ChaAccessoryComponent chaAccessoryComponent = go.GetComponentInChildren <ChaAccessoryComponent>();

        if (chaAccessoryComponent != null)
        {
            chaAccessoryComponent.SetMaterialsOriginal();
        }
    }
Exemplo n.º 2
0
        public static bool ChangeSettingHairAcsColorPrefix(int parts, ChaControl __instance)
        {
            int HairAcsColorNum = __instance.GetHairAcsColorNum(parts);

            if (HairAcsColorNum == 0)
            {
                return(false);
            }

            ChaCustomHairComponent customHairComponent = __instance.GetCustomHairComponent(parts);

            if (null == customHairComponent)
            {
                return(false);
            }

            for (int i = 0; i < customHairComponent.rendAccessory.Length; i++)
            {
                for (int j = 0; j < HairAcsColorNum; j++)
                {
                    if (customHairComponent.rendAccessory[i] == null) //Added null check
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 3
0
            private static void RemoveNullParts(ChaCustomHairComponent hairComponent)
            {
                if (hairComponent == null)
                {
                    return;
                }

                hairComponent.rendAccessory = hairComponent.rendAccessory.RemoveNulls();
                hairComponent.rendHair      = hairComponent.rendHair.RemoveNulls();
                hairComponent.trfLength     = hairComponent.trfLength.RemoveNulls();
            }
Exemplo n.º 4
0
        public static bool ChaCustomHairComponentUpdatePrefix(ChaCustomHairComponent __instance)
        {
            if (__instance.trfLength != null)
            {
                for (int i = 0; i < __instance.trfLength.Length; i++)
                {
                    if (__instance.trfLength[i] == null) //Added null check
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        public static bool ChangeSettingHairColor(int parts, bool c00, bool c01, bool c02, ChaControl __instance)
        {
            ChaCustomHairComponent customHairComponent = __instance.GetCustomHairComponent(parts);

            if (null == customHairComponent || customHairComponent.rendHair == null || customHairComponent.rendHair.Length == 0)
            {
                return(false);
            }
            ChaFileHair hair = __instance.chaFile.custom.hair;

            for (int i = 0; i < customHairComponent.rendHair.Length; i++)
            {
                if (c00)
                {
                    if (1f > hair.parts[parts].baseColor.a)
                    {
                        hair.parts[parts].baseColor = new Color(hair.parts[parts].baseColor.r, hair.parts[parts].baseColor.g, hair.parts[parts].baseColor.b, 1f);
                    }
                    if (customHairComponent.rendHair[i] != null) //Added null check
                    {
                        customHairComponent.rendHair[i].material.SetColor(ChaShader._Color, hair.parts[parts].baseColor);
                    }
                }
                if (c01)
                {
                    if (1f > hair.parts[parts].startColor.a)
                    {
                        hair.parts[parts].startColor = new Color(hair.parts[parts].startColor.r, hair.parts[parts].startColor.g, hair.parts[parts].startColor.b, 1f);
                    }
                    if (customHairComponent.rendHair[i] != null) //Added null check
                    {
                        customHairComponent.rendHair[i].material.SetColor(ChaShader._Color2, hair.parts[parts].startColor);
                    }
                }
                if (c02)
                {
                    if (1f > hair.parts[parts].endColor.a)
                    {
                        hair.parts[parts].endColor = new Color(hair.parts[parts].endColor.r, hair.parts[parts].endColor.g, hair.parts[parts].endColor.b, 1f);
                    }
                    if (customHairComponent.rendHair[i] != null) //Added null check
                    {
                        customHairComponent.rendHair[i].material.SetColor(ChaShader._Color3, hair.parts[parts].endColor);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public static bool HarmonyPatch_ChaCustomHairComponent_Update(ChaCustomHairComponent __instance)
        {
            if (__instance.trfLength != null)
            {
                for (int i = 0; i < __instance.trfLength.Length; i++)
                {
                    var transform = __instance.trfLength[i];
                    if (transform) // Check trfLength[i] before using it
                    {
                        float y = __instance.baseLength[i] + Mathf.Lerp(0f, __instance.addLength, __instance.lengthRate);
                        transform.localPosition = new Vector3(transform.localPosition.x, y, transform.localPosition.z);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 7
0
        public static bool ChangeSettingHairOutlineColor(int parts, ChaControl __instance)
        {
            ChaCustomHairComponent customHairComponent = __instance.GetCustomHairComponent(parts);

            if (null == customHairComponent || customHairComponent.rendHair == null || customHairComponent.rendHair.Length == 0)
            {
                return(false);
            }
            ChaFileHair hair = __instance.chaFile.custom.hair;

            for (int i = 0; i < customHairComponent.rendHair.Length; i++)
            {
                if (customHairComponent.rendHair[i] != null) //Added null check
                {
                    customHairComponent.rendHair[i].material.SetColor(ChaShader._LineColor, hair.parts[parts].outlineColor);
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        public static bool ChangeSettingHairAcsColor(int parts, ChaControl __instance)
        {
            int hairAcsColorNum = __instance.GetHairAcsColorNum(parts);

            if (hairAcsColorNum == 0)
            {
                return(false);
            }
            ChaCustomHairComponent customHairComponent = __instance.GetCustomHairComponent(parts);

            if (null == customHairComponent)
            {
                return(false);
            }
            int[] array = new int[]
            {
                ChaShader._Color,
                ChaShader._Color2,
                ChaShader._Color3
            };
            ChaFileHair hair = __instance.chaFile.custom.hair;

            for (int i = 0; i < customHairComponent.rendAccessory.Length; i++)
            {
                for (int j = 0; j < hairAcsColorNum; j++)
                {
                    if (1f > hair.parts[parts].acsColor[j].a)
                    {
                        hair.parts[parts].acsColor[j] = new Color(hair.parts[parts].acsColor[j].r, hair.parts[parts].acsColor[j].g, hair.parts[parts].acsColor[j].b, 1f);
                    }
                    if (customHairComponent.rendAccessory[i] != null) //Added null check
                    {
                        customHairComponent.rendAccessory[i].material.SetColor(array[j], hair.parts[parts].acsColor[j]);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 9
0
            /// <summary>
            /// Updates the specified hair accessory
            /// </summary>
            public void UpdateAccessory(int slot, bool updateCharacter = true)
            {
                if (!IsHairAccessory(slot))
                {
                    return;
                }

                var acc = ChaControl.GetAccessoryObject(slot);

                if (acc == null)
                {
                    return;
                }
                ChaAccessoryComponent chaAccessoryComponent = acc.GetComponent <ChaAccessoryComponent>();

                if (chaAccessoryComponent == null)
                {
                    return;
                }
                ChaCustomHairComponent chaCustomHairComponent = chaAccessoryComponent.gameObject.GetComponent <ChaCustomHairComponent>();

                if (chaCustomHairComponent.rendHair == null)
                {
                    return;
                }

                if (!HairAccessories.ContainsKey(CurrentCoordinateIndex))
                {
                    return;
                }
                if (!HairAccessories[CurrentCoordinateIndex].TryGetValue(slot, out var hairAccessoryInfo))
                {
                    return;
                }
                if (chaAccessoryComponent.rendNormal == null)
                {
                    return;
                }
                if (chaCustomHairComponent.rendHair == null)
                {
                    return;
                }

                if (updateCharacter && hairAccessoryInfo.ColorMatch)
                {
                    if (MakerAPI.InsideAndLoaded)
                    {
                        CvsAccessory cvsAccessory = AccessoriesApi.GetMakerAccessoryPageObject(slot).GetComponent <CvsAccessory>();
                        cvsAccessory.UpdateAcsColor01(ChaControl.chaFile.custom.hair.parts[0].baseColor);
                        cvsAccessory.UpdateAcsColor02(ChaControl.chaFile.custom.hair.parts[0].startColor);
                        cvsAccessory.UpdateAcsColor03(ChaControl.chaFile.custom.hair.parts[0].endColor);
                        OutlineColorPicker.SetValue(slot, ChaControl.chaFile.custom.hair.parts[0].outlineColor, false);
                        hairAccessoryInfo.OutlineColor = ChaControl.chaFile.custom.hair.parts[0].outlineColor;
                    }
                    else
                    {
                        for (var i = 0; i < chaCustomHairComponent.rendHair.Length; i++)
                        {
                            Renderer renderer = chaCustomHairComponent.rendHair[i];
                            if (renderer == null)
                            {
                                continue;
                            }

                            if (renderer.sharedMaterial.HasProperty(ChaShader._Color))
                            {
                                renderer.sharedMaterial.SetColor(ChaShader._Color, ChaControl.chaFile.custom.hair.parts[0].baseColor);
                            }
                            if (renderer.sharedMaterial.HasProperty(ChaShader._Color2))
                            {
                                renderer.sharedMaterial.SetColor(ChaShader._Color2, ChaControl.chaFile.custom.hair.parts[0].startColor);
                            }
                            if (renderer.sharedMaterial.HasProperty(ChaShader._Color3))
                            {
                                renderer.sharedMaterial.SetColor(ChaShader._Color3, ChaControl.chaFile.custom.hair.parts[0].endColor);
                            }
                        }
                    }
                }

                Texture2D texHairGloss = (Texture2D)AccessTools.Property(typeof(ChaControl), "texHairGloss").GetValue(ChaControl, null);

                for (var i = 0; i < chaCustomHairComponent.rendHair.Length; i++)
                {
                    Renderer renderer = chaCustomHairComponent.rendHair[i];
                    if (renderer == null)
                    {
                        continue;
                    }

                    if (renderer.sharedMaterial.HasProperty(ChaShader._HairGloss))
                    {
                        if (hairAccessoryInfo.HairGloss)
                        {
                            renderer.sharedMaterial.SetTexture(ChaShader._HairGloss, texHairGloss);
                        }
                        else
                        {
                            renderer.sharedMaterial.SetTexture(ChaShader._HairGloss, null);
                        }
                    }

                    if (renderer.sharedMaterial.HasProperty(ChaShader._LineColor))
                    {
                        if (hairAccessoryInfo.ColorMatch)
                        {
                            renderer.sharedMaterial.SetColor(ChaShader._LineColor, ChaControl.chaFile.custom.hair.parts[0].outlineColor);
                        }
                        else
                        {
                            renderer.sharedMaterial.SetColor(ChaShader._LineColor, hairAccessoryInfo.OutlineColor);
                        }
                    }
                }

                for (var i = 0; i < chaCustomHairComponent.rendAccessory.Length; i++)
                {
                    Renderer renderer = chaCustomHairComponent.rendAccessory[i];
                    if (renderer == null)
                    {
                        continue;
                    }

                    if (renderer.sharedMaterial.HasProperty(ChaShader._Color))
                    {
                        renderer.sharedMaterial.SetColor(ChaShader._Color, hairAccessoryInfo.AccessoryColor);
                    }
                    if (renderer.sharedMaterial.HasProperty(ChaShader._Color2))
                    {
                        renderer.sharedMaterial.SetColor(ChaShader._Color2, hairAccessoryInfo.AccessoryColor);
                    }
                    if (renderer.sharedMaterial.HasProperty(ChaShader._Color3))
                    {
                        renderer.sharedMaterial.SetColor(ChaShader._Color3, hairAccessoryInfo.AccessoryColor);
                    }
                }

                chaCustomHairComponent.lengthRate = hairAccessoryInfo.HairLength;
            }