MethodProcessor: remove static Log references

This commit is contained in:
vis2k 2021-08-20 13:40:28 +08:00
parent b430e29e8b
commit f0747c5418
5 changed files with 14 additions and 14 deletions

View File

@ -29,9 +29,9 @@ and replaces the body of the original method with the send message code.
This way we do not need to modify the code anywhere else, and this works This way we do not need to modify the code anywhere else, and this works
correctly in dependent assemblies correctly in dependent assemblies
*/ */
public static MethodDefinition ProcessCommandCall(WeaverTypes weaverTypes, TypeDefinition td, MethodDefinition md, CustomAttribute commandAttr) public static MethodDefinition ProcessCommandCall(WeaverTypes weaverTypes, Logger Log, TypeDefinition td, MethodDefinition md, CustomAttribute commandAttr)
{ {
MethodDefinition cmd = MethodProcessor.SubstituteMethod(td, md); MethodDefinition cmd = MethodProcessor.SubstituteMethod(Log, td, md);
ILProcessor worker = md.Body.GetILProcessor(); ILProcessor worker = md.Body.GetILProcessor();

View File

@ -30,7 +30,7 @@ public static class MethodProcessor
// //
// the original method definition loses all code // the original method definition loses all code
// this returns the newly created method with all the user provided code // this returns the newly created method with all the user provided code
public static MethodDefinition SubstituteMethod(TypeDefinition td, MethodDefinition md) public static MethodDefinition SubstituteMethod(Logger Log, TypeDefinition td, MethodDefinition md)
{ {
string newName = RpcPrefix + md.Name; string newName = RpcPrefix + md.Name;
MethodDefinition cmd = new MethodDefinition(newName, md.Attributes, md.ReturnType); MethodDefinition cmd = new MethodDefinition(newName, md.Attributes, md.ReturnType);
@ -66,13 +66,13 @@ public static MethodDefinition SubstituteMethod(TypeDefinition td, MethodDefinit
td.Methods.Add(cmd); td.Methods.Add(cmd);
FixRemoteCallToBaseMethod(td, cmd); FixRemoteCallToBaseMethod(Log, td, cmd);
return cmd; return cmd;
} }
// Finds and fixes call to base methods within remote calls // Finds and fixes call to base methods within remote calls
//For example, changes `base.CmdDoSomething` to `base.CallCmdDoSomething` within `this.CallCmdDoSomething` //For example, changes `base.CmdDoSomething` to `base.CallCmdDoSomething` within `this.CallCmdDoSomething`
public static void FixRemoteCallToBaseMethod(TypeDefinition type, MethodDefinition method) public static void FixRemoteCallToBaseMethod(Logger Log, TypeDefinition type, MethodDefinition method)
{ {
string callName = method.Name; string callName = method.Name;
@ -95,14 +95,14 @@ public static void FixRemoteCallToBaseMethod(TypeDefinition type, MethodDefiniti
if (baseMethod == null) if (baseMethod == null)
{ {
Weaver.Log.Error($"Could not find base method for {callName}", method); Log.Error($"Could not find base method for {callName}", method);
Weaver.WeavingFailed = true; Weaver.WeavingFailed = true;
return; return;
} }
if (!baseMethod.IsVirtual) if (!baseMethod.IsVirtual)
{ {
Weaver.Log.Error($"Could not find base method that was virutal {callName}", method); Log.Error($"Could not find base method that was virutal {callName}", method);
Weaver.WeavingFailed = true; Weaver.WeavingFailed = true;
return; return;
} }

View File

@ -1117,7 +1117,7 @@ void ProcessClientRpc(HashSet<string> names, MethodDefinition md, CustomAttribut
includeOwner = includeOwner includeOwner = includeOwner
}); });
MethodDefinition rpcCallFunc = RpcProcessor.ProcessRpcCall(weaverTypes, netBehaviourSubclass, md, clientRpcAttr); MethodDefinition rpcCallFunc = RpcProcessor.ProcessRpcCall(weaverTypes, Log, netBehaviourSubclass, md, clientRpcAttr);
// need null check here because ProcessRpcCall returns null if it can't write all the args // need null check here because ProcessRpcCall returns null if it can't write all the args
if (rpcCallFunc == null) { return; } if (rpcCallFunc == null) { return; }
@ -1149,7 +1149,7 @@ void ProcessTargetRpc(HashSet<string> names, MethodDefinition md, CustomAttribut
names.Add(md.Name); names.Add(md.Name);
targetRpcs.Add(md); targetRpcs.Add(md);
MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(weaverTypes, netBehaviourSubclass, md, targetRpcAttr); MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(weaverTypes, Log, netBehaviourSubclass, md, targetRpcAttr);
MethodDefinition rpcFunc = TargetRpcProcessor.ProcessTargetRpcInvoke(weaverTypes, netBehaviourSubclass, md, rpcCallFunc); MethodDefinition rpcFunc = TargetRpcProcessor.ProcessTargetRpcInvoke(weaverTypes, netBehaviourSubclass, md, rpcCallFunc);
if (rpcFunc != null) if (rpcFunc != null)
@ -1186,7 +1186,7 @@ void ProcessCommand(HashSet<string> names, MethodDefinition md, CustomAttribute
requiresAuthority = requiresAuthority requiresAuthority = requiresAuthority
}); });
MethodDefinition cmdCallFunc = CommandProcessor.ProcessCommandCall(weaverTypes, netBehaviourSubclass, md, commandAttr); MethodDefinition cmdCallFunc = CommandProcessor.ProcessCommandCall(weaverTypes, Log, netBehaviourSubclass, md, commandAttr);
MethodDefinition cmdFunc = CommandProcessor.ProcessCommandInvoke(weaverTypes, netBehaviourSubclass, md, cmdCallFunc); MethodDefinition cmdFunc = CommandProcessor.ProcessCommandInvoke(weaverTypes, netBehaviourSubclass, md, cmdCallFunc);
if (cmdFunc != null) if (cmdFunc != null)

View File

@ -56,9 +56,9 @@ and replaces the body of the original method with the send message code.
This way we do not need to modify the code anywhere else, and this works This way we do not need to modify the code anywhere else, and this works
correctly in dependent assemblies correctly in dependent assemblies
*/ */
public static MethodDefinition ProcessRpcCall(WeaverTypes weaverTypes, TypeDefinition td, MethodDefinition md, CustomAttribute clientRpcAttr) public static MethodDefinition ProcessRpcCall(WeaverTypes weaverTypes, Logger Log, TypeDefinition td, MethodDefinition md, CustomAttribute clientRpcAttr)
{ {
MethodDefinition rpc = MethodProcessor.SubstituteMethod(td, md); MethodDefinition rpc = MethodProcessor.SubstituteMethod(Log, td, md);
ILProcessor worker = md.Body.GetILProcessor(); ILProcessor worker = md.Body.GetILProcessor();

View File

@ -90,9 +90,9 @@ and replaces the body of the original method with the send message code.
correctly in dependent assemblies correctly in dependent assemblies
*/ */
public static MethodDefinition ProcessTargetRpcCall(WeaverTypes weaverTypes, TypeDefinition td, MethodDefinition md, CustomAttribute targetRpcAttr) public static MethodDefinition ProcessTargetRpcCall(WeaverTypes weaverTypes, Logger Log, TypeDefinition td, MethodDefinition md, CustomAttribute targetRpcAttr)
{ {
MethodDefinition rpc = MethodProcessor.SubstituteMethod(td, md); MethodDefinition rpc = MethodProcessor.SubstituteMethod(Log, td, md);
ILProcessor worker = md.Body.GetILProcessor(); ILProcessor worker = md.Body.GetILProcessor();