Skip to content

Commit

Permalink
[PR] New build
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
wolfcomp authored Jan 10, 2024
2 parents 78ceb25 + 321d3a3 commit 631ad81
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 33 deletions.
34 changes: 27 additions & 7 deletions DeepDungeonDex/Hooks/AddonAgent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using FFXIVClientStructs.FFXIV.Client.Game.Event;
using System.Runtime.InteropServices;
using FFXIVClientStructs.FFXIV.Client.Game.InstanceContent;

namespace DeepDungeonDex.Hooks;

Expand All @@ -9,6 +11,7 @@ public unsafe class AddonAgent : IDisposable
private EventFramework* _structsFramework;
public byte Floor { get; private set; }
public bool Disabled { get; private set; }
public ContentType ContentType { get; private set; }

public AddonAgent(IFramework framework, IPluginLog log, CommandHandler handler)
{
Expand All @@ -17,7 +20,7 @@ public AddonAgent(IFramework framework, IPluginLog log, CommandHandler handler)
_framework.Update += OnUpdate;
handler.AddCommand(new[] { "enable_floor", "e_floor", "enable_f", "ef" }, () =>
{
if(!Disabled)
if (!Disabled)
return;
Disabled = false;
_framework.Update += OnUpdate;
Expand All @@ -27,16 +30,26 @@ public AddonAgent(IFramework framework, IPluginLog log, CommandHandler handler)
private void OnUpdate(IFramework framework)
{
_structsFramework = EventFramework.Instance();
if (!IsInstanceContentSafe())
if (!IsContentSafe())
return;
try
{
var activeInstance = _structsFramework->GetInstanceContentDeepDungeon();
var activePublic = (PublicContentDirectorResearch*)_structsFramework->GetPublicContentDirector();

if (activeInstance == null)
return;

Floor = activeInstance->Floor;
if (activeInstance != null)
{
ContentType = (ContentType)(1 << (int)activeInstance->InstanceContentDirector.InstanceContentType);
Floor = activeInstance->Floor;
}
else if (activePublic != null)
{
ContentType = (ContentType)(1 << (int)activePublic->PublicContentDirectorType);
}
else
{
ContentType = ContentType.None;
}
}
catch (Exception e)
{
Expand All @@ -45,7 +58,7 @@ private void OnUpdate(IFramework framework)
}
}

private bool IsInstanceContentSafe()
private bool IsContentSafe()
{
var contentDirector = _structsFramework->GetContentDirector();

Expand All @@ -69,4 +82,11 @@ public void Dispose(bool disposing)
}

public void Dispose() => Dispose(true);
}

[StructLayout(LayoutKind.Explicit)]
public unsafe struct PublicContentDirectorResearch
{
[FieldOffset(0x0)] public PublicContentDirector PublicContentDirector;
[FieldOffset(0xC76)] public uint PublicContentDirectorType;
}
10 changes: 4 additions & 6 deletions DeepDungeonDex/Requests/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public partial class Requests : IDisposable
private readonly Thread _loadLangThread;
private readonly Regex _percentRegex = new("(%%)|(%)", RegexOptions.Compiled);
private IPluginLog _log;
private bool _loadedOnce;
public HttpClient Client = new();
public const string BaseUrl = "https://raw.githubusercontent.com/wolfcomp/DeepDungeonDex/data";
public TimeSpan CacheTime = TimeSpan.FromHours(6);
Expand Down Expand Up @@ -53,11 +54,6 @@ public async Task RefreshFileList(bool continuous = true)
StartRequest:
RequestingData = true;
var list = await GetFileList();
if (list == null)
{
_log.Error("Failed to get file list using precompiled data");
list = await GetFileListFromFile();
}
if (list == null)
goto RefreshEnd;

Expand Down Expand Up @@ -92,6 +88,8 @@ public async Task RefreshFileList(bool continuous = true)
}
}

_loadedOnce = true;

RefreshEnd:
RequestingData = false;
if (continuous)
Expand Down Expand Up @@ -121,7 +119,7 @@ public async Task RefreshFileList(bool continuous = true)
catch (Exception e)
{
_log.Error(e, "Trying to get file from precompiled data");
return await GetFromFile(url);
return !_loadedOnce ? await GetFromFile(url) : null;
}
}

Expand Down
41 changes: 37 additions & 4 deletions DeepDungeonDex/Storage/MobData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Drawing;
using System.IO;
using FFXIVClientStructs.FFXIV.Client.Game.InstanceContent;
using YamlDotNet.Serialization;

namespace DeepDungeonDex.Storage;
Expand Down Expand Up @@ -63,7 +60,7 @@ public string[][]? Description
public Weakness Weakness { get; set; }
public Aggro Aggro { get; set; }
public Threat Threat { get; set; }
public InstanceContentType InstanceContentType { get; set; }
public ContentType InstanceContentType { get; set; }

public void ProcessDescription(float width)
{
Expand Down Expand Up @@ -131,6 +128,42 @@ public enum Threat : byte
Vicious
}

[Flags]
public enum ContentType : uint
{
None = 0,
Raid = 1,
Dungeon = 1 << 1,
GuildOrder = 1 << 2,
Trial = 1 << 3,
CrystallineConflict = 1 << 4,
Frontlines = 1 << 5,
QuestBattle = 1 << 6,
BeginnerTraining = 1 << 7,
DeepDungeon = 1 << 8,
TreasureHuntDungeon = 1 << 9,
SeasonalDungeon = 1 << 10,
RivalWing = 1 << 11,
MaskedCarnivale = 1 << 12,
Mahjong = 1 << 13,
GoldSaucer = 1 << 14,
OceanFishing = 1 << 15,
UnrealTrial = 1 << 16,
TripleTriad = 1 << 17,
VariantDungeon = 1 << 18,
CriterionDungeon = 1 << 19,
BondingCeremony = 1 << 20,
PublicTripleTriad = 1 << 21,
Eureka = 1 << 22,
CalamityRetold = 1 << 23, // seems to be only for the rising event in 2018
LeapOfFaith = 1 << 24,
Diadem = 1 << 25,
Bozja = 1 << 26,
Delubrum = 1 << 27,
IslandSanctuary = 1 << 28,
FallGuys = 1 << 29,
}

public static class MobDataExtensions
{
public static Mob? GetData(this MobData data, uint key)
Expand Down
2 changes: 1 addition & 1 deletion DeepDungeonDex/Windows/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override void Draw()
ImGui.SameLine(0, 14);
ImGui.TextUnformatted($"Weakness: {mobValue.Weakness}");
ImGui.SameLine(0, 14);
ImGui.TextUnformatted($"InstanceContentType: {mobValue.InstanceContentType}");
ImGui.TextUnformatted($"ContentType: {mobValue.InstanceContentType}");
ImGui.Unindent();
}
break;
Expand Down
50 changes: 36 additions & 14 deletions DeepDungeonDex/Windows/Main.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.IO;
using System.Numerics;
using System.Runtime.InteropServices;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility.Raii;
using FFXIVClientStructs.FFXIV.Client.Game.InstanceContent;
using Dalamud.Utility;
using DeepDungeonDex.Hooks;

namespace DeepDungeonDex.Windows;

Expand All @@ -27,8 +29,10 @@ public partial class Main : Window, IDisposable
private uint _targetId;
private bool _debug;
private IDalamudTextureWrap? _unknown;
private AddonAgent _addon;
private const string _githubIssuePath = "https://github.com/wolfcomp/DeepDungeonDex/issues/new?template=fix_node.yaml";

public Main(StorageHandler storage, CommandHandler command, ITargetManager target, IFramework framework, IClientState state, ICondition condition, ITextureProvider textureProvider, IPluginLog log, DalamudPluginInterface pluginInterface) : base("DeepDungeonDex MobView", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoTitleBar)
public Main(StorageHandler storage, CommandHandler command, ITargetManager target, IFramework framework, IClientState state, ICondition condition, ITextureProvider textureProvider, IPluginLog log, DalamudPluginInterface pluginInterface, AddonAgent addon) : base("DeepDungeonDex MobView", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoTitleBar)
{
_condition = condition;
_target = target;
Expand All @@ -39,6 +43,7 @@ public Main(StorageHandler storage, CommandHandler command, ITargetManager targe
_pluginInterface = pluginInterface;
_clientState = state;
_log = log;
_addon = addon;
var instance = this;
_config = _storage.GetInstance<Configuration>()!;
SizeConstraints = new WindowSizeConstraints
Expand Down Expand Up @@ -168,27 +173,44 @@ public override void Draw()
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (_currentMob.InstanceContentType)
{
case InstanceContentType.DeepDungeon:
case ContentType.DeepDungeon:
DrawDeepDungeonData();
break;
case InstanceContentType.Dungeon:
case InstanceContentType.GuildOrder:
case InstanceContentType.QuestBattle:
case InstanceContentType.BeginnerTraining:
case InstanceContentType.TreasureHuntDungeon:
case InstanceContentType.SeasonalDungeon:
case InstanceContentType.MaskedCarnivale:
case InstanceContentType.VariantDungeon:
case InstanceContentType.CriterionDungeon:
default:
DrawUnknownContent();
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (_addon.ContentType)
{
case ContentType.OceanFishing:
case ContentType.BondingCeremony:
case ContentType.CrystallineConflict:
case ContentType.Trial:
case ContentType.Raid:
case ContentType.UnrealTrial:
case ContentType.Mahjong:
case ContentType.GoldSaucer:
case ContentType.RivalWing:
case ContentType.TripleTriad:
case ContentType.PublicTripleTriad:
case ContentType.LeapOfFaith:
case ContentType.Frontlines:
break;
default:
DrawUnknownContent();
break;
}
break;
}
}

public void DrawUnknownContent()
public unsafe void DrawUnknownContent()
{
ImGui.TextUnformatted(string.Format(_locale.GetLocale("UnknownContent"), _currentMob.Name, _currentMob.Id));
// ReSharper disable once InvertIf
if (ImGui.Button(_locale.GetLocale("CreateDataIssue")))
{
var url = $"{_githubIssuePath}&mob_id={_currentMob.Id}%20-%20{_currentMob.Name}&content_type={_addon.ContentType:G}";
Util.OpenLink(url);
}
}

public void LoadIcons()
Expand Down
2 changes: 1 addition & 1 deletion DeepDungeonDexConsole/data
Submodule data updated from c62c04 to be3ef6

0 comments on commit 631ad81

Please sign in to comment.