@@ -8,35 +8,37 @@ public class CalibrationLinesVisualizer : MelonLoader.MelonMod
8
8
static CalibrationLinesVisualizer ms_instance = null ;
9
9
bool m_quit = false ;
10
10
11
- List < TrackerBoneLine > m_trackerLines = null ;
12
- bool m_calibrationInProgress = false ;
11
+ bool m_activeCalibration = false ;
12
+
13
+ List < GameObject > m_trackerLines = null ;
13
14
14
15
public override void OnApplicationStart ( )
15
16
{
16
- ms_instance = this ;
17
+ if ( ms_instance == null )
18
+ ms_instance = this ;
19
+
20
+ m_trackerLines = new List < GameObject > ( ) ;
17
21
18
22
MethodsResolver . ResolveMethods ( ) ;
19
23
Settings . LoadSettings ( ) ;
20
24
21
- m_trackerLines = new List < TrackerBoneLine > ( ) ;
22
-
23
25
// Events
24
26
VRChatUtilityKit . Utilities . VRCUtils . OnUiManagerInit += this . OnUiManagerInit ;
25
27
VRChatUtilityKit . Utilities . NetworkEvents . OnRoomJoined += this . OnRoomJoined ;
26
28
VRChatUtilityKit . Utilities . NetworkEvents . OnRoomLeft += this . OnRoomLeft ;
27
29
28
30
// Patches
29
31
if ( MethodsResolver . PrepareForCalibration != null )
30
- HarmonyInstance . Patch ( MethodsResolver . PrepareForCalibration , null , new HarmonyLib . HarmonyMethod ( typeof ( CalibrationLinesVisualizer ) , nameof ( VRCTrackingManager_PrepareForCalibration ) ) ) ;
32
+ HarmonyInstance . Patch ( MethodsResolver . PrepareForCalibration , null , new HarmonyLib . HarmonyMethod ( typeof ( CalibrationLinesVisualizer ) , nameof ( OnPrepareForCalibration_Postfix ) ) ) ;
31
33
32
34
if ( MethodsResolver . RestoreTrackingAfterCalibration != null )
33
- HarmonyInstance . Patch ( MethodsResolver . RestoreTrackingAfterCalibration , null , new HarmonyLib . HarmonyMethod ( typeof ( CalibrationLinesVisualizer ) , nameof ( VRCTrackingManager_RestoreTrackingAfterCalibration ) ) ) ;
35
+ HarmonyInstance . Patch ( MethodsResolver . RestoreTrackingAfterCalibration , null , new HarmonyLib . HarmonyMethod ( typeof ( CalibrationLinesVisualizer ) , nameof ( OnRestoreTrackingAfterCalibration_Postfix ) ) ) ;
34
36
35
37
if ( MethodsResolver . IKTweaks_Calibrate != null )
36
- HarmonyInstance . Patch ( MethodsResolver . IKTweaks_Calibrate , new HarmonyLib . HarmonyMethod ( typeof ( CalibrationLinesVisualizer ) , nameof ( VRCTrackingManager_PrepareForCalibration ) ) , null ) ;
38
+ HarmonyInstance . Patch ( MethodsResolver . IKTweaks_Calibrate , new HarmonyLib . HarmonyMethod ( typeof ( CalibrationLinesVisualizer ) , nameof ( OnPrepareForCalibration_Postfix ) ) , null ) ;
37
39
38
40
if ( MethodsResolver . IKTweaks_ApplyStoredCalibration != null )
39
- HarmonyInstance . Patch ( MethodsResolver . IKTweaks_ApplyStoredCalibration , new HarmonyLib . HarmonyMethod ( typeof ( CalibrationLinesVisualizer ) , nameof ( VRCTrackingManager_RestoreTrackingAfterCalibration ) ) , null ) ;
41
+ HarmonyInstance . Patch ( MethodsResolver . IKTweaks_ApplyStoredCalibration , new HarmonyLib . HarmonyMethod ( typeof ( CalibrationLinesVisualizer ) , nameof ( OnRestoreTrackingAfterCalibration_Postfix ) ) , null ) ;
40
42
}
41
43
42
44
public override void OnApplicationQuit ( )
@@ -51,14 +53,11 @@ public override void OnPreferencesSaved()
51
53
Settings . ReloadSettings ( ) ;
52
54
if ( Settings . IsAnyEntryUpdated ( ) )
53
55
{
54
- if ( TrackerBoneLine . GetLineMaterial ( ) != null )
55
- TrackerBoneLine . GetLineMaterial ( ) . color = new Color ( Settings . ColorR , Settings . ColorG , Settings . ColorB ) ;
56
-
57
- if ( m_trackerLines . Count != 0 )
58
- {
59
- foreach ( TrackerBoneLine l_trackerLine in m_trackerLines )
60
- l_trackerLine . gameObject . active = ( Settings . Enabled && m_calibrationInProgress ) ;
61
- }
56
+ if ( TrackerBoneLine . Material != null )
57
+ TrackerBoneLine . Material . color = new Color ( Settings . ColorR , Settings . ColorG , Settings . ColorB ) ;
58
+
59
+ foreach ( GameObject l_trackerLine in m_trackerLines )
60
+ l_trackerLine . active = ( Settings . Enabled && m_activeCalibration ) ;
62
61
}
63
62
}
64
63
}
@@ -77,79 +76,74 @@ System.Collections.IEnumerator CreateTrackerLines()
77
76
yield return null ;
78
77
79
78
TrackerBoneLine . ControllerManager = Utils . GetSteamVRControllerManager ( ) ;
80
- if ( TrackerBoneLine . GetLineMaterial ( ) != null )
81
- TrackerBoneLine . GetLineMaterial ( ) . color = new Color ( Settings . ColorR , Settings . ColorG , Settings . ColorB ) ;
82
79
80
+ // Material
81
+ TrackerBoneLine . Material = new Material ( Shader . Find ( "Hidden/Internal-Colored" ) ) ;
82
+ TrackerBoneLine . Material . hideFlags = HideFlags . HideAndDontSave ;
83
+ TrackerBoneLine . Material . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . SrcAlpha ) ;
84
+ TrackerBoneLine . Material . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . OneMinusSrcAlpha ) ;
85
+ TrackerBoneLine . Material . SetInt ( "_Cull" , ( int ) UnityEngine . Rendering . CullMode . Off ) ;
86
+ TrackerBoneLine . Material . SetInt ( "_ZWrite" , 0 ) ;
87
+ TrackerBoneLine . Material . SetInt ( "_ZTest" , ( int ) UnityEngine . Rendering . CompareFunction . Always ) ;
88
+
89
+ // Game objects
83
90
var l_puckArray = Utils . GetSteamVRControllerManager ( ) . field_Public_ArrayOf_GameObject_0 ;
84
91
for ( int i = 0 ; i < l_puckArray . Length - 2 ; i ++ )
85
92
{
86
- GameObject l_obj = new GameObject ( "BoneLine " ) ;
93
+ GameObject l_obj = new GameObject ( "Line " ) ;
87
94
l_obj . active = false ;
88
95
l_obj . layer = LayerMask . NameToLayer ( "Player" ) ;
89
96
l_obj . transform . parent = l_puckArray [ i + 2 ] . transform ;
90
97
l_obj . transform . localPosition = Vector3 . zero ;
91
98
l_obj . transform . localRotation = Quaternion . identity ;
92
99
Object . DontDestroyOnLoad ( l_obj ) ;
93
100
94
- l_obj . AddComponent < LineRenderer > ( ) ;
95
- TrackerBoneLine l_boneLine = l_obj . AddComponent < TrackerBoneLine > ( ) ;
96
- l_boneLine . Index = i + 2 ;
101
+ l_obj . AddComponent < TrackerBoneLine > ( ) . Index = i + 2 ;
97
102
98
- m_trackerLines . Add ( l_boneLine ) ;
103
+ m_trackerLines . Add ( l_obj ) ;
99
104
}
100
105
}
101
106
102
107
void OnRoomJoined ( )
103
108
{
104
- MelonLoader . MelonCoroutines . Start ( AssignPlayerToTrackerLines ( ) ) ;
109
+ MelonLoader . MelonCoroutines . Start ( AssignLocalPlayer ( ) ) ;
105
110
}
106
- System . Collections . IEnumerator AssignPlayerToTrackerLines ( )
111
+ System . Collections . IEnumerator AssignLocalPlayer ( )
107
112
{
108
113
while ( Utils . GetLocalPlayer ( ) == null )
109
114
yield return null ;
110
115
111
- foreach ( TrackerBoneLine l_trackerLine in m_trackerLines )
112
- l_trackerLine . Player = Utils . GetLocalPlayer ( ) ;
116
+ TrackerBoneLine . Player = Utils . GetLocalPlayer ( ) ;
113
117
}
114
118
115
119
void OnRoomLeft ( )
116
120
{
117
- OnCalibrationEnd ( ) ;
121
+ OnRestoreTrackingAfterCalibration ( ) ;
118
122
119
- if ( m_trackerLines . Count != 0 )
120
- {
121
- foreach ( TrackerBoneLine l_trackerLine in m_trackerLines )
122
- l_trackerLine . Player = null ;
123
- }
123
+ TrackerBoneLine . Player = null ;
124
124
}
125
125
126
- static public void VRCTrackingManager_PrepareForCalibration ( ) => ms_instance ? . OnCalibrationBegin ( ) ;
127
- void OnCalibrationBegin ( )
126
+ static public void OnPrepareForCalibration_Postfix ( ) => ms_instance ? . OnPrepareForCalibration ( ) ;
127
+ void OnPrepareForCalibration ( )
128
128
{
129
- if ( Settings . Enabled && ! m_calibrationInProgress )
129
+ if ( Settings . Enabled && ! m_activeCalibration )
130
130
{
131
- m_calibrationInProgress = true ;
131
+ m_activeCalibration = true ;
132
132
133
- if ( m_trackerLines . Count != 0 )
134
- {
135
- foreach ( TrackerBoneLine l_trackerLine in m_trackerLines )
136
- l_trackerLine . gameObject . active = true ;
137
- }
133
+ foreach ( GameObject l_trackerLine in m_trackerLines )
134
+ l_trackerLine . active = true ;
138
135
}
139
136
}
140
137
141
- static public void VRCTrackingManager_RestoreTrackingAfterCalibration ( ) => ms_instance ? . OnCalibrationEnd ( ) ;
142
- void OnCalibrationEnd ( )
138
+ static public void OnRestoreTrackingAfterCalibration_Postfix ( ) => ms_instance ? . OnRestoreTrackingAfterCalibration ( ) ;
139
+ void OnRestoreTrackingAfterCalibration ( )
143
140
{
144
- if ( Settings . Enabled && m_calibrationInProgress )
141
+ if ( m_activeCalibration )
145
142
{
146
- m_calibrationInProgress = false ;
143
+ m_activeCalibration = false ;
147
144
148
- if ( m_trackerLines . Count != 0 )
149
- {
150
- foreach ( TrackerBoneLine l_trackerLine in m_trackerLines )
151
- l_trackerLine . gameObject . active = false ;
152
- }
145
+ foreach ( GameObject l_trackerLine in m_trackerLines )
146
+ l_trackerLine . active = false ;
153
147
}
154
148
}
155
149
}
0 commit comments