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 "common/file.h"
#include "image/bmp.h"
#include "mm/shared/utils/bitmap_font.h"
namespace MM {
bool BitmapFont::load(const Common::Path &filename) {
Image::BitmapDecoder decoder;
Common::File f;
_startingChar = ' ';
if (!f.open(filename))
error("Could not open font");
if (!decoder.loadStream(f))
error("Could not decode font");
const Graphics::Surface &src = *decoder.getSurface();
assert(src.format.bytesPerPixel == 1);
assert((src.w % 8) == 0);
assert((src.h % 8) == 0);
// Set up a characters array
_chars.resize(97 - 32);
// Iterate through loading characters
Common::Rect r(8, 8);
int charsPerRow = src.w / 8;
for (uint idx = 0; idx < _chars.size(); ++idx) {
r.moveTo((idx % charsPerRow) * 8, (idx / charsPerRow) * 8);
Common::Rect charBounds(r.left, r.top, r.left + 8, r.bottom);
_chars[idx].create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
_chars[idx].transBlitFrom(src, charBounds, Common::Rect(0, 0, 8, 8));
}
return true;
}
void BitmapFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const {
// Get the fg/bg color. When the character is >= 128,
// the colors are reversed from normal
byte fgColor = (chr < 128) ? color : 0;
byte bgColor = (chr < 128) ? 0 : color;
chr &= 0x7f;
const Graphics::ManagedSurface &c = _chars[chr - _startingChar];
for (int yCtr = 0; yCtr < c.h; ++yCtr) {
const byte *srcP = (const byte *)c.getBasePtr(0, yCtr);
for (int xCtr = 0; xCtr < c.w; ++xCtr, ++srcP) {
dst->hLine(x + xCtr, y + yCtr, x + xCtr,
*srcP ? bgColor : fgColor);
}
}
}
} // namespace MM

View File

@@ -0,0 +1,76 @@
/* 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 MM_UTILS_BITMAP_FONT_H
#define MM_UTILS_BITMAP_FONT_H
#include "common/array.h"
#include "common/rect.h"
#include "graphics/font.h"
#include "graphics/managed_surface.h"
namespace MM {
/**
* Implements a font stored as a grid on a passed surface
*/
class BitmapFont : public Graphics::Font {
private:
Common::Array<Graphics::ManagedSurface> _chars;
size_t _startingChar;
public:
/**
* Constructor
*/
BitmapFont() : _startingChar(' ') {}
/**
* Loads the font
*/
bool load(const Common::Path &filename);
/**
* Get the font height
*/
int getFontHeight() const override { return 8; }
/**
* Get the maximum character width
*/
int getMaxCharWidth() const override { return 8; }
/**
* Get the width of the given character
*/
int getCharWidth(uint32 chr) const override { return 8; }
/**
* Draw a character
*/
void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
void drawChar(Graphics::ManagedSurface *dst, uint32 chr, int x, int y, uint32 color) const override {
Graphics::Font::drawChar(dst, chr, x, y, color);
}
};
} // namespace MM
#endif

View File

@@ -0,0 +1,141 @@
/* 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/textconsole.h"
#include "mm/shared/utils/strings.h"
namespace MM {
Common::String capitalize(const Common::String &str) {
Common::String result = str;
bool capitalize = true;
for (uint i = 0; i < str.size(); ++i) {
if (!scumm_strnicmp(result.c_str() - 1, " i ", 3))
// the word 'I' is always capitalized
capitalize = true;
if (capitalize) {
result.setChar(toupper(result[i]), i);
capitalize = false;
} else {
result.setChar(tolower(result[i]), i);
}
if (result[i] == '.')
capitalize = true;
}
return result;
}
Common::String camelCase(const Common::String &str) {
Common::String result = str;
bool capitalize = true;
for (uint i = 0; i < str.size(); ++i) {
if (capitalize) {
result.setChar(toupper(result[i]), i);
capitalize = false;
} else {
result.setChar(tolower(result[i]), i);
}
if (result[i] == ' ')
capitalize = true;
}
return result;
}
Common::String uppercase(const Common::String &str) {
Common::String result;
for (uint i = 0; i < str.size(); ++i)
result += toupper(str[i]);
return result;
}
Common::String searchAndReplace(const Common::String &str,
const Common::String &find, const Common::String &replace) {
Common::String result = str;
const char *p = result.c_str();
while ((p = strstr(p, find.c_str())) != nullptr) {
uint idx = p - result.c_str();
result = Common::String::format("%s%s%s",
Common::String(result.c_str(), p).c_str(),
replace.c_str(),
Common::String(p + find.size()).c_str()
);
p = result.c_str() + idx + replace.size();
}
return result;
}
int strToInt(const Common::String &str) {
const char *s = str.c_str();
size_t size = strlen(s);
if (size == 0)
// No string at all
return 0;
if (toupper(s[size - 1]) != 'H')
// Standard decimal string
return atoi(s);
// Hexadecimal string
uint tmp = 0;
int read = sscanf(s, "%xh", &tmp);
if (read < 1)
error("strToInt failed on string \"%s\"", s);
return (int)tmp;
}
int hexToInt(const Common::String &str) {
uint tmp = 0;
int read = sscanf(str.c_str(), "%xh", &tmp);
if (read < 1)
error("hexToInt failed on string \"%s\"", str.c_str());
return (int)tmp;
}
Common::StringArray splitLines(const Common::String &str) {
Common::StringArray results;
size_t start = 0, end;
while ((end = str.findFirstOf('\n', start)) != Common::String::npos) {
results.push_back(Common::String(
str.c_str() + start, str.c_str() + end));
start = end + 1;
}
results.push_back(str.c_str() + start);
return results;
}
} // namespace MM

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 MM_UTILS_STRINGS_H
#define MM_UTILS_STRINGS_H
#include "common/str.h"
#include "common/str-array.h"
namespace MM {
extern Common::String capitalize(const Common::String &str);
extern Common::String camelCase(const Common::String &str);
extern Common::String uppercase(const Common::String &str);
extern Common::String searchAndReplace(const Common::String &str,
const Common::String &find, const Common::String &replace);
extern int strToInt(const Common::String &str);
extern int hexToInt(const Common::String &str);
extern Common::StringArray splitLines(const Common::String &str);
} // namespace MM
#endif

View File

@@ -0,0 +1,121 @@
/* 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/array.h"
#include "common/file.h"
#include "mm/shared/utils/strings_data.h"
#include "mm/shared/utils/strings.h"
namespace MM {
bool StringsData::load(const Common::Path &filename) {
Common::File f;
Common::Array<Common::String> prefixKeys;
Common::String key, value, fullKey;
size_t p;
if (!f.open(filename))
return false;
while (!f.eos()) {
// Get the next line
Common::String line = f.readLine();
// Check for blank or comment lines
Common::String lineTrimmed = line;
lineTrimmed.trim();
if (lineTrimmed.empty() || lineTrimmed.hasPrefix("#"))
continue;
// Count number of tabs for identation amount
size_t numTabs = 0;
while (line.hasPrefix("\t")) {
line.deleteChar(0);
++numTabs;
}
// Split key and value if present
p = line.findFirstOf(":");
if (p == Common::String::npos)
error("Line encountered without colon");
key = Common::String(line.c_str(), line.c_str() + p);
value = Common::String(line.c_str() + p + 1);
key.trim();
value.trim();
// Strip quotes from start and end of string
if (value.hasPrefix("\"") && value.hasSuffix("\"")) {
value.deleteChar(0);
value.deleteLastChar();
value = searchAndReplace(value, "\"\"", "");
value = searchAndReplace(value, "\\\"", "\"");
}
// Replace any sequences
for (uint i = 0; i < value.size(); ++i) {
if (value[i] == '\\' && (value[i + 1] == 'n' ||
value[i + 1] == 'r')) {
value.deleteChar(i);
value.setChar('\n', i);
} else if (!strncmp(value.c_str() + i, "\\x", 2)) {
Common::String hex(value.c_str() + i + 2,
value.c_str() + i + 4);
value.deleteChar(i);
value.deleteChar(i);
value.deleteChar(i);
value.setChar((char)hexToInt(hex), i);
} else if (value[i] == '"' && i < (value.size() - 1) &&
value[i + 1] == '"') {
value.deleteChar(i);
}
}
// Handle the entries
if (numTabs == prefixKeys.size()) {
// Do nothing
} else if (numTabs < prefixKeys.size()) {
// Drop off prefixes to the desired indentation
prefixKeys.resize(numTabs);
} else {
error("Incorrect indentation");
}
if (value.empty()) {
prefixKeys.push_back(key);
} else {
// Form a key from the prefix and current key
fullKey = "";
for (size_t i = 0; i < prefixKeys.size(); ++i) {
fullKey += prefixKeys[i];
fullKey += ".";
}
fullKey = fullKey + key;
(*this)[fullKey] = value;
}
}
return true;
}
} // namespace MM

View File

@@ -0,0 +1,42 @@
/* 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 MM_UTILS_STRINGS_DATA_H
#define MM_UTILS_STRINGS_DATA_H
#include "common/hash-str.h"
#include "common/path.h"
namespace MM {
class StringsData : public Common::StringMap {
public:
StringsData() : Common::StringMap() {}
/**
* Loads the data
*/
bool load(const Common::Path &filename);
};
} // namespace MM
#endif

View File

@@ -0,0 +1,112 @@
/* 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 "image/bmp.h"
#include "mm/shared/utils/xeen_font.h"
namespace MM {
#define FONT_HEIGHT 8
#define CHARS_COUNT 128
byte XeenFont::_colors[4];
byte XeenFont::_colorsSet[40][4];
void XeenFont::load(Common::SeekableReadStream *src,
size_t charsOffset, size_t charWidthsOffset) {
// Read in character data
src->seek(charsOffset);
_data.resize(CHARS_COUNT * FONT_HEIGHT);
for (int i = 0; i < CHARS_COUNT * FONT_HEIGHT; ++i)
_data[i] = src->readUint16LE();
// Read in the char widths
src->seek(charWidthsOffset);
_widths.resize(128);
src->read(&_widths[0], 128);
}
void XeenFont::loadColors(Common::SeekableReadStream *src) {
src->read(_colorsSet, 40 * 4);
}
void XeenFont::setColors(uint index) {
assert(index < 40);
Common::copy(&_colorsSet[index][0],
&_colorsSet[index][4], &_colors[0]);
}
int XeenFont::getCharWidth(uint32 chr) const {
assert(chr < 256);
return _widths[chr & 0x7f];
}
void XeenFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const {
assert(chr < 256);
if (chr == 'g' || chr == 'p' || chr == 'q' || chr == 'y')
++y;
bool isInverse = (chr >= 128);
chr &= 0x7f;
const uint16 *src = &_data[chr * FONT_HEIGHT];
for (int yCtr = 0; yCtr < FONT_HEIGHT; ++yCtr, ++src) {
if ((y + yCtr) < 0 || (y + yCtr) >= dst->h)
continue;
uint16 srcVal = *src;
byte *dest = (byte *)dst->getBasePtr(x, y + yCtr);
for (int xCtr = 0; xCtr < _widths[chr];
++xCtr, ++dest, srcVal >>= 2) {
if ((x + xCtr) >= 0 && (x + xCtr) < dst->w) {
if (isInverse)
*dest = (srcVal & 3) ? 2 : 0;
else if (srcVal & 3)
*dest = _colors[srcVal & 3];
}
}
}
}
int XeenFont::getStringWidth(const Common::String &str) const {
// Handle not counting character highlighting sequences
// as part of the string width
static const char *const CONTROL_CHARS = "\x01\x02";
size_t p = str.findFirstOf(CONTROL_CHARS);
if (p == Common::String::npos)
return Graphics::Font::getStringWidth(str);
size_t totalWidth = 0;
Common::String strCopy = str;
do {
totalWidth += Graphics::Font::getStringWidth(
Common::String(strCopy.c_str(), strCopy.c_str() + p));
strCopy = Common::String(strCopy.c_str() + p + 3);
p = strCopy.findFirstOf(CONTROL_CHARS);
} while (p != Common::String::npos);
totalWidth += Graphics::Font::getStringWidth(strCopy);
return totalWidth;
}
} // namespace MM

View File

@@ -0,0 +1,89 @@
/* 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 MM_UTILS_XEEN_FONT_H
#define MM_UTILS_XEEN_FONT_H
#include "common/array.h"
#include "common/rect.h"
#include "graphics/font.h"
#include "graphics/managed_surface.h"
namespace MM {
/**
* Implements a font stored as a grid on a passed surface
*/
class XeenFont : public Graphics::Font {
private:
Common::Array<uint16> _data;
Common::Array<byte> _widths;
private:
static byte _colors[4];
static byte _colorsSet[40][4];
public:
static void loadColors(Common::SeekableReadStream *src);
/**
* Set the text colors set index
*/
static void setColors(uint index);
public:
XeenFont() {}
/**
* Loads the font
*/
void load(Common::SeekableReadStream *src,
size_t charsOffset, size_t charWidthsOffset);
/**
* Get the font height
*/
int getFontHeight() const override { return 8 + 1; }
/**
* Get the maximum character width
*/
int getMaxCharWidth() const override { return 8; }
/**
* Get the width of the given character
*/
int getCharWidth(uint32 chr) const override;
/**
* Get the string width
*/
int getStringWidth(const Common::String &str) const;
/**
* Draw a character
*/
void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
void drawChar(Graphics::ManagedSurface *dst, uint32 chr, int x, int y, uint32 color) const override {
return Graphics::Font::drawChar(dst, chr, x, y, color);
}
};
} // namespace MM
#endif