Skip to content

Commit

Permalink
Merge pull request #635 from misternebula/dev
Browse files Browse the repository at this point in the history
0.29.0
  • Loading branch information
misternebula authored Jul 9, 2023
2 parents a1fcbd3 + 9ff28dc commit c8e4487
Show file tree
Hide file tree
Showing 21 changed files with 281 additions and 69 deletions.
8 changes: 7 additions & 1 deletion QSB/Audio/Messages/ShipThrusterAudioOneShotMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ public ShipThrusterAudioOneShotMessage(AudioType audioType, float pitch = 1f, fl

public override void OnReceiveRemote()
{
var source = ShipManager.Instance.ShipThrusterAudio._rotationalSource;
var source = ShipManager.Instance?.ShipThrusterAudio?._rotationalSource;

if (source == null)
{
return;
}

source.pitch = Data.pitch;
source.PlayOneShot(Data.audioType, Data.volume);
}
Expand Down
42 changes: 40 additions & 2 deletions QSB/HUD/MultiplayerHUDManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

Expand Down Expand Up @@ -94,7 +95,7 @@ public void WriteMessage(string message, Color color)

if (_messages.Count > LINE_COUNT)
{
_messages.RemoveFirstElementAndShift();
_messages.PopFromBack();
}

var currentLineIndex = 10;
Expand Down Expand Up @@ -157,6 +158,8 @@ public void WriteMessage(string message, Color color)
_textChat.GetComponent<CanvasGroup>().alpha = 1;
}

ListStack<string> previousMessages = new(true);

private void Update()
{
if (!QSBWorldSync.AllObjectsReady || _playerList == null)
Expand All @@ -168,12 +171,39 @@ private void Update()

var inSuit = Locator.GetPlayerSuit().IsWearingHelmet();

if (OWInput.IsNewlyPressed(InputLibrary.enter, InputMode.Character) && !_writingMessage && inSuit && QSBCore.TextChatInput)
if ((OWInput.IsNewlyPressed(InputLibrary.enter, InputMode.Character) || (Keyboard.current[Key.Slash].wasPressedThisFrame && OWInput.IsInputMode(InputMode.Character)))
&& !_writingMessage && inSuit && QSBCore.TextChatInput)
{
OWInput.ChangeInputMode(InputMode.KeyboardInput);
_writingMessage = true;
_inputField.ActivateInputField();
_textChat.GetComponent<CanvasGroup>().alpha = 1;

if (Keyboard.current[Key.Slash].wasPressedThisFrame)
{
Delay.RunNextFrame(() => _inputField.text = "/");
}
}

if (Keyboard.current[Key.UpArrow].wasPressedThisFrame && _writingMessage)
{
var currentText = _inputField.text;

if (previousMessages.Contains(currentText))
{
var index = previousMessages.IndexOf(currentText);

if (index == 0)
{
return;
}

_inputField.text = previousMessages[index - 1];
}
else
{
_inputField.text = previousMessages.Last();
}
}

if (OWInput.IsNewlyPressed(InputLibrary.enter, InputMode.KeyboardInput) && _writingMessage)
Expand All @@ -185,6 +215,14 @@ private void Update()
var message = _inputField.text;
_inputField.text = "";
message = message.Replace("\n", "").Replace("\r", "");

previousMessages.Push(message);

if (QSBCore.DebugSettings.DebugMode && CommandInterpreter.InterpretCommand(message))
{
return;
}

message = $"{QSBPlayerManager.LocalPlayer.Name}: {message}";
new ChatMessage(message, Color.white).Send();
}
Expand Down
4 changes: 2 additions & 2 deletions QSB/HUD/PlanetTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void OnSectorOccupantAdded(SectorDetector detector)
}

MultiplayerHUDManager.HUDIconStack.Push(Icon);
var top = MultiplayerHUDManager.HUDIconStack.Peek();
var top = MultiplayerHUDManager.HUDIconStack.PeekFront();
new PlanetMessage(top).Send();
}

Expand All @@ -28,7 +28,7 @@ public override void OnSectorOccupantRemoved(SectorDetector detector)
}

MultiplayerHUDManager.HUDIconStack.Remove(Icon);
var top = MultiplayerHUDManager.HUDIconStack.Peek();
var top = MultiplayerHUDManager.HUDIconStack.PeekFront();
new PlanetMessage(top).Send();
}
}
4 changes: 1 addition & 3 deletions QSB/Localization/Translation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mirror;
using System.Collections.Generic;
using System.Collections.Generic;

namespace QSB.Localization;

Expand Down Expand Up @@ -29,7 +28,6 @@ public class Translation
public string OK;
public string ServerRefusedConnection;
public string ClientDisconnectWithError;
public Dictionary<TransportError, string> TransportErrors;
public string QSBVersionMismatch;
public string OWVersionMismatch;
public string DLCMismatch;
Expand Down
2 changes: 1 addition & 1 deletion QSB/Menus/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ private void OnDisconnected(TransportError error, string reason)
}
};

OpenInfoPopup(string.Format(QSBLocalization.Current.ClientDisconnectWithError, QSBLocalization.Current.TransportErrors[error], reason), QSBLocalization.Current.OK);
OpenInfoPopup(string.Format(QSBLocalization.Current.ClientDisconnectWithError, reason), QSBLocalization.Current.OK);
}

SetButtonActive(DisconnectButton, false);
Expand Down
2 changes: 1 addition & 1 deletion QSB/Messaging/QSBMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class QSBMessage
/// <summary>
/// set automatically by Send
/// </summary>
internal uint From;
protected internal uint From;
/// <summary>
/// (default) uint.MaxValue = send to everyone <br/>
/// 0 = send to host
Expand Down
40 changes: 34 additions & 6 deletions QSB/Patches/QSBPatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,44 @@ public static void Init()
{
if (_inited)
{
var count = _patchList.Count;
var newPatches = new List<QSBPatch>();

foreach (var type in typeof(QSBPatch).GetDerivedTypes())
{
if (!_patchList.Any(x => x.GetType() == type))
if (!newPatches.Any(x => x.GetType() == type)
&& !_patchList.Any(x => x.GetType() == type))
{
newPatches.Add((QSBPatch)Activator.CreateInstance(type));
}
}

_patchList.AddRange(newPatches);

// could do lots of code to make sure all addon patches are done here,
// but the only patch type that will have been used by this point in the
// mod execution is OnModStart

DebugLog.DebugWrite($"Re-patching block OnModStart for addons", MessageType.Info);
var harmonyInstance = TypeToInstance[QSBPatchTypes.OnModStart];
foreach (var patch in newPatches)
{
if (patch.Type != QSBPatchTypes.OnModStart)
{
continue;
}

DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info);
try
{
patch.DoPatches(harmonyInstance);
}
catch (Exception ex)
{
_patchList.Add((QSBPatch)Activator.CreateInstance(type));
DebugLog.ToConsole($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error);
}
}

DebugLog.DebugWrite($"Registered {_patchList.Count - count} addon patches.", MessageType.Success);
DebugLog.DebugWrite($"Registered {newPatches.Count()} addon patches.", MessageType.Success);
return;
}

Expand All @@ -59,10 +87,10 @@ public static void DoPatchType(QSBPatchTypes type)
}

OnPatchType?.SafeInvoke(type);
//DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info);
DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info);
foreach (var patch in _patchList.Where(x => x.Type == type && x.PatchVendor.HasFlag(QSBCore.GameVendor)))
{
//DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info);
DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info);
try
{
patch.DoPatches(TypeToInstance[type]);
Expand Down
16 changes: 16 additions & 0 deletions QSB/Player/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using QSB.ShipSync;
using QSB.Tools;
using QSB.Utility;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

Expand Down Expand Up @@ -178,5 +179,20 @@ public void Revive()
HUDBox.OnRespawn();
}

private Dictionary<string, object> _customData = new();

public void SetCustomData<T>(string key, T data)
=> _customData[key] = data;

public T GetCustomData<T>(string key)
{
if (!_customData.ContainsKey(key))
{
return default;
}

return (T)_customData[key];
}

public override string ToString() => $"{PlayerId}:{GetType().Name} ({Name})";
}
4 changes: 2 additions & 2 deletions QSB/QSB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.393" IncludeAssets="compile" />
<PackageReference Include="OWML" Version="2.9.0" IncludeAssets="compile" />
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.457" IncludeAssets="compile" />
<PackageReference Include="OWML" Version="2.9.3" IncludeAssets="compile" />
<Reference Include="..\Mirror\*.dll" />
<Reference Include="..\UniTask\*.dll" />
<ProjectReference Include="..\EpicOnlineTransport\EpicOnlineTransport.csproj" />
Expand Down
37 changes: 21 additions & 16 deletions QSB/QSBNetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,52 +106,52 @@ public override void Awake()
playerPrefab = QSBCore.NetworkAssetBundle.LoadAsset<GameObject>("Assets/Prefabs/NETWORK_Player_Body.prefab");
playerPrefab.GetRequiredComponent<NetworkIdentity>().SetValue("_assetId", (uint)1);

ShipPrefab = MakeNewNetworkObject(2, "NetworkShip", typeof(ShipTransformSync));
ShipPrefab = MakeNewNetworkObject("NetworkShip", typeof(ShipTransformSync));
var shipVector3Sync = ShipPrefab.AddComponent<Vector3VariableSyncer>();
var shipThrustSync = ShipPrefab.AddComponent<ShipThrusterVariableSyncer>();
shipThrustSync.AccelerationSyncer = shipVector3Sync;
spawnPrefabs.Add(ShipPrefab);

_probePrefab = MakeNewNetworkObject(3, "NetworkProbe", typeof(PlayerProbeSync));
_probePrefab = MakeNewNetworkObject("NetworkProbe", typeof(PlayerProbeSync));
spawnPrefabs.Add(_probePrefab);

OrbPrefab = MakeNewNetworkObject(4, "NetworkOrb", typeof(NomaiOrbTransformSync));
OrbPrefab = MakeNewNetworkObject("NetworkOrb", typeof(NomaiOrbTransformSync));
spawnPrefabs.Add(OrbPrefab);

AnglerPrefab = MakeNewNetworkObject(5, "NetworkAngler", typeof(AnglerTransformSync));
AnglerPrefab = MakeNewNetworkObject("NetworkAngler", typeof(AnglerTransformSync));
spawnPrefabs.Add(AnglerPrefab);

JellyfishPrefab = MakeNewNetworkObject(6, "NetworkJellyfish", typeof(JellyfishTransformSync));
JellyfishPrefab = MakeNewNetworkObject("NetworkJellyfish", typeof(JellyfishTransformSync));
spawnPrefabs.Add(JellyfishPrefab);

OccasionalPrefab = MakeNewNetworkObject(7, "NetworkOccasional", typeof(OccasionalTransformSync));
OccasionalPrefab = MakeNewNetworkObject("NetworkOccasional", typeof(OccasionalTransformSync));
spawnPrefabs.Add(OccasionalPrefab);

RaftPrefab = MakeNewNetworkObject(8, "NetworkRaft", typeof(RaftTransformSync));
RaftPrefab = MakeNewNetworkObject("NetworkRaft", typeof(RaftTransformSync));
spawnPrefabs.Add(RaftPrefab);

DoorPrefab = MakeNewNetworkObject(9, "NetworkEclipseDoor", typeof(EclipseDoorVariableSyncer));
DoorPrefab = MakeNewNetworkObject("NetworkEclipseDoor", typeof(EclipseDoorVariableSyncer));
spawnPrefabs.Add(DoorPrefab);

ElevatorPrefab = MakeNewNetworkObject(10, "NetworkEclipseElevator", typeof(EclipseElevatorVariableSyncer));
ElevatorPrefab = MakeNewNetworkObject("NetworkEclipseElevator", typeof(EclipseElevatorVariableSyncer));
spawnPrefabs.Add(ElevatorPrefab);

AirlockPrefab = MakeNewNetworkObject(11, "NetworkGhostAirlock", typeof(AirlockVariableSyncer));
AirlockPrefab = MakeNewNetworkObject("NetworkGhostAirlock", typeof(AirlockVariableSyncer));
spawnPrefabs.Add(AirlockPrefab);

ShipModulePrefab = MakeNewNetworkObject(12, "NetworkShipModule", typeof(ShipModuleTransformSync));
ShipModulePrefab = MakeNewNetworkObject("NetworkShipModule", typeof(ShipModuleTransformSync));
spawnPrefabs.Add(ShipModulePrefab);

ShipLegPrefab = MakeNewNetworkObject(13, "NetworkShipLeg", typeof(ShipLegTransformSync));
ShipLegPrefab = MakeNewNetworkObject("NetworkShipLeg", typeof(ShipLegTransformSync));
spawnPrefabs.Add(ShipLegPrefab);

ModelShipPrefab = MakeNewNetworkObject(14, "NetworkModelShip", typeof(ModelShipTransformSync));
ModelShipPrefab = MakeNewNetworkObject("NetworkModelShip", typeof(ModelShipTransformSync));
var modelShipVector3Syncer = ModelShipPrefab.AddComponent<Vector3VariableSyncer>();
var modelShipThrusterVariableSyncer = ModelShipPrefab.AddComponent<ModelShipThrusterVariableSyncer>();
modelShipThrusterVariableSyncer.AccelerationSyncer = modelShipVector3Syncer;
spawnPrefabs.Add(ModelShipPrefab);

StationaryProbeLauncherPrefab = MakeNewNetworkObject(15, "NetworkStationaryProbeLauncher", typeof(StationaryProbeLauncherVariableSyncer));
StationaryProbeLauncherPrefab = MakeNewNetworkObject("NetworkStationaryProbeLauncher", typeof(StationaryProbeLauncherVariableSyncer));
spawnPrefabs.Add(StationaryProbeLauncherPrefab);

ConfigureNetworkManager();
Expand Down Expand Up @@ -207,11 +207,13 @@ private void InitPlayerName() =>
}
});

private static uint _assetId = 2; // 1 is the player

/// create a new network prefab from the network object prefab template.
/// this works by calling Unload(false) and then reloading the AssetBundle,
/// which makes LoadAsset give you a new resource.
/// see https://docs.unity3d.com/Manual/AssetBundles-Native.html.
private static GameObject MakeNewNetworkObject(uint assetId, string name, Type networkBehaviourType)
public static GameObject MakeNewNetworkObject(string name, Type networkBehaviourType)
{
var bundle = QSBCore.Helper.Assets.LoadBundle("AssetBundles/qsb_empty");

Expand All @@ -225,8 +227,11 @@ private static GameObject MakeNewNetworkObject(uint assetId, string name, Type n
bundle.Unload(false);

template.name = name;
template.AddComponent<NetworkIdentity>().SetValue("_assetId", assetId);
template.AddComponent<NetworkIdentity>().SetValue("_assetId", _assetId);
template.AddComponent(networkBehaviourType);

_assetId++;

return template;
}

Expand Down
12 changes: 9 additions & 3 deletions QSB/ShipSync/Messages/FlyShipMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@ public override void OnReceiveRemote()
{
SetCurrentFlyer(From, Data);
var shipCockpitController = ShipManager.Instance.CockpitController;

if (shipCockpitController == null)
{
return;
}

if (Data)
{
QSBPlayerManager.GetPlayer(From)?.AudioController?.PlayOneShot(AudioType.ShipCockpitBuckleUp);
shipCockpitController._interactVolume.DisableInteraction();
shipCockpitController._interactVolume?.DisableInteraction();
}
else
{
QSBPlayerManager.GetPlayer(From)?.AudioController?.PlayOneShot(AudioType.ShipCockpitUnbuckle);
shipCockpitController._interactVolume.EnableInteraction();
shipCockpitController._interactVolume?.EnableInteraction();
}
}

Expand All @@ -57,7 +63,7 @@ private static void SetCurrentFlyer(uint id, bool isFlying)

if (QSBCore.IsHost)
{
ShipTransformSync.LocalInstance.netIdentity.SetOwner(isFlying
ShipTransformSync.LocalInstance?.netIdentity.SetOwner(isFlying
? id
: QSBPlayerManager.LocalPlayerId);
}
Expand Down
2 changes: 1 addition & 1 deletion QSB/ShipSync/Patches/ShipAudioPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace QSB.ShipSync.Patches;

internal class ShipAudioPatches : QSBPatch
public class ShipAudioPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;

Expand Down
2 changes: 1 addition & 1 deletion QSB/ShipSync/Patches/ShipDetachableModulePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace QSB.ShipSync.Patches;

[HarmonyPatch(typeof(ShipDetachableModule))]
internal class ShipDetachableModulePatches : QSBPatch
public class ShipDetachableModulePatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;

Expand Down
Loading

0 comments on commit c8e4487

Please sign in to comment.