Skip to content

Commit 0a378e1

Browse files
committed
Fix #25: PCR is now aware of ThroughTheEyes and cycles correctly when you have an external command chair and a probe core on board
1 parent 322b64e commit 0a378e1

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

ProbeControlRoom/ProbeControlRoom.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ public bool startIVA()
321321
ProbeControlRoomUtils.Logger.debug("startIVA() - return ACTIVE VESSEL NULL");
322322
return false;
323323
}
324-
ProbeControlRoomUtils.Logger.debug("startIVA()");
325324

326325
if (FlightGlobals.ActiveVessel.packed)
327326
{
@@ -341,6 +340,8 @@ public bool startIVA()
341340
return false;
342341
}
343342

343+
ProbeControlRoomUtils.Logger.debug("startIVA()");
344+
344345
// spawn the internal model
345346
if (aPart.internalModel == null)
346347
{
@@ -502,7 +503,10 @@ public void stopIVA()
502503

503504
// this re-attaches the camera to the internal space, so that it doesn't get deactivated below
504505
// It's really important that the camera doesn't get deactivated, because then it can't be found again by the stock code
505-
InternalCamera.Instance.DisableCamera();
506+
if (InternalCamera.Instance.transform.IsChildOf(aPart.internalModel.transform))
507+
{
508+
InternalCamera.Instance.DisableCamera();
509+
}
506510

507511
if (aPart != null && aPart.internalModel != null)
508512
{
@@ -555,7 +559,7 @@ public void stopIVA()
555559
InputLockManager.RemoveControlLock("ProbeControlRoom");
556560

557561
//Switch back to normal cameras
558-
if (CameraManager.Instance != null && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA)
562+
if (CameraManager.Instance != null && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA && !ThroughTheEyes.IsFirstPerson)
559563
{
560564
CameraManager.Instance.SetCameraFlight();
561565
}
@@ -604,6 +608,11 @@ public void LateUpdate()
604608
}
605609
else
606610
{
611+
// if we just pressed C and ThroughTheEyes entered first person, then we should go back to normal flight camera mode to preserve the cycle of flight -> iva -> pcr -> flight
612+
if (ThroughTheEyes.IsFirstPerson)
613+
{
614+
ThroughTheEyes.ExitFirstPerson();
615+
}
607616

608617
stopIVA();
609618
}
@@ -624,7 +633,7 @@ public void LateUpdate()
624633
else
625634
{
626635
// if pressing the camera mode (C) button and we either failed to enter IVA mode or just left it, then try to start PCR mode
627-
if (!GameSettings.MODIFIER_KEY.GetKey() && GameSettings.CAMERA_MODE.GetKeyDown() && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Flight)
636+
if (!GameSettings.MODIFIER_KEY.GetKey() && GameSettings.CAMERA_MODE.GetKeyDown() && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Flight && !ThroughTheEyes.IsFirstPerson)
628637
{
629638
//if (FlightGlobals.ActiveVessel?.GetCrewCount() == 0)
630639
{

ProbeControlRoom/ThroughTheEyes.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ProbeControlRoom
9+
{
10+
internal static class ThroughTheEyes
11+
{
12+
static TypeInfo x_FirstPersonEVA_TypeInfo;
13+
static FieldInfo x_instance_FieldInfo;
14+
static FieldInfo x_fpCameraManagerFieldInfo;
15+
16+
static TypeInfo x_FirstPersonCameraManager_TypeInfo;
17+
static FieldInfo x_isFirstPerson_FieldInfo;
18+
static MethodInfo x_resetCamera_MethodInfo;
19+
20+
static ThroughTheEyes()
21+
{
22+
var throughTheEyesAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name == "ThroughTheEyes");
23+
if (throughTheEyesAssembly == null) return;
24+
25+
x_FirstPersonEVA_TypeInfo = throughTheEyesAssembly.assembly.GetType("FirstPerson.FirstPersonEVA").GetTypeInfo();
26+
x_instance_FieldInfo = x_FirstPersonEVA_TypeInfo.GetField("instance", BindingFlags.Static | BindingFlags.Public);
27+
x_fpCameraManagerFieldInfo = x_FirstPersonEVA_TypeInfo.GetField("fpCameraManager", BindingFlags.Instance | BindingFlags.Public);
28+
29+
x_FirstPersonCameraManager_TypeInfo = throughTheEyesAssembly.assembly.GetType("FirstPerson.FirstPersonCameraManager").GetTypeInfo();
30+
x_isFirstPerson_FieldInfo = x_FirstPersonCameraManager_TypeInfo.GetField("isFirstPerson", BindingFlags.Instance | BindingFlags.Public);
31+
x_resetCamera_MethodInfo = x_FirstPersonCameraManager_TypeInfo.GetMethod("resetCamera", BindingFlags.Instance | BindingFlags.Public);
32+
}
33+
34+
public static bool IsFirstPerson
35+
{
36+
get
37+
{
38+
if (x_isFirstPerson_FieldInfo == null)
39+
{
40+
return false;
41+
}
42+
43+
object firstPersonEVAInstance = x_instance_FieldInfo.GetValue(null);
44+
object firstPersonCameraManager = x_fpCameraManagerFieldInfo.GetValue(firstPersonEVAInstance);
45+
return (bool)x_isFirstPerson_FieldInfo.GetValue(firstPersonCameraManager);
46+
}
47+
}
48+
49+
public static void ExitFirstPerson()
50+
{
51+
if (x_isFirstPerson_FieldInfo == null) return;
52+
53+
object firstPersonEVAInstance = x_instance_FieldInfo.GetValue(null);
54+
object firstPersonCameraManager = x_fpCameraManagerFieldInfo.GetValue(firstPersonEVAInstance);
55+
x_resetCamera_MethodInfo.Invoke(firstPersonCameraManager, new object[] { FlightGlobals.ActiveVessel });
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)