Merge branch 'dev' into localization

This commit is contained in:
Mister_Nebula 2022-06-08 21:16:35 +01:00
commit c01efcf768
30 changed files with 293 additions and 40 deletions

View File

@ -3,7 +3,6 @@ using QSB.DeathSync.Messages;
using QSB.Messaging;
using QSB.Patches;
using QSB.Player;
using QSB.ShipSync.TransformSync;
using QSB.Utility;
using System.Linq;
using UnityEngine;
@ -115,6 +114,12 @@ public class DeathPatches : QSBPatch
[HarmonyPatch(typeof(DeathManager), nameof(DeathManager.KillPlayer))]
private static bool DeathManager_KillPlayer(DeathManager __instance, DeathType deathType)
{
// funny moment for eye
if (QSBSceneManager.CurrentScene != OWScene.SolarSystem)
{
return true;
}
Original(__instance, deathType);
return false;
@ -163,7 +168,7 @@ public class DeathPatches : QSBPatch
PlayerData.SetPersistentCondition("THERE_IS_BUT_VOID", true);
}
if ((TimeLoop.GetLoopCount() != 1 && TimeLoop.GetSecondsElapsed() < 60f || TimeLoop.GetLoopCount() == 1 && Time.timeSinceLevelLoad < 60f && !TimeLoop.IsTimeFlowing()) && deathType != DeathType.Meditation && LoadManager.GetCurrentScene() == OWScene.SolarSystem)
if (((TimeLoop.GetLoopCount() != 1 && TimeLoop.GetSecondsElapsed() < 60f) || (TimeLoop.GetLoopCount() == 1 && Time.timeSinceLevelLoad < 60f && !TimeLoop.IsTimeFlowing())) && deathType != DeathType.Meditation && LoadManager.GetCurrentScene() == OWScene.SolarSystem)
{
Achievements.Earn(Achievements.Type.GONE_IN_60_SECONDS);
}

View File

@ -87,6 +87,8 @@ public class RespawnOnDeath : MonoBehaviour
_playerResources._isSuffocating = false;
_playerResources.DebugRefillResources();
// death by oxygen turns this off, so we gotta enable it again
Delay.RunNextFrame(() => _playerResources.enabled = true);
_spaceSuit.RemoveSuit(true);
foreach (var pickupVolume in _suitPickupVolumes)

View File

@ -33,7 +33,7 @@ internal abstract class RotatingElementsVariableSyncer<TWorldObject> : BaseVaria
protected abstract Transform[] RotatingElements { get; }
protected override bool CheckChanged()
protected override bool HasChanged()
{
var rotatingElements = RotatingElements;
Value ??= new Quaternion[rotatingElements.Length];

View File

@ -69,6 +69,23 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart
}
QSBLocalisation.LanguageChanged += OnLanguageChanged;
if (QSBCore.DebugSettings.AutoStart)
{
// auto host/connect
Delay.RunWhen(PlayerData.IsLoaded, () =>
{
if (DebugLog.ProcessInstanceId == 0)
{
Host(false);
}
else
{
QSBCore.DefaultServerIP = "localhost";
Connect();
}
});
}
}
private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isUniverse)

View File

@ -31,4 +31,6 @@ public static class OWEvents
public const string FlickerOffAndOn = nameof(FlickerOffAndOn);
public const string EnterDreamWorld = nameof(EnterDreamWorld);
public const string ExitDreamWorld = nameof(ExitDreamWorld);
public const string EnterRemoteFlightConsole = nameof(EnterRemoteFlightConsole);
public const string ExitRemoteFlightConsole = nameof(ExitRemoteFlightConsole);
}

View File

@ -0,0 +1,13 @@
using QSB.Messaging;
using QSB.Patches;
using QSB.WorldSync;
namespace QSB.ModelShip.Messages;
internal class RespawnModelShipMessage : QSBMessage<bool>
{
public RespawnModelShipMessage(bool playEffects) : base(playEffects) { }
public override void OnReceiveRemote() =>
QSBPatch.RemoteCall(() => QSBWorldSync.GetUnityObject<RemoteFlightConsole>().RespawnModelShip(Data));
}

View File

@ -0,0 +1,73 @@
using QSB.AuthoritySync;
using QSB.Messaging;
using QSB.ModelShip.TransformSync;
using QSB.Player;
using QSB.Player.TransformSync;
using QSB.Utility;
using QSB.WorldSync;
namespace QSB.ModelShip.Messages;
internal class UseFlightConsoleMessage : QSBMessage<bool>
{
static UseFlightConsoleMessage()
{
GlobalMessenger<OWRigidbody>.AddListener(OWEvents.EnterRemoteFlightConsole, _ => Handler(true));
GlobalMessenger.AddListener(OWEvents.ExitRemoteFlightConsole, () => Handler(false));
}
private static void Handler(bool active)
{
if (PlayerTransformSync.LocalInstance != null)
{
new UseFlightConsoleMessage(active).Send();
}
}
private UseFlightConsoleMessage(bool active) : base(active) { }
public override void OnReceiveLocal()
{
if (QSBCore.IsHost)
{
ModelShipTransformSync.LocalInstance.netIdentity.SetAuthority(Data
? From
: QSBPlayerManager.LocalPlayerId);
}
}
public override void OnReceiveRemote()
{
var console = QSBWorldSync.GetUnityObject<RemoteFlightConsole>();
if (Data)
{
console._modelShipBody.Unsuspend();
console._interactVolume.ResetInteraction();
console._interactVolume.DisableInteraction();
}
else
{
console._interactVolume.ResetInteraction();
if (console._modelShipBody == null)
{
console._interactVolume.DisableInteraction();
return;
}
console._modelShipBody.Suspend(console._suspensionBody);
console._interactVolume.EnableInteraction();
}
QSBWorldSync.GetUnityObject<ModelShipController>()._detector.SetActive(Data);
QSBWorldSync.GetUnityObjects<ModelShipLandingSpot>().ForEach(x => x._owCollider.SetActivation(Data));
if (QSBCore.IsHost)
{
ModelShipTransformSync.LocalInstance.netIdentity.SetAuthority(Data
? From
: QSBPlayerManager.LocalPlayerId);
}
}
}

View File

@ -0,0 +1,34 @@
using Cysharp.Threading.Tasks;
using Mirror;
using OWML.Common;
using QSB.ModelShip.TransformSync;
using QSB.Utility;
using QSB.WorldSync;
using System.Threading;
namespace QSB.ModelShip;
internal class ModelShipManager : WorldObjectManager
{
public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem;
public override bool DlcOnly => false;
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
{
if (QSBCore.IsHost)
{
if (ModelShipTransformSync.LocalInstance != null)
{
if (ModelShipTransformSync.LocalInstance.gameObject == null)
{
DebugLog.ToConsole($"Warning - ShipTransformSync's LocalInstance is not null, but it's gameobject is null!", MessageType.Warning);
return;
}
NetworkServer.Destroy(ModelShipTransformSync.LocalInstance.gameObject);
}
Instantiate(QSBNetworkManager.singleton.ModelShipPrefab).SpawnWithServerAuthority();
}
}
}

View File

@ -0,0 +1,23 @@
using HarmonyLib;
using QSB.Messaging;
using QSB.ModelShip.Messages;
using QSB.Patches;
namespace QSB.ModelShip.Patches;
public class ModelShipPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(RemoteFlightConsole), nameof(RemoteFlightConsole.RespawnModelShip))]
private static void RemoteFlightConsole_RespawnModelShip(bool playEffects)
{
if (Remote)
{
return;
}
new RespawnModelShipMessage(playEffects).Send();
}
}

View File

@ -0,0 +1,58 @@
using QSB.Syncs.Sectored.Rigidbodies;
using QSB.Utility;
using QSB.WorldSync;
namespace QSB.ModelShip.TransformSync;
internal class ModelShipTransformSync : SectoredRigidbodySync
{
public static ModelShipTransformSync LocalInstance { get; private set; }
public override void OnStartClient()
{
base.OnStartClient();
LocalInstance = this;
}
/// <summary>
/// normally prints error when attached object is null.
/// this overrides it so that doesn't happen, since the model ship can be destroyed.
/// </summary>
protected override bool CheckValid()
=> AttachedTransform
&& base.CheckValid();
protected override bool UseInterpolation => true;
protected override OWRigidbody InitAttachedRigidbody()
{
var modelShip = QSBWorldSync.GetUnityObject<RemoteFlightConsole>()._modelShipBody;
SectorDetector.Init(modelShip.transform.Find("Detector").GetComponent<SectorDetector>());
return modelShip;
}
/// <summary>
/// replacement for base method
/// using SetPos/Rot instead of Move
/// </summary>
protected override void ApplyToAttached()
{
ApplyToSector();
if (!ReferenceTransform)
{
return;
}
var targetPos = ReferenceTransform.FromRelPos(SmoothPosition);
var targetRot = ReferenceTransform.FromRelRot(SmoothRotation);
AttachedRigidbody.SetPosition(targetPos);
AttachedRigidbody.SetRotation(targetRot);
var targetVelocity = ReferenceRigidbody.FromRelVel(Velocity, targetPos);
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(AngularVelocity);
AttachedRigidbody.SetVelocity(targetVelocity);
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
}
}

View File

@ -69,7 +69,6 @@ public partial class PlayerInfo
SignalscopeEquipped = default;
TranslatorEquipped = default;
ProbeActive = default;
ProbeLauncherEquipped = default;
}

View File

@ -105,6 +105,13 @@ public class QSBCore : ModBehaviour
);
}
if (DebugSettings.AutoStart)
{
DebugSettings.UseKcpTransport = true;
DebugSettings.SkipTitleScreen = true;
DebugSettings.DebugMode = true;
}
RegisterAddons();
InitAssemblies();

View File

@ -13,6 +13,7 @@ using QSB.EchoesOfTheEye.EclipseElevators.VariableSync;
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
using QSB.JellyfishSync.TransformSync;
using QSB.Messaging;
using QSB.ModelShip.TransformSync;
using QSB.OrbSync.Messages;
using QSB.OrbSync.TransformSync;
using QSB.OrbSync.WorldObjects;
@ -53,6 +54,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
public GameObject AirlockPrefab { get; private set; }
public GameObject ShipModulePrefab { get; private set; }
public GameObject ShipLegPrefab { get; private set; }
public GameObject ModelShipPrefab { get; private set; }
private string PlayerName { get; set; }
private GameObject _probePrefab;
@ -143,6 +145,9 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
ShipLegPrefab = MakeNewNetworkObject(13, "NetworkShipLeg", typeof(ShipLegTransformSync));
spawnPrefabs.Add(ShipLegPrefab);
ModelShipPrefab = MakeNewNetworkObject(14, "NetworkModelShip", typeof(ModelShipTransformSync));
spawnPrefabs.Add(ModelShipPrefab);
ConfigureNetworkManager();
}

View File

@ -24,7 +24,7 @@ public class ShipThrusterVariableSyncer : NetworkBehaviour
return;
}
if (AccelerationSyncer.HasChanged)
if (AccelerationSyncer.public_HasChanged())
{
if (AccelerationSyncer.Value == Vector3.zero)
{
@ -47,6 +47,11 @@ public class ShipThrusterVariableSyncer : NetworkBehaviour
}
}
private void GetFromShip() => AccelerationSyncer.Value = _thrusterModel.GetLocalAcceleration();
private void GetFromShip()
{
if (_thrusterModel)
{
AccelerationSyncer.Value = _thrusterModel.GetLocalAcceleration();
}
}
}

View File

@ -15,10 +15,7 @@ internal class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehav
=> AttachedTransform
&& base.CheckValid();
protected override bool CheckReady()
=> _qsbModule != null
&& _qsbModule.AttachedObject.isDetached
&& base.CheckReady();
protected override bool CheckReady() => base.CheckReady() && _qsbModule.AttachedObject.isDetached;
protected override bool UseInterpolation => true;

View File

@ -15,10 +15,7 @@ internal class ShipModuleTransformSync : SectoredRigidbodySync, ILinkedNetworkBe
=> AttachedTransform
&& base.CheckValid();
protected override bool CheckReady()
=> _qsbModule != null
&& _qsbModule.AttachedObject.isDetached
&& base.CheckReady();
protected override bool CheckReady() => base.CheckReady() && _qsbModule.AttachedObject.isDetached;
protected override bool UseInterpolation => true;

View File

@ -14,7 +14,7 @@ public class QSBNetworkTransform : QSBNetworkBehaviour
private Vector3 _prevPosition;
private Quaternion _prevRotation;
protected override bool CheckChanged() =>
protected override bool HasChanged() =>
Vector3.Distance(transform.position, _prevPosition) > PositionChangeThreshold ||
Quaternion.Angle(transform.rotation, _prevRotation) > RotationChangeThreshold;

View File

@ -16,7 +16,7 @@ public class QSBNetworkTransformChild : QSBNetworkBehaviour
private Vector3 _prevPosition;
private Quaternion _prevRotation;
protected override bool CheckChanged() =>
protected override bool HasChanged() =>
Vector3.Distance(Target.localPosition, _prevPosition) > PositionChangeThreshold ||
Quaternion.Angle(Target.localRotation, _prevRotation) > RotationChangeThreshold;

View File

@ -36,8 +36,8 @@ public abstract class SectoredRigidbodySync : BaseSectoredSync
ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null;
}
protected override bool CheckChanged() =>
base.CheckChanged() ||
protected override bool HasChanged() =>
base.HasChanged() ||
Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold ||
Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold;

View File

@ -198,7 +198,7 @@ public abstract class SyncBase : QSBNetworkTransform
/// <summary>
/// call the base method FIRST
/// </summary>
protected override bool CheckChanged()
protected override bool HasChanged()
{
GetFromAttached();
if (UseInterpolation)
@ -207,7 +207,7 @@ public abstract class SyncBase : QSBNetworkTransform
SmoothRotation = transform.rotation;
}
return base.CheckChanged();
return base.HasChanged();
}
/// <summary>

View File

@ -36,8 +36,8 @@ public abstract class UnsectoredRigidbodySync : BaseUnsectoredSync
ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null;
}
protected override bool CheckChanged() =>
base.CheckChanged() ||
protected override bool HasChanged() =>
base.HasChanged() ||
Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold ||
Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold;

View File

@ -1,4 +1,5 @@
using HarmonyLib;
using QSB.Inputs;
using QSB.Patches;
using QSB.Utility;
@ -17,6 +18,16 @@ internal class TimePatches : QSBPatch
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerCameraEffectController), nameof(PlayerCameraEffectController.WakeUp))]
public static void PlayerCameraEffectController_WakeUp(PlayerCameraEffectController __instance)
{
// prevent funny thing when you pause while waking up
QSBInputManager.Instance.SetInputsEnabled(false);
Delay.RunWhen(() => !__instance._isOpeningEyes, () => QSBInputManager.Instance.SetInputsEnabled(true));
}
[HarmonyPrefix]
[HarmonyPatch(typeof(OWTime), nameof(OWTime.Pause))]
public static bool StopPausing(OWTime.PauseType pauseType)

View File

@ -6,14 +6,14 @@ namespace QSB.Utility;
public static class DebugLog
{
private static readonly int _processInstanceId = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)
public static readonly int ProcessInstanceId = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)
.IndexOf(x => x.Id == Process.GetCurrentProcess().Id);
public static void ToConsole(string message, MessageType type = MessageType.Message)
{
if (QSBCore.DebugSettings.InstanceIdInLogs)
{
message = $"[{_processInstanceId}] " + message;
message = $"[{ProcessInstanceId}] " + message;
}
QSBCore.Helper.Console.WriteLine(message, type, GetCallingType(new StackTrace()));

View File

@ -20,6 +20,12 @@ public class DebugSettings
[JsonProperty("avoidTimeSync")]
public bool AvoidTimeSync;
[JsonProperty("autoStart")]
public bool AutoStart;
[JsonProperty("skipTitleScreen")]
public bool SkipTitleScreen;
[JsonProperty("debugMode")]
public bool DebugMode;
@ -43,10 +49,6 @@ public class DebugSettings
private bool _drawGhostAI;
public bool DrawGhostAI => DebugMode && _drawGhostAI;
[JsonProperty("skipTitleScreen")]
private bool _skipTitleScreen;
public bool SkipTitleScreen => DebugMode && _skipTitleScreen;
[JsonProperty("greySkybox")]
private bool _greySkybox;
public bool GreySkybox => DebugMode && _greySkybox;

View File

@ -22,8 +22,6 @@ public static class Extensions
/// </summary>
public static void SpawnLinked(this ILinkedWorldObject<NetworkBehaviour> worldObject, GameObject prefab, bool spawnWithServerAuthority)
{
DebugLog.DebugWrite($"SpawnLinked {prefab.name}");
var go = Object.Instantiate(prefab);
var networkBehaviour = go.GetComponent<ILinkedNetworkBehaviour>();

View File

@ -20,12 +20,10 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour
public override void OnStopClient() => RequestInitialStatesMessage.SendInitialState -= SendInitialState;
public bool HasChanged { get; private set; }
/// <summary>
/// checked before serializing
/// </summary>
protected abstract bool CheckChanged();
protected abstract bool HasChanged();
protected abstract void Serialize(NetworkWriter writer);
@ -56,8 +54,7 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour
{
_lastSendTime = NetworkTime.localTime;
HasChanged = CheckChanged();
if (!HasChanged)
if (!HasChanged())
{
return;
}

View File

@ -12,7 +12,8 @@ public abstract class BaseVariableSyncer<T> : QSBNetworkBehaviour
[NonSerialized]
public T Value;
protected override bool CheckChanged() => !EqualityComparer<T>.Default.Equals(PrevValue, Value);
public bool Bruh() => HasChanged();
protected override bool HasChanged() => !EqualityComparer<T>.Default.Equals(PrevValue, Value);
protected override void UpdatePrevData() => PrevValue = Value;
protected override void Serialize(NetworkWriter writer) => writer.Write(Value);
protected override void Deserialize(NetworkReader reader) => Value = reader.Read<T>();

View File

@ -4,4 +4,8 @@ namespace QSB.Utility.VariableSync;
public class Vector3VariableSyncer : BaseVariableSyncer<Vector3>
{
/// <summary>
/// hack for ShipThrusterVariableSyncer
/// </summary>
public bool public_HasChanged() => HasChanged();
}

View File

@ -4,12 +4,13 @@
"instanceIdInLogs": false,
"hookDebugLogs": false,
"avoidTimeSync": false,
"autoStart": false,
"skipTitleScreen": false,
"debugMode": false,
"drawGui": false,
"drawLines": false,
"drawLabels": false,
"drawQuantumVisibilityObjects": false,
"drawGhostAI": false,
"skipTitleScreen": false,
"greySkybox": false
}

View File

@ -132,13 +132,14 @@ The template for this file is this :
"instanceIdInLogs": false,
"hookDebugLogs": false,
"avoidTimeSync": false,
"autoStart": false,
"skipTitleScreen": false,
"debugMode": false,
"drawGui": false,
"drawLines": false,
"drawLabels": false,
"drawQuantumVisibilityObjects": false,
"drawGhostAI": false,
"skipTitleScreen": false,
"greySkybox": false
}
```
@ -148,13 +149,14 @@ The template for this file is this :
- instanceIdInLogs - Appends the game instance id to every log message sent.
- hookDebugLogs - Print Unity logs and warnings.
- avoidTimeSync - Disables the syncing of time.
- autoStart - Host/connect automatically for faster testing.
- skipTitleScreen - Auto-skips the splash screen.
- debugMode - Enables debug mode. If this is set to `false`, none of the following settings do anything.
- drawGui - Draws a GUI at the top of the screen that gives information on many things.
- drawLines - Draws gizmo-esque lines around things. Indicates reference sectors/transforms, triggers, etc. LAGGY.
- drawLabels - Draws GUI labels attached to some objects. LAGGY.
- drawQuantumVisibilityObjects - Indicates visibility objects with an orange shape.
- drawGhostAI - Draws debug lines and labels just for the ghosts.
- skipTitleScreen - Auto-skips the splash screen.
- greySkybox - Turns the skybox grey. Useful in the Eye, where it's pretty dark.
**Warning : Mod development can lead to unexpected errors in your computer system.**