Example #1
0
        public void UpdateOnCoordinateSave(ChaFileCoordinate coordinate, List <int> slotsToRemove)
        {
            CharaCustomFunctionController materialController = FindMaterialCharaController();

            if (materialController == null)
            {
                return;
            }

            snapshotData = null;

            // Store a snapshot for later restoration
            snapshotData = FillMaterialEditorLists();
            // And our copy for tampering with
            MaterialEditorSaveData saveData = FillMaterialEditorLists();

#if DEBUG
            AdditionalAccessoryControlsPlugin.Instance.Log.LogInfo($"Update Coord Save: Storing Snapshot {snapshotData}");
#endif

            // Remove character accessories from save data
            ClearRemovedSlots(slotsToRemove, saveData);
            ApplyMaterialEditorLists(saveData);

#if DEBUG
            AdditionalAccessoryControlsPlugin.Instance.Log.LogInfo($"Update Coord Save: After Slot Removal {saveData}");
#endif
            OnCoordinateSave.Invoke(materialController, new object[] { coordinate });
        }
Example #2
0
        private MaterialEditorSaveData FillMaterialEditorLists()
        {
            MaterialEditorSaveData        saveData           = new MaterialEditorSaveData();
            CharaCustomFunctionController materialController = FindMaterialCharaController();

            saveData.rendererPropertyList = new List <object>();
            CopyList((IList)AccessTools.Field(materialController.GetType(), "RendererPropertyList").GetValue(materialController), saveData.rendererPropertyList);

            saveData.materialFloatPropertyList = new List <object>();
            CopyList((IList)AccessTools.Field(materialController.GetType(), "MaterialFloatPropertyList").GetValue(materialController), saveData.materialFloatPropertyList);

            saveData.materialColorPropertyList = new List <object>();
            CopyList((IList)AccessTools.Field(materialController.GetType(), "MaterialColorPropertyList").GetValue(materialController), saveData.materialColorPropertyList);

            saveData.materialTexturePropertyList = new List <object>();
            CopyList((IList)AccessTools.Field(materialController.GetType(), "MaterialTexturePropertyList").GetValue(materialController), saveData.materialTexturePropertyList);

            saveData.materialShaderPropertyList = new List <object>();
            CopyList((IList)AccessTools.Field(materialController.GetType(), "MaterialShaderList").GetValue(materialController), saveData.materialShaderPropertyList);

            if (AccessTools.GetFieldNames(materialController.GetType()).Contains("MaterialCopyList"))
            {
                saveData.materialCopyList = new List <object>();
                CopyList((IList)AccessTools.Field(materialController.GetType(), "MaterialCopyList").GetValue(materialController), saveData.materialCopyList);
            }

            return(saveData);
        }
Example #3
0
        public void UpdateOnCoordinateLoadApply(ChaFileCoordinate coordinate, List <Tuple <int, int> > movedSlots)
        {
            CharaCustomFunctionController materialController = FindMaterialCharaController();

            if (materialController == null || snapshotData == null)
            {
                return;
            }

#if DEBUG
            AdditionalAccessoryControlsPlugin.Instance.Log.LogInfo($"Restore Snapshot {snapshotData}");
#endif

            // Update the material editor data to account for moving slots
            MaterialEditorSaveData currentSaveData = FillMaterialEditorLists();
            MoveSlots(movedSlots, currentSaveData, snapshotData);
            ApplyMaterialEditorLists(currentSaveData);

            // Need to do both of these, first in case material editor hasn't loaded yet, second if they have
            OnCoordinateSave.Invoke(materialController, new object[] { coordinate });
            OnCoordinateLoad.Invoke(materialController, new object[] { coordinate, false });

#if DEBUG
            AdditionalAccessoryControlsPlugin.Instance.Log.LogInfo($"After Application {FillMaterialEditorLists()}");
#endif

            snapshotData = null;
        }
Example #4
0
        private void ClearRemovedSlots(List <int> slotsToRemove, MaterialEditorSaveData saveData)
        {
#if DEBUG
            AdditionalAccessoryControlsPlugin.Instance.Log.LogInfo($"Removing Slots: {string.Join(",", slotsToRemove)}");
#endif
            ClearRemovedNodes(slotsToRemove, saveData.rendererPropertyList);
            ClearRemovedNodes(slotsToRemove, saveData.materialFloatPropertyList);
            ClearRemovedNodes(slotsToRemove, saveData.materialColorPropertyList);
            ClearRemovedNodes(slotsToRemove, saveData.materialTexturePropertyList);
            ClearRemovedNodes(slotsToRemove, saveData.materialShaderPropertyList);
            ClearRemovedNodes(slotsToRemove, saveData.materialCopyList);
        }
Example #5
0
        private void MoveSlots(List <Tuple <int, int> > slotsToMove, MaterialEditorSaveData saveData, MaterialEditorSaveData snapshotData)
        {
#if DEBUG
            AdditionalAccessoryControlsPlugin.Instance.Log.LogInfo($"Moving Slots: {string.Join(",", slotsToMove)}");
#endif

            DoMoveSlots(slotsToMove, saveData.rendererPropertyList, snapshotData.rendererPropertyList);
            DoMoveSlots(slotsToMove, saveData.materialFloatPropertyList, snapshotData.materialFloatPropertyList);
            DoMoveSlots(slotsToMove, saveData.materialColorPropertyList, snapshotData.materialColorPropertyList);
            DoMoveSlots(slotsToMove, saveData.materialTexturePropertyList, snapshotData.materialTexturePropertyList);
            DoMoveSlots(slotsToMove, saveData.materialShaderPropertyList, snapshotData.materialShaderPropertyList);
            DoMoveSlots(slotsToMove, saveData.materialCopyList, snapshotData.materialCopyList);
        }
Example #6
0
        public void UpdateOnCoordinateLoadSnapshot()
        {
            CharaCustomFunctionController materialController = FindMaterialCharaController();

            if (materialController == null)
            {
                return;
            }

            // Squirrel away the current data so we can put character accessories back on later
            snapshotData = FillMaterialEditorLists();
#if DEBUG
            AdditionalAccessoryControlsPlugin.Instance.Log.LogInfo($"Preload Snapshot Enum {snapshotData}");
#endif
        }
Example #7
0
        public void RestoreSnapshot(ChaFileCoordinate coordinate)
        {
            CharaCustomFunctionController materialController = FindMaterialCharaController();

            if (materialController == null)
            {
                return;
            }

            if (snapshotData != null)
            {
#if DEBUG
                AdditionalAccessoryControlsPlugin.Instance.Log.LogInfo($"Restore Snapshot {snapshotData}");
#endif
                ApplyMaterialEditorLists(snapshotData);

                OnCoordinateSave.Invoke(materialController, new object[] { coordinate });
                OnCoordinateLoad.Invoke(materialController, new object[] { coordinate, false });

                snapshotData = null;
            }
        }
Example #8
0
        private void ApplyMaterialEditorLists(MaterialEditorSaveData saveData)
        {
            CharaCustomFunctionController materialController = FindMaterialCharaController();

            IList rendererList = (IList)AccessTools.Field(materialController.GetType(), "RendererPropertyList").GetValue(materialController);

            rendererList.Clear();
            CopyList(saveData.rendererPropertyList, rendererList);

            IList materialFloatList = (IList)AccessTools.Field(materialController.GetType(), "MaterialFloatPropertyList").GetValue(materialController);

            materialFloatList.Clear();
            CopyList(saveData.materialFloatPropertyList, materialFloatList);

            IList materialColorList = (IList)AccessTools.Field(materialController.GetType(), "MaterialColorPropertyList").GetValue(materialController);

            materialColorList.Clear();
            CopyList(saveData.materialColorPropertyList, materialColorList);

            IList materialTextureList = (IList)AccessTools.Field(materialController.GetType(), "MaterialTexturePropertyList").GetValue(materialController);

            materialTextureList.Clear();
            CopyList(saveData.materialTexturePropertyList, materialTextureList);

            IList materialShaderList = (IList)AccessTools.Field(materialController.GetType(), "MaterialShaderList").GetValue(materialController);

            materialShaderList.Clear();
            CopyList(saveData.materialShaderPropertyList, materialShaderList);

            if (AccessTools.GetFieldNames(materialController.GetType()).Contains("MaterialCopyList"))
            {
                IList materialCopyList = (IList)AccessTools.Field(materialController.GetType(), "MaterialCopyList").GetValue(materialController);
                materialCopyList.Clear();
                CopyList(saveData.materialCopyList, materialCopyList);
            }
        }