mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-30 03:32:47 +00:00
commit
c8e44875e3
@ -13,7 +13,13 @@ public class ShipThrusterAudioOneShotMessage : QSBMessage<(AudioType audioType,
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@ -94,7 +95,7 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
|
||||
if (_messages.Count > LINE_COUNT)
|
||||
{
|
||||
_messages.RemoveFirstElementAndShift();
|
||||
_messages.PopFromBack();
|
||||
}
|
||||
|
||||
var currentLineIndex = 10;
|
||||
@ -157,6 +158,8 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
_textChat.GetComponent<CanvasGroup>().alpha = 1;
|
||||
}
|
||||
|
||||
ListStack<string> previousMessages = new(true);
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!QSBWorldSync.AllObjectsReady || _playerList == null)
|
||||
@ -168,12 +171,39 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
|
||||
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)
|
||||
@ -185,6 +215,14 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
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();
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class PlanetTrigger : SectoredMonoBehaviour
|
||||
}
|
||||
|
||||
MultiplayerHUDManager.HUDIconStack.Push(Icon);
|
||||
var top = MultiplayerHUDManager.HUDIconStack.Peek();
|
||||
var top = MultiplayerHUDManager.HUDIconStack.PeekFront();
|
||||
new PlanetMessage(top).Send();
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ public class PlanetTrigger : SectoredMonoBehaviour
|
||||
}
|
||||
|
||||
MultiplayerHUDManager.HUDIconStack.Remove(Icon);
|
||||
var top = MultiplayerHUDManager.HUDIconStack.Peek();
|
||||
var top = MultiplayerHUDManager.HUDIconStack.PeekFront();
|
||||
new PlanetMessage(top).Send();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Mirror;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QSB.Localization;
|
||||
|
||||
@ -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;
|
||||
|
@ -736,7 +736,7 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
|
@ -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
|
||||
|
@ -23,16 +23,44 @@ public static class QSBPatchManager
|
||||
{
|
||||
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))
|
||||
{
|
||||
_patchList.Add((QSBPatch)Activator.CreateInstance(type));
|
||||
newPatches.Add((QSBPatch)Activator.CreateInstance(type));
|
||||
}
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"Registered {_patchList.Count - count} addon patches.", MessageType.Success);
|
||||
_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)
|
||||
{
|
||||
DebugLog.ToConsole($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"Registered {newPatches.Count()} addon patches.", MessageType.Success);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -59,10 +87,10 @@ public static class QSBPatchManager
|
||||
}
|
||||
|
||||
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]);
|
||||
|
@ -11,6 +11,7 @@ using QSB.QuantumSync.WorldObjects;
|
||||
using QSB.ShipSync;
|
||||
using QSB.Tools;
|
||||
using QSB.Utility;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@ -178,5 +179,20 @@ public partial class PlayerInfo
|
||||
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})";
|
||||
}
|
||||
|
@ -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" />
|
||||
|
@ -106,52 +106,52 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
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();
|
||||
@ -207,11 +207,13 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
}
|
||||
});
|
||||
|
||||
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");
|
||||
|
||||
@ -225,8 +227,11 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
bundle.Unload(false);
|
||||
|
||||
template.name = name;
|
||||
template.AddComponent<NetworkIdentity>().SetValue("_assetId", assetId);
|
||||
template.AddComponent<NetworkIdentity>().SetValue("_assetId", _assetId);
|
||||
template.AddComponent(networkBehaviourType);
|
||||
|
||||
_assetId++;
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
|
@ -37,15 +37,21 @@ internal class FlyShipMessage : QSBMessage<bool>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +63,7 @@ internal class FlyShipMessage : QSBMessage<bool>
|
||||
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
ShipTransformSync.LocalInstance.netIdentity.SetOwner(isFlying
|
||||
ShipTransformSync.LocalInstance?.netIdentity.SetOwner(isFlying
|
||||
? id
|
||||
: QSBPlayerManager.LocalPlayerId);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ShipSync.Patches;
|
||||
|
||||
internal class ShipAudioPatches : QSBPatch
|
||||
public class ShipAudioPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
|
@ -8,7 +8,7 @@ using QSB.WorldSync;
|
||||
namespace QSB.ShipSync.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(ShipDetachableModule))]
|
||||
internal class ShipDetachableModulePatches : QSBPatch
|
||||
public class ShipDetachableModulePatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
|
@ -8,7 +8,7 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ShipSync.Patches;
|
||||
|
||||
internal class ShipFlameWashPatches : QSBPatch
|
||||
public class ShipFlameWashPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
|
@ -13,7 +13,7 @@ using UnityEngine;
|
||||
namespace QSB.ShipSync.Patches;
|
||||
|
||||
[HarmonyPatch]
|
||||
internal class ShipPatches : QSBPatch
|
||||
public class ShipPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
|
@ -16,7 +16,7 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ShipSync;
|
||||
|
||||
internal class ShipManager : WorldObjectManager
|
||||
public class ShipManager : WorldObjectManager
|
||||
{
|
||||
public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem;
|
||||
|
||||
|
@ -22,17 +22,7 @@
|
||||
"Connecting": "CONNECTING...",
|
||||
"OK": "OK",
|
||||
"ServerRefusedConnection": "Server refused connection.\n{0}",
|
||||
"ClientDisconnectWithError": "Client disconnected with error!\n{0}\nMore info: {1}",
|
||||
"TransportErrors": {
|
||||
"DnsResolve": "Failed to resolve host name.",
|
||||
"Refused": "Connection refused.",
|
||||
"Timeout": "Connection timed out.",
|
||||
"Congestion": "Congestion on transport.",
|
||||
"InvalidReceive": "Error receiving message.",
|
||||
"InvalidSend": "Error sending message.",
|
||||
"ConnectionClosed": "Connection closed.",
|
||||
"Unexpected": "Unexpected error."
|
||||
},
|
||||
"ClientDisconnectWithError": "Client disconnected with error!\n{0}",
|
||||
"QSBVersionMismatch": "QSB version does not match. (Client:{0}, Server:{1})",
|
||||
"OWVersionMismatch": "Outer Wilds version does not match. (Client:{0}, Server:{1})",
|
||||
"DLCMismatch": "DLC installation state does not match. (Client:{0}, Server:{1})",
|
||||
|
74
QSB/Utility/CommandInterpreter.cs
Normal file
74
QSB/Utility/CommandInterpreter.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using QSB.HUD;
|
||||
using QSB.Messaging;
|
||||
using QSB.ShipSync;
|
||||
using QSB.ShipSync.Messages;
|
||||
using QSB.WorldSync;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Utility;
|
||||
|
||||
public class CommandInterpreter : MonoBehaviour, IAddComponentOnStart
|
||||
{
|
||||
public static bool InterpretCommand(string message)
|
||||
{
|
||||
if (message[0] != '/')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var commandParts = message.ToLower().Substring(1).Split(' ');
|
||||
var command = commandParts[0];
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case "ship":
|
||||
ShipCommand(commandParts.Skip(1).ToArray());
|
||||
break;
|
||||
default:
|
||||
MultiplayerHUDManager.Instance.WriteMessage($"Unknown command \"{command}\".", Color.red);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void ShipCommand(string[] arguments)
|
||||
{
|
||||
var command = arguments[0];
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case "explode":
|
||||
MultiplayerHUDManager.Instance.WriteMessage($"Blowing up the ship.", Color.green);
|
||||
var shipDamageController = Locator.GetShipTransform().GetComponentInChildren<ShipDamageController>();
|
||||
shipDamageController.Explode();
|
||||
break;
|
||||
case "repair":
|
||||
case "damage":
|
||||
var damage = command == "damage";
|
||||
switch (arguments[1])
|
||||
{
|
||||
case "headlight":
|
||||
var headlight = QSBWorldSync.GetUnityObject<ShipHeadlightComponent>();
|
||||
headlight.SetDamaged(damage);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
MultiplayerHUDManager.Instance.WriteMessage($"{(damage ? "Damaging" : "Repairing")} the {arguments[1]}.", Color.green);
|
||||
break;
|
||||
case "open-hatch":
|
||||
QSBWorldSync.GetUnityObject<HatchController>().OpenHatch();
|
||||
new HatchMessage(true).Send();
|
||||
break;
|
||||
case "close-hatch":
|
||||
QSBWorldSync.GetUnityObject<HatchController>().CloseHatch();
|
||||
new HatchMessage(false).Send();
|
||||
break;
|
||||
default:
|
||||
MultiplayerHUDManager.Instance.WriteMessage($"Unknown ship command \"{command}\".", Color.red);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using OWML.Common;
|
||||
using OWML.Logging;
|
||||
using OWML.Utils;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
@ -28,7 +28,20 @@ public static class DebugLog
|
||||
}
|
||||
else
|
||||
{
|
||||
QSBCore.Helper.Console.WriteLine(message, type, GetCallingType());
|
||||
var socket = QSBCore.Helper.Console.GetValue<IModSocket>("_socket");
|
||||
socket.WriteToSocket(new ModSocketMessage
|
||||
{
|
||||
SenderName = "QSB",
|
||||
SenderType = GetCallingType(),
|
||||
Type = type,
|
||||
Message = message
|
||||
});
|
||||
|
||||
if (type == MessageType.Fatal)
|
||||
{
|
||||
socket.Close();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,9 @@ using System.Collections.Generic;
|
||||
|
||||
namespace QSB.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// A LIFO collection with List<> functionality.
|
||||
/// </summary>
|
||||
public class ListStack<T> : IEnumerable<T>
|
||||
{
|
||||
private List<T> _items = new();
|
||||
@ -12,14 +15,21 @@ public class ListStack<T> : IEnumerable<T>
|
||||
|
||||
private readonly bool _removeDuplicates;
|
||||
|
||||
/// <param name="removeDuplicates">If true, all elements equal to the added item will be removed prior to adding the new element.</param>
|
||||
public ListStack(bool removeDuplicates)
|
||||
{
|
||||
_removeDuplicates = removeDuplicates;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all items from the stack.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
=> _items.Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Pushes an element onto the front of the stack.
|
||||
/// </summary>
|
||||
public void Push(T item)
|
||||
{
|
||||
if (_removeDuplicates && _items.Contains(item))
|
||||
@ -30,7 +40,10 @@ public class ListStack<T> : IEnumerable<T>
|
||||
_items.Add(item);
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
/// <summary>
|
||||
/// Pops an element off the front of the stack.
|
||||
/// </summary>
|
||||
public T PopFromFront()
|
||||
{
|
||||
if (_items.Count > 0)
|
||||
{
|
||||
@ -42,7 +55,10 @@ public class ListStack<T> : IEnumerable<T>
|
||||
return default;
|
||||
}
|
||||
|
||||
public T RemoveFirstElementAndShift()
|
||||
/// <summary>
|
||||
/// Pops an element off the back of the stack and shifts the entire stack backwards.
|
||||
/// </summary>
|
||||
public T PopFromBack()
|
||||
{
|
||||
if (_items.Count == 0)
|
||||
{
|
||||
@ -50,32 +66,54 @@ public class ListStack<T> : IEnumerable<T>
|
||||
}
|
||||
|
||||
var firstElement = _items[0];
|
||||
|
||||
if (_items.Count == 0)
|
||||
{
|
||||
return firstElement;
|
||||
}
|
||||
|
||||
// shift list left
|
||||
// allocates blehhh who cares
|
||||
_items = _items.GetRange(1, _items.Count - 1);
|
||||
|
||||
_items.RemoveAt(0);
|
||||
return firstElement;
|
||||
}
|
||||
|
||||
public T Peek() => _items.Count > 0
|
||||
/// <summary>
|
||||
/// Returns the element at the front of the stack.
|
||||
/// </summary>
|
||||
public T PeekFront() => _items.Count > 0
|
||||
? _items[_items.Count - 1]
|
||||
: default;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the element at the back of the stack.
|
||||
/// </summary>
|
||||
public T PeekBack() => _items.Count > 0
|
||||
? _items[0]
|
||||
: default;
|
||||
|
||||
/// <summary>
|
||||
/// Removes the element at the given index, where 0 is the back of the stack. The stack will shift backwards to fill empty space.
|
||||
/// </summary>
|
||||
public void RemoveAt(int index)
|
||||
=> _items.RemoveAt(index);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the first occurence (back to front) of an item.
|
||||
/// </summary>
|
||||
public bool Remove(T item)
|
||||
=> _items.Remove(item);
|
||||
|
||||
/// <summary>
|
||||
/// Removes all elements that match the given predicate.
|
||||
/// </summary>
|
||||
public int RemoveAll(Predicate<T> match)
|
||||
=> _items.RemoveAll(match);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the index of the given item, where 0 is the back of the stack.
|
||||
/// </summary>
|
||||
public int IndexOf(T item)
|
||||
=> _items.IndexOf(item);
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get => _items[index];
|
||||
set => _items[index] = value;
|
||||
}
|
||||
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => ((IEnumerable<T>)_items).GetEnumerator();
|
||||
public IEnumerator GetEnumerator() => ((IEnumerable<T>)_items).GetEnumerator();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
"body": "- Disable *all* other mods. (Can heavily affect performance)\n- Make sure you are not running any other network-intensive applications."
|
||||
},
|
||||
"uniqueName": "Raicuparta.QuantumSpaceBuddies",
|
||||
"version": "0.28.3",
|
||||
"version": "0.29.0",
|
||||
"owmlVersion": "2.9.0",
|
||||
"dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ],
|
||||
"pathsToPreserve": [ "debugsettings.json" ],
|
||||
|
Loading…
x
Reference in New Issue
Block a user