Created
May 30, 2017 18:27
-
-
Save sarbian/829efb072f71691527ad4a95057b7884 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using UnityEngine; | |
namespace MJReflect | |
{ | |
[KSPAddon(KSPAddon.Startup.Instantly, false)] | |
public class MJReflect : MonoBehaviour | |
{ | |
public static bool Initialized { get; set; } | |
public static System.Type CoreType; | |
public static System.Object core; | |
public static Vessel vessel { get { return FlightGlobals.ActiveVessel; } } | |
public static System.Type mjVesExtensions; | |
public static MethodInfo GetMastr; | |
internal void Awake() | |
{ | |
DontDestroyOnLoad(gameObject); | |
} | |
public void Update() | |
{ | |
if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(KeyCode.Y)) | |
{ | |
print("[Test] Starting"); | |
Test(); | |
} | |
} | |
private void Test() | |
{ | |
Initialized = Initialize(); | |
GetCore(); | |
MethodInfo APToggle = CoreType.GetMethod("OnAscentAPToggleAction", BindingFlags.Instance | BindingFlags.Public); | |
if (APToggle == null) | |
{ | |
print("[Test] Unable to get APToggle"); | |
} | |
else | |
{ | |
print("[Test] Calling OnAscentAPToggleAction"); | |
APToggle.Invoke(core, new object[] { null }); | |
} | |
} | |
public static bool Initialize() | |
{ | |
if (Initialized) | |
return true; | |
print("[Test] Starting"); | |
AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "MuMech.MechJebCore") { CoreType = t; } }); | |
AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "MuMech.VesselExtensions") { mjVesExtensions = t; } }); | |
GetMastr = mjVesExtensions.GetMethod("GetMasterMechJeb", BindingFlags.Public | BindingFlags.Static); | |
if (GetMastr == null) | |
{ | |
print("[Test] Unable to find GetMastr"); | |
return false; | |
} | |
if (CoreType == null) | |
{ | |
print("[Test] Unable to find CoreType"); | |
return false; | |
} | |
if (mjVesExtensions == null) | |
{ | |
print("[Test] Unable to find mjVesExtensions"); | |
return false; | |
} | |
return true; | |
} | |
public static bool GetCore() | |
{ | |
core = GetMastr.Invoke(null, new object[] { vessel }); | |
if (core == null) | |
{ | |
print("[Test] Unable to find core"); | |
return false; | |
} | |
else | |
{ | |
print("[Test] Found the MJ core"); | |
} | |
return (core != null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment