Speech bubbles can point down right.
[scummvm-innocent.git] / engines / saga / resource.h
blobc3554cf7ce2c3943574d606111e89f5245d034c7
1 /* ScummVM - Graphic Adventure Engine
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.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $URL$
22 * $Id$
26 // RSC Resource file management header file
28 #ifndef SAGA_RESOURCE_H
29 #define SAGA_RESOURCE_H
31 #include "common/file.h"
33 namespace Saga {
35 #define MAC_BINARY_HEADER_SIZE 128
36 #define RSC_TABLEINFO_SIZE 8
37 #define RSC_TABLEENTRY_SIZE 8
39 #define RSC_MIN_FILESIZE (RSC_TABLEINFO_SIZE + RSC_TABLEENTRY_SIZE + 1)
41 struct PatchData {
42 bool _deletePatchFile;
43 Common::File *_patchFile;
44 const GamePatchDescription *_patchDescription;
46 PatchData(const GamePatchDescription *patchDescription): _patchDescription(patchDescription), _deletePatchFile(true) {
47 _patchFile = new Common::File();
49 PatchData(Common::File *patchFile): _patchDescription(NULL), _patchFile(patchFile), _deletePatchFile(false) {
52 ~PatchData() {
53 if (_deletePatchFile) {
54 delete _patchFile;
59 struct ResourceData {
60 uint32 id; // SAGA2
61 size_t offset;
62 size_t size;
63 PatchData *patchData;
65 bool isExternal() { return ((offset & (1L<<31)) != 0L); } // SAGA2
68 struct ResourceContext {
69 const char *fileName;
70 uint16 fileType;
71 Common::File *file;
72 int serial; // IHNM speech files
74 bool isCompressed;
75 bool isBigEndian;
76 ResourceData *table;
77 size_t count;
78 ResourceData *categories; // SAGA2
80 Common::File *getFile(ResourceData *resourceData) const {
81 if (resourceData->patchData != NULL) {
82 if (!resourceData->patchData->_patchFile->isOpen())
83 resourceData->patchData->_patchFile->open(resourceData->patchData->_patchDescription->fileName);
84 return resourceData->patchData->_patchFile;
85 } else {
86 return file;
90 bool validResourceId(uint32 resourceId) const {
91 return (resourceId < count);
94 ResourceData *getResourceData(uint32 resourceId) const {
95 if (resourceId >= count) {
96 error("ResourceContext::getResourceData() wrong resourceId %d", resourceId);
98 return &table[resourceId];
101 // SAGA 2
102 int32 getEntryNum(uint32 id) {
103 for (int32 i = 0; i < (int32)count; i++) {
104 if (table[i].id == id) {
105 return i;
108 return -1;
113 struct MetaResource {
114 int16 sceneIndex;
115 int16 objectCount;
116 int32 objectsStringsResourceID;
117 int32 inventorySpritesID;
118 int32 mainSpritesID;
119 int32 objectsResourceID;
120 int16 actorCount;
121 int32 actorsStringsResourceID;
122 int32 actorsResourceID;
123 int32 protagFaceSpritesID;
124 int32 field_22;
125 int16 field_26;
126 int16 protagStatesCount;
127 int32 protagStatesResourceID;
128 int32 cutawayListResourceID;
129 int32 songTableID;
131 MetaResource() {
132 memset(this, 0, sizeof(*this));
136 class Resource {
137 public:
138 Resource(SagaEngine *vm);
139 virtual ~Resource();
140 bool createContexts();
141 void clearContexts();
142 void loadResource(ResourceContext *context, uint32 resourceId, byte*&resourceBuffer, size_t &resourceSize);
144 virtual uint32 convertResourceId(uint32 resourceId) = 0;
145 virtual void loadGlobalResources(int chapter, int actorsEntrance) = 0;
147 ResourceContext *getContext(uint16 fileType, int serial = 0) {
148 for (int i = 0; i < _contextsCount; i++) {
149 if ((_contexts[i].fileType & fileType) && _contexts[i].serial == serial) {
150 return &_contexts[i];
153 return NULL;
156 protected:
157 SagaEngine *_vm;
158 ResourceContext *_contexts;
159 int _contextsCount;
160 char _voicesFileName[8][256];
161 char _musicFileName[256];
162 char _soundFileName[256];
164 bool loadContext(ResourceContext *context);
165 virtual bool loadMacContext(ResourceContext *context) = 0;
166 virtual bool loadResContext(ResourceContext *context, uint32 contextOffset, uint32 contextSize) = 0;
167 bool loadResContext_v1(ResourceContext *context, uint32 contextOffset, uint32 contextSize);
168 public:
169 virtual MetaResource* getMetaResource() = 0;
172 // ITE
173 class Resource_RSC : public Resource {
174 public:
175 Resource_RSC(SagaEngine *vm) : Resource(vm) {}
176 virtual uint32 convertResourceId(uint32 resourceId);
177 virtual void loadGlobalResources(int chapter, int actorsEntrance) {}
178 virtual MetaResource* getMetaResource() {
179 MetaResource *dummy = 0;
180 return dummy;
182 private:
183 virtual bool loadMacContext(ResourceContext *context);
184 virtual bool loadResContext(ResourceContext *context, uint32 contextOffset, uint32 contextSize) {
185 return loadResContext_v1(context, contextOffset, contextSize);
189 #ifdef ENABLE_IHNM
190 // IHNM
191 class Resource_RES : public Resource {
192 public:
193 Resource_RES(SagaEngine *vm) : Resource(vm) {}
194 virtual uint32 convertResourceId(uint32 resourceId) { return resourceId; }
195 virtual void loadGlobalResources(int chapter, int actorsEntrance);
196 virtual MetaResource* getMetaResource() { return &_metaResource; };
197 private:
198 virtual bool loadMacContext(ResourceContext *context) { return false; }
199 virtual bool loadResContext(ResourceContext *context, uint32 contextOffset, uint32 contextSize) {
200 return loadResContext_v1(context, 0, contextSize);
202 MetaResource _metaResource;
204 #endif
206 #ifdef ENABLE_SAGA2
207 // DINO, FTA2
208 class Resource_HRS : public Resource {
209 public:
210 Resource_HRS(SagaEngine *vm) : Resource(vm) {}
211 virtual uint32 convertResourceId(uint32 resourceId) { return resourceId; }
212 virtual void loadGlobalResources(int chapter, int actorsEntrance) {}
213 virtual MetaResource* getMetaResource() {
214 MetaResource *dummy = 0;
215 return dummy;
217 private:
218 virtual bool loadMacContext(ResourceContext *context) { return false; }
219 virtual bool loadResContext(ResourceContext *context, uint32 contextOffset, uint32 contextSize) {
220 return loadResContext_v2(context, contextSize);
222 bool loadResContext_v2(ResourceContext *context, uint32 contextSize);
224 #endif
226 } // End of namespace Saga
228 #endif