From f99d613dcb1022a6c30b0c299ffada11fb7eba6b Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 15:12:24 -0500 Subject: ZVISION: Rename files to use underscores instead of camelCase --- engines/zvision/resultAction.cpp | 38 ---- engines/zvision/resultAction.h | 92 -------- engines/zvision/result_action.cpp | 38 ++++ engines/zvision/result_action.h | 92 ++++++++ engines/zvision/scrFileHandling.cpp | 287 ------------------------ engines/zvision/scr_file_handling.cpp | 287 ++++++++++++++++++++++++ engines/zvision/scriptManager.cpp | 46 ---- engines/zvision/scriptManager.h | 107 --------- engines/zvision/script_manager.cpp | 46 ++++ engines/zvision/script_manager.h | 107 +++++++++ engines/zvision/singleValueContainer.cpp | 345 ----------------------------- engines/zvision/singleValueContainer.h | 181 --------------- engines/zvision/single_value_container.cpp | 345 +++++++++++++++++++++++++++++ engines/zvision/single_value_container.h | 181 +++++++++++++++ engines/zvision/zfsArchive.cpp | 155 ------------- engines/zvision/zfsArchive.h | 121 ---------- engines/zvision/zfs_archive.cpp | 155 +++++++++++++ engines/zvision/zfs_archive.h | 121 ++++++++++ 18 files changed, 1372 insertions(+), 1372 deletions(-) delete mode 100644 engines/zvision/resultAction.cpp delete mode 100644 engines/zvision/resultAction.h create mode 100644 engines/zvision/result_action.cpp create mode 100644 engines/zvision/result_action.h delete mode 100644 engines/zvision/scrFileHandling.cpp create mode 100644 engines/zvision/scr_file_handling.cpp delete mode 100644 engines/zvision/scriptManager.cpp delete mode 100644 engines/zvision/scriptManager.h create mode 100644 engines/zvision/script_manager.cpp create mode 100644 engines/zvision/script_manager.h delete mode 100644 engines/zvision/singleValueContainer.cpp delete mode 100644 engines/zvision/singleValueContainer.h create mode 100644 engines/zvision/single_value_container.cpp create mode 100644 engines/zvision/single_value_container.h delete mode 100644 engines/zvision/zfsArchive.cpp delete mode 100644 engines/zvision/zfsArchive.h create mode 100644 engines/zvision/zfs_archive.cpp create mode 100644 engines/zvision/zfs_archive.h diff --git a/engines/zvision/resultAction.cpp b/engines/zvision/resultAction.cpp deleted file mode 100644 index d14438d190..0000000000 --- a/engines/zvision/resultAction.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* 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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/scummsys.h" - -#include "zvision/resultAction.h" - -namespace ZVision { - -ActionAdd::ActionAdd(Common::String line) { - sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); -} - -bool ActionAdd::execute(ZVision *zVision) { - zVision->getScriptManager()->addToStateValue(_key, _value); - return true; -} - -} // End of namespace ZVision diff --git a/engines/zvision/resultAction.h b/engines/zvision/resultAction.h deleted file mode 100644 index 4fd589d7cc..0000000000 --- a/engines/zvision/resultAction.h +++ /dev/null @@ -1,92 +0,0 @@ -/* 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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef ZVISION_RESULT_ACTION_H -#define ZVISION_RESULT_ACTION_H - -#include "common/scummsys.h" - -#include "zvision/zvision.h" - -namespace ZVision { - -class ResultAction { -public: - virtual ~ResultAction() {} - virtual bool execute(ZVision *zVision) = 0; -}; - - -// The different types of actions -// ADD, -// ANIM_PLAY, -// ANIM_PRELOAD, -// ANIM_UNLOAD, -// ATTENUATE, -// ASSIGN, -// CHANGE_LOCATION, -// CROSSFADE, -// DEBUG, -// DELAY_RENDER, -// DISABLE_CONTROL, -// DISABLE_VENUS, -// DISPLAY_MESSAGE, -// DISSOLVE, -// DISTORT, -// ENABLE_CONTROL, -// FLUSH_MOUSE_EVENTS, -// INVENTORY, -// KILL, -// MENU_BAR_ENABLE, -// MUSIC, -// PAN_TRACK, -// PLAY_PRELOAD, -// PREFERENCES, -// QUIT, -// RANDOM, -// REGION, -// RESTORE_GAME, -// ROTATE_TO, -// SAVE_GAME, -// SET_PARTIAL_SCREEN, -// SET_SCREEN, -// SET_VENUS, -// STOP, -// STREAM_VIDEO, -// SYNC_SOUND, -// TIMER, -// TTY_TEXT, -// UNIVERSE_MUSIC, - -class ActionAdd : public ResultAction { -public: - ActionAdd(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - byte _value; -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/result_action.cpp b/engines/zvision/result_action.cpp new file mode 100644 index 0000000000..d14438d190 --- /dev/null +++ b/engines/zvision/result_action.cpp @@ -0,0 +1,38 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" + +#include "zvision/resultAction.h" + +namespace ZVision { + +ActionAdd::ActionAdd(Common::String line) { + sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); +} + +bool ActionAdd::execute(ZVision *zVision) { + zVision->getScriptManager()->addToStateValue(_key, _value); + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/result_action.h b/engines/zvision/result_action.h new file mode 100644 index 0000000000..4fd589d7cc --- /dev/null +++ b/engines/zvision/result_action.h @@ -0,0 +1,92 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ZVISION_RESULT_ACTION_H +#define ZVISION_RESULT_ACTION_H + +#include "common/scummsys.h" + +#include "zvision/zvision.h" + +namespace ZVision { + +class ResultAction { +public: + virtual ~ResultAction() {} + virtual bool execute(ZVision *zVision) = 0; +}; + + +// The different types of actions +// ADD, +// ANIM_PLAY, +// ANIM_PRELOAD, +// ANIM_UNLOAD, +// ATTENUATE, +// ASSIGN, +// CHANGE_LOCATION, +// CROSSFADE, +// DEBUG, +// DELAY_RENDER, +// DISABLE_CONTROL, +// DISABLE_VENUS, +// DISPLAY_MESSAGE, +// DISSOLVE, +// DISTORT, +// ENABLE_CONTROL, +// FLUSH_MOUSE_EVENTS, +// INVENTORY, +// KILL, +// MENU_BAR_ENABLE, +// MUSIC, +// PAN_TRACK, +// PLAY_PRELOAD, +// PREFERENCES, +// QUIT, +// RANDOM, +// REGION, +// RESTORE_GAME, +// ROTATE_TO, +// SAVE_GAME, +// SET_PARTIAL_SCREEN, +// SET_SCREEN, +// SET_VENUS, +// STOP, +// STREAM_VIDEO, +// SYNC_SOUND, +// TIMER, +// TTY_TEXT, +// UNIVERSE_MUSIC, + +class ActionAdd : public ResultAction { +public: + ActionAdd(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + byte _value; +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/scrFileHandling.cpp b/engines/zvision/scrFileHandling.cpp deleted file mode 100644 index 61feb12b7e..0000000000 --- a/engines/zvision/scrFileHandling.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* 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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/scummsys.h" - -#include - -#include "zvision/scriptManager.h" -#include "zvision/utility.h" -#include "zvision/puzzle.h" - -#include "common/textconsole.h" -#include "common/file.h" -#include "common/tokenizer.h" - -namespace ZVision { - -void ScriptManager::parseScrFile(Common::String fileName) { - Common::File file; - if (!file.open(fileName)) - return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another - - while(!file.eos()) { - Common::String line = file.readLine(); - if (file.err()) { - warning("Error parsing scr file: %s", fileName); - return; - } - - trimCommentsAndWhiteSpace(line); - if (line.empty()) - continue; - - if (line.matchString("puzzle:*", true)) { - Puzzle puzzle; - sscanf(line.c_str(),"puzzle:%u",&(puzzle.id)); - - parsePuzzle(puzzle, file); - _puzzles.push_back(puzzle); - } else if (line.matchString("control:*", true)) { - Control control; - char controlType[20]; - sscanf(line.c_str(),"control:%u %s",&(control.id), controlType); - - parseControl(control, file); - _controls.push_back(control); - } - } -} - -void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream) { - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - - while (!line.contains('}')) { - if (line.matchString("criteria {", true)) - puzzle.criteriaList.push_back(parseCriteria(stream)); - else if (line.matchString("results {", true)) - parseResult(stream, puzzle.resultActions); - else if (line.matchString("flags {", true)) - puzzle.flags = parseFlags(stream); - } -} - -Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const { - Criteria criteria; - - // Loop until we find the closing brace - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - - while (!line.contains('}')) { - // Split the string into tokens using ' ' as a delimiter - Common::StringTokenizer tokenizer(line); - Common::String token; - - // Parse the id out of the first token - token = tokenizer.nextToken(); - sscanf(token.c_str(), "[%u]", &(criteria.id)); - - // Parse the operator out of the second token - token = tokenizer.nextToken(); - if (token.c_str()[0] == '=') - criteria.criteriaOperator = EQUAL_TO; - else if (token.c_str()[0] == '!') - criteria.criteriaOperator = NOT_EQUAL_TO; - else if (token.c_str()[0] == '>') - criteria.criteriaOperator = GREATER_THAN; - else if (token.c_str()[0] == '<') - criteria.criteriaOperator = LESS_THAN; - - // First determine if the last token is an id or a value - // Then parse it into 'argument' - token = tokenizer.nextToken(); - if (token.contains('[')) { - sscanf(token.c_str(), "[%u]", &(criteria.argument)); - criteria.isArgumentAnId = true; - } else { - sscanf(token.c_str(), "%u", &(criteria.argument)); - criteria.isArgumentAnId = false; - } - - line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - } - - return criteria; -} - -void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { - // Loop until we find the closing brace - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - - while (!line.contains('}')) { - // Parse for the action type - if (line.matchString("*:add*", true)) { - actionList.push_back(ActionAdd(line)); - } else if (line.matchString("*:animplay*", true)) { - - - } else if (line.matchString("*:animpreload*", true)) { - - - } else if (line.matchString("*:animunload*", true)) { - - - } else if (line.matchString("*:attenuate*", true)) { - - - } else if (line.matchString("*:assign*", true)) { - - - } else if (line.matchString("*:change_location*", true)) { - - - } else if (line.matchString("*:crossfade*", true)) { - - - } else if (line.matchString("*:debug*", true)) { - - - } else if (line.matchString("*:delay_render*", true)) { - - - } else if (line.matchString("*:disable_control*", true)) { - - - } else if (line.matchString("*:disable_venus*", true)) { - - - } else if (line.matchString("*:display_message*", true)) { - - - } else if (line.matchString("*:dissolve*", true)) { - - - } else if (line.matchString("*:distort*", true)) { - - - } else if (line.matchString("*:enable_control*", true)) { - - - } else if (line.matchString("*:flush_mouse_events*", true)) { - - - } else if (line.matchString("*:inventory*", true)) { - - - } else if (line.matchString("*:kill*", true)) { - - - } else if (line.matchString("*:menu_bar_enable*", true)) { - - - } else if (line.matchString("*:music*", true)) { - - - } else if (line.matchString("*:pan_track*", true)) { - - - } else if (line.matchString("*:playpreload*", true)) { - - - } else if (line.matchString("*:preferences*", true)) { - - - } else if (line.matchString("*:quit*", true)) { - - - } else if (line.matchString("*:random*", true)) { - - - } else if (line.matchString("*:region*", true)) { - - - } else if (line.matchString("*:restore_game*", true)) { - - - } else if (line.matchString("*:rotate_to*", true)) { - - - } else if (line.matchString("*:save_game*", true)) { - - - } else if (line.matchString("*:set_partial_screen*", true)) { - - - } else if (line.matchString("*:set_screen*", true)) { - - - } else if (line.matchString("*:set_venus*", true)) { - - - } else if (line.matchString("*:stop*", true)) { - - - } else if (line.matchString("*:streamvideo*", true)) { - - - } else if (line.matchString("*:syncsound*", true)) { - - - } else if (line.matchString("*:timer*", true)) { - - - } else if (line.matchString("*:ttytext*", true)) { - - - } else if (line.matchString("*:universe_music*", true)) { - - - } else { - warning("Unhandled result action type: ", line); - } - - line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - } - - return; -} - -byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { - byte flags; - - // Loop until we find the closing brace - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - - while (!line.contains('}')) { - if (line.matchString("ONCE_PER_INST", true)) { - flags |= ONCE_PER_INST; - } else if (line.matchString("DO_ME_NOW", true)) { - flags |= DO_ME_NOW; - } else if (line.matchString("DISABLED", true)) { - flags |= DISABLED; - } - } - - return flags; -} - -void ScriptManager::parseControl(Control &control, Common::SeekableReadStream &stream) { - -} - -} // End of namespace ZVision diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp new file mode 100644 index 0000000000..61feb12b7e --- /dev/null +++ b/engines/zvision/scr_file_handling.cpp @@ -0,0 +1,287 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" + +#include + +#include "zvision/scriptManager.h" +#include "zvision/utility.h" +#include "zvision/puzzle.h" + +#include "common/textconsole.h" +#include "common/file.h" +#include "common/tokenizer.h" + +namespace ZVision { + +void ScriptManager::parseScrFile(Common::String fileName) { + Common::File file; + if (!file.open(fileName)) + return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another + + while(!file.eos()) { + Common::String line = file.readLine(); + if (file.err()) { + warning("Error parsing scr file: %s", fileName); + return; + } + + trimCommentsAndWhiteSpace(line); + if (line.empty()) + continue; + + if (line.matchString("puzzle:*", true)) { + Puzzle puzzle; + sscanf(line.c_str(),"puzzle:%u",&(puzzle.id)); + + parsePuzzle(puzzle, file); + _puzzles.push_back(puzzle); + } else if (line.matchString("control:*", true)) { + Control control; + char controlType[20]; + sscanf(line.c_str(),"control:%u %s",&(control.id), controlType); + + parseControl(control, file); + _controls.push_back(control); + } + } +} + +void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream) { + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + if (line.matchString("criteria {", true)) + puzzle.criteriaList.push_back(parseCriteria(stream)); + else if (line.matchString("results {", true)) + parseResult(stream, puzzle.resultActions); + else if (line.matchString("flags {", true)) + puzzle.flags = parseFlags(stream); + } +} + +Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const { + Criteria criteria; + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + // Split the string into tokens using ' ' as a delimiter + Common::StringTokenizer tokenizer(line); + Common::String token; + + // Parse the id out of the first token + token = tokenizer.nextToken(); + sscanf(token.c_str(), "[%u]", &(criteria.id)); + + // Parse the operator out of the second token + token = tokenizer.nextToken(); + if (token.c_str()[0] == '=') + criteria.criteriaOperator = EQUAL_TO; + else if (token.c_str()[0] == '!') + criteria.criteriaOperator = NOT_EQUAL_TO; + else if (token.c_str()[0] == '>') + criteria.criteriaOperator = GREATER_THAN; + else if (token.c_str()[0] == '<') + criteria.criteriaOperator = LESS_THAN; + + // First determine if the last token is an id or a value + // Then parse it into 'argument' + token = tokenizer.nextToken(); + if (token.contains('[')) { + sscanf(token.c_str(), "[%u]", &(criteria.argument)); + criteria.isArgumentAnId = true; + } else { + sscanf(token.c_str(), "%u", &(criteria.argument)); + criteria.isArgumentAnId = false; + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + } + + return criteria; +} + +void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + // Parse for the action type + if (line.matchString("*:add*", true)) { + actionList.push_back(ActionAdd(line)); + } else if (line.matchString("*:animplay*", true)) { + + + } else if (line.matchString("*:animpreload*", true)) { + + + } else if (line.matchString("*:animunload*", true)) { + + + } else if (line.matchString("*:attenuate*", true)) { + + + } else if (line.matchString("*:assign*", true)) { + + + } else if (line.matchString("*:change_location*", true)) { + + + } else if (line.matchString("*:crossfade*", true)) { + + + } else if (line.matchString("*:debug*", true)) { + + + } else if (line.matchString("*:delay_render*", true)) { + + + } else if (line.matchString("*:disable_control*", true)) { + + + } else if (line.matchString("*:disable_venus*", true)) { + + + } else if (line.matchString("*:display_message*", true)) { + + + } else if (line.matchString("*:dissolve*", true)) { + + + } else if (line.matchString("*:distort*", true)) { + + + } else if (line.matchString("*:enable_control*", true)) { + + + } else if (line.matchString("*:flush_mouse_events*", true)) { + + + } else if (line.matchString("*:inventory*", true)) { + + + } else if (line.matchString("*:kill*", true)) { + + + } else if (line.matchString("*:menu_bar_enable*", true)) { + + + } else if (line.matchString("*:music*", true)) { + + + } else if (line.matchString("*:pan_track*", true)) { + + + } else if (line.matchString("*:playpreload*", true)) { + + + } else if (line.matchString("*:preferences*", true)) { + + + } else if (line.matchString("*:quit*", true)) { + + + } else if (line.matchString("*:random*", true)) { + + + } else if (line.matchString("*:region*", true)) { + + + } else if (line.matchString("*:restore_game*", true)) { + + + } else if (line.matchString("*:rotate_to*", true)) { + + + } else if (line.matchString("*:save_game*", true)) { + + + } else if (line.matchString("*:set_partial_screen*", true)) { + + + } else if (line.matchString("*:set_screen*", true)) { + + + } else if (line.matchString("*:set_venus*", true)) { + + + } else if (line.matchString("*:stop*", true)) { + + + } else if (line.matchString("*:streamvideo*", true)) { + + + } else if (line.matchString("*:syncsound*", true)) { + + + } else if (line.matchString("*:timer*", true)) { + + + } else if (line.matchString("*:ttytext*", true)) { + + + } else if (line.matchString("*:universe_music*", true)) { + + + } else { + warning("Unhandled result action type: ", line); + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + } + + return; +} + +byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { + byte flags; + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + if (line.matchString("ONCE_PER_INST", true)) { + flags |= ONCE_PER_INST; + } else if (line.matchString("DO_ME_NOW", true)) { + flags |= DO_ME_NOW; + } else if (line.matchString("DISABLED", true)) { + flags |= DISABLED; + } + } + + return flags; +} + +void ScriptManager::parseControl(Control &control, Common::SeekableReadStream &stream) { + +} + +} // End of namespace ZVision diff --git a/engines/zvision/scriptManager.cpp b/engines/zvision/scriptManager.cpp deleted file mode 100644 index 5317bf60f1..0000000000 --- a/engines/zvision/scriptManager.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -*/ - -#include "common/scummsys.h" - -#include "zvision/scriptManager.h" - -namespace ZVision { - -// TODO: Actually do something in the initialize or remove it -void ScriptManager::initialize() { - -} - -byte ScriptManager::getStateValue(uint32 key) { - return _globalState[key]; -} - -void ScriptManager::setStateValue(uint32 key, byte value) { - _globalState[key] = value; -} - -void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) { - _globalState[key] += valueToAdd; -} - -} // End of namespace ZVision diff --git a/engines/zvision/scriptManager.h b/engines/zvision/scriptManager.h deleted file mode 100644 index 563a010de5..0000000000 --- a/engines/zvision/scriptManager.h +++ /dev/null @@ -1,107 +0,0 @@ -/* 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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef ZVISION_SCRIPT_MANAGER_H -#define ZVISION_SCRIPT_MANAGER_H - -#include "common/str.h" -#include "common/stream.h" -#include "common/hashmap.h" - -#include "zvision/puzzle.h" -#include "zvision/control.h" -#include "zvision/singleValueContainer.h" - -namespace ZVision { - -class ScriptManager { -private: - /** Holds the global state variables. Optimize for fast random access */ - Common::HashMap _globalState; - /** Holds the currently active puzzles. Optimize for fast iteration */ - Common::List _puzzles; - /** Holds the currently active controls. Optimize for fast iteration */ - Common::List _controls; - -public: - - void initialize(); - byte getStateValue(uint32 key); - void setStateValue(uint32 key, byte value); - void addToStateValue(uint32 key, byte valueToAdd); - -private: - /** - * Parses a script file into triggers and events - * - * @param fileName Name of the .scr file - */ - void parseScrFile(Common::String fileName); - - /** - * Parses the stream into a Puzzle object - * Helper method for parseScrFile. - * - * @param puzzle The object to store what is parsed - * @param stream Scr file stream - */ - void parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream); - - /** - * Parses the stream into a Criteria object - * Helper method for parsePuzzle. - * - * @param stream Scr file stream - * @return Created Criteria object - */ - Criteria parseCriteria(Common::SeekableReadStream &stream) const; - - /** - * Parses the stream into a Results object - * Helper method for parsePuzzle. - * - * @param stream Scr file stream - * @return Created Results object - */ - void parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const; - - /** - * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum - * - * @param stream Scr file stream - * @return Bitwise or of all the flags set within the puzzle - */ - byte parseFlags(Common::SeekableReadStream &stream) const; - - /** - * Helper method for parseScrFile. Parses the stream into a Control object - * - * @param control The object to store what is parsed - * @param stream Scr file stream - */ - void parseControl(Control &control, Common::SeekableReadStream &stream); -}; - - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp new file mode 100644 index 0000000000..5317bf60f1 --- /dev/null +++ b/engines/zvision/script_manager.cpp @@ -0,0 +1,46 @@ +/* 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 2 +* 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, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +*/ + +#include "common/scummsys.h" + +#include "zvision/scriptManager.h" + +namespace ZVision { + +// TODO: Actually do something in the initialize or remove it +void ScriptManager::initialize() { + +} + +byte ScriptManager::getStateValue(uint32 key) { + return _globalState[key]; +} + +void ScriptManager::setStateValue(uint32 key, byte value) { + _globalState[key] = value; +} + +void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) { + _globalState[key] += valueToAdd; +} + +} // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h new file mode 100644 index 0000000000..563a010de5 --- /dev/null +++ b/engines/zvision/script_manager.h @@ -0,0 +1,107 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ZVISION_SCRIPT_MANAGER_H +#define ZVISION_SCRIPT_MANAGER_H + +#include "common/str.h" +#include "common/stream.h" +#include "common/hashmap.h" + +#include "zvision/puzzle.h" +#include "zvision/control.h" +#include "zvision/singleValueContainer.h" + +namespace ZVision { + +class ScriptManager { +private: + /** Holds the global state variables. Optimize for fast random access */ + Common::HashMap _globalState; + /** Holds the currently active puzzles. Optimize for fast iteration */ + Common::List _puzzles; + /** Holds the currently active controls. Optimize for fast iteration */ + Common::List _controls; + +public: + + void initialize(); + byte getStateValue(uint32 key); + void setStateValue(uint32 key, byte value); + void addToStateValue(uint32 key, byte valueToAdd); + +private: + /** + * Parses a script file into triggers and events + * + * @param fileName Name of the .scr file + */ + void parseScrFile(Common::String fileName); + + /** + * Parses the stream into a Puzzle object + * Helper method for parseScrFile. + * + * @param puzzle The object to store what is parsed + * @param stream Scr file stream + */ + void parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream); + + /** + * Parses the stream into a Criteria object + * Helper method for parsePuzzle. + * + * @param stream Scr file stream + * @return Created Criteria object + */ + Criteria parseCriteria(Common::SeekableReadStream &stream) const; + + /** + * Parses the stream into a Results object + * Helper method for parsePuzzle. + * + * @param stream Scr file stream + * @return Created Results object + */ + void parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const; + + /** + * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum + * + * @param stream Scr file stream + * @return Bitwise or of all the flags set within the puzzle + */ + byte parseFlags(Common::SeekableReadStream &stream) const; + + /** + * Helper method for parseScrFile. Parses the stream into a Control object + * + * @param control The object to store what is parsed + * @param stream Scr file stream + */ + void parseControl(Control &control, Common::SeekableReadStream &stream); +}; + + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/singleValueContainer.cpp b/engines/zvision/singleValueContainer.cpp deleted file mode 100644 index bd91c44daf..0000000000 --- a/engines/zvision/singleValueContainer.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* 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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/scummsys.h" -#include "common/textconsole.h" - -#include "zvision/singleValueContainer.h" - -namespace ZVision { - -SingleValueContainer::SingleValueContainer(ValueType type) : _objectType(type) { } - -SingleValueContainer::SingleValueContainer(bool value) : _objectType(BOOL) { - _value.boolVal = value; -} - -SingleValueContainer::SingleValueContainer(byte value) : _objectType(BYTE) { - _value.byteVal = value; -} - -SingleValueContainer::SingleValueContainer(int16 value) : _objectType(INT16) { - _value.int16Val = value; -} - -SingleValueContainer::SingleValueContainer(uint16 value) : _objectType(UINT16) { - _value.uint16Val = value; -} - -SingleValueContainer::SingleValueContainer(int32 value) : _objectType(INT32) { - _value.int32Val = value; -} - -SingleValueContainer::SingleValueContainer(uint32 value) : _objectType(UINT32) { - _value.uint32Val = value; -} - -SingleValueContainer::SingleValueContainer(float value) : _objectType(FLOAT) { - _value.floatVal = value; -} - -SingleValueContainer::SingleValueContainer(double value) : _objectType(DOUBLE) { - _value.doubleVal = value; -} - -SingleValueContainer::SingleValueContainer(Common::String value) : _objectType(BYTE) { - _value.stringVal = new char[value.size() + 1]; - memcpy(_value.stringVal, value.c_str(), value.size() + 1); -} - -SingleValueContainer::SingleValueContainer(const SingleValueContainer &other) { - _objectType = other._objectType; - - switch (_objectType) { - case BOOL: - _value.boolVal = other._value.boolVal; - break; - case BYTE: - _value.byteVal = other._value.byteVal; - break; - case INT16: - _value.int16Val = other._value.int16Val; - break; - case UINT16: - _value.uint16Val = other._value.uint16Val; - break; - case INT32: - _value.int32Val = other._value.int32Val; - break; - case UINT32: - _value.uint32Val = other._value.uint32Val; - break; - case FLOAT: - _value.floatVal = other._value.floatVal; - break; - case DOUBLE: - _value.doubleVal = other._value.doubleVal; - break; - case STRING: - uint32 length = strlen(other._value.stringVal); - _value.stringVal = new char[length + 1]; - memcpy(_value.stringVal, other._value.stringVal, length + 1); - break; - } -} - -SingleValueContainer::~SingleValueContainer() { - deleteCharPointer(); -} - -void SingleValueContainer::deleteCharPointer() { - if (_objectType == STRING) - delete[] _value.stringVal; -} - - -SingleValueContainer &SingleValueContainer::operator=(const bool &rhs) { - if (_objectType == BOOL) { - _value.boolVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = BOOL; - _value.boolVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const byte &rhs) { - if (_objectType == BYTE) { - _value.byteVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = BYTE; - _value.byteVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const int16 &rhs) { - if (_objectType == INT16) { - _value.int16Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = INT16; - _value.int16Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const uint16 &rhs) { - if (_objectType == UINT16) { - _value.uint16Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = UINT16; - _value.uint16Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const int32 &rhs) { - if (_objectType == INT32) { - _value.int32Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = INT32; - _value.int32Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const uint32 &rhs) { - if (_objectType == UINT32) { - _value.uint32Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = UINT32; - _value.uint32Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const float &rhs) { - if (_objectType == FLOAT) { - _value.floatVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = FLOAT; - _value.floatVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const double &rhs) { - if (_objectType == DOUBLE) { - _value.doubleVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = DOUBLE; - _value.doubleVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const Common::String &rhs) { - if (_objectType != STRING) { - _objectType = STRING; - _value.stringVal = new char[rhs.size() + 1]; - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - - return *this; - } - - uint32 length = strlen(_value.stringVal); - if (length <= rhs.size() + 1) { - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - } else { - delete[] _value.stringVal; - _value.stringVal = new char[rhs.size() + 1]; - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - } - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const SingleValueContainer &rhs) { - switch (_objectType) { - case BOOL: - return operator=(rhs._value.boolVal); - case BYTE: - return operator=(rhs._value.byteVal); - case INT16: - return operator=(rhs._value.int16Val); - case UINT16: - return operator=(rhs._value.uint16Val); - case INT32: - return operator=(rhs._value.int32Val); - case UINT32: - return operator=(rhs._value.uint32Val); - case FLOAT: - return operator=(rhs._value.floatVal); - case DOUBLE: - return operator=(rhs._value.doubleVal); - case STRING: - uint32 length = strlen(rhs._value.stringVal); - - _value.stringVal = new char[length + 1]; - memcpy(_value.stringVal, rhs._value.stringVal, length + 1); - - return *this; - } - - return *this; -} - - -bool SingleValueContainer::getBoolValue(bool *returnValue) const { - if (_objectType != BOOL) { - warning("'Object' is not storing a bool."); - return false; - } - - *returnValue = _value.boolVal; - return true; -} - -bool SingleValueContainer::getByteValue(byte *returnValue) const { - if (_objectType != BYTE) - warning("'Object' is not storing a byte."); - - *returnValue = _value.byteVal; - return true; -} - -bool SingleValueContainer::getInt16Value(int16 *returnValue) const { - if (_objectType != INT16) - warning("'Object' is not storing an int16."); - - *returnValue = _value.int16Val; - return true; -} - -bool SingleValueContainer::getUInt16Value(uint16 *returnValue) const { - if (_objectType != UINT16) - warning("'Object' is not storing a uint16."); - - *returnValue = _value.uint16Val; - return true; -} - -bool SingleValueContainer::getInt32Value(int32 *returnValue) const { - if (_objectType != INT32) - warning("'Object' is not storing an int32."); - - *returnValue = _value.int32Val; - return true; -} - -bool SingleValueContainer::getUInt32Value(uint32 *returnValue) const { - if (_objectType != UINT32) - warning("'Object' is not storing a uint32."); - - *returnValue = _value.uint32Val; - return true; -} - -bool SingleValueContainer::getFloatValue(float *returnValue) const { - if (_objectType != FLOAT) - warning("'Object' is not storing a float."); - - *returnValue = _value.floatVal; - return true; -} - -bool SingleValueContainer::getDoubleValue(double *returnValue) const { - if (_objectType != DOUBLE) - warning("'Object' is not storing a double."); - - *returnValue = _value.doubleVal; - return true; -} - -bool SingleValueContainer::getStringValue(Common::String *returnValue) const { - if (_objectType != STRING) - warning("'Object' is not storing a Common::String."); - - *returnValue = _value.stringVal; - return true; -} - -} // End of namespace ZVision diff --git a/engines/zvision/singleValueContainer.h b/engines/zvision/singleValueContainer.h deleted file mode 100644 index 49c7267f77..0000000000 --- a/engines/zvision/singleValueContainer.h +++ /dev/null @@ -1,181 +0,0 @@ -/* 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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef ZVISION_OBJECT_H -#define ZVISION_OBJECT_H - -#include "common/str.h" - -namespace ZVision { - -/** - * A generic single value storage class. It is useful for storing different - * value types in a single List, Hashmap, etc. - */ -class SingleValueContainer { -public: - enum ValueType { - BOOL, - BYTE, - INT16, - UINT16, - INT32, - UINT32, - FLOAT, - DOUBLE, - STRING, - }; - - // Constructors - explicit SingleValueContainer(ValueType type); - explicit SingleValueContainer(bool value); - explicit SingleValueContainer(byte value); - explicit SingleValueContainer(int16 value); - explicit SingleValueContainer(uint16 value); - explicit SingleValueContainer(int32 value); - explicit SingleValueContainer(uint32 value); - explicit SingleValueContainer(float value); - explicit SingleValueContainer(double value); - explicit SingleValueContainer(Common::String value); - - // Copy constructor - explicit SingleValueContainer(const SingleValueContainer& other); - - // Destructor - ~SingleValueContainer(); - -private: - ValueType _objectType; - - union { - bool boolVal; - byte byteVal; - int16 int16Val; - uint16 uint16Val; - int32 int32Val; - uint32 uint32Val; - float floatVal; - double doubleVal; - char *stringVal; - } _value; - -public: - SingleValueContainer &operator=(const bool &rhs); - SingleValueContainer &operator=(const byte &rhs); - SingleValueContainer &operator=(const int16 &rhs); - SingleValueContainer &operator=(const uint16 &rhs); - SingleValueContainer &operator=(const int32 &rhs); - SingleValueContainer &operator=(const uint32 &rhs); - SingleValueContainer &operator=(const float &rhs); - SingleValueContainer &operator=(const double &rhs); - SingleValueContainer &operator=(const Common::String &rhs); - - SingleValueContainer& operator=(const SingleValueContainer &rhs); - - /** - * Retrieve a bool from the container. If the container is not storing a - * bool, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getBoolValue(bool *returnValue) const; - /** - * Retrieve a byte from the container. If the container is not storing a - * byte, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getByteValue(byte *returnValue) const; - /** - * Retrieve an int16 from the container. If the container is not storing an - * int16, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getInt16Value(int16 *returnValue) const; - /** - * Retrieve a uint16 from the container. If the container is not storing a - * uint16, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getUInt16Value(uint16 *returnValue) const; - /** - * Retrieve an int32 from the container. If the container is not storing an - * int32, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getInt32Value(int32 *returnValue) const; - /** - * Retrieve a uint32 from the container. If the container is not storing a - * uint32, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getUInt32Value(uint32 *returnValue) const; - /** - * Retrieve a float from the container. If the container is not storing a - * float, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getFloatValue(float *returnValue) const; - /** - * Retrieve a double from the container. If the container is not storing a - * double, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getDoubleValue(double *returnValue) const; - /** - * Retrieve a String from the container. If the container is not storing a - * string, this will return false and display a warning(). - * - * Caution: Strings are internally stored as char[]. getStringValue uses - * Common::String::operator=(char *) to do the assigment, which uses both - * strlen() AND memmove(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getStringValue(Common::String *returnValue) const; - -private: - /** - * Helper method for destruction and assignment. It checks to see - * if the char pointer is being used, and if so calls delete on it - */ - void deleteCharPointer(); -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/single_value_container.cpp b/engines/zvision/single_value_container.cpp new file mode 100644 index 0000000000..bd91c44daf --- /dev/null +++ b/engines/zvision/single_value_container.cpp @@ -0,0 +1,345 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" +#include "common/textconsole.h" + +#include "zvision/singleValueContainer.h" + +namespace ZVision { + +SingleValueContainer::SingleValueContainer(ValueType type) : _objectType(type) { } + +SingleValueContainer::SingleValueContainer(bool value) : _objectType(BOOL) { + _value.boolVal = value; +} + +SingleValueContainer::SingleValueContainer(byte value) : _objectType(BYTE) { + _value.byteVal = value; +} + +SingleValueContainer::SingleValueContainer(int16 value) : _objectType(INT16) { + _value.int16Val = value; +} + +SingleValueContainer::SingleValueContainer(uint16 value) : _objectType(UINT16) { + _value.uint16Val = value; +} + +SingleValueContainer::SingleValueContainer(int32 value) : _objectType(INT32) { + _value.int32Val = value; +} + +SingleValueContainer::SingleValueContainer(uint32 value) : _objectType(UINT32) { + _value.uint32Val = value; +} + +SingleValueContainer::SingleValueContainer(float value) : _objectType(FLOAT) { + _value.floatVal = value; +} + +SingleValueContainer::SingleValueContainer(double value) : _objectType(DOUBLE) { + _value.doubleVal = value; +} + +SingleValueContainer::SingleValueContainer(Common::String value) : _objectType(BYTE) { + _value.stringVal = new char[value.size() + 1]; + memcpy(_value.stringVal, value.c_str(), value.size() + 1); +} + +SingleValueContainer::SingleValueContainer(const SingleValueContainer &other) { + _objectType = other._objectType; + + switch (_objectType) { + case BOOL: + _value.boolVal = other._value.boolVal; + break; + case BYTE: + _value.byteVal = other._value.byteVal; + break; + case INT16: + _value.int16Val = other._value.int16Val; + break; + case UINT16: + _value.uint16Val = other._value.uint16Val; + break; + case INT32: + _value.int32Val = other._value.int32Val; + break; + case UINT32: + _value.uint32Val = other._value.uint32Val; + break; + case FLOAT: + _value.floatVal = other._value.floatVal; + break; + case DOUBLE: + _value.doubleVal = other._value.doubleVal; + break; + case STRING: + uint32 length = strlen(other._value.stringVal); + _value.stringVal = new char[length + 1]; + memcpy(_value.stringVal, other._value.stringVal, length + 1); + break; + } +} + +SingleValueContainer::~SingleValueContainer() { + deleteCharPointer(); +} + +void SingleValueContainer::deleteCharPointer() { + if (_objectType == STRING) + delete[] _value.stringVal; +} + + +SingleValueContainer &SingleValueContainer::operator=(const bool &rhs) { + if (_objectType == BOOL) { + _value.boolVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = BOOL; + _value.boolVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const byte &rhs) { + if (_objectType == BYTE) { + _value.byteVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = BYTE; + _value.byteVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const int16 &rhs) { + if (_objectType == INT16) { + _value.int16Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = INT16; + _value.int16Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const uint16 &rhs) { + if (_objectType == UINT16) { + _value.uint16Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = UINT16; + _value.uint16Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const int32 &rhs) { + if (_objectType == INT32) { + _value.int32Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = INT32; + _value.int32Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const uint32 &rhs) { + if (_objectType == UINT32) { + _value.uint32Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = UINT32; + _value.uint32Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const float &rhs) { + if (_objectType == FLOAT) { + _value.floatVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = FLOAT; + _value.floatVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const double &rhs) { + if (_objectType == DOUBLE) { + _value.doubleVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = DOUBLE; + _value.doubleVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const Common::String &rhs) { + if (_objectType != STRING) { + _objectType = STRING; + _value.stringVal = new char[rhs.size() + 1]; + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + + return *this; + } + + uint32 length = strlen(_value.stringVal); + if (length <= rhs.size() + 1) { + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + } else { + delete[] _value.stringVal; + _value.stringVal = new char[rhs.size() + 1]; + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + } + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const SingleValueContainer &rhs) { + switch (_objectType) { + case BOOL: + return operator=(rhs._value.boolVal); + case BYTE: + return operator=(rhs._value.byteVal); + case INT16: + return operator=(rhs._value.int16Val); + case UINT16: + return operator=(rhs._value.uint16Val); + case INT32: + return operator=(rhs._value.int32Val); + case UINT32: + return operator=(rhs._value.uint32Val); + case FLOAT: + return operator=(rhs._value.floatVal); + case DOUBLE: + return operator=(rhs._value.doubleVal); + case STRING: + uint32 length = strlen(rhs._value.stringVal); + + _value.stringVal = new char[length + 1]; + memcpy(_value.stringVal, rhs._value.stringVal, length + 1); + + return *this; + } + + return *this; +} + + +bool SingleValueContainer::getBoolValue(bool *returnValue) const { + if (_objectType != BOOL) { + warning("'Object' is not storing a bool."); + return false; + } + + *returnValue = _value.boolVal; + return true; +} + +bool SingleValueContainer::getByteValue(byte *returnValue) const { + if (_objectType != BYTE) + warning("'Object' is not storing a byte."); + + *returnValue = _value.byteVal; + return true; +} + +bool SingleValueContainer::getInt16Value(int16 *returnValue) const { + if (_objectType != INT16) + warning("'Object' is not storing an int16."); + + *returnValue = _value.int16Val; + return true; +} + +bool SingleValueContainer::getUInt16Value(uint16 *returnValue) const { + if (_objectType != UINT16) + warning("'Object' is not storing a uint16."); + + *returnValue = _value.uint16Val; + return true; +} + +bool SingleValueContainer::getInt32Value(int32 *returnValue) const { + if (_objectType != INT32) + warning("'Object' is not storing an int32."); + + *returnValue = _value.int32Val; + return true; +} + +bool SingleValueContainer::getUInt32Value(uint32 *returnValue) const { + if (_objectType != UINT32) + warning("'Object' is not storing a uint32."); + + *returnValue = _value.uint32Val; + return true; +} + +bool SingleValueContainer::getFloatValue(float *returnValue) const { + if (_objectType != FLOAT) + warning("'Object' is not storing a float."); + + *returnValue = _value.floatVal; + return true; +} + +bool SingleValueContainer::getDoubleValue(double *returnValue) const { + if (_objectType != DOUBLE) + warning("'Object' is not storing a double."); + + *returnValue = _value.doubleVal; + return true; +} + +bool SingleValueContainer::getStringValue(Common::String *returnValue) const { + if (_objectType != STRING) + warning("'Object' is not storing a Common::String."); + + *returnValue = _value.stringVal; + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/single_value_container.h b/engines/zvision/single_value_container.h new file mode 100644 index 0000000000..49c7267f77 --- /dev/null +++ b/engines/zvision/single_value_container.h @@ -0,0 +1,181 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ZVISION_OBJECT_H +#define ZVISION_OBJECT_H + +#include "common/str.h" + +namespace ZVision { + +/** + * A generic single value storage class. It is useful for storing different + * value types in a single List, Hashmap, etc. + */ +class SingleValueContainer { +public: + enum ValueType { + BOOL, + BYTE, + INT16, + UINT16, + INT32, + UINT32, + FLOAT, + DOUBLE, + STRING, + }; + + // Constructors + explicit SingleValueContainer(ValueType type); + explicit SingleValueContainer(bool value); + explicit SingleValueContainer(byte value); + explicit SingleValueContainer(int16 value); + explicit SingleValueContainer(uint16 value); + explicit SingleValueContainer(int32 value); + explicit SingleValueContainer(uint32 value); + explicit SingleValueContainer(float value); + explicit SingleValueContainer(double value); + explicit SingleValueContainer(Common::String value); + + // Copy constructor + explicit SingleValueContainer(const SingleValueContainer& other); + + // Destructor + ~SingleValueContainer(); + +private: + ValueType _objectType; + + union { + bool boolVal; + byte byteVal; + int16 int16Val; + uint16 uint16Val; + int32 int32Val; + uint32 uint32Val; + float floatVal; + double doubleVal; + char *stringVal; + } _value; + +public: + SingleValueContainer &operator=(const bool &rhs); + SingleValueContainer &operator=(const byte &rhs); + SingleValueContainer &operator=(const int16 &rhs); + SingleValueContainer &operator=(const uint16 &rhs); + SingleValueContainer &operator=(const int32 &rhs); + SingleValueContainer &operator=(const uint32 &rhs); + SingleValueContainer &operator=(const float &rhs); + SingleValueContainer &operator=(const double &rhs); + SingleValueContainer &operator=(const Common::String &rhs); + + SingleValueContainer& operator=(const SingleValueContainer &rhs); + + /** + * Retrieve a bool from the container. If the container is not storing a + * bool, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getBoolValue(bool *returnValue) const; + /** + * Retrieve a byte from the container. If the container is not storing a + * byte, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getByteValue(byte *returnValue) const; + /** + * Retrieve an int16 from the container. If the container is not storing an + * int16, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getInt16Value(int16 *returnValue) const; + /** + * Retrieve a uint16 from the container. If the container is not storing a + * uint16, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getUInt16Value(uint16 *returnValue) const; + /** + * Retrieve an int32 from the container. If the container is not storing an + * int32, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getInt32Value(int32 *returnValue) const; + /** + * Retrieve a uint32 from the container. If the container is not storing a + * uint32, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getUInt32Value(uint32 *returnValue) const; + /** + * Retrieve a float from the container. If the container is not storing a + * float, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getFloatValue(float *returnValue) const; + /** + * Retrieve a double from the container. If the container is not storing a + * double, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getDoubleValue(double *returnValue) const; + /** + * Retrieve a String from the container. If the container is not storing a + * string, this will return false and display a warning(). + * + * Caution: Strings are internally stored as char[]. getStringValue uses + * Common::String::operator=(char *) to do the assigment, which uses both + * strlen() AND memmove(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getStringValue(Common::String *returnValue) const; + +private: + /** + * Helper method for destruction and assignment. It checks to see + * if the char pointer is being used, and if so calls delete on it + */ + void deleteCharPointer(); +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/zfsArchive.cpp b/engines/zvision/zfsArchive.cpp deleted file mode 100644 index e65d0df14e..0000000000 --- a/engines/zvision/zfsArchive.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* 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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/scummsys.h" - -#include "zvision/zfsArchive.h" -#include "common/hashmap.h" -#include "common/memstream.h" -#include "common/debug.h" - -namespace ZVision { - -ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) { - Common::File zfsFile; - - if (!zfsFile.open(_fileName)) { - warning("ZFSArchive::ZFSArchive(): Could not find the archive file"); - return; - } - - readHeaders(&zfsFile); - - debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); -} - -ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) { - readHeaders(stream); - - debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); -} - -ZfsArchive::~ZfsArchive() { - debug(0, "ZfsArchive Destructor Called"); - ZfsEntryHeaderMap::iterator it = _entryHeaders.begin(); - for ( ; it != _entryHeaders.end(); ++it) { - delete it->_value; - } -} - -void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { - // Don't do a straight struct cast since we can't guarantee endianness - _header.magic = stream->readUint32LE(); - _header.unknown1 = stream->readUint32LE(); - _header.maxNameLength = stream->readUint32LE(); - _header.filesPerBlock = stream->readUint32LE(); - _header.fileCount = stream->readUint32LE(); - _header.xorKey[0] = stream->readByte(); - _header.xorKey[1] = stream->readByte(); - _header.xorKey[2] = stream->readByte(); - _header.xorKey[3] = stream->readByte(); - _header.fileSectionOffset = stream->readUint32LE(); - - uint32 nextOffset; - - do { - // Read the offset to the next block - nextOffset = stream->readUint32LE(); - - // Read in each entry header - for (int i = 0; i < _header.filesPerBlock; i++) { - ZfsEntryHeader entryHeader; - - entryHeader.name = readEntryName(stream); - entryHeader.offset = stream->readUint32LE(); - entryHeader.id = stream->readUint32LE(); - entryHeader.size = stream->readUint32LE(); - entryHeader.time = stream->readUint32LE(); - entryHeader.unknown = stream->readUint32LE(); - - if (entryHeader.size != 0) - _entryHeaders[entryHeader.name] = new ZfsEntryHeader(entryHeader); - } - - // Seek to the next block of headers - stream->seek(nextOffset); - } while (nextOffset != 0); -} - -Common::String ZfsArchive::readEntryName(Common::SeekableReadStream *stream) const { - // Entry Names are at most 16 bytes and are null padded - char buffer[16]; - stream->read(buffer, 16); - - return Common::String(buffer); -} - -bool ZfsArchive::hasFile(const Common::String &name) const { - return _entryHeaders.contains(name); -} - -int ZfsArchive::listMembers(Common::ArchiveMemberList &list) const { - int matches = 0; - - for (ZfsEntryHeaderMap::const_iterator it = _entryHeaders.begin(); it != _entryHeaders.end(); ++it) { - list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(it->_value->name, this))); - matches++; - } - - return matches; -} - -const Common::ArchiveMemberPtr ZfsArchive::getMember(const Common::String &name) const { - if (!_entryHeaders.contains(name)) - return Common::ArchiveMemberPtr(); - - return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); -} - -Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common::String &name) const { - if (!_entryHeaders.contains(name)) { - return 0; - } - - ZfsEntryHeader *entryHeader = _entryHeaders[name]; - - Common::File zfsArchive; - zfsArchive.open(_fileName); - zfsArchive.seek(entryHeader->offset); - - byte* buffer = new byte[entryHeader->size]; - zfsArchive.read(buffer, entryHeader->size); - // Decrypt the data in place - if (_header.xorKey != 0) - unXor(buffer, entryHeader->size, _header.xorKey); - - return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES); -} - -void ZfsArchive::unXor(byte *buffer, int length, const byte *xorKey) const { - for (uint32 i = 0; i < length; i++) - buffer[i] ^= xorKey[i % 4]; -} - -} // End of namespace ZVision - - diff --git a/engines/zvision/zfsArchive.h b/engines/zvision/zfsArchive.h deleted file mode 100644 index ccdf192571..0000000000 --- a/engines/zvision/zfsArchive.h +++ /dev/null @@ -1,121 +0,0 @@ -/* 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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef ZVISION_ZFS_ARCHIVE_H -#define ZVISION_ZFS_ARCHIVE_H - -#include "common/archive.h" -#include "common/file.h" -#include "common/fs.h" - -namespace ZVision { - -struct ZfsHeader { - uint32 magic; - uint32 unknown1; - uint32 maxNameLength; - uint32 filesPerBlock; - uint32 fileCount; - byte xorKey[4]; - uint32 fileSectionOffset; -}; - -struct ZfsEntryHeader { - Common::String name; - uint32 offset; - uint32 id; - uint32 size; - uint32 time; - uint32 unknown; -}; - -typedef Common::HashMap ZfsEntryHeaderMap; - -class ZfsArchive : public Common::Archive { -public: - ZfsArchive(const Common::String &fileName); - ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream); - ~ZfsArchive(); - - /** - * Check if a member with the given name is present in the Archive. - * Patterns are not allowed, as this is meant to be a quick File::exists() - * replacement. - */ - bool hasFile(const Common::String &fileName) const; - - /** - * Add all members of the Archive to list. - * Must only append to list, and not remove elements from it. - * - * @return The number of names added to list - */ - int listMembers(Common::ArchiveMemberList &list) const; - - /** - * Returns a ArchiveMember representation of the given file. - */ - const Common::ArchiveMemberPtr getMember(const Common::String &name) const; - - /** - * Create a stream bound to a member with the specified name in the - * archive. If no member with this name exists, 0 is returned. - * - * @return The newly created input stream - */ - Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; - -private: - const Common::String _fileName; - ZfsHeader _header; - ZfsEntryHeaderMap _entryHeaders; - - /** - * Parses the zfs file into file entry headers that can be used later - * to get the entry data. - * - * @param stream The contents of the zfs file - */ - void readHeaders(Common::SeekableReadStream *stream); - - /** - * Entry names are contained within a 16 byte block. This reads the block - * and converts it the name to a Common::String - * - * @param stream The zfs file stream - * @return The entry file name - */ - Common::String readEntryName(Common::SeekableReadStream *stream) const; - - /** - * ZFS file entries can be encrypted using XOR encoding. This method - * decodes the buffer in place using the supplied xorKey. - * - * @param buffer The data to decode - * @param length Length of buffer - */ - void unXor(byte *buffer, int length, const byte *xorKey) const; -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp new file mode 100644 index 0000000000..e65d0df14e --- /dev/null +++ b/engines/zvision/zfs_archive.cpp @@ -0,0 +1,155 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" + +#include "zvision/zfsArchive.h" +#include "common/hashmap.h" +#include "common/memstream.h" +#include "common/debug.h" + +namespace ZVision { + +ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) { + Common::File zfsFile; + + if (!zfsFile.open(_fileName)) { + warning("ZFSArchive::ZFSArchive(): Could not find the archive file"); + return; + } + + readHeaders(&zfsFile); + + debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); +} + +ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) { + readHeaders(stream); + + debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); +} + +ZfsArchive::~ZfsArchive() { + debug(0, "ZfsArchive Destructor Called"); + ZfsEntryHeaderMap::iterator it = _entryHeaders.begin(); + for ( ; it != _entryHeaders.end(); ++it) { + delete it->_value; + } +} + +void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { + // Don't do a straight struct cast since we can't guarantee endianness + _header.magic = stream->readUint32LE(); + _header.unknown1 = stream->readUint32LE(); + _header.maxNameLength = stream->readUint32LE(); + _header.filesPerBlock = stream->readUint32LE(); + _header.fileCount = stream->readUint32LE(); + _header.xorKey[0] = stream->readByte(); + _header.xorKey[1] = stream->readByte(); + _header.xorKey[2] = stream->readByte(); + _header.xorKey[3] = stream->readByte(); + _header.fileSectionOffset = stream->readUint32LE(); + + uint32 nextOffset; + + do { + // Read the offset to the next block + nextOffset = stream->readUint32LE(); + + // Read in each entry header + for (int i = 0; i < _header.filesPerBlock; i++) { + ZfsEntryHeader entryHeader; + + entryHeader.name = readEntryName(stream); + entryHeader.offset = stream->readUint32LE(); + entryHeader.id = stream->readUint32LE(); + entryHeader.size = stream->readUint32LE(); + entryHeader.time = stream->readUint32LE(); + entryHeader.unknown = stream->readUint32LE(); + + if (entryHeader.size != 0) + _entryHeaders[entryHeader.name] = new ZfsEntryHeader(entryHeader); + } + + // Seek to the next block of headers + stream->seek(nextOffset); + } while (nextOffset != 0); +} + +Common::String ZfsArchive::readEntryName(Common::SeekableReadStream *stream) const { + // Entry Names are at most 16 bytes and are null padded + char buffer[16]; + stream->read(buffer, 16); + + return Common::String(buffer); +} + +bool ZfsArchive::hasFile(const Common::String &name) const { + return _entryHeaders.contains(name); +} + +int ZfsArchive::listMembers(Common::ArchiveMemberList &list) const { + int matches = 0; + + for (ZfsEntryHeaderMap::const_iterator it = _entryHeaders.begin(); it != _entryHeaders.end(); ++it) { + list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(it->_value->name, this))); + matches++; + } + + return matches; +} + +const Common::ArchiveMemberPtr ZfsArchive::getMember(const Common::String &name) const { + if (!_entryHeaders.contains(name)) + return Common::ArchiveMemberPtr(); + + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); +} + +Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common::String &name) const { + if (!_entryHeaders.contains(name)) { + return 0; + } + + ZfsEntryHeader *entryHeader = _entryHeaders[name]; + + Common::File zfsArchive; + zfsArchive.open(_fileName); + zfsArchive.seek(entryHeader->offset); + + byte* buffer = new byte[entryHeader->size]; + zfsArchive.read(buffer, entryHeader->size); + // Decrypt the data in place + if (_header.xorKey != 0) + unXor(buffer, entryHeader->size, _header.xorKey); + + return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES); +} + +void ZfsArchive::unXor(byte *buffer, int length, const byte *xorKey) const { + for (uint32 i = 0; i < length; i++) + buffer[i] ^= xorKey[i % 4]; +} + +} // End of namespace ZVision + + diff --git a/engines/zvision/zfs_archive.h b/engines/zvision/zfs_archive.h new file mode 100644 index 0000000000..ccdf192571 --- /dev/null +++ b/engines/zvision/zfs_archive.h @@ -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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ZVISION_ZFS_ARCHIVE_H +#define ZVISION_ZFS_ARCHIVE_H + +#include "common/archive.h" +#include "common/file.h" +#include "common/fs.h" + +namespace ZVision { + +struct ZfsHeader { + uint32 magic; + uint32 unknown1; + uint32 maxNameLength; + uint32 filesPerBlock; + uint32 fileCount; + byte xorKey[4]; + uint32 fileSectionOffset; +}; + +struct ZfsEntryHeader { + Common::String name; + uint32 offset; + uint32 id; + uint32 size; + uint32 time; + uint32 unknown; +}; + +typedef Common::HashMap ZfsEntryHeaderMap; + +class ZfsArchive : public Common::Archive { +public: + ZfsArchive(const Common::String &fileName); + ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream); + ~ZfsArchive(); + + /** + * Check if a member with the given name is present in the Archive. + * Patterns are not allowed, as this is meant to be a quick File::exists() + * replacement. + */ + bool hasFile(const Common::String &fileName) const; + + /** + * Add all members of the Archive to list. + * Must only append to list, and not remove elements from it. + * + * @return The number of names added to list + */ + int listMembers(Common::ArchiveMemberList &list) const; + + /** + * Returns a ArchiveMember representation of the given file. + */ + const Common::ArchiveMemberPtr getMember(const Common::String &name) const; + + /** + * Create a stream bound to a member with the specified name in the + * archive. If no member with this name exists, 0 is returned. + * + * @return The newly created input stream + */ + Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; + +private: + const Common::String _fileName; + ZfsHeader _header; + ZfsEntryHeaderMap _entryHeaders; + + /** + * Parses the zfs file into file entry headers that can be used later + * to get the entry data. + * + * @param stream The contents of the zfs file + */ + void readHeaders(Common::SeekableReadStream *stream); + + /** + * Entry names are contained within a 16 byte block. This reads the block + * and converts it the name to a Common::String + * + * @param stream The zfs file stream + * @return The entry file name + */ + Common::String readEntryName(Common::SeekableReadStream *stream) const; + + /** + * ZFS file entries can be encrypted using XOR encoding. This method + * decodes the buffer in place using the supplied xorKey. + * + * @param buffer The data to decode + * @param length Length of buffer + */ + void unXor(byte *buffer, int length, const byte *xorKey) const; +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3