mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 05:04:15 +01:00
feat: add DALAMUD_API_LEVEL
This commit is contained in:
parent
ebce8ab05f
commit
ad93b6324f
5 changed files with 57 additions and 51 deletions
|
|
@ -318,8 +318,12 @@ namespace Dalamud {
|
|||
{
|
||||
OnPluginReloadCommand(string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
ImGui.MenuItem("API Level:" + PluginManager.DALAMUD_API_LEVEL, false);
|
||||
ImGui.MenuItem("Loaded plugins:" + PluginManager?.Plugins.Count, false);
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui.BeginMenu("Localization"))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,5 +16,6 @@ namespace Dalamud.Plugin
|
|||
public string ApplicableVersion { get; set; }
|
||||
public string RepoUrl { get; set; }
|
||||
public bool IsHide { get; set; }
|
||||
public int DalamudApiLevel { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,8 +66,9 @@ namespace Dalamud.Plugin
|
|||
} else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Fail) {
|
||||
ImGui.Text(Loc.Localize("InstallerDownloadFailed", "Download failed."));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
var didAny = false;
|
||||
|
||||
foreach (var pluginDefinition in this.dalamud.PluginRepository.PluginMaster) {
|
||||
if (pluginDefinition.ApplicableVersion != this.gameVersion &&
|
||||
pluginDefinition.ApplicableVersion != "any")
|
||||
|
|
@ -76,6 +77,11 @@ namespace Dalamud.Plugin
|
|||
if (pluginDefinition.IsHide)
|
||||
continue;
|
||||
|
||||
if (pluginDefinition.DalamudApiLevel != PluginManager.DALAMUD_API_LEVEL)
|
||||
continue;
|
||||
|
||||
didAny = true;
|
||||
|
||||
ImGui.PushID(pluginDefinition.InternalName + pluginDefinition.AssemblyVersion);
|
||||
|
||||
var isInstalled = this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).Any(
|
||||
|
|
@ -159,6 +165,9 @@ namespace Dalamud.Plugin
|
|||
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
if (!didAny)
|
||||
ImGui.TextColored(new Vector4(0.70f, 0.70f, 0.70f, 1.00f), Loc.Localize("InstallerNoCompatible", "No compatible plugins were found :( Please restart your game and try again."));
|
||||
}
|
||||
|
||||
ImGui.PopStyleVar();
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ using Serilog;
|
|||
namespace Dalamud.Plugin
|
||||
{
|
||||
internal class PluginManager {
|
||||
public const int DALAMUD_API_LEVEL = 1;
|
||||
|
||||
private readonly Dalamud dalamud;
|
||||
private readonly string pluginDirectory;
|
||||
private readonly string devPluginDirectory;
|
||||
|
|
@ -132,65 +134,49 @@ namespace Dalamud.Plugin
|
|||
// Assembly.Load() by name here will not load multiple versions with the same name, in the case of updates
|
||||
var pluginAssembly = Assembly.LoadFile(dllFile.FullName);
|
||||
|
||||
// Don't wanna fuck this up
|
||||
// This is a fix for earlier Chat Extender versions, since they break command handlers
|
||||
try
|
||||
Log.Information("Loading types for {0}", pluginAssembly.FullName);
|
||||
var types = pluginAssembly.GetTypes();
|
||||
foreach (var type in types)
|
||||
{
|
||||
var ver = int.Parse(pluginAssembly.GetName().Version.ToString().Replace(".", ""));
|
||||
if (dllFile.Name.Contains("ChatExtender") &&
|
||||
ver < 1410)
|
||||
if (type.IsInterface || type.IsAbstract)
|
||||
{
|
||||
Log.Information($"Found banned v{ver} ChatExtender, skipping...");
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
if (pluginAssembly != null)
|
||||
{
|
||||
Log.Information("Loading types for {0}", pluginAssembly.FullName);
|
||||
var types = pluginAssembly.GetTypes();
|
||||
foreach (var type in types)
|
||||
if (type.GetInterface(interfaceType.FullName) != null)
|
||||
{
|
||||
if (type.IsInterface || type.IsAbstract)
|
||||
if (this.Plugins.Any(x => x.Plugin.GetType().Assembly.GetName().Name == type.Assembly.GetName().Name))
|
||||
{
|
||||
continue;
|
||||
Log.Error("Duplicate plugin found: {0}", dllFile.FullName);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type.GetInterface(interfaceType.FullName) != null)
|
||||
{
|
||||
if (this.Plugins.Any(x => x.Plugin.GetType().Assembly.GetName().Name == type.Assembly.GetName().Name)) {
|
||||
Log.Error("Duplicate plugin found: {0}", dllFile.FullName);
|
||||
return false;
|
||||
}
|
||||
var plugin = (IDalamudPlugin)Activator.CreateInstance(type);
|
||||
|
||||
var plugin = (IDalamudPlugin)Activator.CreateInstance(type);
|
||||
// this happens for raw plugins that don't specify a PluginDefinition - just generate a dummy one to avoid crashes anywhere
|
||||
pluginDef ??= new PluginDefinition{
|
||||
Author = "developer",
|
||||
Name = plugin.Name,
|
||||
InternalName = Path.GetFileNameWithoutExtension(dllFile.Name),
|
||||
AssemblyVersion = plugin.GetType().Assembly.GetName().Version.ToString(),
|
||||
Description = "",
|
||||
ApplicableVersion = "any",
|
||||
IsHide = false,
|
||||
DalamudApiLevel = DALAMUD_API_LEVEL
|
||||
};
|
||||
|
||||
// this happens for raw plugins that don't specify a PluginDefinition - just generate a dummy one to avoid crashes anywhere
|
||||
if (pluginDef == null)
|
||||
{
|
||||
pluginDef = new PluginDefinition
|
||||
{
|
||||
Author = "developer",
|
||||
Name = plugin.Name,
|
||||
InternalName = Path.GetFileNameWithoutExtension(dllFile.Name),
|
||||
AssemblyVersion = plugin.GetType().Assembly.GetName().Version.ToString(),
|
||||
Description = "",
|
||||
ApplicableVersion = "any",
|
||||
IsHide = false
|
||||
};
|
||||
}
|
||||
|
||||
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name, this.pluginConfigs);
|
||||
plugin.Initialize(dalamudInterface);
|
||||
Log.Information("Loaded plugin: {0}", plugin.Name);
|
||||
this.Plugins.Add((plugin, pluginDef, dalamudInterface));
|
||||
|
||||
return true;
|
||||
if (pluginDef.DalamudApiLevel != DALAMUD_API_LEVEL) {
|
||||
Log.Error("Incompatible API level: {0}", dllFile.FullName);
|
||||
return false;
|
||||
}
|
||||
|
||||
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name, this.pluginConfigs);
|
||||
plugin.Initialize(dalamudInterface);
|
||||
|
||||
Log.Information("Loaded plugin: {0}", plugin.Name);
|
||||
this.Plugins.Add((plugin, pluginDef, dalamudInterface));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -160,6 +160,12 @@ namespace Dalamud.Plugin
|
|||
continue;
|
||||
}
|
||||
|
||||
if (remoteInfo.DalamudApiLevel != PluginManager.DALAMUD_API_LEVEL)
|
||||
{
|
||||
Log.Information("Has not applicable API level: {0}", info.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (remoteInfo.AssemblyVersion != info.AssemblyVersion)
|
||||
{
|
||||
Log.Information("Eligible for update: {0}", remoteInfo.InternalName);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue