add custom files

This commit is contained in:
Mister_Nebula 2020-12-02 09:51:53 +00:00
parent 88428ba151
commit b649090258
25 changed files with 1703 additions and 70 deletions

View File

@ -74,7 +74,7 @@ namespace QSB.Animation
_netAnim.enabled = true; _netAnim.enabled = true;
_bodyAnim = body.GetComponent<Animator>(); _bodyAnim = body.GetComponent<Animator>();
Mirror = body.gameObject.AddComponent<AnimatorMirror>(); Mirror = body.gameObject.AddComponent<AnimatorMirror>();
if (isLocalPlayer) if (IsLocalPlayer)
{ {
Mirror.Init(_bodyAnim, _anim); Mirror.Init(_bodyAnim, _anim);
} }

View File

@ -4,7 +4,7 @@ using UnityEngine.Networking;
namespace QSB.Animation namespace QSB.Animation
{ {
public class CrouchSync : NetworkBehaviour public class CrouchSync : QSBNetworkBehaviour
{ {
public AnimFloatParam CrouchParam { get; } = new AnimFloatParam(); public AnimFloatParam CrouchParam { get; } = new AnimFloatParam();
@ -29,7 +29,7 @@ namespace QSB.Animation
private void Update() private void Update()
{ {
if (isLocalPlayer) if (IsLocalPlayer)
{ {
SyncLocalCrouch(); SyncLocalCrouch();
return; return;

View File

@ -6,9 +6,7 @@ namespace QSB.Animation
{ {
// Cleaned up unity code. UNET is so broken I gave up and fixed it myself. // Cleaned up unity code. UNET is so broken I gave up and fixed it myself.
[RequireComponent(typeof(NetworkIdentity))] class QSBNetworkAnimator : QSBNetworkBehaviour
[RequireComponent(typeof(Animator))]
class QSBNetworkAnimator : NetworkBehaviour
{ {
private static QSBAnimationMessage AnimationMessage = new QSBAnimationMessage(); private static QSBAnimationMessage AnimationMessage = new QSBAnimationMessage();
private static QSBAnimationParametersMessage ParametersMessage = new QSBAnimationParametersMessage(); private static QSBAnimationParametersMessage ParametersMessage = new QSBAnimationParametersMessage();
@ -65,7 +63,7 @@ namespace QSB.Animation
} }
var animationMessage = new QSBAnimationMessage var animationMessage = new QSBAnimationMessage
{ {
netId = netId, netId = NetId,
stateHash = stateHash, stateHash = stateHash,
normalizedTime = normalizedTime normalizedTime = normalizedTime
}; };
@ -74,13 +72,13 @@ namespace QSB.Animation
WriteParameters(m_ParameterWriter, false); WriteParameters(m_ParameterWriter, false);
animationMessage.parameters = m_ParameterWriter.ToArray(); animationMessage.parameters = m_ParameterWriter.ToArray();
if (hasAuthority || ClientScene.readyConnection != null) if (HasAuthority || ClientScene.readyConnection != null)
{ {
ClientScene.readyConnection.Send(40, animationMessage); ClientScene.readyConnection.Send(40, animationMessage);
} }
else else
{ {
if (!isServer || localPlayerAuthority) if (!IsServer || LocalPlayerAuthority)
{ {
return; return;
} }
@ -127,18 +125,18 @@ namespace QSB.Animation
m_SendTimer = Time.time + GetNetworkSendInterval(); m_SendTimer = Time.time + GetNetworkSendInterval();
var parametersMessage = new QSBAnimationParametersMessage var parametersMessage = new QSBAnimationParametersMessage
{ {
netId = netId netId = NetId
}; };
m_ParameterWriter.SeekZero(); m_ParameterWriter.SeekZero();
WriteParameters(m_ParameterWriter, true); WriteParameters(m_ParameterWriter, true);
parametersMessage.parameters = m_ParameterWriter.ToArray(); parametersMessage.parameters = m_ParameterWriter.ToArray();
if (hasAuthority && ClientScene.readyConnection != null) if (HasAuthority && ClientScene.readyConnection != null)
{ {
ClientScene.readyConnection.Send(41, parametersMessage); ClientScene.readyConnection.Send(41, parametersMessage);
} }
else else
{ {
if (!isServer || localPlayerAuthority) if (!IsServer || LocalPlayerAuthority)
return; return;
NetworkServer.SendToReady(gameObject, 41, parametersMessage); NetworkServer.SendToReady(gameObject, 41, parametersMessage);
} }
@ -146,7 +144,7 @@ namespace QSB.Animation
internal void HandleAnimMsg(QSBAnimationMessage msg, NetworkReader reader) internal void HandleAnimMsg(QSBAnimationMessage msg, NetworkReader reader)
{ {
if (hasAuthority) if (HasAuthority)
{ {
return; return;
} }
@ -159,7 +157,7 @@ namespace QSB.Animation
internal void HandleAnimParamsMsg(QSBAnimationParametersMessage msg, NetworkReader reader) internal void HandleAnimParamsMsg(QSBAnimationParametersMessage msg, NetworkReader reader)
{ {
if (hasAuthority) if (HasAuthority)
{ {
return; return;
} }
@ -267,10 +265,10 @@ namespace QSB.Animation
{ {
var animationTriggerMessage = new QSBAnimationTriggerMessage var animationTriggerMessage = new QSBAnimationTriggerMessage
{ {
netId = netId, netId = NetId,
hash = hash hash = hash
}; };
if (hasAuthority && localPlayerAuthority) if (HasAuthority && LocalPlayerAuthority)
{ {
if (NetworkClient.allClients.Count <= 0) if (NetworkClient.allClients.Count <= 0)
{ {
@ -285,7 +283,7 @@ namespace QSB.Animation
} }
else else
{ {
if (!isServer || localPlayerAuthority) if (!IsServer || LocalPlayerAuthority)
{ {
return; return;
} }

View File

@ -41,7 +41,7 @@ namespace QSB.Instruments
private void OnDestroy() private void OnDestroy()
{ {
if (!isLocalPlayer) if (!IsLocalPlayer)
{ {
return; return;
} }
@ -79,7 +79,7 @@ namespace QSB.Instruments
public void StartInstrument(AnimationType type) public void StartInstrument(AnimationType type)
{ {
if (!isLocalPlayer) if (!IsLocalPlayer)
{ {
DebugLog.DebugWrite("Error - Tried to start instrument on non-local player!", MessageType.Error); DebugLog.DebugWrite("Error - Tried to start instrument on non-local player!", MessageType.Error);
return; return;

View File

@ -48,16 +48,16 @@ namespace QSB.OrbSync.Events
DebugLog.ToConsole($"Error - No orb found for user event. (ID {message.ObjectId})", MessageType.Error); DebugLog.ToConsole($"Error - No orb found for user event. (ID {message.ObjectId})", MessageType.Error);
return; return;
} }
var orbIdentity = orb.GetComponent<NetworkIdentity>(); var orbIdentity = orb.GetComponent<QSBNetworkIdentity>();
if (orbIdentity == null) if (orbIdentity == null)
{ {
DebugLog.ToConsole($"Error - Orb identity is null. (ID {message.ObjectId})", MessageType.Error); DebugLog.ToConsole($"Error - Orb identity is null. (ID {message.ObjectId})", MessageType.Error);
return; return;
} }
if (orbIdentity.clientAuthorityOwner != null && orbIdentity.clientAuthorityOwner != fromPlayer) if (orbIdentity.ClientAuthorityOwner != null && orbIdentity.ClientAuthorityOwner != fromPlayer)
{ {
DebugLog.DebugWrite($"Removed authority of orb {message.ObjectId} from {orbIdentity.clientAuthorityOwner.GetPlayer().PlayerId}"); DebugLog.DebugWrite($"Removed authority of orb {message.ObjectId} from {orbIdentity.ClientAuthorityOwner.GetPlayer().PlayerId}");
orbIdentity.RemoveClientAuthority(orbIdentity.clientAuthorityOwner); orbIdentity.RemoveClientAuthority(orbIdentity.ClientAuthorityOwner);
} }
DebugLog.DebugWrite($"Assigned authority of orb {message.ObjectId} to player {message.FromId}."); DebugLog.DebugWrite($"Assigned authority of orb {message.ObjectId} to player {message.FromId}.");
orbIdentity.AssignClientAuthority(fromPlayer); orbIdentity.AssignClientAuthority(fromPlayer);

View File

@ -45,7 +45,7 @@ namespace QSB.Player.Events
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>() foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId)) .Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
{ {
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.netId.Value, item.ReferenceSector); GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
} }
} }
} }

View File

@ -28,7 +28,7 @@ namespace QSB.Player.Events
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>() foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null)) .Where(x => x != null && x.IsReady && x.ReferenceSector != null))
{ {
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.netId.Value, item.ReferenceSector); GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
} }
} }
} }

View File

@ -2,9 +2,9 @@
namespace QSB.Player namespace QSB.Player
{ {
public abstract class PlayerSyncObject : NetworkBehaviour public abstract class PlayerSyncObject : QSBNetworkBehaviour
{ {
public uint AttachedNetId => GetComponent<NetworkIdentity>()?.netId.Value ?? uint.MaxValue; public uint AttachedNetId => GetComponent<QSBNetworkIdentity>()?.NetId.Value ?? uint.MaxValue;
public uint PlayerId => this.GetPlayerOfObject(); public uint PlayerId => this.GetPlayerOfObject();
public uint PreviousPlayerId { get; set; } public uint PreviousPlayerId { get; set; }
public PlayerInfo Player => QSBPlayerManager.GetPlayer(PlayerId); public PlayerInfo Player => QSBPlayerManager.GetPlayer(PlayerId);

View File

@ -10,7 +10,7 @@ namespace QSB.Player
{ {
public static class QSBPlayerManager public static class QSBPlayerManager
{ {
public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.GetComponent<NetworkIdentity>()?.netId.Value ?? uint.MaxValue; public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.GetComponent<QSBNetworkIdentity>()?.NetId.Value ?? uint.MaxValue;
public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId); public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId);
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>(); public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();
@ -75,7 +75,7 @@ namespace QSB.Player
public static bool IsBelongingToLocalPlayer(uint id) public static bool IsBelongingToLocalPlayer(uint id)
{ {
return id == LocalPlayerId || return id == LocalPlayerId ||
PlayerSyncObjects.Any(x => x != null && x.AttachedNetId == id && x.isLocalPlayer); PlayerSyncObjects.Any(x => x != null && x.AttachedNetId == id && x.IsLocalPlayer);
} }
public static uint GetPlayerOfObject(this PlayerSyncObject syncObject) public static uint GetPlayerOfObject(this PlayerSyncObject syncObject)
@ -131,7 +131,7 @@ namespace QSB.Player
int count = 0; int count = 0;
int totalCount = PlayerSyncObjects.Count; int totalCount = PlayerSyncObjects.Count;
PlayerSyncObjects.RemoveAll(x => x == null); PlayerSyncObjects.RemoveAll(x => x == null);
PlayerSyncObjects.RemoveAll(x => x.GetComponent<NetworkIdentity>() == null); PlayerSyncObjects.RemoveAll(x => x.GetComponent<QSBNetworkIdentity>() == null);
if (PlayerSyncObjects.Count != totalCount) if (PlayerSyncObjects.Count != totalCount)
{ {
DebugLog.ToConsole($"Warning - Removed {totalCount - PlayerSyncObjects.Count} items from PlayerSyncObjects.", MessageType.Warning); DebugLog.ToConsole($"Warning - Removed {totalCount - PlayerSyncObjects.Count} items from PlayerSyncObjects.", MessageType.Warning);

View File

@ -37,7 +37,7 @@ namespace QSB
LogFilter.currentLogLevel = LogFilter.Debug; LogFilter.currentLogLevel = LogFilter.Debug;
Application.logMessageReceived += Application_logMessageReceived; // Application.logMessageReceived += Application_logMessageReceived;
} }
private void Application_logMessageReceived(string condition, string stackTrace, LogType type) private void Application_logMessageReceived(string condition, string stackTrace, LogType type)

View File

@ -163,6 +163,8 @@
<Compile Include="Player\Events\ServerSendPlayerStatesEvent.cs" /> <Compile Include="Player\Events\ServerSendPlayerStatesEvent.cs" />
<Compile Include="Player\PlayerSyncObject.cs" /> <Compile Include="Player\PlayerSyncObject.cs" />
<Compile Include="QSBInputManager.cs" /> <Compile Include="QSBInputManager.cs" />
<Compile Include="QSBNetworkBehaviour.cs" />
<Compile Include="QSBNetworkIdentity.cs" />
<Compile Include="QSBNetworkLobby.cs" /> <Compile Include="QSBNetworkLobby.cs" />
<Compile Include="Patches\QSBPatch.cs" /> <Compile Include="Patches\QSBPatch.cs" />
<Compile Include="Patches\QSBPatchTypes.cs" /> <Compile Include="Patches\QSBPatchTypes.cs" />

612
QSB/QSBNetworkBehaviour.cs Normal file
View File

@ -0,0 +1,612 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.Sockets;
using UnityEngine;
using UnityEngine.Networking;
namespace QSB
{
public class QSBNetworkBehaviour : MonoBehaviour
{
public bool LocalPlayerAuthority => MyView.LocalPlayerAuthority;
public bool IsServer => MyView.IsServer;
public bool IsClient => MyView.IsClient;
public bool IsLocalPlayer => MyView.IsLocalPlayer;
public bool HasAuthority => MyView.HasAuthority;
public NetworkInstanceId NetId => MyView.NetId;
public NetworkConnection ConnectionToServer => MyView.ConnectionToServer;
public NetworkConnection ConnectionToClient => MyView.ConnectionToClient;
public short PlayerControllerId => MyView.PlayerControllerId;
protected uint SyncVarDirtyBits { get; private set; }
protected bool SyncVarHookGuard { get; set; }
internal QSBNetworkIdentity NetIdentity => MyView;
private QSBNetworkIdentity MyView
{
get
{
QSBNetworkIdentity myView;
if (m_MyView == null)
{
m_MyView = GetComponent<QSBNetworkIdentity>();
if (m_MyView == null)
{
Debug.LogError("There is no NetworkIdentity on this object. Please add one.");
}
myView = m_MyView;
}
else
{
myView = m_MyView;
}
return myView;
}
}
protected void SendCommandInternal(NetworkWriter writer, int channelId, string cmdName)
{
if (!IsLocalPlayer && !HasAuthority)
{
Debug.LogWarning("Trying to send command for object without authority.");
}
else if (ClientScene.readyConnection == null)
{
Debug.LogError("Send command attempted with no client running [client=" + ConnectionToServer + "].");
}
else
{
writer.FinishMessage();
ClientScene.readyConnection.SendWriter(writer, channelId);
}
}
public virtual bool InvokeCommand(int cmdHash, NetworkReader reader) => InvokeCommandDelegate(cmdHash, reader);
protected void SendRPCInternal(NetworkWriter writer, int channelId, string rpcName)
{
if (!IsServer)
{
if (LogFilter.logWarn)
{
Debug.LogWarning("ClientRpc call on un-spawned object");
}
}
else
{
writer.FinishMessage();
NetworkServer.SendWriterToReady(base.gameObject, writer, channelId);
}
}
protected void SendTargetRPCInternal(NetworkConnection conn, NetworkWriter writer, int channelId, string rpcName)
{
if (!IsServer)
{
Debug.LogWarning("TargetRpc call on un-spawned object");
}
else
{
writer.FinishMessage();
conn.SendWriter(writer, channelId);
}
}
public virtual bool InvokeRPC(int cmdHash, NetworkReader reader) => InvokeRpcDelegate(cmdHash, reader);
protected void SendEventInternal(NetworkWriter writer, int channelId, string eventName)
{
if (!NetworkServer.active)
{
Debug.LogWarning("SendEvent no server?");
}
else
{
writer.FinishMessage();
NetworkServer.SendWriterToReady(gameObject, writer, channelId);
}
}
public virtual bool InvokeSyncEvent(int cmdHash, NetworkReader reader) => InvokeSyncEventDelegate(cmdHash, reader);
public virtual bool InvokeSyncList(int cmdHash, NetworkReader reader) => InvokeSyncListDelegate(cmdHash, reader);
protected static void RegisterCommandDelegate(Type invokeClass, int cmdHash, CmdDelegate func)
{
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
var invoker = new Invoker
{
invokeType = UNetInvokeType.Command,
invokeClass = invokeClass,
invokeFunction = func
};
s_CmdHandlerDelegates[cmdHash] = invoker;
Debug.Log(string.Concat(new object[]
{
"RegisterCommandDelegate hash:",
cmdHash,
" ",
func.GetMethodName()
}));
}
}
protected static void RegisterRpcDelegate(Type invokeClass, int cmdHash, CmdDelegate func)
{
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
var invoker = new Invoker
{
invokeType = UNetInvokeType.ClientRpc,
invokeClass = invokeClass,
invokeFunction = func
};
s_CmdHandlerDelegates[cmdHash] = invoker;
Debug.Log(string.Concat(new object[]
{
"RegisterRpcDelegate hash:",
cmdHash,
" ",
func.GetMethodName()
}));
}
}
protected static void RegisterEventDelegate(Type invokeClass, int cmdHash, CmdDelegate func)
{
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
var invoker = new Invoker
{
invokeType = UNetInvokeType.SyncEvent,
invokeClass = invokeClass,
invokeFunction = func
};
s_CmdHandlerDelegates[cmdHash] = invoker;
Debug.Log(string.Concat(new object[]
{
"RegisterEventDelegate hash:",
cmdHash,
" ",
func.GetMethodName()
}));
}
}
protected static void RegisterSyncListDelegate(Type invokeClass, int cmdHash, CmdDelegate func)
{
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
var invoker = new Invoker
{
invokeType = UNetInvokeType.SyncList,
invokeClass = invokeClass,
invokeFunction = func
};
s_CmdHandlerDelegates[cmdHash] = invoker;
Debug.Log(string.Concat(new object[]
{
"RegisterSyncListDelegate hash:",
cmdHash,
" ",
func.GetMethodName()
}));
}
}
internal static string GetInvoker(int cmdHash)
{
string result;
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
result = null;
}
else
{
var invoker = s_CmdHandlerDelegates[cmdHash];
result = invoker.DebugString();
}
return result;
}
internal static bool GetInvokerForHashCommand(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
=> GetInvokerForHash(cmdHash, UNetInvokeType.Command, out invokeClass, out invokeFunction);
internal static bool GetInvokerForHashClientRpc(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
=> GetInvokerForHash(cmdHash, UNetInvokeType.ClientRpc, out invokeClass, out invokeFunction);
internal static bool GetInvokerForHashSyncList(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
=> GetInvokerForHash(cmdHash, UNetInvokeType.SyncList, out invokeClass, out invokeFunction);
internal static bool GetInvokerForHashSyncEvent(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
=> GetInvokerForHash(cmdHash, UNetInvokeType.SyncEvent, out invokeClass, out invokeFunction);
private static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Type invokeClass, out CmdDelegate invokeFunction)
{
bool result;
if (!s_CmdHandlerDelegates.TryGetValue(cmdHash, out var invoker))
{
Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found");
invokeClass = null;
invokeFunction = null;
result = false;
}
else if (invoker == null)
{
Debug.Log("GetInvokerForHash hash:" + cmdHash + " invoker null");
invokeClass = null;
invokeFunction = null;
result = false;
}
else if (invoker.invokeType != invokeType)
{
Debug.LogError("GetInvokerForHash hash:" + cmdHash + " mismatched invokeType");
invokeClass = null;
invokeFunction = null;
result = false;
}
else
{
invokeClass = invoker.invokeClass;
invokeFunction = invoker.invokeFunction;
result = true;
}
return result;
}
internal static void DumpInvokers()
{
Debug.Log("DumpInvokers size:" + s_CmdHandlerDelegates.Count);
foreach (var keyValuePair in s_CmdHandlerDelegates)
{
Debug.Log(string.Concat(new object[]
{
" Invoker:",
keyValuePair.Value.invokeClass,
":",
keyValuePair.Value.invokeFunction.GetMethodName(),
" ",
keyValuePair.Value.invokeType,
" ",
keyValuePair.Key
}));
}
}
internal bool ContainsCommandDelegate(int cmdHash)
=> s_CmdHandlerDelegates.ContainsKey(cmdHash);
internal bool InvokeCommandDelegate(int cmdHash, NetworkReader reader)
{
bool result;
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
result = false;
}
else
{
var invoker = s_CmdHandlerDelegates[cmdHash];
if (invoker.invokeType != UNetInvokeType.Command)
{
result = false;
}
else
{
if (GetType() != invoker.invokeClass)
{
if (!GetType().IsSubclassOf(invoker.invokeClass))
{
return false;
}
}
invoker.invokeFunction(this, reader);
result = true;
}
}
return result;
}
internal bool InvokeRpcDelegate(int cmdHash, NetworkReader reader)
{
bool result;
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
result = false;
}
else
{
var invoker = s_CmdHandlerDelegates[cmdHash];
if (invoker.invokeType != UNetInvokeType.ClientRpc)
{
result = false;
}
else
{
if (GetType() != invoker.invokeClass)
{
if (!GetType().IsSubclassOf(invoker.invokeClass))
{
return false;
}
}
invoker.invokeFunction(this, reader);
result = true;
}
}
return result;
}
internal bool InvokeSyncEventDelegate(int cmdHash, NetworkReader reader)
{
bool result;
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
result = false;
}
else
{
var invoker = s_CmdHandlerDelegates[cmdHash];
if (invoker.invokeType != UNetInvokeType.SyncEvent)
{
result = false;
}
else
{
invoker.invokeFunction(this, reader);
result = true;
}
}
return result;
}
internal bool InvokeSyncListDelegate(int cmdHash, NetworkReader reader)
{
bool result;
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
result = false;
}
else
{
var invoker = s_CmdHandlerDelegates[cmdHash];
if (invoker.invokeType != UNetInvokeType.SyncList)
{
result = false;
}
else if (GetType() != invoker.invokeClass)
{
result = false;
}
else
{
invoker.invokeFunction(this, reader);
result = true;
}
}
return result;
}
internal static string GetCmdHashHandlerName(int cmdHash)
{
string result;
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
result = cmdHash.ToString();
}
else
{
var invoker = s_CmdHandlerDelegates[cmdHash];
result = invoker.invokeType + ":" + invoker.invokeFunction.GetMethodName();
}
return result;
}
private static string GetCmdHashPrefixName(int cmdHash, string prefix)
{
string result;
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
result = cmdHash.ToString();
}
else
{
var invoker = s_CmdHandlerDelegates[cmdHash];
var text = invoker.invokeFunction.GetMethodName();
var num = text.IndexOf(prefix);
if (num > -1)
{
text = text.Substring(prefix.Length);
}
result = text;
}
return result;
}
internal static string GetCmdHashCmdName(int cmdHash)
=> GetCmdHashPrefixName(cmdHash, "InvokeCmd");
internal static string GetCmdHashRpcName(int cmdHash)
=> GetCmdHashPrefixName(cmdHash, "InvokeRpc");
internal static string GetCmdHashEventName(int cmdHash)
=> GetCmdHashPrefixName(cmdHash, "InvokeSyncEvent");
internal static string GetCmdHashListName(int cmdHash)
=> GetCmdHashPrefixName(cmdHash, "InvokeSyncList");
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, uint dirtyBit, ref NetworkInstanceId netIdField)
{
if (!SyncVarHookGuard)
{
NetworkInstanceId networkInstanceId = default;
if (newGameObject != null)
{
var component = newGameObject.GetComponent<QSBNetworkIdentity>();
if (component != null)
{
networkInstanceId = component.NetId;
if (networkInstanceId.IsEmpty())
{
if (LogFilter.logWarn)
{
Debug.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?");
}
}
}
}
NetworkInstanceId networkInstanceId2 = default;
if (gameObjectField != null)
{
networkInstanceId2 = gameObjectField.GetComponent<QSBNetworkIdentity>().NetId;
}
if (networkInstanceId != networkInstanceId2)
{
Debug.Log(string.Concat(new object[]
{
"SetSyncVar GameObject ",
base.GetType().Name,
" bit [",
dirtyBit,
"] netfieldId:",
networkInstanceId2,
"->",
networkInstanceId
}));
SetDirtyBit(dirtyBit);
gameObjectField = newGameObject;
netIdField = networkInstanceId;
}
}
}
protected void SetSyncVar<T>(T value, ref T fieldValue, uint dirtyBit)
{
var flag = false;
if (value == null)
{
if (fieldValue != null)
{
flag = true;
}
}
else
{
flag = !value.Equals(fieldValue);
}
if (flag)
{
Debug.Log(string.Concat(new object[]
{
"SetSyncVar ",
GetType().Name,
" bit [",
dirtyBit,
"] ",
fieldValue,
"->",
value
}));
SetDirtyBit(dirtyBit);
fieldValue = value;
}
}
public void SetDirtyBit(uint dirtyBit) => SyncVarDirtyBits |= dirtyBit;
public void ClearAllDirtyBits()
{
m_LastSendTime = Time.time;
SyncVarDirtyBits = 0U;
}
internal int GetDirtyChannel()
{
if (Time.time - m_LastSendTime > GetNetworkSendInterval())
{
if (SyncVarDirtyBits != 0U)
{
return GetNetworkChannel();
}
}
return -1;
}
public virtual bool OnSerialize(NetworkWriter writer, bool initialState)
{
if (!initialState)
{
writer.WritePackedUInt32(0U);
}
return false;
}
public virtual void OnDeserialize(NetworkReader reader, bool initialState)
{
if (!initialState)
{
reader.ReadPackedUInt32();
}
}
public virtual void PreStartClient() { }
public virtual void OnNetworkDestroy() { }
public virtual void OnStartServer() { }
public virtual void OnStartClient() { }
public virtual void OnStartLocalPlayer() { }
public virtual void OnStartAuthority() { }
public virtual void OnStopAuthority() { }
public virtual bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initialize) => false;
public virtual void OnSetLocalVisibility(bool vis) { }
public virtual bool OnCheckObserver(NetworkConnection conn) => true;
public virtual int GetNetworkChannel() => 0;
public virtual float GetNetworkSendInterval() => 0.1f;
private float m_LastSendTime;
private QSBNetworkIdentity m_MyView;
private static readonly Dictionary<int, Invoker> s_CmdHandlerDelegates = new Dictionary<int, Invoker>();
public delegate void CmdDelegate(QSBNetworkBehaviour obj, NetworkReader reader);
protected delegate void EventDelegate(List<Delegate> targets, NetworkReader reader);
protected enum UNetInvokeType
{
Command,
ClientRpc,
SyncEvent,
SyncList
}
protected class Invoker
{
public string DebugString()
{
return string.Concat(new object[]
{
invokeType,
":",
invokeClass,
":",
invokeFunction.GetMethodName()
});
}
public UNetInvokeType invokeType;
public Type invokeClass;
public CmdDelegate invokeFunction;
}
}
internal static class DotNetCompatibility
{
internal static string GetMethodName(this Delegate func) => func.Method.Name;
internal static Type GetBaseType(this Type type) => type.BaseType;
internal static string GetErrorCode(this SocketException e) => e.ErrorCode.ToString();
}
}

1002
QSB/QSBNetworkIdentity.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -46,24 +46,29 @@ namespace QSB
_assetBundle = QSB.NetworkAssetBundle; _assetBundle = QSB.NetworkAssetBundle;
playerPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab"); playerPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
playerPrefab.AddComponent<QSBNetworkIdentity>();
playerPrefab.AddComponent<PlayerTransformSync>(); playerPrefab.AddComponent<PlayerTransformSync>();
playerPrefab.AddComponent<AnimationSync>(); playerPrefab.AddComponent<AnimationSync>();
playerPrefab.AddComponent<WakeUpSync>(); playerPrefab.AddComponent<WakeUpSync>();
playerPrefab.AddComponent<InstrumentsManager>(); playerPrefab.AddComponent<InstrumentsManager>();
_shipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab"); _shipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab");
_shipPrefab.AddComponent<QSBNetworkIdentity>();
_shipPrefab.AddComponent<ShipTransformSync>(); _shipPrefab.AddComponent<ShipTransformSync>();
spawnPrefabs.Add(_shipPrefab); spawnPrefabs.Add(_shipPrefab);
_cameraPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkcameraroot.prefab"); _cameraPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkcameraroot.prefab");
_cameraPrefab.AddComponent<QSBNetworkIdentity>();
_cameraPrefab.AddComponent<PlayerCameraSync>(); _cameraPrefab.AddComponent<PlayerCameraSync>();
spawnPrefabs.Add(_cameraPrefab); spawnPrefabs.Add(_cameraPrefab);
_probePrefab = _assetBundle.LoadAsset<GameObject>("assets/networkprobe.prefab"); _probePrefab = _assetBundle.LoadAsset<GameObject>("assets/networkprobe.prefab");
_probePrefab.AddComponent<QSBNetworkIdentity>();
_probePrefab.AddComponent<PlayerProbeSync>(); _probePrefab.AddComponent<PlayerProbeSync>();
spawnPrefabs.Add(_probePrefab); spawnPrefabs.Add(_probePrefab);
OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab"); OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab");
OrbPrefab.AddComponent<QSBNetworkIdentity>();
OrbPrefab.AddComponent<NomaiOrbTransformSync>(); OrbPrefab.AddComponent<NomaiOrbTransformSync>();
spawnPrefabs.Add(OrbPrefab); spawnPrefabs.Add(OrbPrefab);
@ -100,7 +105,7 @@ namespace QSB
public override void OnStartServer() public override void OnStartServer()
{ {
DebugLog.DebugWrite("~~ ON START SERVER ~~", MessageType.Info); DebugLog.DebugWrite("OnStartServer", MessageType.Info);
if (WorldRegistry.OrbSyncList.Count == 0 && QSBSceneManager.IsInUniverse) if (WorldRegistry.OrbSyncList.Count == 0 && QSBSceneManager.IsInUniverse)
{ {
OrbManager.Instance.QueueBuildOrbs(); OrbManager.Instance.QueueBuildOrbs();
@ -120,10 +125,9 @@ namespace QSB
public override void OnServerAddPlayer(NetworkConnection connection, short playerControllerId) // Called on the server when a client joins public override void OnServerAddPlayer(NetworkConnection connection, short playerControllerId) // Called on the server when a client joins
{ {
DebugLog.DebugWrite("[S] Add player"); DebugLog.DebugWrite("OnServerAddPlayer", MessageType.Info);
base.OnServerAddPlayer(connection, playerControllerId); base.OnServerAddPlayer(connection, playerControllerId);
// These have to be in a constant order (for now, until we get a better netId getting system...)
NetworkServer.SpawnWithClientAuthority(Instantiate(_shipPrefab), connection); NetworkServer.SpawnWithClientAuthority(Instantiate(_shipPrefab), connection);
NetworkServer.SpawnWithClientAuthority(Instantiate(_cameraPrefab), connection); NetworkServer.SpawnWithClientAuthority(Instantiate(_cameraPrefab), connection);
NetworkServer.SpawnWithClientAuthority(Instantiate(_probePrefab), connection); NetworkServer.SpawnWithClientAuthority(Instantiate(_probePrefab), connection);
@ -131,6 +135,7 @@ namespace QSB
public override void OnClientConnect(NetworkConnection connection) // Called on the client when connecting to a server public override void OnClientConnect(NetworkConnection connection) // Called on the client when connecting to a server
{ {
DebugLog.DebugWrite("OnClientConnect", MessageType.Info);
base.OnClientConnect(connection); base.OnClientConnect(connection);
gameObject.AddComponent<SectorSync.SectorSync>(); gameObject.AddComponent<SectorSync.SectorSync>();
@ -172,6 +177,7 @@ namespace QSB
public override void OnStopClient() // Called on the client when closing connection public override void OnStopClient() // Called on the client when closing connection
{ {
DebugLog.DebugWrite("OnStopClient", MessageType.Info);
DebugLog.ToConsole("Disconnecting from server...", MessageType.Info); DebugLog.ToConsole("Disconnecting from server...", MessageType.Info);
Destroy(GetComponent<SectorSync.SectorSync>()); Destroy(GetComponent<SectorSync.SectorSync>());
Destroy(GetComponent<RespawnOnDeath>()); Destroy(GetComponent<RespawnOnDeath>());
@ -197,14 +203,15 @@ namespace QSB
public override void OnServerDisconnect(NetworkConnection connection) // Called on the server when any client disconnects public override void OnServerDisconnect(NetworkConnection connection) // Called on the server when any client disconnects
{ {
DebugLog.DebugWrite("OnServerDisconnect", MessageType.Info);
var player = connection.GetPlayer(); var player = connection.GetPlayer();
var netIds = connection.clientOwnedObjects.Select(x => x.Value).ToArray(); var netIds = connection.clientOwnedObjects.Select(x => x.Value).ToArray();
GlobalMessenger<uint, uint[]>.FireEvent(EventNames.QSBPlayerLeave, player.PlayerId, netIds); GlobalMessenger<uint, uint[]>.FireEvent(EventNames.QSBPlayerLeave, player.PlayerId, netIds);
foreach (var item in WorldRegistry.OrbSyncList) foreach (var item in WorldRegistry.OrbSyncList)
{ {
var identity = item.GetComponent<NetworkIdentity>(); var identity = item.GetComponent<QSBNetworkIdentity>();
if (identity.clientAuthorityOwner == connection) if (identity.ClientAuthorityOwner == connection)
{ {
identity.RemoveClientAuthority(connection); identity.RemoveClientAuthority(connection);
} }
@ -216,6 +223,7 @@ namespace QSB
public override void OnStopServer() public override void OnStopServer()
{ {
DebugLog.DebugWrite("OnStopServer", MessageType.Info);
Destroy(GetComponent<SectorSync.SectorSync>()); Destroy(GetComponent<SectorSync.SectorSync>());
Destroy(GetComponent<RespawnOnDeath>()); Destroy(GetComponent<RespawnOnDeath>());
Destroy(GetComponent<PreventShipDestruction>()); Destroy(GetComponent<PreventShipDestruction>());
@ -246,8 +254,8 @@ namespace QSB
{ {
DebugLog.DebugWrite($"Cleaning up netId {netId}"); DebugLog.DebugWrite($"Cleaning up netId {netId}");
// Multiple networkbehaviours can use the same networkidentity (same netId), so get all of them // Multiple networkbehaviours can use the same networkidentity (same netId), so get all of them
var networkBehaviours = FindObjectsOfType<NetworkBehaviour>() var networkBehaviours = FindObjectsOfType<QSBNetworkBehaviour>()
.Where(x => x != null && x.netId.Value == netId); .Where(x => x != null && x.NetId.Value == netId);
foreach (var networkBehaviour in networkBehaviours) foreach (var networkBehaviour in networkBehaviours)
{ {
var transformSync = networkBehaviour.GetComponent<TransformSync.TransformSync>(); var transformSync = networkBehaviour.GetComponent<TransformSync.TransformSync>();
@ -256,7 +264,7 @@ namespace QSB
{ {
DebugLog.DebugWrite($" * Removing TransformSync from syncobjects"); DebugLog.DebugWrite($" * Removing TransformSync from syncobjects");
QSBPlayerManager.PlayerSyncObjects.Remove(transformSync); QSBPlayerManager.PlayerSyncObjects.Remove(transformSync);
if (transformSync.SyncedTransform != null && netId != QSBPlayerManager.LocalPlayerId && !networkBehaviour.hasAuthority) if (transformSync.SyncedTransform != null && netId != QSBPlayerManager.LocalPlayerId && !networkBehaviour.HasAuthority)
{ {
DebugLog.DebugWrite($" * Destroying {transformSync.SyncedTransform.gameObject.name}"); DebugLog.DebugWrite($" * Destroying {transformSync.SyncedTransform.gameObject.name}");
Destroy(transformSync.SyncedTransform.gameObject); Destroy(transformSync.SyncedTransform.gameObject);
@ -271,7 +279,7 @@ namespace QSB
QSBPlayerManager.PlayerSyncObjects.Remove(animationSync); QSBPlayerManager.PlayerSyncObjects.Remove(animationSync);
} }
if (!networkBehaviour.hasAuthority) if (!networkBehaviour.HasAuthority)
{ {
DebugLog.DebugWrite($" * Destroying {networkBehaviour.gameObject.name}"); DebugLog.DebugWrite($" * Destroying {networkBehaviour.gameObject.name}");
Destroy(networkBehaviour.gameObject); Destroy(networkBehaviour.gameObject);

View File

@ -21,7 +21,7 @@ namespace QSB.SectorSync
{ {
return; return;
} }
QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>().Where(x => x.hasAuthority).ToList().ForEach(CheckTransformSyncSector); QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>().Where(x => x.HasAuthority).ToList().ForEach(CheckTransformSyncSector);
_checkTimer = 0; _checkTimer = 0;
} }
@ -38,7 +38,7 @@ namespace QSB.SectorSync
return; return;
} }
transformSync.SetReferenceSector(closestSector); transformSync.SetReferenceSector(closestSector);
SendSector(transformSync.netId.Value, closestSector); SendSector(transformSync.NetId.Value, closestSector);
} }
private void SendSector(uint id, QSBSector sector) private void SendSector(uint id, QSBSector sector)

View File

@ -3,14 +3,14 @@ using UnityEngine.Networking;
namespace QSB.TimeSync namespace QSB.TimeSync
{ {
public class PreserveTimeScale : NetworkBehaviour public class PreserveTimeScale : QSBNetworkBehaviour
{ {
private void Start() private void Start()
{ {
QSB.Helper.Menus.PauseMenu.GetTitleButton("Button-EndCurrentLoop").Hide(); // Remove the meditation button QSB.Helper.Menus.PauseMenu.GetTitleButton("Button-EndCurrentLoop").Hide(); // Remove the meditation button
// Allow server to sleep at campfires // Allow server to sleep at campfires
if (isServer) if (IsServer)
{ {
return; return;
} }

View File

@ -7,7 +7,7 @@ using UnityEngine.Networking;
namespace QSB.TimeSync namespace QSB.TimeSync
{ {
public class WakeUpSync : NetworkBehaviour public class WakeUpSync : QSBNetworkBehaviour
{ {
public static WakeUpSync LocalInstance { get; private set; } public static WakeUpSync LocalInstance { get; private set; }
@ -34,7 +34,7 @@ namespace QSB.TimeSync
private void Start() private void Start()
{ {
if (!isLocalPlayer) if (!IsLocalPlayer)
{ {
return; return;
} }
@ -88,7 +88,7 @@ namespace QSB.TimeSync
GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest); GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest);
_state = State.Loaded; _state = State.Loaded;
gameObject.AddComponent<PreserveTimeScale>(); gameObject.AddComponent<PreserveTimeScale>();
if (isServer) if (IsServer)
{ {
SendServerTime(); SendServerTime();
} }
@ -187,11 +187,11 @@ namespace QSB.TimeSync
private void Update() private void Update()
{ {
if (isServer) if (IsServer)
{ {
UpdateServer(); UpdateServer();
} }
else if (isLocalPlayer) else if (IsLocalPlayer)
{ {
UpdateLocal(); UpdateLocal();
} }

View File

@ -5,7 +5,7 @@ using UnityEngine.Networking;
namespace QSB.TransformSync namespace QSB.TransformSync
{ {
public class NomaiOrbTransformSync : NetworkBehaviour public class NomaiOrbTransformSync : QSBNetworkBehaviour
{ {
public NomaiInterfaceOrb AttachedOrb { get; private set; } public NomaiInterfaceOrb AttachedOrb { get; private set; }
public Transform OrbTransform { get; private set; } public Transform OrbTransform { get; private set; }
@ -29,12 +29,12 @@ namespace QSB.TransformSync
public override void OnStartAuthority() public override void OnStartAuthority()
{ {
DebugLog.DebugWrite("START AUTHORITY - has auth? : " + hasAuthority); DebugLog.DebugWrite("START AUTHORITY - has auth? : " + HasAuthority);
} }
public override void OnStopAuthority() public override void OnStopAuthority()
{ {
DebugLog.DebugWrite("END AUTHORITY - has auth? : " + hasAuthority); DebugLog.DebugWrite("END AUTHORITY - has auth? : " + HasAuthority);
} }
private void OnReady() private void OnReady()
@ -76,7 +76,7 @@ namespace QSB.TransformSync
protected virtual void UpdateTransform() protected virtual void UpdateTransform()
{ {
if (hasAuthority) if (HasAuthority)
{ {
transform.position = _orbParent.InverseTransformPoint(OrbTransform.position); transform.position = _orbParent.InverseTransformPoint(OrbTransform.position);
transform.rotation = _orbParent.InverseTransformRotation(OrbTransform.rotation); transform.rotation = _orbParent.InverseTransformRotation(OrbTransform.rotation);

View File

@ -1,4 +1,5 @@
using QSB.EventsCore; using OWML.Common;
using QSB.EventsCore;
using QSB.Player; using QSB.Player;
using QSB.Tools; using QSB.Tools;
using QSB.Utility; using QSB.Utility;
@ -12,6 +13,7 @@ namespace QSB.TransformSync
public override void OnStartLocalPlayer() public override void OnStartLocalPlayer()
{ {
DebugLog.DebugWrite("OnStartLocalPlayer", MessageType.Info);
LocalInstance = this; LocalInstance = this;
} }
@ -43,7 +45,7 @@ namespace QSB.TransformSync
public override bool IsReady => Locator.GetPlayerTransform() != null public override bool IsReady => Locator.GetPlayerTransform() != null
&& Player != null && Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId) && QSBPlayerManager.PlayerExists(Player.PlayerId)
&& netId.Value != uint.MaxValue && NetId.Value != uint.MaxValue
&& netId.Value != 0U; && NetId.Value != 0U;
} }
} }

View File

@ -14,6 +14,7 @@ namespace QSB.TransformSync
public override void OnStartLocalPlayer() public override void OnStartLocalPlayer()
{ {
DebugLog.DebugWrite("OnStartLocalPlayer", MessageType.Info);
LocalInstance = this; LocalInstance = this;
} }
@ -78,7 +79,7 @@ namespace QSB.TransformSync
{ {
return; return;
} }
if (hasAuthority) if (HasAuthority)
{ {
transform.position = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position); transform.position = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
return; return;
@ -94,7 +95,7 @@ namespace QSB.TransformSync
&& Player != null && Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId) && QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.IsReady && Player.IsReady
&& netId.Value != uint.MaxValue && NetId.Value != uint.MaxValue
&& netId.Value != 0U; && NetId.Value != 0U;
} }
} }

View File

@ -1,6 +1,8 @@
using QSB.Animation; using OWML.Common;
using QSB.Animation;
using QSB.Instruments; using QSB.Instruments;
using QSB.Player; using QSB.Player;
using QSB.Utility;
using UnityEngine; using UnityEngine;
namespace QSB.TransformSync namespace QSB.TransformSync
@ -11,11 +13,13 @@ namespace QSB.TransformSync
static PlayerTransformSync() static PlayerTransformSync()
{ {
DebugLog.DebugWrite("Constructor", MessageType.Info);
AnimControllerPatch.Init(); AnimControllerPatch.Init();
} }
public override void OnStartLocalPlayer() public override void OnStartLocalPlayer()
{ {
DebugLog.DebugWrite("OnStartLocalPlayer", MessageType.Info);
LocalInstance = this; LocalInstance = this;
} }
@ -55,7 +59,7 @@ namespace QSB.TransformSync
&& Player != null && Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId) && QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.IsReady && Player.IsReady
&& netId.Value != uint.MaxValue && NetId.Value != uint.MaxValue
&& netId.Value != 0U; && NetId.Value != 0U;
} }
} }

View File

@ -1,4 +1,6 @@
using QSB.Player; using OWML.Common;
using QSB.Player;
using QSB.Utility;
using UnityEngine; using UnityEngine;
namespace QSB.TransformSync namespace QSB.TransformSync
@ -9,6 +11,7 @@ namespace QSB.TransformSync
public override void OnStartLocalPlayer() public override void OnStartLocalPlayer()
{ {
DebugLog.DebugWrite("OnStartLocalPlayer", MessageType.Info);
LocalInstance = this; LocalInstance = this;
} }
@ -54,7 +57,7 @@ namespace QSB.TransformSync
&& Player != null && Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId) && QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.IsReady && Player.IsReady
&& netId.Value != uint.MaxValue && NetId.Value != uint.MaxValue
&& netId.Value != 0U; && NetId.Value != 0U;
} }
} }

View File

@ -23,6 +23,7 @@ namespace QSB.TransformSync
protected virtual void Awake() protected virtual void Awake()
{ {
DebugLog.DebugWrite($"Awake of {GetType().Name}", MessageType.Info);
QSBPlayerManager.PlayerSyncObjects.Add(this); QSBPlayerManager.PlayerSyncObjects.Add(this);
DontDestroyOnLoad(gameObject); DontDestroyOnLoad(gameObject);
QSBSceneManager.OnSceneLoaded += OnSceneLoaded; QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
@ -41,7 +42,7 @@ namespace QSB.TransformSync
protected void Init() protected void Init()
{ {
DebugLog.DebugWrite($"Init of {AttachedNetId} ({Player.PlayerId}.{GetType().Name})"); DebugLog.DebugWrite($"Init of {AttachedNetId} ({Player.PlayerId}.{GetType().Name})");
SyncedTransform = hasAuthority ? InitLocalTransform() : InitRemoteTransform(); SyncedTransform = HasAuthority ? InitLocalTransform() : InitRemoteTransform();
_isInitialized = true; _isInitialized = true;
_isVisible = true; _isVisible = true;
} }
@ -74,7 +75,7 @@ namespace QSB.TransformSync
protected virtual void UpdateTransform() protected virtual void UpdateTransform()
{ {
if (hasAuthority) // If this script is attached to the client's own body on the client's side. if (HasAuthority) // If this script is attached to the client's own body on the client's side.
{ {
if (ReferenceSector == null || ReferenceSector.Sector == null) if (ReferenceSector == null || ReferenceSector.Sector == null)
{ {
@ -105,7 +106,7 @@ namespace QSB.TransformSync
DebugLog.DebugWrite($"Setting {Player.PlayerId}.{GetType().Name} to {sector.Name}", MessageType.Info); DebugLog.DebugWrite($"Setting {Player.PlayerId}.{GetType().Name} to {sector.Name}", MessageType.Info);
_positionSmoothVelocity = Vector3.zero; _positionSmoothVelocity = Vector3.zero;
ReferenceSector = sector; ReferenceSector = sector;
if (!hasAuthority) if (!HasAuthority)
{ {
SyncedTransform.SetParent(sector.Transform, true); SyncedTransform.SetParent(sector.Transform, true);
transform.position = sector.Transform.InverseTransformPoint(SyncedTransform.position); transform.position = sector.Transform.InverseTransformPoint(SyncedTransform.position);

View File

@ -10,7 +10,7 @@ namespace QSB.Utility
{ {
var go = connection.playerControllers[0].gameObject; var go = connection.playerControllers[0].gameObject;
var controller = go.GetComponent<PlayerTransformSync>(); var controller = go.GetComponent<PlayerTransformSync>();
return QSBPlayerManager.GetPlayer(controller.netId.Value); return QSBPlayerManager.GetPlayer(controller.NetId.Value);
} }
} }
} }

View File

@ -53,7 +53,7 @@ namespace QSB.WorldSync
{ {
qsbSlot = slotList.First(x => x.InterfaceSlot == slot); qsbSlot = slotList.First(x => x.InterfaceSlot == slot);
orbSync = OrbSyncList.First(x => x.AttachedOrb == affectingOrb); orbSync = OrbSyncList.First(x => x.AttachedOrb == affectingOrb);
if (orbSync.hasAuthority) if (orbSync.HasAuthority)
{ {
qsbSlot.HandleEvent(state); qsbSlot.HandleEvent(state);
} }