-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI.cs
123 lines (100 loc) · 4.21 KB
/
API.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static XUiC_ArchetypesWindowGroup;
using HarmonyLib;
using UnityEngine;
using System.Reflection;
using InControl;
using Gizmos = Popcron.Gizmos;
using System.Linq;
namespace _7DaysToDieVR
{
public class API : IModApi
{
public static float VRHeadsetFOV = 90f;
public void InitMod(Mod mod)
{
Log.Out(" Loading Patch: " + GetType().ToString());
new Harmony(GetType().ToString()).PatchAll(Assembly.GetExecutingAssembly());
}
}
/* FORMAT OF 7D2D arms
prefabEntityPlayerLocal (Clone)
↳ Camera
↳ femaleArms_fp
↳ Origin
↳ RightShoulder
↳ RightArm
↳ Right ForeArm
↳ RightForeArm Roll1
↳ RightForeArm Roll2
↳ RightForeArm Roll3
↳ RightForeArm Roll4
↳ RightHand
↳ RightHandThumb1
↳ RightHandThumb2
↳ RightHandThumb3
↳ RightHandThumb4
*/
[HarmonyPatch(typeof(EntityPlayerLocal))]
[HarmonyPatch("Init")]
public class EntityPlayerLocal_Init
{
static public vp_FPPlayerEventHandler eventHandler = new vp_FPPlayerEventHandler();
static void Postfix(EntityPlayerLocal __instance, int _entityClass)
{
if (VorpX.VPX_RESULT.VPX_RES_OK != VorpX.vpxInit())
{
Log.Out($"VorpX fatal error when trying to initialize");
return;
}
var instanceCamera = __instance.cameraTransform.GetComponent<Camera>();
if (instanceCamera)
{
API.VRHeadsetFOV = VorpX.vpxGetHeadsetFOV();
}
instanceCamera.fieldOfView = API.VRHeadsetFOV;
// Create an instance of the custom InputDevice.
var leftController = new VRControllerDevice(0);
var rightController = new VRControllerDevice(1);
// Attach the custom InputDevice to the InputManager.
InputManager.AttachDevice(leftController);
InputManager.AttachDevice(rightController);
VorpX.vpxForceControllerRendering(VorpX.VPX_BOOL.VPX_TRUE);
}
static void PrintTransformHierarchy(Transform transform, string prefix = "")
{
Log.Out(prefix + transform.name);
foreach (Transform child in transform)
{
PrintTransformHierarchy(child, prefix + transform.name + "/");
}
}
}
[HarmonyPatch(typeof(EntityPlayerLocal))]
[HarmonyPatch("LateUpdate")]
public class EntityPlayerLocal_LateUpdate
{
static bool printedOnce = false;
static void Postfix(EntityPlayerLocal __instance)
{
Transform cameraTransform = __instance.cameraTransform;
var instanceCamera = cameraTransform.GetComponent<Camera>();
if (instanceCamera)
{
API.VRHeadsetFOV = VorpX.vpxGetHeadsetFOV();
}
instanceCamera.fieldOfView = API.VRHeadsetFOV;
var headsetRotation4f = VorpX.vpxGetHeadsetRotationQuaternion();
var headsetPosition3f = VorpX.vpxGetHeadsetPosition();
var yaw_corrected_pos = VorpX.vpxYawCorrection(headsetPosition3f, headsetRotation4f.y);
Quaternion headsetRotation = new Quaternion(-headsetRotation4f.x, -headsetRotation4f.y, headsetRotation4f.z, headsetRotation4f.w);
Vector3 headsetPosition = new Vector3(yaw_corrected_pos.x, yaw_corrected_pos.y, yaw_corrected_pos.z);
__instance.playerCamera.transform.rotation = headsetRotation;
__instance.playerCamera.transform.position = __instance.cameraTransform.position + headsetPosition;
}
}
}