Skip to content

Instantly share code, notes, and snippets.

@artwhaley
Last active May 22, 2017 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artwhaley/f5bb453b8ed18fa89b53e47ffde46407 to your computer and use it in GitHub Desktop.
Save artwhaley/f5bb453b8ed18fa89b53e47ffde46407 to your computer and use it in GitHub Desktop.
public class MJWrapper
{
public static System.Type CoreType; //holds the mechjeb core type
public static System.Object core; //holds the core itself
public static bool Initialized = false; //keeps from reinitializing
public static Vessel vessel { get { return FlightGlobals.ActiveVessel; } } //shortcut to grab active vessel
public static bool Initialize() //Startup function to grab the core type and core
{
if (Initialized)
return true;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>{if (t.FullName == "MuMech.MechJebCore"){CoreType = t;}});
if (CoreType == null) {return false;}
if (!GetCore()){ return false;}
Initialized = true;
return true;
}
public static bool GetCore()
{
foreach (Part p in vessel.parts)
{
foreach (PartModule module in p.Modules)
{
if (module.GetType() == CoreType)
{
core = module;
return true;
}
}
}
return false;
}
public static System.Type FindMechJebModule(string module) // Used to load mechjeb modules.
{
Type type = null;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>
{
if (t.FullName == module)
{
type = t;
}
});
return type;
}
#region Public Functions
public static Vector3d Circularize(double UT) //This part works great- grabbing a static method.
{
System.Type OrbitalManeuverCalculatorType = FindMechJebModule("MuMech.OrbitalManeuverCalculator");
MethodInfo MPMethod = OrbitalManeuverCalculatorType.GetMethod("DeltaVToCircularize", BindingFlags.Public | BindingFlags.Static);
return (Vector3d)MPMethod.Invoke(null, new object[] { vessel.orbit, UT });
}
public static void ExecuteOne()
{
}
public static bool ExecStatus
{
get {return true; } //Placeholder to make this compile! Obviously doesn't work!
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment