feat: capture mods in use

This commit is contained in:
Anna 2024-02-18 11:39:40 -05:00
parent 282f764916
commit b5089d00e4
Signed by: anna
GPG Key ID: D0943384CD9F87D1
3 changed files with 55 additions and 13 deletions

View File

@ -43,18 +43,6 @@ internal class Command : IDisposable {
return;
}
if (this.Plugin.Penumbra.GetPlayerResourcePaths() is { } paths) {
foreach (var (objId, data) in paths) {
Plugin.Log.Info($"{objId}");
foreach (var (key, value) in data) {
Plugin.Log.Info($" {key}");
foreach (var str in value) {
Plugin.Log.Info($" {str}");
}
}
}
}
Task.Factory.StartNew(async () => {
using var bitmap = bitmapOuter;

View File

@ -3,12 +3,24 @@ using Screenie;
internal class PenumbraIpc {
private Plugin Plugin { get; }
private FuncSubscriber<string> GetModDirectorySubscriber { get; }
private FuncSubscriber<IReadOnlyDictionary<ushort, IReadOnlyDictionary<string, string[]>>> GetPlayerResourcePathsSubscriber { get; }
private FuncSubscriber<IList<(string, string)>> GetModsSubscriber { get; }
internal PenumbraIpc(Plugin plugin) {
this.Plugin = plugin;
this.GetModDirectorySubscriber = Penumbra.Api.Ipc.GetModDirectory.Subscriber(this.Plugin.Interface);
this.GetPlayerResourcePathsSubscriber = Penumbra.Api.Ipc.GetPlayerResourcePaths.Subscriber(this.Plugin.Interface);
this.GetModsSubscriber = Penumbra.Api.Ipc.GetMods.Subscriber(this.Plugin.Interface);
}
internal string? GetModDirectory() {
try {
return this.GetModDirectorySubscriber.Invoke();
} catch {
return null;
}
}
internal IReadOnlyDictionary<ushort, IReadOnlyDictionary<string, string[]>>? GetPlayerResourcePaths() {
@ -18,4 +30,12 @@ internal class PenumbraIpc {
return null;
}
}
internal IList<(string Directory, string Name)>? GetMods() {
try {
return this.GetModsSubscriber.Invoke();
} catch {
return null;
}
}
}

View File

@ -111,6 +111,40 @@ public class ScreenshotMetadata {
.Select(tuple => new Character(tuple.chara, tuple.screenPos, scale, offsetX, offsetY))
.ToArray();
var modDir = plugin.Penumbra.GetModDirectory();
var paths = plugin.Penumbra.GetPlayerResourcePaths();
var mods = plugin.Penumbra.GetMods();
var modsInUse = new List<PenumbraMod>();
if (modDir != null && paths != null && mods != null) {
var baseUri = new Uri($"{modDir}/");
foreach (var dict in paths.Values) {
foreach (var path in dict.Keys) {
if (!Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var pathUri)) {
continue;
}
if (!pathUri.IsAbsoluteUri || !baseUri.IsBaseOf(pathUri)) {
continue;
}
var modPathUntrimmed = Uri.UnescapeDataString(pathUri.Segments[baseUri.Segments.Length..][0]);
var modPath = Path.TrimEndingDirectorySeparator(modPathUntrimmed);
var found = mods.FirstOrDefault(mod => string.Equals(mod.Directory, modPath, StringComparison.OrdinalIgnoreCase));
if (found != default) {
modsInUse.Add(new PenumbraMod {
Name = found.Name,
Path = found.Directory,
});
}
}
}
}
foreach (var mod in modsInUse) {
Plugin.Log.Info($"{mod.Name} at {mod.Path}");
}
return new ScreenshotMetadata {
ActiveCharacter = active,
Location = map?.PlaceName.Value?.Name.ToDalamudString().TextValue.WhitespaceToNull()
@ -128,7 +162,7 @@ public class ScreenshotMetadata {
Ward = ward,
Plot = plot,
VisibleCharacters = visible,
ModsInUse = Array.Empty<PenumbraMod>(), // TODO
ModsInUse = [.. modsInUse],
};
}
}