Skip to content

Commit

Permalink
implement some audio stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AnakinRaW committed May 27, 2024
1 parent 937a8cd commit 60a4ed1
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 85 deletions.
5 changes: 5 additions & 0 deletions src/ModVerify.CliApp/GameFinderResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using PG.StarWarsGame.Infrastructure.Games;

namespace ModVerify.CliApp;

public readonly record struct GameFinderResult(IGame Game, IGame FallbackGame);
6 changes: 2 additions & 4 deletions src/ModVerify.CliApp/ModFinderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using PG.StarWarsGame.Infrastructure.Services.Dependencies;
using PG.StarWarsGame.Infrastructure.Services.Detection;

namespace RepublicAtWar.DevLauncher.Services;
namespace ModVerify.CliApp;

internal class ModFinderService
{
Expand Down Expand Up @@ -90,6 +90,4 @@ public GameFinderResult FindAndAddModInCurrentDirectory()

return new GameFinderResult(foc, eaw);
}
}

public readonly record struct GameFinderResult(IGame Game, IGame FallbackGame);
}
6 changes: 5 additions & 1 deletion src/ModVerify.CliApp/ModVerify.CliApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net48</TargetFrameworks>
<OutputType>Exe</OutputType>
<Title>AET.ModVerify.CommandLine</Title>
<Product>AET.ModVerify</Product>
Expand All @@ -23,6 +23,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions src/ModVerify.CliApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Extensions.Logging;
using PG.Commons.Extensibility;
using PG.StarWarsGame.Engine;
using PG.StarWarsGame.Engine.FileSystem;
using PG.StarWarsGame.Files.ALO;
using PG.StarWarsGame.Files.DAT.Services.Builder;
using PG.StarWarsGame.Files.MEG.Data.Archives;
Expand All @@ -22,7 +23,6 @@
using PG.StarWarsGame.Infrastructure.Games;
using PG.StarWarsGame.Infrastructure.Mods;
using PG.StarWarsGame.Infrastructure.Services.Dependencies;
using RepublicAtWar.DevLauncher.Services;

namespace ModVerify.CliApp;

Expand Down Expand Up @@ -92,8 +92,12 @@ private static VerifyFocPipeline BuildPipeline(IPlayableObject playableObject, I
.ToList();
}

return new VerifyFocPipeline(mods, playableObject.Game.Directory.FullName, fallbackGame.Directory.FullName,
_services);
var gameLocations = new GameLocations(
mods,
playableObject.Game.Directory.FullName,
fallbackGame.Directory.FullName);

return new VerifyFocPipeline(gameLocations, _services);
}

private static IServiceProvider CreateAppServices()
Expand Down
4 changes: 2 additions & 2 deletions src/ModVerify/VerifyPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

namespace AET.ModVerify;

public class VerifyFocPipeline(IList<string> modDirectories, string gameDirectory, string fallbackGameDirectory, IServiceProvider serviceProvider)
public class VerifyFocPipeline(GameLocations gameLocations, IServiceProvider serviceProvider)
: ParallelPipeline(serviceProvider, 4, false)
{
private IList<GameVerificationStep> _verificationSteps = null!;

protected override Task<IList<IStep>> BuildSteps()
{
var repository = new FocGameRepository(modDirectories, gameDirectory, fallbackGameDirectory, ServiceProvider);
var repository = new FocGameRepository(gameLocations, ServiceProvider);

var buildIndexStep = new CreateGameDatabaseStep(repository, ServiceProvider);
_verificationSteps = new List<GameVerificationStep>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AnakinRaW.CommonUtilities;

namespace PG.StarWarsGame.Engine.FileSystem;

public sealed class GameLocations
{
public IReadOnlyList<string> ModPaths { get; }

public string GamePath { get; }

public IReadOnlyList<string> FallbackPaths { get; }

public GameLocations(string gamePath, string fallbackGamePath) : this(Array.Empty<string>(), gamePath, fallbackGamePath)
{
}

public GameLocations(string modPath, string gamePath, string fallbackGamePath) : this([modPath], gamePath, fallbackGamePath)
{
ThrowHelper.ThrowIfNullOrEmpty(modPath);
}

public GameLocations(IList<string> modPaths, string gamePath, string fallbackGamePath) : this(modPaths,
gamePath, [fallbackGamePath])
{
ThrowHelper.ThrowIfNullOrEmpty(fallbackGamePath);
}

public GameLocations(IList<string> modPaths, string gamePath, IList<string> fallbackPaths)
{
if (modPaths == null)
throw new ArgumentNullException(nameof(modPaths));
if (fallbackPaths == null)
throw new ArgumentNullException(nameof(fallbackPaths));

ModPaths = modPaths.ToList();
GamePath = gamePath;
FallbackPaths = fallbackPaths.ToList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,17 @@ public class FocGameRepository : IGameRepository
private readonly string _gameDirectory;

private readonly IList<string> _modPaths = new List<string>();

private readonly string _fallbackPath;
private readonly IList<string> _fallbackPaths = new List<string>();

private readonly IVirtualMegArchive? _masterMegArchive;

public IRepository EffectsRepository { get; }

public FocGameRepository(string mod, string baseGame, string fallbackGame, IServiceProvider serviceProvider) :
this(baseGame, fallbackGame, serviceProvider)
{
if (mod == null)
throw new ArgumentNullException(nameof(mod));

_modPaths.Add(_fileSystem.Path.GetFullPath(mod));
}

public FocGameRepository(IList<string> mods, string baseGame, string fallbackGame, IServiceProvider serviceProvider) :
this(baseGame, fallbackGame, serviceProvider)

public FocGameRepository(GameLocations gameLocations, IServiceProvider serviceProvider)
{
if (mods == null)
throw new ArgumentNullException(nameof(mods));
if (gameLocations == null)
throw new ArgumentNullException(nameof(gameLocations));

foreach (var mod in mods)
_modPaths.Add(_fileSystem.Path.GetFullPath(mod));
}

public FocGameRepository(string baseGame, string fallbackGame, IServiceProvider serviceProvider)
{
if (fallbackGame == null)
throw new ArgumentNullException(nameof(fallbackGame));
if (fallbackGame == null)
throw new ArgumentNullException(nameof(fallbackGame));
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
_megPathNormalizer = serviceProvider.GetRequiredService<PetroglyphDataEntryPathNormalizer>();
_crc32HashingService = serviceProvider.GetRequiredService<ICrc32HashingService>();
Expand All @@ -71,8 +50,28 @@ public FocGameRepository(string baseGame, string fallbackGame, IServiceProvider

_fileSystem = serviceProvider.GetRequiredService<IFileSystem>();

_gameDirectory = _fileSystem.Path.GetFullPath(baseGame);
_fallbackPath = _fileSystem.Path.GetFullPath(fallbackGame);
foreach (var mod in gameLocations.ModPaths)
{
if (string.IsNullOrEmpty(mod))
{
_logger?.LogTrace("Skipping null or empty mod path.");
continue;
}
_modPaths.Add(_fileSystem.Path.GetFullPath(mod));
}

_gameDirectory = _fileSystem.Path.GetFullPath(gameLocations.GamePath);


foreach (var fallbackPath in gameLocations.FallbackPaths)
{
if (string.IsNullOrEmpty(fallbackPath))
{
_logger?.LogTrace("Skipping null or empty fallback path.");
continue;
}
_fallbackPaths.Add(_fileSystem.Path.GetFullPath(fallbackPath));
}

_masterMegArchive = CreateMasterMegArchive();

Expand All @@ -85,24 +84,29 @@ private IVirtualMegArchive CreateMasterMegArchive()

var megsToConsider = new List<IMegFile>();

var eawMegs = LoadMegArchivesFromXml(_fallbackPath);
var eawPatch = LoadMegArchive(_fileSystem.Path.Combine(_fallbackPath, "Data\\Patch.meg"));
var eawPatch2 = LoadMegArchive(_fileSystem.Path.Combine(_fallbackPath, "Data\\Patch2.meg"));
var eaw64Patch = LoadMegArchive(_fileSystem.Path.Combine(_fallbackPath, "Data\\64Patch.meg"));
// We assume that the first fallback path (if present at all) is always Empire at War.
var firstFallback = _fallbackPaths.FirstOrDefault();
if (firstFallback is not null)
{
var eawMegs = LoadMegArchivesFromXml(firstFallback);
var eawPatch = LoadMegArchive(_fileSystem.Path.Combine(firstFallback, "Data\\Patch.meg"));
var eawPatch2 = LoadMegArchive(_fileSystem.Path.Combine(firstFallback, "Data\\Patch2.meg"));
var eaw64Patch = LoadMegArchive(_fileSystem.Path.Combine(firstFallback, "Data\\64Patch.meg"));

megsToConsider.AddRange(eawMegs);
if (eawPatch is not null)
megsToConsider.Add(eawPatch);
if (eawPatch2 is not null)
megsToConsider.Add(eawPatch2);
if (eaw64Patch is not null)
megsToConsider.Add(eaw64Patch);
}

var focOrModMegs = LoadMegArchivesFromXml(".");
var focPatch = LoadMegArchive("Data\\Patch.meg");
var focPatch2 = LoadMegArchive("Data\\Patch2.meg");
var foc64Patch = LoadMegArchive("Data\\64Patch.meg");

megsToConsider.AddRange(eawMegs);
if (eawPatch is not null)
megsToConsider.Add(eawPatch);
if (eawPatch2 is not null)
megsToConsider.Add(eawPatch2);
if (eaw64Patch is not null)
megsToConsider.Add(eaw64Patch);

megsToConsider.AddRange(focOrModMegs);
if (focPatch is not null)
megsToConsider.Add(focPatch);
Expand Down Expand Up @@ -132,7 +136,6 @@ private IList<IMegFile> LoadMegArchivesFromXml(string lookupPath)
var megaFilesXml = parser.ParseFile(xmlStream);



var megs = new List<IMegFile>(megaFilesXml.Files.Count);

foreach (var file in megaFilesXml.Files.Select(x => x.Trim()))
Expand All @@ -151,7 +154,7 @@ private IList<IMegFile> LoadMegArchivesFromXml(string lookupPath)
using var megFileStream = TryOpenFile(megPath);
if (megFileStream is not FileSystemStream fileSystemStream)
{
_logger?.LogTrace($"Unable to find MEG data at '{megPath}'");
_logger?.LogWarning($"Unable to find MEG data at '{megPath}'");
return null;
}

Expand Down Expand Up @@ -215,9 +218,13 @@ public bool FileExists(string filePath, bool megFileOnly = false)

if (!megFileOnly)
{
var fallbackPath = _fileSystem.Path.Combine(_fallbackPath, filePath);
if (_fileSystem.File.Exists(fallbackPath))
return true;

foreach (var fallbackPath in _fallbackPaths)
{
var fallbackFilePath = _fileSystem.Path.Combine(fallbackPath, filePath);
if (_fileSystem.File.Exists(fallbackFilePath))
return true;
}
}

return false;
Expand Down Expand Up @@ -256,11 +263,13 @@ public bool FileExists(string filePath, bool megFileOnly = false)

if (!megFileOnly)
{
var fallbackPath = _fileSystem.Path.Combine(_fallbackPath, filePath);
if (_fileSystem.File.Exists(fallbackPath))
return OpenFileRead(fallbackPath);
foreach (var fallbackPath in _fallbackPaths)
{
var fallbackFilePath = _fileSystem.Path.Combine(fallbackPath, filePath);
if (_fileSystem.File.Exists(fallbackFilePath))
return OpenFileRead(fallbackFilePath);
}
}

return null;
}

Expand All @@ -281,8 +290,12 @@ private bool AllowOpenFile(string filePath)

if (_fileSystem.Path.IsChildOf(_gameDirectory, filePath))
return true;
if (_fileSystem.Path.IsChildOf(_fallbackPath, filePath))
return true;

foreach (var fallbackPath in _fallbackPaths)
{
if (_fileSystem.Path.IsChildOf(fallbackPath, filePath))
return true;
}

return false;
}
Expand Down
Loading

0 comments on commit 60a4ed1

Please sign in to comment.