2013-06-04 20:24:40 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2013-06-04 20:24:40 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2013-06-04 20:24:40 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FULLPIPE_UTILS_H
|
|
|
|
#define FULLPIPE_UTILS_H
|
|
|
|
|
2013-06-07 20:56:40 +00:00
|
|
|
#include "common/hash-str.h"
|
|
|
|
#include "common/array.h"
|
2013-06-19 18:46:25 +00:00
|
|
|
#include "common/file.h"
|
2013-06-07 20:56:40 +00:00
|
|
|
|
2013-06-04 20:24:40 +00:00
|
|
|
namespace Fullpipe {
|
|
|
|
|
2013-06-06 21:49:50 +00:00
|
|
|
class CObject;
|
2013-06-22 01:30:38 +00:00
|
|
|
class NGIArchive;
|
2013-06-06 21:49:50 +00:00
|
|
|
|
2016-09-17 22:59:17 +00:00
|
|
|
struct Pointer_EqualTo {
|
|
|
|
bool operator()(const void *x, const void *y) const { return x == y; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Pointer_Hash {
|
|
|
|
uint operator()(const void *x) const {
|
|
|
|
#ifdef SCUMM_64BITS
|
|
|
|
uint64 v = (uint64)x;
|
|
|
|
return (v >> 32) ^ (v & 0xffffffff);
|
|
|
|
#else
|
|
|
|
return (uint)x;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef Common::HashMap<void *, int, Pointer_Hash, Pointer_EqualTo> ObjHash;
|
|
|
|
|
2013-06-07 20:56:40 +00:00
|
|
|
typedef Common::HashMap<Common::String, int, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ClassMap;
|
|
|
|
|
2016-09-17 22:02:11 +00:00
|
|
|
class MfcArchive : public Common::SeekableReadStream, public Common::WriteStream {
|
2013-06-07 20:56:40 +00:00
|
|
|
ClassMap _classMap;
|
2013-06-10 22:17:11 +00:00
|
|
|
Common::Array<CObject *> _objectMap;
|
|
|
|
Common::Array<int> _objectIdMap;
|
2016-09-17 22:59:17 +00:00
|
|
|
ObjHash _objectHash;
|
2013-06-07 20:56:40 +00:00
|
|
|
|
|
|
|
int _lastIndex;
|
2013-06-10 22:34:37 +00:00
|
|
|
int _level;
|
2013-06-07 20:56:40 +00:00
|
|
|
|
2013-06-20 21:21:37 +00:00
|
|
|
Common::SeekableReadStream *_stream;
|
2016-09-17 18:41:15 +00:00
|
|
|
Common::WriteStream *_wstream;
|
2013-06-20 21:21:37 +00:00
|
|
|
|
2016-09-17 18:41:15 +00:00
|
|
|
public:
|
2013-06-20 21:21:37 +00:00
|
|
|
MfcArchive(Common::SeekableReadStream *file);
|
2016-09-17 18:41:15 +00:00
|
|
|
MfcArchive(Common::WriteStream *file);
|
2013-06-07 20:56:40 +00:00
|
|
|
|
2013-06-08 14:05:51 +00:00
|
|
|
char *readPascalString(bool twoByte = false);
|
2016-09-19 16:58:39 +00:00
|
|
|
void writePascalString(const char *str, bool twoByte = false);
|
2013-06-07 20:56:40 +00:00
|
|
|
int readCount();
|
2013-06-16 13:10:46 +00:00
|
|
|
double readDouble();
|
2013-06-10 22:17:11 +00:00
|
|
|
CObject *parseClass(bool *isCopyReturned);
|
2013-06-09 22:03:15 +00:00
|
|
|
CObject *readClass();
|
2013-06-10 22:34:37 +00:00
|
|
|
|
2016-09-17 22:02:11 +00:00
|
|
|
void writeObject(CObject *obj);
|
|
|
|
|
2013-06-10 22:34:37 +00:00
|
|
|
void incLevel() { _level++; }
|
|
|
|
void decLevel() { _level--; }
|
|
|
|
int getLevel() { return _level; }
|
2013-06-20 21:21:37 +00:00
|
|
|
|
|
|
|
virtual bool eos() const { return _stream->eos(); }
|
|
|
|
virtual uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
|
2016-09-17 18:41:15 +00:00
|
|
|
virtual int32 pos() const { return _stream ? _stream->pos() : _wstream->pos(); }
|
2013-06-20 21:21:37 +00:00
|
|
|
virtual int32 size() const { return _stream->size(); }
|
|
|
|
virtual bool seek(int32 offset, int whence = SEEK_SET) { return _stream->seek(offset, whence); }
|
2016-09-17 18:41:15 +00:00
|
|
|
|
|
|
|
virtual uint32 write(const void *dataPtr, uint32 dataSize) { return _wstream->write(dataPtr, dataSize); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init();
|
2013-06-04 20:24:40 +00:00
|
|
|
};
|
|
|
|
|
2013-08-26 19:17:20 +00:00
|
|
|
enum ObjType {
|
|
|
|
kObjTypeDefault,
|
2014-01-04 13:01:27 +00:00
|
|
|
kObjTypeExCommand,
|
|
|
|
kObjTypeExCommand2,
|
2014-05-01 06:44:47 +00:00
|
|
|
kObjTypeModalSaveGame,
|
2013-10-16 21:55:34 +00:00
|
|
|
kObjTypeMovGraph,
|
2013-10-17 19:44:30 +00:00
|
|
|
kObjTypeMovGraphLink,
|
2013-10-16 21:55:34 +00:00
|
|
|
kObjTypeMovGraphNode,
|
|
|
|
kObjTypeMctlCompound,
|
2013-09-04 21:13:16 +00:00
|
|
|
kObjTypeObjstateCommand,
|
2013-09-17 20:00:33 +00:00
|
|
|
kObjTypePictureObject,
|
2016-09-19 16:58:39 +00:00
|
|
|
kObjTypeStaticANIObject,
|
|
|
|
kObjTypeGameVar
|
2013-08-26 19:17:20 +00:00
|
|
|
};
|
|
|
|
|
2013-06-20 18:44:59 +00:00
|
|
|
class CObject {
|
2013-10-16 21:55:34 +00:00
|
|
|
public:
|
2013-08-26 19:17:20 +00:00
|
|
|
ObjType _objtype;
|
|
|
|
|
|
|
|
CObject() : _objtype(kObjTypeDefault) {}
|
2013-06-20 18:44:59 +00:00
|
|
|
virtual bool load(MfcArchive &in) { return true; }
|
2016-09-17 22:02:11 +00:00
|
|
|
virtual void save(MfcArchive &out) { error("Not implemented for obj type: %d", _objtype); }
|
2013-06-20 18:44:59 +00:00
|
|
|
virtual ~CObject() {}
|
|
|
|
|
|
|
|
bool loadFile(const char *fname);
|
|
|
|
};
|
|
|
|
|
2013-09-18 15:08:31 +00:00
|
|
|
class ObList : public Common::List<CObject *>, public CObject {
|
2013-06-20 18:44:59 +00:00
|
|
|
public:
|
|
|
|
virtual bool load(MfcArchive &file);
|
|
|
|
};
|
|
|
|
|
2013-06-21 01:49:28 +00:00
|
|
|
class MemoryObject : CObject {
|
2013-06-22 01:30:38 +00:00
|
|
|
friend class Picture;
|
2013-08-07 17:52:23 +00:00
|
|
|
friend class Scene;
|
2013-06-22 01:30:38 +00:00
|
|
|
|
2013-06-22 17:26:49 +00:00
|
|
|
protected:
|
2013-07-16 20:54:18 +00:00
|
|
|
char *_memfilename;
|
2013-08-12 09:32:49 +00:00
|
|
|
int _mfield_8;
|
|
|
|
int _mfield_C;
|
|
|
|
int _mfield_10;
|
|
|
|
char _mfield_14;
|
2013-07-11 05:09:11 +00:00
|
|
|
byte *_data;
|
2013-06-22 01:30:38 +00:00
|
|
|
int _dataSize;
|
2013-08-12 09:32:49 +00:00
|
|
|
int _mflags;
|
2013-06-22 01:30:38 +00:00
|
|
|
NGIArchive *_libHandle;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MemoryObject();
|
2013-07-26 12:39:17 +00:00
|
|
|
virtual ~MemoryObject();
|
|
|
|
|
2013-06-22 01:30:38 +00:00
|
|
|
virtual bool load(MfcArchive &file);
|
|
|
|
void loadFile(char *filename);
|
2013-07-16 20:54:18 +00:00
|
|
|
void load() { loadFile(_memfilename); }
|
2013-07-12 06:03:02 +00:00
|
|
|
byte *getData();
|
2013-07-26 12:39:17 +00:00
|
|
|
byte *loadData();
|
2014-01-03 14:03:27 +00:00
|
|
|
int getDataSize() const { return _dataSize; }
|
2013-07-26 12:39:17 +00:00
|
|
|
|
|
|
|
bool testFlags();
|
|
|
|
|
|
|
|
void freeData();
|
2013-06-22 01:30:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MemoryObject2 : public MemoryObject {
|
2013-07-12 06:03:02 +00:00
|
|
|
friend class Picture;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
byte **_rows;
|
2013-06-22 01:30:38 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
MemoryObject2();
|
2013-07-26 12:39:17 +00:00
|
|
|
virtual ~MemoryObject2();
|
2013-06-22 01:30:38 +00:00
|
|
|
virtual bool load(MfcArchive &file);
|
2013-07-26 12:39:17 +00:00
|
|
|
|
|
|
|
void copyData(byte *src, int dataSize);
|
2013-06-20 18:44:59 +00:00
|
|
|
};
|
|
|
|
|
2013-09-18 15:08:31 +00:00
|
|
|
class ObArray : public Common::Array<CObject>, public CObject {
|
2013-06-20 18:44:59 +00:00
|
|
|
public:
|
|
|
|
virtual bool load(MfcArchive &file);
|
|
|
|
};
|
|
|
|
|
2013-09-18 15:08:31 +00:00
|
|
|
class DWordArray : public Common::Array<int32>, public CObject {
|
2013-06-20 18:44:59 +00:00
|
|
|
public:
|
|
|
|
virtual bool load(MfcArchive &file);
|
|
|
|
};
|
|
|
|
|
2013-06-20 20:39:05 +00:00
|
|
|
char *genFileName(int superId, int sceneId, const char *ext);
|
2013-06-27 00:46:14 +00:00
|
|
|
byte *transCyrillic(byte *s);
|
2013-06-20 20:39:05 +00:00
|
|
|
|
2013-06-04 20:24:40 +00:00
|
|
|
} // End of namespace Fullpipe
|
|
|
|
|
|
|
|
#endif /* FULLPIPE_UTILS_H */
|