diff --git a/TestMod/TeleportEnginePatch.cs b/TestMod/TeleportEnginePatch.cs new file mode 100644 index 0000000..fd31ec6 --- /dev/null +++ b/TestMod/TeleportEnginePatch.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using RobocraftX.GUI.CommandLine; +using Harmony; +using UnityEngine; + +namespace TestMod.Waypoints +{ + [HarmonyPatch(typeof(TeleportCharacterCommandEngine))] + [HarmonyPatch(typeof(new Type[] {}))] + class TeleportEnginePatch + { + static TeleportCharacterCommandEngine Instance {get; private set;} + + static void Postfix(TeleportCharacterCommandEngine __result) + { + Instance = __result; + Debug.Log("Caught TeleportCharacterCommandEngine"); + } + } +} diff --git a/TestMod/TeleportPatch.cs b/TestMod/TeleportPatch.cs new file mode 100644 index 0000000..f782f92 --- /dev/null +++ b/TestMod/TeleportPatch.cs @@ -0,0 +1,74 @@ +using System.Reflection; +using System.Dictionary.Generic; +using Harmony; +using UnityEngine; +using Unity.Mathematics; +using RobocraftX.GUI.CommandLine; +using uREPL; + +namespace TestMod.Waypoints +{ + [HarmonyPatch] + class TeleportPatch + { + static Action TeleportAbsolute {get; private set;} + + static Action TeleportRelative {get; private set;} + + static Dictionary _waypoints {get;} = new Dictionnary(); + + static void Prefix(string name, Action func, string description) + { + Debug.Log("Caught Register for "+name); + if (name.Equals("TeleportPlayerAbsolute")) + { + TeleportAbsolute = func; + } + + if (name.Equals("TeleportPlayerRelative")) + { + TeleportRelative = func; + } + } + + static MethodBase TargetMethod(HarmonyInstance instance) + { + Type CLUtility = AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"); + return Harmony.AccessTools.Method(CLUtility, "Register", new Type[]{ typeof(string), typeof(Action), typeof(string) }, new Type[]{ typeof(float), typeof(float), typeof(float) }); + } + + static void WaypointCommand(object name) + { + // hopefully entitiesDB does not become private in the future... + if (TeleportEnginePatch.Instance == null) + { + uREPL.Log.Error("Teleport command object missing!"); + return; + } + ref RigidBodyEntityStruct reference = ref TeleportEnginePatch.Instance.entitiesDB.QueryEntity(0u, CharacterExclusiveGroups.CharacterGroup); + if (_waypoints.ContainsKey(name)) + { + _waypoints.Remove(name); + } + _waypoints.Add(new float[3]{reference.x, reference.y, reference.z}); + uREPL.Log.Output("Saved "+name.ToString()); + } + + static void TeleportWaypointCommand(object name) + { + if (!_waypoints.ContainsKey(name)) + { + uREPL.Log.Error("Waypoint does not exist!"); + return; + } + if (TeleportAbsolute == null) + { + uREPL.Log.Error("TeleportPlayerAbsolute command missing!"); + return; + } + TeleportAbsolute(_waypoints[name]); + uREPL.Log.Output("Teleported player to "+name.ToString()); + } + } + +} \ No newline at end of file