Initial commit

This commit is contained in:
goat 2019-09-21 22:29:38 +09:00
commit ac838687f8
157 changed files with 27905 additions and 0 deletions

View file

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dalamud.Game.ClientState;
using Dalamud.Game.Command;
using Dalamud.Game.Internal;
using Dalamud.Game.Internal.Gui;
namespace Dalamud.Plugin
{
/// <summary>
/// This class acts as an interface to various objects needed to interact with Dalamud and the game.
/// </summary>
public class DalamudPluginInterface {
/// <summary>
/// The CommandManager object that allows you to add and remove custom chat commands.
/// </summary>
public readonly CommandManager CommandManager;
/// <summary>
/// The ClientState object that allows you to access current client memory information like actors, territories, etc.
/// </summary>
public readonly ClientState ClientState;
/// <summary>
/// The Framework object that allows you to interact with the client.
/// </summary>
public readonly Framework Framework;
/// <summary>
/// Set up the interface and populate all fields needed.
/// </summary>
/// <param name="dalamud"></param>
public DalamudPluginInterface(Dalamud dalamud) {
this.CommandManager = dalamud.CommandManager;
this.Framework = dalamud.Framework;
this.ClientState = dalamud.ClientState;
}
}
}

View file

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dalamud.Plugin
{
/// <summary>
/// This interface represents a basic Dalamud plugin. All plugins have to implement this interface.
/// </summary>
public interface IDalamudPlugin : IDisposable
{
/// <summary>
/// The name of the plugin.
/// </summary>
string Name { get; }
/// <summary>
/// Initializes a Dalamud plugin.
/// </summary>
/// <param name="pluginInterface">The <see cref="DalamudPluginInterface"/> needed to access various Dalamud objects.</param>
void Initialize(DalamudPluginInterface pluginInterface);
}
}

View file

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Serilog;
namespace Dalamud.Plugin
{
public class PluginManager {
private readonly Dalamud dalamud;
private readonly string pluginDirectory;
private readonly string defaultPluginDirectory;
private readonly DalamudPluginInterface dalamudInterface;
private List<IDalamudPlugin> plugins;
public PluginManager(Dalamud dalamud, string pluginDirectory, string defaultPluginDirectory) {
this.dalamud = dalamud;
this.pluginDirectory = pluginDirectory;
this.defaultPluginDirectory = defaultPluginDirectory;
this.dalamudInterface = new DalamudPluginInterface(dalamud);
}
public void UnloadPlugins() {
if (this.plugins == null)
return;
for (var i = 0; i < this.plugins.Count; i++) {
this.plugins[i].Dispose();
this.plugins[i] = null;
}
}
public void LoadPlugins() {
LoadPluginsAt(this.defaultPluginDirectory);
LoadPluginsAt(this.pluginDirectory);
}
private void LoadPluginsAt(string folder) {
if (Directory.Exists(folder))
{
Log.Debug("Loading plugins at {0}", folder);
var pluginFileNames = Directory.GetFiles(folder, "*.dll");
var assemblies = new List<Assembly>(pluginFileNames.Length);
foreach (var dllFile in pluginFileNames)
{
Log.Debug("Loading assembly at {0}", dllFile);
var assemblyName = AssemblyName.GetAssemblyName(dllFile);
var pluginAssembly = Assembly.Load(assemblyName);
assemblies.Add(pluginAssembly);
}
var interfaceType = typeof(IDalamudPlugin);
var foundImplementations = new List<Type>();
foreach (var assembly in assemblies) {
if (assembly != null) {
Log.Debug("Loading types for {0}", assembly.FullName);
var types = assembly.GetTypes();
foreach (var type in types) {
if (type.IsInterface || type.IsAbstract) {
continue;
}
if (type.GetInterface(interfaceType.FullName) != null) {
foundImplementations.Add(type);
}
}
}
}
this.plugins = new List<IDalamudPlugin>(foundImplementations.Count);
foreach (var pluginType in foundImplementations)
{
var plugin = (IDalamudPlugin)Activator.CreateInstance(pluginType);
plugin.Initialize(this.dalamudInterface);
Log.Information("Loaded plugin: {0}", plugin.Name);
this.plugins.Add(plugin);
}
}
}
}
}