aboutsummaryrefslogtreecommitdiff
path: root/engines/tony
diff options
context:
space:
mode:
authorPaul Gilbert2012-04-29 11:01:40 +1000
committerPaul Gilbert2012-04-29 11:01:40 +1000
commitf21bfe1c41148368f30b0602a8e8820fbd543543 (patch)
tree33dd374be4b3f994250df07d98421ee3bfc58f29 /engines/tony
parent40680deaa5f94b1644cf277b8c9a89796a1ff815 (diff)
downloadscummvm-rg350-f21bfe1c41148368f30b0602a8e8820fbd543543.tar.gz
scummvm-rg350-f21bfe1c41148368f30b0602a8e8820fbd543543.tar.bz2
scummvm-rg350-f21bfe1c41148368f30b0602a8e8820fbd543543.zip
TONY: Added resource update manager
Diffstat (limited to 'engines/tony')
-rw-r--r--engines/tony/module.mk1
-rw-r--r--engines/tony/tony.h2
-rw-r--r--engines/tony/utils.cpp114
-rw-r--r--engines/tony/utils.h54
4 files changed, 171 insertions, 0 deletions
diff --git a/engines/tony/module.mk b/engines/tony/module.mk
index b4d0d7321d..0ec4563207 100644
--- a/engines/tony/module.mk
+++ b/engines/tony/module.mk
@@ -3,6 +3,7 @@ MODULE := engines/tony
MODULE_OBJS := \
detection.o \
tony.o \
+ utils.o \
mpal/expr.o \
mpal/loadmpc.o \
mpal/mpal.o \
diff --git a/engines/tony/tony.h b/engines/tony/tony.h
index 804e489d82..9bf5f4cb98 100644
--- a/engines/tony/tony.h
+++ b/engines/tony/tony.h
@@ -31,6 +31,7 @@
#include "engines/engine.h"
#include "tony/mpal/mpal.h"
+#include "tony/utils.h"
/**
* This is the namespace of the Tony engine.
@@ -67,6 +68,7 @@ protected:
public:
LPCUSTOMFUNCTION FuncList[300];
Common::RandomSource _randomSource;
+ RMResUpdate _resUpdate;
public:
TonyEngine(OSystem *syst, const TonyGameDescription *gameDesc);
virtual ~TonyEngine();
diff --git a/engines/tony/utils.cpp b/engines/tony/utils.cpp
new file mode 100644
index 0000000000..1368111a05
--- /dev/null
+++ b/engines/tony/utils.cpp
@@ -0,0 +1,114 @@
+/* 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.
+
+ * 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.
+
+ * 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.
+ *
+ */
+
+#include "tony/utils.h"
+#include "mpal/lzo.h"
+
+namespace Tony {
+
+/****************************************************************************\
+* Resource Update
+\****************************************************************************/
+
+RMResUpdate::RMResUpdate() {
+ _infos = NULL;
+}
+
+RMResUpdate::~RMResUpdate() {
+ if (_infos) {
+ delete[] _infos;
+ _infos = NULL;
+ }
+
+ if (_hFile.isOpen())
+ _hFile.close();
+}
+
+void RMResUpdate::Init(const Common::String &fileName) {
+ // Open the resource update file
+ if (!_hFile.open(fileName))
+ // It doesn't exist, so exit immediately
+ return;
+
+ uint8 version;
+ uint32 i;
+
+ version = _hFile.readByte();
+ _numUpd = _hFile.readUint32LE();
+
+ _infos = new ResUpdInfo[_numUpd];
+
+ // Load the index of the resources in the file
+ for (i=0; i<_numUpd; ++i) {
+ ResUpdInfo &info = _infos[i];
+
+ info.dwRes = _hFile.readUint32LE();
+ info.offset = _hFile.readUint32LE();
+ info.size = _hFile.readUint32LE();
+ info.cmpSize = _hFile.readUint32LE();
+ }
+}
+
+const byte *RMResUpdate::QueryResource(uint32 dwRes) {
+ // If there isn't an update file, return NULL
+ if (!_hFile.isOpen())
+ return NULL;
+
+ uint32 i;
+ for (i=0; i < _numUpd; ++i)
+ if (_infos[i].dwRes == dwRes)
+ // Found the index
+ break;
+
+ if (i==_numUpd)
+ // Couldn't find a matching resource, so return NULL
+ return NULL;
+
+ const ResUpdInfo &info = _infos[i];
+ byte *cmpBuf = new byte[info.cmpSize];
+ uint32 dwRead;
+
+ // Move to the correct offset and read in the compressed data
+ _hFile.seek(info.offset);
+ dwRead = _hFile.read(cmpBuf, info.cmpSize);
+
+ if (info.cmpSize > dwRead) {
+ // Error occurred reading data, so return NULL
+ delete[] cmpBuf;
+ return NULL;
+ }
+
+ // Allocate space for the output resource
+ byte *lpDestBuf = new byte[info.size];
+ uint32 dwSize;
+
+ // Decompress the data
+ MPAL::lzo1x_decompress(cmpBuf, info.cmpSize, lpDestBuf, &dwSize);
+
+ // Delete buffer for compressed data
+ delete [] cmpBuf;
+
+ // Return the resource
+ return lpDestBuf;
+}
+
+} // End of namespace Tony
diff --git a/engines/tony/utils.h b/engines/tony/utils.h
new file mode 100644
index 0000000000..b1afcca074
--- /dev/null
+++ b/engines/tony/utils.h
@@ -0,0 +1,54 @@
+/* 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.
+
+ * 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.
+
+ * 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 TONY_UTILS_H
+#define TONY_UTILS_H
+
+#include "common/scummsys.h"
+#include "common/file.h"
+#include "common/str.h"
+
+namespace Tony {
+
+class RMResUpdate {
+ struct ResUpdInfo {
+ uint32 dwRes;
+ uint32 offset;
+ uint32 size;
+ uint32 cmpSize;
+ };
+
+ uint32 _numUpd;
+ ResUpdInfo *_infos;
+ Common::File _hFile;
+
+public:
+ RMResUpdate();
+ ~RMResUpdate();
+
+ void Init(const Common::String &fileName);
+ const byte *QueryResource(uint32 dwRes);
+};
+
+} // End of namespace Tony
+
+#endif /* TONY_H */