SyncVarProcessor: remove static weaverLists references

This commit is contained in:
vis2k 2021-08-19 01:33:57 +08:00
parent 3ccf9c51f5
commit cffc983731
2 changed files with 8 additions and 6 deletions

View File

@ -50,7 +50,7 @@ public NetworkBehaviourProcessor(AssemblyDefinition assembly, WeaverTypes weaver
this.assembly = assembly;
this.weaverTypes = weaverTypes;
this.weaverLists = weaverLists;
syncVarProcessor = new SyncVarProcessor(assembly, weaverTypes);
syncVarProcessor = new SyncVarProcessor(assembly, weaverTypes, weaverLists);
netBehaviourSubclass = td;
}

View File

@ -14,14 +14,16 @@ public class SyncVarProcessor
AssemblyDefinition assembly;
WeaverTypes weaverTypes;
WeaverLists weaverLists;
string HookParameterMessage(string hookName, TypeReference ValueType) =>
$"void {hookName}({ValueType} oldValue, {ValueType} newValue)";
public SyncVarProcessor(AssemblyDefinition assembly, WeaverTypes weaverTypes)
public SyncVarProcessor(AssemblyDefinition assembly, WeaverTypes weaverTypes, WeaverLists weaverLists)
{
this.assembly = assembly;
this.weaverTypes = weaverTypes;
this.weaverLists = weaverLists;
}
// Get hook method if any
@ -338,7 +340,7 @@ public void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, Dictionary<Fie
td.Methods.Add(get);
td.Methods.Add(set);
td.Properties.Add(propertyDefinition);
Weaver.WeaveLists.replacementSetterProperties[fd] = set;
weaverLists.replacementSetterProperties[fd] = set;
// replace getter field if GameObject/NetworkIdentity so it uses
// netId instead
@ -346,7 +348,7 @@ public void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, Dictionary<Fie
// end up in recursion.
if (fd.FieldType.IsNetworkIdentityField())
{
Weaver.WeaveLists.replacementGetterProperties[fd] = get;
weaverLists.replacementGetterProperties[fd] = get;
}
}
@ -357,7 +359,7 @@ public void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, Dictionary<Fie
// the mapping of dirtybits to sync-vars is implicit in the order of the fields here. this order is recorded in m_replacementProperties.
// start assigning syncvars at the place the base class stopped, if any
int dirtyBitCounter = Weaver.WeaveLists.GetSyncVarStart(td.BaseType.FullName);
int dirtyBitCounter = weaverLists.GetSyncVarStart(td.BaseType.FullName);
// find syncvars
foreach (FieldDefinition fd in td.Fields)
@ -404,7 +406,7 @@ public void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, Dictionary<Fie
{
td.Fields.Add(fd);
}
Weaver.WeaveLists.SetNumSyncVars(td.FullName, syncVars.Count);
weaverLists.SetNumSyncVars(td.FullName, syncVars.Count);
return (syncVars, syncVarNetIds);
}