Skip to content

Commit

Permalink
update mod verify
Browse files Browse the repository at this point in the history
  • Loading branch information
AnakinRaW committed Jul 24, 2024
1 parent a677fb9 commit 52f68c0
Show file tree
Hide file tree
Showing 65 changed files with 955 additions and 372 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
# Change into the artifacts directory to avoid including the directory itself in the zip archive
working-directory: ./releases/net8.0
run: zip -r ../ModVerify-Net8.zip .
- name: Rename .NET Framework executable
run: mv ./releases/net48/ModVerify.CliApp.exe ./releases/net48/ModVerify.exe
- uses: dotnet/[email protected]
id: nbgv
- name: Create GitHub release
Expand All @@ -65,5 +67,5 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
generate_release_notes: true
files: |
./releases/net48/ModVerify.CliApp.exe
./releases/net48/ModVerify.exe
./releases/ModVerify-Net8.zip
78 changes: 77 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
# ModVerify
# ModVerify: A Mod Verification Tool

ModVerify is a command-line tool designed to verify mods for the game Star Wars: Empire at War and its expansion Forces of Corruption.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Options](#options)
- [Available Checks](#available-checks)

## Installation

Download the latest release from the [releases page](https://github.com/AlamoEngine-Tools/ModVerify/releases). There are two versions of the application available.

1. `ModVerify.exe` is the default version. Use this if you simply want to verify your mods. This version only works on Windows.
2. `ModVerify-NetX.zip` is the cross-platform app. It works on Windows and Linux and is most likely the version you want to use to include it in some CI/CD scenarios.

You can place the files anywhere on your system, eg. your Desktop. There is no need to place it inside a mod's directory.

*Note: Both versions have the exact same feature set. They just target a different .NET runtime. Linux and CI/CD support is not fully tested yet. Current priority is on the Windows-only version.*

## Usage

Simply run the executable file `ModVerify.exe`.

When given no specific argument through the command line, the app will ask you which game or mod you want to verify. When the tool is done, it will write the verification results into new files next to the executable.

A `.JSON` file lists all found issues. Into seperate `.txt` files the same errors get grouped by a category of the finding. The text files may be easier to read, while the json file is more useful for 3rd party tool processing.

## Options

You can also run the tool with command line arguments to adjust the tool to your needs.

To see all available options, open the command line and type:

```bash
ModVerify.exe --help
```

Here is a list of the most relevant options:

### `--path`
Specifies a path that shall be analyzed. **There will be no user input required when using this option**

### `--output`
Specified the output path where analysis result shall be written to.

### `--baseline`
Specifies a baseline file that shall be used to filter out known errors. You can download the [FoC baseline](focBaseline.json) which includes all errors produced by the vanilla game.

### `--createBaseline`
If you want to create your own baseline, add this option with a file path such as `myModBaseline.json`.

### Example
This is an example run configuration that analyzes a specific mod, uses a the FoC basline and writes the output into a dedicated directory:

```bash
ModVerify.exe --path "C:\My Games\FoC\Mods\MyMod" --output "C:\My Games\FoC\Mods\MyMod\verifyResults" --baseline focBaseline.json
```


## Available Checks

The following verifiers are currently implemented:

### For SFX Events:
- Checks whether coded preset exists
- Checks the referenced samples for validity (bit rate, sample size, channels, etc.)
- Duplicates


### For GameObjects
- Checks the referenced models for validity (textures, particles and shaders)
- Duplicates


5 changes: 5 additions & 0 deletions src/ModVerify.CliApp/ModVerify.CliApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nullable" Version="1.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="AlamoEngineTools.PG.StarWarsGame.Infrastructure.Clients" Version="3.1.5" />
<PackageReference Include="AlamoEngineTools.SteamAbstraction" Version="3.1.5" />
Expand All @@ -36,6 +40,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
<PackageReference Include="Required" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
78 changes: 66 additions & 12 deletions src/ModVerify.CliApp/ModVerifyApp.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,90 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Threading.Tasks;
using AET.ModVerify;
using AET.ModVerify.Reporting;
using AET.ModVerify.Settings;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PG.StarWarsGame.Engine;
using PG.StarWarsGame.Infrastructure.Mods;
using PG.StarWarsGame.Infrastructure.Services.Dependencies;

namespace ModVerify.CliApp;

internal class ModVerifyApp(GameVerifySettings settings, IServiceProvider services)
internal class ModVerifyApp(ModVerifyAppSettings settings, IServiceProvider services)
{
private readonly ILogger? _logger = services.GetService<ILoggerFactory>()?.CreateLogger(typeof(ModVerifyApp));
private readonly IFileSystem _fileSystem = services.GetRequiredService<IFileSystem>();

private IReadOnlyCollection<VerificationError> Errors { get; set; } = Array.Empty<VerificationError>();

public async Task RunVerification(VerifyGameSetupData gameSetupData)
public async Task<int> RunApplication()
{
var verifyPipeline = BuildPipeline(gameSetupData);
_logger?.LogInformation($"Verifying {gameSetupData.VerifyObject.Name}...");
await verifyPipeline.RunAsync();
_logger?.LogInformation("Finished Verifying");
var returnCode = 0;

var gameSetupData = CreateGameSetupData(settings, services);
var verifyPipeline = new ModVerifyPipeline(gameSetupData.EngineType, gameSetupData.GameLocations, settings.GameVerifySettigns, services);

try
{
_logger?.LogInformation($"Verifying {gameSetupData.VerifyObject.Name}...");
await verifyPipeline.RunAsync().ConfigureAwait(false);
_logger?.LogInformation("Finished Verifying");
}
catch (GameVerificationException e)
{
returnCode = e.HResult;
}

if (settings.CreateNewBaseline)
await WriteBaseline(verifyPipeline.Errors, settings.NewBaselinePath).ConfigureAwait(false);

return returnCode;
}

private VerifyGamePipeline BuildPipeline(VerifyGameSetupData setupData)
private async Task WriteBaseline(IEnumerable<VerificationError> errors, string baselineFile)
{
return new ModVerifyPipeline(setupData.EngineType, setupData.GameLocations, settings, services);
var fullPath = _fileSystem.Path.GetFullPath(baselineFile);
#if NET
await
#endif
using var fs = _fileSystem.FileStream.New(fullPath, FileMode.Create, FileAccess.Write, FileShare.None);
var baseline = new VerificationBaseline(errors);
await baseline.ToJsonAsync(fs);
}

public async Task WriteBaseline(string baselineFile)
private static VerifyGameSetupData CreateGameSetupData(ModVerifyAppSettings options, IServiceProvider services)
{
var selectionResult = new ModOrGameSelector(services).SelectModOrGame(options.PathToVerify);

IList<string> mods = Array.Empty<string>();
if (selectionResult.ModOrGame is IMod mod)
{
var traverser = services.GetRequiredService<IModDependencyTraverser>();
mods = traverser.Traverse(mod)
.Select(x => x.Mod)
.OfType<IPhysicalMod>().Select(x => x.Directory.FullName)
.ToList();
}

var fallbackPaths = new List<string>();
if (selectionResult.FallbackGame is not null)
fallbackPaths.Add(selectionResult.FallbackGame.Directory.FullName);

if (!string.IsNullOrEmpty(options.AdditionalFallbackPath))
fallbackPaths.Add(options.AdditionalFallbackPath);

var gameLocations = new GameLocations(
mods,
selectionResult.ModOrGame.Game.Directory.FullName,
fallbackPaths);

return new VerifyGameSetupData
{
EngineType = GameEngineType.Foc,
GameLocations = gameLocations,
VerifyObject = selectionResult.ModOrGame,
};
}
}
21 changes: 21 additions & 0 deletions src/ModVerify.CliApp/ModVerifyAppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using AET.ModVerify.Settings;
using System.Diagnostics.CodeAnalysis;

namespace ModVerify.CliApp;

public record ModVerifyAppSettings
{
public GameVerifySettings GameVerifySettigns { get; init; }

public string? PathToVerify { get; init; } = null;

public string Output { get; init; } = Environment.CurrentDirectory;

public string? AdditionalFallbackPath { get; init; } = null;

[MemberNotNullWhen(true, nameof(NewBaselinePath))]
public bool CreateNewBaseline => !string.IsNullOrEmpty(NewBaselinePath);

public string? NewBaselinePath { get; init; }
}
19 changes: 16 additions & 3 deletions src/ModVerify.CliApp/ModVerifyOptions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using CommandLine;
using AET.ModVerify.Reporting;
using CommandLine;

namespace ModVerify.CliApp;

internal class ModVerifyOptions
{
[Option('p', "path", Required = false,
HelpText = "The path to a mod directory to verify. If not path is specified, " +
"the app search for mods and asks the user to select a game or mod.")]
"the app searches for game installations and asks the user to select a game or mod.")]
public string? Path { get; set; }

[Option('o', "output", Required = false, HelpText = "directory where result files shall be stored to.")]
public string? Output { get; set; }

[Option('v', "verbose", Required = false, HelpText = "Set output to verbose messages.")]
public bool Verbose { get; set; }

Expand All @@ -18,7 +22,16 @@ internal class ModVerifyOptions
[Option("suppressions", Required = false, HelpText = "Path to a JSON suppression file.")]
public string? Suppressions { get; set; }

[Option("createBaseLine", Required = false,
[Option("minFailSeverity", Required = false, Default = null,
HelpText = "When set, the application return with an error, if any finding has at least the specified severity value.")]
public VerificationSeverity? MinimumFailureSeverity { get; set; }


[Option("failFast", Required = false, Default = false,
HelpText = "When set, the application will abort on the first failure. The option also recognized the 'MinimumFailureSeverity' setting.")]
public bool FailFast { get; set; }

[Option("createBaseline", Required = false,
HelpText = "When a path is specified, the tools creates a new baseline file. " +
"An existing file will be overwritten. " +
"Previous baselines are merged into the new baseline.")]
Expand Down
Loading

0 comments on commit 52f68c0

Please sign in to comment.