Esempio n. 1
0
        /// <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;
                try
                {
                    var data = GetExtendedData();
                    if (data != null)
                    {
                        try
                        {
                            switch (data.version)
                            {
                            case 2:
                                newModifiers =
                                    LZ4MessagePackSerializer.Deserialize <List <BoneModifier> >(
                                        (byte[])data.data[ExtDataBoneDataKey]);
                                break;

                            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);
                        }
                    }
                    else
                    {
                        var legacyData = OldDataConverter.ImportOldData(CharacterApi.GetLastLoadedCardPath(ChaControl), ChaControl);
                        if (legacyData != null)
                        {
                            newModifiers = legacyData;
                        }
                    }
                }
                catch (Exception ex)
                {
                    KKABMX_Core.Logger.LogError("Failed to load bonemod data: " + ex);
                }

                if (newModifiers == null)
                {
                    newModifiers = new List <BoneModifier>();
                }

                if (GUI.KKABMX_GUI.LoadBody && GUI.KKABMX_GUI.LoadFace)
                {
                    Modifiers = newModifiers;
                }
                else
                {
                    var bodyRoot = GetBodyRootTransform();
                    var headRoot = bodyRoot.FindLoop(ChaControl.sex == SEX.MALE ? "cm_J_Head" : "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>(bodyRoot.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());
        }