This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RemoteSaber.cs
90 lines (79 loc) · 2.83 KB
/
RemoteSaber.cs
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
using HarmonyLib;
using UnityEngine;
namespace BSCM.Modifiers
{
public class RemoteSaber
{
internal static VRController LeftSaber = null;
internal static VRController RightSaber = null;
public RemoteSaber(GameObject gameCore)
{
Plugin.Log.Info("Searching Sabers ...");
var saberManagerObj = gameCore.transform
.Find("Origin")
?.Find("VRGameCore")
?.Find("SaberManager");
if (saberManagerObj == null)
{
Plugin.Log.Critical("Couldn't find SaberManager !");
return;
}
var saberManager = saberManagerObj.GetComponent<SaberManager>();
LeftSaber = saberManager.GetPrivateField<Saber>("_leftSaber").GetComponent<VRController>();
RightSaber = saberManager.GetPrivateField<Saber>("_rightSaber").GetComponent<VRController>();
if (LeftSaber is null || RightSaber is null)
{
Plugin.Log.Critical("Sabers cannot be found !");
return;
}
Plugin.Log.Info("Sabers Found !");
}
}
[HarmonyPatch(typeof(VRController))]
[HarmonyPatch("Update")]
class RemoteSaberVRControllerPatch
{
static void Postfix(VRController __instance)
{
if (!PluginConfig.Instance.Enabled)
{
return;
}
Plugin.Multi.checkMessages();
if (ReferenceEquals(__instance, RemoteSaber.LeftSaber))
{
if(PluginConfig.Instance.isLeftRemoteSaber)
{
__instance.transform.position = Plugin.Multi.getLatestPosition();
__instance.transform.rotation = Plugin.Multi.getLatestRotation();
}
else
{
Plugin.Multi.sendCoords(__instance.transform.position, __instance.transform.rotation);
}
}
else if (ReferenceEquals(__instance, RemoteSaber.RightSaber))
{
if (!PluginConfig.Instance.isLeftRemoteSaber)
{
__instance.transform.position = Plugin.Multi.getLatestPosition();
__instance.transform.rotation = Plugin.Multi.getLatestRotation();
}
else
{
Plugin.Multi.sendCoords(__instance.transform.position, __instance.transform.rotation);
}
}
}
}
[HarmonyPatch(typeof(AudioTimeSyncController))]
[HarmonyPatch("StartSong")]
class AudioTimeSyncControllerPatch
{
static void Postfix(AudioTimeSyncController __instance)
{
if (PluginConfig.Instance.Enabled)
Plugin.Multi.startSong();
}
}
}