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();
        }
    }
Example #2
0
            internal static bool IsHairAccessory(ChaControl _chaCtrl, int _slotIndex)
            {
                ChaAccessoryComponent accessory = GetChaAccessoryComponent(_chaCtrl, _slotIndex);

                if (accessory == null)
                {
                    return(false);
                }
                return(accessory.gameObject.GetComponent <ChaCustomHairComponent>() != null);
            }
Example #3
0
 internal static bool IsHairAccessory(int _slotIndex)
 {
     try
     {
         ChaAccessoryComponent accessory = _chaCtrl.GetAccessoryObject(_slotIndex)?.GetComponent <ChaAccessoryComponent>();
         if (accessory == null)
         {
             return(false);
         }
         return(accessory.gameObject?.GetComponent <ChaCustomHairComponent>() != null);
     }
     catch
     {
         return(false);
     }
 }
Example #4
0
 internal static bool IsHairAccessory(ChaControl chaCtrl, int slot)
 {
     try
     {
         ChaAccessoryComponent accessory = chaCtrl.GetAccessoryObject(slot)?.GetComponent <ChaAccessoryComponent>();
         if (accessory == null)
         {
             return(false);
         }
         return(accessory.gameObject?.GetComponent <ChaCustomHairComponent>() != null);
     }
     catch
     {
         return(false);
     }
 }
Example #5
0
        private void Start()
        {
            ChaAccessoryComponent chaAccessory = gameObject.GetComponent <ChaAccessoryComponent>();
            var chaControl    = gameObject.GetComponentInParent <ChaControl>();
            var aaWeightsBody = (AssignedAnotherWeights)Traverse.Create(chaControl).Field("aaWeightsBody").GetValue();
            var bounds        = (Bounds)Traverse.Create(chaControl).Field("bounds").GetValue();
            var objRootBone   = chaControl.GetReferenceInfo(ChaReference.RefObjKey.A_ROOTBONE);

            //AssignedWeightsAndSetBounds replaces the bones of an object with the body bones
            for (var index = 0; index < chaAccessory.rendNormal.Length; index++)
            {
                aaWeightsBody.AssignedWeightsAndSetBounds(chaAccessory.rendNormal[index].gameObject, "cf_j_root", bounds, objRootBone.transform);
            }

            //Get rid of this since it's no longer needed
            Destroy(ArmatureRoot.gameObject);
        }
        private void Start()
        {
            ChaAccessoryComponent chaAccessory = gameObject.GetComponent <ChaAccessoryComponent>();
            var chaControl = gameObject.GetComponentInParent <ChaControl>();

#if KK
            // KK darnkess has different enum values for the same names than games without it, so it needs to be obtained dynamically
            var rootBoneKey = (ChaReference.RefObjKey)System.Enum.Parse(typeof(ChaReference.RefObjKey), "A_ROOTBONE");
#else
            var rootBoneKey = ChaReference.RefObjKey.A_ROOTBONE;
#endif
            var objRootBone = chaControl.GetReferenceInfo(rootBoneKey);

            //AssignedWeightsAndSetBounds replaces the bones of an object with the body bones
            for (var index = 0; index < chaAccessory.rendNormal.Length; index++)
            {
                chaControl.aaWeightsBody.AssignedWeightsAndSetBounds(chaAccessory.rendNormal[index].gameObject, "cf_j_root", chaControl.bounds, objRootBone.transform);
            }

            //Get rid of this since it's no longer needed
            Destroy(ArmatureRoot.gameObject);
        }
Example #7
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;
            }
Example #8
0
 /// <summary>
 /// Checks if the specified accessory is a hair accessory
 /// </summary>
 public bool IsHairAccessory(ChaAccessoryComponent chaAccessoryComponent) => chaAccessoryComponent != null && chaAccessoryComponent.gameObject.GetComponent <ChaCustomHairComponent>() != null;
Example #9
0
        /// <summary>
        /// Get slot index of his accessory, useful for referencing to the accesory in extended data.
        /// </summary>
        public static int GetAccessoryIndex(this ChaAccessoryComponent accessoryComponent)
        {
            var chaControl = GetOwningChaControl(accessoryComponent);

            return(_getChaAccessoryCmpIndex(chaControl, accessoryComponent));
        }
Example #10
0
 /// <summary>
 /// Get the ChaControl that owns this accessory
 /// </summary>
 public static ChaControl GetOwningChaControl(this ChaAccessoryComponent accessoryComponent)
 {
     return(accessoryComponent.GetComponentInParent <ChaControl>());
 }
        public void Initialize(ChaControl owner, ChaClothesComponent clothesComponent, ChaAccessoryComponent accessoryComponent, ListInfoBase listInfoBase, ChaListDefine.CategoryNo kind)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (clothesComponent == null)
            {
                throw new ArgumentNullException(nameof(clothesComponent));
            }
            if (accessoryComponent == null)
            {
                throw new ArgumentNullException(nameof(accessoryComponent));
            }
            if (listInfoBase == null)
            {
                throw new ArgumentNullException(nameof(listInfoBase));
            }
            ClothesComponent   = clothesComponent;
            AccessoryComponent = accessoryComponent;
            Owner    = owner;
            InfoBase = listInfoBase;
            _kind    = kind;

            // Treat top parts as normal tops
            if (kind >= ChaListDefine.CategoryNo.cpo_sailor_a)
            {
                _clothingKind = 0;
            }
            else
            {
                _clothingKind = kind - ChaListDefine.CategoryNo.co_top;
            }

            var firstInstanceForCharacter = false;

            AllInstances.TryGetValue(owner, out var instances);
            if (instances == null)
            {
                // + 1 for inner shoes. Only outer / index 7 are used, but some hooks can look for index 8
                instances                 = Enumerable.Range(0, 8 /*+ 1*/).Select(i => new List <ClothesToAccessoriesAdapter>()).ToArray();
                AllInstances[Owner]       = instances;
                firstInstanceForCharacter = true;
            }
            instances[_clothingKind].Add(this);

            Reference = gameObject.AddComponent <ChaReference>();
            Reference.CreateReferenceInfo((ulong)(_clothingKind + 5), gameObject);

            if (_kind == ChaListDefine.CategoryNo.co_gloves || _kind == ChaListDefine.CategoryNo.co_shoes || _kind == ChaListDefine.CategoryNo.co_socks)
            {
                AllObjects = AccessoryComponent.rendNormal.Select(x => x.transform.parent.gameObject).Distinct().ToArray();
            }

            _colorRend = AccessoryComponent.rendNormal.FirstOrDefault(x => x != null) ?? AccessoryComponent.rendAlpha.FirstOrDefault(x => x != null) ?? AccessoryComponent.rendHair.FirstOrDefault(x => x != null);

            if (!InitializeCreateTextures())
            {
                ClothesToAccessoriesPlugin.Logger.LogWarning($"InitializeCreateTextures failed for kind={kind} id={listInfoBase.Id}");
            }

            // If there's already a bra mask active it needs to be applied again to a newly loaded accessory bra
            if (_kind == ChaListDefine.CategoryNo.co_bra)
            {
                // If this bra is the first clothing accessory added to the character, LastTopState needs to be calculated by UpdateVisibleAccessoryClothes before it can be used below
                if (firstInstanceForCharacter)
                {
                    ClothesToAccessoriesPlugin.UpdateVisibleAccessoryClothes(Owner);
                }

                if (ClothesToAccessoriesPlugin.LastTopState.TryGetValue(Owner, out var topState))
                {
                    ChangeAlphaMask(ClothesToAccessoriesPlugin.alphaState[topState, 0], ClothesToAccessoriesPlugin.alphaState[topState, 1]);
                }
            }

            // bug: if multipe clothes with skirt dynamic bones are spawned then their dynamic bone components all work at the same time on the same body bones, which can cause some weird physics effects
        }
Example #12
0
        public static int GetAccessoryIndex(this ChaAccessoryComponent accessoryComponent)
        {
            var chaControl = GetOwningChaControl(accessoryComponent);

            return(Array.IndexOf(chaControl.cusAcsCmp, accessoryComponent));
        }