diff --git a/Behaviours/AirJump.cs b/Behaviours/AirJump.cs index e49a560..81759dc 100644 --- a/Behaviours/AirJump.cs +++ b/Behaviours/AirJump.cs @@ -14,7 +14,7 @@ using AirJump.Logging; using AirJump.Data; -using AirJump.Helpers; +//using AirJump.Helpers; namespace AirJump.Behaviours { @@ -25,7 +25,7 @@ class AirJump : MonoBehaviour private string fileLocation = string.Format("{0}\\SaveData", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); private string folderLocation = string.Format("{0}\\", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); - private Material customMaterial = new Material(Shader.Find("Standard")); + //private Material customMaterial = new Material(Shader.Find("Standard")); public bool isInModdedRoom = false; private bool isLeftPressed = false; @@ -48,7 +48,7 @@ class AirJump : MonoBehaviour private XRNode rightHandNode = XRNode.RightHand; private Vector3[] sizes = new Vector3[] { new Vector3(0.0125f, 0.28f, 0.3825f), new Vector3(0.0125f, 0.42f, 0.57375f), new Vector3(0.0125f, 0.56f, 0.765f) }; - private Material[] materials = new Material[] { null, Resources.Load("objects/treeroom/materials/darkfur"), null, null, Resources.Load("objects/character/materials/ice"), null }; + private Material[] materials = new Material[] { null, null, null, null, null, null }; void Awake() { @@ -56,7 +56,7 @@ void Awake() try { - customMaterial.mainTexture = AirJumpImageLoader.LoadImage($"{folderLocation}\\Custom.png", FilterMode.Point, 465, 1260); + //customMaterial.mainTexture = AirJumpImageLoader.LoadImage($"{folderLocation}\\Custom.png", FilterMode.Point, 465, 1260); } catch (Exception e) { @@ -69,12 +69,14 @@ void Awake() //materials[3] = GorillaTagger.Instance.offlineVRRig.materialsToChangeTo[1]; - foreach (VRRig rig in GameObject.FindObjectsOfType(typeof(VRRig))) + foreach (VRRig rig in FindObjectsOfType()) { if (rig.isOfflineVRRig) { + materials[1] = rig.materialsToChangeTo[0]; materials[2] = rig.materialsToChangeTo[2]; materials[3] = rig.materialsToChangeTo[1]; + materials[4] = rig.materialsToChangeTo[3]; } } @@ -99,13 +101,11 @@ void Awake() { settings.enabled = true; } - - PhotonNetwork.NetworkingClient.EventReceived += NetworkJump; } void Update() { - if (settings.enabled && isInModdedRoom && VersionVerifier.instance.validVersion) + if (settings.enabled && isInModdedRoom && VersionVerifier.validVersion) { InputDevices.GetDeviceAtXRNode(leftHandNode).TryGetFeatureValue(CommonUsages.gripButton, out isLeftPressed); InputDevices.GetDeviceAtXRNode(rightHandNode).TryGetFeatureValue(CommonUsages.gripButton, out isRightPressed); @@ -114,11 +114,23 @@ void Update() { if (!onceLeft) { - leftJump.transform.position = player.leftHandTransform.position; + VRRig vrRig = FindObjectOfType(); + + foreach (VRRig rig in FindObjectsOfType()) + { + if (rig.isMyPlayer) + vrRig = rig; + } + + leftJump.transform.parent = vrRig.transform; + leftJump.transform.localScale = sizes[settings.sizeIndex]; + leftJump.transform.parent = null; + + leftJump.transform.position = player.leftControllerTransform.position + (Vector3.down * 0.05f) * vrRig.scaleFactor; //leftJump.transform.rotation = Quaternion.Euler(0, -45, 0) * player.leftHandTransform.rotation; - leftJump.transform.rotation = player.leftHandTransform.rotation; + leftJump.transform.rotation = player.leftControllerTransform.rotation; - object[] leftJumpData = new object[] { player.leftHandTransform.position, player.leftHandTransform.rotation, settings.sizeIndex, settings.matIndex }; + object[] leftJumpData = new object[] { leftJump.transform.position, leftJump.transform.rotation, settings.sizeIndex, settings.matIndex }; PhotonNetwork.RaiseEvent((byte)PhotonEventCodes.LeftJump, leftJumpData, new RaiseEventOptions { Receivers = ReceiverGroup.Others }, SendOptions.SendReliable); onceLeft = true; @@ -140,11 +152,24 @@ void Update() { if (!onceRight) { - rightJump.transform.position = new Vector3(0, (float)-0.0075, 0) + player.rightHandTransform.position; + VRRig vrRig = FindObjectOfType(); + + foreach (VRRig rig in FindObjectsOfType()) + { + if (rig.isMyPlayer) + vrRig = rig; + } + + rightJump.transform.parent = vrRig.transform; + rightJump.transform.localScale = sizes[settings.sizeIndex]; + rightJump.transform.parent = null; + + //rightJump.transform.position = new Vector3(0, (float)-0.0075, 0) + player.rightHandTransform.position; + rightJump.transform.position = player.rightControllerTransform.position + (new Vector3(0, (float)-0.0075, 0) + Vector3.down * 0.05f) * vrRig.scaleFactor; //rightJump.transform.rotation = Quaternion.Euler(0, 45, 0) * player.rightHandTransform.rotation; - rightJump.transform.rotation = player.rightHandTransform.rotation; + rightJump.transform.rotation = player.rightControllerTransform.rotation; - object[] rightJumpData = new object[] { player.rightHandTransform.position, player.rightHandTransform.rotation, settings.sizeIndex, settings.matIndex }; + object[] rightJumpData = new object[] { rightJump.transform.position, rightJump.transform.rotation, settings.sizeIndex, settings.matIndex }; PhotonNetwork.RaiseEvent((byte)PhotonEventCodes.RightJump, rightJumpData, new RaiseEventOptions { Receivers = ReceiverGroup.Others }, SendOptions.SendReliable); onceRight = true; @@ -161,12 +186,18 @@ void Update() onceRight = false; } } - } } + public void JoinModded() + { + PhotonNetwork.NetworkingClient.EventReceived += NetworkJump; + } + public void LeaveModded() { + PhotonNetwork.NetworkingClient.EventReceived -= NetworkJump; + leftJump.transform.position = new Vector3(0, -999, 0); rightJump.transform.position = new Vector3(0, -999, 0); foreach (GameObject obj in leftJumpNetwork.Values) @@ -184,13 +215,15 @@ public void UpdateEnabled(bool enable) rightJump.transform.position = new Vector3(0, -999, 0); } - File.WriteAllText(fileLocation, JsonUtility.ToJson(settings)); + Plugin.instance.enabled = enable; + + SaveSettings(); } public void UpdateCollisions() { settings.otherCollisions = !settings.otherCollisions; - File.WriteAllText(fileLocation, JsonUtility.ToJson(settings)); + SaveSettings(); foreach (GameObject obj in leftJumpNetwork.Values) obj.GetComponent().enabled = settings.otherCollisions; @@ -213,7 +246,7 @@ public void UpdateSize(int index) } settings.sizeIndex = index; - File.WriteAllText(fileLocation, JsonUtility.ToJson(settings)); + SaveSettings(); } public void UpdateMat(int index) @@ -226,8 +259,8 @@ public void UpdateMat(int index) rightJump.GetComponent().material.SetColor("_Color", Color.black); break; case 5: - leftJump.GetComponent().material = customMaterial; - rightJump.GetComponent().material = customMaterial; + //leftJump.GetComponent().material = customMaterial; + //rightJump.GetComponent().material = customMaterial; break; default: leftJump.GetComponent().material = materials[index]; @@ -237,6 +270,9 @@ public void UpdateMat(int index) settings.matIndex = index; + AssignSurfaceOverride(leftJump, index); + AssignSurfaceOverride(rightJump, index); + if (isRightPressed || isLeftPressed) { object[] matData = new object[] { true, index }; @@ -244,6 +280,37 @@ public void UpdateMat(int index) } settings.matIndex = index; + + SaveSettings(); + } + + public void AssignSurfaceOverride(GameObject jump, int index) + { + if (jump.GetComponent() == null) + jump.AddComponent(); + + GorillaSurfaceOverride surface = jump.GetComponent(); + + switch (index) + { + case 1: + surface.overrideIndex = 4; + break; + case 2: + case 3: + surface.overrideIndex = 114; + break; + case 4: + surface.overrideIndex = 42; + break; + default: + surface.overrideIndex = 81; + break; + } + } + + public void SaveSettings() + { File.WriteAllText(fileLocation, JsonUtility.ToJson(settings)); } @@ -253,6 +320,10 @@ void NetworkJump(EventData eventData) try { + // Prevent cheating + if (!isInModdedRoom) + return; + object[] data = null; if (eventData.CustomData != null) @@ -287,12 +358,14 @@ void NetworkJump(EventData eventData) rightJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].GetComponent().material.SetColor("_Color", Color.black); break; case 5: - rightJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].GetComponent().material = customMaterial; + //rightJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].GetComponent().material = customMaterial; break; default: rightJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].GetComponent().material = materials[(int)data[1]]; break; } + + AssignSurfaceOverride(rightJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId], (int)data[1]); } if (leftJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId] != null) { @@ -302,16 +375,19 @@ void NetworkJump(EventData eventData) leftJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].GetComponent().material.SetColor("_Color", Color.black); break; case 5: - leftJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].GetComponent().material = customMaterial; + //leftJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].GetComponent().material = customMaterial; break; default: leftJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].GetComponent().material = materials[(int)data[1]]; break; } + + AssignSurfaceOverride(leftJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId], (int)data[1]); } } else { + if (rightJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId] != null) rightJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId].transform.localScale = sizes[(int)data[1]]; if (leftJumpNetwork[PhotonNetwork.CurrentRoom.GetPlayer(eventData.Sender).UserId] != null) @@ -337,7 +413,9 @@ GameObject CreateJump() GameObject CreateJumpNetwork(Vector3 position, Quaternion rotation, int sizeIndex, int matIndex, Photon.Realtime.Player player, bool otherCol) { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); + obj.transform.parent = GorillaGameManager.instance.FindVRRigForPlayer(player).transform; obj.transform.localScale = sizes[sizeIndex]; + obj.transform.parent = null; obj.transform.position = position; obj.transform.rotation = rotation; @@ -352,7 +430,7 @@ GameObject CreateJumpNetwork(Vector3 position, Quaternion rotation, int sizeInde break; case 5: //obj.GetComponent().material = GorillaGameManager.instance.FindVRRigForPlayer(player).GetComponent().mainSkin.material; - obj.GetComponent().material = customMaterial; + //obj.GetComponent().material = customMaterial; break; default: obj.GetComponent().material = materials[matIndex];