Esempio n. 1
0
#pragma warning restore 649

        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(_drawScene).Transpilers
            .Add(Method(nameof(TranspileDrawScene)));
            ctx.GetPattern(_draw).Transpilers
            .Add(Method(nameof(TranspileDraw)));
        }
Esempio n. 2
0
        /// <inheritdoc cref="Manager.Attach"/>
        public override void Attach()
        {
            base.Attach();

            if (_ctx == null)
            {
                _ctx = _patchManager.AcquireContext();
            }

            Torch.GameStateChanged += Torch_GameStateChanged;
            _sessionManager         = Torch.Managers.GetManager <TorchSessionManager>();
            if (_sessionManager != null)
            {
                _sessionManager.SessionStateChanged += SessionChanged;
            }
            else
            {
                LogManager.GetCurrentClassLogger().Warn("No session manager. Player metrics won't work");
            }

            loadTimer           = new System.Timers.Timer(500);
            loadTimer.Elapsed  += LoadTimerElapsed;
            loadTimer.AutoReset = true;
            loadTimer.Start();

            var perfMetricManager = typeof(PerformanceMetricsManager);

            _ctx.GetPattern(_asyncSavingStart).Prefixes.Add(perfMetricManager.GetMethod(nameof(PrefixAsyncSavingStart), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
            _ctx.GetPattern(_asyncSavingStart).Suffixes.Add(perfMetricManager.GetMethod(nameof(SuffixAsyncSavingStart), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
            _ctx.GetPattern(_serverBanClient).Suffixes.Add(perfMetricManager.GetMethod(nameof(SuffixBanClient), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
            _ctx.GetPattern(_spaceRespawnComponentCreateNewIdentity).Suffixes.Add(perfMetricManager.GetMethod(nameof(SuffixCreateNewIdentity), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
            _patchManager.Commit();

            LogManager.GetCurrentClassLogger().Info("Attached");
        }
Esempio n. 3
0
            public void TestCombo()
            {
                Invoke(_resetMethod);
                PatchContext context = _patchContext.AcquireContext();

                if (_prefixMethod != null)
                {
                    context.GetPattern(_targetMethod).Prefixes.Add(_prefixMethod);
                }
                if (_transpileMethod != null)
                {
                    context.GetPattern(_targetMethod).Transpilers.Add(_transpileMethod);
                }
                if (_suffixMethod != null)
                {
                    context.GetPattern(_targetMethod).Suffixes.Add(_suffixMethod);
                }
                _patchContext.Commit();

                Invoke();
                Invoke(_prefixAssert);
                Invoke(_transpileAssert);
                Invoke(_suffixAssert);

                _patchContext.FreeContext(context);
                _patchContext.Commit();
            }
Esempio n. 4
0
        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(typeof(MyCubeBuilder).GetMethod("RequestGridSpawn", BindingFlags.NonPublic | BindingFlags.Static))
            .Prefixes.Add(typeof(GridSpawnPatch).GetMethod(nameof(Prefix), BindingFlags.NonPublic | BindingFlags.Static));

            ctx.GetPattern(typeof(MyCubeGrid).GetMethod("TryPasteGrid_Implementation", BindingFlags.Public | BindingFlags.Static)).
            Prefixes.Add(typeof(GridSpawnPatch).GetMethod(nameof(AttemptSpawn), BindingFlags.Static | BindingFlags.NonPublic));
        }
Esempio n. 5
0
        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(typeof(MyFunctionalBlock).GetMethod("UpdateBeforeSimulation10", BindingFlags.Instance | BindingFlags.Public)).
            Prefixes.Add(typeof(BlockSwitchPatch).GetMethod(nameof(KeepBlocksOff), BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));

            ctx.GetPattern(typeof(MyFunctionalBlock).GetMethod("UpdateBeforeSimulation100", BindingFlags.Instance | BindingFlags.Public)).
            Prefixes.Add(typeof(BlockSwitchPatch).GetMethod(nameof(KeepBlocksOff), BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
        }
Esempio n. 6
0
        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(typeof(MyShipMergeBlock).GetMethod("CheckUnobstructed", BindingFlags.NonPublic | BindingFlags.Instance)).
            Prefixes.Add(typeof(MergeBlockPatch).GetMethod(nameof(MergeCheck), BindingFlags.NonPublic | BindingFlags.Static));

            ctx.GetPattern(typeof(MyShipMergeBlock).GetMethod("AddConstraint", BindingFlags.NonPublic | BindingFlags.Instance)).
            Suffixes.Add(typeof(MergeBlockPatch).GetMethod(nameof(AddBlocks), BindingFlags.NonPublic | BindingFlags.Static));
        }
        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(OnChangeOwnersRequest).Prefixes.Add(patchOnChangeOwnersRequest);
            ctx.GetPattern(ChangeOwnerRequest).Prefixes.Add(patchChangeOwnerRequest);
            ctx.GetPattern(DestroyRequest).Prefixes.Add(patchOnDestroyRequest);

            LogManager.GetCurrentClassLogger().Debug("Patched MyCubeGrid!");
        }
Esempio n. 8
0
 public static void Patch(PatchContext ctx)
 {
     ApplyLogging();
     ctx.GetPattern(update).Prefixes.Add(updatePatch);
     ctx.GetPattern(update2).Prefixes.Add(updatePatch2);
     ctx.GetPattern(update3).Prefixes.Add(updatePatch3);
     ctx.GetPattern(AddFactionRepSuccess).Prefixes.Add(RepSuccessPatch);
 }
Esempio n. 9
0
        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(typeof(MyProjectorBase).GetMethod("OnNewBlueprintSuccess", BindingFlags.Instance | BindingFlags.NonPublic)).
            Prefixes.Add(typeof(ProjectionPatch).GetMethod(nameof(PrefixNewBlueprint), BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));

            ctx.GetPattern(typeof(MyProjectorBase).GetMethod("RemoveProjection", BindingFlags.Instance | BindingFlags.NonPublic)).
            Prefixes.Add(typeof(ProjectionPatch).GetMethod(nameof(DecreaseProjectedCount), BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
        }
#pragma warning restore 649

        internal static void Patch(PatchContext context)
        {
            context.GetPattern(_methodReadSettingsFromControls).Suffixes
            .Add(typeof(MyGuiScreenOptionsDisplayVr).GetMethod(nameof(SuffixReadSettingsFromControls),
                                                               BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static));
            context.GetPattern(_methodWriteSettingsToControls).Suffixes
            .Add(typeof(MyGuiScreenOptionsDisplayVr).GetMethod(nameof(SuffixWriteSettingsToControls),
                                                               BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static));
        }
        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!");
        }
Esempio n. 12
0
        public static void Patch(PatchContext ctx)
        {
            var t       = typeof(MyCubeGrid);
            var aMethod = t.GetMethod("BuildBlocksRequest", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            ctx.GetPattern(aMethod).Prefixes.Add(typeof(BuildBlockPatch).GetMethod(nameof(BuildBlocksRequest), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));
            var bMethod = t.GetMethod("BuildBlocksAreaRequest", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            ctx.GetPattern(bMethod).Prefixes.Add(typeof(BuildBlockPatch).GetMethod(nameof(BuildBlocksArea), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));
        }
Esempio n. 13
0
        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(typeof(MyEntity).GetMethod("Close", BindingFlags.Public | BindingFlags.Instance)).
            Prefixes.Add(typeof(GridChange).GetMethod(nameof(OnClose), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));

            ctx.GetPattern(ConvertToStationRequest).Prefixes.Add(typeof(GridChange).GetMethod(nameof(ToStatic), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));
            ctx.GetPattern(ConvertToShipRequest).Prefixes.Add(typeof(GridChange).GetMethod(nameof(ToDynamic), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));

            ctx.GetPattern(typeof(MyCubeGrid).GetMethod("MoveBlocks", BindingFlags.Static | BindingFlags.NonPublic)).Suffixes
            .Add(typeof(GridChange).GetMethod(nameof(OnCreateSplit), BindingFlags.Static | BindingFlags.NonPublic));
        }
Esempio n. 14
0
        private static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(typeof(MySlimBlock).GetMethod(nameof(MySlimBlock.TransferAuthorship), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)).
            Prefixes.Add(typeof(BlockOwnershipTransfer).GetMethod(nameof(OnTransfer), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));

            ctx.GetPattern(typeof(MyCubeGrid).GetMethod(nameof(MyCubeGrid.ChangeOwnerRequest), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)).
            Prefixes.Add(typeof(BlockOwnershipTransfer).GetMethod(nameof(ChangeOwner), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));

            ctx.GetPattern(typeof(MyCubeGrid).GetMethod("OnChangeOwnersRequest", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)).
            Prefixes.Add(typeof(BlockOwnershipTransfer).GetMethod(nameof(ChangeOwnersRequest), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));
        }
Esempio n. 15
0
        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(typeof(MyFactionCollection).GetMethod("FactionStateChangeRequest",
                                                                 BindingFlags.NonPublic | BindingFlags.Static)).Prefixes
            .Add(typeof(ReputationPatch).GetMethod(nameof(ChangeRequest), BindingFlags.NonPublic | BindingFlags.Static));

            ctx.GetPattern(typeof(MyFactionCollection).GetMethod(
                               nameof(MyFactionCollection.DamageFactionPlayerReputation),
                               BindingFlags.Public | BindingFlags.Instance))
            .Prefixes.Add(typeof(ReputationPatch).GetMethod(nameof(DamageFaction), BindingFlags.NonPublic | BindingFlags.Static));
        }
Esempio n. 16
0
        public static void Patch(PatchContext ctx)
        {
            var stepWorldsInternalPatchee = typeof(MyPhysics).GetInstanceMethod("StepWorldsInternal");
            var stepWorldsInternalPatcher = typeof(MyPhysics_StepWorlds).GetStaticMethod(nameof(StepWorldsInternalTranspiler));

            ctx.GetPattern(stepWorldsInternalPatchee).Transpilers.Add(stepWorldsInternalPatcher);

            var stepSingleWorldPatchee = typeof(MyPhysics).GetInstanceMethod("StepSingleWorld");
            var stepSingleWorldPrefix  = typeof(MyPhysics_StepWorlds).GetStaticMethod(nameof(StepSingleWorldPrefix));
            var stepSingleWorldSuffix  = typeof(MyPhysics_StepWorlds).GetStaticMethod(nameof(StepSingleWorldSuffix));

            ctx.GetPattern(stepSingleWorldPatchee).Prefixes.Add(stepSingleWorldPrefix);
            ctx.GetPattern(stepSingleWorldPatchee).Suffixes.Add(stepSingleWorldSuffix);
        }
        public static void Patch(PatchContext ctx)
        {
            ctx.GetPattern(typeof(MyProjectorBase).GetMethod("RemoveProjection", BindingFlags.Instance | BindingFlags.NonPublic)).
            Suffixes.Add(typeof(ProjectorPatch).GetMethod(nameof(IncreaseCount), BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));

            ctx.GetPattern(typeof(MyProjectorBase).GetMethod("InitializeClipboard", BindingFlags.Instance | BindingFlags.NonPublic)).
            Suffixes.Add(typeof(ProjectorPatch).GetMethod(nameof(DecreaseCount), BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));

            ctx.GetPattern(typeof(MyProjectorBase).GetMethod("BuildInternal", BindingFlags.Instance | BindingFlags.NonPublic)).
            Prefixes.Add(typeof(ProjectorPatch).GetMethod(nameof(ExtraCheck), BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance));

            ctx.GetPattern(typeof(MyProjectorBase).GetMethod("OnNewBlueprintSuccess", BindingFlags.Instance | BindingFlags.NonPublic)).
            Prefixes.Add(typeof(ProjectorPatch).GetMethod(nameof(PrefixNewBlueprint), BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
        }
        public static void Patch(PatchContext ctx)
        {
            try
            {
                var prefix = SelfType.GetStaticMethod(nameof(Prefix));
                var suffix = SelfType.GetStaticMethod(nameof(Suffix));

                ctx.GetPattern(Method).Prefixes.Add(prefix);
                ctx.GetPattern(Method).Suffixes.Add(suffix);
            }
            catch (Exception e)
            {
                Log.Error($"Failed to patch: {e.Message}");
            }
        }
Esempio n. 19
0
 private void SessionChanged(ITorchSession session, TorchSessionState state)
 {
     switch (state)
     {
     case TorchSessionState.Loaded:
         Task.Delay(3000).ContinueWith((t) =>
         {
             Log.Debug("Patching MyLargeTurretBasePatch");
             _ctx.GetPattern(MyLargeTurretBasePatch._updateAfterSimulation).Prefixes.Add(MyLargeTurretBasePatch._throttler1);
             _ctx.GetPattern(MyLargeTurretBasePatch._updateAfterSimulation10).Prefixes.Add(MyLargeTurretBasePatch._throttler10);
             _patchManager.Commit();
         });
         break;
     }
 }
Esempio n. 20
0
        internal static void Patch(PatchContext context)
        {
            var target      = typeof(MyMultiplayerBase).GetMethod("OnChatMessageRecieved_Server", BindingFlags.Static | BindingFlags.NonPublic);
            var patchMethod = typeof(ChatInterceptPatch).GetMethod(nameof(PrefixMessageProcessing), BindingFlags.Static | BindingFlags.NonPublic);

            context.GetPattern(target).Prefixes.Add(patchMethod);
        }
Esempio n. 21
0
        public static void Patch(PatchContext ctx)
        {
            Type type = Type.GetType("GameAnalyticsSDK.Net.Logging.GALogger, GameAnalytics.Mono");

            if (type == null)
            {
                return;
            }
            FieldInfo loggerField = type.GetField("logger",
                                                  BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);

            if (loggerField == null)
            {
                _log.Warn("GALogger logger field is unknown.  Logging may not function.");
                return;
            }
            RuntimeHelpers.RunClassConstructor(type.TypeHandle);
            _setLogger = loggerField?.CreateSetter <ILogger, ILogger>();
            FixLogging();

            ConstructorInfo ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[0], new ParameterModifier[0]);

            if (ctor == null)
            {
                _log.Warn("GALogger constructor is unknown.  Logging may not function.");
                return;
            }
            ctx.GetPattern(ctor).Prefixes.Add(typeof(GameAnalyticsPatch).GetMethod(nameof(PatchLogger),
                                                                                   BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public));
        }
Esempio n. 22
0
#pragma warning restore 649

        public static void Patch(PatchContext ctx)
        {
            _log.Info("Patching mods downloading");

            ctx.GetPattern(_downloadWorldModsBlockingMethod).Suffixes
            .Add(typeof(ModsDownloadingPatch).GetMethod(nameof(Postfix)));
        }
Esempio n. 23
0
        public static void Patch(PatchContext ctx)
        {
            var actionMethod = FindAction(Method);
            var transpiler   = SelfType.GetStaticMethod(nameof(Transpile));

            ctx.GetPattern(actionMethod).PostTranspilers.Add(transpiler);
        }
Esempio n. 24
0
        public static void Patch(PatchContext ptx)
        {
            var patchMethod = typeof(GameLoopObserver).GetMethod(nameof(OnSessionUpdate), BindingFlags.Static | BindingFlags.NonPublic);

            ptx.GetPattern(_sessionUpdateMethod).Suffixes.Add(patchMethod);
            _patched = true;
        }
Esempio n. 25
0
#pragma warning restore 649

        public override void Attach()
        {
            _log.Info("Injecting VR manager");

            _patchContext = _patcher.AcquireContext();

            _patchContext.GetPattern(_createOptionsControls).Suffixes.Add(MyMeth(nameof(FixOptionsControls)));
            _patchContext.GetPattern(_renderApplySettings).Prefixes.Add(MyMeth(nameof(InitStereoMode)));
#if SPACE
            CameraMatrixPatch.Patch(_patchContext);
#endif
            BasicRenderPatch.Patch(_patchContext);
            AmbientOcclusionPatch.Patch(_patchContext);
            MyGuiScreenOptionsDisplayVr.Patch(_patchContext);
//            UserInterfacePatch.Patch(_patchContext);
        }
Esempio n. 26
0
        public static void Patch(PatchContext ptx)
        {
            var patchee = typeof(MyCubeGrid).GetMethod("MoveBlocks", BindingFlags.Static | BindingFlags.NonPublic);
            var patcher = typeof(MyCubeGridPatch).GetMethod(nameof(MoveBlocksPostfix), BindingFlags.Static | BindingFlags.NonPublic);

            ptx.GetPattern(patchee).Suffixes.Add(patcher);
        }
Esempio n. 27
0
        public static void Patch(PatchContext ctx)
        {
            MethodInfo detach = typeof(MyMechanicalConnectionBlockBase).GetMethod("CreateTopPartAndAttach", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(long), typeof(bool), typeof(bool) }, null);

            ctx.GetPattern(detach).Prefixes.Add(detachDetection);

            Log.Debug("Patched MyMotorStator!");
        }
Esempio n. 28
0
        //internal static readonly MethodInfo update =
        //    typeof(MyProjectorBase).GetMethod("InitializeClipboard", BindingFlags.Instance | BindingFlags.NonPublic) ??
        //    throw new Exception("Failed to find patch method");

        //internal static readonly MethodInfo updatePatch =
        //    typeof(ProjectorPatch).GetMethod(nameof(TestPatchMethod), BindingFlags.Static | BindingFlags.Public) ??
        //    throw new Exception("Failed to find patch method");


        //internal static readonly MethodInfo remove =
        // typeof(MyProjectorBase).GetMethod("RemoveProjection", BindingFlags.Instance | BindingFlags.NonPublic) ??
        // throw new Exception("Failed to find patch method");

        //internal static readonly MethodInfo removePatch =
        //    typeof(ProjectorPatch).GetMethod(nameof(removeM), BindingFlags.Static | BindingFlags.Public) ??
        //    throw new Exception("Failed to find patch method");


        public static void Patch(PatchContext ctx)
        {
            //  ctx.GetPattern(update).Suffixes.Add(updatePatch);
            ctx.GetPattern(build).Prefixes.Add(buildPatch);
            //    ctx.GetPattern(remove).Prefixes.Add(removePatch);

            CrunchUtilitiesPlugin.Log.Info("Patching Successful Crunch Projector!");
        }
Esempio n. 29
0
        public static void Patch(PatchContext ctx)
        {
            var transpiler = typeof(ServerResponsePatch).GetMethod(nameof(Transpile), BindingFlags.Public | BindingFlags.Static);

            ctx.GetPattern(typeof(MyDedicatedServerBase).GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance))
            .Transpilers.Add(transpiler);
            _log.Info("Patching Steam response polling");
        }
Esempio n. 30
0
 public static void Patch(PatchContext ctx)
 {
     Log.Info("Patch init");
     ctx.GetPattern(typeof(MyProjectorBase).GetMethod("OnNewBlueprintSuccess",
                                                      BindingFlags.Instance | BindingFlags.NonPublic)).Prefixes.Add(
         typeof(ProjectorFixPatch).GetMethod(nameof(PrefixNewBlueprint),
                                             BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
 }