ScummVM API documentation
datafile.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MEDIASTATION_DATAFILE_H
23 #define MEDIASTATION_DATAFILE_H
24 
25 #include "common/file.h"
26 #include "common/stream.h"
27 #include "common/path.h"
28 #include "common/rect.h"
29 #include "common/str.h"
30 
31 namespace MediaStation {
32 
33 // The version number of this engine,
34 // in the form 4.0r8 (major . minor r revision).
35 struct VersionInfo {
36  uint16 major = 0;
37  uint16 minor = 0;
38  uint16 patch = 0;
39 };
40 
42 
43 // A Media Station datafile consists of one or more RIFF-style "subfiles". Aside
44 // from some oddness at the start of the subfile, each subfile is basically
45 // standard sequence of chunks inside a LIST chunk, like you'd see in any RIFF
46 // file. These chunks have special IDs:
47 // - igod: Indicates a chunk that contains metadata about asset(s) in metadata sections.
48 // - a000, where 000 is a string that represents a 3-digit hexadecimal number.
49 // Indicates a chunk that contains actor data (sounds and bitmaps).
50 
51 enum DatumType {
52  kDatumTypeEmpty = 0x00,
53  kDatumTypeUint8 = 0x02,
54  kDatumTypeUint16 = 0x03,
55  kDatumTypeUint32 = 0x04,
56  kDatumTypeInt8 = 0x05,
57  kDatumTypeInt16 = 0x06,
58  kDatumTypeInt32 = 0x07,
59  kDatumTypeFloat = 0x08,
60  kDatumTypeDouble = 0x09,
61  kDatumTypeFilename = 0x0a,
62  kDatumTypeRect = 0x0d,
63  kDatumTypePoint = 0x0e,
64  kDatumTypeGraphicSize = 0x0f,
65  kDatumTypeGraphicUnit = 0x10,
66  kDatumTypeTime = 0x11,
67  kDatumTypeString = 0x12,
68  kDatumTypeVersion = 0x13,
69  kDatumTypeChunkReference = 0x1b,
70  kDatumTypePolygon = 0x1d,
71  kDatumTypePalette = 0x05aa
72 };
73 
75 public:
76  // Data files are internally little-endian, even on game versions targeting
77  // big-endian systems. The original engine has code for swapping byte order
78  // at runtime when needed. All of these internally assume the data files are
79  // stored little-endian on disk.
80  byte readTypedByte();
81  uint16 readTypedUint16();
82  uint32 readTypedUint32();
83  int8 readTypedSByte();
84  int16 readTypedSint16();
85  int32 readTypedSint32();
86  float readTypedFloat();
87  double readTypedDouble();
88  Common::String readTypedFilename();
89  Common::Rect readTypedRect();
90  Common::Point readTypedPoint();
91  Common::Point readTypedGraphicSize();
92  int16 readTypedGraphicUnit();
93  double readTypedTime();
94  Common::String readTypedString();
95  VersionInfo readTypedVersion();
96  uint32 readTypedChunkReference();
97  Polygon readTypedPolygon();
98 
99 private:
100  void readAndVerifyType(DatumType type);
101 };
102 
103 class Chunk : public ParameterReadStream {
104 public:
105  Chunk() = default;
107 
108  uint32 bytesRemaining();
109 
110  uint32 _id = 0;
111  uint32 _length = 0;
112 
113  // ReadStream implementation
114  virtual bool eos() const { return _parentStream->eos(); };
115  virtual bool err() const { return _parentStream->err(); };
116  virtual void clearErr() { _parentStream->clearErr(); };
117  virtual uint32 read(void *dataPtr, uint32 dataSize);
118  virtual int64 pos() const { return _parentStream->pos(); };
119  virtual int64 size() const { return _parentStream->size(); };
120  virtual bool skip(uint32 offset) { return seek(offset, SEEK_CUR); };
121  virtual bool seek(int64 offset, int whence = SEEK_SET);
122 
123 private:
124  Common::SeekableReadStream *_parentStream = nullptr;
125  uint32 _dataStartOffset = 0;
126  uint32 _dataEndOffset = 0;
127 };
128 
129 class Subfile {
130 public:
131  Subfile() = default;
133 
134  Chunk nextChunk();
135  bool atEnd();
136 
137  Chunk _currentChunk;
138  uint32 _rate;
139 
140 private:
141  Common::SeekableReadStream *_stream = nullptr;
142  Chunk _rootChunk;
143 };
144 
145 class Datafile : public Common::File {
146 public:
147  Datafile(const Common::Path &path);
148 
149  Subfile getNextSubfile();
150 };
151 
152 } // End of namespace MediaStation
153 
154 #endif
virtual void clearErr()
Definition: datafile.h:116
virtual int64 size() const
Definition: datafile.h:119
Definition: datafile.h:35
Definition: str.h:59
Definition: datafile.h:145
virtual bool eos() const
Definition: datafile.h:114
Definition: asset.h:32
Definition: datafile.h:103
virtual int64 pos() const
Definition: datafile.h:118
Definition: rect.h:524
Definition: path.h:52
Definition: stream.h:745
Definition: file.h:47
virtual bool skip(uint32 offset)
Definition: datafile.h:120
Definition: rect.h:144
Definition: datafile.h:129
virtual bool err() const
Definition: datafile.h:115
Definition: datafile.h:74