mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Apply new configuration scheme to everything
This commit is contained in:
parent
1ab43645f7
commit
dc960c5f6f
6 changed files with 45 additions and 79 deletions
|
|
@ -18,6 +18,14 @@ namespace Dalamud
|
||||||
|
|
||||||
public List<string> BadWords { get; set; }
|
public List<string> BadWords { get; set; }
|
||||||
|
|
||||||
|
public class FateInfo {
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FateInfo> Fates;
|
||||||
|
|
||||||
|
|
||||||
public static DalamudConfiguration Load(string path) {
|
public static DalamudConfiguration Load(string path) {
|
||||||
return JsonConvert.DeserializeObject<DalamudConfiguration>(File.ReadAllText(path));
|
return JsonConvert.DeserializeObject<DalamudConfiguration>(File.ReadAllText(path));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ using Dalamud.Game.Internal;
|
||||||
using Dalamud.Game.Internal.Gui;
|
using Dalamud.Game.Internal.Gui;
|
||||||
using Dalamud.Game.Network;
|
using Dalamud.Game.Network;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Settings;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using XIVLauncher.Dalamud;
|
using XIVLauncher.Dalamud;
|
||||||
|
|
||||||
|
|
@ -218,8 +217,8 @@ namespace Dalamud {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFateWatchAdd(string command, string arguments) {
|
private void OnFateWatchAdd(string command, string arguments) {
|
||||||
if (PersistentSettings.Instance.Fates == null)
|
if (this.Configuration.Fates == null)
|
||||||
PersistentSettings.Instance.Fates = new List<PersistentSettings.FateInfo>();
|
this.Configuration.Fates = new List<DalamudConfiguration.FateInfo>();
|
||||||
|
|
||||||
dynamic candidates = XivApi.Search(arguments, "Fate").GetAwaiter().GetResult();
|
dynamic candidates = XivApi.Search(arguments, "Fate").GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
|
@ -228,32 +227,36 @@ namespace Dalamud {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fateInfo = new PersistentSettings.FateInfo {
|
var fateInfo = new DalamudConfiguration.FateInfo {
|
||||||
Id = candidates.Results[0].ID,
|
Id = candidates.Results[0].ID,
|
||||||
Name = candidates.Results[0].Name
|
Name = candidates.Results[0].Name
|
||||||
};
|
};
|
||||||
|
|
||||||
PersistentSettings.Instance.Fates.Add(fateInfo);
|
this.Configuration.Fates.Add(fateInfo);
|
||||||
|
|
||||||
|
this.Configuration.Save(this.StartInfo.ConfigurationPath);
|
||||||
|
|
||||||
Framework.Gui.Chat.Print($"Added fate \"{fateInfo.Name}\".");
|
Framework.Gui.Chat.Print($"Added fate \"{fateInfo.Name}\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFateWatchList(string command, string arguments) {
|
private void OnFateWatchList(string command, string arguments) {
|
||||||
if (PersistentSettings.Instance.Fates == null)
|
if (this.Configuration.Fates == null)
|
||||||
PersistentSettings.Instance.Fates = new List<PersistentSettings.FateInfo>();
|
this.Configuration.Fates = new List<DalamudConfiguration.FateInfo>();
|
||||||
|
|
||||||
if (PersistentSettings.Instance.Fates.Count == 0) {
|
if (this.Configuration.Fates.Count == 0) {
|
||||||
Framework.Gui.Chat.Print("No fates on your watchlist.");
|
Framework.Gui.Chat.Print("No fates on your watchlist.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var fate in PersistentSettings.Instance.Fates)
|
this.Configuration.Save(this.StartInfo.ConfigurationPath);
|
||||||
|
|
||||||
|
foreach (var fate in this.Configuration.Fates)
|
||||||
Framework.Gui.Chat.Print($"Fate {fate.Id}: {fate.Name}");
|
Framework.Gui.Chat.Print($"Fate {fate.Id}: {fate.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFateWatchRemove(string command, string arguments) {
|
private void OnFateWatchRemove(string command, string arguments) {
|
||||||
if (PersistentSettings.Instance.Fates == null)
|
if (this.Configuration.Fates == null)
|
||||||
PersistentSettings.Instance.Fates = new List<PersistentSettings.FateInfo>();
|
this.Configuration.Fates = new List<DalamudConfiguration.FateInfo>();
|
||||||
|
|
||||||
dynamic candidates = XivApi.Search(arguments, "Fate").GetAwaiter().GetResult();
|
dynamic candidates = XivApi.Search(arguments, "Fate").GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
|
@ -262,37 +265,45 @@ namespace Dalamud {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentSettings.Instance.Fates.RemoveAll(x => x.Id == candidates.Results[0].ID);
|
this.Configuration.Fates.RemoveAll(x => x.Id == candidates.Results[0].ID);
|
||||||
|
|
||||||
|
this.Configuration.Save(this.StartInfo.ConfigurationPath);
|
||||||
|
|
||||||
Framework.Gui.Chat.Print($"Removed fate \"{candidates.Results[0].Name}\".");
|
Framework.Gui.Chat.Print($"Removed fate \"{candidates.Results[0].Name}\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBadWordsAdd(string command, string arguments) {
|
private void OnBadWordsAdd(string command, string arguments) {
|
||||||
if (PersistentSettings.Instance.BadWords == null)
|
if (this.Configuration.BadWords == null)
|
||||||
PersistentSettings.Instance.BadWords = new List<string>();
|
this.Configuration.BadWords = new List<string>();
|
||||||
|
|
||||||
PersistentSettings.Instance.BadWords.Add(arguments);
|
this.Configuration.BadWords.Add(arguments);
|
||||||
|
|
||||||
|
this.Configuration.Save(this.StartInfo.ConfigurationPath);
|
||||||
|
|
||||||
Framework.Gui.Chat.Print($"Muted \"{arguments}\".");
|
Framework.Gui.Chat.Print($"Muted \"{arguments}\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBadWordsList(string command, string arguments) {
|
private void OnBadWordsList(string command, string arguments) {
|
||||||
if (PersistentSettings.Instance.BadWords == null)
|
if (this.Configuration.BadWords == null)
|
||||||
PersistentSettings.Instance.BadWords = new List<string>();
|
this.Configuration.BadWords = new List<string>();
|
||||||
|
|
||||||
if (PersistentSettings.Instance.BadWords.Count == 0) {
|
if (this.Configuration.BadWords.Count == 0) {
|
||||||
Framework.Gui.Chat.Print("No muted words or sentences.");
|
Framework.Gui.Chat.Print("No muted words or sentences.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var word in PersistentSettings.Instance.BadWords) Framework.Gui.Chat.Print($"\"{word}\"");
|
this.Configuration.Save(this.StartInfo.ConfigurationPath);
|
||||||
|
|
||||||
|
foreach (var word in this.Configuration.BadWords) Framework.Gui.Chat.Print($"\"{word}\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBadWordsRemove(string command, string arguments) {
|
private void OnBadWordsRemove(string command, string arguments) {
|
||||||
if (PersistentSettings.Instance.BadWords == null)
|
if (this.Configuration.BadWords == null)
|
||||||
PersistentSettings.Instance.BadWords = new List<string>();
|
this.Configuration.BadWords = new List<string>();
|
||||||
|
|
||||||
PersistentSettings.Instance.BadWords.RemoveAll(x => x == arguments);
|
this.Configuration.BadWords.RemoveAll(x => x == arguments);
|
||||||
|
|
||||||
|
this.Configuration.Save(this.StartInfo.ConfigurationPath);
|
||||||
|
|
||||||
Framework.Gui.Chat.Print($"Unmuted \"{arguments}\".");
|
Framework.Gui.Chat.Print($"Unmuted \"{arguments}\".");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dalamud.Game.Chat;
|
using Dalamud.Game.Chat;
|
||||||
using Dalamud.Settings;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace Dalamud.Game {
|
namespace Dalamud.Game {
|
||||||
|
|
@ -81,8 +80,8 @@ namespace Dalamud.Game {
|
||||||
|
|
||||||
var originalMessage = string.Copy(message);
|
var originalMessage = string.Copy(message);
|
||||||
|
|
||||||
if (PersistentSettings.Instance.BadWords != null &&
|
if (this.dalamud.Configuration.BadWords != null &&
|
||||||
PersistentSettings.Instance.BadWords.Any(x => originalMessage.Contains(x))) {
|
this.dalamud.Configuration.BadWords.Any(x => originalMessage.Contains(x))) {
|
||||||
// This seems to be in the user block list - let's not show it
|
// This seems to be in the user block list - let's not show it
|
||||||
Log.Debug("Blocklist triggered");
|
Log.Debug("Blocklist triggered");
|
||||||
isHandled = true;
|
isHandled = true;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Dalamud.Settings;
|
|
||||||
using Dalamud.Game.Internal.Gui;
|
using Dalamud.Game.Internal.Gui;
|
||||||
using Dalamud.Game.Internal.Libc;
|
using Dalamud.Game.Internal.Libc;
|
||||||
using Dalamud.Game.Internal.Network;
|
using Dalamud.Game.Internal.Network;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ using System.Threading.Tasks;
|
||||||
using Dalamud.Game.Network.MarketBoardUploaders;
|
using Dalamud.Game.Network.MarketBoardUploaders;
|
||||||
using Dalamud.Game.Network.Structures;
|
using Dalamud.Game.Network.Structures;
|
||||||
using Dalamud.Game.Network.Universalis.MarketBoardUploaders;
|
using Dalamud.Game.Network.Universalis.MarketBoardUploaders;
|
||||||
using Dalamud.Settings;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace Dalamud.Game.Network {
|
namespace Dalamud.Game.Network {
|
||||||
|
|
@ -46,14 +45,14 @@ namespace Dalamud.Game.Network {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opCode == ZoneOpCode.FateSpawn) {
|
if (opCode == ZoneOpCode.FateSpawn) {
|
||||||
if (PersistentSettings.Instance.Fates == null)
|
if (this.dalamud.Configuration.Fates == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var data = new byte[64];
|
var data = new byte[64];
|
||||||
Marshal.Copy(dataPtr, data, 0, 64);
|
Marshal.Copy(dataPtr, data, 0, 64);
|
||||||
|
|
||||||
var fateId = data[16];
|
var fateId = data[16];
|
||||||
if (PersistentSettings.Instance.Fates.Any(x => x.Id == fateId) &&
|
if (this.dalamud.Configuration.Fates.Any(x => x.Id == fateId) &&
|
||||||
this.dalamud.BotManager.IsConnected)
|
this.dalamud.BotManager.IsConnected)
|
||||||
Task.Run(() => this.dalamud.BotManager.ProcessFate(fateId));
|
Task.Run(() => this.dalamud.BotManager.ProcessFate(fateId));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Dalamud.Settings
|
|
||||||
{
|
|
||||||
public class PersistentSettings {
|
|
||||||
private static PersistentSettings _instance = null;
|
|
||||||
|
|
||||||
private static readonly string ConfigPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "settings.json");
|
|
||||||
|
|
||||||
public static PersistentSettings Instance {
|
|
||||||
get {
|
|
||||||
if (_instance == null) {
|
|
||||||
if (!File.Exists(ConfigPath)) {
|
|
||||||
_instance = new PersistentSettings();
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
_instance = JsonConvert.DeserializeObject<PersistentSettings>(File.ReadAllText(ConfigPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class FateInfo {
|
|
||||||
public string Name { get; set; }
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FateInfo> Fates;
|
|
||||||
|
|
||||||
public List<string> BadWords;
|
|
||||||
|
|
||||||
public void Save() {
|
|
||||||
File.WriteAllText(ConfigPath, JsonConvert.SerializeObject(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Reset() {
|
|
||||||
_instance = new PersistentSettings();
|
|
||||||
Instance.Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue