Skip to content

Commit

Permalink
ビー祭演出コード+BlendShape変更Json対応中
Browse files Browse the repository at this point in the history
  • Loading branch information
Reiya1013 committed Jun 23, 2022
1 parent 7662e30 commit 8ed8ece
Show file tree
Hide file tree
Showing 18 changed files with 984 additions and 230 deletions.
32 changes: 32 additions & 0 deletions Source/Harmony/CustomPreviewBeatmapLevelHarmony.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.IO;
using HarmonyLib;
using UniGLTF;
using UnityEngine;
using VRM;
using VMCAvatar;
namespace VMCAvatarMaterialChange
{
[HarmonyPatch(typeof(CustomPreviewBeatmapLevel), nameof(CustomPreviewBeatmapLevel.GetCoverImageAsync))]
public static class CustomPreviewBeatmapLevelHarmony
{
private static string _latestSelectedSong = string.Empty;
public static string customLevelPath = string.Empty;
static void Postfix(CustomPreviewBeatmapLevel __instance)
{

if (__instance.customLevelPath != _latestSelectedSong && __instance.customLevelPath != string.Empty)
{
_latestSelectedSong = __instance.customLevelPath;

Logger.log.Notice($"Selected CustomLevel Path :\n {__instance.customLevelPath}");

if (File.Exists(Path.Combine(__instance.customLevelPath, "NalulunaAvatarsEvents.json")))
customLevelPath = Path.Combine(__instance.customLevelPath, "NalulunaAvatarsEvents.json");
else
customLevelPath = string.Empty;
}
}
}

}
62 changes: 13 additions & 49 deletions Source/Harmony/LightHarmony.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,59 +43,23 @@ public static void Postfix(Chroma.Lighting.ChromaIDColorTween __instance, ILight
}
}

//本当はOnEnableで取りたいけど、こっちのほうが起動が遅いと取れないため仕方なく・・・
[HarmonyPatch(typeof(LightController), "OnDirectionalLightTransformAndColor", MethodType.Normal)]
public static class LightControllerHarmony
{
public static void Postfix(LightController __instance)
{
if (!Plugin.instance.OptionLight.VMCLight)
{
Plugin.instance.OptionLight.VMCLight = __instance.VMCLight;
}
//if (Plugin.instance.OptionLight.IsVMCLightBoost)
//{
// Color color = __instance.VMCLight.color;
// color.a *= Plugin.instance.OptionLight.VMCLightBoost;
// __instance.VMCLight.color = color;
//}
}
}

//[HarmonyPatch(typeof(SetSaberGlowColor), "SetColors", MethodType.Normal)]
//public static class SetSaberGlowColorHarmony
////本当はOnEnableで取りたいけど、こっちのほうが起動が遅いと取れないため仕方なく・・・
//[HarmonyPatch(typeof(LightController), "OnDirectionalLightTransformAndColor", MethodType.Normal)]
//public static class LightControllerHarmony
//{
// public static void Postfix(SetSaberGlowColor __instance, SaberType ____saberType, ColorManager ____colorManager)
// public static void Postfix(LightController __instance)
// {
// if (____colorManager is null) return;
// if (__instance.transform is null) return;
// if (__instance.transform.name != "SaberGlowingEdges") return;
// Plugin.instance.OptionLight.AddSaberLight(____saberType, __instance.gameObject, ____colorManager.ColorForSaberType(____saberType));


// //Logger.log?.Warn($"SaberLight Setup Parent: {__instance.transform.name}");
// //Logger.log?.Warn($"SaberLight Setup Parent: { Plugin.instance.OptionLight.SaberLights[____saberType] is null}");
// //Logger.log?.Warn($"SaberLight Setup Parent: { Plugin.instance.OptionLight.SaberLights[____saberType].gameObject is null}");
// //Logger.log?.Warn($"SaberLight Setup Parent: { Plugin.instance.OptionLight.SaberLights[____saberType].transform.name}");
// //Plugin.instance.OptionLight.SaberLights[____saberType].transform.SetParent(__instance.transform);
// //Plugin.instance.OptionLight.SaberLights[____saberType].color = ____colorManager.ColorForSaberType(____saberType);

// //if (____saberType == SaberType.SaberA)
// //{


// // //Logger.log?.Warn($"RightSaberLight Setup Parent: {__instance.transform} {Plugin.instance.OptionLight.RightSaberLight.transform.parent.name}");
// // //Logger.log?.Warn($"RightSaberLight Setup Color: {____colorManager is null} {Plugin.instance.OptionLight.RightSaberLight.transform.parent.name}");
// //}
// //else if (____saberType == SaberType.SaberB)
// if (!Plugin.instance.OptionLight.VMCLight)
// {
// Plugin.instance.OptionLight.VMCLight = __instance.VMCLight;
// }
// //if (Plugin.instance.OptionLight.IsVMCLightBoost)
// //{
// // //Logger.log?.Warn($"LeftSaberLight Setup: {Plugin.instance.OptionLight.LeftSaberLight is null} {Plugin.instance.OptionLight.LeftSaberLight.transform.parent.name}");
// // //Plugin.instance.OptionLight.LeftSaberLight.transform.parent = __instance.transform;
// // //Logger.log?.Warn($"LeftSaberLight Setup Parent: {__instance.transform} {Plugin.instance.OptionLight.LeftSaberLight.transform.parent.name}");
// // //Logger.log?.Warn($"LeftSaberLight Setup Color: {____colorManager is null} {Plugin.instance.OptionLight.LeftSaberLight.transform.parent.name}");
// // //Plugin.instance.OptionLight.LeftSaberLight.color = ____colorManager.ColorForSaberType(____saberType);
// // Color color = __instance.VMCLight.color;
// // color.a *= Plugin.instance.OptionLight.VMCLightBoost;
// // __instance.VMCLight.color = color;
// //}
// }

//}

}
23 changes: 14 additions & 9 deletions Source/Harmony/Patches.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using HarmonyLib;
using System;
using System.Reflection;
//using VMCAvatar;
using UniGLTF;
using VRM;
using static VRM.VRMFirstPerson;

Expand All @@ -21,14 +21,19 @@ public Patcher(string id)
public void Enable()
{
Logger.log?.Warn("Applying Harmony patches.");
Patch(typeof(UniGLTF.ImporterContext).GetMethod("ShowMeshes"), new HarmonyMethod(typeof(VRMHarmony).GetMethod("Prefix")), null);
//Patch(typeof(VRMFirstPerson).GetMethod("Setup", new Type[] { typeof(bool), typeof(SetVisiblityFunc) }), new HarmonyMethod(typeof(VRMFirstPerson_Setup).GetMethod("Prefix")), null);
//Patch(typeof(SetSaberGlowColor).GetMethod("SetColors"), null, new HarmonyMethod(typeof(SetSaberGlowColorHarmony).GetMethod("Postfix")));
if (Plugin.instance.IsChroma)
{
ChromaPatch();
}
Patch(typeof(LightWithIdManager).GetMethod("SetColorForId"), null, new HarmonyMethod(typeof(LightHarmony).GetMethod("Postfix")));
harmony.PatchAll(Assembly.GetExecutingAssembly());

//Patch(typeof(RuntimeGltfInstance).GetMethod("ShowMeshes"), new HarmonyMethod(typeof(VRMHarmony).GetMethod("Prefix")), null);
////Patch(typeof(RuntimeGltfInstance).GetMethod("Dispose"), new HarmonyMethod(typeof(VRMDisposeHarmony).GetMethod("Prefix")), null);
//Patch(typeof(VRMBlendShapeProxy).GetMethod("AccumulateValue"), new HarmonyMethod(typeof(VRMBlendShapeProxyDisable).GetMethod("Prefix")), null);
//Patch(typeof(CustomPreviewBeatmapLevel).GetMethod(nameof(CustomPreviewBeatmapLevel.GetCoverImageAsync)), null, new HarmonyMethod(typeof(CustomPreviewBeatmapLevelHarmony).GetMethod("Postfix")));
////Patch(typeof(VRMFirstPerson).GetMethod("Setup", new Type[] { typeof(bool), typeof(SetVisiblityFunc) }), new HarmonyMethod(typeof(VRMFirstPerson_Setup).GetMethod("Prefix")), null);
////Patch(typeof(SetSaberGlowColor).GetMethod("SetColors"), null, new HarmonyMethod(typeof(SetSaberGlowColorHarmony).GetMethod("Postfix")));
//if (Plugin.instance.IsChroma)
//{
// ChromaPatch();
//}
//Patch(typeof(LightWithIdManager).GetMethod("SetColorForId"), null, new HarmonyMethod(typeof(LightHarmony).GetMethod("Postfix")));

}

Expand Down
206 changes: 203 additions & 3 deletions Source/Harmony/VRMHarmony.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using System;
using HarmonyLib;
using UniGLTF;
using UnityEngine;
using VRM;
//using VMCAvatar;
using VMCAvatar;
using OscJack;
using System.Collections.Generic;

namespace VMCAvatarMaterialChange
{
[HarmonyPatch(typeof(UniGLTF.ImporterContext), "ShowMeshes", MethodType.Normal)]
[HarmonyPatch(typeof(RuntimeGltfInstance), "ShowMeshes", MethodType.Normal)]
public static class VRMHarmony
{
/// <summary>
/// ロード済のアバターを表示するUniVRMのメソッドをHarmonyで割り込んでマテリアルチェンジする
/// </summary>
/// <param name="__instance"></param>
public static void Prefix(UniGLTF.ImporterContext __instance)
public static void Prefix(RuntimeGltfInstance __instance)
{
try
{
Expand All @@ -26,6 +29,11 @@ public static void Prefix(UniGLTF.ImporterContext __instance)
//マテリアル変更
SharedCoroutineStarter.instance.StartCoroutine(VMCMaterialChange.instance.ChangeMaterial(__instance));

//表情変更イベントオブジェクト追加
__instance.gameObject.AddComponent<BlendShapeChanger>();

Plugin.instance.DisposeVRMOff = false;

Logger.log.Debug($"Harmony ChangeMaterial End");
}
catch (System.Exception e)
Expand All @@ -35,6 +43,198 @@ public static void Prefix(UniGLTF.ImporterContext __instance)
}
}

[HarmonyPatch(typeof(RuntimeGltfInstance), "Dispose", MethodType.Normal)]
public static class VRMDisposeHarmony
{
/// <summary>
/// アバター情報開放処理を中断して、情報保持する
/// </summary>
/// <param name="__instance"></param>
public static bool Prefix(RuntimeGltfInstance __instance)
{
if (Plugin.instance.DisposeVRMOff == false) return true;
Logger.log.Debug($"VRMDisposeHarmony Stop");

return false;
}
}

//[HarmonyPatch(typeof(VMCProtocol.Marionette), "OscOnBlendShapProxyValue", MethodType.Normal)]
//public static class MarionetteOscOnBlendShapProxyValueHarmony
//{
// public static bool StopAutoBlendShape = false;
// public static bool StopAutoBlink = false;
// public static bool StopLipSync = false;

// public static bool Prefix(VMCProtocol.Marionette __instance, OscDataHandle data,ref Dictionary<string, float> ____constructingBlendShapes)
// {
// string keyName = data.GetElementAsString(0);

// Logger.log.Debug($"MarionetteOscOnBlendShapProxyValueHarmony Key{keyName}");

// //表情停止中はすべて拒否
// if (StopAutoBlendShape == true) return false;

// //瞬き許可にまばたきがきたら許可
// bool ret = false;
// if (StopAutoBlink == false && keyName == "Blink")
// {
// ret = true;
// }
// else
// {
// if (____constructingBlendShapes.ContainsKey("Blink"))
// ____constructingBlendShapes.Remove("Blink");
// }
// //リップシンク許可時にAIUEOが来たら許可
// if (StopLipSync == false)
// {
// if (keyName == "A" ||
// keyName == "I" ||
// keyName == "U" ||
// keyName == "E" ||
// keyName == "O")
// ret = true;
// }
// else
// {
// if (____constructingBlendShapes.ContainsKey("A"))
// ____constructingBlendShapes.Remove("A");
// if (____constructingBlendShapes.ContainsKey("I"))
// ____constructingBlendShapes.Remove("I");
// if (____constructingBlendShapes.ContainsKey("U"))
// ____constructingBlendShapes.Remove("U");
// if (____constructingBlendShapes.ContainsKey("E"))
// ____constructingBlendShapes.Remove("E");
// if (____constructingBlendShapes.ContainsKey("O"))
// ____constructingBlendShapes.Remove("O");

// }

// return ret;

// }
//}


[HarmonyPatch(typeof(VMCProtocol.Marionette), "OscOnBlendShapProxyValue", MethodType.Normal)]
public static class MarionetteOscOnBlendShapProxyApplyHarmony
{
public static bool StopAutoBlendShape = false;
public static bool StopAutoBlink = false;
public static bool StopLipSync = false;

public static bool Prefix(VMCProtocol.Marionette __instance, OscDataHandle data, ref Dictionary<string, float> ____constructingBlendShapes)
{
//表情停止中はすべて拒否
if (StopAutoBlendShape == true)
{
____constructingBlendShapes.Clear();
return false;
}

if (____constructingBlendShapes is null || ____constructingBlendShapes.Count == 0)
return true;

//Prefix結果判定
string keyName = data.GetElementAsString(0);

Logger.log.Debug($"MarionetteOscOnBlendShapProxyValueHarmony Key{keyName}");

//表情停止中はすべて拒否
if (StopAutoBlendShape == true) return false;

//瞬き許可にまばたきがきたら許可
bool ret = false;
if (StopAutoBlink == false && keyName == "Blink")
{
ret = true;
}
//リップシンク許可時にAIUEOが来たら許可
if (StopLipSync == false)
{
if (keyName == "A" ||
keyName == "I" ||
keyName == "U" ||
keyName == "E" ||
keyName == "O")
ret = true;
}

//設定済みKey削除
List<string> delList = new List<string>();
foreach (var blendShape in ____constructingBlendShapes)
{
bool addflg = true;
if (StopAutoBlink == false && blendShape.Key == "Blink")
{
addflg = false;
}
if (StopLipSync == false)
{
if (blendShape.Key == "A" ||
blendShape.Key == "I" ||
blendShape.Key == "U" ||
blendShape.Key == "E" ||
blendShape.Key == "O")
{
addflg = false;
}
}

if (addflg == true)
delList.Add(blendShape.Key);
}



if (delList.Count > 0)
foreach (var delname in delList)
{
____constructingBlendShapes.Remove(delname);
}

return ret;
}
}

//[HarmonyPatch(typeof(VRMBlendShapeProxy), "AccumulateValue", MethodType.Normal)]
//public static class VRMBlendShapeProxyDisable
//{
// public static bool StopAutoBlendShape = false;
// public static bool StopAutoBlink = false;
// public static bool StopLipSync = false;


// /// <summary>
// /// 表情制御OFF
// /// </summary>
// /// <param name="__instance"></param>
// public static bool Prefix(VRMBlendShapeProxy __instance, BlendShapeKey key)
// {
// var keyName = key.Name.ToUpper();

// //表情停止中はすべて拒否
// if (StopAutoBlendShape == true) return false;

// //瞬き許可にまばたきがきたら許可
// bool ret = false;
// if (StopAutoBlink == false && keyName.Contains("BLINK")) ret = true;

// //リップシンク許可時にAIUEOが来たら許可
// if (StopLipSync == false)
// {
// if (keyName.Contains("A") ||
// keyName.Contains("I") ||
// keyName.Contains("U") ||
// keyName.Contains("E") ||
// keyName.Contains("O"))
// ret = true;
// }
// return ret;
// }
//}

//[HarmonyPatch(typeof(VRMFirstPerson), "Setup", MethodType.Normal)]
//public static class VRMFirstPerson_Setup
//{
Expand Down
Loading

0 comments on commit 8ed8ece

Please sign in to comment.