2021-10-15 21:06:51 +01:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using QSB.Patches;
|
2020-12-22 09:13:08 +00:00
|
|
|
|
using QSB.Player;
|
2021-07-06 20:08:26 -03:00
|
|
|
|
using QSB.Utility;
|
2020-12-22 09:13:08 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.QuantumSync.Patches;
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch]
|
|
|
|
|
public class QuantumVisibilityPatches : QSBPatch
|
2020-12-22 09:13:08 +00:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
|
|
|
|
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
[HarmonyPatch(typeof(Shape), nameof(Shape.OnEnable))]
|
|
|
|
|
public static void Shape_OnEnable(Shape __instance)
|
|
|
|
|
=> __instance.RaiseEvent(nameof(__instance.OnShapeActivated), __instance);
|
|
|
|
|
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
[HarmonyPatch(typeof(Shape), nameof(Shape.OnDisable))]
|
|
|
|
|
public static void Shape_OnDisable(Shape __instance)
|
|
|
|
|
=> __instance.RaiseEvent(nameof(__instance.OnShapeDeactivated), __instance);
|
|
|
|
|
|
|
|
|
|
// ShapeVisibilityTracker patches
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(ShapeVisibilityTracker), nameof(ShapeVisibilityTracker.IsVisibleUsingCameraFrustum))]
|
|
|
|
|
public static bool ShapeVisibilityTracker_IsVisibleUsingCameraFrustum(ShapeVisibilityTracker __instance, out bool __result)
|
2020-12-22 09:13:08 +00:00
|
|
|
|
{
|
2022-03-06 22:36:52 -08:00
|
|
|
|
__result = QuantumManager.IsVisibleUsingCameraFrustum(__instance, false).FoundPlayers;
|
2022-03-02 19:46:33 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-22 09:13:08 +00:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(ShapeVisibilityTracker), nameof(ShapeVisibilityTracker.IsVisible))]
|
|
|
|
|
public static bool ShapeVisibilityTracker_IsVisible(ShapeVisibilityTracker __instance, out bool __result)
|
|
|
|
|
{
|
|
|
|
|
__result = QuantumManager.IsVisible(__instance, false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-02-27 14:23:35 +00:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
// RendererVisibilityTracker patches - probably not needed as i don't think RendererVisibilityTracker is ever used?
|
2021-02-09 17:18:01 +00:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(RendererVisibilityTracker), nameof(RendererVisibilityTracker.IsVisibleUsingCameraFrustum))]
|
|
|
|
|
public static bool RendererVisibilityTracker_IsVisibleUsingCameraFrustum(RendererVisibilityTracker __instance, out bool __result)
|
|
|
|
|
{
|
|
|
|
|
__result = QSBPlayerManager.GetPlayersWithCameras()
|
|
|
|
|
.Any(x => GeometryUtility.TestPlanesAABB(x.Camera.GetFrustumPlanes(), __instance._renderer.bounds))
|
|
|
|
|
&& (!__instance._checkFrustumOcclusion || QSBPlayerManager.GetPlayersWithCameras()
|
|
|
|
|
.Any(x => !__instance.IsOccludedFromPosition(x.Camera.transform.position)));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-22 09:13:08 +00:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
// VisibilityObject
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(VisibilityObject), nameof(VisibilityObject.CheckIllumination))]
|
|
|
|
|
public static bool VisibilityObject_CheckIllumination(VisibilityObject __instance, out bool __result)
|
|
|
|
|
{
|
|
|
|
|
if (!__instance._checkIllumination)
|
2020-12-22 09:13:08 +00:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
__result = true;
|
2020-12-22 09:13:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
var point = __instance.transform.TransformPoint(__instance._localIlluminationOffset);
|
2022-03-06 22:36:52 -08:00
|
|
|
|
var (localFlashlight, playerFlashlights) = QSBPlayerManager.GetPlayerFlashlights();
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
|
|
|
|
if (localFlashlight.CheckIlluminationAtPoint(point, __instance._illuminationRadius))
|
2020-12-22 09:13:08 +00:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
__result = true;
|
2020-12-22 09:13:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (playerFlashlights.Any(x => x.CheckIlluminationAtPoint(point, __instance._illuminationRadius)))
|
2021-01-31 14:21:54 +00:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
__result = true;
|
2022-02-24 22:04:54 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-01-31 14:21:54 +00:00
|
|
|
|
|
2022-03-07 13:25:41 -08:00
|
|
|
|
var (localProbe, playerProbes) = QSBPlayerManager.GetPlayerProbes();
|
|
|
|
|
|
2022-03-07 20:34:35 +00:00
|
|
|
|
if (localProbe != null
|
|
|
|
|
&& localProbe.IsLaunched()
|
|
|
|
|
&& localProbe.CheckIlluminationAtPoint(point, __instance._illuminationRadius))
|
|
|
|
|
{
|
|
|
|
|
__result = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playerProbes.Any(x => x.IsLaunched() && x.CheckIlluminationAtPoint(point, __instance._illuminationRadius)))
|
2022-02-24 22:04:54 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
__result = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-02-27 04:40:44 -08:00
|
|
|
|
|
2022-03-07 13:25:41 -08:00
|
|
|
|
if (QSBPlayerManager.GetThrusterLightTrackers()
|
|
|
|
|
.Any(x => x.CheckIlluminationAtPoint(point, __instance._illuminationRadius)))
|
2022-03-02 19:46:33 -08:00
|
|
|
|
{
|
|
|
|
|
__result = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-02-27 04:40:44 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (__instance._lightSources != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var light in __instance._lightSources)
|
2022-02-27 04:40:44 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (light.intensity > 0f && light.range > 0f)
|
2021-01-31 14:21:54 +00:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
__result = true;
|
|
|
|
|
return false;
|
2021-01-31 14:21:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-27 04:40:44 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
|
|
|
|
__result = false;
|
|
|
|
|
return false;
|
2020-12-22 09:13:08 +00:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|