ScummVM API documentation
main_game_file.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // This unit provides functions for reading main game file into appropriate
25 // data structures. Main game file contains general game data, such as global
26 // options, lists of static game entities and compiled scripts modules.
27 //
28 //=============================================================================
29 
30 #ifndef AGS_SHARED_GAME_MAIN_GAME_FILE_H
31 #define AGS_SHARED_GAME_MAIN_GAME_FILE_H
32 
33 #include "common/std/functional.h"
34 #include "common/std/memory.h"
35 #include "common/std/set.h"
36 #include "common/std/vector.h"
37 #include "ags/shared/core/platform.h"
38 #include "ags/shared/ac/game_version.h"
39 #include "ags/shared/ac/view.h"
40 #include "ags/shared/game/plugin_info.h"
41 #include "ags/shared/script/cc_script.h"
42 #include "ags/shared/util/error.h"
43 #include "ags/shared/util/stream.h"
44 #include "ags/shared/util/string.h"
45 #include "ags/shared/util/version.h"
46 
47 namespace AGS3 {
48 
49 struct GameSetupStruct;
50 struct DialogTopic;
51 
52 namespace AGS {
53 namespace Shared {
54 
55 // Error codes for main game file reading
56 enum MainGameFileErrorType {
57  kMGFErr_NoError,
58  kMGFErr_FileOpenFailed,
59  kMGFErr_SignatureFailed,
60  // separate error given for "too old" format to provide clarifying message
61  kMGFErr_FormatVersionTooOld,
62  kMGFErr_FormatVersionNotSupported,
63  kMGFErr_CapsNotSupported,
64  kMGFErr_InvalidNativeResolution,
65  kMGFErr_TooManySprites,
66  kMGFErr_InvalidPropertySchema,
67  kMGFErr_InvalidPropertyValues,
68  kMGFErr_CreateGlobalScriptFailed,
69  kMGFErr_CreateDialogScriptFailed,
70  kMGFErr_CreateScriptModuleFailed,
71  kMGFErr_GameEntityFailed,
72  kMGFErr_PluginDataFmtNotSupported,
73  kMGFErr_PluginDataSizeTooLarge,
74  kMGFErr_ExtListFailed,
75  kMGFErr_ExtUnknown
76 };
77 
78 String GetMainGameFileErrorText(MainGameFileErrorType err);
79 
80 typedef TypedCodeError<MainGameFileErrorType, GetMainGameFileErrorText> MainGameFileError;
81 typedef ErrorHandle<MainGameFileError> HGameFileError;
82 typedef std::unique_ptr<Stream> UStream;
83 
84 // MainGameSource defines a successfully opened main game file
86  // Standart main game file names for 3.* and 2.* games respectively
87  static const char *DefaultFilename_v3;
88  static const char *DefaultFilename_v2;
89  // Signature of the current game format
90  static const char *Signature;
91 
92  // Name of the asset file
93  String Filename;
94  // Game file format version
95  GameDataVersion DataVersion;
96  // Tool identifier (like version) this game was compiled with
97  String CompiledWith;
98  // Extended engine capabilities required by the game; their primary use
99  // currently is to let "alternate" game formats indicate themselves
100  std::set<String> Caps;
101  // A ponter to the opened stream
102  UStream InputStream;
103 
104  MainGameSource();
105 };
106 
107 // LoadedGameEntities is meant for keeping objects loaded from the game file.
108 // Because copying/assignment methods are not properly implemented for some
109 // of these objects yet, they have to be attached using references to be read
110 // directly. This is temporary solution that has to be resolved by the future
111 // code refactoring.
113  GameSetupStruct &Game;
114  std::vector<DialogTopic> Dialogs;
116  PScript GlobalScript;
117  PScript DialogScript;
118  std::vector<PScript> ScriptModules;
119  std::vector<PluginInfo> PluginInfos;
120 
121  // Original sprite data (when it was read into const-sized arrays)
122  size_t SpriteCount;
123  std::vector<uint8_t> SpriteFlags; // SPF_* flags
124 
125  // Old dialog support
126  // legacy compiled dialog script of its own format,
127  // requires separate interpreting
128  std::vector<std::vector<uint8_t>> OldDialogScripts;
129  // probably, actual dialog script sources kept within some older games
130  std::vector<String> OldDialogSources;
131  // speech texts displayed during dialog
132  std::vector<String> OldSpeechLines;
133 
136 };
137 
138 class AssetManager;
139 
140 // Tells if the given path (library filename) contains main game file
141 bool IsMainGameLibrary(const String &filename);
142 // Scans given directory path for a package containing main game data, returns first found or none.
143 String FindGameData(const String &path);
144 String FindGameData(const String &path, bool(*fn_testfile)(const String &));
145 // Opens main game file for reading from an arbitrary file
146 HGameFileError OpenMainGameFile(const String &filename, MainGameSource &src);
147 // Opens main game file for reading using the current Asset Manager (uses default asset name)
148 HGameFileError OpenMainGameFileFromDefaultAsset(MainGameSource &src, AssetManager *mgr);
149 // Reads game data, applies necessary conversions to match current format version
150 HGameFileError ReadGameData(LoadedGameEntities &ents, Stream *in, GameDataVersion data_ver);
151 // Pre-reads the heading game data, just enough to identify the game and its special file locations
152 void PreReadGameData(GameSetupStruct &game, Stream *in, GameDataVersion data_ver);
153 // Applies necessary updates, conversions and fixups to the loaded data
154 // making it compatible with current engine
155 HGameFileError UpdateGameData(LoadedGameEntities &ents, GameDataVersion data_ver);
156 // Ensures that the game saves directory path is valid
157 void FixupSaveDirectory(GameSetupStruct &game);
158 // Maps legacy sound numbers to real audio clips
159 void RemapLegacySoundNums(GameSetupStruct &game, std::vector<ViewStruct> &views, GameDataVersion data_ver);
160 
161 } // namespace Shared
162 } // namespace AGS
163 } // namespace AGS3
164 
165 #endif
Definition: achievements_tables.h:27
Definition: vector.h:39
Definition: ptr.h:572
Definition: asset_manager.h:78
Definition: main_game_file.h:85
Definition: game_setup_struct.h:53
Definition: set.h:42
Definition: string.h:62
Definition: ptr.h:159
Definition: stream.h:52
Definition: main_game_file.h:112
Definition: ags.h:40