22 #ifndef SCI_RESOURCE_RESOURCE_H 23 #define SCI_RESOURCE_RESOURCE_H 25 #include "common/str.h" 26 #include "common/list.h" 27 #include "common/hashmap.h" 29 #include "sci/graphics/helpers.h" 30 #include "sci/resource/decompressor.h" 33 #include "sci/version.h" 40 class SeekableReadStream;
48 kResPatVolumeNumber = 100,
59 kResStatusNoMalloc = 0,
68 SCI_ERROR_IO_ERROR = 1,
69 SCI_ERROR_EMPTY_RESOURCE = 2,
71 SCI_ERROR_RESMAP_NOT_FOUND = 4,
73 SCI_ERROR_UNKNOWN_COMPRESSION = 6,
83 kResourceTypeView = 0,
95 kResourceTypeCdAudio = 12,
97 kResourceTypeWave = 12,
101 kResourceTypeMessage,
104 kResourceTypeAudio36,
106 kResourceTypeTranslation,
112 kResourceTypeAnimation,
122 kResourceTypeMacIconBarPictN,
123 kResourceTypeMacIconBarPictS,
124 kResourceTypeMacPict,
131 const char *getResourceTypeName(ResourceType restype);
132 const char *getResourceTypeExtension(ResourceType restype);
136 kResVersionSci0Sci1Early,
137 kResVersionSci1Middle,
162 static inline ResourceType fixupType(ResourceType type) {
163 if (type >= kResourceTypeInvalid)
164 return kResourceTypeInvalid;
177 int character = number % 36;
178 string = ((character < 10) ? (character +
'0') : (character +
'A' - 10)) + string;
188 ResourceId() : _type(kResourceTypeInvalid), _number(0), _tuple(0) { }
190 ResourceId(ResourceType type_, uint16 number_, uint32 tuple_ = 0)
191 : _type(fixupType(type_)), _number(number_), _tuple(tuple_) {
194 ResourceId(ResourceType type_, uint16 number_, byte noun, byte verb, byte cond, byte seq)
195 : _type(fixupType(type_)), _number(number_) {
196 _tuple = (noun << 24) | (verb << 16) | (cond << 8) | seq;
203 retStr +=
Common::String::format(
"(%d, %d, %d, %d)", _tuple >> 24, (_tuple >> 16) & 0xff, (_tuple >> 8) & 0xff, _tuple & 0xff);
213 if (getSciVersion() >= SCI_VERSION_2) {
214 output += (getType() == kResourceTypeAudio36) ?
'A' :
'S';
216 output += (getType() == kResourceTypeAudio36) ?
'@' :
'#';
218 output += intToBase36(getNumber(), 3);
219 output += intToBase36(getTuple() >> 24, 2);
220 output += intToBase36((getTuple() >> 16) & 0xff, 2);
222 output += intToBase36((getTuple() >> 8) & 0xff, 2);
223 output += intToBase36(getTuple() & 0xff, 1);
225 assert(output.size() == 12);
229 inline ResourceType getType()
const {
return _type; }
230 inline uint16 getNumber()
const {
return _number; }
231 inline uint32 getTuple()
const {
return _tuple; }
233 inline uint hash()
const {
234 return ((uint)((_type << 16) | _number)) ^ _tuple;
237 bool operator==(
const ResourceId &other)
const {
238 return (_type == other._type) && (_number == other._number) && (_tuple == other._tuple);
241 bool operator!=(
const ResourceId &other)
const {
242 return !operator==(other);
245 bool operator<(
const ResourceId &other)
const {
246 return (_type < other._type) || ((_type == other._type) && (_number < other._number))
247 || ((_type == other._type) && (_number == other._number) && (_tuple < other._tuple));
252 uint operator()(
ResourceId val)
const {
return val.hash(); }
268 friend class ChunkResourceSource;
285 inline ResourceType getType()
const {
return _id.getType(); }
286 inline uint16 getNumber()
const {
return _id.getNumber(); }
303 uint32 getAudioCompressionType()
const;
305 uint16 getNumLockers()
const {
return _lockers; }
316 bool loadFromPatchFile();
321 int readResourceInfo(ResVersion volVersion,
Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression);
341 friend class ChunkResourceSource;
360 void addAppropriateSources();
365 void addAppropriateSourcesForDetection(
const Common::FSList &fslist);
408 bool hasResourceType(ResourceType type);
410 void setAudioLanguage(
int language);
411 int getAudioLanguage()
const;
414 bool isGMTrackIncluded();
415 bool isSci11Mac()
const {
return _volVersion == kResVersionSci11Mac; }
416 ViewType getViewType()
const {
return _viewType; }
417 const char *getMapVersionDesc()
const {
return versionDescription(_mapVersion); }
418 const char *getVolVersionDesc()
const {
return versionDescription(_volVersion); }
419 ResVersion getVolVersion()
const {
return _volVersion; }
427 void addNewGMPatch(SciGameId gameId);
428 void addNewD110Patch(SciGameId gameId);
435 void addResourcesFromChunk(uint16
id);
440 void findDisc(
const int16 discNo);
445 int16 getCurrentDiscNo()
const {
return _currentDiscNo; }
451 int16 _currentDiscNo;
457 bool _multiDiscAudio;
463 bool detectFontExtended();
465 bool detectPaletteMergingSci11();
467 bool detectEarlySound();
480 reg_t findGameObject(
const bool addSci11ScriptOffset);
487 ResourceType convertResType(byte type);
500 SourcesList _sources;
543 void scanNewSources();
545 bool addAudioSources();
546 void addScriptChunkSources();
547 void freeResourceSources();
554 const char *versionDescription(ResVersion version)
const;
564 void freeOldResources();
565 bool validateResource(
const ResourceId &resourceId,
const Common::Path &sourceMapLocation,
const Common::Path &sourceName,
const uint32 offset,
const uint32 size,
const uint32 sourceSize)
const;
572 ResVersion detectMapVersion();
573 ResVersion detectVolVersion();
575 bool detectSci2Mac();
612 void readResourcePatches();
613 void readResourcePatchesBase36();
619 bool isBlacklistedPatch(
const ResourceId &resId)
const;
621 void processPatch(
ResourceSource *source, ResourceType resourceType, uint16 resourceNr, uint32 tuple = 0);
626 void readWaveAudioPatches();
633 void readAIFFAudioPatches();
644 bool hasOldScriptHeader();
649 ResourceCompression getViewCompression();
650 ViewType detectViewType();
651 bool hasSci0Voc999();
652 bool hasSci1Voc900();
653 bool checkResourceDataForSignature(
Resource *resource,
const byte *signature);
654 bool checkResourceForSignatures(ResourceType resourceType, uint16 resourceNr,
const byte *signature1,
const byte *signature2);
655 void detectSciVersion();
666 bool _hasBadResources;
698 int16 digitalChannelNr;
699 uint16 digitalSampleRate;
700 uint16 digitalSampleSize;
701 uint16 digitalSampleStart;
702 uint16 digitalSampleEnd;
708 Track *getTrackByNumber(uint16 number);
710 Track *getTrackByType(byte type);
711 Track *getDigitalTrack();
712 int getChannelFilterMask(
int hardwareMask,
bool wantsRhythm);
714 byte getInitialVoiceCount(byte channel);
716 byte getSoundPriority()
const {
return _soundPriority; }
717 bool exists()
const {
return _resource !=
nullptr; }
732 #endif // SCI_RESOURCE_RESOURCE_H ResVersion _mapVersion
resource.map version
Definition: resource.h:508
patch type + header size
Definition: resource.h:51
uint16 _lockers
Definition: resource.h:311
Definition: resource.h:669
byte * _header
Definition: resource.h:277
Definition: resource.h:70
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
ResourceSource * _audioMapSCI1
Currently loaded audio map for SCI1.
Definition: resource.h:506
int _memoryLocked
Amount of resource bytes in locked memory.
Definition: resource.h:501
SciVersion
Definition: detection.h:134
SciVersion getSciVersionForDetection()
Definition: resource.h:693
int32 _fileOffset
Definition: resource.h:309
Definition: resource.h:54
Definition: resource_intern.h:92
Definition: serializer.h:79
Definition: resource.h:327
Definition: resource_intern.h:178
Definition: resource.h:671
Definition: resource_intern.h:99
Definition: resource.h:61
Definition: resource_intern.h:197
Definition: resource_intern.h:135
Max number of simultaneously opened volumes.
Definition: resource.h:79
Common::List< Common::File * > _volumeFiles
list of opened volume files
Definition: resource.h:505
Definition: resource.h:75
Definition: resource.h:62
Definition: resource_intern.h:126
Definition: algorithm.h:29
const char * getSciVersionDesc(SciVersion version)
Definition: resource.h:256
Definition: resource_patcher.h:90
Definition: resource_intern.h:145
Definition: resource.h:161
Definition: resource_intern.h:187
ResourceErrorCodes
Definition: resource.h:66
ResVersion _volVersion
resource.0xx version
Definition: resource.h:507
int _memoryLRU
Amount of resource bytes under LRU control.
Definition: resource.h:502
Definition: resource_intern.h:48
Definition: resource.h:72
Definition: vm_types.h:39
Definition: resource.h:74
Definition: resource.h:251
Common::List< Resource * > _LRU
Last Resource Used list.
Definition: resource.h:503
ResourceStatus
Definition: resource.h:58