quantum-space-buddies/QSB/SatelliteSync/Patches/SatelliteProjectorPatches.cs

70 lines
2.0 KiB
C#
Raw Normal View History

2021-11-03 09:18:52 +00:00
using HarmonyLib;
2021-12-25 05:19:21 +00:00
using QSB.Messaging;
2021-11-03 09:18:52 +00:00
using QSB.Patches;
2021-12-25 05:19:21 +00:00
using QSB.SatelliteSync.Messages;
2021-11-03 11:56:50 +00:00
using UnityEngine;
2021-11-03 09:18:52 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.SatelliteSync.Patches;
[HarmonyPatch]
internal class SatelliteProjectorPatches : QSBPatch
2021-11-03 09:18:52 +00:00
{
2022-03-03 03:46:33 +00:00
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPostfix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.Awake))]
public static void CreateNewRenderTexture(SatelliteSnapshotController __instance)
{
__instance._snapshotTexture = SatelliteProjectorManager.Instance.SatelliteCameraSnapshot;
__instance._satelliteCamera.targetTexture = __instance._snapshotTexture;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.OnPressInteract))]
public static bool UseProjector()
2021-11-03 09:18:52 +00:00
{
2022-03-03 03:46:33 +00:00
new SatelliteProjectorMessage(true).Send();
return true;
}
2021-11-03 09:18:52 +00:00
2022-03-03 03:46:33 +00:00
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.TurnOffProjector))]
public static bool LeaveProjector()
{
new SatelliteProjectorMessage(false).Send();
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.Update))]
public static bool UpdateReplacement(SatelliteSnapshotController __instance)
{
if (!OWInput.IsInputMode(InputMode.SatelliteCam))
2021-11-30 19:17:26 +00:00
{
2022-03-03 03:46:33 +00:00
return false;
2021-11-30 19:17:26 +00:00
}
2022-03-03 03:46:33 +00:00
if (OWInput.IsNewlyPressed(InputLibrary.toolActionPrimary))
2021-11-03 09:18:52 +00:00
{
2022-03-03 03:46:33 +00:00
new SatelliteProjectorSnapshotMessage(true).Send();
__instance._satelliteCamera.transform.localEulerAngles = __instance._initCamLocalRot;
__instance.RenderSnapshot();
return false;
2021-11-03 09:18:52 +00:00
}
2022-03-03 03:46:33 +00:00
if (__instance._allowRearview && OWInput.IsNewlyPressed(InputLibrary.toolActionSecondary))
2021-11-03 09:18:52 +00:00
{
2022-03-03 03:46:33 +00:00
new SatelliteProjectorSnapshotMessage(false).Send();
__instance._satelliteCamera.transform.localEulerAngles = __instance._initCamLocalRot + new Vector3(0f, 180f, 0f);
__instance.RenderSnapshot();
return false;
2021-11-03 09:18:52 +00:00
}
2021-11-03 11:56:50 +00:00
2022-03-03 03:46:33 +00:00
if (OWInput.IsNewlyPressed(InputLibrary.cancel))
2021-11-03 11:56:50 +00:00
{
2022-03-03 03:46:33 +00:00
__instance.TurnOffProjector();
}
2022-03-03 03:46:33 +00:00
return false;
2021-11-03 09:18:52 +00:00
}
}