mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-22 12:39:51 +00:00
patches (i hate this)
This commit is contained in:
parent
814fb5cc20
commit
fb92861ed2
@ -12,11 +12,13 @@ internal class LightSensorManager : WorldObjectManager
|
|||||||
public override WorldObjectScene WorldObjectScene => WorldObjectScene.Both;
|
public override WorldObjectScene WorldObjectScene => WorldObjectScene.Both;
|
||||||
public override bool DlcOnly => true;
|
public override bool DlcOnly => true;
|
||||||
|
|
||||||
|
public static bool IsPlayerLightSensor(LightSensor lightSensor) => lightSensor.name is "CameraDetector" or "REMOTE_CameraDetector";
|
||||||
|
|
||||||
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
|
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
|
||||||
{
|
{
|
||||||
// ignore player light sensors
|
// ignore player light sensors
|
||||||
var list = QSBWorldSync.GetUnityObjects<SingleLightSensor>()
|
var list = QSBWorldSync.GetUnityObjects<SingleLightSensor>()
|
||||||
.Where(x => x.name is not ("CameraDetector" or "REMOTE_CameraDetector"))
|
.Where(x => !IsPlayerLightSensor(x))
|
||||||
.SortDeterministic();
|
.SortDeterministic();
|
||||||
QSBWorldSync.Init<QSBLightSensor, SingleLightSensor>(list);
|
QSBWorldSync.Init<QSBLightSensor, SingleLightSensor>(list);
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,8 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__instance.TryGetWorldObject(out QSBLightSensor qsbLightSensor))
|
var isPlayerLightSensor = LightSensorManager.IsPlayerLightSensor(__instance);
|
||||||
{
|
var qsbLightSensor = isPlayerLightSensor ? null : __instance.GetWorldObject<QSBLightSensor>();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (__instance._lightDetector != null)
|
if (__instance._lightDetector != null)
|
||||||
{
|
{
|
||||||
@ -67,9 +65,19 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
__instance._lightDetector.GetShape().enabled = false;
|
__instance._lightDetector.GetShape().enabled = false;
|
||||||
if (__instance._startIlluminated)
|
if (__instance._startIlluminated)
|
||||||
{
|
{
|
||||||
qsbLightSensor._locallyIlluminated = true;
|
if (isPlayerLightSensor)
|
||||||
qsbLightSensor.OnDetectLocalLight?.Invoke();
|
{
|
||||||
qsbLightSensor.SendMessage(new SetIlluminatedMessage(true));
|
var qsbPlayerLightSensor = __instance.GetComponent<QSBPlayerLightSensor>();
|
||||||
|
|
||||||
|
qsbPlayerLightSensor._locallyIlluminated = true;
|
||||||
|
new PlayerSetIlluminatedMessage(qsbPlayerLightSensor.PlayerId, true).Send();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qsbLightSensor._locallyIlluminated = true;
|
||||||
|
qsbLightSensor.OnDetectLocalLight?.Invoke();
|
||||||
|
qsbLightSensor.SendMessage(new SetIlluminatedMessage(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,10 +93,8 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__instance.TryGetWorldObject(out QSBLightSensor qsbLightSensor))
|
var isPlayerLightSensor = LightSensorManager.IsPlayerLightSensor(__instance);
|
||||||
{
|
var qsbLightSensor = isPlayerLightSensor ? null : __instance.GetWorldObject<QSBLightSensor>();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var containsAnyOccupants = __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe);
|
var containsAnyOccupants = __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe);
|
||||||
if (containsAnyOccupants && !__instance.enabled)
|
if (containsAnyOccupants && !__instance.enabled)
|
||||||
@ -106,11 +112,24 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
__instance._lightDetector.GetShape().enabled = false;
|
__instance._lightDetector.GetShape().enabled = false;
|
||||||
if (!__instance._preserveStateWhileDisabled)
|
if (!__instance._preserveStateWhileDisabled)
|
||||||
{
|
{
|
||||||
if (qsbLightSensor._locallyIlluminated)
|
if (isPlayerLightSensor)
|
||||||
{
|
{
|
||||||
qsbLightSensor._locallyIlluminated = false;
|
var qsbPlayerLightSensor = __instance.GetComponent<QSBPlayerLightSensor>();
|
||||||
qsbLightSensor.OnDetectLocalDarkness?.Invoke();
|
|
||||||
qsbLightSensor.SendMessage(new SetIlluminatedMessage(false));
|
if (qsbPlayerLightSensor._locallyIlluminated)
|
||||||
|
{
|
||||||
|
qsbPlayerLightSensor._locallyIlluminated = false;
|
||||||
|
new PlayerSetIlluminatedMessage(qsbPlayerLightSensor.PlayerId, false).Send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (qsbLightSensor._locallyIlluminated)
|
||||||
|
{
|
||||||
|
qsbLightSensor._locallyIlluminated = false;
|
||||||
|
qsbLightSensor.OnDetectLocalDarkness?.Invoke();
|
||||||
|
qsbLightSensor.SendMessage(new SetIlluminatedMessage(false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,10 +151,8 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__instance.TryGetWorldObject(out QSBLightSensor qsbLightSensor))
|
var isPlayerLightSensor = LightSensorManager.IsPlayerLightSensor(__instance);
|
||||||
{
|
var qsbLightSensor = isPlayerLightSensor ? null : __instance.GetWorldObject<QSBLightSensor>();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (__instance._fixedUpdateFrameDelayCount > 0)
|
if (__instance._fixedUpdateFrameDelayCount > 0)
|
||||||
{
|
{
|
||||||
@ -150,27 +167,63 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
|
|
||||||
var illuminated = __instance._illuminated;
|
var illuminated = __instance._illuminated;
|
||||||
__instance.UpdateIllumination();
|
__instance.UpdateIllumination();
|
||||||
var locallyIlluminated = qsbLightSensor._locallyIlluminated;
|
bool locallyIlluminated;
|
||||||
qsbLightSensor._locallyIlluminated = __instance._illuminated;
|
QSBPlayerLightSensor qsbPlayerLightSensor = null;
|
||||||
|
if (isPlayerLightSensor)
|
||||||
|
{
|
||||||
|
qsbPlayerLightSensor = __instance.GetComponent<QSBPlayerLightSensor>();
|
||||||
|
|
||||||
|
locallyIlluminated = qsbPlayerLightSensor._locallyIlluminated;
|
||||||
|
qsbPlayerLightSensor._locallyIlluminated = __instance._illuminated;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
locallyIlluminated = qsbLightSensor._locallyIlluminated;
|
||||||
|
qsbLightSensor._locallyIlluminated = __instance._illuminated;
|
||||||
|
}
|
||||||
|
|
||||||
__instance._illuminated = illuminated;
|
__instance._illuminated = illuminated;
|
||||||
|
|
||||||
if (!locallyIlluminated && qsbLightSensor._locallyIlluminated)
|
if (isPlayerLightSensor)
|
||||||
{
|
{
|
||||||
qsbLightSensor._locallyIlluminated = true;
|
if (!locallyIlluminated && qsbPlayerLightSensor._locallyIlluminated)
|
||||||
qsbLightSensor.OnDetectLocalLight?.Invoke();
|
{
|
||||||
qsbLightSensor.SendMessage(new SetIlluminatedMessage(true));
|
qsbPlayerLightSensor._locallyIlluminated = true;
|
||||||
|
new PlayerSetIlluminatedMessage(qsbPlayerLightSensor.PlayerId, true).Send();
|
||||||
|
}
|
||||||
|
else if (locallyIlluminated && !qsbPlayerLightSensor._locallyIlluminated)
|
||||||
|
{
|
||||||
|
qsbPlayerLightSensor._locallyIlluminated = false;
|
||||||
|
new PlayerSetIlluminatedMessage(qsbPlayerLightSensor.PlayerId, false).Send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (locallyIlluminated && !qsbLightSensor._locallyIlluminated)
|
else
|
||||||
{
|
{
|
||||||
qsbLightSensor._locallyIlluminated = false;
|
if (!locallyIlluminated && qsbLightSensor._locallyIlluminated)
|
||||||
qsbLightSensor.OnDetectLocalDarkness?.Invoke();
|
{
|
||||||
qsbLightSensor.SendMessage(new SetIlluminatedMessage(false));
|
qsbLightSensor._locallyIlluminated = true;
|
||||||
|
qsbLightSensor.OnDetectLocalLight?.Invoke();
|
||||||
|
qsbLightSensor.SendMessage(new SetIlluminatedMessage(true));
|
||||||
|
}
|
||||||
|
else if (locallyIlluminated && !qsbLightSensor._locallyIlluminated)
|
||||||
|
{
|
||||||
|
qsbLightSensor._locallyIlluminated = false;
|
||||||
|
qsbLightSensor.OnDetectLocalDarkness?.Invoke();
|
||||||
|
qsbLightSensor.SendMessage(new SetIlluminatedMessage(false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__instance._illuminatingDreamLanternList != null
|
if (__instance._illuminatingDreamLanternList != null
|
||||||
&& !__instance._illuminatingDreamLanternList.SequenceEqual(_prevIlluminatingDreamLanternList))
|
&& !__instance._illuminatingDreamLanternList.SequenceEqual(_prevIlluminatingDreamLanternList))
|
||||||
{
|
{
|
||||||
qsbLightSensor.SendMessage(new IlluminatingLanternsMessage(__instance._illuminatingDreamLanternList));
|
if (isPlayerLightSensor)
|
||||||
|
{
|
||||||
|
new PlayerIlluminatingLanternsMessage(qsbPlayerLightSensor.PlayerId, __instance._illuminatingDreamLanternList).Send();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qsbLightSensor.SendMessage(new IlluminatingLanternsMessage(__instance._illuminatingDreamLanternList));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -10,17 +10,13 @@ namespace QSB.EchoesOfTheEye.LightSensorSync;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// stores a bit of extra data needed for player light sensor sync
|
/// stores a bit of extra data needed for player light sensor sync
|
||||||
///
|
|
||||||
///
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// todo you might be able to remove when you simplify light sensor after the fake sector thingy
|
/// todo you might be able to remove when you simplify light sensor after the fake sector thingy
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RequireComponent(typeof(SingleLightSensor))]
|
[RequireComponent(typeof(SingleLightSensor))]
|
||||||
public class QSBPlayerLightSensor : MonoBehaviour
|
public class QSBPlayerLightSensor : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public uint PlayerId;
|
||||||
private SingleLightSensor _lightSensor;
|
private SingleLightSensor _lightSensor;
|
||||||
private PlayerInfo _player;
|
|
||||||
|
|
||||||
internal bool _locallyIlluminated;
|
internal bool _locallyIlluminated;
|
||||||
internal readonly List<uint> _illuminatedBy = new();
|
internal readonly List<uint> _illuminatedBy = new();
|
||||||
@ -28,7 +24,7 @@ public class QSBPlayerLightSensor : MonoBehaviour
|
|||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
_lightSensor = GetComponent<SingleLightSensor>();
|
_lightSensor = GetComponent<SingleLightSensor>();
|
||||||
_player = QSBPlayerManager.PlayerList.First(x => x.LightSensor == _lightSensor);
|
PlayerId = QSBPlayerManager.PlayerList.First(x => x.LightSensor == _lightSensor).PlayerId;
|
||||||
|
|
||||||
RequestInitialStatesMessage.SendInitialState += SendInitialState;
|
RequestInitialStatesMessage.SendInitialState += SendInitialState;
|
||||||
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
||||||
@ -42,10 +38,10 @@ public class QSBPlayerLightSensor : MonoBehaviour
|
|||||||
|
|
||||||
private void SendInitialState(uint to)
|
private void SendInitialState(uint to)
|
||||||
{
|
{
|
||||||
new PlayerIlluminatedByMessage(_player.PlayerId, _illuminatedBy.ToArray()) { To = to }.Send();
|
new PlayerIlluminatedByMessage(PlayerId, _illuminatedBy.ToArray()) { To = to }.Send();
|
||||||
if (_lightSensor._illuminatingDreamLanternList != null)
|
if (_lightSensor._illuminatingDreamLanternList != null)
|
||||||
{
|
{
|
||||||
new PlayerIlluminatingLanternsMessage(_player.PlayerId, _lightSensor._illuminatingDreamLanternList) { To = to }.Send();
|
new PlayerIlluminatingLanternsMessage(PlayerId, _lightSensor._illuminatingDreamLanternList) { To = to }.Send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,26 +269,6 @@ public static class QSBWorldSync
|
|||||||
return (TWorldObject)worldObject;
|
return (TWorldObject)worldObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetWorldObject<TWorldObject>(this MonoBehaviour unityObject, out TWorldObject worldObject)
|
|
||||||
where TWorldObject : IWorldObject
|
|
||||||
{
|
|
||||||
if (!unityObject)
|
|
||||||
{
|
|
||||||
DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:NULL, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error);
|
|
||||||
worldObject = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!UnityObjectsToWorldObjects.TryGetValue(unityObject, out var iWorldObject))
|
|
||||||
{
|
|
||||||
worldObject = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
worldObject = (TWorldObject)iWorldObject;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// not deterministic across platforms.
|
/// not deterministic across platforms.
|
||||||
/// iterates thru all objects and throws error if there isn't exactly 1.
|
/// iterates thru all objects and throws error if there isn't exactly 1.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user