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; } }
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; } }
static JSIMechJeb() { try { var loadedMechJebAssy = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name == "MechJeb2"); if (loadedMechJebAssy == null) { mjFound = false; //JUtil.LogMessage(this, "A supported version of MechJeb is {0}", (mjFound) ? "present" : "not available"); return; } //--- Process all the reflection info // MechJebCore mjMechJebCore_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebCore"); if (mjMechJebCore_t == null) { return; } MethodInfo mjGetComputerModule = mjMechJebCore_t.GetMethod("GetComputerModule", new Type[] { typeof(string) }); if (mjGetComputerModule == null) { throw new NotImplementedException("mjGetComputerModule"); } getComputerModule = DynamicMethodDelegateFactory.Create(mjGetComputerModule); mjCoreTarget = mjMechJebCore_t.GetField("target", BindingFlags.Instance | BindingFlags.Public); if (mjCoreTarget == null) { throw new NotImplementedException("mjCoreTarget"); } mjCoreNode = mjMechJebCore_t.GetField("node", BindingFlags.Instance | BindingFlags.Public); if (mjCoreNode == null) { throw new NotImplementedException("mjCoreNode"); } mjCoreAttitude = mjMechJebCore_t.GetField("attitude", BindingFlags.Instance | BindingFlags.Public); if (mjCoreAttitude == null) { throw new NotImplementedException("mjCoreAttitude"); } mjCoreVesselState = mjMechJebCore_t.GetField("vesselState", BindingFlags.Instance | BindingFlags.Public); if (mjCoreVesselState == null) { throw new NotImplementedException("mjCoreVesselState"); } // VesselExtensions Type mjVesselExtensions_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.VesselExtensions"); if (mjVesselExtensions_t == null) { throw new NotImplementedException("mjVesselExtensions_t"); } MethodInfo mjGetMasterMechJeb = mjVesselExtensions_t.GetMethod("GetMasterMechJeb", BindingFlags.Static | BindingFlags.Public); if (mjGetMasterMechJeb == null) { throw new NotImplementedException("mjGetMasterMechJeb"); } getMasterMechJeb = DynamicMethodDelegateFactory.Create(mjGetMasterMechJeb); MethodInfo mjPlaceManeuverNode = mjVesselExtensions_t.GetMethod("PlaceManeuverNode", BindingFlags.Static | BindingFlags.Public); if (mjPlaceManeuverNode == null) { throw new NotImplementedException("mjPlaceManeuverNode"); } placeManeuverNode = DynamicMethodDelegateFactory.Create(mjPlaceManeuverNode); // VesselState Type mjVesselState_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.VesselState"); if (mjVesselState_t == null) { throw new NotImplementedException("mjVesselState_t"); } MethodInfo mjTerminalVelocity = mjVesselState_t.GetMethod("TerminalVelocity", BindingFlags.Instance | BindingFlags.Public); if (mjTerminalVelocity == null) { throw new NotImplementedException("mjTerminalVelocity"); } terminalVelocity = DynamicMethodDelegateFactory.CreateFuncDouble(mjTerminalVelocity); // SmartASS Type mjSmartass_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebModuleSmartASS"); mjSmartassTarget = mjSmartass_t.GetField("target", BindingFlags.Instance | BindingFlags.Public); if (mjSmartassTarget == null) { throw new NotImplementedException("mjSmartassTarget"); } MethodInfo mjSmartassEngage = mjSmartass_t.GetMethod("Engage", BindingFlags.Instance | BindingFlags.Public); if (mjSmartassEngage == null) { throw new NotImplementedException("mjSmartassEngage"); } engageSmartass = DynamicMethodDelegateFactory.Create(mjSmartassEngage); mjSmartassForceRol = mjSmartass_t.GetField("forceRol", BindingFlags.Instance | BindingFlags.Public); if (mjSmartassForceRol == null) { throw new NotImplementedException("mjSmartassForceRol"); } mjSmartassRol = mjSmartass_t.GetField("rol", BindingFlags.Instance | BindingFlags.Public); if (mjSmartassRol == null) { throw new NotImplementedException("mjSmartassRol"); } FieldInfo TargetTextsInfo = mjSmartass_t.GetField("TargetTexts", BindingFlags.Static | BindingFlags.Public); TargetTexts = (string[])TargetTextsInfo.GetValue(null); if (TargetTexts == null) { throw new NotImplementedException("TargetTexts"); } FieldInfo ModeTextsInfo = mjSmartass_t.GetField("ModeTexts", BindingFlags.Static | BindingFlags.Public); ModeTexts = (string[])ModeTextsInfo.GetValue(null); if (ModeTexts == null) { throw new NotImplementedException("ModeTexts"); } // Landing Predictions Type mjModuleLandingPredictions_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebModuleLandingPredictions"); if (mjModuleLandingPredictions_t == null) { throw new NotImplementedException("mjModuleLandingPredictions_t"); } MethodInfo mjPredictionsGetResult = mjModuleLandingPredictions_t.GetMethod("GetResult", BindingFlags.Instance | BindingFlags.Public); if (mjPredictionsGetResult == null) { throw new NotImplementedException("mjPredictionsGetResult"); } getPredictionsResult = DynamicMethodDelegateFactory.Create(mjPredictionsGetResult); // AbsoluteVector Type mjAbsoluteVector_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.AbsoluteVector"); if (mjAbsoluteVector_t == null) { throw new NotImplementedException("mjAbsoluteVector_t"); } mjAbsoluteVectorLat = mjAbsoluteVector_t.GetField("latitude", BindingFlags.Instance | BindingFlags.Public); if (mjAbsoluteVectorLat == null) { throw new NotImplementedException("mjAbsoluteVectorLat"); } mjAbsoluteVectorLon = mjAbsoluteVector_t.GetField("longitude", BindingFlags.Instance | BindingFlags.Public); if (mjAbsoluteVectorLon == null) { throw new NotImplementedException("mjAbsoluteVectorLon"); } // MechJebModuleAscentAutopilot Type mjMechJebModuleAscentAutopilot_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebModuleAscentAutopilot"); if (mjMechJebModuleAscentAutopilot_t == null) { throw new NotImplementedException("mjMechJebModuleAscentAutopilot_t"); } launchOrbitAltitude = mjMechJebModuleAscentAutopilot_t.GetField("desiredOrbitAltitude"); if (launchOrbitAltitude == null) { throw new NotImplementedException("launchOrbitAltitude"); } Type mjEditableDoubleMult_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.EditableDoubleMult"); if (mjEditableDoubleMult_t == null) { throw new NotImplementedException("mjEditableDoubleMult_t"); } getEditableDoubleMultMultiplier = mjEditableDoubleMult_t.GetField("multiplier"); if (getEditableDoubleMultMultiplier == null) { throw new NotImplementedException("getEditableDoubleMultMultiplier"); } PropertyInfo edmVal = mjEditableDoubleMult_t.GetProperty("val"); if (edmVal == null) { throw new NotImplementedException("edmVal"); } // getEditableDoubleMult MethodInfo mjGetEDM = edmVal.GetGetMethod(); if (mjGetEDM != null) { getEditableDoubleMult = DynamicMethodDelegateFactory.CreateFuncDouble(mjGetEDM); } // setEditableDoubleMult MethodInfo mjSetEDM = edmVal.GetSetMethod(); if (mjSetEDM != null) { setEditableDoubleMult = DynamicMethodDelegateFactory.Create(mjSetEDM); } // EditableAngle Type mjEditableAngle_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.EditableAngle"); if (mjEditableAngle_t == null) { throw new NotImplementedException("mjEditableAngle_t"); } MethodInfo mjAbsoluteVectorToDouble = null; foreach (MethodInfo method in mjEditableAngle_t.GetMethods(BindingFlags.Static | BindingFlags.Public)) { // The method name reports as "op_Implicit", but there are two if (method.ReturnType == typeof(System.Double)) { mjAbsoluteVectorToDouble = method; break; } } if (mjAbsoluteVectorToDouble == null) { throw new NotImplementedException("mjAbsoluteVectorToDouble"); } absoluteVectorToDouble = DynamicMethodDelegateFactory.Create(mjAbsoluteVectorToDouble); // MechJebModuleTargetController Type mjModuleTargetController_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebModuleTargetController"); if (mjModuleTargetController_t == null) { throw new NotImplementedException("mjModuleTargetController_t"); } mjTargetLongitude = mjModuleTargetController_t.GetField("targetLongitude", BindingFlags.Instance | BindingFlags.Public); if (mjTargetLongitude == null) { throw new NotImplementedException("mjTargetLongitude"); } mjTargetLatitude = mjModuleTargetController_t.GetField("targetLatitude", BindingFlags.Instance | BindingFlags.Public); if (mjTargetLatitude == null) { throw new NotImplementedException("mjTargetLatitude"); } PropertyInfo mjPositionTargetExists = mjModuleTargetController_t.GetProperty("PositionTargetExists", BindingFlags.Instance | BindingFlags.Public); MethodInfo mjGetPositionTargetExists = null; if (mjPositionTargetExists != null) { mjGetPositionTargetExists = mjPositionTargetExists.GetGetMethod(); } if (mjGetPositionTargetExists == null) { throw new NotImplementedException("mjGetPositionTargetExists"); } getPositionTargetExists = DynamicMethodDelegateFactory.CreateFuncBool(mjGetPositionTargetExists); PropertyInfo mjNormalTargetExists = mjModuleTargetController_t.GetProperty("NormalTargetExists", BindingFlags.Instance | BindingFlags.Public); MethodInfo mjGetNormalTargetExists = null; if (mjNormalTargetExists != null) { mjGetNormalTargetExists = mjNormalTargetExists.GetGetMethod(); } if (mjGetNormalTargetExists == null) { throw new NotImplementedException("mjGetNormalTargetExists"); } getNormalTargetExists = DynamicMethodDelegateFactory.CreateFuncBool(mjGetNormalTargetExists); PropertyInfo mjTargetOrbit = mjModuleTargetController_t.GetProperty("TargetOrbit", BindingFlags.Instance | BindingFlags.Public); ; MethodInfo mjGetTargetOrbit = null; if (mjTargetOrbit != null) { mjGetTargetOrbit = mjTargetOrbit.GetGetMethod(); } if (mjGetTargetOrbit == null) { throw new NotImplementedException("mjGetTargetOrbit"); } getTargetOrbit = DynamicMethodDelegateFactory.CreateFuncObject(mjGetTargetOrbit); // MuMech.FuelFlowSimulation Type mjFuelFlowSimulation_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.FuelFlowSimulation"); if (mjFuelFlowSimulation_t == null) { throw new NotImplementedException("mjFuelFlowSimulation_t"); } // MuMech.FuelFlowSimulation.Stats Type mjFuelFlowSimulationStats_t = mjFuelFlowSimulation_t.GetNestedType("Stats"); if (mjFuelFlowSimulationStats_t == null) { throw new NotImplementedException("mjFuelFlowSimulationStats_t"); } mjStageDv = mjFuelFlowSimulationStats_t.GetField("deltaV", BindingFlags.Instance | BindingFlags.Public); if (mjStageDv == null) { throw new NotImplementedException("mjStageDv"); } // MuMech.ReentrySimulation.Result Type mjReentrySim_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.ReentrySimulation"); if (mjReentrySim_t == null) { throw new NotImplementedException("mjReentrySim_t"); } Type mjReentryResult_t = mjReentrySim_t.GetNestedType("Result"); if (mjReentryResult_t == null) { throw new NotImplementedException("mjReentryResult_t"); } mjReentryOutcome = mjReentryResult_t.GetField("outcome", BindingFlags.Instance | BindingFlags.Public); if (mjReentryOutcome == null) { throw new NotImplementedException("mjReentryOutcome"); } mjReentryEndPosition = mjReentryResult_t.GetField("endPosition", BindingFlags.Instance | BindingFlags.Public); if (mjReentryEndPosition == null) { throw new NotImplementedException("mjReentryEndPosition"); } mjReentryTime = mjReentryResult_t.GetField("endUT", BindingFlags.Instance | BindingFlags.Public); if (mjReentryTime == null) { throw new NotImplementedException("mjReentryTime"); } // UserPool Type mjUserPool_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.UserPool"); MethodInfo mjAddUser = mjUserPool_t.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public); if (mjAddUser == null) { throw new NotImplementedException("mjAddUser"); } addUser = DynamicMethodDelegateFactory.Create(mjAddUser); MethodInfo mjRemoveUser = mjUserPool_t.GetMethod("Remove", BindingFlags.Instance | BindingFlags.Public); if (mjRemoveUser == null) { throw new NotImplementedException("mjRemoveUser"); } removeUser = DynamicMethodDelegateFactory.Create(mjRemoveUser); MethodInfo mjContainsUser = mjUserPool_t.GetMethod("Contains", BindingFlags.Instance | BindingFlags.Public); if (mjContainsUser == null) { throw new NotImplementedException("mjContainsUser"); } containsUser = DynamicMethodDelegateFactory.Create(mjContainsUser); // MechJebModuleLandingAutopilot Type mjLandingAutopilot_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebModuleLandingAutopilot"); MethodInfo mjLandAtPositionTarget = mjLandingAutopilot_t.GetMethod("LandAtPositionTarget", BindingFlags.Instance | BindingFlags.Public); if (mjLandAtPositionTarget == null) { throw new NotImplementedException("mjLandAtPositionTarget"); } landAtPositionTarget = DynamicMethodDelegateFactory.Create(mjLandAtPositionTarget); MethodInfo mjLandUntargeted = mjLandingAutopilot_t.GetMethod("LandUntargeted", BindingFlags.Instance | BindingFlags.Public); if (mjLandUntargeted == null) { throw new NotImplementedException("mjLandUntargeted"); } landUntargeted = DynamicMethodDelegateFactory.Create(mjLandUntargeted); MethodInfo mjStopLanding = mjLandingAutopilot_t.GetMethod("StopLanding", BindingFlags.Instance | BindingFlags.Public); if (mjStopLanding == null) { throw new NotImplementedException("mjStopLanding"); } stopLanding = DynamicMethodDelegateFactory.CreateAction(mjStopLanding); Type mjSpaceplaneAutopilot_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebModuleSpaceplaneAutopilot"); MethodInfo mjSPAutoland = mjSpaceplaneAutopilot_t.GetMethod("Autoland", BindingFlags.Instance | BindingFlags.Public); if (mjSPAutoland == null) { throw new NotImplementedException("mjSPAutoland"); } spaceplaneAutoland = DynamicMethodDelegateFactory.Create(mjSPAutoland); MethodInfo mjSPHoldHeadingAndAltitude = mjSpaceplaneAutopilot_t.GetMethod("HoldHeadingAndAltitude", BindingFlags.Instance | BindingFlags.Public); if (mjSPHoldHeadingAndAltitude == null) { throw new NotImplementedException("mjSPHoldHeadingAndAltitude"); } spaceplaneHoldHeading = DynamicMethodDelegateFactory.Create(mjSPHoldHeadingAndAltitude); MethodInfo mjSPAutopilotOff = mjSpaceplaneAutopilot_t.GetMethod("AutopilotOff", BindingFlags.Instance | BindingFlags.Public); if (mjSPAutopilotOff == null) { throw new NotImplementedException("mjSPAutopilotOff"); } spaceplaneAPOff = DynamicMethodDelegateFactory.CreateAction(mjSPAutopilotOff); spaceplaneAPMode = mjSpaceplaneAutopilot_t.GetField("mode", BindingFlags.Instance | BindingFlags.Public); if (spaceplaneAPMode == null) { throw new NotImplementedException("spaceplaneAPMode"); } spaceplaneAltitude = mjSpaceplaneAutopilot_t.GetField("targetAltitude", BindingFlags.Instance | BindingFlags.Public); if (spaceplaneAltitude == null) { throw new NotImplementedException("spaceplaneAltitude"); } spaceplaneHeading = mjSpaceplaneAutopilot_t.GetField("targetHeading", BindingFlags.Instance | BindingFlags.Public); if (spaceplaneHeading == null) { throw new NotImplementedException("spaceplaneHeading"); } spaceplaneGlideslope = mjSpaceplaneAutopilot_t.GetField("glideslope", BindingFlags.Instance | BindingFlags.Public); if (spaceplaneGlideslope == null) { throw new NotImplementedException("spaceplaneGlideslope"); } // EditableDouble Type mjEditableDouble_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.EditableDouble"); PropertyInfo mjEditableDoubleVal = mjEditableDouble_t.GetProperty("val", BindingFlags.Instance | BindingFlags.Public); MethodInfo mjGetEditableDouble = null, mjSetEditableDouble = null; if (mjEditableDoubleVal != null) { mjGetEditableDouble = mjEditableDoubleVal.GetGetMethod(); mjSetEditableDouble = mjEditableDoubleVal.GetSetMethod(); } if (mjGetEditableDouble == null) { throw new NotImplementedException("mjGetEditableDouble"); } getEditableDouble = DynamicMethodDelegateFactory.CreateFuncDouble(mjGetEditableDouble); if (mjSetEditableDouble == null) { throw new NotImplementedException("mjSetEditableDouble"); } setEditableDouble = DynamicMethodDelegateFactory.Create(mjSetEditableDouble); // OrbitalManeuverCalculator Type mjOrbitalManeuverCalculator_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.OrbitalManeuverCalculator"); mjDeltaVAndTimeForHohmannTransfer = mjOrbitalManeuverCalculator_t.GetMethod("DeltaVAndTimeForHohmannTransfer", BindingFlags.Static | BindingFlags.Public); if (mjDeltaVAndTimeForHohmannTransfer == null) { throw new NotImplementedException("mjDeltaVAndTimeForHohmannTransfer"); } //deltaVAndTimeForHohmannTransfer = DynamicMethodDelegateFactory.Create(mjDeltaVAndTimeForHohmannTransfer); mjDeltaVAndTimeForInterplanetaryTransferEjection = mjOrbitalManeuverCalculator_t.GetMethod("DeltaVAndTimeForInterplanetaryTransferEjection", BindingFlags.Static | BindingFlags.Public); if (mjDeltaVAndTimeForInterplanetaryTransferEjection == null) { throw new NotImplementedException("mjDeltaVAndTimeForInterplanetaryTransferEjection"); } //deltaVAndTimeForInterplanetaryTransferEjection = DynamicMethodDelegateFactory.Create(mjDeltaVAndTimeForInterplanetaryTransferEjection); MethodInfo mjDeltaVToCircularize = mjOrbitalManeuverCalculator_t.GetMethod("DeltaVToCircularize", BindingFlags.Static | BindingFlags.Public); if (mjDeltaVToCircularize == null) { throw new NotImplementedException("mjDeltaVToCircularize"); } deltaVToCircularize = DynamicMethodDelegateFactory.Create(mjDeltaVToCircularize); // MechJebModuleStageStats Type mjModuleStageStats_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebModuleStageStats"); if (mjModuleStageStats_t == null) { throw new NotImplementedException("mjModuleStageStats_t"); } MethodInfo mjRequestUpdate = mjModuleStageStats_t.GetMethod("RequestUpdate", BindingFlags.Instance | BindingFlags.Public); if (mjRequestUpdate == null) { throw new NotImplementedException("mjRequestUpdate"); } requestUpdate = DynamicMethodDelegateFactory.Create(mjRequestUpdate); mjVacStageStats = mjModuleStageStats_t.GetField("vacStats", BindingFlags.Instance | BindingFlags.Public); if (mjVacStageStats == null) { throw new NotImplementedException("mjVacStageStats"); } // Updated MechJeb (post 2.5.1) switched from using KER back to // its internal FuelFlowSimulation. This sim uses an array of // structs, which entails a couple of extra hoops to jump through // when reading via reflection. mjAtmStageStats = mjModuleStageStats_t.GetField("atmoStats", BindingFlags.Instance | BindingFlags.Public); if (mjAtmStageStats == null) { throw new NotImplementedException("mjAtmStageStats"); } PropertyInfo mjStageStatsLength = mjVacStageStats.FieldType.GetProperty("Length"); if (mjStageStatsLength == null) { throw new NotImplementedException("mjStageStatsLength"); } MethodInfo mjStageStatsGetLength = mjStageStatsLength.GetGetMethod(); if (mjStageStatsGetLength == null) { throw new NotImplementedException("mjStageStatsGetLength"); } stageStatsGetLength = DynamicMethodDelegateFactory.CreateFuncInt(mjStageStatsGetLength); MethodInfo mjStageStatsGetIndex = mjVacStageStats.FieldType.GetMethod("Get"); if (mjStageStatsGetIndex == null) { throw new NotImplementedException("mjStageStatsGetIndex"); } stageStatsGetIndex = DynamicMethodDelegateFactory.Create(mjStageStatsGetIndex); // MechJebModuleNodeExecutor Type mjNodeExecutor_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.MechJebModuleNodeExecutor"); MethodInfo mjExecuteOneNode = mjNodeExecutor_t.GetMethod("ExecuteOneNode", BindingFlags.Instance | BindingFlags.Public); if (mjExecuteOneNode == null) { throw new NotImplementedException("mjExecuteOneNode"); } executeOneNode = DynamicMethodDelegateFactory.Create(mjExecuteOneNode); MethodInfo mjAbortNode = mjNodeExecutor_t.GetMethod("Abort", BindingFlags.Instance | BindingFlags.Public); if (mjAbortNode == null) { throw new NotImplementedException("mjAbortNode"); } abortNode = DynamicMethodDelegateFactory.CreateAction(mjAbortNode); // Computer Module Type mjComputerModule_t = loadedMechJebAssy.assembly.GetExportedTypes() .SingleOrDefault(t => t.FullName == "MuMech.ComputerModule"); PropertyInfo mjModuleEnabledProperty = mjComputerModule_t.GetProperty("enabled", BindingFlags.Instance | BindingFlags.Public); MethodInfo mjModuleEnabled = null; if (mjModuleEnabledProperty != null) { mjModuleEnabled = mjModuleEnabledProperty.GetGetMethod(); } if (mjModuleEnabled == null) { throw new NotImplementedException("mjModuleEnabled"); } moduleEnabled = DynamicMethodDelegateFactory.CreateFuncBool(mjModuleEnabled); mjModuleUsers = mjComputerModule_t.GetField("users", BindingFlags.Instance | BindingFlags.Public); if (mjModuleUsers == null) { throw new NotImplementedException("mjModuleUsers"); } } catch (Exception e) { mjMechJebCore_t = null; JUtil.LogMessage(null, "Exception initializing JSIMechJeb: {0}", e); } if (mjMechJebCore_t != null && getMasterMechJeb != null) { mjFound = true; } else { mjFound = false; } }
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); 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"); } } 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; } if (rcModuleRealChute != null && armChute != null && getAnyDeployed != null && disarmChute != null && deployChute != null && cutChute != null && rcArmed != null ) { rcFound = true; } else { rcFound = false; } }