Fix devplugins again & bump CS (#1221)

* reapply devplugins directory removal, without breaking everything

Revert "Revert "Remove support for legacy devplugins directory (#1219)" (#1220)"

This reverts commit 681cda91a4.

* bump CS
This commit is contained in:
Ava Chaney 2023-05-26 18:40:51 -07:00 committed by GitHub
parent 5af1425c97
commit 95b0565976
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 103 additions and 42 deletions

View file

@ -200,15 +200,21 @@ namespace Dalamud.Injector
var logFile = new FileInfo(logPath); var logFile = new FileInfo(logPath);
if (!logFile.Exists) if (!logFile.Exists)
{
logFile.Create(); logFile.Create();
}
if (logFile.Length <= cullingFileSize) if (logFile.Length <= cullingFileSize)
{
return; return;
}
var amountToCull = logFile.Length - cullingFileSize; var amountToCull = logFile.Length - cullingFileSize;
if (amountToCull < bufferSize) if (amountToCull < bufferSize)
{
return; return;
}
using var reader = new BinaryReader(logFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); using var reader = new BinaryReader(logFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
using var writer = new BinaryWriter(logFile.Open(FileMode.Open, FileAccess.Write, FileShare.ReadWrite)); using var writer = new BinaryWriter(logFile.Open(FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
@ -247,7 +253,6 @@ namespace Dalamud.Injector
var workingDirectory = startInfo.WorkingDirectory; var workingDirectory = startInfo.WorkingDirectory;
var configurationPath = startInfo.ConfigurationPath; var configurationPath = startInfo.ConfigurationPath;
var pluginDirectory = startInfo.PluginDirectory; var pluginDirectory = startInfo.PluginDirectory;
var defaultPluginDirectory = startInfo.DefaultPluginDirectory;
var assetDirectory = startInfo.AssetDirectory; var assetDirectory = startInfo.AssetDirectory;
var delayInitializeMs = startInfo.DelayInitializeMs; var delayInitializeMs = startInfo.DelayInitializeMs;
var logName = startInfo.LogName; var logName = startInfo.LogName;
@ -257,25 +262,41 @@ namespace Dalamud.Injector
for (var i = 2; i < args.Count; i++) for (var i = 2; i < args.Count; i++)
{ {
if (args[i].StartsWith(key = "--dalamud-working-directory=")) if (args[i].StartsWith(key = "--dalamud-working-directory="))
{
workingDirectory = args[i][key.Length..]; workingDirectory = args[i][key.Length..];
}
else if (args[i].StartsWith(key = "--dalamud-configuration-path=")) else if (args[i].StartsWith(key = "--dalamud-configuration-path="))
{
configurationPath = args[i][key.Length..]; configurationPath = args[i][key.Length..];
}
else if (args[i].StartsWith(key = "--dalamud-plugin-directory=")) else if (args[i].StartsWith(key = "--dalamud-plugin-directory="))
{
pluginDirectory = args[i][key.Length..]; pluginDirectory = args[i][key.Length..];
else if (args[i].StartsWith(key = "--dalamud-dev-plugin-directory=")) }
defaultPluginDirectory = args[i][key.Length..];
else if (args[i].StartsWith(key = "--dalamud-asset-directory=")) else if (args[i].StartsWith(key = "--dalamud-asset-directory="))
{
assetDirectory = args[i][key.Length..]; assetDirectory = args[i][key.Length..];
}
else if (args[i].StartsWith(key = "--dalamud-delay-initialize=")) else if (args[i].StartsWith(key = "--dalamud-delay-initialize="))
{
delayInitializeMs = int.Parse(args[i][key.Length..]); delayInitializeMs = int.Parse(args[i][key.Length..]);
}
else if (args[i].StartsWith(key = "--dalamud-client-language=")) else if (args[i].StartsWith(key = "--dalamud-client-language="))
{
languageStr = args[i][key.Length..].ToLowerInvariant(); languageStr = args[i][key.Length..].ToLowerInvariant();
}
else if (args[i].StartsWith(key = "--dalamud-tspack-b64=")) else if (args[i].StartsWith(key = "--dalamud-tspack-b64="))
{
troubleshootingData = Encoding.UTF8.GetString(Convert.FromBase64String(args[i][key.Length..])); troubleshootingData = Encoding.UTF8.GetString(Convert.FromBase64String(args[i][key.Length..]));
}
else if (args[i].StartsWith(key = "--logname=")) else if (args[i].StartsWith(key = "--logname="))
{
logName = args[i][key.Length..]; logName = args[i][key.Length..];
}
else else
{
continue; continue;
}
args.RemoveAt(i); args.RemoveAt(i);
i--; i--;
@ -287,33 +308,49 @@ namespace Dalamud.Injector
workingDirectory ??= Directory.GetCurrentDirectory(); workingDirectory ??= Directory.GetCurrentDirectory();
configurationPath ??= Path.Combine(xivlauncherDir, "dalamudConfig.json"); configurationPath ??= Path.Combine(xivlauncherDir, "dalamudConfig.json");
pluginDirectory ??= Path.Combine(xivlauncherDir, "installedPlugins"); pluginDirectory ??= Path.Combine(xivlauncherDir, "installedPlugins");
defaultPluginDirectory ??= Path.Combine(xivlauncherDir, "devPlugins");
assetDirectory ??= Path.Combine(xivlauncherDir, "dalamudAssets", "dev"); assetDirectory ??= Path.Combine(xivlauncherDir, "dalamudAssets", "dev");
ClientLanguage clientLanguage; ClientLanguage clientLanguage;
if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "english").Length))] == key[0..len]) if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "english").Length))] == key[0..len])
{
clientLanguage = ClientLanguage.English; clientLanguage = ClientLanguage.English;
}
else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "japanese").Length))] == key[0..len]) else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "japanese").Length))] == key[0..len])
{
clientLanguage = ClientLanguage.Japanese; clientLanguage = ClientLanguage.Japanese;
}
else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "日本語").Length))] == key[0..len]) else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "日本語").Length))] == key[0..len])
{
clientLanguage = ClientLanguage.Japanese; clientLanguage = ClientLanguage.Japanese;
}
else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "german").Length))] == key[0..len]) else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "german").Length))] == key[0..len])
{
clientLanguage = ClientLanguage.German; clientLanguage = ClientLanguage.German;
}
else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "deutsch").Length))] == key[0..len]) else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "deutsch").Length))] == key[0..len])
{
clientLanguage = ClientLanguage.German; clientLanguage = ClientLanguage.German;
}
else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "french").Length))] == key[0..len]) else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "french").Length))] == key[0..len])
{
clientLanguage = ClientLanguage.French; clientLanguage = ClientLanguage.French;
}
else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "français").Length))] == key[0..len]) else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "français").Length))] == key[0..len])
{
clientLanguage = ClientLanguage.French; clientLanguage = ClientLanguage.French;
}
else if (int.TryParse(languageStr, out var languageInt) && Enum.IsDefined((ClientLanguage)languageInt)) else if (int.TryParse(languageStr, out var languageInt) && Enum.IsDefined((ClientLanguage)languageInt))
{
clientLanguage = (ClientLanguage)languageInt; clientLanguage = (ClientLanguage)languageInt;
}
else else
{
throw new CommandLineException($"\"{languageStr}\" is not a valid supported language."); throw new CommandLineException($"\"{languageStr}\" is not a valid supported language.");
}
startInfo.WorkingDirectory = workingDirectory; startInfo.WorkingDirectory = workingDirectory;
startInfo.ConfigurationPath = configurationPath; startInfo.ConfigurationPath = configurationPath;
startInfo.PluginDirectory = pluginDirectory; startInfo.PluginDirectory = pluginDirectory;
startInfo.DefaultPluginDirectory = defaultPluginDirectory;
startInfo.AssetDirectory = assetDirectory; startInfo.AssetDirectory = assetDirectory;
startInfo.Language = clientLanguage; startInfo.Language = clientLanguage;
startInfo.DelayInitializeMs = delayInitializeMs; startInfo.DelayInitializeMs = delayInitializeMs;
@ -350,10 +387,14 @@ namespace Dalamud.Injector
exeSpaces += " "; exeSpaces += " ";
if (particularCommand is null or "help") if (particularCommand is null or "help")
{
Console.WriteLine("{0} help [command]", exeName); Console.WriteLine("{0} help [command]", exeName);
}
if (particularCommand is null or "inject") if (particularCommand is null or "inject")
{
Console.WriteLine("{0} inject [-h/--help] [-a/--all] [--warn] [--fix-acl] [--se-debug-privilege] [pid1] [pid2] [pid3] ...", exeName); Console.WriteLine("{0} inject [-h/--help] [-a/--all] [--warn] [--fix-acl] [--se-debug-privilege] [pid1] [pid2] [pid3] ...", exeName);
}
if (particularCommand is null or "launch") if (particularCommand is null or "launch")
{ {
@ -367,7 +408,7 @@ namespace Dalamud.Injector
} }
Console.WriteLine("Specifying dalamud start info: [--dalamud-working-directory=path] [--dalamud-configuration-path=path]"); Console.WriteLine("Specifying dalamud start info: [--dalamud-working-directory=path] [--dalamud-configuration-path=path]");
Console.WriteLine(" [--dalamud-plugin-directory=path] [--dalamud-dev-plugin-directory=path]"); Console.WriteLine(" [--dalamud-plugin-directory=path]");
Console.WriteLine(" [--dalamud-asset-directory=path] [--dalamud-delay-initialize=0(ms)]"); Console.WriteLine(" [--dalamud-asset-directory=path] [--dalamud-delay-initialize=0(ms)]");
Console.WriteLine(" [--dalamud-client-language=0-3|j(apanese)|e(nglish)|d|g(erman)|f(rench)]"); Console.WriteLine(" [--dalamud-client-language=0-3|j(apanese)|e(nglish)|d|g(erman)|f(rench)]");
@ -431,7 +472,7 @@ namespace Dalamud.Injector
} }
else else
{ {
throw new CommandLineException($"\"{args[i]}\" is not a command line argument."); Log.Warning($"\"{args[i]}\" is not a valid command line argument, ignoring.");
} }
} }
@ -505,29 +546,53 @@ namespace Dalamud.Injector
} }
if (args[i] == "-h" || args[i] == "--help") if (args[i] == "-h" || args[i] == "--help")
{
showHelp = true; showHelp = true;
}
else if (args[i] == "-f" || args[i] == "--fake-arguments") else if (args[i] == "-f" || args[i] == "--fake-arguments")
{
useFakeArguments = true; useFakeArguments = true;
}
else if (args[i] == "--without-dalamud") else if (args[i] == "--without-dalamud")
{
withoutDalamud = true; withoutDalamud = true;
}
else if (args[i] == "--no-wait") else if (args[i] == "--no-wait")
{
waitForGameWindow = false; waitForGameWindow = false;
}
else if (args[i] == "--no-fix-acl" || args[i] == "--no-acl-fix") else if (args[i] == "--no-fix-acl" || args[i] == "--no-acl-fix")
{
noFixAcl = true; noFixAcl = true;
}
else if (args[i] == "-g") else if (args[i] == "-g")
{
gamePath = args[++i]; gamePath = args[++i];
}
else if (args[i].StartsWith("--game=")) else if (args[i].StartsWith("--game="))
{
gamePath = args[i].Split('=', 2)[1]; gamePath = args[i].Split('=', 2)[1];
}
else if (args[i] == "-m") else if (args[i] == "-m")
{
mode = args[++i]; mode = args[++i];
}
else if (args[i].StartsWith("--mode=")) else if (args[i].StartsWith("--mode="))
{
mode = args[i].Split('=', 2)[1]; mode = args[i].Split('=', 2)[1];
}
else if (args[i].StartsWith("--handle-owner=")) else if (args[i].StartsWith("--handle-owner="))
{
handleOwner = IntPtr.Parse(args[i].Split('=', 2)[1]); handleOwner = IntPtr.Parse(args[i].Split('=', 2)[1]);
}
else if (args[i] == "--") else if (args[i] == "--")
{
parsingGameArgument = true; parsingGameArgument = true;
}
else else
throw new CommandLineException($"\"{args[i]}\" is not a command line argument."); {
Log.Warning($"\"{args[i]}\" is not a valid command line argument, ignoring.");
}
} }
var checksumTable = "fX1pGtdS5CAP4_VL"; var checksumTable = "fX1pGtdS5CAP4_VL";
@ -536,11 +601,15 @@ namespace Dalamud.Injector
gameArguments = gameArguments.SelectMany(x => gameArguments = gameArguments.SelectMany(x =>
{ {
if (!x.StartsWith("//**sqex0003") || !x.EndsWith("**//")) if (!x.StartsWith("//**sqex0003") || !x.EndsWith("**//"))
{
return new List<string>() { x }; return new List<string>() { x };
}
var checksum = checksumTable.IndexOf(x[x.Length - 5]); var checksum = checksumTable.IndexOf(x[x.Length - 5]);
if (checksum == -1) if (checksum == -1)
{
return new List<string>() { x }; return new List<string>() { x };
}
var encData = Convert.FromBase64String(x.Substring(12, x.Length - 12 - 5).Replace('-', '+').Replace('_', '/').Replace('*', '=')); var encData = Convert.FromBase64String(x.Substring(12, x.Length - 12 - 5).Replace('-', '+').Replace('_', '/').Replace('*', '='));
var rawData = new byte[encData.Length]; var rawData = new byte[encData.Length];
@ -554,13 +623,25 @@ namespace Dalamud.Injector
encryptArguments = true; encryptArguments = true;
var args = argDelimiterRegex.Split(rawString).Skip(1).Select(y => string.Join('=', kvDelimiterRegex.Split(y, 2)).Replace(" ", " ")).ToList(); var args = argDelimiterRegex.Split(rawString).Skip(1).Select(y => string.Join('=', kvDelimiterRegex.Split(y, 2)).Replace(" ", " ")).ToList();
if (!args.Any()) if (!args.Any())
{
continue; continue;
}
if (!args.First().StartsWith("T=")) if (!args.First().StartsWith("T="))
{
continue; continue;
}
if (!uint.TryParse(args.First().Substring(2), out var tickCount)) if (!uint.TryParse(args.First().Substring(2), out var tickCount))
{
continue; continue;
}
if (tickCount >> 16 != i) if (tickCount >> 16 != i)
{
continue; continue;
}
return args.Skip(1); return args.Skip(1);
} }
@ -712,7 +793,9 @@ namespace Dalamud.Injector
if (handleOwner != IntPtr.Zero) if (handleOwner != IntPtr.Zero)
{ {
if (!DuplicateHandle(Process.GetCurrentProcess().Handle, process.Handle, handleOwner, out processHandleForOwner, 0, false, DuplicateOptions.SameAccess)) if (!DuplicateHandle(Process.GetCurrentProcess().Handle, process.Handle, handleOwner, out processHandleForOwner, 0, false, DuplicateOptions.SameAccess))
{
Log.Warning("Failed to call DuplicateHandle: Win32 error code {0}", Marshal.GetLastWin32Error()); Log.Warning("Failed to call DuplicateHandle: Win32 error code {0}", Marshal.GetLastWin32Error());
}
} }
Console.WriteLine($"{{\"pid\": {process.Id}, \"handle\": {processHandleForOwner}}}"); Console.WriteLine($"{{\"pid\": {process.Id}, \"handle\": {processHandleForOwner}}}");
@ -755,7 +838,9 @@ namespace Dalamud.Injector
helperProcess.BeginErrorReadLine(); helperProcess.BeginErrorReadLine();
helperProcess.WaitForExit(); helperProcess.WaitForExit();
if (helperProcess.ExitCode != 0) if (helperProcess.ExitCode != 0)
{
return -1; return -1;
}
var result = JsonSerializer.CreateDefault().Deserialize<Dictionary<string, int>>(new JsonTextReader(helperProcess.StandardOutput)); var result = JsonSerializer.CreateDefault().Deserialize<Dictionary<string, int>>(new JsonTextReader(helperProcess.StandardOutput));
var pid = result["pid"]; var pid = result["pid"];
@ -812,7 +897,9 @@ namespace Dalamud.Injector
var startInfoAddress = startInfoBuffer.Add(startInfoBytes); var startInfoAddress = startInfoBuffer.Add(startInfoBytes);
if (startInfoAddress == 0) if (startInfoAddress == 0)
{
throw new Exception("Unable to allocate start info JSON"); throw new Exception("Unable to allocate start info JSON");
}
injector.GetFunctionAddress(bootModule, "Initialize", out var initAddress); injector.GetFunctionAddress(bootModule, "Initialize", out var initAddress);
injector.CallRemoteFunction(initAddress, startInfoAddress, out var exitCode); injector.CallRemoteFunction(initAddress, startInfoAddress, out var exitCode);
@ -847,7 +934,10 @@ namespace Dalamud.Injector
/// </param> /// </param>
private static string EncodeParameterArgument(string argument, bool force = false) private static string EncodeParameterArgument(string argument, bool force = false)
{ {
if (argument == null) throw new ArgumentNullException(nameof(argument)); if (argument == null)
{
throw new ArgumentNullException(nameof(argument));
}
// Unless we're told otherwise, don't quote unless we actually // Unless we're told otherwise, don't quote unless we actually
// need to do so --- hopefully avoid problems if programs won't // need to do so --- hopefully avoid problems if programs won't

View file

@ -30,7 +30,6 @@ public record DalamudStartInfo : IServiceType
this.ConfigurationPath = other.ConfigurationPath; this.ConfigurationPath = other.ConfigurationPath;
this.LogName = other.LogName; this.LogName = other.LogName;
this.PluginDirectory = other.PluginDirectory; this.PluginDirectory = other.PluginDirectory;
this.DefaultPluginDirectory = other.DefaultPluginDirectory;
this.AssetDirectory = other.AssetDirectory; this.AssetDirectory = other.AssetDirectory;
this.Language = other.Language; this.Language = other.Language;
this.GameVersion = other.GameVersion; this.GameVersion = other.GameVersion;
@ -72,11 +71,6 @@ public record DalamudStartInfo : IServiceType
/// </summary> /// </summary>
public string? PluginDirectory { get; set; } public string? PluginDirectory { get; set; }
/// <summary>
/// Gets or sets the path to the directory for developer plugins.
/// </summary>
public string? DefaultPluginDirectory { get; set; }
/// <summary> /// <summary>
/// Gets or sets the path to core Dalamud assets. /// Gets or sets the path to core Dalamud assets.
/// </summary> /// </summary>

View file

@ -67,7 +67,7 @@ public class DevPluginsSettingsEntry : SettingsEntry
} }
} }
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsDevPluginLocationsHint", "Add additional dev plugin load locations.\nThese can be either the directory or DLL path.")); ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsDevPluginLocationsHint", "Add dev plugin load locations.\nThese can be either the directory or DLL path."));
ImGuiHelpers.ScaledDummy(5); ImGuiHelpers.ScaledDummy(5);

View file

@ -57,15 +57,6 @@ internal partial class PluginManager : IDisposable, IServiceType
/// </summary> /// </summary>
public const int PluginWaitBeforeFreeDefault = 1000; // upped from 500ms, seems more stable public const int PluginWaitBeforeFreeDefault = 1000; // upped from 500ms, seems more stable
private const string DevPluginsDisclaimerFilename = "DONT_USE_THIS_FOLDER.txt";
private const string DevPluginsDisclaimerText = @"Hey!
The devPlugins folder is deprecated and will be removed soon. Please don't use it anymore for plugin development.
Instead, open the Dalamud settings and add the path to your plugins build output folder as a dev plugin location.
Remove your devPlugin from this folder.
Thanks and have fun!";
private static readonly ModuleLog Log = new("PLUGINM"); private static readonly ModuleLog Log = new("PLUGINM");
private readonly object pluginListLock = new(); private readonly object pluginListLock = new();
@ -88,18 +79,10 @@ Thanks and have fun!";
private PluginManager() private PluginManager()
{ {
this.pluginDirectory = new DirectoryInfo(this.startInfo.PluginDirectory!); this.pluginDirectory = new DirectoryInfo(this.startInfo.PluginDirectory!);
this.devPluginDirectory = new DirectoryInfo(this.startInfo.DefaultPluginDirectory!);
if (!this.pluginDirectory.Exists) if (!this.pluginDirectory.Exists)
this.pluginDirectory.Create(); this.pluginDirectory.Create();
if (!this.devPluginDirectory.Exists)
this.devPluginDirectory.Create();
var disclaimerFileName = Path.Combine(this.devPluginDirectory.FullName, DevPluginsDisclaimerFilename);
if (!File.Exists(disclaimerFileName))
File.WriteAllText(disclaimerFileName, DevPluginsDisclaimerText);
this.SafeMode = EnvironmentConfiguration.DalamudNoPlugins || this.configuration.PluginSafeMode || this.startInfo.NoLoadPlugins; this.SafeMode = EnvironmentConfiguration.DalamudNoPlugins || this.configuration.PluginSafeMode || this.startInfo.NoLoadPlugins;
try try
@ -394,9 +377,6 @@ Thanks and have fun!";
if (!this.pluginDirectory.Exists) if (!this.pluginDirectory.Exists)
this.pluginDirectory.Create(); this.pluginDirectory.Create();
if (!this.devPluginDirectory.Exists)
this.devPluginDirectory.Create();
// Add installed plugins. These are expected to be in a specific format so we can look for exactly that. // Add installed plugins. These are expected to be in a specific format so we can look for exactly that.
foreach (var pluginDir in this.pluginDirectory.GetDirectories()) foreach (var pluginDir in this.pluginDirectory.GetDirectories())
{ {
@ -437,7 +417,7 @@ Thanks and have fun!";
} }
// devPlugins are more freeform. Look for any dll and hope to get lucky. // devPlugins are more freeform. Look for any dll and hope to get lucky.
var devDllFiles = this.devPluginDirectory.GetFiles("*.dll", SearchOption.AllDirectories).ToList(); var devDllFiles = new List<FileInfo>();
foreach (var setting in this.configuration.DevPluginLoadLocations) foreach (var setting in this.configuration.DevPluginLoadLocations)
{ {
@ -660,11 +640,8 @@ Thanks and have fun!";
/// </summary> /// </summary>
public void ScanDevPlugins() public void ScanDevPlugins()
{ {
if (!this.devPluginDirectory.Exists)
this.devPluginDirectory.Create();
// devPlugins are more freeform. Look for any dll and hope to get lucky. // devPlugins are more freeform. Look for any dll and hope to get lucky.
var devDllFiles = this.devPluginDirectory.GetFiles("*.dll", SearchOption.AllDirectories).ToList(); var devDllFiles = new List<FileInfo>();
foreach (var setting in this.configuration.DevPluginLoadLocations) foreach (var setting in this.configuration.DevPluginLoadLocations)
{ {

@ -1 +1 @@
Subproject commit 010e878febb631c8f3ff5ff90d656f318e35b1de Subproject commit 08d8bfc64d31ac1a2bfa5bc2cb927459254bb635