示例#1
0
        protected DeltaStreamServer()
        {
            _state = InjectorState.Starting;
            _defaultSessionReady = new TaskCompletionSource <DeltaBackendSession>();

            StartListening();
        }
示例#2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            if (e.Args.Length != 0)
            {
                bool injectMaterial = false;
                bool injectOnion    = false;
                bool recover        = false;

                foreach (var argument in e.Args.Select(arg => arg.ToLower()).ToList())
                {
                    if (InjectMaterialArgumentAliases.Contains(argument))
                    {
                        recover = injectMaterial = true;
                    }
                    else if (InjectOnionArgumentAliases.Contains(argument))
                    {
                        recover = injectOnion = true;
                    }
                    else if (RecoverArgumentAliases.Contains(argument))
                    {
                        recover = true;
                    }
                }

                if (injectMaterial || injectOnion || recover)
                {
                    Recover();

                    if (injectMaterial || injectOnion)
                    {
                        var state = new InjectorState
                        {
                            InjectMaterialColor = injectMaterial,
                            InjectOnion         = injectOnion,
                        };

                        Inject(state);

                        new InjectorStateManager(new JsonManager()).SaveState(state);
                    }

                    Shutdown();

                    return;
                }
            }

            try
            {
                new Bootstrapper().Run();
            }
            catch
            {
                Shutdown(1);
            }
        }
示例#3
0
        private async Task InjectorListenerLoop(CancellationToken ct = default)
        {
            _state = InjectorState.Starting;
            await CreateIncomingConnectionListener(ct);

            while (_state != InjectorState.Disconnected)
            {
                if (ct.IsCancellationRequested)
                {
                    _state = InjectorState.Disconnected;
                }
                await ListenForInjectorConnection(ct);
            }
        }
        public bool InjectDefaultAndBackup(InjectorState injectorState)
        {
            var coreModule     = CecilHelper.GetModule(Paths.DefaultCoreAssemblyPath, Paths.ManagedDirectoryPath);
            var materialModule = CecilHelper.GetModule(Paths.DefaultMaterialAssemblyPath, Paths.ManagedDirectoryPath);
            var onionModule    = CecilHelper.GetModule(Paths.DefaultOnionAssemblyPath, Paths.ManagedDirectoryPath);

            var csharpModule    = CecilHelper.GetModule(Paths.DefaultAssemblyCSharpPath, Paths.ManagedDirectoryPath);
            var firstPassModule = CecilHelper.GetModule(Paths.DefaultAssemblyFirstPassPath, Paths.ManagedDirectoryPath);

            var injection = new Injection(coreModule, materialModule, onionModule, csharpModule, firstPassModule)
            {
                Logger = Logger
            };

            injection.Inject(injectorState);

            BackupAndSaveCSharpModule(csharpModule);
            BackupAndSaveFirstPassModule(firstPassModule);

            return(injection.Failed);
        }
 public void SaveState(InjectorState state)
 {
     this._manager.Serialize(state, Paths.InjectorStatePath);
 }
示例#6
0
        // TODO: refactor
        public void Inject(InjectorState injectorState)
        {
            InjectCore();

            if (injectorState.FixLogicBridges)
            {
                MakeLogicBridgesPlaceableOnLogicGates();
            }

            if (injectorState.EnableImprovedOxygenOverlay)
            {
                try
                {
                    _csharpInstructionRemover.ClearAllButLast("SimDebugView", "GetOxygenMapColour");
                    _materialToCSharpInjector.InjectAsFirst("InjectionEntry", "EnterGasOverlay", "SimDebugView", "GetOxygenMapColour", includeArgumentCount: 1);
                }
                catch (Exception e)
                {
                    Logger.Log("Improved gas overlay injection failed");
                    Logger.Log(e);

                    Failed = true;
                }
            }

            if (injectorState.EnableDraggableGUI)
            {
                try
                {
                    var coreToFirstpass = new MethodInjector(_coreModule, _firstPassModule);

                    coreToFirstpass.InjectAsFirst("DraggablePanel", "Attach", "KScreen", "OnPrefabInit", includeCallingObject: true);

                    var kScreen     = _firstPassModule.Types.First(t => t.Name == "KScreen");
                    var onSpawnBody = kScreen.Methods.First(m => m.Name == "OnSpawn").Body;

                    var lastInstruction = onSpawnBody.Instructions.Last();

                    coreToFirstpass.InjectBefore("DraggablePanel", "SetPositionFromFile", onSpawnBody, lastInstruction, includeCallingObject: true);

                    var injectedCallFirstInstruction = onSpawnBody.Instructions.Last(i => i.OpCode == OpCodes.Ldarg_0);

                    foreach (var branch in onSpawnBody.Instructions.Where(i => i.OpCode == OpCodes.Brtrue || i.OpCode == OpCodes.Brfalse))
                    {
                        branch.Operand = injectedCallFirstInstruction;
                    }
                }
                catch (Exception e)
                {
                    Logger.Log("Draggable GUI injection failed");
                    Logger.Log(e);

                    Failed = true;
                }
            }

            if (injectorState.InjectMaterialColor)
            {
                InjectMain();
                InjectCellColorHandling();
                InjectBuildingsSpecialCasesHandling();

                try
                {
                    _materialToCSharpInjector.InjectAsFirst("InjectionEntry", "OverlayChangedEntry", "OverlayMenu", "OnOverlayChanged");
                }
                catch (Exception e)
                {
                    Logger.Log("OverlayChangedEntry injection failed");
                    Logger.Log(e);

                    Failed = true;
                }

                if (injectorState.InjectMaterialColorOverlayButton)
                {
                    try
                    {
                        InjectToggleButton();
                    }
                    catch (Exception e)
                    {
                        if (Logger != null)
                        {
                            Logger.Log("Overlay menu button injection failed");
                            Logger.Log(e);

                            Failed = true;
                        }
                    }
                }
            }

            if (injectorState.InjectOnion)
            {
                try
                {
                    InjectOnionPatcher();
                }
                catch (Exception e)
                {
                    Logger.Log("OnionPatcher injection failed");
                    Logger.Log(e);

                    Failed = true;
                }
            }

            if (injectorState.CustomSensorRanges)
            {
                ExpandTemperatureSensorRange(injectorState.MaxSensorTemperature);
                ExpandGasSensorPressureRange(injectorState.MaxGasSensorPressure);
                ExpandLiquidSensorPressureRange(injectorState.MaxLiquidSensorPressure);
            }

            InjectPatchedSign();
            FixGameUpdateExceptionHandling();
        }
示例#7
0
 private void Inject(InjectorState state)
 {
     new InjectionManager(FileManager).InjectDefaultAndBackup(state);
 }
示例#8
0
        // TODO: refactor
        public void Inject(InjectorState injectorState)
        {
            InjectCore();

            if (injectorState.FixLogicBridges)
            {
                MakeLogicBridgesPlaceableOnLogicGates();
            }

            if (injectorState.EnableImprovedOxygenOverlay)
            {
                try
                {
                    _csharpInstructionRemover.ClearAllButLast("SimDebugView", "GetOxygenMapColour");
                    _materialToCSharpInjector.InjectAsFirst("InjectionEntry", "EnterGasOverlay", "SimDebugView", "GetOxygenMapColour", includeArgumentCount: 1);
                }
                catch (Exception e)
                {
                    Logger.Log("Improved gas overlay injection failed");
                    Logger.Log(e);

                    Failed = true;
                }
            }

            if (injectorState.EnableDraggableGUI)
            {
                try
                {
                    var coreToFirstpass = new MethodInjector(_coreModule, _firstPassModule);
                    coreToFirstpass.InjectAsFirst("DraggablePanel", "Attach", "KScreen", "OnPrefabInit", includeCallingObject: true);
                }
                catch (Exception e)
                {
                    Logger.Log("Draggable GUI injection failed");
                    Logger.Log(e);

                    Failed = true;
                }
            }

            if (injectorState.InjectMaterialColor)
            {
                InjectMain();
                InjectCellColorHandling();
                InjectBuildingsSpecialCasesHandling();

                try
                {
                    _materialToCSharpInjector.InjectAsFirst("InjectionEntry", "OverlayChangedEntry", "OverlayMenu", "OnOverlayChanged");
                }
                catch (Exception e)
                {
                    Logger.Log("OverlayChangedEntry injection failed");
                    Logger.Log(e);

                    Failed = true;
                }

                if (injectorState.InjectMaterialColorOverlayButton)
                {
                    try
                    {
                        InjectToggleButton();
                    }
                    catch (Exception e)
                    {
                        if (Logger != null)
                        {
                            Logger.Log("Overlay menu button injection failed");
                            Logger.Log(e);

                            Failed = true;
                        }
                    }
                }
            }

            if (injectorState.InjectOnion)
            {
                InjectOnionPatcher();
            }

            if (injectorState.CustomSensorRanges)
            {
                ExpandTemperatureSensorRange(injectorState.MaxSensorTemperature);
                ExpandGasSensorPressureRange(injectorState.MaxGasSensorPressure);
                ExpandLiquidSensorPressureRange(injectorState.MaxLiquidSensorPressure);
            }

            InjectPatchedSign();
            FixGameUpdateExceptionHandling();
        }
示例#9
0
        private async Task CreateIncomingConnectionListener(CancellationToken ct = default)
        {
            await OnCreateIncomingConnectionListener(ct);

            _state = InjectorState.Listening;
        }