internal static List <BoneModifier> ReadModifiers(PluginData data) { if (data != null) { try { switch (data.version) { case 2: return(LZ4MessagePackSerializer.Deserialize <List <BoneModifier> >( (byte[])data.data[ExtDataBoneDataKey])); #if KK || EC || KKS case 1: KKABMX_Core.Logger.LogDebug("[KKABMX] Loading legacy embedded ABM data"); return(OldDataConverter.MigrateOldExtData(data)); #endif default: throw new NotSupportedException($"Save version {data.version} is not supported"); } } catch (Exception ex) { KKABMX_Core.Logger.LogError("[KKABMX] Failed to load extended data - " + ex); } } return(new List <BoneModifier>()); }
protected override void OnReload(GameMode currentGameMode, bool maintainState) { foreach (var modifier in Modifiers) { modifier.Reset(); } // Stop baseline collection if it's running StopAllCoroutines(); _baselineKnown = false; if (!maintainState) { Modifiers = null; var data = GetExtendedData(); if (data != null) { try { switch (data.version) { case 2: Modifiers = LZ4MessagePackSerializer.Deserialize <List <BoneModifier> >((byte[])data.data[ExtDataBoneDataKey]); break; case 1: Logger.Log(LogLevel.Debug, $"[KKABMX] Loading legacy embedded ABM data from card: {ChaFileControl.parameter?.fullname}"); Modifiers = OldDataConverter.MigrateOldExtData(data); break; default: throw new NotSupportedException($"Save version {data.version} is not supported"); } } catch (Exception ex) { Logger.Log(LogLevel.Error, "[KKABMX] Failed to load extended data - " + ex); } } } if (Modifiers == null) { Modifiers = new List <BoneModifier>(); } StartCoroutine(OnDataChangedCo()); }
/// <inheritdoc /> protected override void OnReload(GameMode currentGameMode, bool maintainState) { foreach (var modifier in Modifiers) { modifier.Reset(); } // Stop baseline collection if it's running StopAllCoroutines(); _baselineKnown = false; if (!maintainState && (GUI.KKABMX_GUI.LoadBody || GUI.KKABMX_GUI.LoadFace)) { List <BoneModifier> newModifiers = null; var data = GetExtendedData(); if (data != null) { try { switch (data.version) { case 2: newModifiers = LZ4MessagePackSerializer.Deserialize <List <BoneModifier> >((byte[])data.data[ExtDataBoneDataKey]); break; #if KK || EC case 1: KKABMX_Core.Logger.LogDebug($"[KKABMX] Loading legacy embedded ABM data from card: {ChaFileControl.parameter?.fullname}"); newModifiers = OldDataConverter.MigrateOldExtData(data); break; #endif default: throw new NotSupportedException($"Save version {data.version} is not supported"); } } catch (Exception ex) { KKABMX_Core.Logger.LogError("[KKABMX] Failed to load extended data - " + ex); } } if (newModifiers == null) { newModifiers = new List <BoneModifier>(); } if (GUI.KKABMX_GUI.LoadBody && GUI.KKABMX_GUI.LoadFace) { Modifiers = newModifiers; } else { #if AI var headRoot = transform.FindLoop("cf_J_Head"); #else var headRoot = transform.FindLoop("cf_j_head"); #endif var headBones = new HashSet <string>(headRoot.GetComponentsInChildren <Transform>().Select(x => x.name)); headBones.Add(headRoot.name); if (GUI.KKABMX_GUI.LoadFace) { Modifiers.RemoveAll(x => headBones.Contains(x.BoneName)); Modifiers.AddRange(newModifiers.Where(x => headBones.Contains(x.BoneName))); } else if (GUI.KKABMX_GUI.LoadBody) { var bodyBones = new HashSet <string>(transform.FindLoop("BodyTop").GetComponentsInChildren <Transform>().Select(x => x.name).Except(headBones)); Modifiers.RemoveAll(x => bodyBones.Contains(x.BoneName)); Modifiers.AddRange(newModifiers.Where(x => bodyBones.Contains(x.BoneName))); } } } StartCoroutine(OnDataChangedCo()); }