2021-02-25 01:01:12 +00:00
|
|
|
|
using Dalamud.Plugin;
|
2020-08-04 22:22:57 +00:00
|
|
|
|
using System;
|
2020-08-31 17:47:51 +00:00
|
|
|
|
using System.Collections.Generic;
|
2021-04-28 03:36:57 +00:00
|
|
|
|
using System.Globalization;
|
2020-12-21 02:49:10 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
2020-08-21 09:00:04 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2021-04-28 14:15:41 +00:00
|
|
|
|
using Dalamud;
|
2022-08-21 19:57:42 +00:00
|
|
|
|
using Dalamud.ContextMenu;
|
2021-08-22 22:07:28 +00:00
|
|
|
|
using Dalamud.IoC;
|
2023-09-29 00:59:42 +00:00
|
|
|
|
using Dalamud.Plugin.Services;
|
2021-03-04 04:34:52 +00:00
|
|
|
|
using NoSoliciting.Interface;
|
2020-12-21 02:49:10 +00:00
|
|
|
|
using NoSoliciting.Ml;
|
2021-04-30 23:55:31 +00:00
|
|
|
|
using NoSoliciting.Resources;
|
2021-04-28 00:16:07 +00:00
|
|
|
|
using XivCommon;
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
|
|
|
|
namespace NoSoliciting {
|
2021-08-22 22:07:28 +00:00
|
|
|
|
// ReSharper disable once ClassNeverInstantiated.Global
|
2020-12-21 02:49:10 +00:00
|
|
|
|
public class Plugin : IDalamudPlugin {
|
|
|
|
|
private bool _disposedValue;
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
2023-09-29 00:59:42 +00:00
|
|
|
|
internal static string Name => "NoSoliciting";
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
2021-08-22 22:07:28 +00:00
|
|
|
|
private Filter Filter { get; }
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
2023-09-29 00:59:42 +00:00
|
|
|
|
[PluginService]
|
|
|
|
|
internal static IPluginLog Log { get; private set; } = null!;
|
|
|
|
|
|
2021-08-22 22:07:28 +00:00
|
|
|
|
[PluginService]
|
|
|
|
|
internal DalamudPluginInterface Interface { get; init; } = null!;
|
|
|
|
|
|
|
|
|
|
[PluginService]
|
2023-09-29 00:59:42 +00:00
|
|
|
|
private IClientState ClientState { get; init; } = null!;
|
2021-08-22 22:07:28 +00:00
|
|
|
|
|
|
|
|
|
[PluginService]
|
2023-09-29 00:59:42 +00:00
|
|
|
|
internal IChatGui ChatGui { get; init; } = null!;
|
2021-08-22 22:07:28 +00:00
|
|
|
|
|
|
|
|
|
[PluginService]
|
2023-09-29 00:59:42 +00:00
|
|
|
|
internal IPartyFinderGui PartyFinderGui { get; init; } = null!;
|
2021-08-22 22:07:28 +00:00
|
|
|
|
|
|
|
|
|
[PluginService]
|
2023-09-29 00:59:42 +00:00
|
|
|
|
internal IDataManager DataManager { get; init; } = null!;
|
2021-08-22 22:07:28 +00:00
|
|
|
|
|
|
|
|
|
[PluginService]
|
2023-09-29 00:59:42 +00:00
|
|
|
|
internal ICommandManager CommandManager { get; init; } = null!;
|
2021-08-22 22:07:28 +00:00
|
|
|
|
|
|
|
|
|
[PluginService]
|
2023-09-29 00:59:42 +00:00
|
|
|
|
internal IToastGui ToastGui { get; init; } = null!;
|
2021-08-22 22:07:28 +00:00
|
|
|
|
|
|
|
|
|
internal PluginConfiguration Config { get; }
|
|
|
|
|
internal XivCommonBase Common { get; }
|
2022-08-21 19:57:42 +00:00
|
|
|
|
internal DalamudContextMenu DalamudContextMenu { get; }
|
2021-08-22 22:07:28 +00:00
|
|
|
|
internal PluginUi Ui { get; }
|
|
|
|
|
private Commands Commands { get; }
|
|
|
|
|
private ContextMenu ContextMenu { get; }
|
|
|
|
|
internal MlFilterStatus MlStatus { get; set; } = MlFilterStatus.Uninitialised;
|
|
|
|
|
internal MlFilter? MlFilter { get; set; }
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
2021-02-16 17:15:00 +00:00
|
|
|
|
private readonly List<Message> _messageHistory = new();
|
2021-08-22 22:07:28 +00:00
|
|
|
|
internal IEnumerable<Message> MessageHistory => this._messageHistory;
|
2020-08-31 17:47:51 +00:00
|
|
|
|
|
2021-02-16 17:15:00 +00:00
|
|
|
|
private readonly List<Message> _partyFinderHistory = new();
|
2021-08-22 22:07:28 +00:00
|
|
|
|
internal IEnumerable<Message> PartyFinderHistory => this._partyFinderHistory;
|
2020-12-21 02:49:10 +00:00
|
|
|
|
|
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Global
|
|
|
|
|
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
|
|
|
|
|
public string AssemblyLocation { get; private set; } = Assembly.GetExecutingAssembly().Location;
|
2020-08-31 17:47:51 +00:00
|
|
|
|
|
2021-08-22 22:07:28 +00:00
|
|
|
|
public Plugin() {
|
2020-12-21 02:49:10 +00:00
|
|
|
|
string path = Environment.GetEnvironmentVariable("PATH")!;
|
|
|
|
|
string newPath = Path.GetDirectoryName(this.AssemblyLocation)!;
|
|
|
|
|
Environment.SetEnvironmentVariable("PATH", $"{path};{newPath}");
|
|
|
|
|
|
2020-08-23 14:55:52 +00:00
|
|
|
|
this.Config = this.Interface.GetPluginConfig() as PluginConfiguration ?? new PluginConfiguration();
|
|
|
|
|
this.Config.Initialise(this.Interface);
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
2021-04-28 14:15:41 +00:00
|
|
|
|
this.ConfigureLanguage();
|
2021-08-22 22:07:28 +00:00
|
|
|
|
this.Interface.LanguageChanged += this.OnLanguageUpdate;
|
2021-04-28 14:15:41 +00:00
|
|
|
|
|
2023-10-03 21:35:46 +00:00
|
|
|
|
this.Common = new XivCommonBase(this.Interface, Hooks.PartyFinderListings);
|
2023-09-29 00:59:42 +00:00
|
|
|
|
this.DalamudContextMenu = new DalamudContextMenu(this.Interface);
|
2021-04-28 00:16:07 +00:00
|
|
|
|
|
2021-04-08 16:09:53 +00:00
|
|
|
|
this.Ui = new PluginUi(this);
|
|
|
|
|
this.Commands = new Commands(this);
|
2021-04-28 00:16:07 +00:00
|
|
|
|
this.ContextMenu = new ContextMenu(this);
|
2020-08-21 09:00:04 +00:00
|
|
|
|
|
2020-12-21 02:49:10 +00:00
|
|
|
|
this.Filter = new Filter(this);
|
|
|
|
|
|
2021-04-28 00:16:07 +00:00
|
|
|
|
this.InitialiseMachineLearning(false);
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
2020-09-24 03:14:41 +00:00
|
|
|
|
// pre-compute the max ilvl to prevent stutter
|
2021-04-14 18:39:57 +00:00
|
|
|
|
try {
|
2021-08-22 22:07:28 +00:00
|
|
|
|
FilterUtil.MaxItemLevelAttainable(this.DataManager);
|
2021-04-14 18:39:57 +00:00
|
|
|
|
} catch (Exception ex) {
|
2023-09-29 00:59:42 +00:00
|
|
|
|
Plugin.Log.Error(ex, "Exception while computing max item level");
|
2021-04-14 18:39:57 +00:00
|
|
|
|
}
|
2021-02-25 01:01:12 +00:00
|
|
|
|
}
|
2020-09-24 03:14:41 +00:00
|
|
|
|
|
2021-02-25 01:01:12 +00:00
|
|
|
|
protected virtual void Dispose(bool disposing) {
|
|
|
|
|
if (this._disposedValue) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (disposing) {
|
|
|
|
|
this.Filter.Dispose();
|
|
|
|
|
this.MlFilter?.Dispose();
|
2021-04-28 00:16:07 +00:00
|
|
|
|
this.ContextMenu.Dispose();
|
2021-02-25 01:01:12 +00:00
|
|
|
|
this.Commands.Dispose();
|
|
|
|
|
this.Ui.Dispose();
|
2022-08-21 19:57:42 +00:00
|
|
|
|
this.DalamudContextMenu.Dispose();
|
2021-04-28 00:16:07 +00:00
|
|
|
|
this.Common.Dispose();
|
2021-08-22 22:07:28 +00:00
|
|
|
|
this.Interface.LanguageChanged -= this.OnLanguageUpdate;
|
2021-02-25 01:01:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._disposedValue = true;
|
2020-08-04 22:22:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-28 14:15:41 +00:00
|
|
|
|
private void OnLanguageUpdate(string langCode) {
|
|
|
|
|
this.ConfigureLanguage(langCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void ConfigureLanguage(string? langCode = null) {
|
|
|
|
|
if (this.Config.FollowGameLanguage) {
|
2021-08-22 22:07:28 +00:00
|
|
|
|
langCode = this.ClientState.ClientLanguage switch {
|
2021-04-28 14:15:41 +00:00
|
|
|
|
ClientLanguage.Japanese => "ja",
|
|
|
|
|
ClientLanguage.English => "en",
|
|
|
|
|
ClientLanguage.German => "de",
|
|
|
|
|
ClientLanguage.French => "fr",
|
2021-08-22 22:07:28 +00:00
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(this.ClientState.ClientLanguage), "Unknown ClientLanguage"),
|
2021-04-28 14:15:41 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 20:17:39 +00:00
|
|
|
|
langCode ??= this.Interface.UiLanguage;
|
2021-08-22 22:07:28 +00:00
|
|
|
|
// I don't fucking trust this. Not since last time.
|
|
|
|
|
// ReSharper disable once ConstantNullCoalescingCondition
|
|
|
|
|
Language.Culture = new CultureInfo(langCode ?? "en");
|
2021-04-28 03:36:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-06 04:00:52 +00:00
|
|
|
|
internal void InitialiseMachineLearning(bool showWindow) {
|
2020-12-21 02:49:10 +00:00
|
|
|
|
if (this.MlFilter != null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-06 04:00:52 +00:00
|
|
|
|
Task.Run(async () => this.MlFilter = await MlFilter.Load(this, showWindow))
|
2020-12-23 08:52:19 +00:00
|
|
|
|
.ContinueWith(e => {
|
2021-02-25 01:58:47 +00:00
|
|
|
|
if (e.IsFaulted) {
|
|
|
|
|
this.MlStatus = MlFilterStatus.Uninitialised;
|
|
|
|
|
return;
|
2020-12-23 08:52:19 +00:00
|
|
|
|
}
|
2021-02-25 01:58:47 +00:00
|
|
|
|
|
|
|
|
|
this.MlStatus = MlFilterStatus.Initialised;
|
2023-09-29 00:59:42 +00:00
|
|
|
|
Log.Info("Machine learning model loaded");
|
2020-12-23 08:52:19 +00:00
|
|
|
|
});
|
2020-12-21 02:49:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 17:47:51 +00:00
|
|
|
|
public void AddMessageHistory(Message message) {
|
2020-12-21 02:49:10 +00:00
|
|
|
|
this._messageHistory.Insert(0, message);
|
2020-08-31 17:47:51 +00:00
|
|
|
|
|
2020-12-21 02:49:10 +00:00
|
|
|
|
while (this._messageHistory.Count > 250) {
|
|
|
|
|
this._messageHistory.RemoveAt(this._messageHistory.Count - 1);
|
2020-08-31 17:47:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearPartyFinderHistory() {
|
2020-12-21 02:49:10 +00:00
|
|
|
|
this._partyFinderHistory.Clear();
|
2020-08-31 17:47:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddPartyFinderHistory(Message message) {
|
2020-12-21 02:49:10 +00:00
|
|
|
|
this._partyFinderHistory.Add(message);
|
2020-08-31 17:47:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 22:22:57 +00:00
|
|
|
|
public void Dispose() {
|
|
|
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
2020-12-21 02:49:10 +00:00
|
|
|
|
this.Dispose(true);
|
2020-08-04 22:22:57 +00:00
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|