Browse Source

Add untested waypoint commands

tags/v0.0.0a
NGnius (Graham) 5 years ago
parent
commit
f077373f8b
2 changed files with 96 additions and 0 deletions
  1. +22
    -0
      TestMod/TeleportEnginePatch.cs
  2. +74
    -0
      TestMod/TeleportPatch.cs

+ 22
- 0
TestMod/TeleportEnginePatch.cs View File

@@ -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");
}
}
}

+ 74
- 0
TestMod/TeleportPatch.cs View File

@@ -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());
}
}

}