From c3b87d717f24c9e0673d826ac1472cd82b73ff75 Mon Sep 17 00:00:00 2001 From: krypto5863 <29824718+krypto5863@users.noreply.github.com> Date: Wed, 3 Aug 2022 20:21:11 -0400 Subject: [PATCH] Cleaned, did SMVD changes. --- .../0OldClasses/ControlClass.cs | 4 +- .../0OldClasses/Main - TPLimplementation.cs | 17 ++----- .../0OldClasses/Main - TPLimplementation2.cs | 13 ++--- .../0OldClasses/Main.cs | 28 +++-------- .../InfinitePartitioner.cs | 2 +- .../LiveDirectory.cs | 8 +-- .../Loaders/GSModMenuLoad.cs | 50 ++++++------------- .../Loaders/ModMenuLoad.cs | 10 ++-- .../Loaders/VanillaMenuLoad.cs | 38 +++++++------- .../Loaders/VanillaMenuLoaderSMVDCompat.cs | 15 +++--- Experiment5ParallelMenuLoading/Main.cs | 9 ++-- Experiment5ParallelMenuLoading/MenuStub.cs | 20 ++++++-- .../ParallelWhile.cs | 3 +- .../PreloadTexture.cs | 11 ++-- .../Properties/AssemblyInfo.cs | 2 +- Experiment5ParallelMenuLoading/QuickEdit.cs | 28 +++++------ .../QuickEditVanilla.cs | 11 +--- 17 files changed, 105 insertions(+), 164 deletions(-) diff --git a/Experiment5ParallelMenuLoading/0OldClasses/ControlClass.cs b/Experiment5ParallelMenuLoading/0OldClasses/ControlClass.cs index 64617e6..7cc1400 100644 --- a/Experiment5ParallelMenuLoading/0OldClasses/ControlClass.cs +++ b/Experiment5ParallelMenuLoading/0OldClasses/ControlClass.cs @@ -51,10 +51,8 @@ static IEnumerable Transpiler1(IEnumerable ins new CodeInstruction(OpCodes.Ldarg_0), Transpilers.EmitDelegate(() => { - Main.logger.LogDebug("Calling your control test coroutine."); @this2.StartCoroutine(InitMenuNative()); - }), new CodeInstruction(OpCodes.Pop) ) @@ -193,4 +191,4 @@ private static IEnumerator InitMenuNative() yield break; } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/0OldClasses/Main - TPLimplementation.cs b/Experiment5ParallelMenuLoading/0OldClasses/Main - TPLimplementation.cs index 8aeb326..1c8c46a 100644 --- a/Experiment5ParallelMenuLoading/0OldClasses/Main - TPLimplementation.cs +++ b/Experiment5ParallelMenuLoading/0OldClasses/Main - TPLimplementation.cs @@ -21,7 +21,6 @@ namespace Experiment5ParallelMenuLoading [BepInPlugin("Experiment5ParallelMenuLoading", "Experiment5ParallelMenuLoading", "1.0.0.0")] public class Main : BaseUnityPlugin { - public static Harmony harmony; public static SceneEdit @this; public static Main @this2; @@ -84,14 +83,12 @@ static IEnumerable Transpiler1(IEnumerable ins new CodeInstruction(OpCodes.Ldarg_0), Transpilers.EmitDelegate(() => { - Main.logger.LogInfo("Calling your test coroutine."); //InitMenuNativeRe(); @this2.StartCoroutine(LoadIcons()); @this2.StartCoroutine(test2()); //test2(); - }), new CodeInstruction(OpCodes.Pop) ) @@ -102,7 +99,6 @@ static IEnumerable Transpiler1(IEnumerable ins } public static IEnumerator test2() { - Stopwatch test = new Stopwatch(); Main.logger.LogError("Coroutine was successfully engaged!"); @@ -221,7 +217,7 @@ public static IEnumerator test2() SetupDone = true; - while (IconLoadDone != true) + while (IconLoadDone != true) { yield return null; } @@ -319,8 +315,6 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile { NDebug.Assert(false, "メニュースクリプトが読めませんでした。" + f_strMenuFileName); } - - } catch (Exception ex) { @@ -338,7 +332,6 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile return true; } - public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFileName, bool f_bMan, out string IconTex) { var fetchedField = AccessTools.DeclaredField(typeof(SceneEdit), "m_byItemFileBuffer"); @@ -565,7 +558,7 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi public static IEnumerator LoadIcons() { - while (SetupDone == false || ListOfIconLoads.Count > 1) + while (SetupDone == false || ListOfIconLoads.Count > 1) { if (ListOfIconLoads.Count == 0) { @@ -573,13 +566,11 @@ public static IEnumerator LoadIcons() } else { - Main.logger.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 _); - } } @@ -593,11 +584,11 @@ public static IEnumerator ThrowConcurrentException(string error) yield return null; } /* - public static IEnumerator LoadTexture(SceneEdit.SMenuItem menu, string texture) + public static IEnumerator LoadTexture(SceneEdit.SMenuItem menu, string texture) { menu.m_texIcon = ImportCM.CreateTexture(texture); yield return null; }*/ } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/0OldClasses/Main - TPLimplementation2.cs b/Experiment5ParallelMenuLoading/0OldClasses/Main - TPLimplementation2.cs index f1ed270..38dab0f 100644 --- a/Experiment5ParallelMenuLoading/0OldClasses/Main - TPLimplementation2.cs +++ b/Experiment5ParallelMenuLoading/0OldClasses/Main - TPLimplementation2.cs @@ -21,7 +21,6 @@ namespace Experiment5ParallelMenuLoading [BepInPlugin("Experiment5ParallelMenuLoading", "Experiment5ParallelMenuLoading", "1.0.0.0")] public class Main : BaseUnityPlugin { - public static Harmony harmony; public static SceneEdit @this; public static Main @this2; @@ -30,7 +29,6 @@ public class Main : BaseUnityPlugin private static bool SetupDone = false; private static bool IconLoadDone = false; - /* static Dictionary menuRidDicThreadSafe; static Dictionary> menuGroupMemberDic; @@ -92,7 +90,6 @@ static IEnumerable Transpiler1(IEnumerable ins new CodeInstruction(OpCodes.Ldarg_0), Transpilers.EmitDelegate(() => { - Main.logger.LogInfo("Calling your test coroutine."); //InitMenuNativeRe(); @@ -101,7 +98,6 @@ static IEnumerable Transpiler1(IEnumerable ins @this2.StartCoroutine(InitialBackgroundWorker()); //@this2.StartCoroutine(MenuLoaderWorker()); //test2(); - }), new CodeInstruction(OpCodes.Pop) ) @@ -112,7 +108,6 @@ static IEnumerable Transpiler1(IEnumerable ins } public static IEnumerator InitialBackgroundWorker() { - Main.logger.LogError("Coroutine was successfully engaged!"); while (GameMain.Instance.CharacterMgr.IsBusy()) @@ -232,7 +227,7 @@ public static IEnumerator InitialBackgroundWorker() { var keyPair = ListOfIconLoads.FirstOrDefault(); - if (keyPair.Key == null || keyPair.Value == null) + if (keyPair.Key == null || keyPair.Value == null) { ListOfIconLoads.Remove(keyPair.Key); continue; @@ -263,10 +258,9 @@ public static IEnumerator InitialBackgroundWorker() //foreach (SceneEdit.SMenuItem mi2 in ListOfContinues) while (ListOfContinues.Count > 0) { - var mi2 = ListOfContinues.FirstOrDefault(); - if (mi2 == null) + if (mi2 == null) { continue; } @@ -340,7 +334,6 @@ public static IEnumerator InitialBackgroundWorker() test.Reset(); yield break; - }/* public static IEnumerator MenuLoaderWorker() { @@ -606,4 +599,4 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi return true; } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/0OldClasses/Main.cs b/Experiment5ParallelMenuLoading/0OldClasses/Main.cs index 1713cc7..3911097 100644 --- a/Experiment5ParallelMenuLoading/0OldClasses/Main.cs +++ b/Experiment5ParallelMenuLoading/0OldClasses/Main.cs @@ -20,7 +20,6 @@ namespace Experiment5ParallelMenuLoading [BepInPlugin("Experiment5ParallelMenuLoading", "Experiment5ParallelMenuLoading", "1.0.0.0")] public class Main : BaseUnityPlugin { - public static Harmony harmony; public static SceneEdit @this; public static Main @this2; @@ -85,7 +84,6 @@ static IEnumerable Transpiler1(IEnumerable ins new CodeInstruction(OpCodes.Ldarg_0), Transpilers.EmitDelegate(() => { - Main.logger.LogInfo("Calling your test coroutine."); ListOfContinues = new Dictionary(); @@ -98,7 +96,6 @@ static IEnumerable Transpiler1(IEnumerable ins @this.StartCoroutine(SetupTexturesCoRoutine()); Task.Factory.StartNew(new Action(() => test2())); //Task.Factory.StartNew(new Action(() => Test2Continuation())); - }), new CodeInstruction(OpCodes.Pop) ) @@ -109,7 +106,6 @@ static IEnumerable Transpiler1(IEnumerable ins } public static void test2() { - Main.logger.LogError("Coroutine was successfully engaged!"); while (GameMain.Instance.CharacterMgr.IsBusy()) @@ -216,8 +212,6 @@ public static void test2() Main.logger.LogError("Finished GetMenuItemSetUP: " + test2.Elapsed); }//); - - //@this2.StartCoroutine(SetupTexturesCoRoutine(menuList, menuGroupMemberDic)); SavedmenuList = menuList; @@ -227,10 +221,9 @@ public static void test2() public static IEnumerator SetupTexturesCoRoutine() { - Main.logger.LogError($"Starting coroutine to set textures to menu items."); - while (Test2Done != true) + while (Test2Done != true) { yield return null; } @@ -248,7 +241,7 @@ public static IEnumerator SetupTexturesCoRoutine() Test2Continuation(); - while (Test2ContinuatonDone == false) + while (Test2ContinuatonDone == false) { yield return null; } @@ -278,7 +271,7 @@ public static void Test2Continuation() int i = 0; - while (i < ListOfContinues.Keys.Count()) + while (i < ListOfContinues.Keys.Count()) { Main.logger.LogError("Relooping for."); @@ -287,7 +280,7 @@ public static void Test2Continuation() Main.logger.LogError("Creating task..."); - while (d < 1 && i < ListOfContinues.Keys.Count()) + while (d < 1 && i < ListOfContinues.Keys.Count()) { int index = i; taskList.Add(Task.Factory.StartNew(new Action(() => ContinueSetup(list[index])))); @@ -302,7 +295,7 @@ public static void Test2Continuation() //Main.logger.LogError($"Waiting for tasks to complete: {taskList.Count}"); Task.WaitAll(taskList.ToArray()); - + Main.logger.LogError("All tasks complete. Starting a new batch."); } @@ -318,7 +311,7 @@ public static void Test2Continuation() //yield break; } - public static void ContinueSetup(SceneEdit.SMenuItem mi2) + public static void ContinueSetup(SceneEdit.SMenuItem mi2) { Stopwatch test2 = new Stopwatch(); @@ -371,7 +364,6 @@ public static void ContinueSetup(SceneEdit.SMenuItem mi2) public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFileName, out string IconTex, bool f_bMan = false) { - IconTex = null; if (f_strMenuFileName.Contains("_zurashi")) @@ -391,8 +383,6 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile { NDebug.Assert(false, "メニュースクリプトが読めませんでした。" + f_strMenuFileName); } - - } catch (Exception ex) { @@ -410,7 +400,6 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile return true; } - public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFileName, bool f_bMan, out string IconTex) { var fetchedField = AccessTools.DeclaredField(typeof(SceneEdit), "m_byItemFileBuffer"); @@ -635,7 +624,6 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi return true; } - public static IEnumerator ThrowConcurrentException(string error) { Main.logger.LogError("A concurrent thread ran into this error: " + error); @@ -643,11 +631,11 @@ public static IEnumerator ThrowConcurrentException(string error) yield return null; } /* - public static IEnumerator LoadTexture(SceneEdit.SMenuItem menu, string texture) + public static IEnumerator LoadTexture(SceneEdit.SMenuItem menu, string texture) { menu.m_texIcon = ImportCM.CreateTexture(texture); yield return null; }*/ } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/InfinitePartitioner.cs b/Experiment5ParallelMenuLoading/InfinitePartitioner.cs index e17221b..7e8a735 100644 --- a/Experiment5ParallelMenuLoading/InfinitePartitioner.cs +++ b/Experiment5ParallelMenuLoading/InfinitePartitioner.cs @@ -38,4 +38,4 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/LiveDirectory.cs b/Experiment5ParallelMenuLoading/LiveDirectory.cs index 3d95612..05f8afc 100644 --- a/Experiment5ParallelMenuLoading/LiveDirectory.cs +++ b/Experiment5ParallelMenuLoading/LiveDirectory.cs @@ -44,11 +44,11 @@ public void DirectoryChanged(object sender, EventArgs e) if (args1.ChangeType == WatcherChangeTypes.Created) { FilesInDirectory.Add(args1.FullPath); - } - else if (args1.ChangeType == WatcherChangeTypes.Deleted) + } + else if (args1.ChangeType == WatcherChangeTypes.Deleted) { FilesInDirectory.Remove(args1.FullPath); - } + } } } @@ -63,4 +63,4 @@ public void Dispose() FilesInDirectory = null; } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/Loaders/GSModMenuLoad.cs b/Experiment5ParallelMenuLoading/Loaders/GSModMenuLoad.cs index 2bac545..20e0f13 100644 --- a/Experiment5ParallelMenuLoading/Loaders/GSModMenuLoad.cs +++ b/Experiment5ParallelMenuLoading/Loaders/GSModMenuLoad.cs @@ -1,17 +1,14 @@ -using HarmonyLib; -using Newtonsoft.Json; +using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using TMonitor = System.Threading.Monitor; using UnityEngine; +using TMonitor = System.Threading.Monitor; namespace ShortMenuLoader { @@ -29,7 +26,6 @@ internal class GSModMenuLoad public static IEnumerator LoadCache(int Retry = 0) { - CacheLoadDone = false; Task cacheLoader = Task.Factory.StartNew(new Action(() => @@ -73,6 +69,7 @@ public static IEnumerator LoadCache(int Retry = 0) } } } + public static IEnumerator SaveCache(int Retry = 0) { Task cacheSaver = Task.Factory.StartNew(new Action(() => @@ -81,7 +78,7 @@ public static IEnumerator SaveCache(int Retry = 0) .Where(k => FilesDictionary.Keys.Contains(k.Key)) .ToDictionary(t => t.Key, l => l.Value); - File.WriteAllText(CacheFile, JsonConvert.SerializeObject(MenuCache)); + File.WriteAllText(CacheFile, JsonConvert.SerializeObject(MenuCache, Formatting.Indented)); Main.logger.LogDebug("Finished cleaning and saving the mod cache..."); })); @@ -111,6 +108,7 @@ public static IEnumerator SaveCache(int Retry = 0) } } } + public static IEnumerator GSMenuLoadStart(List menuList, Dictionary> menuGroupMemberDic) { HashSet listOfLoads = new HashSet(); @@ -123,7 +121,6 @@ public static IEnumerator GSMenuLoadStart(List menuList, Di DictionaryBuilt = false; - var cts = new CancellationTokenSource(); var token = cts.Token; @@ -424,7 +421,6 @@ public static IEnumerator GSMenuLoadStart(List menuList, Di Main.@this.StartCoroutine(SaveCache()); - if (listOfDuplicates.Count > 0) { Main.logger.LogWarning($"There are {listOfDuplicates.Count} duplicate menus in your mod folder!"); @@ -474,6 +470,7 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile return true; } + public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFileName, out string IconTex) { IconTex = null; @@ -501,34 +498,17 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi mi.m_strInfo = tempStub.Description; } - if (tempStub.Category != null) - { - mi.m_strCateName = tempStub.Category; - mi.m_mpn = (MPN)Enum.Parse(typeof(MPN), tempStub.Category); - } - else - { - mi.m_mpn = MPN.null_mpn; - } + mi.m_strCateName = Enum.GetName(typeof(MPN), tempStub.Category); + mi.m_mpn = tempStub.Category; - if (tempStub.ColorSetMPN != null) - { - mi.m_eColorSetMPN = (MPN)Enum.Parse(typeof(MPN), tempStub.ColorSetMPN); - } + mi.m_eColorSetMPN = tempStub.ColorSetMPN; if (tempStub.ColorSetMenu != null) { mi.m_strMenuNameInColorSet = tempStub.ColorSetMenu; } - if (tempStub.MultiColorID == null) - { - mi.m_pcMultiColorID = MaidParts.PARTS_COLOR.NONE; - } - else if (tempStub.MultiColorID != null) - { - mi.m_pcMultiColorID = (MaidParts.PARTS_COLOR)Enum.Parse(typeof(MaidParts.PARTS_COLOR), tempStub.MultiColorID); - } + mi.m_pcMultiColorID = tempStub.MultiColorID; mi.m_boDelOnly = tempStub.DelMenu; @@ -681,11 +661,11 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi { string strCateName = stringList[1].ToLower(); mi.m_strCateName = strCateName; - cacheEntry.Category = mi.m_strCateName; + cacheEntry.Category = (MPN)Enum.Parse(typeof(MPN), mi.m_strCateName); try { mi.m_mpn = (MPN)Enum.Parse(typeof(MPN), mi.m_strCateName); - cacheEntry.Category = mi.m_mpn.ToString(); + cacheEntry.Category = mi.m_mpn; } catch { @@ -706,7 +686,7 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi try { mi.m_eColorSetMPN = (MPN)Enum.Parse(typeof(MPN), stringList[1].ToLower()); - cacheEntry.ColorSetMPN = mi.m_eColorSetMPN.ToString(); + cacheEntry.ColorSetMPN = mi.m_eColorSetMPN; } catch { @@ -742,7 +722,7 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi return false; } mi.m_pcMultiColorID = pcMultiColorID; - cacheEntry.MultiColorID = mi.m_pcMultiColorID.ToString(); + cacheEntry.MultiColorID = mi.m_pcMultiColorID; } } else if (stringCom == "icon" || stringCom == "icons") @@ -858,4 +838,4 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi return true; } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/Loaders/ModMenuLoad.cs b/Experiment5ParallelMenuLoading/Loaders/ModMenuLoad.cs index 03b9898..809837c 100644 --- a/Experiment5ParallelMenuLoading/Loaders/ModMenuLoad.cs +++ b/Experiment5ParallelMenuLoading/Loaders/ModMenuLoad.cs @@ -1,16 +1,11 @@ -using HarmonyLib; -using System; +using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using System.Threading; using System.Threading.Tasks; -using TMonitor = System.Threading.Monitor; using UnityEngine; -using Debug = UnityEngine.Debug; -using System.Diagnostics; namespace ShortMenuLoader { @@ -154,6 +149,7 @@ public static IEnumerator ModMenuLoadStart(List menuList, D Main.ThreadsDone++; Main.logger.LogInfo($".Mods finished loading at: {Main.WatchOverall.Elapsed}"); } + public static bool InitModMenuItemScript(SceneEdit.SMenuItem mi, string f_strModFileName, out byte[] Icon) { Icon = null; @@ -292,4 +288,4 @@ public static bool InitModMenuItemScript(SceneEdit.SMenuItem mi, string f_strMod return true; } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/Loaders/VanillaMenuLoad.cs b/Experiment5ParallelMenuLoading/Loaders/VanillaMenuLoad.cs index 9859990..15552ee 100644 --- a/Experiment5ParallelMenuLoading/Loaders/VanillaMenuLoad.cs +++ b/Experiment5ParallelMenuLoading/Loaders/VanillaMenuLoad.cs @@ -6,10 +6,8 @@ using System.Diagnostics; using System.IO; using System.Linq; -using System.Threading; using System.Threading.Tasks; using UnityEngine; -using Debug = UnityEngine.Debug; namespace ShortMenuLoader { @@ -18,6 +16,7 @@ internal class VanillaMenuLoad private static readonly string CacheFile = BepInEx.Paths.CachePath + "\\ShortMenuLoaderVanillaCache.json"; private static bool CacheLoadDone = false; private static Dictionary MenuCache = new Dictionary(); + public static IEnumerator LoadCache(int Retry = 0) { CacheLoadDone = false; @@ -65,6 +64,7 @@ public static IEnumerator LoadCache(int Retry = 0) } CacheLoadDone = true; } + public static IEnumerator SaveCache(Dictionary filesToLoad, int Retry = 0) { if (!Main.SMVDLoaded && Main.UseVanillaCache.Value) @@ -108,6 +108,7 @@ public static IEnumerator SaveCache(Dictionary file } } } + public static IEnumerator VanillaMenuLoadStart(List menuList, Dictionary> menuGroupMemberDic) { Dictionary filesToLoadFromDatabase = new Dictionary(); @@ -135,8 +136,8 @@ public static IEnumerator VanillaMenuLoadStart(List menuLis //This entire for loop is what loads in normal game menus. It's been left relatively untouched. - if (!Main.SMVDLoaded) { - + if (!Main.SMVDLoaded) + { int fileCount = menuDataBase.GetDataSize(); for (int i = 0; i < fileCount; i++) @@ -155,7 +156,8 @@ public static IEnumerator VanillaMenuLoadStart(List menuLis filesToLoadFromDatabase[mi] = i; } } - } else + } + else { VanillaMenuLoaderSMVDCompat.LoadFromSMVDDictionary(ref filesToLoadFromDatabase); } @@ -179,11 +181,11 @@ public static IEnumerator VanillaMenuLoadStart(List menuLis { 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_mpn = tempStub.Category; + mi.m_strCateName = Enum.GetName(typeof(MPN), tempStub.Category); + mi.m_eColorSetMPN = tempStub.ColorSetMPN; mi.m_strMenuNameInColorSet = tempStub.ColorSetMenu; - mi.m_pcMultiColorID = (MaidParts.PARTS_COLOR)Enum.Parse(typeof(MaidParts.PARTS_COLOR), tempStub.MultiColorID); + mi.m_pcMultiColorID = tempStub.MultiColorID; mi.m_boDelOnly = tempStub.DelMenu; mi.m_fPriority = tempStub.Priority; mi.m_bMan = tempStub.ManMenu; @@ -207,7 +209,7 @@ public static IEnumerator VanillaMenuLoadStart(List menuLis filesToLoad[mi] = null; if (!string.IsNullOrEmpty(iconFileName) && GameUty.FileSystem.IsExistentFile(iconFileName)) - { + { /* if (SceneEdit.Instance != null) { @@ -236,7 +238,7 @@ public static IEnumerator VanillaMenuLoadStart(List menuLis } } - while (GSModMenuLoad.DictionaryBuilt == false) + while (GSModMenuLoad.DictionaryBuilt == false) { yield return null; } @@ -280,9 +282,9 @@ public static IEnumerator VanillaMenuLoadStart(List menuLis } Main.ThreadsDone++; - Main.logger.LogInfo($"Vanilla menus finished loading at: {Main.WatchOverall.Elapsed}. " - + ((Main.SMVDLoaded == false) ? - $"We also spent {waitOnKiss.Elapsed} waiting for an unmodified database to finish loading..." + Main.logger.LogInfo($"Vanilla menus finished loading at: {Main.WatchOverall.Elapsed}. " + + ((Main.SMVDLoaded == false) ? + $"We also spent {waitOnKiss.Elapsed} waiting for an unmodified database to finish loading..." : $"We also spent {waitOnKiss.Elapsed} waiting for SMVD's Database to load...")); Main.@this.StartCoroutine(SaveCache(filesToLoad)); @@ -313,10 +315,10 @@ public static void ReadMenuItemDataFromNative(SceneEdit.SMenuItem mi, int menuDa { Name = mi.m_strMenuName, Description = mi.m_strInfo, - Category = mi.m_mpn.ToString(), - ColorSetMPN = mi.m_eColorSetMPN.ToString(), + Category = mi.m_mpn, + ColorSetMPN = mi.m_eColorSetMPN, ColorSetMenu = mi.m_strMenuNameInColorSet, - MultiColorID = mi.m_pcMultiColorID.ToString(), + MultiColorID = mi.m_pcMultiColorID, DelMenu = mi.m_boDelOnly, Priority = mi.m_fPriority, ManMenu = mi.m_bMan, @@ -338,4 +340,4 @@ public static void ReadMenuItemDataFromNative(SceneEdit.SMenuItem mi, int menuDa } } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/Loaders/VanillaMenuLoaderSMVDCompat.cs b/Experiment5ParallelMenuLoading/Loaders/VanillaMenuLoaderSMVDCompat.cs index a8bbcfe..50f6470 100644 --- a/Experiment5ParallelMenuLoading/Loaders/VanillaMenuLoaderSMVDCompat.cs +++ b/Experiment5ParallelMenuLoading/Loaders/VanillaMenuLoaderSMVDCompat.cs @@ -1,13 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace ShortMenuLoader { - class VanillaMenuLoaderSMVDCompat + internal class VanillaMenuLoaderSMVDCompat { - internal static void ReadMenuItemDataFromNative(SceneEdit.SMenuItem mi, int menuDataBaseIndex, out string iconStr) + internal static void ReadMenuItemDataFromNative(SceneEdit.SMenuItem mi, int menuDataBaseIndex, out string iconStr) { var menuDataBase = ShortMenuVanillaDatabase.Main.Database.MenusList; mi.m_strMenuName = menuDataBase[menuDataBaseIndex].Name; @@ -29,12 +27,11 @@ internal static void ReadMenuItemDataFromNative(SceneEdit.SMenuItem mi, int menu } } - internal static void LoadFromSMVDDictionary(ref Dictionary filesToLoadFromDatabase) { - foreach (KeyValuePair menu in ShortMenuVanillaDatabase.Main.Database.MenusList) + foreach (var menu in ShortMenuVanillaDatabase.Main.Database.MenusList) { - string fileName = menu.Value.FileName; + string fileName = menu.FileName; if (GameMain.Instance.CharacterMgr.status.IsHavePartsItem(fileName)) { @@ -44,9 +41,9 @@ internal static void LoadFromSMVDDictionary(ref Dictionary r.Equals(menu)); } } } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/Main.cs b/Experiment5ParallelMenuLoading/Main.cs index 6c95e5f..5595aa8 100644 --- a/Experiment5ParallelMenuLoading/Main.cs +++ b/Experiment5ParallelMenuLoading/Main.cs @@ -12,7 +12,6 @@ using System.Security; using System.Security.Permissions; using System.Text.RegularExpressions; -using System.Threading; using UnityEngine; [module: UnverifiableCode] @@ -20,7 +19,7 @@ namespace ShortMenuLoader { - [BepInPlugin("ShortMenuLoader", "ShortMenuLoader", "1.5.6")] + [BepInPlugin("ShortMenuLoader", "ShortMenuLoader", "1.5.7")] [BepInDependency("ShortMenuVanillaDatabase", BepInDependency.DependencyFlags.SoftDependency)] internal class Main : BaseUnityPlugin { @@ -130,6 +129,7 @@ private static void GetInstance(ref SceneEdit __instance) WatchOverall.Start(); @this = __instance; } + [HarmonyPatch(typeof(SceneEdit), "Start")] [HarmonyTranspiler] private static IEnumerable Transpiler1(IEnumerable instructions) @@ -153,7 +153,6 @@ private static IEnumerable Transpiler1(IEnumerable Transpiler1(IEnumerable menuList = new List(); @@ -208,6 +208,7 @@ private static IEnumerator InitMenuNative() Main.logger.LogInfo($"Loading completely done at: {WatchOverall.Elapsed}."); } + private static IEnumerator FixedInitMenu(List menuList, Dictionary menuRidDic, Dictionary> menuGroupMemberDic) { var watch = Stopwatch.StartNew(); @@ -293,7 +294,6 @@ private static IEnumerator FixedInitMenu(List menuList, Dic { if (mi.m_strMenuNameInColorSet != null) { - mi.m_strMenuNameInColorSet = mi.m_strMenuNameInColorSet.Replace("*", ".*"); mi.m_listColorSet = @this.m_dicColor[mi.m_eColorSetMPN].FindAll((SceneEdit.SMenuItem i) => new Regex(mi.m_strMenuNameInColorSet).IsMatch(i.m_strMenuFileName)); } @@ -377,7 +377,6 @@ private static IEnumerator FixedInitMenu(List menuList, Dic } } - @this.UpdatePanel_Category(); Main.logger.LogInfo($"FixedInitMenu done in {watch.Elapsed}"); diff --git a/Experiment5ParallelMenuLoading/MenuStub.cs b/Experiment5ParallelMenuLoading/MenuStub.cs index 2a58f35..8b7a261 100644 --- a/Experiment5ParallelMenuLoading/MenuStub.cs +++ b/Experiment5ParallelMenuLoading/MenuStub.cs @@ -1,4 +1,6 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System; namespace ShortMenuLoader { @@ -8,14 +10,22 @@ internal class MenuStub public string SourceArc { get; set; } public string Icon { get; set; } public string Description { get; set; } - public string Category { get; set; } - public string ColorSetMPN { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public MPN Category { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public MPN ColorSetMPN { get; set; } + public string ColorSetMenu { get; set; } - public string MultiColorID { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public MaidParts.PARTS_COLOR MultiColorID { get; set; } + public bool DelMenu { get; set; } public bool ManMenu { get; set; } public float Priority { get; set; } public bool LegacyMenu { get; set; } public DateTime DateModified { get; set; } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/ParallelWhile.cs b/Experiment5ParallelMenuLoading/ParallelWhile.cs index 45e8368..1edb135 100644 --- a/Experiment5ParallelMenuLoading/ParallelWhile.cs +++ b/Experiment5ParallelMenuLoading/ParallelWhile.cs @@ -17,5 +17,4 @@ public static void While(ParallelOptions parallelOptions, Func condition, }); } } -} - +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/PreloadTexture.cs b/Experiment5ParallelMenuLoading/PreloadTexture.cs index 83be843..3206a4f 100644 --- a/Experiment5ParallelMenuLoading/PreloadTexture.cs +++ b/Experiment5ParallelMenuLoading/PreloadTexture.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; namespace ShortMenuLoader @@ -24,10 +21,10 @@ internal class PreloadTexture public string TextureName { get; private set; } = string.Empty; - private PreloadTexture(Texture2D tex) + private PreloadTexture(Texture2D tex) { Texture = tex; - } + } public PreloadTexture(int width, int height, TextureFormat format, ref Rect[] uvRects, ref byte[] data, string texName = null) { @@ -43,7 +40,7 @@ public PreloadTexture(int width, int height, TextureFormat format, ref Rect[] uv this.data = data; } - public Texture2D CreateTexture2D() + public Texture2D CreateTexture2D() { if (Texture == null) { @@ -70,4 +67,4 @@ public Texture2D CreateTexture2D() return Texture; } } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/Properties/AssemblyInfo.cs b/Experiment5ParallelMenuLoading/Properties/AssemblyInfo.cs index aad07d0..09592ac 100644 --- a/Experiment5ParallelMenuLoading/Properties/AssemblyInfo.cs +++ b/Experiment5ParallelMenuLoading/Properties/AssemblyInfo.cs @@ -32,4 +32,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/QuickEdit.cs b/Experiment5ParallelMenuLoading/QuickEdit.cs index d0ef562..551b6c3 100644 --- a/Experiment5ParallelMenuLoading/QuickEdit.cs +++ b/Experiment5ParallelMenuLoading/QuickEdit.cs @@ -1,5 +1,4 @@ using HarmonyLib; -using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Concurrent; @@ -7,11 +6,10 @@ using System.Diagnostics; using System.IO; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TMonitor = System.Threading.Monitor; using UnityEngine; +using TMonitor = System.Threading.Monitor; namespace ShortMenuLoader { @@ -19,11 +17,12 @@ internal static class QuickEdit { private static long AmountOfDataPreloaded; - //A cache of files + //A cache of files private static Dictionary f_TexInModFolder = null; //Will be accessed in a concurrent modality frequently. Locking is slow. internal static Dictionary f_RidsToStubs = new Dictionary(); + private static readonly ConcurrentDictionary f_ProcessedTextures = new ConcurrentDictionary(); //Should only be used in a non-concurrent modality. @@ -41,6 +40,7 @@ internal static void EngageModPreloader() Main.@this.StartCoroutine(f_TextureLoaderCoroute); } } + //Despite how it may appear, this is used, it's patched manually in Main.Awake private static void MenuItemSet(ref SceneEdit.SMenuItem __1) { @@ -79,11 +79,11 @@ private static bool GetTextureByRid(ref Texture2D __result, int __2) return true; } + [HarmonyPatch(typeof(SceneEditWindow.CustomViewItem), "UpdateIcon")] [HarmonyPrefix] private static void UpdateIcon(ref SceneEditWindow.CustomViewItem __instance, Maid __0) { - if (__0 == null) { __0 = GameMain.Instance.CharacterMgr.GetMaid(0); @@ -102,11 +102,11 @@ private static void UpdateIcon(ref SceneEditWindow.CustomViewItem __instance, Ma } else if (menuItem.m_texIcon == null || menuItem.m_texIcon == Texture2D.whiteTexture) { - if (f_RidsToStubs.ContainsKey(menuItem.m_nMenuFileRID)) + if (f_RidsToStubs.ContainsKey(menuItem.m_nMenuFileRID)) { menuItem.m_texIcon = GetTexture(menuItem.m_nMenuFileRID); menuItem.m_texIconRandomColor = menuItem.m_texIcon; - } + } } } @@ -122,12 +122,11 @@ private static Texture2D GetTexture(int menuFileID) if (Main.UseIconPreloader.Value == false) { - if (ModDirScanned) { var fetchedResource = LoadTextureFromModFolder(textureFileName); - if (fetchedResource != null) + if (fetchedResource != null) { return fetchedResource.CreateTexture2D(); } @@ -213,7 +212,7 @@ private static IEnumerator TextureLoader() var watch2 = Stopwatch.StartNew(); - var modQueue = new ConcurrentQueue(f_RidsToStubs.Values.Where(val => !f_ProcessedTextures.ContainsKey(val) && !f_LoadedTextures.ContainsKey(val))); + var modQueue = new ConcurrentQueue(f_RidsToStubs.Values.Where(val => !f_ProcessedTextures.ContainsKey(val) && !f_LoadedTextures.ContainsKey(val))); Main.logger.LogInfo($"Starting preloader... GC at {GC.GetTotalMemory(false) / 1000000}"); @@ -222,7 +221,6 @@ private static IEnumerator TextureLoader() { if (modQueue.Count > 0 && modQueue.TryDequeue(out var key)) { - var loadedTex = LoadTextureFromModFolder(key); if (loadedTex != null) @@ -329,7 +327,7 @@ public static PreloadTexture LoadTextureFromModFolder(string f_strFileName) int num7 = binaryReader.ReadInt32(); - if (num7 > binaryReader.BaseStream.Length) + if (num7 > binaryReader.BaseStream.Length) { Array.Resize(ref array, 0); Main.logger.LogWarning($"{f_strFileName} may be corrupted. The loader will use a white texture instead. Please correct the issue or expect large RAM usage spikes."); @@ -377,7 +375,7 @@ public static PreloadTexture LoadTextureFromModFolder(string f_strFileName) } /* - public static void OverlayIcon(ref Texture2D texture2D) + public static void OverlayIcon(ref Texture2D texture2D) { Material systemMaterial = GameUty.GetSystemMaterial(GameUty.SystemMaterial.Alpha); @@ -390,7 +388,7 @@ public static void OverlayIcon(ref Texture2D texture2D) TempRender.DiscardContents(); } - if (ModIconOverlayLoaded == null) + if (ModIconOverlayLoaded == null) { ModIconOverlayLoaded = new Texture2D(80,80); ModIconOverlayLoaded.LoadImage(ModIconOverlay); @@ -402,4 +400,4 @@ public static void OverlayIcon(ref Texture2D texture2D) } */ } -} +} \ No newline at end of file diff --git a/Experiment5ParallelMenuLoading/QuickEditVanilla.cs b/Experiment5ParallelMenuLoading/QuickEditVanilla.cs index 87d65aa..780b5f2 100644 --- a/Experiment5ParallelMenuLoading/QuickEditVanilla.cs +++ b/Experiment5ParallelMenuLoading/QuickEditVanilla.cs @@ -1,19 +1,12 @@ using HarmonyLib; -using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using UnityEngine; namespace ShortMenuLoader { - class QuickEditVanilla + internal class QuickEditVanilla { internal static Dictionary f_RidsToStubs = new Dictionary(); private static ConcurrentDictionary f_ProcessedTextures = new ConcurrentDictionary(); @@ -36,7 +29,6 @@ internal static void EngageVanillaPreloader() [HarmonyPrefix] private static bool GetTextureByRid(ref Texture2D __result, int __0) { - if (f_RidsToStubs.ContainsKey(__0)) { __result = GetTexture(__0); @@ -46,6 +38,7 @@ private static bool GetTextureByRid(ref Texture2D __result, int __0) return true; } + //Checks if we have the icon and says yes, look no further. [HarmonyPatch(typeof(EditItemTextureCache), "IsRegister")] [HarmonyPrefix]