22 #ifndef MTROPOLIS_DATA_H 23 #define MTROPOLIS_DATA_H 25 #include "common/array.h" 26 #include "common/data-io.h" 27 #include "common/endian.h" 28 #include "common/error.h" 29 #include "common/hashmap.h" 30 #include "common/hash-str.h" 31 #include "common/ptr.h" 32 #include "common/stream.h" 33 #include "common/rect.h" 34 #include "common/xpfloat.h" 36 #include "mtropolis/core.h" 64 static inline bool isLittleEndian(MTropolis::Data::DataFormat dataFormat) {
65 return dataFormat != MTropolis::Data::kDataFormatMacintosh;
71 static const uint kMaxSize = 10;
73 static inline uint computeSize(MTropolis::Data::DataFormat dataFormat) {
74 if (dataFormat == MTropolis::Data::kDataFormatMacintosh)
76 else if (dataFormat == MTropolis::Data::kDataFormatWindows)
82 static inline void encode(MTropolis::Data::DataFormat dataFormat, byte *data,
const Common::XPFloat &value) {
83 if (dataFormat == MTropolis::Data::kDataFormatMacintosh) {
86 }
else if (dataFormat == MTropolis::Data::kDataFormatWindows) {
87 uint64 doubleBits = 0;
88 bool overflowed =
false;
89 value.toDoubleBitsSafe(doubleBits, overflowed);
94 static inline void decode(MTropolis::Data::DataFormat dataFormat,
const byte *data,
Common::XPFloat &value) {
95 if (dataFormat == MTropolis::Data::kDataFormatMacintosh) {
98 }
else if (dataFormat == MTropolis::Data::kDataFormatWindows) {
99 uint64 doubleBits = 0;
101 value = value.fromDoubleBits(doubleBits);
115 struct PlugInModifier;
116 struct PlugInModifierData;
134 kProjectFormatUnknown,
136 kProjectFormatMacintosh,
137 kProjectFormatWindows,
138 kProjectFormatNeutral,
141 enum DataReadErrorCode {
142 kDataReadErrorNone = 0,
144 kDataReadErrorUnsupportedRevision,
145 kDataReadErrorReadFailed,
146 kDataReadErrorUnrecognized,
147 kDataReadErrorPlugInNotFound,
151 kModifierFlagLast = 0x2,
154 enum TextAlignmentCode {
155 kTextAlignmentCodeLeft = 0,
156 kTextAlignmentCodeCenter = 1,
157 kTextAlignmentCodeRight = 0xffff,
161 namespace DataObjectTypes {
163 enum DataObjectType : uint {
166 kProjectLabelMap = 0x22,
167 kProjectCatalog = 0x3e8,
168 kStreamHeader = 0x3e9,
169 kProjectHeader = 0x3ea,
170 kPresentationSettings = 0x3ec,
173 kGlobalObjectInfo = 0x17,
177 kProjectStructuralDef = 0x2,
178 kSectionStructuralDef = 0x3,
179 kSubsectionStructuralDef = 0x21,
181 kGraphicElement = 0x8,
186 kTextLabelElement = 0x15,
188 kAVIMovieElement = 0x25,
189 kAliasModifier = 0x27,
190 kChangeSceneModifier = 0x136,
191 kReturnModifier = 0x140,
192 kSoundEffectModifier = 0x1a4,
193 kSimpleMotionModifier = 0x1fe,
194 kDragMotionModifier = 0x208,
195 kPathMotionModifierV1 = 0x21c,
196 kPathMotionModifierV2 = 0x21b,
197 kVectorMotionModifier = 0x226,
198 kSceneTransitionModifier = 0x26c,
199 kElementTransitionModifier = 0x276,
200 kSharedSceneModifier = 0x29a,
201 kIfMessengerModifier = 0x2bc,
202 kBehaviorModifier = 0x2c6,
203 kMessengerModifier = 0x2da,
204 kSetModifier = 0x2df,
205 kTimerMessengerModifier = 0x2e4,
206 kCollisionDetectionMessengerModifier = 0x2ee,
207 kBoundaryDetectionMessengerModifier = 0x2f8,
208 kKeyboardMessengerModifier = 0x302,
209 kTextStyleModifier = 0x32a,
210 kGraphicModifier = 0x334,
211 kImageEffectModifier = 0x384,
212 kMiniscriptModifier = 0x3c0,
213 kCursorModifierV1 = 0x3ca,
214 kGradientModifier = 0x4b0,
215 kColorTableModifier = 0x4c4,
216 kSoundFadeModifier = 0x4ce,
217 kSaveAndRestoreModifier = 0x4d8,
219 kCompoundVariableModifier = 0x2c7,
220 kBooleanVariableModifier = 0x321,
221 kIntegerVariableModifier = 0x322,
222 kIntegerRangeVariableModifier = 0x324,
223 kVectorVariableModifier = 0x327,
224 kPointVariableModifier = 0x326,
225 kFloatingPointVariableModifier = 0x328,
226 kStringVariableModifier = 0x329,
227 kObjectReferenceVariableModifierV1 = 0x33e,
228 kDebris = 0xfffffffe,
229 kPlugInModifier = 0xffffffff,
233 kColorTableAsset = 0x1e,
237 kAVIMovieAsset = 0x24,
239 kAssetDataChunk = 0xffff,
242 bool isValidSceneRootElement(DataObjectType type);
243 bool isVisualElement(DataObjectType type);
244 bool isNonVisualElement(DataObjectType type);
245 bool isStructural(DataObjectType type);
246 bool isElement(DataObjectType type);
247 bool isModifier(DataObjectType type);
248 bool isAsset(DataObjectType type);
252 namespace StructuralFlags {
253 enum StructuralFlags {
256 kNoMoreSiblings = 0x8,
265 bool readU8(uint8 &value);
266 bool readU16(uint16 &value);
267 bool readU32(uint32 &value);
268 bool readU64(uint64 &value);
269 bool readS8(int8 &value);
270 bool readS16(int16 &value);
271 bool readS32(int32 &value);
272 bool readS64(int64 &value);
273 bool readF32(
float &value);
274 bool readF64(
double &value);
278 bool readMultiple(T &...values);
280 bool read(
void *dest,
size_t size);
287 template<
size_t TSize>
288 bool readChars(
char (&arr)[TSize]);
290 template<
size_t TSize>
291 bool readBytes(uint8 (&arr)[TSize]);
293 bool seek(int64 pos);
294 bool skip(
size_t count);
297 inline int64 tellGlobal()
const {
return _globalPosition + tell(); }
299 DataFormat getDataFormat()
const;
301 void setPermitDamagedStrings(
bool permit);
303 bool isVersionAutoDetect()
const;
304 RuntimeVersion getRuntimeVersion()
const;
305 void setRuntimeVersion(RuntimeVersion runtimeVersion);
308 bool checkErrorAndReset();
311 DataFormat _dataFormat;
312 int64 _globalPosition;
314 bool _permitDamagedStrings;
316 RuntimeVersion _runtimeVersion;
321 bool DataReader::readMultiple(T &...values) {
325 if (!read(buffer, actualSize))
338 bool toScummVMRectUnchecked(
Common::Rect &outRect)
const;
392 uint16 signAndExponent;
430 kIntegerRange = 0x11,
433 kIncomingData = 0x1b,
434 kVariableReference = 0x1c,
471 kUniversalTime = 0x09,
480 kIncomingData = 0x6e,
481 kVariableReference = 0x73,
523 DataReadErrorCode load(DataObjectTypes::DataObjectType type, uint16 revision,
DataReader &reader);
525 uint16 getRevision()
const;
526 DataObjectTypes::DataObjectType getType()
const;
529 virtual DataReadErrorCode load(
DataReader &reader) = 0;
531 DataObjectTypes::DataObjectType _type;
539 uint32 sizeIncludingTag;
541 uint32 catalogFilePosition;
544 DataReadErrorCode load(
DataReader &reader)
override;
556 kExpandedInEditor = 0x80000000,
586 uint32 numSuperGroups;
587 uint32 nextAvailableID;
595 DataReadErrorCode load(
DataReader &reader)
override;
602 uint32 sizeIncludingTag;
609 DataReadErrorCode load(
DataReader &reader)
override;
615 kFlag1LimitOnePerSegment = 2,
642 uint32 totalNameSizePlus22;
650 DataReadErrorCode load(
DataReader &reader)
override;
657 uint32 sizeIncludingTag;
661 DataReadErrorCode load(
DataReader &reader)
override;
668 uint32 sizeIncludingTag;
671 DataReadErrorCode load(
DataReader &reader)
override;
677 uint32 structuralFlags;
684 uint32 sizeIncludingTag;
692 DataReadErrorCode load(
DataReader &reader)
override;
698 uint32 sizeIncludingTag;
709 DataReadErrorCode load(
DataReader &reader)
override;
715 uint32 structuralFlags;
716 uint32 sizeIncludingTag;
725 DataReadErrorCode load(
DataReader &reader)
override;
728 namespace ElementFlags {
731 kNotDirectToScreen = 0x00001000,
732 kHidden = 0x00008000,
733 kPaused = 0x00010000,
734 kExpandedInEditor = 0x00800000,
735 kCacheBitmap = 0x02000000,
736 kSelectedInEditor = 0x10000000,
741 namespace AnimationFlags {
743 enum AnimationFlags {
744 kAlternate = 0x10000000,
746 kPlayEveryFrame = 0x02000000,
751 namespace SceneTransitionTypes {
753 enum SceneTransitionType {
755 kPatternDissolve = 0x0406,
756 kRandomDissolve = 0x0410,
766 namespace SceneTransitionDirections {
768 enum SceneTransitionDirection {
781 uint32 sizeIncludingTag;
789 uint32 streamLocator;
795 DataReadErrorCode load(
DataReader &reader)
override;
802 uint32 sizeIncludingTag;
811 uint32 streamLocator;
817 DataReadErrorCode load(
DataReader &reader)
override;
824 uint32 sizeIncludingTag;
855 DataReadErrorCode load(
DataReader &reader)
override;
859 enum SoundFlags : uint {
860 kPaused = 0x40000000,
867 uint32 sizeIncludingTag;
883 DataReadErrorCode load(
DataReader &reader)
override;
890 uint32 sizeIncludingTag;
903 uint32 animationFlags;
906 uint32 streamLocator;
914 DataReadErrorCode load(
DataReader &reader)
override;
921 uint32 sizeIncludingTag;
926 uint32 animationFlags;
932 uint32 rateTimes100000;
933 uint32 streamLocator;
939 DataReadErrorCode load(
DataReader &reader)
override;
946 uint32 sizeIncludingTag;
947 uint16 numGlobalModifiers;
951 DataReadErrorCode load(
DataReader &reader)
override;
960 uint16 segmentIndexPlusOne;
978 uint32 sizeOfStreamAndSegmentDescs;
987 DataReadErrorCode load(
DataReader &reader)
override;
994 uint32 sizeIncludingTag;
1001 DataReadErrorCode load(
DataReader &reader)
override;
1005 enum BehaviorFlags {
1006 kBehaviorFlagSwitchable = 1,
1011 uint32 modifierFlags;
1012 uint32 sizeIncludingTag;
1019 Point editorLayoutPosition;
1020 uint16 lengthOfName;
1022 uint32 behaviorFlags;
1030 DataReadErrorCode load(
DataReader &reader)
override;
1056 uint32 sizeOfInstructions;
1057 uint32 numOfInstructions;
1058 uint32 numLocalRefs;
1059 uint32 numAttributes;
1065 DataFormat dataFormat;
1074 uint32 modifierFlags;
1075 uint32 sizeIncludingTag;
1080 Point editorLayoutPosition;
1081 uint16 lengthOfName;
1099 DataReadErrorCode load(
DataReader &reader)
override;
1112 DataReadErrorCode load(
DataReader &reader)
override;
1122 uint16 fadeToVolume;
1123 uint8 codedDuration[4];
1127 DataReadErrorCode load(
DataReader &reader)
override;
1141 uint8 lengthOfFilePath;
1142 uint8 lengthOfFileName;
1143 uint8 lengthOfVariableName;
1144 uint8 lengthOfVariableString;
1152 DataReadErrorCode load(
DataReader &reader)
override;
1155 enum MessageFlags : uint {
1156 kMessageFlagNoRelay = 0x20000000,
1157 kMessageFlagNoCascade = 0x40000000,
1158 kMessageFlagNoImmediate = 0x80000000,
1167 uint32 messageFlags;
1172 uint8 unknown11[10];
1174 uint8 withSourceLength;
1175 uint8 withStringLength;
1181 DataReadErrorCode load(
DataReader &reader)
override;
1194 uint8 sourceNameLength;
1195 uint8 targetNameLength;
1196 uint8 sourceStringLength;
1197 uint8 targetStringLength;
1206 DataReadErrorCode load(
DataReader &reader)
override;
1212 uint32 modifierFlags;
1213 uint32 sizeIncludingTag;
1214 uint16 aliasIndexPlusOne;
1218 uint32 lengthOfName;
1220 Point editorLayoutPosition;
1227 DataReadErrorCode load(
DataReader &reader)
override;
1231 enum ChangeSceneFlags : uint {
1232 kChangeSceneFlagNextScene = 0x80000000,
1233 kChangeSceneFlagPrevScene = 0x40000000,
1234 kChangeSceneFlagSpecificScene = 0x20000000,
1235 kChangeSceneFlagAddToReturnList = 0x10000000,
1236 kChangeSceneFlagAddToDestList = 0x08000000,
1237 kChangeSceneFlagWrapAround = 0x04000000,
1243 uint32 changeSceneFlags;
1245 uint32 targetSectionGUID;
1246 uint32 targetSubsectionGUID;
1247 uint32 targetSceneGUID;
1250 DataReadErrorCode load(
DataReader &reader)
override;
1256 static const uint32 kSpecialAssetIDSystemBeep = 0xffffffffu;
1261 Event terminateWhen;
1268 DataReadErrorCode load(
DataReader &reader)
override;
1275 uint32 messageFlags;
1279 uint8 unknown13[10];
1281 uint8 withSourceLength;
1282 uint8 withStringLength;
1294 kFrameFlagPlaySequentially = 1,
1303 bool load(
DataReader &reader,
bool haveMessageSpec);
1307 kFlagReverse = 0x00100000,
1308 kFlagLoop = 0x10000000,
1309 kFlagAlternate = 0x02000000,
1310 kFlagStartAtBeginning = 0x08000000,
1319 Event terminateWhen;
1324 uint32 frameDurationTimes10Million;
1328 bool havePointDefMessageSpecs;
1333 DataReadErrorCode load(
DataReader &reader)
override;
1342 Event terminateWhen;
1344 uint16 directionFlags;
1346 uint32 delayMSecTimes4800;
1350 DataReadErrorCode load(
DataReader &reader)
override;
1363 uint8 constrainHorizontal;
1364 uint8 constrainVertical;
1365 uint8 constrainToParent;
1373 kConstrainToParent = 0x10,
1374 kConstrainVertical = 0x20,
1375 kConstrainHorizontal = 0x40,
1388 Rect constraintMargin;
1392 DataReadErrorCode load(
DataReader &reader)
override;
1404 uint8 vecSourceLength;
1405 uint8 vecStringLength;
1411 DataReadErrorCode load(
DataReader &reader)
override;
1421 uint16 transitionType;
1429 DataReadErrorCode load(
DataReader &reader)
override;
1435 enum TransitionType {
1436 kTransitionTypeRectangularIris = 0x03e8,
1437 kTransitionTypeOvalIris = 0x03f2,
1438 kTransitionTypeZoom = 0x044c,
1439 kTransitionTypeFade = 0x2328,
1443 kRevealTypeReveal = 0,
1444 kRevealTypeConceal = 1,
1452 uint16 transitionType;
1459 DataReadErrorCode load(
DataReader &reader)
override;
1470 uint32 subsectionGUID;
1474 DataReadErrorCode load(
DataReader &reader)
override;
1482 uint32 messageFlags;
1490 uint8 withSourceLength;
1491 uint8 withStringLength;
1498 DataReadErrorCode load(
DataReader &reader)
override;
1507 kTimerFlagLooping = 0x10000000,
1510 uint32 messageAndTimerFlags;
1513 Event terminateWhen;
1521 uint8 hundredthsOfSeconds;
1525 uint8 withSourceLength;
1526 uint8 withStringLength;
1532 DataReadErrorCode load(
DataReader &reader)
override;
1539 kDetectTopEdge = 0x1000,
1540 kDetectBottomEdge = 0x0800,
1541 kDetectLeftEdge = 0x0400,
1542 kDetectRightEdge = 0x0200,
1543 kDetectExiting = 0x0100,
1544 kWhileDetected = 0x0080,
1548 uint16 messageFlagsHigh;
1556 uint8 withSourceLength;
1557 uint8 withStringLength;
1563 DataReadErrorCode load(
DataReader &reader)
override;
1569 enum ModifierFlags {
1570 kDetectLayerInFront = 0x10000000,
1571 kDetectLayerBehind = 0x08000000,
1572 kSendToCollidingElement = 0x02000000,
1573 kSendToOnlyFirstCollidingElement = 0x00200000,
1575 kDetectionModeMask = 0x01c00000,
1576 kDetectionModeFirstContact = 0x01400000,
1577 kDetectionModeWhileInContact = 0x01000000,
1578 kDetectionModeExiting = 0x00800000,
1580 kNoCollideWithParent = 0x00100000,
1584 uint32 messageAndModifierFlags;
1592 uint8 withSourceLength;
1593 uint8 withStringLength;
1599 DataReadErrorCode load(
DataReader &reader)
override;
1603 enum KeyStateFlags {
1604 kOnDown = 0x10000000,
1606 kOnRepeat = 0x8000000,
1608 kKeyStateMask = (kOnDown | kOnUp | kOnRepeat),
1639 uint32 messageFlagsAndKeyStates;
1641 uint16 keyModifiers;
1649 uint8 withSourceLength;
1650 uint8 withStringLength;
1656 DataReadErrorCode load(
DataReader &reader)
override;
1675 uint16 lengthOfFontFamilyName;
1680 DataReadErrorCode load(
DataReader &reader)
override;
1696 uint8 unknown4_1[6];
1697 uint8 unknown4_2[26];
1701 uint8 unknown5_1[4];
1702 uint8 unknown5_2[22];
1721 uint16 numPolygonPoints;
1727 DataReadErrorCode load(
DataReader &reader)
override;
1735 kTypeSelectedBevels = 2,
1736 kTypeDeselectedBevels = 3,
1752 DataReadErrorCode load(
DataReader &reader)
override;
1764 DataReadErrorCode load(
DataReader &reader)
override;
1781 bool hasMacOnlyPart;
1785 DataReadErrorCode load(
DataReader &reader)
override;
1792 uint32 modifierFlags;
1793 uint32 sizeIncludingTag;
1798 Point editorLayoutPosition;
1799 uint16 lengthOfName;
1806 DataReadErrorCode load(
DataReader &reader)
override;
1817 DataReadErrorCode load(
DataReader &reader)
override;
1828 DataReadErrorCode load(
DataReader &reader)
override;
1839 DataReadErrorCode load(
DataReader &reader)
override;
1850 DataReadErrorCode load(
DataReader &reader)
override;
1862 DataReadErrorCode load(
DataReader &reader)
override;
1873 DataReadErrorCode load(
DataReader &reader)
override;
1880 uint32 lengthOfString;
1885 DataReadErrorCode load(
DataReader &reader)
override;
1893 Event setToSourcesParentWhen;
1896 DataReadErrorCode load(
DataReader &reader)
override;
1907 uint32 modifierFlags;
1909 char modifierName[17];
1912 uint16 plugInRevision;
1914 Point editorLayoutPosition;
1915 uint16 lengthOfName;
1919 uint32 subObjectSize;
1924 DataReadErrorCode load(
DataReader &reader)
override;
1930 uint32 persistFlags;
1931 uint32 sizeIncludingTag;
1934 DataReadErrorCode load(
DataReader &reader)
override;
1940 uint32 persistFlags;
1941 uint32 sizeIncludingTag;
1949 DataReadErrorCode load(
DataReader &reader)
override;
1954 uint8 unknown5_1[66];
1960 uint8 unknown3_1[32];
1972 uint32 persistFlags;
1973 uint32 assetAndDataCombinedSize;
1976 uint8 unknown1_1[4];
1977 uint16 extFileNameLength;
1979 uint32 movieDataPos;
1981 uint32 movieDataSize;
1990 DataReadErrorCode load(
DataReader &reader)
override;
1999 uint16 extFileNameLength;
2005 DataReadErrorCode load(
DataReader &reader)
override;
2019 uint8 unknown11[18];
2020 uint8 unknown12_1[2];
2037 uint32 persistFlags;
2038 uint32 assetAndDataCombinedSize;
2043 uint8 bitsPerSample;
2046 uint8 codedDuration[4];
2048 uint32 cuePointDataSize;
2049 uint16 numCuePoints;
2051 uint32 filePosition;
2062 DataReadErrorCode load(
DataReader &reader)
override;
2081 uint32 persistFlags;
2090 uint16 bitsPerPixel;
2095 uint32 filePosition;
2103 DataReadErrorCode load(
DataReader &reader)
override;
2108 uint8 unknown10[88];
2112 uint8 unknown11[54];
2140 uint32 compressedSize;
2148 uint16 bitsPerPixel;
2150 uint16 decompressedBytesPerRow;
2151 uint32 decompressedSize;
2168 kEncodingFlag_TemporalCompression = 0x80,
2169 kEncodingFlag_HasRanges = 0x20000000,
2170 kEncodingFlag_Trimming = 0x08,
2177 uint32 sizeIncludingTag;
2179 uint32 numFrameRanges;
2193 uint32 frameDataPosition;
2194 uint32 sizeOfFrameData;
2197 uint32 mtoonHeader[2];
2200 uint32 encodingFlags;
2205 uint16 bitsPerPixel;
2207 uint8 unknown4_1[8];
2208 uint32 codecDataSize;
2209 Point registrationPoint;
2226 DataReadErrorCode load(
DataReader &reader)
override;
2256 uint32 persistFlags;
2257 uint32 sizeIncludingTag;
2265 uint8 pitchBigEndian[2];
2287 DataReadErrorCode load(
DataReader &reader)
override;
2294 uint32 sizeIncludingTag;
2298 DataReadErrorCode load(
DataReader &reader)
override;
2303 virtual PlugIn &getPlugIn()
const = 0;
2317 template<
size_t TSize>
2318 inline bool DataReader::readBytes(uint8(&arr)[TSize]) {
2319 return this->read(arr, TSize);
2322 template<
size_t TSize>
2323 inline bool DataReader::readChars(
char (&arr)[TSize]) {
2324 return this->read(arr, TSize);
Definition: data-io.h:167
Definition: runtime.h:1185
Definition: noncopyable.h:39
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: algorithm.h:29
Definition: data-io.h:121