NetworkBehaviourProcessor.WasProcessed/MarkAsProcessed that is also reused in Weaver to avoid redundant code

This commit is contained in:
vis2k 2019-01-01 16:17:51 +01:00
parent 20132046eb
commit 1d4a98b84f
2 changed files with 24 additions and 27 deletions

View File

@ -42,7 +42,7 @@ public void Process()
return;
}
Weaver.DLog(m_td, "Process Start");
ProcessVersion();
MarkAsProcessed(m_td);
SyncVarProcessor.ProcessSyncVars(m_td, m_SyncVars, m_SyncObjects, m_SyncVarNetIds);
Weaver.ResetRecursionCount();
@ -143,23 +143,24 @@ public static bool WriteArguments(ILProcessor worker, MethodDefinition md, strin
return true;
}
// adds empty UNetVersion(), which seems to be used to check if we already
// processed a class or not
void ProcessVersion()
// mark / check type as processed //////////////////////////////////////
// by adding an empty UNetVersion() function
public static bool WasProcessed(TypeDefinition td)
{
foreach (MethodDefinition md in m_td.Methods)
{
if (md.Name == "UNetVersion")
{
return;
}
return td.Methods.Any(method => method.Name == "UNetVersion");
}
public static void MarkAsProcessed(TypeDefinition td)
{
if (!WasProcessed(td))
{
MethodDefinition versionMethod = new MethodDefinition("UNetVersion", MethodAttributes.Private, Weaver.voidType);
ILProcessor worker = versionMethod.Body.GetILProcessor();
worker.Append(worker.Create(OpCodes.Ret));
m_td.Methods.Add(versionMethod);
td.Methods.Add(versionMethod);
}
}
////////////////////////////////////////////////////////////////////////
void GenerateConstants()
{

View File

@ -1023,20 +1023,16 @@ static void ProcessPropertySites()
static bool ProcessNetworkBehaviourType(TypeDefinition td)
{
foreach (var md in td.Resolve().Methods)
if (!NetworkBehaviourProcessor.WasProcessed(td))
{
if (md.Name == "UNetVersion")
{
DLog(td, " Already processed");
return false; // did no work
}
}
DLog(td, "Found NetworkBehaviour " + td.FullName);
NetworkBehaviourProcessor proc = new NetworkBehaviourProcessor(td);
proc.Process();
return true;
}
return false;
}
public static MethodReference ResolveMethod(TypeReference t, string name)
{