Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "got/utils/compression.h"
#include "common/algorithm.h"
#include "common/endian.h"
namespace Got {
void decompressLzss(const byte *src, byte *dest, const size_t destSize) {
byte *endP = dest + destSize;
for (;;) {
byte v = *src++;
for (int bits = 8; bits > 0; --bits) {
if (endP == dest)
return;
const bool bit = (v & 1) != 0;
v >>= 1;
if (bit) {
*dest++ = *src++;
} else {
uint16 offset = READ_LE_UINT16(src);
src += 2;
const int count = (offset >> 12) + 2;
offset &= 0xfff;
Common::copy(dest - offset, dest - offset + count, dest);
dest += count;
}
}
}
}
void decompressRle(const byte *src, byte *dest, const size_t destSize) {
byte *endP = dest + destSize;
for (;;) {
byte val = *src++;
if ((val & 0x80) != 0) {
const byte rep = *src++;
val &= 0x7f;
Common::fill(dest, dest + val, rep);
dest += val;
} else if (val > 0) {
Common::copy(src, src + val, dest);
src += val;
dest += val;
} else {
break;
}
}
assert(dest == endP);
}
} // namespace Got

View File

@@ -0,0 +1,41 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GOT_UTILS_COMPRESSION_H
#define GOT_UTILS_COMPRESSION_H
#include "common/scummsys.h"
namespace Got {
/**
* LZSS decompressor
*/
void decompressLzss(const byte *src, byte *dest, size_t destSize);
/**
* RLE decoding
*/
void decompressRle(const byte *src, byte *dest, size_t destSize);
} // namespace Got
#endif

132
engines/got/utils/file.cpp Normal file
View File

@@ -0,0 +1,132 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "got/utils/file.h"
#include "got/vars.h"
namespace Got {
bool File::open(const Common::Path &filename) {
if (!Common::File::open(filename))
error("Could not open - %s", filename.baseName().c_str());
return true;
}
bool loadActor(int /*file*/, int num) {
Common::String fname = Common::String::format("ACTOR%d", num);
if (resourceRead(fname, _G(tmpBuff), true) < 0)
return false;
return true;
}
bool loadSpeech(int index) {
char tmps[5];
Common::String fname = Common::String::format("SPEAK%d", _G(area));
char *sp = new char[30000];
if (resourceRead(fname, sp) < 0) {
delete[] sp;
return false;
}
char *p = sp;
int cnt = 0;
for (;;) {
if (*p == ':') {
p++;
cnt++;
strncpy(tmps, p, 4);
tmps[4] = '\0';
if (atoi(tmps) == index) {
break;
}
}
p++;
cnt++;
}
while (*p != 10)
p++;
p++;
char *pm = p;
cnt = 0;
for (;;) {
if (*p == 13)
*p = 32;
if (*p == ':') {
if ((*(p + 1) == 'E') && (*(p + 2) == 'N') && (*(p + 3) == 'D'))
break;
}
p++;
cnt++;
if (cnt > 5799) {
delete[] sp;
return false;
}
}
if (*(p - 1) == 10)
*(p - 1) = 0;
*p = 0;
Common::copy(pm, pm + cnt, _G(tmpBuff));
_G(tmpBuff)
[cnt] = 0;
delete[] sp;
return true;
}
long resourceRead(const Common::String &name, void *buff, bool failAllowed) {
Common::File f;
if (f.open(Common::Path(name))) {
return f.read(buff, f.size());
}
if (!failAllowed)
error("Could not load - %s", name.c_str());
return -1;
}
void *resourceAllocRead(const Common::String &name) {
Common::File f;
if (f.open(Common::Path(name))) {
byte *result = (byte *)malloc(f.size());
f.read(result, f.size());
return result;
}
return nullptr;
}
} // End of namespace Got

47
engines/got/utils/file.h Normal file
View File

@@ -0,0 +1,47 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GOT_UTILS_FILE_H
#define GOT_UTILS_FILE_H
#include "common/file.h"
namespace Got {
extern bool loadActor(int, int num);
extern void setupFilenames(int level);
extern bool loadSpeech(int index);
extern long resourceRead(const Common::String &name, void *buff, bool failAllowed = false);
extern void *resourceAllocRead(const Common::String &name);
class File : public Common::File {
public:
File() : Common::File() {}
File(const Common::String &filename) : Common::File() {
File::open(Common::Path(filename));
}
bool open(const Common::Path &filename) override;
};
} // namespace Got
#endif

View File

@@ -0,0 +1,147 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "got/utils/compression.h"
#include "got/utils/res_archive.h"
namespace Got {
static const char *RES_FILENAME = "gotres.dat";
void resInit() {
ResArchive *a = new ResArchive();
SearchMan.add("Res", a);
}
void ResHeader::load(Common::SeekableReadStream *src) {
char buf[10];
src->read(buf, 9);
buf[9] = '\0';
_name = buf;
_offset = src->readUint32LE();
_size = src->readUint32LE();
_originalSize = src->readUint32LE();
_key = src->readUint16LE();
}
ResArchive::ResArchive() {
Common::File f;
if (!f.open(RES_FILENAME))
error("Could not open %s", RES_FILENAME);
// Read in header data and decrypt it
byte buf[RES_MAX_ENTRIES * RES_HEADER_ENTRY_SIZE];
if (f.read(buf, RES_MAX_ENTRIES * RES_HEADER_ENTRY_SIZE) !=
(RES_MAX_ENTRIES * RES_HEADER_ENTRY_SIZE))
error("Could not read in resource headers");
decrypt(buf, RES_MAX_ENTRIES * RES_HEADER_ENTRY_SIZE, 128);
// Load headers
Common::MemoryReadStream hdrData(buf, RES_MAX_ENTRIES * RES_HEADER_ENTRY_SIZE);
for (int i = 0; i < RES_MAX_ENTRIES; ++i) {
ResHeader hdr;
hdr.load(&hdrData);
if (!(hdr._offset == 0 && hdr._size == 0))
_headers.push_back(hdr);
}
}
void ResArchive::decrypt(byte *buf, size_t len, byte key) const {
for (size_t i = 0; i < len; ++i)
*buf++ ^= key++;
}
int ResArchive::indexOf(const Common::String &name) const {
for (uint i = 0; i < _headers.size(); ++i) {
if (_headers[i]._name.equalsIgnoreCase(name))
return i;
}
return -1;
}
bool ResArchive::hasFile(const Common::Path &path) const {
return indexOf(path.baseName()) != -1;
}
int ResArchive::listMembers(Common::ArchiveMemberList &list) const {
int count = 0;
for (uint i = 0; i < _headers.size(); ++i) {
list.push_back(Common::ArchiveMemberList::value_type(
new Common::GenericArchiveMember(_headers[i]._name, *this)));
++count;
}
return count;
}
const Common::ArchiveMemberPtr ResArchive::getMember(const Common::Path &path) const {
if (!hasFile(path))
return Common::ArchiveMemberPtr();
return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(path, *this));
}
Common::SeekableReadStream *ResArchive::createReadStreamForMember(const Common::Path &path) const {
// Get the index of the header entry for this file
const int hdrIndex = indexOf(path.baseName());
if (hdrIndex == -1)
return nullptr;
Common::File f;
if (!f.open(RES_FILENAME))
error("Error reading resource");
// Set up buffers
const ResHeader &hdr = _headers[hdrIndex];
byte *buf = (byte *)malloc(hdr._size);
f.seek(hdr._offset);
if (f.read(buf, hdr._size) != hdr._size)
error("Error reading resource");
// Decrypt if necessary
if (hdr._key != 0) {
byte *temp = buf;
buf = (byte *)malloc(hdr._originalSize);
lzssDecompress(temp, buf);
free(temp);
}
return new Common::MemoryReadStream(buf, hdr._originalSize,
DisposeAfterUse::YES);
}
void ResArchive::lzssDecompress(const byte *src, byte *dest) const {
const uint16 size = READ_LE_UINT16(src);
assert(READ_LE_UINT16(src + 2) == 1);
src += 4;
decompressLzss(src, dest, size);
}
} // namespace Got

View File

@@ -0,0 +1,102 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GOT_UTILS_RES_ARCHIVE_H
#define GOT_UTILS_RES_ARCHIVE_H
#include "common/archive.h"
#include "common/stream.h"
namespace Got {
struct ResHeader {
Common::String _name;
uint32 _offset = 0;
uint32 _size = 0;
uint32 _originalSize = 0;
int _key = 0;
void load(Common::SeekableReadStream *src);
};
#define RES_MAX_ENTRIES 256 // Max # of elements
#define RES_HEADER_ENTRY_SIZE 23 // Size of a single header entry
class ResArchive : public Common::Archive {
private:
Common::Array<ResHeader> _headers;
/**
* Decrypts a passed buffer
* @param buf Pointer to buffer
* @param len Buffer size
* @param key Starting key to use for decryption
*/
void decrypt(byte *buf, size_t len, byte key) const;
/**
* Decodes a passed buffer
*/
void lzssDecompress(const byte *src, byte *dest) const;
/**
* Returns the index of a header for a given filename
*/
int indexOf(const Common::String &name) const;
public:
/**
* Constructor
*/
ResArchive();
/**
* Check if a member with the given name is present in the Archive.
* Patterns are not allowed, as this is meant to be a quick File::exists()
* replacement.
*/
bool hasFile(const Common::Path &path) const override;
/**
* Add all members of the Archive to list.
* Must only append to list, and not remove elements from it.
*
* @return the number of names added to list
*/
int listMembers(Common::ArchiveMemberList &list) const override;
/**
* Returns a ArchiveMember representation of the given file.
*/
const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
/**
* Create a stream bound to a member with the specified name in the
* archive. If no member with this name exists, 0 is returned.
* @return the newly created input stream
*/
Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
};
extern void resInit();
} // namespace Got
#endif