Skip to content

Commit

Permalink
Fix breaking with missing .csv, add stripping extended data
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathWeasel1337 committed Feb 20, 2019
1 parent 2b8d137 commit 7486797
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
70 changes: 39 additions & 31 deletions KK_GUIDMigration/KK_GUIDMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MigrationInfo> MigrationInfoList = new List<MigrationInfo>();
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.");
}
}
}
}
Expand All @@ -54,9 +57,9 @@ private static IEnumerable<ResolveInfo> MigrateGUID(IEnumerable<ResolveInfo> 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
Expand All @@ -65,37 +68,38 @@ private static IEnumerable<ResolveInfo> MigrateGUID(IEnumerable<ResolveInfo> 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"))
propertyWithoutPrefix = propertyWithoutPrefix.Remove(0, propertyWithoutPrefix.IndexOf('.') + 1);
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)
{
//We do not have the old mod installed, do migration. Whether we have the new mod is irrelevant.
//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
{
Expand All @@ -104,34 +108,38 @@ private static IEnumerable<ResolveInfo> MigrateGUID(IEnumerable<ResolveInfo> 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)
{
//We do not have the old mod installed, do migration. Whether we have the new mod is irrelevant.
//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
{
Expand All @@ -140,14 +148,14 @@ private static IEnumerable<ResolveInfo> MigrateGUID(IEnumerable<ResolveInfo> 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);
Expand Down
7 changes: 6 additions & 1 deletion KK_GUIDMigration/KK_GUIDMigration.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,<not set>,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
Expand Down Expand Up @@ -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
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

0 comments on commit 7486797

Please sign in to comment.