diff --git a/Features/Commands.cs b/Features/Commands.cs index 17892187..0d7682ff 100644 --- a/Features/Commands.cs +++ b/Features/Commands.cs @@ -447,6 +447,8 @@ private void RegisterCommands() CreateCommand("load", () => LoadSettings()); CreateCommand("save", SaveSettings); + CreateCommand("template", $"(?<{ValueGroup}>.+)", FindTemplates); + // Load default configuration LoadSettings(false); SetupWindowCoordinates(); @@ -454,6 +456,46 @@ private void RegisterCommands() Registered = true; } + private static IEnumerable FindTemplates(string searchShortNameOrTemplateId) + { + if (!Singleton.Instantiated) + return []; + + var templates = Singleton + .Instance + .ItemTemplates; + + // Match by TemplateId + if (templates.TryGetValue(searchShortNameOrTemplateId, out var template)) + return [template]; + + // Match by short name(s) + return templates + .Values + .Where(t => t.ShortNameLocalizationKey.Localized().IndexOf(searchShortNameOrTemplateId, StringComparison.OrdinalIgnoreCase) >= 0 + || t.NameLocalizationKey.Localized().IndexOf(searchShortNameOrTemplateId, StringComparison.OrdinalIgnoreCase) >= 0); + } + + private void FindTemplates(Match match) + { + var matchGroup = match.Groups[ValueGroup]; + if (matchGroup is not {Success: true}) + return; + + if (!Singleton.Instantiated) + return; + + var search = matchGroup.Value; + + var templates = FindTemplates(search).ToArray(); + + foreach (var template in templates) + AddConsoleLog($"{template._id}: {template.ShortNameLocalizationKey.Localized().Green()} [{template.NameLocalizationKey.Localized()}]"); + + AddConsoleLog("------"); + AddConsoleLog($"found {templates.Length.ToString().Cyan()} template(s)"); + } + private void SetupWindowCoordinates() { bool needfix = false; @@ -483,7 +525,7 @@ private static void CreateCommand(string name, Action action) private void CreateCommand(string cmdName, string pattern, Action action) { #if DEBUG - AddConsoleLog($"Registering {cmdName} command..."); + AddConsoleLog($"Registering {cmdName} command..."); #endif ConsoleScreen.Processor.RegisterCommand(cmdName, (string args) => { @@ -618,7 +660,7 @@ private void ListLootItems(Match match, LootItems feature, ELootRarity? rarityFi } AddConsoleLog("------"); - AddConsoleLog($"found {count.ToString().Cyan()} items"); + AddConsoleLog($"found {count.ToString().Cyan()} item(s)"); } private static void FindItemsInContainers(GameWorld world, Dictionary> itemsPerName) diff --git a/NLog.EFT.Trainer.csproj b/NLog.EFT.Trainer.csproj index 6060693d..c6b7ceb3 100644 --- a/NLog.EFT.Trainer.csproj +++ b/NLog.EFT.Trainer.csproj @@ -94,6 +94,9 @@ $(EFTManagedPath)\UnityEngine.TextRenderingModule.dll + + $(EFTManagedPath)\ItemTemplate.Types.dll + Installer\Resources\0Harmony.dll diff --git a/README.md b/README.md index f59ca880..0396ecc0 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ This trainer hooks into the command system, so you can easily setup features usi | stamina | `on` or `off` | `off` | Enable/Disable unlimited stamina | | stash | `on` or `off` | `off` | Show/Hide stashes | | status | | | Show status of all features | +| template | `name` | | Search for templates by short/name | | thermal | `on` or `off` | `off` | Enable/Disable thermal vision | | track | `[name]` or `*` | | Track all items matching `name` | | track | `[name]` `` | | Ex: track `roler` `red` |