Example #1
0
Common::String ComposerEngine::mangleFilename(Common::String filename) {
	while (filename.size() && (filename[0] == '~' || filename[0] == ':' || filename[0] == '\\'))
		filename = filename.c_str() + 1;

	uint slashesToStrip = _directoriesToStrip;

	if (filename.hasPrefix(".."))
		slashesToStrip = 1;

	while (slashesToStrip--) {
		for (uint i = 0; i < filename.size(); i++) {
			if (filename[i] != '\\' && filename[i] != ':')
				continue;
			filename = filename.c_str() + i + 1;
			break;
		}
	}

	Common::String outFilename;
	for (uint i = 0; i < filename.size(); i++) {
		if (filename[i] == '\\' || filename[i] == ':')
			outFilename += '/';
		else
			outFilename += filename[i];
	}
	return outFilename;
}
Example #2
0
bool ActionStreamVideo::execute() {
	Video::VideoDecoder *decoder;
	Common::Rect destRect = Common::Rect(_x1, _y1, _x2 + 1, _y2 + 1);
	Common::String subname = _fileName;
	subname.setChar('s', subname.size() - 3);
	subname.setChar('u', subname.size() - 2);
	subname.setChar('b', subname.size() - 1);
	bool subtitleExists = _engine->getSearchManager()->hasFile(subname);
	bool switchToHires = false;

// NOTE: We only show the hires MPEG2 videos when libmpeg2 is compiled in,
// otherwise we fall back to the lowres ones
#ifdef USE_MPEG2
	Common::String hiresFileName = _fileName;
	hiresFileName.setChar('d', hiresFileName.size() - 8);
	hiresFileName.setChar('v', hiresFileName.size() - 3);
	hiresFileName.setChar('o', hiresFileName.size() - 2);
	hiresFileName.setChar('b', hiresFileName.size() - 1);

	if (_engine->getScriptManager()->getStateValue(StateKey_MPEGMovies) == 1 &&_engine->getSearchManager()->hasFile(hiresFileName)) {
		// TODO: Enable once AC3 support is implemented
		if (!_engine->getSearchManager()->hasFile(_fileName))	// Check for the regular video
			return true;
		warning("The hires videos of the DVD version of ZGI aren't supported yet, using lowres");
		//_fileName = hiresFileName;
		//switchToHires = true;
	} else if (!_engine->getSearchManager()->hasFile(_fileName))
		return true;
#else
	if (!_engine->getSearchManager()->hasFile(_fileName))
		return true;
#endif

	decoder = _engine->loadAnimation(_fileName);
	Subtitle *sub = (subtitleExists) ? new Subtitle(_engine, subname, switchToHires) : NULL;

	_engine->getCursorManager()->showMouse(false);

	if (switchToHires) {
		_engine->initHiresScreen();
		destRect = Common::Rect(40, -40, 760, 440);
		Common::Rect workingWindow = _engine->_workingWindow;
		workingWindow.translate(0, -40);
		_engine->getRenderManager()->initSubArea(HIRES_WINDOW_WIDTH, HIRES_WINDOW_HEIGHT, workingWindow);
	}

	_engine->playVideo(*decoder, destRect, _skippable, sub);

	if (switchToHires) {
		_engine->initScreen();
		_engine->getRenderManager()->initSubArea(WINDOW_WIDTH, WINDOW_HEIGHT, _engine->_workingWindow);
	}

	_engine->getCursorManager()->showMouse(true);

	delete decoder;
	delete sub;

	return true;
}
Example #3
0
Common::String OSystem_POSIX::getDefaultConfigFileName() {
	Common::String configFile;

	Common::String prefix;
#ifdef MACOSX
	prefix = getenv("HOME");
#elif !defined(SAMSUNGTV)
	const char *envVar;
	// Our old configuration file path for POSIX systems was ~/.scummvmrc.
	// If that file exists, we still use it.
	envVar = getenv("HOME");
	if (envVar && *envVar) {
		configFile = envVar;
		configFile += '/';
		configFile += ".scummvmrc";

		if (configFile.size() < MAXPATHLEN) {
			struct stat sb;
			if (stat(configFile.c_str(), &sb) == 0) {
				return configFile;
			}
		}
	}

	// On POSIX systems we follow the XDG Base Directory Specification for
	// where to store files. The version we based our code upon can be found
	// over here: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
	envVar = getenv("XDG_CONFIG_HOME");
	if (!envVar || !*envVar) {
		envVar = getenv("HOME");
		if (!envVar) {
			return 0;
		}

		if (Posix::assureDirectoryExists(".config", envVar)) {
			prefix = envVar;
			prefix += "/.config";
		}
	} else {
		prefix = envVar;
	}

	if (!prefix.empty() && Posix::assureDirectoryExists("scummvm", prefix.c_str())) {
		prefix += "/scummvm";
	}
#endif

	if (!prefix.empty() && (prefix.size() + 1 + _baseConfigName.size()) < MAXPATHLEN) {
		configFile = prefix;
		configFile += '/';
		configFile += _baseConfigName;
	} else {
		configFile = _baseConfigName;
	}

	return configFile;
}
Example #4
0
Common::String DefaultSaveFileManager::concatWithSavesPath(Common::String name) {
	DefaultSaveFileManager *manager = dynamic_cast<DefaultSaveFileManager *>(g_system->getSavefileManager());
	Common::String path = (manager ? manager->getSavePath() : ConfMan.get("savepath"));
	if (path.size() > 0 && (path.lastChar() == '/' || path.lastChar() == '\\'))
		return path + name;

	//simple heuristic to determine which path separator to use
	int backslashes = 0;
	for (uint32 i = 0; i < path.size(); ++i)
		if (path[i] == '/') --backslashes;
		else if (path[i] == '\\') ++backslashes;

	if (backslashes > 0) return path + '\\' + name;
	return path + '/' + name;
}
Example #5
0
static bool isValidSaveFileName(const Common::String &desc) {
    for (uint32 i = 0; i < desc.size(); i++)
        if (!isValidSaveFileChar(desc[i]))
            return false;

    return true;
}
Example #6
0
bool Debugger::Cmd_DumpVocab(int argc, const char **argv) {
    Common::DumpFile outFile;
    outFile.open("vocab.txt");

    for (uint32 i = 0; i < _vm->_game->_scene.getVocabStringsCount(); i++) {
        Common::String curId = Common::String::format("%x", i + 1);
        Common::String curVocab = _vm->_game->_scene.getVocab(i + 1);
        curVocab.toUppercase();

        for (uint j = 0; j < curVocab.size(); j++) {
            if (curVocab[j] == ' ' || curVocab[j] == '-')
                curVocab.setChar('_', j);
        }

        Common::String cur = "\tNOUN_" + curVocab + " = 0x" + curId + ",\n";

        outFile.writeString(cur.c_str());
    }

    outFile.flush();
    outFile.close();

    debugPrintf("Game vocab dumped\n");

    return true;
}
Example #7
0
bool Debugger::Cmd_DumpItems(int argc, const char **argv) {
    InventoryObjects &objects = _vm->_game->_objects;

    Common::DumpFile outFile;
    outFile.open("items.txt");

    for (uint32 i = 0; i < objects.size(); i++) {
        Common::String curId = Common::String::format("%d", i);
        Common::String desc = _vm->_game->_scene.getVocab(objects[i]._descId);
        desc.toUppercase();

        for (uint j = 0; j < desc.size(); j++) {
            if (desc[j] == ' ' || desc[j] == '-')
                desc.setChar('_', j);
        }

        Common::String cur = "\tOBJ_" + desc + " = " + curId + ",\n";

        outFile.writeString(cur.c_str());
    }

    outFile.flush();
    outFile.close();

    debugPrintf("Game items dumped\n");

    return true;
}
Example #8
0
uint8 Widget::parseHotkey(const Common::String &label) {
    if (!label.contains('~'))
        return 0;

    int state = 0;
    uint8 hotkey = 0;

    for (uint i = 0; i < label.size() && state != 3; i++) {
        switch (state) {
        case 0:
            if (label[i] == '~')
                state = 1;
            break;
        case 1:
            if (label[i] != '~') {
                state = 2;
                hotkey = label[i];
            } else
                state = 0;
            break;
        case 2:
            if (label[i] == '~')
                state = 3;
            else
                state = 0;
            break;
        }
    }

    if (state == 3)
        return hotkey;

    return 0;
}
Example #9
0
/**
 * @brief Calculate the width of a string when drawn in the current font
 *
 * @param str       String to draw
 * @param spacing   Space to leave between individual characters. Defaults to 0.
 *
 * @return The calculated width of the string
 */
uint Font::getStringWidth(const Common::String &str, int spacing) const {
    uint width = 0;

    // Real length, including '|' separators
    uint len = str.size();

    for (uint i = 0, tmp = 0; i < len; ++i) {

        if (str[i] != '|') {
            tmp += getCharWidth(str[i]) + spacing;
        }

        // Newline char encountered, skip it and store the new length if it is greater.
        // Also, all strings in the data files should end with '|' but not all do.
        // This is why we check whether we are at the last char too.
        if (str[i] == '|' || i == len - 1) {
            if (tmp > width) {
                width = tmp;
            }

            tmp = 0;
        }
    }

    return width + 1;
}
Example #10
0
void Font::drawString(Surface *dst, const Common::String &str,
                      int x, int y, int with_color, int spacing, bool markDirty) const {
    assert(dst != NULL);
    assert(x >= 0);
    assert(y >= 0);

    uint widest = getStringWidth(str, spacing);

    int curx = x + (widest - getLineWidth(str, 0, spacing)) / 2;
    int cury = y;

    for (uint i = 0; i < str.size(); ++i) {

        // If we encounter the '|' char (newline and end of string marker),
        // skip it and go to the start of the next line
        if (str[i] == '|') {
            cury += getFontHeight();
            curx = x + (widest - getLineWidth(str, i+1, spacing) - 1) / 2;
            continue;
        }

        // Break early if there's no more space on the screen
        if (curx >= dst->w - 1 || cury >= dst->h - 1) {
            break;
        }

        drawChar(dst, str[i], curx, cury, with_color);
        curx += getCharWidth(str[i]) + spacing;
    }

    if (markDirty) {
        Common::Rect r(x, y, x + widest, y + getStringHeight(str));
        dst->markDirtyRect(r);
    }
}
Example #11
0
void FMVScreen::play(const Common::String &name) {
	Common::SeekableReadStream *stream = nullptr;

	// Play the low-resolution video, if possible
	if (!StarkSettings->getBoolSetting(Settings::kHighFMV) && StarkSettings->hasLowResFMV()) {
		Common::String lowResName = name;
		lowResName.erase(lowResName.size() - 4);
		lowResName += "_lo_res.bbb";

		stream = StarkArchiveLoader->getExternalFile(lowResName, "Global/");
		if (!stream) {
			debug("Could not open %s", lowResName.c_str());
		}
	}

	// Play the original video
	if (!stream) {
		stream = StarkArchiveLoader->getExternalFile(name, "Global/");
	}

	if (!stream) {
		warning("Could not open %s", name.c_str());
		return;
	}

	_decoder->loadStream(stream);
	if (!_decoder->isVideoLoaded()) {
		error("Could not open %s", name.c_str());
	}
	_decoder->start();
}
Example #12
0
int Overlays::play(const Common::String &name, int loopId, bool loopForever, bool startNow, int a6) {
	assert(name.size() <= 12);

	int32 hash = MIXArchive::getHash(name);
	int index = findByHash(hash);
	if (index < 0) {
		index = findEmpty();
		if (index < 0) {
			return index;
		}
		_videos[index].loaded = true;
		_videos[index].name = name;
		_videos[index].hash = hash;
		_videos[index].vqaPlayer = new VQAPlayer(_vm, &_vm->_surfaceFront);

		// repeat forever
		_videos[index].vqaPlayer->setBeginAndEndFrame(0, 0, -1, kLoopSetModeJustStart, nullptr, nullptr);
	}

	Common::String resourceName = Common::String::format("%s.VQA", name.c_str());
	_videos[index].vqaPlayer->open(resourceName);
	_videos[index].vqaPlayer->setLoop(
		loopId,
		loopForever ? -1 : 0,
		startNow ? kLoopSetModeImmediate : kLoopSetModeEnqueue,
		nullptr, nullptr);

	return index;
}
Example #13
0
Common::String BuriedEngine::getFilePath(uint32 stringID) {
	Common::String path = getString(stringID);
	Common::String output;

	if (path.empty())
		return output;

	uint i = 0;

	// The non-demo paths have CD info followed by a backslash.
	// We ignore this.
	// In the demo, we remove the "BITDATA" prefix because the
	// binaries are in the same directory.
	if (isDemo())
		i += 8;
	else
		i += 2;

	for (; i < path.size(); i++) {
		if (path[i] == '\\')
			output += '/';
		else
			output += path[i];
	}

	return output;
}
Example #14
0
bool StarTrekEngine::showSaveMenu() {
	GUI::SaveLoadChooser *dialog;
	Common::String desc;
	int slot;

	dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);

	slot = dialog->runModalWithCurrentTarget();
	desc = dialog->getResultString();

	if (desc.empty()) {
		// create our own description for the saved game, the user didnt enter it
		desc = dialog->createDefaultSaveDescription(slot);
	}

	if (desc.size() > 28)
		desc = Common::String(desc.c_str(), 28);

	delete dialog;

	if (slot < 0)
		return true;

	return saveGame(slot, desc);
}
Example #15
0
void GfxText16::DrawString(const Common::String &text) {
	GuiResourceId previousFontId = GetFontId();
	int16 previousPenColor = _ports->_curPort->penClr;

	Draw(text.c_str(), 0, text.size(), previousFontId, previousPenColor);
	SetFont(previousFontId);
	_ports->penColor(previousPenColor);
}
Example #16
0
void Costume::setColormap(const Common::String &map) {
	// Sometimes setColormap is called on a null costume,
	// see where raoul is gone in hh.set
	if (!map.size())
		return;
	_cmap = g_resourceloader->getColormap(map);
	for (int i = 0; i < _numComponents; i++)
		_components[i]->setColormap(NULL);
}
Example #17
0
Common::String Widget::cleanupHotkey(const Common::String &label) {
    Common::String res;

    for (uint i = 0; i < label.size() ; i++)
        if (label[i] != '~')
            res = res + label[i];

    return res;
}
Example #18
0
void RemoteBrowserDialog::goUp() {
	if (_rememberedNodeContents.contains(_node.path()))
		_rememberedNodeContents.erase(_node.path());

	Common::String path = _node.path();
	if (path.size() && (path.lastChar() == '/' || path.lastChar() == '\\'))
		path.deleteLastChar();
	if (path.empty()) {
		_rememberedNodeContents.erase("");
	} else {
		for (int i = path.size() - 1; i >= 0; --i)
			if (i == 0 || path[i] == '/' || path[i] == '\\') {
				path.erase(i);
				break;
			}
	}

	listDirectory(Cloud::StorageFile(path, 0, 0, true));
}
Example #19
0
uint Font::getLineWidth(const Common::String &str, uint startIndex, int spacing) const {
    uint width = 0;

    // If the index is greater or equal to the string size,
    // the width of the line is 0
    if (startIndex >= str.size())
        return 0;

    for (uint i = startIndex; i < str.size(); ++i) {

        // EOL encountered
        if (str[i] == '|')
            break;

        // Add width of the current char
        width += getCharWidth(str[i]) + spacing;
    }

    return width;
}
Example #20
0
void DefaultSaveFileManager::saveTimestamps(Common::HashMap<Common::String, uint32> &timestamps) {
	Common::DumpFile f;
	Common::String filename = concatWithSavesPath(TIMESTAMPS_FILENAME);
	if (!f.open(filename, true)) {
		warning("DefaultSaveFileManager: failed to open '%s' file to save timestamps", filename.c_str());
		return;
	}

	for (Common::HashMap<Common::String, uint32>::iterator i = timestamps.begin(); i != timestamps.end(); ++i) {
		Common::String data = i->_key + Common::String::format(" %u\n", i->_value);
		if (f.write(data.c_str(), data.size()) != data.size()) {
			warning("DefaultSaveFileManager: failed to write timestamps data into '%s'", filename.c_str());
			return;
		}
	}

	f.flush();
	f.finalize();
	f.close();
}
Example #21
0
Common::String OSystem_SDL::getSystemLanguage() const {
#if defined(USE_DETECTLANG) && !defined(_WIN32_WCE)
#ifdef WIN32
	// We can not use "setlocale" (at least not for MSVC builds), since it
	// will return locales like: "English_USA.1252", thus we need a special
	// way to determine the locale string for Win32.
	char langName[9];
	char ctryName[9];

	const LCID languageIdentifier = GetThreadLocale();

	if (GetLocaleInfo(languageIdentifier, LOCALE_SISO639LANGNAME, langName, sizeof(langName)) != 0 &&
		GetLocaleInfo(languageIdentifier, LOCALE_SISO3166CTRYNAME, ctryName, sizeof(ctryName)) != 0) {
		Common::String localeName = langName;
		localeName += "_";
		localeName += ctryName;

		return localeName;
	} else {
		return ModularBackend::getSystemLanguage();
	}
#else // WIN32
	// Activating current locale settings
	const Common::String locale = setlocale(LC_ALL, "");

	// Restore default C locale to prevent issues with
	// portability of sscanf(), atof(), etc.
	// See bug #3615148
	setlocale(LC_ALL, "C");

	// Detect the language from the locale
	if (locale.empty()) {
		return ModularBackend::getSystemLanguage();
	} else {
		int length = 0;

		// Strip out additional information, like
		// ".UTF-8" or the like. We do this, since
		// our translation languages are usually
		// specified without any charset information.
		for (int size = locale.size(); length < size; ++length) {
			// TODO: Check whether "@" should really be checked
			// here.
			if (locale[length] == '.' || locale[length] == ' ' || locale[length] == '@')
				break;
		}

		return Common::String(locale.c_str(), length);
	}
#endif // WIN32
#else // USE_DETECTLANG
	return ModularBackend::getSystemLanguage();
#endif // USE_DETECTLANG
}
Example #22
0
bool GameVar::load(MfcArchive &file) {
	_varName = file.readPascalString();
	_varType = file.readUint32LE();

	debugCN(6, kDebugLoading, "[%03d] ", file.getLevel());
	for (int i = 0; i < file.getLevel(); i++)
		debugCN(6, kDebugLoading, " ");

	debugCN(6, kDebugLoading, "<%s>: ", transCyrillic(_varName));

	switch (_varType) {
	case 0:
		_value.intValue = file.readUint32LE();
		debugC(6, kDebugLoading, "d --> %d", _value.intValue);
		break;
	case 1:
		_value.intValue = file.readUint32LE(); // FIXME
		debugC(6, kDebugLoading, "f --> %f", _value.floatValue);
		break;
	case 2: {
		Common::String str = file.readPascalString();
		_value.stringValue = (char *)calloc(str.size() + 1, 1);
		Common::strlcpy(_value.stringValue, str.c_str(), str.size() + 1);
		debugC(6, kDebugLoading, "s --> %s", _value.stringValue);
		}
		break;
	default:
		error("Unknown var type: %d (0x%x)", _varType, _varType);
	}

	file.incLevel();
	_parentVarObj = file.readClass<GameVar>();
	_prevVarObj = file.readClass<GameVar>();
	_nextVarObj = file.readClass<GameVar>();
	_field_14 = file.readClass<GameVar>();
	_subVars = file.readClass<GameVar>();
	file.decLevel();

	return true;
}
Example #23
0
int Overlays::play(const Common::String &name, int loopId, bool loopForever, bool startNow, int a6) {
	assert(name.size() <= 12);
	if (loopId < 0) {
		warning("Overlays::play - loop id can't be a negative number!");
		return -1;
	}

	int32 hash = MIXArchive::getHash(name);
	int index = findByHash(hash);
	if (index < 0) {
		index = findEmpty();
		if (index < 0) {
			return index;
		}
		_videos[index].loaded = true;
		_videos[index].name = name;
		_videos[index].hash = hash;
		_videos[index].loopId = loopId;
		_videos[index].enqueuedLoopId = -1;
		_videos[index].loopForever = loopForever;
		_videos[index].vqaPlayer = new VQAPlayer(_vm, &_vm->_surfaceFront, Common::String::format("%s.VQA", name.c_str()));

		if (!_videos[index].vqaPlayer) {
			resetSingle(index);
			return -1;
		}
		// TODO? Removed as redundant
		// repeat forever
		//_videos[index].vqaPlayer->setBeginAndEndFrame(0, 0, -1, kLoopSetModeJustStart, nullptr, nullptr);
	}

	bool skipNewVQAPlayerOpen = false;
	if (_videos[index].vqaPlayer
	    && !startNow
	    && _videos[index].vqaPlayer->getFrameCount() > 0
	) {
		skipNewVQAPlayerOpen = true;
		_videos[index].enqueuedLoopId = loopId;
	}

	if (skipNewVQAPlayerOpen || _videos[index].vqaPlayer->open()) {
		_videos[index].vqaPlayer->setLoop(
			loopId,
			loopForever ? -1 : 0,
			startNow ? kLoopSetModeImmediate : kLoopSetModeEnqueue,
			nullptr, nullptr);
	} else {
		resetSingle(index);
		return -1;
	}
	return index;
}
Example #24
0
Common::U32String UTF8Converter::convertUtf8ToUtf32(const Common::String &str) {
	// we assume one character in a Common::String is one byte
	// but in this case it's actually an UTF-8 string
	// with up to 4 bytes per character. To work around this,
	// convert it to an U32String before any further operation
	Common::U32String u32str;
	int i = 0;
	while (i < (int)str.size()) {
		uint32 chr = nextchar(str.c_str(), &i);
		u32str += chr;
	}
	return u32str;
}
static Common::String loadString(Common::InSaveFile *in, uint maxSize = 999) {
    Common::String result;

    char ch = (char)in->readByte();
    while (ch != '\0') {
        result += ch;
        if (result.size() >= maxSize)
            break;
        ch = (char)in->readByte();
    }

    return result;
}
Example #26
0
bool ScScript::createMethodThread(ScScript *original, const Common::String &methodName) {
    uint32 ip = original->getMethodPos(methodName);
    if (ip == 0) {
        return STATUS_FAILED;
    }

    cleanup();

    _thread = true;
    _methodThread = true;
    _threadEvent = new char[methodName.size() + 1];
    if (_threadEvent) {
        strcpy(_threadEvent, methodName.c_str());
    }

    // copy filename
    _filename = new char[strlen(original->_filename) + 1];
    if (_filename) {
        strcpy(_filename, original->_filename);
    }

    // copy buffer
    _buffer = new byte [original->_bufferSize];
    if (!_buffer) {
        return STATUS_FAILED;
    }

    memcpy(_buffer, original->_buffer, original->_bufferSize);
    _bufferSize = original->_bufferSize;

    // initialize
    bool res = initScript();
    if (DID_FAIL(res)) {
        return res;
    }

    // copy globals
    _globals = original->_globals;

    // skip to the beginning of the event
    _iP = ip;

    _timeSlice = original->_timeSlice;
    _freezable = original->_freezable;
    _owner = original->_owner;

    _engine = original->_engine;
    _parentScript = original;

    return STATUS_OK;
}
Example #27
0
bool ThemeParser::resolutionCheck(const Common::String &resolution) {
	if (resolution.empty())
		return true;

	Common::StringTokenizer globTokenizer(resolution, ", ");
	Common::String cur;

	while (!globTokenizer.empty()) {
		cur = globTokenizer.nextToken();

		bool lt;
		int val;

		if (cur.size() < 5) {
			warning("Invalid theme 'resolution' token '%s'", resolution.c_str());
			return false;
		}

		if (cur[0] == 'x') {
			val = g_system->getOverlayWidth();
		} else if (cur[0] == 'y') {
			val = g_system->getOverlayHeight();
		} else {
			warning("Error parsing theme 'resolution' token '%s'", resolution.c_str());
			return false;
		}

		if (cur[1] == '<') {
			lt = true;
		} else if (cur[1] == '>') {
			lt = false;
		} else {
			warning("Error parsing theme 'resolution' token '%s'", resolution.c_str());
			return false;
		}

		int token = atoi(cur.c_str() + 2);

		// check inverse for unfulfilled requirements
		if (lt) {
			if (val >= token)
				return false;
		} else {
			if (val <= token)
				return false;
		}
	}

	return true;
}
Example #28
0
/**
 * @brief Calculate the height of a string by counting the number of '|' chars (which
 *        are used as newline characters and end-of-string markers)
 *
 * @param str       String to draw
 * @param spacing   Space to leave between individual characters. Defaults to 0.
 *
 * @return The calculated height of the string
 */
uint Font::getStringHeight(const Common::String &str) const {
    uint len = str.size();
    int separators = 0;

    for (uint i = 0; i < len; ++i) {
        // All strings in the data files should end with '|' but not all do.
        // This is why we check whether we are at the last char too.
        if (str[i] == '|' || i == len - 1) {
            ++separators;
        }
    }

    return separators * getFontHeight();
}
Example #29
0
reg_t kArrayDuplicate(EngineState *s, int argc, reg_t *argv) {
	reg_t targetHandle;

	// String duplicates may be made from static script data
	if (!s->_segMan->isArray(argv[0])) {
		const Common::String source = s->_segMan->getString(argv[0]);
		SciArray &target = *s->_segMan->allocateArray(kArrayTypeString, source.size(), &targetHandle);
		target.fromString(source);
	} else {
		SciArray &source = *s->_segMan->lookupArray(argv[0]);
		SciArray &target = *s->_segMan->allocateArray(source.getType(), source.size(), &targetHandle);
		target = source;
	}

	return targetHandle;
}
Example #30
0
/**
 * Read in a static strings block, and if the language matches, load up the static strings
 */
void MortevielleEngine::readStaticStrings(Common::File &f, int dataSize, DataType dataType) {
	// Figure out what language Id is needed
	byte desiredLanguageId;
	switch(getLanguage()) {
	case Common::EN_ANY:
		desiredLanguageId = MORTDAT_LANG_ENGLISH;
		break;
	case Common::FR_FRA:
		desiredLanguageId = MORTDAT_LANG_FRENCH;
		break;
	case Common::DE_DEU:
		desiredLanguageId = MORTDAT_LANG_GERMAN;
		break;
	default:
		warning("Language not supported, switching to English");
		desiredLanguageId = MORTDAT_LANG_ENGLISH;
		break;
	}

	// Read in the language
	byte languageId = f.readByte();
	--dataSize;

	// If the language isn't correct, then skip the entire block
	if (languageId != desiredLanguageId) {
		f.skip(dataSize);
		return;
	}

	// Load in each of the strings
	while (dataSize > 0) {
		Common::String s;
		char ch;
		while ((ch = (char)f.readByte()) != '\0')
			s += ch;

		if (dataType == kStaticStrings)
			_engineStrings.push_back(s);
		else if (dataType == kGameStrings)
			_gameStrings.push_back(s);

		dataSize -= s.size() + 1;
	}
	assert(dataSize == 0);
}