mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Do not load plugins before performing checks
Modify the logic to perform all checks before proceeding to load the assembly and create an instance of the plugin - Removed `bool preloaded` in exchange to a `null` check in `pluginDef`. - Moved all checks into a common place before loading the assembly and before creating an instance. - Applicable Version check - Dalamud API check - Banned Plugins check - Checks will only be performed on raw / developer plugins. - Removed the old banned plugin code since the data is now in `bannedplugins.json`. All checks in the types foreach is removed since all the checks would had already be performed before then *(Only developer plugins has no pluginDef)* This should avoid mysterious crashes in future updates without making any major API / behavior changes.
This commit is contained in:
parent
7b7f1e8965
commit
9f9a41c768
1 changed files with 27 additions and 60 deletions
|
|
@ -152,7 +152,7 @@ namespace Dalamud.Plugin
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.LoadPluginFromAssembly(dllFile, isRaw, PluginLoadReason.Boot, true, definition);
|
this.LoadPluginFromAssembly(dllFile, isRaw, PluginLoadReason.Boot, definition);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -206,10 +206,9 @@ namespace Dalamud.Plugin
|
||||||
/// <param name="dllFile">The <see cref="FileInfo"/> associated with the main assembly of this plugin.</param>
|
/// <param name="dllFile">The <see cref="FileInfo"/> associated with the main assembly of this plugin.</param>
|
||||||
/// <param name="isRaw">Whether or not the plugin is a dev plugin.</param>
|
/// <param name="isRaw">Whether or not the plugin is a dev plugin.</param>
|
||||||
/// <param name="reason">The reason this plugin was loaded.</param>
|
/// <param name="reason">The reason this plugin was loaded.</param>
|
||||||
/// <param name="preloaded">Whether or not to skip loading a definition from a file path.</param>
|
/// <param name="pluginDef">The already loaded definition, if available</param>
|
||||||
/// <param name="preloadedDef">The already loaded definition, when <paramref name="preloaded"/> is set to true.</param>
|
|
||||||
/// <returns>Whether or not the plugin was loaded successfully.</returns>
|
/// <returns>Whether or not the plugin was loaded successfully.</returns>
|
||||||
public bool LoadPluginFromAssembly(FileInfo dllFile, bool isRaw, PluginLoadReason reason, bool preloaded = false, PluginDefinition preloadedDef = null)
|
public bool LoadPluginFromAssembly(FileInfo dllFile, bool isRaw, PluginLoadReason reason, PluginDefinition pluginDef = null)
|
||||||
{
|
{
|
||||||
Log.Information("Loading plugin at {0}", dllFile.Directory.FullName);
|
Log.Information("Loading plugin at {0}", dllFile.Directory.FullName);
|
||||||
|
|
||||||
|
|
@ -230,28 +229,8 @@ namespace Dalamud.Plugin
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginDefinition pluginDef = null;
|
|
||||||
|
|
||||||
// Preloaded
|
// Preloaded
|
||||||
if (preloaded)
|
if (pluginDef == null)
|
||||||
{
|
|
||||||
if (preloadedDef == null && !isRaw)
|
|
||||||
{
|
|
||||||
Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preloadedDef != null &&
|
|
||||||
preloadedDef.ApplicableVersion != this.dalamud.StartInfo.GameVersion &&
|
|
||||||
preloadedDef.ApplicableVersion != "any")
|
|
||||||
{
|
|
||||||
Log.Information("Plugin {0} has not applicable version.", dllFile.FullName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pluginDef = preloadedDef;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// read the plugin def if present - again, fail before actually trying to load the dll if there is a problem
|
// read the plugin def if present - again, fail before actually trying to load the dll if there is a problem
|
||||||
var defJsonFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, $"{Path.GetFileNameWithoutExtension(dllFile.Name)}.json"));
|
var defJsonFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, $"{Path.GetFileNameWithoutExtension(dllFile.Name)}.json"));
|
||||||
|
|
@ -264,16 +243,35 @@ namespace Dalamud.Plugin
|
||||||
pluginDef =
|
pluginDef =
|
||||||
JsonConvert.DeserializeObject<PluginDefinition>(
|
JsonConvert.DeserializeObject<PluginDefinition>(
|
||||||
File.ReadAllText(defJsonFile.FullName));
|
File.ReadAllText(defJsonFile.FullName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pluginDef.ApplicableVersion != this.dalamud.StartInfo.GameVersion && pluginDef.ApplicableVersion != "any")
|
// Perform checks
|
||||||
|
if (!isRaw)
|
||||||
|
{
|
||||||
|
if (pluginDef != null)
|
||||||
|
{
|
||||||
|
if (pluginDef.ApplicableVersion != this.dalamud.StartInfo.GameVersion &&
|
||||||
|
pluginDef.ApplicableVersion != "any")
|
||||||
{
|
{
|
||||||
Log.Information("Plugin {0} has not applicable version.", dllFile.FullName);
|
Log.Information("Plugin {0} has not applicable version.", dllFile.FullName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// but developer plugins don't require one to load
|
if (pluginDef.DalamudApiLevel < DalamudApiLevel)
|
||||||
else if (!isRaw)
|
{
|
||||||
|
Log.Error("Incompatible API level: {0}", dllFile.FullName);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.bannedPlugins.Any(x => x.Name == pluginDef.InternalName &&
|
||||||
|
x.AssemblyVersion == pluginDef.AssemblyVersion))
|
||||||
|
{
|
||||||
|
Log.Error($"[PLUGINM] Banned plugin {pluginDef.InternalName} {pluginDef.AssemblyVersion}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName);
|
Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -322,37 +320,6 @@ namespace Dalamud.Plugin
|
||||||
DalamudApiLevel = DalamudApiLevel,
|
DalamudApiLevel = DalamudApiLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.bannedPlugins.Any(x => x.Name == pluginDef.InternalName &&
|
|
||||||
x.AssemblyVersion == pluginDef.AssemblyVersion))
|
|
||||||
{
|
|
||||||
Log.Error($"[PLUGINM] Banned plugin {pluginDef.InternalName} with {pluginDef.AssemblyVersion}");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pluginDef.InternalName == "PingPlugin" && pluginDef.AssemblyVersion == "1.11.0.0")
|
|
||||||
{
|
|
||||||
Log.Error("Banned PingPlugin");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pluginDef.InternalName == "FPSPlugin" && pluginDef.AssemblyVersion == "1.4.2.0")
|
|
||||||
{
|
|
||||||
Log.Error("Banned PingPlugin");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pluginDef.InternalName == "SonarPlugin" && pluginDef.AssemblyVersion == "0.1.3.1")
|
|
||||||
{
|
|
||||||
Log.Error("Banned SonarPlugin");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pluginDef.DalamudApiLevel < DalamudApiLevel)
|
|
||||||
{
|
|
||||||
Log.Error("Incompatible API level: {0}", dllFile.FullName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Verbose("Plugin Initialize...");
|
Log.Verbose("Plugin Initialize...");
|
||||||
|
|
||||||
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name, this.pluginConfigs, reason);
|
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name, this.pluginConfigs, reason);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue