Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,27 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass
instructions.Reverse();
instructions.ForEach(instruction => processor.Body.Instructions.Insert(0, instruction));
}

// override NetworkBehaviour.__getTypeName() method to return concrete type
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this scoped (i.e. in brackets)? Is this an ILPP thing or something else?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its just an documentation/organizational thing, since the ILPP code can be very hard to follow

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, a block with comment on top is a cool way to document what's going on in that region.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in addition to andrew and fatih's comments, the brackets are to scope the local variables since they share a name with the other scopes. reasonably these could be functions to avoid this but i didn't want to add complexity to an already huge class

var baseType = typeDefinition.BaseType.Resolve();
var baseGetTypeNameMethod = baseType.Methods.First(p => p.Name.Equals(nameof(NetworkBehaviour.__getTypeName)));

var newGetTypeNameMethod = new MethodDefinition(
nameof(NetworkBehaviour.__getTypeName),
(baseGetTypeNameMethod.Attributes & ~MethodAttributes.NewSlot) | MethodAttributes.ReuseSlot,
baseGetTypeNameMethod.ReturnType)
{
ImplAttributes = baseGetTypeNameMethod.ImplAttributes,
SemanticsAttributes = baseGetTypeNameMethod.SemanticsAttributes
};

var processor = newGetTypeNameMethod.Body.GetILProcessor();
processor.Body.Instructions.Add(processor.Create(OpCodes.Ldstr, typeDefinition.Name));
processor.Body.Instructions.Add(processor.Create(OpCodes.Ret));

typeDefinition.Methods.Add(newGetTypeNameMethod);
}
}

private CustomAttribute CheckAndGetRpcAttribute(MethodDefinition methodDefinition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ private static void SetUpdateStage<T>(ref T param) where T : IHasUpdateStage
}
}

#pragma warning disable IDE1006 // disable naming rule violation check
// NetworkBehaviourILPP will override this in derived classes to return the name of the concrete type
internal virtual string __getTypeName() => nameof(NetworkBehaviour);
#pragma warning restore IDE1006 // restore naming rule violation check

#pragma warning disable 414 // disable assigned but its value is never used
#pragma warning disable IDE1006 // disable naming rule violation check
[NonSerialized]
// RuntimeAccessModifiersILPP will make this `protected`
internal __RpcExecStage __rpc_exec_stage = __RpcExecStage.None;
#pragma warning restore 414 // restore assigned but its value is never used
#pragma warning restore IDE1006 // restore naming rule violation
#pragma warning restore IDE1006 // restore naming rule violation check

#pragma warning disable IDE1006 // disable naming rule violation check
// RuntimeAccessModifiersILPP will make this `protected`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public void AccessNetworkObjectTest()
Object.DestroyImmediate(gameObject);
}

[Test]
public void GetNetworkBehaviourNameTest()
{
var gameObject = new GameObject(nameof(GetNetworkBehaviourNameTest));
var networkBehaviour = gameObject.AddComponent<EmptyNetworkBehaviour>();

Assert.AreEqual(nameof(EmptyNetworkBehaviour), networkBehaviour.__getTypeName());
}

public class EmptyNetworkBehaviour : NetworkBehaviour
{

Expand Down