aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2004-04-17 16:29:03 +0000
committerMax Horn2004-04-17 16:29:03 +0000
commit9defe4fc1880ab8926c5cdf167f35985c7ee9afc (patch)
tree6413d350e3d082b9324185a0e6798dd15fd8a58f
parentae50adfd310cc4304129e5c2b5de7ffc69ba229c (diff)
downloadscummvm-rg350-9defe4fc1880ab8926c5cdf167f35985c7ee9afc.tar.gz
scummvm-rg350-9defe4fc1880ab8926c5cdf167f35985c7ee9afc.tar.bz2
scummvm-rg350-9defe4fc1880ab8926c5cdf167f35985c7ee9afc.zip
Removed XOR encoding stuff from File class; instead the new Scumm::XORFile class provides this functionality now
svn-id: r13597
-rw-r--r--common/file.cpp29
-rw-r--r--common/file.h5
-rw-r--r--common/stream.h14
-rw-r--r--scumm/resource.cpp4
-rw-r--r--scumm/script_v5.cpp2
-rw-r--r--scumm/scumm.h21
-rw-r--r--scumm/sound.cpp5
7 files changed, 42 insertions, 38 deletions
diff --git a/common/file.cpp b/common/file.cpp
index 4bb6e94fad..24c8907002 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -132,7 +132,6 @@ void File::setDefaultDirectory(const Common::String &directory) {
File::File() {
_handle = NULL;
_ioFailed = false;
- _encbyte = 0;
_name = 0;
}
@@ -141,7 +140,7 @@ File::~File() {
delete [] _name;
}
-bool File::open(const char *filename, const char *directory, AccessMode mode, byte encbyte) {
+bool File::open(const char *filename, const char *directory, AccessMode mode) {
if (_handle) {
debug(2, "File %s already opened", filename);
return false;
@@ -174,8 +173,6 @@ bool File::open(const char *filename, const char *directory, AccessMode mode, by
return false;
}
- _encbyte = encbyte;
-
int len = strlen(filename);
if (_name != 0)
delete [] _name;
@@ -263,19 +260,10 @@ uint32 File::read(void *ptr, uint32 len) {
_ioFailed = true;
}
- if (_encbyte != 0) {
- uint32 t_size = real_len;
- while (t_size--) {
- *ptr2++ ^= _encbyte;
- }
- }
-
return real_len;
}
uint32 File::write(const void *ptr, uint32 len) {
- byte *tmp = 0;
-
if (_handle == NULL) {
error("File is not open!");
return 0;
@@ -284,25 +272,10 @@ uint32 File::write(const void *ptr, uint32 len) {
if (len == 0)
return 0;
- if (_encbyte != 0) {
- // Maybe FIXME: while it's efficient to do the encoding here,
- // it not really nice for a write function to modify its input.
- // Maybe we should work on a copy here...
- tmp = (byte *)malloc(len);
- for (uint32 i = 0; i < len; i ++) {
- tmp[i] = ((const byte *)ptr)[i] ^ _encbyte;
- }
- ptr = tmp;
- }
-
if ((uint32)fwrite(ptr, 1, len, _handle) != len) {
clearerr(_handle);
_ioFailed = true;
}
- if (_encbyte != 0) {
- free(tmp);
- }
-
return len;
}
diff --git a/common/file.h b/common/file.h
index 42d521495f..ba8eb469e4 100644
--- a/common/file.h
+++ b/common/file.h
@@ -32,7 +32,6 @@ private:
FILE * _handle;
bool _ioFailed;
- byte _encbyte;
char *_name; // For debugging
static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);
@@ -50,7 +49,7 @@ public:
File();
virtual ~File();
bool open(const char *filename, const Common::String &directory) { return open(filename, directory.c_str()); }
- bool open(const char *filename, const char *directory = NULL, AccessMode mode = kFileReadMode, byte encbyte = 0);
+ bool open(const char *filename, const char *directory = NULL, AccessMode mode = kFileReadMode);
void close();
bool isOpen() const;
bool ioFailed() const;
@@ -62,8 +61,6 @@ public:
void seek(int32 offs, int whence = SEEK_SET);
uint32 read(void *ptr, uint32 size);
uint32 write(const void *ptr, uint32 size);
-
- void setEnc(byte value) { _encbyte = value; }
};
#endif
diff --git a/common/stream.h b/common/stream.h
index bd20bdbc20..e5fdd96b09 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -80,16 +80,21 @@ public:
* XORReadStream is a wrapper around an arbitrary other ReadStream,
* which 'decrypts' the data being read by XORing all data bytes with the given
* encryption 'key'.
+ *
+ * Currently, this is not used anywhere, it's just a demo of how one can chain
+ * streams if necessary.
*/
class XORReadStream : public ReadStream {
private:
byte _encbyte;
ReadStream *_realStream;
public:
- XORReadStream(ReadStream *in, byte enc = 0) : _realStream(in), _encbyte(enc) {}
+ XORReadStream(ReadStream *in = 0, byte enc = 0) : _realStream(in), _encbyte(enc) {}
+ void setStream(ReadStream *in) { _realStream = in; }
void setEnc(byte value) { _encbyte = value; }
uint32 read(void *ptr, uint32 size) {
+ assert(_realStream);
uint32 len = _realStream->read(ptr, size);
if (_encbyte) {
byte *p = (byte *)ptr;
@@ -101,6 +106,13 @@ public:
}
};
+/**
+ * Simple memory based 'stream', which implements the ReadStream interface for
+ * a plain memory block.
+ *
+ * Currently not used anywhere, just a proof of concept, and meant to give an
+ * idea of what streams can be used for.
+ */
class MemoryReadStream : public ReadStream {
private:
const byte *_ptr;
diff --git a/scumm/resource.cpp b/scumm/resource.cpp
index 9fe9eacc81..4dbd1ff6af 100644
--- a/scumm/resource.cpp
+++ b/scumm/resource.cpp
@@ -222,7 +222,8 @@ bool ScummEngine::openResourceFile(const char *filename, byte encByte) {
_fileHandle.close();
}
- _fileHandle.open(filename, getGameDataPath(), File::kFileReadMode, encByte);
+ _fileHandle.open(filename);
+ _fileHandle.setEnc(encByte);
return _fileHandle.isOpen();
}
@@ -888,6 +889,7 @@ static const uint16 num_steps_table[] = {
240, 276, 340, 460,
600, 860, 1200, 1600
};
+
int ScummEngine::convert_extraflags(byte * ptr, byte * src_ptr) {
int flags = src_ptr[0];
diff --git a/scumm/script_v5.cpp b/scumm/script_v5.cpp
index 3d50febab3..4f0e9bcd8e 100644
--- a/scumm/script_v5.cpp
+++ b/scumm/script_v5.cpp
@@ -2684,7 +2684,7 @@ void ScummEngine_v5::decodeParseString() {
break;
case 15: // SO_TEXTSTRING
msg = _scriptPointer;
- _scriptPointer += resStrLen(_scriptPointer)+ 1;
+ _scriptPointer += resStrLen(_scriptPointer) + 1;
switch (textSlot) {
case 0:
diff --git a/scumm/scumm.h b/scumm/scumm.h
index e7971cb586..62570d1d74 100644
--- a/scumm/scumm.h
+++ b/scumm/scumm.h
@@ -60,6 +60,25 @@ struct ScummGameSettings;
typedef Common::Map<Common::String, int> ObjectIDMap;
+class XORFile : public File {
+private:
+ byte _encbyte;
+public:
+ XORFile() : _encbyte(0) {}
+ void setEnc(byte value) { _encbyte = value; }
+
+ uint32 read(void *ptr, uint32 len) {
+ uint32 realLen = File::read(ptr, len);
+ if (_encbyte) {
+ byte *p = (byte *)ptr;
+ byte *end = p + realLen;
+ while (p < end)
+ *p++ ^= _encbyte;
+ }
+ return realLen;
+ }
+};
+
// Use g_scumm from error() ONLY
extern ScummEngine *g_scumm;
@@ -599,7 +618,7 @@ protected:
void doSentence(int c, int b, int a);
/* Should be in Resource class */
- File _fileHandle;
+ XORFile _fileHandle;
uint32 _fileOffset;
int _resourceHeaderSize;
Common::String _gameName; // This is the name we use for opening resource files
diff --git a/scumm/sound.cpp b/scumm/sound.cpp
index 8d40f16c64..a668c8c82a 100644
--- a/scumm/sound.cpp
+++ b/scumm/sound.cpp
@@ -892,7 +892,7 @@ void Sound::startSfxSound(File *file, int file_size, PlayingSoundHandle *handle,
File *Sound::openSfxFile() {
char buf[256];
- File *file = new File();
+ XORFile *file = new XORFile();
_offsetTable = NULL;
struct SoundFileExtensions {
@@ -935,7 +935,8 @@ File *Sound::openSfxFile() {
if (!file->isOpen()) {
sprintf(buf, "%s.tlk", _vm->getGameName());
- file->open(buf, _vm->getGameDataPath(), File::kFileReadMode, 0x69);
+ file->open(buf);
+ file->setEnc(0x69);
_soundMode = kVOCMode;
} else if (_soundMode != kVOCMode) {
/* Now load the 'offset' index in memory to be able to find the MP3 data