Weaver.ResolveMethodInParents moved to Resolvers

This commit is contained in:
vis2k 2019-01-02 13:07:46 +01:00
parent feb6a9e01d
commit 6252201f21
3 changed files with 21 additions and 20 deletions

View File

@ -330,7 +330,7 @@ void GenerateSerialization()
VariableDefinition dirtyLocal = new VariableDefinition(Weaver.boolType); VariableDefinition dirtyLocal = new VariableDefinition(Weaver.boolType);
serialize.Body.Variables.Add(dirtyLocal); serialize.Body.Variables.Add(dirtyLocal);
MethodReference baseSerialize = Weaver.ResolveMethodInParents(m_td.BaseType, "OnSerialize"); MethodReference baseSerialize = Resolvers.ResolveMethodInParents(m_td.BaseType, Weaver.scriptDef, "OnSerialize");
if (baseSerialize != null) if (baseSerialize != null)
{ {
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); // base serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); // base
@ -527,7 +527,7 @@ void GenerateDeSerialization()
serialize.Parameters.Add(new ParameterDefinition("initialState", ParameterAttributes.None, Weaver.boolType)); serialize.Parameters.Add(new ParameterDefinition("initialState", ParameterAttributes.None, Weaver.boolType));
ILProcessor serWorker = serialize.Body.GetILProcessor(); ILProcessor serWorker = serialize.Body.GetILProcessor();
MethodReference baseDeserialize = Weaver.ResolveMethodInParents(m_td.BaseType, "OnDeserialize"); MethodReference baseDeserialize = Resolvers.ResolveMethodInParents(m_td.BaseType, Weaver.scriptDef, "OnDeserialize");
if (baseDeserialize != null) if (baseDeserialize != null)
{ {
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); // base serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); // base

View File

@ -37,5 +37,24 @@ public static MethodReference ResolveMethod(TypeReference tr, AssemblyDefinition
Weaver.fail = true; Weaver.fail = true;
return null; return null;
} }
public static MethodReference ResolveMethodInParents(TypeReference tr, AssemblyDefinition scriptDef, string name)
{
if (tr == null)
{
Log.Error("Type missing for " + name);
Weaver.fail = true;
return null;
}
foreach (MethodDefinition methodRef in tr.Resolve().Methods)
{
if (methodRef.Name == name)
{
return scriptDef.MainModule.ImportReference(methodRef);
}
}
// Could not find the method in this class, try the parent
return ResolveMethodInParents(tr.Resolve().BaseType, scriptDef, name);
}
} }
} }

View File

@ -1033,24 +1033,6 @@ static bool ProcessNetworkBehaviourType(TypeDefinition td)
} }
return false; return false;
} }
public static MethodReference ResolveMethodInParents(TypeReference t, string name)
{
if (t == null)
{
Log.Error("Type missing for " + name);
fail = true;
return null;
}
foreach (var methodRef in t.Resolve().Methods)
{
if (methodRef.Name == name)
{
return scriptDef.MainModule.ImportReference(methodRef);
}
}
// Could not find the method in this class, try the parent
return ResolveMethodInParents(t.Resolve().BaseType, name);
}
static MethodReference ResolveMethodWithArg(TypeReference t, string name, TypeReference argType) static MethodReference ResolveMethodWithArg(TypeReference t, string name, TypeReference argType)
{ {