205 lines
6.4 KiB
C#
205 lines
6.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using FishNet.Connection;
|
|
using FishNet.Managing;
|
|
using FishNet.Object;
|
|
using FishNet.Object.Synchronizing;
|
|
using FishNet.Serializing;
|
|
using FishNet.Transporting;
|
|
using Heathen.SteamworksIntegration;
|
|
using UnityEngine;
|
|
|
|
public class FishNetSpawnerProxy : NetworkBehaviour
|
|
{
|
|
[SerializeField]
|
|
private ScriptableEventNetworkObjectSpawn OnNetworkObjectSpawn;
|
|
|
|
[SerializeField]
|
|
private List<NetworkObject> spawnableObjects;
|
|
|
|
[SerializeField]
|
|
private PlayerProfile PlayerProfile;
|
|
|
|
public readonly SyncVar<ulong> steamID = new SyncVar<ulong>(0uL);
|
|
|
|
public readonly SyncVar<string> profileName = new SyncVar<string>();
|
|
|
|
private bool NetworkInitialize___EarlyFishNetSpawnerProxyAssembly_002DCSharp_002Edll_Excuted;
|
|
|
|
private bool NetworkInitialize___LateFishNetSpawnerProxyAssembly_002DCSharp_002Edll_Excuted;
|
|
|
|
public bool ClientStarted { get; private set; }
|
|
|
|
public ulong SteamID => steamID.Value;
|
|
|
|
public string ProfileName => profileName.Value;
|
|
|
|
public override void OnStartClient()
|
|
{
|
|
base.OnStartClient();
|
|
if (base.IsOwner)
|
|
{
|
|
OnNetworkObjectSpawn.OnRaised += OnNetworkObjectSpawn_OnRaised;
|
|
if (SteamSettings.Initialized)
|
|
{
|
|
_ = UserData.Me;
|
|
UpdateSyncVars(UserData.Me.id.m_SteamID, PlayerProfile.Name);
|
|
}
|
|
base.LocalConnection.SetFirstObject(base.NetworkObject);
|
|
ClientStarted = true;
|
|
}
|
|
}
|
|
|
|
public override void OnStopClient()
|
|
{
|
|
base.OnStopClient();
|
|
if (base.IsOwner)
|
|
{
|
|
OnNetworkObjectSpawn.OnRaised -= OnNetworkObjectSpawn_OnRaised;
|
|
}
|
|
}
|
|
|
|
private void OnNetworkObjectSpawn_OnRaised(NetworkObjectSpawn networkObjectSpawn)
|
|
{
|
|
if (base.IsOwner)
|
|
{
|
|
Debug.Log("(FishNetSpawnerProxy) Sending RPC to spawn: " + networkObjectSpawn.name);
|
|
Spawn(networkObjectSpawn.name, networkObjectSpawn.position, networkObjectSpawn.rotation);
|
|
}
|
|
}
|
|
|
|
[ServerRpc]
|
|
private void Spawn(string name, Vector3 position, Quaternion rotation, NetworkConnection callingClientConnetion = null)
|
|
{
|
|
RpcWriter___Server_Spawn_2178936640(name, position, rotation, callingClientConnetion);
|
|
}
|
|
|
|
[ServerRpc]
|
|
private void UpdateSyncVars(ulong steamID, string profileName)
|
|
{
|
|
RpcWriter___Server_UpdateSyncVars_3264264606(steamID, profileName);
|
|
}
|
|
|
|
public override void NetworkInitialize___Early()
|
|
{
|
|
if (!NetworkInitialize___EarlyFishNetSpawnerProxyAssembly_002DCSharp_002Edll_Excuted)
|
|
{
|
|
NetworkInitialize___EarlyFishNetSpawnerProxyAssembly_002DCSharp_002Edll_Excuted = true;
|
|
base.NetworkInitialize___Early();
|
|
profileName.InitializeEarly(this, 1u, isSyncObject: false);
|
|
steamID.InitializeEarly(this, 0u, isSyncObject: false);
|
|
RegisterServerRpc(0u, RpcReader___Server_Spawn_2178936640);
|
|
RegisterServerRpc(1u, RpcReader___Server_UpdateSyncVars_3264264606);
|
|
}
|
|
}
|
|
|
|
public override void NetworkInitialize___Late()
|
|
{
|
|
if (!NetworkInitialize___LateFishNetSpawnerProxyAssembly_002DCSharp_002Edll_Excuted)
|
|
{
|
|
NetworkInitialize___LateFishNetSpawnerProxyAssembly_002DCSharp_002Edll_Excuted = true;
|
|
base.NetworkInitialize___Late();
|
|
profileName.InitializeLate();
|
|
steamID.InitializeLate();
|
|
}
|
|
}
|
|
|
|
public override void NetworkInitializeIfDisabled()
|
|
{
|
|
NetworkInitialize___Early();
|
|
NetworkInitialize___Late();
|
|
}
|
|
|
|
private void RpcWriter___Server_Spawn_2178936640(string name, Vector3 position, Quaternion rotation, NetworkConnection callingClientConnetion = null)
|
|
{
|
|
if (!base.IsClientInitialized)
|
|
{
|
|
NetworkManager networkManager = base.NetworkManager;
|
|
networkManager.LogWarning("Cannot complete action because client is not active. This may also occur if the object is not yet initialized, has deinitialized, or if it does not contain a NetworkObject component.");
|
|
return;
|
|
}
|
|
if (!base.IsOwner)
|
|
{
|
|
NetworkManager networkManager2 = base.NetworkManager;
|
|
networkManager2.LogWarning("Cannot complete action because you are not the owner of this object. .");
|
|
return;
|
|
}
|
|
Channel channel = Channel.Reliable;
|
|
PooledWriter pooledWriter = WriterPool.Retrieve();
|
|
pooledWriter.WriteString(name);
|
|
pooledWriter.WriteVector3(position);
|
|
pooledWriter.WriteQuaternion32(rotation);
|
|
SendServerRpc(0u, pooledWriter, channel, DataOrderType.Default);
|
|
pooledWriter.Store();
|
|
}
|
|
|
|
private void RpcLogic___Spawn_2178936640(string P_0, Vector3 P_1, Quaternion P_2, NetworkConnection P_3)
|
|
{
|
|
NetworkObject networkObject = spawnableObjects.FirstOrDefault((NetworkObject element) => element.name == P_0);
|
|
if (networkObject != null)
|
|
{
|
|
NetworkObject nob = Object.Instantiate(networkObject, P_1, P_2);
|
|
Spawn(nob, P_3);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("(FishNetSpawnerProxy) Cannot spawn prefab because it's not in (spawnableObjects) list: " + P_0);
|
|
}
|
|
}
|
|
|
|
private void RpcReader___Server_Spawn_2178936640(PooledReader PooledReader0, Channel channel, NetworkConnection conn)
|
|
{
|
|
string text = PooledReader0.ReadStringAllocated();
|
|
Vector3 vector = PooledReader0.ReadVector3();
|
|
Quaternion quaternion = PooledReader0.ReadQuaternion32();
|
|
if (base.IsServerInitialized && OwnerMatches(conn))
|
|
{
|
|
RpcLogic___Spawn_2178936640(text, vector, quaternion, conn);
|
|
}
|
|
}
|
|
|
|
private void RpcWriter___Server_UpdateSyncVars_3264264606(ulong steamID, string profileName)
|
|
{
|
|
if (!base.IsClientInitialized)
|
|
{
|
|
NetworkManager networkManager = base.NetworkManager;
|
|
networkManager.LogWarning("Cannot complete action because client is not active. This may also occur if the object is not yet initialized, has deinitialized, or if it does not contain a NetworkObject component.");
|
|
return;
|
|
}
|
|
if (!base.IsOwner)
|
|
{
|
|
NetworkManager networkManager2 = base.NetworkManager;
|
|
networkManager2.LogWarning("Cannot complete action because you are not the owner of this object. .");
|
|
return;
|
|
}
|
|
Channel channel = Channel.Reliable;
|
|
PooledWriter pooledWriter = WriterPool.Retrieve();
|
|
pooledWriter.WriteUInt64(steamID);
|
|
pooledWriter.WriteString(profileName);
|
|
SendServerRpc(1u, pooledWriter, channel, DataOrderType.Default);
|
|
pooledWriter.Store();
|
|
}
|
|
|
|
private void RpcLogic___UpdateSyncVars_3264264606(ulong P_0, string P_1)
|
|
{
|
|
steamID.Value = P_0;
|
|
profileName.Value = P_1;
|
|
}
|
|
|
|
private void RpcReader___Server_UpdateSyncVars_3264264606(PooledReader PooledReader0, Channel channel, NetworkConnection conn)
|
|
{
|
|
ulong num = PooledReader0.ReadUInt64();
|
|
string text = PooledReader0.ReadStringAllocated();
|
|
if (base.IsServerInitialized && OwnerMatches(conn))
|
|
{
|
|
RpcLogic___UpdateSyncVars_3264264606(num, text);
|
|
}
|
|
}
|
|
|
|
public virtual void Awake()
|
|
{
|
|
NetworkInitialize___Early();
|
|
NetworkInitialize___Late();
|
|
}
|
|
}
|