0.2.0-dev Download ZIP
463 lines ·23.8 KB Raw
| 1 | using System.Reflection; |
| 2 | using System.Security.Cryptography; |
| 3 | using EvilEngine.Adapters.Tests.Support; |
| 4 | using EvilEngine.Conversion; |
| 5 | using EvilEngine.Formats; |
| 6 | using EvilEngine.Mounts; |
| 7 | |
| 8 | namespace EvilEngine.Host.Tests; |
| 9 | |
| 10 | public sealed class AdapterFolderTests : IDisposable |
| 11 | { |
| 12 | private static readonly string Installed = typeof(AdapterFolderTests).Assembly |
| 13 | .GetCustomAttributes<AssemblyMetadataAttribute>() |
| 14 | .Single(attribute => attribute.Key == "AdapterOutputRoot").Value!; |
| 15 | |
| 16 | private readonly string _extra = Path.Combine(Path.GetTempPath(), $"evil-adapters-{Guid.NewGuid():N}"); |
| 17 | |
| 18 | public void Dispose() |
| 19 | { |
| 20 | if (Directory.Exists(_extra)) |
| 21 | Directory.Delete(_extra, true); |
| 22 | } |
| 23 | |
| 24 | private static EngineHost Boot(params string[] roots) |
| 25 | { |
| 26 | var host = new EngineHost(); |
| 27 | host.Adapters.LoadAll([Installed, .. roots]); |
| 28 | return host; |
| 29 | } |
| 30 | |
| 31 | private static MemorySource GarrysModInstall() |
| 32 | { |
| 33 | var install = new MemorySource("GarrysMod", CaseRule.Insensitive) |
| 34 | .Add("garrysmod/gameinfo.txt", "\"GameInfo\" {}") |
| 35 | .Add("garrysmod/steam.inf", "PatchVersion=2026.04.29\nProductName=garrysmod\nappID=4000\n") |
| 36 | .Add("garrysmod/garrysmod.ver", "260917") |
| 37 | .Add("garrysmod/addons/evil_fungus/lua/autorun/fungus.lua", "print('spores')") |
| 38 | .Add("garrysmod/addons/evil_api/evil_api.gma", |
| 39 | new GmaWriter().Add("lua/autorun/evil_api.lua", "EVIL = {}") |
| 40 | .Add("models/props_c17/oildrum001.mdl", "IDST from the addon").Build("Evil API")) |
| 41 | .Add("garrysmod/models/props_c17/oildrum001.mdl", "IDST") |
| 42 | .Add("hl2_linux", ""); |
| 43 | foreach (var (path, data) in new VpkWriter() |
| 44 | .Add("models/props_c17/oildrum001.mdl", "IDST from the vpk", 0, 4) |
| 45 | .Add("models/maxofs2d/cube_tool.mdl", "IDST cube", 1) |
| 46 | .Add("scripts/propdata.txt", "inline") |
| 47 | .Build("garrysmod/garrysmod_dir.vpk")) |
| 48 | install.Add(path, data); |
| 49 | return install; |
| 50 | } |
| 51 | |
| 52 | [Fact] |
| 53 | public void AnnouncesEachAdapterAsItLoads() |
| 54 | { |
| 55 | var host = new EngineHost(); |
| 56 | var heard = new List<string>(); |
| 57 | host.Adapters.AdapterLoaded += adapter => heard.Add(adapter.Manifest.Id); |
| 58 | |
| 59 | host.Adapters.LoadAll([Installed]); |
| 60 | |
| 61 | Assert.Equal(host.Adapters.Loaded.Select(adapter => adapter.Manifest.Id), heard); |
| 62 | } |
| 63 | |
| 64 | [Fact] |
| 65 | public void LoadsOnlyTheAdaptersTheSwitchedOnGamesNeed() |
| 66 | { |
| 67 | var host = new EngineHost(); |
| 68 | |
| 69 | host.Adapters.LoadAll([Installed], FeatureFlags.Parse("[games]\ngmod = true\n", "features.toml")); |
| 70 | |
| 71 | Assert.Empty(host.Adapters.Problems); |
| 72 | Assert.Equal(["gma", "gmod", "pc", "source", "steam", "vpk"], |
| 73 | host.Adapters.Loaded.Select(adapter => adapter.Manifest.Id).Order(StringComparer.Ordinal)); |
| 74 | Assert.Contains(host.Adapters.LeftOut, manifest => manifest.Id == "overgrowth"); |
| 75 | Assert.Contains(host.Adapters.LeftOut, manifest => manifest.Id == "zip"); |
| 76 | Assert.DoesNotContain(host.Adapters.LeftOut, manifest => manifest.Id == "vpk"); |
| 77 | } |
| 78 | |
| 79 | [Fact] |
| 80 | public void LoadsTheEnginesAdaptersInNeedsOrder() |
| 81 | { |
| 82 | var host = Boot(); |
| 83 | |
| 84 | Assert.Empty(host.Adapters.Problems); |
| 85 | Assert.Equal( |
| 86 | [ |
| 87 | "addressables", "hpl3", "pc", "steam", "amnesia-bunker", "hpl2", "amnesia-dark-descent", "unity", |
| 88 | "battlebit", "zip", "beamng", "ea.big", "dbpf", "ea.pegasus", "gma", |
| 89 | "source", "vpk", "gmod", "pak", "goldsrc", "iso9660", "ksp", "left4dead2", "lethal-company", "oodle", |
| 90 | "overgrowth", "portal2", "ps3", |
| 91 | "quake", |
| 92 | "unreal", "rocket-league", "satisfactory", "schedule-i", "scp-containment-breach", "skate3", |
| 93 | "slime-rancher", "sourcegames", "subnautica", |
| 94 | "the-sims-4", "unityfs" |
| 95 | ], host.Adapters.Loaded.Select(adapter => adapter.Manifest.Id)); |
| 96 | Assert.Equal( |
| 97 | ["dbpf", "ea.big", "gma", "iso9660", "pak", "unityfs", "unreal.iostore", "unreal.pak", "vpk", "zip"], |
| 98 | host.Mounts.Containers.Select(container => container.Id).Order()); |
| 99 | Assert.Equal([ |
| 100 | "amnesia-bunker", "amnesia-dark-descent", "amnesia-justine", "battlebit-remastered", "beamng-drive", |
| 101 | "ep2", "episodic", "gmod", "half-life", "hl2", "ksp", "left4dead2", "lethal-company", |
| 102 | "lostcoast", "overgrowth", "portal", "portal2", "quake", "quake-rerelease", "rocket-league", |
| 103 | "satisfactory", "schedule-i", |
| 104 | "scp-containment-breach", "skate3", "slime-rancher", "subnautica", "the-sims-4" |
| 105 | ], |
| 106 | host.Mounts.Games.Select(game => game.Game).Order()); |
| 107 | Assert.Equal(["source.mdl", "source.bsp"], |
| 108 | host.Conversion.Converters("gmod", ContentKind.Model).Select(converter => converter.Id)); |
| 109 | } |
| 110 | |
| 111 | [Fact] |
| 112 | public void TitlesEveryInstalledGameApart() |
| 113 | { |
| 114 | var host = Boot(); |
| 115 | var titles = host.Adapters.Loaded.SelectMany(adapter => adapter.Manifest.Titles).ToArray(); |
| 116 | |
| 117 | Assert.Equal(host.Mounts.Games.Select(game => game.Game).Order(), titles.Select(pair => pair.Key).Order()); |
| 118 | Assert.Equal(titles.Length, titles.Select(pair => pair.Value).Distinct(StringComparer.OrdinalIgnoreCase).Count()); |
| 119 | Assert.Equal( |
| 120 | ["Portal", "Half-Life 2", "Half-Life 2: Episode One", "Half-Life 2: Episode Two", "Half-Life 2: Lost Coast"], |
| 121 | host.Adapters.Find("sourcegames")!.Manifest.Games.Select(host.Adapters.Find("sourcegames")!.Manifest.Title)); |
| 122 | } |
| 123 | |
| 124 | [Fact] |
| 125 | public void NotesAGameTitledAsAnotherAdaptersGame() |
| 126 | { |
| 127 | var folder = Path.Combine(_extra, "zz-gmod"); |
| 128 | Directory.CreateDirectory(folder); |
| 129 | File.WriteAllText(Path.Combine(folder, "adapter.toml"), |
| 130 | "id = \"zz-gmod\"\nname = \"Another Garry's Mod\"\nversion = \"0.1.0\"\napi = 1\ncode = \"Code/zz-gmod.dll\"\ngames = [\"gmod2\"]\n[titles]\ngmod2 = \"garry's mod\"\n"); |
| 131 | |
| 132 | var host = Boot(_extra); |
| 133 | |
| 134 | Assert.Contains(host.Adapters.Problems, |
| 135 | problem => problem.Subject == "zz-gmod" && |
| 136 | problem.Reason == "titles gmod2 'garry's mod', as gmod titles gmod."); |
| 137 | } |
| 138 | |
| 139 | [Fact] |
| 140 | public void LoadsAdaptersFromARelativeRoot() |
| 141 | { |
| 142 | var host = new EngineHost(); |
| 143 | host.Adapters.LoadAll([Path.GetRelativePath(Environment.CurrentDirectory, Installed)]); |
| 144 | |
| 145 | Assert.Empty(host.Adapters.Problems); |
| 146 | Assert.Equal(Boot().Adapters.Loaded.Select(adapter => adapter.Manifest.Id), |
| 147 | host.Adapters.Loaded.Select(adapter => adapter.Manifest.Id)); |
| 148 | } |
| 149 | |
| 150 | [Fact] |
| 151 | public void ProbesAndPlansGarrysMod() |
| 152 | { |
| 153 | var host = Boot(); |
| 154 | |
| 155 | var probe = Assert.Single(host.Mounts.Probe(GarrysModInstall(), "GarrysMod")); |
| 156 | Assert.Equal(new MountId("gmod", "pc", "2026.04.29"), probe.Id); |
| 157 | Assert.Equal(ProbeStatus.Known, probe.Probe.Status); |
| 158 | Assert.Contains("hl2_linux is the linux player build", probe.Probe.Evidence); |
| 159 | |
| 160 | var mount = host.Mounts.Open(probe); |
| 161 | Assert.Equal( |
| 162 | [ |
| 163 | "addons/evil_api", "addons/evil_fungus", "addons/evil_api/evil_api.gma", "garrysmod.vpk", "garrysmod", |
| 164 | "sourceengine", "download" |
| 165 | ], |
| 166 | mount.Layers.Select(layer => layer.Name)); |
| 167 | Assert.Equal("addons/evil_fungus", mount.Origin("lua/autorun/fungus.lua")!.Layer.Name); |
| 168 | Assert.NotNull(mount.Part("content")); |
| 169 | } |
| 170 | |
| 171 | [Fact] |
| 172 | public void ReadsGarrysModThroughItsVpksAndGmas() |
| 173 | { |
| 174 | var host = Boot(); |
| 175 | var mount = host.Mounts.Open(host.Mounts.Probe(GarrysModInstall(), "GarrysMod")[0]); |
| 176 | |
| 177 | Assert.Equal("EVIL = {}", mount.Files.ReadAllText("lua/autorun/evil_api.lua")); |
| 178 | Assert.Equal("addons/evil_api/evil_api.gma", mount.Origin("lua/autorun/evil_api.lua")!.Layer.Name); |
| 179 | Assert.Equal("IDST from the addon", mount.Files.ReadAllText("models/props_c17/oildrum001.mdl")); |
| 180 | Assert.Equal("IDST cube", mount.Files.ReadAllText("models/maxofs2d/cube_tool.mdl")); |
| 181 | Assert.Equal("garrysmod.vpk", mount.Origin("models/maxofs2d/cube_tool.mdl")!.Layer.Name); |
| 182 | Assert.Equal("GarrysMod/garrysmod/garrysmod_dir.vpk", mount.Origin("scripts/propdata.txt")!.Location); |
| 183 | Assert.Equal("IDST from the vpk", |
| 184 | mount.Layers.Single(layer => layer.Name == "garrysmod.vpk").Files |
| 185 | .ReadAllText("models/props_c17/oildrum001.mdl")); |
| 186 | } |
| 187 | |
| 188 | [Fact] |
| 189 | public void ConvertsGarrysModContentThroughTheSourceFamily() |
| 190 | { |
| 191 | var host = Boot(); |
| 192 | var mount = host.Mounts.Open(host.Mounts.Probe(GarrysModInstall(), "GarrysMod")[0]); |
| 193 | host.Conversion.AddNamespace(new ContentNamespace("gmod", |
| 194 | new LayeredSource("gmod", CaseRule.Insensitive, |
| 195 | [mount.Layers.Single(layer => layer.Name == "garrysmod")]))); |
| 196 | |
| 197 | var barrel = host.Conversion.Get(ContentKind.Model, ContentId.Parse("gmod:models/props_c17/oildrum001")); |
| 198 | Assert.Equal(ConversionStatus.Failed, barrel.Status); |
| 199 | Assert.Contains(barrel.Diagnostics, |
| 200 | diagnostic => diagnostic.StartsWith("source.mdl failed on gmod:models/props_c17/oildrum001") && |
| 201 | diagnostic.Contains("shorter than an MDL header")); |
| 202 | |
| 203 | Assert.Equal(ConversionStatus.NoConverter, |
| 204 | host.Conversion.Get(ContentKind.Model, ContentId.Parse("gmod:models/missing")).Status); |
| 205 | } |
| 206 | |
| 207 | [Fact] |
| 208 | public void RefusesAnAdapterThatReachesTheEnginesOwnAssemblies() |
| 209 | { |
| 210 | var folder = Path.Combine(_extra, "rogue"); |
| 211 | Directory.CreateDirectory(Path.Combine(folder, "Code")); |
| 212 | File.Copy(typeof(AdapterFolderTests).Assembly.Location, Path.Combine(folder, "Code", "rogue.dll")); |
| 213 | File.WriteAllText(Path.Combine(folder, "adapter.toml"), |
| 214 | "id = \"rogue\"\nname = \"Rogue\"\nversion = \"1.0.0\"\napi = 1\ncode = \"Code/rogue.dll\"\n"); |
| 215 | |
| 216 | var host = new EngineHost(); |
| 217 | var heard = new List<HostProblem>(); |
| 218 | host.Adapters.ProblemNoted += heard.Add; |
| 219 | host.Adapters.LoadAll([Installed, _extra]); |
| 220 | |
| 221 | var problem = Assert.Single(host.Adapters.Problems); |
| 222 | Assert.Same(problem, Assert.Single(heard)); |
| 223 | Assert.Equal("rogue", problem.Subject); |
| 224 | Assert.Contains("rogue.dll references EvilEngine.Host, which is the engine's own.", problem.Reason); |
| 225 | } |
| 226 | |
| 227 | [Fact] |
| 228 | public void RefusesAnAdapterWhoseNeedsArentInstalled() |
| 229 | { |
| 230 | var folder = Path.Combine(_extra, "skate2"); |
| 231 | Directory.CreateDirectory(folder); |
| 232 | File.WriteAllText(Path.Combine(folder, "adapter.toml"), |
| 233 | "id = \"skate2\"\nname = \"Skate 2\"\nversion = \"0.1.0\"\napi = 1\ncode = \"Code/skate2.dll\"\ngames = [\"skate2\"]\n[titles]\nskate2 = \"Skate 2\"\n[needs]\n\"ea.ignite\" = \"^1\"\n"); |
| 234 | |
| 235 | var host = Boot(_extra); |
| 236 | |
| 237 | Assert.Contains(host.Adapters.Problems, |
| 238 | problem => problem.Subject == "skate2" && |
| 239 | problem.Reason == "needs adapter ea.ignite ^1, which isn't installed."); |
| 240 | Assert.Equal(SatisfactionStatus.NoAdapter, host.Mounts.Satisfies(new MountRequirement("skate2")).Status); |
| 241 | } |
| 242 | |
| 243 | [Fact] |
| 244 | public void ReadsARealGarrysModInstall() |
| 245 | { |
| 246 | var path = Environment.GetEnvironmentVariable("EVIL_GMOD"); |
| 247 | Assert.SkipWhen(path is null, "Set EVIL_GMOD to a Garry's Mod install to read it."); |
| 248 | var host = Boot(); |
| 249 | |
| 250 | var probe = Assert.Single(host.Mounts.Probe(path!)); |
| 251 | Assert.Equal("gmod", probe.Id.Game); |
| 252 | Assert.Equal(ProbeStatus.Known, probe.Probe.Status); |
| 253 | var mount = host.Mounts.Open(probe); |
| 254 | var tree = mount.Files.EnumerateAll().Select(entry => entry.Path.Value) |
| 255 | .ToHashSet(StringComparer.OrdinalIgnoreCase); |
| 256 | foreach (var layer in mount.Layers) |
| 257 | Assert.All(layer.Files.EnumerateAll(), entry => Assert.Contains(entry.Path.Value, tree)); |
| 258 | Assert.True(host.Mounts.Satisfies(new MountRequirement("gmod") |
| 259 | { Parts = ["content"], Platforms = ["pc"], Builds = [probe.Id.Build] }).IsSatisfied); |
| 260 | Assert.Equal(SatisfactionStatus.NotMounted, |
| 261 | host.Mounts.Satisfies(new MountRequirement("gmod") { Builds = ["2013.01.01"] }).Status); |
| 262 | Assert.Equal(ExternalState.Resolved, mount.Externals["workshop"]!.State); |
| 263 | var items = mount.Layers.Where(layer => layer.Name.StartsWith("workshop/", StringComparison.Ordinal)) |
| 264 | .Select(layer => layer.Name).ToArray(); |
| 265 | Assert.NotEmpty(items); |
| 266 | Assert.All(items, item => Assert.NotNull(mount.Part(item))); |
| 267 | var withoutFirst = Boot().Mounts; |
| 268 | var without = withoutFirst.Open(withoutFirst.Probe(path!)[0], |
| 269 | new Dictionary<string, ExternalSetting> { [items[0]] = ExternalSetting.Disabled }); |
| 270 | Assert.Equal(items[1..], |
| 271 | without.Layers.Where(layer => layer.Name.StartsWith("workshop/", StringComparison.Ordinal)) |
| 272 | .Select(layer => layer.Name)); |
| 273 | var again = Boot().Mounts; |
| 274 | var reopened = again.Open(again.Probe(path!)[0]); |
| 275 | Assert.Equal(mount.Build, reopened.Build); |
| 276 | Assert.Equal(mount.Part("content")!.Fingerprint, reopened.Part("content")!.Fingerprint); |
| 277 | } |
| 278 | |
| 279 | [Theory] |
| 280 | [InlineData("models/alyx.mdl", 480915, "028bb5d5569cab0aad8ccdd367ff5c38d5452e33bf0f6a4df9262c0ce2881844", |
| 281 | "garrysmod.vpk")] |
| 282 | [InlineData("models/maxofs2d/cube_tool.mdl", 6664, |
| 283 | "8f3e842b0ca5045f507094f8b50161941b244ef532987b6dd067008b7dbb70ee", "garrysmod.vpk")] |
| 284 | [InlineData("models/player.phy", 0, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", |
| 285 | "garrysmod.vpk")] |
| 286 | [InlineData("materials/brick/brickwall001a.vtf", 174968, |
| 287 | "ce3714eb72c9c3c03a40047a401ecdf965b0a7c4240571b623ea6fe7e3a9eee8", "sourceengine/hl2_textures.vpk")] |
| 288 | [InlineData("sound/vo/breencast/br_welcome01.wav", 342299, |
| 289 | "c1b045ad95d61fdcbfd8ca0d651ddb1d0dac6103e99315ffb429edeef5871e36", "sourceengine/hl2_sound_vo_english.vpk")] |
| 290 | [InlineData("sound/ambient/wind/wind1.wav", 293566, |
| 291 | "cb2cf64ba720211ec52d13243a25bdd12d7126c935955e2866b78e23c06c6b6a", "sourceengine/hl2_sound_misc.vpk")] |
| 292 | [InlineData("models/props_c17/oildrum001.mdl", 1976, |
| 293 | "baab025ebeea54f3977ede109c9903389e289bfc545e62ed2d978bfe11a4e325", "sourceengine/hl2_misc.vpk")] |
| 294 | [InlineData("gameinfo.txt", 1197, "c616a6f675f69b6fe2d35d5950949a8379b49e4e26c6690ba40c3b33822a7df4", "garrysmod")] |
| 295 | [InlineData("lua/wos/dynabase/registers/wos_legacy_registers.lua", 6956, |
| 296 | "87f1280a79b72b2688d3e773357199819648a78a5512c17f2bc3406db7cd0c15", "workshop/2917050373")] |
| 297 | [InlineData("materials/models/props_foliage/tree_deciduous_cards_01_darker.vmt", 236, |
| 298 | "9ab398f4218fbd87a800275c3c73715ec801901637fb8d991feef5dda56098c8", "hl2/hl2/hl2_misc.vpk")] |
| 299 | [InlineData("materials/models/ceilinggibs/ceiling1.vmt", 69, |
| 300 | "347ebaccd4b3af2ef449a9c78c40d728892b982a830a963eab527cd9d9b1933f", "fallbacks.vpk")] |
| 301 | public void ReadsARealGarrysModInstallByteForByte(string path, long length, string sha256, string layer) |
| 302 | { |
| 303 | var install = Environment.GetEnvironmentVariable("EVIL_GMOD"); |
| 304 | Assert.SkipWhen(install is null, "Set EVIL_GMOD to a Garry's Mod install to read it."); |
| 305 | var host = Boot(); |
| 306 | var mount = host.Mounts.Open(Assert.Single(host.Mounts.Probe(install!))); |
| 307 | |
| 308 | var bytes = mount.Files.ReadAllBytes(path); |
| 309 | Assert.Equal(length, bytes.Length); |
| 310 | Assert.Equal(sha256, Convert.ToHexStringLower(SHA256.HashData(bytes))); |
| 311 | Assert.Equal(layer, mount.Origin(path)!.Layer.Name); |
| 312 | } |
| 313 | |
| 314 | [Theory] |
| 315 | [InlineData("PS3_GAME/PARAM.SFO", 1040, "f4d897b2b4622eccf89eaa9742d11559db437f493577508793b30b702471422f", null)] |
| 316 | [InlineData("data/content/characterVersion.txt", 8, |
| 317 | "c09d53220616cb8e041092b417a8f5053dc71b07845ed0ab4b8770386d857b49", "USRDIR")] |
| 318 | [InlineData("data/content/world/stream/DIST_StartPark/cPres_50_-50_high.psf", 256, |
| 319 | "86121eb6cd52fc8a7a9ae3938e77b2e515b0ae4bf588d6c28cc06e310947a61e", "data/content/worldDIST_StartPark.big")] |
| 320 | [InlineData("data/boundary/c_2a_02_jam_branded_pure.xml", 213, |
| 321 | "1bfc3377008e3c9997ebe61c6c18317293a2d8f4cf9795abfc2970ee77ad5f68", "data/big/miscload.big")] |
| 322 | [InlineData("data/anim/SkaterBodyPres.abin", 5824, |
| 323 | "edd0733c84f84e8d0e242f4ded5e3a10b8caa9818a6dca3cc8dea38c4fb1a89c", "data/big/miscload.big")] |
| 324 | [InlineData("data/db/challenge_local_data/freeskate_testdmo.vlt", 336, |
| 325 | "17ef0b148e77e3c4ea397c6a8facf7c07c061475770fc36a976428506adf604a", "data/big/db.big")] |
| 326 | [InlineData("data/scene/anim/Balcony_tower_061.abin", 29360, |
| 327 | "2bf66e2556d6ec16626f4bd6387d039dd49de1dfacac9570bae428d8c3986219", "data/big/scene.big")] |
| 328 | [InlineData("data/content/createacharacter/model/cas_db/OuterTorso/0x00000e8e03e38811.psg", 118092, |
| 329 | "37beeb5e5ed1b64fc8d686d9bb7844450f7ef94687303dbecc122acde0d79ee3", "data/content/createacharacter.big")] |
| 330 | public void ReadsARealSkate3Ps3ImageByteForByte(string path, long length, string sha256, string? layer) |
| 331 | { |
| 332 | var image = Environment.GetEnvironmentVariable("EVIL_SKATE3_PS3"); |
| 333 | Assert.SkipWhen(image is null, "Set EVIL_SKATE3_PS3 to the Skate 3 PS3 disc image (BLUS30464) to read it."); |
| 334 | var host = Boot(); |
| 335 | var probe = Assert.Single(host.Mounts.Probe(image!)); |
| 336 | var mount = host.Mounts.Open(probe); |
| 337 | var files = layer is null ? probe.Probe.Tree : mount.Files; |
| 338 | |
| 339 | var bytes = files.ReadAllBytes(path); |
| 340 | Assert.Equal(length, bytes.Length); |
| 341 | Assert.Equal(sha256, Convert.ToHexStringLower(SHA256.HashData(bytes))); |
| 342 | if (layer is not null) |
| 343 | Assert.Equal(layer, mount.Origin(path)!.Layer.Name); |
| 344 | } |
| 345 | |
| 346 | [Fact] |
| 347 | public void MountsARealSkate3Ps3Image() |
| 348 | { |
| 349 | var image = Environment.GetEnvironmentVariable("EVIL_SKATE3_PS3"); |
| 350 | Assert.SkipWhen(image is null, "Set EVIL_SKATE3_PS3 to the Skate 3 PS3 disc image (BLUS30464) to read it."); |
| 351 | var host = Boot(); |
| 352 | |
| 353 | var probe = Assert.Single(host.Mounts.Probe(image!)); |
| 354 | Assert.Equal(new MountId("skate3", "ps3", "BLUS30464-01.00"), probe.Id); |
| 355 | Assert.Equal(ProbeStatus.Known, probe.Probe.Status); |
| 356 | Assert.Equal(["iso9660"], probe.ContainerChain); |
| 357 | var mount = host.Mounts.Open(probe); |
| 358 | Assert.Equal(32, mount.Layers.Count); |
| 359 | Assert.Equal(28046, mount.Files.EnumerateAll().Count()); |
| 360 | Assert.True(host.Mounts.Satisfies(new MountRequirement("skate3") { Parts = ["gameplay", "character"] }) |
| 361 | .IsSatisfied); |
| 362 | Assert.Equal( |
| 363 | [ |
| 364 | "gameplay", "controls", "rig", "character", "skatepark", "world/blackboxpark", "world/downtown", |
| 365 | "world/downtownskatepark", "world/industrial", |
| 366 | "world/industrialskatepark", "world/maloofmoneycup", "world/megapark", "world/skateschool", |
| 367 | "world/startpark", "world/university" |
| 368 | ], |
| 369 | mount.Parts.Select(part => part.Name)); |
| 370 | Assert.All(mount.Parts.SelectMany(part => part.DefiningFiles), |
| 371 | path => Assert.True(mount.Files.Exists(path), $"{path} is missing")); |
| 372 | Assert.Equal(4, mount.Part("world/university")!.DefiningFiles.Count); |
| 373 | |
| 374 | var again = Boot().Mounts; |
| 375 | var reopened = again.Open(again.Probe(image!)[0]); |
| 376 | Assert.Equal(mount.Build, reopened.Build); |
| 377 | Assert.Equal(mount.Part("gameplay")!.Fingerprint, reopened.Part("gameplay")!.Fingerprint); |
| 378 | } |
| 379 | |
| 380 | [Fact] |
| 381 | public void ReadsARealSatisfactoryInstallsKrakenBlocksThroughTheOodleAdapter() |
| 382 | { |
| 383 | var install = Environment.GetEnvironmentVariable("EVIL_SATISFACTORY"); |
| 384 | Assert.SkipWhen(install is null, "Set EVIL_SATISFACTORY to a Satisfactory install to read it."); |
| 385 | var host = Boot(); |
| 386 | var mount = host.Mounts.Open(Assert.Single(host.Mounts.Probe(install!))); |
| 387 | var plate = mount.Files.EnumerateAll().Single(entry => entry.Path.Name == "TX_IronPlate_Relf.ubulk").Path; |
| 388 | |
| 389 | foreach (var path in new[] |
| 390 | { |
| 391 | plate, "FactoryGame/Content/FactoryGame/Resource/Parts/IronPlate/UI/IconDesc_IronPlates_256.uasset" |
| 392 | }) |
| 393 | { |
| 394 | var bytes = mount.Files.ReadAllBytes(path); |
| 395 | var claim = mount.Parts.Select(part => part.Claims.GetValueOrDefault(path)).OfType<string>().First(); |
| 396 | Assert.Equal($"blake3:{Convert.ToHexStringLower(Blake3.Hash(bytes, 20))}", claim); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | [Fact] |
| 401 | public void MountsARealKspInstall() |
| 402 | { |
| 403 | var install = Environment.GetEnvironmentVariable("EVIL_KSP"); |
| 404 | Assert.SkipWhen(install is null, "Set EVIL_KSP to a Kerbal Space Program install to read it."); |
| 405 | var host = Boot(); |
| 406 | |
| 407 | var probe = Assert.Single(host.Mounts.Probe(install!)); |
| 408 | Assert.Equal(new MountId("ksp", "pc", "1.12.5.3190"), probe.Id); |
| 409 | Assert.Equal(ProbeStatus.Known, probe.Probe.Status); |
| 410 | var mount = host.Mounts.Open(probe); |
| 411 | var items = mount.Layers.Where(layer => layer.Name.StartsWith("workshop/", StringComparison.Ordinal)) |
| 412 | .Select(layer => layer.Name).ToArray(); |
| 413 | Assert.Equal(6, items.Length); |
| 414 | Assert.Equal(["GameData/Squad", .. items, "install"], mount.Layers.Select(layer => layer.Name)); |
| 415 | Assert.Equal(probe.Probe.Tree.EnumerateAll().Count() + 12, mount.Files.EnumerateAll().Count()); |
| 416 | Assert.Equal("GameData/Squad", mount.Origin("GameData/Squad/Parts/Aero/airbrake/Airbrake.cfg")!.Layer.Name); |
| 417 | Assert.Equal(["parts", "interiors", .. items], mount.Parts.Select(part => part.Name)); |
| 418 | Assert.All(items, item => Assert.NotNull(mount.Part(item)!.Version)); |
| 419 | Assert.All(mount.Part("parts")!.DefiningFiles.Concat(mount.Part("interiors")!.DefiningFiles), |
| 420 | path => Assert.True(mount.Files.Exists(path), $"{path} is missing")); |
| 421 | Assert.All(items.SelectMany(item => mount.Part(item)!.DefiningFiles), |
| 422 | path => Assert.True(mount.Externals["workshop"]!.Files!.Exists(path), $"{path} is missing")); |
| 423 | Assert.True(host.Mounts.Satisfies(new MountRequirement("ksp") { Parts = ["parts"], Platforms = ["pc"] }) |
| 424 | .IsSatisfied); |
| 425 | Assert.Equal(SatisfactionStatus.NotMounted, |
| 426 | host.Mounts.Satisfies(new MountRequirement("ksp") { Builds = ["1.12.3.3173"] }).Status); |
| 427 | |
| 428 | var again = Boot().Mounts; |
| 429 | var reopened = again.Open(again.Probe(install!)[0]); |
| 430 | Assert.Equal(mount.Build, reopened.Build); |
| 431 | Assert.Equal(mount.Part("parts")!.Fingerprint, reopened.Part("parts")!.Fingerprint); |
| 432 | } |
| 433 | |
| 434 | [Fact] |
| 435 | public void MountsARealSubnauticaInstall() |
| 436 | { |
| 437 | var install = Environment.GetEnvironmentVariable("EVIL_SUBNAUTICA"); |
| 438 | Assert.SkipWhen(install is null, "Set EVIL_SUBNAUTICA to a Subnautica install to read it."); |
| 439 | var host = Boot(); |
| 440 | |
| 441 | var probe = Assert.Single(host.Mounts.Probe(install!)); |
| 442 | Assert.Equal(new MountId("subnautica", "pc", "83031"), probe.Id); |
| 443 | Assert.Equal(ProbeStatus.Known, probe.Probe.Status); |
| 444 | var mount = host.Mounts.Open(probe); |
| 445 | Assert.Equal(["install"], mount.Layers.Select(layer => layer.Name)); |
| 446 | Assert.Equal(probe.Probe.Tree.EnumerateAll().Count(), mount.Files.EnumerateAll().Count()); |
| 447 | Assert.Empty(mount.Notes); |
| 448 | Assert.Equal(["gameplay", "vehicles", "creatures", "habitats", "terrain", "world"], |
| 449 | mount.Parts.Select(part => part.Name)); |
| 450 | Assert.Equal([42, 385, 453, 555, 5420, 15031], mount.Parts.Select(part => part.DefiningFiles.Count)); |
| 451 | Assert.All(mount.Parts.SelectMany(part => part.DefiningFiles), |
| 452 | path => Assert.True(mount.Files.Exists(path), $"{path} is missing")); |
| 453 | Assert.True(host.Mounts.Satisfies(new MountRequirement("subnautica") |
| 454 | { Parts = ["vehicles"], Platforms = ["pc"] }).IsSatisfied); |
| 455 | Assert.Equal(SatisfactionStatus.NotMounted, |
| 456 | host.Mounts.Satisfies(new MountRequirement("subnautica") { Builds = ["71288"] }).Status); |
| 457 | |
| 458 | var again = Boot().Mounts; |
| 459 | var reopened = again.Open(again.Probe(install!)[0]); |
| 460 | Assert.Equal(mount.Build, reopened.Build); |
| 461 | Assert.Equal(mount.Part("vehicles")!.Fingerprint, reopened.Part("vehicles")!.Fingerprint); |
| 462 | } |
| 463 | } |