KYRA: reduce unsafe string ops

(replace all strcpy calls and similar fixes)
This commit is contained in:
athrxx 2022-09-21 23:16:27 +02:00
parent f39e7a15b4
commit 3a49ea6248
40 changed files with 254 additions and 350 deletions

View File

@ -481,11 +481,11 @@ bool DarkMoonEngine::killMonsterExtra(EoBMonsterInPlay *m) {
void DarkMoonEngine::loadVcnData(const char *file, const uint8 *cgaMapping) {
if (file)
strcpy(_lastBlockDataFile, file);
_lastBlockDataFile = file;
delete[] _vcnBlocks;
if (_flags.platform == Common::kPlatformFMTowns) {
Common::String fn = Common::String::format(_vcnFilePattern.c_str(), _lastBlockDataFile);
Common::String fn = Common::String::format(_vcnFilePattern.c_str(), _lastBlockDataFile.c_str());
_vcnBlocks = _res->fileData(fn.c_str(), 0);
} else {
EoBCoreEngine::loadVcnData(file, cgaMapping);

View File

@ -694,10 +694,10 @@ void EoBEngine::readLevelFileData(int level) {
void EoBEngine::loadVcnData(const char *file, const uint8 *cgaMapping) {
if (file)
strcpy(_lastBlockDataFile, file);
_lastBlockDataFile = file;
delete[] _vcnBlocks;
Common::String fn = Common::String::format(_vcnFilePattern.c_str(), _lastBlockDataFile);
Common::String fn = Common::String::format(_vcnFilePattern.c_str(), _lastBlockDataFile.c_str());
if (_flags.platform == Common::kPlatformAmiga) {
Common::SeekableReadStream *in = _res->createReadStream(fn);
uint32 vcnSize = in->readUint16LE() * (_vcnSrcBitsPerPixel << 3);

View File

@ -139,7 +139,6 @@ EoBCoreEngine::EoBCoreEngine(OSystem *system, const GameFlags &flags) : KyraRpgE
_configHpBarGraphs = true;
_configMouseBtSwap = false;
memset(_dialogueLastBitmap, 0, 13);
_npcSequenceSub = 0;
_moveCounter = 0;
_partyResting = false;
@ -1565,7 +1564,7 @@ void EoBCoreEngine::initDialogueSequence() {
_npcSequenceSub = -1;
_txt->setWaitButtonMode(0);
_dialogueField = true;
_dialogueLastBitmap[0] = 0;
_dialogueLastBitmap.clear();
_txt->resetPageBreakString();
gui_updateControls();
@ -1596,7 +1595,7 @@ void EoBCoreEngine::restoreAfterDialogueSequence() {
_txt->allowPageBreak(false);
_dialogueField = _dialogueFieldAmiga = false;
_dialogueLastBitmap[0] = 0;
_dialogueLastBitmap.clear();
gui_restorePlayField();
//_allowSkip = false;
@ -1617,7 +1616,7 @@ void EoBCoreEngine::drawSequenceBitmap(const char *file, int destRect, int x1, i
int page = ((flags & 2) || destRect) ? 0 : 6;
int amigaPalIndex = (x1 ? 1 : 0) + (y1 ? 2 : 0) + 1;
if (scumm_stricmp(_dialogueLastBitmap, file)) {
if (!_dialogueLastBitmap.equalsIgnoreCase(file)) {
_screen->clearPage(2);
if (!destRect) {
if (!(flags & 1)) {
@ -1634,7 +1633,7 @@ void EoBCoreEngine::drawSequenceBitmap(const char *file, int destRect, int x1, i
}
_screen->loadEoBBitmap(file, 0, 3, 3, 2);
strcpy(_dialogueLastBitmap, file);
_dialogueLastBitmap = file;
}
if (_flags.platform == Common::kPlatformAmiga) {

View File

@ -850,7 +850,7 @@ protected:
void drawSequenceBitmap(const char *file, int destRect, int x1, int y1, int flags);
int runDialogue(int dialogueTextId, int numStr, int loopButtonId, ...);
char _dialogueLastBitmap[13];
Common::String _dialogueLastBitmap;
int _moveCounter;
const char *const *_chargenStatStrings;

View File

@ -784,45 +784,39 @@ void KyraEngine_HoF::cleanup() {
#pragma mark - Localization
void KyraEngine_HoF::loadCCodeBuffer(const char *file) {
char tempString[13];
strcpy(tempString, file);
Common::String tempString = file;
changeFileExtension(tempString);
delete[] _cCodeBuffer;
_cCodeBuffer = _res->fileData(tempString, nullptr);
_cCodeBuffer = _res->fileData(tempString.c_str(), nullptr);
}
void KyraEngine_HoF::loadOptionsBuffer(const char *file) {
char tempString[13];
strcpy(tempString, file);
Common::String tempString = file;
changeFileExtension(tempString);
delete[] _optionsBuffer;
_optionsBuffer = _res->fileData(tempString, nullptr);
_optionsBuffer = _res->fileData(tempString.c_str(), nullptr);
}
void KyraEngine_HoF::loadChapterBuffer(int chapter) {
char tempString[14];
static const char *const chapterFilenames[] = {
"CH1.XXX", "CH2.XXX", "CH3.XXX", "CH4.XXX", "CH5.XXX"
};
assert(chapter >= 1 && chapter <= ARRAYSIZE(chapterFilenames));
strcpy(tempString, chapterFilenames[chapter-1]);
Common::String tempString = chapterFilenames[chapter-1];
changeFileExtension(tempString);
delete[] _chapterBuffer;
_chapterBuffer = _res->fileData(tempString, nullptr);
_chapterBuffer = _res->fileData(tempString.c_str(), nullptr);
_currentChapter = chapter;
}
void KyraEngine_HoF::changeFileExtension(char *buffer) {
while (*buffer != '.')
++buffer;
++buffer;
strcpy(buffer, _languageExtension[_lang]);
void KyraEngine_HoF::changeFileExtension(Common::String &file) {
uint insertAt = file.findFirstOf('.');
if (insertAt != Common::String::npos)
file = file.substr(0, insertAt + 1) + _languageExtension[_lang];
}
uint8 *KyraEngine_HoF::getTableEntry(uint8 *buffer, int id) {
@ -953,13 +947,8 @@ void KyraEngine_HoF::loadItemShapes() {
}
void KyraEngine_HoF::loadCharacterShapes(int shapes) {
char file[10];
strcpy(file, "_ZX.SHP");
_characterShapeFile = shapes;
file[2] = '0' + shapes;
uint8 *data = _res->fileData(file, nullptr);
uint8 *data = _res->fileData(Common::String::format("_Z%c.SHP", '0' + (char)shapes).c_str(), nullptr);
assert(data);
for (int i = 9; i <= 32; ++i)
addShapeToPool(data, i, i-9);
delete[] data;
@ -980,16 +969,14 @@ void KyraEngine_HoF::loadInventoryShapes() {
}
void KyraEngine_HoF::runStartScript(int script, int unk1) {
char filename[14];
strcpy(filename, "_START0X.EMC");
filename[7] = script + '0';
Common::String filename = Common::String::format("_START0%c.EMC", '0' + (char)script);
EMCData scriptData;
EMCState scriptState;
memset(&scriptData, 0, sizeof(EMCData));
memset(&scriptState, 0, sizeof(EMCState));
_emc->load(filename, &scriptData, &_opcodes);
_emc->load(filename.c_str(), &scriptData, &_opcodes);
_emc->init(&scriptState, &scriptData);
scriptState.regs[6] = unk1;
_emc->start(&scriptState, 0);
@ -1399,24 +1386,21 @@ void KyraEngine_HoF::restoreGfxRect32x32(int x, int y) {
#pragma mark -
void KyraEngine_HoF::openTalkFile(int newFile) {
char talkFilename[16];
Common::String talkFilename;
if (_oldTalkFile > 0) {
sprintf(talkFilename, "CH%dVOC.TLK", _oldTalkFile);
talkFilename = Common::String::format("CH%dVOC.TLK", _oldTalkFile);
_res->unloadPakFile(talkFilename);
_oldTalkFile = -1;
}
if (newFile == 0)
strcpy(talkFilename, "ANYTALK.TLK");
else
sprintf(talkFilename, "CH%dVOC.TLK", newFile);
talkFilename = newFile ? Common::String::format("CH%dVOC.TLK", newFile) : "ANYTALK.TLK";
_oldTalkFile = newFile;
if (!_res->loadPakFile(talkFilename)) {
if (speechEnabled()) {
warning("Couldn't load voice file '%s', falling back to text only mode", talkFilename);
warning("Couldn't load voice file '%s', falling back to text only mode", talkFilename.c_str());
_configVoice = 0;
// Sync the config manager with the new settings

View File

@ -335,7 +335,7 @@ protected:
Common::String getTableString(int id, uint8 *buffer, bool decode);
Common::String getChapterString(int id);
void changeFileExtension(char *buffer);
void changeFileExtension(Common::String &file);
// - Just used in French version
int getItemCommandStringDrop(Item item);
@ -429,7 +429,7 @@ protected:
};
TalkSections _currentTalkSections;
char _TLKFilename[13];
Common::String _TLKFilename;
// tim
void playTim(const char *filename);

View File

@ -706,11 +706,9 @@ void KyraEngine_MR::runStartupScript(int script, int unk1) {
EMCData data;
memset(&state, 0, sizeof(state));
memset(&data, 0, sizeof(data));
char filename[13];
strcpy(filename, "_START0X.EMC");
filename[7] = (script % 10) + '0';
Common::String filename = Common::String::format("_START0%c.EMC", '0' + (char)(script % 10));
_emc->load(filename, &data, &_opcodes);
_emc->load(filename.c_str(), &data, &_opcodes);
_emc->init(&state, &data);
_emc->start(&state, 0);
state.regs[6] = unk1;
@ -722,22 +720,22 @@ void KyraEngine_MR::runStartupScript(int script, int unk1) {
}
void KyraEngine_MR::openTalkFile(int file) {
char talkFilename[16];
Common::String talkFilename;
if (file == 0) {
strcpy(talkFilename, "ANYTALK.TLK");
talkFilename = "ANYTALK.TLK";
} else {
if (_currentTalkFile > 0) {
sprintf(talkFilename, "CH%dTALK.TLK", _currentTalkFile);
talkFilename = Common::String::format("CH%dTALK.TLK", _currentTalkFile);
_res->unloadPakFile(talkFilename);
}
sprintf(talkFilename, "CH%dTALK.TLK", file);
talkFilename = Common::String::format("CH%dTALK.TLK", file);
}
_currentTalkFile = file;
if (!_res->loadPakFile(talkFilename)) {
if (speechEnabled()) {
warning("Couldn't load voice file '%s', falling back to text only mode", talkFilename);
warning("Couldn't load voice file '%s', falling back to text only mode", talkFilename.c_str());
_configVoice = 0;
// Sync the config manager with the new settings
@ -776,12 +774,11 @@ void KyraEngine_MR::loadCharacterShapes(int newShapes) {
const char highNum = (newShapes / 10) + '0';
for (int i = 0; i < 6; ++i) {
char filename[16];
strcpy(filename, filenames[i]);
filename[numberOffset[i]+0] = highNum;
filename[numberOffset[i]+1] = lowNum;
_res->exists(filename, true);
_res->loadFileToBuf(filename, _screenBuffer, 64000);
Common::String filename = filenames[i];
filename.setChar(highNum, numberOffset[i]);
filename.setChar(lowNum, numberOffset[i] + 1);
_res->exists(filename.c_str(), true);
_res->loadFileToBuf(filename.c_str(), _screenBuffer, 64000);
for (int j = startShape[i]; j <= endShape[i]; ++j) {
if (j == 87)
continue;
@ -1328,8 +1325,8 @@ bool KyraEngine_MR::updateScore(int scoreId, int strId) {
setNextIdleAnimTimer();
_scoreFlagTable[scoreIndex] |= (1 << scoreBit);
strcpy(_stringBuffer, (const char *)getTableEntry(_scoreFile, strId));
strcat(_stringBuffer, ": ");
Common::strlcpy(_stringBuffer, (const char *)getTableEntry(_scoreFile, strId), 500);
Common::strlcat(_stringBuffer, ": ", 500);
assert(scoreId < _scoreTableSize);

View File

@ -323,7 +323,7 @@ protected:
int16 *_lvlShapeTop;
int16 *_lvlShapeBottom;
char _lastBlockDataFile[13];
Common::String _lastBlockDataFile;
uint32 _hasTempDataFlags;
int16 _sceneDrawVarDown;

View File

@ -1007,7 +1007,7 @@ void LoLEngine::update() {
#pragma mark - Localization
char *LoLEngine::getLangString(uint16 id) {
const char *LoLEngine::getLangString(uint16 id) {
if (id == 0xFFFF)
return 0;
@ -1862,7 +1862,7 @@ int LoLEngine::characterSays(int track, int charId, bool redraw) {
return r ? (textEnabled() ? 1 : 0) : 1;
}
int LoLEngine::playCharacterScriptChat(int charId, int mode, int restorePortrait, char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) {
int LoLEngine::playCharacterScriptChat(int charId, int mode, int restorePortrait, const char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) {
int ch = 0;
bool skipAnim = false;

View File

@ -357,7 +357,7 @@ private:
void processCharacterSelection();
void updateSelectionAnims();
int selectionCharInfo(int character);
void selectionCharInfoIntro(char *file);
void selectionCharInfoIntro(Common::String &file);
int getCharSelection();
int selectionCharAccept();
@ -575,7 +575,7 @@ private:
// text
int characterSays(int track, int charId, bool redraw);
int playCharacterScriptChat(int charId, int mode, int restorePortrait, char *str, EMCState *script, const uint16 *paramList, int16 paramIndex);
int playCharacterScriptChat(int charId, int mode, int restorePortrait, const char *str, EMCState *script, const uint16 *paramList, int16 paramIndex);
void setupDialogueButtons(int numStr, const char *s1, const char *s2, const char *s3);
TextDisplayer_LoL *_txt;
@ -816,7 +816,7 @@ private:
int _lastUsedStringBuffer;
char _stringBuffer[5][512]; // TODO: The original used a size of 512, it looks a bit large.
// Maybe we can someday reduce the size.
char *getLangString(uint16 id);
const char *getLangString(uint16 id);
uint8 *getTableEntry(uint8 *buffer, uint16 id);
void decodeSjis(const char *src, char *dst);
int decodeCyrillic(const char *src, char *dst);

View File

@ -318,7 +318,7 @@ void EoBCoreEngine::addLevelItems() {
void EoBCoreEngine::loadVcnData(const char *file, const uint8 *cgaMapping) {
uint32 vcnSize = 0;
Common::String fn = Common::String::format(_vcnFilePattern.c_str(), _lastBlockDataFile);
Common::String fn = Common::String::format(_vcnFilePattern.c_str(), _lastBlockDataFile.c_str());
_screen->loadBitmap(fn.c_str(), 3, 3, 0, true);
const uint8 *pos = _screen->getCPagePtr(3);

View File

@ -389,10 +389,8 @@ void KyraEngine_HoF::loadScenePal() {
uint16 sceneId = _mainCharacter.sceneId;
_screen->copyPalette(1, 0);
char filename[14];
strcpy(filename, _sceneList[sceneId].filename1);
strcat(filename, ".COL");
_screen->loadBitmap(filename, 3, 3, nullptr);
Common::String filename = Common::String(_sceneList[sceneId].filename1) + ".COL";
_screen->loadBitmap(filename.c_str(), 3, 3, nullptr);
_screen->getPalette(1).copy(_screen->getCPagePtr(3), 0, 128);
_screen->getPalette(1).fill(0, 1, 0);
memcpy(_scenePal, _screen->getCPagePtr(3)+336, 432);
@ -400,22 +398,17 @@ void KyraEngine_HoF::loadScenePal() {
void KyraEngine_HoF::loadSceneMsc() {
uint16 sceneId = _mainCharacter.sceneId;
char filename[14];
strcpy(filename, _sceneList[sceneId].filename1);
strcat(filename, ".MSC");
_screen->loadBitmap(filename, 3, 5, nullptr);
_screen->loadBitmap((Common::String(_sceneList[sceneId].filename1) + ".MSC").c_str(), 3, 5, nullptr);
}
void KyraEngine_HoF::startSceneScript(int unk1) {
uint16 sceneId = _mainCharacter.sceneId;
char filename[14];
strcpy(filename, _sceneList[sceneId].filename1);
Common::String filename = _sceneList[sceneId].filename1;
if (sceneId == 68 && (queryGameFlag(0x1BC) || queryGameFlag(0x1BD)))
strcpy(filename, "DOORX");
strcat(filename, ".CPS");
filename = "DOORX";
filename += ".CPS";
_screen->loadBitmap(filename, 3, 3, nullptr);
_screen->loadBitmap(filename.c_str(), 3, 3, nullptr);
resetScaleTable();
_useCharPal = false;
memset(_charPalTable, 0, sizeof(_charPalTable));
@ -434,12 +427,9 @@ void KyraEngine_HoF::startSceneScript(int unk1) {
_sceneCommentString = "Undefined scene comment string!";
_emc->init(&_sceneScriptState, &_sceneScriptData);
strcpy(filename, _sceneList[sceneId].filename1);
strcat(filename, ".");
strcat(filename, _scriptLangExt[(_flags.platform == Common::kPlatformDOS && !_flags.isTalkie) ? 0 : _lang]);
_res->exists(filename, true);
_emc->load(filename, &_sceneScriptData, &_opcodes);
filename = Common::String(_sceneList[sceneId].filename1) + "." + _scriptLangExt[(_flags.platform == Common::kPlatformDOS && !_flags.isTalkie) ? 0 : _lang];
_res->exists(filename.c_str(), true);
_emc->load(filename.c_str(), &_sceneScriptData, &_opcodes);
runSceneScript7();
_emc->start(&_sceneScriptState, 0);

View File

@ -143,10 +143,7 @@ void KyraEngine_LoK::enterNewScene(int sceneId, int facing, int unk1, int unk2,
_currentRoom = sceneId;
int tableId = _roomTable[sceneId].nameIndex;
char fileNameBuffer[32];
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
strcat(fileNameBuffer, ".DAT");
_sprites->loadDat(fileNameBuffer, _sceneExits);
_sprites->loadDat((Common::String(_roomFilenameTable[tableId]) + ".DAT").c_str(), _sceneExits);
_sprites->setupSceneAnims();
_emc->unload(&_scriptClickData);
loadSceneMsc();
@ -188,13 +185,10 @@ void KyraEngine_LoK::transcendScenes(int roomIndex, int roomName) {
assert(roomIndex < _roomTableSize);
if (_flags.isTalkie) {
char file[32];
assert(roomIndex < _roomTableSize);
int tableId = _roomTable[roomIndex].nameIndex;
assert(tableId < _roomFilenameTableSize);
strcpy(file, _roomFilenameTable[tableId]);
strcat(file, ".VRM");
_res->unloadPakFile(file);
_res->unloadPakFile(Common::String(_roomFilenameTable[tableId]) + ".VRM");
}
_roomTable[roomIndex].nameIndex = roomName;
@ -378,25 +372,21 @@ void KyraEngine_LoK::loadSceneMsc() {
assert(_currentCharacter->sceneId < _roomTableSize);
int tableId = _roomTable[_currentCharacter->sceneId].nameIndex;
assert(tableId < _roomFilenameTableSize);
char fileNameBuffer[32];
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
strcat(fileNameBuffer, ".MSC");
Common::String fileNameBuffer = Common::String(_roomFilenameTable[tableId]) + ".MSC";
_screen->fillRect(0, 0, 319, 199, 0, 5);
_res->exists(fileNameBuffer, true);
_screen->loadBitmap(fileNameBuffer, 3, 5, nullptr);
_res->exists(fileNameBuffer.c_str(), true);
_screen->loadBitmap(fileNameBuffer.c_str(), 3, 5, nullptr);
}
void KyraEngine_LoK::startSceneScript(int brandonAlive) {
assert(_currentCharacter->sceneId < _roomTableSize);
int tableId = _roomTable[_currentCharacter->sceneId].nameIndex;
assert(tableId < _roomFilenameTableSize);
char fileNameBuffer[32];
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
strcat(fileNameBuffer, ".CPS");
Common::String fileNameBuffer = Common::String(_roomFilenameTable[tableId]) + ".CPS";
_screen->clearPage(3);
_res->exists(fileNameBuffer, true);
_res->exists(fileNameBuffer.c_str(), true);
// FIXME: check this hack for amiga version
_screen->loadBitmap(fileNameBuffer, 3, 3, (_flags.platform == Common::kPlatformAmiga ? &_screen->getPalette(0) : nullptr));
_screen->loadBitmap(fileNameBuffer.c_str(), 3, 3, (_flags.platform == Common::kPlatformAmiga ? &_screen->getPalette(0) : nullptr));
_sprites->loadSceneShapes();
_exitListPtr = nullptr;
@ -406,11 +396,10 @@ void KyraEngine_LoK::startSceneScript(int brandonAlive) {
clearNoDropRects();
_emc->init(&_scriptClick, &_scriptClickData);
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
strcat(fileNameBuffer, ".EMC");
_res->exists(fileNameBuffer, true);
fileNameBuffer = Common::String(_roomFilenameTable[tableId]) + ".EMC";
_res->exists(fileNameBuffer.c_str(), true);
_emc->unload(&_scriptClickData);
_emc->load(fileNameBuffer, &_scriptClickData, &_opcodes);
_emc->load(fileNameBuffer.c_str(), &_scriptClickData, &_opcodes);
_emc->start(&_scriptClick, 0);
_scriptClick.regs[0] = _currentCharacter->sceneId;
_scriptClick.regs[7] = brandonAlive;
@ -1272,24 +1261,18 @@ void KyraEngine_LoK::setupSceneResource(int sceneId) {
if (!_flags.isTalkie)
return;
Common::String file;
if (_currentRoom != 0xFFFF) {
assert(_currentRoom < _roomTableSize);
int tableId = _roomTable[_currentRoom].nameIndex;
assert(tableId < _roomFilenameTableSize);
// unload our old room
char file[64];
strcpy(file, _roomFilenameTable[tableId]);
strcat(file, ".VRM");
_res->unloadPakFile(file);
strcpy(file, _roomFilenameTable[tableId]);
strcat(file, ".PAK");
_res->unloadPakFile(file);
strcpy(file, _roomFilenameTable[tableId]);
strcat(file, ".APK");
_res->unloadPakFile(file);
file = _roomFilenameTable[tableId];
_res->unloadPakFile(file + ".VRM");
_res->unloadPakFile(file + ".PAK");
_res->unloadPakFile(file + ".APK");
}
assert(sceneId < _roomTableSize);
@ -1297,20 +1280,16 @@ void KyraEngine_LoK::setupSceneResource(int sceneId) {
assert(tableId < _roomFilenameTableSize);
// load our new room
char file[64];
strcpy(file, _roomFilenameTable[tableId]);
strcat(file, ".VRM");
if (_res->exists(file))
file = Common::String(_roomFilenameTable[tableId]) + ".VRM";
if (_res->exists(file.c_str()))
_res->loadPakFile(file);
strcpy(file, _roomFilenameTable[tableId]);
strcat(file, ".PAK");
if (_res->exists(file))
file = Common::String(_roomFilenameTable[tableId]) + ".PAK";
if (_res->exists(file.c_str()))
_res->loadPakFile(file);
strcpy(file, _roomFilenameTable[tableId]);
strcat(file, ".APK");
if (_res->exists(file))
file = Common::String(_roomFilenameTable[tableId]) + ".APK";
if (_res->exists(file.c_str()))
_res->loadPakFile(file);
}

View File

@ -301,7 +301,7 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
if (file) {
_lastSpecialColor = specialColor;
_lastSpecialColorWeight = weight;
strcpy(_lastBlockDataFile, file);
_lastBlockDataFile = file;
if (palFile)
_lastOverridePalFile = palFile;
else
@ -312,7 +312,7 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
if (_lastSpecialColor == 1)
_lastSpecialColor = 0x44;
else if (_lastSpecialColor == 0x66)
_lastSpecialColor = scumm_stricmp(_lastBlockDataFile, "YVEL2") ? 0xCC : 0x44;
_lastSpecialColor = _lastBlockDataFile.equalsIgnoreCase("YVEL2") ? 0x44 : 0xCC;
else if (_lastSpecialColor == 0x6B)
_lastSpecialColor = 0xCC;
else
@ -324,7 +324,7 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
int tlen = 0;
if (_flags.use16ColorMode) {
fname = Common::String::format("%s.VCF", _lastBlockDataFile);
fname = _lastBlockDataFile + ".VCF";
_screen->loadBitmap(fname.c_str(), 3, 3, 0);
v = _screen->getCPagePtr(2);
tlen = READ_LE_UINT16(v) << 5;
@ -336,7 +336,7 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
memcpy(_vcfBlocks, v, tlen);
}
fname = Common::String::format("%s.VCN", _lastBlockDataFile);
fname = _lastBlockDataFile + ".VCN";
_screen->loadBitmap(fname.c_str(), 3, 3, 0);
v = _screen->getCPagePtr(2);
tlen = READ_LE_UINT16(v);
@ -387,7 +387,7 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
memcpy(_vcnBlocks, v, vcnLen);
v += vcnLen;
fname = Common::String::format("%s.VMP", _lastBlockDataFile);
fname = _lastBlockDataFile + ".VMP";
_screen->loadBitmap(fname.c_str(), 3, 3, 0);
v = _screen->getCPagePtr(2);

View File

@ -99,25 +99,25 @@ void KyraEngine_MR::enterNewScene(uint16 sceneId, int facing, int unk1, int unk2
loadScenePal();
if (queryGameFlag(0x1D9)) {
char filename[20];
Common::String filename;
if (queryGameFlag(0x20D)) {
resetGameFlag(0x20D);
strcpy(filename, "COW1_");
filename = "COW1_";
} else if (queryGameFlag(0x20E)) {
resetGameFlag(0x20E);
strcpy(filename, "COW2_");
filename = "COW2_";
} else if (queryGameFlag(0x20F)) {
resetGameFlag(0x20F);
strcpy(filename, "COW3_");
filename ="COW3_";
} else if (queryGameFlag(0x20C)) {
resetGameFlag(0x20C);
strcpy(filename, "BOAT");
filename = "BOAT";
} else if (queryGameFlag(0x210)) {
resetGameFlag(0x210);
strcpy(filename, "JUNG");
filename = "JUNG";
}
playVQA(filename);
playVQA(filename.c_str());
resetGameFlag(0x1D9);
}
@ -297,12 +297,9 @@ void KyraEngine_MR::freeSceneShapes() {
}
void KyraEngine_MR::loadScenePal() {
char filename[16];
_screen->copyPalette(2, 0);
strcpy(filename, _sceneList[_mainCharacter.sceneId].filename1);
strcat(filename, ".COL");
_screen->loadBitmap(filename, 3, 3, nullptr);
_screen->loadBitmap((Common::String(_sceneList[_mainCharacter.sceneId].filename1) + ".COL").c_str(), 3, 3, nullptr);
_screen->getPalette(2).copy(_screen->getCPagePtr(3), 0, 144);
_screen->getPalette(2).fill(0, 1, 0);
@ -318,11 +315,9 @@ void KyraEngine_MR::loadScenePal() {
}
void KyraEngine_MR::loadSceneMsc() {
char filename[16];
strcpy(filename, _sceneList[_mainCharacter.sceneId].filename1);
strcat(filename, ".MSC");
Common::String filename = Common::String(_sceneList[_mainCharacter.sceneId].filename1) + ".MSC";
_res->exists(filename, true);
_res->exists(filename.c_str(), true);
Common::SeekableReadStream *stream = _res->createReadStream(filename);
assert(stream);
int16 minY = 0, height = 0;
@ -335,7 +330,7 @@ void KyraEngine_MR::loadSceneMsc() {
_screen->setShapePages(5, 3, _maskPageMinY, _maskPageMaxY);
_screen->loadBitmap(filename, 5, 5, nullptr, true);
_screen->loadBitmap(filename.c_str(), 5, 5, nullptr, true);
// HACK
uint8 *data = new uint8[320*200];
@ -349,11 +344,9 @@ void KyraEngine_MR::loadSceneMsc() {
void KyraEngine_MR::initSceneScript(int unk1) {
const SceneDesc &scene = _sceneList[_mainCharacter.sceneId];
char filename[16];
strcpy(filename, scene.filename1);
strcat(filename, ".DAT");
Common::String filename = Common::String(scene.filename1) + ".DAT";
_res->exists(filename, true);
_res->exists(filename.c_str(), true);
Common::SeekableReadStream *stream = _res->createReadStream(filename);
assert(stream);
stream->seek(2, SEEK_CUR);
@ -368,9 +361,8 @@ void KyraEngine_MR::initSceneScript(int unk1) {
_scaleTable[i] = (uint16(scaleTable[i]) << 8) / 100;
if (shapesCount > 0) {
strcpy(filename, scene.filename1);
strcat(filename, "9.CPS");
_screen->loadBitmap(filename, 3, 3, nullptr);
filename = Common::String(scene.filename1) + "9.CPS";
_screen->loadBitmap(filename.c_str(), 3, 3, nullptr);
int pageBackUp = _screen->_curPage;
_screen->_curPage = 2;
for (int i = 0; i < shapesCount; ++i) {
@ -388,9 +380,8 @@ void KyraEngine_MR::initSceneScript(int unk1) {
delete stream;
stream = nullptr;
strcpy(filename, scene.filename1);
strcat(filename, ".CPS");
_screen->loadBitmap(filename, 3, 3, nullptr);
filename = Common::String(scene.filename1) + ".CPS";
_screen->loadBitmap(filename.c_str(), 3, 3, nullptr);
Common::fill(_specialSceneScriptState, ARRAYEND(_specialSceneScriptState), false);
_sceneEnterX1 = 160;
@ -405,14 +396,12 @@ void KyraEngine_MR::initSceneScript(int unk1) {
_sceneMaxX = 319;
_emc->init(&_sceneScriptState, &_sceneScriptData);
strcpy(filename, scene.filename2);
strcat(filename, ".EMC");
_res->exists(filename, true);
_emc->load(filename, &_sceneScriptData, &_opcodes);
filename = Common::String(scene.filename2) + ".EMC";
_res->exists(filename.c_str(), true);
_emc->load(filename.c_str(), &_sceneScriptData, &_opcodes);
strcpy(filename, scene.filename2);
strcat(filename, ".");
loadLanguageFile(filename, _sceneStrings);
filename = Common::String(scene.filename2) + ".";
loadLanguageFile(filename.c_str(), _sceneStrings);
runSceneScript8();
_emc->start(&_sceneScriptState, 0);

View File

@ -52,11 +52,10 @@ void KyraEngine_HoF::timerCauldronAnimation(int arg) {
if (animation == -1)
animation = _rnd.getRandomNumberRng(1, 6);
char filename[13];
strcpy(filename, "CAULD00.WSA");
filename[5] = (animation / 10) + '0';
filename[6] = (animation % 10) + '0';
loadInvWsa(filename, 0, 8, 0, -1, -1, 1);
Common::String filename = "CAULD00.WSA";
filename.setChar((animation / 10) + '0', 5);
filename.setChar((animation % 10) + '0', 6);
loadInvWsa(filename.c_str(), 0, 8, 0, -1, -1, 1);
}
}

View File

@ -325,7 +325,7 @@ void KyraEngine_MR::setupSceneAnimObject(int animId, uint16 flags, int x, int y,
anim.specialSize = specialSize;
anim.shapeIndex = shape;
if (filename)
strcpy(anim.filename, filename);
Common::strlcpy(anim.filename, filename, sizeof(anim.filename));
if (flags & 8) {
_sceneAnimMovie[animId]->open(filename, 1, nullptr);

View File

@ -3040,8 +3040,9 @@ Common::String GUI_EoB::transferTargetMenu(Common::Array<Common::String> &target
Common::StringArray::iterator ii = targets.begin();
for (int i = 0; i < _savegameListSize; ++i) {
_savegameList[i] = new char[(*ii).size() + 1];
strcpy(_savegameList[i], (*ii++).c_str());
int slsize = (*ii).size() + 1;
_savegameList[i] = new char[slsize];
Common::strlcpy(_savegameList[i], (*ii++).c_str(), slsize);
}
const ScreenDim *dm = _screen->getScreenDim(11);

View File

@ -404,46 +404,46 @@ int KyraEngine_HoF::bookButton(Button *button) {
}
void KyraEngine_HoF::loadBookBkgd() {
char filename[16];
Common::String filename;
if (_flags.isTalkie)
strcpy(filename, (_bookBkgd == 0) ? "_XBOOKD.CPS" : "_XBOOKC.CPS");
filename = (_bookBkgd == 0) ? "_XBOOKD.CPS" : "_XBOOKC.CPS";
else
strcpy(filename, (_bookBkgd == 0) ? "_BOOKD.CPS" : "_BOOKC.CPS");
filename = (_bookBkgd == 0) ? "_BOOKD.CPS" : "_BOOKC.CPS";
_bookBkgd ^= 1;
if (_flags.isTalkie) {
if (!_bookCurPage)
strcpy(filename, "_XBOOKB.CPS");
filename = "_XBOOKB.CPS";
if (_bookCurPage == _bookMaxPage)
strcpy(filename, "_XBOOKA.CPS");
filename = "_XBOOKA.CPS";
switch (_lang) {
case 0:
filename[1] = 'E';
filename.setChar('E', 1);
break;
case 1:
filename[1] = 'F';
filename.setChar('F', 1);
break;
case 2:
filename[1] = 'G';
filename.setChar('G', 1);
break;
default:
warning("loadBookBkgd unsupported language");
filename[1] = 'E';
filename.setChar('E', 1);
}
} else {
if (!_bookCurPage)
strcpy(filename, "_BOOKB.CPS");
filename = "_BOOKB.CPS";
if (_bookCurPage == _bookMaxPage)
strcpy(filename, "_BOOKA.CPS");
filename = "_BOOKA.CPS";
}
_screen->loadBitmap(filename, 3, 3, nullptr);
_screen->loadBitmap(filename.c_str(), 3, 3, nullptr);
}
void KyraEngine_HoF::showBookPage() {

View File

@ -2518,15 +2518,16 @@ void GUI_LoL::setupSaveMenuSlots(Menu &menu, int num) {
}
int saveSlotMaxLen = ((_screen->getScreenDim(8))->w << 3) - _screen->getCharWidth('W');
int buffLeft = 5120 - 1;
for (int i = startSlot; i < num && _savegameOffset + i - slotOffs < _savegameListSize; ++i) {
if (_savegameList[i + _savegameOffset - slotOffs]) {
Common::strlcpy(s, _savegameList[i + _savegameOffset - slotOffs], 80);
Common::strlcpy(s, _savegameList[i + _savegameOffset - slotOffs], buffLeft);
// Trim long GMM save descriptions to fit our save slots
int fC = _screen->getTextWidth(s);
while (s[0] && fC >= saveSlotMaxLen) {
s[strlen(s) - 1] = 0;
s[Common::strnlen(s, buffLeft) - 1] = 0;
fC = _screen->getTextWidth(s);
}
@ -2539,7 +2540,9 @@ void GUI_LoL::setupSaveMenuSlots(Menu &menu, int num) {
}
menu.item[i].itemString = s;
s += (strlen(s) + 1);
int slotLen = Common::strnlen(s, buffLeft) + 1;
s += slotLen;
buffLeft -= slotLen;
menu.item[i].saveSlot = _saveSlots[i + _savegameOffset - slotOffs];
menu.item[i].enabled = true;
}
@ -2547,7 +2550,7 @@ void GUI_LoL::setupSaveMenuSlots(Menu &menu, int num) {
if (_savegameOffset == 0) {
if (&menu == &_saveMenu) {
strcpy(s, _vm->getLangString(0x4010));
Common::strlcpy(s, _vm->getLangString(0x4010), buffLeft);
menu.item[0].itemString = s;
menu.item[0].saveSlot = -3;
menu.item[0].enabled = true;
@ -2682,19 +2685,19 @@ int GUI_LoL::clickedSaveMenu(Button *button) {
_saveDescription = (char *)_vm->_tempBuffer5120 + 1000;
_saveDescription[0] = 0;
if (_saveMenu.item[-s - 2].saveSlot != -3) {
strcpy(_saveDescription, _saveMenu.item[-s - 2].itemString.c_str());
Common::strlcpy(_saveDescription, _saveMenu.item[-s - 2].itemString.c_str(), 80);
} else if (_vm->_autoSaveNamesEnabled) {
TimeDate td;
g_system->getTimeAndDate(td);
// Skip character name for Japanese to prevent garbage rendering (the save description is rendered in the non-SJIS default font).
Common::String ts = (_vm->gameFlags().lang != Common::JA_JPN) ? Common::String::format("%s / ", _vm->_characters[0].name) : "";
Common::String lvl1 = Common::String(_vm->_lastBlockDataFile).substr(0, 1);
Common::String lvl2 = Common::String(_vm->_lastBlockDataFile).substr(1);
Common::String lvl1 = _vm->_lastBlockDataFile.substr(0, 1);
Common::String lvl2 = _vm->_lastBlockDataFile.substr(1);
lvl1.toUppercase();
lvl2.toLowercase();
ts = ts + lvl1 + lvl2;
ts += Common::String::format(" / %02d-%02d-%02d - %02d:%02d:%02d", td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, td.tm_hour, td.tm_min, td.tm_sec);
strcpy(_saveDescription, ts.c_str());
Common::strlcpy(_saveDescription, ts.c_str(), 80);
}
return 1;

View File

@ -137,7 +137,7 @@ void KyraEngine_MR::showMessageFromCCode(int string, uint8 c0, int) {
}
void KyraEngine_MR::updateItemCommand(Item item, int str, uint8 c0) {
char buffer[100];
Common::String buffer;
char *src = (char *)getTableEntry(_itemFile, item);
if (_flags.lang != Common::HE_ISR) {
@ -148,20 +148,18 @@ void KyraEngine_MR::updateItemCommand(Item item, int str, uint8 c0) {
*src = toupper(*src);
}
strcpy(buffer, src);
buffer = src;
if (_lang != 3)
strcat(buffer, " ");
buffer += " ";
strcat(buffer, (const char *)getTableEntry(_cCodeFile, str));
buffer += (const char *)getTableEntry(_cCodeFile, str);
} else {
strcpy(buffer, (const char *)getTableEntry(_cCodeFile, str));
strcat(buffer, " ");
strcat(buffer, src);
strcat(buffer, ".");
buffer = (const char *)getTableEntry(_cCodeFile, str);
buffer = buffer + " " + src + ".";
}
showMessage(buffer, c0, 0xF0);
showMessage(buffer.c_str(), c0, 0xF0);
}
void KyraEngine_MR::updateCommandLine() {
@ -620,7 +618,7 @@ int KyraEngine_MR::buttonMoodChange(Button *button) {
}
int KyraEngine_MR::buttonShowScore(Button *button) {
strcpy(_stringBuffer, (const char *)getTableEntry(_cCodeFile, 18));
Common::strlcpy(_stringBuffer, (const char *)getTableEntry(_cCodeFile, 18), 500);
char *buffer = _stringBuffer;

View File

@ -48,13 +48,10 @@ Common::Error KyraEngine_LoK::loadGameState(int slot) {
// unloading the current voice file should fix some problems with voices
if (_currentRoom != 0xFFFF && _flags.isTalkie) {
char file[32];
assert(_currentRoom < _roomTableSize);
int tableId = _roomTable[_currentRoom].nameIndex;
assert(tableId < _roomFilenameTableSize);
strcpy(file, _roomFilenameTable[tableId]);
strcat(file, ".VRM");
_res->unloadPakFile(file);
_res->unloadPakFile(Common::String(_roomFilenameTable[tableId]) + ".VRM");
}
for (int i = 0; i < 11; i++) {

View File

@ -459,7 +459,7 @@ bool StaticResource::loadStringTable(Common::SeekableReadStream &stream, void *&
string += c;
output[i] = new char[string.size() + 1];
strcpy(output[i], string.c_str());
Common::strlcpy(output[i], string.c_str(), string.size() + 1);
}
ptr = output;

View File

@ -520,7 +520,7 @@ int EoBInfProcessor::oeob_printMessage_v1(int8 *data) {
char col[5];
int8 *pos = data;
strcpy(col, colorConfig);
Common::strlcpy(col, colorConfig, sizeof(col));
const char *str = (const char *)pos;
pos += (strlen(str) + 1);
bool lineBreak = true;

View File

@ -59,7 +59,7 @@ int KyraEngine_HoF::o2_defineObject(EMCState *script) {
debugC(3, kDebugLevelScriptFuncs, "KyraEngine_HoF::o2_defineObject(%p) (%d, '%s', %d, %d, %d, %d)", (const void *)script,
stackPos(0), stackPosString(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5));
TalkObject *object = &_talkObjectList[stackPos(0)];
strcpy(object->filename, stackPosString(1));
Common::strlcpy(object->filename, stackPosString(1), sizeof(object->filename));
object->scriptId = stackPos(2);
object->x = stackPos(3);
object->y = stackPos(4);
@ -872,7 +872,7 @@ int KyraEngine_HoF::o2_defineSceneAnim(EMCState *script) {
anim.height = stackPos(7);
anim.specialSize = stackPos(9);
anim.shapeIndex = stackPos(11);
strcpy(anim.filename, stackPosString(12));
Common::strlcpy(anim.filename, stackPosString(12), sizeof(anim.filename));
if (anim.flags & 0x40) {
if (!_sceneAnimMovie[animId]->open(anim.filename, 1, nullptr))
@ -1197,7 +1197,7 @@ int KyraEngine_HoF::o2_setupSceneAnimation(EMCState *script) {
anim.specialSize = stackPos(9);
anim.shapeIndex = stackPos(11);
if (stackPosString(12))
strcpy(anim.filename, stackPosString(12));
Common::strlcpy(anim.filename, stackPosString(12), sizeof(anim.filename));
if (flags & 0x40) {
_sceneAnimMovie[index]->open(stackPosString(12), 0, nullptr);

View File

@ -1313,7 +1313,7 @@ int LoLEngine::olol_drawExitButton(EMCState *script) {
int y = printPara[3 * stackPos(0) + 1];
int offs = printPara[3 * stackPos(0) + 2];
char *str = getLangString(0x4033);
const char *str = getLangString(0x4033);
int w = _screen->getTextWidth(str);
if (_flags.use16ColorMode) {
@ -1592,7 +1592,7 @@ int LoLEngine::olol_playDialogueTalkText(EMCState *script) {
int track = stackPos(0);
if (!snd_playCharacterSpeech(track, 0, 0) || textEnabled()) {
char *s = getLangString(track);
const char *s = getLangString(track);
_txt->printDialogueText2(4, s, script, 0, 1);
}
@ -2579,23 +2579,18 @@ int LoLEngine::tlol_fadeInScene(const TIM *tim, const uint16 *param) {
_screen->copyRegion(0, 0, 0, 0, 320, 200, 0, 2, Screen::CR_NO_P_CHECK);
char filename[32];
strcpy(filename, sceneFile);
strcat(filename, ".CPS");
_screen->loadBitmap(filename, 7, 5, &_screen->getPalette(0));
Common::String filename = Common::String(sceneFile) + ".CPS";
_screen->loadBitmap(filename.c_str(), 7, 5, &_screen->getPalette(0));
uint8 *overlay = 0;
if (!_flags.use16ColorMode) {
filename[0] = 0;
filename.clear();
if (_flags.isTalkie) {
strcpy(filename, _languageExt[_lang]);
strcat(filename, "/");
}
if (_flags.isTalkie)
filename = Common::String(_languageExt[_lang]) + "/";
strcat(filename, overlayFile);
overlay = _res->fileData(filename, 0);
filename += overlayFile;
overlay = _res->fileData(filename.c_str(), 0);
for (int i = 0; i < 3; ++i) {
uint32 endTime = _system->getMillis() + 10 * _tickLength;

View File

@ -52,7 +52,7 @@ int KyraEngine_MR::o3_defineObject(EMCState *script) {
debugC(3, kDebugLevelScriptFuncs, "KyraEngine_MR::o3_defineObject(%p) (%d, '%s', %d, %d, %d, %d, %d, %d)", (const void *)script,
stackPos(0), stackPosString(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5), stackPos(6), stackPos(7));
TalkObject &obj = _talkObjectList[stackPos(0)];
strcpy(obj.filename, stackPosString(1));
Common::strlcpy(obj.filename, stackPosString(1), sizeof(obj.filename));
obj.sceneAnim = stackPos(2);
obj.sceneScript = stackPos(3);
obj.x = stackPos(4);
@ -289,7 +289,7 @@ int KyraEngine_MR::o3_makeSecondChanceSave(EMCState *script) {
int KyraEngine_MR::o3_setSceneFilename(EMCState *script) {
debugC(3, kDebugLevelScriptFuncs, "KyraEngine_MR::o3_setSceneFilename(%p) (%d, '%s')", (const void *)script, stackPos(0), stackPosString(1));
strcpy(_sceneList[stackPos(0)].filename1, stackPosString(1));
Common::strlcpy(_sceneList[stackPos(0)].filename1, stackPosString(1), sizeof(_sceneList[stackPos(0)].filename1));
_sceneList[stackPos(0)].filename1[9] = 0;
return 0;
}
@ -882,7 +882,7 @@ int KyraEngine_MR::o3_defineSceneAnim(EMCState *script) {
const char *filename = stackPosString(12);
if (filename)
strcpy(anim.filename, filename);
Common::strlcpy(anim.filename, filename, sizeof(anim.filename));
if (flags & 8) {
_sceneAnimMovie[animId]->open(filename, 1, nullptr);
@ -1067,7 +1067,7 @@ int KyraEngine_MR::o3_customChat(EMCState *script) {
if (!str)
return 0;
strcpy(_stringBuffer, str);
Common::strlcpy(_stringBuffer, str, 500);
_chatText = _stringBuffer;
_chatObject = object;
_chatVocHigh = _chatVocLow = -1;

View File

@ -994,7 +994,7 @@ void TIMInterpreter_LoL::checkSpeechProgress() {
}
}
char *TIMInterpreter_LoL::getTableString(int id) {
const char *TIMInterpreter_LoL::getTableString(int id) {
return _vm->getLangString(id);
}

View File

@ -275,7 +275,7 @@ private:
void update() override;
void checkSpeechProgress() override;
char *getTableString(int id);
const char *getTableString(int id);
void advanceToOpcode(int opcode);
LoLEngine *_vm;

View File

@ -242,8 +242,8 @@ int KyraEngine_v2::o2_defineScene(EMCState *script) {
debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_defineScene(%p) (%d, '%s', %d, %d, %d, %d, %d, %d)",
(const void *)script, stackPos(0), stackPosString(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5), stackPos(6), stackPos(7));
const int scene = stackPos(0);
strcpy(_sceneList[scene].filename1, stackPosString(1));
strcpy(_sceneList[scene].filename2, stackPosString(1));
Common::strlcpy(_sceneList[scene].filename1, stackPosString(1), sizeof(_sceneList[scene].filename1));
Common::strlcpy(_sceneList[scene].filename2, stackPosString(1), sizeof(_sceneList[scene].filename2));
_sceneList[scene].exit1 = stackPos(2);
_sceneList[scene].exit2 = stackPos(3);
@ -323,7 +323,7 @@ int KyraEngine_v2::o2_getVocHigh(EMCState *script) {
int KyraEngine_v2::o2a_setAnimationShapes(EMCState *script) {
debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2a_setAnimationShapes(%p) ('%s', %d, %d, %d, %d, %d)", (const void *)script,
stackPosString(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5));
strcpy(_animShapeFilename, stackPosString(0));
Common::strlcpy(_animShapeFilename, stackPosString(0), sizeof(_animShapeFilename));
_animShapeLastEntry = stackPos(1);
_animShapeWidth = stackPos(2);
_animShapeHeight = stackPos(3);

View File

@ -1421,32 +1421,18 @@ void DarkmoonSequenceHelper::printText(int index, int color) {
color = 255;
}
char *temp = new char[strlen(_config->strings[index]) + 1];
char *str = temp;
strcpy(str, _config->strings[index]);
Common::String str = _config->strings[index];
const ScreenDim *dm = _screen->_curDim;
int fontHeight = _screen->getFontHeight() + 1;
int fontHeight = (_vm->gameFlags().platform == Common::kPlatformPC98) ? (_screen->getFontHeight() << 1) : (_screen->getFontHeight() + 1);
int xAlignFactor = (_vm->gameFlags().platform == Common::kPlatformPC98) ? 2 : 1;
for (int yOffs = 0; *str; yOffs += fontHeight) {
char *cr = strchr(str, 13);
if (cr)
*cr = 0;
uint32 len = strlen(str);
_screen->printText(str, (dm->sx + ((dm->w - len) >> 1)) << 3, dm->sy + yOffs, color, dm->unkA);
if (cr) {
*cr = 13;
str = cr + 1;
} else {
str += len;
}
for (int yOffs = 0; !str.empty(); yOffs += fontHeight) {
uint linebrk = str.findFirstOf('\r');
Common::String str2 = (linebrk != Common::String::npos) ? str.substr(0, linebrk) : str;
_screen->printText(str2.c_str(), (dm->sx * xAlignFactor + ((dm->w * xAlignFactor - str2.size()) >> 1)) << (4 - xAlignFactor), dm->sy + yOffs, color, dm->unkA);
str = (linebrk != Common::String::npos) ? str.substr(linebrk + 1) : "";
}
delete[] temp;
if (_vm->gameFlags().platform == Common::kPlatformAmiga)
_screen->fadePalette(*_palettes[0], 20);
else

View File

@ -420,20 +420,20 @@ SeqPlayer_HOF::SeqPlayer_HOF(KyraEngine_v1 *vm, Screen_v2 *screen, OSystem *syst
char **tmpSndLst = new char *[_sequenceSoundListSize];
for (int i = 0; i < _sequenceSoundListSize; i++) {
const int len = strlen(seqSoundList[i]);
const int len = Common::strnlen(seqSoundList[i], 8);
tmpSndLst[i] = new char[len + 1];
tmpSndLst[i][0] = 0;
if (tlkfiles && len > 1) {
for (int ii = 0; ii < tempSize; ii++) {
if (strlen(tlkfiles[ii]) > 1 && !scumm_stricmp(&seqSoundList[i][1], &tlkfiles[ii][1]))
strcpy(tmpSndLst[i], tlkfiles[ii]);
if (Common::strnlen(tlkfiles[ii], 8) > 1 && !scumm_stricmp(&seqSoundList[i][1], &tlkfiles[ii][1]))
Common::strlcpy(tmpSndLst[i], tlkfiles[ii], len + 1);
}
}
if (tmpSndLst[i][0] == 0)
strcpy(tmpSndLst[i], seqSoundList[i]);
Common::strlcpy(tmpSndLst[i], seqSoundList[i], len + 1);
}
tlkfiles = seqSoundList = nullptr;

View File

@ -171,20 +171,18 @@ void LoLEngine::setupPrologueData(bool load) {
const char *const *fileList = _flags.isTalkie ? (_flags.isDemo ? fileListCDDemo : fileListCD) : (_flags.platform == Common::kPlatformFMTowns ? fileListTowns : fileListFloppy);
char filename[32];
Common::String filename;
for (uint i = 0; fileList[i]; ++i) {
filename[0] = '\0';
filename.clear();
if (_flags.isTalkie && !_flags.isDemo) {
strcpy(filename, _languageExt[_lang]);
strcat(filename, "/");
}
if (_flags.isTalkie && !_flags.isDemo)
filename = Common::String(_languageExt[_lang]) + "/";
strcat(filename, fileList[i]);
filename += fileList[i];
if (load) {
if (!_res->loadPakFile(filename))
error("Couldn't load file: '%s'", filename);
error("Couldn't load file: '%s'", filename.c_str());
} else {
_res->unloadPakFile(filename);
}
@ -575,36 +573,35 @@ int LoLEngine::selectionCharInfo(int character) {
if (character < 0)
return -1;
char filename[16];
char vocFilename[6];
strcpy(vocFilename, "000X0");
Common::String filename;
Common::String vocFilename = "000X0";
switch (character) {
case 0:
strcpy(filename, "FACE09.SHP");
vocFilename[3] = 'A';
filename = "FACE09.SHP";
vocFilename.setChar('A', 3);
break;
case 1:
strcpy(filename, "FACE01.SHP");
vocFilename[3] = 'M';
filename = "FACE01.SHP";
vocFilename.setChar('M', 3);
break;
case 2:
strcpy(filename, "FACE08.SHP");
vocFilename[3] = 'K';
filename = "FACE08.SHP";
vocFilename.setChar('K', 3);
break;
case 3:
strcpy(filename, "FACE05.SHP");
vocFilename[3] = 'C';
filename = "FACE05.SHP";
vocFilename.setChar('C', 3);
break;
default:
break;
}
_screen->loadBitmap(filename, 9, 9, 0);
_screen->loadBitmap(filename.c_str(), 9, 9, 0);
_screen->copyRegion(0, 122, 0, 122, 320, 78, 4, 0, Screen::CR_NO_P_CHECK);
_screen->copyRegion(_charPreviews[character].x - 3, _charPreviews[character].y - 3, 8, 127, 38, 38, 2, 0);
@ -656,17 +653,17 @@ int LoLEngine::selectionCharInfo(int character) {
return character;
}
void LoLEngine::selectionCharInfoIntro(char *file) {
int index = 0;
file[4] = '0';
void LoLEngine::selectionCharInfoIntro(Common::String &file) {
char index = '\0';
file.setChar('0', 4);
bool processAnim = true;
while (_charSelectionInfoResult == -1 && !shouldQuit()) {
if (speechEnabled() && !_sound->isVoicePresent(file))
if (speechEnabled() && !_sound->isVoicePresent(file.c_str()))
break;
if (_flags.isTalkie)
_sound->voicePlay(file, &_speechHandle);
_sound->voicePlay(file.c_str(), &_speechHandle);
int i = 0;
while ((!speechEnabled() || (speechEnabled() && _sound->voiceIsPlaying(&_speechHandle))) && _charSelectionInfoResult == -1 && !shouldQuit()) {
@ -686,7 +683,7 @@ void LoLEngine::selectionCharInfoIntro(char *file) {
}
_sound->voiceStop(&_speechHandle);
file[4] = ++index + '0';
file.setChar(++index + '0', 4);
}
_screen->drawShape(0, _screen->getPtrToShape(_screen->getCPagePtr(9), 0), 11, 130, 0, 0);
@ -811,7 +808,7 @@ void HistoryPlayer::play() {
char tempWsaFilename[16];
char voiceFilename[13];
// the 'a' *has* to be lowercase
strcpy(voiceFilename, "PS_1a");
Common::strlcpy(voiceFilename, "PS_1a", sizeof(voiceFilename));
int part = 0;
Sound *sound = _vm->sound();
@ -870,7 +867,7 @@ void HistoryPlayer::play() {
sound->voicePlay(voiceFilename);
playWsa(true);
strcpy(tempWsaFilename, &data[part * 15]);
Common::strlcpy(tempWsaFilename, &data[part * 15], sizeof(tempWsaFilename));
for (int i = 1; i < 4 && !_vm->shouldQuit(); ++i) {
uint32 nextTime = _system->getMillis() + 30 * _vm->tickLength();
@ -1046,20 +1043,18 @@ void LoLEngine::setupEpilogueData(bool load) {
const char *const *fileList = _flags.isTalkie ? fileListCD : (_flags.platform == Common::kPlatformFMTowns ? fileListTowns : fileListFloppy);
assert(fileList);
char filename[32];
Common::String filename;
for (uint i = 0; fileList[i]; ++i) {
filename[0] = '\0';
filename.clear();
if (_flags.isTalkie) {
strcpy(filename, _languageExt[_lang]);
strcat(filename, "/");
}
if (_flags.isTalkie)
filename = Common::String(_languageExt[_lang]) + "/";
strcat(filename, fileList[i]);
filename += fileList[i];
if (load) {
if (!_res->loadPakFile(filename))
error("Couldn't load file: '%s'", filename);
error("Couldn't load file: '%s'", filename.c_str());
} else {
_res->unloadPakFile(filename);
}

View File

@ -90,7 +90,7 @@ int TextDisplayer::dropCRIntoString(char *str, int offs) {
char *TextDisplayer::preprocessString(const char *str) {
if (str != _talkBuffer) {
assert(strlen(str) < sizeof(_talkBuffer) - 1);
strcpy(_talkBuffer, str);
Common::strlcpy(_talkBuffer, str, sizeof(_talkBuffer));
}
if (_vm->gameFlags().lang == Common::ZH_TWN)

View File

@ -80,7 +80,7 @@ void TextDisplayer_HoF::printCustomCharacterText(const char *text, int x, int y,
char *TextDisplayer_HoF::preprocessString(const char *str) {
if (str != _talkBuffer) {
assert(strlen(str) < sizeof(_talkBuffer) - 1);
strcpy(_talkBuffer, str);
Common::strlcpy(_talkBuffer, str, sizeof(_talkBuffer));
}
if (_vm->gameFlags().lang == Common::ZH_TWN)
@ -558,20 +558,13 @@ void KyraEngine_HoF::processDialogue(int dlgOffset, int vocH, int csEntry) {
void KyraEngine_HoF::initTalkObject(int index) {
TalkObject &object = _talkObjectList[index];
char STAFilename[13];
char ENDFilename[13];
Common::String STAFilename = Common::String(object.filename) + "_STA.TIM";
_TLKFilename = Common::String(object.filename) + "_TLK.TIM";
Common::String ENDFilename = Common::String(object.filename) + "_END.TIM";
strcpy(STAFilename, object.filename);
strcpy(_TLKFilename, object.filename);
strcpy(ENDFilename, object.filename);
strcat(STAFilename + 4, "_STA.TIM");
strcat(_TLKFilename + 4, "_TLK.TIM");
strcat(ENDFilename + 4, "_END.TIM");
_currentTalkSections.STATim = _tim->load(STAFilename, &_timOpcodes);
_currentTalkSections.TLKTim = _tim->load(_TLKFilename, &_timOpcodes);
_currentTalkSections.ENDTim = _tim->load(ENDFilename, &_timOpcodes);
_currentTalkSections.STATim = _tim->load(STAFilename.c_str(), &_timOpcodes);
_currentTalkSections.TLKTim = _tim->load(_TLKFilename.c_str(), &_timOpcodes);
_currentTalkSections.ENDTim = _tim->load(ENDFilename.c_str(), &_timOpcodes);
if (object.scriptId != -1) {
_specialSceneScriptStateBackup[object.scriptId] = _specialSceneScriptState[object.scriptId];
@ -620,7 +613,7 @@ void KyraEngine_HoF::npcChatSequence(const Common::String &str, int objectId, in
objectChatInit(str, objectId, vocHigh, vocLow);
if (!_currentTalkSections.TLKTim)
_currentTalkSections.TLKTim = _tim->load(_TLKFilename, &_timOpcodes);
_currentTalkSections.TLKTim = _tim->load(_TLKFilename.c_str(), &_timOpcodes);
setNextIdleAnimTimer();

View File

@ -133,7 +133,7 @@ void TextDisplayer_LoL::expandField() {
}
}
void TextDisplayer_LoL::printDialogueText2(int dim, char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) {
void TextDisplayer_LoL::printDialogueText2(int dim, const char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) {
int oldDim = 0;
if (dim == 3) {
@ -163,7 +163,7 @@ void TextDisplayer_LoL::printDialogueText2(int dim, char *str, EMCState *script,
Screen::FontId of = _screen->setFont(_pc98TextMode ? Screen::FID_SJIS_TEXTMODE_FNT : Screen::FID_9_FNT);
preprocessString(str, script, paramList, paramIndex);
_numCharsTotal = strlen(_dialogueBuffer);
_numCharsTotal = Common::strnlen(_dialogueBuffer, 2559);
displayText(_dialogueBuffer);
_screen->setScreenDim(oldDim);
@ -224,10 +224,10 @@ void TextDisplayer_LoL::printMessage(uint16 type, const char *str, ...) {
_vm->_fadeText = false;
}
void TextDisplayer_LoL::preprocessString(char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) {
void TextDisplayer_LoL::preprocessString(const char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) {
char *dst = _dialogueBuffer;
for (char *s = str; *s;) {
for (const char *s = str; *s;) {
if (_vm->gameFlags().lang == Common::JA_JPN) {
uint8 c = *s;
if (c >= 0xE0 || (c > 0x80 && c < 0xA0)) {
@ -300,26 +300,26 @@ void TextDisplayer_LoL::preprocessString(char *str, EMCState *script, const uint
switch (para) {
case 'a':
strcpy(dst, Common::String::format("%d", _scriptTextParameter).c_str());
dst += strlen(dst);
Common::strlcpy(dst, Common::String::format("%d", _scriptTextParameter).c_str(), 2560 - (dst - _dialogueBuffer));
dst += Common::strnlen(dst, 2559 - (dst - _dialogueBuffer));
break;
case 'n':
strcpy(dst, _vm->_characters[script ? script->stack[script->sp + paramIndex] : paramList[paramIndex]].name);
dst += strlen(dst);
Common::strlcpy(dst, _vm->_characters[script ? script->stack[script->sp + paramIndex] : paramList[paramIndex]].name, 2560 - (dst - _dialogueBuffer));
dst += Common::strnlen(dst, 2559 - (dst - _dialogueBuffer));
break;
case 's':
strcpy(dst, _vm->getLangString(script ? script->stack[script->sp + paramIndex] : paramList[paramIndex]));
dst += strlen(dst);
Common::strlcpy(dst, _vm->getLangString(script ? script->stack[script->sp + paramIndex] : paramList[paramIndex]), 2560 - (dst - _dialogueBuffer));
dst += Common::strnlen(dst, 2559 - (dst - _dialogueBuffer));
break;
case 'X':
case 'd':
case 'u':
case 'x':
strcpy(dst, Common::String::format("%d", script ? script->stack[script->sp + paramIndex] : paramList[paramIndex]).c_str());
dst += strlen(dst);
Common::strlcpy(dst, Common::String::format("%d", script ? script->stack[script->sp + paramIndex] : paramList[paramIndex]).c_str(), 2560 - (dst - _dialogueBuffer));
dst += Common::strnlen(dst, 2559 - (dst - _dialogueBuffer));
break;
case '\0':
@ -339,7 +339,7 @@ Screen *TextDisplayer_LoL::screen() {
}
void TextDisplayer_LoL::textPageBreak() {
strcpy(_pageBreakString, _vm->getLangString(0x4073));
_pageBreakString = _vm->getLangString(0x4073);
TextDisplayer_rpg::textPageBreak();
}

View File

@ -43,7 +43,7 @@ public:
void setupField(bool mode);
void expandField();
void printDialogueText2(int dim, char *str, EMCState *script, const uint16 *paramList, int16 paramIndex);
void printDialogueText2(int dim, const char *str, EMCState *script, const uint16 *paramList, int16 paramIndex);
void printMessage(uint16 type, const char *str, ...) GCC_PRINTF(3, 4);
int16 _scriptTextParameter;
@ -52,7 +52,7 @@ private:
KyraRpgEngine *vm() override;
Screen *screen() override;
void preprocessString(char *str, EMCState *script, const uint16 *paramList, int16 paramIndex);
void preprocessString(const char *str, EMCState *script, const uint16 *paramList, int16 paramIndex);
void textPageBreak() override;
char *_stringParameters[15];

View File

@ -33,7 +33,7 @@ TextDisplayer_MR::TextDisplayer_MR(KyraEngine_MR *vm, Screen_MR *screen)
char *TextDisplayer_MR::preprocessString(const char *str) {
if (_talkBuffer != str) {
assert(strlen(str) < sizeof(_talkBuffer) - 1);
strcpy(_talkBuffer, str);
Common::strlcpy(_talkBuffer, str, sizeof(_talkBuffer));
}
char *p = _talkBuffer;

View File

@ -111,7 +111,7 @@ void TextDisplayer_rpg::resetDimTextPositions(int dim) {
void TextDisplayer_rpg::resetPageBreakString() {
if (_vm->_moreStrings)
strcpy(_pageBreakString, _vm->_moreStrings[0]);
_pageBreakString = _vm->_moreStrings[0];
}
void TextDisplayer_rpg::setPageBreakFlag() {
@ -157,10 +157,10 @@ void TextDisplayer_rpg::displayText(char *str, ...) {
if (!_tempString2 && c == '%') {
if (a == 'd') {
strcpy(_scriptParaString, Common::String::format("%d", va_arg(args, int)).c_str());
_tempString2 = _scriptParaString;
_scriptParaString = Common::String::format("%d", va_arg(args, int));
_tempString2 = _scriptParaString.c_str();
} else if (a == 's') {
_tempString2 = va_arg(args, char*);
_tempString2 = va_arg(args, const char*);
} else {
break;
}
@ -547,7 +547,7 @@ void TextDisplayer_rpg::printDialogueText(int stringId, const char *pageBreakStr
if (pageBreakString) {
if (pageBreakString[0]) {
strcpy(_pageBreakString, pageBreakString);
_pageBreakString = pageBreakString;
displayWaitButton();
resetPageBreakString();
}
@ -557,10 +557,9 @@ void TextDisplayer_rpg::printDialogueText(int stringId, const char *pageBreakStr
}
void TextDisplayer_rpg::printDialogueText(const char *str, bool wait) {
assert(strlen(str) < kEoBTextBufferSize);
assert(Common::strnlen(str, kEoBTextBufferSize) < kEoBTextBufferSize);
Common::strlcpy(_dialogueBuffer, str, kEoBTextBufferSize);
strcpy(_dialogueBuffer, str);
displayText(_dialogueBuffer);
if (wait)
displayWaitButton();
@ -658,12 +657,12 @@ void TextDisplayer_rpg::textPageBreak() {
if (_vm->game() == GI_LOL && _vm->gameFlags().use16ColorMode) {
_vm->gui_drawBox(x + 8, (y & ~7) - 1, 66, 10, 0xEE, 0xCC, -1);
_screen->printText(_pageBreakString, (x + 37 - (strlen(_pageBreakString) << 1) + 4) & ~3, (y + 2) & ~7, 0xC1, 0);
_screen->printText(_pageBreakString.c_str(), (x + 37 - (_pageBreakString.size() << 1) + 4) & ~3, (y + 2) & ~7, 0xC1, 0);
} else {
_screen->set16bitShadingLevel(4);
_vm->gui_drawBox(x, y, w, _vm->guiSettings()->buttons.height, _vm->guiSettings()->colors.frame1, _vm->guiSettings()->colors.frame2, _vm->guiSettings()->colors.fill);
_screen->set16bitShadingLevel(0);
_screen->printText(_pageBreakString, x + (w >> 1) - (_vm->screen()->getTextWidth(_pageBreakString) >> 1), y + _vm->guiSettings()->buttons.txtOffsY, _vm->_dialogueButtonLabelColor1, 0);
_screen->printText(_pageBreakString.c_str(), x + (w >> 1) - (_vm->screen()->getTextWidth(_pageBreakString.c_str()) >> 1), y + _vm->guiSettings()->buttons.txtOffsY, _vm->_dialogueButtonLabelColor1, 0);
}
_vm->removeInputTop();
@ -741,7 +740,7 @@ void TextDisplayer_rpg::textPageBreak() {
void TextDisplayer_rpg::displayWaitButton() {
_vm->_dialogueNumButtons = 1;
_vm->_dialogueButtonString[0] = _pageBreakString;
_vm->_dialogueButtonString[0] = _pageBreakString.c_str();
_vm->_dialogueButtonString[1] = 0;
_vm->_dialogueButtonString[2] = 0;
_vm->_dialogueHighlightedButton = 0;

View File

@ -71,8 +71,8 @@ protected:
char *_dialogueBuffer;
char *_tempString1;
char *_tempString2;
const char *_tempString1;
const char *_tempString2;
char *_currentLine;
char _ctrl[3];
@ -85,8 +85,8 @@ protected:
bool _sjisTextModeLineBreak;
const bool _pc98TextMode;
char _pageBreakString[20];
char _scriptParaString[11];
Common::String _pageBreakString;
Common::String _scriptParaString;
int _lineCount;
bool _allowPageBreak;