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; }
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 }); }
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); }
private IList FillDBEditorLists() { IList saveData = new List <object>(); CharaCustomFunctionController dbController = FindDynamicBoneController(); CopyList((IList)AccessTools.Field(dbController.GetType(), "AccessoryDynamicBoneData").GetValue(dbController), saveData); return(saveData); }
private void ApplyDynamicBoneList(IList dynamicBoneList) { CharaCustomFunctionController dbController = FindDynamicBoneController(); IList currentList = (IList)AccessTools.Field(dbController.GetType(), "AccessoryDynamicBoneData").GetValue(dbController); currentList.Clear(); CopyList(dynamicBoneList, currentList); }
private static void GetMilkAmountPatch(CharaCustomFunctionController controller, ref float __result) { if (__result < 1f && controller != null) { if (controller.ChaControl.GetCurrentCrest() == CrestType.lactation) { __result = 1f; } } }
internal UrineBag(ChaControl ChaControl) { if (!_installed) { return; } _chaCtrl = ChaControl; _pluginCtrl = GetController(_chaCtrl); }
internal static void MaterialEditorCharaController_OnReload_Prefix(CharaCustomFunctionController __instance) { ChaControl chaCtrl = __instance.ChaControl; MaterialRouterController pluginCtrl = GetController(chaCtrl); if (pluginCtrl == null) { return; } DebugMsg(LogLevel.Warning, $"MaterialEditorCharaController_OnReload_Prefix [{pluginCtrl.CurrentCoordinateIndex}]"); pluginCtrl.OnReload_Prefix(); }
internal UrineBag(ChaControl ChaControl) { _chaCtrl = ChaControl; _pluginCtrl = GetController(_chaCtrl); foreach (string _key in _containerKeys) { _extdataLink[_key] = Traverse.Create(_pluginCtrl).Field(_key).GetValue(); _charaAccData[_key] = _extdataLink[_key].JsonClone(); Traverse.Create(_charaAccData[_key]).Method("Clear").GetValue(); } }
internal static bool DuringLoading_Prefix(CharaCustomFunctionController __instance) { ChaControl _chaCtrl = __instance.ChaControl; CharacterAccessoryController _pluginCtrl = GetController(_chaCtrl); if (_pluginCtrl.DuringLoading) { #if DEBUG DebugMsg(LogLevel.Warning, $"[DuringLoading_Prefix][{_chaCtrl.GetFullname()}] await loading"); #endif return(false); } return(true); }
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 }
internal UrineBag(ChaControl ChaControl) { if (!_installed) { return; } _chaCtrl = ChaControl; _pluginCtrl = GetController(_chaCtrl); foreach (string _key in _containerKeys) { Type _type = _types[_key.Replace("List", "")]; Type _generic = typeof(List <>).MakeGenericType(_type); _charaAccData[_key] = Activator.CreateInstance(_generic); } }
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; } }
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); } }
private static bool TransferBonesOverride(CharaCustomFunctionController __instance, SkinnedMeshRenderer src, SkinnedMeshRenderer dst) { // Clean up no longer used implanted bones foreach (var kvp in _implantedBones.ToList()) { kvp.Value.Usages.Remove(dst); kvp.Value.Usages.RemoveWhere(x => x == null); if (kvp.Value.Usages.Count == 0) { if (kvp.Value.ImplantedBones != null) { Logger.LogDebug($"Removing {kvp.Value.ImplantedBones.Count} no longer used implanted bones"); foreach (var implantedBone in kvp.Value.ImplantedBones) { if (implantedBone != null) { Destroy(implantedBone.gameObject); } } } _implantedBones.Remove(kvp.Key); } } var bodyBoneDict = __instance.ChaControl.GetBodyBoneDict(); /* try dst.GetBoneDict() if there are any missing bones */ // Figure out the root object of the instantiated uncensor object and use it to figure out which renderers should share the instantiated bones var topmostParent = src.GetTopmostParent(); // Cache results of bone implanting and reuse them on renderers from the same instantiated uncensor object if (!_implantedBones.TryGetValue(topmostParent, out var implantedBonesData)) { implantedBonesData = TryImplantBones(topmostParent.gameObject, bodyBoneDict); if (implantedBonesData == null) { return(true); } _implantedBones[topmostParent] = implantedBonesData; } implantedBonesData.Usages.Add(dst); if (implantedBonesData.ImplantedBones == null || implantedBonesData.ImplantedBones.Count == 0) { return(true); } var existingBoneDict = dst.GetBoneDict(); var bodyBonesDict = (Dictionary <string, GameObject>)null; var boneCount = src.bones.Length; var reassignedBoneArr = new Transform[boneCount]; for (var i = 0; i < boneCount; i++) { var rendererBone = src.bones[i]; if (rendererBone == null) // Extra safety check, should never happen { Logger.LogWarning($"Renderer has a null bone! BoneIndex: {i} Renderer: {src.GetFullPath()}"); } else if (implantedBonesData.ImplantedBones.Contains(rendererBone)) // Copy implanted bones as they are { reassignedBoneArr[i] = rendererBone; } else if (existingBoneDict.TryGetValue(rendererBone.name, out var baseBone)) // Use the equivalent bone from the target renderer if found { reassignedBoneArr[i] = baseBone.transform; } else { // This branch shouldn't happen in most cases so do a lazy init to avoid the reflection cost if (bodyBonesDict == null) { bodyBonesDict = bodyBoneDict; } // Use the equivalent bone from the body skeleton if found if (bodyBonesDict.TryGetValue(rendererBone.name, out var bodyBone)) { reassignedBoneArr[i] = bodyBone.transform; } else { Logger.LogWarning( "Renderer is using a bone that is not in the base skeleton and is not implanted. It will be set to null. You need to add a BoneImplantProcess component to your object.\n" + $"Renderer: {src.GetFullPath()}\n" + $"Bone: {rendererBone.GetFullPath()}\n" + $"BoneIndex: {i}"); } } } dst.bones = reassignedBoneArr; return(false); }
public OverlayStorage(CharaCustomFunctionController controller) { _chaControl = controller.ChaControl; _textureStorage = new TextureStorage(); _allOverlayTextures = new Dictionary <CoordinateType, Dictionary <TexType, int> >(); }