24#ifndef SAGA_RESOURCE_H
25#define SAGA_RESOURCE_H
27#include "common/array.h"
28#include "common/file.h"
29#include "common/list.h"
34#define RSC_TABLEINFO_SIZE 8
35#define RSC_TABLEENTRY_SIZE 8
37#define RSC_MIN_FILESIZE (RSC_TABLEINFO_SIZE + RSC_TABLEENTRY_SIZE + 1)
45 const char *_fileName;
46 bool _deletePatchFile;
47 bool _patchFileOpened;
50 PatchData(
const char *fileName): _fileName(fileName), _deletePatchFile(
true), _patchFile(
nullptr), _patchFileOpened(
false) {
60 _patchFileOpened =
true;
61 if (!file->
open(_fileName)) {
71 if (_deletePatchFile && _patchFileOpened) {
74 _patchFileOpened =
false;
79 if (_deletePatchFile) {
92 offset(0), size(0), patchData(NULL), diskNum(-1) {
110 _fileName(NULL), _fileType(0), _isCompressed(
false), _serial(0),
112 _fileSize(0), _tombstone(
false) {
117 bool isCompressed()
const {
return _isCompressed; }
118 uint16 fileType()
const {
return _fileType; }
119 int32 fileSize()
const {
return _fileSize; }
120 int serial()
const {
return _serial; }
121 bool isBigEndian()
const {
return _isBigEndian; }
122 const char * fileName()
const {
return _fileName; }
125 if (resourceData && resourceData->patchData != NULL) {
126 return resourceData->patchData->getStream();
128 if (!_file && !_tombstone)
137 bool validResourceId(uint32 resourceId)
const {
138 return (resourceId < _table.
size());
142 if (resourceId >= _table.
size()) {
143 error(
"ResourceContext::getResourceData() wrong resourceId %d", resourceId);
145 return &_table[resourceId];
153 const char *_fileName;
167 bool loadResIteAmiga(
SagaEngine *_vm,
int type,
bool isFloppy);
168 bool loadResIteAmigaSound(
SagaEngine *_vm,
int type);
170 virtual bool loadRes(
SagaEngine *_vm,
int type) = 0;
179 int32 objectsStringsResourceID;
180 int32 inventorySpritesID;
182 int32 objectsResourceID;
184 int32 actorsStringsResourceID;
185 int32 actorsResourceID;
186 int32 protagFaceSpritesID;
189 int16 protagStatesCount;
190 int32 protagStatesResourceID;
191 int32 cutawayListResourceID;
195 memset(
this, 0,
sizeof(*
this));
203 bool createContexts();
204 void clearContexts();
207 virtual uint32 convertResourceId(uint32 resourceId) = 0;
208 virtual void loadGlobalResources(
int chapter,
int actorsEntrance) = 0;
215 char _voicesFileName[8][256];
216 char _musicFileName[256];
217 char _soundFileName[256];
219 void addContext(
const char *fileName, uint16 fileType,
bool isCompressed =
false,
int serial = 0);
226 bool loadRes(
SagaEngine *_vm,
int type)
override {
237 bool loadRes(
SagaEngine *_vm,
int type)
override {
238 return loadResIteAmiga(_vm, type, _isFloppy);
247 uint32 convertResourceId(uint32 resourceId)
override {
248 return _vm->isMacResources() ? resourceId - 2 : resourceId;
250 void loadGlobalResources(
int chapter,
int actorsEntrance)
override {}
257 if (_vm->getPlatform() == Common::kPlatformAmiga && _vm->getGameId() == GID_ITE) {
268 bool loadRes(
SagaEngine *_vm,
int type)
override {
272 void processPatches(Resource *resource,
const GamePatchDescription *patchFiles)
override;
276class VoiceResourceContext_RES:
public ResourceContext {
278 bool loadRes(SagaEngine *_vm,
int type)
override {
282 VoiceResourceContext_RES() : ResourceContext() {
283 _fileType = GAME_VOICEFILE;
288class Resource_RES :
public Resource {
290 Resource_RES(SagaEngine *vm) : Resource(vm) {}
291 uint32 convertResourceId(uint32 resourceId)
override {
return resourceId; }
292 void loadGlobalResources(
int chapter,
int actorsEntrance)
override;
293 MetaResource* getMetaResource()
override {
return &_metaResource; }
295 ResourceContext *createContext()
override {
296 return new ResourceContext_RES();
299 MetaResource _metaResource;
size_type size() const
Definition: array.h:316
virtual bool open(const Path &filename)
static SeekableReadStream * openFileOrDataFork(const Path &fileName, Archive &archive)
void reset(PointerType o=nullptr)
Definition: ptr.h:607
PointerType get() const
Definition: ptr.h:637
Definition: resource.h:42
Definition: resource.h:244
Definition: resource.h:232
Definition: resource.h:224
Definition: resource.h:105
Definition: resource.h:199
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: resource.h:85