From 74867976aab5cfd7423acad00c66511cbc605b15 Mon Sep 17 00:00:00 2001 From: DeathWeasel1337 Date: Wed, 20 Feb 2019 17:39:04 -0600 Subject: [PATCH] Fix breaking with missing .csv, add stripping extended data --- KK_GUIDMigration/KK_GUIDMigration.cs | 70 +++++++++++++++------------ KK_GUIDMigration/KK_GUIDMigration.csv | 7 ++- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/KK_GUIDMigration/KK_GUIDMigration.cs b/KK_GUIDMigration/KK_GUIDMigration.cs index 517e9bdc..957ff563 100644 --- a/KK_GUIDMigration/KK_GUIDMigration.cs +++ b/KK_GUIDMigration/KK_GUIDMigration.cs @@ -19,25 +19,28 @@ public class KK_GUIDMigration : BaseUnityPlugin { public const string GUID = "com.deathweasel.bepinex.guidmigration"; public const string PluginName = "GUID Migration"; - public const string Version = "1.1"; + public const string Version = "1.2"; private static List MigrationInfoList = new List(); private static readonly string GUIDMigrationFilePath = Path.Combine(Paths.PluginPath, "KK_GUIDMigration.csv"); - private static bool DoMigration = false; void Main() { //Don't even bother if there's no mods directory if (Directory.Exists(Path.Combine(Paths.GameRootPath, "mods")) && Directory.Exists(Paths.PluginPath)) { - var harmony = HarmonyInstance.Create("com.deathweasel.bepinex.guidmigration"); - harmony.PatchAll(typeof(KK_GUIDMigration)); - //Only do migration if there's a .csv file and it has stuff in it if (File.Exists(GUIDMigrationFilePath)) { GenerateMigrationInfo(); if (MigrationInfoList.Count > 0) - DoMigration = true; + { + var harmony = HarmonyInstance.Create(GUID); + harmony.PatchAll(typeof(KK_GUIDMigration)); + } + else + { + Logger.Log(LogLevel.Error | LogLevel.Message, "KK_GUIDMigration was not loaded due to missing or empty KK_GUIDMigration.csv file."); + } } } } @@ -54,9 +57,9 @@ private static IEnumerable MigrateGUID(IEnumerable ext if (extInfo == null) return extInfo; - foreach (ResolveInfo a in extInfo) + foreach (ResolveInfo resolveInfo in extInfo) { - if (a.GUID.IsNullOrEmpty()) + if (resolveInfo.GUID.IsNullOrEmpty()) { //Don't add empty GUID to the new list, this way CompatibilityResolve will treat it as a hard mod and attempt to find a match if (!DidBlankGUIDMessage) //No need to spam it for every single thing @@ -65,9 +68,9 @@ private static IEnumerable MigrateGUID(IEnumerable ext DidBlankGUIDMessage = true; } } - else if (DoMigration) + else { - string propertyWithoutPrefix = a.Property; + string propertyWithoutPrefix = resolveInfo.Property; //Remove outfit and accessory prefixes for searching purposes if (propertyWithoutPrefix.StartsWith("outfit")) @@ -75,16 +78,17 @@ private static IEnumerable MigrateGUID(IEnumerable ext if (propertyWithoutPrefix.StartsWith("accessory")) propertyWithoutPrefix = propertyWithoutPrefix.Remove(0, propertyWithoutPrefix.IndexOf('.') + 1); - MigrationInfo info = MigrationInfoList.Where(x => (x.Property == propertyWithoutPrefix && x.OldID == a.Slot && x.OldGUID == a.GUID) - || (x.Property == "*" && x.OldGUID == a.GUID)).FirstOrDefault(); + MigrationInfo info = MigrationInfoList.Where(x => (x.Property == propertyWithoutPrefix && x.OldID == resolveInfo.Slot && x.OldGUID == resolveInfo.GUID) + || (x.Property == "*" && x.OldGUID == resolveInfo.GUID) + || (x.Property == "-" && x.OldGUID == resolveInfo.GUID)).FirstOrDefault(); if (info == null) { //This item does not need to be migrated - extInfoNew.Add(a); + extInfoNew.Add(resolveInfo); } else if (info.Property == "*") //* assumes only the GUID changed while the IDs stayed the same { - ResolveInfo GUIDCheckOld = UniversalAutoResolver.LoadedResolutionInfo.FirstOrDefault(x => x.GUID == a.GUID); + ResolveInfo GUIDCheckOld = UniversalAutoResolver.LoadedResolutionInfo.FirstOrDefault(x => x.GUID == resolveInfo.GUID); if (GUIDCheckOld == null) { @@ -92,10 +96,10 @@ private static IEnumerable MigrateGUID(IEnumerable ext //If we don't have the new mod the user will get a missing mod warning for the new mod since they should be using that instead. //If we do it will load correctly. Logger.Log(LogLevel.Info, $"Migrating GUID {info.OldGUID} -> {info.NewGUID}"); - ResolveInfo b = new ResolveInfo(); - b = a; - b.GUID = info.NewGUID; - extInfoNew.Add(b); + ResolveInfo resolveInfoNew = new ResolveInfo(); + resolveInfoNew = resolveInfo; + resolveInfoNew.GUID = info.NewGUID; + extInfoNew.Add(resolveInfoNew); } else { @@ -104,22 +108,26 @@ private static IEnumerable MigrateGUID(IEnumerable ext if (GUIDCheckNew == null) { //We have the old mod but not the new, do not do migration - extInfoNew.Add(a); + extInfoNew.Add(resolveInfo); } else { //We have the old mod and the new, do migration so characters save with the new stuff Logger.Log(LogLevel.Info, $"Migrating GUID {info.OldGUID} -> {info.NewGUID}"); - ResolveInfo b = new ResolveInfo(); - b = a; - b.GUID = info.NewGUID; - extInfoNew.Add(b); + ResolveInfo resolveInfoNew = new ResolveInfo(); + resolveInfoNew = resolveInfo; + resolveInfoNew.GUID = info.NewGUID; + extInfoNew.Add(resolveInfoNew); } } } + else if (info.Property == "-") //- indicates the entry needs to be stripped of its extended data and loaded as a hard mod + { + continue; + } else { - ResolveInfo intResolveOld = UniversalAutoResolver.LoadedResolutionInfo.FirstOrDefault(x => x.Property == propertyWithoutPrefix && x.Slot == a.Slot && x.GUID == a.GUID); + ResolveInfo intResolveOld = UniversalAutoResolver.LoadedResolutionInfo.FirstOrDefault(x => x.Property == propertyWithoutPrefix && x.Slot == resolveInfo.Slot && x.GUID == resolveInfo.GUID); if (intResolveOld == null) { @@ -127,11 +135,11 @@ private static IEnumerable MigrateGUID(IEnumerable ext //If we don't have the new mod the user will get a missing mod warning for the new mod since they should be using that instead. //If we do it will load correctly. Logger.Log(LogLevel.Info, $"Migrating {info.OldGUID}:{info.OldID} -> {info.NewGUID}:{info.NewID}"); - ResolveInfo b = new ResolveInfo(); - b = a; - b.GUID = info.NewGUID; - b.Slot = info.NewID; - extInfoNew.Add(b); + ResolveInfo resolveInfoNew = new ResolveInfo(); + resolveInfoNew = resolveInfo; + resolveInfoNew.GUID = info.NewGUID; + resolveInfoNew.Slot = info.NewID; + extInfoNew.Add(resolveInfoNew); } else { @@ -140,14 +148,14 @@ private static IEnumerable MigrateGUID(IEnumerable ext if (intResolveNew == null) { //We have the old mod but not the new, do not do migration - extInfoNew.Add(a); + extInfoNew.Add(resolveInfo); } else { //We have the old mod and the new, do migration so characters save with the new stuff Logger.Log(LogLevel.Warning, $"Migrating {info.OldGUID}:{info.OldID} -> {info.NewGUID}:{info.NewID}"); ResolveInfo b = new ResolveInfo(); - b = a; + b = resolveInfo; b.GUID = info.NewGUID; b.Slot = info.NewID; extInfoNew.Add(b); diff --git a/KK_GUIDMigration/KK_GUIDMigration.csv b/KK_GUIDMigration/KK_GUIDMigration.csv index f06c2d52..25e7a8bc 100644 --- a/KK_GUIDMigration/KK_GUIDMigration.csv +++ b/KK_GUIDMigration/KK_GUIDMigration.csv @@ -12,6 +12,8 @@ *,HeartCat_mod2016051013,0,HearCat_ModPack,0 *,com.roy12.sexypacka,0,com.roy12.SexySchoolgirlPackA,0 *,nashi.Jacket.ver1,0,nashi.Jacket,0 +-,Nexus.TrapClothes,0,Nexus.TrapClothes,0 +-,Nexus.Trapclothes,0,Nexus.Trapclothes,0 ChaFileClothes.ClothesPants,,93,com.Quokka.thighhighs,93 ChaFileClothes.ClothesBra,com.mysto.mechabikini,6548,com.mysto.modpack,6548 ChaFileClothes.ClothesTop,com.mysto.demongodnochainmail,8960,com.mysto.modpack,45346747 @@ -127,4 +129,7 @@ ChaFileClothes.ClothesBot,Mint_E403.SuperMiniTightSkirt,784,Mint_E403.SuperMiniT ChaFileClothes.ClothesTop,Mint_E403.NakedCoat,741,Mint_E403.NakedCoat,2831 ChaFileClothes.ClothesTop,Mint_E403.NakedCoat,742,Mint_E403.NakedCoat,2832 ChaFileFace.eyelineUpId,RikkaEyeline,180008,mm.RikkaEyeline,180008 -ChaFileFace.eyelineUpId,RikkaEyeline,180009,mm.RikkaEyeline,180011 \ No newline at end of file +ChaFileFace.eyelineUpId,RikkaEyeline,180009,mm.RikkaEyeline,180011 +ChaFileClothes.ClothesTop,com.mysto.demongodnochainmail,8960,com.mysto.modpack,45346747 +ChaFileClothes.ClothesTop,mat.Corset,1208,mat.Tops,1214 +ChaFileClothes.ClothesTop,mat.Tops,1216,mat.Tops,1215