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;
|
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)
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user