@@ -1,6 +1,4 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using RobocraftX.GUI.CommandLine; | |||
using Harmony; | |||
using UnityEngine; | |||
@@ -8,22 +6,16 @@ using UnityEngine; | |||
namespace TestMod.Waypoints | |||
{ | |||
[HarmonyPatch(typeof(TeleportCharacterCommandEngine))] | |||
[HarmonyPatch(typeof(new Type[] {}))] | |||
class TeleportEnginePatch | |||
[HarmonyPatch("Ready")] | |||
[HarmonyPatch(new Type[] { })] | |||
public static class TeleportEnginePatch | |||
{ | |||
static TeleportCharacterCommandEngine Instance {get; private set;} | |||
public static TeleportCharacterCommandEngine Instance {get; private set;} | |||
static void Postfix(TeleportCharacterCommandEngine __result, TeleportCharacterCommandEngine __instance) | |||
static void Postfix(TeleportCharacterCommandEngine __instance) | |||
{ | |||
// this works because this class should be a singleton; only one copy of it should exist at a time | |||
if (__instance != null) | |||
{ | |||
Instance = __instance; | |||
Debug.Log("Instance caught from constructor"); | |||
} else { | |||
Instance = __result; | |||
Debug.Log("Result caught from constructor") | |||
} | |||
Instance = __instance; | |||
Debug.Log("Caught TeleportCharacterCommandEngine"); | |||
} | |||
} | |||
@@ -1,29 +1,27 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using System.Dictionary.Generic; | |||
using Harmony; | |||
using UnityEngine; | |||
using Unity.Mathematics; | |||
using RobocraftX.Character; | |||
using RobocraftX.StateSync; | |||
using RobocraftX.GUI.CommandLine; | |||
using Svelto.ECS; | |||
using uREPL; | |||
namespace TestMod.Waypoints | |||
{ | |||
[HarmonyPatch(typeof(uREPL.RuntimeCommands))] | |||
[HarmonyPatch("Register")] | |||
[HarmonyPatch(new Type[] { typeof(string), typeof(Action<float,float,float>), typeof(string) })] | |||
class TeleportPatch | |||
[HarmonyPatch] | |||
public static class TeleportPatch | |||
{ | |||
// TeleportPatch intercepts all Register(string, Action<float,float,float> string) method calls | |||
// which allows it to catch Teleport Actions as they're registered as CLI commands | |||
static Action<float,float,float> TeleportAbsolute {get; private set;} | |||
public static Action<float,float,float> TeleportAbsolute {get; private set;} | |||
static Action<float, float, float> TeleportRelative {get; private set;} | |||
public static Action<float, float, float> TeleportRelative {get; private set;} | |||
static Dictionary<object,float[3]> _waypoints {get;} = new Dictionnary<object, float[3]>(); | |||
public static Dictionary<object,float[]> _waypoints {get;} = new Dictionary<object, float[]>(); | |||
static void Prefix(string name, Action func, string description) | |||
static void Prefix(string name, Action<float,float,float> func, string description) | |||
{ | |||
Debug.Log("Caught Register method call for "+name); | |||
if (name.Equals("TeleportPlayerAbsolute")) | |||
@@ -37,7 +35,18 @@ namespace TestMod.Waypoints | |||
} | |||
} | |||
static void WaypointHereCommand(object name) | |||
static MethodBase TargetMethod(HarmonyInstance instance) | |||
{ | |||
// TODO: make less hacky | |||
return _giveMeMethodInfoFFS(uREPL.RuntimeCommands.Register<float, float, float>); | |||
} | |||
private static MethodInfo _giveMeMethodInfoFFS(Action<string, Action<float, float, float>, string> a) | |||
{ | |||
return a.Method; | |||
} | |||
public static void WaypointHereCommand(object name) | |||
{ | |||
// hopefully entitiesDB does not become private in the future... | |||
if (TeleportEnginePatch.Instance == null) | |||
@@ -49,12 +58,13 @@ namespace TestMod.Waypoints | |||
{ | |||
_waypoints.Remove(name); | |||
} | |||
ref RigidBodyEntityStruct reference = ref TeleportEnginePatch.Instance.entitiesDB.QueryEntity<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.CharacterGroup); | |||
_waypoints.Add(new float[3]{reference.x, reference.y, reference.z}); | |||
IEntitiesDB entitiesDB = Harmony.Traverse.Create(TeleportEnginePatch.Instance).Property("entitiesDB").GetValue<IEntitiesDB>(); | |||
ref PhysicsEntityStruct reference = ref entitiesDB.QueryEntity<PhysicsEntityStruct>(0u, CharacterExclusiveGroups.CharacterGroup); | |||
_waypoints.Add(name, new float[3]{reference.position.x, reference.position.y, reference.position.z}); | |||
uREPL.Log.Output("Saved "+name.ToString()); | |||
} | |||
static void TeleportToWaypointCommand(object name) | |||
public static void TeleportToWaypointCommand(object name) | |||
{ | |||
if (!_waypoints.ContainsKey(name)) | |||
{ | |||
@@ -67,7 +77,6 @@ namespace TestMod.Waypoints | |||
return; | |||
} | |||
TeleportAbsolute(_waypoints[name][0], _waypoints[name][1], _waypoints[name][2]); | |||
uREPL.Log.Output("Teleported player to "+name.ToString()); | |||
} | |||
} | |||
@@ -15,6 +15,24 @@ | |||
<Reference Include="IllusionPlugin"> | |||
<HintPath>..\..\..\IPA\IPA\bin\Debug\IPA\Data\Managed\IllusionPlugin.dll</HintPath> | |||
</Reference> | |||
<Reference Include="RobocraftX.Character"> | |||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\RobocraftX.Character.dll</HintPath> | |||
</Reference> | |||
<Reference Include="RobocraftX.StateSync"> | |||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\RobocraftX.StateSync.dll</HintPath> | |||
</Reference> | |||
<Reference Include="Svelto.ECS"> | |||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\Svelto.ECS.dll</HintPath> | |||
</Reference> | |||
<Reference Include="Unity.Mathematics"> | |||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\Unity.Mathematics.dll</HintPath> | |||
</Reference> | |||
<Reference Include="Unity.Mathematics.Extensions"> | |||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\Unity.Mathematics.Extensions.dll</HintPath> | |||
</Reference> | |||
<Reference Include="Unity.Mathematics.Extensions.Hybrid"> | |||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\Unity.Mathematics.Extensions.Hybrid.dll</HintPath> | |||
</Reference> | |||
<Reference Include="UnityEngine"> | |||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\UnityEngine.dll</HintPath> | |||
</Reference> | |||
@@ -38,9 +38,9 @@ namespace TestMod | |||
uREPL.RuntimeCommands.Register("Exit", QuitCommand, "Close Gamecraft"); | |||
commandHelp.Invoke(null, new string[] { "Exit", "Forcefully exit Gamecraft immediately" }); | |||
// waypoint commands | |||
uREPL.RuntimeCommands.Register<object>("WaypointHere", Waypoints.WaypointHereCommand, "/shrug"); | |||
uREPL.RuntimeCommands.Register<object>("WaypointHere", Waypoints.TeleportPatch.WaypointHereCommand, "/shrug"); | |||
commandHelp.Invoke(null, new string[] { "WaypointHere", "Create a named waypoint in your current location" }); | |||
uREPL.RuntimeCommands.Register<object>("TeleportToWaypoint", Waypoints.TeleportToWaypoint, "Blame Josh"); | |||
uREPL.RuntimeCommands.Register<object>("TeleportToWaypoint", Waypoints.TeleportPatch.TeleportToWaypointCommand, "Blame Josh"); | |||
commandHelp.Invoke(null, new string[] { "TeleportToWaypoint", "Teleport to a waypoint by name" }); | |||
Debug.Log("TestPlugin startup complete"); | |||
} | |||