public ExpectZeroes ( int size, int count ) : bool | ||
size | int | |
count | int | |
Результат | bool |
internal PictureCel(Picture picture, int celIndex, AssetLoader loader) : base(loader) { Name = "Cel " + celIndex; BinaryReader reader = loader.Reader; reader.BaseStream.Position = 0x0E + celIndex * 0x2A; Vector2i dimensions = new Vector2i(reader.ReadUInt16(), reader.ReadUInt16()); Displacement = new Vector2i(reader.ReadUInt16(), reader.ReadUInt16()); MaskIndex = reader.ReadByte(); loader.ExpectZeroes(1, 3); Unknowns.ReadInt32s(reader, 2, "Data offsets?"); loader.ExpectZeroes(4, 1); int dataOffset = reader.ReadInt32(); loader.ExpectZeroes(4, 2); Priority = reader.ReadUInt16(); Offset = new Vector2i(reader.ReadUInt16(), reader.ReadUInt16()) * 2; if (Offset.Y > 0) Offset = new Vector2i(Offset.X, Offset.Y * 6 / 5); reader.BaseStream.Position = dataOffset; int[] indices = reader.ReadBytesAsInt32(dimensions.Product); Setup(picture.Palette.PaletteAsset, dimensions.X, dimensions.Y, indices); }
internal Rom(AssetLoader loader) : base(loader) { BinaryReader reader = Reader = loader.Reader; Codex<RomFile> files = new Codex<RomFile>(); Codex<RomFolder> folders = new Codex<RomFolder>(); Files = files; Folders = folders; GameTitle = Reader.ReadStringz(12, Encoding.ASCII); GameCode = Reader.ReadStringz(4, Encoding.ASCII); // Offset 0x10 MakerCode = Reader.ReadStringz(2, Encoding.ASCII); UnitCode = reader.ReadByte(); DeviceCode = reader.ReadByte(); CardSizeBase = reader.ReadByte(); loader.ExpectZeroes(1, 7); Unknowns.ReadInt32s(reader, 1); // Usually 0, Alice in Wonderland: 3 // Offset 0x20 PageSize = reader.ReadInt32(); // Usually (always?) 0x4000 Unknowns.ReadInt16s(reader, 2); // The Dark Spire: 0x800; Trauma Center: 0xF780 (-2176) loader.Expect(0x2000000); Unknowns.ReadInt32s(reader, 1); // The Dark Spire: 0x9BEF8; Trauma Center: 0x1DC518 // Offset 0x30 Unknowns.ReadInt32s(reader, 1); // Entry points? The Dark Spire: 0x152200; Trauma Center: 0x1E0600 loader.Expect(0x2380000); loader.Expect(0x2380000); Unknowns.ReadInt16s(reader, 1); // The Dark Spire: 0x6F28; Trauma Center: 0x6F24 loader.Expect((short)0x2); // Offset 0x40 int fileNameTableOffset = reader.ReadInt32(); int fileNameTableSize = reader.ReadInt32(); int fileSizeTableOffset = reader.ReadInt32(); int fileSizeTableSize = reader.ReadInt32(); // Offset 0x50 Unknowns.ReadInt32s(reader, 2, "Offset and size"); // Used in The Dark Spire, zeroes in Trauma Center. loader.ExpectZeroes(4, 2); // Offset 0x60 Unknowns.ReadInt32s(reader, 2); int iconAndTitleOffset = reader.ReadInt32(); Unknowns.ReadInt32s(reader, 1); // Offset 0x70 Unknowns.ReadInt32s(reader, 2); loader.ExpectZeroes(4, 2); // Offset 0x80 DataLength = reader.ReadInt32(); loader.Expect(PageSize); Unknowns.ReadInt32s(reader, 2); // The Dark Spire: 0x4B68; 0 in Trauma Center. ReadIconAndTitle(iconAndTitleOffset); if (fileNameTableOffset > 0) { int folderNamesOffset = reader.ReadInt32At(fileNameTableOffset); reader.BaseStream.Position = fileNameTableOffset; int folderCount = folderNamesOffset / 8; for (int index = 0; index < folderCount; index++) folders.Add(new RomFolder(this, index, reader)); byte[] folderNames = reader.ReadBytes(fileNameTableSize - folderNamesOffset); reader.BaseStream.Position = fileSizeTableOffset; int fileCount = fileSizeTableSize / 8; for (int index = 0; index < fileCount; index++) files.Add(new RomFile(this, index, reader)); folders[0].Sort(this, "Root", folderNamesOffset, folderNames); FolderAsset orphanedFolders = null, orphanedFiles = null; foreach (RomFolder folder in folders) { if (folder.Used) continue; if (orphanedFolders == null) orphanedFolders = new FolderAsset(this, "Orphaned folder[s]"); folder.Sort(this, folder.Name, folderNamesOffset, folderNames); } foreach (RomFile file in files) { if (file.Used) continue; if (orphanedFiles == null) orphanedFiles = new FolderAsset(this, "Orphaned file[s]"); file.Sort(orphanedFiles, file.Name); } } }
internal Model(AssetLoader loader) : base(loader) { Asset context = loader.Context; string name = loader.Name; BinaryReader reader = loader.Reader; FolderAsset textureArchive = null; FolderAsset bonesFolder = new FolderAsset(this, "Bones"); FolderAsset materialsFolder = new FolderAsset(this, "Materials"); FolderAsset meshesFolder = new FolderAsset(this, "Meshes"); FolderAsset vertexDeclarationsFolder = new FolderAsset(this, "Vertex declarations"); ArrayBackedList<byte> bufferData = new ArrayBackedList<byte>(); if (context != null && context.Parent is FolderAsset) { // @"/map/m##_##_##_##/m*.flver.dcx" for DS1; textures are in the @"/map/m##/" folder. if (name.StartsWith(@"map/m")) { string folderName = name.Substring(4, 3); FolderAsset maps = (FolderAsset)context.Parent.Parent; foreach (FolderAsset child in maps.Children) { if (child.Name == folderName) { textureArchive = child; break; } } } else textureArchive = (FolderAsset)context.Parent; } #if Marking MarkingStream markingStream = loader.StartMarking(out reader); #endif loader.ExpectMagic(Magic); char endian = (char)reader.ReadByte(); switch (endian) { case 'L': ByteOrder = ByteOrder.LittleEndian; break; case 'B': reader = loader.MakeBigEndian(); ByteOrder = ByteOrder.BigEndian; break; default: throw new Exception(); } using (reader) { // Read header. loader.Expect((byte)0); Version = (ModelVersion)reader.ReadInt32(); if (Version != ModelVersion.DarkSouls && Version != ModelVersion.DarkSouls2) loader.AddError(loader.Position - 4, "Unknown model version " + VersionString + "; will try to load it anyway."); int dataOffset = reader.ReadInt32(); int dataSize = reader.ReadInt32(); if (((dataOffset + dataSize + 31) & ~31) != reader.BaseStream.Length) loader.AddError(loader.Position - 4, "Data size and offset aren't correct."); int boneUnknownCount = reader.ReadInt32(); int materialCount = reader.ReadInt32(); int boneCount = reader.ReadInt32(); int meshCount = reader.ReadInt32(); int meshCount2 = reader.ReadInt32(); if (meshCount != meshCount2) loader.AddError(loader.Position - 4, "Mesh count 1 and 2 aren't the same."); Bounds = new Box3f(reader.ReadVector3f(), reader.ReadVector3f()); Unknowns.ReadInt32s(reader, 1); // Possible the non-degenerate triangle count. Seems related. int triangleCount = reader.ReadInt32(); loader.Expect(IsDS1 ? 272 : 0x10010100); loader.Expect(IsDS1 ? 0 : 0xFFFF); int partCount = reader.ReadInt32(); int vertexDeclarationCount = reader.ReadInt32(); int materialParameterCount = reader.ReadInt32(); loader.Expect(IsDS1 ? 0 : 0x1000000); loader.ExpectZeroes(4, 8); // Calculate offsets. long boneUnknownsOffset = HeaderSize; long materialsOffset = boneUnknownsOffset + boneUnknownCount * ModelBoneUnknown.DataSize; long bonesOffset = materialsOffset + materialCount * ModelMaterial.DataSize; long meshesOffset = bonesOffset + boneCount * ModelBone.DataSize; long detailLevelsOffset = meshesOffset + meshCount * ModelMesh.DataSize; long meshVerticesOffset = detailLevelsOffset + partCount * ModelDetailLevel.DataSize; long vertexDeclarationsOffset = meshVerticesOffset + meshCount * ModelMesh.DataSizeVertexHeader; long materialParametersOffset = vertexDeclarationsOffset + vertexDeclarationCount * ModelVertexDeclaration.DataSize; long postHeaderOffset = materialParametersOffset + materialParameterCount * ModelMaterialParameter.DataSize; // BoneUnknowns ExpectedOffset(loader, boneUnknownsOffset, typeof(ModelBoneUnknown).Name); for (int index = 0; index < boneUnknownCount; index++) boneUnknowns.Add(new ModelBoneUnknown(bonesFolder, index, loader)); // Materials ExpectedOffset(loader, materialsOffset, typeof(ModelMaterial).Name); for (int index = 0; index < materialCount; index++) materials.Add(new ModelMaterial(materialsFolder, index, loader)); int expectedMaterialParameterCount = materialCount > 0 ? materials[materialCount - 1].ParameterEndIndex : 0; if (expectedMaterialParameterCount != materialParameterCount) loader.AddError(null, "Expected material parameter count {0} doesn't match actual count {1}.", expectedMaterialParameterCount, materialParameterCount); // Bones ExpectedOffset(loader, bonesOffset, typeof(ModelBone).Name); for (int index = 0; index < boneCount; index++) bones.Add(new ModelBone(bonesFolder, index, loader)); // Meshes ExpectedOffset(loader, meshesOffset, typeof(ModelMesh).Name); for (int index = 0; index < meshCount; index++) meshes.Add(new ModelMesh(meshesFolder, index, loader)); int expectedPartCount = meshCount > 0 ? meshes[meshCount - 1].PartEndIndex : 0; if (expectedPartCount != partCount) throw new InvalidDataException("Expected part count doesn't match actual count."); // Detail levels ExpectedOffset(loader, detailLevelsOffset, typeof(ModelDetailLevel).Name); foreach (ModelMesh mesh in meshes) { mesh.ReadDetailLevels(loader, dataOffset, bufferData); detailLevels.AddRange(mesh.DetailLevels); } // Mesh vertices ExpectedOffset(loader, meshVerticesOffset, typeof(ModelMesh).Name + " vertex header"); foreach (ModelMesh mesh in meshes) mesh.ReadVertexHeaders(reader, dataOffset, bufferData); // Vertex declarations ExpectedOffset(loader, vertexDeclarationsOffset, typeof(ModelVertexDeclaration).Name); for (int index = 0; index < vertexDeclarationCount; index++) vertexDeclarations.Add(new ModelVertexDeclaration(vertexDeclarationsFolder, index, loader)); // Material parameters ExpectedOffset(loader, materialParametersOffset, typeof(ModelMaterialParameter).Name); foreach (ModelMaterial material in materials) { material.ReadParameters(loader, textureArchive); materialParameters.AddRange(material.Parameters); } ExpectedOffset(loader, postHeaderOffset, "Post-header"); #if Marking if (markingStream != null) { markingStream.Report(loader); } #endif // Marking #if SkippedChecks /*int vertexDataSize = 0, indexCount = 0, indexSize = 0, vertexCount = 0, expectedTriangleCount = 0, nondegenerateTriangleCount = 0; foreach (var mesh in Meshes) { vertexDataSize += mesh.VertexCount * mesh.VertexSize; vertexCount += mesh.VertexCount; foreach (var part in mesh.Parts) { indexCount += part.Indices.Length; indexSize += part.Indices.Length * 2; expectedTriangleCount += part.Indices.Length - 2; for (int index = 0; index < part.Indices.Length - 2; index++) { if (part.Indices[index] != part.Indices[index + 1] && part.Indices[index + 1] != part.Indices[index + 2] && part.Indices[index] != part.Indices[index + 2]) nondegenerateTriangleCount++; } } } if (Math.Abs(expectedTriangleCount - triangleCount) > partCount) throw new InvalidDataException("Expected triangle count doesn't match the read value.");*/ #endif } Buffer = new GraphicsBuffer(bufferData.Count == 0 ? 1 : bufferData.Count); Buffer.Write(0, bufferData.Array, 0, bufferData.Count); }