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; } }
internal static Action <BenchmarkContext> CreateDelegateWithContext(object target, MethodInfo invocationMethod) { // As the base method DOES accept a BenchmarkContext as a parameter, we test to see if any other method parameters are required. if (invocationMethod.GetParameters().Length == 1) { // If no additional parameters are required, we create a simple Delegate to the method, that already matches the signature // Action<BenchmarkContext> var simpleDelegate = (Action <BenchmarkContext>)invocationMethod.CreateDelegate(typeof(Action <BenchmarkContext>), target); return(simpleDelegate); } // If additional parameters are required, we use a DynamicMethod to build a Delegate capable of handling 1-n parameters, of any type. var paramaterisedDelegate = DynamicMethodDelegateFactory.CreateMethodCaller(invocationMethod); // As we require a known Action signature, we wrap the delegate in one that specifies Action<BenchmarkContext> Action <BenchmarkContext> wrappedParamaterisedDelegate = context => paramaterisedDelegate(target, _testParamaters); return(wrappedParamaterisedDelegate); }
internal static Action <BenchmarkContext> CreateDelegateWithoutContext(object target, MethodInfo invocationMethod) { // As the base method does not accept a BenchmarkContext as a parameter, and a known Action delegate signature is // required for the sake of performance, we test to see if any method parameters are required. if (invocationMethod.GetParameters().Length == 0) { // If no parameters are required, we create a simple Delegate to the method. var simpleDelegate = (Action)invocationMethod.CreateDelegate(typeof(Action), target); // As we require a knownAction signature, we wrap the simple delegate in one that specifies Action<BenchmarkContext> Action <BenchmarkContext> wrappedSimpleDelegate = context => simpleDelegate(); return(wrappedSimpleDelegate); } // If parameters are required, we use a DynamicMethod to build a Delegate capable of handling 1-n parameters, of any type. var paramaterisedDelegate = DynamicMethodDelegateFactory.CreateMethodCaller(invocationMethod); // Again, as we require a known Action signature, we wrap the delegate in one that specifies Action<BenchmarkContext> Action <BenchmarkContext> wrappedParamaterisedDelegate = context => paramaterisedDelegate(target, _testParamaters); return(wrappedParamaterisedDelegate); }
public RpcDeserializer(MethodInfo method, object target, SerializationManager serializer, Type[] paramTypes, IRpcFilter <T>[] filters = null, DynamicMethodDelegate @delegate = null) { if (@delegate == null) { _delegate = DynamicMethodDelegateFactory.Create(method); } else { _delegate = @delegate; } _target = target; _serializer = serializer; _paramTypes = paramTypes; if (filters != null) { _filters = filters; } else { _filters = new IRpcFilter <T> [0]; } var parms = method.GetParameters(); _parmOptionals = new bool[parms.Length]; _parmOptionDefaults = new object[parms.Length]; for (int i = 0; i < parms.Length; i++) { var isOptional = parms[i].IsOptional; _parmOptionals[i] = isOptional; if (isOptional) { _parmOptionDefaults[i] = parms[i].DefaultValue; } } }
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 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; }