Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
 public override void Detach()
 {
     if (_patchContext != null)
     {
         _patcher.FreeContext(_patchContext);
     }
     _patcher.Commit();
 }
Exemplo n.º 3
0
 private void SessionChanged(ITorchSession session, TorchSessionState newState)
 {
     if (newState == TorchSessionState.Loaded)
     {
         MyCubeGridPatch.Patch(ctx);
         patchManager.Commit();
     }
 }
Exemplo n.º 4
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;
     }
 }