Skip to content

fix: unique handlers per rpc method #1694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
75a8e33
Squashed commit of the following:
NoelStephensUnity Feb 4, 2022
5c040a6
fix and merge updates
NoelStephensUnity Feb 4, 2022
5bffb1c
update
NoelStephensUnity Feb 4, 2022
06f518c
test fix
NoelStephensUnity Feb 4, 2022
dce9e98
test fix
NoelStephensUnity Feb 4, 2022
22a9588
refactor
NoelStephensUnity Feb 4, 2022
356b1b8
temp backport of #1638
NoelStephensUnity Feb 5, 2022
10ea0e6
test backport temp
NoelStephensUnity Feb 5, 2022
b6d44ec
test full backport of TransportTests
NoelStephensUnity Feb 5, 2022
707307e
Squashed commit of the following:
NoelStephensUnity Feb 5, 2022
b2aac00
fix
NoelStephensUnity Feb 5, 2022
e7a1317
fix
NoelStephensUnity Feb 5, 2022
34bda56
Merge branch 'fix/testproject-runtimetests-not-passing-on-all-console…
NoelStephensUnity Feb 5, 2022
11d4d6c
fix
NoelStephensUnity Feb 5, 2022
80fc011
fix
NoelStephensUnity Feb 5, 2022
b06cc5c
style
NoelStephensUnity Feb 5, 2022
91f368c
refactor
NoelStephensUnity Feb 7, 2022
900e96b
update and style
NoelStephensUnity Feb 7, 2022
cd31bc8
update
NoelStephensUnity Feb 7, 2022
c8c2730
Merge branch 'fix/runtime-tests-not-passing-on-all-console-platforms-…
NoelStephensUnity Feb 7, 2022
87d1bb8
test
NoelStephensUnity Feb 8, 2022
4937a7c
Merge branch 'develop' into test/rpc-hash-collisions-on-consoles-v1.1.0
0xFA11 Feb 14, 2022
27afb31
print `sigStr`
0xFA11 Feb 14, 2022
2ad0508
print `sigHash`
0xFA11 Feb 14, 2022
75f3713
revert `CodeGenHelpers.cs`
0xFA11 Feb 14, 2022
39af58e
unique handlers per rpc method
0xFA11 Feb 14, 2022
fbfe35b
update changelog
0xFA11 Feb 14, 2022
d66a712
Update CHANGELOG.md
0xFA11 Feb 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).

## [Unreleased]

### Added

### Changed

### Fixed
- Fixed: Issue where Alpha release versions of Unity (version 20202.2.0a5 and later) will not compile due to the UNet Transport no longer existing (#1678)

- Fixed an issue where Alpha release versions of Unity (version 20202.2.0a5 and later) will not compile due to the UNet Transport no longer existing (#1678)
- Fixed overloading RPC methods causing collisions and failing on IL2CPP targets. (#1694)

## [1.0.0-pre.5] - 2022-01-26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass

InjectWriteAndCallBlocks(methodDefinition, rpcAttribute, rpcMethodId);

rpcHandlers.Add((rpcMethodId, GenerateStaticHandler(methodDefinition, rpcAttribute)));
rpcHandlers.Add((rpcMethodId, GenerateStaticHandler(methodDefinition, rpcAttribute, rpcMethodId)));

if (isEditorOrDevelopment)
{
Expand Down Expand Up @@ -1132,18 +1132,18 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
instructions.ForEach(instruction => processor.Body.Instructions.Insert(0, instruction));
}

private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition, CustomAttribute rpcAttribute)
private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition, CustomAttribute rpcAttribute, uint rpcMethodId)
{
var typeSystem = methodDefinition.Module.TypeSystem;
var nhandler = new MethodDefinition(
$"{methodDefinition.Name}__nhandler",
var rpcHandler = new MethodDefinition(
$"__rpc_handler_{rpcMethodId}",
MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.HideBySig,
methodDefinition.Module.TypeSystem.Void);
nhandler.Parameters.Add(new ParameterDefinition("target", ParameterAttributes.None, m_NetworkBehaviour_TypeRef));
nhandler.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, m_FastBufferReader_TypeRef));
nhandler.Parameters.Add(new ParameterDefinition("rpcParams", ParameterAttributes.None, m_RpcParams_TypeRef));
rpcHandler.Parameters.Add(new ParameterDefinition("target", ParameterAttributes.None, m_NetworkBehaviour_TypeRef));
rpcHandler.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, m_FastBufferReader_TypeRef));
rpcHandler.Parameters.Add(new ParameterDefinition("rpcParams", ParameterAttributes.None, m_RpcParams_TypeRef));

var processor = nhandler.Body.GetILProcessor();
var processor = rpcHandler.Body.GetILProcessor();

// begin Try/Catch
var tryStart = processor.Create(OpCodes.Nop);
Expand All @@ -1161,10 +1161,10 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
}
}

nhandler.Body.InitLocals = true;
rpcHandler.Body.InitLocals = true;
// NetworkManager networkManager;
nhandler.Body.Variables.Add(new VariableDefinition(m_NetworkManager_TypeRef));
int netManLocIdx = nhandler.Body.Variables.Count - 1;
rpcHandler.Body.Variables.Add(new VariableDefinition(m_NetworkManager_TypeRef));
int netManLocIdx = rpcHandler.Body.Variables.Count - 1;

{
var returnInstr = processor.Create(OpCodes.Ret);
Expand Down Expand Up @@ -1233,8 +1233,8 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
var paramType = paramDef.ParameterType;

// local variable
nhandler.Body.Variables.Add(new VariableDefinition(paramType));
int localIndex = nhandler.Body.Variables.Count - 1;
rpcHandler.Body.Variables.Add(new VariableDefinition(paramType));
int localIndex = rpcHandler.Body.Variables.Count - 1;
paramLocalMap[paramIndex] = localIndex;

// ServerRpcParams, ClientRpcParams
Expand Down Expand Up @@ -1268,8 +1268,8 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
}

// reader.ReadValueSafe(out bool isSet)
nhandler.Body.Variables.Add(new VariableDefinition(typeSystem.Boolean));
int isSetLocalIndex = nhandler.Body.Variables.Count - 1;
rpcHandler.Body.Variables.Add(new VariableDefinition(typeSystem.Boolean));
int isSetLocalIndex = rpcHandler.Body.Variables.Count - 1;
processor.Emit(OpCodes.Ldarga, 1);
processor.Emit(OpCodes.Ldloca, isSetLocalIndex);
processor.Emit(OpCodes.Call, boolMethodRef);
Expand Down Expand Up @@ -1345,8 +1345,8 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
// Get String.Format (This is equivalent to an interpolated string)
var stringFormat = m_MainModule.ImportReference(typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) }));

nhandler.Body.Variables.Add(new VariableDefinition(exception));
int exceptionVariableIndex = nhandler.Body.Variables.Count - 1;
rpcHandler.Body.Variables.Add(new VariableDefinition(exception));
int exceptionVariableIndex = rpcHandler.Body.Variables.Count - 1;

//try ends/catch begins
var catchEnds = processor.Create(OpCodes.Nop);
Expand Down Expand Up @@ -1384,7 +1384,7 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition

processor.Emit(OpCodes.Ret);

return nhandler;
return rpcHandler;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ private void Update()
}
m_GlobalCounter++;
OnSendGlobalCounterClientRpc(m_GlobalCounter);
OnSendGlobalCounterClientRpc((float)m_GlobalCounter);
m_RpcMessagesSent++;
}

Expand Down Expand Up @@ -704,6 +705,21 @@ private void OnSendGlobalCounterClientRpc(int counter)
}
}

/// <summary>
/// [Tests] Server to Clients
/// [Tests] broadcasting to all clients (similar to unified direct without specifying all client ids)
/// </summary>
/// <param name="counter">the global counter value</param>
[ClientRpc]
private void OnSendGlobalCounterClientRpc(float counter)
{
m_GlobalCounter = (int)counter;
if (m_GlobalCounterOffset == 0)
{
m_GlobalCounterOffset = Mathf.Max(m_GlobalCounter - 1, 0);
}
}

/// <summary>
/// Server to Client
/// Handles setting the m_GlobalDirectCounter for the client in questions
Expand Down