using System.Diagnostics; using EvilEngine.Adapters.Overgrowth; using EvilEngine.Adapters.Steam; using EvilEngine.Adapters.Tests.Support; using EvilEngine.Mounts; namespace EvilEngine.Adapters.Tests; public sealed class OvergrowthTests { private const string InstallPath = "/library/steamapps/common/Overgrowth"; private const string Version = """ 105583 1.4.0 5583 """; private const string CoreMod = """ com-wolfire-overgrowth-core Overgrowth Core Wolfire Games * """; private const string CampaignMod = """ com-wolfire-overgrowth-campaign * og_story/01_Landing.xml Arenas/Cave_Arena.xml """; private const string TranslationsMod = """ com-wolfire-machine-translations Wolfire machine translations 1.3.0 """; private const string Landing = """ saved Data/LevelLoading/og_story/01_Landing.xml_loading.jpg Data/Textures/Terrain/hm.png """; private static MemorySource Install(string version = Version, string location = InstallPath) { return new MemorySource(location, CaseRule.Insensitive) .Add("Overgrowth.bin.x86_64", "\u007fELF") .Add("lib64/libsteam_api.so", "\u007fELF") .Add("Data/version.xml", version) .Add("Data/defaults.txt", "screenwidth: 800") .Add("Data/level_list", "Levels/og_story/01_Landing.xml") .Add("Data/Campaign/campaign.xml", "") .Add("Data/LevelInfo/og_story/01_Landing.xml", "") .Add("Data/Mods/wolfire_overgrowth_core/mod.xml", CoreMod) .Add("Data/Mods/wolfire_overgrowth_core/Data/Images/core/thumb.png", "png") .Add("Data/Mods/wolfire_overgrowth_campaign/mod.xml", CampaignMod) .Add("Data/Mods/wolfire_machine_translations/mod.xml", TranslationsMod) .Add("Data/Mods/wolfire_machine_translations/Data/DialoguesLocalized/sv/start.txt", "Hej") .Add("Data/ExampleMods/example_item_pack/mod.xml", "com-wolfire-example-item-pack") .Add("Data/Objects/Rock.xml", """ Data/Models/Rock.obj Data/Textures/Rock_c.tga data/textures/ROCK_N.tga Data/GLSL/envobject """) .Add("Data/Models/Rock.obj", "v 0 0 0") .Add("Data/Models/Rock.obj.cache", "cache") .Add("Data/Models/Rock.obj_flipped.cache", "flipped") .Add("Data/Models/Rock.obj.mcache", "dead") .Add("Data/Models/Rock_col.obj", "v 0 0 0") .Add("Data/Textures/Rock_c.tga_converted.dds", "DDS ") .Add("Data/Textures/Rock_n.tga", "tga") .Add("Data/Textures/Rock_n.tga_converted.dds", "DDS ") .Add("Data/Textures/Rock_n.tga_image_sample_cache", "sample") .Add("Data/Textures/Terrain/hm.png", "png") .Add("Data/Textures/Terrain/hm.png_hmcache", "hm") .Add("Data/Textures/Terrain/hm.png.cache", "mesh") .Add("Data/Textures/Terrain/hm.png_normal.png", "normals") .Add("Data/Textures/Terrain/hm.png_01_Landing_weights.png", "weights") .Add("Data/Textures/Terrain/hm.png_02_Cut_weights.png", "another level's") .Add("Data/Levels/og_story/01_Landing.xml", Landing) .Add("Data/Levels/og_story/01_Landing.xml_refl_cap_1.hdrcube", "cube") .Add("Data/Levels/og_story/01_Landing_2.xml", "saved") .Add("Data/Levels/arenas/Cave_Arena.xml", "saved") .Add("Data/Levels/proto/dev.xml", "saved") .Add("Data/LevelNavmeshes/og_story/01_Landing.nav.zip", "PK") .Add("Data/LevelNavmeshes/og_story/01_Landing.nav.xml", "") .Add("Data/LevelLoading/og_story/01_Landing.xml_loading.jpg", "jpg") .Add("Data/Objects/IGF_Characters/TurnerActor.xml", """ Data/Characters/turner.xml enemycontrol.as """) .Add("Data/Characters/turner.xml", """ """) .Add("Data/Characters/turner.xml.lod_cache", "lod") .Add("Data/Objects/turner_obj.xml", "Data/Models/Characters/turner.obj") .Add("Data/Models/Characters/turner.obj", "v 0 0 0") .Add("Data/Skeletons/r_turner.xml", "") .Add("Data/Skeletons/r_turner.phxbn", "bones") .Add("Data/Attacks/haymaker.xml", "") .Add("Data/Animations/r_idle.anm", "anm") .Add("Data/Items/sword.xml", "") .Add("Data/Scripts/aschar.as", "void Update() {}") .Add("Data/Sounds/hit.wav", "RIFF") .Add("Data/Music/theme.ogg", "OggS") .Add("Data/Dialogues/start.txt", "#name \"start\"") .Add("Data/GLSL/envobject.frag", "void main() {}") .Add("Data/UI/menu.html", "") .Add("Data/Prototypes/test.obj", "v 0 0 0"); } private static MemorySource WorkshopFolder(params (string Id, string ModId, string File)[] items) { var installed = string.Join("\n", items.Select(item => $"\t\t\"{item.Id}\"\t{{ \"manifest\" \"9{item.Id}\" }}")); var workshop = new MemorySource("/library/steamapps/workshop", CaseRule.Insensitive).Add( "appworkshop_25000.acf", $$""" "AppWorkshop" { "appid" "25000" "WorkshopItemsInstalled" { {{installed}} } } """); foreach (var (id, modId, file) in items) workshop .Add($"content/25000/{id}/mod.xml", $"{modId}{modId}*") .Add($"content/25000/{id}/{file}", $"from {id}"); return workshop; } private static ResolvedExternal Folder(External external, IFileSource files) { return new ResolvedExternal(external, ExternalState.Resolved, ExternalFrom.Hint) { Files = files, Location = files.Location }; } private static MountRegistry Registry() { var registry = new MountRegistry(); registry.Add(new OvergrowthGame()); return registry; } private static Mount Open(MemorySource install, Externals? externals = null) { var registry = Registry(); var probe = Assert.Single(registry.Probe(install, install.Location)); externals ??= Externals.None; return registry.Open(probe, new OvergrowthGame().Open(probe.Probe, externals), externals); } private static string[] Files(Mount mount, string part) { return [.. mount.Part(part)!.DefiningFiles.Select(path => path.Value)]; } [Fact] public void ProbesTheBuildAndItsVersionFromVersionXml() { var probe = Assert.Single(Registry().Probe(Install(), InstallPath)); Assert.Equal((new MountId("overgrowth", "pc", "5583"), ProbeStatus.Known), (probe.Id, probe.Probe.Status)); Assert.Equal( [ "Data/Mods/wolfire_overgrowth_core/mod.xml is com-wolfire-overgrowth-core", "Data/version.xml names build 5583", "that build is version 1.4.0" ], probe.Probe.Evidence); Assert.Equal(["steamapps", "depotcache", "workshop", "userdata"], probe.Probe.Externals.Select(external => external.Name)); } [Fact] public void HintsTheWriteFolderTheWayTheGameFindsIt() { Assert.Equal(new ExternalHint.HostPath("/home/me/.local/share/Overgrowth"), OvergrowthGame.Userdata("/home/me", "").Hint); Assert.Equal(new ExternalHint.HostPath("/data/Overgrowth"), OvergrowthGame.Userdata("/home/me", "/data").Hint); var windows = Install(); windows.Remove("Overgrowth.bin.x86_64"); Assert.Null(Assert.Single(Registry().Probe(windows, InstallPath)).Probe.Externals.Single(external => external.Name == "userdata").Hint); } [Fact] public void ProbesAVersionFileWithNoBuildAsAnUnknownVariant() { var probe = Assert.Single(Registry().Probe(Install("1.4.0"), InstallPath)); Assert.Equal((new MountId("overgrowth", "pc", "unknown"), ProbeStatus.UnknownVariant), (probe.Id, probe.Probe.Status)); Assert.Contains("Data/version.xml names no build, so the build is unknown", probe.Probe.Evidence); } [Fact] public void DeclinesATreeWithoutTheCoreModOrAVersionFile() { var noCore = Install(); noCore.Remove("Data/Mods/wolfire_overgrowth_core/mod.xml"); var noVersion = Install(); noVersion.Remove("Data/version.xml"); Assert.Empty(Registry().Probe(noCore, InstallPath)); Assert.Empty(Registry().Probe(noVersion, InstallPath)); } [Fact] public void LaysEachCoreModOverTheInstallLeavingOtherModsOut() { var mount = Open(Install()); Assert.Equal( [ ("Data/Mods/wolfire_overgrowth_campaign", "core"), ("Data/Mods/wolfire_overgrowth_core", "core"), ("install", "base") ], mount.Layers.Select(layer => (layer.Name, layer.Role))); Assert.Equal("png", mount.Files.ReadAllText("Data/Images/core/thumb.png")); Assert.True(mount.Files.Exists("Data/Mods/wolfire_overgrowth_core/mod.xml")); Assert.False(mount.Files.Exists("Data/DialoguesLocalized/sv/start.txt")); Assert.Equal( [ "Data/Mods/wolfire_overgrowth_campaign/mod.xml", "Data/Mods/wolfire_overgrowth_core/mod.xml", "Data/version.xml" ], new OvergrowthGame().Open(new OvergrowthGame().Probe(Install())!, Externals.None).BuildFiles .Select(path => path.Value).Order(StringComparer.Ordinal)); } [Fact] public void NamesItsPartsAfterWhatAPluginReads() { var mount = Open(Install()); Assert.Equal( [ "props", "characters", "moves", "level/og_story/01_Landing", "level/arenas/Cave_Arena", "scripts", "sounds", "dialogues", "config", "mod/wolfire_machine_translations" ], mount.Parts.Select(part => part.Name)); Assert.All(mount.Parts, part => Assert.True(part.Sha1Claims)); Assert.Equal(["Data/Scripts/aschar.as"], Files(mount, "scripts")); Assert.Equal(["Data/Music/theme.ogg", "Data/Sounds/hit.wav"], Files(mount, "sounds")); Assert.Equal( [ "Data/Campaign/campaign.xml", "Data/LevelInfo/og_story/01_Landing.xml", "Data/Mods/wolfire_overgrowth_campaign/mod.xml", "Data/Mods/wolfire_overgrowth_core/mod.xml", "Data/defaults.txt", "Data/level_list", "Data/version.xml" ], Files(mount, "config")); } [Fact] public void HoldsEachPropWithTheTwinsTheEngineReadsAndNotTheDeadCaches() { var mount = Open(Install()); Assert.Equal( [ "Data/Models/Rock.obj", "Data/Models/Rock.obj.cache", "Data/Models/Rock.obj_flipped.cache", "Data/Models/Rock_col.obj", "Data/Objects/Rock.xml", "Data/Textures/Rock_c.tga_converted.dds", "Data/Textures/Rock_n.tga", "Data/Textures/Rock_n.tga_converted.dds", "Data/Textures/Rock_n.tga_image_sample_cache" ], Files(mount, "props")); Assert.Contains( "Data/Mods/wolfire_overgrowth_core/mod.xml names Data/Objects/Gone.xml, which isn't in the install.", mount.Notes); } [Fact] public void ReadsALevelNamedByItsTextOrItsPathWithItsTitleAndCampaign() { var mod = ModXml.Parse("Data/Mods/a", """ com-wolfire-timbles-therium Therium-2 LugaruStory/Village.xml loose.xml """, [])!; Assert.Equal( [ new ModLevel("t2/tutorial.xml", "Tutorial", "Textures/ui/t2/tutorial.jpg", "Therium-2"), new ModLevel("LugaruStory/Village.xml", "Village", null, "Therium-2"), new ModLevel("loose.xml", "Loose", null, null) ], mod.Levels); } [Fact] public void HoldsALevelWithItsSideFilesAndWhatItPlacesButNotWhatItsCommentsName() { var mount = Open(Install()); Assert.Equal(new[] { "Data/Characters/turner.xml", "Data/Characters/turner.xml.lod_cache", "Data/LevelLoading/og_story/01_Landing.xml_loading.jpg", "Data/LevelNavmeshes/og_story/01_Landing.nav.xml", "Data/LevelNavmeshes/og_story/01_Landing.nav.zip", "Data/Levels/og_story/01_Landing.xml", "Data/Levels/og_story/01_Landing.xml_refl_cap_1.hdrcube", "Data/Models/Characters/turner.obj", "Data/Models/Rock.obj", "Data/Models/Rock.obj.cache", "Data/Models/Rock.obj_flipped.cache", "Data/Objects/IGF_Characters/TurnerActor.xml", "Data/Objects/Rock.xml", "Data/Objects/turner_obj.xml", "Data/Skeletons/r_turner.phxbn", "Data/Skeletons/r_turner.xml", "Data/Attacks/haymaker.xml", "Data/Textures/Rock_c.tga_converted.dds", "Data/Textures/Rock_n.tga", "Data/Textures/Rock_n.tga_converted.dds", "Data/Textures/Rock_n.tga_image_sample_cache", "Data/Textures/Terrain/hm.png", "Data/Textures/Terrain/hm.png_hmcache", "Data/Models/Rock_col.obj", "Data/Textures/Terrain/hm.png.cache", "Data/Textures/Terrain/hm.png_normal.png", "Data/Textures/Terrain/hm.png_01_Landing_weights.png" }.Order(StringComparer.Ordinal), Files(mount, "level/og_story/01_Landing")); Assert.Contains("Data/Levels/og_story/01_Landing.xml names Data/Objects/gone.xml, which isn't in the install.", mount.Notes); Assert.DoesNotContain(mount.Notes, note => note.Contains("commented.xml") || note.Contains("02_Cut")); Assert.DoesNotContain(mount.Parts, part => part.Name.Contains("dev") || part.Name.Contains("01_Landing_2")); } [Fact] public void FollowsActorsIntoTheirCharactersAndMovesIntoWhatTheyName() { var mount = Open(Install()); Assert.Equal( [ "Data/Attacks/haymaker.xml", "Data/Characters/turner.xml", "Data/Characters/turner.xml.lod_cache", "Data/Models/Characters/turner.obj", "Data/Objects/IGF_Characters/TurnerActor.xml", "Data/Objects/turner_obj.xml", "Data/Skeletons/r_turner.phxbn", "Data/Skeletons/r_turner.xml" ], Files(mount, "characters")); Assert.Equal( [ "Data/Animations/r_idle.anm", "Data/Attacks/haymaker.xml", "Data/Items/sword.xml", "Data/Skeletons/r_turner.phxbn", "Data/Skeletons/r_turner.xml" ], Files(mount, "moves")); } [Fact] public void ListsAModTheGameStartsOffAsAPartWithANote() { var mount = Open(Install()); Assert.Equal( [ "Data/Mods/wolfire_machine_translations/Data/DialoguesLocalized/sv/start.txt", "Data/Mods/wolfire_machine_translations/mod.xml" ], Files(mount, "mod/wolfire_machine_translations")); Assert.Contains( "Wolfire machine translations (Data/Mods/wolfire_machine_translations) is off: the game starts a mod from its own folder off.", mount.Notes); Assert.Contains( "Wolfire machine translations (Data/Mods/wolfire_machine_translations) doesn't list 1.4.0 among its supported versions, which the game only warns about.", mount.Notes); } [Fact] public void LeavesTheExecutablesRendererMenusAndWorkInProgressOutOfEveryPart() { var mount = Open(Install()); Assert.All(mount.Parts, part => Assert.DoesNotContain(part.DefiningFiles, path => path.Value.StartsWith("Data/GLSL/") || path.Value.StartsWith("Data/UI/") || path.Value.StartsWith("Data/Prototypes/") || path.Value.StartsWith("Data/ExampleMods/") || path.Value.StartsWith("lib64/") || path.Value.EndsWith(".mcache") || path.Value == "Overgrowth.bin.x86_64")); } [Fact] public void LaysAWorkshopModOverTheGameAsItsOwnPartLeavingTheGamesPartsAlone() { var workshop = WorkshopFolder(("123", "com-someone-red-rock", "Data/Textures/Rock_c.tga_converted.dds")); var without = Open(Install()); var mount = Open(Install(), new Externals([Folder(Workshop.External, workshop)])); Assert.Equal(("workshop/123", "workshop"), (mount.Layers[0].Name, mount.Layers[0].Role)); Assert.Equal("from 123", mount.Files.ReadAllText("Data/Textures/Rock_c.tga_converted.dds")); Assert.Equal(["content/25000/123/Data/Textures/Rock_c.tga_converted.dds", "content/25000/123/mod.xml"], Files(mount, "workshop/123")); Assert.Contains("com-someone-red-rock (workshop/123) is on, as the game starts a workshop mod.", mount.Notes); Assert.Equal(without.Part("props")!.Fingerprint, mount.Part("props")!.Fingerprint); } [Fact] public void NotesTwoWorkshopModsReplacingOneFileAndTheOneThatWins() { var workshop = WorkshopFolder(("7", "com-b", "Data/Textures/Rock_c.tga_converted.dds"), ("8", "com-a", "Data/Textures/Rock_c.tga_converted.dds")); var mount = Open(Install(), new Externals([Folder(Workshop.External, workshop)])); Assert.Equal("from 8", mount.Files.ReadAllText("Data/Textures/Rock_c.tga_converted.dds")); Assert.Contains( "workshop/7 and workshop/8 both replace Data/Textures/Rock_c.tga_converted.dds; workshop/8 wins, as its Id comes first.", mount.Notes); } [Fact] public void ListsAModInTheWriteFolderAsOffAndNotesSharedIds() { var userdata = new MemorySource("/home/me/.local/share/Overgrowth", CaseRule.Sensitive) .Add("Data/Mods/mine/mod.xml", "com-wolfire-machine-translationsMine*") .Add("Data/Mods/mine/Data/Textures/Rock_c.tga_converted.dds", "mine"); var mount = Open(Install(), new Externals([Folder(OvergrowthGame.Userdata("/home/me", ""), userdata)])); Assert.Equal(["Data/Mods/mine/Data/Textures/Rock_c.tga_converted.dds", "Data/Mods/mine/mod.xml"], Files(mount, "mod/mine")); Assert.Contains("Mine (userdata/Data/Mods/mine) is off: the game starts a mod from its own folder off.", mount.Notes); Assert.Contains( "Data/Mods/wolfire_machine_translations and Data/Mods/mine share the mod Id com-wolfire-machine-translations, which the game refuses for all but the first.", mount.Notes); Assert.Equal("DDS ", mount.Files.ReadAllText("Data/Textures/Rock_c.tga_converted.dds")); } [Fact] public void FingerprintsASteamCopyByItsClaimsAsACopyFromElsewhere() { var install = Install(); var depot = new DepotManifestWriter(25002, 8572447376951838510); foreach (var entry in install.EnumerateAll()) depot.File(entry.Path.Value.Replace('/', '\\'), install.ReadAllText(entry.Path)); var steamapps = new MemorySource("/library/steamapps", CaseRule.Insensitive).Add("appmanifest_25000.acf", """ "AppState" { "appid" "25000" "StateFlags" "4" "installdir" "Overgrowth" "InstalledDepots" { "25002" { "manifest" "8572447376951838510" } } } """); var depotcache = new MemorySource("/library/depotcache", CaseRule.Insensitive) .Add("25002_8572447376951838510.manifest", depot.Build()); var game = new OvergrowthGame(); var steam = game.Open(game.Probe(install)!, new Externals([Folder(SteamClaims.Steamapps, steamapps), Folder(SteamClaims.Depotcache, depotcache)])); var elsewhere = game.Open(game.Probe(Install(location: "/run/media/me/Overgrowth"))!, Externals.None); Assert.All(steam.Parts, part => Assert.Equal(part.DefiningFiles.Count, part.Claims.Count)); Assert.All(elsewhere.Parts, part => Assert.Empty(part.Claims)); foreach (var (claimed, read) in steam.Parts.Zip(elsewhere.Parts)) Assert.Equal(Fingerprint.Of(install, read.DefiningFiles, sha1Claims: true), Fingerprint.Of(install, claimed.DefiningFiles, claims: claimed.Claims, sha1Claims: true)); } [Fact] public void MountsARealOvergrowthInstall() { var install = Environment.GetEnvironmentVariable("EVIL_OVERGROWTH"); Assert.SkipWhen(install is null, "Set EVIL_OVERGROWTH to an Overgrowth install to read it."); var registry = Registry(); var probe = Assert.Single(registry.Probe(install!)); Assert.Equal(new MountId("overgrowth", "pc", "5583"), probe.Id); Assert.Contains("that build is version 1.4.0", probe.Probe.Evidence); registry.Close(registry.Open(probe)); var timer = Stopwatch.StartNew(); var mount = registry.Open(probe); var opened = timer.Elapsed; Assert.Equal(["core", "core", "core", "core", "core", "core", "core", "core", "base"], mount.Layers.Select(layer => layer.Role)); Assert.Equal(21499, mount.Files.EnumerateAll().Count()); Assert.DoesNotContain(mount.Notes, note => note.Contains("hash from their bytes") || note.Contains("hashes from")); Assert.All(mount.Parts, part => Assert.Equal(part.DefiningFiles.Count, part.Claims.Count)); var files = mount.Parts.ToDictionary(part => part.Name, part => part.DefiningFiles.Count); Assert.Equal(5918, files["props"]); Assert.Equal(737, files["characters"]); Assert.Equal(1159, files["moves"]); Assert.Equal(1756, files["level/og_story/27_Sky_Ark"]); Assert.Equal(212, files["scripts"]); Assert.Equal(3069, files["sounds"]); Assert.Equal(573, files["dialogues"]); Assert.Equal(391, files["config"]); Assert.Equal(3286, files["mod/wolfire_machine_translations"]); Assert.Equal(127, mount.Parts.Count(part => part.Name.StartsWith("level/"))); Assert.Equal(988, mount.Notes.Count(note => note.EndsWith("which isn't in the install."))); Assert.Contains( "Wolfire machine translations (Data/Mods/wolfire_machine_translations) is off: the game starts a mod from its own folder off.", mount.Notes); TestContext.Current.TestOutputHelper?.WriteLine($"Opened in {opened.TotalMilliseconds:F0} ms."); } }