Пример #1
0
        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());
        }
Пример #2
0
        protected override void OnCoordinateBeingLoaded(ChaFileCoordinate coordinate, bool maintainState)
        {
            if (maintainState)
            {
                return;
            }

            // Clear previous data for this coordinate from coord specific modifiers
            foreach (var modifier in Modifiers.Where(x => x.IsCoordinateSpecific()))
            {
                modifier.GetModifier(CurrentCoordinate.Value).Clear();
            }

            var data = GetCoordinateExtendedData(coordinate);

            if (data != null)
            {
                try
                {
                    if (data.version != 2)
                    {
                        throw new NotSupportedException($"Save version {data.version} is not supported");
                    }

                    var boneData = LZ4MessagePackSerializer.Deserialize <Dictionary <string, BoneModifierData> >((byte[])data.data[ExtDataBoneDataKey]);
                    if (boneData != null)
                    {
                        foreach (var modifier in boneData)
                        {
                            var target = GetModifier(modifier.Key);
                            if (target == null)
                            {
                                // Add any missing modifiers
                                target = new BoneModifier(modifier.Key);
                                AddModifier(target);
                            }
                            target.MakeCoordinateSpecific();
                            target.CoordinateModifiers[(int)CurrentCoordinate.Value] = modifier.Value;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.Error, "[KKABMX] Failed to load coordinate extended data - " + ex);
                }
            }

            StartCoroutine(OnDataChangedCo());
        }
Пример #3
0
        private static List <BoneModifier> DeserializeToModifiers(IEnumerable <string> lines)
        {
            string GetTrimmedName(string[] splitValues)
            {
                // Turn cf_d_sk_top__1 into cf_d_sk_top
                var boneName = splitValues[1];

                return(boneName[boneName.Length - 2] == '_' && boneName[boneName.Length - 3] == '_'
                    ? boneName.Substring(0, boneName.Length - 3)
                    : boneName);
            }

            var query = from lineText in lines
                        let trimmedText = lineText?.Trim()
                                          where !string.IsNullOrEmpty(trimmedText)
                                          let splitValues = trimmedText.Split(',')
                                                            where splitValues.Length >= 6
                                                            group splitValues by GetTrimmedName(splitValues);

            var results = new List <BoneModifier>();

            foreach (var groupedBoneDataEntries in query)
            {
                var groupedOrderedEntries = groupedBoneDataEntries.OrderBy(x => x[1]).ToList();

                var coordinateModifiers = new List <BoneModifierData>(groupedOrderedEntries.Count);

                foreach (var singleEntry in groupedOrderedEntries)
                {
                    try
                    {
                        //var boneName = singleEntry[1];
                        //var isEnabled = bool.Parse(singleEntry[2]);
                        var x = float.Parse(singleEntry[3]);
                        var y = float.Parse(singleEntry[4]);
                        var z = float.Parse(singleEntry[5]);

                        var lenMod = singleEntry.Length > 6 ? float.Parse(singleEntry[6]) : 1f;

                        coordinateModifiers.Add(new BoneModifierData(new Vector3(x, y, z), lenMod));
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogLevel.Error, $"[KKABMX] Failed to load legacy line \"{string.Join(",", singleEntry)}\" - {ex.Message}");
                        Logger.Log(LogLevel.Debug, "Error details: " + ex);
                    }
                }

                if (coordinateModifiers.Count == 0)
                {
                    continue;
                }

                if (coordinateModifiers.Count > BoneModifier.CoordinateCount)
                {
                    coordinateModifiers.RemoveRange(0, coordinateModifiers.Count - BoneModifier.CoordinateCount);
                }
                if (coordinateModifiers.Count > 1 && coordinateModifiers.Count < BoneModifier.CoordinateCount)
                {
                    coordinateModifiers.RemoveRange(0, coordinateModifiers.Count - 1);
                }

                results.Add(new BoneModifier(groupedBoneDataEntries.Key, coordinateModifiers.ToArray()));
            }

            return(results);
        }
Пример #4
0
        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))
            {
                var newModifiers = new List <BoneModifier>();
                var data         = GetExtendedData();
                if (data != null)
                {
                    try
                    {
                        switch (data.version)
                        {
                        case 2:
                            newModifiers = 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}");
                            newModifiers = 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 (GUI.KKABMX_GUI.LoadBody && GUI.KKABMX_GUI.LoadFace)
                {
                    Modifiers = newModifiers;
                }
                else
                {
                    var headRoot  = transform.FindLoop("cf_j_head");
                    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());
        }