Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More performant o.plugins #487

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions src/RustCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using ConVar;

namespace Oxide.Game.Rust
{
Expand Down Expand Up @@ -297,37 +299,49 @@ private void LoadCommand(IPlayer player, string command, string[] args)
[HookMethod("PluginsCommand")]
private void PluginsCommand(IPlayer player)
{
Plugin[] loadedPlugins = pluginManager.GetPlugins().Where(pl => !pl.IsCorePlugin).ToArray();
HashSet<string> loadedPluginNames = new HashSet<string>(loadedPlugins.Select(pl => pl.Name));
Dictionary<string, string> unloadedPluginErrors = new Dictionary<string, string>();
foreach (PluginLoader loader in Interface.Oxide.GetPluginLoaders())
var plugins = pluginManager.GetPlugins();

var output = Facepunch.Pool.Get<StringBuilder>();

output.Append("Listing ") // Plugin count appended later on
.Append(" plugins:"); // TODO: Localization

int pluginCount = 0;

foreach (var plugin in plugins)
{
foreach (string name in loader.ScanDirectory(Interface.Oxide.PluginDirectory).Except(loadedPluginNames))
{
unloadedPluginErrors[name] = loader.PluginErrors.TryGetValue(name, out string msg) ? msg : "Unloaded"; // TODO: Localization
}
if (plugin.Filename == null || plugin.IsCorePlugin) continue;

output.AppendLine().Append(" ").Append(pluginCount++.ToString("00")).Append(" \"").Append(plugin.Title)
.Append("\"").Append(" (").Append(plugin.Version).Append(") by ").Append(plugin.Author).Append(" (")
.Append(plugin.TotalHookTime.ToString("0.00")).Append("s) - ").Append("(")
.Append(FormatBytes(plugin.TotalHookMemory)).Append(" - ").Append(plugin.Filename.Basename());
}

int totalPluginCount = loadedPlugins.Length + unloadedPluginErrors.Count;
if (totalPluginCount < 1)
if (pluginCount == 0)
{
player.Reply(lang.GetMessage("NoPluginsFound", this, player.Id));
Facepunch.Pool.FreeUnmanaged(ref output);
return;
}

string output = $"Listing {loadedPlugins.Length + unloadedPluginErrors.Count} plugins:"; // TODO: Localization
int number = 1;
foreach (Plugin plugin in loadedPlugins.Where(p => p.Filename != null))
foreach (var loader in Interface.Oxide.GetPluginLoaders())
{
output += $"\n {number++:00} \"{plugin.Title}\" ({plugin.Version}) by {plugin.Author} ({plugin.TotalHookTime:0.00}s / {FormatBytes(plugin.TotalHookMemory)}) - {plugin.Filename.Basename()}";
}
var unloadedNames = loader.ScanDirectory(Interface.Oxide.PluginDirectory)
.Except(plugins.Select(pl => pl.Name));

foreach (string pluginName in unloadedPluginErrors.Keys)
{
output += $"\n {number++:00} {pluginName} - {unloadedPluginErrors[pluginName]}";
foreach (var name in unloadedNames)
{
output.AppendLine().Append(" ").Append(pluginCount++.ToString("00")).Append(" ").Append(name)
.Append(" - ").Append(loader.PluginErrors.TryGetValue(name, out var msg) ? msg : "Unloaded");
}
}

player.Reply(output);
output.Insert(8, pluginCount - 1);

player.Reply(output.ToString());

Facepunch.Pool.FreeUnmanaged(ref output);
}

private static string FormatBytes(long bytes)
Expand Down