Removed XOR encoding stuff from File class; instead the new Scumm::XORFile class provides this functionality now
svn-id: r13597
This commit is contained in:
parent
ae50adfd31
commit
9defe4fc18
7 changed files with 42 additions and 38 deletions
|
@ -132,7 +132,6 @@ void File::setDefaultDirectory(const Common::String &directory) {
|
||||||
File::File() {
|
File::File() {
|
||||||
_handle = NULL;
|
_handle = NULL;
|
||||||
_ioFailed = false;
|
_ioFailed = false;
|
||||||
_encbyte = 0;
|
|
||||||
_name = 0;
|
_name = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +140,7 @@ File::~File() {
|
||||||
delete [] _name;
|
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) {
|
if (_handle) {
|
||||||
debug(2, "File %s already opened", filename);
|
debug(2, "File %s already opened", filename);
|
||||||
return false;
|
return false;
|
||||||
|
@ -174,8 +173,6 @@ bool File::open(const char *filename, const char *directory, AccessMode mode, by
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_encbyte = encbyte;
|
|
||||||
|
|
||||||
int len = strlen(filename);
|
int len = strlen(filename);
|
||||||
if (_name != 0)
|
if (_name != 0)
|
||||||
delete [] _name;
|
delete [] _name;
|
||||||
|
@ -263,19 +260,10 @@ uint32 File::read(void *ptr, uint32 len) {
|
||||||
_ioFailed = true;
|
_ioFailed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_encbyte != 0) {
|
|
||||||
uint32 t_size = real_len;
|
|
||||||
while (t_size--) {
|
|
||||||
*ptr2++ ^= _encbyte;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return real_len;
|
return real_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 File::write(const void *ptr, uint32 len) {
|
uint32 File::write(const void *ptr, uint32 len) {
|
||||||
byte *tmp = 0;
|
|
||||||
|
|
||||||
if (_handle == NULL) {
|
if (_handle == NULL) {
|
||||||
error("File is not open!");
|
error("File is not open!");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -284,25 +272,10 @@ uint32 File::write(const void *ptr, uint32 len) {
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 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) {
|
if ((uint32)fwrite(ptr, 1, len, _handle) != len) {
|
||||||
clearerr(_handle);
|
clearerr(_handle);
|
||||||
_ioFailed = true;
|
_ioFailed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_encbyte != 0) {
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ private:
|
||||||
|
|
||||||
FILE * _handle;
|
FILE * _handle;
|
||||||
bool _ioFailed;
|
bool _ioFailed;
|
||||||
byte _encbyte;
|
|
||||||
char *_name; // For debugging
|
char *_name; // For debugging
|
||||||
|
|
||||||
static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);
|
static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);
|
||||||
|
@ -50,7 +49,7 @@ public:
|
||||||
File();
|
File();
|
||||||
virtual ~File();
|
virtual ~File();
|
||||||
bool open(const char *filename, const Common::String &directory) { return open(filename, directory.c_str()); }
|
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();
|
void close();
|
||||||
bool isOpen() const;
|
bool isOpen() const;
|
||||||
bool ioFailed() const;
|
bool ioFailed() const;
|
||||||
|
@ -62,8 +61,6 @@ public:
|
||||||
void seek(int32 offs, int whence = SEEK_SET);
|
void seek(int32 offs, int whence = SEEK_SET);
|
||||||
uint32 read(void *ptr, uint32 size);
|
uint32 read(void *ptr, uint32 size);
|
||||||
uint32 write(const void *ptr, uint32 size);
|
uint32 write(const void *ptr, uint32 size);
|
||||||
|
|
||||||
void setEnc(byte value) { _encbyte = value; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -80,16 +80,21 @@ public:
|
||||||
* XORReadStream is a wrapper around an arbitrary other ReadStream,
|
* XORReadStream is a wrapper around an arbitrary other ReadStream,
|
||||||
* which 'decrypts' the data being read by XORing all data bytes with the given
|
* which 'decrypts' the data being read by XORing all data bytes with the given
|
||||||
* encryption 'key'.
|
* 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 {
|
class XORReadStream : public ReadStream {
|
||||||
private:
|
private:
|
||||||
byte _encbyte;
|
byte _encbyte;
|
||||||
ReadStream *_realStream;
|
ReadStream *_realStream;
|
||||||
public:
|
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; }
|
void setEnc(byte value) { _encbyte = value; }
|
||||||
|
|
||||||
uint32 read(void *ptr, uint32 size) {
|
uint32 read(void *ptr, uint32 size) {
|
||||||
|
assert(_realStream);
|
||||||
uint32 len = _realStream->read(ptr, size);
|
uint32 len = _realStream->read(ptr, size);
|
||||||
if (_encbyte) {
|
if (_encbyte) {
|
||||||
byte *p = (byte *)ptr;
|
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 {
|
class MemoryReadStream : public ReadStream {
|
||||||
private:
|
private:
|
||||||
const byte *_ptr;
|
const byte *_ptr;
|
||||||
|
|
|
@ -222,7 +222,8 @@ bool ScummEngine::openResourceFile(const char *filename, byte encByte) {
|
||||||
_fileHandle.close();
|
_fileHandle.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
_fileHandle.open(filename, getGameDataPath(), File::kFileReadMode, encByte);
|
_fileHandle.open(filename);
|
||||||
|
_fileHandle.setEnc(encByte);
|
||||||
|
|
||||||
return _fileHandle.isOpen();
|
return _fileHandle.isOpen();
|
||||||
}
|
}
|
||||||
|
@ -888,6 +889,7 @@ static const uint16 num_steps_table[] = {
|
||||||
240, 276, 340, 460,
|
240, 276, 340, 460,
|
||||||
600, 860, 1200, 1600
|
600, 860, 1200, 1600
|
||||||
};
|
};
|
||||||
|
|
||||||
int ScummEngine::convert_extraflags(byte * ptr, byte * src_ptr) {
|
int ScummEngine::convert_extraflags(byte * ptr, byte * src_ptr) {
|
||||||
int flags = src_ptr[0];
|
int flags = src_ptr[0];
|
||||||
|
|
||||||
|
|
|
@ -2684,7 +2684,7 @@ void ScummEngine_v5::decodeParseString() {
|
||||||
break;
|
break;
|
||||||
case 15: // SO_TEXTSTRING
|
case 15: // SO_TEXTSTRING
|
||||||
msg = _scriptPointer;
|
msg = _scriptPointer;
|
||||||
_scriptPointer += resStrLen(_scriptPointer)+ 1;
|
_scriptPointer += resStrLen(_scriptPointer) + 1;
|
||||||
|
|
||||||
switch (textSlot) {
|
switch (textSlot) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -60,6 +60,25 @@ struct ScummGameSettings;
|
||||||
|
|
||||||
typedef Common::Map<Common::String, int> ObjectIDMap;
|
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
|
// Use g_scumm from error() ONLY
|
||||||
extern ScummEngine *g_scumm;
|
extern ScummEngine *g_scumm;
|
||||||
|
|
||||||
|
@ -599,7 +618,7 @@ protected:
|
||||||
void doSentence(int c, int b, int a);
|
void doSentence(int c, int b, int a);
|
||||||
|
|
||||||
/* Should be in Resource class */
|
/* Should be in Resource class */
|
||||||
File _fileHandle;
|
XORFile _fileHandle;
|
||||||
uint32 _fileOffset;
|
uint32 _fileOffset;
|
||||||
int _resourceHeaderSize;
|
int _resourceHeaderSize;
|
||||||
Common::String _gameName; // This is the name we use for opening resource files
|
Common::String _gameName; // This is the name we use for opening resource files
|
||||||
|
|
|
@ -892,7 +892,7 @@ void Sound::startSfxSound(File *file, int file_size, PlayingSoundHandle *handle,
|
||||||
|
|
||||||
File *Sound::openSfxFile() {
|
File *Sound::openSfxFile() {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
File *file = new File();
|
XORFile *file = new XORFile();
|
||||||
_offsetTable = NULL;
|
_offsetTable = NULL;
|
||||||
|
|
||||||
struct SoundFileExtensions {
|
struct SoundFileExtensions {
|
||||||
|
@ -935,7 +935,8 @@ File *Sound::openSfxFile() {
|
||||||
|
|
||||||
if (!file->isOpen()) {
|
if (!file->isOpen()) {
|
||||||
sprintf(buf, "%s.tlk", _vm->getGameName());
|
sprintf(buf, "%s.tlk", _vm->getGameName());
|
||||||
file->open(buf, _vm->getGameDataPath(), File::kFileReadMode, 0x69);
|
file->open(buf);
|
||||||
|
file->setEnc(0x69);
|
||||||
_soundMode = kVOCMode;
|
_soundMode = kVOCMode;
|
||||||
} else if (_soundMode != kVOCMode) {
|
} else if (_soundMode != kVOCMode) {
|
||||||
/* Now load the 'offset' index in memory to be able to find the MP3 data
|
/* Now load the 'offset' index in memory to be able to find the MP3 data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue