Skip to content

Commit

Permalink
merging develop into release/1.5.2 (#2634)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadauxCat authored Jul 21, 2023
1 parent dfe7138 commit 3394881
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 21 deletions.
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Instruction>();
var processor = staticCtorMethodDef.Body.GetILProcessor();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
}

Expand All @@ -130,6 +138,11 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition)
{
methodDefinition.IsFamily = true;
}

if (methodDefinition.Name == nameof(NetworkBehaviour.__getTypeName))
{
methodDefinition.IsFamilyOrAssembly = true;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 0 additions & 2 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -1211,7 +1210,6 @@ internal NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index)
}
NetworkLog.LogInfo(currentKnownChildren.ToString());
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public void Serialize(FastBufferWriter writer, int targetVersion)
{
networkVariable.WriteDelta(writer);
}

NetworkBehaviour.NetworkManager.NetworkMetrics.TrackNetworkVariableDeltaSent(
TargetClientId,
NetworkBehaviour.NetworkObject,
Expand Down Expand Up @@ -207,7 +206,6 @@ public void Handle(ref NetworkContext context)
networkBehaviour.__getTypeName(),
context.MessageSize);


if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety)
{
if (m_ReceivedNetworkVariableData.Position > (readStartPos + varSize))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions com.unity.netcode.gameobjects/ValidationExceptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ErrorExceptions": [
{
"ValidationTest": "API Validation",
"ExceptionMessage": "Additions require a new minor or major version.",
"PackageVersion": "1.5.2"
}
],
"WarningExceptions": []
}
7 changes: 7 additions & 0 deletions com.unity.netcode.gameobjects/ValidationExceptions.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3394881

Please sign in to comment.