diff --git a/QSB/EchoesOfTheEye/LightSensorSync/Patches/LightSensorPatches.cs b/QSB/EchoesOfTheEye/LightSensorSync/Patches/LightSensorPatches.cs index 1ec5d2ef..637185a1 100644 --- a/QSB/EchoesOfTheEye/LightSensorSync/Patches/LightSensorPatches.cs +++ b/QSB/EchoesOfTheEye/LightSensorSync/Patches/LightSensorPatches.cs @@ -6,6 +6,7 @@ using QSB.Patches; using QSB.WorldSync; using System.Collections.Generic; using System.Linq; +using UnityEngine; /* * For those who come here, @@ -19,6 +20,52 @@ internal class LightSensorPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + [HarmonyPrefix] + [HarmonyPatch(nameof(SingleLightSensor.Start))] + private static bool Start(SingleLightSensor __instance) + { + if (__instance._lightDetector != null) + { + __instance._lightSources = new List(); + __instance._lightSourceMask = LightSourceType.VOLUME_ONLY; + if (__instance._detectFlashlight) + { + __instance._lightSourceMask |= LightSourceType.FLASHLIGHT; + } + + if (__instance._detectProbe) + { + __instance._lightSourceMask |= LightSourceType.PROBE; + } + + if (__instance._detectDreamLanterns) + { + __instance._lightSourceMask |= LightSourceType.DREAM_LANTERN; + } + + if (__instance._detectSimpleLanterns) + { + __instance._lightSourceMask |= LightSourceType.SIMPLE_LANTERN; + } + + __instance._lightDetector.OnLightVolumeEnter += __instance.OnLightSourceEnter; + __instance._lightDetector.OnLightVolumeExit += __instance.OnLightSourceExit; + } + else + { + Debug.LogError("LightSensor has no LightSourceDetector", __instance); + } + + if (__instance._sector != null) + { + __instance.enabled = false; + __instance._lightDetector.GetShape().enabled = false; + // dont do _startIlluminated stuff here since its done in the worldobject + } + + return false; + } + [HarmonyPrefix] [HarmonyPatch(nameof(SingleLightSensor.OnSectorOccupantsUpdated))] private static bool OnSectorOccupantsUpdated(SingleLightSensor __instance) diff --git a/QSB/EchoesOfTheEye/LightSensorSync/QSBPlayerLightSensor.cs b/QSB/EchoesOfTheEye/LightSensorSync/QSBPlayerLightSensor.cs index 0a141c61..d7b8499a 100644 --- a/QSB/EchoesOfTheEye/LightSensorSync/QSBPlayerLightSensor.cs +++ b/QSB/EchoesOfTheEye/LightSensorSync/QSBPlayerLightSensor.cs @@ -35,14 +35,13 @@ public class QSBPlayerLightSensor : MonoBehaviour RequestInitialStatesMessage.SendInitialState += SendInitialState; QSBPlayerManager.OnRemovePlayer += OnPlayerLeave; + // normally done in Start, but world objects arent ready by that point if (_lightSensor._sector != null) { if (_lightSensor._startIlluminated) { _locallyIlluminated = true; - // do it manually so as not to invoke OnDetectLight, since that's handled by Start - // BUG? should add all players to the list, not just local - _illuminatedBy.SafeAdd(PlayerId); + new PlayerSetIlluminatedMessage(PlayerId, true).Send(); } } } diff --git a/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBLightSensor.cs b/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBLightSensor.cs index 6ccebfd1..2832108e 100644 --- a/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBLightSensor.cs +++ b/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBLightSensor.cs @@ -36,15 +36,14 @@ internal class QSBLightSensor : WorldObject { QSBPlayerManager.OnRemovePlayer += OnPlayerLeave; + // normally done in Start, but world objects arent ready by that point if (AttachedObject._sector != null) { if (AttachedObject._startIlluminated) { _locallyIlluminated = true; OnDetectLocalLight?.Invoke(); - // do it manually so as not to invoke OnDetectLight, since that's handled by Start - // BUG? should add all players to the list, not just local - _illuminatedBy.SafeAdd(QSBPlayerManager.LocalPlayerId); + this.SendMessage(new SetIlluminatedMessage(true)); } } }