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

Add template command #482

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
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
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