Example #1
0
 public static void SetExtendedDataById(this ChaFileClothes.PartsInfo messagePackObject, string id, PluginData data) => SetExtendedData(messagePackObject, id, data);
        public bool UpdateClothesColorAndStuff()
        {
            if (_ctcArr[0] == null)
            {
                return(false);
            }

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

            // todo pattern support
            var partsInfo = new ChaFileClothes.PartsInfo();

            // Accessories have colors applied to materials of all of their renderers, so it's safe to grab it from there (as a bonus this supports ME or other plugin edits)
            partsInfo.colorInfo[0].baseColor = _colorRend.material.GetColor(ChaShader._Color);
            partsInfo.colorInfo[1].baseColor = _colorRend.material.GetColor(ChaShader._Color2);
            partsInfo.colorInfo[2].baseColor = _colorRend.material.GetColor(ChaShader._Color3);
            // color4 is not used in clothes, it's a fake color for some parts of inner top clothes (it's used as color 1 in those)

            var result       = true;
            var patternMasks = new[] { ChaShader._PatternMask1, ChaShader._PatternMask2, ChaShader._PatternMask3, ChaShader._PatternMask1 };

            for (var i = 0; i < 3; i++)
            {
                Texture2D tex = null;

#if KKS
                Owner.lstCtrl.GetFilePath(ChaListDefine.CategoryNo.mt_pattern, partsInfo.colorInfo[i].pattern,
                                          ChaListDefine.KeyType.MainTexAB, ChaListDefine.KeyType.MainTex, out var abName, out var assetName);
#elif KK
                var listInfo  = Owner.lstCtrl.GetListInfo(ChaListDefine.CategoryNo.mt_pattern, partsInfo.colorInfo[i].pattern);
                var abName    = listInfo.GetInfo(ChaListDefine.KeyType.MainTexAB);
                var assetName = listInfo.GetInfo(ChaListDefine.KeyType.MainTex);
#endif

                if (abName != "0" && assetName != "0")
                {
                    tex = CommonLib.LoadAsset <Texture2D>(abName, assetName, false, "");
#if KK
                    Character.Instance.AddLoadAssetBundle(abName, "");
#else
                    Character.AddLoadAssetBundle(abName, "");
#endif
                }

                foreach (var ctc in _ctcArr)
                {
                    if (ctc != null)
                    {
                        ctc.SetTexture(patternMasks[i], tex);
                    }
                }
            }

            foreach (var ctc in _ctcArr)
            {
                if (ctc != null)
                {
                    ctc.SetColor(ChaShader._Color, partsInfo.colorInfo[0].baseColor);
                    ctc.SetColor(ChaShader._Color1_2, partsInfo.colorInfo[0].patternColor);
                    ctc.SetFloat(ChaShader._PatternScale1u, partsInfo.colorInfo[0].tiling.x);
                    ctc.SetFloat(ChaShader._PatternScale1v, partsInfo.colorInfo[0].tiling.y);
#if KKS
                    ctc.SetFloat(ChaShader._PatternOffset1u, partsInfo.colorInfo[0].offset.x);
                    ctc.SetFloat(ChaShader._PatternOffset1v, partsInfo.colorInfo[0].offset.y);
                    ctc.SetFloat(ChaShader._PatternRotator1, partsInfo.colorInfo[0].rotate);
#endif
                    ctc.SetColor(ChaShader._Color2, partsInfo.colorInfo[1].baseColor);
                    ctc.SetColor(ChaShader._Color2_2, partsInfo.colorInfo[1].patternColor);
                    ctc.SetFloat(ChaShader._PatternScale2u, partsInfo.colorInfo[1].tiling.x);
                    ctc.SetFloat(ChaShader._PatternScale2v, partsInfo.colorInfo[1].tiling.y);
                    ctc.SetColor(ChaShader._Color3, partsInfo.colorInfo[2].baseColor);
                    ctc.SetColor(ChaShader._Color3_2, partsInfo.colorInfo[2].patternColor);
                    ctc.SetFloat(ChaShader._PatternScale3u, partsInfo.colorInfo[2].tiling.x);
                    ctc.SetFloat(ChaShader._PatternScale3v, partsInfo.colorInfo[2].tiling.y);
#if KKS
                    ctc.SetFloat(ChaShader._PatternOffset2u, partsInfo.colorInfo[1].offset.x);
                    ctc.SetFloat(ChaShader._PatternOffset2v, partsInfo.colorInfo[1].offset.y);
                    ctc.SetFloat(ChaShader._PatternRotator2, partsInfo.colorInfo[1].rotate);
                    ctc.SetFloat(ChaShader._PatternOffset3u, partsInfo.colorInfo[2].offset.x);
                    ctc.SetFloat(ChaShader._PatternOffset3v, partsInfo.colorInfo[2].offset.y);
                    ctc.SetFloat(ChaShader._PatternRotator3, partsInfo.colorInfo[2].rotate);
#endif
                }
            }

            var hasRendNormal = ClothesComponent.rendNormal01 != null && ClothesComponent.rendNormal01.Length != 0;
            var hasRendAlpha  = ClothesComponent.rendAlpha01 != null && ClothesComponent.rendAlpha01.Length != 0;
            if (hasRendNormal || hasRendAlpha)
            {
                var tex = _ctcArr[0].RebuildTextureAndSetMaterial();
                if (tex != null)
                {
                    if (hasRendNormal)
                    {
                        for (var k = 0; k < ClothesComponent.rendNormal01.Length; k++)
                        {
                            if (ClothesComponent.rendNormal01[k])
                            {
                                ClothesComponent.rendNormal01[k].material.SetTexture(ChaShader._MainTex, tex);
                            }
                            else
                            {
                                result = false;
                            }
                        }
                    }
                    if (hasRendAlpha)
                    {
                        for (var l = 0; l < ClothesComponent.rendAlpha01.Length; l++)
                        {
                            if (ClothesComponent.rendAlpha01[l])
                            {
                                ClothesComponent.rendAlpha01[l].material.SetTexture(ChaShader._MainTex, tex);
                            }
                            else
                            {
                                result = false;
                            }
                        }
                    }
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            var hasRendNormal02 = ClothesComponent.rendNormal02 != null && ClothesComponent.rendNormal02.Length != 0;
            if (hasRendNormal02 && _ctcArr[1] != null)
            {
                var tex = _ctcArr[1].RebuildTextureAndSetMaterial();
                if (tex != null)
                {
                    for (var m = 0; m < ClothesComponent.rendNormal02.Length; m++)
                    {
                        if (ClothesComponent.rendNormal02[m])
                        {
                            ClothesComponent.rendNormal02[m].material.SetTexture(ChaShader._MainTex, tex);
                        }
                        else
                        {
                            result = false;
                        }
                    }
                }
                else
                {
                    result = false;
                }
            }
#if KKS
            var hasRendNormal03 = ClothesComponent.rendNormal03 != null && ClothesComponent.rendNormal03.Length != 0;
            if (hasRendNormal03 && _ctcArr[2] != null)
            {
                var tex = _ctcArr[2].RebuildTextureAndSetMaterial();
                if (tex != null)
                {
                    for (var n = 0; n < ClothesComponent.rendNormal03.Length; n++)
                    {
                        if (ClothesComponent.rendNormal03[n])
                        {
                            ClothesComponent.rendNormal03[n].material.SetTexture(ChaShader._MainTex, tex);
                        }
                        else
                        {
                            result = false;
                        }
                    }
                }
                else
                {
                    result = false;
                }
            }
#endif
            var hasRendAccessory = ClothesComponent.rendAccessory != null;
            if (hasRendAccessory && _ctcArr[0] != null)
            {
                var tex = _ctcArr[0].RebuildTextureAndSetMaterial();
                if (tex != null)
                {
                    if (ClothesComponent.rendAccessory)
                    {
                        ClothesComponent.rendAccessory.material.SetTexture(ChaShader._MainTex, tex);
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    result = false;
                }
            }

            return(result);
        }
Example #3
0
 public static bool TryGetExtendedDataById(this ChaFileClothes.PartsInfo messagePackObject, string id, out PluginData data) => GetExtendedData(messagePackObject, id, out data);
 private static void MemberInit(ChaFileClothes.PartsInfo __instance) => Traverse.Create(__instance).Property(ExtendedSaveDataPropertyName).SetValue(null);