Skip to content

Commit

Permalink
Merge pull request #482 from sailro/template
Browse files Browse the repository at this point in the history
Add template command
  • Loading branch information
sailro authored Apr 13, 2024
2 parents 9801029 + eaba4c8 commit 8446497
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
46 changes: 44 additions & 2 deletions Features/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,55 @@ private void RegisterCommands()
CreateCommand("load", () => LoadSettings());
CreateCommand("save", SaveSettings);

CreateCommand("template", $"(?<{ValueGroup}>.+)", FindTemplates);

// Load default configuration
LoadSettings(false);
SetupWindowCoordinates();

Registered = true;
}

private static IEnumerable<ItemTemplate> FindTemplates(string searchShortNameOrTemplateId)
{
if (!Singleton<ItemFactory>.Instantiated)
return [];

var templates = Singleton<ItemFactory>
.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<ItemFactory>.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;
Expand Down Expand Up @@ -483,7 +525,7 @@ private static void CreateCommand(string name, Action action)
private void CreateCommand(string cmdName, string pattern, Action<Match> action)
{
#if DEBUG
AddConsoleLog($"Registering {cmdName} command...");
AddConsoleLog($"Registering {cmdName} command...");
#endif
ConsoleScreen.Processor.RegisterCommand(cmdName, (string args) =>
{
Expand Down Expand Up @@ -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<string, List<Item>> itemsPerName)
Expand Down
3 changes: 3 additions & 0 deletions NLog.EFT.Trainer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>$(EFTManagedPath)\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="ItemTemplate.Types">
<HintPath>$(EFTManagedPath)\ItemTemplate.Types.dll</HintPath>
</Reference>
<Reference Include="0Harmony">
<HintPath>Installer\Resources\0Harmony.dll</HintPath>
</Reference>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]` `<color>` | | Ex: track `roler` `red` |
Expand Down

0 comments on commit 8446497

Please sign in to comment.