示例#1
0
        public static void post_CustomTextureCreate_RebuildTextureAndSetMaterial(CustomTextureCreate __instance, ref Texture __result)
        {
            if (__instance is CustomTextureControl)
            {
                var overlay = __instance.trfParent?.GetComponent <KoiSkinOverlayController>();
                if (overlay == null)
                {
                    return;
                }

                var createTex = __result as RenderTexture;
                if (createTex == null)
                {
                    return;
                }

                if (overlay.ChaControl.customTexCtrlFace == __instance)
                {
                    overlay.ApplyOverlayToRT(createTex, TexType.FaceOver);
                }
                else if (overlay.ChaControl.customTexCtrlBody == __instance)
                {
                    overlay.ApplyOverlayToRT(createTex, TexType.BodyOver);
                }
            }
        }
示例#2
0
        public static void EyeSetMainTexturePrefix(CustomTextureCreate __instance, ref Texture tex)
        {
            var overlay = __instance.trfParent?.GetComponent <KoiSkinOverlayController>();

            if (overlay == null)
            {
                return;
            }

            if (__instance == overlay.ChaControl.ctCreateEyeL || __instance == overlay.ChaControl.ctCreateEyeR)
            {
                tex = overlay.ApplyOverlayToTex(tex, TexType.EyeUnder);
            }
        }
示例#3
0
        public static void EyeChangeSettingEyePostfix(CustomTextureCreate __instance, Texture __result)
        {
            var overlay = __instance.trfParent?.GetComponent <KoiSkinOverlayController>();

            if (overlay == null)
            {
                return;
            }

            if (__instance == overlay.ChaControl.ctCreateEyeL || __instance == overlay.ChaControl.ctCreateEyeR)
            {
                overlay.ApplyOverlayToRT((RenderTexture)__result, TexType.EyeOver);
            }
        }
示例#4
0
        public static void RebuildTexPostfix(CustomTextureCreate __instance, ref bool __state)
        {
            if (!__state)
            {
                return;
            }

            CharaOverlaysBasedOnCoordinateController controller = __instance.trfParent?.GetComponent <CharaOverlaysBasedOnCoordinateController>();

            if (null != controller)
            {
                foreach (KeyValuePair <TexType, byte[]> kvp in EyeTexture)
                {
                    controller.OverwriteOverlayWithoutUpdate(kvp.Key, kvp.Value);
                }
                Extension.Extension.TryGetPluginInstance("KSOX_GUI").Invoke("OnChaFileLoaded");
            }
        }
示例#5
0
        public static void RebuildTexPrefix(CustomTextureCreate __instance, ref bool __state)
        {
            __state = false;
            CharaOverlaysBasedOnCoordinateController controller = __instance.trfParent?.GetComponent <CharaOverlaysBasedOnCoordinateController>();

            if (null == controller || controller.LoadingLock)
            {
                return;
            }

            CustomTextureCreate toCompare;

            switch (controller.IrisDisplaySide[(int)controller.CurrentCoordinate.Value])
            {
            case 1:
                toCompare = controller.ChaControl.ctCreateEyeL;
                break;

            case 2:
                toCompare = controller.ChaControl.ctCreateEyeR;
                break;

            default:
                //Not Display Both
                return;
            }

            //要保留的那邊return
            if (toCompare == __instance)
            {
                return;
            }

            __state = true;
            foreach (KeyValuePair <TexType, byte[]> kvp in controller.GetOverlayLoaded(new TexType[] { TexType.EyeOver, TexType.EyeUnder }))
            {
                EyeTexture[kvp.Key] = kvp.Value;
                controller.OverwriteOverlayWithoutUpdate(kvp.Key, new byte[] { });
            }
        }
示例#6
0
        /// <summary>
        /// Skin underlay logic
        /// </summary>
        private static Texture RebuildTextureHook(CustomTextureCreate __instance, Texture texMain)
        {
            if (__instance is CustomTextureControl)
            {
                var overlay = __instance.trfParent?.GetComponent <KoiSkinOverlayController>();
                if (overlay == null)
                {
                    return(texMain);
                }

                if (overlay.ChaControl.customTexCtrlFace == __instance)
                {
                    return(overlay.ApplyOverlayToTex(texMain, TexType.FaceUnder));
                }

                if (overlay.ChaControl.customTexCtrlBody == __instance)
                {
                    return(overlay.ApplyOverlayToTex(texMain, TexType.BodyUnder));
                }
            }
            return(texMain);
        }
示例#7
0
        private static void OverlayBlit(Texture source, RenderTexture dest, Material mat, int pass, CustomTextureCreate instance)
        {
            if (!instance.CreateInitEnd)
            {
                return;
            }

            if (source == null)
            {
                KoiSkinOverlayMgr.Logger.LogError(instance.trfParent.name + " source texture is null, can't apply overlays!");
                return;
            }

            if (dest == null)
            {
                throw new System.ArgumentNullException(nameof(dest));
            }
            if (mat == null)
            {
                throw new System.ArgumentNullException(nameof(mat));
            }

            var overlay = instance.trfParent?.GetComponent <KoiSkinOverlayController>();

            if (overlay != null)
            {
                if (overlay.ChaControl.customTexCtrlFace == instance)
                {
                    OverlayBlitImpl(source, dest, mat, pass, overlay, TexType.FaceUnder);
                    overlay.ApplyOverlayToRT(dest, TexType.FaceOver);
                    return;
                }
                if (overlay.ChaControl.customTexCtrlBody == instance)
                {
                    OverlayBlitImpl(source, dest, mat, pass, overlay, TexType.BodyUnder);
                    overlay.ApplyOverlayToRT(dest, TexType.BodyOver);
                    return;
                }
                if (overlay.ChaControl.ctCreateEyeL == instance)
                {
                    OverlayBlitImpl(source, dest, mat, pass, overlay, TexType.EyeUnderL);
                    overlay.ApplyOverlayToRT(dest, TexType.EyeOverL);
                    return;
                }
                if (overlay.ChaControl.ctCreateEyeR == instance)
                {
                    OverlayBlitImpl(source, dest, mat, pass, overlay, TexType.EyeUnderR);
                    overlay.ApplyOverlayToRT(dest, TexType.EyeOverR);
                    return;
                }
            }

            // Fall back to original code
            Graphics.Blit(source, dest, mat, pass);
        }
        /// <summary>
        /// Clothes use shaders that do not support applying colors directly, instead they rely on the main texture having all colors and effects already applied to it
        /// CustomTextureCreate is used to apply colors and masks to the original main texture of the clothes
        /// </summary>
        private bool InitializeCreateTextures()
        {
            var lib          = InfoBase;
            var mainManifest = lib.GetInfo(ChaListDefine.KeyType.MainManifest);
            var mainTexAb    = lib.GetInfo(ChaListDefine.KeyType.MainTexAB);

            if ("0" == mainTexAb)
            {
                mainTexAb = lib.GetInfo(ChaListDefine.KeyType.MainAB);
            }
            var mainTex = lib.GetInfo(ChaListDefine.KeyType.MainTex);

            if ("0" == mainTexAb || "0" == mainTex)
            {
                return(false);
            }
            var t2dMain = CommonLib.LoadAsset <Texture2D>(mainTexAb, mainTex, false, mainManifest);

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

            var colorMaskAb = lib.GetInfo(ChaListDefine.KeyType.ColorMaskAB);

            if ("0" == colorMaskAb)
            {
                colorMaskAb = lib.GetInfo(ChaListDefine.KeyType.MainAB);
            }
            var colorMaskTex = lib.GetInfo(ChaListDefine.KeyType.ColorMaskTex);

            if ("0" == colorMaskAb || "0" == colorMaskTex)
            {
                Resources.UnloadAsset(t2dMain);
                return(false);
            }
            var t2dColorMask = CommonLib.LoadAsset <Texture2D>(colorMaskAb, colorMaskTex, false, mainManifest);

            if (null == t2dColorMask)
            {
                Resources.UnloadAsset(t2dMain);
                return(false);
            }

            var mainTex02Ab = lib.GetInfo(ChaListDefine.KeyType.MainTex02AB);

            if ("0" == mainTex02Ab)
            {
                mainTex02Ab = lib.GetInfo(ChaListDefine.KeyType.MainAB);
            }
            var       mainTex02    = lib.GetInfo(ChaListDefine.KeyType.MainTex02);
            Texture2D t2dMainTex02 = null;

            if ("0" != mainTex02Ab && "0" != mainTex02)
            {
                t2dMainTex02 = CommonLib.LoadAsset <Texture2D>(mainTex02Ab, mainTex02, false, mainManifest);
            }

            var colorMask02Ab = lib.GetInfo(ChaListDefine.KeyType.ColorMask02AB);

            if ("0" == colorMask02Ab)
            {
                colorMask02Ab = lib.GetInfo(ChaListDefine.KeyType.MainAB);
            }
            var       colorMask02Tex = lib.GetInfo(ChaListDefine.KeyType.ColorMask02Tex);
            Texture2D t2dColorMask02 = null;

            if ("0" != colorMask02Ab && "0" != colorMask02Tex)
            {
                t2dColorMask02 = CommonLib.LoadAsset <Texture2D>(colorMask02Ab, colorMask02Tex, false, mainManifest);
            }

#if KKS
            var mainTex03Ab = lib.GetInfo(ChaListDefine.KeyType.MainTex03AB);
            if ("0" == mainTex03Ab)
            {
                mainTex03Ab = lib.GetInfo(ChaListDefine.KeyType.MainAB);
            }
            var mainTex03 = lib.GetInfo(ChaListDefine.KeyType.MainTex03);

            Texture2D t2dMainTex03 = null;
            if ("0" != mainTex03Ab && "0" != mainTex03)
            {
                t2dMainTex03 = CommonLib.LoadAsset <Texture2D>(mainTex03Ab, mainTex03, false, mainManifest, true);
            }

            var colorMask03Tex = lib.GetInfo(ChaListDefine.KeyType.ColorMask03Tex);
            var colorMask03Ab  = lib.GetInfo(ChaListDefine.KeyType.ColorMask03AB);
            if ("0" == colorMask03Ab)
            {
                colorMask03Ab = lib.GetInfo(ChaListDefine.KeyType.MainAB);
            }
            Texture2D t2dColorMask03 = null;
            if ("0" != colorMask03Ab && "0" != colorMask03Tex)
            {
                t2dColorMask03 = CommonLib.LoadAsset <Texture2D>(colorMask03Ab, colorMask03Tex, false, mainManifest, true);
            }
#endif

            for (var i = 0; i < 3; i++)
            {
                CustomTextureCreate ctc   = null;
                Texture2D           main  = null;
                Texture2D           color = null;
                if (i == 0)
                {
                    main  = t2dMain;
                    color = t2dColorMask;
                }
                else if (1 == i)
                {
                    main  = t2dMainTex02;
                    color = t2dColorMask02;
                }
                else
                {
#if KKS
                    main  = t2dMainTex03;
                    color = t2dColorMask03;
#endif
                }
                if (null != main)
                {
                    ctc = new CustomTextureCreate(Owner.objRoot.transform);
                    ctc.Initialize("chara/mm_base.unity3d", "cf_m_clothesN_create", "", main.width, main.height, RenderTextureFormat.ARGB32);
                    ctc.SetMainTexture(main);
                    ctc.SetTexture(ChaShader._ColorMask, color);
                }

                _ctcArr[i] = ctc;
            }

            return(true);
        }