Example #1
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();
        }
Example #2
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();
        }