-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyShadowAnimPatch.cs
More file actions
127 lines (117 loc) · 5.71 KB
/
EnemyShadowAnimPatch.cs
File metadata and controls
127 lines (117 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System.Diagnostics.CodeAnalysis;
using HarmonyLib;
using UnityEngine;
#pragma warning disable CS8618
namespace LoomConfig
{
[HarmonyPatch(typeof(EnemyShadowAnim))]
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal static class EnemyShadowAnimPatch
{
// private static readonly Vector3 neckOriginalPosition = new(-0.00324382959f, 0.60799998f, -0.0120000001f);
// private static readonly List<Vector3> neckFixedPositions = new()
// {
// new Vector3(-0.00324380398f, 0.500300169f, -0.0120002478f),
// new Vector3(-0.00324380398f, 0.435680211f, -0.0120004788f),
// new Vector3(-0.00324380398f, 0.399781346f, -0.0120002031f)
// };
// private static readonly Vector3 neckOriginalScale = new(0.41f, 0.41f, 0.41f);
// private static readonly List<Vector3> neckFixedScales = new()
// {
// new Vector3(0.41f, 0.3484999f, 0.41f),
// new Vector3(0.41f, 0.3115999f, 0.41f),
// new Vector3(0.41f, 0.2911f, 0.41f)
// };
// internal static readonly ConditionalWeakTable<EnemyShadowAnim, Transform> neckRefs = new();
// internal static bool inLevel;
// [HarmonyPostfix, HarmonyPatch(nameof(EnemyShadowAnim.Awake))]
// internal static void EnemyShadowAnimAwakePostfix(EnemyShadowAnim __instance)
// {
// Transform mesh = __instance.transform.Find("Whole mesh CODE ✢/Whole Mesh ANIM ⟺/____________ (Torso)/Torso CODE ✢/Torso ANIM ⟺/____________ (Neck)/Neck CODE ✢/Neck ANIM ⟺/Neck (mesh)");
// if (!mesh)
// {
// LoomConfig.Error("Neck mesh transform not found! Has the GameObject hierarchy changed?", __instance);
// return;
// }
// LoomConfig.Debug($"Found neck mesh transform:\n{mesh}", __instance);
// neckRefs.Add(__instance, mesh);
// inLevel = true;
// }
[HarmonyPrefix, HarmonyPatch(nameof(EnemyShadowAnim.Update))]
internal static void UpdatePrefix(EnemyShadowAnim __instance)
{
var idleLoopVolume = LoomConfig.configIdleLoopVolume.Value;
if (Mathf.Approximately(idleLoopVolume, .1f) &&
Mathf.Approximately(idleLoopVolume, __instance.idleLoop.Volume)) return;
__instance.idleLoop.Volume = idleLoopVolume;
}
// [HarmonyPostfix, HarmonyPatch(nameof(EnemyShadowAnim.Update))]
// internal static void UpdatePostfix(EnemyShadowAnim __instance)
// {
// if (!inLevel ||
// __instance.enemyShadow.currentState is EnemyShadow.State.Despawn or EnemyShadow.State.CoolDown) return;
//
// neckRefs.TryGetValue(__instance, out Transform neck);
// var flag = !LoomConfig.configFixNeckClipping.Value;
//
// if (!neck && SemiFunc.PerSecond(.033f, __instance))
// {
// LoomConfig.Error("Missing transform to neck mesh transform!", __instance);
// flag = true;
// }
// if (flag)
// {
// neck.localPosition = neckOriginalPosition;
// neck.localScale = neckOriginalScale;
// return;
// }
//
// var bendState = __instance.enemyShadow.bendState;
// var delta = Time.deltaTime * __instance.enemyShadow.headTurnSpeed;
//
// if (bendState > 0 &&
// neck.localPosition != neckFixedPositions[bendState] && neck.localScale != neckFixedScales[bendState])
// {
// neck.localPosition = Vector3.Slerp(neck.localPosition, neckFixedPositions[bendState], delta);
// neck.localScale = Vector3.Slerp(neck.localScale, neckFixedScales[bendState], delta);
// }
// else if (neck.localPosition != neckOriginalPosition && neck.localScale != neckOriginalScale)
// {
// neck.localPosition = Vector3.Slerp(neck.localPosition, neckOriginalPosition, delta);
// neck.localScale = Vector3.Slerp(neck.localScale, neckOriginalScale, delta);
// }
// }
[HarmonyPrefix, HarmonyPatch(nameof(EnemyShadowAnim.playTargetedSound))]
internal static bool PlayTargetedSoundPrefix(EnemyShadowAnim __instance)
{
var targetedVolume = LoomConfig.configTargetedVolume.Value;
if (targetedVolume <= 0f) return false;
if (!Mathf.Approximately(targetedVolume, .5f) ||
!Mathf.Approximately(targetedVolume, __instance.targeted.Volume))
{
__instance.targeted.Volume = targetedVolume;
if (targetedVolume < .2f)
{
__instance.targeted.VolumeRandom = targetedVolume * .5f;
}
}
return true;
}
[HarmonyPrefix, HarmonyPatch(nameof(EnemyShadowAnim.PlayUntargetedSound))]
internal static bool PlayUntargetedSoundPrefix(EnemyShadowAnim __instance)
{
var notTargetedVolume = LoomConfig.configNotTargetedVolume.Value;
if (notTargetedVolume <= 0f) return false;
if (!Mathf.Approximately(notTargetedVolume, .5f) ||
!Mathf.Approximately(notTargetedVolume, __instance.notTargeted.Volume))
{
__instance.notTargeted.Volume = notTargetedVolume;
if (notTargetedVolume < .2f)
{
__instance.notTargeted.VolumeRandom = notTargetedVolume * .5f;
}
}
return true;
}
}
}