LogicAndTrick / sledge-formats

C# parsers and formats for Half-Life 1 and related engines.
MIT License
71 stars 10 forks source link

Add `IFileResolver` implementation for `IPackage` instances #33

Open LogicAndTrick opened 1 week ago

LogicAndTrick commented 1 week ago

To fully emulate a game environment for some games, IPackage instances need to be added as sources to a CompositeFileResolver. Add a PackageFileResolver to the Sledge.Formats.Packages library that will accept an IPackage as its source.

Also consider cases where a package (or just a different folder) might need to be added to CompositeFileResolver with a different root - not sure if any games actually require that, but would be good for extensibility. I think this could be solved by having something like a VirtualSubdirectoryFileResolver that wraps another IFileResolver and prefixes all its files with a subfolder path.

For example:

Root would be GameName/ModName, and models.pak should be added with a prefix of models/. Like so:

var modelsPak = new PakPackage("GameName/ModName/models.pak");
var environment = new CompositeFileResolver(new IFileResolver[]
{
    new DiskFileResolver("GameName/ModName/"),
    new VirtualSubdirectoryFileResolver("models/", new PackageFileResolver(modelsPak))
});