diff --git a/SneakOnBy.DataBuilder/Builder.cs b/SneakOnBy.DataBuilder/Builder.cs index a47f60e..da257f7 100644 --- a/SneakOnBy.DataBuilder/Builder.cs +++ b/SneakOnBy.DataBuilder/Builder.cs @@ -61,7 +61,7 @@ static void Main(string[] args) var uniqueId = $"{m.Groups[1].Captures[0].Value}_{m.Groups[2].Captures[0].Value}_{npc.Key}"; if(bnpcAgro.ContainsKey(uniqueId) && !bnpcAgro[uniqueId].Equals(agro)) { - System.Console.WriteLine($"Found duplicate {name} with different agro types."); + System.Console.WriteLine($"Found duplicate {uniqueId} {name} with different agro types."); } else if(!bnpcAgro.ContainsKey(uniqueId)) { diff --git a/SneakOnBy/Configuration.cs b/SneakOnBy/Configuration.cs index 3e8d5d5..770ea26 100644 --- a/SneakOnBy/Configuration.cs +++ b/SneakOnBy/Configuration.cs @@ -22,18 +22,9 @@ public class Configuration : IPluginConfiguration public Vector4 UnknownColorFront { get; set; } = ImGuiColors.DalamudGrey.WithW(0.2f); public Vector4 UnknownColorBack { get; set; } = ImGuiColors.DalamudGrey3.WithW(0.2f); - // the below exist just to make saving less cumbersome - [NonSerialized] - private DalamudPluginInterface? PluginInterface; - - public void Initialize(DalamudPluginInterface pluginInterface) - { - this.PluginInterface = pluginInterface; - } - public void Save() { - this.PluginInterface!.SavePluginConfig(this); + Services.PluginInterface!.SavePluginConfig(this); } } } diff --git a/SneakOnBy/DeepDungeonDex.cs b/SneakOnBy/DeepDungeonDex.cs deleted file mode 100644 index d79d732..0000000 --- a/SneakOnBy/DeepDungeonDex.cs +++ /dev/null @@ -1,121 +0,0 @@ -using Dalamud.Logging; -using Dalamud.Plugin; -using ECommons.Reflection; -using FFXIVClientStructs.FFXIV.Component.GUI; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -namespace SneakOnBy -{ - internal static class DeepDungeonDex - { - internal static IDalamudPlugin Instance; - internal static object StorageHandler; - - internal static Boolean TryConnect() - { - if (Instance == null || StorageHandler == null) - { - Connect(); - } - - return Instance != null && StorageHandler != null; - } - - static void Connect() - { - try - { - PluginLog.Information("Trying to connect to DeepDungeonDex"); - if (DalamudReflector.TryGetDalamudPlugin("DeepDungeonDex", out var plugin, false, true)) - { - Instance = plugin; - PluginLog.Information("Successfully connected to DeepDungeonDex."); - var provider = ReflectionHelper.GetFoP(Instance, "_provider"); - if(provider != null) - { - PluginLog.Information("Successfully got provider"); - - Type storageHandlerType = Assembly.GetAssembly(Instance.GetType()).GetType("DeepDungeonDex.Storage.StorageHandler"); - - var storageHandler = provider.GetType().GetMethod("GetService").Invoke(provider, new object[] { storageHandlerType }); - if(storageHandler != null) - { - PluginLog.Information("Successfully got storageHandler"); - StorageHandler = storageHandler; - } - } - } - else - { - throw new Exception("DeepDungeonDex is not initialized"); - } - } - catch (Exception e) - { - PluginLog.Error("Can't find DeepDungeonDex plugin: " + e.Message); - PluginLog.Error(e.StackTrace); - } - } - - internal static void Reset() - { - Instance = null; - StorageHandler = null; - PluginLog.Information("Disconnected from DeepDungeonDex"); - } - - public static Aggro GetMobAggroType(uint id) - { - if(TryConnect()) - { - Type mobDataType = Assembly.GetAssembly(StorageHandler.GetType()).GetType("DeepDungeonDex.Storage.MobData"); - MethodInfo getInstancesMethod = StorageHandler.GetType().GetMethod("GetInstances", new Type[] { }).MakeGenericMethod(new Type[] { mobDataType }); - if(getInstancesMethod != null) - { - var instances = (object[]) getInstancesMethod.Invoke(StorageHandler, new object[] { }); - var data = GetData(instances, id); - if(data != null) - { - var aggro = ReflectionHelper.GetFoP(data, "Aggro"); - string aggroStr = Enum.GetName(aggro.GetType(), aggro); - return (Aggro) Enum.Parse(typeof(Aggro), aggroStr); - } - } - } - - return Aggro.Undefined; - } - - private static object? GetData(this IEnumerable data, uint key) - { - foreach(object l in data) - { - var dict = ReflectionHelper.GetFoP(l, "MobDictionary") as IDictionary; - if (dict != null && dict.Contains(key)) - { - return dict[key]; - } - } - return null; - } - } - - public enum Aggro - { - Undefined, - Sight, - Sound, - Proximity, - Boss - } - - -} diff --git a/SneakOnBy/ECommons/CardinalDirection.cs b/SneakOnBy/ECommons/CardinalDirection.cs index 2d52d38..28da688 100644 --- a/SneakOnBy/ECommons/CardinalDirection.cs +++ b/SneakOnBy/ECommons/CardinalDirection.cs @@ -1,4 +1,4 @@ -namespace ECommons.MathHelpers; +namespace ECommons.MathHelpers; public enum CardinalDirection { diff --git a/SneakOnBy/ECommons/DalamudReflector.cs b/SneakOnBy/ECommons/DalamudReflector.cs deleted file mode 100644 index e8cc22c..0000000 --- a/SneakOnBy/ECommons/DalamudReflector.cs +++ /dev/null @@ -1,168 +0,0 @@ -using Dalamud; -using Dalamud.Game.ClientState.Keys; -using Dalamud.Plugin; -using ECommons.Schedulers; -using SneakOnBy; -using System; -using System.Collections.Generic; -using System.Reflection; - -namespace ECommons.Reflection; - -public static class DalamudReflector -{ - delegate ref int GetRefValue(int vkCode); - static GetRefValue getRefValue; - static Dictionary pluginCache; - static List onPluginsChangedActions; - - internal static void Init() - { - onPluginsChangedActions = new(); - pluginCache = new(); - GenericHelpers.Safe(delegate - { - getRefValue = (GetRefValue)Delegate.CreateDelegate(typeof(GetRefValue), Services.KeyState, - Services.KeyState.GetType().GetMethod("GetRefValue", - BindingFlags.NonPublic | BindingFlags.Instance, - null, new Type[] { typeof(int) }, null)); - }, (e) => { - Services.PluginLog.Error(e); - }); - Services.PluginInterface.ActivePluginsChanged += OnInstalledPluginsChanged; - } - - internal static void Dispose() - { - if (pluginCache != null) - { - pluginCache = null; - onPluginsChangedActions = null; - } - Services.PluginInterface.ActivePluginsChanged -= OnInstalledPluginsChanged; - } - - public static void RegisterOnInstalledPluginsChangedEvents(params Action[] actions) - { - foreach (var x in actions) - { - onPluginsChangedActions.Add(x); - } - } - - public static void SetKeyState(VirtualKey key, int state) - { - getRefValue((int)key) = state; - } - - public static object GetPluginManager() - { - return Services.PluginInterface.GetType().Assembly. - GetType("Dalamud.Service`1", true).MakeGenericType(Services.PluginInterface.GetType().Assembly.GetType("Dalamud.Plugin.Internal.PluginManager", true)). - GetMethod("Get").Invoke(null, BindingFlags.Default, null, Array.Empty(), null); - } - - public static object GetService(string serviceFullName) - { - return Services.PluginInterface.GetType().Assembly. - GetType("Dalamud.Service`1", true).MakeGenericType(Services.PluginInterface.GetType().Assembly.GetType(serviceFullName, true)). - GetMethod("Get").Invoke(null, BindingFlags.Default, null, Array.Empty(), null); - } - - public static bool TryGetLocalPlugin(out object localPlugin, out Type type) - { - try - { - var pluginManager = GetPluginManager(); - var installedPlugins = (System.Collections.IList)pluginManager.GetType().GetProperty("InstalledPlugins").GetValue(pluginManager); - - foreach (var t in installedPlugins) - { - if (t != null) - { - type = t.GetType().Name == "LocalDevPlugin" ? t.GetType().BaseType : t.GetType(); - if (object.ReferenceEquals(type.GetField("instance", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(t), Plugin.Instance)) - { - localPlugin = t; - return true; - } - } - } - localPlugin = type = null; - return false; - } - catch (Exception e) - { - Services.PluginLog.Error(e.StackTrace); - localPlugin = type = null; - return false; - } - } - - public static bool TryGetDalamudPlugin(string internalName, out IDalamudPlugin instance, bool suppressErrors = false, bool ignoreCache = false) - { - if (pluginCache == null) - { - throw new Exception("PluginCache is null. Have you initialised the DalamudReflector module on ECommons initialisation?"); - } - - if (!ignoreCache && pluginCache.TryGetValue(internalName, out instance) && instance != null) - { - return true; - } - try - { - var pluginManager = GetPluginManager(); - var installedPlugins = (System.Collections.IList)pluginManager.GetType().GetProperty("InstalledPlugins").GetValue(pluginManager); - - foreach (var t in installedPlugins) - { - if ((string)t.GetType().GetProperty("Name").GetValue(t) == internalName) - { - var type = t.GetType().Name == "LocalDevPlugin" ? t.GetType().BaseType : t.GetType(); - var plugin = (IDalamudPlugin)type.GetField("instance", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(t); - if (plugin == null) - { - Services.PluginLog.Warning($"Found requested plugin {internalName} but it was null"); - } - else - { - instance = plugin; - pluginCache[internalName] = plugin; - return true; - } - } - } - instance = null; - return false; - } - catch (Exception e) - { - if (!suppressErrors) - { - Services.PluginLog.Error($"Can't find {internalName} plugin: " + e.Message); - Services.PluginLog.Error(e.StackTrace); - } - instance = null; - return false; - } - } - - public static string GetPluginName() - { - return Services.PluginInterface?.InternalName ?? "Not initialized"; - } - - internal static void OnInstalledPluginsChanged(PluginListInvalidationKind kind, bool affectedThisPlugin) - { - Services.PluginLog.Verbose("Installed plugins changed event fired"); - _ = new TickScheduler(delegate - { - pluginCache.Clear(); - foreach (var x in onPluginsChangedActions) - { - x(); - } - }); - } -} diff --git a/SneakOnBy/ECommons/GenericHelpers.cs b/SneakOnBy/ECommons/GenericHelpers.cs deleted file mode 100644 index f182da5..0000000 --- a/SneakOnBy/ECommons/GenericHelpers.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace ECommons; - -public static unsafe class GenericHelpers -{ - public static void Safe(System.Action a, Action fail, bool suppressErrors = false) - { - try - { - a(); - } - catch (Exception e) - { - try - { - fail(e.Message); - } - catch(Exception ex) - { - Services.PluginLog.Error("Error while trying to process error handler:"); - Services.PluginLog.Error($"{ex.Message}\n{ex.StackTrace ?? ""}"); - suppressErrors = false; - } - if (!suppressErrors) Services.PluginLog.Error($"{e.Message}\n{e.StackTrace ?? ""}"); - } - } -} diff --git a/SneakOnBy/ECommons/IScheduler.cs b/SneakOnBy/ECommons/IScheduler.cs deleted file mode 100644 index c0c8493..0000000 --- a/SneakOnBy/ECommons/IScheduler.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; - -namespace ECommons.Schedulers; - -public interface IScheduler : IDisposable -{ -} diff --git a/SneakOnBy/ECommons/MathHelper.cs b/SneakOnBy/ECommons/MathHelper.cs index 7d66c48..a054e05 100644 --- a/SneakOnBy/ECommons/MathHelper.cs +++ b/SneakOnBy/ECommons/MathHelper.cs @@ -1,3 +1,4 @@ +using SneakOnBy; using System; using System.Numerics; diff --git a/SneakOnBy/ECommons/ReflectionHelper.cs b/SneakOnBy/ECommons/ReflectionHelper.cs deleted file mode 100644 index 8bcfe8f..0000000 --- a/SneakOnBy/ECommons/ReflectionHelper.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System.Linq; -using System.Reflection; - -namespace ECommons.Reflection; - -public static class ReflectionHelper -{ - public const BindingFlags AllFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; - public const BindingFlags StaticFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; - - public static object GetFoP(this object obj, string name) - { - return obj.GetType().GetField(name, AllFlags)?.GetValue(obj) - ?? obj.GetType().GetProperty(name, AllFlags)?.GetValue(obj); - } - - public static T GetFoP(this object obj, string name) - { - return (T)GetFoP(obj, name); - } - - public static void SetFoP(this object obj, string name, object value) - { - var field = obj.GetType().GetField(name, AllFlags); - if(field != null) - { - field.SetValue(obj, value); - } - else - { - obj.GetType().GetProperty(name, AllFlags).SetValue(obj, value); - } - } - - public static object GetStaticFoP(this object obj, string type, string name) - { - return obj.GetType().Assembly.GetType(type).GetField(name, StaticFlags)?.GetValue(null) - ?? obj.GetType().Assembly.GetType(type).GetProperty(name, StaticFlags)?.GetValue(null); - } - - public static T GetStaticFoP(this object obj, string type, string name) - { - return (T)GetStaticFoP(obj, type, name); - } - - public static void SetStaticFoP(this object obj, string type, string name, object value) - { - var field = obj.GetType().Assembly.GetType(type).GetField(name, StaticFlags); - if (field != null) - { - field.SetValue(null, value); - } - else - { - obj.GetType().Assembly.GetType(type).GetProperty(name, StaticFlags).SetValue(null, value); - } - } - - public static object Call(this object obj, string name, params object[] values) - { - var info = obj.GetType().GetMethod(name, AllFlags, values.Select(x => x.GetType()).ToArray()); - return info.Invoke(obj, values); - } -} diff --git a/SneakOnBy/ECommons/TickScheduler.cs b/SneakOnBy/ECommons/TickScheduler.cs deleted file mode 100644 index 4387908..0000000 --- a/SneakOnBy/ECommons/TickScheduler.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; - -namespace ECommons.Schedulers; - -public class TickScheduler : IScheduler -{ - long executeAt; - Action function; - bool disposed = false; - - public TickScheduler(Action function, long delayMS = 0) - { - executeAt = Environment.TickCount64 + delayMS; - this.function = function; - Services.Framework.Update += Execute; - } - - public void Dispose() - { - if (!disposed) - { - Services.Framework.Update -= Execute; - } - disposed = true; - } - - void Execute(object _) - { - if (Environment.TickCount64 < executeAt) return; - try - { - function(); - } - catch (Exception e) - { - Services.PluginLog.Error(e.Message + "\n" + e.StackTrace ?? ""); - } - Dispose(); - } -} diff --git a/SneakOnBy/Plugin.cs b/SneakOnBy/Plugin.cs index 9c3164e..8f4fbbe 100644 --- a/SneakOnBy/Plugin.cs +++ b/SneakOnBy/Plugin.cs @@ -3,9 +3,9 @@ using Dalamud.Plugin; using Dalamud.Interface.Windowing; using SneakOnBy.Windows; -using ECommons; using Dalamud.Plugin.Services; -using ECommons.Reflection; +using SneakOnBy.Storage; +using System.Threading.Tasks; namespace SneakOnBy { @@ -16,30 +16,30 @@ public sealed class Plugin : IDalamudPlugin public static IDalamudPlugin Instance; - private DalamudPluginInterface PluginInterface { get; init; } + private IDalamudPluginInterface PluginInterface { get; init; } private ICommandManager CommandManager { get; init; } public Configuration Configuration { get; init; } + public static StorageManager StorageManager = null!; public WindowSystem WindowSystem = new("SneakOnBy"); private ConfigWindow ConfigWindow { get; init; } private Canvas Canvas { get; init; } public Plugin( - [RequiredVersion("1.0")] DalamudPluginInterface pluginInterface, - [RequiredVersion("1.0")] ICommandManager commandManager) + IDalamudPluginInterface pluginInterface, + ICommandManager commandManager) { Instance = this; this.PluginInterface = pluginInterface; this.CommandManager = commandManager; - Services.Initialize(pluginInterface); - //ECommonsMain.Init(pluginInterface, this, Module.DalamudReflector, Module.ObjectFunctions); + pluginInterface.Create(); - this.Configuration = this.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); - this.Configuration.Initialize(this.PluginInterface); + Configuration = Services.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); - // you might normally want to embed resources and load them from the manifest stream + StorageManager = new StorageManager(); + Task.Run(StorageManager.Load); ConfigWindow = new ConfigWindow(this); Canvas = new Canvas(this); @@ -55,8 +55,6 @@ public Plugin( this.PluginInterface.UiBuilder.Draw += DrawUI; this.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI; - DalamudReflector.Init(); - } @@ -71,8 +69,6 @@ public void Dispose() Canvas.Dispose(); this.CommandManager.RemoveHandler(CommandName); - - DalamudReflector.Dispose(); } private void OnCommand(string command, string args) diff --git a/SneakOnBy/Services.cs b/SneakOnBy/Services.cs index eb5fff6..7291537 100644 --- a/SneakOnBy/Services.cs +++ b/SneakOnBy/Services.cs @@ -2,21 +2,21 @@ using Dalamud.Plugin.Services; using Dalamud.Plugin; +namespace SneakOnBy; + public class Services { - public static void Initialize(DalamudPluginInterface pluginInterface) - => pluginInterface.Create(); - // @formatter:off - [PluginService][RequiredVersion("1.0")] public static IClientState ClientState { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static IGameInteropProvider GameInteropProvider { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static IPluginLog PluginLog { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static IFramework Framework { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static ICondition Condition { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static IObjectTable Objects { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static IGameGui GameGui { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static IKeyState KeyState { get; private set; } = null!; + [PluginService] public static IClientState ClientState { get; private set; } = null!; + [PluginService] public static IGameInteropProvider GameInteropProvider { get; private set; } = null!; + [PluginService] public static IPluginLog PluginLog { get; private set; } = null!; + [PluginService] public static IDalamudPluginInterface PluginInterface { get; private set; } = null!; + [PluginService] public static IFramework Framework { get; private set; } = null!; + [PluginService] public static ICondition Condition { get; private set; } = null!; + [PluginService] public static IObjectTable Objects { get; private set; } = null!; + [PluginService] public static IGameGui GameGui { get; private set; } = null!; + [PluginService] public static IKeyState KeyState { get; private set; } = null!; + [PluginService] public static IDataManager DataManager { get; private set; } = null!; // @formatter:on } diff --git a/SneakOnBy/SneakOnBy.csproj b/SneakOnBy/SneakOnBy.csproj index fa40603..5171533 100644 --- a/SneakOnBy/SneakOnBy.csproj +++ b/SneakOnBy/SneakOnBy.csproj @@ -3,7 +3,7 @@ - 0.0.0.1 + 2.0.0.0 A sample plugin. https://github.com/McSwindler/SneakOnBy @@ -33,6 +33,10 @@ + + + + $(DalamudLibPath)FFXIVClientStructs.dll diff --git a/SneakOnBy/Storage/Aggro.cs b/SneakOnBy/Storage/Aggro.cs new file mode 100644 index 0000000..b798172 --- /dev/null +++ b/SneakOnBy/Storage/Aggro.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace SneakOnBy.Storage +{ + [JsonConverter(typeof(JsonStringEnumConverter))] + public enum Aggro + { + Sight, + Sound, + Proximity, + Undefined + } +} diff --git a/SneakOnBy/Storage/DeepDungeonType.cs b/SneakOnBy/Storage/DeepDungeonType.cs new file mode 100644 index 0000000..c18aec5 --- /dev/null +++ b/SneakOnBy/Storage/DeepDungeonType.cs @@ -0,0 +1,20 @@ +namespace SneakOnBy.Storage +{ + public enum DeepDungeonType + { + PalaceOfTheDead, + HeavenOnHigh, + EurekaOrthos, + } + + public static class DeepDungeonTypeExtensions + { + public static string Shorthand(this DeepDungeonType type) => type switch + { + DeepDungeonType.PalaceOfTheDead => "potd", + DeepDungeonType.HeavenOnHigh => "hoh", + DeepDungeonType.EurekaOrthos => "eo", + _ => string.Empty + }; + } +} diff --git a/SneakOnBy/Storage/StorageManager.cs b/SneakOnBy/Storage/StorageManager.cs new file mode 100644 index 0000000..034c9b5 --- /dev/null +++ b/SneakOnBy/Storage/StorageManager.cs @@ -0,0 +1,35 @@ +using Lumina.Data.Parsing; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace SneakOnBy.Storage +{ + public class StorageManager + { + public Dictionary Enemies = new(); + public bool DataReady; + + public void Load() + { + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = "SneakOnBy.Data.agro.json"; + + var options = new System.Text.Json.JsonSerializerOptions { IncludeFields = true }; + + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + using (StreamReader reader = new StreamReader(stream)) + using (var jsonTextReader = new JsonTextReader(reader)) + { + this.Enemies = new JsonSerializer().Deserialize>(jsonTextReader); + } + + Services.PluginLog.Debug($"Loaded {Enemies.Count} enemies"); + + DataReady = Enemies != null; + } + } + +} diff --git a/SneakOnBy/Utility/DeepDungeonUtil.cs b/SneakOnBy/Utility/DeepDungeonUtil.cs new file mode 100644 index 0000000..0d680f0 --- /dev/null +++ b/SneakOnBy/Utility/DeepDungeonUtil.cs @@ -0,0 +1,67 @@ +using FFXIVClientStructs.FFXIV.Client.Game.Event; +using FFXIVClientStructs.FFXIV.Client.Game.InstanceContent; +using Lumina.Excel.GeneratedSheets; +using SneakOnBy.Storage; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SneakOnBy.Utility +{ + public static class DeepDungeonUtil + { + + public static unsafe InstanceContentDeepDungeon* GetDirector() + { + var eventFramework = EventFramework.Instance(); + return eventFramework == null ? null : eventFramework->GetInstanceContentDeepDungeon(); + } + + public static unsafe bool InDeepDungeon() => GetDirector() != null; + + public static unsafe byte? GetFloor() + { + var director = GetDirector(); + if (director is null) return null; + return director->Floor; + } + + public static uint? GetFloorSetId() + { + if (GetFloor() is { } floor) + { + return (uint)((floor - 1) / 10 * 10 + 1); + } + + return null; + } + + public static DeepDungeonType? GetDeepDungeonType() + { + if (Services.DataManager.GetExcelSheet()?.GetRow(Services.ClientState.TerritoryType) is { } territoryInfo) + { + return territoryInfo switch + { + { TerritoryIntendedUse: 31, ExVersion.Row: 0 or 1 } => DeepDungeonType.PalaceOfTheDead, + { TerritoryIntendedUse: 31, ExVersion.Row: 2 } => DeepDungeonType.HeavenOnHigh, + { TerritoryIntendedUse: 31, ExVersion.Row: 4 } => DeepDungeonType.EurekaOrthos, + _ => null + }; + } + + return null; + } + + public static String? GetUniqueBattleNpcId(uint bNpcId) + { + if (GetDeepDungeonType() is DeepDungeonType dungeonType && GetFloorSetId() is uint floorSet) + { + return $"{dungeonType.Shorthand()}_{floorSet:D3}_{bNpcId}"; + } + + return null; + } + } +} diff --git a/SneakOnBy/Windows/Canvas.cs b/SneakOnBy/Windows/Canvas.cs index f112cdb..c5cd28c 100644 --- a/SneakOnBy/Windows/Canvas.cs +++ b/SneakOnBy/Windows/Canvas.cs @@ -7,6 +7,11 @@ using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Conditions; using Dalamud.Interface.Utility; +using static SneakOnBy.Storage.StorageManager; +using Lumina.Excel.GeneratedSheets; +using SneakOnBy.Utility; +using SneakOnBy.Storage; +using System.Linq; namespace SneakOnBy.Windows; @@ -40,17 +45,18 @@ public override void PreDraw() public override bool DrawConditions() { - return Services.ClientState.LocalPlayer != null && Services.Condition[ConditionFlag.InDeepDungeon]; + return Services.ClientState.LocalPlayer != null && Services.Condition[ConditionFlag.InDeepDungeon] && Plugin.StorageManager.DataReady; } public void Dispose() { } public override void Draw() { - foreach (GameObject obj in Services.Objects) + foreach (IGameObject obj in Services.Objects) { - if (obj is BattleNpc bnpc && bnpc.StatusFlags.HasFlag(StatusFlags.Hostile) && !bnpc.StatusFlags.HasFlag(StatusFlags.InCombat)) { - Aggro aggro = DeepDungeonDex.GetMobAggroType(bnpc.NameId); + if (obj is IBattleNpc bnpc && bnpc.StatusFlags.HasFlag(StatusFlags.Hostile) && !bnpc.StatusFlags.HasFlag(StatusFlags.InCombat)) { + string? uniqueId = DeepDungeonUtil.GetUniqueBattleNpcId(bnpc.NameId); + Aggro aggro = uniqueId != null && Plugin.StorageManager.Enemies.ContainsKey(uniqueId) ? Plugin.StorageManager.Enemies[uniqueId] : Aggro.Undefined; switch (aggro) { case Aggro.Sight: @@ -89,7 +95,7 @@ public override void PostDraw() ImGui.PopStyleVar(); } - internal static CardinalDirection GetDirection(GameObject bnpc) + internal static CardinalDirection GetDirection(IGameObject bnpc) { return MathHelper.GetCardinalDirection(GetAngle(bnpc)); } @@ -110,12 +116,12 @@ internal static (int min, int max) Get18PieForAngle(float a) return (default, default); } - internal static float GetAngle(GameObject bnpc) + internal static float GetAngle(IGameObject bnpc) { return (MathHelper.GetRelativeAngle(Services.ClientState.LocalPlayer.Position, bnpc.Position) + bnpc.Rotation.RadToDeg()) % 360; } - internal static void ActorConeXZ(GameObject actor, float radius, float startRads, float endRads, Vector4 color, bool lines = true) + internal static void ActorConeXZ(IGameObject actor, float radius, float startRads, float endRads, Vector4 color, bool lines = true) { ConeXZ(actor.Position, radius, startRads + actor.Rotation, endRads + actor.Rotation, color, lines); }