Beispiel #1
0
        public void TestInstanceInvoke()
        {
            ReflectedManager.Process(typeof(ReflectionTestBinding));
            var target = new ReflectionTestTarget();

            Assert.True(ReflectionTestBinding.TestCall.Invoke(target, 1));
            Assert.False(ReflectionTestBinding.TestCall.Invoke(target, -1));
        }
Beispiel #2
0
        public void TestStaticPropertySet()
        {
            ReflectedManager.Process(typeof(ReflectionTestBinding));
            int testNumber = AcquireRandomNum();

            ReflectionTestBinding.TestStaticPropertySetter.Invoke(testNumber);
            Assert.Equal(testNumber, ReflectionTestTarget.TestPropertyStatic);
        }
Beispiel #3
0
        public void TestStaticFieldGet()
        {
            ReflectedManager.Process(typeof(ReflectionTestBinding));
            int testNumber = AcquireRandomNum();

            ReflectionTestTarget.TestFieldStatic = testNumber;
            Assert.Equal(testNumber, ReflectionTestBinding.TestStaticFieldGetter.Invoke());
        }
Beispiel #4
0
        public void TestInstancePropertySet()
        {
            ReflectedManager.Process(typeof(ReflectionTestBinding));
            int testNumber = AcquireRandomNum();
            var target     = new ReflectionTestTarget();

            ReflectionTestBinding.TestPropertySetter.Invoke(target, testNumber);
            Assert.Equal(testNumber, target.TestProperty);
        }
        public static void Patch(PatchContext ctx)
        {
            ReflectedManager.Process(typeof(PBProfilerPatch));

            ctx.GetPattern(_programmableRunSandboxed).Prefixes.Add(ReflectionUtils.StaticMethod(typeof(PBProfilerPatch), nameof(PrefixProfilePb)));
            ctx.GetPattern(_programmableRunSandboxed).Suffixes.Add(ReflectionUtils.StaticMethod(typeof(PBProfilerPatch), nameof(SuffixProfilePb)));
            ctx.GetPattern(_programableRecompile).Suffixes.Add(ReflectionUtils.StaticMethod(typeof(PBProfilerPatch), nameof(PrefixRecompilePb)));

            Log.Info("Finished Patching!");
        }
Beispiel #6
0
        public void TestInstanceFieldGet()
        {
            ReflectedManager.Process(typeof(ReflectionTestBinding));
            int testNumber = AcquireRandomNum();
            var target     = new ReflectionTestTarget
            {
                TestField = testNumber
            };

            Assert.Equal(testNumber, ReflectionTestBinding.TestFieldGetter.Invoke(target));
        }
Beispiel #7
0
        public static void Patch(PatchContext ctx)
        {
            Log.Trace("Profiler patch started");

            ReflectedManager.Process(typeof(ProfilerPatch));

            // MyEntity and MyEntityComponentBase
            MyGameLogic_Update.Patch(ctx);
            MyParallelEntityUpdateOrchestrator_Transpile.Patch(ctx);
            MyProgrammableBlock_RunSandboxedProgramAction.Patch(ctx);

            // Physics
            MyPhysics_StepWorlds.Patch(ctx);

            // Game loop in call hierarchy
            Game_RunSingleFrame.Patch(ctx);
            {
                Game_UpdateInternal.Patch(ctx);
                {
                    MyTransportLayer_Tick.Patch(ctx);
                    MyGameService_Update.Patch(ctx);
                    MyNetworkReader_Process.Patch(ctx);
                    {
                        MyDedicatedServerBase_ClientConnected.Patch(ctx);
                        MyMultiplayerServerBase_ClientReady.Patch(ctx);
                        MyReplicationServer_OnClientAcks.Patch(ctx);
                        MyReplicationServer_OnClientUpdate.Patch(ctx);
                        MyReplicationServer_ReplicableReady.Patch(ctx);
                        MyReplicationServer_ReplicableRequest.Patch(ctx);
                        MyReplicationServer_OnEvent.Patch(ctx);
                    }
                    MyDedicatedServer_ReportReplicatedObjects.Patch(ctx);
                    {
                        MySession_Update_Transpile.Patch(ctx);
                        MyReplicationServer_UpdateBefore.Patch(ctx);
                        MySession_UpdateComponents.Patch(ctx);
                        {
                            MySession_UpdateComponents_Transpile.Patch(ctx);
                        }
                        MyGpsCollection_Update.Patch(ctx);
                        MyReplicationServer_UpdateAfter.Patch(ctx);
                        MyDedicatedServer_Tick.Patch(ctx);
                        {
                            MyReplicationServer_SendUpdate.Patch(ctx);
                        }
                        MyPlayerCollection_SendDirtyBlockLimits.Patch(ctx);
                    }
                }
                FixedLoop_Run.Patch(ctx);
            }

            Log.Trace("Profiler patch ended");
        }
Beispiel #8
0
 static TorchBase()
 {
     ReflectedManager.Process(typeof(TorchBase).Assembly);
     ReflectedManager.Process(typeof(ITorchBase).Assembly);
     PatchManager.AddPatchShim(typeof(GameStatePatchShim));
     PatchManager.AddPatchShim(typeof(GameAnalyticsPatch));
     PatchManager.AddPatchShim(typeof(KeenLogPatch));
     PatchManager.CommitInternal();
     RegisterCoreAssembly(typeof(ITorchBase).Assembly);
     RegisterCoreAssembly(typeof(TorchBase).Assembly);
     RegisterCoreAssembly(Assembly.GetEntryAssembly());
 }
Beispiel #9
0
 public void TestBindingMemberInfo(ReflectionTestManager.FieldRef field)
 {
     if (field.Field == null)
     {
         return;
     }
     Assert.True(ReflectedManager.Process(field.Field));
     if (field.Field.IsStatic)
     {
         Assert.NotNull(field.Field.GetValue(null));
     }
 }
Beispiel #10
0
 public void TestBindingEvents(ReflectionTestManager.FieldRef field)
 {
     if (field.Field == null)
     {
         return;
     }
     Assert.True(ReflectedManager.Process(field.Field));
     if (field.Field.IsStatic)
     {
         ((Func <ReflectedEventReplacer>)field.Field.GetValue(null)).Invoke();
     }
 }
Beispiel #11
0
 static TorchBase()
 {
     ReflectedManager.Process(typeof(TorchBase).Assembly);
     ReflectedManager.Process(typeof(ITorchBase).Assembly);
     PatchManager.AddPatchShim(typeof(GameStatePatchShim));
     PatchManager.AddPatchShim(typeof(GameAnalyticsPatch));
     PatchManager.AddPatchShim(typeof(KeenLogPatch));
     PatchManager.CommitInternal();
     RegisterCoreAssembly(typeof(ITorchBase).Assembly);
     RegisterCoreAssembly(typeof(TorchBase).Assembly);
     RegisterCoreAssembly(Assembly.GetEntryAssembly());
     //exceptions in English, please
     Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
 }
        public static void Patch(PatchContext ctx)
        {
            ReflectedManager.Process(typeof(MyCubeGridPatch));

            try
            {
                ctx.GetPattern(requestValidation).Prefixes.Add(requestValidationPatch);
                Log.Info("Patching successful!");
            }
            catch (Exception e)
            {
                Log.Error(e, "Patching failed!");
            }
        }
Beispiel #13
0
 static TorchBase()
 {
     MyVRageWindows.Init("SpaceEngineersDedicated", MySandboxGame.Log, null, false);
     ReflectedManager.Process(typeof(TorchBase).Assembly);
     ReflectedManager.Process(typeof(ITorchBase).Assembly);
     PatchManager.AddPatchShim(typeof(GameStatePatchShim));
     PatchManager.AddPatchShim(typeof(GameAnalyticsPatch));
     PatchManager.AddPatchShim(typeof(KeenLogPatch));
     PatchManager.CommitInternal();
     RegisterCoreAssembly(typeof(ITorchBase).Assembly);
     RegisterCoreAssembly(typeof(TorchBase).Assembly);
     RegisterCoreAssembly(Assembly.GetEntryAssembly());
     //exceptions in English, please
     Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
 }
Beispiel #14
0
        static PatchTest()
        {
            TestUtils.Init();
            foreach (Type type in typeof(PatchManager).Assembly.GetTypes())
            {
                if (type.Namespace?.StartsWith(typeof(PatchManager).Namespace ?? "") ?? false)
                {
                    ReflectedManager.Process(type);
                }
            }

            _patchTest = new List <TestBootstrap>();
            foreach (Type type in typeof(PatchTest).GetNestedTypes(BindingFlags.NonPublic))
            {
                if (type.GetCustomAttribute(typeof(PatchTestAttribute)) != null)
                {
                    _patchTest.Add(new TestBootstrap(type));
                }
            }
        }
Beispiel #15
0
        public static void Patch(PatchContext ctx)
        {
            ReflectedManager.Process(typeof(ProfilerPatch));

            _distributedUpdaterIterate = typeof(MyDistributedUpdater <,>).GetMethod("Iterate");
            ParameterInfo[] duiP = _distributedUpdaterIterate?.GetParameters();
            if (_distributedUpdaterIterate == null || duiP == null || duiP.Length != 1 || typeof(Action <>) != duiP[0].ParameterType.GetGenericTypeDefinition())
            {
                _log.Error(
                    $"Unable to find MyDistributedUpdater.Iterate(Delegate) method.  Profiling will not function.  (Found {_distributedUpdaterIterate}");
                return;
            }

            PatchDistributedUpdate(ctx, _gameLogicUpdateBeforeSimulation);
            PatchDistributedUpdate(ctx, _gameLogicUpdateAfterSimulation);
            PatchDistributedUpdate(ctx, _entitiesUpdateBeforeSimulation);
            PatchDistributedUpdate(ctx, _entitiesUpdateAfterSimulation);



            {
                MethodInfo patcher = typeof(ProfilerPatch).GetMethod(nameof(TranspilerForUpdate),
                                                                     BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)?
                                     .MakeGenericMethod(typeof(MyCubeGridSystems));
                if (patcher == null)
                {
                    _log.Error($"Failed to make generic patching method for cube grid systems");
                }
                ctx.GetPattern(_cubeGridSystemsUpdateBeforeSimulation).PostTranspilers.Add(patcher);
                ctx.GetPattern(_cubeGridSystemsUpdateBeforeSimulation10).PostTranspilers.Add(patcher);
                ctx.GetPattern(_cubeGridSystemsUpdateBeforeSimulation100).PostTranspilers.Add(patcher);
                //                ctx.GetPattern(_cubeGridSystemsUpdateAfterSimulation).Transpilers.Add(patcher);
                //                ctx.GetPattern(_cubeGridSystemsUpdateAfterSimulation10).Transpilers.Add(patcher);
                ctx.GetPattern(_cubeGridSystemsUpdateAfterSimulation100).PostTranspilers.Add(patcher);
            }

            {
                MethodInfo patcher = typeof(ProfilerPatch).GetMethod(nameof(TranspilerForUpdate),
                                                                     BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)?
                                     .MakeGenericMethod(typeof(MyGameLogicComponent));
                if (patcher == null)
                {
                    _log.Error($"Failed to make generic patching method for composite updates");
                }
                ctx.GetPattern(_gameLogicUpdateOnceBeforeFrame).PostTranspilers.Add(patcher);
                foreach (var type in new[] { "After", "Before" })
                {
                    foreach (var timing in new[] { 1, 10, 100 })
                    {
                        var period = timing == 1 ? "" : timing.ToString();
                        var name   = $"{typeof(IMyGameLogicComponent).FullName}.Update{type}Simulation{period}";
                        var method = typeof(MyCompositeGameLogicComponent).GetMethod(name,
                                                                                     BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        if (method == null)
                        {
                            _log.Warn(
                                $"Failed to find {name} in CompositeGameLogicComponent.  Entity component profiling may not work.");
                            continue;
                        }
                        ctx.GetPattern(method).PostTranspilers.Add(patcher);
                    }
                }
            }

            {
                MethodInfo patcher = typeof(ProfilerPatch).GetMethod(nameof(TranspilerForUpdate),
                                                                     BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)?
                                     .MakeGenericMethod(typeof(MyEntity));
                if (patcher == null)
                {
                    _log.Error($"Failed to make generic patching method for entity update before frame");
                }
                ctx.GetPattern(_entitiesUpdateOnceBeforeFrame).PostTranspilers.Add(patcher);
            }

            {
                MethodInfo patcher = typeof(ProfilerPatch).GetMethod(nameof(TranspilerForUpdate),
                                                                     BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)?
                                     .MakeGenericMethod(typeof(MySessionComponentBase));
                if (patcher == null)
                {
                    _log.Error($"Failed to make generic patching method for session components");
                }

                ctx.GetPattern(_sessionUpdateComponents).PostTranspilers.Add(patcher);
            }

            ctx.GetPattern(_gameRunSingleFrame).Suffixes.Add(ProfilerData.DoRotateEntries);


            var singleMethodProfiler = typeof(ProfilerPatch).GetMethod(nameof(TranspileSingleMethod),
                                                                       BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);

            ctx.GetPattern(_cubeGridUpdatePhysicsShape).PostTranspilers.Add(singleMethodProfiler);
            ctx.GetPattern(_turretUpdateAiWeapon).PostTranspilers.Add(singleMethodProfiler);
            ctx.GetPattern(_programmableBlockRunSandbox).PostTranspilers.Add(singleMethodProfiler);
            ctx.GetPattern(_slimBlockDoDamageInternal).PostTranspilers.Add(singleMethodProfiler);
            ctx.GetPattern(_voxelPhysicsUpdateAfterSimulation10).PostTranspilers.Add(singleMethodProfiler);
            ctx.GetPattern(_voxelPhysicsUpdateBeforeSimulation10).PostTranspilers.Add(singleMethodProfiler);
            ctx.GetPattern(_planetUpdateFloraAndPhysics).PostTranspilers.Add(singleMethodProfiler);
        }
        public static void Patch(PatchContext ctx)
        {
            ReflectedManager.Process(typeof(ProfilerPatch));

            _distributedUpdaterIterate = typeof(MyDistributedUpdater <,>).GetMethod("Iterate");
            var duiP = _distributedUpdaterIterate?.GetParameters();

            if (_distributedUpdaterIterate == null || duiP == null || duiP.Length != 1 ||
                typeof(Action <>) != duiP[0].ParameterType.GetGenericTypeDefinition())
            {
                Log.Error(
                    $"Unable to find MyDistributedUpdater.Iterate(Delegate) method.  Profiling will not function.  (Found {_distributedUpdaterIterate}");
                return;
            }

            PatchDistributedUpdate(ctx, _gameLogicUpdateBeforeSimulation);
            PatchDistributedUpdate(ctx, _gameLogicUpdateAfterSimulation);
            PatchDistributedUpdate(ctx, _entitiesUpdateBeforeSimulation);
            PatchDistributedUpdate(ctx, _entitiesUpdateAfterSimulation);

            {
                var patcher = typeof(ProfilerPatch).GetMethod(nameof(TranspilerForUpdate),
                                                              BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)?
                              .MakeGenericMethod(typeof(MyGameLogicComponent));
                if (patcher == null)
                {
                    Log.Error($"Failed to make generic patching method for composite updates");
                }

                ctx.GetPattern(_gameLogicUpdateOnceBeforeFrame).PostTranspilers.Add(patcher);
                foreach (var type in new[] { "After", "Before" })
                {
                    foreach (var timing in new[] { 1, 10, 100 })
                    {
                        var period = timing == 1 ? "" : timing.ToString();
                        var name   = $"{typeof(IMyGameLogicComponent).FullName}.Update{type}Simulation{period}";
                        var method = typeof(MyCompositeGameLogicComponent).GetMethod(name,
                                                                                     BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        if (method == null)
                        {
                            Log.Warn($"Failed to find {name} in CompositeGameLogicComponent.  Entity component profiling may not work.");
                            continue;
                        }

                        ctx.GetPattern(method).PostTranspilers.Add(patcher);
                    }
                }
            }

            {
                var patcher = typeof(ProfilerPatch).GetMethod(nameof(TranspilerForUpdate),
                                                              BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)?
                              .MakeGenericMethod(typeof(MyEntity));
                if (patcher == null)
                {
                    Log.Error($"Failed to make generic patching method for entity update before frame");
                }

                ctx.GetPattern(_entitiesUpdateOnceBeforeFrame).PostTranspilers.Add(patcher);
            }

            {
                var patcher = typeof(ProfilerPatch).GetMethod(nameof(TranspilerForUpdate),
                                                              BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)?
                              .MakeGenericMethod(typeof(MySessionComponentBase));
                if (patcher == null)
                {
                    Log.Error($"Failed to make generic patching method for session components");
                }

                ctx.GetPattern(_sessionUpdateComponents).PostTranspilers.Add(patcher);
            }

            ctx.GetPattern(_physicsStepWorlds).Prefixes.Add(ProfilerData.HandlePrefixPhysicsStepWorlds);

            ctx.GetPattern(_gameRunSingleFrame).Suffixes.Add(ProfilerData.DoTick);

            ctx.GetPattern(_programmableRunSandboxed).Prefixes.Add(ReflectionUtils.StaticMethod(typeof(ProfilerPatch), nameof(PrefixProfilePb)));
            ctx.GetPattern(_programmableRunSandboxed).Suffixes.Add(ReflectionUtils.StaticMethod(typeof(ProfilerPatch), nameof(SuffixProfilePb)));
        }
Beispiel #17
0
 public void TestStaticInvoke()
 {
     ReflectedManager.Process(typeof(ReflectionTestBinding));
     Assert.True(ReflectionTestBinding.TestCallStatic.Invoke(1));
     Assert.False(ReflectionTestBinding.TestCallStatic.Invoke(-1));
 }