public static Texture2D LoadTexture(string textureName)
        {
            Texture2D texture = null;

            if (textureName != null)
            {
                if (textureName != string.Empty)
                {
                    try
                    {
                        texture = ImportCM.CreateTexture(textureName);
                    }
                    catch
                    {
                        try
                        {
                            textureName = textureName.Replace(@"tex\", "");
                            texture     = ImportCM.CreateTexture(textureName);
                        }
                        catch (Exception ex)
                        {
                            UnityEngine.Debug.LogError("Error: " + ex.ToString());
                        }
                    }
                }
            }

            return(texture);
        }
Ejemplo n.º 2
0
        public static Texture2D GetTexture(int menuFileID)
        {
            string textureFileName = texFileIDDic[menuFileID];

            if (tex2DDic.ContainsKey(textureFileName))
            {
                if (tex2DDic[textureFileName] == null)
                {
                    tex2DDic[textureFileName] = ImportCM.CreateTexture(textureFileName);
                }
                return(tex2DDic[textureFileName]);
            }
            else
            {
                Texture2D tex2D = ImportCM.CreateTexture(textureFileName);
                tex2DDic.Add(textureFileName, tex2D);
                return(tex2D);
            }
        }
        public static IEnumerator LoadIcons()
        {
            while (SetupDone == false || ListOfIconLoads.Count > 1)
            {
                if (ListOfIconLoads.Count == 0)
                {
                    yield return(null);
                }
                else
                {
                    Debug.LogError("Icon Coroutine is loading an icon...");

                    ListOfIconLoads.Keys.ElementAt(0).m_texIcon = ImportCM.CreateTexture(ListOfIconLoads[ListOfIconLoads.Keys.ElementAt(0)]);
                    ListOfContinues.Enqueue(ListOfIconLoads.Keys.ElementAt(0));
                    ListOfIconLoads.TryRemove(ListOfIconLoads.Keys.ElementAt(0), out _);
                }
            }

            IconLoadDone = true;
        }
        public static IEnumerator SetupTexturesCoRoutine()
        {
            Main.logger.LogError($"Starting coroutine to set textures to menu items.");

            while (Test2Done != true)
            {
                yield return(null);
            }

            Main.logger.LogError($"Test2 part 1 finished in {test.Elapsed}\n. Creating textures....");

            foreach (KeyValuePair <SceneEdit.SMenuItem, string> dic in ListOfContinues)
            {
                dic.Key.m_texIcon = ImportCM.CreateTexture(dic.Value);
            }

            Main.logger.LogError($"Done creating textures at {test.Elapsed}, continuing Test2 ");

            CoRouteDone = true;

            Test2Continuation();

            while (Test2ContinuatonDone == false)
            {
                yield return(null);
            }

            Main.logger.LogError($"Test2 finished it's work at {test.Elapsed}");

            Main.logger.LogError("Invoking coroutines...");

            //yield return @this.StartCoroutine(@this.CoLoadWait());
            @this.StartCoroutine(AccessTools.Method(typeof(SceneEdit), "CoLoadWait").Invoke(@this, null) as IEnumerator);

            //yield return @this.StartCoroutine(@this.FixedInitMenu(menuList, @this.m_menuRidDic, menuGroupMemberDic));
            @this.StartCoroutine(AccessTools.Method(typeof(SceneEdit), "FixedInitMenu").Invoke(@this, new object[] { SavedmenuList, @this.m_menuRidDic, SavedmenuGroupMemberDic }) as IEnumerator);

            Main.logger.LogError($"Finished work at {test.Elapsed}");
        }
Ejemplo n.º 5
0
        public static IEnumerator InitialBackgroundWorker()
        {
            Debug.LogError("Coroutine was successfully engaged!");

            while (GameMain.Instance.CharacterMgr.IsBusy())
            {
                yield return(null);
                //Thread.Sleep(20);
            }
            MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;

            while (!menuDataBase.JobFinished())
            {
                //Thread.Sleep(20);
                yield return(null);
            }

            test.Start();

            Debug.LogError("Reaching first access method.");

            AccessTools.Method(typeof(SceneEdit), "InitCategoryList").Invoke(@this, null);
            //@this.InitCategoryList();
            int fileCount = menuDataBase.GetDataSize();
            var menuList  = new HashSet <SceneEdit.SMenuItem>();

            @this.m_menuRidDic = new Dictionary <int, SceneEdit.SMenuItem>(fileCount);
            var   menuRidDicThreadSafe = @this.m_menuRidDic;
            var   menuGroupMemberDic   = new Dictionary <int, HashSet <int> >();
            float time = Time.realtimeSinceStartup;

            for (int i = 0; i < fileCount; i++)
            {
                menuDataBase.SetIndex(i);
                string fileName        = menuDataBase.GetMenuFileName();
                string parent_filename = menuDataBase.GetParentMenuFileName();
                if (GameMain.Instance.CharacterMgr.status.IsHavePartsItem(fileName))
                {
                    SceneEdit.SMenuItem mi = new SceneEdit.SMenuItem();
                    mi.m_strMenuFileName = fileName;
                    mi.m_nMenuFileRID    = fileName.GetHashCode();
                    try
                    {
                        SceneEdit.ReadMenuItemDataFromNative(mi, i);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError(string.Concat(new string[]
                        {
                            "ReadMenuItemDataFromNative 例外/",
                            fileName,
                            "/",
                            ex.Message,
                            " StackTrace/",
                            ex.StackTrace
                        }));
                    }
                    if (!mi.m_bMan && @this.editItemTextureCache.IsRegister(mi.m_nMenuFileRID))
                    {
                        AccessTools.Method(typeof(SceneEdit), "AddMenuItemToList").Invoke(@this, new object[] { mi });
                        //@this.AddMenuItemToList(mi);
                        menuList.Add(mi);
                        menuRidDicThreadSafe[mi.m_nMenuFileRID] = mi;
                        string parentMenuName = AccessTools.Method(typeof(SceneEdit), "GetParentMenuFileName").Invoke(@this, new object[] { mi }) as string;
                        //string parentMenuName = SceneEdit.GetParentMenuFileName(mi);
                        if (!string.IsNullOrEmpty(parentMenuName))
                        {
                            int hashCode = parentMenuName.GetHashCode();
                            if (!menuGroupMemberDic.ContainsKey(hashCode))
                            {
                                menuGroupMemberDic[hashCode] = new HashSet <int>();
                            }
                            menuGroupMemberDic[hashCode].Add(mi.m_strMenuFileName.ToLower().GetHashCode());
                        }
                        else if (mi.m_strCateName.IndexOf("set_") != -1 && mi.m_strMenuFileName.IndexOf("_del") == -1)
                        {
                            mi.m_bGroupLeader = true;
                            mi.m_listMember   = new List <SceneEdit.SMenuItem>();
                            mi.m_listMember.Add(mi);
                        }
                        if (0.5f < Time.realtimeSinceStartup - time)
                        {
                            //Thread.Sleep(20);
                            yield return(null);

                            time = Time.realtimeSinceStartup;
                        }
                    }
                }
            }

            Debug.LogError($"Reaching the load ForEach at {test.Elapsed}.");

            Stopwatch test2 = new Stopwatch();

            foreach (string strFileName in GameUty.ModOnlysMenuFiles)
            {
                test2.Reset();
                test2.Start();

                SceneEdit.SMenuItem mi2 = new SceneEdit.SMenuItem();
                if (Main.GetMenuItemSetUP(mi2, strFileName, out string iconTex, false))
                {
                    ListOfIconLoads[mi2] = iconTex;
                }

                Debug.LogError("Finished One GetMenuItemSetUP in " + test2.Elapsed);
            }

            Debug.LogError($"We've finished SceneEdit.SMenuItem {test.Elapsed}");

            /*
             * SetupDone = true;
             *
             * while (IconLoadDone == false)
             * {
             *      yield return null;
             * }*/

            //foreach (KeyValuePair<SceneEdit.SMenuItem, string> keyPair in ListOfIconLoads)
            while (ListOfIconLoads.Count > 0)
            {
                var keyPair = ListOfIconLoads.FirstOrDefault();

                if (keyPair.Key == null || keyPair.Value == null)
                {
                    ListOfIconLoads.Remove(keyPair.Key);
                    continue;
                }

                //Debug.LogError("Icon Coroutine is loading an icon...");

                try
                {
                    keyPair.Key.m_texIcon = ImportCM.CreateTexture(keyPair.Value);
                }
                catch
                {
                    //ListOfIconLoads.Remove(keyPair.Key);
                    continue;
                }

                if (!(keyPair.Key.m_texIconRef == null))
                {
                    ListOfContinues.Add(keyPair.Key);
                }
                ListOfIconLoads.Remove(keyPair.Key);
            }

            Debug.LogError($"Now we've finished loading icons into each menu at {test.Elapsed}.");

            //Parallel.ForEach(ListOfContinues, (mi2) =>
            //foreach (SceneEdit.SMenuItem mi2 in ListOfContinues)
            while (ListOfContinues.Count > 0)
            {
                var mi2 = ListOfContinues.FirstOrDefault();

                if (mi2 == null)
                {
                    continue;
                }

                test2.Reset();

                if (!mi2.m_bMan)
                {
                    test2.Start();
                    //Debug.LogError("Invoking addmenuitemtolist");
                    AccessTools.Method(typeof(SceneEdit), "AddMenuItemToList").Invoke(@this, new object[] { mi2 });
                    //@this.AddMenuItemToList(mi2);
                    //Debug.LogError($"Done invoking AddMenuItemToList at: {test2.Elapsed}");
                    menuRidDicThreadSafe[mi2.m_nMenuFileRID] = mi2;
                    //Debug.LogError("Invoking GetParentMenuFileName");
                    string parentMenuName2 = AccessTools.Method(typeof(SceneEdit), "GetParentMenuFileName").Invoke(@this, new object[] { mi2 }) as string;
                    //string parentMenuName2 = SceneEdit.GetParentMenuFileName(mi2);
                    //Debug.LogError($"Done Invoking GetParentMenuFileName at: {test2.Elapsed}");
                    if (!string.IsNullOrEmpty(parentMenuName2))
                    {
                        int hashCode2 = parentMenuName2.GetHashCode();
                        if (!menuGroupMemberDic.ContainsKey(hashCode2))
                        {
                            menuGroupMemberDic[hashCode2] = new HashSet <int>();
                        }
                        menuGroupMemberDic[hashCode2].Add(mi2.m_strMenuFileName.ToLower().GetHashCode());
                    }
                    else if (mi2.m_strCateName.IndexOf("set_") != -1 && mi2.m_strMenuFileName.IndexOf("_del") == -1)
                    {
                        mi2.m_bGroupLeader = true;
                        mi2.m_listMember   = new List <SceneEdit.SMenuItem>();
                        mi2.m_listMember.Add(mi2);
                    }
                    if (0.5f < Time.realtimeSinceStartup - time)
                    {
                        yield return(null);

                        Debug.LogError($"Sleeping thread, 100ms...");
                        time = Time.realtimeSinceStartup;
                    }
                    Debug.LogError($"Finished processing one menu file in {test2.Elapsed}");
                }

                ListOfContinues.Remove(mi2);
            }            //);

            Debug.LogError($"Finished previous foreach at {test.Elapsed}\nInvoking coroutines...");

            @this.m_menuRidDic = menuRidDicThreadSafe;

            //var localmenuRidDic = @this.m_menuRidDic;

            //var tempMenuList = menuList.ToList();
            var tempGroupMemberDic = menuGroupMemberDic.ToDictionary(t => t.Key, t => t.Value.ToList());

            Debug.LogError($"Converted Dictionary back...");

            //yield return @this.StartCoroutine(@this.CoLoadWait());
            yield return(@this.StartCoroutine(AccessTools.Method(typeof(SceneEdit), "CoLoadWait").Invoke(@this, null) as IEnumerator));

            Debug.LogError($"Starting problematic coroutine.");

            //yield return @this.StartCoroutine(@this.FixedInitMenu(menuList, @this.m_menuRidDic, menuGroupMemberDic));
            yield return(@this.StartCoroutine(AccessTools.Method(typeof(SceneEdit), "FixedInitMenu").Invoke(@this, new object[] { menuList.ToList(), @this.m_menuRidDic, tempGroupMemberDic }) as IEnumerator));

            test.Stop();

            Debug.LogError($"Done, loaded {ListOfContinues.Count} menus in {test.Elapsed}");

            ListOfContinues.Clear();

            test.Reset();

            yield break;
        }        /*
        public static Material ReadMaterial(BinaryReader r, Material existmat)
        {
            string   str1     = r.ReadString();
            string   str2     = r.ReadString();
            string   path     = "DefMaterial/" + r.ReadString();
            Material material = existmat;

            if (existmat == null)
            {
                Material original = Resources.Load(path, typeof(Material)) as Material;
                if ((UnityEngine.Object)original == (UnityEngine.Object)null)
                {
                    NDebug.Assert("DefMaterialが見つかりません。" + path);
                }
                material = UnityEngine.Object.Instantiate <Material>(original);
            }
            else
            {
                material = existmat;
                NDebug.Assert(material.shader.name == str2, "マテリアル入れ替えエラー。違うシェーダーに入れようとしました。 " + str2 + " -> " + material.shader.name);
            }
            material.name = str1;
            int hashCode = material.name.GetHashCode();

            // if (ImportCM.m_hashPriorityMaterials != null && ImportCM.m_hashPriorityMaterials.ContainsKey(hashCode))
            // {
            //   KeyValuePair<string, float> priorityMaterial = ImportCM.m_hashPriorityMaterials[hashCode];
            //   if (priorityMaterial.Key == material.name)
            //   {
            //     material.SetFloat("_SetManualRenderQueue", priorityMaterial.Value);
            //     material.renderQueue = (int) priorityMaterial.Value;
            //   }
            // }
            while (true)
            {
                string str3;
                string propertyName;
                string str4;
                do
                {
                    str3 = r.ReadString();
                    if (!(str3 == "end"))
                    {
                        propertyName = r.ReadString();
                        if (str3 == "tex")
                        {
                            str4 = r.ReadString();
                            if (str4 == "null")
                            {
                                material.SetTexture(propertyName, (Texture)null);
                            }
                            else if (str4 == "tex2d")
                            {
                                string str5 = r.ReadString();
                                r.ReadString();
                                Texture2D texture = ImportCM.CreateTexture(str5 + ".tex");
                                texture.name     = str5;
                                texture.wrapMode = TextureWrapMode.Clamp;
                                material.SetTexture(propertyName, (Texture)texture);
                                // if (bodyskin != null)
                                //   bodyskin.listDEL.Add((UnityEngine.Object) texture);
                                Vector2 offset;
                                offset.x = r.ReadSingle();
                                offset.y = r.ReadSingle();
                                material.SetTextureOffset(propertyName, offset);
                                Vector2 scale;
                                scale.x = r.ReadSingle();
                                scale.y = r.ReadSingle();
                                material.SetTextureScale(propertyName, scale);
                            }
                        }
                        else
                        {
                            goto label_36;
                        }
                    }
                    else
                    {
                        goto label_43;
                    }
                }while (!(str4 == "texRT"));
                r.ReadString();
                r.ReadString();
                continue;
label_36:
                if (str3 == "col")
                {
                    Color color;
                    color.r = r.ReadSingle();
                    color.g = r.ReadSingle();
                    color.b = r.ReadSingle();
                    color.a = r.ReadSingle();
                    material.SetColor(propertyName, color);
                }
                else if (str3 == "vec")
                {
                    Vector4 vector;
                    vector.x = r.ReadSingle();
                    vector.y = r.ReadSingle();
                    vector.z = r.ReadSingle();
                    vector.w = r.ReadSingle();
                    material.SetVector(propertyName, vector);
                }
                else if (str3 == "f")
                {
                    float num = r.ReadSingle();
                    material.SetFloat(propertyName, num);
                }
                else
                {
                    Debug.LogError((object)("マテリアルが読み込めません。不正なマテリアルプロパティ型です " + str3));
                }
            }
label_43:
            return(material);
        }
        public static IEnumerator VanillaMenuLoadStart(List <SceneEdit.SMenuItem> menuList, Dictionary <int, List <int> > menuGroupMemberDic)
        {
            Dictionary <SceneEdit.SMenuItem, int>    filesToLoadFromDatabase = new Dictionary <SceneEdit.SMenuItem, int>();
            Dictionary <SceneEdit.SMenuItem, string> filesToLoad             = new Dictionary <SceneEdit.SMenuItem, string>();

            //We wait until the manager is not busy because starting work while the manager is busy causes egregious bugs.
            while (GameMain.Instance.CharacterMgr.IsBusy())
            {
                yield return(null);
            }

            MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;

            Stopwatch waitOnKiss = new Stopwatch();

            waitOnKiss.Start();

            while (!menuDataBase.JobFinished())
            {
                yield return(null);
            }

            waitOnKiss.Stop();

            int fileCount = menuDataBase.GetDataSize();

            //This entire for loop is what loads in normal game menus. It's been left relatively untouched.
            for (int i = 0; i < fileCount; i++)
            {
                menuDataBase.SetIndex(i);
                string fileName = menuDataBase.GetMenuFileName();

                if (GameMain.Instance.CharacterMgr.status.IsHavePartsItem(fileName))
                {
                    SceneEdit.SMenuItem mi = new SceneEdit.SMenuItem
                    {
                        m_strMenuFileName = fileName,
                        m_nMenuFileRID    = fileName.GetHashCode()
                    };

                    filesToLoadFromDatabase[mi] = i;
                }
            }

            while (CacheLoadDone != true && Main.UseVanillaCache.Value)
            {
                yield return(null);
            }

            foreach (SceneEdit.SMenuItem mi in filesToLoadFromDatabase.Keys)
            {
                try
                {
                    string iconFileName = null;

                    if (MenuCache.ContainsKey(mi.m_strMenuFileName) && Main.UseVanillaCache.Value)
                    {
                        MenuStub tempStub = MenuCache[mi.m_strMenuFileName];

                        if (tempStub.DateModified == File.GetLastWriteTimeUtc(BepInEx.Paths.GameRootPath + "\\GameData\\paths.dat"))
                        {
                            mi.m_strMenuName           = tempStub.Name;
                            mi.m_strInfo               = tempStub.Description;
                            mi.m_mpn                   = (MPN)Enum.Parse(typeof(MPN), tempStub.Category);
                            mi.m_strCateName           = tempStub.Category;
                            mi.m_eColorSetMPN          = (MPN)Enum.Parse(typeof(MPN), tempStub.ColorSetMPN);
                            mi.m_strMenuNameInColorSet = tempStub.ColorSetMenu;
                            mi.m_pcMultiColorID        = (MaidParts.PARTS_COLOR)Enum.Parse(typeof(MaidParts.PARTS_COLOR), tempStub.MultiColorID);
                            mi.m_boDelOnly             = tempStub.DelMenu;
                            mi.m_fPriority             = tempStub.Priority;
                            mi.m_bMan                  = tempStub.ManMenu;
                            mi.m_bOld                  = tempStub.LegacyMenu;

                            iconFileName = tempStub.Icon;
                        }
                        else
                        {
                            Debug.LogWarning("GameData folder was changed! We'll be wiping the vanilla cache clean and rebuilding it now.");
                            MenuCache = new Dictionary <string, MenuStub>();
                        }
                    }

                    if (string.IsNullOrEmpty(mi.m_strMenuName))
                    {
                        //Debug.Log($"Loading {mi.m_strMenuFileName} from the database as it wasn't in cache...");
                        VanillaMenuLoad.ReadMenuItemDataFromNative(mi, filesToLoadFromDatabase[mi], out iconFileName);
                    }

                    filesToLoad[mi] = null;

                    if (!string.IsNullOrEmpty(iconFileName) && GameUty.FileSystem.IsExistentFile(iconFileName))
                    {
                        if (SceneEdit.Instance != null)
                        {
                            SceneEdit.Instance.editItemTextureCache.PreLoadRegister(mi.m_nMenuFileRID, iconFileName);
                        }
                        else
                        {
                            mi.m_texIcon = ImportCM.CreateTexture(iconFileName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(string.Concat(new string[]
                    {
                        "ReadMenuItemDataFromNative 例外/",
                        mi.m_strMenuFileName,
                        "/",
                        ex.Message,
                        " StackTrace/",
                        ex.StackTrace
                    }));
                }
            }

            while (GSModMenuLoad.DictionaryBuilt == false)
            {
                yield return(null);
            }

            foreach (SceneEdit.SMenuItem mi in filesToLoad.Keys)
            {
                if (!mi.m_bMan && !GSModMenuLoad.FilesDictionary.ContainsKey(mi.m_strMenuFileName) && [email protected](mi.m_nMenuFileRID))
                {
                    AccessTools.Method(typeof(SceneEdit), "AddMenuItemToList").Invoke(Main.@this, new object[] { mi });

                    menuList.Add(mi);

                    [email protected]_menuRidDic[mi.m_nMenuFileRID] = mi;
                    string parentMenuName = AccessTools.Method(typeof(SceneEdit), "GetParentMenuFileName").Invoke(Main.@this, new object[] { mi }) as string;

                    if (!string.IsNullOrEmpty(parentMenuName))
                    {
                        int hashCode = parentMenuName.GetHashCode();
                        if (!menuGroupMemberDic.ContainsKey(hashCode))
                        {
                            menuGroupMemberDic.Add(hashCode, new List <int>());
                        }
                        menuGroupMemberDic[hashCode].Add(mi.m_strMenuFileName.ToLower().GetHashCode());
                    }
                    else if (mi.m_strCateName.IndexOf("set_") != -1 && mi.m_strMenuFileName.IndexOf("_del") == -1)
                    {
                        mi.m_bGroupLeader = true;
                        mi.m_listMember   = new List <SceneEdit.SMenuItem>
                        {
                            mi
                        };
                    }

                    if (0.5f < Time.realtimeSinceStartup - Main.time)
                    {
                        yield return(null);

                        Main.time = Time.realtimeSinceStartup;
                    }
                }
            }

            Main.ThreadsDone++;
            Debug.Log($"Vanilla menus finished loading at: {Main.WatchOverall.Elapsed}. We also spent {waitOnKiss.Elapsed} waiting for an unmodified database to finish loading...");

            [email protected](SaveCache(filesToLoad));
        }
Ejemplo n.º 8
0
        public static void ModMaterial(Material material, float OutWVal, float RimSVal, float RimPVal, bool modrim, Color RimCol, Color OutCol, string toon, string stoon)
        {
#if (DEBUG)
            Debug.Log("Started material modification");
#endif

            const string OUTWIDTH    = "_OutlineWidth";
            const string RIMCOLOR    = "_RimColor";
            const string NPRRIMCOLOR = "_RimLightColor";
            const string RIMPOWER    = "_RimPower";
            const string RIMSHIFT    = "_RimShift";
            //Color RColor; RColor.a = 0; RColor.r = 0; RColor.g = 0; RColor.b = 0;
            //Color OColor; OColor.a = 1; OColor.r = 1; OColor.g = 1; OColor.b = 1;

            //Console.WriteLine("Alpha color found was: " + material.GetColor(RIMCOLOR).a);
            // Console.WriteLine("Desired Alpha value is: " + RimAVal);



            if (Main.ToonMod.Value && material.GetTexture("_ToonRamp"))
            {
                try
                {
                    Texture2D ntoon = ImportCM.CreateTexture(stoon);

                    Console.WriteLine(material.GetTexture("_ToonRamp").name);

                    material.SetTexture("_ToonRamp", ntoon);
                }
                catch
                {
                }
            }

            if (Main.SToonMod.Value && material.GetTexture("_ShadowRateToon"))
            {
                try
                {
                    Texture2D nstoon = ImportCM.CreateTexture(stoon);

                    Console.WriteLine(material.GetTexture("_ShadowRateToon").name);

                    material.SetTexture("_ShadowRateToon", nstoon);
                }
                catch
                {
                }
            }

            if (Main.RimMod.Value == true)
            {
                if (material.GetFloat(RIMPOWER) != RimPVal)
                {
#if (DEBUG)
                    Console.WriteLine("RimPower was found equal to: " + material.GetFloat(RIMPOWER));
                    Console.WriteLine("Setting rimpower to: " + RimPVal);
#endif
                    material.SetFloat(RIMPOWER, RimPVal);
                }

                if (material.GetFloat(RIMSHIFT) != RimSVal)
                {
#if (DEBUG)
                    Console.WriteLine("RimShift was found equal to: " + material.GetFloat(RIMSHIFT));
                    Console.WriteLine("Setting rimshift to: " + RimSVal);
#endif
                    material.SetFloat(RIMSHIFT, RimSVal);
                }

                if (material.GetColor(RIMCOLOR) != RimCol)
                {
#if (DEBUG)
                    Console.WriteLine("Found Rimcolor not equal to desired. Changing!");
#endif
                    material.SetColor(RIMCOLOR, RimCol);
                }

                if (material.GetColor(NPRRIMCOLOR) != RimCol)
                {
#if (DEBUG)
                    Console.WriteLine("Found NPR Rimcolor not equal to desired. Changing!");
#endif
                    material.SetColor(NPRRIMCOLOR, RimCol);
                }
            }

            if (Main.OutMod.Value == true)
            {
                if (material.GetColor("_OutlineColor") != OutCol)
                {
#if (DEBUG)
                    Console.WriteLine("Found OutlineColor not equal to desired. Changing!");
#endif
                    material.SetColor("_OutlineColor", OutCol);
                }

                if (material.GetFloat(OUTWIDTH) != OutWVal)
                {
#if (DEBUG)
                    Console.WriteLine("Outline was found equal to: " + material.GetFloat(OUTWIDTH));
                    Console.WriteLine("Setting outline to: " + OutWVal);
#endif
                    material.SetFloat(OUTWIDTH, OutWVal);
                }
            }
        }
Ejemplo n.º 9
0
        override public void Awake()
        {
            this.deleteRequested = false;

            this.modelNameLabel      = new CustomLabel();
            this.modelNameLabel.Text = this.Name;
            this.ChildControls.Add(this.modelNameLabel);

            this.modelIconImage = new CustomImage(null);
            this.ChildControls.Add(this.modelIconImage);

            if (this.iconName != null && this.iconName != string.Empty)
            {
                try
                {
                    this.modelIconImage.Texture = ImportCM.CreateTexture(this.iconName);
                }
                catch (Exception e)
                {
                    Debug.LogError("Failed to load model icon: " + e);

                    Texture2D iconTexture = new Texture2D(1, 1);
                    iconTexture.SetPixel(0, 0, new Color32(1, 1, 1, 1));
                    iconTexture.Apply();
                    this.modelIconImage.Texture = iconTexture;
                }
            }
            else
            {
                Texture2D iconTexture = new Texture2D(1, 1);
                iconTexture.SetPixel(0, 0, new Color32(1, 1, 1, 1));
                iconTexture.Apply();
                this.modelIconImage.Texture = iconTexture;
            }

            this.gizmoPanToggle                 = new CustomToggleButton(false);
            this.gizmoPanToggle.FontSize        = this.FontSize;
            this.gizmoPanToggle.Text            = Translation.GetText("Model", "gizmoPan");
            this.gizmoPanToggle.CheckedChanged += this.TogglePan;
            this.ChildControls.Add(this.gizmoPanToggle);

            this.gizmoRotateToggle                 = new CustomToggleButton(false);
            this.gizmoRotateToggle.FontSize        = this.FontSize;
            this.gizmoRotateToggle.Text            = Translation.GetText("Model", "gizmoRotate");
            this.gizmoRotateToggle.CheckedChanged += this.ToggleRotate;
            this.ChildControls.Add(this.gizmoRotateToggle);

            this.gizmoScaleToggle                 = new CustomToggleButton(false);
            this.gizmoScaleToggle.FontSize        = this.FontSize;
            this.gizmoScaleToggle.Text            = Translation.GetText("Model", "gizmoScale");
            this.gizmoScaleToggle.CheckedChanged += this.ToggleScale;
            this.ChildControls.Add(this.gizmoScaleToggle);

            this.gizmoScaleAllAxesToggle                 = new CustomToggleButton(false, "toggle");
            this.gizmoScaleAllAxesToggle.FontSize        = this.FontSize;
            this.gizmoScaleAllAxesToggle.Text            = Translation.GetText("Model", "gizmoScaleAllAxes");
            this.gizmoScaleAllAxesToggle.CheckedChanged += this.ToggleScale;
            this.ChildControls.Add(this.gizmoScaleAllAxesToggle);

            this.resetPanButton          = new CustomButton();
            this.resetPanButton.FontSize = this.FontSize;
            this.resetPanButton.Text     = Translation.GetText("UI", "reset");
            this.resetPanButton.Click   += this.ResetPan;
            this.ChildControls.Add(this.resetPanButton);

            this.resetRotateButton          = new CustomButton();
            this.resetRotateButton.FontSize = this.FontSize;
            this.resetRotateButton.Text     = Translation.GetText("UI", "reset");
            this.resetRotateButton.Click   += this.ResetRotation;
            this.ChildControls.Add(this.resetRotateButton);

            this.resetScaleButton          = new CustomButton();
            this.resetScaleButton.FontSize = this.FontSize;
            this.resetScaleButton.Text     = Translation.GetText("UI", "reset");
            this.resetScaleButton.Click   += this.ResetScale;
            this.ChildControls.Add(this.resetScaleButton);

            this.modelDeleteButton          = new CustomButton();
            this.modelDeleteButton.FontSize = this.FontSize;
            this.modelDeleteButton.Text     = Translation.GetText("Model", "modelDelete");
            this.modelDeleteButton.Click   += this.DeleteModel;
            this.ChildControls.Add(this.modelDeleteButton);

            this.modelCopyButton          = new CustomButton();
            this.modelCopyButton.FontSize = this.FontSize;
            this.modelCopyButton.Text     = Translation.GetText("Model", "modelCopy");
            this.modelCopyButton.Click   += this.CopyModel;
            this.ChildControls.Add(this.modelCopyButton);
        }
Ejemplo n.º 10
0
        public static IEnumerator Run(Material material, CfgGroup cfg)
        {
#if (DEBUG)
            Debug.Log($"Editing material with name of: {material.name} with configuration for {cfg.GroupName}");
#endif

            yield return(new WaitForEndOfFrame());

            if (material == null)
            {
                yield break;
            }
            //ModifyShaderIntoOutlineShader
            if (cfg.SetOutlineShader.Value)
            {
                if (!material.shader.name.Contains("Outline") && material.GetTag("Queue", true, null) != "Transparent" && material.GetTag("Queue", true, null) != "AlphaTest")
                {
                    /*
                     *      List<string> keywords = new List<string>(material.shaderKeywords);
                     *
                     #if (DEBUG)
                     *      foreach (string s in keywords){
                     *              Debug.Log($"{material.shader.name} has the shader keyword of {s}");
                     *      }
                     #endif
                     */

                    //if (!keywords.Contains("_ALPHAPREMULTIPLY_ON"))
                    //{

                    Shader shader = new Shader();

#if (DEBUG)
                    Debug.Log($"Trying to fetch shader of name Shaders/" + material.shader.name + "_Outline");
#endif

                    //shader = Resources.Load<Shader>("Shaders/" + material.shader.name + "_Outline");

                    shader = Shader.Find(material.shader.name + "_Outline");

                    if (shader == null)
                    {
#if (DEBUG)
                        Debug.Log($"No shader found, resorting to fallback!");
#endif
                        //shader = Resources.Load<Shader>("Shaders/" + "CM3D2/Lighted_Outline");

                        shader = Shader.Find("CM3D2/Toony_Lighted_Outline");
                    }

                    if (shader != null)
                    {
#if (DEBUG)
                        Debug.Log($"Setting {shader.name} as new material over {material.shader.name}");
#endif

                        material.shader = shader;
                    }
                    //}
                }
                else if (material.shader.name.Contains("Outline_Tex"))
                {
                    Shader shader = new Shader();

#if (DEBUG)
                    Debug.Log($"Shaders/" + material.shader.name.Replace("_Tex", ""));
#endif

                    //shader = Resources.Load<Shader>("Shaders/" + material.shader.name.Replace("_Tex", ""));

                    shader = Shader.Find(material.shader.name.Replace("_Tex", ""));

                    if (shader == null)
                    {
#if (DEBUG)
                        Debug.Log($"No shader found, resorting to fallback!");
#endif

                        shader = Shader.Find("CM3D2/Toony_Lighted_Outline");
                    }

                    if (shader != null)
                    {
#if (DEBUG)
                        Debug.Log($"Setting {shader.name} as new material over {material.shader.name}");
#endif

                        material.shader = shader;
                    }
                }
            }

            //ModifyRimPower
            if (cfg.EditRimPower.Value && material.GetFloat(RimPow) != cfg.RimPower.Value)
            {
#if (DEBUG)
                Debug.Log($"Editing RimPow");
#endif
                material.SetFloat(RimPow, cfg.RimPower.Value);
            }
            if (cfg.EditRimPower.Value && material.GetFloat(NPRRimPow) != cfg.RimPower.Value)
            {
                material.SetFloat(NPRRimPow, cfg.RimPower.Value);
            }
            //ModifyRimShift
            if (cfg.EditRimShift.Value && material.GetFloat(RimShift) != cfg.RimShift.Value)
            {
#if (DEBUG)
                Debug.Log($"Editing RimShift");
#endif
                material.SetFloat(RimShift, cfg.RimShift.Value);
            }
            if (cfg.EditRimShift.Value && material.GetFloat(NPRRimShift) != cfg.RimShift.Value)
            {
#if (DEBUG)
                Debug.Log($"Editing RimShift");
#endif
                material.SetFloat(NPRRimShift, cfg.RimShift.Value);
            }
            //ModifyRimColor
            if (cfg.EditRimColor.Value)
            {
#if (DEBUG)
                Debug.Log($"Editing RimCol");
#endif
                Color c = new Color(cfg.RimRed.Value, cfg.RimGreen.Value, cfg.RimBlue.Value, cfg.RimAlpha.Value);

                if (material.GetColor(RimCol) != c)
                {
                    material.SetColor(RimCol, c);
                }

                if (material.GetColor(NPRRimCol) != c)
                {
                    material.SetColor(NPRRimCol, c);
                }
            }
            //ModifyOutlineWidth
            if (cfg.EditOutlineWidth.Value && material.GetFloat(OutlineWid) != cfg.OutlineWidth.Value)
            {
#if (DEBUG)
                Debug.Log($"Editing Outline Width");
#endif
                material.SetFloat(OutlineWid, cfg.OutlineWidth.Value);
            }
            //ModifyOutlineColor
            if (cfg.EditOutlineColor.Value)
            {
#if (DEBUG)
                Debug.Log($"Editing OutlineColor");
#endif
                Color c = new Color(cfg.OutlineRed.Value, cfg.OutlineGreen.Value, cfg.OutlineBlue.Value, cfg.OutlineAlpha.Value);

                if (material.GetColor(OutlineCol) != c)
                {
                    material.SetColor(OutlineCol, c);
                }
            }
            //ModifyToonRamp
            if (cfg.ChangeToonTex.Value)
            {
                try
                {
                    Texture2D tex = ImportCM.CreateTexture(cfg.ToonTex.Value);

                    if (material.GetTexture(Toon) != tex)
                    {
                        material.SetTexture(Toon, tex);
                    }
                }
                catch { };
            }
            //ModifyShadowRateToon
            if (cfg.ChangeShadowRateTex.Value)
            {
                try
                {
                    Texture2D tex = ImportCM.CreateTexture(cfg.ShadowRateTex.Value);

                    if (material.GetTexture(ShadowRate) != tex)
                    {
                        material.SetTexture(ShadowRate, tex);
                    }
                }
                catch { };
            }
            //ModifyShadowColor
            if (cfg.EditShadowColor.Value)
            {
                Color c = new Color(cfg.ShadowRed.Value, cfg.ShadowGreen.Value, cfg.ShadowBlue.Value, cfg.ShadowAlpha.Value);

                if (material.GetColor(ShadowCol) != c)
                {
                    material.SetColor(ShadowCol, c);
                }
            }
        }