-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPlugin.cs
244 lines (205 loc) · 10.7 KB
/
Plugin.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
using BepInEx;
using GorillaTag.CosmeticSystem;
using Photon.Pun;
using Photon.Voice.Unity;
using Steamworks;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEngine;
namespace FortniteEmoteWheel
{
[BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
public class Plugin : BaseUnityPlugin
{
public void Start()
{
HarmonyPatches.ApplyHarmonyPatches();
}
private static AssetBundle assetBundle;
public static GameObject LoadAsset(string assetName)
{
GameObject gameObject = null;
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("FortniteEmoteWheel.Resources.fn");
if (stream != null)
{
if (assetBundle == null)
{
assetBundle = AssetBundle.LoadFromStream(stream);
}
gameObject = Instantiate<GameObject>(assetBundle.LoadAsset<GameObject>(assetName));
}
else
{
Debug.LogError("Failed to load asset from resource: " + assetName);
}
return gameObject;
}
public static GameObject audiomgr = null;
public static void Play2DAudio(AudioClip sound, float volume, bool looping = false)
{
if (audiomgr == null)
{
audiomgr = new GameObject("2DAudioMgr");
AudioSource temp = audiomgr.AddComponent<AudioSource>();
temp.spatialBlend = 0f;
}
AudioSource ausrc = audiomgr.GetComponent<AudioSource>();
ausrc.volume = volume;
ausrc.loop = looping;
if (!looping)
ausrc.PlayOneShot(sound);
else
{
ausrc.clip = sound;
ausrc.Play();
}
}
public static Dictionary<string, AudioClip> audioPool = new Dictionary<string, AudioClip> { };
public static AudioClip LoadSoundFromResource(string resourcePath)
{
AudioClip sound = null;
if (!audioPool.ContainsKey(resourcePath))
{
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("FortniteEmoteWheel.Resources.fn");
if (stream != null)
{
if (assetBundle == null)
{
assetBundle = AssetBundle.LoadFromStream(stream);
}
sound = assetBundle.LoadAsset(resourcePath) as AudioClip;
audioPool.Add(resourcePath, sound);
}
else
{
Debug.LogError("Failed to load sound from resource: " + resourcePath);
}
}
else
{
sound = audioPool[resourcePath];
}
return sound;
}
private static List<GameObject> portedCosmetics = new List<GameObject> { };
public static void DisableCosmetics()
{
try
{
GorillaTagger.Instance.offlineVRRig.transform.Find("RigAnchor/rig/body/head/gorillaface").gameObject.layer = LayerMask.NameToLayer("Default");
foreach (GameObject Cosmetic in GorillaTagger.Instance.offlineVRRig.cosmetics)
{
if (Cosmetic.activeSelf && Cosmetic.transform.parent == GorillaTagger.Instance.offlineVRRig.mainCamera.transform)
{
portedCosmetics.Add(Cosmetic);
Cosmetic.transform.SetParent(GorillaTagger.Instance.offlineVRRig.headMesh.transform, false);
Cosmetic.transform.localPosition += new Vector3(0f, 0.1333f, 0.1f);
}
}
} catch { }
}
public static void EnableCosmetics()
{
GorillaTagger.Instance.offlineVRRig.transform.Find("RigAnchor/rig/body/head/gorillaface").gameObject.layer = LayerMask.NameToLayer("MirrorOnly");
foreach (GameObject Cosmetic in portedCosmetics)
{
Cosmetic.transform.SetParent(GorillaTagger.Instance.offlineVRRig.mainCamera.transform, false);
Cosmetic.transform.localPosition -= new Vector3(0f, 0.1333f, 0.1f);
}
portedCosmetics.Clear();
}
public static GameObject Kyle;
public static float emoteTime;
private static int PreviousSerializationRate = -1;
public static Vector3 archivePosition;
public static void Emote(string emoteName, string emoteSound, float animationTime = -1f, bool looping = false)
{
if (Kyle != null)
UnityEngine.Object.Destroy(Kyle);
GorillaTagger.Instance.offlineVRRig.enabled = false;
DisableCosmetics();
PreviousSerializationRate = PhotonNetwork.SerializationRate;
PhotonNetwork.SerializationRate *= 3;
Play2DAudio(LoadSoundFromResource("play"), 0.5f);
archivePosition = GorillaTagger.Instance.transform.position;
GorillaLocomotion.Player.Instance.rightControllerTransform.parent.rotation *= Quaternion.Euler(0f, 180f, 0f);
Kyle = LoadAsset("Rig");
Kyle.transform.position = GorillaTagger.Instance.offlineVRRig.transform.Find("RigAnchor/rig/body").position - new Vector3(0f, 1.15f, 0f);
Kyle.transform.rotation = GorillaTagger.Instance.offlineVRRig.transform.Find("RigAnchor/rig/body").rotation;
Kyle.transform.Find("KyleRobot/RobotKile").gameObject.GetComponent<Renderer>().renderingLayerMask = 0;
Animator KyleRobot = Kyle.transform.Find("KyleRobot").GetComponent<Animator>();
KyleRobot.enabled = true;
AnimationClip Animation = null;
foreach (AnimationClip Clip in KyleRobot.runtimeAnimatorController.animationClips)
{
if (Clip.name == emoteName)
{
Animation = Clip;
break;
}
}
Animation.wrapMode = looping ? WrapMode.Loop : WrapMode.Default;
KyleRobot.Play(Animation.name);
AudioClip Sound = LoadSoundFromResource(emoteSound);
Play2DAudio(Sound, 0.5f, looping);
if (GorillaTagger.Instance.myRecorder != null)
{
GorillaTagger.Instance.myRecorder.SourceType = Recorder.InputSourceType.AudioClip;
GorillaTagger.Instance.myRecorder.AudioClip = Sound;
GorillaTagger.Instance.myRecorder.RestartRecording(true);
}
emoteTime = Time.time + (animationTime > 0f ? animationTime : Animation.length) + (looping ? 999999999999999f : 0);
}
public static Vector3 World2Player(Vector3 world)
{
return world - GorillaTagger.Instance.bodyCollider.transform.position + GorillaTagger.Instance.transform.position;
}
public void Update()
{
if (Classes.Wheel.instance == null && GorillaTagger.Instance.offlineVRRig != null)
{
GameObject Wheel = Plugin.LoadAsset("Wheel");
Wheel.transform.SetParent(GorillaTagger.Instance.offlineVRRig.transform.Find("RigAnchor/rig/body/shoulder.R/upper_arm.R/forearm.R/hand.R"), false);
Wheel.AddComponent<Classes.Wheel>();
}
if (Time.time < emoteTime)
{
if (Kyle != null)
{
GorillaTagger.Instance.offlineVRRig.enabled = false;
GorillaTagger.Instance.transform.position = World2Player(Kyle.transform.position + (Kyle.transform.forward * 1.5f) + new Vector3(0f, 1.15f, 0f)) + new Vector3(0f, 0.5f, 0f);
GorillaTagger.Instance.leftHandTransform.position = GorillaTagger.Instance.bodyCollider.transform.position;
GorillaTagger.Instance.rightHandTransform.position = GorillaTagger.Instance.bodyCollider.transform.position;
GorillaTagger.Instance.rigidbody.velocity = Vector3.zero;
GorillaTagger.Instance.offlineVRRig.transform.position = Kyle.transform.Find("KyleRobot/ROOT/Hips/Spine1/Spine2").transform.position - (Kyle.transform.Find("KyleRobot/ROOT/Hips/Spine1/Spine2").transform.right / 2.5f);
GorillaTagger.Instance.offlineVRRig.transform.rotation = Quaternion.Euler(new Vector3(0f, Kyle.transform.Find("KyleRobot/ROOT/Hips/Spine1/Spine2").transform.rotation.eulerAngles.y, 0f));
GorillaTagger.Instance.offlineVRRig.leftHand.rigTarget.transform.position = Kyle.transform.Find("KyleRobot/ROOT/Hips/Spine1/Spine2/LeftShoulder/LeftUpperArm/LeftArm/LeftHand").transform.position;
GorillaTagger.Instance.offlineVRRig.rightHand.rigTarget.transform.position = Kyle.transform.Find("KyleRobot/ROOT/Hips/Spine1/Spine2/RightShoulder/RightUpperArm/RightArm/RightHand").transform.position;
GorillaTagger.Instance.offlineVRRig.leftHand.rigTarget.transform.rotation = Kyle.transform.Find("KyleRobot/ROOT/Hips/Spine1/Spine2/LeftShoulder/LeftUpperArm/LeftArm/LeftHand").transform.rotation * Quaternion.Euler(0, 0, 75);
GorillaTagger.Instance.offlineVRRig.rightHand.rigTarget.transform.rotation = Kyle.transform.Find("KyleRobot/ROOT/Hips/Spine1/Spine2/RightShoulder/RightUpperArm/RightArm/RightHand").transform.rotation * Quaternion.Euler(180, 0, -75);
GorillaTagger.Instance.offlineVRRig.head.rigTarget.transform.rotation = Kyle.transform.Find("KyleRobot/ROOT/Hips/Spine1/Spine2/Neck/Head").transform.rotation * Quaternion.Euler(0f, 0f, 90f);
}
} else
{
if (Kyle != null)
{
GorillaTagger.Instance.offlineVRRig.enabled = true;
EnableCosmetics();
if (PreviousSerializationRate > 0)
PhotonNetwork.SerializationRate = PreviousSerializationRate;
UnityEngine.Object.Destroy(Kyle);
if (GorillaTagger.Instance.myRecorder != null)
{
GorillaTagger.Instance.myRecorder.SourceType = Recorder.InputSourceType.Microphone;
GorillaTagger.Instance.myRecorder.AudioClip = null;
GorillaTagger.Instance.myRecorder.RestartRecording(true);
}
GorillaTagger.Instance.transform.position = archivePosition;
GorillaLocomotion.Player.Instance.rightControllerTransform.parent.rotation *= Quaternion.Euler(0f, 180f, 0f);
}
}
}
}
}