Weaver ProcessEvents moved into NetworkBehaviourSyncEventProcessor too

This commit is contained in:
vis2k 2018-12-31 01:23:16 +01:00
parent 4f5f76e42f
commit 39a599963a
2 changed files with 50 additions and 49 deletions

View File

@ -48,7 +48,7 @@ public void Process()
ProcessMethods();
ProcessEvents();
NetworkBehaviourSyncEventProcessor.ProcessEvents(m_td, m_Events, m_EventInvocationFuncs);
if (Weaver.fail)
{
return;
@ -982,54 +982,6 @@ void ProcessMethods()
}
}
void ProcessEvents()
{
// find events
foreach (EventDefinition ed in m_td.Events)
{
foreach (var ca in ed.CustomAttributes)
{
if (ca.AttributeType.FullName == Weaver.SyncEventType.FullName)
{
if (ed.Name.Length > 4 && ed.Name.Substring(0, 5) != "Event")
{
Log.Error("Event [" + m_td.FullName + ":" + ed.FullName + "] doesnt have 'Event' prefix");
Weaver.fail = true;
return;
}
if (ed.EventType.Resolve().HasGenericParameters)
{
Log.Error("Event [" + m_td.FullName + ":" + ed.FullName + "] cannot have generic parameters");
Weaver.fail = true;
return;
}
m_Events.Add(ed);
MethodDefinition eventFunc = NetworkBehaviourSyncEventProcessor.ProcessEventInvoke(m_td, ed);
if (eventFunc == null)
{
return;
}
m_td.Methods.Add(eventFunc);
m_EventInvocationFuncs.Add(eventFunc);
Weaver.DLog(m_td, "ProcessEvent " + ed);
MethodDefinition eventCallFunc = NetworkBehaviourSyncEventProcessor.ProcessEventCall(ed, ca);
m_td.Methods.Add(eventCallFunc);
Weaver.lists.replacedEvents.Add(ed);
Weaver.lists.replacementEvents.Add(eventCallFunc);
Weaver.DLog(m_td, " Event: " + ed.Name);
break;
}
}
}
}
bool HasMethod(string name)
{
foreach (var method in m_td.Methods)

View File

@ -1,4 +1,5 @@
// all the SyncEvent code from NetworkBehaviourProcessor in one place
using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil.Cil;
@ -99,5 +100,53 @@ public static MethodDefinition ProcessEventCall(EventDefinition ed, CustomAttrib
return evt;
}
public static void ProcessEvents(TypeDefinition td, List<EventDefinition> events, List<MethodDefinition> eventInvocationFuncs)
{
// find events
foreach (EventDefinition ed in td.Events)
{
foreach (var ca in ed.CustomAttributes)
{
if (ca.AttributeType.FullName == Weaver.SyncEventType.FullName)
{
if (ed.Name.Length > 4 && ed.Name.Substring(0, 5) != "Event")
{
Log.Error("Event [" + td.FullName + ":" + ed.FullName + "] doesnt have 'Event' prefix");
Weaver.fail = true;
return;
}
if (ed.EventType.Resolve().HasGenericParameters)
{
Log.Error("Event [" + td.FullName + ":" + ed.FullName + "] cannot have generic parameters");
Weaver.fail = true;
return;
}
events.Add(ed);
MethodDefinition eventFunc = NetworkBehaviourSyncEventProcessor.ProcessEventInvoke(td, ed);
if (eventFunc == null)
{
return;
}
td.Methods.Add(eventFunc);
eventInvocationFuncs.Add(eventFunc);
Weaver.DLog(td, "ProcessEvent " + ed);
MethodDefinition eventCallFunc = NetworkBehaviourSyncEventProcessor.ProcessEventCall(ed, ca);
td.Methods.Add(eventCallFunc);
Weaver.lists.replacedEvents.Add(ed);
Weaver.lists.replacementEvents.Add(eventCallFunc);
Weaver.DLog(td, " Event: " + ed.Name);
break;
}
}
}
}
}
}