more stuff and fixes

This commit is contained in:
Mister_Nebula 2020-12-02 20:43:16 +00:00
parent c293fd53c5
commit d9e6b5c8c9
5 changed files with 39 additions and 83 deletions

View File

@ -581,7 +581,7 @@ namespace QSB
{
Debug.LogError(string.Concat(new object[]
{
"Failed to spawn server object, did you forget to add it to the NetworkManager? assetId=",
"Failed to spawn server object, did you forget to add it to the QSBNetworkManager? assetId=",
s_ObjectSpawnMessage.assetId,
" netId=",
s_ObjectSpawnMessage.netId

View File

@ -108,7 +108,6 @@ namespace QSB
}
else
{
DebugLog.DebugWrite("try replace");
s_InternalMessage.reader.GetType().GetMethod("Replace", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public).Invoke(s_InternalMessage.reader, new object[] { t.buffer });
}
s_InternalMessage.reader.ReadInt16();

View File

@ -50,6 +50,8 @@ namespace QSB
playerPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
var ident = playerPrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", playerPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", playerPrefab.GetComponent<NetworkIdentity>().sceneId);
playerPrefab.AddComponent<PlayerTransformSync>();
playerPrefab.AddComponent<AnimationSync>();
playerPrefab.AddComponent<WakeUpSync>();
@ -59,6 +61,8 @@ namespace QSB
_shipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab");
ident = _shipPrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", _shipPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", _shipPrefab.GetComponent<NetworkIdentity>().sceneId);
_shipPrefab.AddComponent<ShipTransformSync>();
spawnPrefabs.Add(_shipPrefab);
@ -66,6 +70,8 @@ namespace QSB
_cameraPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkcameraroot.prefab");
ident = _cameraPrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", _cameraPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", _cameraPrefab.GetComponent<NetworkIdentity>().sceneId);
_cameraPrefab.AddComponent<PlayerCameraSync>();
spawnPrefabs.Add(_cameraPrefab);
@ -73,6 +79,8 @@ namespace QSB
_probePrefab = _assetBundle.LoadAsset<GameObject>("assets/networkprobe.prefab");
ident = _probePrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId",_probePrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", _probePrefab.GetComponent<NetworkIdentity>().sceneId);
_probePrefab.AddComponent<PlayerProbeSync>();
spawnPrefabs.Add(_probePrefab);
@ -80,6 +88,8 @@ namespace QSB
OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab");
ident = OrbPrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", OrbPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", OrbPrefab.GetComponent<NetworkIdentity>().sceneId);
OrbPrefab.AddComponent<NomaiOrbTransformSync>();
spawnPrefabs.Add(OrbPrefab);

View File

@ -623,14 +623,14 @@ namespace QSB
client.RegisterHandler(39, new QSBNetworkMessageDelegate(OnClientSceneInternal));
if (m_PlayerPrefab != null)
{
ClientScene.RegisterPrefab(m_PlayerPrefab);
QSBClientScene.RegisterPrefab(m_PlayerPrefab);
}
for (int i = 0; i < m_SpawnPrefabs.Count; i++)
{
GameObject gameObject = m_SpawnPrefabs[i];
if (gameObject != null)
{
ClientScene.RegisterPrefab(gameObject);
QSBClientScene.RegisterPrefab(gameObject);
}
}
}
@ -988,10 +988,7 @@ namespace QSB
{
if (s_LoadingSceneAsync.isDone)
{
if (LogFilter.logDebug)
{
Debug.Log("ClientChangeScene done readyCon:" + s_ClientReadyConnection);
}
DebugLog.DebugWrite("ClientChangeScene done readyCon:" + s_ClientReadyConnection);
singleton.FinishLoadScene();
s_LoadingSceneAsync.allowSceneActivation = true;
s_LoadingSceneAsync = null;

View File

@ -10,7 +10,7 @@ namespace QSB
{
class QSBNetworkScene
{
internal Dictionary<NetworkInstanceId, QSBNetworkIdentity> localObjects { get; } = new Dictionary<NetworkInstanceId, QSBNetworkIdentity>();
private Dictionary<NetworkInstanceId, QSBNetworkIdentity> m_LocalObjects = new Dictionary<NetworkInstanceId, QSBNetworkIdentity>();
internal static Dictionary<NetworkHash128, GameObject> guidToPrefab { get; } = new Dictionary<NetworkHash128, GameObject>();
@ -18,6 +18,14 @@ namespace QSB
internal static Dictionary<NetworkHash128, UnSpawnDelegate> unspawnHandlers { get; } = new Dictionary<NetworkHash128, UnSpawnDelegate>();
internal Dictionary<NetworkInstanceId, QSBNetworkIdentity> localObjects
{
get
{
return this.m_LocalObjects;
}
}
internal void Shutdown()
{
this.ClearLocalObjects();
@ -26,13 +34,6 @@ namespace QSB
internal void SetLocalObject(NetworkInstanceId netId, GameObject obj, bool isClient, bool isServer)
{
Debug.Log(string.Concat(new object[]
{
"SetLocalObject ",
netId,
" ",
obj
}));
if (obj == null)
{
this.localObjects[netId] = null;
@ -46,6 +47,7 @@ namespace QSB
}
if (networkIdentity == null)
{
DebugLog.DebugWrite($"Adding {netId} to local objects.");
networkIdentity = obj.GetComponent<QSBNetworkIdentity>();
this.localObjects[netId] = networkIdentity;
}
@ -69,9 +71,9 @@ namespace QSB
internal bool GetNetworkIdentity(NetworkInstanceId netId, out QSBNetworkIdentity uv)
{
bool result;
if (this.localObjects.ContainsKey(netId) && this.localObjects[netId] != null)
if (localObjects.ContainsKey(netId) && localObjects[netId] != null)
{
uv = this.localObjects[netId];
uv = localObjects[netId];
result = true;
}
else
@ -84,7 +86,7 @@ namespace QSB
internal bool RemoveLocalObject(NetworkInstanceId netId)
{
return this.localObjects.Remove(netId);
return localObjects.Remove(netId);
}
internal bool RemoveLocalObjectAndDestroy(NetworkInstanceId netId)
@ -114,13 +116,6 @@ namespace QSB
if (component)
{
component.SetDynamicAssetId(newAssetId);
DebugLog.DebugWrite(string.Concat(new object[]
{
"Registering prefab '",
prefab.name,
"' as asset:",
component.AssetId
}));
guidToPrefab[component.AssetId] = prefab;
}
else if (LogFilter.logError)
@ -131,20 +126,10 @@ namespace QSB
internal static void RegisterPrefab(GameObject prefab)
{
NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
QSBNetworkIdentity component = prefab.GetComponent<QSBNetworkIdentity>();
if (component)
{
if (LogFilter.logDebug)
{
Debug.Log(string.Concat(new object[]
{
"Registering prefab '",
prefab.name,
"' as asset:",
component.assetId
}));
}
guidToPrefab[component.assetId] = prefab;
guidToPrefab[component.AssetId] = prefab;
NetworkIdentity[] componentsInChildren = prefab.GetComponentsInChildren<NetworkIdentity>();
if (componentsInChildren.Length > 1)
{
@ -205,18 +190,6 @@ namespace QSB
}
else
{
if (LogFilter.logDebug)
{
Debug.Log(string.Concat(new object[]
{
"RegisterSpawnHandler asset '",
assetId,
"' ",
spawnHandler.GetMethodName(),
"/",
unspawnHandler.GetMethodName()
}));
}
spawnHandlers[assetId] = spawnHandler;
unspawnHandlers[assetId] = unspawnHandler;
}
@ -224,7 +197,7 @@ namespace QSB
internal static void UnregisterPrefab(GameObject prefab)
{
NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
QSBNetworkIdentity component = prefab.GetComponent<QSBNetworkIdentity>();
if (component == null)
{
if (LogFilter.logError)
@ -234,53 +207,30 @@ namespace QSB
}
else
{
spawnHandlers.Remove(component.assetId);
unspawnHandlers.Remove(component.assetId);
spawnHandlers.Remove(component.AssetId);
unspawnHandlers.Remove(component.AssetId);
}
}
internal static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
QSBNetworkIdentity component = prefab.GetComponent<QSBNetworkIdentity>();
if (component == null)
{
if (LogFilter.logError)
{
Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component");
}
Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component");
}
else if (spawnHandler == null || unspawnHandler == null)
{
if (LogFilter.logError)
{
Debug.LogError("RegisterPrefab custom spawn function null for " + component.assetId);
}
Debug.LogError("RegisterPrefab custom spawn function null for " + component.AssetId);
}
else if (!component.assetId.IsValid())
else if (!component.AssetId.IsValid())
{
if (LogFilter.logError)
{
Debug.LogError("RegisterPrefab game object " + prefab.name + " has no prefab. Use RegisterSpawnHandler() instead?");
}
Debug.LogError("RegisterPrefab game object " + prefab.name + " has no prefab. Use RegisterSpawnHandler() instead?");
}
else
{
if (LogFilter.logDebug)
{
Debug.Log(string.Concat(new object[]
{
"Registering custom prefab '",
prefab.name,
"' as asset:",
component.assetId,
" ",
spawnHandler.GetMethodName(),
"/",
unspawnHandler.GetMethodName()
}));
}
spawnHandlers[component.assetId] = spawnHandler;
unspawnHandlers[component.assetId] = unspawnHandler;
spawnHandlers[component.AssetId] = spawnHandler;
unspawnHandlers[component.AssetId] = unspawnHandler;
}
}