diff --git a/TweaksAndThings/AutoEngineerDestinationPicker_Loop_Patch.cs b/TweaksAndThings/AutoEngineerDestinationPicker_Loop_Patch.cs new file mode 100644 index 0000000..1594772 --- /dev/null +++ b/TweaksAndThings/AutoEngineerDestinationPicker_Loop_Patch.cs @@ -0,0 +1,62 @@ +using HarmonyLib; +using Helpers; +using Model.AI; +using Railloader; +using Serilog; +using System.Collections; +using Track; +using UI; +using UnityEngine; +using static Game.Messages.RequestOps; +using static UI.AutoEngineerDestinationPicker; + +namespace RMROC451.TweaksAndThings; + +[HarmonyPatch(typeof(AutoEngineerDestinationPicker))] +[HarmonyPatch(nameof(AutoEngineerDestinationPicker.Loop))] +[HarmonyPatchCategory("RMROC451TweaksAndThings")] +internal class AutoEngineerDestinationPicker_Loop_Patch +{ + static bool Prefix(AutoEngineerDestinationPicker __instance, ref IEnumerator __result) + { + TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase.Shared; + if (!tweaksAndThings.IsEnabled()) return true; + + __result = Loop(__instance); + + return false; + } + + private static IEnumerator Loop(AutoEngineerDestinationPicker __instance) + { + Hit valueOrDefault; + Location location; + WaitForSecondsRealtime wait = new WaitForSecondsRealtime(.1f); + while (true) + { + Location? currentOrdersGotoLocation = __instance.GetCurrentOrdersGotoLocation(); + Hit? hit = __instance.HitLocation(); + if (hit.HasValue) + { + valueOrDefault = hit.GetValueOrDefault(); + location = valueOrDefault.Location; + Graph.PositionRotation positionRotation = __instance._graph.GetPositionRotation(location); + __instance.destinationMarker.position = WorldTransformer.GameToWorld(positionRotation.Position); + __instance.destinationMarker.rotation = positionRotation.Rotation; + __instance.destinationMarker.gameObject.SetActive(value: true); + if (!currentOrdersGotoLocation.Equals(location) && __instance.MouseClicked) + { + break; + } + } + else + { + __instance.destinationMarker.gameObject.SetActive(value: false); + } + yield return wait; + } + Log.Debug("DestinationPicker Hit: {hit} {car} {end}", valueOrDefault.Location, valueOrDefault.CarInfo?.car, valueOrDefault.CarInfo?.end); + __instance._ordersHelper.SetWaypoint(location, valueOrDefault.CarInfo?.car.id); + __instance.StopLoop(); + } +}