Skip to content

Commit

Permalink
Merge pull request #248 from misternebula/dev
Browse files Browse the repository at this point in the history
0.8.0 - Quantum Sync, Signalscope Sync, Sprial Sync, Tests
  • Loading branch information
misternebula authored Feb 26, 2021
2 parents 5b25035 + 8d45ffa commit 2cae5b9
Show file tree
Hide file tree
Showing 211 changed files with 5,732 additions and 2,023 deletions.
6 changes: 6 additions & 0 deletions QSB.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QSB", "QSB\QSB.csproj", "{1
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantumUNET", "QuantumUNET\QuantumUNET.csproj", "{C8C53004-1508-4F86-A419-4292C188DC2A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QSBTests", "QSBTests\QSBTests.csproj", "{2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{C8C53004-1508-4F86-A419-4292C188DC2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8C53004-1508-4F86-A419-4292C188DC2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8C53004-1508-4F86-A419-4292C188DC2A}.Release|Any CPU.Build.0 = Release|Any CPU
{2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 6 additions & 6 deletions QSB/Animation/AnimationSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AnimationSync : PlayerSyncObject
{
private Animator _anim;
private Animator _bodyAnim;
private QSBNetworkAnimator _netAnim;
private QNetworkAnimator _netAnim;

private RuntimeAnimatorController _suitedAnimController;
private AnimatorOverrideController _unsuitedAnimController;
Expand All @@ -34,7 +34,7 @@ public class AnimationSync : PlayerSyncObject
protected void Awake()
{
_anim = gameObject.AddComponent<Animator>();
_netAnim = gameObject.AddComponent<QSBNetworkAnimator>();
_netAnim = gameObject.AddComponent<QNetworkAnimator>();
_netAnim.enabled = false;
_netAnim.animator = _anim;

Expand Down Expand Up @@ -130,7 +130,7 @@ public void InitRemote(Transform body)
InitCrouchSync();

var ikSync = body.gameObject.AddComponent<PlayerHeadRotationSync>();
QSBCore.Helper.Events.Unity.RunWhen(() => Player.Camera != null, () => ikSync.Init(Player.Camera.transform));
QSBCore.Helper.Events.Unity.RunWhen(() => Player.CameraBody != null, () => ikSync.Init(Player.CameraBody.transform));
}

private void InitCrouchSync()
Expand All @@ -145,19 +145,19 @@ private void InitCrouchSync()

private void OnBecomeUngrounded() => _netAnim.SetTrigger("Ungrounded");

public void SendCrouch(float value = 0) => GlobalMessenger<float>.FireEvent(EventNames.QSBCrouch, value);
public void SendCrouch(float value = 0) => QSBEventManager.FireEvent(EventNames.QSBCrouch, value);

public void HandleCrouch(float value) => _crouchSync.CrouchParam.Target = value;

private void SuitUp()
{
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, PlayerId, AnimationType.PlayerSuited);
QSBEventManager.FireEvent(EventNames.QSBChangeAnimType, PlayerId, AnimationType.PlayerSuited);
SetAnimationType(AnimationType.PlayerSuited);
}

private void SuitDown()
{
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, PlayerId, AnimationType.PlayerUnsuited);
QSBEventManager.FireEvent(EventNames.QSBChangeAnimType, PlayerId, AnimationType.PlayerUnsuited);
SetAnimationType(AnimationType.PlayerUnsuited);
}

Expand Down
2 changes: 1 addition & 1 deletion QSB/Animation/CrouchSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace QSB.Animation
{
public class CrouchSync : QSBNetworkBehaviour
public class CrouchSync : QNetworkBehaviour
{
public AnimFloatParam CrouchParam { get; } = new AnimFloatParam();

Expand Down
23 changes: 8 additions & 15 deletions QSB/ConversationSync/ConversationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace QSB.ConversationSync
public class ConversationManager : MonoBehaviour
{
public static ConversationManager Instance { get; private set; }
public AssetBundle ConversationAssetBundle { get; private set; }
public Dictionary<CharacterDialogueTree, GameObject> BoxMappings { get; } = new Dictionary<CharacterDialogueTree, GameObject>();

private GameObject _boxPrefab;
Expand All @@ -23,10 +22,9 @@ public void Start()
{
Instance = this;

ConversationAssetBundle = QSBCore.Helper.Assets.LoadBundle("assets/conversation");

_boxPrefab = ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
_boxPrefab = QSBCore.ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
// TODO : make dynamic so it can be different sizes!
// the dynamic font seems to be super lo-res at this size...?
var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold");
if (font == null)
{
Expand All @@ -45,8 +43,7 @@ public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
}

public void SendPlayerOption(string text) =>
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, text, ConversationType.Player);
QSBEventManager.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, text, ConversationType.Player);

public void SendCharacterDialogue(int id, string text)
{
Expand All @@ -55,17 +52,14 @@ public void SendCharacterDialogue(int id, string text)
DebugLog.ToConsole("Warning - Tried to send conv. event with char id -1.", MessageType.Warning);
return;
}
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, (uint)id, text, ConversationType.Character);
QSBEventManager.FireEvent(EventNames.QSBConversation, (uint)id, text, ConversationType.Character);
}

public void CloseBoxPlayer() =>
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, "", ConversationType.ClosePlayer);
QSBEventManager.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, "", ConversationType.ClosePlayer);

public void CloseBoxCharacter(int id) =>
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, (uint)id, "", ConversationType.CloseCharacter);
QSBEventManager.FireEvent(EventNames.QSBConversation, (uint)id, "", ConversationType.CloseCharacter);

public void SendConvState(int charId, bool state)
{
Expand All @@ -74,8 +68,7 @@ public void SendConvState(int charId, bool state)
DebugLog.ToConsole("Warning - Tried to send conv. start/end event with char id -1.", MessageType.Warning);
return;
}
GlobalMessenger<int, uint, bool>
.FireEvent(EventNames.QSBConversationStartEnd, charId, QSBPlayerManager.LocalPlayerId, state);
QSBEventManager.FireEvent(EventNames.QSBConversationStartEnd, charId, QSBPlayerManager.LocalPlayerId, state);
}

public void DisplayPlayerConversationBox(uint playerId, string text)
Expand Down Expand Up @@ -121,7 +114,7 @@ private GameObject CreateBox(Transform parent, float vertOffset, string text)
{
var newBox = Instantiate(_boxPrefab);
newBox.SetActive(false);
newBox.transform.parent = parent;
newBox.transform.SetParent(parent);
newBox.transform.localPosition = new Vector3(0, vertOffset, 0);
newBox.transform.rotation = parent.rotation;
var lookAt = newBox.AddComponent<FaceActiveCamera>();
Expand Down
4 changes: 2 additions & 2 deletions QSB/ConversationSync/Events/ConversationMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class ConversationMessage : PlayerMessage
public int ObjectId { get; set; }
public string Message { get; set; }

public override void Deserialize(QSBNetworkReader reader)
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
ObjectId = reader.ReadInt32();
Type = (ConversationType)reader.ReadInt32();
Message = reader.ReadString();
}

public override void Serialize(QSBNetworkWriter writer)
public override void Serialize(QNetworkWriter writer)
{
base.Serialize(writer);
writer.Write(ObjectId);
Expand Down
4 changes: 2 additions & 2 deletions QSB/ConversationSync/Events/ConversationStartEndMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class ConversationStartEndMessage : PlayerMessage
public uint PlayerId { get; set; }
public bool State { get; set; }

public override void Deserialize(QSBNetworkReader reader)
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
CharacterId = reader.ReadInt32();
PlayerId = reader.ReadUInt32();
State = reader.ReadBoolean();
}

public override void Serialize(QSBNetworkWriter writer)
public override void Serialize(QNetworkWriter writer)
{
base.Serialize(writer);
writer.Write(CharacterId);
Expand Down
4 changes: 2 additions & 2 deletions QSB/ConversationSync/Events/DialogueConditionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public class DialogueConditionMessage : PlayerMessage
public string ConditionName { get; set; }
public bool ConditionState { get; set; }

public override void Deserialize(QSBNetworkReader reader)
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
ConditionName = reader.ReadString();
ConditionState = reader.ReadBoolean();
}

public override void Serialize(QSBNetworkWriter writer)
public override void Serialize(QNetworkWriter writer)
{
base.Serialize(writer);
writer.Write(ConditionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Generic;
using UnityEngine;

namespace QSB.ConversationSync
namespace QSB.ConversationSync.Patches
{
public class ConversationPatches : QSBPatch
{
Expand Down Expand Up @@ -76,7 +76,7 @@ public static bool OnAnimatorIK(float ___headTrackingWeight,
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
var position = playerId == uint.MaxValue
? Locator.GetActiveCamera().transform.position
: QSBPlayerManager.GetPlayer(playerId).Camera.transform.position;
: QSBPlayerManager.GetPlayer(playerId).CameraBody.transform.position;
var b = ___headTrackingWeight * Mathf.Min(1, !___lookOnlyWhenTalking
? !____playerInHeadZone ? 0 : 1
: !____inConversation || !____playerInHeadZone ? 0 : 1);
Expand All @@ -102,5 +102,15 @@ public override void DoPatches()
QSBCore.Helper.HarmonyHelper.AddPrefix<CharacterAnimController>("OnAnimatorIK", typeof(ConversationPatches), nameof(OnAnimatorIK));
QSBCore.Helper.HarmonyHelper.AddPrefix<CharacterAnimController>("OnZoneExit", typeof(ConversationPatches), nameof(OnZoneExit));
}

public override void DoUnpatches()
{
QSBCore.Helper.HarmonyHelper.Unpatch<DialogueNode>("GetNextPage");
QSBCore.Helper.HarmonyHelper.Unpatch<CharacterDialogueTree>("InputDialogueOption");
QSBCore.Helper.HarmonyHelper.Unpatch<CharacterDialogueTree>("StartConversation");
QSBCore.Helper.HarmonyHelper.Unpatch<CharacterDialogueTree>("EndConversation");
QSBCore.Helper.HarmonyHelper.Unpatch<CharacterAnimController>("OnAnimatorIK");
QSBCore.Helper.HarmonyHelper.Unpatch<CharacterAnimController>("OnZoneExit");
}
}
}
39 changes: 0 additions & 39 deletions QSB/DeathSync/DeathPatches.cs

This file was deleted.

1 change: 1 addition & 0 deletions QSB/DeathSync/Events/PlayerDeathEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class PlayerDeathEvent : QSBEvent<EnumMessage<DeathType>>
public override void OnReceiveRemote(bool server, EnumMessage<DeathType> message)
{
var playerName = QSBPlayerManager.GetPlayer(message.AboutId).Name;
// TODO : this is random per client! change this event so it sends the message index and the deathtype?
var deathMessage = Necronomicon.GetPhrase(message.Value);
DebugLog.ToAll(string.Format(deathMessage, playerName));
}
Expand Down
83 changes: 83 additions & 0 deletions QSB/DeathSync/Patches/DeathPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Harmony;
using QSB.Events;
using QSB.Patches;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;

namespace QSB.DeathSync.Patches
{
public class DeathPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;

public override void DoPatches()
{
QSBCore.Helper.HarmonyHelper.AddPrefix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(PreFinishDeathSequence));
QSBCore.Helper.HarmonyHelper.AddPostfix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(BroadcastDeath));
QSBCore.Helper.HarmonyHelper.Transpile<ShipDetachableLeg>("Detach", typeof(DeathPatches), nameof(ReturnNull));
QSBCore.Helper.HarmonyHelper.Transpile<ShipDetachableModule>("Detach", typeof(DeathPatches), nameof(ReturnNull));
QSBCore.Helper.HarmonyHelper.EmptyMethod<ShipEjectionSystem>("OnPressInteract");
QSBCore.Helper.HarmonyHelper.AddPostfix<ShipDamageController>("Awake", typeof(DeathPatches), nameof(DamageController_Exploded));
QSBCore.Helper.HarmonyHelper.AddPrefix<DestructionVolume>("VanishShip", typeof(DeathPatches), nameof(DestructionVolume_VanishShip));
}

public override void DoUnpatches()
{
QSBCore.Helper.HarmonyHelper.Unpatch<DeathManager>("KillPlayer");
QSBCore.Helper.HarmonyHelper.Unpatch<ShipDetachableLeg>("Detach");
QSBCore.Helper.HarmonyHelper.Unpatch<ShipDetachableModule>("Detach");
QSBCore.Helper.HarmonyHelper.Unpatch<ShipEjectionSystem>("OnPressInteract");
QSBCore.Helper.HarmonyHelper.Unpatch<ShipDamageController>("Awake");
QSBCore.Helper.HarmonyHelper.Unpatch<DestructionVolume>("VanishShip");
}

public static bool PreFinishDeathSequence(DeathType deathType)
{
if (RespawnOnDeath.Instance == null)
{
return true;
}

if (RespawnOnDeath.Instance.AllowedDeathTypes.Contains(deathType))
{
return true;
}

RespawnOnDeath.Instance.ResetShip();
RespawnOnDeath.Instance.ResetPlayer();
return false;
}

public static void BroadcastDeath(DeathType deathType)
=> QSBEventManager.FireEvent(EventNames.QSBPlayerDeath, deathType);

public static void DamageController_Exploded(ref bool ____exploded)
=> ____exploded = true;

public static IEnumerable<CodeInstruction> ReturnNull(IEnumerable<CodeInstruction> instructions)
{
return new List<CodeInstruction>
{
new CodeInstruction(OpCodes.Ldnull),
new CodeInstruction(OpCodes.Ret)
};
}

public static bool DestructionVolume_VanishShip(DeathType ____deathType)
{
if (RespawnOnDeath.Instance == null)
{
return true;
}

if (PlayerState.IsInsideShip() || PlayerState.UsingShipComputer() || PlayerState.AtFlightConsole())
{
Locator.GetDeathManager().KillPlayer(____deathType);
}
// Ship is being destroyed, but player isn't in it.
RespawnOnDeath.Instance.ResetShip();
return false;
}
}
}
Loading

0 comments on commit 2cae5b9

Please sign in to comment.