Beispiel #1
0
        static MASIFAR()
        {
            farFound = false;
#if !UNSUPPORT_FAR
            Type farAPI_t = Utility.GetExportedType("FerramAerospaceResearch", "FerramAerospaceResearch.FARAPI");
            if (farAPI_t != null)
            {
                MethodInfo coeffBallistic_t = farAPI_t.GetMethod("VesselBallisticCoeff", BindingFlags.Static | BindingFlags.Public);
                if (coeffBallistic_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselBallisticCoeff' in FAR");
                    return;
                }
                VesselCoeffBallistic = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), coeffBallistic_t, false);
                if (VesselCoeffBallistic == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselBallisticCoeff' in FAR");
                    return;
                }

                MethodInfo coeffDrag_t = farAPI_t.GetMethod("VesselDragCoeff", BindingFlags.Static | BindingFlags.Public);
                if (coeffDrag_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselDragCoeff' in FAR");
                    return;
                }
                VesselCoeffDrag = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), coeffDrag_t, false);
                if (VesselCoeffDrag == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselCoeffDrag' in FAR");
                    return;
                }

                MethodInfo coeffLift_t = farAPI_t.GetMethod("VesselLiftCoeff", BindingFlags.Static | BindingFlags.Public);
                if (coeffLift_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselLiftCoeff' in FAR");
                    return;
                }
                VesselCoeffLift = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), coeffLift_t, false);
                if (VesselCoeffLift == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselCoeffLift' in FAR");
                    return;
                }

                MethodInfo aoA_t = farAPI_t.GetMethod("VesselAoA", BindingFlags.Static | BindingFlags.Public);
                if (aoA_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselAoA' in FAR");
                    return;
                }
                VesselAoA = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), aoA_t, false);
                if (VesselAoA == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselAoA' in FAR");
                    return;
                }

                MethodInfo dynPress_t = farAPI_t.GetMethod("VesselDynPres", BindingFlags.Static | BindingFlags.Public);
                if (dynPress_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselDynPres' in FAR");
                    return;
                }
                VesselDynPress = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), dynPress_t, false);
                if (VesselDynPress == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselDynPress' in FAR");
                    return;
                }

                MethodInfo refArea_t = farAPI_t.GetMethod("VesselRefArea", BindingFlags.Static | BindingFlags.Public);
                if (refArea_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselRefArea' in FAR");
                    return;
                }
                VesselRefArea = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), refArea_t, false);
                if (VesselRefArea == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselRefArea' in FAR");
                    return;
                }

                MethodInfo stallFrac_t = farAPI_t.GetMethod("VesselStallFrac", BindingFlags.Static | BindingFlags.Public);
                if (stallFrac_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselStallFrac' in FAR");
                    return;
                }
                VesselStallFrac = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), stallFrac_t, false);
                if (VesselStallFrac == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselStallFrac' in FAR");
                    return;
                }

                MethodInfo termVel_t = farAPI_t.GetMethod("VesselTermVelEst", BindingFlags.Static | BindingFlags.Public);
                if (termVel_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselTermVelEst' in FAR");
                    return;
                }
                VesselTerminalVelocity = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), termVel_t, false);
                if (VesselTerminalVelocity == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselTerminalVelocity' in FAR");
                    return;
                }

                MethodInfo flapSetting_t = farAPI_t.GetMethod("VesselFlapSetting", BindingFlags.Static | BindingFlags.Public);
                if (flapSetting_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselFlapSetting' in FAR");
                    return;
                }
                VesselFlapSetting = (Func <Vessel, int>)Delegate.CreateDelegate(typeof(Func <Vessel, int>), flapSetting_t, false);
                if (VesselFlapSetting == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselFlapSetting' in FAR");
                    return;
                }

                MethodInfo decreaseFlapSetting_t = farAPI_t.GetMethod("VesselDecreaseFlapDeflection", BindingFlags.Static | BindingFlags.Public);
                if (decreaseFlapSetting_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselDecreaseFlapDeflection' in FAR");
                    return;
                }
                VesselDecreaseFlapDeflection = (Action <Vessel>)Delegate.CreateDelegate(typeof(Action <Vessel>), decreaseFlapSetting_t, false);
                if (VesselDecreaseFlapDeflection == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselDecreaseFlapDeflection' in FAR");
                    return;
                }

                MethodInfo increaseFlapSetting_t = farAPI_t.GetMethod("VesselIncreaseFlapDeflection", BindingFlags.Static | BindingFlags.Public);
                if (increaseFlapSetting_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselIncreaseFlapDeflection' in FAR");
                    return;
                }
                VesselIncreaseFlapDeflection = (Action <Vessel>)Delegate.CreateDelegate(typeof(Action <Vessel>), increaseFlapSetting_t, false);
                if (VesselIncreaseFlapDeflection == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselIncreaseFlapDeflection' in FAR");
                    return;
                }

                MethodInfo spoilerSetting_t = farAPI_t.GetMethod("VesselSpoilerSetting", BindingFlags.Static | BindingFlags.Public);
                if (spoilerSetting_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselSpoilerSetting' in FAR");
                    return;
                }
                VesselSpoilerSetting = (Func <Vessel, bool>)Delegate.CreateDelegate(typeof(Func <Vessel, bool>), spoilerSetting_t, false);
                if (VesselSpoilerSetting == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselSpoilerSetting' in FAR");
                    return;
                }

                MethodInfo setSpoiler_t = farAPI_t.GetMethod("VesselSetSpoilers", BindingFlags.Static | BindingFlags.Public);
                if (setSpoiler_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselSetSpoilers' in FAR");
                    return;
                }
                VesselSetSpoilers = (Action <Vessel, bool>)Delegate.CreateDelegate(typeof(Action <Vessel, bool>), setSpoiler_t, false);
                if (VesselSetSpoilers == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselSetSpoilers' in FAR");
                    return;
                }

                MethodInfo sideslip_t = farAPI_t.GetMethod("VesselSideslip", BindingFlags.Static | BindingFlags.Public);
                if (sideslip_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselSideslip' in FAR");
                    return;
                }
                VesselSideSlip = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), sideslip_t, false);
                if (VesselSideSlip == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselSideSlip' in FAR");
                    return;
                }

                MethodInfo specFuelConsumption_t = farAPI_t.GetMethod("VesselTSFC", BindingFlags.Static | BindingFlags.Public);
                if (specFuelConsumption_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselTSFC' in FAR");
                    return;
                }
                VesselSpecFuelConsumption = (Func <Vessel, double>)Delegate.CreateDelegate(typeof(Func <Vessel, double>), specFuelConsumption_t, false);
                if (VesselSpecFuelConsumption == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselSpecFuelConsumption' in FAR");
                    return;
                }

                MethodInfo flightInfo_t = farAPI_t.GetMethod("VesselFlightInfo", BindingFlags.Static | BindingFlags.Public);
                if (flightInfo_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselFlightInfo' in FAR");
                    return;
                }
                VesselFlightInfo = (Func <Vessel, object>)Delegate.CreateDelegate(typeof(Func <Vessel, object>), flightInfo_t, false);
                if (VesselFlightInfo == null)
                {
                    Utility.LogStaticError("Failed to configure 'VesselFlightInfo' in FAR");
                    return;
                }

                Type flightGUI_t = Utility.GetExportedType("FerramAerospaceResearch", "FerramAerospaceResearch.FARGUI.FARFlightGUI.FlightGUI");
                if (flightGUI_t == null)
                {
                    Utility.LogStaticError("Failed to find 'FlightGUI' in FAR");
                    return;
                }
                PropertyInfo infoParam_t = flightGUI_t.GetProperty("InfoParameters", BindingFlags.Instance | BindingFlags.Public);
                if (infoParam_t == null)
                {
                    Utility.LogStaticError("Failed to find 'InfoParameters' in FAR");
                    return;
                }
                MethodInfo getInfo_t = infoParam_t.GetGetMethod();
                if (getInfo_t == null)
                {
                    Utility.LogStaticError("Failed to find 'InfoParameters' get method in FAR");
                    return;
                }
                GetInfoParameters = DynamicMethodFactory.CreateFunc <object, object>(getInfo_t);
                if (GetInfoParameters == null)
                {
                    Utility.LogStaticError("Failed to configure 'GetInfoParameters' in FAR");
                    return;
                }

                Type FlightInfo_t = Utility.GetExportedType("FerramAerospaceResearch", "FerramAerospaceResearch.FARGUI.FARFlightGUI.VesselFlightInfo");
                if (FlightInfo_t == null)
                {
                    Utility.LogStaticError("Failed to find 'VesselFlightInfo' in FAR");
                    return;
                }
                FieldInfo DragForceFieldInfo = FlightInfo_t.GetField("dragForce");
                if (DragForceFieldInfo == null)
                {
                    Utility.LogStaticError("Failed to find 'dragForce' field in FAR");
                    return;
                }
                GetDragForce = DynamicMethodFactory.CreateGetField <object, double>(DragForceFieldInfo);
                FieldInfo LiftForceFieldInfo = FlightInfo_t.GetField("liftForce");
                if (LiftForceFieldInfo == null)
                {
                    Utility.LogStaticError("Failed to find 'liftForce' field in FAR");
                    return;
                }
                GetLiftForce = DynamicMethodFactory.CreateGetField <object, double>(LiftForceFieldInfo);

                farFound = true;
            }
#endif
        }
Beispiel #2
0
        internal MASPageText(ConfigNode config, InternalProp prop, MASFlightComputer comp, MASMonitor monitor, Transform pageRoot, float depth)
            : base(config, prop, comp)
        {
            if (!config.TryGetValue("text", ref text))
            {
                string textfile = string.Empty;
                if (!config.TryGetValue("textfile", ref textfile))
                {
                    string rpmModText = string.Empty;
                    if (!config.TryGetValue("textmethod", ref rpmModText))
                    {
                        throw new ArgumentException("Unable to find 'text', 'textfile', or 'textmethod' in TEXT " + name);
                    }

                    string[] rpmMod = rpmModText.Split(':');
                    if (rpmMod.Length != 2)
                    {
                        throw new ArgumentException("Invalid 'textmethod' in TEXT " + name);
                    }
                    bool moduleFound = false;

                    int numModules = prop.internalModules.Count;
                    int moduleIndex;
                    for (moduleIndex = 0; moduleIndex < numModules; ++moduleIndex)
                    {
                        if (prop.internalModules[moduleIndex].ClassName == rpmMod[0])
                        {
                            moduleFound = true;
                            break;
                        }
                    }

                    if (moduleFound)
                    {
                        rpmModule = prop.internalModules[moduleIndex];
                        Type       moduleType = prop.internalModules[moduleIndex].GetType();
                        MethodInfo method     = moduleType.GetMethod(rpmMod[1]);
                        if (method != null && method.GetParameters().Length == 2 && method.GetParameters()[0].ParameterType == typeof(int) && method.GetParameters()[1].ParameterType == typeof(int))
                        {
                            rpmModuleTextMethod = DynamicMethodFactory.CreateFunc <object, int, int, string>(method);
                        }
                    }

                    if (rpmModuleTextMethod != null)
                    {
                        this.comp = comp;
                        this.prop = prop;
                    }
                    text = " ";
                }
                else
                {
                    // Load text
                    text = string.Join(Environment.NewLine, File.ReadAllLines(KSPUtil.ApplicationRootPath + "GameData/" + textfile.Trim(), Encoding.UTF8));
                }
            }

            string localFonts = string.Empty;

            if (!config.TryGetValue("font", ref localFonts))
            {
                localFonts = string.Empty;
            }

            string    styleStr = string.Empty;
            FontStyle style    = FontStyle.Normal;

            if (config.TryGetValue("style", ref styleStr))
            {
                style = MdVTextMesh.FontStyle(styleStr);
            }
            else
            {
                style = monitor.defaultStyle;
            }

            Vector2 fontSize = Vector2.zero;

            if (!config.TryGetValue("fontSize", ref fontSize) || fontSize.x < 0.0f || fontSize.y < 0.0f)
            {
                fontSize = monitor.fontSize;
            }

            Color32 textColor;
            string  textColorStr = string.Empty;

            if (!config.TryGetValue("textColor", ref textColorStr) || string.IsNullOrEmpty(textColorStr))
            {
                textColor = monitor.textColor_;
            }
            else
            {
                textColor = Utility.ParseColor32(textColorStr, comp);
            }

            // Position is based on default font size
            fontScale = monitor.fontSize;
            // Position is based on local font size.
            //fontScale = fontSize;

            string variableName = string.Empty;

            if (config.TryGetValue("variable", ref variableName))
            {
                variableName = variableName.Trim();
            }

            // Set up our text.
            imageOrigin = pageRoot.position + new Vector3(monitor.screenSize.x * -0.5f, monitor.screenSize.y * 0.5f, depth);

            meshObject                    = new GameObject();
            meshObject.name               = Utility.ComposeObjectName(pageRoot.gameObject.name, this.GetType().Name, name, (int)(-depth / MASMonitor.depthDelta));
            meshObject.layer              = pageRoot.gameObject.layer;
            meshObject.transform.parent   = pageRoot;
            meshObject.transform.position = imageOrigin;

            string positionString = string.Empty;

            if (config.TryGetValue("position", ref positionString))
            {
                string[] positions = Utility.SplitVariableList(positionString);
                if (positions.Length != 2)
                {
                    throw new ArgumentException("position does not contain 2 values in TEXT " + name);
                }

                variableRegistrar.RegisterVariableChangeCallback(positions[0], (double newValue) =>
                {
                    position.x = (float)newValue * fontScale.x;
                    meshObject.transform.position = imageOrigin + new Vector3(position.x, -position.y, 0.0f);
                });

                variableRegistrar.RegisterVariableChangeCallback(positions[1], (double newValue) =>
                {
                    position.y = (float)newValue * fontScale.y;
                    meshObject.transform.position = imageOrigin + new Vector3(position.x, -position.y, 0.0f);
                });
            }

            textObj = meshObject.gameObject.AddComponent <MdVTextMesh>();

            Font font;

            if (string.IsNullOrEmpty(localFonts))
            {
                font = monitor.defaultFont;
            }
            else
            {
                font = MASLoader.GetFont(localFonts.Trim());
            }

            // We want to use a different shader for monitor displays.
            textObj.material = new Material(MASLoader.shaders["MOARdV/TextMonitor"]);
            textObj.SetFont(font, fontSize);
            textObj.SetColor(textColor);
            textObj.material.SetFloat(Shader.PropertyToID("_EmissiveFactor"), 1.0f);
            textObj.fontStyle = style;

            // text, immutable, preserveWhitespace, comp, prop
            textObj.SetText(text, false, true, comp, prop);
            RenderPage(false);

            if (!string.IsNullOrEmpty(variableName))
            {
                // Disable the mesh if we're in variable mode
                meshObject.SetActive(false);
                variableRegistrar.RegisterVariableChangeCallback(variableName, VariableCallback);
            }
            else
            {
                currentState = true;
            }

            if (rpmModuleTextMethod != null)
            {
                comp.StartCoroutine(TextMethodUpdate());
            }
        }
        internal MASPageRpmModule(ConfigNode config, InternalProp prop, MASFlightComputer comp, MASMonitor monitor, Transform pageRoot, float depth)
            : base(config, prop, comp)
        {
            this.comp = comp;

            Vector2 size = Vector2.zero;

            if (!config.TryGetValue("size", ref size))
            {
                size = monitor.screenSize;
            }

            string variableName = string.Empty;

            if (config.TryGetValue("variable", ref variableName))
            {
                variableName = variableName.Trim();
            }

            displayTexture = new RenderTexture(((int)size.x) >> MASConfig.CameraTextureScale, ((int)size.y) >> MASConfig.CameraTextureScale, 24, RenderTextureFormat.ARGB32);
            displayTexture.Create();

            string moduleNameString = string.Empty;

            if (!config.TryGetValue("moduleName", ref moduleNameString))
            {
                throw new ArgumentException("Unable to find 'moduleName' in RPM_MODULE " + name);
            }

            bool moduleFound = false;

            int numModules = prop.internalModules.Count;
            int moduleIndex;

            for (moduleIndex = 0; moduleIndex < numModules; ++moduleIndex)
            {
                if (prop.internalModules[moduleIndex].ClassName == moduleNameString)
                {
                    moduleFound = true;
                    break;
                }
            }

            if (moduleFound)
            {
                rpmModule = prop.internalModules[moduleIndex];
                Type moduleType = prop.internalModules[moduleIndex].GetType();

                string renderMethodName = string.Empty;
                if (config.TryGetValue("renderMethod", ref renderMethodName))
                {
                    MethodInfo method = moduleType.GetMethod(renderMethodName);
                    if (method != null && method.GetParameters().Length == 2 && method.GetParameters()[0].ParameterType == typeof(RenderTexture) && method.GetParameters()[1].ParameterType == typeof(float))
                    {
                        renderMethod = DynamicMethodFactory.CreateFunc <object, RenderTexture, float, object>(method);
                    }

                    if (renderMethod != null)
                    {
                        Vector2 renderSize = Vector2.zero;
                        if (!config.TryGetValue("renderSize", ref renderSize))
                        {
                            renderSize = size;
                        }

                        if (renderSize != size)
                        {
                            temporarySizeX      = (int)renderSize.x;
                            temporarySizeY      = (int)renderSize.y;
                            useTemporaryTexture = true;

                            float xScaling = size.x / renderSize.x;
                            float yScaling = size.y / renderSize.y;

                            float aspectRatio = xScaling / yScaling;
                            if (aspectRatio > 1.0f)
                            {
                                // wide aspect ratio
                                uvScale.y  = 1.0f / aspectRatio;
                                uvOffset.y = uvScale.y * 0.5f;
                            }
                            else if (aspectRatio < 1.0f)
                            {
                                uvScale.x  = aspectRatio;
                                uvOffset.x = uvScale.x * 0.5f;
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Unable to initialize 'renderMethod' " + renderMethodName + " in RPM_MODULE " + name);
                    }
                }

                string pageActiveMethodName = string.Empty;
                if (config.TryGetValue("pageActiveMethod", ref pageActiveMethodName))
                {
                    MethodInfo method = moduleType.GetMethod(pageActiveMethodName);
                    if (method != null && method.GetParameters().Length == 2 && method.GetParameters()[0].ParameterType == typeof(bool) && method.GetParameters()[1].ParameterType == typeof(int))
                    {
                        pageActiveMethod = DynamicMethodFactory.CreateFunc <object, bool, int, object>(method);
                    }
                    else
                    {
                        throw new ArgumentException("Unable to initialize 'pageActiveMethod' " + pageActiveMethodName + " in RPM_MODULE " + name);
                    }
                }

                string buttonClickMethodName = string.Empty;
                if (config.TryGetValue("buttonClickMethod", ref buttonClickMethodName))
                {
                    MethodInfo method = moduleType.GetMethod(buttonClickMethodName);
                    if (method != null && method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(int))
                    {
                        buttonClickMethod = DynamicMethodFactory.CreateDynFunc <object, int, object>(method);
                    }
                }
            }
            else
            {
                string textureName = string.Empty;
                if (config.TryGetValue("texture", ref textureName))
                {
                    Texture missingTexture = GameDatabase.Instance.GetTexture(textureName, false);
                    if (missingTexture != null)
                    {
                        Graphics.Blit(missingTexture, displayTexture);
                    }
                }
            }

            componentOrigin = pageRoot.position + new Vector3(monitor.screenSize.x * -0.5f + size.x * 0.5f, monitor.screenSize.y * 0.5f - size.y * 0.5f, depth);

            // Set up our surface.
            imageObject                    = new GameObject();
            imageObject.name               = Utility.ComposeObjectName(pageRoot.gameObject.name, this.GetType().Name, name, (int)(-depth / MASMonitor.depthDelta));
            imageObject.layer              = pageRoot.gameObject.layer;
            imageObject.transform.parent   = pageRoot;
            imageObject.transform.position = pageRoot.position;
            imageObject.transform.Translate(monitor.screenSize.x * -0.5f + position.x + size.x * 0.5f, monitor.screenSize.y * 0.5f - position.y - size.y * 0.5f, depth);
            // add renderer stuff
            MeshFilter meshFilter = imageObject.AddComponent <MeshFilter>();

            meshRenderer = imageObject.AddComponent <MeshRenderer>();
            Mesh mesh = new Mesh();

            mesh.vertices = new[]
            {
                new Vector3(-0.5f * size.x, 0.5f * size.y, depth),
                new Vector3(0.5f * size.x, 0.5f * size.y, depth),
                new Vector3(-0.5f * size.x, -0.5f * size.y, depth),
                new Vector3(0.5f * size.x, -0.5f * size.y, depth),
            };
            mesh.uv = new[]
            {
                new Vector2(0.0f, 1.0f),
                Vector2.one,
                Vector2.zero,
                new Vector2(1.0f, 0.0f),
            };
            mesh.triangles = new[]
            {
                0, 1, 2,
                1, 3, 2
            };
            mesh.RecalculateBounds();
            mesh.UploadMeshData(true);
            meshFilter.mesh = mesh;

            string positionString = string.Empty;

            if (!config.TryGetValue("position", ref positionString))
            {
                positionString = "0,0";
            }

            string[] pos = Utility.SplitVariableList(positionString);
            if (pos.Length != 2)
            {
                throw new ArgumentException("Invalid number of values for 'position' in RPM_MODULE " + name);
            }

            variableRegistrar.RegisterVariableChangeCallback(pos[0], (double newValue) =>
            {
                position.x = (float)newValue;
                imageObject.transform.position = componentOrigin + new Vector3(position.x, -position.y, 0.0f);
            });

            variableRegistrar.RegisterVariableChangeCallback(pos[1], (double newValue) =>
            {
                position.y = (float)newValue;
                imageObject.transform.position = componentOrigin + new Vector3(position.x, -position.y, 0.0f);
            });

            imageMaterial             = new Material(MASLoader.shaders["MOARdV/Monitor"]);
            imageMaterial.mainTexture = displayTexture;
            meshRenderer.material     = imageMaterial;
            RenderPage(false);

            if (!string.IsNullOrEmpty(variableName))
            {
                // Disable the mesh if we're in variable mode
                imageObject.SetActive(false);
                variableRegistrar.RegisterVariableChangeCallback(variableName, VariableCallback);
            }
            else
            {
                currentState = true;
                imageObject.SetActive(true);
            }

            if (renderMethod != null)
            {
                comp.StartCoroutine(QueryModule());
            }
        }
Beispiel #4
0
        static MASIVTOL()
        {
            wbiVtolManager_t = Utility.GetExportedType("KerbalActuators", "KerbalActuators.WBIVTOLManager");

            if (wbiVtolManager_t != null)
            {
                // Init
                MethodInfo FindControllers_t = wbiVtolManager_t.GetMethod("FindControllers", BindingFlags.Instance | BindingFlags.Public);
                if (FindControllers_t == null)
                {
                    Utility.LogStaticError("Didn't find FindControllers");
                    return;
                }
                wbiFindControllers = DynamicMethodFactory.CreateAction <object, Vessel>(FindControllers_t);

                // Capabilities
                MethodInfo AirParkControllerActive_t = wbiVtolManager_t.GetMethod("AirParkControllerActive", BindingFlags.Instance | BindingFlags.Public);
                if (AirParkControllerActive_t != null)
                {
                    wbiAirParkAvailable = DynamicMethodFactory.CreateFunc <object, bool>(AirParkControllerActive_t);
                }
                else
                {
                    Utility.LogStaticError("Didn't find AirParkControllerActive");
                    return;
                }
                MethodInfo HoverControllerActive_t = wbiVtolManager_t.GetMethod("HoverControllerActive", BindingFlags.Instance | BindingFlags.Public);
                if (HoverControllerActive_t != null)
                {
                    wbiHoverControllerAvailable = DynamicMethodFactory.CreateFunc <object, bool>(HoverControllerActive_t);
                }
                else
                {
                    Utility.LogStaticError("Didn't find HoverControllerActive");
                    return;
                }
                MethodInfo HasRotationControllers_t = wbiVtolManager_t.GetMethod("HasRotationControllers", BindingFlags.Instance | BindingFlags.Public);
                if (HasRotationControllers_t != null)
                {
                    wbiRotationControllerAvailable = DynamicMethodFactory.CreateFunc <object, bool>(HasRotationControllers_t);
                }
                else
                {
                    Utility.LogStaticError("Didn't find HasRotationControllers");
                    return;
                }
                MethodInfo ThrustVectorControllerActive_t = wbiVtolManager_t.GetMethod("ThrustVectorControllerActive", BindingFlags.Instance | BindingFlags.Public);
                if (ThrustVectorControllerActive_t != null)
                {
                    wbiThrustControllerAvailable = DynamicMethodFactory.CreateFunc <object, bool>(ThrustVectorControllerActive_t);
                }
                else
                {
                    Utility.LogStaticError("Didn't find ThrustVectorControllerActive");
                    return;
                }

                // Air Park
                MethodInfo IsParked_t = wbiVtolManager_t.GetMethod("IsParked", BindingFlags.Instance | BindingFlags.Public);
                if (IsParked_t == null)
                {
                    Utility.LogStaticError("Didn't find IsParked");
                    return;
                }
                wbiGetParkActive = DynamicMethodFactory.CreateFunc <object, bool>(IsParked_t);

                MethodInfo TogglePark_t = wbiVtolManager_t.GetMethod("TogglePark", BindingFlags.Instance | BindingFlags.Public);
                if (TogglePark_t == null)
                {
                    Utility.LogStaticError("Didn't find TogglePark");
                    return;
                }
                wbiTogglePark = DynamicMethodFactory.CreateAction <object>(TogglePark_t);

                // Hover
                MethodInfo EnginesAreActive_t = wbiVtolManager_t.GetMethod("EnginesAreActive", BindingFlags.Instance | BindingFlags.Public);
                if (EnginesAreActive_t == null)
                {
                    Utility.LogStaticError("Didn't find EnginesAreActive");
                    return;
                }
                wbiEnginesAreActive = DynamicMethodFactory.CreateFunc <object, bool>(EnginesAreActive_t);

                MethodInfo StartEngines_t = wbiVtolManager_t.GetMethod("StartEngines", BindingFlags.Instance | BindingFlags.Public);
                if (StartEngines_t == null)
                {
                    Utility.LogStaticError("Didn't find StartEngines");
                    return;
                }
                wbiStartEngines = DynamicMethodFactory.CreateAction <object>(StartEngines_t);

                MethodInfo StopEngines_t = wbiVtolManager_t.GetMethod("StopEngines", BindingFlags.Instance | BindingFlags.Public);
                if (StopEngines_t == null)
                {
                    Utility.LogStaticError("Didn't find StopEngines");
                    return;
                }
                wbiStopEngines = DynamicMethodFactory.CreateAction <object>(StopEngines_t);

                FieldInfo HoverActive_t = wbiVtolManager_t.GetField("hoverActive", BindingFlags.Instance | BindingFlags.Public);
                if (HoverActive_t == null)
                {
                    Utility.LogStaticError("Didn't find hoverActive");
                    return;
                }
                wbiGetHoverActive = DynamicMethodFactory.CreateGetField <object, bool>(HoverActive_t);

                MethodInfo ToggleHover_t = wbiVtolManager_t.GetMethod("ToggleHover", BindingFlags.Instance | BindingFlags.Public);
                if (ToggleHover_t == null)
                {
                    Utility.LogStaticError("Didn't find ToggleHover");
                    return;
                }
                wbiToggleHover = DynamicMethodFactory.CreateAction <object>(ToggleHover_t);

                // Rotation
                MethodInfo CanRotateMax_t = wbiVtolManager_t.GetMethod("CanRotateMax", BindingFlags.Instance | BindingFlags.Public);
                if (CanRotateMax_t == null)
                {
                    Utility.LogStaticError("Didn't find CanRotateMax");
                    return;
                }
                wbiCanRotateMax = DynamicMethodFactory.CreateFunc <object, bool>(CanRotateMax_t);

                MethodInfo CanRotateMin_t = wbiVtolManager_t.GetMethod("CanRotateMin", BindingFlags.Instance | BindingFlags.Public);
                if (CanRotateMin_t == null)
                {
                    Utility.LogStaticError("Didn't find CanRotateMin");
                    return;
                }
                wbiCanRotateMin = DynamicMethodFactory.CreateFunc <object, bool>(CanRotateMin_t);

                MethodInfo RotateToMax_t = wbiVtolManager_t.GetMethod("RotateToMax", BindingFlags.Instance | BindingFlags.Public);
                if (RotateToMax_t == null)
                {
                    Utility.LogStaticError("Didn't find RotateToMax");
                    return;
                }
                wbiRotateMax = DynamicMethodFactory.CreateAction <object>(RotateToMax_t);

                MethodInfo RotateToMin_t = wbiVtolManager_t.GetMethod("RotateToMin", BindingFlags.Instance | BindingFlags.Public);
                if (RotateToMin_t == null)
                {
                    Utility.LogStaticError("Didn't find RotateToMin");
                    return;
                }
                wbiRotateMin = DynamicMethodFactory.CreateAction <object>(RotateToMin_t);

                MethodInfo RotateToNeutral_t = wbiVtolManager_t.GetMethod("RotateToNeutral", BindingFlags.Instance | BindingFlags.Public);
                if (ToggleHover_t == null)
                {
                    Utility.LogStaticError("Didn't find RotateToNeutral");
                    return;
                }
                wbiRotateNeutral = DynamicMethodFactory.CreateAction <object>(RotateToNeutral_t);

                MethodInfo IncreaseRotationAngle_t = wbiVtolManager_t.GetMethod("IncreaseRotationAngle", BindingFlags.Instance | BindingFlags.Public);
                if (IncreaseRotationAngle_t == null)
                {
                    Utility.LogStaticError("Didn't find IncreaseRotationAngle");
                    return;
                }
                wbiIncreaseRotationAngle = DynamicMethodFactory.CreateAction <object, float>(IncreaseRotationAngle_t);

                MethodInfo DecreaseRotationAngle_t = wbiVtolManager_t.GetMethod("DecreaseRotationAngle", BindingFlags.Instance | BindingFlags.Public);
                if (DecreaseRotationAngle_t == null)
                {
                    Utility.LogStaticError("Didn't find DecreaseRotationAngle");
                    return;
                }
                wbiDecreaseRotationAngle = DynamicMethodFactory.CreateAction <object, float>(DecreaseRotationAngle_t);

                MethodInfo GetMaxRotation_t = wbiVtolManager_t.GetMethod("GetMaxRotation", BindingFlags.Instance | BindingFlags.Public);
                if (GetMaxRotation_t == null)
                {
                    Utility.LogStaticError("Didn't find GetMaxRotation");
                    return;
                }
                wbiGetMaxRotation = DynamicMethodFactory.CreateFunc <object, float>(GetMaxRotation_t);

                MethodInfo GetMinRotation_t = wbiVtolManager_t.GetMethod("GetMinRotation", BindingFlags.Instance | BindingFlags.Public);
                if (GetMinRotation_t == null)
                {
                    Utility.LogStaticError("Didn't find GetMinRotation");
                    return;
                }
                wbiGetMinRotation = DynamicMethodFactory.CreateFunc <object, float>(GetMinRotation_t);

                MethodInfo GetCurrentRotation_t = wbiVtolManager_t.GetMethod("GetCurrentRotation", BindingFlags.Instance | BindingFlags.Public);
                if (GetCurrentRotation_t == null)
                {
                    Utility.LogStaticError("Didn't find GetCurrentRotation");
                    return;
                }
                wbiGetCurrentRotation = DynamicMethodFactory.CreateFunc <object, float>(GetCurrentRotation_t);

                // VSpd
                MethodInfo KillVerticalSpeed_t = wbiVtolManager_t.GetMethod("KillVerticalSpeed", BindingFlags.Instance | BindingFlags.Public);
                if (KillVerticalSpeed_t == null)
                {
                    Utility.LogStaticError("Didn't find KillVerticalSpeed");
                    return;
                }
                wbiKillVerticalSpeed = DynamicMethodFactory.CreateAction <object>(KillVerticalSpeed_t);

                MethodInfo IncreaseVerticalSpeed_t = wbiVtolManager_t.GetMethod("IncreaseVerticalSpeed", BindingFlags.Instance | BindingFlags.Public);
                if (IncreaseVerticalSpeed_t == null)
                {
                    Utility.LogStaticError("Didn't find IncreaseVerticalSpeed");
                    return;
                }
                wbiIncreaseVerticalSpeed = DynamicMethodFactory.CreateAction <object, float>(IncreaseVerticalSpeed_t);

                MethodInfo DecreaseVerticalSpeed_t = wbiVtolManager_t.GetMethod("DecreaseVerticalSpeed", BindingFlags.Instance | BindingFlags.Public);
                if (DecreaseVerticalSpeed_t == null)
                {
                    Utility.LogStaticError("Didn't find DecreaseVerticalSpeed");
                    return;
                }
                wbiDecreaseVerticalSpeed = DynamicMethodFactory.CreateAction <object, float>(DecreaseVerticalSpeed_t);

                // Thrust mode
                FieldInfo ThrustMode_t = wbiVtolManager_t.GetField("thrustMode", BindingFlags.Instance | BindingFlags.Public);
                if (ThrustMode_t == null)
                {
                    Utility.LogStaticError("Didn't find thrustMode");
                    return;
                }
                wbiGetThrustMode = DynamicMethodFactory.CreateGetField <object, object>(ThrustMode_t);

                MethodInfo SetForwardThrust_t = wbiVtolManager_t.GetMethod("SetForwardThrust", BindingFlags.Instance | BindingFlags.Public);
                if (SetForwardThrust_t == null)
                {
                    Utility.LogStaticError("Didn't find SetForwardThrust");
                    return;
                }
                wbiSetForwardThrust = DynamicMethodFactory.CreateAction <object>(SetForwardThrust_t);

                MethodInfo SetReverseThrust_t = wbiVtolManager_t.GetMethod("SetReverseThrust", BindingFlags.Instance | BindingFlags.Public);
                if (SetReverseThrust_t == null)
                {
                    Utility.LogStaticError("Didn't find SetReverseThrust");
                    return;
                }
                wbiSetReverseThrust = DynamicMethodFactory.CreateAction <object>(SetReverseThrust_t);

                MethodInfo SetVTOLThrust_t = wbiVtolManager_t.GetMethod("SetVTOLThrust", BindingFlags.Instance | BindingFlags.Public);
                if (SetVTOLThrust_t == null)
                {
                    Utility.LogStaticError("Didn't find SetVTOLThrust");
                    return;
                }
                wbiSetVTOLThrust = DynamicMethodFactory.CreateAction <object>(SetVTOLThrust_t);

                FieldInfo VerticalSpeed_t = wbiVtolManager_t.GetField("verticalSpeed", BindingFlags.Instance | BindingFlags.Public);
                if (VerticalSpeed_t == null)
                {
                    Utility.LogStaticError("Didn't find verticalSpeed");
                    return;
                }
                wbiGetVerticalSpeed = DynamicMethodFactory.CreateGetField <object, float>(VerticalSpeed_t);

                wbiWBIGraviticEngine_t = Utility.GetExportedType("FlyingSaucers", "WildBlueIndustries.WBIGraviticEngine");
                if (wbiWBIGraviticEngine_t != null)
                {
                    MethodInfo IsCrazyModeUnlocked_t = wbiWBIGraviticEngine_t.GetMethod("IsCrazyModeUnlocked", BindingFlags.Instance | BindingFlags.Public);
                    if (IsCrazyModeUnlocked_t == null)
                    {
                        Utility.LogStaticError("Didn't find IsCrazyModeUnlocked");
                        return;
                    }
                    wbiCrazyModeUnlocked = DynamicMethodFactory.CreateFunc <object, bool>(IsCrazyModeUnlocked_t);

                    MethodInfo IsActive_t = wbiWBIGraviticEngine_t.GetMethod("IsActive", BindingFlags.Instance | BindingFlags.Public);
                    if (IsActive_t == null)
                    {
                        Utility.LogStaticError("Didn't find IsActive");
                        return;
                    }
                    wbiCrazyModeIsActive = DynamicMethodFactory.CreateFunc <object, bool>(IsActive_t);

                    MethodInfo GetWarpDirection_t = wbiWBIGraviticEngine_t.GetMethod("GetWarpDirection", BindingFlags.Instance | BindingFlags.Public);
                    if (GetWarpDirection_t == null)
                    {
                        Utility.LogStaticError("Didn't find GetWarpDirection");
                        return;
                    }
                    wbiGetWarpDirection = DynamicMethodFactory.CreateFunc <object, object>(GetWarpDirection_t);

                    MethodInfo SetWarpDirection_t = wbiWBIGraviticEngine_t.GetMethod("SetWarpDirection", BindingFlags.Instance | BindingFlags.Public);
                    if (SetWarpDirection_t == null)
                    {
                        Utility.LogStaticError("Didn't find SetWarpDirection");
                        return;
                    }
                    wbiSetWarpDirection = DynamicMethodFactory.CreateAction <object, int>(SetWarpDirection_t);
                }

                wbivtolInstalled = true;
            }
        }