Replace ECommons with LLib, replace Logout with pre-Logout check to persist data

This commit is contained in:
Liza 2023-10-17 10:12:59 +02:00
parent d8cce75e66
commit b0c8aee855
Signed by: liza
GPG Key ID: 7199F8D727D55F67
13 changed files with 84 additions and 34 deletions

6
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "ECommons"] [submodule "LLib"]
path = ECommons path = LLib
url = https://github.com/NightmareXIV/ECommons.git url = https://git.carvel.li/liza/LLib.git

@ -1 +0,0 @@
Subproject commit 1ad0decf6d6a169dc0d5779b1c40a5ca733a51d0

View File

@ -2,7 +2,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Influx", "Influx\Influx.csproj", "{588F6FDE-C6DF-42D9-BD7A-941BE2EB7E44}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Influx", "Influx\Influx.csproj", "{588F6FDE-C6DF-42D9-BD7A-941BE2EB7E44}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ECommons", "ECommons\ECommons\ECommons.csproj", "{D93B90D0-2071-475B-AADD-54D43BCF6A94}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LLib", "LLib\LLib.csproj", "{C11552A8-9C8C-4084-A669-AAFE55E24DCC}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -14,9 +14,9 @@ Global
{588F6FDE-C6DF-42D9-BD7A-941BE2EB7E44}.Debug|Any CPU.Build.0 = Debug|Any CPU {588F6FDE-C6DF-42D9-BD7A-941BE2EB7E44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{588F6FDE-C6DF-42D9-BD7A-941BE2EB7E44}.Release|Any CPU.ActiveCfg = Release|Any CPU {588F6FDE-C6DF-42D9-BD7A-941BE2EB7E44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{588F6FDE-C6DF-42D9-BD7A-941BE2EB7E44}.Release|Any CPU.Build.0 = Release|Any CPU {588F6FDE-C6DF-42D9-BD7A-941BE2EB7E44}.Release|Any CPU.Build.0 = Release|Any CPU
{D93B90D0-2071-475B-AADD-54D43BCF6A94}.Debug|Any CPU.ActiveCfg = Debug|x64 {C11552A8-9C8C-4084-A669-AAFE55E24DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D93B90D0-2071-475B-AADD-54D43BCF6A94}.Debug|Any CPU.Build.0 = Debug|x64 {C11552A8-9C8C-4084-A669-AAFE55E24DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D93B90D0-2071-475B-AADD-54D43BCF6A94}.Release|Any CPU.ActiveCfg = Release|x64 {C11552A8-9C8C-4084-A669-AAFE55E24DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D93B90D0-2071-475B-AADD-54D43BCF6A94}.Release|Any CPU.Build.0 = Release|x64 {C11552A8-9C8C-4084-A669-AAFE55E24DCC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -5,14 +5,15 @@ using Dalamud.Plugin;
using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc;
using Dalamud.Plugin.Ipc.Exceptions; using Dalamud.Plugin.Ipc.Exceptions;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using ECommons.Reflection; using LLib;
using ECommons.Schedulers;
namespace Influx.AllaganTools; namespace Influx.AllaganTools;
internal sealed class AllaganToolsIpc : IDisposable internal sealed class AllaganToolsIpc : IDisposable
{ {
private readonly IChatGui _chatGui; private readonly IChatGui _chatGui;
private readonly DalamudReflector _dalamudReflector;
private readonly IFramework _framework;
private readonly IPluginLog _pluginLog; private readonly IPluginLog _pluginLog;
private readonly ICallGateSubscriber<bool, bool>? _initalized; private readonly ICallGateSubscriber<bool, bool>? _initalized;
private readonly ICallGateSubscriber<bool>? _isInitialized; private readonly ICallGateSubscriber<bool>? _isInitialized;
@ -20,9 +21,11 @@ internal sealed class AllaganToolsIpc : IDisposable
public ICharacterMonitor Characters { get; private set; } = new UnavailableCharacterMonitor(); public ICharacterMonitor Characters { get; private set; } = new UnavailableCharacterMonitor();
public IInventoryMonitor Inventories { get; private set; } = new UnavailableInventoryMonitor(); public IInventoryMonitor Inventories { get; private set; } = new UnavailableInventoryMonitor();
public AllaganToolsIpc(DalamudPluginInterface pluginInterface, IChatGui chatGui, IPluginLog pluginLog) public AllaganToolsIpc(DalamudPluginInterface pluginInterface, IChatGui chatGui, DalamudReflector dalamudReflector, IFramework framework, IPluginLog pluginLog)
{ {
_chatGui = chatGui; _chatGui = chatGui;
_dalamudReflector = dalamudReflector;
_framework = framework;
_pluginLog = pluginLog; _pluginLog = pluginLog;
_initalized = pluginInterface.GetIpcSubscriber<bool, bool>("AllaganTools.Initialized"); _initalized = pluginInterface.GetIpcSubscriber<bool, bool>("AllaganTools.Initialized");
@ -44,11 +47,11 @@ internal sealed class AllaganToolsIpc : IDisposable
private void ConfigureIpc(bool initialized) private void ConfigureIpc(bool initialized)
{ {
_pluginLog.Information("Configuring Allagan tools IPC"); _pluginLog.Information("Configuring Allagan tools IPC");
_ = new TickScheduler(() => _framework.RunOnTick(() =>
{ {
try try
{ {
if (DalamudReflector.TryGetDalamudPlugin("Allagan Tools", out var it, false, true)) if (_dalamudReflector.TryGetDalamudPlugin("Allagan Tools", out var it, false, true))
{ {
var pluginService = it.GetType().Assembly.GetType("InventoryTools.PluginService")!; var pluginService = it.GetType().Assembly.GetType("InventoryTools.PluginService")!;
@ -66,7 +69,7 @@ internal sealed class AllaganToolsIpc : IDisposable
_pluginLog.Error(e, "Could not initialize IPC"); _pluginLog.Error(e, "Could not initialize IPC");
_chatGui.PrintError(e.ToString()); _chatGui.PrintError(e.ToString());
} }
}, 100); }, TimeSpan.FromMilliseconds(100));
} }
public Dictionary<Character, Currencies> CountCurrencies() public Dictionary<Character, Currencies> CountCurrencies()

20
Influx/GameStrings.cs Normal file
View File

@ -0,0 +1,20 @@
using System;
using Dalamud.Plugin.Services;
using LLib;
using Addon = Lumina.Excel.GeneratedSheets.Addon;
namespace Influx;
internal sealed class GameStrings
{
public GameStrings(IDataManager dataManager, IPluginLog pluginLog)
{
LogoutToTitleScreen = dataManager.GetString<Addon>(115, s => s.Text, pluginLog)
?? throw new Exception($"Unable to resolve {nameof(LogoutToTitleScreen)}");
LogoutAndExitGame = dataManager.GetString<Addon>(116, s => s.Text, pluginLog)
?? throw new Exception($"Unable to resolve {nameof(LogoutAndExitGame)}");
}
public string LogoutToTitleScreen { get; }
public string LogoutAndExitGame { get; }
}

View File

@ -54,7 +54,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ECommons\ECommons\ECommons.csproj"/> <ProjectReference Include="..\LLib\LLib.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="RenameLatestZip" AfterTargets="PackagePlugin"> <Target Name="RenameLatestZip" AfterTargets="PackagePlugin">

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using Influx.AllaganTools; using Influx.AllaganTools;
using Influx.LocalStatistics;
using InfluxDB.Client; using InfluxDB.Client;
using InfluxDB.Client.Api.Domain; using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Writes; using InfluxDB.Client.Writes;
@ -63,18 +64,20 @@ internal sealed class InfluxStatisticsClient : IDisposable
{ {
if (character.CharacterType == CharacterType.Character) if (character.CharacterType == CharacterType.Character)
{ {
update.LocalStats.TryGetValue(character, out LocalStats? localStats);
values.Add(PointData.Measurement("currency") values.Add(PointData.Measurement("currency")
.Tag("id", character.CharacterId.ToString()) .Tag("id", character.CharacterId.ToString())
.Tag("player_name", character.Name) .Tag("player_name", character.Name)
.Tag("type", character.CharacterType.ToString()) .Tag("type", character.CharacterType.ToString())
.Tag("fc_id", character.FreeCompanyId > 0 ? character.FreeCompanyId.ToString() : null) .Tag("fc_id", character.FreeCompanyId > 0 ? character.FreeCompanyId.ToString() : null)
.Field("gil", currencies.Gil) .Field("gil", localStats?.Gil ?? currencies.Gil)
.Field("ventures", currencies.Ventures) .Field("ventures", currencies.Ventures)
.Field("ceruleum_tanks", currencies.CeruleumTanks) .Field("ceruleum_tanks", currencies.CeruleumTanks)
.Field("repair_kits", currencies.RepairKits) .Field("repair_kits", currencies.RepairKits)
.Timestamp(date, WritePrecision.S)); .Timestamp(date, WritePrecision.S));
if (update.LocalStats.TryGetValue(character, out var localStats)) if (localStats != null)
{ {
values.Add(PointData.Measurement("grandcompany") values.Add(PointData.Measurement("grandcompany")
.Tag("id", character.CharacterId.ToString()) .Tag("id", character.CharacterId.ToString())

View File

@ -6,12 +6,12 @@ using Dalamud.Game.Command;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using ECommons;
using Influx.AllaganTools; using Influx.AllaganTools;
using Influx.Influx; using Influx.Influx;
using Influx.LocalStatistics; using Influx.LocalStatistics;
using Influx.SubmarineTracker; using Influx.SubmarineTracker;
using Influx.Windows; using Influx.Windows;
using LLib;
namespace Influx; namespace Influx;
@ -33,18 +33,18 @@ public class InfluxPlugin : IDalamudPlugin
private readonly Timer _timer; private readonly Timer _timer;
public InfluxPlugin(DalamudPluginInterface pluginInterface, IClientState clientState, IPluginLog pluginLog, public InfluxPlugin(DalamudPluginInterface pluginInterface, IClientState clientState, IPluginLog pluginLog,
ICommandManager commandManager, IChatGui chatGui, IDataManager dataManager) ICommandManager commandManager, IChatGui chatGui, IDataManager dataManager, IFramework framework,
IAddonLifecycle addonLifecycle)
{ {
ECommonsMain.Init(pluginInterface, this, Module.DalamudReflector);
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;
_configuration = LoadConfig(); _configuration = LoadConfig();
_clientState = clientState; _clientState = clientState;
_commandManager = commandManager; _commandManager = commandManager;
_pluginLog = pluginLog; _pluginLog = pluginLog;
_allaganToolsIpc = new AllaganToolsIpc(pluginInterface, chatGui, _pluginLog); DalamudReflector dalamudReflector = new DalamudReflector(pluginInterface, framework, pluginLog);
_submarineTrackerIpc = new SubmarineTrackerIpc(); _allaganToolsIpc = new AllaganToolsIpc(pluginInterface, chatGui, dalamudReflector, framework, _pluginLog);
_localStatsCalculator = new LocalStatsCalculator(pluginInterface, clientState, pluginLog, dataManager); _submarineTrackerIpc = new SubmarineTrackerIpc(dalamudReflector);
_localStatsCalculator = new LocalStatsCalculator(pluginInterface, clientState, addonLifecycle, pluginLog, dataManager);
_influxStatisticsClient = new InfluxStatisticsClient(chatGui, _configuration, dataManager, clientState); _influxStatisticsClient = new InfluxStatisticsClient(chatGui, _configuration, dataManager, clientState);
_windowSystem = new WindowSystem(typeof(InfluxPlugin).FullName); _windowSystem = new WindowSystem(typeof(InfluxPlugin).FullName);
@ -130,7 +130,5 @@ public class InfluxPlugin : IDalamudPlugin
_influxStatisticsClient.Dispose(); _influxStatisticsClient.Dispose();
_localStatsCalculator.Dispose(); _localStatsCalculator.Dispose();
_allaganToolsIpc.Dispose(); _allaganToolsIpc.Dispose();
ECommonsMain.Dispose();
} }
} }

View File

@ -14,4 +14,5 @@ public record LocalStats
public int MsqCount { get; set; } = -1; public int MsqCount { get; set; } = -1;
public string? MsqName { get; set; } public string? MsqName { get; set; }
public uint MsqGenre { get; set; } public uint MsqGenre { get; set; }
public int? Gil { get; set; }
} }

View File

@ -3,13 +3,16 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dalamud.Game.Addon.Lifecycle;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.Memory;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.UI; using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.FFXIV.Client.UI;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json; using Newtonsoft.Json;
using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany;
namespace Influx.LocalStatistics; namespace Influx.LocalStatistics;
@ -27,7 +30,9 @@ internal sealed class LocalStatsCalculator : IDisposable
private readonly DalamudPluginInterface _pluginInterface; private readonly DalamudPluginInterface _pluginInterface;
private readonly IClientState _clientState; private readonly IClientState _clientState;
private readonly IAddonLifecycle _addonLifecycle;
private readonly IPluginLog _pluginLog; private readonly IPluginLog _pluginLog;
private readonly GameStrings _gameStrings;
private readonly Dictionary<ulong, LocalStats> _cache = new(); private readonly Dictionary<ulong, LocalStats> _cache = new();
private IReadOnlyList<QuestInfo>? _gridaniaStart; private IReadOnlyList<QuestInfo>? _gridaniaStart;
@ -39,16 +44,19 @@ internal sealed class LocalStatsCalculator : IDisposable
public LocalStatsCalculator( public LocalStatsCalculator(
DalamudPluginInterface pluginInterface, DalamudPluginInterface pluginInterface,
IClientState clientState, IClientState clientState,
IAddonLifecycle addonLifecycle,
IPluginLog pluginLog, IPluginLog pluginLog,
IDataManager dataManager) IDataManager dataManager)
{ {
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;
_clientState = clientState; _clientState = clientState;
_addonLifecycle = addonLifecycle;
_pluginLog = pluginLog; _pluginLog = pluginLog;
_gameStrings = new GameStrings(dataManager, pluginLog);
_clientState.Login += UpdateStatistics; _clientState.Login += UpdateStatistics;
_clientState.Logout += UpdateStatistics;
_clientState.TerritoryChanged += UpdateStatistics; _clientState.TerritoryChanged += UpdateStatistics;
_addonLifecycle.RegisterListener(AddonEvent.PreFinalize, "SelectYesno", UpdateStatistics);
Task.Run(() => Task.Run(() =>
{ {
@ -140,13 +148,21 @@ internal sealed class LocalStatsCalculator : IDisposable
public void Dispose() public void Dispose()
{ {
_addonLifecycle.UnregisterListener(AddonEvent.PreFinalize, "SelectYesno", UpdateStatistics);
_clientState.Login -= UpdateStatistics; _clientState.Login -= UpdateStatistics;
_clientState.Logout -= UpdateStatistics;
_clientState.TerritoryChanged -= UpdateStatistics; _clientState.TerritoryChanged -= UpdateStatistics;
} }
private void UpdateStatistics(ushort territoryType) => UpdateStatistics(); private void UpdateStatistics(ushort territoryType) => UpdateStatistics();
private unsafe void UpdateStatistics(AddonEvent type, AddonArgs args)
{
AddonSelectYesno* addonSelectYesNo = (AddonSelectYesno*)args.Addon;
string text = MemoryHelper.ReadSeString(&addonSelectYesNo->PromptText->NodeText).ToString().Replace("\n", "").Replace("\r", "");
if (text == _gameStrings.LogoutToTitleScreen || text == _gameStrings.LogoutAndExitGame)
UpdateStatistics();
}
private unsafe void UpdateStatistics() private unsafe void UpdateStatistics()
{ {
var localContentId = _clientState.LocalContentId; var localContentId = _clientState.LocalContentId;
@ -156,6 +172,7 @@ internal sealed class LocalStatsCalculator : IDisposable
return; return;
} }
_pluginLog.Information($"Updating character {_clientState.LocalContentId}");
try try
{ {
PlayerState* playerState = PlayerState.Instance(); PlayerState* playerState = PlayerState.Instance();
@ -171,6 +188,7 @@ internal sealed class LocalStatsCalculator : IDisposable
MaxLevel = playerState->MaxLevel, MaxLevel = playerState->MaxLevel,
ClassJobLevels = ExtractClassJobLevels(playerState), ClassJobLevels = ExtractClassJobLevels(playerState),
StartingTown = playerState->StartTown, StartingTown = playerState->StartTown,
Gil = InventoryManager.Instance()->GetInventoryItemCount(1),
}; };
if (_msqQuests != null) if (_msqQuests != null)
@ -205,7 +223,7 @@ internal sealed class LocalStatsCalculator : IDisposable
localStats.MsqGenre = 0; localStats.MsqGenre = 0;
} }
_pluginLog.Information($"ls → {localStats.MsqCount}, {localStats.MsqName}"); _pluginLog.Information($"Current MSQ Progress: {localStats.MsqCount}, {localStats.MsqName}");
if (_cache.TryGetValue(localContentId, out var existingStats)) if (_cache.TryGetValue(localContentId, out var existingStats))
{ {

View File

@ -1,16 +1,23 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ECommons.Reflection;
using Influx.AllaganTools; using Influx.AllaganTools;
using LLib;
namespace Influx.SubmarineTracker; namespace Influx.SubmarineTracker;
internal sealed class SubmarineTrackerIpc internal sealed class SubmarineTrackerIpc
{ {
private readonly DalamudReflector _dalamudReflector;
public SubmarineTrackerIpc(DalamudReflector dalamudReflector)
{
_dalamudReflector = dalamudReflector;
}
public Dictionary<Character, List<SubmarineStats>> GetSubmarineStats(List<Character> characters) public Dictionary<Character, List<SubmarineStats>> GetSubmarineStats(List<Character> characters)
{ {
if (DalamudReflector.TryGetDalamudPlugin("Submarine Tracker", out var it, false, true)) if (_dalamudReflector.TryGetDalamudPlugin("Submarine Tracker", out var it, false, true))
{ {
var submarineData = it.GetType().Assembly.GetType("SubmarineTracker.Data.Submarines"); var submarineData = it.GetType().Assembly.GetType("SubmarineTracker.Data.Submarines");
var knownSubmarineData = submarineData!.GetField("KnownSubmarines")!; var knownSubmarineData = submarineData!.GetField("KnownSubmarines")!;

View File

@ -191,7 +191,7 @@
"System.Drawing.Common": "6.0.0" "System.Drawing.Common": "6.0.0"
} }
}, },
"ecommons": { "llib": {
"type": "Project" "type": "Project"
} }
} }

1
LLib Submodule

@ -0,0 +1 @@
Subproject commit 2f6ef354c401a9f1bb9b807327acad7e98662a2e