mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkBehaviourProcessor.WasProcessed/MarkAsProcessed that is also reused in Weaver to avoid redundant code
This commit is contained in:
parent
20132046eb
commit
1d4a98b84f
@ -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,24 +143,25 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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));
|
||||
td.Methods.Add(versionMethod);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GenerateConstants()
|
||||
{
|
||||
if (m_Cmds.Count == 0 && m_Rpcs.Count == 0 && m_TargetRpcs.Count == 0 && m_Events.Count == 0 && m_SyncObjects.Count == 0)
|
||||
|
@ -1023,19 +1023,15 @@ 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);
|
||||
DLog(td, "Found NetworkBehaviour " + td.FullName);
|
||||
|
||||
NetworkBehaviourProcessor proc = new NetworkBehaviourProcessor(td);
|
||||
proc.Process();
|
||||
return true;
|
||||
NetworkBehaviourProcessor proc = new NetworkBehaviourProcessor(td);
|
||||
proc.Process();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static MethodReference ResolveMethod(TypeReference t, string name)
|
||||
|
Loading…
Reference in New Issue
Block a user