mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
reload player resources once a mod reload has occurred, wip api
This commit is contained in:
parent
f1d8ce0221
commit
77cda604c6
6 changed files with 109 additions and 8 deletions
41
Penumbra/API/ModsController.cs
Normal file
41
Penumbra/API/ModsController.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using EmbedIO;
|
||||||
|
using EmbedIO.Routing;
|
||||||
|
using EmbedIO.WebApi;
|
||||||
|
|
||||||
|
namespace Penumbra.API
|
||||||
|
{
|
||||||
|
public class ModsController : WebApiController
|
||||||
|
{
|
||||||
|
private readonly Plugin _plugin;
|
||||||
|
|
||||||
|
public ModsController( Plugin plugin )
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route( HttpVerbs.Get, "/mods" )]
|
||||||
|
public object GetMods()
|
||||||
|
{
|
||||||
|
return _plugin.ModManager.Mods.ModSettings.Select( x => new
|
||||||
|
{
|
||||||
|
x.Enabled,
|
||||||
|
x.Priority,
|
||||||
|
x.FolderName,
|
||||||
|
x.Mod.Meta,
|
||||||
|
BasePath = x.Mod.ModBasePath.FullName,
|
||||||
|
Files = x.Mod.ModFiles.Select( x => x.FullName )
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route( HttpVerbs.Get, "/files" )]
|
||||||
|
public object CreateMod()
|
||||||
|
{
|
||||||
|
return _plugin.ModManager.ResolvedFiles.ToDictionary(
|
||||||
|
o => o.Key,
|
||||||
|
o => o.Value.FullName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,8 @@ namespace Penumbra
|
||||||
|
|
||||||
public bool DisableFileSystemNotifications { get; set; } = false;
|
public bool DisableFileSystemNotifications { get; set; } = false;
|
||||||
|
|
||||||
|
public bool EnableHttpApi { get; set; } = false;
|
||||||
|
|
||||||
public string CurrentCollection { get; set; } = @"D:/ffxiv/fs_mods/";
|
public string CurrentCollection { get; set; } = @"D:/ffxiv/fs_mods/";
|
||||||
|
|
||||||
public List< string > ModCollections { get; set; } = new();
|
public List< string > ModCollections { get; set; } = new();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ namespace Penumbra.Mods
|
||||||
{
|
{
|
||||||
public class ModManager : IDisposable
|
public class ModManager : IDisposable
|
||||||
{
|
{
|
||||||
|
private readonly Plugin _plugin;
|
||||||
public readonly Dictionary< string, FileInfo > ResolvedFiles = new();
|
public readonly Dictionary< string, FileInfo > ResolvedFiles = new();
|
||||||
public readonly Dictionary< string, string > SwappedFiles = new();
|
public readonly Dictionary< string, string > SwappedFiles = new();
|
||||||
|
|
||||||
|
|
@ -14,6 +15,11 @@ namespace Penumbra.Mods
|
||||||
|
|
||||||
private DirectoryInfo _basePath;
|
private DirectoryInfo _basePath;
|
||||||
|
|
||||||
|
public ModManager( Plugin plugin )
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
public void DiscoverMods()
|
public void DiscoverMods()
|
||||||
{
|
{
|
||||||
if( _basePath == null )
|
if( _basePath == null )
|
||||||
|
|
@ -92,6 +98,9 @@ namespace Penumbra.Mods
|
||||||
Mods.Save();
|
Mods.Save();
|
||||||
|
|
||||||
CalculateEffectiveFileList();
|
CalculateEffectiveFileList();
|
||||||
|
|
||||||
|
// Needed to reload body textures with mods
|
||||||
|
_plugin.GameUtils.ReloadPlayerResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CalculateEffectiveFileList()
|
public void CalculateEffectiveFileList()
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="EmbedIO" Version="3.4.3" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="Reloaded.Hooks" Version="2.4.1" />
|
<PackageReference Include="Reloaded.Hooks" Version="2.4.1" />
|
||||||
<PackageReference Include="SharpZipLib" Version="1.3.1" />
|
<PackageReference Include="SharpZipLib" Version="1.3.1" />
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
|
using EmbedIO;
|
||||||
|
using EmbedIO.Actions;
|
||||||
|
using EmbedIO.WebApi;
|
||||||
|
using Penumbra.API;
|
||||||
using Penumbra.Game;
|
using Penumbra.Game;
|
||||||
using Penumbra.Mods;
|
using Penumbra.Mods;
|
||||||
using Penumbra.UI;
|
using Penumbra.UI;
|
||||||
|
|
@ -13,7 +17,7 @@ namespace Penumbra
|
||||||
private const string CommandName = "/penumbra";
|
private const string CommandName = "/penumbra";
|
||||||
|
|
||||||
public DalamudPluginInterface PluginInterface { get; set; }
|
public DalamudPluginInterface PluginInterface { get; set; }
|
||||||
|
|
||||||
public Configuration Configuration { get; set; }
|
public Configuration Configuration { get; set; }
|
||||||
|
|
||||||
public ResourceLoader ResourceLoader { get; set; }
|
public ResourceLoader ResourceLoader { get; set; }
|
||||||
|
|
@ -26,18 +30,18 @@ namespace Penumbra
|
||||||
|
|
||||||
public string PluginDebugTitleStr { get; private set; }
|
public string PluginDebugTitleStr { get; private set; }
|
||||||
|
|
||||||
public bool ImportInProgress => SettingsInterface?.IsImportRunning ?? true;
|
private WebServer _webServer;
|
||||||
|
|
||||||
public void Initialize( DalamudPluginInterface pluginInterface )
|
public void Initialize( DalamudPluginInterface pluginInterface )
|
||||||
{
|
{
|
||||||
PluginInterface = pluginInterface;
|
PluginInterface = pluginInterface;
|
||||||
|
|
||||||
Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
||||||
Configuration.Initialize( PluginInterface );
|
Configuration.Initialize( PluginInterface );
|
||||||
|
|
||||||
GameUtils = new GameUtils( PluginInterface );
|
GameUtils = new GameUtils( PluginInterface );
|
||||||
|
|
||||||
ModManager = new ModManager();
|
ModManager = new ModManager( this );
|
||||||
ModManager.DiscoverMods( Configuration.CurrentCollection );
|
ModManager.DiscoverMods( Configuration.CurrentCollection );
|
||||||
|
|
||||||
ResourceLoader = new ResourceLoader( this );
|
ResourceLoader = new ResourceLoader( this );
|
||||||
|
|
@ -50,13 +54,39 @@ namespace Penumbra
|
||||||
ResourceLoader.Init();
|
ResourceLoader.Init();
|
||||||
ResourceLoader.Enable();
|
ResourceLoader.Enable();
|
||||||
|
|
||||||
// Needed to reload body textures with mods
|
|
||||||
GameUtils.ReloadPlayerResources();
|
|
||||||
|
|
||||||
SettingsInterface = new SettingsInterface( this );
|
SettingsInterface = new SettingsInterface( this );
|
||||||
PluginInterface.UiBuilder.OnBuildUi += SettingsInterface.Draw;
|
PluginInterface.UiBuilder.OnBuildUi += SettingsInterface.Draw;
|
||||||
|
|
||||||
PluginDebugTitleStr = $"{Name} - Debug Build";
|
PluginDebugTitleStr = $"{Name} - Debug Build";
|
||||||
|
|
||||||
|
if( Configuration.EnableHttpApi )
|
||||||
|
{
|
||||||
|
CreateWebServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateWebServer()
|
||||||
|
{
|
||||||
|
var prefix = "http://localhost:45800/";
|
||||||
|
|
||||||
|
ShutdownWebServer();
|
||||||
|
|
||||||
|
_webServer = new WebServer( o => o
|
||||||
|
.WithUrlPrefix( prefix )
|
||||||
|
.WithMode( HttpListenerMode.EmbedIO ) )
|
||||||
|
.WithCors( prefix )
|
||||||
|
.WithWebApi( "/api", m => m
|
||||||
|
.WithController( () => new ModsController( this ) ) );
|
||||||
|
|
||||||
|
_webServer.StateChanged += ( s, e ) => PluginLog.Information( $"WebServer New State - {e.NewState}" );
|
||||||
|
|
||||||
|
_webServer.RunAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShutdownWebServer()
|
||||||
|
{
|
||||||
|
_webServer?.Dispose();
|
||||||
|
_webServer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|
@ -69,6 +99,8 @@ namespace Penumbra
|
||||||
PluginInterface.Dispose();
|
PluginInterface.Dispose();
|
||||||
|
|
||||||
ResourceLoader.Dispose();
|
ResourceLoader.Dispose();
|
||||||
|
|
||||||
|
ShutdownWebServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCommand( string command, string rawArgs )
|
private void OnCommand( string command, string rawArgs )
|
||||||
|
|
@ -94,4 +126,4 @@ namespace Penumbra
|
||||||
SettingsInterface.Visible = !SettingsInterface.Visible;
|
SettingsInterface.Visible = !SettingsInterface.Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -299,6 +299,22 @@ namespace Penumbra.UI
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var http = _plugin.Configuration.EnableHttpApi;
|
||||||
|
if( ImGui.Checkbox( "Enable HTTP API", ref http ) )
|
||||||
|
{
|
||||||
|
if( http )
|
||||||
|
{
|
||||||
|
_plugin.CreateWebServer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_plugin.ShutdownWebServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
_plugin.Configuration.EnableHttpApi = http;
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
if( ImGui.Button( "Reload Player Resource" ) )
|
if( ImGui.Button( "Reload Player Resource" ) )
|
||||||
{
|
{
|
||||||
_plugin.GameUtils.ReloadPlayerResources();
|
_plugin.GameUtils.ReloadPlayerResources();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue