ScummVM API documentation
resource_patcher.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 #ifndef SCI_RESOURCE_RESOURCE_PATCHER_H
23 #define SCI_RESOURCE_RESOURCE_PATCHER_H
24 
25 #include "common/language.h"
26 #include "sci/sci.h"
27 #include "sci/resource/resource.h"
28 #include "sci/resource/resource_intern.h"
29 
30 namespace Sci {
31 
32 enum ResourcePatchOp {
33  // Using high bytes to make it less likely that accidental raw data will be
34  // treated like an operator instead of an error
35  kSkipBytes = 0xF0,
36  kReplaceBytes,
37  kInsertBytes,
38  kReplaceNumber,
39  kAdjustNumber,
40  kInsertNumber,
41  kReplaceFill,
42  kInsertFill,
43  kEndOfPatch
44 };
45 
46 enum SciMedia : uint;
47 
52  SciGameId gameId;
53 
57  SciMedia media;
58 
64 
68  ResourceType resourceType;
69 
74 
78  const byte *patchData;
79 
85 };
86 
91 public:
92  ResourcePatcher(const SciGameId gameId, const bool isCD, const Common::Platform platform, const Common::Language gameLanguage);
93 
94  ~ResourcePatcher() override {}
95 
101  bool applyPatch(Resource &resource) const;
102 
108  void scanSource(ResourceManager *resMan) override;
109 
115  void loadResource(ResourceManager *resMan, Resource *res) override {}
116 
117 private:
118  struct PatchSizes {
122  uint32 expected;
123 
128  int32 delta;
129 
130  PatchSizes(uint32 exp, int32 d) {
131  expected = exp;
132  delta = d;
133  }
134  };
135 
137 
141  PatchList _patches;
142 
147  void patchResource(Resource &resource, const GameResourcePatch &patch) const;
148 
152  PatchSizes calculatePatchSizes(const byte *patchData) const;
153 
158  int32 readBlockSize(const byte * &patchData) const;
159 };
160 } // End of namespace Sci
161 
162 #endif // SCI_RESOURCE_RESOURCE_PATCHER_H
uint16 resourceNumber
Definition: resource_patcher.h:73
Definition: resource_patcher.h:48
Definition: resource.h:327
SciGameId gameId
Definition: resource_patcher.h:52
void loadResource(ResourceManager *resMan, Resource *res) override
Definition: resource_patcher.h:115
bool isNewResource
Definition: resource_patcher.h:84
Definition: resource.h:256
Definition: console.h:28
ResourceType resourceType
Definition: resource_patcher.h:68
Common::Language gameLanguage
Definition: resource_patcher.h:63
Definition: resource_patcher.h:90
Definition: resource_intern.h:48
SciMedia media
Definition: resource_patcher.h:57
const byte * patchData
Definition: resource_patcher.h:78
Platform
Definition: platform.h:46
Language
Definition: language.h:45