0.2.0-dev Download ZIP
543 lines ·27.4 KB Raw
| 1 | using System.Diagnostics; |
| 2 | using EvilEngine.Adapters.Overgrowth; |
| 3 | using EvilEngine.Adapters.Steam; |
| 4 | using EvilEngine.Adapters.Tests.Support; |
| 5 | using EvilEngine.Mounts; |
| 6 | |
| 7 | namespace EvilEngine.Adapters.Tests; |
| 8 | |
| 9 | public sealed class OvergrowthTests |
| 10 | { |
| 11 | private const string InstallPath = "/library/steamapps/common/Overgrowth"; |
| 12 | |
| 13 | private const string Version = """ |
| 14 | <release> |
| 15 | <version>105583</version> |
| 16 | <name>1.4.0</name> |
| 17 | <build>5583</build> |
| 18 | </release> |
| 19 | """; |
| 20 | |
| 21 | private const string CoreMod = """ |
| 22 | <?xml version="1.0" ?> |
| 23 | <Mod> |
| 24 | <Id>com-wolfire-overgrowth-core</Id> |
| 25 | <Name>Overgrowth Core</Name> |
| 26 | <Author>Wolfire Games</Author> |
| 27 | <SupportedVersion>*</SupportedVersion> |
| 28 | <Item category="Static Objects" title="Rock" path="Data/Objects/Rock.xml" thumbnail="Data/UI/spawner/thumbs/Rock.png"/> |
| 29 | <Item category="Static Objects" title="Gone" path="Data/Objects/Gone.xml" thumbnail="Data/UI/spawner/thumbs/Gone.png"/> |
| 30 | </Mod> |
| 31 | """; |
| 32 | |
| 33 | private const string CampaignMod = """ |
| 34 | <Mod> |
| 35 | <Id>com-wolfire-overgrowth-campaign </Id> |
| 36 | <SupportedVersion>*</SupportedVersion> |
| 37 | <Campaign title="Overgrowth Story"> |
| 38 | <Level id="landing" title="White Flags">og_story/01_Landing.xml</Level> |
| 39 | <!--<Level id="cut" title="Cut">og_story/02_Cut.xml</Level>--> |
| 40 | </Campaign> |
| 41 | <Level title="Arena">Arenas/Cave_Arena.xml</Level> |
| 42 | </Mod> |
| 43 | """; |
| 44 | |
| 45 | private const string TranslationsMod = """ |
| 46 | <Mod> |
| 47 | <Id>com-wolfire-machine-translations</Id> |
| 48 | <Name>Wolfire machine translations</Name> |
| 49 | <SupportedVersion>1.3.0</SupportedVersion> |
| 50 | </Mod> |
| 51 | """; |
| 52 | |
| 53 | private const string Landing = """ |
| 54 | <?xml version="2.0" ?> |
| 55 | <Type>saved</Type> |
| 56 | <LoadingScreen> |
| 57 | <Image>Data/LevelLoading/og_story/01_Landing.xml_loading.jpg</Image> |
| 58 | </LoadingScreen> |
| 59 | <Terrain> |
| 60 | <Heightmap>Data/Textures/Terrain/hm.png</Heightmap> |
| 61 | </Terrain> |
| 62 | <ActorObjects> |
| 63 | <ActorObject id="0" is_player="1" type_file="Data/Objects/IGF_Characters/TurnerActor.xml"/> |
| 64 | </ActorObjects> |
| 65 | <EnvObject id="1" type_file="Data/Objects/Rock.xml"/> |
| 66 | <EnvObject id="2" type_file="Data/Objects/gone.xml"/> |
| 67 | <!-- <EnvObject type_file="Data/Objects/commented.xml"/> --> |
| 68 | """; |
| 69 | |
| 70 | private static MemorySource Install(string version = Version, string location = InstallPath) |
| 71 | { |
| 72 | return new MemorySource(location, CaseRule.Insensitive) |
| 73 | .Add("Overgrowth.bin.x86_64", "\u007fELF") |
| 74 | .Add("lib64/libsteam_api.so", "\u007fELF") |
| 75 | .Add("Data/version.xml", version) |
| 76 | .Add("Data/defaults.txt", "screenwidth: 800") |
| 77 | .Add("Data/level_list", "Levels/og_story/01_Landing.xml") |
| 78 | .Add("Data/Campaign/campaign.xml", "<Campaign/>") |
| 79 | .Add("Data/LevelInfo/og_story/01_Landing.xml", "<LevelInfo/>") |
| 80 | .Add("Data/Mods/wolfire_overgrowth_core/mod.xml", CoreMod) |
| 81 | .Add("Data/Mods/wolfire_overgrowth_core/Data/Images/core/thumb.png", "png") |
| 82 | .Add("Data/Mods/wolfire_overgrowth_campaign/mod.xml", CampaignMod) |
| 83 | .Add("Data/Mods/wolfire_machine_translations/mod.xml", TranslationsMod) |
| 84 | .Add("Data/Mods/wolfire_machine_translations/Data/DialoguesLocalized/sv/start.txt", "Hej") |
| 85 | .Add("Data/ExampleMods/example_item_pack/mod.xml", "<Mod><Id>com-wolfire-example-item-pack</Id></Mod>") |
| 86 | .Add("Data/Objects/Rock.xml", """ |
| 87 | <Object> |
| 88 | <Model>Data/Models/Rock.obj</Model> |
| 89 | <ColorMap>Data/Textures/Rock_c.tga</ColorMap> |
| 90 | <NormalMap>data/textures/ROCK_N.tga</NormalMap> |
| 91 | <ShaderPath>Data/GLSL/envobject</ShaderPath> |
| 92 | </Object> |
| 93 | """) |
| 94 | .Add("Data/Models/Rock.obj", "v 0 0 0") |
| 95 | .Add("Data/Models/Rock.obj.cache", "cache") |
| 96 | .Add("Data/Models/Rock.obj_flipped.cache", "flipped") |
| 97 | .Add("Data/Models/Rock.obj.mcache", "dead") |
| 98 | .Add("Data/Models/Rock_col.obj", "v 0 0 0") |
| 99 | .Add("Data/Textures/Rock_c.tga_converted.dds", "DDS ") |
| 100 | .Add("Data/Textures/Rock_n.tga", "tga") |
| 101 | .Add("Data/Textures/Rock_n.tga_converted.dds", "DDS ") |
| 102 | .Add("Data/Textures/Rock_n.tga_image_sample_cache", "sample") |
| 103 | .Add("Data/Textures/Terrain/hm.png", "png") |
| 104 | .Add("Data/Textures/Terrain/hm.png_hmcache", "hm") |
| 105 | .Add("Data/Textures/Terrain/hm.png.cache", "mesh") |
| 106 | .Add("Data/Textures/Terrain/hm.png_normal.png", "normals") |
| 107 | .Add("Data/Textures/Terrain/hm.png_01_Landing_weights.png", "weights") |
| 108 | .Add("Data/Textures/Terrain/hm.png_02_Cut_weights.png", "another level's") |
| 109 | .Add("Data/Levels/og_story/01_Landing.xml", Landing) |
| 110 | .Add("Data/Levels/og_story/01_Landing.xml_refl_cap_1.hdrcube", "cube") |
| 111 | .Add("Data/Levels/og_story/01_Landing_2.xml", "<Type>saved</Type>") |
| 112 | .Add("Data/Levels/arenas/Cave_Arena.xml", "<Type>saved</Type>") |
| 113 | .Add("Data/Levels/proto/dev.xml", "<Type>saved</Type>") |
| 114 | .Add("Data/LevelNavmeshes/og_story/01_Landing.nav.zip", "PK") |
| 115 | .Add("Data/LevelNavmeshes/og_story/01_Landing.nav.xml", "<NavMesh/>") |
| 116 | .Add("Data/LevelLoading/og_story/01_Landing.xml_loading.jpg", "jpg") |
| 117 | .Add("Data/Objects/IGF_Characters/TurnerActor.xml", """ |
| 118 | <?xml version="1.0" ?> |
| 119 | <Actor> |
| 120 | <Character>Data/Characters/turner.xml</Character> |
| 121 | <ControlScript>enemycontrol.as</ControlScript> |
| 122 | </Actor> |
| 123 | """) |
| 124 | .Add("Data/Characters/turner.xml", """ |
| 125 | <character> |
| 126 | <appearance obj_path="Data/Objects/turner_obj.xml" skeleton="Data/Skeletons/r_turner.xml"/> |
| 127 | <attacks moving="Data/Attacks/haymaker.xml"/> |
| 128 | </character> |
| 129 | """) |
| 130 | .Add("Data/Characters/turner.xml.lod_cache", "lod") |
| 131 | .Add("Data/Objects/turner_obj.xml", "<Object><Model>Data/Models/Characters/turner.obj</Model></Object>") |
| 132 | .Add("Data/Models/Characters/turner.obj", "v 0 0 0") |
| 133 | .Add("Data/Skeletons/r_turner.xml", "<rig bone_path=\"Data/Skeletons/r_turner.phxbn\"/>") |
| 134 | .Add("Data/Skeletons/r_turner.phxbn", "bones") |
| 135 | .Add("Data/Attacks/haymaker.xml", "<attack/>") |
| 136 | .Add("Data/Animations/r_idle.anm", "anm") |
| 137 | .Add("Data/Items/sword.xml", "<item/>") |
| 138 | .Add("Data/Scripts/aschar.as", "void Update() {}") |
| 139 | .Add("Data/Sounds/hit.wav", "RIFF") |
| 140 | .Add("Data/Music/theme.ogg", "OggS") |
| 141 | .Add("Data/Dialogues/start.txt", "#name \"start\"") |
| 142 | .Add("Data/GLSL/envobject.frag", "void main() {}") |
| 143 | .Add("Data/UI/menu.html", "<html/>") |
| 144 | .Add("Data/Prototypes/test.obj", "v 0 0 0"); |
| 145 | } |
| 146 | |
| 147 | private static MemorySource WorkshopFolder(params (string Id, string ModId, string File)[] items) |
| 148 | { |
| 149 | var installed = string.Join("\n", |
| 150 | items.Select(item => $"\t\t\"{item.Id}\"\t{{ \"manifest\" \"9{item.Id}\" }}")); |
| 151 | var workshop = new MemorySource("/library/steamapps/workshop", CaseRule.Insensitive).Add( |
| 152 | "appworkshop_25000.acf", |
| 153 | $$""" |
| 154 | "AppWorkshop" |
| 155 | { |
| 156 | "appid" "25000" |
| 157 | "WorkshopItemsInstalled" |
| 158 | { |
| 159 | {{installed}} |
| 160 | } |
| 161 | } |
| 162 | """); |
| 163 | foreach (var (id, modId, file) in items) |
| 164 | workshop |
| 165 | .Add($"content/25000/{id}/mod.xml", |
| 166 | $"<Mod><Id>{modId}</Id><Name>{modId}</Name><SupportedVersion>*</SupportedVersion></Mod>") |
| 167 | .Add($"content/25000/{id}/{file}", $"from {id}"); |
| 168 | return workshop; |
| 169 | } |
| 170 | |
| 171 | private static ResolvedExternal Folder(External external, IFileSource files) |
| 172 | { |
| 173 | return new ResolvedExternal(external, ExternalState.Resolved, ExternalFrom.Hint) |
| 174 | { Files = files, Location = files.Location }; |
| 175 | } |
| 176 | |
| 177 | private static MountRegistry Registry() |
| 178 | { |
| 179 | var registry = new MountRegistry(); |
| 180 | registry.Add(new OvergrowthGame()); |
| 181 | return registry; |
| 182 | } |
| 183 | |
| 184 | private static Mount Open(MemorySource install, Externals? externals = null) |
| 185 | { |
| 186 | var registry = Registry(); |
| 187 | var probe = Assert.Single(registry.Probe(install, install.Location)); |
| 188 | externals ??= Externals.None; |
| 189 | return registry.Open(probe, new OvergrowthGame().Open(probe.Probe, externals), externals); |
| 190 | } |
| 191 | |
| 192 | private static string[] Files(Mount mount, string part) |
| 193 | { |
| 194 | return [.. mount.Part(part)!.DefiningFiles.Select(path => path.Value)]; |
| 195 | } |
| 196 | |
| 197 | [Fact] |
| 198 | public void ProbesTheBuildAndItsVersionFromVersionXml() |
| 199 | { |
| 200 | var probe = Assert.Single(Registry().Probe(Install(), InstallPath)); |
| 201 | |
| 202 | Assert.Equal((new MountId("overgrowth", "pc", "5583"), ProbeStatus.Known), (probe.Id, probe.Probe.Status)); |
| 203 | Assert.Equal( |
| 204 | [ |
| 205 | "Data/Mods/wolfire_overgrowth_core/mod.xml is com-wolfire-overgrowth-core", |
| 206 | "Data/version.xml names build 5583", "that build is version 1.4.0" |
| 207 | ], |
| 208 | probe.Probe.Evidence); |
| 209 | Assert.Equal(["steamapps", "depotcache", "workshop", "userdata"], |
| 210 | probe.Probe.Externals.Select(external => external.Name)); |
| 211 | } |
| 212 | |
| 213 | [Fact] |
| 214 | public void HintsTheWriteFolderTheWayTheGameFindsIt() |
| 215 | { |
| 216 | Assert.Equal(new ExternalHint.HostPath("/home/me/.local/share/Overgrowth"), |
| 217 | OvergrowthGame.Userdata("/home/me", "").Hint); |
| 218 | Assert.Equal(new ExternalHint.HostPath("/data/Overgrowth"), OvergrowthGame.Userdata("/home/me", "/data").Hint); |
| 219 | var windows = Install(); |
| 220 | windows.Remove("Overgrowth.bin.x86_64"); |
| 221 | Assert.Null(Assert.Single(Registry().Probe(windows, InstallPath)).Probe.Externals.Single(external => |
| 222 | external.Name == "userdata").Hint); |
| 223 | } |
| 224 | |
| 225 | [Fact] |
| 226 | public void ProbesAVersionFileWithNoBuildAsAnUnknownVariant() |
| 227 | { |
| 228 | var probe = Assert.Single(Registry().Probe(Install("<release><name>1.4.0</name></release>"), InstallPath)); |
| 229 | |
| 230 | Assert.Equal((new MountId("overgrowth", "pc", "unknown"), ProbeStatus.UnknownVariant), |
| 231 | (probe.Id, probe.Probe.Status)); |
| 232 | Assert.Contains("Data/version.xml names no build, so the build is unknown", probe.Probe.Evidence); |
| 233 | } |
| 234 | |
| 235 | [Fact] |
| 236 | public void DeclinesATreeWithoutTheCoreModOrAVersionFile() |
| 237 | { |
| 238 | var noCore = Install(); |
| 239 | noCore.Remove("Data/Mods/wolfire_overgrowth_core/mod.xml"); |
| 240 | var noVersion = Install(); |
| 241 | noVersion.Remove("Data/version.xml"); |
| 242 | |
| 243 | Assert.Empty(Registry().Probe(noCore, InstallPath)); |
| 244 | Assert.Empty(Registry().Probe(noVersion, InstallPath)); |
| 245 | } |
| 246 | |
| 247 | [Fact] |
| 248 | public void LaysEachCoreModOverTheInstallLeavingOtherModsOut() |
| 249 | { |
| 250 | var mount = Open(Install()); |
| 251 | |
| 252 | Assert.Equal( |
| 253 | [ |
| 254 | ("Data/Mods/wolfire_overgrowth_campaign", "core"), ("Data/Mods/wolfire_overgrowth_core", "core"), |
| 255 | ("install", "base") |
| 256 | ], |
| 257 | mount.Layers.Select(layer => (layer.Name, layer.Role))); |
| 258 | Assert.Equal("png", mount.Files.ReadAllText("Data/Images/core/thumb.png")); |
| 259 | Assert.True(mount.Files.Exists("Data/Mods/wolfire_overgrowth_core/mod.xml")); |
| 260 | Assert.False(mount.Files.Exists("Data/DialoguesLocalized/sv/start.txt")); |
| 261 | Assert.Equal( |
| 262 | [ |
| 263 | "Data/Mods/wolfire_overgrowth_campaign/mod.xml", "Data/Mods/wolfire_overgrowth_core/mod.xml", |
| 264 | "Data/version.xml" |
| 265 | ], |
| 266 | new OvergrowthGame().Open(new OvergrowthGame().Probe(Install())!, Externals.None).BuildFiles |
| 267 | .Select(path => path.Value).Order(StringComparer.Ordinal)); |
| 268 | } |
| 269 | |
| 270 | [Fact] |
| 271 | public void NamesItsPartsAfterWhatAPluginReads() |
| 272 | { |
| 273 | var mount = Open(Install()); |
| 274 | |
| 275 | Assert.Equal( |
| 276 | [ |
| 277 | "props", "characters", "moves", "level/og_story/01_Landing", "level/arenas/Cave_Arena", "scripts", |
| 278 | "sounds", "dialogues", "config", "mod/wolfire_machine_translations" |
| 279 | ], |
| 280 | mount.Parts.Select(part => part.Name)); |
| 281 | Assert.All(mount.Parts, part => Assert.True(part.Sha1Claims)); |
| 282 | Assert.Equal(["Data/Scripts/aschar.as"], Files(mount, "scripts")); |
| 283 | Assert.Equal(["Data/Music/theme.ogg", "Data/Sounds/hit.wav"], Files(mount, "sounds")); |
| 284 | Assert.Equal( |
| 285 | [ |
| 286 | "Data/Campaign/campaign.xml", "Data/LevelInfo/og_story/01_Landing.xml", |
| 287 | "Data/Mods/wolfire_overgrowth_campaign/mod.xml", "Data/Mods/wolfire_overgrowth_core/mod.xml", |
| 288 | "Data/defaults.txt", "Data/level_list", "Data/version.xml" |
| 289 | ], |
| 290 | Files(mount, "config")); |
| 291 | } |
| 292 | |
| 293 | [Fact] |
| 294 | public void HoldsEachPropWithTheTwinsTheEngineReadsAndNotTheDeadCaches() |
| 295 | { |
| 296 | var mount = Open(Install()); |
| 297 | |
| 298 | Assert.Equal( |
| 299 | [ |
| 300 | "Data/Models/Rock.obj", "Data/Models/Rock.obj.cache", "Data/Models/Rock.obj_flipped.cache", |
| 301 | "Data/Models/Rock_col.obj", "Data/Objects/Rock.xml", "Data/Textures/Rock_c.tga_converted.dds", |
| 302 | "Data/Textures/Rock_n.tga", "Data/Textures/Rock_n.tga_converted.dds", |
| 303 | "Data/Textures/Rock_n.tga_image_sample_cache" |
| 304 | ], |
| 305 | Files(mount, "props")); |
| 306 | Assert.Contains( |
| 307 | "Data/Mods/wolfire_overgrowth_core/mod.xml names Data/Objects/Gone.xml, which isn't in the install.", |
| 308 | mount.Notes); |
| 309 | } |
| 310 | |
| 311 | [Fact] |
| 312 | public void ReadsALevelNamedByItsTextOrItsPathWithItsTitleAndCampaign() |
| 313 | { |
| 314 | var mod = ModXml.Parse("Data/Mods/a", """ |
| 315 | <Mod> |
| 316 | <Id>com-wolfire-timbles-therium</Id> |
| 317 | <Name>Therium-2</Name> |
| 318 | <Campaign title="Therium-2"> |
| 319 | <Level id="tutorial" thumbnail="Textures/ui/t2/tutorial.jpg" title="Tutorial" path="t2/tutorial.xml"> |
| 320 | <Parameter name="x" /> |
| 321 | </Level> |
| 322 | <Level title="Village">LugaruStory/Village.xml</Level> |
| 323 | </Campaign> |
| 324 | <Level title="Loose">loose.xml</Level> |
| 325 | </Mod> |
| 326 | """, [])!; |
| 327 | |
| 328 | Assert.Equal( |
| 329 | [ |
| 330 | new ModLevel("t2/tutorial.xml", "Tutorial", "Textures/ui/t2/tutorial.jpg", "Therium-2"), |
| 331 | new ModLevel("LugaruStory/Village.xml", "Village", null, "Therium-2"), |
| 332 | new ModLevel("loose.xml", "Loose", null, null) |
| 333 | ], |
| 334 | mod.Levels); |
| 335 | } |
| 336 | |
| 337 | [Fact] |
| 338 | public void HoldsALevelWithItsSideFilesAndWhatItPlacesButNotWhatItsCommentsName() |
| 339 | { |
| 340 | var mount = Open(Install()); |
| 341 | |
| 342 | Assert.Equal(new[] |
| 343 | { |
| 344 | "Data/Characters/turner.xml", "Data/Characters/turner.xml.lod_cache", |
| 345 | "Data/LevelLoading/og_story/01_Landing.xml_loading.jpg", |
| 346 | "Data/LevelNavmeshes/og_story/01_Landing.nav.xml", "Data/LevelNavmeshes/og_story/01_Landing.nav.zip", |
| 347 | "Data/Levels/og_story/01_Landing.xml", "Data/Levels/og_story/01_Landing.xml_refl_cap_1.hdrcube", |
| 348 | "Data/Models/Characters/turner.obj", "Data/Models/Rock.obj", "Data/Models/Rock.obj.cache", |
| 349 | "Data/Models/Rock.obj_flipped.cache", "Data/Objects/IGF_Characters/TurnerActor.xml", |
| 350 | "Data/Objects/Rock.xml", "Data/Objects/turner_obj.xml", "Data/Skeletons/r_turner.phxbn", |
| 351 | "Data/Skeletons/r_turner.xml", "Data/Attacks/haymaker.xml", |
| 352 | "Data/Textures/Rock_c.tga_converted.dds", "Data/Textures/Rock_n.tga", |
| 353 | "Data/Textures/Rock_n.tga_converted.dds", "Data/Textures/Rock_n.tga_image_sample_cache", |
| 354 | "Data/Textures/Terrain/hm.png", "Data/Textures/Terrain/hm.png_hmcache", |
| 355 | "Data/Models/Rock_col.obj", "Data/Textures/Terrain/hm.png.cache", |
| 356 | "Data/Textures/Terrain/hm.png_normal.png", |
| 357 | "Data/Textures/Terrain/hm.png_01_Landing_weights.png" |
| 358 | }.Order(StringComparer.Ordinal), |
| 359 | Files(mount, "level/og_story/01_Landing")); |
| 360 | Assert.Contains("Data/Levels/og_story/01_Landing.xml names Data/Objects/gone.xml, which isn't in the install.", |
| 361 | mount.Notes); |
| 362 | Assert.DoesNotContain(mount.Notes, note => note.Contains("commented.xml") || note.Contains("02_Cut")); |
| 363 | Assert.DoesNotContain(mount.Parts, part => part.Name.Contains("dev") || part.Name.Contains("01_Landing_2")); |
| 364 | } |
| 365 | |
| 366 | [Fact] |
| 367 | public void FollowsActorsIntoTheirCharactersAndMovesIntoWhatTheyName() |
| 368 | { |
| 369 | var mount = Open(Install()); |
| 370 | |
| 371 | Assert.Equal( |
| 372 | [ |
| 373 | "Data/Attacks/haymaker.xml", "Data/Characters/turner.xml", "Data/Characters/turner.xml.lod_cache", |
| 374 | "Data/Models/Characters/turner.obj", "Data/Objects/IGF_Characters/TurnerActor.xml", |
| 375 | "Data/Objects/turner_obj.xml", "Data/Skeletons/r_turner.phxbn", "Data/Skeletons/r_turner.xml" |
| 376 | ], |
| 377 | Files(mount, "characters")); |
| 378 | Assert.Equal( |
| 379 | [ |
| 380 | "Data/Animations/r_idle.anm", "Data/Attacks/haymaker.xml", "Data/Items/sword.xml", |
| 381 | "Data/Skeletons/r_turner.phxbn", "Data/Skeletons/r_turner.xml" |
| 382 | ], |
| 383 | Files(mount, "moves")); |
| 384 | } |
| 385 | |
| 386 | [Fact] |
| 387 | public void ListsAModTheGameStartsOffAsAPartWithANote() |
| 388 | { |
| 389 | var mount = Open(Install()); |
| 390 | |
| 391 | Assert.Equal( |
| 392 | [ |
| 393 | "Data/Mods/wolfire_machine_translations/Data/DialoguesLocalized/sv/start.txt", |
| 394 | "Data/Mods/wolfire_machine_translations/mod.xml" |
| 395 | ], |
| 396 | Files(mount, "mod/wolfire_machine_translations")); |
| 397 | Assert.Contains( |
| 398 | "Wolfire machine translations (Data/Mods/wolfire_machine_translations) is off: the game starts a mod from its own folder off.", |
| 399 | mount.Notes); |
| 400 | Assert.Contains( |
| 401 | "Wolfire machine translations (Data/Mods/wolfire_machine_translations) doesn't list 1.4.0 among its supported versions, which the game only warns about.", |
| 402 | mount.Notes); |
| 403 | } |
| 404 | |
| 405 | [Fact] |
| 406 | public void LeavesTheExecutablesRendererMenusAndWorkInProgressOutOfEveryPart() |
| 407 | { |
| 408 | var mount = Open(Install()); |
| 409 | |
| 410 | Assert.All(mount.Parts, part => Assert.DoesNotContain(part.DefiningFiles, path => |
| 411 | path.Value.StartsWith("Data/GLSL/") || path.Value.StartsWith("Data/UI/") || |
| 412 | path.Value.StartsWith("Data/Prototypes/") || path.Value.StartsWith("Data/ExampleMods/") || |
| 413 | path.Value.StartsWith("lib64/") || path.Value.EndsWith(".mcache") || |
| 414 | path.Value == "Overgrowth.bin.x86_64")); |
| 415 | } |
| 416 | |
| 417 | [Fact] |
| 418 | public void LaysAWorkshopModOverTheGameAsItsOwnPartLeavingTheGamesPartsAlone() |
| 419 | { |
| 420 | var workshop = WorkshopFolder(("123", "com-someone-red-rock", "Data/Textures/Rock_c.tga_converted.dds")); |
| 421 | var without = Open(Install()); |
| 422 | |
| 423 | var mount = Open(Install(), new Externals([Folder(Workshop.External, workshop)])); |
| 424 | |
| 425 | Assert.Equal(("workshop/123", "workshop"), (mount.Layers[0].Name, mount.Layers[0].Role)); |
| 426 | Assert.Equal("from 123", mount.Files.ReadAllText("Data/Textures/Rock_c.tga_converted.dds")); |
| 427 | Assert.Equal(["content/25000/123/Data/Textures/Rock_c.tga_converted.dds", "content/25000/123/mod.xml"], |
| 428 | Files(mount, "workshop/123")); |
| 429 | Assert.Contains("com-someone-red-rock (workshop/123) is on, as the game starts a workshop mod.", mount.Notes); |
| 430 | Assert.Equal(without.Part("props")!.Fingerprint, mount.Part("props")!.Fingerprint); |
| 431 | } |
| 432 | |
| 433 | [Fact] |
| 434 | public void NotesTwoWorkshopModsReplacingOneFileAndTheOneThatWins() |
| 435 | { |
| 436 | var workshop = WorkshopFolder(("7", "com-b", "Data/Textures/Rock_c.tga_converted.dds"), |
| 437 | ("8", "com-a", "Data/Textures/Rock_c.tga_converted.dds")); |
| 438 | |
| 439 | var mount = Open(Install(), new Externals([Folder(Workshop.External, workshop)])); |
| 440 | |
| 441 | Assert.Equal("from 8", mount.Files.ReadAllText("Data/Textures/Rock_c.tga_converted.dds")); |
| 442 | Assert.Contains( |
| 443 | "workshop/7 and workshop/8 both replace Data/Textures/Rock_c.tga_converted.dds; workshop/8 wins, as its Id comes first.", |
| 444 | mount.Notes); |
| 445 | } |
| 446 | |
| 447 | [Fact] |
| 448 | public void ListsAModInTheWriteFolderAsOffAndNotesSharedIds() |
| 449 | { |
| 450 | var userdata = new MemorySource("/home/me/.local/share/Overgrowth", CaseRule.Sensitive) |
| 451 | .Add("Data/Mods/mine/mod.xml", |
| 452 | "<Mod><Id>com-wolfire-machine-translations</Id><Name>Mine</Name><SupportedVersion>*</SupportedVersion></Mod>") |
| 453 | .Add("Data/Mods/mine/Data/Textures/Rock_c.tga_converted.dds", "mine"); |
| 454 | |
| 455 | var mount = Open(Install(), new Externals([Folder(OvergrowthGame.Userdata("/home/me", ""), userdata)])); |
| 456 | |
| 457 | Assert.Equal(["Data/Mods/mine/Data/Textures/Rock_c.tga_converted.dds", "Data/Mods/mine/mod.xml"], |
| 458 | Files(mount, "mod/mine")); |
| 459 | Assert.Contains("Mine (userdata/Data/Mods/mine) is off: the game starts a mod from its own folder off.", |
| 460 | mount.Notes); |
| 461 | Assert.Contains( |
| 462 | "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.", |
| 463 | mount.Notes); |
| 464 | Assert.Equal("DDS ", mount.Files.ReadAllText("Data/Textures/Rock_c.tga_converted.dds")); |
| 465 | } |
| 466 | |
| 467 | [Fact] |
| 468 | public void FingerprintsASteamCopyByItsClaimsAsACopyFromElsewhere() |
| 469 | { |
| 470 | var install = Install(); |
| 471 | var depot = new DepotManifestWriter(25002, 8572447376951838510); |
| 472 | foreach (var entry in install.EnumerateAll()) |
| 473 | depot.File(entry.Path.Value.Replace('/', '\\'), install.ReadAllText(entry.Path)); |
| 474 | var steamapps = new MemorySource("/library/steamapps", CaseRule.Insensitive).Add("appmanifest_25000.acf", |
| 475 | """ |
| 476 | "AppState" |
| 477 | { |
| 478 | "appid" "25000" |
| 479 | "StateFlags" "4" |
| 480 | "installdir" "Overgrowth" |
| 481 | "InstalledDepots" |
| 482 | { |
| 483 | "25002" |
| 484 | { |
| 485 | "manifest" "8572447376951838510" |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | """); |
| 490 | var depotcache = new MemorySource("/library/depotcache", CaseRule.Insensitive) |
| 491 | .Add("25002_8572447376951838510.manifest", depot.Build()); |
| 492 | var game = new OvergrowthGame(); |
| 493 | |
| 494 | var steam = game.Open(game.Probe(install)!, |
| 495 | new Externals([Folder(SteamClaims.Steamapps, steamapps), Folder(SteamClaims.Depotcache, depotcache)])); |
| 496 | var elsewhere = game.Open(game.Probe(Install(location: "/run/media/me/Overgrowth"))!, Externals.None); |
| 497 | |
| 498 | Assert.All(steam.Parts, part => Assert.Equal(part.DefiningFiles.Count, part.Claims.Count)); |
| 499 | Assert.All(elsewhere.Parts, part => Assert.Empty(part.Claims)); |
| 500 | foreach (var (claimed, read) in steam.Parts.Zip(elsewhere.Parts)) |
| 501 | Assert.Equal(Fingerprint.Of(install, read.DefiningFiles, sha1Claims: true), |
| 502 | Fingerprint.Of(install, claimed.DefiningFiles, claims: claimed.Claims, sha1Claims: true)); |
| 503 | } |
| 504 | |
| 505 | [Fact] |
| 506 | public void MountsARealOvergrowthInstall() |
| 507 | { |
| 508 | var install = Environment.GetEnvironmentVariable("EVIL_OVERGROWTH"); |
| 509 | Assert.SkipWhen(install is null, "Set EVIL_OVERGROWTH to an Overgrowth install to read it."); |
| 510 | var registry = Registry(); |
| 511 | var probe = Assert.Single(registry.Probe(install!)); |
| 512 | Assert.Equal(new MountId("overgrowth", "pc", "5583"), probe.Id); |
| 513 | Assert.Contains("that build is version 1.4.0", probe.Probe.Evidence); |
| 514 | |
| 515 | registry.Close(registry.Open(probe)); |
| 516 | var timer = Stopwatch.StartNew(); |
| 517 | var mount = registry.Open(probe); |
| 518 | var opened = timer.Elapsed; |
| 519 | |
| 520 | Assert.Equal(["core", "core", "core", "core", "core", "core", "core", "core", "base"], |
| 521 | mount.Layers.Select(layer => layer.Role)); |
| 522 | Assert.Equal(21499, mount.Files.EnumerateAll().Count()); |
| 523 | Assert.DoesNotContain(mount.Notes, |
| 524 | note => note.Contains("hash from their bytes") || note.Contains("hashes from")); |
| 525 | Assert.All(mount.Parts, part => Assert.Equal(part.DefiningFiles.Count, part.Claims.Count)); |
| 526 | var files = mount.Parts.ToDictionary(part => part.Name, part => part.DefiningFiles.Count); |
| 527 | Assert.Equal(5918, files["props"]); |
| 528 | Assert.Equal(737, files["characters"]); |
| 529 | Assert.Equal(1159, files["moves"]); |
| 530 | Assert.Equal(1756, files["level/og_story/27_Sky_Ark"]); |
| 531 | Assert.Equal(212, files["scripts"]); |
| 532 | Assert.Equal(3069, files["sounds"]); |
| 533 | Assert.Equal(573, files["dialogues"]); |
| 534 | Assert.Equal(391, files["config"]); |
| 535 | Assert.Equal(3286, files["mod/wolfire_machine_translations"]); |
| 536 | Assert.Equal(127, mount.Parts.Count(part => part.Name.StartsWith("level/"))); |
| 537 | Assert.Equal(988, mount.Notes.Count(note => note.EndsWith("which isn't in the install."))); |
| 538 | Assert.Contains( |
| 539 | "Wolfire machine translations (Data/Mods/wolfire_machine_translations) is off: the game starts a mod from its own folder off.", |
| 540 | mount.Notes); |
| 541 | TestContext.Current.TestOutputHelper?.WriteLine($"Opened in {opened.TotalMilliseconds:F0} ms."); |
| 542 | } |
| 543 | } |