The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.7.0] - 2023-10-11 ### Added - exposed NetworkObject.GetNetworkBehaviourAtOrderIndex as a public API (#2724) - Added context menu tool that provides users with the ability to quickly update the GlobalObjectIdHash value for all in-scene placed prefab instances that were created prior to adding a NetworkObject component to it. (#2707) - Added methods NetworkManager.SetPeerMTU and NetworkManager.GetPeerMTU to be able to set MTU sizes per-peer (#2676) - Added `GenerateSerializationForGenericParameterAttribute`, which can be applied to user-created Network Variable types to ensure the codegen generates serialization for the generic types they wrap. (#2694) - Added `GenerateSerializationForTypeAttribute`, which can be applied to any class or method to ensure the codegen generates serialization for the specific provided type. (#2694) - Exposed `NetworkVariableSerialization<T>.Read`, `NetworkVariableSerialization<T>.Write`, `NetworkVariableSerialization<T>.AreEqual`, and `NetworkVariableSerialization<T>.Duplicate` to further support the creation of user-created network variables by allowing users to access the generated serialization methods and serialize generic types efficiently without boxing. (#2694) - Added `NetworkVariableBase.MarkNetworkBehaviourDirty` so that user-created network variable types can mark their containing `NetworkBehaviour` to be processed by the update loop. (#2694) ### Fixed - Fixed issue where the server side `NetworkSceneManager` instance was not adding the currently active scene to its list of scenes loaded. (#2723) - Generic NetworkBehaviour types no longer result in compile errors or runtime errors (#2720) - Rpcs within Generic NetworkBehaviour types can now serialize parameters of the class's generic types (but may not have generic types of their own) (#2720) - Errors are no longer thrown when entering play mode with domain reload disabled (#2720) - NetworkSpawn is now correctly called each time when entering play mode with scene reload disabled (#2720) - NetworkVariables of non-integer types will no longer break the inspector (#2714) - NetworkVariables with NonSerializedAttribute will not appear in the inspector (#2714) - Fixed issue where `UnityTransport` would attempt to establish WebSocket connections even if using UDP/DTLS Relay allocations when the build target was WebGL. This only applied to working in the editor since UDP/DTLS can't work in the browser. (#2695) - Fixed issue where a `NetworkBehaviour` component's `OnNetworkDespawn` was not being invoked on the host-server side for an in-scene placed `NetworkObject` when a scene was unloaded (during a scene transition) and the `NetworkBehaviour` component was positioned/ordered before the `NetworkObject` component. (#2685) - Fixed issue where `SpawnWithObservers` was not being honored when `NetworkConfig.EnableSceneManagement` was disabled. (#2682) - Fixed issue where `NetworkAnimator` was not internally tracking changes to layer weights which prevented proper layer weight synchronization back to the original layer weight value. (#2674) - Fixed "writing past the end of the buffer" error when calling ResetDirty() on managed network variables that are larger than 256 bytes when serialized. (#2670) - Fixed issue where generation of the `DefaultNetworkPrefabs` asset was not enabled by default. (#2662) - Fixed issue where the `GlobalObjectIdHash` value could be updated but the asset not marked as dirty. (#2662) - Fixed issue where the `GlobalObjectIdHash` value of a (network) prefab asset could be assigned an incorrect value when editing the prefab in a temporary scene. (#2662) - Fixed issue where the `GlobalObjectIdHash` value generated after creating a (network) prefab from an object constructed within the scene would not be the correct final value in a stand alone build. (#2662) ### Changed - Updated dependency on `com.unity.transport` to version 1.4.0. (#2716)
174 lines
6.8 KiB
C#
174 lines
6.8 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Mono.Cecil;
|
|
using Mono.Cecil.Cil;
|
|
using Unity.CompilationPipeline.Common.Diagnostics;
|
|
using Unity.CompilationPipeline.Common.ILPostProcessing;
|
|
using ILPPInterface = Unity.CompilationPipeline.Common.ILPostProcessing.ILPostProcessor;
|
|
|
|
namespace Unity.Netcode.Editor.CodeGen
|
|
{
|
|
internal sealed class RuntimeAccessModifiersILPP : ILPPInterface
|
|
{
|
|
public override ILPPInterface GetInstance() => this;
|
|
|
|
public override bool WillProcess(ICompiledAssembly compiledAssembly) => compiledAssembly.Name == CodeGenHelpers.RuntimeAssemblyName;
|
|
|
|
private readonly List<DiagnosticMessage> m_Diagnostics = new List<DiagnosticMessage>();
|
|
|
|
public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
|
|
{
|
|
if (!WillProcess(compiledAssembly))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
m_Diagnostics.Clear();
|
|
|
|
// read
|
|
var assemblyDefinition = CodeGenHelpers.AssemblyDefinitionFor(compiledAssembly, out var unused);
|
|
if (assemblyDefinition == null)
|
|
{
|
|
m_Diagnostics.AddError($"Cannot read Netcode Runtime assembly definition: {compiledAssembly.Name}");
|
|
return null;
|
|
}
|
|
|
|
// process
|
|
var mainModule = assemblyDefinition.MainModule;
|
|
if (mainModule != null)
|
|
{
|
|
foreach (var typeDefinition in mainModule.Types)
|
|
{
|
|
if (!typeDefinition.IsClass)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
switch (typeDefinition.Name)
|
|
{
|
|
case nameof(NetworkManager):
|
|
ProcessNetworkManager(typeDefinition, compiledAssembly.Defines);
|
|
break;
|
|
case nameof(NetworkBehaviour):
|
|
ProcessNetworkBehaviour(typeDefinition);
|
|
break;
|
|
case nameof(__RpcParams):
|
|
case nameof(RpcFallbackSerialization):
|
|
typeDefinition.IsPublic = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_Diagnostics.AddError($"Cannot get main module from Netcode Runtime assembly definition: {compiledAssembly.Name}");
|
|
}
|
|
|
|
// write
|
|
var pe = new MemoryStream();
|
|
var pdb = new MemoryStream();
|
|
|
|
var writerParameters = new WriterParameters
|
|
{
|
|
SymbolWriterProvider = new PortablePdbWriterProvider(),
|
|
SymbolStream = pdb,
|
|
WriteSymbols = true
|
|
};
|
|
|
|
assemblyDefinition.Write(pe, writerParameters);
|
|
|
|
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), m_Diagnostics);
|
|
}
|
|
|
|
// TODO: Deprecate...
|
|
// This is changing accessibility for values that are no longer used, but since our validator runs
|
|
// after ILPP and sees those values as public, they cannot be removed until a major version change.
|
|
private void ProcessNetworkManager(TypeDefinition typeDefinition, string[] assemblyDefines)
|
|
{
|
|
foreach (var fieldDefinition in typeDefinition.Fields)
|
|
{
|
|
if (fieldDefinition.Name == nameof(NetworkManager.__rpc_func_table))
|
|
{
|
|
fieldDefinition.IsPublic = true;
|
|
}
|
|
|
|
if (fieldDefinition.Name == nameof(NetworkManager.RpcReceiveHandler))
|
|
{
|
|
fieldDefinition.IsPublic = true;
|
|
}
|
|
|
|
if (fieldDefinition.Name == nameof(NetworkManager.__rpc_name_table))
|
|
{
|
|
fieldDefinition.IsPublic = true;
|
|
}
|
|
}
|
|
|
|
foreach (var nestedTypeDefinition in typeDefinition.NestedTypes)
|
|
{
|
|
if (nestedTypeDefinition.Name == nameof(NetworkManager.RpcReceiveHandler))
|
|
{
|
|
nestedTypeDefinition.IsNestedPublic = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ProcessNetworkBehaviour(TypeDefinition typeDefinition)
|
|
{
|
|
foreach (var nestedType in typeDefinition.NestedTypes)
|
|
{
|
|
if (nestedType.Name == nameof(NetworkBehaviour.__RpcExecStage))
|
|
{
|
|
nestedType.IsNestedFamily = true;
|
|
}
|
|
if (nestedType.Name == nameof(NetworkBehaviour.RpcReceiveHandler))
|
|
{
|
|
nestedType.IsNestedPublic = true;
|
|
}
|
|
}
|
|
|
|
foreach (var fieldDefinition in typeDefinition.Fields)
|
|
{
|
|
if (fieldDefinition.Name == nameof(NetworkBehaviour.__rpc_exec_stage) || fieldDefinition.Name == nameof(NetworkBehaviour.NetworkVariableFields))
|
|
{
|
|
fieldDefinition.IsFamilyOrAssembly = true;
|
|
}
|
|
if (fieldDefinition.Name == nameof(NetworkBehaviour.__rpc_func_table))
|
|
{
|
|
fieldDefinition.IsFamilyOrAssembly = true;
|
|
}
|
|
|
|
if (fieldDefinition.Name == nameof(NetworkBehaviour.RpcReceiveHandler))
|
|
{
|
|
fieldDefinition.IsFamilyOrAssembly = true;
|
|
}
|
|
|
|
if (fieldDefinition.Name == nameof(NetworkBehaviour.__rpc_name_table))
|
|
{
|
|
fieldDefinition.IsFamilyOrAssembly = true;
|
|
}
|
|
}
|
|
|
|
foreach (var methodDefinition in typeDefinition.Methods)
|
|
{
|
|
if (methodDefinition.Name == nameof(NetworkBehaviour.__beginSendServerRpc) ||
|
|
methodDefinition.Name == nameof(NetworkBehaviour.__endSendServerRpc) ||
|
|
methodDefinition.Name == nameof(NetworkBehaviour.__beginSendClientRpc) ||
|
|
methodDefinition.Name == nameof(NetworkBehaviour.__endSendClientRpc) ||
|
|
methodDefinition.Name == nameof(NetworkBehaviour.__initializeVariables) ||
|
|
methodDefinition.Name == nameof(NetworkBehaviour.__initializeRpcs) ||
|
|
methodDefinition.Name == nameof(NetworkBehaviour.__registerRpc) ||
|
|
methodDefinition.Name == nameof(NetworkBehaviour.__nameNetworkVariable) ||
|
|
methodDefinition.Name == nameof(NetworkBehaviour.__createNativeList))
|
|
{
|
|
methodDefinition.IsFamily = true;
|
|
}
|
|
|
|
if (methodDefinition.Name == nameof(NetworkBehaviour.__getTypeName))
|
|
{
|
|
methodDefinition.IsFamilyOrAssembly = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|