public ReaderWriterProcessor(ModuleDefinition module, Readers readers, Writers writers)
 {
     this.module     = module;
     this.readers    = readers;
     this.writers    = writers;
     extensionHelper = new SerailizeExtensionHelper(module, readers, writers);
 }
Exemple #2
0
 protected RpcProcessor(ModuleDefinition module, Readers readers, Writers writers, IWeaverLogger logger)
 {
     this.module  = module;
     this.readers = readers;
     this.writers = writers;
     this.logger  = logger;
 }
Exemple #3
0
 public SyncVarProcessor(ModuleDefinition module, Readers readers, Writers writers, PropertySiteProcessor propertySiteProcessor)
 {
     this.module  = module;
     this.readers = readers;
     this.writers = writers;
     this.propertySiteProcessor = propertySiteProcessor;
 }
Exemple #4
0
 public NetworkBehaviourProcessor(TypeDefinition td, Readers readers, Writers writers, PropertySiteProcessor propertySiteProcessor, IWeaverLogger logger)
 {
     Weaver.DebugLog(td, "NetworkBehaviourProcessor");
     netBehaviourSubclass = td;
     this.logger          = logger;
     serverRpcProcessor   = new ServerRpcProcessor(netBehaviourSubclass.Module, readers, writers, logger);
     clientRpcProcessor   = new ClientRpcProcessor(netBehaviourSubclass.Module, readers, writers, logger);
     syncVarProcessor     = new SyncVarProcessor(netBehaviourSubclass.Module, readers, writers, propertySiteProcessor);
     syncObjectProcessor  = new SyncObjectProcessor(readers, writers, logger);
 }
Exemple #5
0
        public NetworkBehaviourProcessor(TypeDefinition td, Readers readers, Writers writers, PropertySiteProcessor propertySiteProcessor, IWeaverLogger logger)
        {
            Weaver.DebugLog(td, "NetworkBehaviourProcessor");
            netBehaviourSubclass = td;
            this.logger          = logger;
            serverRpcProcessor   = new ServerRpcProcessor(netBehaviourSubclass.Module, readers, writers, logger);
            clientRpcProcessor   = new ClientRpcProcessor(netBehaviourSubclass.Module, readers, writers, logger);
            syncVarProcessor     = new SyncVarProcessor(netBehaviourSubclass.Module, readers, writers, propertySiteProcessor);
            syncObjectProcessor  = new SyncObjectProcessor(readers, writers, logger);

            // no max for rpcs, index is sent as var int, so more rpc just means bigger header size (still smaller than 4 byte hash)
            rpcCounter = new ConstFieldTracker("RPC_COUNT", td, int.MaxValue, "Rpc");
        }
Exemple #6
0
        public AssemblyDefinition Weave(ICompiledAssembly compiledAssembly)
        {
            try
            {
                CurrentAssembly = AssemblyDefinitionFor(compiledAssembly);

                ModuleDefinition module = CurrentAssembly.MainModule;
                readers = new Readers(module, logger);
                writers = new Writers(module, logger);
                var rwstopwatch = System.Diagnostics.Stopwatch.StartNew();
                propertySiteProcessor = new PropertySiteProcessor();
                var rwProcessor = new ReaderWriterProcessor(module, readers, writers);

                bool modified = rwProcessor.Process();
                rwstopwatch.Stop();
                Console.WriteLine($"Find all reader and writers took {rwstopwatch.ElapsedMilliseconds} milliseconds");

                Console.WriteLine($"Script Module: {module.Name}");

                modified |= WeaveModule(module);

                if (!modified)
                {
                    return(CurrentAssembly);
                }

                rwProcessor.InitializeReaderAndWriters();

                return(CurrentAssembly);
            }
            catch (Exception e)
            {
                logger.Error("Exception :" + e);
                return(null);
            }
        }
Exemple #7
0
 public ServerRpcProcessor(ModuleDefinition module, Readers readers, Writers writers, IWeaverLogger logger) : base(module, readers, writers, logger)
 {
 }
Exemple #8
0
 public SyncObjectProcessor(Readers readers, Writers writers, IWeaverLogger logger)
 {
     this.readers = readers;
     this.writers = writers;
     this.logger  = logger;
 }
Exemple #9
0
        public AssemblyDefinition Weave(ICompiledAssembly compiledAssembly)
        {
            try
            {
                timer = new WeaverDiagnosticsTimer()
                {
                    writeToFile = true
                };
                timer.Start(compiledAssembly.Name);

                using (timer.Sample("AssemblyDefinitionFor"))
                {
                    CurrentAssembly = AssemblyDefinitionFor(compiledAssembly);
                }

                ModuleDefinition module = CurrentAssembly.MainModule;
                readers = new Readers(module, logger);
                writers = new Writers(module, logger);
                propertySiteProcessor = new PropertySiteProcessor();
                var rwProcessor = new ReaderWriterProcessor(module, readers, writers);

                bool modified = false;
                using (timer.Sample("ReaderWriterProcessor"))
                {
                    modified = rwProcessor.Process();
                }

                IReadOnlyList <FoundType> foundTypes = FindAllClasses(module);

                using (timer.Sample("AttributeProcessor"))
                {
                    var attributeProcessor = new AttributeProcessor(module, logger);
                    modified |= attributeProcessor.ProcessTypes(foundTypes);
                }

                using (timer.Sample("WeaveNetworkBehavior"))
                {
                    foreach (FoundType foundType in foundTypes)
                    {
                        if (foundType.IsNetworkBehaviour)
                        {
                            modified |= WeaveNetworkBehavior(foundType);
                        }
                    }
                }


                if (modified)
                {
                    using (timer.Sample("propertySiteProcessor"))
                    {
                        propertySiteProcessor.Process(module);
                    }

                    using (timer.Sample("InitializeReaderAndWriters"))
                    {
                        rwProcessor.InitializeReaderAndWriters();
                    }
                }

                return(CurrentAssembly);
            }
            catch (Exception e)
            {
                logger.Error("Exception :" + e);
                return(null);
            }
            finally
            {
                // end in finally incase it return early
                timer?.End();
            }
        }
Exemple #10
0
 public ReaderWriterProcessor(ModuleDefinition module, Readers readers, Writers writers)
 {
     this.module  = module;
     this.readers = readers;
     this.writers = writers;
 }
 public SerailizeExtensionHelper(ModuleDefinition module, Readers readers, Writers writers)
 {
     this.module  = module;
     this.readers = readers;
     this.writers = writers;
 }
Exemple #12
0
        public AssemblyDefinition Weave(ICompiledAssembly compiledAssembly)
        {
            Log($"Starting weaver on {compiledAssembly.Name}");
            try
            {
                timer = new WeaverDiagnosticsTimer()
                {
                    writeToFile = true
                };
                timer.Start(compiledAssembly.Name);

                using (timer.Sample("AssemblyDefinitionFor"))
                {
                    CurrentAssembly = AssemblyDefinitionFor(compiledAssembly);
                }


                var module = CurrentAssembly.MainModule;
                readers = new Readers(module, logger);
                writers = new Writers(module, logger);
                propertySiteProcessor = new PropertySiteProcessor();
                var rwProcessor = new ReaderWriterProcessor(module, readers, writers);

                var modified = false;
                using (timer.Sample("ReaderWriterProcessor"))
                {
                    modified = rwProcessor.Process();
                }

                var foundTypes = FindAllClasses(module);

                using (timer.Sample("AttributeProcessor"))
                {
                    var attributeProcessor = new AttributeProcessor(module, logger);
                    modified |= attributeProcessor.ProcessTypes(foundTypes);
                }

                using (timer.Sample("WeaveNetworkBehavior"))
                {
                    foreach (var foundType in foundTypes)
                    {
                        if (foundType.IsNetworkBehaviour)
                        {
                            modified |= WeaveNetworkBehavior(foundType);
                        }
                    }
                }


                if (modified)
                {
                    using (timer.Sample("propertySiteProcessor"))
                    {
                        propertySiteProcessor.Process(module);
                    }

                    using (timer.Sample("InitializeReaderAndWriters"))
                    {
                        rwProcessor.InitializeReaderAndWriters();
                    }
                }

                return(CurrentAssembly);
            }
            catch (Exception e)
            {
                logger.Error("Exception :" + e);
                // write line too because the error about doesn't show stacktrace
                Console.WriteLine("[WeaverException] :" + e);
                return(null);
            }
            finally
            {
                Log($"Finished weaver on {compiledAssembly.Name}");
                // end in finally incase it return early
                timer?.End();
            }
        }