forked from aly/qstbak
punish v6.8.18.0
This commit is contained in:
commit
cfb4dea47e
316 changed files with 554088 additions and 0 deletions
100
LLib/LLib/DalamudReflector.cs
Normal file
100
LLib/LLib/DalamudReflector.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Services;
|
||||
|
||||
namespace LLib;
|
||||
|
||||
public sealed class DalamudReflector : IDisposable
|
||||
{
|
||||
private readonly IDalamudPluginInterface _pluginInterface;
|
||||
|
||||
private readonly IFramework _framework;
|
||||
|
||||
private readonly IPluginLog _pluginLog;
|
||||
|
||||
private readonly Dictionary<string, IDalamudPlugin> _pluginCache = new Dictionary<string, IDalamudPlugin>();
|
||||
|
||||
private bool _pluginsChanged;
|
||||
|
||||
public DalamudReflector(IDalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog)
|
||||
{
|
||||
_pluginInterface = pluginInterface;
|
||||
_framework = framework;
|
||||
_pluginLog = pluginLog;
|
||||
object pluginManager = GetPluginManager();
|
||||
pluginManager.GetType().GetEvent("OnInstalledPluginsChanged").AddEventHandler(pluginManager, new Action(OnInstalledPluginsChanged));
|
||||
_framework.Update += FrameworkUpdate;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_framework.Update -= FrameworkUpdate;
|
||||
object pluginManager = GetPluginManager();
|
||||
pluginManager.GetType().GetEvent("OnInstalledPluginsChanged").RemoveEventHandler(pluginManager, new Action(OnInstalledPluginsChanged));
|
||||
}
|
||||
|
||||
private void FrameworkUpdate(IFramework framework)
|
||||
{
|
||||
if (_pluginsChanged)
|
||||
{
|
||||
_pluginsChanged = false;
|
||||
_pluginCache.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private object GetPluginManager()
|
||||
{
|
||||
return _pluginInterface.GetType().Assembly.GetType("Dalamud.Service`1", throwOnError: true).MakeGenericType(_pluginInterface.GetType().Assembly.GetType("Dalamud.Plugin.Internal.PluginManager", throwOnError: true)).GetMethod("Get")
|
||||
.Invoke(null, BindingFlags.Default, null, Array.Empty<object>(), null);
|
||||
}
|
||||
|
||||
public bool TryGetDalamudPlugin(string internalName, [MaybeNullWhen(false)] out IDalamudPlugin instance, bool suppressErrors = false, bool ignoreCache = false)
|
||||
{
|
||||
if (!ignoreCache && _pluginCache.TryGetValue(internalName, out instance))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
object pluginManager = GetPluginManager();
|
||||
foreach (object item in (IList)pluginManager.GetType().GetProperty("InstalledPlugins").GetValue(pluginManager))
|
||||
{
|
||||
if ((string)item.GetType().GetProperty("Name").GetValue(item) == internalName)
|
||||
{
|
||||
IDalamudPlugin dalamudPlugin = (IDalamudPlugin)((item.GetType().Name == "LocalDevPlugin") ? item.GetType().BaseType : item.GetType()).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(item);
|
||||
if (dalamudPlugin != null)
|
||||
{
|
||||
instance = dalamudPlugin;
|
||||
_pluginCache[internalName] = dalamudPlugin;
|
||||
return true;
|
||||
}
|
||||
if (!suppressErrors)
|
||||
{
|
||||
_pluginLog.Warning("[DalamudReflector] Found requested plugin " + internalName + " but it was null");
|
||||
}
|
||||
}
|
||||
}
|
||||
instance = null;
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!suppressErrors)
|
||||
{
|
||||
_pluginLog.Error(ex, "Can't find " + internalName + " plugin: " + ex.Message);
|
||||
}
|
||||
instance = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInstalledPluginsChanged()
|
||||
{
|
||||
_pluginLog.Verbose("Installed plugins changed event fired");
|
||||
_pluginsChanged = true;
|
||||
}
|
||||
}
|
||||
104
LLib/LLib/DataManagerExtensions.cs
Normal file
104
LLib/LLib/DataManagerExtensions.cs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Dalamud.Plugin.Services;
|
||||
using Lumina.Excel;
|
||||
using Lumina.Text.Payloads;
|
||||
using Lumina.Text.ReadOnly;
|
||||
|
||||
namespace LLib;
|
||||
|
||||
public static class DataManagerExtensions
|
||||
{
|
||||
public static ReadOnlySeString? GetSeString<T>(this IDataManager dataManager, string key) where T : struct, IQuestDialogueText, IExcelRow<T>
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(dataManager, "dataManager");
|
||||
return dataManager.GetExcelSheet<T>().Cast<T?>().SingleOrDefault((T? x) => x.Value.Key == key)?.Value;
|
||||
}
|
||||
|
||||
public static string? GetString<T>(this IDataManager dataManager, string key, IPluginLog? pluginLog) where T : struct, IQuestDialogueText, IExcelRow<T>
|
||||
{
|
||||
string text = dataManager.GetSeString<T>(key)?.WithCertainMacroCodeReplacements();
|
||||
pluginLog?.Verbose($"{typeof(T).Name}.{key} => {text}");
|
||||
return text;
|
||||
}
|
||||
|
||||
public static Regex? GetRegex<T>(this IDataManager dataManager, string key, IPluginLog? pluginLog) where T : struct, IQuestDialogueText, IExcelRow<T>
|
||||
{
|
||||
ReadOnlySeString? seString = dataManager.GetSeString<T>(key);
|
||||
if (!seString.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string text = string.Join("", seString.Select((ReadOnlySePayload payload) => (payload.Type == ReadOnlySePayloadType.Text) ? Regex.Escape(payload.ToString()) : "(.*)"));
|
||||
pluginLog?.Verbose($"{typeof(T).Name}.{key} => /{text}/");
|
||||
return new Regex(text);
|
||||
}
|
||||
|
||||
public static ReadOnlySeString? GetSeString<T>(this IDataManager dataManager, uint rowId, Func<T, ReadOnlySeString?> mapper) where T : struct, IExcelRow<T>
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(dataManager, "dataManager");
|
||||
ArgumentNullException.ThrowIfNull(mapper, "mapper");
|
||||
T? rowOrDefault = dataManager.GetExcelSheet<T>().GetRowOrDefault(rowId);
|
||||
if (!rowOrDefault.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return mapper(rowOrDefault.Value);
|
||||
}
|
||||
|
||||
public static string? GetString<T>(this IDataManager dataManager, uint rowId, Func<T, ReadOnlySeString?> mapper, IPluginLog? pluginLog = null) where T : struct, IExcelRow<T>
|
||||
{
|
||||
string text = dataManager.GetSeString(rowId, mapper)?.WithCertainMacroCodeReplacements();
|
||||
pluginLog?.Verbose($"{typeof(T).Name}.{rowId} => {text}");
|
||||
return text;
|
||||
}
|
||||
|
||||
public static Regex? GetRegex<T>(this IDataManager dataManager, uint rowId, Func<T, ReadOnlySeString?> mapper, IPluginLog? pluginLog = null) where T : struct, IExcelRow<T>
|
||||
{
|
||||
ReadOnlySeString? seString = dataManager.GetSeString(rowId, mapper);
|
||||
if (!seString.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Regex regex = seString.ToRegex();
|
||||
pluginLog?.Verbose($"{typeof(T).Name}.{rowId} => /{regex}/");
|
||||
return regex;
|
||||
}
|
||||
|
||||
public static Regex? GetRegex<T>(this T excelRow, Func<T, ReadOnlySeString?> mapper, IPluginLog? pluginLog) where T : struct, IExcelRow<T>
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(mapper, "mapper");
|
||||
ReadOnlySeString? text = mapper(excelRow);
|
||||
if (!text.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Regex regex = text.ToRegex();
|
||||
pluginLog?.Verbose($"{typeof(T).Name}.regex => /{regex}/");
|
||||
return regex;
|
||||
}
|
||||
|
||||
public static Regex ToRegex(this ReadOnlySeString? text)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(text, "text");
|
||||
return new Regex(string.Join("", text.Value.Select((ReadOnlySePayload payload) => (payload.Type == ReadOnlySePayloadType.Text) ? Regex.Escape(payload.ToString()) : "(.*)")));
|
||||
}
|
||||
|
||||
public static string WithCertainMacroCodeReplacements(this ReadOnlySeString text)
|
||||
{
|
||||
return string.Join("", text.Select((ReadOnlySePayload payload) => payload.Type switch
|
||||
{
|
||||
ReadOnlySePayloadType.Text => payload.ToString(),
|
||||
ReadOnlySePayloadType.Macro => payload.MacroCode switch
|
||||
{
|
||||
MacroCode.NewLine => "",
|
||||
MacroCode.NonBreakingSpace => " ",
|
||||
MacroCode.Hyphen => "-",
|
||||
MacroCode.SoftHyphen => "",
|
||||
_ => payload.ToString(),
|
||||
},
|
||||
_ => payload.ToString(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
10
LLib/LLib/IQuestDialogueText.cs
Normal file
10
LLib/LLib/IQuestDialogueText.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Lumina.Text.ReadOnly;
|
||||
|
||||
namespace LLib;
|
||||
|
||||
public interface IQuestDialogueText
|
||||
{
|
||||
ReadOnlySeString Key { get; }
|
||||
|
||||
ReadOnlySeString Value { get; }
|
||||
}
|
||||
26
LLib/LLib/QuestDialogueText.cs
Normal file
26
LLib/LLib/QuestDialogueText.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using Lumina.Excel;
|
||||
using Lumina.Text.ReadOnly;
|
||||
|
||||
namespace LLib;
|
||||
|
||||
[Sheet("PleaseSpecifyTheSheetExplicitly")]
|
||||
public readonly struct QuestDialogueText : IQuestDialogueText, IExcelRow<QuestDialogueText>
|
||||
{
|
||||
public uint RowId => _003Crow_003EP;
|
||||
|
||||
public ReadOnlySeString Key => _003Cpage_003EP.ReadString(_003Coffset_003EP, _003Coffset_003EP);
|
||||
|
||||
public ReadOnlySeString Value => _003Cpage_003EP.ReadString(_003Coffset_003EP + 4, _003Coffset_003EP);
|
||||
|
||||
public QuestDialogueText(ExcelPage page, uint offset, uint row)
|
||||
{
|
||||
_003Cpage_003EP = page;
|
||||
_003Coffset_003EP = offset;
|
||||
_003Crow_003EP = row;
|
||||
}
|
||||
|
||||
static QuestDialogueText IExcelRow<QuestDialogueText>.Create(ExcelPage page, uint offset, uint row)
|
||||
{
|
||||
return new QuestDialogueText(page, offset, row);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue