diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 4c160e1771..a226fda36e 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -18,6 +18,7 @@ Additional documentation and release notes are available at [Multiplayer Documen - Fixed issue where `NetworkObject.SpawnWithObservers` was not being honored for late joining clients. (#2623) - Fixed issue where invoking `NetworkManager.Shutdown` multiple times, depending upon the timing, could cause an exception. (#2622) - Fixed issue where removing ownership would not notify the server that it gained ownership. This also resolves the issue where an owner authoritative NetworkTransform would not properly initialize upon removing ownership from a remote client. (#2618) +- Fixed ILPP issues when using CoreCLR and for certain dedicated server builds. (#2614) - Fixed an ILPP compile error when creating a generic NetworkBehaviour singleton with a static T instance. (#2603) ### Changed diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs index 84133fff0d..00a9e0ac46 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs @@ -396,6 +396,8 @@ private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly) #endif private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_ManagedClassEquals_MethodRef; + private MethodReference m_RuntimeInitializeOnLoadAttribute_Ctor; + private MethodReference m_ExceptionCtorMethodReference; private MethodReference m_List_NetworkVariableBase_Add; @@ -509,6 +511,8 @@ private bool ImportReferences(ModuleDefinition moduleDefinition) } } + m_RuntimeInitializeOnLoadAttribute_Ctor = moduleDefinition.ImportReference(typeof(RuntimeInitializeOnLoadMethodAttribute).GetConstructor(new Type[] { })); + TypeDefinition networkManagerTypeDef = null; TypeDefinition networkBehaviourTypeDef = null; TypeDefinition networkVariableBaseTypeDef = null; @@ -1200,19 +1204,14 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass if (rpcHandlers.Count > 0 || rpcNames.Count > 0) { - var staticCtorMethodDef = typeDefinition.GetStaticConstructor(); - if (staticCtorMethodDef == null) - { - staticCtorMethodDef = new MethodDefinition( - ".cctor", // Static Constructor (constant-constructor) - MethodAttributes.HideBySig | - MethodAttributes.SpecialName | - MethodAttributes.RTSpecialName | + var staticCtorMethodDef = new MethodDefinition( + $"InitializeRPCS_{typeDefinition.Name}", + MethodAttributes.Assembly | MethodAttributes.Static, typeDefinition.Module.TypeSystem.Void); - staticCtorMethodDef.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); - typeDefinition.Methods.Add(staticCtorMethodDef); - } + staticCtorMethodDef.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); + staticCtorMethodDef.CustomAttributes.Add(new CustomAttribute(m_RuntimeInitializeOnLoadAttribute_Ctor)); + typeDefinition.Methods.Add(staticCtorMethodDef); var instructions = new List(); var processor = staticCtorMethodDef.Body.GetILProcessor(); @@ -1254,7 +1253,8 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass baseGetTypeNameMethod.ReturnType) { ImplAttributes = baseGetTypeNameMethod.ImplAttributes, - SemanticsAttributes = baseGetTypeNameMethod.SemanticsAttributes + SemanticsAttributes = baseGetTypeNameMethod.SemanticsAttributes, + IsFamilyOrAssembly = true }; var processor = newGetTypeNameMethod.Body.GetILProcessor(); diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs index 73166648d8..51cf65adb5 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs @@ -98,6 +98,14 @@ private void ProcessNetworkManager(TypeDefinition typeDefinition, string[] assem fieldDefinition.IsPublic = true; } } + + foreach (var nestedTypeDefinition in typeDefinition.NestedTypes) + { + if (nestedTypeDefinition.Name == nameof(NetworkManager.RpcReceiveHandler)) + { + nestedTypeDefinition.IsNestedPublic = true; + } + } } private void ProcessNetworkBehaviour(TypeDefinition typeDefinition) @@ -114,7 +122,7 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition) { if (fieldDefinition.Name == nameof(NetworkBehaviour.__rpc_exec_stage) || fieldDefinition.Name == nameof(NetworkBehaviour.NetworkVariableFields)) { - fieldDefinition.IsFamily = true; + fieldDefinition.IsFamilyOrAssembly = true; } } @@ -130,6 +138,11 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition) { methodDefinition.IsFamily = true; } + + if (methodDefinition.Name == nameof(NetworkBehaviour.__getTypeName)) + { + methodDefinition.IsFamilyOrAssembly = true; + } } } } diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs index 782ecba650..7a79babb67 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs @@ -18,8 +18,6 @@ internal enum __RpcExecStage Server = 1, Client = 2 } - - // NetworkBehaviourILPP will override this in derived classes to return the name of the concrete type internal virtual string __getTypeName() => nameof(NetworkBehaviour); @@ -98,7 +96,6 @@ internal void __endSendServerRpc(ref FastBufferWriter bufferWriter, uint rpcMeth } bufferWriter.Dispose(); - #if DEVELOPMENT_BUILD || UNITY_EDITOR if (NetworkManager.__rpc_name_table.TryGetValue(rpcMethodId, out var rpcMethodName)) { @@ -230,7 +227,6 @@ internal void __endSendClientRpc(ref FastBufferWriter bufferWriter, uint rpcMeth } bufferWriter.Dispose(); - #if DEVELOPMENT_BUILD || UNITY_EDITOR if (NetworkManager.__rpc_name_table.TryGetValue(rpcMethodId, out var rpcMethodName)) { diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs index cd98c11e20..81542e3318 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs @@ -1198,7 +1198,6 @@ internal NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index) { NetworkLog.LogError($"{nameof(NetworkBehaviour)} index {index} was out of bounds for {name}. NetworkBehaviours must be the same, and in the same order, between server and client."); } - if (NetworkLog.CurrentLogLevel <= LogLevel.Developer) { var currentKnownChildren = new System.Text.StringBuilder(); @@ -1211,7 +1210,6 @@ internal NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index) } NetworkLog.LogInfo(currentKnownChildren.ToString()); } - return null; } diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs index 68e64cde7d..99970c4467 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs @@ -105,7 +105,6 @@ public void Serialize(FastBufferWriter writer, int targetVersion) { networkVariable.WriteDelta(writer); } - NetworkBehaviour.NetworkManager.NetworkMetrics.TrackNetworkVariableDeltaSent( TargetClientId, NetworkBehaviour.NetworkObject, @@ -207,7 +206,6 @@ public void Handle(ref NetworkContext context) networkBehaviour.__getTypeName(), context.MessageSize); - if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety) { if (m_ReceivedNetworkVariableData.Position > (readStartPos + varSize)) diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/RpcMessages.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/RpcMessages.cs index 1e91b0651f..59ecb9f531 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/RpcMessages.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/RpcMessages.cs @@ -72,6 +72,14 @@ public static void Handle(ref NetworkContext context, ref RpcMetadata metadata, catch (Exception ex) { Debug.LogException(new Exception("Unhandled RPC exception!", ex)); + if (networkManager.LogLevel == LogLevel.Developer) + { + Debug.Log($"RPC Table Contents"); + foreach (var entry in NetworkManager.__rpc_func_table) + { + Debug.Log($"{entry.Key} | {entry.Value.Method.Name}"); + } + } } } } diff --git a/com.unity.netcode.gameobjects/ValidationExceptions.json b/com.unity.netcode.gameobjects/ValidationExceptions.json new file mode 100644 index 0000000000..2d816124e2 --- /dev/null +++ b/com.unity.netcode.gameobjects/ValidationExceptions.json @@ -0,0 +1,10 @@ +{ + "ErrorExceptions": [ + { + "ValidationTest": "API Validation", + "ExceptionMessage": "Additions require a new minor or major version.", + "PackageVersion": "1.5.2" + } + ], + "WarningExceptions": [] +} \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/ValidationExceptions.json.meta b/com.unity.netcode.gameobjects/ValidationExceptions.json.meta new file mode 100644 index 0000000000..3316cf20bd --- /dev/null +++ b/com.unity.netcode.gameobjects/ValidationExceptions.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2a43005be301c9043aab7034757d4868 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: