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();
        }
    }
        private void ApplyOverlays(ChaClothesComponent clothesCtrl)
        {
            if (CurrentOverlayTextures == null)
            {
                return;
            }

            var clothesName  = clothesCtrl.name;
            var rendererArrs = GetRendererArrays(clothesCtrl);

            if (_dumpCallback != null && _dumpClothesId == clothesName)
            {
                DumpBaseTextureImpl(rendererArrs);
            }

            if (CurrentOverlayTextures.Count == 0)
            {
                return;
            }

            if (!CurrentOverlayTextures.TryGetValue(clothesName, out var overlay) || overlay == null)
            {
                return;
            }

            var applicableRenderers = GetApplicableRenderers(rendererArrs).ToList();

            if (applicableRenderers.Count == 0)
            {
                Logger.Log(MakerAPI.InsideMaker ? LogLevel.Warning | LogLevel.Message : LogLevel.Debug, $"[KCOX] Removing unused overlay for {clothesName}");

                Destroy(overlay.Texture);
                CurrentOverlayTextures.Remove(clothesName);
                return;
            }

            foreach (var renderer in applicableRenderers)
            {
                var mat = renderer.material;

                var mainTexture = (RenderTexture)mat.mainTexture;
                if (mainTexture == null)
                {
                    return;
                }

                if (overlay.Override)
                {
                    var rta = RenderTexture.active;
                    RenderTexture.active = mainTexture;
                    GL.Clear(false, true, Color.clear);
                    RenderTexture.active = rta;
                }

                if (overlay.Texture != null)
                {
                    KoiSkinOverlayController.ApplyOverlay(mainTexture, overlay.Texture);
                }
            }
        }
Ejemplo n.º 3
0
        public static Renderer[][] GetRendererArrays(ChaClothesComponent clothesCtrl)
        {
            return(new[] {
                clothesCtrl.rendNormal01,
                clothesCtrl.rendNormal02,
                clothesCtrl.rendAlpha01,
#if KK || KKS
                clothesCtrl.rendAlpha02
#endif
            });
        }
        public static void ChangeCustomClothesPostHook(ChaControl __instance, ref bool main, ref int kind)
        {
            var clothesCtrl = GetCustomClothesComponent(__instance, main, kind);

            if (!clothesCtrl)
            {
                Logger.Log(LogLevel.Info, "No clothes component found");
                return;
            }

            currentClothesComponent = clothesCtrl;
        }
Ejemplo n.º 5
0
 private void ApplyOverlays(ChaClothesComponent clothesCtrl)
 static Renderer[][] GetRendererArrays(ChaClothesComponent clothesCtrl)
 {
     return(new[] { clothesCtrl.rendNormal01, clothesCtrl.rendNormal02, clothesCtrl.rendAlpha01, clothesCtrl.rendAlpha02 });
 }
        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
        }