|
|
@ -11,7 +11,7 @@ using TMPro;
|
|
|
|
using Console = FancyPantsConsole.Console;
|
|
|
|
using Console = FancyPantsConsole.Console;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ConsoleImprovements.Client {
|
|
|
|
namespace ConsoleImprovements.Client {
|
|
|
|
public class CommandHistoryPatch {
|
|
|
|
public class CommandInputPatch {
|
|
|
|
const int HistLength = 1000;
|
|
|
|
const int HistLength = 1000;
|
|
|
|
|
|
|
|
|
|
|
|
private static ILogicLogger _logger = null!;
|
|
|
|
private static ILogicLogger _logger = null!;
|
|
|
@ -24,6 +24,7 @@ namespace ConsoleImprovements.Client {
|
|
|
|
public static bool Prepare(ILogicLogger logger) {
|
|
|
|
public static bool Prepare(ILogicLogger logger) {
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Get access to the rich text string inside the MessageData class
|
|
|
|
// Get access to the rich text string inside the MessageData class
|
|
|
|
_commandInputFieldField = Fields.getPrivate(typeof(Console), "CommandInputField");
|
|
|
|
_commandInputFieldField = Fields.getPrivate(typeof(Console), "CommandInputField");
|
|
|
|
|
|
|
|
|
|
|
@ -33,7 +34,8 @@ namespace ConsoleImprovements.Client {
|
|
|
|
// CommandRegistry.CommandCollectionByName
|
|
|
|
// CommandRegistry.CommandCollectionByName
|
|
|
|
var commandCollection = Properties.get(registry, "AllRegisteredCommands").GetValue(registry);
|
|
|
|
var commandCollection = Properties.get(registry, "AllRegisteredCommands").GetValue(registry);
|
|
|
|
// IEnumerable<Command>
|
|
|
|
// IEnumerable<Command>
|
|
|
|
var commands = (IEnumerable) Methods.getPublic(commandCollection, "EnumerateAllCommands").Invoke(commandCollection, null)!;
|
|
|
|
var commands = (IEnumerable) Methods.getPublic(commandCollection, "EnumerateAllCommands")
|
|
|
|
|
|
|
|
.Invoke(commandCollection, null)!;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var command in commands) {
|
|
|
|
foreach (var command in commands) {
|
|
|
|
var nameProperty = Properties.getPublic(command, "Name");
|
|
|
|
var nameProperty = Properties.getPublic(command, "Name");
|
|
|
@ -41,6 +43,10 @@ namespace ConsoleImprovements.Client {
|
|
|
|
if ((bool) hiddenProperty.GetValue(command)!) continue;
|
|
|
|
if ((bool) hiddenProperty.GetValue(command)!) continue;
|
|
|
|
_commandRegistry.AddEntry((string) nameProperty.GetValue(command)!);
|
|
|
|
_commandRegistry.AddEntry((string) nameProperty.GetValue(command)!);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (AccessHelperException e) {
|
|
|
|
|
|
|
|
_logger.Error($"Error occured while preparing command history patch: {e}");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -52,13 +58,13 @@ namespace ConsoleImprovements.Client {
|
|
|
|
|
|
|
|
|
|
|
|
private static void PatchUpdate(Harmony harmony) {
|
|
|
|
private static void PatchUpdate(Harmony harmony) {
|
|
|
|
var methodTarget = Methods.getPrivate(typeof(Console), "Update");
|
|
|
|
var methodTarget = Methods.getPrivate(typeof(Console), "Update");
|
|
|
|
var methodHook = Methods.get(typeof(CommandHistoryPatch), nameof(HookUpdate));
|
|
|
|
var methodHook = Methods.get(typeof(CommandInputPatch), nameof(HookUpdate));
|
|
|
|
harmony.Patch(methodTarget, prefix: new HarmonyMethod(methodHook));
|
|
|
|
harmony.Patch(methodTarget, prefix: new HarmonyMethod(methodHook));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void PatchCommandSubmit(Harmony harmony) {
|
|
|
|
private static void PatchCommandSubmit(Harmony harmony) {
|
|
|
|
var methodTarget = Methods.getPrivate(typeof(Console), "OnCommandInputFieldSubmit");
|
|
|
|
var methodTarget = Methods.getPrivate(typeof(Console), "OnCommandInputFieldSubmit");
|
|
|
|
var methodHook = Methods.get(typeof(CommandHistoryPatch), nameof(HookCommandSubmit));
|
|
|
|
var methodHook = Methods.get(typeof(CommandInputPatch), nameof(HookCommandSubmit));
|
|
|
|
harmony.Patch(methodTarget, prefix: new HarmonyMethod(methodHook));
|
|
|
|
harmony.Patch(methodTarget, prefix: new HarmonyMethod(methodHook));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|