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,24 +143,25 @@ 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;
}
}
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);
} }
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));
td.Methods.Add(versionMethod);
}
}
////////////////////////////////////////////////////////////////////////
void GenerateConstants() void GenerateConstants()
{ {
if (m_Cmds.Count == 0 && m_Rpcs.Count == 0 && m_TargetRpcs.Count == 0 && m_Events.Count == 0 && m_SyncObjects.Count == 0) if (m_Cmds.Count == 0 && m_Rpcs.Count == 0 && m_TargetRpcs.Count == 0 && m_Events.Count == 0 && m_SyncObjects.Count == 0)

View File

@ -1023,19 +1023,15 @@ 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, "Found NetworkBehaviour " + td.FullName);
{
DLog(td, " Already processed");
return false; // did no work
}
}
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)