Example #1
0
        static JSIChatterer()
        {
            try
            {
                var loadedChattererAssy = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name == "Chatterer");

                if (loadedChattererAssy == null)
                {
                    chattererFound = false;

                    return;
                }

                //--- Process all the reflection info
                // MechJebCore
                chatterer_t = loadedChattererAssy.assembly.GetExportedTypes()
                              .SingleOrDefault(t => t.FullName == "Chatterer.chatterer");
                if (chatterer_t == null)
                {
                    JUtil.LogErrorMessage(null, "Did not find Chatterer.chatterer");
                    return;
                }

                MethodInfo txMethod = chatterer_t.GetMethod("VesselIsTransmitting", BindingFlags.Instance | BindingFlags.Public);
                if (txMethod == null)
                {
                    throw new NotImplementedException("txMethod");
                }
                chattererTx = DynamicMethodDelegateFactory.CreateFuncBool(txMethod);

                MethodInfo rxMethod = chatterer_t.GetMethod("VesselIsReceiving", BindingFlags.Instance | BindingFlags.Public);
                if (rxMethod == null)
                {
                    throw new NotImplementedException("rxMethod");
                }
                chattererRx = DynamicMethodDelegateFactory.CreateFuncBool(rxMethod);

                MethodInfo chatterMethod = chatterer_t.GetMethod("InitiateChatter", BindingFlags.Instance | BindingFlags.Public);
                if (chatterMethod == null)
                {
                    throw new NotImplementedException("chatterMethod");
                }
                chattererStartTalking = DynamicMethodDelegateFactory.CreateAction(chatterMethod);
            }
            catch (Exception e)
            {
                chatterer_t = null;
                JUtil.LogMessage(null, "Exception initializing JSIChatterer: {0}", e);
            }

            if (chatterer_t != null && chattererStartTalking != null)
            {
                chattererFound = true;
            }
            else
            {
                chattererFound = false;
            }
        }
Example #2
0
        static JSIParachute()
        {
            try
            {
                rcModuleRealChute = AssemblyLoader.loadedAssemblies.SelectMany(
                    a => a.assembly.GetExportedTypes())
                                    .SingleOrDefault(t => t.FullName == "RealChute.RealChuteModule");
                if (rcModuleRealChute == null)
                {
                    rcFound = false;
                    JUtil.LogMessage(null, "rcModuleRealChute is null");
                    return;
                }

                PropertyInfo rcAnyDeployed = rcModuleRealChute.GetProperty("AnyDeployed", BindingFlags.Instance | BindingFlags.Public);
                if (rcAnyDeployed == null)
                {
                    JUtil.LogMessage(null, "rcAnyDeployed is null");
                }
                MethodInfo rcGetAnyDeployed = rcAnyDeployed.GetGetMethod();
                getAnyDeployed = DynamicMethodDelegateFactory.CreateFuncBool(rcGetAnyDeployed);
                if (getAnyDeployed == null)
                {
                    JUtil.LogMessage(null, "getAnyDeployed is null");
                }

                MethodInfo rcArmChute = rcModuleRealChute.GetMethod("GUIArm", BindingFlags.Instance | BindingFlags.Public);
                armChute = DynamicMethodDelegateFactory.CreateAction(rcArmChute);
                if (armChute == null)
                {
                    JUtil.LogMessage(null, "armChute is null");
                }

                MethodInfo rcDisarmChute = rcModuleRealChute.GetMethod("GUIDisarm", BindingFlags.Instance | BindingFlags.Public);
                disarmChute = DynamicMethodDelegateFactory.CreateAction(rcDisarmChute);
                if (disarmChute == null)
                {
                    JUtil.LogMessage(null, "disarmChute is null");
                }

                MethodInfo rcDeployChute = rcModuleRealChute.GetMethod("GUIDeploy", BindingFlags.Instance | BindingFlags.Public);
                deployChute = DynamicMethodDelegateFactory.CreateAction(rcDeployChute);
                if (deployChute == null)
                {
                    JUtil.LogMessage(null, "deployChute is null");
                }

                MethodInfo rcCutChute = rcModuleRealChute.GetMethod("GUICut", BindingFlags.Instance | BindingFlags.Public);
                cutChute = DynamicMethodDelegateFactory.CreateAction(rcCutChute);
                if (cutChute == null)
                {
                    JUtil.LogMessage(null, "cutChute is null");
                }

                rcArmed = rcModuleRealChute.GetField("armed", BindingFlags.Instance | BindingFlags.Public);
                if (rcArmed == null)
                {
                    JUtil.LogMessage(null, "rcArmed is null");
                }

                rcSafeState = rcModuleRealChute.GetField("safeState", BindingFlags.Instance | BindingFlags.Public);
                if (rcSafeState == null)
                {
                    JUtil.LogMessage(null, "rcSafeState is null");
                }
            }
            catch (Exception e)
            {
                JUtil.LogMessage(null, "static JSIParachute exception {0}", e);
                rcModuleRealChute = null;
                getAnyDeployed    = null;
                armChute          = null;
                disarmChute       = null;
                deployChute       = null;
                cutChute          = null;
                rcArmed           = null;
                rcSafeState       = null;
            }

            if (rcModuleRealChute != null &&
                armChute != null &&
                getAnyDeployed != null &&
                disarmChute != null &&
                deployChute != null &&
                cutChute != null &&
                rcArmed != null &&
                rcSafeState != null
                )
            {
                rcFound = true;
            }
            else
            {
                rcFound = false;
            }
        }
Example #3
0
        static JSIPilotAssistant()
        {
            try
            {
                var loadedPAAssy = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name == "PilotAssistant");
                if (loadedPAAssy == null)
                {
                    //JUtil.LogMessage(null, "Did not load PilotAssistant");
                    //var list = AssemblyLoader.loadedAssemblies;
                    //foreach(var a in list)
                    //{
                    //    JUtil.LogMessage(null, "-- {0}", a.name);
                    //}
                    return;
                }
                //else
                //{
                //    JUtil.LogMessage(null, "Did find PilotAssistant");
                //}

                Type paAsstVesselModule_t = loadedPAAssy.assembly.GetExportedTypes()
                                            .SingleOrDefault(t => t.FullName == "PilotAssistant.FlightModules.AsstVesselModule");
                if (paAsstVesselModule_t == null)
                {
                    throw new NotImplementedException("paAsstVesselModule_t");
                }

                vesselAsst_t = paAsstVesselModule_t.GetField("vesselAsst", BindingFlags.Instance | BindingFlags.Public);
                if (vesselAsst_t == null)
                {
                    throw new NotImplementedException("vesselAsst_t");
                }

                Type paPilotAssistant_t = loadedPAAssy.assembly.GetExportedTypes()
                                          .SingleOrDefault(t => t.FullName == "PilotAssistant.FlightModules.PilotAssistant");
                if (paPilotAssistant_t == null)
                {
                    throw new NotImplementedException("paPilotAssistant_t");
                }

                vertMode_t = paPilotAssistant_t.GetField("CurrentVertMode", BindingFlags.Instance | BindingFlags.Public);
                if (vertMode_t == null)
                {
                    throw new NotImplementedException("currentVertMode_t");
                }
                vertActive_t = paPilotAssistant_t.GetField("VertActive", BindingFlags.Instance | BindingFlags.Public);
                if (vertActive_t == null)
                {
                    throw new NotImplementedException("vertActive_t");
                }
                MethodInfo vertSetting_t = paPilotAssistant_t.GetMethod("GetCurrentVert", BindingFlags.Instance | BindingFlags.Public);
                if (vertSetting_t == null)
                {
                    throw new NotImplementedException("vertSetting_t");
                }
                GetCurrentVert = DynamicMethodDelegateFactory.CreateFuncDouble(vertSetting_t);
                MethodInfo setVert_t = paPilotAssistant_t.GetMethod("SetVert", BindingFlags.Instance | BindingFlags.Public);
                if (setVert_t == null)
                {
                    throw new NotImplementedException("setVert_t");
                }
                SetVert = DynamicMethodDelegateFactory.Create(setVert_t);

                horzMode_t = paPilotAssistant_t.GetField("CurrentHrztMode", BindingFlags.Instance | BindingFlags.Public);
                if (horzMode_t == null)
                {
                    throw new NotImplementedException("horzMode_t");
                }
                horzActive_t = paPilotAssistant_t.GetField("HrztActive", BindingFlags.Instance | BindingFlags.Public);
                if (horzActive_t == null)
                {
                    throw new NotImplementedException("horzActive_t");
                }
                MethodInfo horzSetting_t = paPilotAssistant_t.GetMethod("GetCurrentHrzt", BindingFlags.Instance | BindingFlags.Public);
                if (horzSetting_t == null)
                {
                    throw new NotImplementedException("horzSetting_t");
                }
                GetCurrentHorz = DynamicMethodDelegateFactory.CreateFuncDouble(horzSetting_t);
                MethodInfo setHorz_t = paPilotAssistant_t.GetMethod("SetHrzt", BindingFlags.Instance | BindingFlags.Public);
                if (setHorz_t == null)
                {
                    throw new NotImplementedException("setHorz_t");
                }
                SetHorz = DynamicMethodDelegateFactory.Create(setHorz_t);

                throttleMode_t = paPilotAssistant_t.GetField("CurrentThrottleMode", BindingFlags.Instance | BindingFlags.Public);
                if (throttleMode_t == null)
                {
                    throw new NotImplementedException("throttleMode_t");
                }
                throttleActive_t = paPilotAssistant_t.GetField("ThrtActive", BindingFlags.Instance | BindingFlags.Public);
                if (throttleActive_t == null)
                {
                    throw new NotImplementedException("throttleActive_t");
                }
                MethodInfo throttleSetting_t = paPilotAssistant_t.GetMethod("GetCurrentThrottle", BindingFlags.Instance | BindingFlags.Public);
                if (throttleSetting_t == null)
                {
                    throw new NotImplementedException("throttleSetting_t");
                }
                GetCurrentThrottle = DynamicMethodDelegateFactory.CreateFuncDouble(throttleSetting_t);
                MethodInfo setThrottle_t = paPilotAssistant_t.GetMethod("SetThrottle", BindingFlags.Instance | BindingFlags.Public);
                if (setThrottle_t == null)
                {
                    throw new NotImplementedException("setThrottle_t");
                }
                SetThrottle = DynamicMethodDelegateFactory.Create(setThrottle_t);

                speedRef_t = paPilotAssistant_t.GetField("speedRef", BindingFlags.Instance | BindingFlags.NonPublic);
                if (speedRef_t == null)
                {
                    throw new NotImplementedException("PA speedRef_t");
                }
                MethodInfo changeSpeedRef_t = paPilotAssistant_t.GetMethod("ChangeSpeedRef", BindingFlags.Instance | BindingFlags.Public);
                if (changeSpeedRef_t == null)
                {
                    throw new NotImplementedException("PA changeSpeedRef_t");
                }
                SetSpeedRef = DynamicMethodDelegateFactory.Create(changeSpeedRef_t);

                speedUnits_t = paPilotAssistant_t.GetField("units", BindingFlags.Instance | BindingFlags.NonPublic);
                if (speedUnits_t == null)
                {
                    throw new NotImplementedException("PA speedUnits_t");
                }
                MethodInfo changeSpeedUnits_t = paPilotAssistant_t.GetMethod("ChangeSpeedUnit", BindingFlags.Instance | BindingFlags.Public);
                if (changeSpeedUnits_t == null)
                {
                    throw new NotImplementedException("PA changeSpeedUnits_t");
                }
                SetSpeedUnits = DynamicMethodDelegateFactory.Create(changeSpeedUnits_t);

                pauseState_t = paPilotAssistant_t.GetField("bPause", BindingFlags.Instance | BindingFlags.Public);
                if (pauseState_t == null)
                {
                    throw new NotImplementedException("PA pauseState_t");
                }
                MethodInfo TogglePause_t = paPilotAssistant_t.GetMethod("TogglePauseCtrlState", BindingFlags.Instance | BindingFlags.Public);
                if (TogglePause_t == null)
                {
                    throw new NotImplementedException("PA TogglePause_t");
                }
                TogglePause = DynamicMethodDelegateFactory.CreateAction(TogglePause_t);
            }
            catch (Exception e)
            {
                JUtil.LogMessage(null, "Exception tripped: {0}", e);
                paFound = false;
                return;
            }

            paFound = true;
        }