From 3358f410452897465df0dcc8c4d772e65c1ae255 Mon Sep 17 00:00:00 2001 From: nt153133 <52430037+nt153133@users.noreply.github.com> Date: Sun, 24 Nov 2024 12:37:34 -0500 Subject: [PATCH] feat: Add teleport with tickets code --- Helpers/TeleportHelper.cs | 367 ++++++++++++++++++++++++-------------- 1 file changed, 235 insertions(+), 132 deletions(-) diff --git a/Helpers/TeleportHelper.cs b/Helpers/TeleportHelper.cs index 1f23db3..556695a 100644 --- a/Helpers/TeleportHelper.cs +++ b/Helpers/TeleportHelper.cs @@ -6,219 +6,322 @@ using ff14bot; using ff14bot.Behavior; using ff14bot.Managers; +using ff14bot.RemoteWindows; using LlamaLibrary.Enums; using LlamaLibrary.Logging; using LlamaLibrary.Memory.Attributes; using LlamaLibrary.Structs; -namespace LlamaLibrary.Helpers +namespace LlamaLibrary.Helpers; + +public static class TeleportHelper { - public static class TeleportHelper + private static readonly LLogger Log = new(nameof(TeleportHelper), Colors.MediumTurquoise); + + private static DateTime _lastUpdate; + + private static World _lastUpdateWorld; + + private static TeleportInfo[] _teleportList; + + static TeleportHelper() { - private static readonly LLogger Log = new(nameof(TeleportHelper), Colors.MediumTurquoise); + UpdateTeleportArray(); + } - private static class Offsets + public static TeleportInfo[] TeleportList + { + get { - //7.1 - [Offset("Search E8 ? ? ? ? 49 89 44 24 ? 4C 8B F8 TraceCall")] - [OffsetCN("Search E8 ? ? ? ? 49 89 47 68 TraceCall")] - internal static IntPtr UpdatePlayerAetheryteList; + if (DateTime.Now.Subtract(_lastUpdate).TotalMinutes > 5 || (WorldHelper.IsOnHomeWorld && _lastUpdateWorld != WorldHelper.HomeWorld)) + { + UpdateTeleportArray(); + } + + return _teleportList; } + } - private static DateTime _lastUpdate; + public static void UpdateTeleportArray() + { + CallUpdate(); + _lastUpdate = DateTime.Now; + _lastUpdateWorld = WorldHelper.CurrentWorld; + _teleportList = Core.Memory.Read(Memory.Offsets.UIStateTelepo).TeleportInfos; + } - private static World _lastUpdateWorld; + public static void CallUpdate() + { + Core.Memory.CallInjected64(Offsets.UpdatePlayerAetheryteList, Memory.Offsets.UIStateTelepo, 0); + } - private static TeleportInfo[] _teleportList; + public static async Task TeleportToApartment() + { + var house = -1; - public static TeleportInfo[] TeleportList + for (var index = 0; index < TeleportList.Length; index++) { - get + if (TeleportList[index].IsOwnHouse && _teleportList[index].IsApartment) { - if ((DateTime.Now.Subtract(_lastUpdate).TotalMinutes > 5) || (WorldHelper.IsOnHomeWorld && _lastUpdateWorld != WorldHelper.HomeWorld)) - { - UpdateTeleportArray(); - } - - return _teleportList; + house = index; + break; } } - static TeleportHelper() + if (house == -1) { - UpdateTeleportArray(); + Log.Information("Can't find teleport"); + return false; } - public static void UpdateTeleportArray() + return await TeleportWithTicket(TeleportList[house]); + } + + public static async Task TeleportToPrivateEstate() + { + var house = -1; + + for (var index = 0; index < TeleportList.Length; index++) { - //Log.Information("Updating teleport"); - CallUpdate(); - _lastUpdate = DateTime.Now; - _lastUpdateWorld = WorldHelper.CurrentWorld; - _teleportList = Core.Memory.Read(LlamaLibrary.Memory.Offsets.UIStateTelepo).TeleportInfos; - //Log.Information("Finished updating teleport"); + if (TeleportList[index].IsOwnHouse && !_teleportList[index].IsApartment) + { + house = index; + break; + } } - public static void CallUpdate() + if (house == -1) { - Core.Memory.CallInjected64(Offsets.UpdatePlayerAetheryteList, LlamaLibrary.Memory.Offsets.UIStateTelepo, 0); + Log.Information("Can't find teleport"); + return false; } - public static async Task TeleportToApartment() - { - var house = -1; + return await TeleportWithTicket(TeleportList[house]); + } - for (var index = 0; index < TeleportList.Length; index++) - { - if (TeleportList[index].IsOwnHouse && _teleportList[index].IsApartment) - { - house = index; - break; - } - } + public static async Task TeleportToFreeCompanyEstate() + { + var house = -1; - if (house == -1) + for (var index = 0; index < TeleportList.Length; index++) + { + if (!TeleportList[index].IsFCHouse) { - Log.Information("Can't find teleport"); - return false; + continue; } - return await TeleportByIndex(house); + house = index; + break; } - public static async Task TeleportToPrivateEstate() + if (house != -1) { - var house = -1; + return await TeleportWithTicket(TeleportList[house]); + } - for (var index = 0; index < TeleportList.Length; index++) + Log.Information("Can't find teleport"); + foreach (var teleportInfo in TeleportList.Take(5)) + { + Log.Information(teleportInfo.ToString()); + } + + return false; + } + + public static async Task TeleportToSharedEstate(int estateIndex) + { + var house = -1; + var count = 0; + for (var index = 0; index < TeleportList.Length; index++) + { + if (!TeleportList[index].IsSharedHouse) { - if (TeleportList[index].IsOwnHouse && !_teleportList[index].IsApartment) - { - house = index; - break; - } + continue; } - if (house == -1) + if (count == estateIndex) { - Log.Information("Can't find teleport"); - return false; + house = index; + break; } - return await TeleportByIndex(house); + count++; } - public static async Task TeleportToFreeCompanyEstate() + if (house != -1) { - var house = -1; + return await TeleportWithTicket(TeleportList[house]); + } + + Log.Information("Can't find teleport"); + return false; + } - for (var index = 0; index < TeleportList.Length; index++) + public static async Task TeleportToSharedEstate(ushort zone, int ward, int plot) + { + var house = -1; + + for (var index = 0; index < TeleportList.Length; index++) + { + if (!TeleportList[index].IsSharedHouse) { - if (TeleportList[index].IsFCHouse) - { - house = index; - break; - } + continue; } - if (house == -1) + if (TeleportList[index].TerritoryId == zone && TeleportList[index].Ward == ward && TeleportList[index].Plot == plot) { - Log.Information("Can't find teleport"); - foreach (var teleportInfo in TeleportList.Take(5)) - { - Log.Information(teleportInfo.ToString()); - } - - return false; + house = index; + break; } + } - return await TeleportByIndex(house); + if (house != -1) + { + return await TeleportWithTicket(TeleportList[house]); } - public static async Task TeleportToSharedEstate(int estateIndex) + Log.Information("Can't find teleport"); + return false; + } + + private static async Task TeleportByIndex(int index) + { + return await TeleportByIndex((uint)index); + } + + public static async Task TeleportByIndex(uint index) + { + Log.Information($"Using teleport index {index}"); + if (WorldManager.CanTeleport() || await Coroutine.Wait(5000, WorldManager.CanTeleport)) { - var house = -1; - var count = 0; - for (var index = 0; index < TeleportList.Length; index++) + if (!WorldManager.Teleport(index)) { - if (TeleportList[index].IsSharedHouse) + Log.Information("Can't teleport"); + } + + if (await Coroutine.Wait(5000, () => Core.Me.IsCasting) && await Coroutine.Wait(10000, () => !Core.Me.IsCasting)) + { + if (await Coroutine.Wait(5000, () => CommonBehaviors.IsLoading) && await Coroutine.Wait(-1, () => !CommonBehaviors.IsLoading)) { - if (count == estateIndex) + if (await Coroutine.Wait(10000, () => WorldManager.AvailableLocations[index].ZoneId == WorldManager.ZoneId)) { - house = index; - break; + await Coroutine.Sleep(1000); + return true; } - - count++; } } + } - if (house == -1) - { - Log.Information("Can't find teleport"); - return false; - } + Log.Error("Failed trying to teleport"); + return false; + } - return await TeleportByIndex(house); + public static bool TeleportUsingTicket(uint ae, byte subIndex = 0) + { + return Core.Memory.CallInjected64(Offsets.TeleportWithSettings, Offsets.Telepo, ae, subIndex) != 0; + } + + public static async Task TeleportWithTicket(AetheryteResult aetheryte) + { + Log.Information($"Using teleport location {aetheryte.CurrentLocaleAethernetName}"); + + if (!WorldManager.CanTeleport() && !await Coroutine.Wait(5000, WorldManager.CanTeleport)) + { + Log.Error("Can't teleport"); + return false; } - public static async Task TeleportToSharedEstate(ushort zone, int ward, int plot) + return await TeleportByIdTicket(aetheryte.Id); + } + + public static async Task TeleportWithTicket(TeleportInfo location) + { + Log.Information($"Using teleport location {location.ZoneName}"); + + if (!WorldManager.CanTeleport() && !await Coroutine.Wait(5000, WorldManager.CanTeleport)) { - var house = -1; - var count = 0; - for (var index = 0; index < TeleportList.Length; index++) - { - if (TeleportList[index].IsSharedHouse) - { - if (TeleportList[index].TerritoryId == zone && TeleportList[index].Ward == ward && TeleportList[index].Plot == plot) - { - house = index; - break; - } + Log.Error("Can't teleport"); + return false; + } - count++; - } - } + if (!TeleportUsingTicket(location.AetheryteId, location.SubIndex)) + { + Log.Error("Teleport Failed"); + return false; + } - if (house == -1) - { - Log.Information("Can't find teleport"); - return false; - } + return await HandleTeleport(location.TerritoryId); + } + + public static async Task TeleportByIndexTicket(int index) + { + var location = TeleportList[index]; + return await TeleportWithTicket(location); + } - return await TeleportByIndex(house); + public static async Task TeleportByIdTicket(uint aetheryteId) + { + Log.Information($"Using AE id {DataManager.AetheryteCache[aetheryteId].CurrentLocaleAethernetName}"); + if (!WorldManager.CanTeleport() && !await Coroutine.Wait(5000, WorldManager.CanTeleport)) + { + Log.Error("Can't teleport"); + return false; } - private static async Task TeleportByIndex(int index) + if (!TeleportUsingTicket(aetheryteId)) { - return await TeleportByIndex((uint)index); + Log.Error("Teleport Failed"); + return false; } - public static async Task TeleportByIndex(uint index) + return await HandleTeleport((ushort)WorldManager.GetZoneForAetheryteId(aetheryteId)); + } + + private static async Task HandleTeleport(ushort newZone) + { + if (!await Coroutine.Wait(5000, () => Core.Me.IsCasting || SelectYesno.IsOpen)) + { + Log.Error("Failed to cast"); + return false; + } + + if (SelectYesno.IsOpen) { - Log.Information($"Using teleport index {index}"); - if (WorldManager.CanTeleport() || await Coroutine.Wait(5000, WorldManager.CanTeleport)) + SelectYesno.Yes(); + if (!await Coroutine.Wait(5000, () => Core.Me.IsCasting)) { - if (!WorldManager.Teleport(index)) - { - Log.Information("WTF can't teleport"); - } + Log.Error("Failed to cast"); + return false; + } + } - if (await Coroutine.Wait(5000, () => Core.Me.IsCasting) && await Coroutine.Wait(10000, () => !Core.Me.IsCasting)) + if (await Coroutine.Wait(10000, () => !Core.Me.IsCasting)) + { + if (await Coroutine.Wait(5000, () => CommonBehaviors.IsLoading) && await Coroutine.Wait(-1, () => !CommonBehaviors.IsLoading)) + { + if (await Coroutine.Wait(10000, () => newZone == WorldManager.ZoneId)) { - if (await Coroutine.Wait(5000, () => CommonBehaviors.IsLoading) && await Coroutine.Wait(-1, () => !CommonBehaviors.IsLoading)) - { - if (await Coroutine.Wait(10000, () => WorldManager.AvailableLocations[index].ZoneId == WorldManager.ZoneId)) - { - await Coroutine.Sleep(1000); - return true; - } - } + await Coroutine.Sleep(1000); + return true; } } - - Log.Error("Shit failed trying to teleport"); - return false; } + + Log.Error("Failed trying to teleport"); + return false; + } + + private static class Offsets + { + //7.1 + [Offset("Search E8 ? ? ? ? 49 89 44 24 ? 4C 8B F8 TraceCall")] + [OffsetCN("Search E8 ? ? ? ? 49 89 47 68 TraceCall")] + internal static IntPtr UpdatePlayerAetheryteList; + + [Offset("Search E8 ? ? ? ? 48 8B 4B ? 84 C0 48 8B 01 74 ? Add 1 TraceRelative")] + internal static IntPtr TeleportWithSettings; + + [Offset("Search 48 8D 0D ? ? ? ? 8B FA E8 ? ? ? ? 48 8B 4B ? Add 3 TraceRelative")] + internal static IntPtr Telepo; } } \ No newline at end of file