SyncVarProcessor: remove static Weaver.CurrentAssembly references

This commit is contained in:
vis2k 2021-08-17 22:50:29 +08:00
parent e36b39f328
commit 133c4bb181
2 changed files with 11 additions and 4 deletions

View File

@ -46,7 +46,7 @@ public struct ClientRpcResult
public NetworkBehaviourProcessor(AssemblyDefinition assembly, TypeDefinition td)
{
this.assembly = assembly;
syncVarProcessor = new SyncVarProcessor();
syncVarProcessor = new SyncVarProcessor(assembly);
netBehaviourSubclass = td;
}

View File

@ -12,9 +12,16 @@ public class SyncVarProcessor
// ulong = 64 bytes
const int SyncVarLimit = 64;
AssemblyDefinition assembly;
string HookParameterMessage(string hookName, TypeReference ValueType) =>
$"void {hookName}({ValueType} oldValue, {ValueType} newValue)";
public SyncVarProcessor(AssemblyDefinition assembly)
{
this.assembly = assembly;
}
// Get hook method if any
public MethodDefinition GetHookMethod(TypeDefinition td, FieldDefinition syncVar)
{
@ -116,7 +123,7 @@ public MethodDefinition GenerateSyncVarGetter(FieldDefinition fd, string origina
worker.Emit(OpCodes.Ldfld, netFieldId);
worker.Emit(OpCodes.Ldarg_0);
worker.Emit(OpCodes.Ldflda, fd);
MethodReference getFunc = Weaver.weaverTypes.getSyncVarNetworkBehaviourReference.MakeGeneric(Weaver.CurrentAssembly.MainModule, fd.FieldType);
MethodReference getFunc = Weaver.weaverTypes.getSyncVarNetworkBehaviourReference.MakeGeneric(assembly.MainModule, fd.FieldType);
worker.Emit(OpCodes.Call, getFunc);
worker.Emit(OpCodes.Ret);
}
@ -176,7 +183,7 @@ public MethodDefinition GenerateSyncVarSetter(TypeDefinition td, FieldDefinition
worker.Emit(OpCodes.Ldarg_0);
worker.Emit(OpCodes.Ldfld, netFieldId);
MethodReference getFunc = Weaver.weaverTypes.syncVarNetworkBehaviourEqualReference.MakeGeneric(Weaver.CurrentAssembly.MainModule, fd.FieldType);
MethodReference getFunc = Weaver.weaverTypes.syncVarNetworkBehaviourEqualReference.MakeGeneric(assembly.MainModule, fd.FieldType);
worker.Emit(OpCodes.Call, getFunc);
}
else
@ -235,7 +242,7 @@ public MethodDefinition GenerateSyncVarSetter(TypeDefinition td, FieldDefinition
worker.Emit(OpCodes.Ldarg_0);
worker.Emit(OpCodes.Ldflda, netFieldId);
MethodReference getFunc = Weaver.weaverTypes.setSyncVarNetworkBehaviourReference.MakeGeneric(Weaver.CurrentAssembly.MainModule, fd.FieldType);
MethodReference getFunc = Weaver.weaverTypes.setSyncVarNetworkBehaviourReference.MakeGeneric(assembly.MainModule, fd.FieldType);
worker.Emit(OpCodes.Call, getFunc);
}
else