0.2.0-dev Download ZIP
226 lines ·10.0 KB Raw
| 1 | using System.Text; |
| 2 | using EvilEngine.Adapters.EaBig; |
| 3 | using EvilEngine.Adapters.Iso9660; |
| 4 | using EvilEngine.Adapters.Skate3; |
| 5 | using EvilEngine.Adapters.Tests.Support; |
| 6 | using EvilEngine.Mounts; |
| 7 | |
| 8 | namespace EvilEngine.Adapters.Tests; |
| 9 | |
| 10 | public sealed class Skate3Tests : IDisposable |
| 11 | { |
| 12 | private static readonly string Record = string.Concat(Enumerable.Range(0, 30).Select(i => $"trick {i}\n")); |
| 13 | |
| 14 | private readonly string _folder = Path.Combine(Path.GetTempPath(), $"evil-skate3-{Guid.NewGuid():N}"); |
| 15 | |
| 16 | public void Dispose() |
| 17 | { |
| 18 | if (Directory.Exists(_folder)) |
| 19 | Directory.Delete(_folder, true); |
| 20 | } |
| 21 | |
| 22 | private static MountRegistry Registry() |
| 23 | { |
| 24 | var registry = new MountRegistry(); |
| 25 | registry.Add(new Iso9660Container()); |
| 26 | registry.Add(new EbContainer()); |
| 27 | registry.Add(new Skate3Game()); |
| 28 | return registry; |
| 29 | } |
| 30 | |
| 31 | private static List<(string Path, byte[] Data)> Disc(string titleId = "BLUS30464", string eboot = "SCE\0self", |
| 32 | bool character = true, string onBoard = "ollie", string stream = "<stream/>") |
| 33 | { |
| 34 | var usr = "PS3_GAME/USRDIR/"; |
| 35 | var files = new List<(string, byte[])> |
| 36 | { |
| 37 | ("PS3_DISC.SFB", Ps3Files.DiscSfb(titleId.Insert(4, "-"))), |
| 38 | ("PS3_GAME/PARAM.SFO", |
| 39 | Ps3Files.ParamSfo(("TITLE_ID", titleId), ("VERSION", "01.00"), ("APP_VER", "01.00"), |
| 40 | ("TITLE", "Skate 3"))), |
| 41 | (usr + "EBOOT.BIN", Encoding.ASCII.GetBytes(eboot)), |
| 42 | (usr + "data/big/miscload.big", |
| 43 | new EbWriter().Add("data/anim/SkaterBodyPres.abin", Record, EbCompression.RefPack) |
| 44 | .Add("data/anim/OnBoard.abin", onBoard + Record, EbCompression.RefPack) |
| 45 | .Add("data/stream/ol_hom_urbanres.xml", stream).Build(6)), |
| 46 | (usr + "data/big/miscboot.big", |
| 47 | new EbWriter().Add("data/webkit/Content/images/skate_feed_logo.png", "png").Build(6)), |
| 48 | (usr + "data/big/db.big", |
| 49 | new EbWriter().Add("data/db/challenge_local_data/domination_test_01.vlt", Record, EbCompression.RefPack) |
| 50 | .Build(6)), |
| 51 | (usr + "data/big/fedata.big", |
| 52 | new EbWriter().Add("data/fe/source/controls/list_item_awardbox.geo", "geo").Build(6)), |
| 53 | (usr + "data/big/fedynamic.big", |
| 54 | new EbWriter().Add("data/fe/source/controls/list_item_awardbox.geo", "geo").Build(6)), |
| 55 | (usr + "data/content/worldDIST_StartPark.big", |
| 56 | new EbWriter().Add("data/content/world/stream/DIST_StartPark/cPres_50_-50_high.psf", Record, |
| 57 | EbCompression.ChunkRef).Build()), |
| 58 | (usr + "data/content/characterVersion.txt", "12345678"u8.ToArray()), |
| 59 | (usr + "data/content/global_locators/PARK/DIST_StartPark/DIST_StartPa_[0x18f5bf0dd72c75c8].psg", |
| 60 | "locator"u8.ToArray()), |
| 61 | (usr + "data/audio/audiofiles.big", new EbWriter().Add("data/audio/water_brook.abk", "abk").Build(6)), |
| 62 | (usr + "data/audio/english/nis.big", new EbWriter().Add("31_5044_TUT-JORD_2.sns", "speech").Build()), |
| 63 | (usr + "data/audio/music/overlays.big", "BIG4\x82r\x07\0"u8.ToArray()), |
| 64 | (usr + "data/fe/subtitles/subtitles.big", |
| 65 | new EbWriter().Add("data/fe/subtitles/SubTitles_English/film_dwtn_01_intro.sub", "sub").Build(6)), |
| 66 | ("PS3_UPDATE/PS3UPDAT.PUP", "SCEUF"u8.ToArray()) |
| 67 | }; |
| 68 | if (character) |
| 69 | files.Add((usr + "data/content/createacharacter.big", |
| 70 | new EbWriter().Add("data/content/createacharacter/texture/0x2c7f381800171b5b.psg", Record, |
| 71 | EbCompression.ChunkRef).Build(6))); |
| 72 | return files; |
| 73 | } |
| 74 | |
| 75 | private static MemorySource Folder(IEnumerable<(string Path, byte[] Data)> files) |
| 76 | { |
| 77 | var folder = new MemorySource("BLUS30464", CaseRule.Sensitive); |
| 78 | foreach (var (path, data) in files) |
| 79 | folder.Add(path, data); |
| 80 | return folder; |
| 81 | } |
| 82 | |
| 83 | private static byte[] Image(IEnumerable<(string Path, byte[] Data)> files) |
| 84 | { |
| 85 | var writer = new IsoWriter(); |
| 86 | foreach (var (path, data) in files) |
| 87 | writer.Add(path, data); |
| 88 | return writer.Build(); |
| 89 | } |
| 90 | |
| 91 | private string Write(byte[] image) |
| 92 | { |
| 93 | Directory.CreateDirectory(_folder); |
| 94 | var path = Path.Combine(_folder, "Skate 3.dec.iso"); |
| 95 | File.WriteAllBytes(path, image); |
| 96 | return path; |
| 97 | } |
| 98 | |
| 99 | [Fact] |
| 100 | public void ProbesTheImageThroughIso9660() |
| 101 | { |
| 102 | var registry = Registry(); |
| 103 | |
| 104 | var probe = Assert.Single(registry.Probe(Write(Image(Disc())))); |
| 105 | |
| 106 | Assert.Equal(new MountId("skate3", "ps3", "BLUS30464-01.00"), probe.Id); |
| 107 | Assert.Equal(ProbeStatus.Known, probe.Probe.Status); |
| 108 | Assert.Equal(["iso9660"], probe.ContainerChain); |
| 109 | Assert.Contains("BLUS30464 is Skate 3 (USA, Asia)", probe.Probe.Evidence); |
| 110 | } |
| 111 | |
| 112 | [Fact] |
| 113 | public void LayersTheArchivesNamedFromDataOverUsrdir() |
| 114 | { |
| 115 | var registry = Registry(); |
| 116 | var mount = registry.Open(registry.Probe(Write(Image(Disc())))[0]); |
| 117 | |
| 118 | Assert.Equal( |
| 119 | [ |
| 120 | "data/audio/audiofiles.big", "data/big/db.big", "data/big/fedata.big", "data/big/fedynamic.big", |
| 121 | "data/big/miscboot.big", |
| 122 | "data/big/miscload.big", "data/content/createacharacter.big", "data/content/worldDIST_StartPark.big", |
| 123 | "data/fe/subtitles/subtitles.big", "USRDIR" |
| 124 | ], |
| 125 | mount.Layers.Select(layer => layer.Name)); |
| 126 | Assert.Equal(Record, mount.Files.ReadAllText("data/anim/SkaterBodyPres.abin")); |
| 127 | Assert.Equal(Record, mount.Files.ReadAllText("data/content/world/stream/DIST_StartPark/cPres_50_-50_high.psf")); |
| 128 | Assert.Equal("12345678", mount.Files.ReadAllText("data/content/characterVersion.txt")); |
| 129 | Assert.Equal("data/big/fedata.big", mount.Origin("data/fe/source/controls/list_item_awardbox.geo")!.Layer.Name); |
| 130 | Assert.Equal("data/content/worldDIST_StartPark.big", |
| 131 | mount.Origin("data/content/world/stream/DIST_StartPark/cPres_50_-50_high.psf")!.Layer.Name); |
| 132 | Assert.Equal("USRDIR", mount.Origin("data/audio/english/nis.big")!.Layer.Name); |
| 133 | Assert.False(mount.Files.Exists("31_5044_TUT-JORD_2.sns")); |
| 134 | Assert.False(mount.Files.Exists("PS3_UPDATE/PS3UPDAT.PUP")); |
| 135 | Assert.Equal(CaseRule.Sensitive, mount.Files.CaseRule); |
| 136 | } |
| 137 | |
| 138 | [Fact] |
| 139 | public void ProbesAndFingerprintsAJbFolderTheSameAsTheImage() |
| 140 | { |
| 141 | var fromImage = Registry(); |
| 142 | var image = fromImage.Open(fromImage.Probe(Write(Image(Disc())))[0]); |
| 143 | var fromFolder = Registry(); |
| 144 | var folderProbe = Assert.Single(fromFolder.Probe(Folder(Disc()), "BLUS30464")); |
| 145 | var folder = fromFolder.Open(folderProbe); |
| 146 | |
| 147 | Assert.Equal(image.Id, folder.Id); |
| 148 | Assert.Empty(folderProbe.ContainerChain); |
| 149 | Assert.Equal(image.Build, folder.Build); |
| 150 | Assert.Equal(image.Part("gameplay")!.Fingerprint, folder.Part("gameplay")!.Fingerprint); |
| 151 | Assert.Equal(image.Part("character")!.Fingerprint, folder.Part("character")!.Fingerprint); |
| 152 | Assert.Equal(image.Files.EnumerateAll().Count(), folder.Files.EnumerateAll().Count()); |
| 153 | } |
| 154 | |
| 155 | [Fact] |
| 156 | public void SatisfiesARequirementOnTheGameplayPart() |
| 157 | { |
| 158 | var registry = Registry(); |
| 159 | registry.Open(registry.Probe(Folder(Disc()), "BLUS30464")[0]); |
| 160 | |
| 161 | Assert.True(registry.Satisfies(new MountRequirement("skate3") { Parts = ["gameplay"] }).IsSatisfied); |
| 162 | Assert.True(registry.Satisfies(new MountRequirement("skate3") |
| 163 | { Platforms = ["ps3"], Builds = ["BLUS30464-01.00"] }).IsSatisfied); |
| 164 | Assert.Equal(SatisfactionStatus.NotMounted, |
| 165 | registry.Satisfies(new MountRequirement("skate3") { Platforms = ["x360"] }).Status); |
| 166 | Assert.Equal(SatisfactionStatus.MissingParts, |
| 167 | registry.Satisfies(new MountRequirement("skate3") { Parts = ["skating"] }).Status); |
| 168 | } |
| 169 | |
| 170 | [Fact] |
| 171 | public void FingerprintsTheGameplayPartFromTheFilesInsideItsArchives() |
| 172 | { |
| 173 | Mount Open(List<(string Path, byte[] Data)> files) |
| 174 | { |
| 175 | return Registry().Open(Registry().Probe(Folder(files), "BLUS30464")[0]); |
| 176 | } |
| 177 | |
| 178 | var first = Open(Disc()); |
| 179 | var unrelatedChange = Open(Disc(stream: "<stream changed/>")); |
| 180 | var gameplayChange = Open(Disc(onBoard: "kickflip")); |
| 181 | |
| 182 | Assert.Equal(first.Part("gameplay")!.Fingerprint, unrelatedChange.Part("gameplay")!.Fingerprint); |
| 183 | Assert.NotEqual(first.Part("gameplay")!.Fingerprint, gameplayChange.Part("gameplay")!.Fingerprint); |
| 184 | Assert.Equal(first.Part("rig")!.Fingerprint, gameplayChange.Part("rig")!.Fingerprint); |
| 185 | Assert.Contains((VirtualPath)"data/anim/OnBoard.abin", first.Part("gameplay")!.DefiningFiles); |
| 186 | } |
| 187 | |
| 188 | [Fact] |
| 189 | public void NamesAPartForEachWorldWithItsLocators() |
| 190 | { |
| 191 | var mount = Registry().Open(Registry().Probe(Folder(Disc()), "BLUS30464")[0]); |
| 192 | |
| 193 | Assert.Equal(["gameplay", "controls", "rig", "character", "skatepark", "world/startpark"], |
| 194 | mount.Parts.Select(part => part.Name)); |
| 195 | Assert.Equal( |
| 196 | [ |
| 197 | "data/content/worldDIST_StartPark.big", |
| 198 | "data/content/global_locators/PARK/DIST_StartPark/DIST_StartPa_[0x18f5bf0dd72c75c8].psg" |
| 199 | ], |
| 200 | mount.Part("world/startpark")!.DefiningFiles.Select(path => path.Value)); |
| 201 | } |
| 202 | |
| 203 | [Fact] |
| 204 | public void ReportsAnEncryptedImageAsNeedingItsKey() |
| 205 | { |
| 206 | var probe = Assert.Single(Registry().Probe(Folder(Disc(eboot: "\x9f\x31scrambled")), "BLUS30464")); |
| 207 | |
| 208 | Assert.Equal(ProbeStatus.NeedsKey, probe.Probe.Status); |
| 209 | Assert.Equal(new MountId("skate3", "ps3", "BLUS30464-01.00"), probe.Id); |
| 210 | } |
| 211 | |
| 212 | [Fact] |
| 213 | public void ReportsADiscMissingAnArchiveAsDamaged() |
| 214 | { |
| 215 | var probe = Assert.Single(Registry().Probe(Folder(Disc(character: false)), "BLUS30464")); |
| 216 | |
| 217 | Assert.Equal(ProbeStatus.Damaged, probe.Probe.Status); |
| 218 | Assert.Contains("PS3_GAME/USRDIR/data/content/createacharacter.big is missing", probe.Probe.Evidence); |
| 219 | } |
| 220 | |
| 221 | [Fact] |
| 222 | public void LeavesAnotherPs3GameAlone() |
| 223 | { |
| 224 | Assert.Empty(Registry().Probe(Folder(Disc("BLUS30187")), "another")); |
| 225 | } |
| 226 | } |