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

View File

@ -1023,20 +1023,16 @@ static void ProcessPropertySites()
static bool ProcessNetworkBehaviourType(TypeDefinition td) 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); DLog(td, "Found NetworkBehaviour " + td.FullName);
NetworkBehaviourProcessor proc = new NetworkBehaviourProcessor(td); NetworkBehaviourProcessor proc = new NetworkBehaviourProcessor(td);
proc.Process(); proc.Process();
return true; return true;
} }
return false;
}
public static MethodReference ResolveMethod(TypeReference t, string name) public static MethodReference ResolveMethod(TypeReference t, string name)
{ {