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.
26 // RSC Resource file management header file
28 #ifndef SAGA_RESOURCE_H
29 #define SAGA_RESOURCE_H
31 #include "common/file.h"
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)
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) {
53 if (_deletePatchFile
) {
65 bool isExternal() { return ((offset
& (1L<<31)) != 0L); } // SAGA2
68 struct ResourceContext
{
72 int serial
; // IHNM speech files
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
;
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
];
102 int32
getEntryNum(uint32 id
) {
103 for (int32 i
= 0; i
< (int32
)count
; i
++) {
104 if (table
[i
].id
== id
) {
113 struct MetaResource
{
116 int32 objectsStringsResourceID
;
117 int32 inventorySpritesID
;
119 int32 objectsResourceID
;
121 int32 actorsStringsResourceID
;
122 int32 actorsResourceID
;
123 int32 protagFaceSpritesID
;
126 int16 protagStatesCount
;
127 int32 protagStatesResourceID
;
128 int32 cutawayListResourceID
;
132 memset(this, 0, sizeof(*this));
138 Resource(SagaEngine
*vm
);
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
];
158 ResourceContext
*_contexts
;
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
);
169 virtual MetaResource
* getMetaResource() = 0;
173 class Resource_RSC
: public Resource
{
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;
183 virtual bool loadMacContext(ResourceContext
*context
);
184 virtual bool loadResContext(ResourceContext
*context
, uint32 contextOffset
, uint32 contextSize
) {
185 return loadResContext_v1(context
, contextOffset
, contextSize
);
191 class Resource_RES
: public Resource
{
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
; };
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
;
208 class Resource_HRS
: public Resource
{
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;
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
);
226 } // End of namespace Saga