Skip to content

Commit

Permalink
fix: passing NetworkBehaviors in RPC works with IL2PP (#630)
Browse files Browse the repository at this point in the history
When passing a NetworkBehavior derived class as a parameter, we were generating
invalid IL.  Mono was ok with it, but it caused a problem for IL2PP

fixes #629
  • Loading branch information
paulpach committed Feb 21, 2021
1 parent 1457e57 commit 87becee
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Assets/Mirage/Weaver/Readers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,14 @@ public MethodReference GetReadFunc(TypeReference typeReference, SequencePoint se

private MethodReference GetNetworkBehaviourReader(TypeReference typeReference)
{
MethodReference readFunc = module.ImportReference<NetworkReader>((reader) => reader.ReadNetworkBehaviour());
Register(typeReference, readFunc);
return readFunc;
MethodDefinition readerFunc = GenerateReaderFunction(typeReference);
ILProcessor worker = readerFunc.Body.GetILProcessor();

worker.Append(worker.Create(OpCodes.Ldarg_0));
worker.Append(worker.Create<NetworkReader>(OpCodes.Call, (reader) => reader.ReadNetworkBehaviour()));
worker.Append(worker.Create(OpCodes.Castclass, typeReference));
worker.Append(worker.Create(OpCodes.Ret));
return readerFunc;
}

void RegisterReadFunc(TypeReference typeReference, MethodDefinition newReaderFunc)
Expand Down

0 comments on commit 87becee

Please sign in to comment.