b1f01d2794
- Add debug logging (gated by Debug) and scan mode to find party-invite addon - Listen for PartyInvite and SelectYesno addons - Cache friends and FC members on login: open Friends/FC addons briefly, scrape names, close; persist cache to HSRToolsFriendFcCache.json - Auto-accept checks cache first, then live proxy (works without opening UIs) - Config: CacheFriendsAndFcOnLogin, AutoAcceptScanAddons - FC: RequestData() + longer wait; clearer log when 0 FC members Co-authored-by: Cursor <cursoragent@cursor.com>
131 lines
4.0 KiB
C#
131 lines
4.0 KiB
C#
using System.IO;
|
|
using System.Text.Json;
|
|
using Dalamud.Game.Command;
|
|
using Dalamud.Interface.Windowing;
|
|
using Dalamud.Plugin;
|
|
using HSRTools.Configuration;
|
|
using HSRTools.Services;
|
|
using HSRTools.UI;
|
|
|
|
namespace HSRTools;
|
|
|
|
public sealed class HSRToolsPlugin : IDalamudPlugin
|
|
{
|
|
private const string ConfigFileName = "HSRTools.json";
|
|
|
|
private readonly string _configDir;
|
|
private readonly ChatMonitorService _chatMonitorService;
|
|
private readonly FriendFcCacheService _friendFcCacheService;
|
|
private readonly AutoAcceptPartyService _autoAcceptPartyService;
|
|
private readonly ConfigWindow _configWindow;
|
|
private readonly WindowSystem _windowSystem;
|
|
private HSRToolsConfiguration _config;
|
|
|
|
public HSRToolsPlugin(IDalamudPluginInterface pluginInterface)
|
|
{
|
|
pluginInterface.Create<PluginServices>();
|
|
|
|
_configDir = PluginServices.PluginInterface.ConfigDirectory.FullName;
|
|
_config = LoadConfig(_configDir) ?? new HSRToolsConfiguration();
|
|
|
|
_chatMonitorService = new ChatMonitorService(
|
|
PluginServices.ChatGui,
|
|
new PartyInviteService(PluginServices.DataManager, PluginServices.PlayerState),
|
|
PluginServices.PluginLog,
|
|
_config);
|
|
|
|
_friendFcCacheService = new FriendFcCacheService(
|
|
_configDir,
|
|
PluginServices.PluginLog,
|
|
PluginServices.Framework,
|
|
PluginServices.ClientState,
|
|
_config);
|
|
|
|
_autoAcceptPartyService = new AutoAcceptPartyService(
|
|
PluginServices.AddonLifecycle,
|
|
PluginServices.PluginLog,
|
|
_config,
|
|
_friendFcCacheService);
|
|
|
|
_configWindow = new ConfigWindow(_config);
|
|
_windowSystem = new WindowSystem("HSRTools");
|
|
_windowSystem.AddWindow(_configWindow);
|
|
|
|
PluginServices.PluginInterface.UiBuilder.Draw += OnDraw;
|
|
PluginServices.Framework.Update += _friendFcCacheService.OnFrameworkUpdate;
|
|
PluginServices.PluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi;
|
|
PluginServices.CommandManager.AddHandler("/hsr", new CommandInfo(OnHsrCommand)
|
|
{
|
|
HelpMessage = "Open HSRTools settings.",
|
|
});
|
|
_chatMonitorService.SetConfiguration(_config);
|
|
_friendFcCacheService.Start();
|
|
_chatMonitorService.Start();
|
|
_autoAcceptPartyService.SetConfiguration(_config);
|
|
_autoAcceptPartyService.Start();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
PluginServices.Framework.Update -= _friendFcCacheService.OnFrameworkUpdate;
|
|
PluginServices.CommandManager.RemoveHandler("/hsr");
|
|
_friendFcCacheService.Stop();
|
|
_chatMonitorService.Stop();
|
|
_autoAcceptPartyService.Stop();
|
|
_windowSystem.RemoveAllWindows();
|
|
SaveConfig(_configDir, _config);
|
|
}
|
|
|
|
private void OnDraw()
|
|
{
|
|
_windowSystem.Draw();
|
|
if (_configWindow.IsOpen)
|
|
{
|
|
_autoAcceptPartyService.SetConfiguration(_config);
|
|
_friendFcCacheService.SetConfiguration(_config);
|
|
}
|
|
}
|
|
|
|
private void OpenConfigUi()
|
|
{
|
|
_configWindow.IsOpen = true;
|
|
}
|
|
|
|
private void OnHsrCommand(string command, string args)
|
|
{
|
|
OpenConfigUi();
|
|
}
|
|
|
|
private static HSRToolsConfiguration? LoadConfig(string configDir)
|
|
{
|
|
var path = Path.Combine(configDir, ConfigFileName);
|
|
if (!File.Exists(path))
|
|
return null;
|
|
|
|
try
|
|
{
|
|
var json = File.ReadAllText(path);
|
|
return JsonSerializer.Deserialize<HSRToolsConfiguration>(json);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static void SaveConfig(string configDir, HSRToolsConfiguration config)
|
|
{
|
|
var path = Path.Combine(configDir, ConfigFileName);
|
|
try
|
|
{
|
|
Directory.CreateDirectory(configDir);
|
|
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(path, json);
|
|
}
|
|
catch
|
|
{
|
|
// ignore
|
|
}
|
|
}
|
|
}
|