|
|
@@ -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<float,float,float> TeleportAbsolute {get; private set;} |
|
|
|
|
|
|
|
static Action<float, float, float> TeleportRelative {get; private set;} |
|
|
|
|
|
|
|
static Dictionary<object,float[3]> _waypoints {get;} = new Dictionnary<object, float[3]>(); |
|
|
|
|
|
|
|
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<float, float, float>), 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<RigidBodyEntityStruct>(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()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |